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]

question about operator priority


hi all,

This is a quesiton about priority of operator in c, I
have a simple program:

#include <stdio.h>

main()
{
        int i = 1;
        i = i + ++i;
        printf("%d\n",i);
}

the result is 4 in my redhat 7.3, I think the compiler
first get the result of ++i, because ++ have high
priority than +, so the result is right.

However, after above code is changed to:

#include <stdio.h>

main()
{
        int i = 1;
        i = i + i + ++i;
        printf("%d\n",i);
}

The result is still 4. If compiler think ++ has higher
priority, it should do it in blow sequence:

++i; /* the value of i should be 2 now */
i + i +i; /* the result should be 6 */


but this time the result is not my expected.

Is this problem is because my wrong concept about c or
it is a bug of c compiler?


Thanks,

Yongming


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


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