Operator address with and without parentheses

I came across a kernel patch that added a line func(&(a->b))when it was already func(&a->b). Is there any difference between &a->band &(a->b)?

Please explain.

+4
source share
3 answers

There is no difference, it is only for readability. ->has a higher priority than the link operator &. See here .

To continue this proof, look at the breakdown of these lines:

Some short code

struct A {
   int b;
};

int main() {
   struct A *a; 
   int *c;

   c = &a->b; // Disassemble these lines. 
   c = &(a->b);

   return 1;
}

Dismantling both lines is equivalent to the following:

    movq    -16(%rbp), %rax
    movq    %rax, -8(%rbp)

Try the code here to see for yourself.

+3
source

. ->foo ( foo) , & ( ).

0

There is no difference. The component selection operator ->has higher priority than the unary operator &, so the expression is &a->bparsed as &(a->b), and the result is the address of the member bin the instance that it points to a.

0
source

Source: https://habr.com/ru/post/1611512/


All Articles