Using #define to "extend" C
Walter Bright
bright at Data-IO.COM
Sat Sep 9 06:36:38 AEST 1989
In article <1461 at atanasoff.cs.iastate.edu> hascall at atanasoff.cs.iastate.edu.UUCP (John Hascall) writes:
< While we are on the subject of loops, how do people feel about the
< practice of using #define to "extend" the language? For example:
< #define loop for (;;)
< #define exitloop break
Please do yourself and us all a favor and don't do this because:
1. Simple C program analyzers (like cb and indent) won't work on it.
2. Error messages from the C compiler will be in terms of C, not your
language.
3. After you get comfortable with C, you will no longer regard C syntax
idioms as a legibility problem.
4. You will seriously impair your ability to read other people's code, and
other people's ability to read yours.
5. Most programmers will treat your code as if they would be struck blind
if they looked at it.
6. Since C is not entirely consistent in how {}, ;, and expressions are
handled, your #defines could cause unintended flow-of-control bugs that
only become apparent if you examine the preprocessor output.
7. This was thrashed about in this newsgroup years ago, and the consensus
was it is a bad idea.
Expend your energies instead on an appropriate identifier naming convention,
and on commenting your algorithms.
More information about the Comp.lang.c
mailing list