Do you have to cast void pointers when dereferencing them?

David Geary dmg at ssc-vax.UUCP
Wed Dec 14 04:52:38 AEST 1988


  struct junk { int   x,y; };
  struct funk { float f,z; }; 

  main()
  {
    struct junk J;
    struct funk F;
    void  *p;

    J.x = 10,  J.y = 20;
    F.f = 4.2, F.z = 5.6;

    p = &J, printf("JUNK:  %d %d\n", p->x, p->y);

    p = &F, printf("FUNK:  %f %f\n", p->f, p->z);
}

  This runs just fine on my Sun, but gives me illegal
pointer WARNINGS.  Under ANSI C, do I HAVE to cast
my void pointer, or not?

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ David Geary, Boeing Aerospace,               ~ 
~ #define    Seattle     RAIN                  ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.lang.c mailing list