We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
It happened again.
I have many cases of modules with something like #ifdef TYPEA ... many lines #endif #ifdef TYPEB ... many similar lines #endif #ifdef TYPEC ... many similar lines #endif
It happens that I am looking at the type b code trying to figure out something in type a (the codes are VERY similar).
To avoid this, I have tried
blah,blah // comment TYPEA
and that "kind of works"
Now, the ideal would be if for type a I could do the following: #ifdef TYPEA #define ATYPE #define BTYPE // #define CTYPE // #endif
and then just make it ATYPE blah,blah // comment
Of course this does not work. Does anyone have a trick that makes this possible?
Erik
you'll have to encapsulate statements, not blocks or lines:
--- a.c --- #define TYPE_A(x) x #define TYPE_B(x) /* nothing */ #define TYPE_C(x) /* nothing */
That one I do not understand
Strange, given it does exactly what you tried to achieve, just differently enough to get it to work. You wanted to write
TYPEA code for a; TYPEB code for variant b; TYPEC code vor variant c;
The macros I've shown allow to do that, but you'll have to spell it a bit differently:
TYPEA(code for a); TYPEB(code for variant b); TYPEC(code vor variant c);
and this syntax will pose some constraints on what you can write as "code for ...".
I guess the extra parentheses would be confoosing, i will write a few lines and judge
thanx