K
kj
It is my understanding that the subscripting operation has higher
precedence than the direct or indirect selection operation. This
means that an expression like, for example,
s.m[1]
gets parsed as if it were written
s.(m[1])
But the last expression can't possibly make sense, because the
parenthesized subexpression evaluates to data, not to something
like a struct (or union) field.
Therefore, it looks like the compiler has two choices when it comes
across s.m[1]: either be completely correct, and generate an error
whenever it comes across something like s.m[1], or else use some
"common sense" and parse it as (s.m)[1], which at least has some
hope of being correct.
A similar conundrum exists with expressions like
s->t.m
because direct selection (.) has higher precedence than indirect
selection (->). According to the precedence rules, s->t.m should
be equivalent to s->(t.m), but this is nonsensical. In contrast,
the interpretation (s->t).m at least could make sense, but it
violates precedence rules.
I suppose that all of the above could be correct, but it sounds
screwy... What am I missing?
kynn
precedence than the direct or indirect selection operation. This
means that an expression like, for example,
s.m[1]
gets parsed as if it were written
s.(m[1])
But the last expression can't possibly make sense, because the
parenthesized subexpression evaluates to data, not to something
like a struct (or union) field.
Therefore, it looks like the compiler has two choices when it comes
across s.m[1]: either be completely correct, and generate an error
whenever it comes across something like s.m[1], or else use some
"common sense" and parse it as (s.m)[1], which at least has some
hope of being correct.
A similar conundrum exists with expressions like
s->t.m
because direct selection (.) has higher precedence than indirect
selection (->). According to the precedence rules, s->t.m should
be equivalent to s->(t.m), but this is nonsensical. In contrast,
the interpretation (s->t).m at least could make sense, but it
violates precedence rules.
I suppose that all of the above could be correct, but it sounds
screwy... What am I missing?
kynn