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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cc7bad83fb245cb3 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: Binding a type to a union. Date: 1999/11/24 Message-ID: #1/1 X-Deja-AN: 552413079 References: <383b8e49@rsl2.rslnet.net> X-Complaints-To: abuse@pacbell.net X-Trace: typhoon-sf.snfc21.pbi.net 943430103 206.170.2.186 (Tue, 23 Nov 1999 23:55:03 PST) Organization: SBC Internet Services NNTP-Posting-Date: Tue, 23 Nov 1999 23:55:03 PST Newsgroups: comp.lang.ada Date: 1999-11-24T00:00:00+00:00 List-Id: >Its use may be a little worrying if you have portability issues to consider, Often you have just one, or very few, objects of the schizophrenic type, in which case you might prefer: with ada.text_io; with interfaces.c, system.address_to_access_conversions; procedure foobar is use interfaces; type foo_struct is record x : C.Int; end record; for foo_struct use record x at 0 range 0 .. 31; end record; for foo_struct'size use 32; type some_enum_type is (a,b); type bar_struct is record x : C.char; y : some_enum_type; end record; for bar_struct use record x at 0 range 0 .. 7; y at 1 range 0 .. 7; end record; for bar_struct'size use 32; package foo_locs is new system.address_to_access_conversions(foo_struct); --Then you can make a foo and a bar at the same place in memory. -- (See Cohen, 2nd Edition, section 19.3 for some warnings) foo : aliased foo_struct; foo_loc : constant system.address := foo_locs.to_address(foo'access); bar : bar_struct; for bar'address use foo_loc; begin foo.x := 3; bar.y := b; ada.text_io.put_line(c.int'image(foo.x)); end foobar;