On 22 February 2012 19:05, James Courtier-Dutton <james.dut...@gmail.com> wrote:
> On 22 February 2012 13:34, 嘉谟 <yxy....@gmail.com> wrote:
>> 2012/2/22 James Courtier-Dutton <james.dut...@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;
}

Reply via email to