From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca.giganews.com!nntp.giganews.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: 'Size hack for enumerated types Date: Sun, 06 Jul 2014 08:22:29 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="117da9042fa4d6f5956a9b8f72035635"; logging-data="14167"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tGn9xxVOjMxIZiPfm2do9f+Z9nQgvsOo=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:0Q/HePhuQ7HgUPLVc2gDQ5V780g= sha1:5D09jbi1djOR5RsQZIE2DPL5tTU= Xref: number.nntp.dca.giganews.com comp.lang.ada:187390 Date: 2014-07-06T08:22:29+01:00 List-Id: Victor Porton 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