Consider this C construct that checks for errors before doing actual work:
int function(struct Context *context,struct Connection *conn)
{
int retval;
switch(0)
{
case 0:
retval = BUFFER_INACTIVE;
if(conn->mSocket == -1)
break;
retval = BUFFER_FULL;
/* Is there enough room to add ? */
if((context->mMaxBufferSize - conn->mSendPacketLength) < aPacketLength)
break;
/* Is the send packet buffer half sent? */
if(conn->mSendPacketLength > 0 && conn->mSendPacketPos != conn->mSendPacket)
break;
/* Do some work here */
retval = BUFFER_DONE;
}
/* Do some things before returning */
printf("%d",retval);
return retval;
}
Would you consider this a being readable? Would the alternatives, using goto
or stacked if()
be better?