Recent

Author Topic: Int64 and QWord not ordinal types?  (Read 1097 times)

DavidL

  • New Member
  • *
  • Posts: 20
Int64 and QWord not ordinal types?
« on: May 01, 2026, 03:27:16 pm »
I'm sure this has been covered before (likely ad nauseam) but forum searches turned up nothing helpful.  Why, in 2026, are Int64 and QWord not ordinal types?  What with all the "convenience clutter" that's been jammed into FPC over the years wouldn't this have to be considered a truly fundamental oversight?

cdbc

  • Hero Member
  • *****
  • Posts: 2812
    • http://www.cdbc.dk
Re: Int64 and QWord not ordinal types?
« Reply #1 on: May 01, 2026, 03:35:39 pm »
Hi
That depends on your machine's bitness -- 32bit: ordinals are up to LongWord, 64bit: ordinals are up to QWord.
PtrInt & PtrUInt are aliases for the platforms /pointersized/ integers, i.e. they are 4 bytes on 32bit & 8 bytes on 64bit
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Thaddy

  • Hero Member
  • *****
  • Posts: 19262
  • Glad to be alive.
Re: Int64 and QWord not ordinal types?
« Reply #2 on: May 01, 2026, 06:57:52 pm »
It is just like using compiling for 32 bit on a 64 bit platform is a very sane thing, if one would rephrase your 2026 remark...
Because you only run into that if you compile for 32 bit on a 64 bit platform.
« Last Edit: May 01, 2026, 06:59:24 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

DavidL

  • New Member
  • *
  • Posts: 20
Re: Int64 and QWord not ordinal types?
« Reply #3 on: May 02, 2026, 01:55:24 am »
It is just like using compiling for 32 bit on a 64 bit platform is a very sane thing, if one would rephrase your 2026 remark...
Because you only run into that if you compile for 32 bit on a 64 bit platform.

Sorry but none of that makes any sense and doesn't address the actual question of "why?".  Everything that can be done with a 16-bit ordinal can be done with a 32-bit ordinal irrespective of the compilation target's bit width, right?  It follows that everything that can be done with a 32-bit ordinal should be doable with a 64-bit ordinal, again irrespective of the compilation target's bit width.  The documentation's unhelpful "some Pascal constructs will not work with these two integer types." doesn't bother to list the faulty constructs, so one is just left to wander in the wilderness.

440bx

  • Hero Member
  • *****
  • Posts: 6528
Re: Int64 and QWord not ordinal types?
« Reply #4 on: May 02, 2026, 02:13:26 am »
Aside from all the mathematical properties an ordinal type must comply with, in programming, there is a usually unspoken/unstated rule that an ordinal type must fit entirely in a CPU register.

Because of this, in 64 bit programming, an int64 or a qword is considered an ordinal type whereas neither of those two types are considered ordinals in 32 bit programming. 

For instance, in FPC, a "for" loop can use an int64 or qword as a loop index in 64 bit but cannot in 32 bit.  The reason ?... simply register size, neither one of them fits in 32 bits which is the register width of a 32 bit architecture.


FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 19262
  • Glad to be alive.
Re: Int64 and QWord not ordinal types?
« Reply #5 on: May 02, 2026, 08:11:07 am »
It is also consistent over all supported cross-compilers:
from 8bit registers upto 64 bit register size, the maximum size of an ordinal equals the register size. As with most real compilers, btw.
objects are fine constructs. You can even initialize them with constructors.

DavidL

  • New Member
  • *
  • Posts: 20
Re: Int64 and QWord not ordinal types?
« Reply #6 on: May 02, 2026, 02:46:43 pm »
Aside from all the mathematical properties an ordinal type must comply with, in programming, there is a usually unspoken/unstated rule that an ordinal type must fit entirely in a CPU register.

Because of this, in 64 bit programming, an int64 or a qword is considered an ordinal type whereas neither of those two types are considered ordinals in 32 bit programming. 

For instance, in FPC, a "for" loop can use an int64 or qword as a loop index in 64 bit but cannot in 32 bit.  The reason ?... simply register size, neither one of them fits in 32 bits which is the register width of a 32 bit architecture.

This explains it completely, thanks - an "unspoken/unstated rule" established by an arbitrary, lazy implementation decision and calcified by never being corrected, got it.   %)

Thausand

  • Hero Member
  • *****
  • Posts: 560
Re: Int64 and QWord not ordinal types?
« Reply #7 on: May 02, 2026, 02:53:34 pm »
This explains it completely, thanks - an "unspoken/unstated rule" established by an arbitrary, lazy implementation decision and calcified by never being corrected, got it.   %)
... and all other programing language. It not fpc/pascal specific.
A docile goblin always follow HERMES.md

