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

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!aplcen.apl.jhu.edu!ddsdx2.jhuapl.edu!dlc
  3. From: dlc@ddsdx2.jhuapl.edu (Dave Collard x7468)
  4. Subject: Re: Novice Question on Record Representation
  5. Message-ID: <1992Dec17.132850.2305@aplcen.apl.jhu.edu>
  6. Sender: news@aplcen.apl.jhu.edu (USENET News System)
  7. Organization: Johns Hopkins University
  8. References: <1992Dec16.225712.23791@saifr00.cfsat.honeywell.com>
  9. Distribution: usa
  10. Date: Thu, 17 Dec 92 13:28:50 GMT
  11. Lines: 80
  12.  
  13. >Josh Lam
  14. >Honeywell Inc
  15. >lam@saifr00.cfsat.honeywell.com
  16.  
  17. -- OOH, OOH, OOH!!! Something technical on comp.lang.ada!  Wow!
  18. -- Today should become a federal holiday! :-)
  19.  
  20. package Some_Package is
  21.  
  22.  type Some_Int is new short_integer;
  23.  for Some_Int'size use 16;
  24.  
  25.  type Some_Type is private;
  26.  
  27.  private
  28.  
  29.   type Some_Type is new integer;
  30.   for Some_Type'size use 32;
  31.  
  32. end Some_Package;
  33.  
  34.  
  35. with Some_Package;
  36. package My_Package is
  37.  
  38.  XX : constant Integer := Integer(Some_Package.Some_Type'Size);
  39.  
  40.  type My_Rec (Choice: Boolean := True) is record
  41.    case Choice is
  42.      when True =>
  43.        A : Some_Package.Some_Int;
  44.        B : Some_Package.Some_Int;
  45.        C : Some_Package.Some_Type;
  46.      when False =>
  47.        D : Some_Package.Some_Int;
  48.    end case;
  49.  end record;
  50.    
  51. -- for My_Rec use record
  52. --    A      at 0 range 0..15;
  53. --    B      at 0 range 16..31;
  54. --    C      at 1 range 0..31;     -- of course there is an error here!
  55. --    Choice at 2 range 0..31;
  56. --    D      at 0 range 0..15;
  57. -- end record;
  58.  
  59.  -- Is the storage unit on your machine really 32 bits?  the '0' in "A at 0" 
  60.  -- refers to which storage unit to start the component at.  But the answer
  61.  -- to your question is that you CAN use rep specs with private types.  The
  62.  -- attributes of private types are also available (such as 'SIZE).  The 
  63.  -- problem in your example is overlapping components of your record.  Try:
  64.  
  65.  for My_Rec use record
  66.     A      at 0 range 0..15;
  67.     B      at 2 range 0..15;
  68.     C      at 4 range 0..31;     -- of course there is an error here! NOT!
  69.     Choice at 8 range 0..31;
  70.     D      at 0 range 0..15;
  71.  end record;
  72.  
  73.  -- This works for me.  Yes I actually compiled it.
  74.  
  75. -- etc etc
  76.  
  77. end My_Package;
  78.  
  79. --I know that I cannot do the above cos C is of Some_Package.Some_Type which
  80. --is a private type.
  81. --
  82. --So, other than yelling at the person and getting him to change his type
  83. --to public, what are my alternatives given that I need to use record
  84. --representation. Please also let me know some pros and cons (if any) to any
  85. --alternative.
  86. --
  87. --Thanks in advance!
  88. --
  89.  
  90. --Thor
  91. --dlc@ddsdx2.jhuapl.edu
  92. --collard@capsrv.jhuapl.edu
  93.