From: Markus Schoepflin <nospam@no.spam>
Subject: Enumeration representation clause surprise.
Date: Wed, 11 Jun 2008 13:38:17 +0200
Date: 2008-06-11T13:38:17+02:00 [thread overview]
Message-ID: <g2odf9$3um$1@nntp.ilk.net> (raw)
Hello,
please consider the following code snippet:
type ENUM_T is (ONE, TWO);
for ENUM_T use (ONE => 1, TWO => 2);
type RECORD_T is record
A1 : ENUM_T;
A2 : ENUM_T;
end record;
for RECORD_T use record
A1 at 0 range 0 .. 0; -- (*)
A2 at 1 range 0 .. 7;
end record;
for RECORD_T'Size use 2 * 8;
FOO : RECORD_T;
I was _very_ surprised to discover that when executing
FOO.A1 := TWO;
FOO.A2 := TWO;
the binary content of FOO looks like this:
00000010 00000001
IOW, for A1 ONE is coded as 0 and TWO as 1, and for A2 ONE is coded as 1
and TWO as 2.
I checked this with GNAT 3.4.5 and some old DEC Ada compiler, therefore I
think this behaviour is compiler independent.
Anybody knows why the compiler is allowed to silently ignore my
representation clause for the enumeration? I would have expected to get an
error at the indicated line, telling me that A1 is too small.
BTW, this was found in a real word application, where code like this was
used to model a given external interface, and later the enumeration was
extended by a few values, but the record representation clause was never
updated.
Is there a way I can protect myself from this very nasty trap?
Best regards,
Markus
next reply other threads:[~2008-06-11 11:38 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-11 11:38 Markus Schoepflin [this message]
2008-06-11 12:30 ` Enumeration representation clause surprise christoph.grein
2008-06-11 12:56 ` Markus Schoepflin
2008-06-11 13:08 ` christoph.grein
2008-06-11 13:28 ` Samuel Tardieu
2008-06-11 13:48 ` Markus Schoepflin
2008-06-11 13:56 ` Samuel Tardieu
2008-06-11 14:58 ` Adam Beneschan
2008-06-11 15:23 ` Markus Schoepflin
2008-06-12 2:37 ` Randy Brukardt
2008-06-12 2:37 ` Randy Brukardt
2008-06-11 15:56 ` Samuel Tardieu
2008-06-11 19:10 ` Adam Beneschan
2008-06-11 19:59 ` Niklas Holsti
2008-06-12 1:16 ` tmoran
2008-06-12 8:27 ` christoph.grein
2008-06-12 8:45 ` Markus Schoepflin
2008-06-12 16:43 ` Mike Silva
2008-06-12 18:41 ` Markus Schöpflin
2008-06-12 20:10 ` Mike Silva
2008-06-12 20:52 ` Simon Wright
2008-06-12 23:36 ` Mike Silva
2008-06-13 5:49 ` Simon Wright
2008-06-13 7:21 ` Keith Thompson
2008-06-13 13:31 ` Mike Silva
2008-06-13 14:45 ` Markus Schoepflin
2008-06-13 17:52 ` Keith Thompson
2008-06-13 9:14 ` Jean-Pierre Rosen
2008-06-12 19:05 ` richtmyer
2008-06-12 21:26 ` Samuel Tardieu
2008-06-12 22:42 ` Adam Beneschan
2008-06-13 7:11 ` Samuel Tardieu
2008-06-13 8:27 ` christoph.grein
2008-06-13 16:21 ` Adam Beneschan
2008-06-15 19:33 ` Robert A Duff
2008-06-16 14:50 ` Adam Beneschan
2008-06-16 19:18 ` Robert A Duff
2008-06-17 6:03 ` christoph.grein
2008-06-17 7:22 ` christoph.grein
2008-06-13 8:24 ` Peter Hermann
2008-06-13 14:47 ` Samuel Tardieu
2008-06-14 11:48 ` John B. Matthews
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox