Problems with ?: operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux