comp.lang.ada
 help / color / mirror / Atom feed
From: "Samuel T. Harris" <sam_harris@hso.link.com>
Subject: Re: Boolean Representation
Date: 1998/09/27
Date: 1998-09-27T00:00:00+00:00	[thread overview]
Message-ID: <360E9B5E.FF081471@hso.link.com> (raw)
In-Reply-To: 6uend9$fl8$1@nnrp1.dejanews.com

dewarr@my-dejanews.com wrote:
> 
> In article <360A8CCB.2D358953@hso.link.com>,
>   "Samuel T. Harris" <sam_harris@hso.link.com> wrote:
> > 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.
> 
> There is a difference between relying on common compiler
> implementations, and relying on the RM.
> 
> In fact the above described technique is significantly
> non-portable because of 13.4(10)
> 
>    10  An implementation should support at least the
>        internal codes in the range System.Min_Int..
>        System.Max_Int.  An implementation need
>        not support enumeration_representation_clauses
>        for boolean types.

As to portability, any compiler which does not support
the Chapter 13 features _required_ is simply not a candidate
compiler for the project. Indeed, having the representation
clause present insures an explicit "compatibility" test
when evaluating a new compiler. If the compiler does
not support the representation clause, then I'll know
it the first time I try to compile it.

In this particular case, any compiler complaining about
the representation clause _may_ be a candidate if its
default behavior is satisfactory to the problem at hand.
The represenation clause can be commented out with
additional commentary inserted explaining the reliance
on the compiler's default representation. The extra
commentary is not necessarily for the programmers
(who should know how their compiler behaves) but for
any representatives of the hardware being interfaced
who probably do not know Ada very well but are present
at design and code reviews.

> 
> On the other hand, obviously if a boolean is stored in one
> bit, False must be zero and True must be one, because
> absolute ordering is required.
> 

I don't see anything in the RM which makes this a "must"
proposition. I have been burned many times by trusting
compilers' use "common sense" implementations, GNAT
included.

> Your paranoia here is leading you astray into completely
> unnecessary and significantly implementation dependent
> coding!
> 

I contend that relying upon default compiler representations
is "significantly implementation dependent coding", especially
when the representations matter so much. When interfacing to
hardwary, my policy is to assume nothing and to leave nothing
to chance. 

-- 
Samuel T. Harris, Principal Engineer
Raytheon Training Incorporated
"If you can make it, We can fake it!"




  reply	other threads:[~1998-09-27  0:00 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-24  0:00 Boolean Representation matthew_snyder
1998-09-24  0:00 ` dennison
1998-09-24  0:00   ` Keith Thompson
1998-09-25  0:00     ` dennison
1998-09-25  0:00       ` Keith Thompson
1998-09-26  0:00         ` Tucker Taft
1998-09-26  0:00           ` Keith Thompson
1998-09-27  0:00             ` dewarr
1998-09-27  0:00             ` null pointer representation (was: Boolean Representation) Arthur Evans Jr
1998-09-27  0:00               ` Keith Thompson
1998-09-28  0:00               ` dewarr
1998-09-28  0:00                 ` Lieven Marchand
1998-09-28  0:00                 ` Keith Thompson
1998-09-28  0:00                   ` dewarr
1998-09-30  0:00                     ` Keith Thompson
1998-10-02  0:00                       ` Robert I. Eachus
1998-09-27  0:00           ` Boolean Representation dewarr
1998-09-24  0:00 ` dewarr
1998-09-24  0:00   ` Samuel T. Harris
1998-09-25  0:00     ` dewarr
1998-09-27  0:00       ` Samuel T. Harris [this message]
1998-09-28  0:00         ` dewar
1998-09-24  0:00   ` matthew_snyder
1998-09-24  0:00     ` dennison
1998-09-24  0:00     ` Tom Moran
1998-09-25  0:00       ` dewarr
1998-09-25  0:00         ` Tom Moran
1998-09-25  0:00     ` dewarr
1998-09-25  0:00     ` Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
1998-09-24  0:00 matthew_snyder
1998-09-25  0:00 ` Tucker Taft
1998-09-25  0:00   ` dewarr
1998-09-25  0:00   ` dewarr
replies disabled

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