Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!necntc!ima!compilers-sender From: Tom.Lane@ZOG.CS.CMU.EDU Newsgroups: comp.compilers Subject: Re: Who should convert literals to integers? Message-ID: <2299@ima.ima.isc.com> Date: 21 Aug 88 19:42:30 GMT Sender: compilers-sender@ima.ima.isc.com Reply-To: Tom.Lane@ZOG.CS.CMU.EDU Lines: 30 Approved: compilers@ima.UUCP In-Reply-To: Dick Dunn's netnews message of 17 Aug 88 23:45:36 GMT > 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: !zog.cs.cmu.edu!tgl BITNET: tgl%zog.cs.cmu.edu@cmuccvma -- Send compilers articles to ima!compilers or, in a pinch, to Levine@YALE.EDU Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | bbn}!ima Please send responses to the originator of the message -- I cannot forward mail accidentally sent back to compilers. Meta-mail to ima!compilers-request