int a[4];
#define n (sizeof(a) / sizeof(a[0]))
int d = n;
if (-1 < n) {
printf("yup\n");
}
if (-1 < d) {
printf("cuack\n");
}
Why is that it doesn't print "yup"?
Name:
Anonymous2011-03-12 2:07
I'm going to go out on a sleep-deprived limb and guess it has something to do with formally declaring and initializing d to constraint whatever is in n, whereas n may not even have a representable value before that.
Which version of C are we talking about?
Name:
Anonymous2011-03-12 2:13
I am using gcc, with sizeof(int) produces the dame result.
if (-1 < sizeof(int)) {
printf("yup\n");
}
As always when macros are giving an unexpected result, look at the preprocessed source and be enlightened.
Name:
Anonymous2011-03-22 22:58
gcc (3.4.4) does this and the preprocessed results don't give anything away
even with all -O0, the first branch and call to printf is missing from the generated assembly
are the optimization flags buggy?