I assumed that too, but looking at the symbol tables on Linux and Mac, I noticed that all three compilers (gfortran, ifort, and nvfortran) have this thing with MAIN_ and main going on. A colleague remarked that this must be some aboriginal Unix/ELF convention. The gfortran documentation for “Non-Fortran Main Program’s” states this is for historical reasons:
When you compile a
PROGRAMwith GNU Fortran, a function with the namemain(in the symbol table of the object file) is generated, which initializes the libgfortran library and then calls the actual program which uses the nameMAIN__, for historic reasons. If you link GNU Fortran compiled procedures to, e.g., a C or C++ program or to a Fortran program compiled by a different compiler, the libgfortran library is not initialized and thus a few intrinsic procedures do not work properly, e.g. those for obtaining the command-line arguments.
In libgfortran/runtime/main.c you can inspect that the runtime simply makes a copy of the input arguments from the C main:
static int argc_save;
static char **argv_save;
/* Set the saved values of the command line arguments. */
void
set_args (int argc, char **argv)
{
argc_save = argc;
argv_save = argv;
}
iexport(set_args);