lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 03/12/12 22:50, Martin Krpan wrote:
[...]
> Obviously I am missing some knowledge therefore can somebody please
> educate me as I do not thing that FORTRAN can calculate faster than C
> statement like

FORTRAN (classic Fortran, that is) doesn't have a lot of features which
C does: such as recursion, pointers, dynamic memory allocation, operator
precedence... The end result is that a simple minded Fortran compiler
has a much easier job optimising the machine code than an equally simple
C compiler would. For example: with no recursion, the compiler's allowed
to treat all variables as global!

These days, of course, compilers are good enough that there's not much
in it.

Fun fact: all parameters in Fortran are passed by reference. So if you
modify them in the function, you modify the value that's passed in. What
happens if you do foo(x+1)? Answer: the compiler creates a temporary
value, assigns x+1 to it, and passes a reference to that value.

But if you do foo(1), the compiler notices that the 1 is a constant and
instead passes a reference to an entry in the constant pool. So when
foo() changes its parameter, you end up redefining the value of 1 in the
constant pool, with, usually, hilarious results...

(I'll repeat that all the horror stories about Fortran usually refer to
really old versions of the language, typically Fortran 70 or 77. Modern
Fortran is a totally different beast. Guy I knew at university was
nearly driven to a nervous breakdown by Fortran 70.)

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Of course, on a sufficiently small planet, 40 km/hr is, in fact,
│ sufficient to punt the elastic spherical cow into low orbit." ---
│ Brooks Moses on r.a.sf.c

Attachment: signature.asc
Description: OpenPGP digital signature