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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab132517972acd5f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.uni-stuttgart.de!not-for-mail From: Peter Hermann Newsgroups: comp.lang.ada Subject: Re: accessing record element (question to the pros) Date: Fri, 24 Feb 2006 15:27:28 +0000 (UTC) Organization: Comp.Center (RUS), U of Stuttgart, FRG Message-ID: References: X-Trace: infosun2.rus.uni-stuttgart.de 1140794848 12113 141.58.7.20 (24 Feb 2006 15:27:28 GMT) X-Complaints-To: news@news.uni-stuttgart.de NNTP-Posting-Date: Fri, 24 Feb 2006 15:27:28 +0000 (UTC) User-Agent: tin/1.7.8-20050315 ("Scalpay") (UNIX) (Linux/2.4.27 (i686)) Xref: g2news1.google.com comp.lang.ada:3136 Date: 2006-02-24T15:27:28+00:00 List-Id: Norbert Caspari wrote: > 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 how to assign ? > 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); may be cumbersome to replace 0 by off etc why not boolean? > 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); with these declarations you have lost the advantage of the discriminated record bfeld > 49. > 50. Xxx : Bfeld_Bitmode; > 51. Yyy : Bfeld_Bytemode; > 52. > 53. begin > 54. > 55. Xxx.Bit(2) := On; > 56. Yyy := 20; yyy.byte := 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 > -- --Peter.Hermann@ihr.uni-stuttgart.de (+49)0711-685-87244 --Nobelstr.19 Raum 0.030, D-70569 Stuttgart IHR Hoechstleistungsrechnen --http://www.ihr.uni-stuttgart.de/ Fax 0711-89238279