comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@notmyhomepage.invalid>
Subject: Re: Problem with Position of the enumeration Type
Date: Sat, 26 Jan 2019 10:44:26 +0100
Date: 2019-01-26T10:44:26+01:00	[thread overview]
Message-ID: <q2ha5r$u6r$1@dont-email.me> (raw)
In-Reply-To: <gas5dpFns14U1@mid.individual.net>

On 23.01.19 22:42, Niklas Holsti wrote:
> 
> As others have also noted, enumeration representation clauses are used mostly when the enumeration value is an input (say, from some memory-mapped control register, or from a binary input file) or an output. Communication protocols and HW interfaces often define fields that encode some finite set of possible logical values/meanings, but where the encoding has gaps.
> 
> A final note: if you use an enumerated type for an input value, it is wise to check if the input is valid before using it. Use the 'Valid attribute for this. However, this attribute can also have a non-trivial cost. For example, the compiler may implement the function call E_Test'Valid(E) by code that compares the (representation of) E against each of the valid values 10, 21, 34, 100, 255 in turn (although a better compiler would use a binary search).

Has it been pointed out that one can use two enum types
together, one for I/O and the other for internal purposes
and then simply convert?

    type E_Test is (A, B, C);

    type E_for_IO is new E_Test;
    for E_for_IO use
       (A => 2#0000_1010#
        B => 2#0001_0101#
        C => 2#0010_0010#);

...

    some_E_Test := E_Test (some_E_for_IO);


-- 
"HOTDOGS ARE NOT BOOKMARKS"
Springfield Elementary teaching staff


      parent reply	other threads:[~2019-01-26  9:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 10:05 Problem with Position of the enumeration Type Luis Ladron de Guevara Moreno
2019-01-23 10:33 ` AdaMagica
2019-01-23 10:55   ` AdaMagica
2019-01-23 12:08   ` Luis Ladron de Guevara Moreno
2019-01-23 12:15     ` Karl Müller
2019-01-23 21:50     ` Niklas Holsti
2019-01-24  8:06     ` AdaMagica
2019-01-23 11:32 ` Mark Lorenzen
2019-01-23 12:30   ` Luis Ladron de Guevara Moreno
2019-01-23 20:22     ` Shark8
2019-01-24  8:13       ` AdaMagica
2019-01-23 17:06 ` Simon Wright
2019-01-23 22:54   ` Randy Brukardt
2019-01-23 23:47     ` Keith Thompson
2019-01-24  4:34       ` Keith Thompson
2019-01-24  9:11         ` Simon Wright
2019-01-24 21:41       ` Randy Brukardt
2019-01-23 21:42 ` Niklas Holsti
2019-01-23 22:35   ` Simon Wright
2019-01-23 23:20     ` Niklas Holsti
2019-01-24 16:43     ` Jeffrey R. Carter
2019-01-24 19:39       ` Niklas Holsti
2019-01-24 20:29         ` Jeffrey R. Carter
2019-01-24 21:43         ` Randy Brukardt
2019-01-26  9:44   ` G.B. [this message]
replies disabled

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