[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] how to print size_t in LGPLv2+ program

Hi Eric,

> My understanding is that on 64-bit windows,
> sizeof(long)==4 but sizeof(void*)==8; and ... sizeof(size_t) is also 8.

Yes, correct.

> Which means you _can't_ use "%lu",(unsigned long)size_t_val.

You _can_ use this. It will work as long as each of your program's data
structures is less than 4 GB large. Remember that size_t values get
larger than 4 GB only if you have a memory object (array) that is larger
than 4 GB.

> What a shame that POSIX omitted an <inttypes.h> PRIu* for size_t.

You can define it by yourself: Basically you define

  #if @BITSIZEOF_SIZE_T@ == 32
  # define PRIuSIZE PRIu32
  #if @BITSIZEOF_SIZE_T@ == 64
  # define PRIuSIZE PRIu64

This will work with mingw's and msvc's native printf, because gnulib's
<inttypes.h> replacement defines PRIu64 to "I64u", and the native printf
supports %I64u directives.

Note that this will not work inside gettext() arguments, though, because
PRIuSIZE is not standard. For internationalized messages, you will need
the workaround described in the second half of

I hope one of these two alternatives works for you, so that we can avoid an
LGPLv2+ cascade.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]