comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: ANN: AdaTutor on the Web - done
Date: Sat, 29 Sep 2012 03:22:41 -0700 (PDT)
Date: 2012-09-29T03:22:41-07:00	[thread overview]
Message-ID: <7611a745-1290-4957-91b6-289ba97abf13@googlegroups.com> (raw)
In-Reply-To: <k46267$cng$1@speranza.aioe.org>

This text in the tutorial about UC is nonsense:

<quote>
One use of Ada.Unchecked_Conversion might be to allow us to and two Integers.  (Ada 95 allows us to and two objects of a modular type, but not two Integers.) Some Ada compilers come with a package that enables us to and two Integers, but many compilers have no such package.  Suppose that types Integer and Boolean occupy the same amount of storage.  If our program says with Ada.Unchecked_Conversion; we could write

function Int_To_Bool is new Ada.Unchecked_Conversion(Integer, Boolean);
function Bool_To_Int is new Ada.Unchecked_Conversion(Boolean, Integer);
function "and"(Left, Right : in Integer) return Integer is
begin
   return Bool_To_Int(Int_To_Bool(Left) and Int_To_Bool(Right));
end "and";
</quote>

Integer and Boolean have never the same size. Boolean'Size = 1. "and" will pick either the MSB or the LSB of Left and Right, depending on compiler resp. hardware.

(Ada83 was a bit unclear about the meaning of 'Size, there are differences in the behaviour of compilers. Ada95 fixed that - in a way that some find awkward.)

UC between Integer and Natural might work or include a multiplication/division by 2 because Natural'Size=Integer'Size-1. I have been bitten by UC between objects of types with different sizes when porting some legacy Ada83 code to a different hardware and compiler. Be careful: Stand-along objects of subtype Natural and of Integer have of course the same size - what matters for UC is the subtype's size, which is given by 'Size - this is why GNAT has an attribute 'Object_Size.



  parent reply	other threads:[~2012-09-29 10:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-29  5:50 ANN: AdaTutor on the Web - done Zhu Qun-Ying
2012-09-29  9:03 ` Nasser M. Abbasi
2012-09-29 20:49   ` Zhu Qun-Ying
2012-09-29 23:41     ` Patrick
2012-10-07  8:24       ` Michael Erdmann
2012-10-07  8:38         ` Simon Wright
2012-10-07 13:24           ` Nasser M. Abbasi
2012-10-07 14:13             ` Michael Erdmann
2012-10-07 16:45               ` Patrick
2012-10-08  7:04                 ` Egil Høvik
2012-10-07 18:20             ` Shark8
2012-10-07 19:59               ` Michael Erdmann
2012-10-11  3:37             ` Yannick Duchêne (Hibou57)
2012-10-07 14:16           ` Michael Erdmann
2012-10-11  3:30           ` Yannick Duchêne (Hibou57)
2012-10-07 12:40         ` Patrick
2012-10-07 14:21           ` Michael Erdmann
2012-10-07 15:25             ` Ludovic Brenta
2012-10-07 15:28               ` Michael Erdmann
2012-09-29 10:22 ` AdaMagica [this message]
2012-09-30  6:09 ` Micronian Coder
2012-10-01  4:39 ` Shark8
replies disabled

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