From: Lucretia <laguest9000@googlemail.com>
Subject: What shoudl GNAT do wrt variant record and representation clauses?
Date: Sun, 1 Feb 2015 17:29:49 -0800 (PST)
Date: 2015-02-01T17:29:49-08:00 [thread overview]
Message-ID: <49494faf-1e2d-43a1-a2b0-fd25af3850cc@googlegroups.com> (raw)
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.
Well, I was getting an inconsistent failure, so I printed out both numbers in base 2, but multiple invocations caused 1 bit to be set or unset depending on the call:
<log>
Pixel_Format_Index_1_LSB (2#10001000100000000000100000000#) /= C_Index_1_LSB (2#10001000100000000000100000000#)
Pixel_Format_Index_1_MSB (2#10001101000000000000100000000#) /= C_Index_1_MSB (2#10001001000000000000100000000#)
FAIL Pixel format test
Pixel_Format_Index_1_MSB (2#10001101000000000000100000000#) /= C_Index_1_MSB (2#10001001000000000000100000000#)
at pixel_format_test_cases.adb:75
Total Tests Run: 1
Successful Tests: 0
Failed Assertions: 1
Unexpected Errors: 0
laguest@rogue ~/src/mine/sdlada $ ./build_unit_tests/unit_tests
Pixel_Format_Index_1_LSB (2#10001000100000000000100000000#) /= C_Index_1_LSB (2#10001000100000000000100000000#)
Pixel_Format_Index_1_MSB (2#10001001000000000000100000000#) /= C_Index_1_MSB (2#10001001000000000000100000000#)
OK Pixel format test
Total Tests Run: 1
Successful Tests: 1
Failed Assertions: 0
Unexpected Errors: 0
</log>
Couldn't see anything wrong, took a break, came back and looked at the record in question:
<code>
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;
</code>
The full source is here: https://github.com/Lucretia/sdlada/blob/master/src/sdl-video-pixel_formats.ads
I changed the Indexed_Order range to finish at bit 3, like the others. Compiled and ran, it worked. Multiple times in a row, I kept trying. Still working.
So, is this correct behaviour? If so, is there a compiler flag to catch this?
Thanks,
Luke.
next reply other threads:[~2015-02-02 1:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-02 1:29 Lucretia [this message]
2015-02-02 7:45 ` What shoudl GNAT do wrt variant record and representation clauses? jsquirek
2015-02-02 7:55 ` Lucretia
2015-02-02 9:04 ` Simon Wright
2015-02-04 9:59 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox