Lets say I define a macro:
#define MAX(x,y) ((x)>(y)?(x):(y))
What would happen if I call MAX(I++,J++)?
I couldn’t understand why the answer would not be as expected.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Macros are just for the preprocessor. This is what would get compiled by the C compiler:
As you can see, if I is larger than J then I will get incremented twice and J once, otherwise it’s vice versa.
Your macro is not even correct. The outer layer of parentheses is wrong here, which will cause a compilation error: