Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > dereference precedence

Reply
Thread Tools

dereference precedence

 
 
Toni
Guest
Posts: n/a
 
      04-13-2006
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
 
Reply With Quote
 
 
 
 
Abdo Haji-Ali
Guest
Posts: n/a
 
      04-13-2006

> 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

> Thanks,

Welcome..

Abdo Haji-Ali
Programmer
In|Framez

 
Reply With Quote
 
 
 
 
Abdo Haji-Ali
Guest
Posts: n/a
 
      04-13-2006
> >
> > (*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


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

Abdo Haji-Ali
Programmer
In|Framez

 
Reply With Quote
 
Toni
Guest
Posts: n/a
 
      04-13-2006
En/na Abdo Haji-Ali ha escrit:
>>> (*a)->b

>> No, if this is the case then * has a higher precedence that -> which
>> contradict what you said above.


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
 
Reply With Quote
 
Bill Pursell
Guest
Posts: n/a
 
      04-13-2006
Abdo Haji-Ali wrote:
> > 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


(*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);

}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dereference Adaptor Matthias Kaeppler C++ 3 02-28-2005 05:42 PM
How does dereference operator overloading really work? Joe Seigh C++ 18 09-22-2003 05:42 PM
NULL Pointer Dereference Denis Palmeiro C Programming 10 07-16-2003 12:33 PM
Re: how to properly dereference STL list item Howard C++ 0 07-01-2003 05:46 PM
Re: how to properly dereference STL list item Jakob Bieling C++ 0 07-01-2003 05:45 PM



Advertisments