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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f752883594af27e3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-04-25 12:04:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: pragma pack in external packages Date: 25 Apr 2002 15:03:38 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1019761790 27520 128.183.220.71 (25 Apr 2002 19:09:50 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 25 Apr 2002 19:09:50 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:23116 Date: 2002-04-25T19:09:50+00:00 List-Id: This compiles with GNAT 3.15a: package definitions is type ONE_BIT_TYPE is range 0..1; for ONE_BIT_TYPE'SIZE use 1; type MY_5_BIT_ARRAY_TYPE is array (1..5) of ONE_BIT_TYPE; pragma pack (MY_5_BIT_ARRAY_TYPE); end definitions; with Definitions; package More_Definitions is type my_record is record IMPORTANT_5_BIT_ARRAY : Definitions.MY_5_BIT_ARRAY_TYPE; end record; pragma pack(my_record); for my_record use record IMPORTANT_5_BIT_ARRAY at 0 range 0 .. 4; end record; end More_Definitions; robert_s_quinn@yahoo.com (Robert Quinn) writes: > I'm trying to figure out something about raw storage. I just > installed gnat and I'm trying to teach myself to represent bits of > data with Ada, but I hit a snag. Basically I can't seem to "pragma > pack" the data type if I am using the data type in a package OTHER > than the declaration package. e.g.: > > Suppose I have an array of bits: > > package definitions is > > ONE_BIT_TYPE is range 0..1; > for ONE_BIT_TYPE'SIZE use 1 > > 5_BIT_ARRAY_TYPE is array (1..5) of ONE_BIT; > pragma pack (5_BIT_ARRAY_TYPE); > > end definitions; > > It seems like my 5 bit array should now refer to 5 consecutive bits. > But now if I try to use this array in a record in an external package, > I get an error: > > package more_definitions is > > type my_record is record > IMPORTANT_5_BIT_ARRAY : definitions.5_BIT_ARRAY_TYPE; > end record > > pragma pack(my_record); > > for my_record use record > IMPORTANT_5_BIT_ARRAY at 0 range 0 .. 4; > end record; > > end more_definitions; > > after compile I get: > ERROR: size for IMPORTANT_5_BIT_ARRAY too small, minimum allowed is 40 > > Note that I don't get this error if I move the record declaration > INTERNAL to the package where the array type is defined. Only when I > use the array type in an external package does the compiler decide I > need a whole BYTE for each BIT of data! > > Any ideas? > Thanks, > Robert Quinn > > Note that I don't do any low-level programming in my job (is this what > you low level programmers do a lot of?), this is just a hobby. -- -- Stephe