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: a07f3367d7,97439a4c062cf25d X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII X-Received: by 10.224.59.205 with SMTP id m13mr9934071qah.7.1368111026865; Thu, 09 May 2013 07:50:26 -0700 (PDT) X-Received: by 10.50.153.101 with SMTP id vf5mr1833708igb.11.1368111026823; Thu, 09 May 2013 07:50:26 -0700 (PDT) Path: y6ni20871qax.0!nntp.google.com!m7no3927436qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 9 May 2013 07:50:26 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <58b02858-3292-438b-bb21-4105f85ada0d@googlegroups.com> Subject: Re: User defined type conversion From: Adam Beneschan Injection-Date: Thu, 09 May 2013 14:50:26 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-05-09T07:50:26-07:00 List-Id: On Thursday, May 9, 2013 7:07:33 AM UTC-7, Vin=EDcius Franchini wrote: > Hi Folks, >=20 > I have a problem with a type conversion. Hereby is what I'm trying to do= : >=20 > type AB is tagged > record > A : Unsigned_16; > B : Unsigned_16; > end record; >=20 > type abcde is tagged > record > a: Unsigned_8; > b: Unsigned_8; > c: Unsigned_8; > d: Unsigned_8;=20 > end record;=20 >=20 > X : AB; > Y : abcd; >=20 > X :=3D Y; >=20 > I'd like to do a direct conversion without creating a method for it. Yes, I'd often like the program to do what I want done without having to wr= ite any code. Unfortunately, Ada is not expected to have mind-reading capa= bilities until at least Ada 2030. I don't know what you mean by "direct conversion". Whatever you're doing, = it's not all that direct. Obviously, using Unchecked_Conversion on the ent= ire record type is a very bad idea since these are tagged records. There's= going to be at least one piece of data in Y that is not the same as any da= ta in X, i.e whatever data the compiler sets aside for "tag" information. = So you'll have to define your own function function To_AB (Source : ABCD) return AB is ... How you write it depends on what you're trying to do. If the Unsigned_* ty= pes are the ones defined in Interfaces, and you're trying to combine Source= .a and Source.b into an A field, and Source.c and Source.d into a B field, = I'd probably just use the "or" operator and Shift_Left to produce the resul= ts, something like begin return (A =3D> Shift_Left(Unsigned_16(Source.a), 8) or=20 Unsigned_16(Source.b), B =3D> Shift_Left(Unsigned_16(Source.c), 8) or=20 Unsigned_16(Source.d)); end; or something similar depending on exactly what you're trying to do. I have= n't tested the above. -- Adam =20