bug-gnulib
[Top][All Lists]
Advanced

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

Re: how to print size_t in LGPLv2+ program


From: Bruno Haible
Subject: Re: how to print size_t in LGPLv2+ program
Date: Wed, 18 Aug 2010 00:33:33 +0200
User-agent: KMail/1.9.9

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
  #endif
  #if @BITSIZEOF_SIZE_T@ == 64
  # define PRIuSIZE PRIu64
  #endif

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
<http://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html>.

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

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]