Some confuse about the pass of the arguments by gcc
James Courtier-Dutton
james.dutton@gmail.com
Wed Feb 22 19:09:00 GMT 2012
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;
}
More information about the Gcc
mailing list