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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Representation clauses and side-efects on STM32F411 ravenscar runtime Date: Sun, 02 Aug 2015 10:40:33 +0100 Organization: A noiseless patient Spider Message-ID: References: <55bddbe2$0$3384$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="fbe1d5b0173017f7cc2ccfa8ad3bc8c1"; logging-data="10500"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18E9SAe9KPoGZ35sdHt1V1gasehRgDGF1g=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:ifpeVGNF5N8qSS85UDg+TJmSuKU= sha1:lJ8YNfgteEHKsobVW61Oa2vMJaU= Xref: news.eternal-september.org comp.lang.ada:27322 Date: 2015-08-02T10:40:33+01:00 List-Id: Frédéric Praca writes: > I was expecting the compiler (GNAT GPL 2014 (20140331) from Adacore > under Linux x64) to handle all and, or and xor operations by itself > for such kind of representation. Was I wrong ? I think you should declare Baud_Rate_Register as Volatile in any case. But there was a discussion here about this recently; Volatile doesn't guarantee any sort of full word access (or half word; how would the compiler know?). AdaCore recently included aspect Volatile_Full_Access[1] which is supposed to do what you want. GNAT GPL 2015 recognises this aspect; FSF GCC 5.1.0 doesn't (I haven't looked into 5.2.0 yet, but AdaCore typically only fix serious bugs in subreleases). Failing that, the recommended technique to change one component is to use a temporary: declare BRR : Baud_Rate_Register := USART2.BRR; begin BRR.DIV_Mantissa := 16#445#; USART2.BRR := BRR; end; but of course if you're changing all the components your whole record assignment will do the trick. In any case, a whole record assignment is better practice, because it means the compiler won't let you forget to assign a component. [1] http://www.adacore.com/developers/development-log/NF-74-M715-002-gnat/