An unsafe function-like macro is one whose expansion results in evaluating one of its parameters more than once or not at all.
#define ABS(x) (((x) < 0) ? -(x) : (x)) /* UNSAFE */
void func(int n) {
/* Validate that n is within the desired range */
++n;
int m = ABS(n);
/* ... */
}
The arguments to a macro must not include preprocessor directives, such as #define, #ifdef, and #include.
void func(const char *src) {
/* Validate the source string; calculate size */
char *dest;
/* malloc() destination string */
memcpy(dest, src,
#ifdef PLATFORM1
12
#else
24
#endif
);
/* ... */
}
struct flexArrayStruct{
int num;
int data[];
};