This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: linux libio status



> 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++.






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]