From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Buck To: seebs@monolith.solon.com (Peter Seebach) Cc: egcs@cygnus.com Subject: Re: linux libio status Date: Wed, 15 Oct 1997 20:16:00 -0000 Message-id: <199710151855.LAA23996@atrus.synopsys.com> References: <199710151419.JAA20162@monolith.solon.com> X-SW-Source: 1997-10/msg00616.html > It would have been a little easier if C89 had ruled that NULL must > actually have pointer type, then you could just use it for anything > that would be taking arguments as (void *), and, if you're feeling > courageous and not-quite-perfectly-portable, you could just use it > for all the pointers... The problem is that C didn't think out this pointer stuff well enough. The main breakage was to say that (void *) can be assigned to any pointer type. But that confuses several types of pointers together into one mishmash. There are certain distinguished pointer types not directly reflected in the language: -- the null pointer -- a "maximally aligned" pointer, as returned by malloc Such objects can be legally assigned to any pointer type. Then there is another beast, the pointer to unknown data object. We can't say anything about its alignment. The problem is that C decided to make all of these beasts (void *) and permit free casting. What if there were a new type, aligned_pointer_t. malloc would return one of these. We can safely convert an aligned_pointer to any type of pointer, so no cast is needed. Any cast in the reverse direction would be system-dependent, so a cast is needed. Similarly, any pointer can be converted to void *, but neither C nor C++ would allow conversion of (void *) to another type of pointer without a cast. Then NULL could be (aligned_pointer_t)0, and this could work in C or C++.