comp.lang.ada
 help / color / mirror / Atom feed
* What does this code mean?
@ 2015-01-08  3:53 John Smith
  2015-01-08  4:37 ` Shark8
  2015-01-08 18:42 ` AdaMagica
  0 siblings, 2 replies; 7+ messages in thread
From: John Smith @ 2015-01-08  3:53 UTC (permalink / raw)


Hello,

I'm working through the wikibook Ada Programming [ https://upload.wikimedia.org/wikipedia/commons/8/8d/Ada_Programming.pdf ].  I came across this example on page 59:

==========================================================
with Ada ;

procedure Convert_Checked is
  type Short is range -128 .. +127;
  type Byte is mod 256;

  package T_IO renames Ada ;
  package I_IO is new Ada (Short);
  package M_IO is new Ada (Byte);

  A : Short := -1; 
  B : Byte;
begin
  B := Byte (A); -- range check will lead to Constraint_Error

  T_IO.Put("A = ");
  I_IO.Put(Item  => A,
           Width => 5,
           Base  => 10);
  T_IO.Put(", B = ");
  M_IO.Put(Item  => B,
           Width => 5,
           Base  => 10);
end Convert_Checked;
==========================================================

And when I compile it, I get this:

==========================================================
% gnatmake -g convert_checked.adb
gcc -c -g convert_checked.adb
convert_checked.adb:13:23: "Ada" is not the name of a generic package
convert_checked.adb:14:23: "Ada" is not the name of a generic package
convert_checked.adb:21:07: "Put" not declared in "Ada"
convert_checked.adb:22:03: "I_IO" is undefined
convert_checked.adb:25:07: "Put" not declared in "Ada"
convert_checked.adb:26:03: "M_IO" is undefined
gnatmake: "convert_checked.adb" compilation error
==========================================================

My question is why is this code written this way?  Is it just plain wrong or am I missing some concept that the author(s) tried to get across that I'm missing?


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

end of thread, other threads:[~2015-01-10 21:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08  3:53 What does this code mean? John Smith
2015-01-08  4:37 ` Shark8
2015-01-08  9:13   ` Simon Wright
2015-01-08 16:44     ` Dirk Heinrichs
2015-01-08 18:42 ` AdaMagica
2015-01-08 18:45   ` AdaMagica
2015-01-10 21:37     ` John Smith

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