compiler construction - C operator precedence -
this question has answer here:
- undefined behavior , sequence points 4 answers
for compiler class, gradually creating pseudo-pascal compiler. does, however, follow same precedence c. being said, in section create prefix , postfix operators, 0 for
int = 1; int b = 2; ++a - b++ - --b + a--
when c returns 1. don't understand how can 1. doing straight prefix first, answer should 2. , doing postfix first, answer should -2. doing left right, zero.
my question is, should precedence of operators return 1?
operator precedence tells example whether ++a - b
means (++a) - b
or ++(a - b)
. should former since latter isn't valid. in implementation it's former (or wouldn't getting result @ all), implemeneted operator precedence correctly.
operator precedence has nothing order in subexpressions evaluated. in fact order in operator operands +
, -
evaluated unspecified in c , code modifies same variable twice without sequence point in between invokes undefined behavior. whichever order choose fine , 0 valid result other value.
Comments
Post a Comment