I have a function that I need to macro’ize. The function contains temp variables and I can’t remember if there are any rules about use of temporary variables in macro substitutions.
long fooAlloc(struct foo *f, long size)
{
long i1, i2;
double *data[7];
/* do something */
return 42;
}
MACRO Form:
#define ALLOC_FOO(f, size) \
{\
long i1, i2;\
double *data[7];\
\
/* do something */ \
}
Is this ok? (i.e. no nasty side effect – other than the usual ones : not “type safe” etc). BTW, I know “macros are evil” – I simply have to use it in this case – not much choice.
There are only two conditions under which it works in any “reasonable” way.
The macro doesn’t have a return statement. You can use the
do whiletrick.You only target GCC.
It would help if you explain why you have to use a macro (does your office have “macro mondays” or something?). Otherwise we can’t really help.