[fpc-pascal] History of the Cardinal data type?

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Wed Mar 30 03:06:17 CEST 2016

Thanks Marco, interesting history lesson. ;-)

On 2016-03-29 22:16, Marco van de Voort wrote:
> Moreover since shorter types are not always faster, I think it is better to
> forget all this, and in new code use INTEGER for the variable types, where
> range doesn't matter (much) and (u)int<xx> for the rest.

I already tend to use Integer for most code, but the code I'm currently
working on has an extensive amount of record structures used to read a
complex binary data file. The documentation for the data file is
primarily in C and uses types like SHORT, USHORT, LONG etc. These
translated easily to the SmallInt, Word, LongWord etc types, but as
already mentioned in can get confusing keeping track of valid ranges and
occasional programmer error.

So I definitely see the benefit in using (U)Int<xx> style data types.
They are a lot more obvious [to the programmer] regarding data ranges
and byte size.

I was just surprised not to find any reference to them in the FPC
documentation. I already made personal annotations about them so as not
to be forgotten, but I think it will be beneficial to have them
officially included in the FPC Language Reference too. After all, they
are part of the System unit.

Here is an example of the annotation I added to my own documentation.

 Type                         Range                   Size in bytes
 Int8   = ShortInt        -128 .. 127                             1
 Int16  = SmallInt      -32768 .. 32767                           2
 Int32  = LongInt  -2147483648 .. 2147483647                      4
 Int64    -9223372036854775808 .. 9223372036854775807             8

 UInt8  = Byte               0 .. 255                             1
 UInt16 = Word               0 .. 65535                           2
 UInt32 = Cardinal           0 .. 4294967295                      4
 UInt64 = QWord              0 .. 18446744073709551615            8

  - Graeme -

More information about the fpc-pascal mailing list