Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Actually one of the reasons that Fortran is fast is not that the code you write in it is inherently faster than C. It is more that the idiomatic way of programming it is fast. This is not necessarily the case in C, where it is quite natural to use pointer structures, while in Fortran you would in most cases use large arrays that consists of continuously allocated memory instead.

It is of cause possible to do that in C as well, but it is not as natural. You can use pointer structures in modern Fortrans as well (as in F90 and later). Again, the difference is that idiomatic Fortran often lead to faster code.

One real difference is that Fortran do not allow aliased memory in arrays unless that is specifically declared using the "equivalence" statement, while in C and C++ that is the default assumption. This allows for some optimizations that can't be done safely in C. In C99 and later, you can use the "restrict" keyword to state the opposite, namely that an array is not aliased, but usually you won't do that outside of tight loops if at all.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: