🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3218

Re: #ifdef XXXX

#3218
From: Fergus Henderson
Date: Sat, 03 Feb 1996 04:43
54 lines
2258 bytes
marek@iiasa.ac.at (Marek  MAKOWSKI) writes:

>Would not it be sensible to add to the preprocessing a directive
>that would stop processing the current file ?

I don't think it would be very useful.

>Something like
>
>#ifdef XXXX
>#exit
>
>this would safe processing (sometimes very long) file in the common
>situations:
>
>#ifdef XXXX
>// a (possibly) long header file hear
>#endif  /* ifdef XXXX*/

There is one situation in which this is very common: headers that
are guarded against multiple inclusion:

	#ifndef FOO_H
	#define FOO_H
	... code for foo.h ...
	#endif

With your proposal, this could be rewritten as

	#ifdef FOO_H
	#exit
	#endif
	#define FOO_H
	... code for foo.h ...

However, implementations can (and some do) optimize the processing of
files using the standard guard technique so that they are only read
when necessary.  This optimization actually improves performance more
than your `#exit' would, because it avoids even opening the file the
second and subsequent times.

`#exit' is not necessary for performance; adding `#exit' would not improve
performance for already existing code; and use of `#exit' would require
four preprocessor directives to guard include files rather than the three
required by the standard guard idiom.  So I think adding `#exit' would be
a bad idea.

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9602020740.22411@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <1996Feb1.092058.4745@iiasa.ac.at>

Show Full Headers
Complete Article Headers
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Message-ID: <9602020740.22411@mulga.cs.mu.OZ.AU>
X-Original-Date: Fri, 2 Feb 1996 18:40:50 +1100
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 03 Feb 96 04:43:34 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: #ifdef XXXX 
Organization: Computer Science, University of Melbourne, Australia
References: <1996Feb1.092058.4745@iiasa.ac.at>
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMRLoA+EDnX0m9pzZAQFXDwGAkf7rkyUiF0uE9bfttCEJbeumqyePcSLe
 QQD4Lk2HXGcbQekih+Km8Pt+2mVthRKK
 =dqH9