lundi 8 février 2021

Do 'true' and 'false' have their usual meaning in preprocessor expressions?

Given a C++11 compiler, which #error is the correct one it should end up with?

// no #includes!
#define SOMEMACRO true
#if SOMEMACRO
  #error "it was true"
#else
  #error "it was false"
#endif

Godbolt demo

Obviously I'm using #error just as a test. I know true and false are defined on the C++ language level, but this is preprocessing. In C99 it seems to be not a preprocessor word.

I'm asking because it seems that all compilers I tried see it as 'true', while a static code analysis tool insists that true isn't defined, implicitly false and ends up in "it was false".

Aucun commentaire:

Enregistrer un commentaire