Re: why use -> (not .) with pointers?
- From: Lew Pitcher <Lew.Pitcher@xxxxxx>
- Date: Thu, 30 Jun 2005 12:19:37 -0400
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
lawrence.jones@xxxxxxx wrote:
> Felix Kater <f.kater2@xxxxxxx> wrote:
>
>>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?
>
>
> Not anymore. But back in the dark ages, C was much less concerned about
> types than it is today and would allow pretty much *anything* as the
> left operand of . or ->. In that environment, the compiler couldn't
> figure out what to do, so having two different operators was essential.
Nonsense.
Even K&R (1st Edition) admits that the -> notation is 'syntactic sugar' (my
terms). The actual quote from "The C Programming Language" is
"...pointers to structures are so frequently used that the -> notation is
provided as a convenient shorthand."
This, in reference to an example of the use of pointers to structures, which
points out that, given
struct date {
int day;
int month;
int year;
int yearday;
char mon_name[4];
};
and
struct date *pd;
then
pd->year
is exactly the same as
(*pd).year
- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFCxBuYagVFX4UWr64RAt02AKCZe0YXskg4oZ+UrPYPXmqtyTHXhgCg5uRk
W0SnNGl1N0ZayPZGkQC+qrs=
=Ckpm
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: why use -> (not .) with pointers?
- From: Tydr Schnubbis
- Re: why use -> (not .) with pointers?
- From: Tydr Schnubbis
- Re: why use -> (not .) with pointers?
- References:
- why use -> (not .) with pointers?
- From: Felix Kater
- Re: why use -> (not .) with pointers?
- From: lawrence . jones
- why use -> (not .) with pointers?
- Prev by Date: Re: why use -> (not .) with pointers?
- Next by Date: Re: why use -> (not .) with pointers?
- Previous by thread: Re: why use -> (not .) with pointers?
- Next by thread: Re: why use -> (not .) with pointers?
- Index(es):
Relevant Pages
|
|