comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: Thought this was funny
Date: Tue, 21 Oct 2003 23:13:12 +0000 (UTC)
Date: 2003-10-21T23:13:12+00:00	[thread overview]
Message-ID: <bn4ei8$58b$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: 3F95AFE3.7030308@comcast.net

Robert I. Eachus <rieachus@comcast.net> wrote:
: Stephane Richard wrote:
: 
:> I'm canadian and that code made me chuckle too ;-). The programmer much have
:> read how to handle the enumeration type first, then read about the Boolean
:> type being an enumeration of True and False maybe? ;-).
: 
: No, he must have been taught that your program design should allow for 
: changes in requirements.  He was prepared for another value being added 
: to Boolean. ;-)

Or he is just a careful programmer, who knows GNAT, case statements,
and Unchecked_Conversion :-)

with Unchecked_Conversion;
with Ada.Text_IO; use Ada;

procedure test is

   type This_Or_That is (This, That);
   for This_Or_That use (That => 17, This => 4);
   for This_Or_That'Size use 8;

   type My_Truth is new Boolean;
   for My_Truth'Size use 8;



   function from_This_Or_That is
      new Unchecked_Conversion(This_Or_That, My_Truth);

begin

   if from_This_Or_That(This) then
      Text_IO.put_line("Y");
   else
      Text_IO.put_line("N");
   end if;


   case from_This_Or_That(This) is
      when True =>
         Text_IO.put_line("Y");

      when False =>
         Text_IO.put_line("N");
   end case;

end test;


$ ./test
Y

raised CONSTRAINT_ERROR : test.adb:27 invalid data


Georg



  parent reply	other threads:[~2003-10-21 23:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-21 19:49 Thought this was funny Xenos
2003-10-21 20:26 ` Ching Bon Lam
2003-10-21 20:44   ` Lutz Donnerhacke
2003-10-21 20:36 ` Ed Falis
2003-10-21 21:08 ` Stephane Richard
2003-10-21 22:16   ` Robert I. Eachus
2003-10-21 22:24     ` Ed Falis
2003-10-22  0:36       ` Robert I. Eachus
2003-10-22  1:37         ` Ed Falis
2003-10-22  3:56           ` Robert I. Eachus
2003-10-22 13:44             ` Ed Falis
2003-10-21 23:13     ` Georg Bauhaus [this message]
2003-10-22  0:23     ` Alexandre E. Kopilovitch
2003-10-21 22:23   ` Simon Wright
2003-10-22  2:57 ` Steve
2003-10-22  6:26 ` Anders Wirzenius
2003-10-22  6:36 ` Vinzent 'Gadget' Hoefler
2003-10-22 12:38   ` Christopher J. Henrich
2003-10-22 15:00 ` Martin Dowie
  -- strict thread matches above, loose matches on Subject: below --
2003-10-22  6:44 christoph.grein
2003-10-22  7:31 ` Dmitry A. Kazakov
2003-10-22  8:48   ` Vinzent 'Gadget' Hoefler
2003-10-23  2:17 ` Wes Groleau
replies disabled

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