Reputation: 1489
There was one evil macro trick I DON'T REMEMBER and it was a lot like this:
public :
var = 3;
}
Which should expand to
if(route == ROOTING_PUBLIC)
{
var = 3;
}
How can I achieve something like this ?
Upvotes: 1
Views: 595
Reputation: 1489
Now that I found the implementation of such bad idea, I also could understand the deeper sense in it.
The code
#define public if(route == ROOTING_PUBLIC) { public_offset
The usage
public :
var = 3;
} // <-- makes no sense
The idea
To avoid loops, to reduce the spaghetti code and to demonstrate more exotic code. It will be better to be implemented with an id system as such:
#define public(id) if(route == ROOTING_PUBLIC) { public_##id
And then if the user decides to loop the code (that by semantics will be invoked solely "publicly"):
public(2) :
var = 3;
if(var > 3) goto public_2; // or #define repeat(x, id) goto x##_##id
}
Even better version of it will include the omitting of magic numbers, replacing it with user_id
Upvotes: 1
Reputation: 54505
Macros are used to reduce clutter; though a lot of clutter indicates problems with the program structure.
The OP's notion of the possible macro does not match C-syntax. But something along those lines might be:
#define if_ROOTED(name) if (ROOTED_##name & input) { output = e##name; }
#define ROOTED_FIRST 16
#define ROOTED_SECOND 64
#define eFIRST 1
#define eSECOND 2
if_ROOTED(FIRST);
if_ROOTED(SECOND);
where input and output and the repetitive test are the "clutter" to be eliminated. Making a table would be a better way to reduce clutter; however OP asked for a hint about macros.
Upvotes: 3