đź“ťFortran used to be faster than C because of aliasing

source

Scott2016

C assumes that pointers of the same type can point to the same location in memory (aliasing), and thus cannot perform certain optimizations.

For example, in the following program, the compiler is required to fetch p twice—if q point to the same memory as p, it is invalid to reuse p’s value fetched before *q = 3 assignment.

int a, b, *p, *q;

a = *p;
*q = 3;
b = *p;

The situation is made worse by C heavily relying on pointers.

On the other hand, Fortran simply didn’t have pointers. So it used to be faster than C. Fortran forbids aliasing and that’s programmer’s responsibility to ensure values do not alias. The compiler assumes values do not alias.

Recently, however aliasing analysis got much better so it can generate good code in most of the cases.

See also:

Backlinks