Re: Who should convert literals to integers?

Tom.Lane@ZOG.CS.CMU.EDU
Sun, 21 Aug 88 15:42:30 EDT

          From comp.compilers

Related articles
Who should convert literals to integers? ubc-cs!calgary!radford@uunet.com (1988-08-12)
Who should convert literals to integers? think!compass!worley@eddie.mit.edu.uucp (Dale Worley) (1988-08-17)
Re: Who should convert literals to integers? haddock!ico!rcd (1988-08-17)
Re: Who should convert literals to integers? Tom.Lane@ZOG.CS.CMU.EDU (1988-08-21)
Re: Who should convert literals to integers? markhall@pyramid.pyramid.com (1988-08-29)
Re: Who should convert literals to integers? tgl@zog.cs.cmu.edu (1988-09-04)
Re: Who should convert literals to integers? wendyt@pyrps5.pyramid.com (1988-09-09)
| List of all articles for this month |

In-Reply-To: Dick Dunn's netnews message of 17 Aug 88 23:45:36 GMT
Date: Sun, 21 Aug 88 15:42:30 EDT
From: Tom.Lane@ZOG.CS.CMU.EDU

> Does anyone else think that converting a series of digits into an integer
> is inappropriate for a lexical analyser? It seems to be a very common
> thing to do, but I can see practically no advantages to it, and several
> disadvantages.


The main reason for converting constants to binary is so the compiler
can do arithmetic on them. Somebody already mentioned constant folding,
but nobody has yet pointed out the most crucial case where the compiler
must do this: where the constants in question are array subscript
bounds. You *must* do arithmetic at compile time to do storage
allocation! (Unless you want to use a dope vector and run-time
storage allocation for every array, which is mighty expensive.)


I once worked on a cross-compiler that ran on a 16-bit-integer machine
but produced code for a 32-bit-integer machine. Integer constants
smaller than 32k were converted to binary, but we left larger ones in
text form until the assembly pass. Users weren't allowed to declare
arrays of more than 32k elements... [That compiler also left floating
point constants in text form, mainly for accuracy reasons: the
machines' floating point formats differed.]


--
tom lane
Internet: tgl@zog.cs.cmu.edu
UUCP: <your favorite internet/arpanet gateway>!zog.cs.cmu.edu!tgl
BITNET: tgl%zog.cs.cmu.edu@cmuccvma
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.