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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45a9122ddf5fcf5 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Rules for Representation of Subtypes Date: 1996/09/23 Message-ID: <01bba947$d8990620$188371a5@dhoossr.iquest.com>#1/1 X-Deja-AN: 184767529 distribution: world references: content-type: text/plain; charset=ISO-8859-1 organization: DBH Enterprises, Inc. mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-09-23T00:00:00+00:00 List-Id: Matthew Heaney wrote in article ... > I've always been curious about the rules for representation of subtypes. > For example, if I make a declaration like this: > > A_Small_Integer : Integer range 0 .. 255; -- assume type Integer is 4 bytes > > then is an implementation allowed to use fewer than 4 bytes to represent > A_Small_Integer? > > Suppose I'm on a Unix system and I do this > > read (fd, A_Small_Integer'Address, 4); > > If the representation of A_Small_Integer is only 1 byte, then obviously I'm > in trouble. Am I required to specify the size of objects? > > A_Small_Integer : Integer range 0 .. 255; > for A_Small_Integer'Size use 32; -- required? > > matt > mheaney@ni.net > > -------------------------------------------------------------------- > Matthew Heaney > Software Development Consultant > mheaney@ni.net > (818) 985-1271 > Hi Matthew, My understanding of the rules for representation clauses for types is that the size attribute may only be specified for the first subtype, so for any subtype of integer you would get the same size as Integer. In fact, I just tried to specify a size of 8 bits for your object "A_Small_Integer", with gnat 3.04a on Win95, and found that the compiler gave no warning, and ignored the clause. Printing out the 'size attribute yielded 32. However, as far as your "UNIX" example is concerned (I say "UNIX", because this would apply to any OS where you're doing what you appear to be doing here -- i.e. interfacing to the C library), why not write the code in a manner where it doesn't matter how the compiler represents the object -- i.e., write: read (fd, A_Small_Integer'Address, A_Small_Integer'Size / System.Storage_Unit); The division is a compile-time operation, so there is no run-time difference. I hope this helps -- David C. Hoos, Sr., http://www.dbhwww.com http://www.ada95.com