From: "Eric G. Miller" <egm2@jps-nospam.net>
Subject: Portable binary number types...
Date: Mon, 25 Mar 2002 01:47:51 GMT
Date: 2002-03-25T01:47:51+00:00 [thread overview]
Message-ID: <pan.2002.03.24.17.48.34.875505.18394@jps-nospam.net> (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?
reply other threads:[~2002-03-25 1:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox