Re: Conditional compilation sans the cpp

From: Steven T. Hatton (susudata_at_setidava.kushan.aa)
Date: 08/18/04


Date: Wed, 18 Aug 2004 07:43:06 -0400

Karl Heinz Buchegger wrote:

> "Steven T. Hatton" wrote:
>>
>> I've made no secret of the fact that I really dislike the C preprocessor
>> in
>> C++. No aspect of the language has caused me more trouble. No aspect of
>> the language has cause more code I've read to be difficult to understand.
>> I've described it as GOTO's on steroids, and that's what it is!.
>>
>> One argument against abolishing it it that it is useful for conditional
>> compilation when porting code, etc. Well, it seems to me C++ supports
>> that
>> natively. According to TC++PL(SE) §24.3.7.2 if a block of code is
>> bracketted with an if(CONDITION){...} the entire expression is "compiled
>> away" when CONDITION==false.
>
> But it nevertheless runs through the compiler.

It would appear that is the case with g++. I doesn't simply ignore
unreachable code. I know Stroustrup and some others have been playing with
a design for some kind of macro firewall that is supposed to isolate code
from an effects from the preprocessor. But that can't be completely
effective. The CPP is capable of rewriting any code not exclusively
protected, and if you depend on any of the stuff it mangles, all bets are
off.

I fully understand that the CPP has been used to to some great stuff. The
damn thing's been around since the mid 70s or so. It couldn't have
survived this long if it wasn't useful. I probably have most of my major
problems with understanding what it's doing to me under normal
circumstances behind me. OTOH, if Stroustrup has been stung by other
people's macros mangling his code, I'm sure it can and will happen to a
mere mortal like me.

Not only that, but take a look at a translation unit some time. I was in
shock when I saw everything the CPP sucked in to build a tiny little file.
There's got to be a better way!

-- 
STH 
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org  SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org


Relevant Pages

  • Re: Question about Leverage source from Different Projects
    ... conditional preprocessor stuff INSIDE the stdafx.h depending on the project macro defined. ... There is, as far as I can tell, not even a discussion of the .cpp files, just a strange ... #pragma message ...
    (microsoft.public.vc.mfc)
  • Re: Why code completion and early error checking are needed
    ... existing C++ code using the flawed exception mechanism. ... is a good chance there will be means of confining the C preprocessor to the ... There's one significant qualification to that which would ... "There is only One inviolable Law" ...
    (comp.lang.cpp)
  • Re: Cpp Considered Harmful
    ... not bring down the server. ... > library management when finally addressing the preprocessor in the ... regarding the CPP. ...
    (comp.lang.cpp)
  • Re: To bean or not to bean
    ... Qt development begain in 1991, and the first public release was on the 20th ... The preprocessor is the main reason that there is no serious C++ contender ... techniques it supports do not scale to that level of programming. ... and the Cpp than he does. ...
    (comp.lang.cpp)
  • Re: delete comments in .c file
    ... Assuming you have access to the C preprocessor (cpp) you can do a quick hack ... Isolate the file from it's include files and run like, ...
    (comp.lang.c)