<< Openfire 3.3.1 fixes critical Security Issue | Home | Open Archive 1.0.1 for Openfire 3.3.2 released >>

Why the C preprocessor is a bad thing

Christian has posted a follow-up to a discussion on the good old C preprocessor a few years ago. My opinion was (and still is) the C preprocessor is a "feature" hacked into the language to overcome its shortage and is ugly by design.

Nevertheless, as one comment notes it all sums up to "use the right tool for the job". Replacing inline functions and C++ templates by preprocessor macros does not qualify in most cases though there may be situations in which there is no easy to use alternative. One of these situations is making sure a header file is only included once:

#ifndef _STDIO_H
# define _STDIO_H       1
...

#endif /* !_STDIO_H */

This is a common pattern for which I am not aware of a suitable alternative in C land. Fortunately all modern programming languages have introduced other means to solve the problem.

Christian finishes with a link to this very "cool" macro - nothing to add to this one ;)

Tags :


Re: Why the C preprocessor is a bad thing

Thank you for being one of the smartest persons I know.  

Re: Why the C preprocessor is a bad thing

The Big Time Saver: #define while if
The Big Space Saver: #define struct union

Add a comment Send a TrackBack