avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] AVR Libc int32_t and uint32_t typedefs are incorrect


From: Georg-Johann Lay
Subject: Re: [avr-gcc-list] AVR Libc int32_t and uint32_t typedefs are incorrect
Date: Wed, 11 Jan 2012 18:11:24 +0100
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Joerg Wunsch schrieb:
"Paul McClean" <address@hidden> wrote:

The standard C does not make *any* claim about the actual number of
bits in an `unsigned long' data type, it only specifies a *minimum*
number of bits (indirectly, by telling a minimal magnitude value for
LONG_MIN, LONG_MAX, and ULONG_MIN, respectively).  Thus, an `unsigned

The C standard says it is implementation defined.

The implementation (AVR backend of GCC) say: long is 32 bits or 16 bits if -mint8 is on.

As avr-libc is only intended to work together with GCC, avr-libc could use built-in macros:

typedef __INT32_TYPE__ int32_t;

or

But for static analysis and checking there is more information exposed by defining like so:

#if __SIZEOF_INT__ == 2
typedef signed long int32_t;
#elif __SIZEOF_INT__ 1
/* -mint8 is on */
typedef signed long long int32_t;
#else
#error ...
#endif

or so:

#if defined (__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4
typedef signed long int32_t;
#elif defined (__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 4
typedef signed long long int32_t;
#else
#error ...
#endif

As fas as I know the only reason why avr-libc used mode attribute is to factor out impact of -mint8, but the same can be achived by testing __SIZEOF_INT__. Unfortunately, thr writer of -mint8 did not define respective built-in macro like __AVR_MINT8__, but __SIZEOF_INT__ can serve the same purpose.

long' datatype could as well have 64 bits, still conforming to the
standard.  Likewise, an `unsigned int' on many GCC targets is 32 bits
long, so why does your tool assume it were 16 bits?

Moreover, how would your tool handle Johann's recent GCC addition of a
24-bit integer type?  This one can only be expressed by relying on the
definition of __int24_t (or __uint24_t) providing the necessary magic
to tell this to the compiler.

Notice that the names are __int24 and __uint24 similar to __int128 types some backend support. avr-gcc does *not* typedef/define int24_t or uint24_t because it's no good to mess in user name space. But if user likes he still can

#ifdef __INT24_MAX__
typedef __int24 int24_t;
#else
/* fallback on 32-bit integers */
typedef int32_t int24_t;

Johann



reply via email to

[Prev in Thread] Current Thread [Next in Thread]