From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f798c20ee494262a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: setting 'Size and unchecked conversion safe here? Date: 12 Feb 2005 14:14:30 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1108235670 31625 69.38.147.31 (12 Feb 2005 19:14:30 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 12 Feb 2005 19:14:30 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:8294 Date: 2005-02-12T14:14:30-05:00 List-Id: Marius Amado Alves writes: > On 11 Feb 2005, at 23:38, Robert A Duff wrote: > > > Marius Amado Alves 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