This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A simple question on expression
- To: Jie Zhang <jzhang916 at sina dot com>
- Subject: Re: A simple question on expression
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Fri, 31 Aug 2001 11:16:32 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <3B8F3B41.40900@sina.com>
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
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