Re: why use -> (not .) with pointers?
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Thu, 30 Jun 2005 17:41:15 GMT
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
--
Chuck F (cbfalconer@xxxxxxxxx) (cbfalconer@xxxxxxxxxxxxxxxx)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
.
- Follow-Ups:
- Re: why use -> (not .) with pointers?
- From: Alan Balmer
- Re: why use -> (not .) with pointers?
- References:
- why use -> (not .) with pointers?
- From: Felix Kater
- Re: why use -> (not .) with pointers?
- From: jacob navia
- why use -> (not .) with pointers?
- Prev by Date: Re: reading a line through scanf
- Next by Date: Re: why use -> (not .) with pointers?
- Previous by thread: Re: why use -> (not .) with pointers?
- Next by thread: Re: why use -> (not .) with pointers?
- Index(es):
Relevant Pages
|