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!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc03.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Anonymous Coward Subject: Re: '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 04:04:17 GMT NNTP-Posting-Host: 141.149.78.234 X-Complaints-To: abuse@verizon.net X-Trace: trnddc03 1131509057 141.149.78.234 (Tue, 08 Nov 2005 23:04:17 EST) NNTP-Posting-Date: Tue, 08 Nov 2005 23:04:17 EST Xref: g2news1.google.com comp.lang.ada:6316 Date: 2005-11-09T04:04:17+00:00 List-Id: In article , Jeffrey R. Carter wrote: > > Note that 'Object_Size is GNAT specific. The portable way to obtain > this value is to use 'Size on an object: > > X : T; > > X'Size That's interesting! I would not have expected ADA to even allow compilers to offer their own attributes like that. It seems like a bad thing. Folks could unwittingly write GNAT only code, which would break later on if a different compiler is chosen. For the archives, here's a complete example that includes Jeff's comment: with Ada.Text_Io; procedure Size_Example is type Color_Type is (Red, Green, Blue); pragma Convention (Convention => C, Entity => Color_Type); --In this case, 'Size really means the *object* size! -- --for Entity_Type'Size use 32; --not needed with convention C! Color_Object : Color_Type := Color_Type'First; begin --GNAT *uniquely* offers a 'Object_Size attribute, --so the following line is not ADA! -- Ada.Text_Io.Put_Line ("The object size is " & Integer'Image(Color_Type'Object_Size) & " GNAT only!"); --ADA does not provide an attribute to get the object size of a type. --You can only acquire this by doing a 'Size directly on an object: -- Ada.Text_Io.Put_Line ("The object size is " & Integer'Image(Color_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(Color_Type'Size)); end Size_Example; Output: The object size is 32 GNAT only! The object size is 32 The value size is 2