Author Topic: QWord in Pascal : Int64 or Uint64 ?  (Read 222 times)

jpt

  • Posts: 109
QWord in Pascal : Int64 or Uint64 ?
« on: 8 Dec '22 - 16:33 »
Hi !

Strange behaviour of QWord in Lazarus (Pascal)...

Found in bass.h for C++ :
Code: [Select]
typedef uint64_t QWORD;
Found in bass.pas for Pascal :
Code: [Select]
type
  QWORD = Int64;
Where is the truth ?

In the FPC/Lazarus help one may read
Code: [Select]
Type                        Range           Size in bytes
Int64 -9223372036854775808 .. 9223372036854775807 8
QWord              0..18446744073709551615              8

Have a look at https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-260003.1.1, table 3.2


Let me say that in /usr/share/fpcsrc/3.2.2/rtl/inc/systemh.inc one may read
Code: [Select]
Type
  { The compiler has all integer types defined internally. Here
    we define only aliases }
  DWord    = LongWord;
  Cardinal = LongWord;
  Integer  = SmallInt;
  UInt64   = QWord;

So, in fine, something's wrong in bass.pas ?
Thanks,

Ian @ un4seen

  • Administrator
  • Posts: 25047
Re: QWord in Pascal : Int64 or Uint64 ?
« Reply #1 on: 8 Dec '22 - 17:28 »
Strictly speaking, UInt64 would be the correct translation of QWORD, but I don't think it'll generally make a big difference if Int64 is used instead. Still, I'm not sure why UInt64 wasn't used in BASS.PAS. Perhaps Int64 was introduced in an earlier Delphi version than UInt64?

Falcosoft

  • Posts: 134
Re: QWord in Pascal : Int64 or Uint64 ?
« Reply #2 on: 8 Dec '22 - 19:42 »
Strictly speaking, UInt64 would be the correct translation of QWORD, but I don't think it'll generally make a big difference if Int64 is used instead. Still, I'm not sure why UInt64 wasn't used in BASS.PAS. Perhaps Int64 was introduced in an earlier Delphi version than UInt64?
Yes, Int64 has been available from Delphi 4 while real unsigned UInt64 was introduced much later in Delphi 2007.
https://stackoverflow.com/questions/36070384/starting-with-which-version-of-delphi-is-uint64-not-just-available-but-also-actu
« Last Edit: 8 Dec '22 - 19:49 by Falcosoft »

jpt

  • Posts: 109
Re: QWord in Pascal : Int64 or Uint64 ?
« Reply #3 on: 9 Dec '22 - 10:19 »
Hello,
... I don't think it'll generally make a big difference if Int64 is used instead.
Oh, just 8 missing bytes, something like 9 223 372 036 854 775 808...  :o

Falcosoft

  • Posts: 134
Re: QWord in Pascal : Int64 or Uint64 ?
« Reply #4 on: 9 Dec '22 - 12:03 »
Oh, just 8 missing bytes, something like 9 223 372 036 854 775 808...  :o
Both Int64 and UInt64 are 8-byte long. So you do not miss any bytes. You only miss half of the positive range (namely $8000000000000000 - $FFFFFFFFFFFFFFFF will mean negative numbers in case of Int64). I think Ian was talking about that if you do not do arithmetic operations Int64 can preserve all the information you need for pointers, error codes etc.

Ian @ un4seen

  • Administrator
  • Posts: 25047
Re: QWord in Pascal : Int64 or Uint64 ?
« Reply #5 on: 9 Dec '22 - 15:28 »
With the "I don't think it'll generally make a big difference" comment, I just meant that it's unlikely that the full 64 bits (rather than 63) will ever be needed to hold a BASS return value or parameter, eg. the length or position of a stream. Note that the QWORD type is only really used for lengths and positions in the BASS API.