* 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
* Re: What does this code mean?
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 18:42 ` AdaMagica
1 sibling, 1 reply; 7+ messages in thread
From: Shark8 @ 2015-01-08 4:37 UTC (permalink / raw)
On 07-Jan-15 20:53, John Smith wrote:
>
> 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?
>
I think it's wrong -- the "package I_IO is new Ada (Short);" is syntax
for instantiating a generic package... noticing the space-comma, I think
there might have been a transcription error -- it is likely this is what
was meant:
With Ada.Text_IO;
procedure Convert_Checked is
type Short is range -128 .. +127;
type Byte is mod 256;
package T_IO renames Ada.Text_IO;
package I_IO is new Ada.Text_IO.Integer_IO (Short);
package M_IO is new Ada.Text_IO.Modular_IO (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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What does this code mean?
2015-01-08 3:53 What does this code mean? John Smith
2015-01-08 4:37 ` Shark8
@ 2015-01-08 18:42 ` AdaMagica
2015-01-08 18:45 ` AdaMagica
1 sibling, 1 reply; 7+ messages in thread
From: AdaMagica @ 2015-01-08 18:42 UTC (permalink / raw)
This seems to be a systematic error. In chapter 13.2.1, you can find the same omission. Somehow everything after the word "Ada" has beend dropped, here ".Unchecked_Deallocation".
^ 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