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.200.202 with SMTP id ex10mr10374134qab.8.1368126933680; Thu, 09 May 2013 12:15:33 -0700 (PDT) X-Received: by 10.50.73.129 with SMTP id l1mr3196632igv.0.1368126918186; Thu, 09 May 2013 12:15:18 -0700 (PDT) Path: y6ni20871qax.0!nntp.google.com!m7no4167897qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 9 May 2013 12:15:17 -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: <6dfc632e-bf34-4dff-85c6-fbbcd47b15ff@googlegroups.com> Subject: Re: User defined type conversion From: Adam Beneschan Injection-Date: Thu, 09 May 2013 19:15:33 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-05-09T12:15:17-07:00 List-Id: On Thursday, May 9, 2013 11:39:06 AM UTC-7, Vin=EDcius Franchini wrote: > Thanks all for the answers.=20 >=20 > I see I should be more clear about my problem. What I mean a "direct conv= ersion" is like copy all bits, in the same positions they are in the origin= al variable to the destination variable. To reiterate what I said before: you do not want to copy in "all bits", sin= ce 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 t= ypes should be tagged? Are you coming from a language where all types are = automatically "classes"? Regardless, when you're dealing with a low-level = type where the exact representation is very important and you need to be aw= are of where all the individual bits are, you probably do *not* want to mak= e it tagged.=20 > I'm programming an ATMEGA2560. I doing it in a way to optimize the code a= nd I did not want to create a method for that. 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 > Now I'm thinking something with Union structure. It could solve. 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 structur= es that you want imported C code to work with. You should not use it for t= he kind of purpose you're looking for. I think what you really want to do is: get rid of "tagged" and declare two = untagged record types, add record representation clauses to them to make su= re the compiler puts the fields at the correct bit locations, and use Unche= cked_Conversion to convert from one record type to the other. -- Adam=20