This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Some confuse about the pass of the arguments by gcc
- From: James Courtier-Dutton <james dot dutton at gmail dot com>
- To: åè <yxy dot 716 at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 22 Feb 2012 19:05:39 +0000
- Subject: Re: Some confuse about the pass of the arguments by gcc
- Authentication-results: mr.google.com; spf=pass (google.com: domain of james.dutton@gmail.com designates 10.229.137.85 as permitted sender) smtp.mail=james.dutton@gmail.com; dkim=pass header.i=james.dutton@gmail.com
- References: <CA+fE_MS_mk81miNq-qe5UenzgfqRKb+mDrXpjt0OfP0q2uifOQ@mail.gmail.com> <CAAMvbhEfabd2-TwWkfW88iX=h8y_FXstdA9friSk+WLnUvFejw@mail.gmail.com> <CA+fE_MQs3eHBkPH5pJ2zP+Ju7oa3OCCKp3q4hv7Lo6mMjY_g5g@mail.gmail.com>
On 22 February 2012 13:34, åè <yxy.716@gmail.com> wrote:
> 2012/2/22 James Courtier-Dutton <james.dutton@gmail.com>:
>> The order that function parameters are evaluated is undefined. Therefore it
>> is wise to ensure that no matter what order they are evaluated, the result
>> should be the same. It is the ++ that breaks it in this case. Didn't you get
>> a compiler warning?
>
> Yes you are right. gcc -Wall indeed get the warning.
> operation on 'a' may be undefined [-Wsequence-point]
>
> Thanks Âfor you reminder.
> Let me know ,If we want the result we want ,we should do the precision
> logic design .
>>> #include <stdio.h>
>>> int main(int argc , char *argv[]){
>>> int a=3;
>>> int b=3;
>>> int c=3;
>>> printf("%d %d\n",++a+c,a+c);
>>> printf("%d %d\n",++b,b);
>>> return 0;
>>> }
I sure exactly what you are asking for, but a version of the above
that will be portable and defined is:
#include <stdio.h>
int main(int argc , char *argv[]){
int a=3;
int b=3;
int c=3;
printf("%d %d\n",++a+c,a+c);
printf("%d %d\n",++b,b);
return 0;
}