C++: variable length arrays and operator new[]
Ian Lance Taylor
iant@google.com
Mon Sep 21 21:56:00 GMT 2009
Florian Weimer <fw@deneb.enyo.de> writes:
> G++ currently accepts the following code:
>
> char *
> alloc(unsigned a, unsigned b)
> {
> typedef char array[a];
> return &**(new array[b]);
> }
>
> Is this intentional? The equivalent "new char[a][b]" is rejected (as
> required by the C++ standard).
Is there any reason that g++ should reject your sample program?
Because of the existence of operator new[], "new char[a][b]" quite a bit
harder to understand than your code is.
Ian
More information about the Gcc
mailing list