This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Initialization with new[]
- To: zvyagin at gams dot ihep dot su
- Subject: Re: Initialization with new[]
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Thu, 4 Nov 1999 23:15:20 +0100
- CC: gcc-bugs at gcc dot gnu dot org, oliva at lsd dot ic dot unicamp dot br, nathan at cs dot bris dot ac dot uk
- References: <Pine.LNX.3.96.991104202346.584C-100000@gams.ihep.su>
> I thought that 'new T[n] (arg list)' was gcc extension (useful!). I read
> that there are only technical limitations on using this synatx. Is it
> right?
I think this is the case. gcc -pedantic says, on Alexey's revised
example:
a.cc:11: warning: ANSI C++ forbids declaration `main' with no type
a.cc: In function `int main()':
a.cc:12: warning: initialization in array new
a.cc:15: warning: initialization in array new
I question whether that extension is particularly useful, though.
Especially in the case of an integer array, there is a clean
standard-conforming solution: write a loop, assigning each element.
It is absolutely portable, and it is as efficient as anything the
compiler could come up with.
Regards,
Martin