Topic: min, max, and ANSI


Author: krc@wam.umd.edu (Kevin R. Coombes)
Date: Thu, 9 Apr 1992 16:58:59 GMT
Raw View
I have a question about the ANSI C header stdlib.h. A certain compiler that
shall for the moment remain nameless includes macros for min(a,b) and
max(a,b) in <stdlib.h>. Consequently, I managed to lose several hours
trying to find out why a working program suddenly broke---eventually
discovering, of course, that I had been using min as the name of a variable,
and had changed things hwen I #included <stdlib.h> for unrelated reasons.
Are min and max SUPPOSED to be in stdlib.h, and have I been just lucky
in avoiding this problem in the past?

Kevin Coombes <krc@math.umd.edu>




Author: cwalker@albiero.tmc.edu (carleton walker `93)
Date: 9 Apr 92 20:04:53 GMT
Raw View
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 that
>shall for the moment remain nameless includes macros for min(a,b) and
>max(a,b) in <stdlib.h>. Consequently, I managed to lose several hours
>trying to find out why a working program suddenly broke---eventually
>discovering, of course, that I had been using min as the name of a variable,
>and had changed things hwen I #included <stdlib.h> for unrelated reasons.
>Are min and max SUPPOSED to be in stdlib.h, and have I been just lucky
>in avoiding this problem in the past?

 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>?


Carl Walker

--
Carl Walker    "Hectic days ahead of us,
Bucknell University    Rotten ones behind,
Lewisburg, PA     Keeping plastics in our pockets,
      Children never mind." - K, S, & W




Author: diamond@jit345.bad.jit.dec.com (Norman Diamond)
Date: Fri, 10 Apr 92 08:29:56 GMT
Raw View
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 that
>shall for the moment remain nameless includes macros for min(a,b) and
>max(a,b) in <stdlib.h>.

1.  If you're asking about the ANSI C header stdlib.h, it does not intrude
on the application's namespace, not even names like min and max.

2.  If you're asking about the draft ANSI C++ standard (for which you
cross-posted your question), you'll have to hope for an answer from
someone else.

3.  If you're asking about a certain nameless compiler, then maybe:
(a)  You might have invoked it in a non-conforming mode, and/or your program
might have done something to request implementation extensions, and in either
case the standard becomes irrelevant.  Please note that non-conforming modes
are often defaults, and often you have to use options for conforming modes; or
(b)  The vendor might not have asserted conformance in the first place; or
(c)  If you did everything as directed to invoke in a conforming mode, then
you should demand a refund from the vendor.  [Personal opinion only.]
--
Norman Diamond       diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"Yeah -- bad wiring.  That was probably it.  Very bad."




Author: pete@borland.com (Pete Becker)
Date: Fri, 10 Apr 1992 16:23:27 GMT
Raw View
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 that
>shall for the moment remain nameless includes macros for min(a,b) and
>max(a,b) in <stdlib.h>. Consequently, I managed to lose several hours
>trying to find out why a working program suddenly broke---eventually
>discovering, of course, that I had been using min as the name of a variable,
>and had changed things hwen I #included <stdlib.h> for unrelated reasons.
>Are min and max SUPPOSED to be in stdlib.h, and have I been just lucky
>in avoiding this problem in the past?
>
>Kevin Coombes <krc@math.umd.edu>

 If you compile in ANSI mode (with the -A switch), min and max go
away.  They also go away when compiling C++.
 -- Pete




Author: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Date: 13 Apr 92 07:48:16 GMT
Raw View
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 that
> shall for the moment remain nameless includes macros for min(a,b) and
> max(a,b) in <stdlib.h>.

In article <1992Apr10.162327.29202@borland.com>, pete@borland.com (Pete Becker) writes:
>  If you compile in ANSI mode (with the -A switch), min and max go
> away.  They also go away when compiling C++.
>  -- Pete

Turbo C 2.01 does have problems in its <stdlib.h> which the -A option does
not fix.  Example:

 int boo[2];
 #define state 0[boo]
 #define seed  1[boo]
 #include <stdlib.h>
 ...

I hadn't noticed this before today, because I hadn't used tcc before today.
It turns out that most of the functions defined in stdlib.h have identiers
in their prototypes, and those identifiers are in the user's name space.

Then of course there's <assert.h>, with Borland's manual explicitly
saying that assert "turns into an if statement".

Where are the *standard* C compilers?  (Ok, I know about Norcroft, but
last I heard they didn't have a compiler for PCs or Encore Multimaxes.)

I spent several hours last week writing a <stdio.h> for Gcc on an
Encore Multimax; not having one it picked up the /usr/include/stdio.h,
and in strict ANSI mode it didn't #define n16, so the record structure
for a stream control block was wrong.  Result: happy compiler, insane
program.  Where are the *standard* C compilers?

--
I am writing a book on debugging aimed at 1st & 2nd year CS students using
C/Modula/Pascal-like languages.  Please send suggestions (other than "you
_must_ cite "C Traps and Pitfalls") to ok@goanna.cs.rmit.oz.au