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=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.165.130 with SMTP id i2mr10478143qay.2.1368129618659; Thu, 09 May 2013 13:00:18 -0700 (PDT) X-Received: by 10.49.1.197 with SMTP id 5mr1265079qeo.24.1368129618637; Thu, 09 May 2013 13:00:18 -0700 (PDT) Path: y6ni20871qax.0!nntp.google.com!m7no4183715qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 9 May 2013 13:00:18 -0700 (PDT) In-Reply-To: <6dfc632e-bf34-4dff-85c6-fbbcd47b15ff@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=189.77.226.1; posting-account=xhShowoAAABwJEaFCs7_gHiUlZrBvRhD NNTP-Posting-Host: 189.77.226.1 References: <6dfc632e-bf34-4dff-85c6-fbbcd47b15ff@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2a7e6432-3be8-48f0-a6c9-f07af819a76c@googlegroups.com> Subject: Re: User defined type conversion From: =?ISO-8859-1?Q?Vin=EDcius_Franchini?= Injection-Date: Thu, 09 May 2013 20:00:18 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-05-09T13:00:18-07:00 List-Id: On Thursday, May 9, 2013 4:15:17 PM UTC-3, Adam Beneschan wrote: > On Thursday, May 9, 2013 11:39:06 AM UTC-7, Vin=EDcius Franchini wrote: >=20 > > Thanks all for the answers.=20 >=20 > >=20 >=20 > > I see I should be more clear about my problem. What I mean a "direct co= nversion" is like copy all bits, in the same positions they are in the orig= inal variable to the destination variable. >=20 >=20 >=20 > To reiterate what I said before: you do not want to copy in "all bits", s= ince tagged types have special data that you definitely do not want to copy= . Why did you make the types tagged? Did someone tell you that all record= types should be tagged? Are you coming from a language where all types ar= e automatically "classes"? Regardless, when you're dealing with a low-leve= l type where the exact representation is very important and you need to be = aware of where all the individual bits are, you probably do *not* want to m= ake it tagged.=20 >=20 >=20 >=20 >=20 >=20 > > I'm programming an ATMEGA2560. I doing it in a way to optimize the code= and I did not want to create a method for that. >=20 >=20 >=20 > I'm still not clear on what you mean by "did not want to create a method"= . What, exactly, did you want to create?=20 >=20 >=20 >=20 >=20 >=20 > > Now I'm thinking something with Union structure. It could solve. >=20 >=20 >=20 > In my opinion this is worse. The only "union" in Ada is Unchecked_Union.= The only real purpose of Unchecked_Union is so that you can define struct= ures that you want imported C code to work with. You should not use it for= the kind of purpose you're looking for. >=20 >=20 >=20 > I think what you really want to do is: get rid of "tagged" and declare tw= o untagged record types, add record representation clauses to them to make = sure the compiler puts the fields at the correct bit locations, and use Unc= hecked_Conversion to convert from one record type to the other. >=20 >=20 >=20 > -- Adam After you insist in the "tagged", I think I did not pay the proper attentio= n to this. Sorry. I put it because I planned to use inheritance, but I did = not. I really do not need this and I will remove. The tip about Union is ve= ry good. I will use the Unchecked_Conversion to conversions. Any more tip ? Thanks for your attention