C sizes
Paper by khorben on 08/04/2006 15:44:41
Why the fuzz?
If you have the chance to be an experienced C programmer, or otherwise be familiar with the C language definition, you may be aware of this part of the ANSI C standard [1]:
5.2.4.2.1 Sizes of integer types <limits.h>
[#1] The values given below shall be replaced by constant
expressions suitable for use in #if preprocessing
directives. Moreover, except for CHAR_BIT and MB_LEN_MAX,
the following shall be replaced by expressions that have the
same type as would an expression that is an object of the
corresponding type converted according to the integer
promotions. Their implementation-defined values shall be
equal or greater in magnitude (absolute value) to those
shown, with the same sign.
And to be complete:
6.3.1.1 Boolean, characters, and integers
[#1] Every integer type has an integer conversion rank
defined as follows:
-- No two signed integer types shall have the same rank,
even if they have the same representation.
-- The rank of a signed integer type shall be greater than
the rank of any signed integer type with less
precision.
-- The rank of long long int shall be greater than the *
rank of long int, which shall be greater than the rank
of int, which shall be greater than the rank of short
int, which shall be greater than the rank of signed
char.
The last sentence of the first excerpt means, if I am correct, that essential scalar types in C have an undetermined size. They just have to hold at least:
Platform |char |short |long |long |int |float |double|Notes
| | | |long | | | |
ANSI C |8 |16 |32 |64 |16 |32 |64 |
So, what's that all about? Well, these days are critical for applications developers, as more and more hardware can be found with native 64 bits processors. However, such an environment may be new to some developers. So, stay tuned for some
If you have the chance to be an experienced C programmer, or otherwise be familiar with the C language definition, you may be aware of this part of the ANSI C standard [1]:
5.2.4.2.1 Sizes of integer types <limits.h>
[#1] The values given below shall be replaced by constant
expressions suitable for use in #if preprocessing
directives. Moreover, except for CHAR_BIT and MB_LEN_MAX,
the following shall be replaced by expressions that have the
same type as would an expression that is an object of the
corresponding type converted according to the integer
promotions. Their implementation-defined values shall be
equal or greater in magnitude (absolute value) to those
shown, with the same sign.
And to be complete:
6.3.1.1 Boolean, characters, and integers
[#1] Every integer type has an integer conversion rank
defined as follows:
-- No two signed integer types shall have the same rank,
even if they have the same representation.
-- The rank of a signed integer type shall be greater than
the rank of any signed integer type with less
precision.
-- The rank of long long int shall be greater than the *
rank of long int, which shall be greater than the rank
of int, which shall be greater than the rank of short
int, which shall be greater than the rank of signed
char.
The last sentence of the first excerpt means, if I am correct, that essential scalar types in C have an undetermined size. They just have to hold at least:
Platform |char |short |long |long |int |float |double|Notes
| | | |long | | | |
ANSI C |8 |16 |32 |64 |16 |32 |64 |
So, what's that all about? Well, these days are critical for applications developers, as more and more hardware can be found with native 64 bits processors. However, such an environment may be new to some developers. So, stay tuned for some