comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: What shoudl GNAT do wrt variant record and representation clauses?
Date: Wed, 04 Feb 2015 03:59:28 -0600
Date: 2015-02-04T03:59:28-06:00	[thread overview]
Message-ID: <85oapa3slb.fsf@stephe-leake.org> (raw)
In-Reply-To: 49494faf-1e2d-43a1-a2b0-fd25af3850cc@googlegroups.com

Lucretia <laguest9000@googlemail.com> writes:

> Hi,
>
> I've been back on SDLAda, one bit I've been dreading, setting up a
> unit test to check to make sure my representations of the pixel
> formats are the same as what the C macros produce.

Use -fdump-ada-spec, then you don't need to write records or tests.

>    type Pixel_Orders (Pixel_Type : Pixel_Types := Unknown) is
>       record
>          case Pixel_Type is
>             when Index_1 | Index_4 | Index_8 =>
>                Indexed_Order : Bitmap_Pixel_Order;
>
>             when Packed_8 | Packed_16 | Packed_32 =>
>                Packed_Order  : Packed_Component_Order;
>
>             when Array_U8 | Array_U16 | Array_U32 | Array_F16 | Array_F32 =>
>                Array_Order   : Array_Component_Order;
>
>             when others =>
>                null;
>          end case;
>       end record with
>         Unchecked_Union => True,
>         Convention      => C,
>         Size            => 4;
>
>    for Pixel_Orders use
>       record
>          Indexed_Order at 0 range 0 .. 2;
>          Packed_Order  at 0 range 0 .. 3;
>          Array_Order   at 0 range 0 .. 3;
>       end record;

> So, is this correct behaviour?

Your original version says there is one bit that is unspecified for
Pixel_Type in Index_1 | Index_4 | Index_8, so yes, this is correct
behavior.

Another way to handle the extra bit is:

          case Pixel_Type is
             when Index_1 | Index_4 | Index_8 =>
                Indexed_Order : Bitmap_Pixel_Order;
                Spare_1 : Boolean;

>If so, is there a compiler flag to catch this?

Consulting the secret documentation:

(info "(gnat_ugn) Warning Message Control")
C-s record

turns up "-gnatw.h (holes in record layouts)"

--
-- Stephe

      parent reply	other threads:[~2015-02-04  9:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-02  1:29 What shoudl GNAT do wrt variant record and representation clauses? Lucretia
2015-02-02  7:45 ` jsquirek
2015-02-02  7:55   ` Lucretia
2015-02-02  9:04 ` Simon Wright
2015-02-04  9:59 ` Stephen Leake [this message]
replies disabled

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