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
is this code correct?
by
LemonParty
[
Today
at 02:08:55 pm]
Pure Pascal LZ4, LZ5 and ...
by
LemonParty
[
Today
at 01:38:07 pm]
Anubis's website security...
by
Marc
[
Today
at 11:29:50 am]
Linking a PortAudio stati...
by
Thaddy
[
Today
at 10:52:31 am]
TShellTreeView TopItem
by
Paolo
[
Today
at 10:07:58 am]
Temp file CGI00000.TMP
by
Thaddy
[
Today
at 09:32:16 am]
Nothing but chaotic attem...
by
LeP
[
Today
at 09:02:05 am]
Feature suggestion - repe...
by
paweld
[
Today
at 07:38:10 am]
search via TSQLQuery
by
paweld
[
Today
at 07:28:41 am]
Amigo programming languag...
by
paxscript
[
Today
at 05:49:02 am]
Klondike solitaire Part 2
by
valdir.marcos
[
Today
at 03:50:07 am]
PopupMenu on dock menu
by
systemgvp
[
Today
at 03:35:31 am]
Creation of LAMW [NoGUI] ...
by
neuro
[
Today
at 01:06:41 am]
wildcard utilities list
by
mas steindorff
[
Today
at 12:22:21 am]
Can I enter MySQL prompt ...
by
tooknox
[May 16, 2026, 10:05:08 pm]
FPC Unleashed (inline var...
by
440bx
[May 16, 2026, 09:30:19 pm]
Artificial Intelligence a...
by
LeP
[May 16, 2026, 06:15:13 pm]
P.I.S.S. a PlugIn-framewo...
by
cdbc
[May 16, 2026, 04:39:24 pm]
Read/Parse PDB file to ge...
by
LeP
[May 16, 2026, 04:12:58 pm]
Dark Theme
by
NickyTi
[May 16, 2026, 04:11:34 pm]
StringGrid: which is "cur...
by
jamie
[May 16, 2026, 04:10:34 pm]
Can /my/ AI help me with ...
by
microxa
[May 16, 2026, 03:51:48 pm]
Database files reader. Di...
by
valdir.marcos
[May 16, 2026, 02:33:27 pm]
AdvancedHTTPServer: A Go-...
by
valdir.marcos
[May 16, 2026, 02:32:51 pm]
Pls support Double Comman...
by
Tomxe
[May 16, 2026, 11:52:40 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Can't wrap around (Read 443 times)
LemonParty
Sr. Member
Posts: 468
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: 89
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: 19156
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
Sr. Member
Posts: 468
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: 12345
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
Sr. Member
Posts: 468
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
Sr. Member
Posts: 468
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