comp.lang.ada
 help / color / mirror / Atom feed
From: Anonymous Coward <spam@spam.com>
Subject: 'Size can mean value size OR object size, depending..
Date: Wed, 09 Nov 2005 02:12:47 GMT
Date: 2005-11-09T02:12:47+00:00	[thread overview]
Message-ID: <slrndn2tqr.lo7.bogus_addy@tango.mindfuq.org> (raw)
In-Reply-To: uk6fn758i.fsf@acm.org

In article <uk6fn758i.fsf@acm.org>, Stephen Leake wrote:
> 
> Hmm. You seem to be saying "convention (C) doesn't work for
> me". That seems like a bug. Can you post some code that doesn't
> work? Or have you submitted a bug report?

I explored this issue a little more, and it looks like it was my
error.  I thought 'Size returned the object size, not the value size!
To top it off, I was using GNAT 2.8.1, which does not have a
-gnatR[1-3] switch.  If it did, this it would have clearly given me
this output for my enum:

   $ gcc -c -gnatR3 main.adb
    
   Representation information for unit Main (body)
   -----------------------------------------------
    
   for Entity_Type'Object_Size use 32;
   for Entity_Type'Value_Size use 2;
   for Entity_Type'Alignment use 4;

   $ gcc --version
   gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

(as you can see, later versions of GNAT support 
 enum representation printing) 

So at work I was reliant on 'Size to tell me how large the enum is,
not knowing until now that 'Object_Size is really an attribute
operation.  I thought 'Object_Size was just gnats way of making the
distinction.  

So this code:

   with Ada.Text_Io;

   procedure Main is

      type Entity_Type is (Red, Green, Blue);

      pragma Convention (Convention => C, Entity => Entity_Type);

      --In this case, 'Size really means the *object* size!
      --
      --for Entity_Type'Size use 32; --not needed with convention C!

   begin

      Ada.Text_Io.Put_Line ("The object size is " & 
                            Integer'Image(Entity_Type'Object_Size));

      --ADA throws a curve ball here, by changing the meaning of 'Size
      --to actually indicate the *value* size in this case!
      --
      Ada.Text_Io.Put_Line ("The value size is "  & 
                            Integer'Image(Entity_Type'Size));

   end Main;

generates:

   The object size is  32
   The value size is  2

proving that pragma convention effectively works on enumeration
types.  So in the interest of writing clean code, I do not intend to
rep spec enum sizes anymore, because pragma Convention takes care of
this from a higher level.



  parent reply	other threads:[~2005-11-09  2:12 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04  2:21 Default rep specs for record types - documented?? Anonymous Coward
2005-11-04  2:36 ` Steve
2005-11-04  4:11   ` Anonymous Coward
2005-11-04  5:30     ` Jeffrey R. Carter
2005-11-05  3:13       ` Steve
2005-11-05  4:45         ` Jeffrey R. Carter
2005-11-06 14:05           ` Steve
2005-11-06 16:08             ` Anonymous Coward
2005-11-07  7:25             ` Jeffrey R. Carter
2005-11-08 13:36               ` Steve
2005-11-14  1:12             ` Robert A Duff
2005-11-14  3:03               ` Anonymous Coward
2005-11-14 18:08                 ` Jeffrey R. Carter
2005-11-14 18:49                 ` Robert A Duff
2005-11-15  1:16                   ` ADA compilers can reject types arbitrarily? Anonymous Coward
2005-11-15  2:10                     ` tmoran
2005-11-15  3:12                     ` Robert A Duff
2005-11-15  6:44                     ` Simon Wright
2005-11-16  0:16                       ` Adaists Deny Acronym. (was: ADA compilers can reject types arbitrarily?) Björn Persson
2005-11-16  5:38                         ` Adaists Deny Acronym Simon Wright
2005-11-16  6:16                         ` Adaists Deny Acronym. (was: ADA compilers can reject types arbitrarily?) Samuel Tardieu
2005-11-15 12:43                     ` ADA compilers can reject types arbitrarily? Jeff Creem
2005-11-14 21:14                 ` Default rep specs for record types - documented?? Simon Wright
2005-11-04 13:26     ` Stephen Leake
2005-11-04 14:33       ` Marc A. Criley
2005-11-04 18:35         ` Georg Bauhaus
2005-11-04 20:07           ` Britt Snodgrass
2005-11-04 14:39       ` Stephen Leake
2005-11-04 15:27         ` Britt Snodgrass
2005-11-04 15:55           ` Lauri Ora
2005-11-04 21:42             ` Larry Kilgallen
2005-11-05  2:26             ` Anonymous Coward
2005-11-05  2:42               ` Frank J. Lhota
2005-11-05  3:27               ` Ed Falis
2005-11-05  3:55                 ` Anonymous Coward
2005-11-05  4:07                 ` Lauri Ora
2005-11-05 13:46                   ` Ed Falis
2005-11-05 10:14                 ` Stephen Leake
2005-11-04 16:52         ` Frank J. Lhota
2005-11-04 16:57           ` Frank J. Lhota
2005-11-04 23:27           ` tmoran
2005-11-05 10:25           ` Stephen Leake
2005-11-14  1:09             ` Robert A Duff
2005-11-05  3:33       ` Anonymous Coward
2005-11-05 10:34         ` Stephen Leake
2005-11-05 16:35           ` ADA/C interfaces: type representations uncontrollable in C Anonymous Coward
2005-11-05 16:49             ` Ed Falis
2005-11-05 18:24             ` tmoran
2005-11-09  2:12           ` Anonymous Coward [this message]
2005-11-09  3:27             ` 'Size can mean value size OR object size, depending Jeffrey R. Carter
2005-11-09  4:04               ` Anonymous Coward
2005-11-05 14:27         ` Default rep specs for record types - documented?? Michael Bode
2005-11-05 16:17           ` pragma convention Anonymous Coward
2005-11-06  1:07             ` Jeffrey R. Carter
2005-11-06 22:22               ` Anonymous Coward
2005-11-07  7:34                 ` Jeffrey R. Carter
2005-11-05 14:39         ` Default rep specs for record types - documented?? Martin Krischik
2005-11-04  9:40   ` Martin Dowie
2005-11-04 14:36   ` Marc A. Criley
2005-11-04 17:45 ` Martin Krischik
replies disabled

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