Re: [dwm] unsigned int or size_t

From: Szabolcs Nagy <>
Date: Thu, 31 Jul 2008 08:49:39 +0200

On 7/31/08, Filippo Erik Negroni <> wrote:
> Hi All,
> I noticed the code in dwm uses unsigned int for positive counters of
> memory arrays instead of size_t.
> Is there a particular reason you don't use size_t in order to convey
> that you are using that quantity as a counter of memory space?

size_t is an unsigned intergal type so using unsigned int, while not
the best chioce there, is not extremely bad either.
(it only matters if we manage memory larger than SIZE_MAX or UINT_MAX,
actually c78 (KR book) didn't have size_t, the standardization
comittee added it for portability reasons)

i guess it's mainly for clarity: one _cannot_ use size_t consistently
[in c89] (eg what is the type of (size_t)a-(size_t)b, or what is a
size_t integer literal 123UL ?), also then one should start indexing
char* arrays with size_t (since it might be larger than int) and use
ptrdiff_t where applicable and where we require 16 bit (tagmask) there
we should use uint_fast16_t (c99), not to mention bools. [in c89 one
cannot even print a size_t value with printf! (except casting it to
unsigned long, but that's not guaranteed to work either) c99 added %z
to the already bloated format string rules..]

morale of the story:
the c integer type system is not strong enough to add hints about
which int is used in which context and how, or to write absolutely
architecture independent code.

the good news is:
usually we don't want to do that (adding hints just makes the code
less readable and applications has a very restricted audience eg. dwm
doesn't want to be more portable than X)
Received on Thu Jul 31 2008 - 06:49:39 UTC

This archive was generated by hypermail 2.2.0 : Thu Jul 31 2008 - 07:00:04 UTC