Reputation: 3
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?
Upvotes: 0
Views: 173
Reputation: 25286
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.
Upvotes: 5
Reputation: 33273
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.
Upvotes: 2