delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/23/00:47:31

Newsgroups: comp.os.msdos.djgpp
From: abostick AT netcom DOT com (Alan Bostick)
Subject: Re: New to djgpp -- curious compilation problem
Message-ID: <abostickE4FK5A.Ky5@netcom.com>
Organization: Arrogant Opinions 'R' Us
References: <abostickE4BLn0 DOT 5EE AT netcom DOT com> <32E5E865 DOT 57FF AT Mathematik DOT tu-chemnitz DOT de>
Date: Wed, 22 Jan 1997 22:07:58 GMT
Lines: 55
Sender: abostick AT netcom19 DOT netcom DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Robert Hoehne <Robert DOT Hoehne AT Mathematik DOT tu-chemnitz DOT de> writes:

>Alan Bostick wrote:
>> 
>> have discovered, when compiling his examples, that djgpp chokes on the
>> following construction:
>>         enum Boolean {false = 0, true};
>It is not DJGPP but gcc which complains the above. The reason: 'false'
>and
>'true' are reserved words in gcc of the new type 'bool'. If you realy
>want
>to declare your own Boolean type, use any other (not reserved) words.
>But I
>think the better way is to use the 'bool' type, because it is stored as
>a single byte but an 'enum' is stored (mostly) as an int (4 bytes).

It's not that I *want* to declare my own Boolean type; it's just that
the sample code that goes with Stanley Lippman's otherwise excellent
C++ PRIMER declares that type all over the place.  It's a bit of a hassle,
don't you know, to have to re-edit the sources to ensure compliance with
the new language definition.

As I mentioned, the code compiled just fine under GCC v2.5.8 under SunOS;
it only bombed under v2.7.2.1 .

There are other places where Lippman uses obsolete constructions.  For
example, he frequently uses an old scoping for for-loop variables:

	for (int ix=0; ix < size; ix++)
	{
		/* blah blah blah */
	}
	for (ix=0;  ix < size; ix++)
	{
		/* etc. etc. etc. */
	}

GCC v2.7.2.1 thinks the scope of ix applies only within the first loop's
statement block, issuing a warning about using an obsolete scoping. Either
ix should be declared outside both loops, or redeclared in the second one,
in direct contradiction to Lippman's discussion of for-loop scoping on 
p.141 of the 2nd edition.

Reminder:  *I am not calling this a bug in GNU CC or djgpp!*  I'm only 
observing how the evolution of the definition of C++ makes writing a textbook
a job of trying to hit a moving target.  People trying to learn the language
sometimes have to do some detective work to discover why their textbook-legal
code won't compile or behaves peculiarly. (So nu -- I still use the original,
pre-ANSI edition of Kerhighan and Ritchie. ;-) )

-- 
Alan Bostick               | To achieve harmony in bad taste is the height
mailto:abostick AT netcom DOT com | of elegance.
news:alt.grelb             |      Jean Genet
http://www.alumni.caltech.edu/~abostick

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019