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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx23.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:30.0) Gecko/20100101 Thunderbird/30.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: On packages hierarchy References: <4vuBv.121143$pu5.79212@fx27.iad> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Tue, 29 Jul 2014 21:26:50 UTC Organization: TeraNews.com Date: Tue, 29 Jul 2014 15:26:49 -0600 X-Received-Bytes: 2587 X-Received-Body-CRC: 28735136 Xref: news.eternal-september.org comp.lang.ada:21343 Date: 2014-07-29T15:26:49-06:00 List-Id: On 29-Jul-14 13:42, Simon Wright wrote: > Given that Light_Number'Size is set to 3 (above), and is biased into the > bargain, I don't see how this is going to work reliably? GNAT is > certainly going to give you warnings about source & target having > different sizes. It should work as expected: > testbed.adb:37:58: warning: size clause forces biased representation for "Light_Number" > testbed.adb:60:09: warning: types for unchecked conversion have different sizes > testbed.adb:60:09: warning: size of "Light_Number" is 3, size of "Gl_Enum" is 32 > testbed.adb:60:09: warning: source will be extended with 29 high order zero bits >... and ( from http://docs.adacore.com/gnat-unw-docs/html/gnat_rm_9.html#SEC485 ) > For example, suppose we have the declaration: > > > > type Small is range -7 .. -4; > for Small'Size use 2; > > Although the default size of type Small is 4, the Size clause is accepted by GNAT and > results in the following representation scheme: > > > > -7 is represented as 2#00# > -6 is represented as 2#01# > -5 is represented as 2#10# > -4 is represented as 2#11# Which means that: 1 would be represented ad 2#000# 2 would be represented ad 2#001# 3 would be represented ad 2#010# etc That internal representation *is* the zero-based indexing that OpenGL expects, and Convert (as shown above) extends its size with zero-bits. So there's no reason it shouldn't work. Granted it's going off a lot of implementation-defined behavior and your method of an array or my suggestion of a proper conversion-function expression-function would handle this in an implementation independent manner.