|
Excellent treatment of C++, however, I discovered an
error in the author's treatment of little endian
platforms. The following code example proves that
the code example on page 449 is incorrect for most 32
bit little endian platforms including intel, which is
specified in the list of little-endian platforms on
page 448. I have known very few pieces of hardware
using the rather exotic scheme described in the book.
endian.c:
#include <stdio.h>
int main() {
int i;
int fourbyteint;
char *ptr;
fourbyteint = 0x11223344;
ptr = &fourbyteint;
for( i = 0; i < sizeof( int ); i++ ) {
printf( "%02x ", (0xff & ptr[i]) );
}
printf( "\n" );
}
On little endian machines which are >16 bit,
the output will be
44 33 22 11
and on big endian machines, the output will be
11 22 33 44
|