Mike said:
You never saw "things like this" discussed in a C++
book because C++ is a platform-indepenedent language,
which does not depend upon or specify such platform
details.
This is an interesting point, worthy of expansion. C++ is indeed a
platform independent language, whose specification does a good job of
avoiding platform-specific language details. However, it is not correct
to state that C++ does not depend upon platform details. If one is
writing code with portability in mind, then striving for exactly this
kind of platform independence is a worthy goal. However, the semantics
of any C++ program are entirely dependent on the underlying architecture.
As a trivial example:
int main()
{
unsigned int x = 0xFFFFFFFF;
x++;
if(x == 0)
{
// 32 bit integers, probably.
return 0;
}
else
{
// Some other sized integers, probably.
return 1;
}
}
The above program is legal C++ (and for that matter legal C, but let's
stay on topic here). However, its runtime semantics critically depend
upon the details of its implementation. The language standard may have
nothing much to say about the word length of integers, but the above
program will behave completely differently depending on whether it is
compiled for a 32 bit or a 64 bit architecture.
C++, therefore, can not be regarded as truly platform independent, since
the semantics of quite simple code is entirely dependent on the details
of the implementation. With clever programming, it is often possible to
get around such limitations, but the language doesn't give you this for
free.
Arguably, if the C++ standard really did standardise data types, giving
them well-defined meanings (e.g. int8, unsigned16, ieeefloat, etc.) with
a fully specified semantics, this would make the language *more*
portable. The existing definition is sufficiently wooly that programming
for portability can often be extremely challenging.
Yes, this may be regarded as a little heretical, but I'm not trolling
here -- this is an important issue. I've written more than one C++
library with portability in mind (e.g. the signal/slot library on my web
site, as well as a new lexical analysis/parsing library that I'll
release sometime when I've finally gotten around to finishing its
documentation), and can't say I find C++ terribly helpful in this regard.
Sarah
--
----------------------------------------------
/ __ + / Sarah Thompson **** /
/ (_ _ _ _ |_ / * /
/ __)(_|| (_|| ) / (e-mail address removed) * /
/ + /
http://findatlantis.com/ /
----------------------------------------------