Date: Tue, 14 Mar 2000 16:50:13 +0000 From: Paul Richards <paul@originative.co.uk> To: Bruce Evans <bde@zeta.org.au> Cc: John Polstra <jdp@polstra.com>, current@FreeBSD.ORG Subject: Re: MAX_UID ? Message-ID: <38CE6DC5.1158EDC1@originative.co.uk> References: <Pine.BSF.4.21.0003131708430.931-100000@alphplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?38CE6DC5.1158EDC1>