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 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;
}


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