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,5697899e4423465c X-Google-Attributes: gid103376,public From: "Samuel T. Harris" Subject: Re: Boolean Representation Date: 1998/09/24 Message-ID: <360A8CCB.2D358953@hso.link.com>#1/1 X-Deja-AN: 394452579 Content-Transfer-Encoding: 7bit References: <6udkcj$87j$1@nnrp1.dejanews.com> <6udriu$hfi$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=us-ascii Organization: Raytheon Training Inc. Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-09-24T00:00:00+00:00 List-Id: dewarr@my-dejanews.com wrote: > > In article <6udkcj$87j$1@nnrp1.dejanews.com>, > matthew_snyder@my-dejanews.com wrote: > > Is it safe to make the assumption that a boolean value of FALSE will always > > be represented as a 0 and a value of TRUE will always be represented as a 1? > > Will an unchecked conversion from a boolean to an integer always yield the > > same results with different compilers? > > Whether true or false, this is junky coding, just use > Boolean'Pos (val) to get 0 or 1 in a for sure portable > manner. Remember that to use an unchecked conversion for > Boolean, you would have to use a 1-bit integer, anything > else most definitely gives an implementation defined result. > Good advice. In general I also am not concerned with the internal representations of enumeration literals. I'm usually concerned only with their order and the fact that each has a unique ordinal within its type. However, I have had occasion to be concerned with the actual internal representation. This is where enumeration representation clauses come in handy. Specifically, I have had to represent a memory-mapped device with an Ada record. One of the fields was a 16-bit flag array. A packed array of booleans fit nicely. However, to insure the boolean literals FALSE and TRUE have the appropriate internal numbers, I used a derived type of boolean to which I applied the appropriate representation clause. I know that this might sound a bit paranoid but I tend to favor ultra-correctness over any reliance on common compiler implementations. -- Samuel T. Harris, Principal Engineer Raytheon Training Incorporated "If you can make it, We can fake it!"