view raw
Humayun Akhtar Humayun Akhtar - 8 months ago 49
C Question

How do i write if conditions like these in macro?

I'm quite new to macro

i know how to use if condition using ternary operator.

How do i convert this into #define


I try my luck with this but seems like it is wrong

#define ifcount(i,j) ((i)==(j)? count=count+1\


Using (abusing) macros to change the flow of the program is usually a bad idea, because the people that will read your code (yourself in a few years) may get surprised by unexpected jumps in the program flow.

That said, your problem has nothing to do with the ternary operator. Actually the ternary operator cannot contain a break in its right side, only expressions.

But macros are allmighty, so you can just do:

#define ifcount(i,j) if ((i)==(j)) { count=count+1; break; } else ;

The else is there to prevent attaching to a nearer unrelated else by accident.