Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
General
(Moderators:
FPK
,
Tomas Hajny
) »
Can't wrap around
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
TPlaysound problem Ubuntu...
by
jamie
[
Today
at 12:57:32 am]
Portable verion of FPC an...
by
Martin_fr
[
Today
at 12:26:26 am]
AArch64. Fast method to c...
by
jamie
[June 07, 2026, 11:45:12 pm]
[New Component] ExtTabCtr...
by
d7_2_laz
[June 07, 2026, 11:42:02 pm]
Call SetLength from assem...
by
runewalsh
[June 07, 2026, 09:20:21 pm]
embed .jpg file into .pp ...
by
SIRUS-VIRUS
[June 07, 2026, 08:23:35 pm]
Lazarus Main and Gnome/Wa...
by
zeljko
[June 07, 2026, 08:10:05 pm]
Release ray4laz 6.0
by
lazarusprogrammer
[June 07, 2026, 08:02:14 pm]
Where is Lazarus config
by
n7800
[June 07, 2026, 07:49:03 pm]
Auto-vectorization hint/w...
by
Ten_Mile_Hike
[June 07, 2026, 07:31:42 pm]
Knigo
by
Fred vS
[June 07, 2026, 07:10:46 pm]
Splitting Picture into Qu...
by
Dzandaa
[June 07, 2026, 06:16:22 pm]
Lazarus 4.99 - New featur...
by
Martin_fr
[June 07, 2026, 05:46:05 pm]
FPC Unleashed (inline var...
by
Thaddy
[June 07, 2026, 05:27:05 pm]
GDB 17 for Windows
by
Martin_fr
[June 07, 2026, 04:45:35 pm]
Hint not being shown
by
J-G
[June 07, 2026, 03:34:25 pm]
UnoLib - library in Pasca...
by
ackarwow
[June 07, 2026, 02:16:15 pm]
Very rough version of a s...
by
hedgehog
[June 07, 2026, 08:24:00 am]
water filling simulation
by
ADMGNS
[June 06, 2026, 09:54:50 pm]
Array of structure -> str...
by
Seenkao
[June 06, 2026, 09:44:44 pm]
TStringGrid Question
by
J-G
[June 06, 2026, 08:05:52 pm]
Benchmark: converting arr...
by
LemonParty
[June 06, 2026, 03:25:25 pm]
Read/Parse PDB file to ge...
by
marcov
[June 06, 2026, 02:48:12 pm]
[SOVLED]Curved text in La...
by
paweld
[June 06, 2026, 11:00:52 am]
Fast Canvas Library V1.05...
by
microxa
[June 06, 2026, 07:03:07 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Can't wrap around (Read 460 times)
LemonParty
Hero Member
Posts: 523
Can't wrap around
«
on:
May 02, 2026, 01:37:38 pm »
Hello.
I create this topic because of this problem
https://forum.lazarus.freepascal.org/index.php/topic,73945.msg581824.html#msg581824
.
I simplified the problem in this code:
Code: Pascal
[Select]
[+]
[-]
{$mode ObjFPC}{$H+}{$R-}
const
PRIME64_1
=
Uint64
(
11400714785074694791
)
;
PRIME64_2
=
Uint64
(
14029467366897019727
)
;
var
a
:
UInt64
;
begin
a
:
=
PRIME64_1
+
PRIME64_2
;
end
.
This code not compile with error:
Quote
(10,16) Error: Overflow in arithmetic operation
Desirable to have a wrap around of values PRIME64_1 and PRIME64_2 in this situation.
Checked in trunk and 3.0.4+dfsg-22 [2019/01/24] of FPC. In both gives an error. In Lazarus 4.4 this code compiles with no problem (at least topic starter say that).
Why it doesn't wrap around in pointed versions of compiler?
Logged
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11
Lutz Mändle
Jr. Member
Posts: 99
Re: Can't wrap around
«
Reply #1 on:
May 02, 2026, 02:39:14 pm »
With FPC 3.2.2 on Linux 64bit it doesn't work either.
It gives the same error (Error: Overflow in arithmetic operation).
Logged
Thaddy
Hero Member
Posts: 19245
Glad to be alive.
Re: Can't wrap around
«
Reply #2 on:
May 02, 2026, 02:56:08 pm »
This is only the case when the consts are untyped, because of the internal representation of untyped consts as signed types.
But this works:
Code: Pascal
[Select]
[+]
[-]
{$mode ObjFPC}{$H+}
const
PRIME64_1
:
Uint64
=
11400714785074694791
;
PRIME64_2
:
Uint64
=
14029467366897019727
;
var
a
:
UInt64
;
begin
a
:
=
PRIME64_1
+
PRIME64_2
;
end
.
«
Last Edit: May 02, 2026, 03:08:51 pm by Thaddy
»
Logged
objects are fine constructs. You can even initialize them with constructors.
LemonParty
Hero Member
Posts: 523
Re: Can't wrap around
«
Reply #3 on:
May 02, 2026, 04:06:16 pm »
Thank you for checking, Lutz Mändle.
Great Thaddy, I hope this will cure the problem.
Logged
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11
Martin_fr
Administrator
Hero Member
Posts: 12397
Debugger - SynEdit - and more
Re: Can't wrap around
«
Reply #4 on:
May 02, 2026, 04:16:41 pm »
Thaddy's example might want a {$WriteableConst off}
Or as a workaround:
Code: Pascal
[Select]
[+]
[-]
{$mode ObjFPC}{$H+}{$R-}
const
PRIME64_1
=
Uint64
(
11400714785074694791
)
;
PRIME64_2
=
Uint64
(
14029467366897019727
)
;
var
a
:
UInt64
;
begin
a
:
=
qword
(
pointer
(
PRIME64_1
)
+
PRIME64_2
)
;
end
.
I don't know, it might be worth opening an issue on this.
As for the example {$R-} is range checking. What should have been there is overflow checking {$Q-}. But that doesn't help either.
Logged
Ide Tools, Code completion and more
/
IDE cool features
/
Debugger Status
LemonParty
Hero Member
Posts: 523
Re: Can't wrap around
«
Reply #5 on:
May 03, 2026, 07:27:55 pm »
I can't for some reason create an issue on gitlab. Previously I was able to do that.
Can someone post this issue?
Logged
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11
LemonParty
Hero Member
Posts: 523
Re: Can't wrap around
«
Reply #6 on:
May 06, 2026, 01:56:28 pm »
I successfully created an issue in bugtracker.
Logged
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
General
(Moderators:
FPK
,
Tomas Hajny
) »
Can't wrap around
TinyPortal
© 2005-2018