1

Parentheses and pointer symbol have same priority, and they are dealed from left to right. Why does the following code try to get the member nfct from skb, then do the type conversion? It's seems that the associativity is from right to left.

(struct nf_conn *) skb->nfct 
2
  • 2
    It is not the parenthesis here but a cast, which has lower precedence than -> Commented Nov 7, 2017 at 8:18
  • Not strictly related to your question since this is a cast and not a parenthesized expression; but "Parentheses and pointer symbol have same priority" is not correct. Parenthesized expression is a primary expression, which is one step higher priority than -> which is postfix operator.
    – user694733
    Commented Nov 7, 2017 at 8:36

1 Answer 1

3

I believe the point you're missing here is the Operator Precedence.

The pointer member access operator (->) has higher precedence than the cast.

To elaborate, (borrowed wordings)

  • Operator precedence determines which operator is performed first in an expression with more than one operators with different precedence.
  • Associativity is used (or comes into play) when two operators of same precedence appear in an expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.