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,cef1e23795181e0c,start X-Google-Attributes: gid103376,public From: "Steve Doiel" Subject: Alternate to Unchecked_Conversion - Portable? Date: 1999/02/21 Message-ID: <36d05e39.0@news.pacifier.com>#1/1 X-Deja-AN: 446796662 X-Trace: 21 Feb 1999 11:27:53 PST, 216.65.138.96 Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Date: 1999-02-21T00:00:00+00:00 List-Id: I discovered a technique for performing a similar function to Unchecked_Conversion. Locating two data structures at the same address by defining the first normally and then using an address clause to locate the second at the same address as the first (as shown in the following sample): WITH Ada.Text_Io; WITH Interfaces; USE Interfaces; PROCEDURE TestAlias IS PACKAGE Text_Io RENAMES Ada.Text_Io; TYPE aRec IS RECORD f1 : Integer_32; f2 : Integer_32; END RECORD; TYPE Integer_16_Array IS ARRAY( Positive RANGE <> ) OF Integer_16; v1 : aRec; v2 : Integer_16_Array( 1..4 ); FOR v2'ADDRESS USE v1'ADDRESS; -- This causes v1 and v2 to occupy the same memory BEGIN v1.f1 := 1; v1.f2 := 2; FOR ii IN v2'RANGE LOOP Text_Io.Put( Integer_16'IMAGE( v2( ii ) ) ); END LOOP; Text_Io.New_Line; END TestAlias; My question is: is this portable? I expect that record layouts will be dependent on different endian machines, and I know that this technique is inherently unsafe, but it makes things very simple. SteveD