Newsgroups: | comp.compilers,comp.human-factors |
From: | beshers@hks.com |
Organization: | HKS, Inc. |
Date: | Thu, 24 Sep 1992 13:53:54 GMT |
Keywords: | C, parse, syntax |
References: | 92-09-048 92-09-157 |
moss@cs.umass.edu writes:
>I second the view that ifdef is not a good idea, primarily in that C style
>macro processing, at and below the level of tokens, is even more dangerous
>and disruptive than a good comment mechanism. One can get by reasonably
>well without a C style preprocessor (as is done in Modula-3) or with
>macros that have more syntactic robustness (as in Lisp).
Jim Cathey writes:
# I for one appreciate the hell out of cpp, because it allows me to maintain
# _one_ source for many slightly different environments. ...
I agree that when one *must* deal with different CPUs and OSs ifdef's work
better than comments because the changes must occur frequently. I try to
limit the use of ifdef's to this purpose in my code and use either single
line comments (reasons explained by others) for all other purposes.
# Moderator writes:
#[Many in the C++ crowd claim that "const" declarations in combination with
#in-line functions and sensible optimization of "if" statements that depend on
>onstants give you nearly everything CPP does without the aggravation of C's
#two-level syntax. -John]
Alas, this technique does not take care of structures which depend on
types defined in header files...
Finally, I would like to point out that many #ifdefs I have seen in
practice are actually required because so man parts of C were not fully
and carefully defined. Having experienced the portability implied by a
formally specified language (SML) I tend to back the use of "constants"
and "if" statements because syntactic and type correctness should always
be correct---even if the code is never used.
The use of #ifdefs for CPU and OS dependencies should be strictly limited
to a very small number of files where such things must be considered.
George Beshers
beshers@hks.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.