This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Incorrect compile warning, possible bug in inttypes.h


Hi Cary,

On Apr 27 22:52, Cary R. wrote:
> The following code:
> 
> #include <stdio.h>
> #include <inttypes.h>
> 
> int main()
> {
>         int32_t ival = 1;
>         uint32_t uval = 2;
> 
>         printf("int = %"PRId32", uint = %"PRIu32".\n", ival, uval);
>         return 0;
> }
> 
> 
> when compiled with either gcc or clang on a 32-bit system and with the -Wall flag produces the following warnings:
> 
> tmp.c: In function âmainâ:
> tmp.c:9:5: warning: format â%ldâ expects argument of type âlong intâ, but argument 2 has type âint32_tâ [-Wformat=]
>          printf("int = %"PRId32", uint = %"PRIu32".\n", ival, uval);
>          ^
> tmp.c:9:5: warning: format â%luâ expects argument of type âlong unsigned intâ, but argument 3 has type âuint32_tâ [-Wformat=]
> tmp.c:9:5: warning: format â%ldâ expects argument of type âlong intâ, but argument 2 has type âint32_tâ [-Wformat=]
> tmp.c:9:5: warning: format â%luâ expects argument of type âlong unsigned intâ, but argument 3 has type âuint32_tâ [-Wformat=]
> 
> I'm not sure why the double report for this, but both gcc and clang do
> the same thing. This looks to be an issue that is generated because a
> long is 32 bits on a 32-bit system and in inttypes.h __have_long32 is
> likely defined and that is forcing the use of the 'l' formats when
> that is incorrect for at least these two 32 bit types.

That looks like the culprit, yes.  This is part of the newlib changes to
stdint.h/inttypes.h, and this is apparently a problem.  Just because
long is a 32 bit type doesn't mean it's the base type of int32_t/uint32_t.
What bugs me most is that I tried to test the changes and failed to see
this problem.  Grr.

I'll discuss this on the newlib mailing list.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpUzhisz8c13.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]