[PATCH] Use PRId32/PRIx32 from inttypes.h for printf of CARD32 values.

Mark Kettenis mark.kettenis at xs4all.nl
Mon Oct 5 13:22:56 PDT 2009


> From: Adam Jackson <ajax at nwnk.net>
> Date: Mon, 05 Oct 2009 15:41:05 -0400
> 
> On Sun, 2009-10-04 at 06:57 -0400, Thomas Dickey wrote:
> > On Sun, 4 Oct 2009, Mark Kettenis wrote:
> > >>> @@ -219,7 +219,7 @@ port_rep_inb(xf86Int10InfoPtr pInt,
> > >>>      register int inc =3D3D d_f ? -1 : 1;
> > >>>      CARD32 dst =3D3D base;
> > >>>      if (PRINT_PORT && DEBUG_IO_TRACE())
> > >>> -	ErrorF(" rep_insb(%#x) %ld bytes at %8.8lx %s\n",
> > >>> +	ErrorF(" rep_insb(%#x) %" PRId32 " bytes at %8.8" PRIx32 " %s\n",
> > >>>  		port, count, base, d_f ? "up" : "down");
> > >>>      while (count--) {
> > >>>  	MEM_WB(pInt, dst, x_inb(port));
> > >>
> > >> Is this portable beyond glibc? Alan? Matthieu?
> > >
> > > The PRId32 and PRIx32 defines are part of C99.
> > >
> > > That said, the consensus among many groups of developers is that they
> > > are ugly, make the code harder to read and can be easily avoided by
> > > using appropriate casts.
> >=20
> > beyond being merely ugly, different versions of gcc give warnings for
> > combinations that are quiet in other versions of gcc.
> 
> The problem in this particular case is that there's no pretty way to
> silence these warnings, because CARD32 is effectively:
> 
> #if __ILP32
> typedef unsigned long CARD32;
> #elif __LP64
> typedef unsigned int CARD32;
> #endif
> 
> Which means you'd actually need different format strings on different
> architectures.  We could (should) fix this the sane way:
> 
> typedef uint32_t CARD32;
> 
> Which would then assuredly trigger more format warnings elsewhere.

Well,

CARD32 num;
printf("%ld", (long)num);

should prevent all warnings.


More information about the xorg-devel mailing list