[fpc-pascal] Re: Code works on Linux x64 but not on Linux x86

Sven Barth pascaldragon at googlemail.com
Tue Feb 7 21:11:32 CET 2012


On 07.02.2012 20:32, Reinier Olislagers wrote:
> On 7-2-2012 19:48, Sven Barth wrote:
>> On 07.02.2012 17:12, Reinier Olislagers wrote:
>>>
>>> Code bombs at decoder.Read(a, readsize). readsize=0 according to
>>> debugger.
>>> readsize=cardinal; according to help "an unsigned 32-bit integer".
>>> However,
>>> http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#32.2F64_bit
>>>
>>> seems to imply Cardinal can vary between 32 bit and 64 bit.
>>>
>>> Is that the culprit or am I doing anyth else wrong?
> Thanks, Sven!
>
>> Does your stream contain at least 4096 bytes? According to the
>> documentation here
>> http://www.freepascal.org/docs-html/rtl/objects/tstream.read.html the
>> Read procedure does not perform any check.
> Yes, that should be the case, compressed size is 909094 bytes. The file
> uncompresses nicely with the bunzip2 executable.

Ok, then I don't know right now what the problem could be... sorry.

>> Also "Cardinal" is always 32-Bit wide. The only types that change
>> depending on bitness are "Pointer", "PtrUInt" and "PtrInt".
> Thanks.
> Let me verify if I understand correctly. The wiki article
> http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#32.2F64_bit
> says:
> FPC defines two types for this: PtrInt and PtrUInt. PtrInt is a 32bit
> signed integer on 32 bit platforms and a 64bit signed integer on 64bit
> platforms. The same for PtrUInt, but unsigned integer instead.
>
> Use for code that should work with Delphi and FPC:
>
> {$IFNDEF FPC}
> type
>    PtrInt = integer;
>    PtrUInt = cardinal;
> {$ENDIF}
>
>
> So in Delphi, presumably cardinal varies between 32 and 64 bit, while in
> FPC it is always 32 bit. Or am I interpreting this incorrectly?
>

Yes, you are interpreting this incorrectly. ;)

The code above was meant for older versions of Delphi which did not 
support 64-bit. There PtrInt and PtrUInt is not defined (newer versions 
since AFAIK Delphi 2007 definee NativeInt and NativeUInt instead which 
is supported in FPC 2.6.0 and 2.7.1 as well). Thus the code above simply 
defines PtrInt and PtrUInt in a way that works for non-64-Bit Delphi 
versions. In principle you might want to simply use NativeInt and 
NativeUInt to stay Delphi compatible and just define these two for older 
Delphi versions where that type does not exist yet (similiar to the 
above code for Ptr(U)Int).

Regards,
Sven



More information about the fpc-pascal mailing list