On Sat, Jun 26, 2010 at 01:32:05AM +0200, Joerg Sonnenberger wrote: > On Fri, Jun 25, 2010 at 11:54:32PM +0200, Alistair Crooks wrote: > > Even in C99, the "%lu" method will work unless size_t is bigger than > > unsigned long *and* the value being printed exceeds ULONG_MAX, which > > is unlikely to happen in practice.
Please get the attributions right - I was quoting that text. > Actually, it doesn't. This method breaks as soon as size_t != u_long and > might only work in a few edge cases like the size_t being the last > argument and the byte order is Little Endian. This is worse because IIRC > Microsoft decided to use IL32LLP64 or something similarly fancy. Can you give us a reference to this, please? > A more portable approach with autoconf can be found in pkg_install, look > for MISSING_SIZE_T_SUPPORT and the corresponding AC_CHECK_SIZEOF calls > in configure.ac. Hmmm, I see this in configure.ac - AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) AC_CHECK_SIZEOF(size_t, [#include <stdlib.h>]) and case $host in *-*-hpux*) AC_DEFINE(MISSING_SIZE_T_SUPPORT) AH_TEMPLATE([MISSING_SIZE_T_SUPPORT], [ Define to 1 if the `z' modifider for printf is missing. ]) ;; esac and #ifndef MISSING_SIZE_T_SUPPORT # define PRIzu "zu" #elif SIZEOF_SIZE_T == SIZEOF_INT # define PRIzu "u" #elif SIZEOF_SIZE_T == SIZEOF_LONG # define PRIzu "lu" #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG # define PRIzu "llu" #else # errror "Unknown size_t size" #endif Not quite what I'd been expecting, though, from the glowing description above. Am I missing a revision of that file or something? It took me ages to find it, since I was looking under src/external first of all - and cvs status does say it's up to date. Thanks, Alistair