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



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
.



Relevant Pages

  • Re: How to convert Infix notation to postfix notation
    ... and make all strings const save where the intent ... function whose contract is to change the string. ... the compiler "just" prevents the string ... try to do using the pointer you get. ...
    (comp.lang.c)
  • Re: Confusion about undefined behaviour
    ... but that dereferencing NULL causes undefined behavior. ... While C may not define what happens when you dereference a NULL pointer, ... Since the compiler "knows" that it's compiling for Linux, and it "knows" that dereferencing NULL will cause a trap, it can remove the check, because it can never be false. ... Undefined Behavior is not a guarantee of a crash, ...
    (comp.lang.c)
  • Re: Confusion about undefined behaviour
    ... While C may not define what happens when you dereference a NULL pointer, ... Since the compiler "knows" that it's compiling for Linux, ... "knows" that dereferencing NULL will cause a trap, it can remove the check, ... that the Standard leaves undefined? ...
    (comp.lang.c)
  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>>would clean up a lot of code by eliminating the pointer dereferences. ... >>>guaranteed by the standard and should not be relied on. ... >>>You can try the GNU C compiler available on mingw or cygwin. ... >>>the Constraints are then both operands shall have arithmetic type. ...
    (comp.soft-sys.matlab)
  • Re: Anybody here endure C/Cpp? (.h to .inc conversion)
    ... Pascal or Stdcall convention... ... "PFNGLPOINTPARAMETERFEXTPROC" to be a type that's a pointer to a function ... DWORD, using a 32-bit compiler, with an address in it...adding the ... this is working on the premise that OpenGL does it like most others ...
    (alt.lang.asm)