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,f71c159449d6e114 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Ada 83 - avoiding unchecked conversions. Date: 1996/12/10 Message-ID: #1/1 X-Deja-AN: 203334797 references: <329C63BC.41C6@lmco.com> <32A311C1.41C67EA6@escmail.orl.lmco.com> content-type: text/plain; charset=ISO-8859-1 organization: Estormza Software mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-12-10T00:00:00+00:00 List-Id: >Ensco Vendor wrote: >> >> we have two 16 bit integers which we need to assemble into a single 32 >> bit integer (one is high order, the other low order). We wish to avoid >> unchecked conversion if we can. Is there a standard accepted way of >> doing this? Unchecked conversion is the accepted way of doing this: function To_Integer_32 (Low, High : Integer_16) return Integer_32 is type Integer_32_Record is record High_Order : Integer_16; Low_Order : Integer_16; end record; for Integer_32_Record use record High_Order at 0 range 16 .. 32; Low_Order at 0 range 0 .. 15; end record; for Integer_32_Record'Size use 32; function To_Integer_32 is new Unchecked_Conversion ( Integer_32_Record, Integer_32); The_Record : constant Integer_32_Record := ( High_Order => High, Low_Order => Low); begin return To_Integer_32 (The_Record); end; Because the source and target types have the same size, this should be completely portable. Some shops have the rule "Thou shalt not use Unchecked_Conversion." But this is silly; use it when it makes sense. The proper place to use Unchecked_Conversion is at the interface boundary of the sytem. That seems to be the case for you, because you're manipulating types whose size is known explicitly (16 and 32 bit integers). -------------------------------------------------------------------- Matthew Heaney Software Development Consultant mheaney@ni.net (818) 985-1271