473,387 Members | 1,904 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,387 software developers and data experts.

late night confusion with -> and .

I heard a few times, and may have repeated thoughtlessly, that p->m is
in a way a shorthand for (*p).m
The standard doesn't seem to have a notion of this; this also sounds
downright wrong if p is a pointer to a volatile type.
How common is this misconception?
--
Thanks,
Ark
Jan 22 '08 #1
8 1200
Ark Khasin <ak*****@macroexpressions.comwrites:
I heard a few times, and may have repeated thoughtlessly, that p->m is
in a way a shorthand for (*p).m
The standard doesn't seem to have a notion of this; this also sounds
downright wrong if p is a pointer to a volatile type.
How common is this misconception?
I certainly have this misconception.

I don't immediately see the distinction you're making. Can you
explain further?
--
Ben Pfaff
http://benpfaff.org
Jan 22 '08 #2
Ben Pfaff wrote:
Ark Khasin <ak*****@macroexpressions.comwrites:
>I heard a few times, and may have repeated thoughtlessly, that p->m is
in a way a shorthand for (*p).m
The standard doesn't seem to have a notion of this; this also sounds
downright wrong if p is a pointer to a volatile type.
How common is this misconception?

I certainly have this misconception.

I don't immediately see the distinction you're making. Can you
explain further?
volatile T *p;
(*p) - as in (*p).m - requires actually reading *p, which in turn may
affect the content of *p. p->m only affects the member m.
--
Ark
Jan 22 '08 #3
Ark Khasin wrote:
Ben Pfaff wrote:
>Ark Khasin <ak*****@macroexpressions.comwrites:
>>I heard a few times, and may have repeated thoughtlessly, that p->m is
in a way a shorthand for (*p).m
The standard doesn't seem to have a notion of this; this also sounds
downright wrong if p is a pointer to a volatile type.
How common is this misconception?

I certainly have this misconception.

I don't immediately see the distinction you're making. Can you
explain further?
volatile T *p;
(*p) - as in (*p).m - requires actually reading *p, which in turn may
affect the content of *p. p->m only affects the member m.
And now I am confused even more.
volatile struct T s;
"Natural" s.m requires evaluation (read) of s, doesn't it?
Should I write (&s)->m so as to leave other members unaffected?
--
Ark
Jan 22 '08 #4
Ark Khasin <akha...@macroexpressions.comwrote:
I heard a few times, and may have repeated thoughtlessly,
that p->m is in a way a shorthand for (*p).m
They are potentially distinct in C++ since one can overload
operators. But that does not apply in C.
The standard doesn't seem to have a notion of this;
The definitions of these operators seem to, at face value,
imply that relationship. There's even a non-normative
footnote that says (&E)->m is E->m if &E is valid.
this also sounds downright wrong if p is a pointer to a
volatile type.
What difference would that make?
How common is this misconception?
You've yet to demonstrate that it actually is a misconception.

--
Peter
Jan 22 '08 #5
Peter Nilsson wrote:
Ark Khasin <akha...@macroexpressions.comwrote:
>I heard a few times, and may have repeated thoughtlessly,
that p->m is in a way a shorthand for (*p).m
They are potentially distinct in C++ since one can overload
operators. But that does not apply in C.
>The standard doesn't seem to have a notion of this;
The definitions of these operators seem to, at face value,
imply that relationship. There's even a non-normative
footnote that says (&E)->m is E->m if &E is valid.
>this also sounds downright wrong if p is a pointer to a
volatile type.
What difference would that make?
>How common is this misconception?
You've yet to demonstrate that it actually is a misconception.

--
Peter
Indeed, thank you for pointing out the Footnote 79) If &E is a valid
pointer expression (where & is the ‘‘address-of ’’ operator, which
generates a pointer to its operand), the expression (&E)->MOS is the
same as E.MOS.
I honestly don't know how to read it: an expression has a value and side
effects. No-one argues with the values part. It's the side effects that
bother me...
--
Ark

