public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Incorrect compile warning, possible bug in inttypes.h
@ 2015-04-27 22:53 Cary R.
  2015-04-28 10:45 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Cary R. @ 2015-04-27 22:53 UTC (permalink / raw)
  To: The Cygwin Mailing List

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.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Incorrect compile warning, possible bug in inttypes.h
  2015-04-27 22:53 Incorrect compile warning, possible bug in inttypes.h Cary R.
@ 2015-04-28 10:45 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2015-04-28 10:45 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1985 bytes --]

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 #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-28 10:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-27 22:53 Incorrect compile warning, possible bug in inttypes.h Cary R.
2015-04-28 10:45 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).