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

Marco van de Voort marcov at stack.nl
Tue Mar 29 23:16:31 CEST 2016


In our previous episode, Graeme Geldenhuys said:
> But from your
> comments Cardinal has a long history in Pascal.

It is the base type of Pascal sucessor Modula 2. (well, in all caps, since
it is a case sensitive language)

GNU Pascal also uses it heavily, but their help
http://www.gnu-pascal.de/gpc/Cardinal.html seems to indicate it is not in
the Pascal standards.

But many dialects imported features from M2, like e.g. the unit system, and
it seems to be a common convention for it to be unsigned as in M2.  

But as always with extensions/backports, the exact definition is typically not specified. 

But usually it is some unsigned main type probably because in Modula2
INTEGER is the signed complement to basetype CARDINAL, so it makes sense to
keep them paired and reverse them in Pascal.  Combinations (SHORT, LONG etc)
exist too, some M2 dialects abbreviated CARDINAL combinations to -CARD like
LONGCARD, some keep it long as LONGCARDINAL.

All -word named types are OS dependent, and systematically wrong on 32+
systems.  This because the word=16-bit convention is a 16-bit DOS one, that
stuck because of evolution via win16 to win32/64.  Also the old conventions
of having a very big base type and subtype it as needed is a bit dated.

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.

>From a language design viewpoint I would add CARDINAL for unsigned integers
variable types, but since it has a fixed type history in Delphi, it is
better not to.  It isn't needed that much anyway, and for the most common
use, API interfacing fixed types or ctypes types are usually better.




More information about the fpc-pascal mailing list