Before I define a macro function, I can check that it doesn't already exist
(this avoids overwriting a previous definition).
I can implement the check and definition like this:
#ifndef MACRO(X)
#define MACRO(X) FUNCTION(X)
#endif
Or like this:
#ifndef MACRO
#define MACRO(X) FUNCTION(X)
#endif
Both appear to work when the function is already defined.
So, which is correct? Which is preferred?
Without.
The standard specifies that
#ifndefis equivalent to#if !defined, and that the argument todefinedmust be a (possibly parenthesized) identifier. You can't have parens in an identifier, sodefined MACRO(X)is not an allowed form. This use ofdefinedcauses undefined behaviour, so it is not portable.