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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:1851:: with SMTP id n17mr12663714qtk.305.1579357059376; Sat, 18 Jan 2020 06:17:39 -0800 (PST) X-Received: by 2002:a9d:12a8:: with SMTP id g37mr10070848otg.261.1579357059065; Sat, 18 Jan 2020 06:17:39 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!peer03.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!g89no9547482qtd.0!news-out.google.com!w29ni1671qtc.0!nntp.google.com!g89no9547478qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 18 Jan 2020 06:17:38 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=47.185.239.228; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 47.185.239.228 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0d3a3416-29f6-4a3c-9542-f25ca33256ae@googlegroups.com> Subject: Re: Creating several types from a base type and conversion From: Optikos Injection-Date: Sat, 18 Jan 2020 14:17:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4711 X-Received-Body-CRC: 771931650 Xref: reader01.eternal-september.org comp.lang.ada:57871 Date: 2020-01-18T06:17:38-08:00 List-Id: On Saturday, January 18, 2020 at 6:16:20 AM UTC-6, Simon Wright wrote: > Ken Roberts writes: >=20 > > So the next question is how to convert between CharWord/BaseWord? >=20 > Possibly using Ada.Unchecked_Conversion. Hidden inside a function with a > helpful-in-six-months name. >=20 > It takes very little time to compile code nowadays, I'd strongly suggest > you start with the basics (e.g. BaseWord) and build up from there, > checking as you go (there are a _lot_ of syntax errors in your example > code). >=20 > You can't say >=20 > type DataWord is new BaseWord with record > Upper : array 00 .. 8#77777# of Boolean; > Lower : array 00 .. 8#77777# of Boolean; > end record; >=20 > because BaseWord isn't a tagged type, and even if it was you don't want > to add extra information, you're looking for an alternative view. > And that's not the syntax for an array declaration. > And you can't declare an anonymous array in a record. > And that's two large arrays (I think you're aiming for representations). >=20 > ---------- >=20 > I was wondering whether an Unchecked Union (ARM B.3.3[1]) might serve, > but (30) says "The use of an unchecked union to obtain the effect of an > unchecked conversion results in erroneous execution". >=20 > [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-B-3-3.html The Unchecked_ series are better focused on the situation that BaseWord, Da= taWord, InstructionWord, and CharWord are originating in another language, = say, C, but that is ostensibly not the case here. More proper in Ada, would be to have multiple conversion functions that tak= e the already-extant FooWord as a parameter and return an extracted/convert= ed BarWord as return value (or a procedure that takes the already-extant Fo= oWord as an in parameter and the to-be-extracted/to-be-converted BarWord as= an out parameter). Then that conversion/extraction subroutine is merely p= erforming garden-variety safe/not-unchecked reading of FooWord and is merel= y performing garden-variety safe/not-unchecked writing of BarWord. You would have a plethora of such FooWord to BarWord conversion/extraction = subroutines=E2=80=94one for each origin-to-destination pairing in your app-= domain, such as {ExtractCharWordFromDataWord, EmbedCharWordIntoDataWord, Ex= tractDataWordFromInstructionWordOpcode, EmbedDataWordIntoInstructionWordOpc= ode, ExtractDataWordFromInstructionWordImmediate, EmbedDataWordIntoInstruct= ionWordImmediate, =E2=80=A6} (assuming that immediates in the machine code = are located at the same offset-from-beginning-of-instruction in all machine= instructions, otherwise ExtractDataWordFromImmediateForSuchandsuchOpcode a= nd EmbedDataWordIntoImmediateForSuchandsuchOpcode for each different format= of suchandsuch opcodes in the instruction-set) and so forth. In modern Ada, for efficiency and perhaps succinct/readable beauty, you mig= ht want to consider the extended return statement if choosing the design ab= ove that is based on functions (instead of the out parameter to a procedure= , which is available in all eras of Ada, but perhaps naturally leading to s= lightly more verbose/less-lucid invocations at points of usage, due to bein= g statements instead of expressions). https://www.adaic.org/resources/add_content/standards/05rm/html/RM-6-5.html= #S0170