Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > accessing recor...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 11 Topic 4221 of 5881
Post > Topic >>

accessing record element (question to the pros)

by Norbert Caspari <nnc@[EMAIL PROTECTED] > Feb 24, 2006 at 04:03 PM

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
 




 11 Posts in Topic:
accessing record element (question to the pros)
Norbert Caspari <nnc@[  2006-02-24 16:03:47 
Re: accessing record element (question to the pros)
Peter Hermann <ica2ph@  2006-02-24 15:27:28 
Re: accessing record element (question to the pros)
"Alex R. Mosteo"  2006-02-24 18:08:35 
Re: accessing record element (question to the pros)
Norbert Caspari <nnc@[  2006-02-24 18:07:23 
Re: accessing record element (question to the pros)
"Jeffrey R. Carter&q  2006-02-24 18:02:09 
Re: accessing record element (question to the pros)
Simon Wright <simon@[E  2006-02-24 19:04:55 
Re: accessing record element (question to the pros)
"Randy Brukardt"  2006-02-24 15:46:05 
many thanks to all the people who give me useful hints!
Norbert Caspari <nnc@[  2006-02-26 12:49:37 
Re: many thanks to all the people who give me useful hints!
"Randy Brukardt"  2006-02-27 18:33:04 
Re: accessing record element (question to the pros)
Martin Krischik <krisc  2006-02-24 19:32:36 
Re: accessing record element (question to the pros)
"Matthew Heaney"  2006-02-28 12:02:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 8:41:56 CDT 2008.