home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / ada / 3736 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.9 KB  |  59 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!cis.ohio-state.edu!sample.eng.ohio-state.edu!purdue!ames!data.nas.nasa.gov!eos!aio!dnsurber
  3. From: dnsurber@lescsse.jsc.nasa.gov (Douglas N. Surber)
  4. Subject: Re: Novice Question on Record Representation
  5. Message-ID: <dnsurber.724602575@node_26400>
  6. Sender: news@aio.jsc.nasa.gov (USENET News System)
  7. Organization: Lockheed Engineering and Sciences
  8. References: <1992Dec16.225712.23791@saifr00.cfsat.honeywell.com>
  9. Date: 17 Dec 92 14:29:35 GMT
  10. Lines: 47
  11.  
  12. In <1992Dec16.225712.23791@saifr00.cfsat.honeywell.com> lam@saifr00.cfsat.honeywell.com (Josh Lam) writes:
  13.  
  14. >There is a type in another package I need to use in a record in my package.
  15. >Unfortunately, that type is private and I need to use record representation
  16. >for my record.
  17.  
  18. > for My_Rec use record
  19. >    A      at 0 range 0..15;
  20. >    B      at 0 range 16..31;
  21. >    C      at 1 range 0..31;     -- of course there is an error here!
  22. >    Choice at 2 range 0..31;
  23. >    D      at 0 range 0..15;
  24. > end record;
  25.  
  26. Try the following small kludge:
  27.  
  28.     package P1 is
  29.     type T is private;
  30.     T_Size : constant := 32;
  31.     private
  32.     type T is new Integer;
  33.     subtype Assertion is boolean range true .. true;
  34.     a1 : constant Assertion := T_Size = T'Size;
  35.     end P1;
  36.  
  37.     with P1;
  38.     package P2 is
  39.     type T is 
  40.         record
  41.         F : P1.T;
  42.         end record;
  43.     for T use record
  44.         F at 0 range 0 .. P1.T_Size - 1;
  45.     end record;
  46.     end P2;
  47.  
  48. You can't use P1.T'Size directly since it isn't static outside of the
  49. private part (at least according to the Alsys compiler).  By using the
  50. Assertion, you assure that T_Size has the right value.  Yes, you may have
  51. to tweak its value when you port, but you can't get a clean compile with
  52. the wrong value so it is safe.
  53.  
  54.  
  55. --
  56. Douglas Surber             "Would you rather debug at
  57. Lockheed                    compile time or run time?"
  58. Houston, TX                      --Michael B. Feldman
  59.