Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 739
thundium Avatar asked Nov 16 '14 16:11

thundium


2 Answers

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
like image 54
Sergey Kalinichenko Avatar answered Nov 04 '22 08:11

Sergey Kalinichenko


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.

like image 38
Columbo Avatar answered Nov 04 '22 09:11

Columbo