Do you have to cast void pointers when dereferencing them?

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Dec 15 10:58:50 AEST 1988


In article <2414 at ssc-vax.UUCP> dmg at ssc-vax.UUCP (David Geary) writes:
>  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?

Many older UNIX compilers will accept pointer to almost anything
in the context p->member_name, if the member_name has an unambiguous
structure offset.  Indeed, really old UNIX kernels (around 6th
Edition) relied heavily on this.

It's not currently legal to use anything other than a pointer to
a structure declared as having such a member_name in that context.
This applies even more strongly for void*, which has only a small
subset of permitted operations, definitely not including structure
member reference.

So, yes, write your code to say what you really mean.



More information about the Comp.lang.c mailing list