Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648

glen herrmannsfeldt <gah@ugcs.caltech.edu>
2 Feb 2006 11:34:02 -0500

          From comp.compilers

Related articles
[3 earlier articles]
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 jm@bourguet.org (Jean-Marc Bourguet) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 gneuner2@comcast.net (George Neuner) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 rivers@dignus.com (Thomas David Rivers) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 david@tribble.com (David R Tribble) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 henry@spsystems.net (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-02-02)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-02-02)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 david@tribble.com (David R Tribble) (2006-02-03)
| List of all articles for this month |
From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: 2 Feb 2006 11:34:02 -0500
Organization: Compilers Central
References: 06-01-131
Keywords: lex, arithmetic, C
Posted-Date: 02 Feb 2006 11:34:01 EST

Edsko de Vries wrote:


> I have a question regarding lexical analysis. I recently came across a
> bug in our lexical analyser in phc (www.phpcompiler.org), that I am
> unsure how to solve. This is the problem: our current definition for
> integer constant looks something like


(snip)


> This works fine, with the sole exception of the number "-2147483648".
> The problem is, of course, overflow: -2147483648 is a valid negative
> number (assuming 32-bit numbers), but the integer 2147483648 is _not_ a
> valid positive number. Thus, the above method of dealing with "-" as a
> unary operator breaks down.


(snip)


Look at the language definition. C allows only positive constants
and unary operators, as you say, though a constant expression might
have the value -2147483648.


Fortran allows only positive constants in expressions, but optionally
signed constants in DATA statements. It might not be required, but I
believe most compilers will allow the maximum negative number in a DATA
statement.


-- glen


Post a followup to this message

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