From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Big-endian vs little-endian
Date: 1999/02/07
Date: 1999-02-07T00:00:00+00:00 [thread overview]
Message-ID: <m3aeyqyf0z.fsf@mheaney.ni.net> (raw)
In-Reply-To: 36BB9A6E.D472A709@wvu.edu
Mike Werner <mwerner@wvu.edu> writes:
> Here's the relevant data structure:
>
> type Sys_type is (Zarya, Unity, PMA1, PMA2);
> type Subsys_type is (CDH, CT, ECLSS, EPS, GNC, SM);
> subtype Desc_type is String(1..256);
> subtype Dur_Min_Type is Integer;
> subtype Dur_Sec_type is Integer;
> type Apm_Rec is
> record
> Description : Desc_Type;
> System : Sys_Type;
> Subsystem : Subsys_Type;
> Dur_Min : Dur_Min_Type;
> Dur_Sec : Dur_Sec_Type;
> end record;
>
> The problematic parts were the Apm_Rec.Dur_Min and the Apm_Rec.Dur_Sec -
> all the others read in just fine. If I'm understanding all this, should
> I have changed
>
> subtype Dur_Min_Type is Integer;
> subtype Dur_Sec_type is Integer;
>
> to
>
> subtype Dur_Min_Type is Integer(S'Bit_Order=>Low_Order_First);
> subtype Dur_Sec_type is Integer(S'Bit_Order=>Low_Order_First);
>
> or perhaps High_Order_First - haven't got everything handy at the
> moment. But the main question is do I have the right syntax and usage?
> Or am I completely off here?
Yes, you are completely off.
Don't bother with the Bit_Order attribute. No compiler vendors support
it.
That leads us to this:
type Sys_type is (Zarya, Unity, PMA1, PMA2);
type Subsys_type is (CDH, CT, ECLSS, EPS, GNC, SM);
type Apm_Rec is
record
Description : Desc_Type (1 .. 256);
System : Sys_Type;
Subsystem : Subsys_Type;
Dur_Min : Integer range 0 .. 59;
Dur_Sec : Integer range 0 .. 59;
end record;
There are two advantages to this:
1) we can pack the last four fields in one longword
2) the integer types fit in 1 byte, so we don't have to worry about
byte-swapping
I think you should now be able to write a standard rep clause for this
record ("for Apm_Rec use ..."), that will work for both big- and
little-endian machines. (Because the latter fields are 1 byte, and the
representation of one-byte data on either machine is the same.)
If you do decide to use 32-bit integers for Dur_Min and Dur_Sec, you
still don't have a rep clause problem. But you do have a byte-swapping
problem.
next prev parent reply other threads:[~1999-02-07 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-29 0:00 Big-endian vs little-endian Mike Werner
1999-02-02 0:00 ` Nick Roberts
1999-02-03 0:00 ` Mark A Biggar
1999-02-06 0:00 ` Samuel T. Harris
1999-02-08 0:00 ` dennison
1999-02-08 0:00 ` Samuel T. Harris
1999-02-04 0:00 ` Richard D Riehle
1999-02-06 0:00 ` Mike Werner
1999-02-07 0:00 ` Matthew Heaney [this message]
1999-02-09 0:00 ` Stephen Leake
1999-02-10 0:00 ` Mike Werner
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox