Fix to Ritchie's pdp11 compiler to allow "short int"

Steve Summit stevesu at copper.UUCP
Mon Jul 28 07:54:47 AEST 1986


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;



More information about the Comp.lang.c mailing list