Integer Size on 64-Bit
Waldek Hebisch
hebisch at math.uni.wroc.pl
Fri Feb 14 20:10:03 CET 2014
Kevan Hashemi wrote:
>
> On Red Hat Linux 6.5 running on a 32-bit machine, I compile GPC to
> obtain a 32-bit Pascal compiler in which the integer type is 4 bytes
> long. I compile TclTk from sources and obtain an executable in which the
> C "int" type is 32 bits long. They work well together.
>
> On Red Hat Linux 6.5 running on a 64-bit machine, I compile GPC to
> obtain a 64-bit Pascal compiler in which the integer type is 8 bytes
> long. I compile TclTk from sources and obtain an executable in which the
> C "int" type is still 32 bits long. They do not work well together.
>
> I can edit my Pascal code to make all integer types a fixed length
> regardless of architecture. But I was wondering if there is a Pascal
> compiler directive that I can use to force the integer size to 32 bits
> on all platforms.
>
> Or perhaps there is a configure option when I compile GPC from its
> sources that will tell the compiler to make the integer type 32 bits.
For interfacing witg C GPC provides special types, for example
CInteger will match C 'int'. Maybe you should use them instead
of Integer?
You can not change size of true Pascal Integer. Changing it
would break binary compatiblity between code generated using
different options and would lead to more troubles than it
solves.
However, in Pascal you can define new type with name 'Integer'
so that your code will use the new type. For example:
type Integer = -2147483648..2147483647
gives type capable of holding 32-bit values, while
type Integer = CInteger
gives type which is compatible with C 'int'. You can minimize
changes to your code by puting this definition in a common module
used by all your files. If you really do not want to change
your files you can use a command line option which causes all
files to use given module (you need to look in the manual for details,
as I never used this option).
Note that after redefining Integer you may get type errors in
your code -- such error may indicate binary incompatibility
caused by the new size, so if you get any treat them seriously.
--
Waldek Hebisch
hebisch at math.uni.wroc.pl
More information about the Gpc
mailing list