* Travis:
Quick question, how is a char * different than any other pointer? I've
never had this really elaborated.
That's not a quick question.
'char' is the smallest addressable unit of memory in C and C++.
First, this means a char* pointer may on some architectures need to be
larger than other data pointers (excluding member data pointers), and in
effect it probably determines the size of void*, which must be large
enough for any data pointer.
Second, it means that char* (or variants signed char* or unsigned char*)
is the pointer type you need to use do byte-level memory addressing,
e.g. for traversing data structures defined at the assembly level or in
file headers.
The above two points are not entirely language-specific. For example,
as I recall in Turbo Pascal you had to use pChar (effectively the same
as C++ char*) in order to do pointer arithmetic, which could not be done
using other pointer types. The C++ properties of char* derive from
general considerations which probably were the same that influenced the
design of Turbo Pascal in this regard.
Apart from that, char* in C++ is a bit more unsafe than other pointer
types because C++ freely converts a literal string to char* instead of
only char const*, for backwards compatibility with C, and because many
old C functions expect char* argument instead of char const*.
Finally, due to the properties of 'char' you can in practice always
safely reinterpret_cast a char* to an (un)signed char* and vice versa,
although this is not directly supported by the standard. You can't do
that in a portable way for e.g. int*, because (disclaimer: this has been
debated infinitely many times without a totally clear and absolutely
convincing conclusion) int allows a trap representation.
Cheers, & hth.,
- Alf