Topic: C++0x (discussion of void and void*)


Author: Sean Parent <sparent@Adobe.COM>
Date: Wed, 27 Jun 2001 17:49:01 GMT
Raw View
I think it is important to come up with a solid conceptual model of void and
then be consistent within the language (which I think the current C++ does
fairly well).

void is nothing - So if you have a function with no result it has a
prototype like:

void foo();

void* - a pointer to nothing - it has a size of zero. Nothing can be at any
address - but it still has no size. Because the size is zero, and pointer
arithmetic is based on size not address - you can't do pointer arithmetic.

There are two additional pointer types that people are arguing for:

An anything* - a pointer that can be implicitly cast to any pointer type.

A storage* - a pointer to raw storage, in bytes for which you can do type
arithmetic. The storage type would be a byte.

It seems to me that the concept of void* as a pointer to nothing isn't
particularly useful. You have to interpret it either as an anything* or a
storage* for it to have meaning.

Also, a storage* will eventually need to be cast to a pointer to _something_
so it would be useful to fold the concept of it together with an anything*.

Perhaps, allow an implicit conversion from an anything* to a storage* for
arithmetic operations.

So what should operator new() return? Well it is raw storage, which could be
used to story anything. So make it an anything*.

Instead of introducing an anything* type, how about we use void* since it
isn't of much use as is, we can just revert the interpretation back to the
old K&R. Sure it doesn't have the symmetry that void is nothing and void* is
a pointer to anything but a pointer to nothing isn't of much use.

Yes, my conclusion contradicts my opening paragraph - I was going to pose an
argument to introduce a new anything type, but my own argument changed my
mind.

--
Sean Parent
Sr. Engineering Manager
Adobe Workgroup Services
sparent@adobe.com


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]