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 
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
river
  • 694
  • 6
  • 22
  • 2
    It is not the parenthesis here but a cast, which has lower precedence than `->` – Ajay Brahmakshatriya Nov 07 '17 at 08: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 Nov 07 '17 at 08:36

1 Answers1

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.
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261