mardi 5 avril 2016

Is it good practice to make a function return different error codes it it fails?

Let's say (in C) we define a set of error codes,

#define action_success 0x00
#define action_fail -0x01
#define action_status_unknown 0x02

and a function

int PerformSomeAction(int *someInput){
       if(!someInput) return action_status_unknown;
       if(sizeof(someInput)/sizeof(int) < 20) return action_fail;
       if(sizeof(someInput)/sizeof(int) >= 21) return action_success;
}

In cases similar to these, is it good to follow such a strategy?

Aucun commentaire:

Enregistrer un commentaire