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-Thread: 103376,f7c38a023cf370dc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Should representation clauses be complete for each bit? Date: Thu, 21 Jul 2011 10:58:03 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <73c10395-ec4f-4a02-b0fc-e35bc14424fa@e18g2000vbx.googlegroups.com> <4e26f324$0$6549$9b4e6d93@newsspool4.arcor-online.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1311260284 22146 192.74.137.71 (21 Jul 2011 14:58:04 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 21 Jul 2011 14:58:04 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:cG3oZlZLxEGnNvrqVp7Z51cZ44Y= Xref: g2news1.google.com comp.lang.ada:20269 Date: 2011-07-21T10:58:03-04:00 List-Id: Simon Wright writes: > Presumably if something took only three bits you'd have to say that much > at least. Part of my complaint is that you have to say it twice: type Bits2 is mod 2**2; pragma Assert (Bits2'Size = 2); OK, now we have a 2-bit type. But we have to specify 2 bits again in the rep clause: Gap1 at 0 range 1..2; > And would it be 'Size or 'Object_Size? (remembering that Natural'Size > {used to be,is} Integer'Size - 1). "is" 'Size is what you want, I think, although you might want a feature that says "warn me if I do something weird" (like making an array of Natural whose 'Component_Size is 31. If you have a record with a 32-bit Natural component, and you read it in from some outside source, you have to worry about that extra bit. You really need to have a 31-bit Natural, with a must-be-zero gap (which I claim should normally be explicit). Or else you want a 32-bit Integer, so you can write validation code ("if X.Y < 0 then panic; end if;"). > Wouldn't pragma Pack do this? No, Pack doesn't guarantee any particular representation. For example, it allows the compiler to reorder the components, which is a good idea for efficiency. Pack is all about efficiency, not about interfacing to some outside hardware or network protocol. > It may be that *if you need to specify a representation* this is a > common use case Yes, that's what I meant. >... (I don't remember it being so), but needing to specify a > representation is pretty rare anyway. And so it should be, after all it > should only happen at the edges, well hidden from the bulk of the > application. I agree. - Bob