473,467 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

why use -> (not .) with pointers?

Hi,

when accessing the variables in a struct: What's the reason why in C
you have -> and . instead of only . ? Are there cases in which the
compiler couldn't figure out what to do?

Felix
Nov 15 '05
53 2351
P.J. Plauger <pj*@dinkumware.com> wrote:

Could be. Early C was pretty wild and wooly.


Which makes sense as far as types are concerned since it was derived
from B, which was essentially typeless.

-Larry Jones

We don't ATTEND parties, we just CRASH 'em. -- Calvin
Nov 15 '05 #51
In article <JJ******************@juliett.dax.net>,
Tydr Schnubbis <fa**@address.dude> wrote:
....
Just to make it clear, there are two issues here:

#1) s->x is a shorthand for (*s).x

#2) early compilers used the difference between s->x and s.x to know
whether to generate code using indirect or direct addressing

la************@ugs.com was stating #2 as a fact. Lew Pitcher, thinking
he instead was disputing #1, replied rather harshly. I think everyone
can see that he misread the post he replied to. They are talking about
two different, but related aspects of the C syntax.

I sometimes misread posts, too. But I still haven't had the 'pleasure'
of people supporting me even when I'm wrong. This discussion is getting
a bit childish now, which I'll be the first to admit. ;)


Meta-discussion follows.

The problem with Usenet (as with the world at large) is that 75% of the
traffic is newbies (stupidly) asserting things that are clearly wrong, such
as that (for example), . and -> mean the same thing (which was the implicit
subtext of the original post). So, we spend a lot of time correcting them.

However, with the remaining 25%, which is (or should be - but please accept
this for the sake of discussion) reasonably well-informed people saying
reasonably well-informed things, the problem is that we spend 90% of our
time convincing each other that we're not in the 75%. That the default
assumption is that we are (since most of the posters, taken as a group, are)
is what led to the above misunderstanding.

Nov 15 '05 #52
Kenny McCormack wrote:
The problem with Usenet (as with the world at large) is that 75% of the
traffic is newbies (stupidly) asserting things that are clearly wrong, such
as that (for example), . and -> mean the same thing (which was the implicit
subtext of the original post). So, we spend a lot of time correcting them.

However, with the remaining 25%, which is (or should be - but please accept
this for the sake of discussion) reasonably well-informed people saying
reasonably well-informed things, the problem is that we spend 90% of our
time convincing each other that we're not in the 75%. That the default
assumption is that we are (since most of the posters, taken as a group, are)
is what led to the above misunderstanding.

I'm glad to get some support here. It may well be that my understanding
of the English language is inadequate. But it seems to me the original
poster understands that '.' and '->' have different meanings. It's just
that he's seen other languages that use the dot for both. Like Java,
which uses the dot notation for both reference and value semantics. But
anyway, I bet he's amused to see what he's stirred up...
Nov 15 '05 #53
On 1 Jul 2005 14:36:04 -0700, "Me" <an*****************@yahoo.com>
wrote:
Other languages don't have this problem because you can't
create pointers to pointers and their types are automatically
dereferenced. But these languages have an ambiguity with assignment
(assuming they're imperative languages) so they need a way to
distinguish between reseating a pointer and making a copy of a value.


Explain to me how Ada, which allows pointers to pointers, doesn't
automatically dereference, only used . (not ->), and is an imperative
language, has any ambiguity with assignment (hint: it doesn't).


I think you already explained it yourself. I said in languages that
don't allow pointers to pointers and that automatically dereference
have this ambiguity. I don't really mean ambiguity in a strict sense, I
mean it in that they need a way to distinguish between reseating a
pointer and making a copy somehow. <snip>


I think you've confused yourself with the negatives. It's if you DO
have pointer to pointer and DO automatically dereference -- in
particular, an LHS -- that you (may) have an issue, as in algol.

Ada does have pointer to pointer (under another name) and dereferences
in many cases but not an LHS.

Fortran doesn't have pointer to pointer, and dereferences the pointers
it does have (since F90) everywhere including LHS but uses a distinct
syntax for reseat. C++ dereferences references everywhere but doesn't
reseat at all.

- David.Thompson1 at worldnet.att.net
Nov 15 '05 #54

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

Similar topics

3
by: glen stark | last post by:
Hi all. I'm working with an array of member function pointers (they are all get function of the class Bead). The typedef is: typedef _real (Bead::*_beadGfp)(void); I have a class System...
11
by: Scott Brady Drummonds | last post by:
Hi, everyone, I've checked a couple of on-line resources and am unable to determine how reinterpret_cast<> is different from static_cast<>. They both seem to perform a compile-time casting of...
8
by: maths_fan | last post by:
Can't understand how to overload these operations and for what reason?
3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
13
by: Jon Slaughter | last post by:
I was wondering if there is any big difference(speed/size) when one uses -> vs . as returning a pointer vs a reference. i..e in my code I overload a lot(cause I have many classes) and I can do...
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
2
by: eb | last post by:
I have this working code : foo.h /* nothing */ foo.cpp ... std::vector<std::vector<T * my_T(board_size,board_size) ; for (i=0; i<board_size; i++)
43
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
6
by: gsBytes | last post by:
I am working with a specialized graph class, which has a node class and an edge class. In the node class, there is a list of pointers to each edge. Code that uses the graph must be able to see what...
12
by: eiji.anonremail | last post by:
Hi all, I'm facing some uncertainty with const template arguments. Maybe someone could explain the general strategy. #include <vector> int main(int arc, char** argv) {
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.