Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Why is glibc not extensive? Date: Sat, 26 Nov 2022 09:07:58 -0800 Organization: A noiseless patient Spider Lines: 47 Message-ID: <867czh8x01.fsf@linuxsc.com> References: <62490c42-3d22-4386-ba2c-09aaf49eb1a5n@googlegroups.com> <81589145-5348-439c-87d7-e34b85378ae6n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="65972d10173aaa2bd10990f397dff173"; logging-data="1506324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+41FUxK57Ir5EFl77ic7tHnmyZi/+Kawc=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:g7A722nCV4DgWGKBWCew/Hb4LeI= sha1:bPYk3niamxl6h4fHDSLkjbQEi04= Xref: csiph.com comp.lang.c:168355 Michael S writes: > On Friday, November 18, 2022 at 2:47:42 PM UTC+2, A wrote: > >> On Friday, 18 November 2022 at 17:39:58 UTC+5:30, David Brown wrote: [...] >>> a) Use size_t like the rest of the world. >> >> This is a problem. If I am not convinced then why should I follow >> the world? The world can use size_t but I will use long and if the >> world says that I should be using size_t then I will ignore that. > > So, you don't want to use size_t because it is unsigned. Well. > Then use signed type ptrdiff_t. When you want to hold size of > arbitrary objects ptrdiff_t is more portable than 'long'. > In corner case of size of object that occupies more than half > of address space both ptrdiff_t and 'long' are not good enough, > but at least ptrdiff_t works in all other cases. The same can't > be said about 'long' which does not work in pretty common case > of size of big objects (>= 2GB) on Win64. IMO it's a mistake to hard-wire either 'long' or 'ptrdiff_t' to be the name of a (signed) size type. Whatever type is chosen should allow as wide a range of values as needed, and neither of those types will necessarily do that. Furthermore the type name used should reflect the purpose rather than the representation. Assuming the name 's_size' is considered appropriate and acceptable, a suitable typedef can be chosen using a scheme along these lines: #include #include #if INT_MAX >= SIZE_MAX typedef int s_size; #elif LONG_MAX >= SIZE_MAX typedef long s_size; #elif defined LLONG_MAX && LLONG_MAX >= SIZE_MAX typedef long long s_size; #else typedef intmax_t s_size; #endif after which any interfaces desired should use 's_size' for values of a signed size type.