Re: why use -> (not .) with pointers?
- From: Alan Balmer <albalmer@xxxxxxx>
- Date: Thu, 30 Jun 2005 11:41:49 -0700
On Thu, 30 Jun 2005 17:41:15 GMT, CBFalconer <cbfalconer@xxxxxxxxx>
wrote:
>jacob navia wrote:
>> Felix Kater wrote:
>>>
>>> when accessing the variables in a struct: What's the reason why
>>> in C newline you have -> and . instead of only . ? Are there
>>> cases in which the compiler couldn't figure out what to do?
>>
>> I think the answer is NO, there aren't any reasons why the
>> distinction exists since the compiler can always figure it out.
>>
>> 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.
>
>It's a convenience, because of the relative operator precedence.
>It is easier and clearer to write:
>
> structxp->fieldf
>than
> (*structxp).fieldf
I think the OP was proposing that you could write
structxp.fieldf
even when structxp was a pointer to a struct. It's true that the
compiler knows whether the dereference is required, but imo it doesn't
fit with C philosophy (and don't ask me to define that ;-)
--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@xxxxxxx
.
- Follow-Ups:
- Re: why use -> (not .) with pointers?
- From: Clint Olsen
- Re: why use -> (not .) with pointers?
- References:
- why use -> (not .) with pointers?
- From: Felix Kater
- Re: why use -> (not .) with pointers?
- From: jacob navia
- Re: why use -> (not .) with pointers?
- From: CBFalconer
- why use -> (not .) with pointers?
- Prev by Date: Re: why use -> (not .) with pointers?
- Next by Date: Re: How to make binary data portable?
- Previous by thread: Re: why use -> (not .) with pointers?
- Next by thread: Re: why use -> (not .) with pointers?
- Index(es):
Relevant Pages
|