comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Controlling endian-ness?
Date: Tue, 5 Aug 2008 17:16:25 -0700 (PDT)
Date: 2008-08-05T17:16:25-07:00	[thread overview]
Message-ID: <66265b13-8e35-4bc7-8e9f-7c4d76adb5b7@b38g2000prf.googlegroups.com> (raw)
In-Reply-To: 4898d0ca$0$19680$4d3efbfe@news.sover.net

On Aug 5, 3:14 pm, "Peter C. Chapin" <pcc482...@gmail.com> wrote:
> anon wrote:
> > For using Unsigned_32. Why not just override the built-in Write attributes
> > routines for Unsigned_32 by re-writing the attributes routines. This may at
> > most require a new package with a few extra attributes routines that may
> > be needed. Also, this will also allow you to use "Shift_Left/Shift_Right"
> > directly with Unsigned_32.
>
> > So in your program you could use:
>
> >    Data : Unsigned_32 ;
> >   ...
> >    Unsigned_32'Write ( Stream_Pointer, Data ) ;
>
> I actually tried something like this but the compiler told me that I
> couldn't redefine attributes for that type (or something like that). I
> think the problem is that since the type is defined in another package
> it is already frozen or some such. It could also be that I did it wrong.

Yes.  You can't apply any "for T'attribute use..." clause to something
defined in another package.  (It sounds to me like this is what you
tried... if I guessed wrong, sorry.)  You might consider defining your
own type (perhaps *derived* from Unsigned_32) and using your new type
when declaring a variable or component that needs to be written using
a special routine.

     type My_Unsigned_32 is new Unsigned_32;
     procedure My_Write
       (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
        Item   : in My_Unsigned_32);
     for My_Unsigned_32'Write use My_Write;

                                    -- Adam
                                -- Adam





  reply	other threads:[~2008-08-06  0:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-05  2:16 Controlling endian-ness? Peter C. Chapin
2008-08-05  3:10 ` Steve
2008-08-05  9:59   ` Peter C. Chapin
2008-08-05  5:23 ` christoph.grein
2008-08-05  9:59   ` Peter C. Chapin
2008-08-05 14:59 ` anon
2008-08-05 22:14   ` Peter C. Chapin
2008-08-06  0:16     ` Adam Beneschan [this message]
2008-08-06 13:44       ` Peter C. Chapin
2008-08-06 17:07     ` Controlling endian-ness? (Example: Attribute Overriding) anon
2008-08-12 13:42     ` Controlling endian-ness? Simon Wright
replies disabled

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