void*

karl at haddock karl at haddock
Sat Aug 16 07:41:00 AEST 1986


alice!bs (Bjarne Stroustrup) writes:
>In addition, the draft ANSI C proposal allows uncasted assignment of a void*
>to a non-void pointer. This, I consider to be an unnecessary weakening of C's
>type system; in the long run it will become a rather serious nuiscance.

I agree that this is a bad idea; I'm glad to hear that C++ disallows it.  If
you don't want to cast the result of malloc(), it's easy to hide it in macros
(I've been doing it for years):
	#define new(type)       ((type *)malloc(sizeof(type)))
	#define nnew(n, type)   ((type *)malloc((n)*sizeof(type)))
This does restrict "type" to something you can add "*" to, though.

Having said that, I'll now point out that X3J11 draft 01-May-1986 does say in
5.5 (Common Warnings), "[An implementation may generate a warning if] an
implicit narrowing conversion is encountered, such as the assignment of ...
a pointer to void to a pointer to any type of object other than char."  This
implies that such an uncasted assignment should be avoided, at least.

Karl W. Z. Heuer (ihnp4!ima!haddock!karl), The Walking Lint



More information about the Comp.lang.c mailing list