440bx

  • Hero Member
  • *****
  • Posts: 6528
Re: Int64 and QWord not ordinal types?
« Reply #8 on: May 02, 2026, 06:12:03 pm »
... and all other programing language. It not fpc/pascal specific.
Correct and, it is very important to point this out because a 1024 bit integer type is still, mathematically speaking, an ordinal but, using that as a loop counter in a 64 bit architecture would be a performance disaster (not to mention an 8 bit one.)

The performance alone is enough to justify limiting ordinals to what fits in a register and that's not the only reason.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1594
    • Lebeau Software
Re: Int64 and QWord not ordinal types?
« Reply #9 on: May 03, 2026, 10:49:42 pm »
... and all other programing language. It not fpc/pascal specific.

Not ALL programming languages. Many languages handle 64bit ordinals in 32bit environments just fine. What a LANGUAGE can handle and what a CPU can handle are two separate things. 64bit ordinal operations can be implemented using 32bit commands if needed. Not being able to handle a 64bit ordinal in a for loop is a limitation of a compiler implementation, not a CPU.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

440bx

  • Hero Member
  • *****
  • Posts: 6528
Re: Int64 and QWord not ordinal types?
« Reply #10 on: May 03, 2026, 11:08:07 pm »
Not ALL programming languages. Many languages handle 64bit ordinals in 32bit environments just fine. What a LANGUAGE can handle and what a CPU can handle are two separate things. 64bit ordinal operations can be implemented using 32bit commands if needed. Not being able to handle a 64bit ordinal in a for loop is a limitation of a compiler implementation, not a CPU.
True, the choice is a compiler implementation limitation.  Do you have an example of a 32 bit compiler that considers 64 bit integers to be ordinals, by that I mean, does not impose some limitations on the usage of the 64 bit ordinal that aren't also imposed on the 32 bit version ?  I ask because, of the top of my head, I cannot think of one.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

creaothceann

  • Sr. Member
  • ****
  • Posts: 375
Re: Int64 and QWord not ordinal types?
« Reply #11 on: May 03, 2026, 11:57:03 pm »
an arbitrary, lazy implementation decision

32-bit code can emulate 64-bit registers (e.g. via ADC on x86), but for each one you still need another register to store the upper half. You'll quickly have to spill variables to the stack.

This is a complete non-issue on 64-bit CPUs. So the question is, why haven't you adjusted the project settings to use a 64-bit CPU target? 64-bit CPUs have been available for mainstream computers since 2003 (x86-64) and 2011 (AArch64). Perhaps this should be the default for 64-bit Lazarus projects, and 32-bit builds shouldn't even be offered.

Khrys

  • Sr. Member
  • ****
  • Posts: 456
Re: Int64 and QWord not ordinal types?
« Reply #12 on: May 04, 2026, 07:57:52 am »
Do you have an example of a 32 bit compiler that considers 64 bit integers to be ordinals, by that I mean, does not impose some limitations on the usage of the 64 bit ordinal that aren't also imposed on the 32 bit version ?

AVR-GCC handles 64-bit integers just fine, and Rust's built-in 128 bit integer types are perfectly usable for e.g. loop indices.

So the question is, why haven't you adjusted the project settings to use a 64-bit CPU target? 64-bit CPUs have been available for mainstream computers since 2003 (x86-64) and 2011 (AArch64).

Legacy dependencies perhaps?

nanobit

  • Full Member
  • ***
  • Posts: 191
Re: Int64 and QWord not ordinal types?
« Reply #13 on: May 04, 2026, 09:32:51 am »
Legacy dependencies perhaps?

True, unported source code, libraries, "extended" floating point.
Not every app needs the 64 bit address space, and 32-bit apps always have been able to use all virtual memory outside of the 32-bit space, by createFileMapping( -1, ...), which is useful for keeping large data (eg. bitmaps) in RAM.

creaothceann

  • Sr. Member
  • ****
  • Posts: 375
Re: Int64 and QWord not ordinal types?
« Reply #14 on: May 04, 2026, 12:24:31 pm »
Not every app needs the 64 bit address space, and 32-bit apps always have been able to use all virtual memory [...]

Even so, 64-bit code has access to many more registers. That alone is a huge speed-up.

If there's perhaps one thing missing that 64-bit Free Pascal could implement, it's a mode in which "pointer" is 32 bits in size.

 

TinyPortal © 2005-2018