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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,54889de51045a215 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-12 07:57:23 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail Message-ID: <3F896BAB.6040804@comcast.net> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: += in ada References: <3F7316F7.219F@mail.ru> <49cbf610.0310070205.2937e71a@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc02 1065970642 24.34.139.183 (Sun, 12 Oct 2003 14:57:22 GMT) NNTP-Posting-Date: Sun, 12 Oct 2003 14:57:22 GMT Organization: Comcast Online Date: Sun, 12 Oct 2003 14:57:22 GMT Xref: archiver1.google.com comp.lang.ada:739 Date: 2003-10-12T14:57:22+00:00 List-Id: Preben Randhol wrote: > No, but for := it is. Let me jump in here. I'll also include comments by my alter ego Bob which should sound supiously like what Bob Duff would say. Bob: Not anymore. In Ada 95 if you have an assignment to Foo in a scope where Constraint_Error occurs, the value of Foo may become abnormal. See 11.6(6). Robert: That is misleading in this case. If the type of Foo is a scalar for which assignment is indivisible (see C.6), the only possible values of Foo visible in an exception handler are the value before the assignment, and the value after. If this is the only potential assignment to Foo in this scope, then the value is well defined. Bob: The only way to ENSURE that the assignment is indivisible is to apply pragma Atomic to the type or to Foo. Robert: Not quite. Foo could also be Volitile, or a component of a Volitile type. But that is irrelevant in this context. An assignment may be indivisible whether or not pragma Volitile or Atomic applies. Bob: But the user can't know that for sure. Imagine a (packed) record type with an Integer component that begins at an odd bit offset. The compiler may have to do a non-indivisible assignment in that case even if assignments to Integers are normally indivisible. Robert: Correct, and in that case, the user would deserve what he got. But note that the user could do the assignment (and Constrain_Error check) in a subprogram in this case. The value of Foo would be pased by value return if the parameter was in out. The constraint check inside the subprogram, and the handler for the exception, would see the value as indivisible. Bob: But only if the subprogram was not inlined! Robert: Right. Well not quite right. If there was a pramga Inline for the subprogram, what Bob says is true. But in this case automatic inlining by the compiler must preserve the required semantics. Bob: But the compiler is not REQUIRED to use an indivisible assignment unless pragma Volitile or Atomic, etc., applies... At this point we will leave the discussion which could continue long into the night. (And I am writing this at 11 o'clock in the morning!) Forcing any compiler to "do the right thing" is possible, but in 99% of the cases it will happen by default. The compiler is allowed to break the assignment of an unaligned component into several operations, and that CAN be visible in an exception handler. But in almost all cases this won't happen. If you are a belt and suspenders type, and you are writing code you want to be portable, you may want to use Atomic or Volitile. Notice that there can be a performance penalty for doing so. -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig