Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#if defined (x) || (y) ; is this valid?

Tags:

c

During one review I came across a piece of code like the following :

#if defined(x) || y 

What does the above statement mean ? Will the condition execute properly ?

like image 976
lxusr Avatar asked Mar 30 '12 15:03

lxusr


1 Answers

Yes it is valid.

Here is what the Standard (C99) says in 6.10p1:

if-group: # if constant-expression new-line groupopt # ifdef identifier new-line groupopt # ifndef identifier new-line groupopt 

the defined operator is seen as unary operator part of a constant expression (6.10.1p1).

In your example, the condition is evaluated as true if the macro x is defined OR if y is defined and different than 0

like image 175
ouah Avatar answered Oct 01 '22 04:10

ouah