Article View: comp.std.c++
Article #4010Re: Draft Std. C++ Preprocessor
From: Steve Clamage
Date: Fri, 12 Apr 1996 16:25
Date: Fri, 12 Apr 1996 16:25
65 lines
4264 bytes
4264 bytes
In article 0804961108400001@news.aimnet.com, mike_duigou@fwb.com (Mike Duigou) writes: >While reading parts of the April 1995 draft I noticed that the section on >preprocessing seemed to be pretty much the same as the ANSI C >preprocessor. Was there a concious descision to make no changes? Yes. The intent is to make preprocessing behave exactly the same way, except of course for the predefined macros __STDC__ and __cplusplus. It is hoped that eventually the preprocessor can be eliminated. The presence of the preprocessor makes code analysis very difficult for programs and for humans. Macros are dangerous for numerous reasons. Conditional compilation in practice turns out to make code less understandable and less maintainable than other techniques that do not depend on preprocessing. In principle, an "include" directive could be added to the language proper, eliminating the need for #include. Few indeed are the preprocessor functions that cannot be achieved equally well in the C++ language proper already. (Realistically, we probably cannot eliminate the preprocessor. But we don't have to encourage its use.) >One change I was hoping for was the inclusion >of a non-fatal "#warning" directive to match the fatal '#error" directive. >(hey, the compiler can make both errors and warnings, why can't I?). As >you probably know, a number of compilers support the #warning directive. We've been through this discussion many times. The #error directive isn't required to be fatal. All that is required is that it cause a message to be emitted. It is difficult to specify "fatal" versus "non-fatal" in a system-independent way. For example, I assume you mean that an #error directive should prevent the program from being linked or run, since the failure would occur at compile time. But what about a pure interpreter? The program could be already executing when the #error directive was encountered. We don't like to require things in the standard that make it impossible to have conforming implementations that would be otherwise useful. Adding non-standard directives like #warning is not very programmer- friendly. The #pragma mechanism exists precisely as a hook to add special behavior without causing compile failures on systems that don't have the facility. Implementors who want to add a programmer warning facility would be better advised to make it "#pragma warning". >Additionally, adding some reccomended pragmas such as ... There is no end to things that might be nice. "Recommending" something in the standard has no real meaning. Either that something is required, in which case you can depend on it being available, or it is not required, in which case you cannot depend on it being available. Pragmas, in my view, are best used for things which do not affect program semantics. "Pragma warning" is an example of such a pragma. "Pragma once" is an example of a pragma which does affect the meaning of a program, and can cause compile failures when the code is moved to a system that doesn't support it. Worse still (IMHO) are pragmas that change meaning without affecting legality. Your code then inexplicably behaves differently on different systems. --- Steve Clamage, stephen.clamage@eng.sun.com --- [ comp.std.c++ is moderated. To submit articles: try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ] [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ] [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Technical Details
Message-ID:
<4klsr0$ii4@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<mike_duigou-0804961108400001@news.aimnet.com>Show Full Headers
Complete Article Headers
From: clamage@Eng.Sun.COM (Steve Clamage) Message-ID: <4klsr0$ii4@engnews1.Eng.Sun.COM> X-Original-Date: 12 Apr 1996 15:28:32 GMT Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 12 Apr 96 16:25:37 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Draft Std. C++ Preprocessor Organization: Sun Microsystems Inc. References: <mike_duigou-0804961108400001@news.aimnet.com> Reply-To: clamage@Eng.Sun.COM X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMW6EEOEDnX0m9pzZAQHJggF/Qnb0IthCPYg5CsJPzUn5+Qz6dnwgo1kI EqQcqjyMre5nUM1m4zaPvXyEse/0ynTS =OELN