Doubt about conditional inclusion

This is really extracted from my module (Pre-processor in C)

A conditional expression can contain any operator C, with the exception of assignment, increment, and decrement operators.

I am not sure if I get this expression or not, since I tried to use this and it worked. Also for other manipulations, the likely work around would be to simply declare a macro or function inside a conditional expression, something like this, to be exact .

And I do not understand what is the reason for this rule. Can someone explain?

thank

+3
source share
3 answers

, , , .

#if defined TEST
  int a = 0;
#endif

- , #if, defined TEST.

, , , , , .
.

#define X a++
#define Y 42

#if X == Y
#endif

#if X == Y X Y ( a++ 42),

#if a++ == 42

a . a , 0:

#if 0++ == 42

, , . 0, .

+5

, , .

, ,

#if X = 4 //wrong

#if X++  //this too wrong

#if X-- //this too

EDIT:

Diego Sevilla,

, - (ideone.com/ahXDA) ? -

, ,

//global code
int b=7; 
b++;  //ill-formed!

C ( ++). , , C,

//legal in C Only
int b = 7;
int b; //well-formed!

. C Standard $6.9.2/2,

static, . , , , , , 0.

, :

//illegal in both C and C++
int b=7;
int b=8; //error 

. , !

+4

The paragraph in bold refers to expressions #if, so you can use the operators:

#if VARIABLE > 3

etc., not the code that is inside the macros that you define.

+1
source

Source: https://habr.com/ru/post/1782589/


All Articles