Question

I've encountered a PC-Lint error message (e136) :

Illegal macro name  -- The ANSI standard restricts the use of certain names as
macros.  defined is on the restricted list.

I cannot find any reference to such a list in the ANSI C specifications. Is this list maintained by PC-Lint itself or is there an official list of Macro names forbidden in ANSI C?

Was it helpful?

Solution

The chances are that you're using a macro name such as _HEADER_FILE_H_ which is reserved to the implementation and PC Lint is telling you about this error.

After removing the horizontal scroll bar, it appears that the name you are misusing is defined. The C preprocessor uses the name defined for:

#if defined(SOME_MACRO)

You cannot, therefore, write:

#define defined(x)   ((x) != 0)

or anything similar. You should treat defined as a keyword, at least in pre-processor directives (and you can't treat it as a macro outside of pre-processor directives). Although you could use it as a variable name (and you could use endif and define and elif as variable names too), you'd be best off not using it and treating them as reserved words.


The C11 standard (ISO/IEC 9899:2011) says:

7.1.3 Reserved identifiers

¶1 Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.

  • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
  • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
  • Each macro name in any of the following subclauses (including the future library directions) is reserved for use as specified if any of its associated headers is included; unless explicitly stated otherwise (see 7.1.4).
  • All identifiers with external linkage in any of the following subclauses (including the future library directions) and errno are always reserved for use as identifiers with external linkage.184)
  • Each identifier with file scope listed in any of the following subclauses (including the future library directions) is reserved for use as a macro name and as an identifier with file scope in the same name space if any of its associated headers is included.

¶2 No other identifiers are reserved. If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.

¶3 If the program removes (with #undef) any macro definition of an identifier in the first group listed above, the behavior is undefined.

184) The list of reserved identifiers with external linkage includes math_errhandling, setjmp, va_copy, and va_end.

Previous editions of the standard used very similar wording for the equivalent set of restrictions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top