Article View: comp.std.c
Article #193Re: min, max, and ANSI
From: Chris Torek
Date: Fri, 10 Apr 1992 00:40
Date: Fri, 10 Apr 1992 00:40
87 lines
2910 bytes
2910 bytes
(Since the question was about ANSI C, I have deleted `comp.std.c++'.) In article <1992Apr9.165859.18578@wam.umd.edu> krc@wam.umd.edu (Kevin R. Coombes) writes: >>I have a question about the ANSI C header stdlib.h. A certain compiler >>... includes macros for min(a,b) and max(a,b) in <stdlib.h>. ... >>Are min and max SUPPOSED to be in stdlib.h, and have I been just lucky >>in avoiding this problem in the past? The ANSI C standard clearly states that <stdlib.h> defines the following: - macros: NULL EXIT_FAILURE EXIT_SUCCESS RAND_MAX MB_CUR_MAX - types: size_t wchar_t div_t ldiv_t - functions: atof atoi atol strtod strtol strtoul rand srand calloc free malloc realloc abort atexit exit getenv system bsearch qsort abs div labs ldiv mblen mbtowc wctomb mbstowcs wcstombs It also notes that future standards may add function names that begin with |str| and a lowercase letter (e.g., strabc, strrts, etc.). Other parts of the standard clearly forbid all implementations to define in <stdlib.h> any names not listed above, except for special cases involving identifiers beginning with underscore. The identifiers `min' and `max' do not appear in the list above, and do not begin with an underscore. Therefore they may not appear in <stdlib.h>. Conclusion: if the vendor claims ANSI conformance, <stdlib.h> is broken. (If not, well, the standard can hardly control nonstandard implementations.) In article <1324@hydra.bucknell.edu> cwalker@albiero.tmc.edu (carleton walker `93) writes: > I've always used the MIN and MAX in <mp.h>. I took a peak in ><stdlib.h> and couldn't find a MIN or MAX function. Do you include ><mp.h>? <mp.h> does not appear in the ANSI standard, so this reply is not relevant to the question as asked. Your particular implementation is not the ANSI C standard---no particular implementation can be---and may or may not even attempt to conform. Nonetheless, min and max macros are commonly found in nonstandard headers (such as <sys/param.h>) on Unix systems, among others. Sometimes they are spelled in uppercase, sometimes in lowercase. If you want your code to compile on non-standard systems, you may wish to avoid these names. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov
Technical Details
Message-ID:
<22620@dog.ee.lbl.gov>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torekReferences:
<1992Apr9.165859.18578@wam.umd.edu> <1324@hydra.bucknell.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek From: torek@horse.ee.lbl.gov (Chris Torek) Newsgroups: comp.std.c Subject: Re: min, max, and ANSI Message-ID: <22620@dog.ee.lbl.gov> Date: 10 Apr 92 00:40:39 GMT Article-I.D.: dog.22620 References: <1992Apr9.165859.18578@wam.umd.edu> <1324@hydra.bucknell.edu> Reply-To: torek@horse.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 87 NNTP-Posting-Host: 128.3.112.15