comp.lang.ada
 help / color / mirror / Atom feed
From: Vinzent Hoefler <ada.rocks@jlfencey.com>
Subject: Re: Q re pack & aliased
Date: Wed, 23 Apr 2003 10:07:55 +0200
Date: 2003-04-23T10:07:55+02:00	[thread overview]
Message-ID: <b85hls$6i604$1@ID-175126.news.dfncis.de> (raw)
In-Reply-To: 63lpa.48072$Si4.30616@rwcrnsc51.ops.asp.att.net

tmoran@acm.org wrote:

>  The case at hand is a DIBitmap in Windows.  It needs to be in packed, 24
>bit, format so I can pass it to Windows (not to mention size
>considerations).  I also need sometimes to make pointers to individual
>elements, so the components need to be aliased.

Well, why don't you do this, then?

|with Ada.Text_IO;
|
|procedure t is
|   type color is range 0 .. 2**8 - 1;
|   for color'Size use 8;
|
|   type triples is record
|      red,
|      green,
|      blue : color;
|   end record;
|   for triples'Size use 24;
|
|   type bunches is array (Integer range <>) of aliased triples;
|   x : bunches (1 .. 10);
|   for x'Size use 240;
|begin
|   x := (1 => (red => 0, green => 1, blue => 1), others => (0, 0, 0));
|   Ada.Text_IO.Put_Line (Integer'Image (x'Size / 80)
|                         & " should = 3, not 4");
|end t;

Probably some of the 'Size-attributes are not needed here (especially
the "x'Size use 240"-one), but I put them in to see if the compiler
warns about any of them. It doesn't and the generated code for the
assignment looks correct to me, too.

I don't know how this would fit into your existing code, but I guess,
a conversion between a 24-bit-type like you used before and the
triples-record is quite easy without breaking too much...


Vinzent.

-- 
Parents strongly cautioned  --  this  posting  is  intended for mature
audiences  over  18.  It  may  contain some material that many parents
would not find suitable for children and may include intense violence,
sexual situations, coarse language and suggestive dialogue.



  reply	other threads:[~2003-04-23  8:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-20  1:08 Q re pack & aliased tmoran
2003-04-20 11:40 ` David Holm
2003-04-21  4:44   ` tmoran
2003-04-22 16:08     ` Jacob Sparre Andersen
2003-04-22 16:30       ` Vinzent Hoefler
2003-04-22 16:44         ` tmoran
2003-04-22 17:23           ` Stephen Leake
2003-04-22 21:45             ` Robert A Duff
2003-04-22 22:25               ` tmoran
2003-04-22 23:10                 ` Nick Roberts
2003-04-23  0:24                   ` tmoran
2003-04-23  8:07                     ` Vinzent Hoefler [this message]
2003-04-23 17:18                       ` tmoran
2003-04-23 19:28                         ` Vinzent Hoefler
2003-04-23 11:52                     ` Martin Dowie
2003-04-25 16:06                     ` Nick Roberts
2003-04-25 16:38                       ` Vinzent Hoefler
2003-04-22 22:51           ` Matthew Heaney
2003-04-22 23:16             ` Nick Roberts
replies disabled

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