🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Article for comp.std.c++: Eliminating #ifdef: if const

#3345
From: Shankar Unni
Date: Mon, 19 Feb 1996 23:16
52 lines
2561 bytes
Mark Russell (M.T.Russell@ukc.ac.uk) wrote:

> Here's an idea I had for a non-preprocessor replacement for #if and  #ifdef.
> 	if const (<expr>) { <stuff> }

> `if const' is a compile time version of `if'.  <expr> is a constant
> expression which is convertible to bool.  If it yields true, <stuff>
> is processed as normal.  Otherwise <stuff> is parsed into tokens, but
> ignored except for counting { and } nesting.  <stuff> is anything that
> can appear inside a namespace block.  `if const' does not introduce a
> new scope.

No dice.

Often, an #ifdef covers just a small part of an expression that may be
different between different environments, or some such small differences:

   if (some condition) {
#ifdef SOMEIMPL
	if (some other condition) {
#endif /* SOMEIMPL */
	/* code */
	/* code */
	/* code */
#ifdef SOMEIMPL
	}
#endif /* SOMEIMPL */
   }

Duplicating all the code so that each half is precisely correct in its {}
matching is both tedious and error-prone (trying to verify that both parts
of the expression are fixed).

Also, the #ifdefs serve a purpose in pointing out the fact that this piece
of code is system-dependent.  The syntax you propose hides its warts rather
too well, and make it easy for a reader to miss the significant piece of
information that this area of code is system-dependent.

On the other hand, I'd really like to see function-like macros eased out
of usage..
--
Shankar Unni				E-Mail:	shankar@sgi.com
Silicon Graphics Inc.			Phone:	+1-415-933-2072
URL:	http://reality.sgi.com/employees/shankar


[ To submit articles: Try just posting with your newsreader.  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: <4gb0a4$sa3@fido.asd.sgi.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <199602160807.IAA06126@condor.ukc.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: shankar@mti.mti.sgi.com (Shankar Unni)
Newsgroups: comp.std.c++
Subject: Re: Article for comp.std.c++: Eliminating #ifdef: if const
Date: 19 Feb 1996 23:16:39 GMT
Organization: Silicon Graphics, Inc., Mountain View, CA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4gb0a4$sa3@fido.asd.sgi.com>
References: <199602160807.IAA06126@condor.ukc.ac.uk>
Reply-To: shankar@engr.sgi.com
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: boris.mti.sgi.com
X-Newsreader: TIN [version 1.2 PL2]
Content-Length: 1543
X-Lines: 45
Originator: clamage@taumet