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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d9523383d7eb42d0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-22 14:56:28 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3C4DEE09.B34A579@Raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.5 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Confused about Attribute Size? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 22 Jan 2002 16:56:09 -0600 NNTP-Posting-Host: 192.27.48.44 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1011740187 192.27.48.44 (Tue, 22 Jan 2002 16:56:27 CST) NNTP-Posting-Date: Tue, 22 Jan 2002 16:56:27 CST Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:19204 Date: 2002-01-22T16:56:09-06:00 List-Id: Zebylon wrote: > > Hi, > > I'm a newbie in Ada but I saw an Ada example that confused me a bit, here it > is: > See comments after each block of code and the questions at the end.... > type My_Type is > (startbit, > endbit, > timeout, > spare, > nextbit, > ...... > ...... > lastbit); > Ok, we define an enumeration of several values. > for My_Type use > (startbit =>0, > endbit=>1, > timeout=>2, > spare=>3, > nextbit=>4, > ...... > ...... > lastbit=>15); > A representation specification that requires startbit to be zero, endbit to be one, and so on. Assuming the items are sequential, there are 16 possible values, 0 through 15. > for My_Type'Size use 8; > Another representation specification. In this case, you are asking that the 16 possible values to be stored in an eight bit byte (or larger). There are several cases where the compiler can use more than 8 bits to store My_Type... - a record component if the record is NOT packed - array components - a formal parameter passed to a function or procedure There are several pages of dense text in the Annotated Ada Reference Manual in section 13.3 that describes this in far more detail that I will attempt to describe - especially to a newbie. > type My_Type_Array is array (My_Type) of Boolean; > An array of 16 boolean values (index is startbit..lastbit). Hmm. Since you did not specify a representation specification nor pragma Packed for this data type, the compiler could... - generate a 16 bit array (two bytes) - generate a 16 byte array (16 bytes) - generate a 16 [some easy to address size goes here] array (16 x n bytes) Without the representation specification or pragma, "you don't care" about the size, you care about an efficient implementation. > What I don't understand is how you can assign the size to 8 bits? > How will this work when there are 16 bits in the type? I assume you refer to My_Type'Size (8) and not My_Type_Array'Size (>=16). Eight bits is more than enough bits to represent 16 values from 0 to 15. > What will be the size of the array? Hmm. You didn't specify the size explicitly, therefore the compiler can pick something "convenient". As I mentioned above, it will likely be some multiple of 16 bits. As small as 16, not likely, but could as large or larger than 16 x 64. > This example was in Ada 83 could this be a clue? Nope. At this level, this code would be the same in Ada 83 and Ada 95. -- --Mark