Addressing struct without ->

Adrian McCarthy adrian at mti.mti.com
Wed Jan 16 05:34:19 AEST 1991


In article <14822 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>... C is not Pascal; it is better. ...

Let's not start that flame war.  The application to be implemented usually
determines which language is best.

>  The whole "using" [Pascal with] approach is insufficiently general, since
> in C different structure types can have the same member names, and often
>do in practical source code.

You can have identically named fields in Pascal records too (some
non-standard compilers don't allow it).  Some older C compilers have
problems with it, too.  Aren't the fields in a struct tm are all prefixed
with tm_ to reduce the chances of a name-space conflict?

What bothers me about x.y and x->y is that I shouldn't *in many cases* have
to worry about whether x is an instance of a struct or a pointer to one.  If
I have a function that works with a struct, and I change my mind about how
to pass that struct into the function (e.g., by value instead of by
reference), it's irritating to have to mindlessly change all the occurences
of x->y to x.y and all of the calls of that function to remove the &'s.  The
mindless stuff should be done by the machine.  In this regard, C constantly
makes you worry about the low-level details when it would be more productive
to think in abstract terms.

Aid.  (adrian at gonzo.mti.com)



More information about the Comp.lang.c mailing list