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,6da15369b6c53c77,start X-Google-Attributes: gid103376,public From: Ted Dennison Subject: LLQ: -1 a valid boolean? Date: 2000/05/19 Message-ID: <39253CD0.C8DC893D@telepath.com>#1/1 X-Deja-AN: 625391537 Content-Transfer-Encoding: 7bit X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii X-Complaints-To: Abuse Role , We Care X-Trace: monger.newsread.com 958741405 216.14.8.34 (Fri, 19 May 2000 09:03:25 EDT) Organization: Telepath Systems (telepath.com) MIME-Version: 1.0 NNTP-Posting-Date: Fri, 19 May 2000 09:03:25 EDT Newsgroups: comp.lang.ada Date: 2000-05-19T00:00:00+00:00 List-Id: 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