NetBSD-Bugs archive

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

Re: lib/34516: size_t should be equivalent to unsigned long



The following reply was made to PR lib/34516; it has been noted by GNATS.

From: Christian Biere <christianbiere%gmx.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: lib/34516: size_t should be equivalent to unsigned long
Date: Sun, 20 Jan 2008 11:44:47 +0100

 David Holland wrote:
 > Subject: Re: lib/34516: size_t should be equivalent to unsigned long
 
 >  size_t is not, however, the *same* as unsigned long. Code that
 >  indiscriminately mixes size_t with unsigned long_t is no better than
 >  code that indiscriminately mixes size_t with unsigned int; it is not
 >  portable.
 
 Code which incorrectly uses unsigned long instead of size_t is
 comparatively rare and it's unlikely to happen by accident. Abuse of
 int instead of proper use of size_t is wide-spread and the result of
 implicit integer promotion is very often int.
 
 > It is not clear to me that there is any particular merit to
 >  associated with picking one way over the other.
 
 It eases writing 64-bit clean code on 32-bit machines. This matters
 more for third-party code than NetBSD itself.
 
 > C does not support newtypes, so there is no way to avoid masking some
 > such set of coding errors.
 
 The conclusion is incorrect. I provided some examples in the initial
 report.
 
 >  Furthermore, the precise expansion of size_t is gcc's choice, because
 >  gcc "knows" the type signatures of various standard functions, so we
 >  can't or shouldn't change it in NetBSD even if there were a good
 >  argument in favor.
 
 It's not so much GCC's choice because other 32-bit targets don't have
 size_t as unsigned int. It's simply a question of editing machine/ansi.h.
 
 I've fixed this locally for myself long ago and never had such a hidden
 problem again. If I'm the only one who cares and/or if it's too hard to
 change this historical decision, it might very well be appropriate to
 close this PR.
 
 -- 
 1000 octets   = 1 ko = 1 kilooctet; 1024 octets   = 1 Kio = 1 kibioctet
 1000^2 octets = 1 Mo = 1 megaoctet; 1024^2 octets = 1 Mio = 1 mebioctet
 1000^3 octets = 1 Go = 1 gigaoctet; 1024^3 octets = 1 Gio = 1 gibioctet
 



Home | Main Index | Thread Index | Old Index