Le 27/04/2013 20:47, Waldek Hebisch a écrit :
BTW2: In Pascal expressions are normally computed using "full" types and range restrictions only play role for assignment. The "equivalent" code will perform assignment to control variable only when body will be execute.
This is how gpc should work, but not how it actually works with current gpc version (20070904 with either 3.4.5 or 4.3.5 gcc backends). To check a suggestion of Florian Kaempfl on the fpc bug list about signed/unsigned underlying type, I changed ttlow to -1 to be sure that the underlying "full" type is integer, not cardinal, and put ttop - 2 for the upper limit of the loop, which is out of bounds for assignment, but not for the underlying integer type, giving ------------------------------------------------------------------ program range ( output );
const ttlow = -1; tthigh = 800;
type ttx = ttlow .. tthigh;
var ttop : ttx;
procedure p ( low : ttx ); var high : ttx; begin for high := low to ttop - 2 do writeln( high, ' ', low, ' ', ttop, ' ', ttop - 1 ); end;
begin ttop := 0; p( 1 ); end. -------------------------------------------------------------------- I obtain the following out of bounds message:
MinGW: C:\Lombardi\mingw\gpc\bugRange>range range: value out of range (error #300 at 40131d)
So the assignment of high:=ttop-2 has been done, even if the loop is not executed.
Maurice