Wednesday, August 14, 2013

Conditional compilation oddity

Newsgroup: comp.lang.c++

Subject: Conditional compilation oddity

From: "Norman J. Goldstein" <normvcr@...>

Date: Fri, 09 Aug 2013 21:36:10 -0700



The following program compiles and links.

No warnings The output is wrong, stating:



value= 1

value NOT 1





//////////////////////////////////////////////

#include <iostream>

using namespace std;



static constexpr int value = 1;



int main( int argc, char* argv[] )

{

cout << "value= "

<< value

<< endl;



static_assert( value == 1, "Value_Not_1" );



#if value == 1

cout << "value 1" << endl;

#else

cout << "value NOT 1" << endl;

#endif



return 0;

}// main

/////////////////////////////////////////////////



Why is value not used in the conditional compilation?

(The static_assert is happy.)



I am using

gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)

pn

Linux 3.9.11-200.fc18.i686.PAE #1 SMP







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?63067-Conditional-compilation-oddity&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment