Problems with ?: operator
Sulabh Nangalia
sulabh.nangalia@gmail.com
Thu Dec 15 08:03:00 GMT 2005
hi,
while compiling the following code on gcc v3.3 compiler (on mac os x),
i got the "invalid lvalue asignment" error as expected in the
following code:
main(){
int a = 1;
a < 10 ? a = 5 : a = 7;
return;
}
but i didn't get any error in
15 < 10 ? a = 5 : a = 7;
and
a < 10 ? a : a = 7;
5 < 10 ? a = 5 : a = 7; is giving error
15 < 10 ? a = 5 : a = 7; is not giving any error
why?
i am compiling using the following command:
$ cc -ansi -O0 file.c
all the syntaxes are wrong according to the ansi C grammar given in
"The C Programming Language" by Kernighan & Ritchie. then how come the
other 2 expressions are not giving compilation error.
when compiled on VC++, none of the expressions is giving error.
--
SULABH NANGALIA
Computer Science Engineer
Avisere
Mobile: +91 98300 29360
More information about the Gcc
mailing list