dereference precedence

T

Toni

Hi, This has probably debated here before but I could not find it in Google.

Though I don't have the standard at hand I've seen several references
point that operator -> has higher precedence than unary * (dereference).

Then I would always have thought that

*a->b

Is equivalent to

(*a)->b

but apparently it should be

*(a->b)

Which which is right and why?

Thanks,

Toni
 
A

Abdo Haji-Ali

Though I don't have the standard at hand I've seen several references
point that operator -> has higher precedence than unary * (dereference).
That's right...
Then I would always have thought that

*a->b

Is equivalent to

(*a)->b
No, if this is the case then * has a higher precedence that -> which
contradict what you said above.
Also this is meaningless, it should be (*a).b
but apparently it should be

*(a->b)

Which which is right and why?
The second one
Welcome..

Abdo Haji-Ali
Programmer
In|Framez
 
A

Abdo Haji-Ali

No, if this is the case then * has a higher precedence that -> which
contradict what you said above.
Also this is meaningless, it should be (*a).b

Silly me, I just assumed that 'a' is a one-level pointer, which is not
necessarily... Sorry

Abdo Haji-Ali
Programmer
In|Framez
 
T

Toni

En/na Abdo Haji-Ali ha escrit:
This is just what I thought, it was just one of those occasions where
the feelings contradict the logic. As (nearly) always the logic turns
out to be right.

Thanks

Toni
 
B

Bill Pursell

Abdo said:
That's right...

No, if this is the case then * has a higher precedence that -> which
contradict what you said above.
Also this is meaningless, it should be (*a).b

(*a)->b is not necessarily meaningless.

#include <stdio.h>

int
main(void)
{
struct foo {
int b;
} c[1];

struct foo *a[1];

c[0].b = 3;
a[0] = c;

printf("%d\n", (*a)->b);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top