From owner-freebsd-current Tue Mar 14 8:50:26 2000 Delivered-To: freebsd-current@freebsd.org Received: from mail.originative.co.uk (mailgate.originative.co.uk [194.217.50.228]) by hub.freebsd.org (Postfix) with ESMTP id 42DD237B756 for <current@FreeBSD.ORG>; Tue, 14 Mar 2000 08:50:17 -0800 (PST) (envelope-from paul@originative.co.uk) Received: from originative.co.uk (lobster.originative.co.uk [194.217.50.241]) by mail.originative.co.uk (Postfix) with ESMTP id E53991D131; Tue, 14 Mar 2000 16:50:13 +0000 (GMT) Message-ID: <38CE6DC5.1158EDC1@originative.co.uk> Date: Tue, 14 Mar 2000 16:50:13 +0000 From: Paul Richards <paul@originative.co.uk> Organization: Originative Solutions Ltd X-Mailer: Mozilla 4.7 [en] (X11; I; FreeBSD 4.0-CURRENT i386) X-Accept-Language: en-GB, en MIME-Version: 1.0 To: Bruce Evans <bde@zeta.org.au> Cc: John Polstra <jdp@polstra.com>, current@FreeBSD.ORG Subject: Re: MAX_UID ? References: <Pine.BSF.4.21.0003131708430.931-100000@alphplex.bde.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Bruce Evans wrote: > > On Sun, 12 Mar 2000, John Polstra wrote: > > > Sheesh, criticism isn't enough? Now it has to be constructive too? ;-) > > > > I guess it could go into <machine/limits.h> in the > > "!defined(_ANSI_SOURCE)" section. Bruce might have a better idea. Trying to draw some closure on this discussion. > > This is the same as putting it in <limits.h> in the > "!defined(_ANSI_SOURCE)" section. Anyway, the names should be FOO_MAX, > not MAX_FOO. > > In C99, there are about 50 *_MAX and *_MIN values defined in <stdint.h> > for Standard C types alone. > > I would prefer standard maxof() and minof() interfaces that work on > any arithmetic type. These can almost be written in portable C, at > least in C89 where types are restricted to char, signed char, ..., > long double: > > #define isfloat(type) ((type)0.5 != 0) > #define issigned(type) ((type)-1 < 0) > #define isschar(type) (!isfloat(type) && issigned(type) && sizeof(type) == 1) > #define isuchar(type) (!isfloat(type) && !issigned(type) && sizeof(type) == 1) > ... > #define maxof(type) ((type)(isschar(type) ? SCHAR_MAX : > isuchar(type) ? UCHAR_MAX ...)) Where do you think these macros should go then? Having though about this some more, although the above macros are useful and can be used in a lot of the places where bounds checking needs to be done, there is still probably a need to define certain constants, such as UID_MAX, because the range of valid values may not necessarily be the same as the range of values supported by the type. UID_MAX being a good example, since FreeBSD does not support 32-bit UIDs at the moment even though the kernel does. Most applications are limiting themselves to USHRT_MAX, those applications should be fixed to use UID_MAX, even if we still limit UID_MAX == USHRT_MAX for backwards compatibility. So, <sys/syslimits.h> seems like the right place for constants like UID_MAX. Any disagreements there? I guess the above macros should really be machine specific if we're going to be pedantic. Would <machine/limits.h> be an appropriate location for them? Paul. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message