Define multiple symbolic constants that replace integer literals. If you have a bunch of functions that return 0 for success and -1 for error, then don’t do this:
#define ERROR -1
#define OK 0
#define ADD_ERR -1
#define ADD_OK 0
#define SEND_OK 0
#define SEND_ERR -1
#define RECV_ERR -1
#define RECV_OK 0
int func()
{
/* stuff */
if(/*something bad*/)
return ERROR;
else
return OK
}
int add()
{
/* add here */
return ADD_OK;
}
int send()
{
if(/*send ok*/)
return SEND_OK;
else
return SEND_ERR;
}
int recv()
{
if(/* receive packet successfully */)
return RECV_OK
else
return RECV_ERR;
}
Andrew Connell
Contact