technique for how to debug macros in C
Posted
by
Dervin Thunk
on Stack Overflow
See other posts from Stack Overflow
or by Dervin Thunk
Published on 2011-01-01T15:15:07Z
Indexed on
2011/01/01
17:53 UTC
Read the original article
Hit count: 187
Hi. So I have the (mostly vilified) #define MAX( a, b ) ( ((a) > (b)) ? (a) : (b) )
somewhere in a program (yes, yes, I know). At some point in the code there is a comparison X>-1?
, where X is (as far as I can tell) a (signed) integer. The line is j += MAX(bmGs[i], bmBc[(int)y[i + j]] - m + 1 + i);
, where y
here is a char*
. Not necessarily surprisingly, I find that the macro is returning -1
as the larger number (I'm guessing too long a number for int
or an unsigned
issue, but I can't find it). I would like to know techniques you guys may have for finding these kinds of errors.
Notice that I'm not asking for programming advice about whether or not to use that macro, I'm sure folks are dying to tell me I should refrain from things like that, but the question is going somewhere else.
Thanks.
© Stack Overflow or respective owner