lkml.org 
[lkml]   [2021]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRE: [RFC v2] bpf.2: Use standard types and attributes
On Wed, 5 May 2021, David Laight via Libc-alpha wrote:

> > __u64 can't be formatted with %llu on all architectures. That's not
> > true for uint64_t, where you have to use %lu on some architectures to
> > avoid compiler warnings (and technically undefined behavior). There are
> > preprocessor macros to get the expected format specifiers, but they are
> > clunky. I don't know if the problem applies to uint32_t. It does
> > happen with size_t and ptrdiff_t on 32-bit targets (both vary between
> > int and long).
>
> uint32_t can be 'randomly' either int or long on typical 32bit architectures.
> The correct way to print it is with eg "xxx %5.4" PRI_u32 " yyy".

C2X adds printf length modifiers such as "w32", so you can use a
friendlier %w32u, for example. (Not yet implemented in glibc or in GCC's
format checking.)

--
Joseph S. Myers
joseph@codesourcery.com

\
 
 \ /
  Last update: 2021-05-06 00:23    [W:0.094 / U:0.640 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site