[Top][All Lists]

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

Re: printf (_("...%zu..."), X) where X is of type size_t

From: Paul Eggert
Subject: Re: printf (_("...%zu..."), X) where X is of type size_t
Date: Fri, 30 Sep 2005 23:18:06 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

address@hidden (James Youngman) writes:

> Am I mistaken, or is it the case that the C99 standard allows size_t
> to be wider than unsigned long?

You are not mistaken.  However, for gnulib the GNU coding standards
trump that.  They say:

   ... don't make any effort to cater to the possibility that
   'long' will be smaller than predefined types like 'size_t'.
   For example, the following code is ok:

     printf ("size = %lu\n", (unsigned long) sizeof array);
     printf ("diff = %ld\n", (long) (pointer2 - pointer1));

   1989 Standard C requires this to work, and we know of only one
   counterexample: 64-bit programs on Microsoft Windows IA-64.  We will
   leave it to those who want to port GNU programs to that environment
   to figure out how to do it.

   Predefined file-size types like 'off_t' are an exception: they are
   longer than 'long' on many platforms, so code like the above won't
   work with them.  One way to print an 'off_t' value portably is to
   print its digits yourself, one by one.

POSIX 1003.1-2001 also requires support for the assumption that size_t
is no wider than long int (sorry, can't cite chapter and verse

reply via email to

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