This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: inttypes.h bug leads to inconsistent warnings cross platform
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Eric Blake <eblake at redhat dot com>
- Cc: Joel Sherrill <joel dot sherrill at oarcorp dot com>, newlib at sourceware dot org, Joseph Myers <joseph at codesourcery dot com>
- Date: Thu, 11 Sep 2014 12:34:58 -0400 (EDT)
- Subject: Re: inttypes.h bug leads to inconsistent warnings cross platform
- Authentication-results: sourceware.org; auth=none
- References: <5409CAAD dot 1030801 at oarcorp dot com> <5410A1D3 dot 4070106 at oarcorp dot com> <2027970937 dot 45186281 dot 1410382415557 dot JavaMail dot zimbra at redhat dot com> <668285ea-373a-48c1-86c0-58e54cd8a440 at email dot android dot com> <1533143832 dot 45194451 dot 1410383583404 dot JavaMail dot zimbra at redhat dot com> <54111980 dot 5030004 at redhat dot com>
----- Original Message -----
> From: "Eric Blake" <eblake@redhat.com>
> To: "Jeff Johnston" <jjohnstn@redhat.com>, "Joel Sherrill" <joel.sherrill@oarcorp.com>
> Cc: newlib@sourceware.org, "Joseph Myers" <joseph@codesourcery.com>
> Sent: Wednesday, September 10, 2014 11:39:44 PM
> Subject: Re: inttypes.h bug leads to inconsistent warnings cross platform
>
> On 09/10/2014 03:13 PM, Jeff Johnston wrote:
> > I was thinking of having something like:
> >
> > <logic in newlib that figures out what uintptr_t is>
> >
> > <PRIuPTR logic from newlib>
> >
> > int printf(char *x, ...);
> >
> > int main()
> > {
> > uintptr_t p = 0;
> >
> > return printf("%" PRIuPTR "\n", p);
> > }
> >
> > then compile this with -Wall -Werror in the compilation test so it either
> > fails or succeeds. You then know that the PRIxPTR code needs tweaking.
>
> That's fragile (depends on -Werror working), whereas you can do type
> detection on ALL compliant C compilers via function pointer assignment
> or function redeclaration. Lightly tested, but observe how I can
> quickly probe that uintptr_t is equal to unsigned long on my x86_64
> GNU/Linux box, with no need for warning detection:
>
> $ cat foo.c
> #include <inttypes.h>
> extern int foo(uintptr_t);
> extern int foo(PROBE);
> int main() { return 0; }
> $ gcc -o foo foo.c -D PROBE='unsigned long'
> $ gcc -o foo foo.c -D PROBE='unsigned long long'
> foo.c:3:12: error: conflicting types for âfooâ
> extern int foo(PROBE);
> ^
> foo.c:2:12: note: previous declaration of âfooâ was here
> extern int foo(uintptr_t);
> ^
> $
>
Yes, that would be a better strategy for the test.
> --
> Eric Blake eblake redhat com +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>