From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-91-241.ec2.internal X-Spam-Level: * X-Spam-Status: No, score=1.0 required=3.0 tests=XPRIO autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Valid attribute and input operations Date: Wed, 27 Sep 2023 22:27:41 -0500 Organization: A noiseless patient Spider Message-ID: References: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com> Injection-Date: Thu, 28 Sep 2023 03:27:17 -0000 (UTC) Injection-Info: dont-email.me; posting-host="4260f7b3e8705760fb05d2d372cfaa1b"; logging-data="3706299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CBjyojJ/kizPBThXnjeS4NMFyR+Z9i3Q=" Cancel-Lock: sha1:orBFv7V6t11Hh3T0A90Aq03ATLQ= X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 Xref: news.eternal-september.org comp.lang.ada:65738 List-Id: No, the specified representation is always used when storing to memory (with the single exception of loop parameters, which cannot have address clauses or other representation specifications). I think even enum parameters are written in the representation. However, any time an enumeration value is read into a register it is converted to a position number. Usually, such values are used in indexing, comparing, or an attribute like 'Pos or 'Succ, all of which are defined to work on position numbers. But if you simply assign the value out again, it will get converted both ways. We do have an optimization to remove pairs of TOREP/DEREP, but not the reverse since Program_Error is a possibility from DEREP. (Well, unless unsafe optimizations are on, but I don't recommend using those for the obvious reasons.) Randy. "Niklas Holsti" wrote in message news:knff56Fdjg6U1@mid.individual.net... > On 2023-09-26 9:13, Randy Brukardt wrote: > >> ... for Janus/Ada, enumeration types with specified representations >> operate internally on the position numbers > > > Hm, that's interesting. Is that also the representation for record > components of such an enumerated type? > > For example, if I have: > > type Command is (Off, On) with Size => 4; > for Command use (Off => 2, On => 5); > type Two_Commands is record > C1, C2: Command; > end record > with Pack, Size => 8; > > TwoC : Two_Commands := (C1 => On, C2 => Off); > > will the record components (in memory) have the values C1 = 1 and C2 = 0 > (position numbers) or C1 = 5, C2 = 2 (specified representation)? > > If they are represented by position numbers in the record, many if not > most of my embedded Ada programs would fail if compiled with Janus/Ada, > because the record values stored in I/O control registers or accessed via > DMA would be wrong. > > Damn, I thought those programs were not so compiler-dependent :-( >