comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Efficient Sequential Access to Arrays
Date: Fri, 27 Jul 2012 08:45:33 +0200
Date: 2012-07-27T08:45:33+02:00	[thread overview]
Message-ID: <1736neo4dgmv4.1bfvp59id2yum.dlg@40tude.net> (raw)
In-Reply-To: 86d31898ne39maimbl24knds7rf38qg7vc@invalid.netcom.com

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"
> <mailbox@dmitry-kazakov.de> 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



  parent reply	other threads:[~2012-08-01  2:50 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-15 18:40 Efficient Sequential Access to Arrays Keean Schupke
2012-07-15 19:48 ` Dmitry A. Kazakov
2012-07-15 20:03   ` Keean Schupke
2012-07-15 20:56     ` Keean Schupke
2012-07-16 11:34       ` Jacob Sparre Andersen
2012-07-15 21:05     ` tmoran
2012-07-15 21:08       ` Keean Schupke
2012-07-16  1:19         ` tmoran
2012-07-15 21:44     ` Georg Bauhaus
2012-07-16  7:47     ` Dmitry A. Kazakov
2012-07-16 10:16       ` Keean Schupke
2012-07-16 14:57         ` Dmitry A. Kazakov
2012-07-16 16:39           ` Keean Schupke
2012-07-16 17:02             ` Georg Bauhaus
2012-07-16 18:48             ` Dmitry A. Kazakov
2012-07-16 19:12               ` Keean Schupke
2012-07-17  6:31                 ` Dmitry A. Kazakov
2012-07-17  6:50                   ` Georg Bauhaus
2012-07-17  8:42                     ` Dmitry A. Kazakov
2012-07-17  7:24                   ` Keean Schupke
2012-07-16 19:43             ` John B. Matthews
2012-07-16 20:44               ` Keean Schupke
2012-07-16 22:23             ` tmoran
2012-07-17  6:40               ` Keean Schupke
2012-07-17  9:01                 ` Dmitry A. Kazakov
2012-07-18  8:10                   ` Keean Schupke
2012-07-18 18:11                     ` tmoran
2012-07-19 10:41                       ` Keean Schupke
2012-07-19 11:18                         ` Georg Bauhaus
2012-07-19 19:58                           ` Keean Schupke
2012-07-21  8:24                             ` Keean Schupke
2012-07-21 11:52                               ` Georg Bauhaus
2012-07-21 16:14                                 ` Keean Schupke
2012-07-21 17:09                                   ` Keean Schupke
     [not found]                                   ` <i78m081tccmp078spmsei1l5vnj3k0kbkj@invalid.netcom.com>
2012-07-22 15:50                                     ` Keean Schupke
2012-07-22  5:13                               ` Shark8
2012-07-15 21:35   ` J-P. Rosen
2012-07-15 19:52 ` Shark8
2012-07-15 20:16   ` Keean Schupke
2012-07-15 21:33     ` Georg Bauhaus
2012-07-17 18:16 ` Florian Weimer
2012-07-22 10:01 ` robin.vowels
2012-07-30  6:31   ` Jacob Sparre Andersen
2012-07-30  7:16     ` Keean Schupke
2012-07-30  9:20     ` Georg Bauhaus
2012-07-30 14:04       ` Keean Schupke
2012-07-22 10:09 ` robin.vowels
2012-07-22 16:02   ` Keean Schupke
2012-07-22 16:21 ` Florian Weimer
2012-07-22 16:46   ` Keean Schupke
2012-07-22 18:41     ` Florian Weimer
2012-07-24  8:21       ` Keean Schupke
2012-07-22 17:34   ` Niklas Holsti
2012-07-22 18:21     ` Keean Schupke
2012-07-30 14:18       ` Jacob Sparre Andersen
2012-07-24 16:00     ` robin.vowels
2012-07-25  7:09       ` Niklas Holsti
2012-07-25  9:03         ` Keean Schupke
2012-07-26  0:15           ` Randy Brukardt
2012-07-26  8:38             ` Keean Schupke
2012-07-26 10:10               ` Brian Drummond
2012-07-26 12:32                 ` Keean Schupke
2012-07-26 13:46                   ` Dmitry A. Kazakov
2012-07-26 17:40                     ` Shark8
2012-07-26 18:56                       ` Dmitry A. Kazakov
2012-07-27  5:25                         ` Shark8
2012-07-27  6:28                           ` Dmitry A. Kazakov
2012-07-27  7:01                             ` Vasiliy Molostov
2012-07-27  8:48                               ` Dmitry A. Kazakov
2012-07-27 12:01                                 ` Georg Bauhaus
2012-07-27 16:49                                 ` Vasiliy Molostov
2012-07-27 19:38                                   ` Dmitry A. Kazakov
2012-07-28  5:32                             ` Shark8
2012-07-28  7:37                               ` Dmitry A. Kazakov
2012-07-28 18:32                                 ` Shark8
     [not found]                     ` <6ov218tnkbqu3vpkuo4t77rd7de0a3aesf@invalid.netcom.com>
2012-07-26 18:49                       ` Dmitry A. Kazakov
     [not found]                         ` <86d31898ne39maimbl24knds7rf38qg7vc@invalid.netcom.com>
2012-07-27  6:45                           ` Dmitry A. Kazakov [this message]
2012-07-27  8:21                   ` Keean Schupke
2012-07-27  8:50                     ` Dmitry A. Kazakov
2012-07-27  9:17                       ` Keean Schupke
2013-02-25 21:18                     ` Eryndlia Mavourneen
2012-07-26 13:08               ` Georg Bauhaus
2012-07-26 19:37                 ` stefan-lucks
2012-07-26 19:21               ` stefan-lucks
2012-07-31  3:12               ` Randy Brukardt
2012-07-26  7:11           ` Markus Schöpflin
2012-07-26 14:47         ` Robin Vowels
2012-07-26 15:18           ` Martin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox