From: Frank Buss <fb@frank-buss.de>
Subject: quiz for Sequential_IO Read
Date: Sun, 3 Sep 2017 13:01:25 +0200
Date: 2017-09-03T13:01:25+02:00 [thread overview]
Message-ID: <oogne5$94b$1@newsreader4.netcologne.de> (raw)
What does this program output?
with Ada.Sequential_IO;
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
type Byte is range 0..255;
package Byte_IO is new Ada.Sequential_IO(Byte);
A : Byte;
B : Byte;
C : Byte;
File : Byte_IO.File_Type;
begin
Byte_IO.Open(File, Byte_IO.In_File, "test.txt");
Byte_IO.Read(File, A);
Put_Line(Byte'Image(A));
Byte_IO.Read(File, B);
Put_Line(Byte'Image(B));
C := (A mod 2) + (B mod 2);
Put_Line(Byte'Image(C));
Byte_IO.Close(File);
end;
The content of test.txt is just the ASCII string "hello":
hexdump -C test.txt:
00000000 68 65 6c 6c 6f |hello|
00000005
Answer without compiling and running it! A hex calculator is allowed.
Extra brownie point if you can explain the result :-)
Don't know if it matters, compiled with "gnatgcc (Debian 6.3.0-18) 6.3.0
20170516", 64 bit version, and "-g -O2" command line options.
--
Frank Buss, http://www.frank-buss.de
electronics and more: http://www.youtube.com/user/frankbuss
next reply other threads:[~2017-09-03 11:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-03 11:01 Frank Buss [this message]
2017-09-03 11:40 ` quiz for Sequential_IO Read Jeffrey R. Carter
2017-09-03 12:47 ` Frank Buss
2017-09-03 13:44 ` Jeffrey R. Carter
2017-09-03 15:38 ` AdaMagica
2017-09-03 12:26 ` Dmitry A. Kazakov
2017-09-03 12:43 ` Frank Buss
2017-09-03 13:11 ` Dmitry A. Kazakov
2017-09-04 19:58 ` Frank Buss
2017-09-04 20:55 ` Dmitry A. Kazakov
2017-09-04 21:51 ` Frank Buss
2017-09-05 1:54 ` Dennis Lee Bieber
2017-09-03 17:28 ` J-P. Rosen
2017-09-03 20:10 ` Frank Buss
2017-09-04 5:12 ` J-P. Rosen
2017-09-04 7:37 ` Dmitry A. Kazakov
2017-09-03 20:17 ` Dennis Lee Bieber
2017-09-04 5:14 ` J-P. Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox