Re: for-loops and subrange types
Maurice Lombardi <[email protected]>
| Newsgroups | gmane.comp.compilers.gpc |
|---|---|
| Message-ID | <[email protected]> |
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
--
Maurice Lombardi
Laboratoire Interdisciplinaire de Physique,
(ex Spectrometrie Physique)
Universite Joseph Fourier de Grenoble, BP87
38402 Saint Martin d'Heres Cedex FRANCE
Tel: 33 (0)4 76 51 47 51
Fax: 33 (0)4 76 63 54 95
mailto:[email protected]
_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc