const void *

Karl Heuer karl at haddock.ISC.COM
Sat Apr 30 08:41:37 AEST 1988


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

Should say: All conversions between (any *) and (void *), with arbitrary type
qualifiers on either, are legal operations; but converting from const to non-
-const or from (void *) to any pointer type other than (void *) or (char *),
except by means of an explicit cast, is a Common Warning.

Does say: Something too restrictive, as Dennis has pointed out.  Has this been
resolved yet, Doug?

>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 *"?

Probably to avoid the Common Warning.  The compiler doesn't know that the
result of malloc is maximally aligned; (void *) generally isn't.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list