comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: setting 'Size and unchecked conversion safe here?
Date: 12 Feb 2005 14:14:30 -0500
Date: 2005-02-12T14:14:30-05:00	[thread overview]
Message-ID: <wcc650xmvzd.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: mailman.135.1108212272.527.comp.lang.ada@ada-france.org

Marius Amado Alves <amado.alves@netcabo.pt> writes:

> On 11 Feb 2005, at 23:38, Robert A Duff wrote:
> 
> > Marius Amado Alves <amado.alves@netcabo.pt> writes:
> >
> >> I need to store access-to-subprogram values in a 64-bit modular type.
> >
> > Why do you want to do that?
> 
> That's the container I have to store small values. It's in a database
> system called Mneson. Mneson is based on a graph. Vertices are
> represented thusly:
> 
>     type Vertex is record
>        Tip : Natural_16;
>        Cue : Modular_64;
>     end record;
>     for Vertex'Size use 80;
>     pragma Pack (Vertex);
> 
> Small values are stored directly in the Cue. Mneson is my baby, so I can
> change it if necessary, but as I said I'd rather leave it that way.
> 
> > What do you mean by "works fine"?  Values convert from one to the other
> > and back, and you get what you started with?
> 
> "Works fine" means the referenced subprograms are correctly
> reaccessed. But I don't know if the unused bits stay the same. That's
> what I'd like to know. Or if there is some means to ensure that.

If the unused bits are ignored, then you don't care whether they stay
the same.  I suspect it will work on most compilers (within a single run
of the program), but there's no guarantee.

Why not do somthing like this:

    X: Acc_To_Subp;
    type Modular_32 is mod 2**32;
    function Cast is new Unchecked_Conversion(Acc_To_Subp, Modular_32);
    V: constant Vertex := (Tip => 0, Cue => Modular_64(Cast(X)));

?  Of course, this has to be different on a 64-bit machine,
if Acc_To_Subp is 64 bits.  But on a 32-bit machine, it seems
like a shame to waste 32 bits in every acc-to-subp value
(I mean, when they're *not* stored in a Vertex).

I presume that are many access-to-subprogram types, normally declared
*after* type Vertex.  If there's just one (or a small fixed number), you
could use a variant record.  See Unchecked_Union for C compatibility.

- Bob



  parent reply	other threads:[~2005-02-12 19:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-11 18:52 setting 'Size and unchecked conversion safe here? Marius Amado Alves
2005-02-11 19:08 ` Martin Krischik
2005-02-11 20:34 ` tmoran
2005-02-11 22:37   ` Marius Amado Alves
2005-02-11 23:49     ` tmoran
2005-02-12 13:10       ` Marius Amado Alves
2005-02-12  6:55     ` Martin Krischik
2005-02-12 13:30       ` Marius Amado Alves
2005-02-12 14:57         ` Martin Krischik
2005-02-12 16:03           ` Marius Amado Alves
2005-02-12 16:04           ` Marius Amado Alves
2005-02-11 23:38 ` Robert A Duff
2005-02-12 12:46   ` Marius Amado Alves
2005-02-12 18:05     ` tmoran
2005-02-12 18:29       ` Marius Amado Alves
2005-02-12 19:14     ` Robert A Duff [this message]
2005-02-12 19:48       ` Marius Amado Alves
replies disabled

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