const void *

Andy Fyfe andy at cit-vax.Caltech.Edu
Tue Apr 26 16:05:01 AEST 1988


In article <6214 at cit-vax.Caltech.Edu> andy at cit-vax.UUCP (Andy Fyfe) writes:
>What does (or should?) the ANSI standard say about const void *?

The reason I wondered about this:  Gnu C wants to be follow the rules
according to ANSI.  The current interpretation says that "void *"
is the generic pointer, so it allows
	any *		<-->	void *
	const any *	<-->	void *
and gives warnings for
	const any *	<-->	const void *
	any *		<-->	const void *
("any" here means any type other than "void".)  RMS seems quite willing
to make gcc conform to the rules.

This has so far given me errors under 2 circumstances.  The first occured
when trying to compile Henry Spencer's string functions.  The second occurs
when using function prototypes that use "const void *" (like fwrite, etc.).

As an aside, K&R 2 (section 7.8.5) makes it clear that the pointer returned
by malloc must explicitly be cast to the correct pointer type.  Why is this
required, given that malloc returns a "void *"?
-- 
Andy Fyfe
            andy at csvax.caltech.edu
            wjafyfe at caltech.bitnet
            andy at cit-vax.UUCP	(...!ames!elroy!cit-vax!andy)



More information about the Comp.lang.c mailing list