From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab132517972acd5f,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Norbert Caspari Newsgroups: comp.lang.ada Subject: accessing record element (question to the pros) Date: Fri, 24 Feb 2006 16:03:47 +0100 Organization: T-Online Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1140793427 02 30135 bUd1v9IJDpWqwzY 060224 15:03:47 X-Complaints-To: usenet-abuse@t-online.de X-ID: b-qQB4ZVoesUofrBzZq84L2pC4xq4cOHo20chMRznWKbgCwDFlL6c1 User-Agent: KNode/0.4 Xref: g2news1.google.com comp.lang.ada:3135 Date: 2006-02-24T16:03:47+01:00 List-Id: 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