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





Felix Kater wrote:
> Hi,
>
> 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?
-> is used when you have a pointer to a struct, and you are trying to
access
elements of the struct whose address is stored in the pointer.

.. is used when you have an object of a struct, and you are trying to
access
elements of the struct.

Does that help?

.



Relevant Pages

  • Re: HardBound and SoftBound (was "The State of Software")
    ... I will explain to you one last time that the problem is not whether a compiler can generate checks for all buffer overflows. ... By the way, in the last example of such code that I saw, it had been changed to use the address of the struct, not of the first element of the struct: ... to take address of struct rather than address of first element. ... such tricks are used to create a pointer which is then passed on. ...
    (comp.arch)
  • Re: pointers to struct members
    ... >I just compiled a program that uses linked lists (needed it as an homework ... The compiler diagnostic is not the problem. ... remove_key requires a pointer to pointer to struct as its first ...
    (comp.lang.c)
  • Re: struct and union alignment
    ... >> pointer to a struct, so how else could this have been done? ... > When 6.2.5 discusses the alignment requirements of various types, ... because the compiler is free to do byte loads of ...
    (comp.lang.c)
  • Re: Another spinoza challenge
    ... You should test against the int type's limits: ... typedef struct complex ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: Casting a void * into a 32-bit struct
    ... Actually, this does not tell a compiler to "assume", but rather to ... of type "pointer to UInt32". ... constraints strong enough to enforce "usefulness" of such conversions. ... >sizeof the struct at all. ...
    (comp.lang.c)

Quantcast