inttypes.h bug leads to inconsistent warnings cross platform
Jeff Johnston
jjohnstn@redhat.com
Thu Sep 11 16:35:00 GMT 2014
----- 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
>
>
More information about the Newlib
mailing list