Re: why use -> (not .) with pointers?



Lew Pitcher wrote:
-----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."

I don't think he's talking about the fact that astruct->x is a shorthand for (*astruct).x at all. I think he's just saying that the early compilers used the syntactical difference between astruct->x and astruct.x to decide whether to generate instructions that used indirect, or conversely indirect addressing.
.




Relevant Pages

  • Re: why use -> (not .) with pointers?
    ... P.J. Plauger wrote: ... Not anymore. ... But back in the dark ages, C was much less concerned about ... In that environment, the compiler couldn't ...
    (comp.lang.c)
  • Re: why use -> (not .) with pointers?
    ... Lew Pitcher wrote: ... Not anymore. ... But back in the dark ages, C was much less concerned about ... In that environment, the compiler couldn't ...
    (comp.lang.c)
  • Re: iForth vsn 2.1 released
    ... > That's why there are people like Marcel, who put a lot of effort and ... they don't look like Forth anymore. ... iForth 2.0 does the following: ... > Designing a compiler is always a matter of objectives and choices. ...
    (comp.lang.forth)
  • Re: Gentoo - Rumours of proprietary components
    ... or stage2 tarball are not supported anymore." ... The main reason that I can ... Does that include libc and the compiler? ... I want to use an alternative c compiler, and I might use a different C library. ...
    (comp.os.linux.misc)
  • Re: Cant compile and run newsreader
    ... It is a bug in the compiler triggered by something ... (don't bother of keeping the source code logic, ... - Remove the method implementations until it doesn't AV anymore. ... While you're removing chunks of code compile once in a while to see it ...
    (borland.public.delphi.non-technical)