autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regarding Fortran Compiler Characteristics


From: Ralf Wildenhues
Subject: Re: Regarding Fortran Compiler Characteristics
Date: Sat, 30 May 2009 11:49:09 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Hello Tobias,

* Tobias Burnus wrote on Fri, May 29, 2009 at 06:12:02PM CEST:
> I have a remark regarding the Fortran Compiler Characteristics section,
> http://www.gnu.org/software/autoconf/manual/html_node/Fortran-Compiler.html
> 
> There one can find for AC_FC_MAIN/AC_F77_MAIN:
> 
> "As discussed above, many Fortran libraries allow you to provide an entry
>  point called (say) MAIN__ instead of the usual main, [...]"
> 
> That part is OK. However, it continues with
> 
> "Thus, when calling Fortran routines from C that perform things like I/O,
>  one should use this macro and declare the "main" function like so:
> 
>           #ifdef __cplusplus
>             extern "C"
>           #endif
>           int F77_MAIN(int argc, char *argv[]);
> "
> 
> I believe this does not make much sense.

AFAIU you are saying that for these compilers:

> gfortran has:
> g95 has:
> NAG f95 uses:
> Intel uses:
> g77 uses:

calling this special function is not necessary, but it also is no
problem at all if the user does this; right?

Well, there are many more Fortran compilers and systems out there,
and the MAIN__ was definitely required for some of them at some point.

The macro has this in the comment:

# What is technically happening is that the Fortran libraries provide
# their own main() function, which usually initializes Fortran I/O and
# similar stuff, and then calls MAIN__, which is the entry point of
# your program.  Usually, a C program will override this with its own
# main() routine, but the linker sometimes complain if you don't
# provide a dummy (never-called) MAIN__ routine anyway.
#
# Of course, programs that want to allow Fortran subroutines to do
# I/O, etcetera, should call their main routine MAIN__() (or whatever)
# instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
# for the routine to use in this case (since the semantics of the test
# are slightly different).  To link to e.g. purely numerical
# libraries, this is normally not necessary, however, and most C/C++
# programs are reluctant to turn over so much control to Fortran.  =)
#
# The name variants we check for are (in order):
#   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
#   MAIN_, __main (SunOS)
#   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)

If the comment regarding g77 is outdated, then we should maybe try to
find out which version does not need it any more.  Also, have you tried
or looked at the Sun Studio, IBM, Portland, PathScale Fortran compilers?

If OTOH calling this other main function poses a problem for gfortran,
then we would need to do something about this (most likely: file a bug
report with gfortran for breaking backward compatibility :-).

Cheers, and thanks for the report,
Ralf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]