Addressing struct without ->

Wolfram Roesler wolfram at cip-s02.informatik.rwth-aachen.de
Fri Feb 1 22:24:36 AEST 1991


NIBMSCM at NDSUVM1.BITNET writes:


>  In working with some of the more common 'C' packages, I've found
>one limiting factor that seems to come back and haunt me.  In working
>with some other languages, such as Pascal, I had the capability to use
>the 'using' keyword, giving the address of a structure and then address
>the elements of that structure without the necessity of using the
>ptr->element notation (could simply use element).

You can't get the same thing in C without getting ABSOLUTELY incompatible.
You can however use the preprocessor trick to avoid long chains of -> and .
in the following way:

#define X ptr->fooptr->foo.bar.bar.baz.foobar->foobaz.x

and now write 

	X->something

instead of (well you know what).

I'm not sure if the following will work:

struct
{
  int foo;
  int bar;
} xyz;
#define foo xyz.foo
#define bar xyz.bar



More information about the Comp.lang.c mailing list