Maurice Lombardi wrote:
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.=20 The following is a cut out of the Delphi help (in french however):
I don't understand much French, sorry, but I think I can recognize the important words :-)
Type Intervalle Format
Integer -32768 .. 32767 Sign=E9, 16 bits
Integer -2147483648 .. 2147483647 Sign=E9, 32 bits
Cardinal 0 .. 65535 Non sign=E9, 16 bits
Cardinal 0 .. 2147483647 Non sign=E9, 32 bits
If I understand it right, Integer and Cardinal have different sizes on 16 and 32 bit Delphi, right? This would be like in gpc (though not 16 bit, AFAIK, but 64 bit and perhaps more).
Perhaps contrary to Delphi, I don't think LongInt should be 32 bits on every platform, but rather twice as bug as Integer. What do you think?
The idea is exactly the same as that contained in the letter of Frank Heckenbach of today, except for the replacement of=20 Ordinal by Cardinal (which was also suggested by Franck).
That's fine! If Delphi uses "Cardinal", gpc should use it too, of course.
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
I'd add {Short,Long,LongLong(?),Longest(?)}{Int,Card} here.
Well defined types
int8 card8 (=3Dbyte is the only case without doubt) int16 card16 int32 card32
...
card9 =3D 0..2 POW 9 -1 ... if needed: this is always allowed by the pascal syntax but the amount of memory involved is implementation dependant:
Sounds good.
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).
I agree! Except for "integer", all types can be redeclared in these units. (I think, "integer" could be redeclared, too, but AFAIR it's not a good idea to do so, is it?)
Frank Heckenbach wrote:
If I understand it right, Integer and Cardinal have different sizes on 16 and 32 bit Delphi, right? This would be like in gpc (though not 16 bit, AFAIK, but 64 bit and perhaps more).
Exactly 16 bits in Delphi1, 32 bits in Delphi2. In any case they are "the best suited signed and unsigned integers for a given machine"
I'd add {Short,Long,LongLong(?),Longest(?)}{Int,Card} here.
But this is much harder to standardize: they will have different meanings on different systems, whence better to reject them in XXcompat units: gpc being cross-platform it will be difficult to give a general rule whereas the others are non ambiguous:
int8 card8 (=byte is the only case without doubt) int16 card16 int32 card32
I agree! Except for "integer", all types can be redeclared in these units. (I think, "integer" could be redeclared, too, but AFAIR it's not a good idea to do so, is it?)
certainly a bad idea in general, but notice that in BP I frequenly used a defreal unit, (referenced from the main and all other units) which contains either
type real = single or type real = double or type real = extended
to have a quick way to see the effect of the size of reals on accuracy or speed of some computations. But this is a purely private trick which should be restricted to such peculiar purposes.