Jan 22 '08 #6
On Jan 21, 8:47*pm, Ark Khasin <akha...@macroexpressions.comwrote:
I heard a few times, and may have repeated thoughtlessly, that p->m is
in a way a shorthand for (*p).m
The standard doesn't seem to have a notion of this; this also sounds
downright wrong if p is a pointer to a volatile type.
If you have an object, and you want to change a member, then it is:
p.m = foo;

If you have a pointer to an object, and you want to change a member,
then it is either:
p->m = foo;
Or:
(*p).m = foo;

Nobody uses the second form. Everyone uses the first form. I don't
know why it came out that way, but if you write (*p).m you will get
raised eyebrows, even though they are totally equivalent expressions.

How common is this misconception?
Really, really rare.
Jan 22 '08 #7

"Ark Khasin" <ak*****@macroexpressions.comwrote in message
news:17flj.6261$YH6.4468@trndny03...
Ben Pfaff wrote:
>Ark Khasin <ak*****@macroexpressions.comwrites:
>>I heard a few times, and may have repeated thoughtlessly, that p->m is
in a way a shorthand for (*p).m
The standard doesn't seem to have a notion of this; this also sounds
downright wrong if p is a pointer to a volatile type.
How common is this misconception?

I certainly have this misconception.

I don't immediately see the distinction you're making. Can you
explain further?
volatile T *p;
(*p) - as in (*p).m - requires actually reading *p, which in turn may
affect the content of *p. p->m only affects the member m.
*p by itself may well involve reading *p, but it is followed by .m and is
also an lvalue and you may find that the internal workings of the compiler
will insert an implicit & in there which will cancel the *.

Similarly, when writing:

a=b

It clearly does not fetch the value of a. The compiler may (I'm guessing)
treat it as:

*(&a) = b

so no loading of a's value occurs, only it's address.

Bart
Jan 22 '08 #8
Jack Klein <ja*******@spamcop.netwrites:
On Tue, 22 Jan 2008 04:06:36 -0800 (PST), "christian.bau"
<ch***********@cbau.wanadoo.co.ukwrote in comp.lang.c:
>In one language, an lvalue-to-rvalue conversion takes place, which
accesses *uart_receive. In the other language, no such conversion
takes place, and there is no access.

You are just plain wrong about this. In both languages the lvalue to
rvalue conversion is performed.
C does not have a conversion called an lvalue-to-rvalue
conversion. C++ does (ISO 14882:1998 clause 4.2
"Lvalue-to-rvalue conversion"). This is probably the distinction
that Christian is making.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
Jan 23 '08 #9

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

Similar topics

1
by: Jeremy Moles | last post by:
class BaseClass: def __init__(self): self.__data = None def getMember(self): return self.__data class GoodSubClass(BaseClass): def __init__(self): BaseClass.__init__(self)
5
by: Nick Stansbury | last post by:
Hi, Sorry for the obscure title but I'm afraid I can't think of a better way to describe what happened to one of my clerks last night. The guy was working late, made a series of changes (accross a...
13
by: Mike MacSween | last post by:
I'm doing this: strAccessPath = SysCmd(acSysCmdAccessDir) & "msaccess.exe" in a vb executable to do what it looks like. If I remove the reference to the access object library this seems to...
14
by: Composer | last post by:
I've read many postings about the problem of Access.References.IsBroken and the consensus seems to be that late binding is the cure-all. I have a very complex Access application that needs...
9
by: Zlatko Matić | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws...
96
by: QuantumG | last post by:
Back in 2002, Harry H. Cheng wrote: > Agreed. gcc is a C compiler for different platforms. > VC++ is a C/C++ compiler for Windows. > SCC is a C compiler for Cray machine. > Ch is an embeddable...
8
by: scorpion53061 | last post by:
I am sorry for this but I am not getting an answer elsewhere so I thought I would try here. It seems the safer way to go prior to deployment is to change my early binding to late binding to...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
13
by: Wayne | last post by:
I have just experienced my first late paying client. By "late" I mean that the invoice is now almost 2 months overdue. I don't think that the client is maliciously withholding payment - rather...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.