comp.lang.ada
 help / color / mirror / Atom feed
From: "Vinícius Franchini" <viniciusnf@gmail.com>
Subject: Re: User defined type conversion
Date: Thu, 9 May 2013 13:00:18 -0700 (PDT)
Date: 2013-05-09T13:00:18-07:00	[thread overview]
Message-ID: <2a7e6432-3be8-48f0-a6c9-f07af819a76c@googlegroups.com> (raw)
In-Reply-To: <6dfc632e-bf34-4dff-85c6-fbbcd47b15ff@googlegroups.com>

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ícius Franchini wrote:
> 
> > Thanks all for the answers. 
> 
> > 
> 
> > 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.
> 
> 
> 
> To reiterate what I said before: you do not want to copy in "all bits", since 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 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 aware of where all the individual bits are, you probably do *not* want to make it tagged. 
> 
> 
> 
> 
> 
> > 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.
> 
> 
> 
> I'm still not clear on what you mean by "did not want to create a method".  What, exactly, did you want to create? 
> 
> 
> 
> 
> 
> > 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 structures that you want imported C code to work with.  You should not use it for the 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 sure the compiler puts the fields at the correct bit locations, and use Unchecked_Conversion to convert from one record type to the other.
> 
> 
> 
>                             -- Adam

After you insist in the "tagged", I think I did not pay the proper attention 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 very good. I will use the Unchecked_Conversion to conversions.
Any more tip ?

Thanks for your attention



  reply	other threads:[~2013-05-09 20:00 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 [this message]
2013-05-09 20:19     ` Jeffrey Carter
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