Pointer Problems

Rhodri James rmj at tcom.stc.co.uk
Tue Aug 21 03:47:00 AEST 1990


In article <UamezZm00WB0EGzUo0 at andrew.cmu.edu> gh1r+ at andrew.cmu.edu (Gaurang Hirpara) writes:
>
>
>
>I got a variety of solutions, but perhaps I didn't state the problem clearly.
>The form ((StructName *)Something)->x=100 works. 
>However, the format I need is this type:
>
>TopLevel->Secondary->Something->x=100;
>
>i.e. I can't do the casting in the middle of the dereference. It won't let
>me no matter which way I do it. Toplevel contains a pointer to
>Secondary, which contains Something. Something initially points to a
>void *. 

Am I missing something? Shouldn't

  ((StructName *)(TopLevel->Secondary->Something))->x=100;

work? Or if all else fails you can hold the pointer to cast in a
temporary variable of type void *, such as;

   void *Tempthing;
   .
   .
   Tempthing = TopLevel->Secondary->Something;
   ((StructName *)Tempthing)->x=100;

Not very pleasant, I will admit, but it should work

Rhodri

Disclaimer: These ideas are mine, mine, all mine. The company doesn't
know that I think, never mind what I think.
-- 
* Windsinger                 * "Nothing is forgotten..."
* rmj at islay.tcom.stc.co.uk   *                    Mike Whitaker
*     or (occasionally)      * "...except sometimes the words"
* rmj10 at phx.cam.ac.uk        *                    Phil Allcock



More information about the Comp.lang.c mailing list