Node: Data Types in BP and GPC, Next: BP Procedural Types, Previous: User-defined Operators in GPC, Up: Borland Pascal
Borland Pascal | GNU Pascal | Bits (1) | Signed
|
ShortInt | ByteInt | 8 | yes
|
Integer | ShortInt | 16 | yes
|
LongInt | Integer | 32 | yes
|
Comp | LongInt, Comp | 64 | yes
|
Byte | Byte | 8 | no
|
Word | ShortWord | 16 | no
|
n/a | Word | 32 | no
|
n/a | LongWord | 64 | no
|
(1) The size of the GNU Pascal types may depend on the platform. The sizes above apply to 32 bit platforms, including the IA32.
If you care for types with exactly the same size as in Borland
Pascal, take a look at the System
unit and read its comments.
You can get the size of a type with SizeOf
in bytes (like in
Borland Pascal) and with BitSizeOf
in bits, and you can
declare types with a specific size (given in bits), e.g.:
program IntegerSizeDemo; type MyInt = Integer attribute (Size = 42); { 42 bits, signed } MyWord = Word attribute (Size = 2); { 2 bits, unsigned, i.e., 0 .. 3 } MyCard = Cardinal attribute (Size = 2); { the same } HalfInt = Integer attribute (Size = BitSizeOf (Integer) div 2); { A signed integer type which is half as big as the normalInteger
type, regardless of how bigInteger
is on any platform the program is compiled on. } begin end.
System
unit provides
conversion routines for it). GNU Pascals's Real
type has 8
bytes on the IA32 and is the same as Double
. In addition
there are alternative names for real types:
Borland Pascal | GNU Pascal
|
Single | Single, ShortReal
|
Real | n/a (1)
|
Double | Double, Real
|
Extended | Extended, LongReal
|
Comp | LongInt, Comp (see above)
|
(1) But see BPReal
, RealToBPReal
and
BPRealToReal
in GPC's System
unit.
Abs
, Sqr
, SqRt
,
Exp
, Ln
, Sin
, Cos
, ArcTan
.
type MyRec = record f, o, oo: Boolean; Bar: Integer end;has 8 bytes, not 7. Use the
--pack-struct
option or declare
the record as packed
to force GPC to pack it to 7 bytes.
However, note that this produces somewhat less efficient code on the
IA32 and far less efficient code on certain other processors.
Packing records and arrays is mostly useful only when using large
structures where memory usage is a real concern, or when reading or
writing them from/to binary files where the exact layout matters.