I need to write a macro that runs on bitarray, looking like this:
array[0] = number of bits in bitarray (integer) array[1..n] = bits
The macro should look like this:
GetBit(pointer, index) Macro *must* return 0,1 or call function similar to exit().
This is my (working) built-in macro function that I have to write:
static inline unsigned long GetBit(BitArray_t array, unsigned long index) { if ((index) >= array[0]) exit(EXIT_FAILURE); else return (GetBit_wo_boundary_checks(array,index)); }
This is what I have:
#define GetBit(array,index)\ (((index) < array[0] || exit(EXIT_FAILURE)) ?\ GetBit_wo_boundary_checks(array,index) : 0)
My problem is that I need to do an index border check (i <p [0]) and exit before trying to access undefined memory using GetBit_wo_boundary_checks (p, i).
I thought I could get around this by putting the output in a short circuit condition, but I get: "invalid use of void expression" .
Is there a way to make this expression a transparent output macro () when the index is greater than the maximum specified in the array [0]?
Aoeoe source share