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.180.11.239 with SMTP id t15mr1646527wib.3.1368583520733; Tue, 14 May 2013 19:05:20 -0700 (PDT) Path: p18ni110080wiv.0!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.news.ucla.edu!nrc-news.nrc.ca!News.Dal.Ca!news.litech.org!news.stack.nl!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: User defined type conversion Date: Thu, 09 May 2013 13:19:47 -0700 Organization: Also freenews.netfront.net; news.tornevall.net Message-ID: References: Mime-Version: 1.0 Injection-Date: Thu, 9 May 2013 20:16:11 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="656ea2f23126f57fb36504d2d15a002c"; logging-data="886"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/woRxaEB+OgUEXLGoPcZXjjeqqj4rwOpY=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Cancel-Lock: sha1:x9/aSywWZenYDeOo93ooeFbplbs= Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Date: 2013-05-09T13:19:47-07:00 List-Id: On 05/09/2013 11:39 AM, Vin�cius Franchini wrote: > > I see I should be more clear about my problem. What I mean a "direct > conversion" is like copy all bits, in the same positions they are in the > original variable to the destination variable. Since you do not know what bits are where in either of the 2 types (the compiler may put the fields in any order, and may put unused space between fields), you have no idea what you'll end up with. This is exacerbated by the implicit tag fields, since these are tagged types, which the compiler may put anywhere in the representation, and may separate them from other fields with unused space. Unless you've investigated exactly how your compiler lays out these records and are sure that copying the bits gives you what you want, and are never going to use another processor or compiler (including a different version of the same compiler) without reinvestigating and possibly rewriting the code, this is not a good idea. (If those conditions apply, then you can simply use Unchecked_Conversion between the 2 types.) > 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. Premature optimization, and all that. Doing it portably will no doubt meet your timing requirements and be a much better choice. > Now I'm thinking something with Union structure. It could solve. Not a good idea. -- Jeff Carter "There's no messiah here. There's a mess all right, but no messiah." Monty Python's Life of Brian 84