Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Enumeration rep...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 42 Topic 5748 of 5930
Post > Topic >>

Enumeration representation clause surprise.

by Markus Schoepflin <nospam@[EMAIL PROTECTED] > Jun 11, 2008 at 01:38 PM

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
 




 42 Posts in Topic:
Enumeration representation clause surprise.
Markus Schoepflin <nos  2008-06-11 13:38:17 
Re: Enumeration representation clause surprise.
christoph.grein@[EMAIL PR  2008-06-11 05:30:35 
Re: Enumeration representation clause surprise.
Markus Schoepflin <nos  2008-06-11 14:56:34 
Re: Enumeration representation clause surprise.
Samuel Tardieu <sam@[E  2008-06-11 15:28:36 
Re: Enumeration representation clause surprise.
Markus Schoepflin <nos  2008-06-11 15:48:09 
Re: Enumeration representation clause surprise.
Samuel Tardieu <sam@[E  2008-06-11 15:56:28 
Re: Enumeration representation clause surprise.
christoph.grein@[EMAIL PR  2008-06-11 06:08:06 
Re: Enumeration representation clause surprise.
Adam Beneschan <adam@[  2008-06-11 07:58:44 
Re: Enumeration representation clause surprise.
Markus Schoepflin <nos  2008-06-11 17:23:25 
Re: Enumeration representation clause surprise.
"Randy Brukardt"  2008-06-11 21:37:06 
Re: Enumeration representation clause surprise.
"Randy Brukardt"  2008-06-11 21:37:06 
Re: Enumeration representation clause surprise.
Samuel Tardieu <sam@[E  2008-06-11 17:56:12 
Re: Enumeration representation clause surprise.
Adam Beneschan <adam@[  2008-06-11 12:10:33 
Re: Enumeration representation clause surprise.
Niklas Holsti <niklas.  2008-06-11 22:59:12 
Re: Enumeration representation clause surprise.
tmoran@[EMAIL PROTECTED]   2008-06-11 20:16:54 
Re: Enumeration representation clause surprise.
christoph.grein@[EMAIL PR  2008-06-12 01:27:45 
Re: Enumeration representation clause surprise.
Markus Schoepflin <nos  2008-06-12 10:45:14 
Re: Enumeration representation clause surprise.
Mike Silva <snarflemik  2008-06-12 09:43:45 
Re: Enumeration representation clause surprise.
=?ISO-8859-1?Q?Markus_Sch  2008-06-12 20:41:37 
Re: Enumeration representation clause surprise.
Mike Silva <snarflemik  2008-06-12 13:10:49 
Re: Enumeration representation clause surprise.
Simon Wright <simon.j.  2008-06-12 21:52:56 
Re: Enumeration representation clause surprise.
Keith Thompson <kst-u@  2008-06-13 00:21:08 
Re: Enumeration representation clause surprise.
Jean-Pierre Rosen <ros  2008-06-13 11:14:09 
Re: Enumeration representation clause surprise.
Mike Silva <snarflemik  2008-06-12 16:36:19 
Re: Enumeration representation clause surprise.
Simon Wright <simon.j.  2008-06-13 06:49:09 
Re: Enumeration representation clause surprise.
Mike Silva <snarflemik  2008-06-13 06:31:41 
Re: Enumeration representation clause surprise.
Markus Schoepflin <nos  2008-06-13 16:45:09 
Re: Enumeration representation clause surprise.
Keith Thompson <kst-u@  2008-06-13 10:52:43 
Re: Enumeration representation clause surprise.
richtmyer@[EMAIL PROTECTE  2008-06-12 12:05:05 
Re: Enumeration representation clause surprise.
Samuel Tardieu <sam@[E  2008-06-12 23:26:55 
Re: Enumeration representation clause surprise.
Peter Hermann <ica2ph@  2008-06-13 08:24:25 
Re: Enumeration representation clause surprise.
Samuel Tardieu <sam@[E  2008-06-13 16:47:45 
Re: Enumeration representation clause surprise.
"John B. Matthews&qu  2008-06-14 07:48:33 
Re: Enumeration representation clause surprise.
Adam Beneschan <adam@[  2008-06-12 15:42:29 
Re: Enumeration representation clause surprise.
Samuel Tardieu <sam@[E  2008-06-13 09:11:17 
Re: Enumeration representation clause surprise.
christoph.grein@[EMAIL PR  2008-06-13 01:27:07 
Re: Enumeration representation clause surprise.
Adam Beneschan <adam@[  2008-06-13 09:21:02 
Re: Enumeration representation clause surprise.
Robert A Duff <bobduff  2008-06-15 15:33:03 
Re: Enumeration representation clause surprise.
Adam Beneschan <adam@[  2008-06-16 07:50:19 
Re: Enumeration representation clause surprise.
Robert A Duff <bobduff  2008-06-16 15:18:23 
Re: Enumeration representation clause surprise.
christoph.grein@[EMAIL PR  2008-06-16 23:03:18 
Re: Enumeration representation clause surprise.
christoph.grein@[EMAIL PR  2008-06-17 00:22:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 9:14:03 CDT 2008.