comp.lang.ada
 help / color / mirror / Atom feed
* how to "put" a binary structure? (newbie question!)
@ 2006-02-01 17:04 Norbert Caspari
  2006-02-01 18:23 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Norbert Caspari @ 2006-02-01 17:04 UTC (permalink / raw)


Dear experts,

I like to print the content of a binary bit structure with the put 
statement but it doesn't work. I'm a newbie to Ada programming and 
therefore please excuse if my question might be silly or stupid. Maybe I 
misunderstood something.

Here is some test case I tried to compile:

--------------------snip--------------------------
with Ada.Text_Io;
with Ada.Integer_Text_Io;
with Interfaces;
use Interfaces;
use Ada;

procedure Bittest is
 
   type Bit_T is
         (Off,
          On);

   for Bit_T use (
      Off => 0,
      On  => 1);

   for Bit_T'Size use 1;

   type Byte is
      record
         Bit0 : Bit_T;
         Bit1 : Bit_T;
         Bit2 : Bit_T;
         Bit3 : Bit_T;
         Bit4 : Bit_T;
         Bit5 : Bit_T;
         Bit6 : Bit_T;
         Bit7 : Bit_T;
      end record;
 
   for Byte'Size use 8;

   pragma Pack(Byte);    -- the whole structure should fit in one byte

   package Byte_Io is new Text_Io.Integer_Io(Byte => Unsigned_8); 
--^^^^^^^^^
-- This does not work, why???

   Xxx.Bit0 := off;
   Xxx.Bit1 := on;
   Xxx.Bit2 := off;
   Xxx.Bit3 := off;
   Xxx.Bit4 := on;
   Xxx.Bit5 := on;
   Xxx.Bit6 := off;
   Xxx.Bit7 := off;

-- and of course this does not work too because the declaration
-- of the child package above failed.

   Byte_IO.Put(Xxx.Bit0,
      Width=>1,
      Base=>2);

-- Is it possible to print the whole content of a record structure with one
-- put statement?

end Bittest;
-------------------------snap----------------------

The compiler says

missing actual for instantiation of "Num"
instantiation abandoned

How can I correct the source code to print the values stored in the 
structure Xxx? Is it possible, to print the whole content of Xxx with just 
one put statement? Or alternatively how can I assign the content of Xxx to 
another variable of the type Unsigned_8 that I can use for output? Or is 
there maybe another way?

Questions over questions ;-)

Anyway, thanks a lot in advance for your help.

Best regards, Norbert




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

end of thread, other threads:[~2006-02-02 11:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-01 17:04 how to "put" a binary structure? (newbie question!) Norbert Caspari
2006-02-01 18:23 ` Dmitry A. Kazakov
2006-02-01 18:34 ` Georg Bauhaus
2006-02-01 18:59 ` Martin Krischik
2006-02-02 11:06   ` Stephen Leake
2006-02-02  2:10 ` Jeffrey R. Carter

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