Is allocating a dynamic array without specifying size well formed code?
Posted
by
Als
on Stack Overflow
See other posts from Stack Overflow
or by Als
Published on 2012-03-20T05:24:08Z
Indexed on
2012/03/20
5:29 UTC
Read the original article
Hit count: 171
The following simple program snippet gives compilation errorswith gcc-4.3.4
.
Program:
int main()
{
char *ptr = new char[10];
char *ptr1 = new char[];
return 0;
}
Compilation errors:
prog.cpp: In function ‘int main()’:
prog.cpp:4: error: expected primary-expression before ‘]’ token
prog.cpp:3: warning: unused variable ‘ptr’
prog.cpp:4: warning: unused variable ‘ptr1’
But the same compiles cleanly with MSVC without any diagnostic message.
So my question is:
Does the Standard allow an new []
to be called without specifying the size
? Or this a bug in MSVC?
Can someone provide a reference from the standard which will conclusively say that the above code example is ill-formed or well-formed?
I have had a look at:
5.3.4 New [expr.new] &
18.4.1.2 Array forms [lib.new.delete.array]
but couldnt find any conclusive evidence about the behavior.
© Stack Overflow or respective owner