[chbot] return value or status from function

Volker Kuhlmann list0570 at paradise.net.nz
Mon Feb 8 04:55:19 GMT 2016


On Fri 05 Feb 2016 19:09:06 NZDT +1300, Col wrote:

> Return TRUE or FALSE to make code more structured and readable
> 
> eg
> 
> if( readSomePIN(...) )
> 	//process result
> else
> 	//deal with error

1) Do not return TRUE or FALSE, return PASS or FAIL. (And
define one as 0, and the other as !0 - never define as 1.)

2) If you need more than binary status, return error code enum (note:
OK == 0 in this case) and make your function return type err_t:

typedef enum {
	E_OK,
	E_WHATEVER
} err_t;

Volker

-- 
Volker Kuhlmann
http://volker.top.geek.nz/	Please do not CC list postings to me.



More information about the Chchrobotics mailing list