[newlib] print formats for FAST and LEAST types

Andre Vieira Andre.SimoesDiasVieira@arm.com
Tue Jul 14 14:57:00 GMT 2015

On 14/07/15 15:18, Corinna Vinschen wrote:
> On Jul 14 15:08, Andre Vieira wrote:
>> On 14/07/15 14:49, Corinna Vinschen wrote:
>>> On Jul 14 12:17, Andre Vieira wrote:
>>>> Hello,
>>>> Kevin Bracey commented on Launchpad that he was having issues with a
>>>> mismatch between <inttypes.h> and <stdint.h> when printing an int_fast32_t.
>>>> See https://answers.launchpad.net/gcc-arm-embedded/+question/269083
>>>> This is due to the fact that on targets where the size of ‘int’ and ‘long’
>>>> are equal and 32 bits, the current header files will configure the type of
>>>> int_fast32_t to be ‘int’ and PRIdFAST32 to be ‘ld’ and make printf thus
>>>> expect a ‘long’. The macro’s used in <stdint.h> come from
>>>> ‘gcc/config/newlib-stdint.h’.
>>> Are you looking into an older version of newlib by any chance?  We
>>> added code to newlib's headers to check explicitely at runtime whether
>>> __INT32_TYPE__ is int or long, and set the PRIxxx32 macros accordingly.
>>> See https://sourceware.org/git/?p=newlib-cygwin.git;h=496380c
>>> I just checked this on 32 bit Cygwin:
>>>    $ gcc -E - <<EOF
>>>    #include <inttypes.h>
>>>    #include <stdint.h>
>>>    __INT_FAST32_TYPE__
>>>    PRIdFAST32
>>>    EOF
>>>    [...]
>>>    int
>>>    "d"
>>> If there's still anything wrong with that, feel free to send patches.
>>> Corinna
>> Hi Corinna,
>> I am on a newer version than the linked patch.
>> However when I run your example I get int and "ld".
>> In your example, if you pass -dM, does it show INT32_EQ_LONG to be defined?
> No, it's undefined.  This is i686-pc-cygwin.  Please have a look at
> libc/include/sys/_intsup.h  and try to find out why this doesn't work
> for your target.
> Thanks,
> Corinna

Hi Corinna,

It doesn't work because PRIdFAST32 uses __PRI32(d) as a definition and 
in the patch you mentioned earlier __PRI32(d) is defined as "ld" if 
_INT32_EQ_LONG is defined.

However __INT_FAST32_TYPE__ is a builtin defined in '<GCC 
SRC>/gcc/c-family/c-common.c' using INT_FAST32_TYPE, which is defined in 
'<GCC SRC>/gcc/config/newlib-stdint.h' as:
#define INT_FAST32_TYPE (INT_TYPE_SIZE >= 32 ? "int" : INT_LEAST32_TYPE)

So if INT_TYPE_SIZE == LONG_TYPE_SIZE, int_fast32_t will be 'int' and 
PRIdFAST32 will yield "ld" and printf won't like that.


More information about the Newlib mailing list