This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problems with ?: operator


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]