comp.lang.ada
 help / color / mirror / Atom feed
From: barmar@think.COM (Barry Margolin)
Subject: Re: Internal data representation
Date: 8 Feb 89 23:14:22 GMT	[thread overview]
Message-ID: <36255@think.UUCP> (raw)
In-Reply-To: 8902081403.AA15437@ajpo.sei.cmu.edu

In article <8902081403.AA15437@ajpo.sei.cmu.edu> LEHMAN%ASD.SPAN@STAR.STANFORD.EDU (Richard A Lehman, DMSTB) writes:
>Bernard Badger of Harris states "I've been wondering why you 
>*want* to access the ``internal'' respresentation.
>
>Here at Johnson Space Center on the Space Station Program we
>have to access the ``internal'' representation of Ada types
>on many different tupes Heterogenous machines.  This is the only
>way we can provide a common transmission format to communicate
>amoung different type of ISAs.  

Why do you have to use the internal representation as the interchange
representation?  What's wrong with something like (excuse my syntax --
I'm not really an Ada programmer):

package COLORS is

  type COLOR is (RED, ORANGE, YELLOW, GREEN, BLUE, VIOLET); -- rainbow order
  REP: constant array(COLOR'FIRST..COLOR'LAST) of COLOR :=
    (BLUE, GREEN, ORANGE, RED, VIOLET, YELLOW); -- alphabetical order

  procedure WRITE (S: STREAM, C: COLOR) is
  begin
    for I in REP'FIRST..REP'LAST loop
      if REP(I) = C then
	INTEGER_IO.WRITE (S, I);
	exit;
      end if;
    end loop;
  end WRITE;

  function READ (S: STREAM) return COLOR is
  begin
    return REP(INTEGER_IO.READ (S));
  end READ;

end COLORS;

My impression is that the ability to specify the internal
representation is strictly to permit enumerated types to be used to
access data whose representation is defined by external forces.  For
instance, if an Ada structure were mapped over the memory used for a
network packet buffer, an enumeriated type could be used to read the
packet type field.  The internal representation clause allows you to
map Ada values to values defined by a standard protocol.

But if all you care about is communication between programs that you
have full control over, you can define an arbitrary representation, as
I did above (notice that the order of the elements in REP is different
from the order in the type definition, to emphasize the arbitrariness
of the representation).

Barry Margolin
Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

      reply	other threads:[~1989-02-08 23:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-02-08 14:16 Internal data representation Richard A Lehman, DMSTB
1989-02-08 23:14 ` Barry Margolin [this message]
replies disabled

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