comp.lang.ada
 help / color / mirror / Atom feed
* Rep spec for tagged type
@ 2004-08-13 11:17 Daniel Wild
  2004-08-13 14:08 ` Georg Bauhaus
  2004-08-13 17:07 ` Nick Roberts
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Wild @ 2004-08-13 11:17 UTC (permalink / raw)


I'm trying to create a rep spec for a tagged type and getting errors
from GNAT that say `compoonent overlaps tag field of ...'.

I gather this means that GNAT stores the tag for the type at the
beginning of the memory used for the type and I'm trying to overwrite
that by starting my rep spec at 0.

So, I figure I need to shift my rep spec along by however big the tag
is. How can I find the size of this? (I'd rather do it properly that
assume it's 32 bits on my machine).

Thanks,
Dan.



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

* Re: Rep spec for tagged type
  2004-08-13 11:17 Rep spec for tagged type Daniel Wild
@ 2004-08-13 14:08 ` Georg Bauhaus
  2004-08-14  9:40   ` Daniel Wild
  2004-08-13 17:07 ` Nick Roberts
  1 sibling, 1 reply; 4+ messages in thread
From: Georg Bauhaus @ 2004-08-13 14:08 UTC (permalink / raw)


Daniel Wild <dan@example.com> wrote:
: 
: I gather this means that GNAT stores the tag for the type at the
: beginning of the memory used for the type and I'm trying to overwrite
: that by starting my rep spec at 0.

There may be another possibility, if the representation
is important for some data items in the objects, but not
for all of the object. You could create a plain record type
"around" the data that you want in your tagged type.
Then provide a representation clause for the plain record,
and declare a component of the plain record type in the
tagged type.


-- Georg



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

* Re: Rep spec for tagged type
  2004-08-13 11:17 Rep spec for tagged type Daniel Wild
  2004-08-13 14:08 ` Georg Bauhaus
@ 2004-08-13 17:07 ` Nick Roberts
  1 sibling, 0 replies; 4+ messages in thread
From: Nick Roberts @ 2004-08-13 17:07 UTC (permalink / raw)


On 13 Aug 2004 20:47:59 +0930, Daniel Wild <dan@example.com> wrote:

> I'm trying to create a rep spec for a tagged type and getting errors
> from GNAT that say `compoonent overlaps tag field of ...'.
>
> I gather this means that GNAT stores the tag for the type at the
> beginning of the memory used for the type and I'm trying to overwrite
> that by starting my rep spec at 0.
>
> So, I figure I need to shift my rep spec along by however big the tag
> is. How can I find the size of this? (I'd rather do it properly that
> assume it's 32 bits on my machine).

The expression:

    Ada.Tags.Tag'Size

will probably give you the size of the tag, but for its position you
will have to look in the GNAT documentation (maybe it is 0).

Unfortunately, I think this means your code may not be portable.

-- 
Nick Roberts



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

* Re: Rep spec for tagged type
  2004-08-13 14:08 ` Georg Bauhaus
@ 2004-08-14  9:40   ` Daniel Wild
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Wild @ 2004-08-14  9:40 UTC (permalink / raw)


Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:

> There may be another possibility, if the representation
> is important for some data items in the objects, but not
> for all of the object. You could create a plain record type
> "around" the data that you want in your tagged type.
> Then provide a representation clause for the plain record,
> and declare a component of the plain record type in the
> tagged type.

I thought about this, and it sort of works but not quite. If I take
this approach then I have to code all the operations on the derived
types twice. 

What I ended up doing was to leave the tagged types alone with no rep
spec, then create separate types with rep specs. Then I just convert
to/from these types when reading/writing them.

Cheers,
Daniel.



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

end of thread, other threads:[~2004-08-14  9:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-13 11:17 Rep spec for tagged type Daniel Wild
2004-08-13 14:08 ` Georg Bauhaus
2004-08-14  9:40   ` Daniel Wild
2004-08-13 17:07 ` Nick Roberts

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