comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: On packages hierarchy
Date: Tue, 29 Jul 2014 15:26:49 -0600
Date: 2014-07-29T15:26:49-06:00	[thread overview]
Message-ID: <ukUBv.162262$4k2.6299@fx23.iad> (raw)
In-Reply-To: <ly8uncq7cw.fsf@pushface.org>

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.

      reply	other threads:[~2014-07-29 21:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-28 13:41 On packages hierarchy Victor Porton
2014-07-28 16:03 ` Shark8
2014-07-28 16:35   ` Victor Porton
2014-07-28 23:24     ` Shark8
2014-07-29 12:36       ` Victor Porton
2014-07-29 18:44         ` Shark8
2014-07-29 19:42           ` Simon Wright
2014-07-29 21:26             ` Shark8 [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox