Bad assumptions

Bad assumptions make your code nonportable. For example, don't assume that:

Additionally, here are a few points to remember when writing your program:

Pointers and integers are not interchangeable. Neither is guaranteed to hold the other.

Use void* if you want an untyped pointer, not char*. Pointer arithmetic can't be done using void* pointers; instead, use a typed pointer (char* for bytes).

Processor portability
To illustrate portability problems, consider the MIPS R4000. This processor has 64-bit integers and 64-bit pointers. Future PowerPC chips will also support
64 bits. However, it's not clear whether a C compiler will make long or int 64 bits.
Other machines can also have large pointers (theoretically up to 48 bits on the 80386) but with 32-bit integers.

Long double is an inherently nonportable data type and can vary in size and precision from processor to processor. It is guaranteed to hold any number a float or double can hold, but that's about all you can count on (for example, many RISC processors don't support any IEEE extended-precision format). Therefore, longdouble is suitable only for in-memory computations, not for data storage or network transmission. What's more, a longdouble is sometimes implemented in software and is therefore slower on some platforms.

Don't make assumptions about memory alignment because of variations between processors and compilers. Here are some common problems with alignment:

NOTE Avoid problems like this by ordering the data members in descending order of size to minimize alignment problems (both space and speed) on
most architectures.

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker