There are two different questions here. The first is for void
, and the second for void*
. They are different types, and have little in common beside the name.
void
is used mainly for function declarations/definitions (as the return type or to mean "takes no arguments"). You can't ever possibly have an object of type void
. Ever. So it's hard to see a need to find out the size of that nonexistent object. GCC's behavior is nonstandard, and an intentional extension. However, I believe they chose sizeof(void) == 1
because the C++ standard requires every object to take at least one byte of space.
void*
means "pointer to real data, but without the relevant type information." It is entirely possible to have void*
; and you will run into them, a lot. However, because the type information is ignored you can't manipulate the pointer much. This is by design, because if you don't know what you have you really don't know what you can do with it.
But if you want to treat the memory as a collection of bytes then char*
does that. A char
is one byte, everywhere. A string of bytes is a char*
. If you find this weird, use byte*
(where you define byte
as something like unsigned char
).