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]

Re: A simple question on expression


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


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