473,387 Members | 3,801 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.

redirection casting?

Why is this the same:
(*(*pCurrent).pData).name

as this:
pCurrent->pData->name

what is the benefit to the first? if any?
why are the parenthesis important?

thanks
Oct 9 '05 #1
2 1234
dave <sp*****@hotmail.com> wrote:
Why is this the same:
(*(*pCurrent).pData).name

as this:
pCurrent->pData->name
The x->y notation is really shorthand for (*x).y; it was originally used
in C to access members of a struct through a pointer, since passing
structs by value can be expensive. Therefore,

(*pCurrent).pData == pCurrent->pData

Applying this again to pData, we have
(*(*pCurrent).pData).name == (pCurrent->pData)->name
== pCurrent->pData->name

what is the benefit to the first? if any?
why are the parenthesis important?


The parentheses are important because without them, it would be
interpreted as *(pCurrent.pData) which is an error, since pCurrent is a
pointer and pointers cannot have fields; however, (*pCurrent) is the
struct (or class) pointed to by pCurrent, so that is allowed to have a
field named pData.

--
Marcus Kwok
Oct 9 '05 #2
dave wrote:
Why is this the same:
(*(*pCurrent).pData).name

as this:
pCurrent->pData->name

what is the benefit to the first? if any?
why are the parenthesis important?

thanks


The "arrow" operator provides access to the members and methods of a
class or struct, given a pointer to the struct or class instance. The
"." operator provides the same access, given a direct instance of a
struct or class object. Lastly, the dereference operator, *, obtains a
the instance of a struct or class object given a pointer to it.

When these three operators are considered together, it becomes clear
that dereferencing and then applying the period operator to a pointer
is equivalent to applying the arrow operator to that pointer. In other
words:

pCurrent->pData->name

should be equivalent to this:

**pCurrent.pData.name

But it is not. The catch is that the order in which the * and the .
operators are applied to this expression affects the outcome. In fact
the compiler follows a strict "order of precedence" when deciding
whether to apply the * or the . operator first. When evaluating the
above expression the compiler appies the operators in this order:

**pCurrent.pData.name
43 1 2 // <- order of operator evaluation

The problem is that trying to apply the operators in this order, fails.
Instead, the compiler has to alternate between the two . and *
operators in order for this expression to make sense. Since parentheses
have a very high precedence, using them forces the compiler to apply
the operators in the desired order: first the *, then a ., then the
other *, and finally the last . before "name" like so

(*(*pCurrent).pData).name
3 1 2 4

Whether to use the -> or *. operator is largely a matter of preference
in this case. Neither is more efficient or better than the other it
terms of the compiled code.

Greg

Oct 9 '05 #3

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

Similar topics

2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
52
by: Gerard M Foley | last post by:
Can one write a webpage which is not displayed but which simply redirects the user to another page without any action by the user? Sorry if this is simple, but I am sometimes simple myself. ...
15
by: Taki Jeden | last post by:
Hello everybody Does anybody know why w3c validator can not get pages that use 404 htaccess redirection? I set up two web sites so that clients request non-existent urls, but htaccess redirects...
2
by: Nadav | last post by:
Hi, Introduction: *************** I am trying to redirect stdout to a RichEdit control, this is done by initiating a StringWriter, associated it with a StringBuilder and setting the...
0
by: Dimitrios Mpougas | last post by:
Hello, I have two asp.net pages. The first is a page (main.aspx) wich has four links on it. The href value of each link is: href="view.aspx?id=1" traget="_blank" href="view.aspx?id=2"...
8
by: Luciano A. Ferrer | last post by:
Hi! I was following the http://www.seomoz.org/articles/301-redirects.php article, trying to do that with one of my test sites I added this to the .htaccess file: RewriteEngine On RewriteCond...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
1
by: comp.lang.php | last post by:
require_once("/users/ppowell/web/php_global_vars.php"); if ($_GET) { // INITIALIZE VARS $fileID = @fopen("$userPath/xml/redirect.xml", 'r'); $stuff = @fread($fileID,...
4
by: psual | last post by:
hi newbie in web design I got some issue concerning a secure redirection between 2 pages let say I have a page with a grid (the 'master' page) in this grid I can select a record, get its pk...
13
by: Massimo Fabbri | last post by:
Maybe it's a little OT, but I'll give it try anyway.... I was asked to maintain and further develop an already existing small company's web site. I know the golden rule of "eternal" URIs, but...
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:
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
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...
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
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
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.