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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,81d15b71303dd93 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Redefining Integer Date: 1997/11/16 Message-ID: #1/1 X-Deja-AN: 290062039 Distribution: world References: <640di0$l432@castor.cca.rockwell.com> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-11-16T00:00:00+00:00 List-Id: In article <640di0$l432@castor.cca.rockwell.com>, No@Junk.Mail wrote: >I am porting some old code that assumes Integer is 16-bits and does lots >of unchecked conversions based on this fact. Well, there is your first problem. Every single Ada book I've ever read warns precisely against assuming a specific size for a predefined type, and strongly encourages defining a user-defined type when low-level programming is required. Why didn't the developers heed that advice? >When "Integer" is redefined in the same declarative region that it is >used it works fine: > > type Integer is range -2**15 .. 2**15 - 1; > for Integer'Size use 16; You should never do this. If you want a 16 bit signed integer, then use the type Integer_16 declared in the predefined Ada package Interfaces. > subtype bit_range is integer range 0 .. integer'size - 1; > type packed_boolean_array is array (Bit_Range) of Boolean; > for packed_boolean_array'Size use 16; > pragma Pack (packed_boolean_array); Don't bother tying the Bit_Range type to the size, just do this subtype Bit_Range is Integer range 0 .. 15; You already hard-coded the fact that the type has to be 16 bits in the size clause, so why not hard-code that info in the index subtype too? If you want, you could do this Packed_Boolean_Array_Size : constant := 16; subtype Bit_Range is Natural range 0 .. Package_Boolean_Array_Size - 1; type Packed_Boolean_Array is array (Bit_Range) of Boolean; pragma Pack (Packed_Boolean_Array); for Package_Boolean_Array'Size use Packed_Boolean_Array_Size; I don't know why the compiler didn't flag the fact that the type named Integer was defined in two directly visible scopes. But because one should never, ever use the names in package Standard for user-defined type names, you don't typically have the problem. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271