comp.lang.ada
 help / color / mirror / Atom feed
* Representation Clauses for tagged types
@ 1998-08-26  0:00 Courville
  1998-08-26  0:00 ` David C. Hoos, Sr.
  1998-08-28  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 4+ messages in thread
From: Courville @ 1998-08-26  0:00 UTC (permalink / raw)


Help!

I'm trying to define a representation clause for a tagged type
and I can't find any information about specifying where the
"tag" goes.  I wan't to do something like this:

	type example_t is tagged
	record
		x: integer;
	end record;

	for example_t use
	record
		TAG at 0 range 0 .. 3;
		x at 0 range 3 .. 7;
	end record;

Can someone help?  Also, another question concerning this is can
I force the tag to be a certain bit size.  It seems my compilier sets
it to 32 bits, I would like it to be just 3 bits.  Can I just do this
in the rep-spec or do I need to do something like:
	for example_t'tag use 3;

Or can I not change this?

Any help would be greatly appreciated, either through a post to this    
newsgroup or by directly emailing me at:

	d1c@ssd.ray.com

Thanks,

Dan







^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Representation Clauses for tagged types
  1998-08-26  0:00 Representation Clauses for tagged types Courville
@ 1998-08-26  0:00 ` David C. Hoos, Sr.
  1998-08-28  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 1998-08-26  0:00 UTC (permalink / raw)



Courville wrote in message <6s129l$i82$1@emperor.ssd.ray.com>...
>Help!
>
>I'm trying to define a representation clause for a tagged type
>and I can't find any information about specifying where the
>"tag" goes.  I wan't to do something like this:
>
Why would you want a representation clause for a tagged type?
If you really care about how a tagged type resides in memory this can be a
real problem.
More about this, later.

If, on the other hand, you only care about how the type appears in a file or
on a network, or other form of byte stream, then you can use the
stream-oriented attributes, 'read, 'write, 'input, and 'output to achieve
this.

I have a small example of this on my FTP site at
ftp://ftp.ada95.com/pub/tagged_types.

Although my examples don't show it (they probably should), you can use the
'external_tag attribute to force the external form of the tag to be what you
want.

Finally, getting back to the problem of exact representation of the tagged
type in memory (if that's what you really need), then you can use a memory
stream package (such as the one on my FTP site -- part of the tagged_types
example) to read and write between the exact representation you need in
memory, and the compiler's representation of the tagged type.

In this case, the tag in your memory stream will have the external tag you
specify, and the compiler's representation of the tagged type will have its
internal tag necessary for access to the dispatch table, etc.

I hope this helps,

David C. Hoos, Sr.







^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Representation Clauses for tagged types
@ 1998-08-26  0:00 tmoran
  0 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 1998-08-26  0:00 UTC (permalink / raw)


There was a discussion of this recently, as I recall.
My experience with three MS Windows targeted compilers
is that letting the tag occupy the first 32 bits, works.
   for example_t use record
      x at 4 range ....
But there's surely no guarantee.

> Also, another question concerning this is can
> I force the tag to be a certain bit size.
  The compiler and run-time-system need to put certain
info (probably a pointer) into the tag.  If they need
32 bits, you can't just toss out 29 of them.

But are you sure you need to specify the tag representation
at all?  Presumably you aren't reading in a tagged record and
its tag (which depends on the particular compiler, and quite
likely is in fact an address in RAM) from an external device,
or from a non-Ada program or OS.  Similarly, you probably
don't really want to send the tag to the non-Ada program or
an external device.  How about:
  type X_Values is range 0 .. 31;
  type Actual_Record_Type is record
    X : X_Values;
  end record;
  for Actual_Record_Type use record
    X at 0 range 3 .. 7;
  end record;
  type example_t is tagged record
    Content : Actual_Record_Type;
  end record;
Then in your Ada program you have a tagged type example_t, but
for external use you can do IO or whatever on Content, whose
representation you control.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Representation Clauses for tagged types
  1998-08-26  0:00 Representation Clauses for tagged types Courville
  1998-08-26  0:00 ` David C. Hoos, Sr.
@ 1998-08-28  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1998-08-28  0:00 UTC (permalink / raw)


d1c@striper.ssd.ray.com (Courville) writes:

> I'm trying to define a representation clause for a tagged type
> and I can't find any information about specifying where the
> "tag" goes.  I wan't to do something like this:

Here is some advice: don't bother trying to write a representation
clause for a tagged type.  Use the streams facility to convert your
tagged-type object to an external representation, and process that.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-08-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-26  0:00 Representation Clauses for tagged types Courville
1998-08-26  0:00 ` David C. Hoos, Sr.
1998-08-28  0:00 ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
1998-08-26  0:00 tmoran

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