Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-05

LongWord

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Carsten Bager

I have written a small demo program that gives a runetime error when it runs.
Is it the compiler or is it me?

Regards carsten

---- The program ------------------------------------------------------------
program word32test;
{$RANGECHECKS ON}
{$OVERFLOWCHECKS ON}
{$S+ STACK CHECKING ON}
{$SMARTLINK ON}
{$TYPEINFO ON}
{$LONGSTRINGS OFF}
var
  a,b,c:longWord;
Begin
  a:=10;
  b:=5;
  writeLn('a=',a,'  b=',b);
  c:= a - b;
  writeLn('Resultat : ',c);
End.
--- The program output --------------------------
$ ./word32test
a=10  b=5
Runtime error 215 at $000081CC
  $000081CC  main,  line 17 of word32test.pp
  $000080F4

---- The compiler output --------------------------------

./makearm.shFpc/Pas/Linux/Test/Word32 #
+---------------------------------+
| CFG file ver. 1.00 d. 19/9-2006 |
+---------------------------------+
+---------------------------------+
| Cross compiling for ARM 9 Linux |
+---------------------------------+
+--------------+
| Standard lib |
+--------------+
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.0.4 [2006/08/29] for arm Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for ARM
Compiling word32test.pp
Assembling word32test
Assembling with smartlinking word32test
/Fpc/ArmBin/ar: creating libpword32test.a
Linking word32test
19 Lines compiled, 0.5 sec
Med venlig hilsen
Carsten Bager

BEAS A/S
Brørupvænget 10
DK-7650 Bøvlingbjerg
Tlf. : +45 9788 5222 Fax : +45 9788 5434
www.beas.dk

Reply by email

Daniël Mantione
to Jonas Maebe

Op Mon, 7 May 2007, schreef Jonas Maebe:

Show quoted text 9 lines
On 7 mei 2007, at 14:15, Carsten Bager wrote: > I have written a small demo program that gives a runetime error when it > runs. > Is it the compiler or is it me? See http://www.freepascal.org/mantis/view.php?id=8321 for a long discussion on this topic.

10 - 5 = 5

This is a different issue; 10-5 should not overflow regardless of the type that is used for the calculation.

Daniël

Reply by email

Carsten Bager
to Jonas Maebe: See http://www.freepascal.org/mantis/view.php?id=8321 for a long discussion on this topic.
> I have written a small demo program that gives a runetime error See http://www.freepascal.org/mantis/view.php?id=8321 for a long discussion on this topic.

I do not think that the discussion covers my case, all my numbers are positive and the result is positive.

I have just tried the example with the 386 linux compiler it returns 5 as one would expect.

-------------------------------
./make386.shFpc/Pas/Linux/Test/Word32 #
+---------------------------------+
| CFG file ver. 1.00 d. 19/9-2006 |
+---------------------------------+
+--------------------------+
| Compiling for I386 Linux |
+--------------------------+
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.0.4 [2006/08/20] for i386 Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for i386
Compiling word32test.pp
Linking word32test
19 Lines compiled, 0.4 sec

-------------------------------------------------

./word32testFpc/Pas/Linux/Test/Word32 #
a=10 b=5
Resultat : 5
Med venlig hilsen
Carsten Bager

BEAS A/S
Brørupvænget 10
DK-7650 Bøvlingbjerg
Tlf. : +45 9788 5222 Fax : +45 9788 5434
www.beas.dk

Reply by email

Bernd Mueller
to Jonas Maebe: See http://www.freepascal.org/mantis/view.php?id=8321 for a long discussion on this topic.

Jonas,

Show quoted text 9 lines
On 7 mei 2007, at 14:15, Carsten Bager wrote: > I have written a small demo program that gives a runetime error when it > runs. > Is it the compiler or is it me? See http://www.freepascal.org/mantis/view.php?id=8321 for a long discussion on this topic.

I think I have hit a similar case with the following code:

{$mode objfpc}{$H+}
program test; { FPC 2.0.4}
var
    w: Word;
begin
    w:= 5555;
    if lo(w)  lo(w + (5 - 5)) then
       writeln('This is a little bit unexpected');
end.

What would you suggest as a "workaround"? Using the mod operator?

Regards, Bernd.

Reply by email

Jonas Maebe
to Bernd Mueller
Bernd Mueller wrote 15 lines
> See http://www.freepascal.org/mantis/view.php?id=8321 for a long > discussion on this topic. I think I have hit a similar case with the following code: {$mode objfpc}{$H+} program test; { FPC 2.0.4} var w: Word; begin w:= 5555; if lo(w) lo(w + (5 - 5)) then writeln('This is a little bit unexpected'); end. What would you suggest as a "workaround"? Using the mod operator?

Yes, or using byte()/word(), or typecasting the result of the calculation. The result of lo/hi depends on the type of the expression.

Jonas

Reply by email

Carsten Bager
to Daniël Mantione: Op Mon, 7 May 2007, schreef Jonas Maebe: 10 - 5 = 5 This is a different issue; 10-5…
10 - 5 = 5 This is a different issue; 10-5 should not overflow regardless of the type that is used for the calculation. Daniël

I tried to compile and run with the
2.1.3 compiler (arm and i386)
Both executables did run without runtime errors but the compilers gave a warning.

The same program compiled with a Delphi7 Compiler does not give any warnings or errors.

Carsten

--------------------------- Arm Compiler output ------------------------------ linux-bh36:/Fpc/Pas/Linux/Test/Word32 # ./makearm.sh +---------------------------------+
| CFG file ver. 1.00 d. 19/9-2006 |
+---------------------------------+
+---------------------------------+
| Cross compiling for ARM 9 Linux |
+---------------------------------+
+--------------+
| Standard lib |
+--------------+
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.1.3 [2007/03/22] for arm Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for ARM
Compiling word32test.pp
word32test.pp(17,12) Warning: Type size mismatch, possible loss of data / range check error
Assembling word32test
Assembling with smartlinking word32test
/Fpc/ArmBin/ar: creating libpword32test.a
Linking word32test
19 lines compiled, 1.1 sec
1 warning(s) issued
2 hint(s) issued

-------------------- I386 Compiler Output ---------------------------------------- linux-bh36:/Fpc/Pas/Linux/Test/Word32 # ./make386.sh +---------------------------------+
| CFG file ver. 1.00 d. 19/9-2006 |
+---------------------------------+
+--------------------------+
| Compiling for I386 Linux |
+--------------------------+
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.1.3 [2007/03/22] for i386 Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling word32test.pp
word32test.pp(17,12) Warning: Type size mismatch, possible loss of data / range check error
Linking word32test
19 lines compiled, 0.3 sec
1 warning(s) issued
2 hint(s) issued

--------- The Program -----------------------------------------
program word32test;
{$RANGECHECKS ON}
{$OVERFLOWCHECKS ON}
{$S+ STACK CHECKING ON}
{$TYPEINFO ON}
{$LONGSTRINGS OFF}
var
  a,b,c:longWord;
Begin
  a:=10;
  b:=5;
  writeLn('a=',a,'  b=',b);
  c:= a - b;
  writeLn('Resultat : ',c);
End.

Reply by email