Newsgroups: | comp.compilers,comp.human-factors |
From: | fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) |
Organization: | Computer Science, University of Melbourne, Australia |
Date: | Thu, 24 Sep 1992 18:47:48 GMT |
References: | 92-09-048 92-09-157 |
Keywords: | C, parse, syntax |
jimc@tau-ceti.isc-br.com (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. ...
>If this sort of preprocessor mechanism were not already present in C I
>would have had to write one anyway (or use m4?), or face a maintenence
>nightmare. I submit that cpp's presence is one of the reasons that C is
>so strong in the industry.
This is a very good point. How many of the languages that were competing
with C came complete with a macro pre-processor as standard? I think that
you are right in suggesting that cpp is one of the major reasons for C's
success.
>It's a tool that wears well, though, like any tool, it can be abused.
The moderator replies:
>[Many in the C++ crowd claim that "const" declarations in combination with
>in-line functions and sensible optimization of "if" statements that depend on
>constants give you nearly everything CPP does without the aggravation of C's
>two-level syntax. -John]
Unfortunately, "nearly" is the operative word.
#ifdef's are usually used at file scope, rather than in places where a
statement could occur. They often surround code whose very syntax may be
compiler-specific, so the two-level structure is *necessary*, to prevent a
compiler from attempting to parse code it could not possibly understand.
Typical examples such as
#ifdef __GNUC__
#define no_return volatile void
#define no_side_effects const
#else
#define no_return void
#endif
...
INLINE int foo(void) { ... }
#ifdef __TURBOC__
#pragma such-and-such
#endif
#if __GNUC__
#define PLACEMENT_NEW(expression) new { expression }
#else
#define PLACEMENT_NEW(expression) new ( expression )
#endif
... var = PLACEMENT_NEW(address) Type;
are still very common, and I do NOT expect cpp to go away, at least not for
a long while yet.
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.