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]
Other format: [Raw text]

Re: Some confuse about the pass of the arguments by gcc


On 22 February 2012 19:05, James Courtier-Dutton <james.dutton@gmail.com> wrote:
> 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;
>>>> }
>

Send button fired accidentally before I had finished.

 I am not 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;
      int tmp1, tmp2, tmp3, tmp4;
      tmp1 = ++a+c;
      tmp2 = a+c;
      printf("%d %d\n",tmp1, tmp2);
      tmp3 = ++b;
      tmp4 = b;
   printf("%d %d\n", tmp3, tmp4);
   return 0;
}


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