#define MIN(A,B) ((A) <= (B) ? (A) : (B))
this is the macro , I was asked what's the side effect if I used the following :
least = MIN(*p++, b);
Note: This was embedded c question
The macro in C language is known as the piece of code which can be replaced by the macro value. The macro is defined with the help of #define preprocessor directive and the macro doesn't end with a semicolon(;).
The formal definition of side effect in the C language (C17 5.1.2.3/2) is rather: Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment.
In C, the macro is used to define any constant value or any variable with its value in the entire program that will be replaced by this macro name, where macro contains the set of code that will be called when the macro name is used in the program.
There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls. You may define any valid identifier as a macro, even if it is a C keyword.
It evaluates p++
twice. Also, since the first evaluation changes p
, the second time around it will point to a different element. So the returned value will be *(initialp + 1)
or b
.
You should try it yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With