Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding zero in c preprocessor statement

While looking through some c header files (specifically stdarg.h), I noticed a very peculiar line:

#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L

The strange part is the + 0. Zero is the additive identity; it's one of the various math has of writing noop.

What purpose does adding zero have in the above preprocessor statement? I know that there's all sorts of weird preprocessor magic out there, but this just seems ridiculous.

like image 920
ApproachingDarknessFish Avatar asked Dec 07 '13 23:12

ApproachingDarknessFish


1 Answers

That avoids a preprocessor syntax error if __STDC_VERSION__ is defined as an empty token (e.g. with #define __STDC_VERSION__).

(Thanks to Jens Gustedt for pointing out that the first version of my answer was wrong.)

like image 59
Martin R Avatar answered Sep 22 '22 17:09

Martin R