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



On Thu, 30 Jun 2005 15:21:16 +0200, jacob navia 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?
>>
>> Felix
> I think the answer is NO, there aren't any reasons why
> the distinction exists since the compiler can always
> figure it out.

True.

> If we would always use '.' and there was a pointer, the
> compiler could test if we have instead of a structure,
> a pointer to a structure, then generate a dereferencing of
> the pointer without much trouble.

True.

> The best way to do this is to deprecate '->'
>
> But, helas, this is not going to happen any time soon.

That assumes that this is a sensible and desirable thing to do. It would
make the language syntax marginally simpler, whereas the existing ->
operator highlights the fact that you are using a pointer, which IMO is no
bad thing in C.

Lawrence

.



Relevant Pages

  • Re: Pointer Declaration/Array definition
    ... the pointer. ... fundamental reason the C language *has* to work this way; ... On the other hand, when you write p, the compiler takes the ... The difference between using a pointer and using the array ...
    (comp.lang.c)
  • Re: Function Pointers and NULL/0
    ... >> function pointer type. ... The compiler is required to recognize '0' as ... absolutely no reason for any diagnostic messages in this case. ... >> function pointer equivalent of NULL, i.e. a pointer that is considered ...
    (comp.lang.c)
  • Re: malloc problem
    ... > whatever actual bit values are used for the NULL pointer. ... > the compiler to make it happen. ... I can't any reason at all to use ... Neil Horman ...
    (comp.os.linux.development.apps)
  • Re: why use -> (not .) with pointers?
    ... > Felix Kater wrote: ... >> when accessing the variables in a struct: What's the reason why ... > distinction exists since the compiler can always figure it out. ... and there was a pointer, ...
    (comp.lang.c)
  • Re: why use -> (not .) with pointers?
    ... Felix Kater wrote: ... the distinction exists since the compiler can always figure it out. ... and there was a pointer, ...
    (comp.lang.c)