thundium
thundium

Reputation: 1063

fatal error C1017: invalid integer constant expression when using "#if (false)"

Have following code which is working under Linux but gives error for MSVS

#if (false)
....
#endif

The error is: fatal error C1017: invalid integer constant expression

I found this report on Microsoft's web: http://msdn.microsoft.com/en-us/library/h5sh3k99.aspx

While the info described there differs a little bit compared to my case as I didn't use the "#define"

So my question is:

  1. Is there any way to make it working for MSVC without changing code ?
  2. If the code must be updated, what's the best solution for this kind of case?

Upvotes: 9

Views: 12522

Answers (2)

Columbo
Columbo

Reputation: 61009

Is there any way to make it working for MSVC without changing code ?

Not really. Defining a macro for false is forbidden by the standard for good reasons, [macro.names]/2:

A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 3, or to the attribute-tokens described in 7.6.

And I don't see any other way.

If the code must be updated, what's the best solution for this kind of case?

Substitute 0 for false.

Upvotes: 4

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727027

It looks like your version of MS compiler does not support false as a built-in constant. This is not surprising, because Microsoft has a spotty record of supporting standards for C and C++.

One way to make this work without changing the code is to pass command-line parameters to the compiler to define false as 0 and true as 1:

-Dfalse=0 -Dtrue=1

Upvotes: 4

Related Questions