I'm in the process of updating a medium-sized Fortran program. I've just finished replacing the random number generator, which is now written in C. The C source code uses variables with "static storage duration" (which some people like to call global variables) to store that state of the random number generator between calls.
If the entire program is written in C, this means (using non-C-expert terminology) that when the program is compiled, there is some mechanism in place to prevent the memory from being freed up and overwritten by other parts of the program. However, what happens if the rest of the program is written in a different language? Can we still say that we are guaranteed that the memory will not be freed up between calls to the random number generator?
The C source files of course will be compiled to object, the Fortran files will be compiled to object files, and the object files will be linked to create the executable. I was always taught that there really isn't a "C linker" and a "Fortran linker", but just an object file linker. This line of reasoning suggests that whatever mechanism is used enforce the C storage duration will be preserved in the executable, regardless of what language the rest of the program is written in. However, I cannot say this with any authority. Can someone comment on this?
If the entire program is written in C, this means (using non-C-expert terminology) that when the program is compiled, there is some mechanism in place to prevent the memory from being freed up and overwritten by other parts of the program. However, what happens if the rest of the program is written in a different language? Can we still say that we are guaranteed that the memory will not be freed up between calls to the random number generator?
The C source files of course will be compiled to object, the Fortran files will be compiled to object files, and the object files will be linked to create the executable. I was always taught that there really isn't a "C linker" and a "Fortran linker", but just an object file linker. This line of reasoning suggests that whatever mechanism is used enforce the C storage duration will be preserved in the executable, regardless of what language the rest of the program is written in. However, I cannot say this with any authority. Can someone comment on this?
Comment