[ABANDONED] stdint.h incorrect sizes

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [ABANDONED] stdint.h incorrect sizes

    I am trying to convert an old NRF52840 project that works with 5.70a to work with the lastest build of 7.12a.

    However, it seems like the <stdint.h> is defining the integer sizes incorrectly.

    This code:

    C Source Code

    1. sprintf(pinstr, "%u", currPin);



    Gives this warning:

    Source Code

    1. format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]

    This is a 32-bit processor. An unsigned int should be equal to an uint32_t correct? It seems like an "uint32_t" is defined as a long unsigned int

    ======= Adding Tests Size Info ===========

    C Source Code

    1. sprintf(intbuf, "size of int is %d\r\n", sizeof(int));
    2. printf(intbuf);
    3. sprintf(intbuf, "size of unsigned int is %d\r\n", sizeof(unsigned int));
    4. printf(intbuf);
    5. sprintf(intbuf, "size of uint32_t is %d\r\n", sizeof(uint32_t));
    6. printf(intbuf);
    7. sprintf(intbuf, "size of int32_t is %d\r\n", sizeof(int32_t));
    8. printf(intbuf);
    Display All

    Source Code

    1. size of int is 4
    2. size of unsigned int is 4
    3. size of uint32_t is 4
    4. size of int32_t is 4

    The post was edited 3 times, last by lcorbin ().

  • Hello,

    Thank you for your inquiry.

    Unfortunately it is not that simple.

    This is a problem that comes up with the Arm AEABI and with C++ mangled names ("exactly what is a uint32_t?"). '%u' should not be used for a uint32_t, you should use PRIuLEAST32 or PRIdLEAST32 from <inttypes.h>.

    Arm confuses the issue with the AEABI defining that 32-bit data are "unsigned" and "int".
    The C RTABI document and the AAPCS document do not discuss uint32_t, and nor does the C++ RTABI which, is more important here.

    The way to handle this is either cast uint32_t to unsigned (which would be incorrect for 16-bit systems),
    or to construct the print correctly for all systems: printf("%" PRIuLEAST32"\n", i);

    The reason why it worked in older versions has been that we defined uint32_t as unsigned int.
    Since V7.12 we use the type that the compiler defines for it (__UINT32_TYPE__), which for gcc happens to be long unsigned int.
    (clang and the SEGGER Compiler define this as unsigned int. There it would work.)

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.