[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suitability of Lua as a First Programming Language?
- From: Jay Carlson <nop@...>
- Date: Mon, 3 Dec 2012 18:52:06 -0500
On Dec 3, 2012, at 5:50 PM, Martin Krpan wrote:
> On Sat, Dec 01, 2012 at 02:12:06PM -0800, M. Edward (Ed) Borasky wrote:
>> C was designed for writing systems programs - operating systems and
>> compilers. It took about ten years for the compilers to get good
>> enough for it to be competitive with FORTRAN for number crunching.
>
> I have read many times that FORTRAN is better Than C for number
> crunching buy I do not know WHY?
Let's start with "because pointers suck". If you have
int n;
void foo(int *p, char *q) {
print(n);
*p = 7;
print(n);
*q = 'c';
print(n);
}
either p or q could point at n; the machine code must reload n each time.
http://en.wikipedia.org/wiki/Restrict
http://en.wikipedia.org/wiki/Pointer_alias
> In computer programming, aliasing refers to the situation where the same memory location can be accessed using different names.
>
> For instance, if a function takes two pointers A and B which have the same value, then the name A[0]aliases the name B[0]. In this case we say the pointers A and B alias each other.
[...]
> Aliasing introduces strong constraints on program execution order. If two write accesses which alias occur in sequence in a program text, they must occur in sequence in the final machine code. Re-ordering the accesses will produce an incorrect program result (in the general case). The same is true for a write access and a read access. [...]
> In FORTRAN, function arguments may not alias each other, and the compiler assumes they do not. This enables excellent optimization, and is one major reason for FORTRAN's reputation as a fast language.