Initialization to invalid value
Posted on 2004-11-16
Consider all 1's to be an invalid value in our implementation.
For initializing the signed quantities to all 1's, we can use the following macro
#define INVAILD_VAL (~0)
It will work for irrespective of the size of the datatype during initialization.
But during comparison, it fails....
unsigned char var = 0xff;
if(var == (~0))
Above example prints 'Not Equal'. However, if datatype of 'var' is changed to unsigned long it print equal.
can you suggest some generic mechanism to check for invalid value for unsigned quantities irrespective of their size.