🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.f77
Article #400

Re: Startup routines for f77 and C

#400
From: sjc
Date: Sun, 20 Jul 1986 21:54
45 lines
2977 bytes
> Hello, is there anyone who knows, and is willing to explain what is
> meant by the following, taken from 'A Portable Fortran 77 Compiler', 
> S.I.Feldman and P.J.Weinberger.
> 
> 	'......the f77 and cc commands cause slightly different loading
> sequences to be generated, since Fortran programs need a few extra libraries

Under 4.2BSD, the "f77" and "cc" commands both tell the linker "ld" to
place the file "crt0.o" (or "mcrt0.o" if you choose to use the "-p"
option) at the beginning of your executable ("a.out") program.  Both
tell it to search "-lc" ("libc.a", the C library), but "f77" tells it
to search "-lF77", "-lI77", "-lU77", and "-lm" (three Fortran-specific
libraries and the Unix math library) prior to "-lc".

Fortran needs additional libraries (a) to implement Fortran-specific
features like read/write/print and the standard subroutines like csin
and sinh, and (b) to permit you to call routines like "getenv (3f)"
which resemble those in the C library but which use the Fortran calling
conventions (arguments generally passed by reference) rather than the C
calling conventions (arguments passed by value).

When you define or reference a subroutine or function in C, the
compiler constructs a symbol for it by prepending an "_". In Fortran,
the compiler both prepends and appends an "_". This has two advantages:
(a) names you invent within your program will not conflict with those
in the C library, and (b) the Fortran libraries can provide wrappers
for C library routines ("_getenv_" versus "_getenv").

"crt0.o" (or "mcrt0.o") jumps to "_main" to start your program. In C, the
main program is always called "main" (which gets transformed to "_main" as
just described). In Fortran, there's no way for you to create an "_main"
(the closest you can come is "_main_"), so by providing a module "main.o"
with an entry point called "_main", the compiler can guarantee that the
runtime library gets initialized before your own code starts to execute.
Among other things, it sets up signal handlers and arranges for the
subroutine "getargv (3f)" to be able to access the command-line arguments.
Then it transfers control to the entry point _MAIN_, which the compiler
always puts at the beginning of the Fortran main program (even if you use a
"program" statement to give it another name).

If you enjoy peeking at what the compiler is doing, "f77 -S" is a useful
technique.

-- 
...decwrl!mips!sjc						Steve Correll
Technical Details
Message-ID: <565@mips.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!nbires!hao!hplabs!pyramid!decwrl!glacier!mips!sjc
References: <1709@eagle.ukc.ac.uk>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!nbires!hao!hplabs!pyramid!decwrl!glacier!mips!sjc
From: sjc@mips.UUCP
Newsgroups: net.lang.f77
Subject: Re: Startup routines for f77 and C
Message-ID: <565@mips.UUCP>
Date: Sun, 20-Jul-86 17:54:25 EDT
Article-I.D.: mips.565
Posted: Sun Jul 20 17:54:25 1986
Date-Received: Mon, 21-Jul-86 21:39:13 EDT
References: <1709@eagle.ukc.ac.uk>
Organization: MIPS Computer Systems, Sunnyvale, CA
Lines: 45