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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fd173879a595bde X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!cycny01.gnilink.net!cyclone1.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc06.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Anonymous Coward Subject: 'Size can mean value size OR object size, depending.. References: Message-Id: User-Agent: slrn/0.9.7.4 (Linux) Date: Wed, 09 Nov 2005 02:12:47 GMT NNTP-Posting-Host: 141.149.78.234 X-Complaints-To: abuse@verizon.net X-Trace: trnddc06 1131502367 141.149.78.234 (Tue, 08 Nov 2005 21:12:47 EST) NNTP-Posting-Date: Tue, 08 Nov 2005 21:12:47 EST Xref: g2news1.google.com comp.lang.ada:6308 Date: 2005-11-09T02:12:47+00:00 List-Id: In article , 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.