|Checking size of variables email@example.com (Thomas Christensen) (2005-05-16)|
|Re: Checking size of variables firstname.lastname@example.org (Karsten Nyblad) (2005-05-18)|
|Re: Checking size of variables DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-05-18)|
|Re: Checking size of variables email@example.com (2005-05-18)|
|Re: Checking size of variables firstname.lastname@example.org (2005-05-18)|
|Re: Checking size of variables email@example.com (Peter \Firefly\Lund) (2005-08-07)|
|From:||firstname.lastname@example.org (Henry Spencer)|
|Date:||18 May 2005 12:17:12 -0400|
|Organization:||SP Systems, Toronto, Canada|
|Posted-Date:||18 May 2005 12:17:12 EDT|
Thomas Christensen <email@example.com> wrote:
>For example. If a user declares a variable as an "int" in the source
>code, and assigns it some 50 digit number (or any number, exceeding
>the size of an int).
>Is this sort of error detected by the lexer or by the type checker, or ?
Most likely it would happen in one of four ways:
+ The scanner/lexer, trying to convert the number to an internal
representation (either that of the type implied by the form of the
constant, or a worst-case temporary internal type), finds it won't fit.
+ The type checker, trying to determine the type of the constant, finds
that the largest possible integer type isn't big enough.
+ The type checker successfully assigns the constant a type, but then
finds that it's not assignment-compatible with the variable, because the
language doesn't have an implicit narrowing conversion.
+ Either the type checker, or some later phase attempting to evaluate
expressions at compile time, notices that the implicit narrowing
conversion would inevitably overflow.
It's also possible for the compiler to accept the code, with the overflow
caught only at run time.
And in sloppy languages like C, it's quite possible for this to be valid
code, or invalid code that the implementation is not required to catch.
"Think outside the box -- the box isn't our friend." | Henry Spencer
-- George Herbert | firstname.lastname@example.org
Return to the
Search the comp.compilers archives again.