Do you have to cast void pointers when dereferencing them?

Wade Guthrie evil at arcturus.UUCP
Sat Dec 17 07:48:32 AEST 1988


In article <15012 at mimsy.UUCP>, chris at mimsy.UUCP (Chris Torek) writes:
> >    struct junk J;
> >    void  *p;
> >    p = &J;
> 
> The assignment `p = &J' (uncast) is legal dpANS C.  

Correct me if I'm wrong (on this net was THAT an unnecessary statement :-)),
but this seems to indicate that the dpANS performs implicit type
conversions for pointers.  

(To clarify my, often, imprecice terminology: given the following:

	int foo;
	float bar, fubar;

	fubar = foo + bar;

I call the cast of foo to a float (which is not done explicitly by the
programmer) along with the possible cast of both of these to double
(not necessarily in that order) an implicit type conversion)

My assumption (about the dbANS) comes from the understanding that
different pointers can have different representations (on some machines).
To say that pointer_of_one_type = pointer_of_another_type is legal, the
code must know the type of the lvalue to put the rvalue into the proper
representation.  Is this not true?


Wade Guthrie
Rockwell International
Anaheim, CA

(Rockwell doesn't necessarily believe / stand by what I'm saying; how could
they when *I* don't even know what I'm talking about???)



More information about the Comp.lang.c mailing list