1 \input texinfo @c -*-texinfo-*-
3 @setfilename gfortran.info
4 @set last-update 13 May 2004
5 @set copyrights-gfortran 1999-2004
7 @include gcc-common.texi
9 @settitle The GNU Fortran 95 Compiler
11 @c Create a separate index for command line options
13 @c Merge the standard indexes into a single one.
22 @c Use with @@smallbook.
24 @c %** start of document
26 @c Cause even numbered pages to be printed on the left hand side of
27 @c the page and odd numbered pages to be printed on the right hand
28 @c side of the page. Using this, you can print on both sides of a
29 @c sheet of paper and have the text on the same part of the sheet.
31 @c The text on right hand pages is pushed towards the right hand
32 @c margin and the text on left hand pages is pushed toward the left
34 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
37 @c \global\bindingoffset=0.75in
38 @c \global\normaloffset =0.75in
42 Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
44 Permission is granted to copy, distribute and/or modify this document
45 under the terms of the GNU Free Documentation License, Version 1.1 or
46 any later version published by the Free Software Foundation; with the
47 Invariant Sections being ``GNU General Public License'' and ``Funding
48 Free Software'', the Front-Cover
49 texts being (a) (see below), and with the Back-Cover Texts being (b)
50 (see below). A copy of the license is included in the section entitled
51 ``GNU Free Documentation License''.
53 (a) The FSF's Front-Cover Text is:
57 (b) The FSF's Back-Cover Text is:
59 You have freedom to copy and modify this GNU Manual, like GNU
60 software. Copies published by the Free Software Foundation raise
61 funds for GNU development.
65 @dircategory Programming
67 * gfortran: (gfortran). The GNU Fortran 95 Compiler.
69 This file documents the use and the internals of
70 the GNU Fortran 95 compiler, (@command{gfortran}).
72 Published by the Free Software Foundation
73 59 Temple Place - Suite 330
74 Boston, MA 02111-1307 USA
79 Contributed by Steven Bosscher (@email{s.bosscher@@gcc.gnu.org}).
81 @setchapternewpage odd
83 @title Using GNU Fortran 95
85 @center Steven Bosscher
87 @center Last updated @value{last-update}
89 @center for version @value {version-GCC}
91 @vskip 0pt plus 1filll
92 For the @value{version-GCC} Version*
94 Published by the Free Software Foundation @*
95 59 Temple Place - Suite 330@*
96 Boston, MA 02111-1307, USA@*
97 @c Last printed ??ber, 19??.@*
98 @c Printed copies are available for $? each.@*
107 @node Top, Copying,, (DIR)
111 This manual documents the use of @command{gfortran},
112 the GNU Fortran 95 compiler. You can find in this manual how to invoke
113 @command{gfortran}, as well as its features and incompatibilities.
116 @emph{Warning:} This document, and the compiler it describes, are still
117 under development. While efforts are made too keep it up-to-date it might
118 not accurately reflect the status of the most recent @command{gfortran}.
122 * Copying:: GNU General Public License says
123 how you can copy and share GNU Fortran.
124 * GNU Free Documentation License::
125 How you can copy and share this manual.
126 * Funding:: How to help assure continued work for free software.
127 * Getting Started:: What you should know about @command{gfortran}.
128 * GFORTRAN and GCC:: You can compile Fortran, C, or other programs.
129 * GFORTRAN and G77:: Why we choose to start from scratch.
130 * Invoking GFORTRAN:: Command options supported by @command{gfortran}.
131 * Project Status:: Status of GFORTRAN, Roadmap, proposed extensions.
132 * Contributing:: Helping you can help.
133 * Standards:: Standards supported by GFORTRAN.
134 * Index:: Index of this documentation.
139 @c ---------------------------------------------------------------------
140 @c GNU General Public License
141 @c ---------------------------------------------------------------------
147 @c ---------------------------------------------------------------------
148 @c GNU Free Documentation License
149 @c ---------------------------------------------------------------------
155 @c ---------------------------------------------------------------------
156 @c Funding Free Software
157 @c ---------------------------------------------------------------------
159 @include funding.texi
163 @c ---------------------------------------------------------------------
165 @c ---------------------------------------------------------------------
167 @node Getting Started
168 @chapter Getting Started
170 Gfortran is the GNU Fortran 95 compiler front end,
171 designed initially as a free replacement for,
172 or alternative to, the unix @command{f95} command;
173 @command{gfortran} is command you'll use to invoke the compiler.
175 Gfortran is still in an early state of development.
176 @command{gfortran} can generate code for most constructs and expressions,
177 but much work remains to be done.
179 When @command{gfortran} is finished,
180 it will do everything you expect from any decent compiler:
184 Read a user's program,
185 stored in a file and containing instructions written
186 in Fortran 77, Fortran 90 or Fortran 95.
187 This file contains @dfn{source code}.
190 Translate the user's program into instructions a computer
191 can carry out more quickly than it takes to translate the
192 instructions in the first
193 place. The result after compilation of a program is
195 code designed to be efficiently translated and processed
196 by a machine such as your computer.
197 Humans usually aren't as good writing machine code
198 as they are at writing Fortran (or C++, Ada, or Java),
199 because is easy to make tiny mistakes writing machine code.
202 Provide the user with information about the reasons why
203 the compiler is unable to create a binary from the source code.
204 Usually this will be the case if the source code is flawed.
205 When writing Fortran, it is easy to make big mistakes.
206 The Fortran 90 requires that the compiler can point out
207 mistakes to the user.
208 An incorrect usage of the language causes an @dfn{error message}.
210 The compiler will also attempt to diagnose cases where the
211 user's program contains a correct usage of the language,
212 but instructs the computer to do something questionable.
213 This kind of diagnostics message is called a @dfn{warning message}.
216 Provide optional information about the translation passes
217 from the source code to machine code.
218 This can help a user of the compiler to find the cause of
219 certain bugs which may not be obvious in the source code,
220 but may be more easily found at a lower level compiler output.
221 It also helps developers to find bugs in the compiler itself.
224 Provide information in the generated machine code that can
225 make it easier to find bugs in the program (using a debugging tool,
226 called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
229 Locate and gather machine code already generated to
230 perform actions requested by statements in the user's program.
231 This machine code is organized into @dfn{modules} and is located
232 and @dfn{linked} to the user program.
235 Gfortran consists of several components:
239 A version of the @command{gcc} command
240 (which also might be installed as the system's @command{cc} command)
241 that also understands and accepts Fortran source code.
242 The @command{gcc} command is the @dfn{driver} program for
243 all the languages in the GNU Compiler Collection (GCC);
245 you can compiler the source code of any language for
246 which a front end is available in GCC.
249 The @command{gfortran} command itself,
250 which also might be installed as the
251 system's @command{f95} command.
252 @command{gfortran} is just another driver program,
253 but specifically for the Fortran 95 compiler only.
254 The difference with @command{gcc} is that @command{gfortran}
255 will automatically link the correct libraries to your program.
258 A collection of run-time libraries.
259 These libraries contains the machine code needed to support
260 capabilities of the Fortran language that are not directly
261 provided by the machine code generated by the
262 @command{gfortran} compilation phase,
263 such as intrinsic functions and subroutines,
264 and routines for interaction with files and the operating system.
265 @c and mechanisms to spawn,
266 @c unleash and pause threads in parallelized code.
269 The Fortran compiler itself, (@command{f951}).
270 This is the gfortran parser and code generator,
271 linked to and interfaced with the GCC backend library.
272 @command{f951} ``translates'' the source code to
273 assembler code. You would typically not use this
275 instead, the @command{gcc} or @command{gfortran} driver
276 programs will call it for you.
281 @c ---------------------------------------------------------------------
283 @c ---------------------------------------------------------------------
285 @node GFORTRAN and GCC
286 @chapter GFORTRAN and GCC
287 @cindex GNU Compiler Collection
289 GCC used to be the GNU ``C'' Compiler,
290 but is now known as the @dfn{GNU Compiler Collection}.
291 GCC provides the GNU system with a very versatile
292 compiler middle end (shared optimization passes),
293 and with back ends (code generators) for many different
294 computer architectures and operating systems.
295 The code of the middle end and back end are shared by all
296 compiler front ends that are in the GNU Compiler Collection.
298 A GCC front end is essentially a source code parser
299 and a pass to generate a representation of the semantics
300 of the program in the source code in the GCC language
301 independent intermediate language,
302 called @dfn{GENERIC}.
304 The parser takes a source file written in a
305 particular computer language, reads and parses it,
306 and tries to make sure that the source code conforms to
308 Once the correctness of a program has been established,
309 the compiler will build a data structure known as the
310 @dfn{Abstract Syntax tree},
311 or just @dfn{AST} or ``tree'' for short.
312 This data structure represents the whole program
313 or a subroutine or a function.
314 The ``tree'' is passed to the GCC middle end,
315 which will perform optimization passes on it,
316 pass the optimized AST and generate assembly
317 for the program unit.
319 Different phases in this translation process can be,
320 and in fact @emph{are} merged in many compiler front ends.
321 GNU Fortran 95 has a strict separation between the
322 parser and code generator.
324 The goal of the gfortran project is to build a new front end for GCC:
325 A Fortran 95 front end.
326 In a non-gfortran installation,
327 @command{gcc} will not be able to compile Fortran 95 source code
328 (only the ``C'' front end has to be compiled if you want to build GCC,
329 all other languages are optional).
330 If you build GCC with gfortran, @command{gcc} will recognize
331 @file{.f/.f90/.f95} source files and accepts Fortran 95 specific
332 command line options.
336 @c ---------------------------------------------------------------------
338 @c ---------------------------------------------------------------------
340 @node GFORTRAN and G77
341 @chapter GFORTRAN and G77
345 Why do we write a compiler front end from scratch?
346 There's a fine Fortran 77 compiler in the
347 GNU Compiler Collection that accepts some features
348 of the Fortran 90 standard as extensions.
349 Why not start from there and revamp it?
351 One of the reasons is that Craig Burley, the author of G77,
352 has decided to stop working on the G77 front end.
353 On @uref{http://world.std.com/~burley/g77-why.html,
354 Craig explains the reasons for his decision to stop working on G77}
355 in one of the pages in his homepage.
356 Among the reasons is a lack of interest in improvements to
358 Users appear to be quite satisfied with @command{g77} as it is.
359 While @command{g77} is still being maintained (by Toon Moene),
360 it is unlikely that sufficient people will be willing
361 to completely rewrite the existing code.
363 But there are other reasons to start from scratch.
364 Many people, including Craig Burley,
365 no longer agreed with certain design decisions in the G77 front end.
366 Also, the interface of @command{g77} to the back end is written in
367 a style which is confusing and not up to date on recommended practice.
368 In fact, a full rewrite had already been planned for GCC 3.0.
370 When Craig decided to stop,
371 it just seemed to be a better idea to start a new project from scratch,
372 because it was expected to be easier to maintain code we
373 develop ourselves than to do a major overhaul of @command{g77} first,
374 and then build a Fortran 95 compiler out of it.
379 @c ---------------------------------------------------------------------
381 @c ---------------------------------------------------------------------
384 @chapter Project Status
387 As soon as gfortran can parse all of the statements correctly,
388 it will be in the ``larva'' state.
389 When we generate code, the ``puppa'' state.
390 When gfortran is done,
391 we'll see if it will be a beautiful butterfly,
392 or just a big bug....
394 --Andy Vaught, April 2000
397 The start of the GNU Fortran 95 project was announced on
398 the GCC homepage in March 18, 2000
399 (even though Andy had already been working on it for a while,
402 Gfortran is currently reaching the stage where is is able to compile real
403 world programs. However it is still under development and has many rough
409 * Proposed Extensions::
412 @node Compiler Status
413 @section Compiler Status
417 This is the part of gfortran which parses a source file, verifies that it
418 is valid Fortran 95, performs compile time replacement of constants
419 (PARAMETER variables) and reads and generate module files. This is
420 almost complete. Every Fortran 95 source should be accepted, and most
421 none-Fortran 95 source should be rejected. If you find a source file where
422 this is not true, please tell us. You can use the -fsyntax-only switch to
423 make gfortran quit after running the front end, effectively reducing it to
426 @item Middle end interface
427 These are the parts of gfortran that take the parse tree generated by the
428 front end and translate it to the GENERIC form required by the GCC back
429 end. Work is ongoing in these parts of gfortran, but a large part has
430 already been completed.
434 @section Library Status
436 Some intrinsic functions map directly to library functions, and in most
437 cases the name of the library function used depends on the type of the
438 arguments. For some intrinsics we generate inline code, and for others,
439 such as sin, cos and sqrt, we rely on the backend to use special
440 instructions in the floating point unit of the CPU if available, or to
441 fall back to a call to libm if these are not available.
443 Implementation of some non-elemental intrinsic functions (eg. DOT_PRODUCT,
444 AVERAGE) is not yet optimal. This is hard because we have to make decisions
445 whether to use inline code (good for small arrays as no function call
446 overhead occurs) or generate function calls (good for large arrays as it
447 allows use of hand-optimized assembly routines, SIMD instructions, etc.)
449 The IO library is still under development. The following features should be
450 usable for real programs:
454 @item Unformatted sequential
460 @item Formatted sequential ('T' edit descriptor, and others)
461 @item Namelist (can read a namelist that it writes, but not free-form)
467 @item Unformatted direct access
468 @item Formatted direct access
471 Many Fortran programs only use a small subset of the available IO
472 capabilities, so your milage may vary.
474 @node Proposed Extensions
475 @section Proposed Extensions
477 Here's a list of proposed extensions for @command{gfortran}, in no particular
478 order. Most of these are necessary to be fully compatible with
479 existing Fortran compilers, but they are not part of the official
480 J3 Fortran 95 standard.
482 @subsection Compiler extensions:
485 Flag for defining the kind number for default logicals.
488 User-specified alignment rules for structures.
490 Flag to generate a @code{Makefile} info.
493 Automatically extend single precision constants to double.
496 Cray pointers (this was high on the @command{g77} wishlist).
499 Compile code that conserves memory by dynamically allocating common and
500 module storage either on stack or heap.
503 Flag to cause the compiler to distinguish between upper and lower case
504 names. The Fortran 95 standard does not distinguish them.
507 Compile switch for changing the interpretation of a backslash from a
508 character to ``C''-style escape characters.
511 Compile flag to generate code for array conformance checking (suggest -CC).
514 User control of symbol names (underscores, etc).
517 Compile setting for maximum size of stack frame size before spilling
518 parts to static or heap.
521 Flag to force local variables into static space.
524 Flag to force local variables onto stack.
527 Flag to compile lines beginning with ``D''.
530 Flag to ignore lines beginning with ``D''.
533 Flag for maximum errors before ending compile.
536 Generate code to check for null pointer dereferences -- prints locus of
537 dereference instead of segfaulting. There was some discussion about this
538 option in the g95 development mailing list.
541 Allow setting default unit number.
544 Option to initialize of otherwise uninitialized integer and floating
548 Support for OpenMP directives. This also requires support from the runtime
549 library and the rest of the compiler.
552 Support for Fortran 200x. This includes several new features including
553 floating point exceptions, extended use of allocatable arrays, C
554 interoperability, Parameterizer data types and function pointers.
558 @subsection Environment Options
561 Pluggable library modules for random numbers, linear algebra.
562 LA should use BLAS calling conventions.
565 Environment variables controlling actions on arithmetic exceptions like
566 overflow, underflow, precision loss -- Generate NaN, abort, default.
570 Set precision for fp units that support it (i387).
573 Variables for setting fp rounding mode.
576 Support old style namelists ending in $end or &end.
579 Variable to fill uninitialized variables with a user-defined bit
583 Environment variable controlling filename that is opened for that unit
587 Environment variable to clear/trash memory being freed.
590 Environment variable to control tracing of allocations and frees.
593 Environment variable to display allocated memory at normal program end.
596 Environment variable for filename for * IO-unit.
599 Environment variable for temporary file directory.
602 Environment variable forcing standard output to be line buffered (unix).
605 Variable for swapping endianness during unformatted read.
608 Variable for swapping Endianness during unformatted write.
613 @c ---------------------------------------------------------------------
615 @c ---------------------------------------------------------------------
618 @chapter Contributing
621 Free software is only possible if people contribute to efforts
623 We're always in need of more people helping out with ideas
624 and comments, writing documentation and contributing code.
626 If you want to contribute to GNU Fortran 95,
627 have a look at the long lists of projects you can take on.
628 Some of these projects are small,
629 some of them are large;
630 some are completely orthogonal to the rest of what is
631 happening on @command{gfortran},
632 but others are ``mainstream'' projects in need of enthusiastic hackers.
633 All of these projects are important!
634 We'll eventually get around to the things here,
635 but they are also things doable by someone who is willing and able.
644 @section Contributors to GNU Fortran 95
649 Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
650 also the initiator of the whole project. Thanks Andy!
651 Most of the interface with GCC was written by @emph{Paul Brook}.
653 The following individuals have contributed code and/or
654 ideas and significant help to the gfortran project
655 (in no particular order):
659 @item Katherine Holcomb
660 @item Tobias Schlüter
661 @item Steven Bosscher
664 @item Niels Kristian Bech Jensen
671 The following people have contributed bug reports,
672 smaller or larger patches,
673 and much needed feedback and encouragement for the
674 @command{gfortran} project:
682 Many other individuals have helped debug,
683 test and improve @command{gfortran} over the past two years,
684 and we welcome you to do the same!
685 If you already have done so,
686 and you would like to see your name listed in the
687 list above, please contact us.
695 @item Help build the test suite
696 Solicit more code for donation to the test suite.
697 We can keep code private on request.
699 @item Bug hunting/squishing
700 Find bugs and write more test cases!
701 Test cases are especially very welcome,
702 because it allows us to concentrate on fixing bugs
703 instead of isolating them.
705 @item Smaller projects (``bug'' fixes):
707 @item Allow init exprs to be numbers raised to integer powers.
708 @item Implement correct rounding.
709 @item Implement F restrictions on Fortran 95 syntax.
710 @item See about making Emacs-parsable error messages.
714 If you wish to work on the runtime libraries,
715 please contact a project maintainer.
719 @c ---------------------------------------------------------------------
721 @c ---------------------------------------------------------------------
727 The GNU Fortran 95 Compiler aims to be a conforming implementation of
728 ISO/IEC 1539:1997 (Fortran 95).
730 In the future it may also support other variants and extensions to the Fortran
731 language. This includes ANSI Fortran 77, Fortran 90, Fortran 2000 (not yet
732 finalized), and OpenMP.