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:07:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.tele.dk!small.news.tele.dk!207.115.63.138!newscon04.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr30.news.prodigy.com.POSTED!not-for-mail From: "Pat Rogers" Newsgroups: comp.lang.ada References: Subject: Re: pragma pack in external packages X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: NNTP-Posting-Host: 208.191.177.131 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr30.news.prodigy.com 1019761620 ST000 208.191.177.131 (Thu, 25 Apr 2002 15:07:00 EDT) NNTP-Posting-Date: Thu, 25 Apr 2002 15:07:00 EDT Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: FKPO@SJGTZYQBQXYQ[OD]_HBWB]^PCPDLXUNNHLHEQR@ETUCCNSKQFCY@TXDX_WHSVB]ZEJLSNY\^J[CUVSA_QLFC^RQHUPH[P[NRWCCMLSNPOD_ESALHUK@TDFUZHBLJ\XGKL^NXA\EVHSP[D_C^B_^JCX^W]CHBAX]POG@SSAZQ\LE[DCNMUPG_VSC@VJM Date: Thu, 25 Apr 2002 19:07:00 GMT Xref: archiver1.google.com comp.lang.ada:23118 Date: 2002-04-25T19:07:00+00:00 List-Id: "Robert Quinn" wrote in message news:db500a4f.0204250849.61c0791e@posting.google.com... > 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 In package Definitions, do something like this: type Bit is range 0 .. 1; for Bit'Size use 1; type Five_Bits is array( 1 .. 5 ) of Bit; for Five_Bits'Component_Size use 1; for Five_Bits'Size use 5; That is, use 'Component_Size instead of pragma Pack, and take it out of the package More_Definitions too. I strongly suggest you think about the alignment issues for the record type, by the way! There is an attribute definition clause for that, too. HTH, --- Patrick Rogers Consulting and Training in: http://www.classwide.com Real-Time/OO Languages progers@classwide.com Hard Deadline Schedulability Analysis (281)648-3165 Software Fault Tolerance