...
Data Type | iAPX86 | IA-32 | IA-64 | SPARC-64 | ARM-32 | Alpha | 64-bit Linux, FreeBSD, |
|---|---|---|---|---|---|---|---|
| 8 | 8 | 8 | 8 | 8 | 8 | 8 |
| 16 | 16 | 16 | 16 | 16 | 16 | 16 |
| 16 | 32 | 32 | 32 | 32 | 32 | 32 |
| 32 | 32 | 32 | 64 | 32 | 64 | 64 |
| N/A | 64 | 64 | 64 | 64 | 64 | 64 |
pointerPointer | 16/32 | 32 | 64 | 64 | 32 | 64 | 64 |
Code frequently embeds assumptions about data models. For example, some code bases require pointer and long to have the same size, while other large code bases require int and long to be the same size [van de Voort 2007]. These types of assumptions, while common, make the code difficult to port and make the ports error prone. One solution is to avoid any implementation-defined behavior. However, this practice can result in inefficient code. Another solution is to include either static or runtime assertions near any platform-specific assumptions, so they can be easily detected and corrected during porting.
...
Smallest Types | signed | unsigned |
|---|---|---|
8 bits |
|
|
16 bits |
|
|
32 bits |
|
|
64 bits |
|
|
Fastest Types | signed | unsigned |
8 bits |
|
|
16 bits |
|
|
32 bits |
|
|
64 bits |
|
|
Largest Types | signed | unsigned |
maximumMaximum |
|
|
Additional types may be supported by an implementation, such as int8_t, a type of exactly 8 bits, and uintptr_t, a type large enough to hold a converted void * if such an integer exists in the implementation.
...
This compliant solution uses the correct format for the type being used.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
FILE *fp;
int x;
/* Initialize fp */
if (fscanf(fp, "%d", &x) < 1) {
/* handle error */
}
|
...
This noncompliant code attempts to guarantee that all bits of a multiplication of two unsigned int values are retained by performing arithmetic in the type unsigned long. This practice works for some platforms, such as 64-bit Linux, but fails for others, such as 64-bit Microsoft Windows.
...