comp.lang.ada
 help / color / mirror / Atom feed
* Portable binary number types...
@ 2002-03-25  1:47 Eric G. Miller
  0 siblings, 0 replies; only message in thread
From: Eric G. Miller @ 2002-03-25  1:47 UTC (permalink / raw)


I have a datafile format that specifies 2 & 4 byte integers and
4 & 8 byte floating point types.  I want to make sure the data
types I use in the program, can reliably be read/written to
files.  It's not crucial that the runtime data types have
the same byte count (provided they have the same range).

So, I wrote something like:

package My_Types is

        -- 16#8000 is NULL
        type My_Short is range -32_767 .. 32_767;
        for  My_Short'Size use 16;
        for  My_Short'Alignment use 2;

        -- 16#80000000 is NULL
        type My_Long is range -2_147_483_647 .. 2_147_483_647;
        for  My_Long'Size use 32;
        for  My_Long'Alignment use 4;

        -- Any IEEE NaN is NULL
        type My_Float is digits 6;
        for  My_Float'Size use 32;
        for  My_Float'Alignment use 4;

        -- Any IEEE NaN is NULL
        type My_Double is digits 15;
        for  My_Double'Size use 64;
        for  My_Double'Alignment use 8;

end My_Types;

Endianness is handled via a character flag, so Read/Write will
involve byte swapping (if needed).  I've got that covered.

I'm less sure about the floating point types.  What's really
wanted is IEEE conformance.  All four have a NULL state, that
I'll need to be able to check.  I figured I could use a pair
of functions to test/set NULL via the Unchecked_Conversion
'Valid and a NULL constant for the Set_Null().

In the general case, is it likely the compiler will see these
types as simple redefinitions of native types (if that's the
case) and not create a performance penalty for using them?
Or is there a better way to handle the requirement?



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-03-25  1:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-25  1:47 Portable binary number types Eric G. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox