It is strange if the condition in c: if (((void) (d), 0)) {...}

I read the Xen source code and saw something like this:

#define is_domain_direct_mapped(d) ((void)(d), 0)

is_domain_direct_mapped is then used in the if statement as follows (d is a pointer to a structure variable):

if( is_domain_direct_mapped(d) ) {...}

So, after the compiler replaces is_domain_direct_mapped with its definition, we have something like:

if( ((void)(d), 0) ) {...}

The above if statement is very strange to me. This is the first time I see such an expression. How should this work?

+4
source share
2 answers

It should always produce 0, but also evaluate d, in case of something with side effects like p++.

, 0: ARM.

#define is_domain_direct_mapped(d) ((d) == hardware_domain && dom0_11_mapping)

, d .

, - Re: [Xen-devel] [PATCH v3 1/3] xen/x86: is_domain_direct_mapped (d) (0) x86:

/memory.c, : [1]:

#define is_domain_is_direct_mapped(d) ((void)(d), 0)

, .

Re: [v4] xen/arm: 1:1:

( ), ,

#define is_domain_direct_mapped(d) ((void)(d), 0)
+7

.

( d) . (0) .

+2

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


All Articles