From a Fortran Code, I intend to run a C code (to read a file) and fetch the read information. The main program is the Fortran code, which uses a function written in C to do the processing. In this C code, is it necessary to run a main function?
If Fortran only calls the C function, then the C code does not need a main()
function.
The main()
function of C is the program entry point. The system loads the .exe, transfers control to the startup code, which address is mentioned in the .exe file (the startup code is called crt
, C run-time start-up). The run-time startup does initialization and then transfers control to the user code. The user code entry point is main()
.
Since Fortran is the main program, no C run-time start-up is needed and so no main()
is needed.
No, you don't need a main
in your C code. The linker will use the main
from the FORTRAN code, or rather, the FORTRAN equivalent of main
, when linking your C functions to the FORTRAN program.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.