[chbot] return value or status from function

Mark Atherton markaren1 at xtra.co.nz
Fri Feb 5 04:38:38 GMT 2016

or use an S16 to return a (+ve) U8 value on success, with one of many 
-ve values indicating error(s).


On 5/02/2016 5:21 p.m., Jasper Mackenzie wrote:
> Good day all,
>  What is the opinion of this esteemed group on the 
> best/proper/whatever way to get the measured value from some external 
> input from a micro in C.
> By measured value I mean something like ADC, OW temp sensor, I2C 
> sensor state etc.
>  I am considering the following three scenarios in increasing order of 
> goodness:
> 1) function returns the measured value indicating error by out of 
> range result (i.e 0xFF for  8 bit int)
> i.e:
> ...
> unit8_t readSomePin(void); // 0xFF indicates error
> 2) function returns the measured value indicating status of 
> measurement in another extern. variable
> ...
> extern uint8_t readSomePinStatus;
> unit8_t readSomePin(void);  // Status in readSomePinStatus
> 3) function returns status, the value is stored in an argument variable:
> ...
> unint8_t readSomePin(uint8_t *returnedValue);
> So, what is best? Is there a better way? This could no doubt also be 
> done with Structs, but seems like overkill to me.
> Cheers
> jasper
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20160205/b3aef527/attachment.html>

More information about the Chchrobotics mailing list