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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Creating several types from a base type and conversion Date: Sun, 19 Jan 2020 02:07:33 +0200 Organization: Tidorum Ltd Message-ID: References: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com> <536e9961-f454-44d9-95a6-aecaaee1addf@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net ZjxeER4GgEUU2xgqYuDEsAHGuH9fbimrYS2aUUrNJYpSd4dq4I Cancel-Lock: sha1:x4fsXA/T/6Wj0cEa6s+P7G2kcTk= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 In-Reply-To: <536e9961-f454-44d9-95a6-aecaaee1addf@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57888 Date: 2020-01-19T02:07:33+02:00 List-Id: On 2020-01-19 0:16, Ken Roberts wrote: > > > package core is > > -- > -- 30-bit word size (CP642/A/B) > -- Data : 0 .. 2**29 > -- Half-word > -- Upper : at 0 range 15 .. 29 > -- Lower : at 0 range 00 .. 14 This means that you (and/or the documentation of the original computer) are using little-endian bit numbering, in which the less-significant 15 bits are numbered 0 .. 14, and the more significant are numbered 15 .. 29. Note, again, that the bit-numbering scheme can be different in different Ada compilers or for different target computers, which means that if you Unchecked_Convert a record type with a representation clause from or to an integer or modular type (wuth the same size) you must use the Bit_Order aspect to ensure portability across Ada compilers. > WORD_BITS : constant := 30; > WORD_MASK : constant := 8#77777_77777#; > HALF_WORD_BITS : constant := 15; > HALF_WORD_MASK : constant := 8#77777#; Most Ada programmers do not use all-caps for constants (or named numbers, as here), because they are not preprocessor macros as in C, but are more like ordinary objects or variables in Ada. You can of course define your own style, this is just a remark. > for DataWord use record > for Upper use HALF_WORD_BITS .. (WORD_BITS - 1); > for Lower use 00 .. (HALF_WORD_BITS - 1); > end record; > pragma pack (DataWord); Pragma Pack has two uses: first, to reduce the amount of memory used for data, which is probably not relevant for your emulator; second, to squeeze records like this into a "word" of a certain size, usually to make it possible to Unchecked_Convert it to/from some other type of the same size, and this is probably your goal here. But note that pragma Pack, even when accepted by the compiler, does _not_ mean that the compiler uses a size that is the sum of the widths of the bit-ranges in the representation clause; the compiler could, for whatever reason, add some space. Therefore it is good practice, IMO, to always add a Size clause if you want a certain size. Therefore I would add, to every pragma Pack that is meant to produce 30 bits, the clause "for the_type'Size use 30;". (But the errors in the type declarations must first be corrected, of course.) -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .