Skip to main content
gamedev.net
🔒 Locked

Compiler error ?

Started by carl404 1 reply 450+ views
Original Post
carl404
carl404
Hello! By accident I wrote this line: char *test = (char *) new char[10,10]; Compiler (VC 6.0, GCC) was able to compile it, the result was allocation of 10 bytes. Why did it happend ? It should be discovered as parse error during compilation.
Illco
Illco
Quote:

It should be discovered as parse error during compilation.

No it shouldn't. C++ has a comma expression which allows you to do this. The value of the expression is, I think, the last in the list (otherwise the first).
10 == 1,2,3,4,5,6,7,8,9,10

This is a valid expression and is also true. In your example the cast is superfluous btw.

Its use is when some of the expressions's evaluations have side effects such as:
unsigned int s = 0;while( cin >> i, i > 0 )  s += i;


Illco
carl404
carl404
You are right :) I've forgot about this. Thanks for help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.