Number of enums
Peter Miller
peter at pdact.pd.necisa.oz
Fri Jan 25 09:58:03 AEST 1991
In article <279DC67C.6ABD at tct.uucp> chip at tct.uucp (Chip Salzenberg) writes:
>According to dave at 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 at pdact.pd.necisa.oz
/\/\* CSNET pmiller at 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
More information about the Comp.lang.c
mailing list