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>, gcc at gcc dot gnu dot org
- Subject: RE: A simple question on expression
- From: Bernard Dautrevaux <Dautrevaux at microprocess dot com>
- Date: Fri, 31 Aug 2001 11:11:55 +0200
- Cc: Bohdan Vlasyuk <bohdan at kivc dot vstu dot vinnica dot ua>
> -----Original Message-----
> From: Jie Zhang [mailto:jzhang916@sina.com]
> Sent: Friday, August 31, 2001 11:01 AM
> To: gcc@gcc.gnu.org
> Cc: Bohdan Vlasyuk
> Subject: Re: A simple question on expression
>
>
> Thank you for your reply!
>
> But your "obvious" explanation is not satisfiable.
>
> If the following statement
>
> a = (a<4)?0:a++;
>
> can be expanded to
>
> if (a<4)
> a=0;
> else
> a=a++; /* 2 */
>
>
> why
> a = 0?0:a++;
> not be expanded to
>
> if (0)
> a=0;
> else
> a=a++; /* 2 */
>
>
> ps. I have read the K&R yet.
>
Don't worry; this is perfectly normal. [2] is always undefined, in both your
expressions (that are effectively both equivalent to the if statments).
Undefined means that, depending on th ecompiler's goodwill *at the moment*,
a=a++; may be compiled as "a=a" or "a=a+1". When I says *at the moment* that
means that this may change from instruction to instruction (or even from
sub-expression to sub-expression) due to register allocation, instruction
sequencing, pipeline handling or various other optimizations...
So when something is undefined you may egt *varying" results...
Anyway, this is quite off-topic for this list. These kinds of question
should be discussed on a general C programming list.
Regards,
Bernard
--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel: +33 (0) 1 47 68 80 80
Fax: +33 (0) 1 47 88 97 85
e-mail: dautrevaux@microprocess.com
b.dautrevaux@usa.net
--------------------------------------------