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



Suman wrote:


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?


You didn't answer the question!

>>Are there cases in which the
>>compiler couldn't figure out what to do?

My answer is no. See elsewhere in this thread
.



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: 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)
  • Re: C Struct question
    ... Move the declaration of the struct out of the file screen.c ... When compiling state.c the compiler needs to see the whole ... Thus variable screen is defined to be a pointer to something ... That's why you get this error: 'dereferencing pointer to incomplete type'. ...
    (alt.comp.lang.learn.c-cpp)