Dont Use Reserved Names

In C and C++, there is a long list of names (and some name-patterns) which are reserved by the C/C++ standards for compiler implementors and standard libraries implementors.

Some names may be implemented as normal functions, #define macros, or recognized in special ways by the compiler... for example, strlen could be all three. A C compiler might in-line special code for strlen when optimization is turned on, but when optimization is turned off, strlen might be a macro that conditionally calls __cstrlen. If used without #including the correct header, then strlen would be a function call to a function named strlen.

Since #define does not respect scope, and since any reserved name could be implemented using a #define, you can't easily use reserved names as identifiers in your code -- this means local variable names, method names, etc...

Since remembering all the reserved names and naming patterns is difficult, use mixed case names when you are programming in C and C++, or trailing underscores. One or two underscores in the beginning of a name constitutes two of the reserved naming patterns.


I once had a weird problem, where a C++ method named abort would not compile in one of two compilers. Turned out that abort is reserved -- it is a function prototyped in stdlib.h for one compiler, and #defined in the header for the other compiler.


CategoryCpp


EditText of this page (last edited June 10, 2003) or FindPage with title or text search