Article View: net.bugs.2bsd
Article #320Fix to Ritchie's pdp11 compiler to allow "short int"
From: Steve Summit
Date: Sun, 27 Jul 1986 21:54
Date: Sun, 27 Jul 1986 21:54
113 lines
3581 bytes
3581 bytes
My only problem in writing code that's portable back to the pdp11
is that I like to declare things as "short int" and the pdp11
compilers that I have access to want just "short." I finally got
around to doing something about it. This may well be fixed in
more modern versions of Ritchie's compiler, (including 2.9 or
2.10; I haven't checked), but the fix is so simple it can't hurt
to post it.
The problem is that the compiler turns the keyword "short" into
the internal token INT at lexical analysis time. "short int"
therefore looks like "int int", an obvious type clash. The
solution is to tokenize "short" as SHORT so that the case can be
detected. This new "type" SHORT is just a placeholder; after
type analysis it is turned back into an INT, since that's what
the rest of the compiler expects.
The changes affect three files: the #definition of the type token
SHORT in c0.h, the keyword table in c00.c, and the type analysis
in c03.c. Context diffs follow.
Steve Summit
tektronix!copper!stevesu
*** /tmp/,RCSt1022392 Sun Jul 27 14:31:50 1986
--- c0.h Sun Jul 27 14:28:48 1986
***************
*** 320,323
#define DOUBLE 3
#define STRUCT 4
#define LONG 6
#define UNSIGN 7
--- 320,324 -----
#define DOUBLE 3
#define STRUCT 4
+ #define SHORT 5 /* adjusted later to int */
#define LONG 6
#define UNSIGN 7
*** /tmp/,RCSt1022392 Sun Jul 27 14:32:01 1986
--- c00.c Sun Jul 27 13:45:13 1986
***************
*** 30,34
"unsigned", UNSIGN,
"union", UNION,
! "short", INT,
"auto", AUTO,
"extern", EXTERN,
--- 30,34 -----
"unsigned", UNSIGN,
"union", UNION,
! "short", SHORT,
"auto", AUTO,
"extern", EXTERN,
*** /tmp/,RCSt1022392 Sun Jul 27 14:31:55 1986
--- c03.c Sun Jul 27 13:50:21 1986
***************
*** 94,99
case STRUCT:
tptr->hstrp = strdec(ismos, cval);
cval = STRUCT;
case INT:
case CHAR:
case FLOAT:
--- 94,102 -----
case STRUCT:
tptr->hstrp = strdec(ismos, cval);
cval = STRUCT;
+ case SHORT:
+ if(tkw == INT)
+ break; /* ignore "short" in "int short" */
case INT:
case CHAR:
case FLOAT:
***************
*** 99,105
case FLOAT:
case DOUBLE:
types:
! if (tkw>=0)
error("Type clash");
tkw = cval;
break;
--- 102,108 -----
case FLOAT:
case DOUBLE:
types:
! if (tkw>=0 && (tkw != SHORT || cval != INT))
error("Type clash");
tkw = cval;
break;
***************
*** 108,114
peeksym = o;
if (isadecl==0)
return(0);
! if (tkw<0)
tkw = INT;
if (skw==0)
skw = blklev==0? DEFXTRN: AUTO;
--- 111,117 -----
peeksym = o;
if (isadecl==0)
return(0);
! if (tkw<0 || tkw==SHORT) /* bug: allows "long short" */
tkw = INT;
if (skw==0)
skw = blklev==0? DEFXTRN: AUTO;
Technical Details
Message-ID:
<505@copper.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!sri-spam!nike!ucbcad!ucbvax!hplabs!tektronix!teklds!copper!stevesuShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!sri-spam!nike!ucbcad!ucbvax!hplabs!tektronix!teklds!copper!stevesu From: stevesu@copper.UUCP (Steve Summit) Newsgroups: net.bugs.2bsd,net.lang.c Subject: Fix to Ritchie's pdp11 compiler to allow "short int" Message-ID: <505@copper.UUCP> Date: Sun, 27-Jul-86 17:54:47 EDT Article-I.D.: copper.505 Posted: Sun Jul 27 17:54:47 1986 Date-Received: Mon, 28-Jul-86 19:20:18 EDT Reply-To: stevesu@copper.UUCP (Steve Summit) Organization: Tektronix, Inc., Beaverton, OR. Lines: 113