Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.forth Subject: Re: Epic Fail Date: Sun, 13 Apr 2014 20:33:16 -0400 Organization: Aioe.org NNTP Server Lines: 38 Message-ID: References: <2014Apr9.181655@mips.complang.tuwien.ac.at> <64idnem648RzN9jOnZ2dnUVZ8iWdnZ2d@supernews.com> <2014Apr11.192347@mips.complang.tuwien.ac.at> <2014Apr13.181030@mips.complang.tuwien.ac.at> <27ilk9dvau3o08tmi9ccedohs8j8oujac2@4ax.com> NNTP-Posting-Host: CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.forth:29621 On Sun, 13 Apr 2014 17:44:11 -0400, Bernd Paysan wrote: > There are some corner cases, which Stephen called "the volatile issue": That's a lovely, lovely, lovely example. So, you guys do learn stuff from C! > Is > > foo @ foo @ > > identical to > > foo @ dup > > ? Actually, it isn't. foo @ dup shall result in two times the same > result, no matter if there is a race condition with another process, > while foo @ foo @ *should* have different results in that case. Exactly. In C, you'd use the "volatile" keyword to prevent the compiler from generating code that would optimize away the second fetch of a C variable or multiple dereferences of a pointer etc., i.e., the conversion of the second "foo @" to "dup" in Forth is an optimization. This is only for things which are modified outside the scope of C, i.e., beyond C's control. The same thing applies here for Forth, e.g., if the address is to memory mapped device which updates the value at foo repeatedly, then the Forth context doesn't have any way to determine the "foo @" is not simply a "dup" and shouldn't be optimized. Someone must tell the Forth context that the second "foo @" shouldn't be optimized, when a Forth optimizer is involved. The other option is no optimization. That would seem more plausible since Forth likely doesn't have any syntax to clarify the issue. Rod Pemberton