comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: 'Size hack for enumerated types
Date: Sun, 06 Jul 2014 08:22:29 +0100
Date: 2014-07-06T08:22:29+01:00	[thread overview]
Message-ID: <ly7g3reytm.fsf@pushface.org> (raw)
In-Reply-To: lp9t79$5pj$1@speranza.aioe.org

Victor Porton <porton@narod.ru> writes:

> Simon Wright wrote:
>>> What is a better way to do this?
>> 
>> Just use convention C:
>> 
>>    type Flag_Type is (Libxml_Error_Save,
>>                       Libxml_Structured_Error_Save,
>>                       URI_Interning,
>>                       WWW_Skip_Init_Finish) with Convention => C;
>
> Your code does not allow to assign particular numbers to the
> enumeration literals. :-(

I just didn't put that in since you already had it.

   with Ada.Text_IO; use Ada.Text_IO;
   procedure Enums is
      type Flag_Type is (Libxml_Error_Save,
                         Libxml_Structured_Error_Save,
                         URI_Interning,
                         WWW_Skip_Init_Finish) with Convention => C;
      for Flag_Type use (Libxml_Error_Save => 1,
                         Libxml_Structured_Error_Save => 2,
                         URI_Interning => 3,
                         WWW_Skip_Init_Finish => 4);
      F : Flag_Type;
      I : Integer with Address => F'Address, Import => Ada;
   begin
      Put_Line ("'Size:       " & Flag_Type'Size'Img);
      Put_Line ("'Object_Size:" & Flag_Type'Object_Size'Img);
      Put_Line ("F'Size:      " & F'Size'Img);
      F := URI_Interning;
      Put_Line ("F:            " & F'Img);
      Put_Line ("I:           " & I'Img);
   end Enums;

(sorry about the hidden unchecked conversion) resulting in

   $ ./enums 
   'Size:        3
   'Object_Size: 32
   F'Size:       32
   F:            URI_INTERNING
   I:            3



  parent reply	other threads:[~2014-07-06  7:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-05 20:32 'Size hack for enumerated types Victor Porton
2014-07-05 21:47 ` Simon Wright
2014-07-05 22:11   ` Victor Porton
2014-07-05 22:18     ` Victor Porton
2014-07-05 22:23       ` Victor Porton
2014-07-06 16:25         ` Victor Porton
2014-07-06 20:59       ` Simon Wright
2014-07-06 23:01         ` Victor Porton
2014-07-06 23:30           ` Jeffrey Carter
2014-07-07 16:00             ` Victor Porton
2014-07-07 17:12               ` Simon Wright
2014-07-07 20:23                 ` Victor Porton
2014-07-08  7:04                   ` Simon Wright
2014-07-08 10:17                     ` sbelmont700
2014-07-08 14:53                     ` Dan'l Miller
2014-07-08 20:56                       ` Randy Brukardt
2014-07-08 22:26                         ` Dan'l Miller
2014-07-08 23:18                         ` Jeffrey Carter
2014-07-08  9:43                   ` AdaMagica
2014-07-08 13:52                     ` Victor Porton
2014-07-08 15:02                       ` Simon Wright
2014-07-07  7:45           ` Simon Wright
2014-07-06  7:22     ` Simon Wright [this message]
2014-07-06 13:21 ` sbelmont700
2014-07-06 16:16   ` Victor Porton
2014-07-06 17:52     ` sbelmont700
replies disabled

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