I'm new to Ada programming and until now I wrote just some small pieces of
code to try out new things and to educate myself. In this example I try to
build a Union Record, where I can access a single Byte either as a small
positive Integer value or as single Bits. I don't understand, why there is
a compiler error in line 56 and why it is forbidden in this case to assign
just a simple positive Integer value. If I comment this line out, the rest
of the code will compile without errors. Please remember, this is just
some
experimental code with no special sense and no meaningful variable names.
Could somebody please help me to correct my code, showing me how to access
a numeric value to the variable Yyy.
Thank you very much for your help!
Best regards, Norbert
----------------------------------------------------------
GNAT 3.15p (20020523) Copyright 1992-2002 Free Software Foundation, Inc.
Compiling: j:/source/uniontest4.adb (source file time stamp: 2006-02-24
14:43:50)
1. with Ada.Text_Io;
2. use Ada.Text_Io;
3.
4. procedure Uniontest4 is
5.
6. type Bit_T is
7. (Off,
8. On);
9.
10. for Bit_T use (
11. Off => 0,
12. On => 1);
13.
14. type Bit8 is array (0 .. 7) of Bit_T;
15.
16. pragma Pack(Bit8);
17. for Bit8'Size use 8;
18.
19. type Uint8 is mod 2**8;
20.
21. for Uint8'Size use 8;
22.
23. type Form is
24. (Bytemode,
25. Bitmode);
26.
27. type Bfeld (Ftyp: Form) is
28. record
29. case Ftyp is
30. when Bitmode =>
31. Bit: Bit8;
32. when Bytemode =>
33. Byte : Uint8;
34. end case;
35. end record;
36.
37. pragma Pack(Bfeld);
38.
39. for Bfeld use record
40. at mod 1;
41. Bit at 0 range 0..7;
42. Byte at 0 range 0..7;
43. end record;
44.
45. type Bfeld_Bitmode is new Bfeld
46. (Bitmode);
47. type Bfeld_Bytemode is new Bfeld
48. (Bytemode);
49.
50. Xxx : Bfeld_Bitmode;
51. Yyy : Bfeld_Bytemode;
52.
53. begin
54.
55. Xxx.Bit(2) := On;
56. Yyy := 20;
|
>>> expected type "Bfeld_Bytemode" defined at line 47
>>> found type universal integer
57.
58. for K in 0 .. 7
59. loop
60. Put(Bit_T'Image(Xxx.Bit(K)));
61. end loop;
62. New_Line;
63.
64. end Uniontest4;
65.
65 lines: 2 errors


|