comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: LLQ: -1 a valid boolean?
Date: 2000/05/23
Date: 2000-05-23T00:00:00+00:00	[thread overview]
Message-ID: <8gen6a$v72$1@nnrp1.deja.com> (raw)
In-Reply-To: 8ge39b$g45$1@nnrp1.deja.com

In article <8ge39b$g45$1@nnrp1.deja.com>,
  Ted Dennison <dennison@telepath.com> wrote:
> > If your compiler implements Interfaces.Fortran, then
everything
> > should be fine, since the type Logical should work properly.
>
> Except that sometimes the value comes from a Fortran program,
and
> sometimes it comes from a C program.

That;s fine Fortran.Logical will work in either case

> I just ended up doing the following, which looks damn silly
> (so I had to comment it copiously), but works:

>    if To_Bool_Ptr(Addr).all then
>       return True;
>    else
>       return False;
>    end if;

It's not only silly, it is incorrect. There is absolutely NO
reason to think this should work correctly, since you are
testing an out of range and hence abnormal value, and the
result of this test is undefined.

You should use unchecked conversion to convert it to an unsigned
integer of the approipriate size, and check that integer for
a non-zero value.

Writing erroneous code like this and being satisied that it
happens to work on the particular compiler you are using is
not a good approach to writing reliable code!


Sent via Deja.com http://www.deja.com/
Before you buy.




  parent reply	other threads:[~2000-05-23  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-19  0:00 LLQ: -1 a valid boolean? Ted Dennison
2000-05-19  0:00 ` Jeff Carter
2000-05-20  0:00   ` Ted Dennison
2000-05-21  0:00 ` Robert Dewar
2000-05-23  0:00   ` Ted Dennison
2000-05-23  0:00     ` David C. Hoos, Sr.
2000-05-24  0:00       ` Robert Dewar
2000-05-24  0:00         ` David C. Hoos, Sr.
2000-05-24  0:00           ` Robert Dewar
2000-05-24  0:00           ` Ted Dennison
2000-05-24  0:00             ` Robert Dewar
2000-05-23  0:00     ` Robert Dewar [this message]
2000-05-23  0:00       ` Ted Dennison
2000-05-23  0:00         ` Robert Dewar
2000-05-23  0:00           ` Ted Dennison
2000-05-24  0:00             ` Robert Dewar
replies disabled

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