Re: 24bit ints (was: [cc65] 24bit addresses)

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-06-18 11:31:33


On Wed, Jun 18, 2003 at 11:22:08AM +0200, Christian Groessler wrote:
> Ups, really?
> I thought, the only thing the standard requires is
> sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long).
>
> Did I miss something?

Yes. The following is from "ISO/IEC 9899:1999 (E), 5.2.4.2.1 Sizes of integer
types <limits.h>":

-----------------------------------------------------------------------------
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.
[...]

-  minimum value for an object of type short int
        SHRT_MIN -32767                 // -(2^15 - 1)
- maximum value for an object of type short int
        SHRT_MAX +32767                 // 2^15 - 1
- maximum value for an object of type unsigned short int
        USHRT_MAX 65535                 // 2^16 - 1
- minimum value for an object of type int
        INT_MIN -32767                  // -(2^15 - 1)
- maximum value for an object of type int
        INT_MAX +32767                  // 2^15 - 1
- maximum value for an object of type unsigned int
        UINT_MAX 65535                  // 2^16 - 1
- minimum value for an object of type long int
        LONG_MIN -2147483647            // -(2^31 - 1)
- maximum value for an object of type long int
        LONG_MAX +2147483647            // 2^31 - 1
- maximum value for an object of type unsigned long int
        ULONG_MAX 4294967295            // 2^32 - 1
-----------------------------------------------------------------------------

This means that any compiler using 8 bit ints, 24 bits longs or similar is not
standards compliant. It does also mean, that portable code can rely on certain
ranges: A variable used to store values between 0 and 100000 needs to be a
long, but you can rely on the fact that this will work in every C
implementation.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-06-18 11:31:41 CEST