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: a07f3367d7,56525db28240414a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.88.168 with SMTP id bh8mr2881118pab.10.1343789445160; Tue, 31 Jul 2012 19:50:45 -0700 (PDT) Path: p10ni7591933pbh.1!nntp.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nrc-news.nrc.ca!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Efficient Sequential Access to Arrays Date: Fri, 27 Jul 2012 08:45:33 +0200 Organization: cbb software GmbH Message-ID: <1736neo4dgmv4.1bfvp59id2yum.dlg@40tude.net> References: <4ce44d2d-d789-42a0-a6ed-035f7f8d58be@googlegroups.com> <1d20andzhb0rk.ytxhpkza8tky$.dlg@40tude.net> <6ov218tnkbqu3vpkuo4t77rd7de0a3aesf@invalid.netcom.com> <86d31898ne39maimbl24knds7rf38qg7vc@invalid.netcom.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: 9A8bJrx4NhDLcSmbrb6AdA.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 X-Received-Bytes: 4327 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-07-27T08:45:33+02:00 List-Id: On Thu, 26 Jul 2012 17:36:11 -0400, Dennis Lee Bieber wrote: > On Thu, 26 Jul 2012 20:49:34 +0200, "Dmitry A. Kazakov" > declaimed the following in comp.lang.ada: > >> I know this case well because getting data out/into hardware is my daily >> job. I do not consider it legitimate for 'Valid. To put it clearer, I don't >> see re-interpretation of some bit pattern a good design. Which is what >> actually happens before 'Valid. It is always worth 10ns or so CPU time of >> doing proper conversion or value construction per arithmetic operations >> instead. It is not only cleaner, it is also safer, because 'Valid is a very >> illusory protection against mangled input. > > Given that the some input sources were from a non-Ada system (it was > part of a satellite ground control test suite) which took operator text > strings for command directives to the simulations. Those directives were > converted to a set of integer values (opcode, argument1...n) via a > database, and then passed though a packetized I/O system to the end > program(s) (which weren't stand-alone, but dynamically loaded libraries, > where the "opcode" defined which library function was to be called to > handle the arguments)... > > The choice then comes down to: > > if argument'Valid then > -- where "argument" is a defined (sub)type (often > -- an enumeration) > process directive > else > log an error > end if > > or > case argument is > -- where "argument" is an generic integer > when some-hand-maintained-value => enumvalue := x > when other-hand-maintained-value => enumvalue := y > when others => log an error > end case You have here arguments of two different types. So the example does not tell all truth. But anyway, I always use the second one properly encapsulated with a comment put near the case statement referring the document and the page where the encoding is defined. The mapping "some-hand-maintained-value" to "some-enumeration-value" is mandated by the protocol. It is outside Ada. You cannot leave that to bit patterns. In some cases you could use: Enum_Value := T'Val (Argument); commenting that the encoding is zero-based. > Side note: the directive database and the handler signatures (Ada > spec and body -- including the enumerated type values) were both > generated from an XML file describing the interface to the simulation > model (the library) -- but on the test systems one had to ensure that > the database was updated whenever the libraries were... Sometimes that > didn't happen correctly, allowing for values to become invalid. My first move in our projects is to root out the XML plague. Pretty much measurement hardware uses XML in these days for what they call "configuration", and I call malfunction. Once eliminated the rest works more or less smoothly. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de