[fpc-devel] integer, cardinal

Vinzent Hoefler JeLlyFish.software at gmx.net
Mon Apr 18 10:10:08 CEST 2005


On Monday 18 April 2005 07:22, Marco van de Voort wrote:
> > On Sunday 17 April 2005 10:45, Ales Katona wrote:
> > > First of all Integer should be size independent, that is, xy bits
> > > depending on the platform.
> >
> > I second that.
>
> It is now. It just happens to be the same.

:) Ok, good point.

> > > Second, we should "force people in a friendly way" to use more
> > > readible names like:
> > > sint32, uint64, etc. than "cardinal"
> >
> > No. Such stuff is only needed when you do hardware-interfacing.
> > And that's the _only_ reason someone would need types with defined
> > bit-sizes.
>
> That's a bit simplistic; Network/system interfacing, binary
> fileformats ?

Oh sorry, in that context, I'd call that "hardware", too. It belongs to 
the "outside world's" interface.

> > > In a few years when 64 bits are normal, what will cardinal
> > > become? who knows..
> >
> > That's why Pascal has range types. Define the range you need, and
> > don't use "just some type" which has the range you think you will
> > need.
>
> I actually tried this in a major app at work.

Well, and I actually do this in a major app at work. Not on everything, 
of course, but it can heavily simplify some stuff, for instance because 
I can use the Low and High-attribu^Wfunctions on the type which is 
safer than using constants, because the compiler can do the work for 
me.

> In theory it is nice

Well, in practice it works. :-)

> However quite a lot of datastructures get written to disc sooner and
> later, and to get fileformats size independant, you need a lot of
> datastructure conversions (from records with fields that have arch
> dependant size to packed records with fields with fixed sized integer
> types).

Yes, of course, that's the outside world. For instance, I have to read 
Image-files (and if you know TIFF, you know the beast) and have to 
write binary structures to a connected embedded system and there I 
badly need known size types, but that's about it.

Maybe, you have to do such things more often, but - no offense meant - 
earlier experience led me to believe that binary file formats are evil. 
They tend to change too often, they tend to use types that don't even 
survive half a decade, and even if this doesn't matter known size types 
won't save you from the Hell of Endianess. And if you don't have that 
problem, you don't have it all. ;-)


Vinzent.





More information about the fpc-devel mailing list