I'm not aware of any C implementation that actually generated code for MAX and MIN using these operators, although the operators were certainly discussed with that spelling.  I think many people just made do with:
   #define MAX(a,b)  ((a)>(b))?(a):(b)
despite the fact that it is wrong if a or b has side effects.   And with register variables, you could generate excellent code for max and min if that was a consideration.

I think the reason was partly that the operators look a bit clunky.   And also that the implementation, like ? :, can be trickier than it first appears...


----- Original Message -----
"Lawrence Stewart" <stewart@serissa.com>

"The Eunuchs Hysterical Society" <tuhs@tuhs.org>

Fri, 3 Nov 2017 08:53:40 -0400
[TUHS] Fwd: [Simh] An abandoned piece of K&R C

This caught my attention.  Did early C really have min and max?  Were they used for anything?  In those days I was a BCPL user, which IIRC, did not have such things.


Begin forwarded message:

From: Leo Broukhis <leob@mailcom.com>
Subject: [Simh] An abandoned piece of K&R C
Date: 2017, November 3 at 1:14:42 AM EDT


In the UNIX V7 version of the C language, there were the /\ (min) and the \/ (max) operators. In the source of the scanner part of the compiler,

case BSLASH:
    if (subseq('/', 0, 1))
    goto unkn;

case DIVIDE:
    if (subseq('\\', 0, 1))

However, attempting to use them reveals that the corresponding part in the code generator is missing. Trying to compile

foo(a, b) { return a \/ b; }

results in

1: No code table for op: \/

The scanner piece survived in the copies of the compiler for various systems for several years. I tried to look for copies of the code generator table which would contain an implementation, but failed. Has anyone ever seen a working MIN/MAX operator in K&R C?


Simh mailing list