Lazarus

Programming => General => Topic started by: frederic on January 12, 2019, 03:05:43 pm

Title: longint in delphi and int32 in fpc lazarus
Post by: frederic 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
Title: Re: longint in delphi and int32 in fpc lazarus
Post by: lucamar 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.
Title: Re: longint in delphi and int32 in fpc lazarus
Post by: Thaddy 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?
Title: Re: longint in delphi and int32 in fpc lazarus
Post by: frederic 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
   
Title: Re: longint in delphi and int32 in fpc lazarus
Post by: lucamar 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.
Title: Re: longint in delphi and int32 in fpc lazarus
Post by: marcov 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)
TinyPortal © 2005-2018