This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
question about operator priority
- From: Yongming wei <weiyongming2001 at yahoo dot com dot cn>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 31 Dec 2002 23:00:39 -0800 (PST)
- Subject: 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