comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: User defined type conversion
Date: Thu, 09 May 2013 13:19:47 -0700
Date: 2013-05-09T13:19:47-07:00	[thread overview]
Message-ID: <kmh069$rm$2@dont-email.me> (raw)
In-Reply-To: <b9dd0717-f4ed-4717-93f1-5f3419235800@googlegroups.com>

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



  parent reply	other threads:[~2013-05-09 20:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09 14:07 User defined type conversion Vinícius Franchini
2013-05-09 14:50 ` Adam Beneschan
2013-05-09 16:12 ` Shark8
2013-05-09 16:50   ` Adam Beneschan
2013-05-09 18:24 ` Jeffrey Carter
2013-05-09 18:39   ` Vinícius Franchini
2013-05-09 19:15     ` Adam Beneschan
2013-05-09 20:00       ` Vinícius Franchini
2013-05-09 20:19     ` Jeffrey Carter [this message]
2013-05-12  7:04 ` ldries46
2013-05-12 14:13   ` AdaMagica
2013-05-12 15:02 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox