Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!munnari.oz.au!csc.anu.edu.au!manuel!anucsd!pdact!peter From: peter@pdact.pd.necisa.oz (Peter Miller) Newsgroups: comp.lang.c Subject: Re: Number of enums Summary: general solution: minof() and maxof() Message-ID: <908@pdact.pd.necisa.oz> Date: 24 Jan 91 22:58:03 GMT References: <703@caslon.cs.arizona.edu> <1991Jan21.133917.18458@cbnews.att.com> <726@caslon.cs.arizona.edu> Organization: NEC Information Systems Australia, Canberra Lines: 42 In article <279DC67C.6ABD@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: >According to dave@cs.arizona.edu (Dave P. Schaumann): >>[suggests the new operator 'numberof' would be A Good Thing] > >[counter example given] This reminds me of my favorite C extension, suggested long a go by Tim Long: operators called "minof" and "maxof", which take an argument similar to the "sizeof" operator. Thus "minof(enum PLUGH)" would return the minimum value of any of the PLUGH enum tags, similarly "maxof(enum PLUGH)" would return the maximum value of any of the PLUGH enum tags. These operators have even more uses, portions of limits.h become the same for all machines: #define SCHAR_MIN minof(signed char) #define SCHAR_MAX maxof(signed char) #define UCHAR_MAX maxof(unsigned char) #define CHAR_MAX maxof(char) #define CHAR_MIN minof(char) #define SHRT_MAX maxof(short) #define SHRT_MIN minof(short) #define USHRT_MAX maxof(unsigned short) #define INT_MAX maxof(int) #define INT_MIN minof(int) #define UINT_MAX maxof(unsigned int) #define LONG_MAX maxof(long) #define LONG_MIN minof(long) #define ULONG_MAX maxof(unsigned long) Note that this works without #ifdef's whether "char" defaults to "signed" or "unsigned". Regards Peter Miller UUCP uunet!munnari!pdact.pd.necisa.oz!pmiller ACSnet pmiller@pdact.pd.necisa.oz /\/\* CSNET pmiller@pdact.pd.necisa.oz.au Disclaimer: The views expressed here are personal and do not necessarily reflect the view of my employer or the views or my colleagues. D