Initialization with new[]
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Thu Nov 4 14:17:00 GMT 1999
> 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
More information about the Gcc-bugs
mailing list