473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

dereference precedence

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
Apr 13 '06 #1
4 1746
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

Apr 13 '06 #2
> >
(*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

Apr 13 '06 #3
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
Apr 13 '06 #4
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);

}

Apr 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: noe | last post by:
Hello, I'm writing a file system filter driver and I've found in an example this sentence: if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead )) { return...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
11
by: Rupesh | last post by:
Hello all, See the code .... int i=-3,j=2,k=0,m; m=++i;&&++j||++k; printf ("%d %d %d %d",i,j,k,m); I executed this code on gcc. the o/p i had got is:- -2 3 0 1
25
by: August Karlstrom | last post by:
Hi, Can someone explain the reason for the warning from GCC below: <shell-session> $ cat test.c #include <stdbool.h> bool a, b, c, d;
36
by: Frederick Gotham | last post by:
sizeof has the same precedence as a cast, and they both bind from right to left. The following won't compile for me with gcc: int main(void) { sizeof(double)5; return 0; }
5
by: junky_fellow | last post by:
Hi, I have a very basic doubt about associativity and precedence of operators. I am not a computer science person and may find it quite weird. Consider an expression 4+5*2
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
7
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 5 - Expressions * exercises 5.1 and 5.2 */ #include <iostream>
9
by: Srinu | last post by:
Hi All, We know the following facts, 1. A two dimentional arrays in C is stored similar to a single dimentional array. 2. * is the dereference operator that gives value at address denoted by...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.