Learn somethin’ new every day

First time I’ve been using the preprocessor to do some math.

Turns out you can’t use sizeof() in math with preprocessor #if…

“The token sequence that makes up the constant expression undergoes macro replacement, except that names prefixed by defined are not expanded. In this context, the expression defined NAME or defined ( NAME ) evaluates to 1 if NAME is currently defined, 0 if it is not. Any other identifiers in the expression including those that are C keywords are replaced with the value 0. Then the expression is evaluated. The replacement even of keywords means that sizeof can’t be used in these expressions to get the result that you would normally expect.”

Makes sense, now I see it.

Comments are closed.