[H-GEN] g++/egcs peculiarity
Craig Eldershaw
ce at comlab.ox.ac.uk
Thu May 14 13:49:53 EDT 1998
>> int *first=new int(5); // create an int
>> int *second=new int[10](5); // create 10 ints
>>
>> myclass *one=new myclass(1,2); // create a myclass
>> myclass *two=new myclass[10](1,2); // create 10 myclasses
>Stroustrup, The C++ Programming Language, Section r.5.3.3, pg 499.
>...
Good point Andrae (note to self: rtfm ! :-)
I actually checked the egcs www page, its FAQ and the last month or so
of bug reports - but not the text (*bonk*). though admittedly there is
(last I heard) no formal ANSI standard as yet - just a draft.
>i.e. what you did with the int there wasn't correct C++ at the time the
>book was written.
First reaction is why *not* allow it ? Second thought is "Oh yeah,
Stroustrap hates C-style arrays".
I assumed that g++ passed it OK, so it must be right. But I guess that
(a) the standard is still draft, and (b) gcc has allowed non-standard
things in the past.
>Granted this reference was current May 1991 so there's plenty of time
>for it to change.
The 3rd edition (1997) of Stroustrup doesn't say one way or another
(they dropped the nice reference section).
>crash.cc:13: warning: initialization in array new
But is seems odd that (a) egcs (a later derivitive of g++) is less
flexible than its ancestor; (b) that it issues a warning rather
than an error in some cases; and (c) it actually works correctly (ie.
the initialisation tests out OK) for the 'int *second=new int[10](5);'
line.
Craig.
----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe
More information about the General
mailing list