Hi, I wrote a test macro to check when I went beyond the bounds of an array vs. writing the same test over and over again but gcc will not accept it. Here's an over simplified version that exhibits the bug.
If I code it with an if test then it will compile. I'm not understanding why the ? : construct does not do the job. To me the ? : construct makes a prettier one liner and even if I were to just decide that the if was ok I still want to know what makes the? : unacceptable as I desire to understand the language better and better.
Code:
#define TESTME(pos, maxpos) ((pos) <= (maxpos)) ? : return(0);
int main(void)
{
int a = 0;
int b = 100;
while(a++)
{
TESTME(a, b);
}
return(0);
}
Code:
% gcc a.c
a.c: In function ‘main’:
a.c:1:53: error: expected expression before ‘return’
#define TESTME(pos, maxpos) ((pos) <= (maxpos)) ? : return(0);
^
a.c:9:9: note: in expansion of macro ‘TESTME’
TESTME(a, b);
^