Frank Heckenbach wrote:
Peter Gerwinski wrote:
I noticed a lot of confusion about Integer types in GNU Pascal.
So did I (read: I was confused in the beginning ;-). I was going to post something about it sometime anyway...
32 Integer Word [unsigned] int == long 64 LongInt LongWord [unsigned] long long
etc etc
You may be interested to know the answer given by Borland to the same problem in Delphi 2.0 when going from 16 bit to 32 bit system. The following is a cut out of the Delphi help (in french however):
-------------------------------------------------------------------
Les types entiers prédéfinis de Pascal Objet sont divisés en types fondamentaux et génériques. Les applications doivent utiliser les formats entiers génériques chaque fois que c'est possible, car cela entraîne de meilleures performances pour le processeur et le système d'exploitation. Les types entiers fondamentaux devraient n'être utilisés que lorsque l'intervalle réel et/ou le format de stockage sont importants pour l'application.
Types fondamentaux
Les types d'entiers fondamentaux sont :
Type Intervalle Format
Shortint -128 .. 127 Signé, 8 bits
SmallInt -32768 .. 32767 Signé, 16 bits
Longint -2147483648 .. 2147483647 Signé, 32 bits
Byte 0 .. 255 Non signé, 8 bits Word 0 .. 65535 Non signé, 16 bits
L'intervalle et le format des types fondamentaux sont indépendants du processeur et du système d'exploitation et ne changent pas avec les différentes implémentations de Pascal Objet.
Types génériques
Les types entiers génériques sont Integer et Cardinal. Le type Integer type représente un entier signé générique et le type Cardinal type représente un entier non signé générique. les intervalles réels et les formats de stockage des types génériques varient avec les différentes implémentations de Pascal Objet, mais permettent généralement les opérations sur les entiers les plus efficaces pour le processeur et le système d'exploitation.
Type Intervalle Format
Integer -32768 .. 32767 Signé, 16 bits
Integer -2147483648 .. 2147483647 Signé, 32 bits
Cardinal 0 .. 65535 Non signé, 16 bits
Cardinal 0 .. 2147483647 Non signé, 32 bits
------------------------------------------------------------
The idea is exactly the same as that contained in the letter of Frank Heckenbach of today, except for the replacement of Ordinal by Cardinal (which was also suggested by Franck). So I would vote to implement what is proposed by Franck, with only the replacement of ordinal by cardinal to have some compatibility. i.e.
Generic Types
Integer Cardinal
Well defined types
int8 card8 (=byte is the only case without doubt) int16 card16 int32 card32
...
card9 = 0..2 POW 9 -1 ... if needed: this is always allowed by the pascal syntax but the amount of memory involved is implementation dependant:
Compatibility types
anything contained in bpcompat.pas delphi1compat.pas delphi2compat.pas and everything you need, better than compiler switches when possible to avoid to garble the compiler by a lot of special purpose oddities: the idea of C to keep a minimum in the compiler and a maximum in libraries is not so bad (when it is possible).