News for hackers. Stuff that matters.
Re:Why physicists still use Fortran by Asooka on Sunday December 18, 2016 @05:40PM (#13208157)
I have one question - if I compile and link a program written in C and Fortran, can the linker inline Fortran functions in C? I know it can do it if I link object files produced from C source, but can it do it if I link object files from separate languages?
Re:Why physicists still use Fortran by greglindahl on Sunday December 18, 2016 @06:41PM (#13208417)
Most Fortran compilers are actually Fortran/C/C++ compilers, and cross-link and cross-inline with no problems.
Re:Why physicists still use Fortran by guitarbill on Sunday December 18, 2016 @06:05PM (#13208262)
Having never done it with Fortran, I don't know. It should be possible, because e.g. on Linux, everything adheres to the ABI. However, the ABI doesn't specify how to interpret pointers AFAIK. Array ordering [0] and indexing is different in Fortran compared to C, so I'm sure there's pitfalls you'd have to account for.

[0] https://en.wikipedia.org/wiki/Row-_and_column-major_order

Re:Why physicists still use Fortran by dfgasfjhjhsdojj on Sunday December 18, 2016 @07:37PM (#13208642)
Fortran arrays can be indexed however you like. Code that is designed to be called from C can be written with 0 indexed arrays.
Re:Why physicists still use Fortran by guitarbill on Monday December 19, 2016 @02:34AM (#13210043)
Sure, but you still have to remember to do so :)
Re:Why physicists still use Fortran by Annatar on Monday December 19, 2016 @02:49AM (#13210103)
It's not the link editor's function to inline; an optimizing compiler does that. A linker can, eventually and depending on the platform, perform some binary optimization, as is for example the case with Sun Studio compilers on SPARC (-xlinkopt=2), or with GCC (-flto), but that's not inlining.
Re:Why physicists still use Fortran by jabl on Monday December 19, 2016 @05:33AM (#13210605)
To nitpick, compilers nor linkers typically are not able to do "binary optimization", if by that you mean analyzing the asm and optimizing that. What happens when you compile with -flto or equivalent is that the compiler hides some internal representation in a special section in the object files, then at the link stage (if you also use -flto when linking) is that the linker invokes the compiler again which deserializes those trees from the object files, and does the inter-procedural optimizations on those.