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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,43ad9ab56ebde91c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.190.2 with SMTP id gm2mr19506037pbc.4.1324989312609; Tue, 27 Dec 2011 04:35:12 -0800 (PST) Path: lh20ni69996pbb.0!nntp.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Does Ada support endiannes? Date: Tue, 27 Dec 2011 13:35:06 +0100 Organization: cbb software GmbH Message-ID: <1qvq7hppsg0u.1oomxndbukhtr.dlg@40tude.net> References: <23835087-313f-427c-b37e-4ff1bdef9d57@r6g2000yqr.googlegroups.com> <20e631fc-e7b4-41ca-be0f-aab8be3f9a25@f33g2000yqh.googlegroups.com> <53n2sd7edt5i.1boh4452h0aks.dlg@40tude.net> <1kc5n51.ffg0umddufyfN%csampson@inetworld.net> <1c2ax12bptm2g.gifwv5vndpxe$.dlg@40tude.net> <1kc8f2j.132xw621jmu761N%csampson@inetworld.net> <16jibtpb9f2o4.1pf3ro8hb8qq2.dlg@40tude.net> <1kcakce.17lpouc1o2nz0gN%csampson@inetworld.net> <1ol1w9audpvta.1drukev3uwfoe.dlg@40tude.net> <1kcu0zg.r0yxxk4341xyN%csampson@inetworld.net> <1tegoy0w6pnqm$.qr7gobrrq1t6$.dlg@40tude.net> <4ef9a028$0$6622$9b4e6d93@newsspool2.arcor-online.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: PPt+vSuBRqtkVsMLa1J3Dg.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2011-12-27T13:35:06+01:00 List-Id: On Tue, 27 Dec 2011 11:38:32 +0100, Georg Bauhaus wrote: > On 26.12.11 11:47, Dmitry A. Kazakov wrote: > >> Your code uses obscure assignments to some fields of some record type, > > Or, as one might say, the expression > > 256 * Incoming.Byte_2 + Byte_1 > > is an obscure arithmetical formula involving the magic number 256. Data (Index) * 2**8 + Data (Index + 1) > It takes careful study by someone with mathematical training and also > requires knowledge of language fine print and data representation or > else 256 is not meaningful, but obscure! You need mathematical training in order to understand how numbers are encoded. Representation clauses require much *additional* understanding on top of that. Difficulties people keep on having with understanding and proper usage of the clauses reflect this simple fact. > So, regarding obscurity, the formula would at first show little advantage. > Neither will it be more readable in this sense. It is. This is the way these things are defined in first place. E.g. http://en.wikipedia.org/wiki/Two_complement There is simply no other way. The only thing you can do with a number is to use numeric operations. Anything else is on top of that. Remember that binary representation of a number is an encoding, itself defined through mathematical operations. >> 4095 -> 2#1111_1111# 2#0111_1111# >> 4096 -> 2#1000_0000# 2#1000_0000# 2#0000_0001# >> ... >> >> [Chain codes are used when the upper bound of the transported number is >> unspecified and it is expected that lesser values are more frequent than >> bigger ones. UTF-8, is chain code.] >> >> Care to write a representation clause for the above? > > Arguably, a chain code might not what a regular programmer would see > as something to which a record representation clause will apply as a whole. Regular programmer does not bother about encoding anyway. But if someone have to, my advise is: don't waste your time on understanding representation clauses. They won't help you. Beyond trivial cases, if you are not a language lawyer, you will never understand why that mess works or does not work. > What will the concrete data type for the above chain code look like, An integer number > as a whole, if it is not a list or array of some sort and if, for example, > a chain code is being used precisely because there is a lot more to link > than can be represented in what physically corresponds to > range 0 .. 2**System.Word_Size? That was another point against representation clauses: they fall short when it comes to validity checks. The peers of the protocol like above would impose certain implementation-specific limits on the number range. Upon decoding (using arithmetic operations), the program would necessarily get Constraint_Error when the limit is exceeded, and reroute to Protocol_Error. It is a very simple and effective method handling protocols in general. > It seems there is value in distinguishing an encoding from a representation, > and establish their relationship. (Ah, you know my weakness of giving definitions. (:-)) OK, here it one: [Machine] representation is an encoding with the alphabet based on the values of a machine type. P.S. A not yet mentioned argument against representation clauses is their unfriendliness to correctness proof and testing (you would likely need a full coverage test). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de