[chbot] return value or status from function

Jasper Mackenzie jasper.mackenzie at gmail.com
Fri Feb 5 04:21:46 GMT 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20160205/70c01e3e/attachment.html>


More information about the Chchrobotics mailing list