Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
From: Chris Ferrall
Subject: range check 32-bit and 64-bit
Date: 9 Apr 2007, 18:04:52
The following program behaves differently under 32-bit and 64-bit
compilation. In 64-bit the "max()" function returns a large integer
when a value is sent out of bounds (output not shown). The point of the
max() is to keep a value from going out of bounds. This problem does
not occur in 32-bit code. To make sure that range checking was on in
both cases I set "a" out of range after the max().
Is this a feature of the cpu option? And/or is there a more robust way
of keeping within range?
Thanks for any help.
P.S. I've already received the following response from Frank.
> I'm not using a 64 bit machine myself, so I can only speculate. I
> hope Waldek can say more about it.
>
> I think the problem might be that GPC treats "arange" internally as
> an unsigned type (i.e., as a subrange of "Cardinal", not "Integer")
> and on the 64 bit machine performs the "a - 1" unsigned which causes
> the range error. (On the 32 bit machine it can do it in LongestInt
> which covers the range of "Cardinal" as well as negative values, but
> on 64 bit, it currently doesn't support larger integer types. This
> might explain the different behaviour.)
>
> Of course, this is a GPC bug as, according to ISO, your program is
> perfectly valid (given a suitable definition of "Max" which isn't
> part of ISO).
>
> So the bugfix might be to make subrange types signed when the range
> allows (which would always be the case in valid ISO programs).
>
> Frank
--------------------
program test(input,output);
type arange = 0..5;
var a,b : arange;
begin
a:= 0;
b := max(a-1,0); /* keep b in range */
writeln('here ',b,' now really go out of range ');
a := b-1; /* take a out of range to make sure
range checking is on */
writeln('there ',a);
end.
--------------------
Output
32-bit:
here 0 now really go out of range
a.out: value out of range (error #300 at 180e3)
64-bit
a.out: value out of range (error #300 at 100009d2b)
32-bit compilation
gpc maxtest.pas
64-bit
gpc $g64pth $m64opt maxtest.pas
where $m64opt= "-mcpu=ultrasparc3 -m64"
---------------------
Here is the version output
hpc1014@sfnode0$ gpc -v
Reading specs from
/opt/gpc/20051104/lib/gcc/sparc-sun-solaris2.10/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=/opt/gpc/20051104
--enable-languages=pascal
Thread model: posix
gpc version 20051104, based on gcc-3.4.3
-- Chris
Christopher Ferrall <http://econ.queensu.ca/%7Eferrall/>
Associate Professor of Economics
Department of Economics <http://www.econ.queensu.ca>
Queen's University <http://www.queensu.ca>
Kingston, Ontario
CANADA K7L 3N6 ferrallc AT post.queensu.ca
Mackintosh-Corry Rm A519
ph: 613-533-6658
fx: 613-533-6668
Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.
Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.
This page was created by Crystal 0.999 (Linux 2.4.27/i686).