[Issue 14186] Silent syntax change from C and C++
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Feb 16 03:27:39 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14186
ag0aep6g at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ag0aep6g at gmail.com
--- Comment #1 from ag0aep6g at gmail.com ---
I'm not well-versed in C/C++, but according to these pages:
http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Operator-Precedence
(points 13 and 14)
http://en.cppreference.com/w/cpp/language/operator_precedence#content (point
15)
it's C++ that deviated from C. Whereas D is line with C.
A little test with gcc and g++ seems to confirm that:
----
#include <stdio.h>
int main()
{
int b = 1, c = 1;
1 ? b : c = 0;
printf("%d\n", b);
return 0;
}
----
Compiling with gcc gives
----
test.c: In function ‘main’:
test.c:5:15: error: lvalue required as left operand of assignment
1 ? b : c = 0;
^
----
Compiling with g++ succeeds, and running prints "1".
--
More information about the Digitalmars-d-bugs
mailing list