Recent

Author Topic: longint in delphi and int32 in fpc lazarus  (Read 2713 times)

frederic

  • Full Member
  • ***
  • Posts: 226
longint in delphi and int32 in fpc lazarus
« on: January 12, 2019, 03:05:43 pm »
dear specialits

in thread "Re: Tfilestream sizeof  and position"we had an discussion on how to construct a filestream file with a consequent memory size of the data in the file  in order to ease the searching in the file.

The conclusion was that all data should be converted to int32 (4 bytes)

Now it happens that i am working in delphi6 and i want to construct the same file design there  with the idea to read these  files in fpc lazarus later.
However in delphi6 i get an  error message that int32 is unknown and that i should use normal integer or longint ( both have 4 bytes) .

My question is : when i use longint or integer as  data-size   in delphi  can i read the files then in lazarus 1.8.4  where i use int32 ?

frederic

lucamar

  • Hero Member
  • *****
  • Posts: 1060
Re: longint in delphi and int32 in fpc lazarus
« Reply #1 on: January 12, 2019, 03:39:56 pm »
Since they are basically the same and only the type name changes I would say: yes, you can.

Of course, you can also add your own type:
Code: Pascal  [Select]
  1. {$IFNDEF FPC}
  2.   type
  3.     Int32 = Integer;
  4. {$ENDIF}

Only problem you may have is in platforms with a different endianess than Intel but you can solve that with the endian-conversoin functions.
« Last Edit: January 12, 2019, 03:41:58 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/FPC 3.0.4 on:
(K)Ubuntu 12..16, Windows XP SP3 (Home/Prof.) and various DOS incarnations.

Thaddy

  • Hero Member
  • *****
  • Posts: 7610
Re: longint in delphi and int32 in fpc lazarus
« Reply #2 on: January 12, 2019, 03:47:51 pm »
http://wiki.freepascal.org/Integer

or better the manual:
https://freepascal.org/docs-html/ref/refsu4.html#x26-250003.1.1

So, although some platforms indeed define integer to an int32 (as per the above) this is not always the case, it is either 16 or 32 bit.
However a longint type is always a 32 bit type on all platforms.

That leaves no room for discussion. < grumpy  >:D >:D > since the manual explains all available integer types.

RTF,F,F,F,F,F,M
Why did you spoil my Saturday by not reading the manuals?
« Last Edit: January 12, 2019, 03:54:28 pm by Thaddy »
Ad Brexinitum (can't help it)

frederic

  • Full Member
  • ***
  • Posts: 226
Re: longint in delphi and int32 in fpc lazarus
« Reply #3 on: January 12, 2019, 04:08:24 pm »
thanks both of you

and......thaddy... i won't disturb you any longer, have very nice weekend

frederic
   

lucamar

  • Hero Member
  • *****
  • Posts: 1060
Re: longint in delphi and int32 in fpc lazarus
« Reply #4 on: January 12, 2019, 05:25:05 pm »
So, although some platforms indeed define integer to an int32 (as per the above) this is not always the case, it is either 16 or 32 bit.
However a longint type is always a 32 bit type on all platforms.

You're right, I should have used Int32 = LongInt but note that the OP refers to Delphi 6, which doesn't have an Int32 type but has both Integer and LongInt which in Delphi 6 are equivalent, so using either of them to save/load from a file created/treated in Lazarus (with Int32) is alright.

But yes, only LongInt is guaranteed to have always 32 bits.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/FPC 3.0.4 on:
(K)Ubuntu 12..16, Windows XP SP3 (Home/Prof.) and various DOS incarnations.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6806
Re: longint in delphi and int32 in fpc lazarus
« Reply #5 on: January 12, 2019, 05:34:24 pm »
(maybe if you import the windows unit? Anyway, int32 and variants became staple in afaik Delphi XE2, and FPC also added them, probably since 2.6.4 or 3.0 or so)