Connect with Expertise | Find Experts, Get Answers, Share Insights

The "->" operator

Jeff Rodriguez
 
Posts: n/a
#1: Nov 13 '05
What does this do? I've been looking online and I've seen mention that it exists
as well as examples to it's use but still no explination as to exactly what it does.

TFTH,
Jeff

Les Cargill
 
Posts: n/a
#2: Nov 13 '05

re: The "->" operator


Jeff Rodriguez wrote:[color=blue]
>
> What does this do? I've been looking online and I've seen mention that it exists
> as well as examples to it's use but still no explination as to exactly what it does.
>
> TFTH,
> Jeff[/color]

It's a struct dereference by pointer.

struct V a;
struct V *b;

b = &a;

a.<something> and b-><something> are now exactly the same thing.

--
Les Cargill
Jeff Rodriguez
 
Posts: n/a
#3: Nov 13 '05

re: The "->" operator


Les Cargill wrote:
[color=blue]
> Jeff Rodriguez wrote:
>[color=green]
>>What does this do? I've been looking online and I've seen mention that it exists
>>as well as examples to it's use but still no explination as to exactly what it does.
>>
>>TFTH,
>>Jeff[/color]
>
>
> It's a struct dereference by pointer.
>
> struct V a;
> struct V *b;
>
> b = &a;
>
> a.<something> and b-><something> are now exactly the same thing.
>
> --
> Les Cargill[/color]
Easy enough!

Thank you much.

Jeff
Ben Pfaff
 
Posts: n/a
#4: Nov 13 '05

re: The "->" operator


Jeff Rodriguez <newsgroup1@gurugeek.EXAMPLENOSPAM.com> writes:
[color=blue]
> What does this do? I've been looking online and I've seen mention that
> it exists as well as examples to it's use but still no explination as
> to exactly what it does.[/color]

The -> operator dereferences its left operand, then accesses one
of the members of the referenced object (which must be of
structure or union type). a->b is equivalent to (*a).b. The ->
operator is simply there to reduce the need for parentheses in
accessing a structure member through a pointer.
--
Here's a tip: null pointers don't have to be *dull* pointers!
Lew Pitcher
 
Posts: n/a
#5: Nov 13 '05

re: The "->" operator


Jeff Rodriguez wrote:
[color=blue]
> What does this do? I've been looking online and I've seen mention that
> it exists as well as examples to it's use but still no explination as to
> exactly what it does.[/color]

The -> operator is a structure element pointer dereference operator. It
takes a pointer to a structure on the left and a membername on the right,
and results in the value of the member of the structure as pointed to by the
pointer.

In other words, assuming something defined like

struct { int number } *pointer;

then

pointer->number

is a shortform for

(*pointer).number

That's it.

--
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)

Dan Pop
 
Posts: n/a
#6: Nov 13 '05

re: The "->" operator


In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <newsgroup1@gurugeek.EXAMPLENOSPAM.com> writes:
[color=blue]
>What does this do? I've been looking online and I've seen mention that it exists
>as well as examples to it's use but still no explination as to exactly what it does.[/color]

What does your favourite C book say about it?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
I.M.A Troll
 
Posts: n/a
#7: Nov 13 '05

re: The "->" operator


Dan Pop wrote:[color=blue]
> In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <newsgroup1@gurugeek.EXAMPLENOSPAM.com> writes:
>
>[color=green]
>>What does this do? I've been looking online and I've seen mention that it exists
>>as well as examples to it's use but still no explination as to exactly what it does.[/color]
>
>
> What does your favourite C book say about it?
>
> Dan[/color]

Dan, it wasn't necessary to lapse into sarcasm. Why not just follow the
example of the prior respondents and answer the question in a serious
and congenial manner (or refrain from making any reply if the question
has already been answered)? Expertise does not excuse bad manners.

John Bode
 
Posts: n/a
#8: Nov 13 '05

re: The "->" operator


"I.M.A Troll" <troll@email.con> wrote in message news:<3FDC9233.70508@email.con>...[color=blue]
> Dan Pop wrote:[color=green]
> > In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <newsgroup1@gurugeek.EXAMPLENOSPAM.com> writes:
> >
> >[color=darkred]
> >>What does this do? I've been looking online and I've seen mention that it exists
> >>as well as examples to it's use but still no explination as to exactly what it does.[/color]
> >
> >
> > What does your favourite C book say about it?
> >
> > Dan[/color]
>
> Dan, it wasn't necessary to lapse into sarcasm. Why not just follow the
> example of the prior respondents and answer the question in a serious
> and congenial manner (or refrain from making any reply if the question
> has already been answered)? Expertise does not excuse bad manners.[/color]

This could be a sign I've been hanging around c.l.c. too long, but
Dan's answer is perfectly appropriate (if a bit brusque, but that's
part of Dan's charm). Answers to basic questions such as this are
best found in your handy C reference manual, not in an online
newsgroup where there is some delay in getting an answer, and where at
least one of the answers you get will be wrong or useless.

The OP needs to get into the habit of checking his C reference manual
*first*; if he has additional questions, he needs to check out the
FAQ; and then, if he still needs guidance, ask a question here.
Closed Thread