A simple question on expression
Jakub Jelinek
jakub@redhat.com
Fri Aug 31 02:14:00 GMT 2001
On Fri, Aug 31, 2001 at 03:22:41PM +0800, Jie Zhang wrote:
This list is for development of gcc, this question is more appropriate for
comp.lang.c or other lists.
> I want to ask a simple question on expression.
> Here are some statements:
>
> int a;
> a = 5;
> a = 0?0:a++;
> printf("a = %d\n", a);
>
> a = 5;
> a = (a<4)?0:a++;
> printf("a = %d\n", a);
ISO C requires only one sequence point there (after the control expression
of ?:), but as in neither case this has side effects this is uninteresting
for your question. As a = a++ does not require a sequence point, the side
effects may happen either before assignment or after (that's why you can get
5 (if they happen before) or 6 (if they happen after).
It is purely gcc decision what value you'll get. With gcc3+, you can even
get a warning for this with -Wsequence-point.
Jakub
More information about the Gcc
mailing list