-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 30.08.2012 19:49, schrieb Garrett Hartshaw:
no, at least for C "void" is a type, too.
The void type comprises an empty set of values; it is an
incomplete object type that cannot be completed.
so "void*" says pointer to void. This is not "nothing" or
"unknown", in that sense void is not much different from "struct
nix" when you never actually define "struct nix" somewhere. It
behaves a bit different in terms of implicit conversions, sure, but
the sematic is the same.
A "void*" pointer is not "an uninitialized" memory region. It may
well already be initialized.
As Keith said, that was meant to be how it should be used, rather than
exactly what it means to the compiler.
But I am really surprised about this strong need of opaque pointer
in C++. If we follow the basic ideas of C++ such a usage should be
very rare in C++, no? Isn't that what "abstract base classes" have
been invented for?
Therefore I had my question that came afterward and that you seem
to have overlooked:
The naming of "char" (and the two others) certainly doesn't cover
all its uses that these type nowadays have, and it would be good to
find semantic names for the different use cases.
typedef char byte_t; // for the minimal addressable
storage unit typedef unsigned char bitX_t; // for an arbitrary
collection of unspecific data, usually X == 8 typedef unsigned char
uintX_t; // for use as small unsigned integer, usually X == 8
typedef signed char intX_t; // for use as small signed
integer, usually X == 8
Jens
One of the major uses of typedef is to allow this kind of
disambiguation between types that are represented identically. While I
don't often have need to work low-level directly on bytes, if I did I
would not hesitate to create a byte_t typedef, and if it was already
included in the standard, so much the better (although I would
probably typedef it as 'unsigned char' to avoid the
implementation-defined signed-ness of plain 'char').
However, even if 'byte_t' were added to the standard, I would still
want to distinguish between 'byte_t *' (used as a pointer to a byte)
and 'void *' (used as an opaque pointer or a pointer to uninitialized
memory) *even if they both meant the same thing to the compiler*.
Granted it would better for 'memcpy' and friends to use 'byte_t *'
rather than 'void *', as their underlying functionality is specified
in terms of moving/copying bytes. 'void *' would still be required *in
C* as the return value of 'malloc' (unitialized memory) and for use as
a userData parameter in callbacks (opaque pointer to an object of
unspecified type). There is little use for 'void *' in pure C++ code,
but it would still be required in the language to interface with C code.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJQQBxQAAoJEP8JewLaHvzSQJ0H+gNUnCggPWCdrovjjEDnANY0
mL2/5I+R+Ckn7sMYDWmdc6jhxQPcfoKX7aHT9C2DV1MWRfigMb4z0rsKqcc+WjUY
FJXEjLtlv9H+IHHuypXWNqVAPm7HgpXq74L/yhv2H2IlJqra6DW58ULdWRm6DUSN
xHijMzGpuNIw7LE3zzilinJfvP26+pxXZDuFmWXs2pCAPXgikZS1AG9PQWnVWXLz
DXDZ7nejxIc8FIesNfxO3NLzzMVZ69ZhyfB4M6UwCD2TdeRdrAYay5f3sEHKtIvG
N2RXXXV+J36ZX4w0i6dQuuCuAHzBaPwBcvtW79nIzgAv5pqlCDA4kuMl8WF1Y4s=
=SUbB
-----END PGP SIGNATURE-----