Kiran's Blog

Ramblings from a dehydrated mind…

  • Archives

  • Blog Stats

    • 9,866

function return values…

Posted by kiraninbng on July 18, 2006

Generally functions on success will return a value of 0,but i have often seen funtions which return a value of 1 for success,which i believe makes the function inextensible
for returning meaningful error codes.Heres what i follow,

typedef enum
{
 SUCCESS,
 …,
 FAILURE_N
}RETURNTYPE;

RETURNTYPE SomeFunction()
{
 RETURNTYPE Result = SUCCESS;
 
 if(…)
 {
  Result = FAILURE_N;
 }

 return(Result);

In simple terms return a value of 0(FALSE) for success and a value other than 0 for failure.

2 Responses to “function return values…”

  1. FarPointer said

    How about making the return type a class , so later you can query to find the
    1. the latest error
    2. to get a descriptive note by maintaining a map inside.
    3. And ofcourse its more object oriented ,enabling us to set different property for the error class.

  2. kiraninbng said

    Totally agree with you,returning an error object is far better solution for bigger and complex projects.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>