From: scj@yaccman.com (Steve Johnson)
Subject: [TUHS] Fwd: [Simh] An abandoned piece of K&R C
Date: Sun, 05 Nov 2017 08:18:33 -0800 [thread overview]
Message-ID: <2b6fb33181aef8a68f6a6a21ff08a82271389a6a@webmail.yaccman.com> (raw)
In-Reply-To: <160331EE-3C7D-4948-ADE3-E57FFDCA5EAF@serissa.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2600 bytes --]
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...
Steve
----- Original Message -----
From:
"Lawrence Stewart" <stewart at serissa.com>
To:
"The Eunuchs Hysterical Society" <tuhs at tuhs.org>
Cc:
Sent:
Fri, 3 Nov 2017 08:53:40 -0400
Subject:
[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.
-Larry
Begin forwarded message:
FROM:
Leo Broukhis <leob at mailcom.com [1]>
SUBJECT:
[SIMH] AN ABANDONED PIECE OF K&R C
DATE:
2017, November 3 at 1:14:42 AM EDT
TO:
"simh at trailing-edge.com [2]" <simh at trailing-edge.com [3]>
https://retrocomputing.stackexchange.com/q/4965/4025 [4]
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))
return(MAX);
goto unkn;
case DIVIDE:
if (subseq('', 0, 1))
return(MIN);
...
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?
Thanks,Leo
_______________________________________________
Simh mailing list
Simh at trailing-edge.com [5]
http://mailman.trailing-edge.com/mailman/listinfo/simh
Links:
------
[1] mailto:leob at mailcom.com
[2] mailto:simh at trailing-edge.com
[3] mailto:simh at trailing-edge.com
[4] https://retrocomputing.stackexchange.com/q/4965/4025
[5] mailto:Simh at trailing-edge.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20171105/6976251a/attachment.html>
prev parent reply other threads:[~2017-11-05 16:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAFmvRsc46TQ10nEHewBt=LpQ814GydW-BmQ+=-jyvitMP1numg@mail.gmail.com>
2017-11-03 12:53 ` Lawrence Stewart
2017-11-05 16:18 ` Steve Johnson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2b6fb33181aef8a68f6a6a21ff08a82271389a6a@webmail.yaccman.com \
--to=scj@yaccman.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).