What is the side effect of the following macro in C? Built-in C

#define MIN(A,B) ((A) <= (B) ? (A) : (B)) 

This is a macro, I was asked what side effect I used:

 least = MIN(*p++, b); 

Note. It was related to the question.

+4
source share
3 answers

It evaluates p++ twice. In addition, since the first estimate changes p , the second time it will point to another element . So the return value will be *(initialp + 1) or b .

You have to try it yourself.

+6
source

The macro will expand to:

 least = ((*p++)<=(b)?(*p++):(b)) 

you will then have *p++ twice in your statement (i.e. it will double in size).

+7
source

*p++ gets evaluated twice when the macro expands to *p++ <= b ? *p++ : b *p++ <= b ? *p++ : b

Also, there is no such thing as "embedded C".

+2
source

All Articles