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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ffdd4d59cbfb4caf X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Ada 95 Numerics questions for the experts Date: 1997/09/05 Message-ID: #1/1 X-Deja-AN: 270115621 References: Organization: New York University Newsgroups: comp.lang.ada Date: 1997-09-05T00:00:00+00:00 List-Id: Matthew says (responding to me) <<>Note that GNAT whereever possible follows the advice in the RM even if >it causes portability troubles. A common example is the following > > type arr8 is array (1..8) of boolean; > for arr8'size use 8; > >The RM permits the size clause to cause implicit packing, but recommends >against it. VADS at least permitted this implicit packing (even though >there was an AI that recommended against it). > >Consequently in GNAT, we reject the above, and require an explicit pragma >Pack. The workdaround for existing code here is easy, and the code is >arguably clearer with the pragma there in any case. I'm confused: why wouldn't you recommend that T'Component_Size be used, instead of pragma Pack? for arr8'Component_Size use 1; instead of pragma Pack (arr8);>> shrug! for a compiler that implements annex C, these are guaranteed to have identical effect, and in fact one cannot imagine a compiler not supporting pragma Pack for this case. Note that specifying a component_size other than 1,2,4,8 etc. is NOT guaranteed to give a no gaps imlementation even if the implementatoin advice IS followed (see RM 13.3(73)). But back to your example, since both declarations have EXACTLY the same status: a) if the chapter 13 IA is not followed (annex C not supported), then neither declaration is guaranteed to give a no-gaps implementation. b) if the chapter 13 IA is followed (annex C supported), then both declarations are guaranteed to give a no-gaps implementation. So there is really no need to have a preference for one over the other, and I suspect that your preference is based on some misunderstanding of the RM requirements. If you go to non-standard sizes like 3,5,7, then in GNAT, both declarations are still equivalent, up to a component size of 32. But as we have heard, that is not necessarily the case with other Ada 95 compilers. To be specific, consider the example: type x is range 0 .. 7; type r is array (1 .. 10) of x; 1) pragma Pack (r); 2) for r'Component_Size use 3; If you use BOTH these declarations, then they must be either obeyed with close packing or rejected as illegal. If you use 1) without 2), then an implementation supporting annex C must give you a component size of 3 or 4 (assuming typical implementations). The Intermetrics compiler gives 4, GNAT will give 3. (the Intermetrics compiler should reject the combination of both 1) and 2) together, since it does not support this combination) If you use 2) without 1), then even an implementation supporting annex C is completely free to do whatever it wants -- that's probably an oversight, and I would guess that typical implementations will behave the same as if 1) is used without 2). Anyway in this case, GNAT will still pack tightly to 3 bits. I do not know what the Intermetrics compiler will do in this case, since, as I say, the RM places no bounds on what an implementation can do if given a component size without a pack pragma and it is not a factor or a multiple of the word size. Here is the para in question 73 An implementation should support specified Component_Sizes that are factors and multiples of the word size. For such Component_ Sizes, the array should contain no gaps between components. For other Component_Sizes (if supported), the array should contain no gaps between components when packing is also specified; the implementation should forbid this combination in cases where it cannot support a no-gaps representation. So all in all, pragma Pack is stronger than using Component_Size in a compiler implementing annex C, and in a compiler not implementing annex C, there are no requirements at all, except to reject 1) and 2) together if you don't do them right, so perhaps actually the most reliable thing is to always use BOTH declarations, that way they must be obeyed or rejected and if we are talking about 1,2,4 etc, we know exactly what obeyed means. So to be specific: type r is array (1 .. 8) of Boolean; pragma Pack (r); for r'component_size use 1; must either be obeyed with close packing, or rejected, even bvy a compiler that does not say anything about supporting annex C. I find this all quite odd, but that is what the RM, quite clearly, says!!!!