home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / ada / 3789 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.8 KB  |  91 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!usafa.af.mil!kirk!cwarack
  3. From: cwarack@kirkusafa.af.mil (Chris Warack <sys mgr>)
  4. Subject: Re: Novice Question on Record Representation
  5. Message-ID: <1992Dec18.002221.17228@usafa.af.mil>
  6. Sender: cwarack@kirk (Chris Warack <sys mgr>)
  7. Nntp-Posting-Host: kirk.usafa.af.mil
  8. Organization: USAF Academy, CO
  9. References:  <1992Dec16.225712.23791@saifr00.cfsat.honeywell.com>
  10. Date: Fri, 18 Dec 1992 00:22:21 GMT
  11. Lines: 78
  12.  
  13. Why do you say, "of course" there is an error in this?  You should be able
  14. to layout a private type just as easily as any other -- of course, you need
  15. knowledge of that private type which you otherwise might not need; but, you're
  16. using a rep clause so you must need it.
  17.  
  18. However, you may be getting an error if your machine's storage unit is a byte
  19. (like most machines).  In this case, you are laying out field A to take bytes
  20. 0 and 1; field B takes bytes 2 and 3; field C starts with byte 1 again, thus
  21. takes bytes 1,2,3, and 4.  Bytes 1,2,3 are already allocated, however. 
  22. That is an error.  If your storage unit is a long word (32 bits), this should
  23. work...
  24.  
  25. -- Chris
  26.  
  27. In article <1992Dec16.225712.23791@saifr00.cfsat.honeywell.com>, lam@saifr00.cfsat.honeywell.com (Josh Lam) writes:
  28. |> There is a type in another package I need to use in a record in my package.
  29. |> Unfortunately, that type is private and I need to use record representation
  30. |> for my record.
  31. |> 
  32. |> package Some_Package is
  33. |> 
  34. |>  type Some_Int is new integer;
  35. |>  for Some_Int'size use 16;
  36. |> 
  37. |>  type Some_Type is private
  38. |> 
  39. |>  -- etc etc
  40. |> 
  41. |>  private
  42. |> 
  43. |>   type Some_Type is new integer;
  44. |>   for Some_Type'size use 32;
  45. |> 
  46. |> end Some_Package;
  47. |> 
  48. |> 
  49. |> with Some_Package;
  50. |> package My_Package is
  51. |> 
  52. |>  type My_Rec (Choice: Boolean := True) is record
  53. |>    case Choice is
  54. |>      when True =>
  55. |>        A : Some_Package.Some_Int;
  56. |>        B : Some_Package.Some_Int;
  57. |>        C : Some_Package.Some_Type;
  58. |>      when False =>
  59. |>        D : Some_Package.Some_Int;
  60. |>    end case;
  61. |>  end record;
  62. |>    
  63. |>  for My_Rec use record
  64. |>     A      at 0 range 0..15;
  65. |>     B      at 0 range 16..31;
  66. |>     C      at 1 range 0..31;     -- of course there is an error here!
  67. |>     Choice at 2 range 0..31;
  68. |>     D      at 0 range 0..15;
  69. |>  end record;
  70. |> 
  71. |> -- etc etc
  72. |> 
  73. |> end My_Package;
  74. |> 
  75. |> 
  76. |> I know that I cannot do the above cos C is of Some_Package.Some_Type which
  77. |> is a private type.
  78. |> 
  79. |> So, other than yelling at the person and getting him to change his type
  80. |> to public, what are my alternatives given that I need to use record
  81. |> representation. Please also let me know some pros and cons (if any) to any
  82. |> alternative.
  83. |> 
  84. |> Thanks in advance!
  85. |> 
  86. |> -- 
  87. |> Josh Lam
  88. |> Honeywell Inc
  89. |> lam@saifr00.cfsat.honeywell.com
  90. |> 
  91.