Talk:Short-circuit evaluation: Difference between revisions

→‎Compiler optimisations?: added a comment about there being at least two FORTRAN II compilers for the IBM 1620.
(→‎Compiler optimisations?: added a comment about there being at least two FORTRAN II compilers for the IBM 1620.)
 
(5 intermediate revisions by 2 users not shown)
Line 84:
::::Notice that "and then" and "or else" are part of the Ada and Pascal standards. (the extended Pascal flavor, or ISO 10206, of course not the nonstandard Borland dialects) It would arguably be nice if short-circuit was the default. Likewise, it would be nice if statements like "integer n = 0" in a function were executed at each function call. But Fortran is not C. :) [[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 19:17, 4 May 2015 (UTC)
:::::Humm. I look in the compiler "help" system, and see for example <code>COMPLEX :: cube_root = (-0.5, 0.867)</code> both declaring and initialising a variable. Whether this value would apply to only the first invocation or to every invocation presumably depends on further opportunities for declaring STATIC and AUTOMATIC and SAVE, but no matter. PL/I also has a declare and initialise protocol.
::::::No, it does not depend, it's only executed once. This is only a replacement for the DATA statement of Fortran 77. [[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 05:34, 10 May 2016 (UTC)
 
So, the options are that a language/compiler
:1) takes the expression at face value, computes both parts and then performs the '''or''' or '''and''', exactly as written.
Line 94:
 
I still think the lead sentence, speaking of avoiding lengthy calculation, should mention not just (''quick'' or ''slow'') but also (''safe'' and ''test'') as justification for knowing just what will happen. I don't regard avoiding an array indexing error as a side effect. If it is avoided, it doesn't happen. [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 11:28, 6 May 2015 (UTC)
:YouYour last sentence reminds me of a compiler trick with gfortran: I wrote a little program to see how a bad program could crash (changing the value of a constant, IIRW). Without optimisation, it crashed, with optimisations, it didn't. It's perfectly correct in regard of the Fortran standard: such a program has unspecified behaviour, thus crashing or not according to a compiler option is as "valid" as blowing up the computer altogether or anything else. But I still feel it's not fair, and I consider this a bug. At least, it's incredibly misleading. This behaviour disappeared with the -fnoipa-cp compiler option. [[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 22:32, 20 July 2015 (UTC)
 
::Ahem. I've done that too, and with intent. The IBM1620's Fortran II compiler allowed only simple expressions for array indexing, (''const''*''variable'' +- ''constant'') and I wanted (I + J) inside a READ statement's list and there was some reason why I couldn't use an implicit DO-loop as in (A(K),K = I + J,...) or similar. Anyway, as you will have guessed, I found I could write A(J + 12345) after calling subroutine ZAP(12345,I) and suddenly, the storage set aside to hold the constant would contain ... something else. This would not work for simple constants such as zero that on some systems might be developed by in-line code. Naturally, there must be no other usage of a constant 12345 that expects it to have its proper value. On the IBM1130 this would ''not'' work, because although the constant would be damaged, constant offsets in array indexing were merged with the base address of the array and so vanished at run time. And anyway, array indexing now allowed arbitrary expressions. [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 03:34, 7 June 2017 (UTC)
 
::: There were (at least) two Fortran II compilers for the IBM 1620. &nbsp; One was written by IBM, the other was a one-pass compiler and written by Dr. D. G. Robinson, D. A. Jardine (and others) of DuPont of Canada. &nbsp; Locally, we called it Fortran 2.5 and it had a lot of Fortran IV features. &nbsp; It allowed almost any expression for array indexing. &nbsp; &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 07:50, 3 January 2019 (UTC)