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

Why do we need "->"?

I often change my mind (sometimes back and forth several times) about
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?

I've read dmr's article on the history and development of C, and he
talks about a time when "foo->bar" would compile almost regardless of
the type of "foo", with "->bar" just meaning "add a certain offset and
dereference a value of a given type". (Does this mean it wasn't
possible to use the same member name in more than one structure type,
at least for members at different offsets?) Anyway, though, if it was
just a question of backwards compatibility at some point, they could
have deprecated "->" while adding new functionality to ".". So: Is
there a good reason that I'm missing, or is it just that somebody
thought it was a good idea for the programmer to have to make the
difference between pointers and values explicit on every reference?
Because it seems like syntactic salt to me.

Jul 23 '07 #1
3 1679
no**********@gmail.com wrote:
I often change my mind (sometimes back and forth several times) about
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?
We just had a long thread on this, look it up.

Brian
Jul 23 '07 #2
On Jul 23, 2:19 am, "Default User" <defaultuse...@yahoo.comwrote:
not.here....@gmail.com wrote:
I often change my mind (sometimes back and forth several times) about
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?

We just had a long thread on this, look it up.

Brian
I was puzzled when I saw this, because a short while ago I checked for
such, without success. But I looked again, and found the thread...
started by me. I thought Google Groups hadn't posted my message, but
in fact it was only delayed by a few hours. Apologies!

Jul 23 '07 #3
no**********@gmail.com wrote, On 23/07/07 07:56:

<snip>
I was puzzled when I saw this, because a short while ago I checked for
such, without success. But I looked again, and found the thread...
started by me. I thought Google Groups hadn't posted my message, but
in fact it was only delayed by a few hours. Apologies!
With news groups you have to wait at least a day before assuming things
have gone wrong.
--
Flash Gordon
Jul 24 '07 #4

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

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
2
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
5
by: comp.lang.php | last post by:
$orderBy = 's.app_date desc, s.last_name asc, s.first_name asc, s.mi asc'; if ($_REQUEST) { $ascArray = array('asc' => 'desc', 'desc' => 'asc'); // ARRAY OF ALL ORDERING POSSIBILITIES $junk =...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
2
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
5
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
2
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.