Hi all,
I am having difficulties figuring out standard integer types. I am on a Raspberry Pi using arduino-cli and I am trying to use sprintf on an int32_t, with the "%d" format specifier.
sprintf(repr_sizes[i], "%-5s %4d bytes (%3d%%)", NAMES[i], sizes[i], percentage);
When I try to compile my code, the compiler warns me about:
"format '%d' expects argument of type 'int', but argument 4 has type 'int32_t {aka long int}'"
However, when I change it to use "%ld" instead, for long int, my linter clangd says this:
"Format specifies type 'long' but the argument has type 'int32_t' (aka 'int')"
I seem to be getting mismatching info here. Looking closer at the only AVR stdint.h on my system, I find the following code (line 129):
typedef signed int int32_t __attribute__ ((__mode__ (__SI__)));
Which seems to agree with clangd. But lines 125-134 of stdint.h seem to define all integer types as signed or unsigned int, which is strange. But then on line 98 of the same stdint.h, I find this code:
typedef signed long int int32_t;
This code is under an #if defined(__DOXYGEN__)
block from lines 66-121. Which begs the question, why does the Doxygen version have different definitions if the only difference is documentation? Is this a bug in the implementation, a copy-paste error perhaps, or am I getting something wrong here?
Can anyone clarify this? Thanks in advance!
stdint.h (16.3 KB)