comp.lang.ada
 help / color / mirror / Atom feed
* LLQ: -1 a valid boolean?
@ 2000-05-19  0:00 Ted Dennison
  2000-05-19  0:00 ` Jeff Carter
  2000-05-21  0:00 ` Robert Dewar
  0 siblings, 2 replies; 16+ messages in thread
From: Ted Dennison @ 2000-05-19  0:00 UTC (permalink / raw)


At work our Ada program has to interface to two other languages; C and
Fortran. We get addresses from them, which are converted into pointers
to known data types, for instance Boolean.

The C code is using 1 for True, so we had no problem there. But the
Fortran code uses -1 for boolean. Now since Boolean'Size = 1, I figured
that would be fine too. It shouldn't care what the other bits are. And
it is perfectly fine, if you just use the result from the address.  But
if I try to assign that value out into another boolean variable, I get a
Constratint_Error! eg:


     package Boolean_Ptr_Conversions is new
     System.Address_To_Access_Conversions (Boolean);
     Fortran_True : Integer := -1;
     Ada_Boolean : Boolean;
     ...
     Ada.Text_IO.Put_Line ("Value is " &
     Boolean'image(Boolean_Ptr_Conversions.To_Pointer(Fortran_Integer'Address).all));

     -- Above runs fine, and prints out "Value is TRUE"

     Ada_Boolean :=
     Boolean_Ptr_Conversions.To_Pointer(Fortran_Integer'Address).all;

     -- Above raises Constraint_Error w/ certian compiler, not w/
     Gnat.


What I'm wondering is if this is legal behavior for the compiler, or if
I should submit a bug report?

You'd think that a value that is legal in situ ought to be legal to
assign as well. Then again, if Ada_Boolean'Size = 8 or 32 or something,
then I can see where one might argue that a value of -1 (all bits set)
is out of range of the possible Boolean values, and thus should raise
Constraint_Error.

So what's right?

--
T.E.D.

Home - mailto:dennison@telepath.com  Work - mailto:dennison@ssd.fsi.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html  ICQ  - 10545591






^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2000-05-24  0:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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     ` Robert Dewar
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
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           ` Ted Dennison
2000-05-24  0:00             ` Robert Dewar
2000-05-24  0:00           ` Robert Dewar

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