OSDN Git Service

6a1c92b8da5b2613c7520de94af1fe654ca36c7b
[pf3gnuchains/gcc-fork.git] / gcc / fortran / gfortran.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename gfortran.info
4 @set copyrights-gfortran 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5
6 @include gcc-common.texi
7
8 @settitle The GNU Fortran Compiler
9
10 @c Create a separate index for command line options
11 @defcodeindex op
12 @c Merge the standard indexes into a single one.
13 @syncodeindex fn cp
14 @syncodeindex vr cp
15 @syncodeindex ky cp
16 @syncodeindex pg cp
17 @syncodeindex tp cp
18
19 @c TODO: The following "Part" definitions are included here temporarily
20 @c until they are incorporated into the official Texinfo distribution.
21 @c They borrow heavily from Texinfo's \unnchapentry definitions.
22
23 @tex
24 \gdef\part#1#2{%
25   \pchapsepmacro
26   \gdef\thischapter{}
27   \begingroup
28     \vglue\titlepagetopglue
29     \titlefonts \rm
30     \leftline{Part #1:@* #2}
31     \vskip4pt \hrule height 4pt width \hsize \vskip4pt
32   \endgroup
33   \writetocentry{part}{#2}{#1}
34 }
35 \gdef\blankpart{%
36   \writetocentry{blankpart}{}{}
37 }
38 % Part TOC-entry definition for summary contents.
39 \gdef\dosmallpartentry#1#2#3#4{%
40   \vskip .5\baselineskip plus.2\baselineskip
41   \begingroup
42     \let\rm=\bf \rm
43     \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
44   \endgroup
45 }
46 \gdef\dosmallblankpartentry#1#2#3#4{%
47   \vskip .5\baselineskip plus.2\baselineskip
48 }
49 % Part TOC-entry definition for regular contents.  This has to be
50 % equated to an existing entry to not cause problems when the PDF
51 % outline is created.
52 \gdef\dopartentry#1#2#3#4{%
53   \unnchapentry{Part #2: #1}{}{#3}{#4}
54 }
55 \gdef\doblankpartentry#1#2#3#4{}
56 @end tex
57
58 @c %**end of header
59
60 @c Use with @@smallbook.
61
62 @c %** start of document
63
64 @c Cause even numbered pages to be printed on the left hand side of
65 @c the page and odd numbered pages to be printed on the right hand
66 @c side of the page.  Using this, you can print on both sides of a
67 @c sheet of paper and have the text on the same part of the sheet.
68
69 @c The text on right hand pages is pushed towards the right hand
70 @c margin and the text on left hand pages is pushed toward the left
71 @c hand margin.
72 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
73
74 @c @tex
75 @c \global\bindingoffset=0.75in
76 @c \global\normaloffset =0.75in
77 @c @end tex
78
79 @copying
80 Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
81
82 Permission is granted to copy, distribute and/or modify this document
83 under the terms of the GNU Free Documentation License, Version 1.3 or
84 any later version published by the Free Software Foundation; with the
85 Invariant Sections being ``Funding Free Software'', the Front-Cover
86 Texts being (a) (see below), and with the Back-Cover Texts being (b)
87 (see below).  A copy of the license is included in the section entitled
88 ``GNU Free Documentation License''.
89
90 (a) The FSF's Front-Cover Text is:
91
92      A GNU Manual
93
94 (b) The FSF's Back-Cover Text is:
95
96      You have freedom to copy and modify this GNU Manual, like GNU
97      software.  Copies published by the Free Software Foundation raise
98      funds for GNU development.
99 @end copying
100
101 @ifinfo
102 @dircategory Software development
103 @direntry
104 * gfortran: (gfortran).                  The GNU Fortran Compiler.
105 @end direntry
106 This file documents the use and the internals of
107 the GNU Fortran compiler, (@command{gfortran}).
108
109 Published by the Free Software Foundation
110 51 Franklin Street, Fifth Floor
111 Boston, MA 02110-1301 USA
112
113 @insertcopying
114 @end ifinfo
115
116
117 @setchapternewpage odd
118 @titlepage
119 @title Using GNU Fortran
120 @versionsubtitle
121 @author The @t{gfortran} team
122 @page
123 @vskip 0pt plus 1filll
124 Published by the Free Software Foundation@*
125 51 Franklin Street, Fifth Floor@*
126 Boston, MA 02110-1301, USA@*
127 @c Last printed ??ber, 19??.@*
128 @c Printed copies are available for $? each.@*
129 @c ISBN ???
130 @sp 1
131 @insertcopying
132 @end titlepage
133
134 @c TODO: The following "Part" definitions are included here temporarily
135 @c until they are incorporated into the official Texinfo distribution.
136
137 @tex
138 \global\let\partentry=\dosmallpartentry
139 \global\let\blankpartentry=\dosmallblankpartentry
140 @end tex
141 @summarycontents
142
143 @tex
144 \global\let\partentry=\dopartentry
145 \global\let\blankpartentry=\doblankpartentry
146 @end tex
147 @contents
148
149 @page
150
151 @c ---------------------------------------------------------------------
152 @c TexInfo table of contents.
153 @c ---------------------------------------------------------------------
154
155 @ifnottex
156 @node Top
157 @top Introduction
158 @cindex Introduction
159
160 This manual documents the use of @command{gfortran}, 
161 the GNU Fortran compiler.  You can find in this manual how to invoke
162 @command{gfortran}, as well as its features and incompatibilities.
163
164 @ifset DEVELOPMENT
165 @emph{Warning:} This document, and the compiler it describes, are still
166 under development.  While efforts are made to keep it up-to-date, it might
167 not accurately reflect the status of the most recent GNU Fortran compiler.
168 @end ifset
169
170 @comment
171 @comment  When you add a new menu item, please keep the right hand
172 @comment  aligned to the same column.  Do not use tabs.  This provides
173 @comment  better formatting.
174 @comment
175 @menu
176 * Introduction::
177
178 Part I: Invoking GNU Fortran
179 * Invoking GNU Fortran:: Command options supported by @command{gfortran}.
180 * Runtime::              Influencing runtime behavior with environment variables.
181
182 Part II: Language Reference
183 * Fortran 2003 and 2008 status::  Fortran 2003 and 2008 features supported by GNU Fortran.
184 * Compiler Characteristics::      User-visible implementation details.
185 * Mixed-Language Programming::    Interoperability with C
186 * Extensions::           Language extensions implemented by GNU Fortran.
187 * Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
188 * Intrinsic Modules::    Intrinsic modules supported by GNU Fortran.
189
190 * Contributing::         How you can help.
191 * Copying::              GNU General Public License says
192                          how you can copy and share GNU Fortran.
193 * GNU Free Documentation License::
194                          How you can copy and share this manual.
195 * Funding::              How to help assure continued work for free software.
196 * Option Index::         Index of command line options
197 * Keyword Index::        Index of concepts
198 @end menu
199 @end ifnottex
200
201 @c ---------------------------------------------------------------------
202 @c Introduction
203 @c ---------------------------------------------------------------------
204
205 @node Introduction
206 @chapter Introduction
207
208 @c The following duplicates the text on the TexInfo table of contents.
209 @iftex
210 This manual documents the use of @command{gfortran}, the GNU Fortran
211 compiler.  You can find in this manual how to invoke @command{gfortran},
212 as well as its features and incompatibilities.
213
214 @ifset DEVELOPMENT
215 @emph{Warning:} This document, and the compiler it describes, are still
216 under development.  While efforts are made to keep it up-to-date, it
217 might not accurately reflect the status of the most recent GNU Fortran
218 compiler.
219 @end ifset
220 @end iftex
221
222 The GNU Fortran compiler front end was
223 designed initially as a free replacement for,
224 or alternative to, the unix @command{f95} command;
225 @command{gfortran} is the command you will use to invoke the compiler.
226
227 @menu
228 * About GNU Fortran::    What you should know about the GNU Fortran compiler.
229 * GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
230 * Preprocessing and conditional compilation:: The Fortran preprocessor
231 * GNU Fortran and G77::  Why we chose to start from scratch.
232 * Project Status::       Status of GNU Fortran, roadmap, proposed extensions.
233 * Standards::            Standards supported by GNU Fortran.
234 @end menu
235
236
237 @c ---------------------------------------------------------------------
238 @c About GNU Fortran
239 @c ---------------------------------------------------------------------
240
241 @node About GNU Fortran
242 @section About GNU Fortran
243
244 The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
245 completely, parts of the Fortran 2003 and Fortran 2008 standards, and
246 several vendor extensions.  The development goal is to provide the
247 following features:
248
249 @itemize @bullet
250 @item
251 Read a user's program,
252 stored in a file and containing instructions written
253 in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
254 This file contains @dfn{source code}.
255
256 @item
257 Translate the user's program into instructions a computer
258 can carry out more quickly than it takes to translate the
259 instructions in the first
260 place.  The result after compilation of a program is
261 @dfn{machine code},
262 code designed to be efficiently translated and processed
263 by a machine such as your computer.
264 Humans usually are not as good writing machine code
265 as they are at writing Fortran (or C++, Ada, or Java),
266 because it is easy to make tiny mistakes writing machine code.
267
268 @item
269 Provide the user with information about the reasons why
270 the compiler is unable to create a binary from the source code.
271 Usually this will be the case if the source code is flawed.
272 The Fortran 90 standard requires that the compiler can point out
273 mistakes to the user.
274 An incorrect usage of the language causes an @dfn{error message}.
275
276 The compiler will also attempt to diagnose cases where the
277 user's program contains a correct usage of the language,
278 but instructs the computer to do something questionable.
279 This kind of diagnostics message is called a @dfn{warning message}.
280
281 @item
282 Provide optional information about the translation passes
283 from the source code to machine code.
284 This can help a user of the compiler to find the cause of
285 certain bugs which may not be obvious in the source code,
286 but may be more easily found at a lower level compiler output.
287 It also helps developers to find bugs in the compiler itself.
288
289 @item
290 Provide information in the generated machine code that can
291 make it easier to find bugs in the program (using a debugging tool,
292 called a @dfn{debugger}, such as the GNU Debugger @command{gdb}). 
293
294 @item
295 Locate and gather machine code already generated to
296 perform actions requested by statements in the user's program.
297 This machine code is organized into @dfn{modules} and is located
298 and @dfn{linked} to the user program. 
299 @end itemize
300
301 The GNU Fortran compiler consists of several components:
302
303 @itemize @bullet
304 @item
305 A version of the @command{gcc} command
306 (which also might be installed as the system's @command{cc} command)
307 that also understands and accepts Fortran source code.
308 The @command{gcc} command is the @dfn{driver} program for
309 all the languages in the GNU Compiler Collection (GCC);
310 With @command{gcc},
311 you can compile the source code of any language for
312 which a front end is available in GCC.
313
314 @item
315 The @command{gfortran} command itself,
316 which also might be installed as the
317 system's @command{f95} command.
318 @command{gfortran} is just another driver program,
319 but specifically for the Fortran compiler only.
320 The difference with @command{gcc} is that @command{gfortran}
321 will automatically link the correct libraries to your program.
322
323 @item
324 A collection of run-time libraries.
325 These libraries contain the machine code needed to support
326 capabilities of the Fortran language that are not directly
327 provided by the machine code generated by the
328 @command{gfortran} compilation phase,
329 such as intrinsic functions and subroutines,
330 and routines for interaction with files and the operating system.
331 @c and mechanisms to spawn,
332 @c unleash and pause threads in parallelized code.
333
334 @item
335 The Fortran compiler itself, (@command{f951}).
336 This is the GNU Fortran parser and code generator,
337 linked to and interfaced with the GCC backend library.
338 @command{f951} ``translates'' the source code to
339 assembler code.  You would typically not use this
340 program directly;
341 instead, the @command{gcc} or @command{gfortran} driver
342 programs will call it for you.
343 @end itemize
344
345
346 @c ---------------------------------------------------------------------
347 @c GNU Fortran and GCC
348 @c ---------------------------------------------------------------------
349
350 @node GNU Fortran and GCC
351 @section GNU Fortran and GCC
352 @cindex GNU Compiler Collection
353 @cindex GCC
354
355 GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
356 consists of a collection of front ends for various languages, which
357 translate the source code into a language-independent form called
358 @dfn{GENERIC}.  This is then processed by a common middle end which
359 provides optimization, and then passed to one of a collection of back
360 ends which generate code for different computer architectures and
361 operating systems.
362
363 Functionally, this is implemented with a driver program (@command{gcc})
364 which provides the command-line interface for the compiler.  It calls
365 the relevant compiler front-end program (e.g., @command{f951} for
366 Fortran) for each file in the source code, and then calls the assembler
367 and linker as appropriate to produce the compiled output.  In a copy of
368 GCC which has been compiled with Fortran language support enabled,
369 @command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn},
370 @file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as
371 Fortran source code, and compile it accordingly.  A @command{gfortran}
372 driver program is also provided, which is identical to @command{gcc}
373 except that it automatically links the Fortran runtime libraries into the
374 compiled program.
375
376 Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
377 @file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
378 Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
379 @file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
380 treated as free form.  The capitalized versions of either form are run
381 through preprocessing.  Source files with the lower case @file{.fpp}
382 extension are also run through preprocessing.
383
384 This manual specifically documents the Fortran front end, which handles
385 the programming language's syntax and semantics.  The aspects of GCC
386 which relate to the optimization passes and the back-end code generation
387 are documented in the GCC manual; see 
388 @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
389 The two manuals together provide a complete reference for the GNU
390 Fortran compiler.
391
392
393 @c ---------------------------------------------------------------------
394 @c Preprocessing and conditional compilation
395 @c ---------------------------------------------------------------------
396
397 @node Preprocessing and conditional compilation
398 @section Preprocessing and conditional compilation
399 @cindex CPP
400 @cindex FPP
401 @cindex Conditional compilation
402 @cindex Preprocessing
403 @cindex preprocessor, include file handling
404
405 Many Fortran compilers including GNU Fortran allow passing the source code
406 through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
407 FPP) to allow for conditional compilation.  In the case of GNU Fortran,
408 this is the GNU C Preprocessor in the traditional mode.  On systems with
409 case-preserving file names, the preprocessor is automatically invoked if the
410 filename extension is @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp},
411 @file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}.  To manually
412 invoke the preprocessor on any file, use @option{-cpp}, to disable
413 preprocessing on files where the preprocessor is run automatically, use
414 @option{-nocpp}.
415
416 If a preprocessed file includes another file with the Fortran @code{INCLUDE}
417 statement, the included file is not preprocessed.  To preprocess included
418 files, use the equivalent preprocessor statement @code{#include}.
419
420 If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
421 is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
422 @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
423 compiler.  See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
424
425 While CPP is the de-facto standard for preprocessing Fortran code,
426 Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
427 Conditional Compilation, which is not widely used and not directly
428 supported by the GNU Fortran compiler.  You can use the program coco
429 to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
430
431
432 @c ---------------------------------------------------------------------
433 @c GNU Fortran and G77
434 @c ---------------------------------------------------------------------
435
436 @node GNU Fortran and G77
437 @section GNU Fortran and G77
438 @cindex Fortran 77
439 @cindex @command{g77}
440
441 The GNU Fortran compiler is the successor to @command{g77}, the Fortran 
442 77 front end included in GCC prior to version 4.  It is an entirely new 
443 program that has been designed to provide Fortran 95 support and 
444 extensibility for future Fortran language standards, as well as providing 
445 backwards compatibility for Fortran 77 and nearly all of the GNU language 
446 extensions supported by @command{g77}.
447
448
449 @c ---------------------------------------------------------------------
450 @c Project Status
451 @c ---------------------------------------------------------------------
452
453 @node Project Status
454 @section Project Status
455
456 @quotation
457 As soon as @command{gfortran} can parse all of the statements correctly,
458 it will be in the ``larva'' state.
459 When we generate code, the ``puppa'' state.
460 When @command{gfortran} is done,
461 we'll see if it will be a beautiful butterfly,
462 or just a big bug....
463
464 --Andy Vaught, April 2000
465 @end quotation
466
467 The start of the GNU Fortran 95 project was announced on
468 the GCC homepage in March 18, 2000
469 (even though Andy had already been working on it for a while,
470 of course).
471
472 The GNU Fortran compiler is able to compile nearly all
473 standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
474 including a number of standard and non-standard extensions, and can be
475 used on real-world programs.  In particular, the supported extensions
476 include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
477 2008 features, including TR 15581.  However, it is still under
478 development and has a few remaining rough edges.
479
480 At present, the GNU Fortran compiler passes the
481 @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html, 
482 NIST Fortran 77 Test Suite}, and produces acceptable results on the
483 @uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
484 It also provides respectable performance on 
485 the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
486 compiler benchmarks} and the
487 @uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
488 Livermore Fortran Kernels test}.  It has been used to compile a number of
489 large real-world programs, including
490 @uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
491 weather-forecasting code} and
492 @uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum 
493 chemistry package}; see @url{http://gcc.gnu.org/@/wiki/@/GfortranApps} for an
494 extended list.
495
496 Among other things, the GNU Fortran compiler is intended as a replacement
497 for G77.  At this point, nearly all programs that could be compiled with
498 G77 can be compiled with GNU Fortran, although there are a few minor known
499 regressions.
500
501 The primary work remaining to be done on GNU Fortran falls into three
502 categories: bug fixing (primarily regarding the treatment of invalid code
503 and providing useful error messages), improving the compiler optimizations
504 and the performance of compiled code, and extending the compiler to support
505 future standards---in particular, Fortran 2003 and Fortran 2008.
506
507
508 @c ---------------------------------------------------------------------
509 @c Standards
510 @c ---------------------------------------------------------------------
511
512 @node Standards
513 @section Standards
514 @cindex Standards
515
516 @menu
517 * Varying Length Character Strings::
518 @end menu
519
520 The GNU Fortran compiler implements
521 ISO/IEC 1539:1997 (Fortran 95).  As such, it can also compile essentially all
522 standard-compliant Fortran 90 and Fortran 77 programs.   It also supports
523 the ISO/IEC TR-15581 enhancements to allocatable arrays.
524
525 In the future, the GNU Fortran compiler will also support ISO/IEC
526 1539-1:2004 (Fortran 2003), ISO/IEC 1539-1:2010 (Fortran 2008) and
527 future Fortran standards.  Partial support of the Fortran 2003 and
528 Fortran 2008 standard is already provided; the current status of the
529 support is reported in the @ref{Fortran 2003 status} and
530 @ref{Fortran 2008 status} sections of the documentation.
531
532 Additionally, the GNU Fortran compilers supports the OpenMP specification
533 (version 3.1, @url{http://openmp.org/@/wp/@/openmp-specifications/}).
534
535 @node Varying Length Character Strings
536 @subsection Varying Length Character Strings
537 @cindex Varying length character strings
538 @cindex Varying length strings
539 @cindex strings, varying length
540
541 The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
542 varying length character strings.  While GNU Fortran currently does not
543 support such strings directly, there exist two Fortran implementations
544 for them, which work with GNU Fortran.  They can be found at
545 @uref{http://www.fortran.com/@/iso_varying_string.f95} and at
546 @uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
547
548
549
550 @c =====================================================================
551 @c PART I: INVOCATION REFERENCE
552 @c =====================================================================
553
554 @tex
555 \part{I}{Invoking GNU Fortran}
556 @end tex
557
558 @c ---------------------------------------------------------------------
559 @c Compiler Options
560 @c ---------------------------------------------------------------------
561
562 @include invoke.texi
563
564
565 @c ---------------------------------------------------------------------
566 @c Runtime
567 @c ---------------------------------------------------------------------
568
569 @node Runtime
570 @chapter Runtime:  Influencing runtime behavior with environment variables
571 @cindex environment variable
572
573 The behavior of the @command{gfortran} can be influenced by
574 environment variables.
575
576 Malformed environment variables are silently ignored.
577
578 @menu
579 * GFORTRAN_STDIN_UNIT:: Unit number for standard input
580 * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
581 * GFORTRAN_STDERR_UNIT:: Unit number for standard error
582 * GFORTRAN_TMPDIR:: Directory for scratch files
583 * GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units.
584 * GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
585 * GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
586 * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
587 * GFORTRAN_DEFAULT_RECL:: Default record length for new files
588 * GFORTRAN_LIST_SEPARATOR::  Separator for list output
589 * GFORTRAN_CONVERT_UNIT::  Set endianness for unformatted I/O
590 * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
591 @end menu
592
593 @node GFORTRAN_STDIN_UNIT
594 @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
595
596 This environment variable can be used to select the unit number
597 preconnected to standard input.  This must be a positive integer.
598 The default value is 5.
599
600 @node GFORTRAN_STDOUT_UNIT
601 @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
602
603 This environment variable can be used to select the unit number
604 preconnected to standard output.  This must be a positive integer.
605 The default value is 6.
606
607 @node GFORTRAN_STDERR_UNIT
608 @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
609
610 This environment variable can be used to select the unit number
611 preconnected to standard error.  This must be a positive integer.
612 The default value is 0.
613
614 @node GFORTRAN_TMPDIR
615 @section @env{GFORTRAN_TMPDIR}---Directory for scratch files
616
617 This environment variable controls where scratch files are
618 created.  If this environment variable is missing,
619 GNU Fortran searches for the environment variable @env{TMP}, then @env{TEMP}.
620 If these are missing, the default is @file{/tmp}.
621
622 @node GFORTRAN_UNBUFFERED_ALL
623 @section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
624
625 This environment variable controls whether all I/O is unbuffered.  If
626 the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
627 unbuffered.  This will slow down small sequential reads and writes.  If
628 the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
629 This is the default.
630
631 @node GFORTRAN_UNBUFFERED_PRECONNECTED
632 @section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
633
634 The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
635 whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered.  If 
636 the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered.  This
637 will slow down small sequential reads and writes.  If the first letter
638 is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.  This is the default.
639
640 @node GFORTRAN_SHOW_LOCUS
641 @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
642
643 If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
644 line numbers for runtime errors are printed.  If the first letter is
645 @samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
646 for runtime errors.  The default is to print the location.
647
648 @node GFORTRAN_OPTIONAL_PLUS
649 @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
650
651 If the first letter is @samp{y}, @samp{Y} or @samp{1},
652 a plus sign is printed
653 where permitted by the Fortran standard.  If the first letter
654 is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
655 in most cases.  Default is not to print plus signs.
656
657 @node GFORTRAN_DEFAULT_RECL
658 @section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
659
660 This environment variable specifies the default record length, in
661 bytes, for files which are opened without a @code{RECL} tag in the
662 @code{OPEN} statement.  This must be a positive integer.  The
663 default value is 1073741824 bytes (1 GB).
664
665 @node GFORTRAN_LIST_SEPARATOR
666 @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
667
668 This environment variable specifies the separator when writing
669 list-directed output.  It may contain any number of spaces and
670 at most one comma.  If you specify this on the command line,
671 be sure to quote spaces, as in
672 @smallexample
673 $ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
674 @end smallexample
675 when @command{a.out} is the compiled Fortran program that you want to run.
676 Default is a single space.
677
678 @node GFORTRAN_CONVERT_UNIT
679 @section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
680
681 By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
682 to change the representation of data for unformatted files.
683 The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
684 @smallexample
685 GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
686 mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
687 exception: mode ':' unit_list | unit_list ;
688 unit_list: unit_spec | unit_list unit_spec ;
689 unit_spec: INTEGER | INTEGER '-' INTEGER ;
690 @end smallexample
691 The variable consists of an optional default mode, followed by
692 a list of optional exceptions, which are separated by semicolons
693 from the preceding default and each other.  Each exception consists
694 of a format and a comma-separated list of units.  Valid values for
695 the modes are the same as for the @code{CONVERT} specifier:
696
697 @itemize @w{}
698 @item @code{NATIVE} Use the native format.  This is the default.
699 @item @code{SWAP} Swap between little- and big-endian.
700 @item @code{LITTLE_ENDIAN} Use the little-endian format
701 for unformatted files.
702 @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
703 @end itemize
704 A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
705 Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
706 @itemize @w{}
707 @item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
708 @item @code{'little_endian;native:10-20,25'}  Do all unformatted I/O 
709 in little_endian mode, except for units 10 to 20 and 25, which are in
710 native format.
711 @item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
712 @end itemize
713
714 Setting the environment variables should be done on the command
715 line or via the @command{export}
716 command for @command{sh}-compatible shells and via @command{setenv}
717 for @command{csh}-compatible shells.
718
719 Example for @command{sh}:
720 @smallexample
721 $ gfortran foo.f90
722 $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
723 @end smallexample
724
725 Example code for @command{csh}:
726 @smallexample
727 % gfortran foo.f90
728 % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
729 % ./a.out
730 @end smallexample
731
732 Using anything but the native representation for unformatted data
733 carries a significant speed overhead.  If speed in this area matters
734 to you, it is best if you use this only for data that needs to be
735 portable.
736
737 @xref{CONVERT specifier}, for an alternative way to specify the
738 data representation for unformatted files.  @xref{Runtime Options}, for
739 setting a default data representation for the whole program.  The
740 @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
741
742 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
743 environment variable will override the CONVERT specifier in the
744 open statement}.  This is to give control over data formats to
745 users who do not have the source code of their program available.
746
747 @node GFORTRAN_ERROR_BACKTRACE
748 @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
749
750 If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
751 @samp{Y} or @samp{1} (only the first letter is relevant) then a
752 backtrace is printed when a serious run-time error occurs.  To disable
753 the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
754 Default is to print a backtrace unless the @option{-fno-backtrace}
755 compile option was used.
756
757 @c =====================================================================
758 @c PART II: LANGUAGE REFERENCE
759 @c =====================================================================
760
761 @tex
762 \part{II}{Language Reference}
763 @end tex
764
765 @c ---------------------------------------------------------------------
766 @c Fortran 2003 and 2008 Status
767 @c ---------------------------------------------------------------------
768
769 @node Fortran 2003 and 2008 status
770 @chapter Fortran 2003 and 2008 Status
771
772 @menu
773 * Fortran 2003 status::
774 * Fortran 2008 status::
775 * TS 29113 status::
776 @end menu
777
778 @node Fortran 2003 status
779 @section Fortran 2003 status
780
781 GNU Fortran supports several Fortran 2003 features; an incomplete
782 list can be found below.  See also the
783 @uref{http://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
784
785 @itemize
786 @item Procedure pointers including procedure-pointer components with
787 @code{PASS} attribute.
788
789 @item Procedures which are bound to a derived type (type-bound procedures)
790 including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and
791 operators bound to a type.
792
793 @item Abstract interfaces and type extension with the possibility to
794 override type-bound procedures or to have deferred binding.
795
796 @item Polymorphic entities (``@code{CLASS}'') for derived types -- including
797 @code{SAME_TYPE_AS}, @code{EXTENDS_TYPE_OF} and @code{SELECT TYPE}.
798 Note that the support for array-valued polymorphic entities is incomplete
799 and unlimited polymophism is currently not supported.
800
801 @item The @code{ASSOCIATE} construct.
802
803 @item Interoperability with C including enumerations, 
804
805 @item In structure constructors the components with default values may be
806 omitted.
807
808 @item Extensions to the @code{ALLOCATE} statement, allowing for a
809 type-specification with type parameter and for allocation and initialization
810 from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE}
811 optionally return an error message string via @code{ERRMSG=}.
812
813 @item Reallocation on assignment: If an intrinsic assignment is
814 used, an allocatable variable on the left-hand side is automatically allocated
815 (if unallocated) or reallocated (if the shape is different). Currently, scalar
816 deferred character length left-hand sides are correctly handled but arrays
817 are not yet fully implemented.
818
819 @item Transferring of allocations via @code{MOVE_ALLOC}.
820
821 @item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually
822 to derived-type components.
823
824 @item In pointer assignments, the lower bound may be specified and
825 the remapping of elements is supported.
826
827 @item For pointers an @code{INTENT} may be specified which affect the
828 association status not the value of the pointer target.
829
830 @item Intrinsics @code{command_argument_count}, @code{get_command},
831 @code{get_command_argument}, and @code{get_environment_variable}.
832
833 @item Support for unicode characters (ISO 10646) and UTF-8, including
834 the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions.
835
836 @item Support for binary, octal and hexadecimal (BOZ) constants in the
837 intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}.
838
839 @item Support for namelist variables with allocatable and pointer
840 attribute and nonconstant length type parameter.
841
842 @item
843 @cindex array, constructors
844 @cindex @code{[...]}
845 Array constructors using square brackets.  That is, @code{[...]} rather
846 than @code{(/.../)}.  Type-specification for array constructors like
847 @code{(/ some-type :: ... /)}.
848
849 @item Extensions to the specification and initialization expressions,
850 including the support for intrinsics with real and complex arguments.
851
852 @item Support for the asynchronous input/output syntax; however, the
853 data transfer is currently always synchronously performed. 
854
855 @item
856 @cindex @code{FLUSH} statement
857 @cindex statement, @code{FLUSH}
858 @code{FLUSH} statement.
859
860 @item
861 @cindex @code{IOMSG=} specifier
862 @code{IOMSG=} specifier for I/O statements.
863
864 @item
865 @cindex @code{ENUM} statement
866 @cindex @code{ENUMERATOR} statement
867 @cindex statement, @code{ENUM}
868 @cindex statement, @code{ENUMERATOR}
869 @opindex @code{fshort-enums}
870 Support for the declaration of enumeration constants via the
871 @code{ENUM} and @code{ENUMERATOR} statements.  Interoperability with
872 @command{gcc} is guaranteed also for the case where the
873 @command{-fshort-enums} command line option is given.
874
875 @item
876 @cindex TR 15581
877 TR 15581:
878 @itemize
879 @item
880 @cindex @code{ALLOCATABLE} dummy arguments
881 @code{ALLOCATABLE} dummy arguments.
882 @item
883 @cindex @code{ALLOCATABLE} function results
884 @code{ALLOCATABLE} function results
885 @item
886 @cindex @code{ALLOCATABLE} components of derived types
887 @code{ALLOCATABLE} components of derived types
888 @end itemize
889
890 @item
891 @cindex @code{STREAM} I/O
892 @cindex @code{ACCESS='STREAM'} I/O
893 The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
894 allowing I/O without any record structure.
895
896 @item
897 Namelist input/output for internal files.
898
899 @item Further I/O extensions: Rounding during formatted output, using of
900 a decimal comma instead of a decimal point, setting whether a plus sign
901 should appear for positive numbers.
902
903 @item
904 @cindex @code{PROTECTED} statement
905 @cindex statement, @code{PROTECTED}
906 The @code{PROTECTED} statement and attribute.
907
908 @item
909 @cindex @code{VALUE} statement
910 @cindex statement, @code{VALUE}
911 The @code{VALUE} statement and attribute.
912
913 @item
914 @cindex @code{VOLATILE} statement
915 @cindex statement, @code{VOLATILE}
916 The @code{VOLATILE} statement and attribute.
917
918 @item
919 @cindex @code{IMPORT} statement
920 @cindex statement, @code{IMPORT}
921 The @code{IMPORT} statement, allowing to import
922 host-associated derived types.
923
924 @item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported,
925 which contains parameters of the I/O units, storage sizes. Additionally,
926 procedures for C interoperability are available in the @code{ISO_C_BINDING}
927 module.
928
929 @item
930 @cindex @code{USE, INTRINSIC} statement
931 @cindex statement, @code{USE, INTRINSIC}
932 @cindex @code{ISO_FORTRAN_ENV} statement
933 @cindex statement, @code{ISO_FORTRAN_ENV}
934 @code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
935 attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
936 @code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS}.
937
938 @item
939 Renaming of operators in the @code{USE} statement.
940
941 @end itemize
942
943
944 @node Fortran 2008 status
945 @section Fortran 2008 status
946
947 The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally
948 known as Fortran 2008.  The official version is available from International
949 Organization for Standardization (ISO) or its national member organizations.
950 The the final draft (FDIS) can be downloaded free of charge from
951 @url{http://www.nag.co.uk/@/sc22wg5/@/links.html}.  Fortran is developed by the
952 Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the
953 International Organization for Standardization and the International
954 Electrotechnical Commission (IEC).  This group is known as
955 @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
956
957 The GNU Fortran compiler supports several of the new features of Fortran 2008;
958 the @uref{http://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
959 about the current Fortran 2008 implementation status.  In particular, the
960 following is implemented.
961
962 @itemize
963 @item The @option{-std=f2008} option and support for the file extensions 
964 @file{.f08} and @file{.F08}.
965
966 @item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
967 which returns a unique file unit, thus preventing inadvertent use of the
968 same unit in different parts of the program.
969
970 @item The @code{g0} format descriptor and unlimited format items.
971
972 @item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH},
973 @code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0},
974 @code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1},
975 @code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}.
976
977 @item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH},
978 @code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible;
979 @code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}).
980
981 @item Support of the @code{PARITY} intrinsic functions.
982
983 @item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for
984 counting the number of leading and trailing zero bits, @code{POPCNT} and
985 @code{POPPAR} for counting the number of one bits and returning the parity;
986 @code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons;
987 @code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts,
988 @code{MASKL} and @code{MASKR} for simple left and right justified masks,
989 @code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA},
990 @code{SHIFTL} and @code{SHIFTR} for shift operations, and the
991 transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}.
992
993 @item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine.
994
995 @item Support for the @code{STORAGE_SIZE} intrinsic inquiry function.
996
997 @item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type
998 parameters and the array-valued named constants @code{INTEGER_KINDS},
999 @code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of
1000 the intrinsic module @code{ISO_FORTRAN_ENV}.
1001
1002 @item The module procedures @code{C_SIZEOF} of the intrinsic module
1003 @code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS}
1004 of @code{ISO_FORTRAN_ENV}.
1005
1006 @item Coarray support for serial programs with @option{-fcoarray=single} flag
1007 and experimental support for multiple images with the @option{-fcoarray=lib}
1008 flag.
1009
1010 @item The @code{DO CONCURRENT} construct is supported.
1011
1012 @item The @code{BLOCK} construct is supported.
1013
1014 @item The @code{STOP} and the new @code{ERROR STOP} statements now
1015 support all constant expressions.
1016
1017 @item Support for the @code{CONTIGUOUS} attribute.
1018
1019 @item Support for @code{ALLOCATE} with @code{MOLD}.
1020
1021 @item Support for the @code{IMPURE} attribute for procedures, which
1022 allows for @code{ELEMENTAL} procedures without the restrictions of
1023 @code{PURE}.
1024
1025 @item Null pointers (including @code{NULL()}) and not-allocated variables
1026 can be used as actual argument to optional non-pointer, non-allocatable
1027 dummy arguments, denoting an absent argument.
1028
1029 @item Non-pointer variables with @code{TARGET} attribute can be used as
1030 actual argument to @code{POINTER} dummies with @code{INTENT(IN)}.
1031
1032 @item Pointers including procedure pointers and those in a derived
1033 type (pointer components) can now be initialized by a target instead
1034 of only by @code{NULL}.
1035
1036 @item The @code{EXIT} statement (with construct-name) can be now be
1037 used to leave not only the @code{DO} but also the @code{ASSOCIATE},
1038 @code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE}
1039 constructs.
1040
1041 @item Internal procedures can now be used as actual argument.
1042
1043 @item Minor features: obsolesce diagnostics for @code{ENTRY} with
1044 @option{-std=f2008}; a line may start with a semicolon; for internal
1045 and module procedures @code{END} can be used instead of
1046 @code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND}
1047 now also takes a @code{RADIX} argument; intrinsic types are supported
1048 for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures
1049 can be declared in a single @code{PROCEDURE} statement; implied-shape
1050 arrays are supported for named constants (@code{PARAMETER}).
1051 @end itemize
1052
1053
1054
1055 @node TS 29113 status
1056 @section Technical Specification 29113 Status
1057
1058 GNU Fortran supports some of the new features of the Technical
1059 Specification (TS) 29113 on Further Interoperability of Fortran with C.
1060 The @uref{http://gcc.gnu.org/wiki/TS29113Status, wiki} has some information
1061 about the current TS 29113 implementation status.  In particular, the
1062 following is implemented.
1063
1064 @itemize
1065 @item The @option{-std=f2008ts} option.
1066
1067 @item The @code{OPTIONAL} attribute is allowed for dummy arguments
1068 of @code{BIND(C) procedures.}
1069
1070 @item The RANK intrinsic is supported.
1071
1072 @item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS}
1073 attribute is compatible with TS 29113.
1074 @end itemize
1075
1076
1077
1078 @c ---------------------------------------------------------------------
1079 @c Compiler Characteristics
1080 @c ---------------------------------------------------------------------
1081
1082 @node Compiler Characteristics
1083 @chapter Compiler Characteristics
1084
1085 This chapter describes certain characteristics of the GNU Fortran
1086 compiler, that are not specified by the Fortran standard, but which
1087 might in some way or another become visible to the programmer.
1088
1089 @menu
1090 * KIND Type Parameters::
1091 * Internal representation of LOGICAL variables::
1092 * Thread-safety of the runtime library::
1093 @end menu
1094
1095
1096 @node KIND Type Parameters
1097 @section KIND Type Parameters
1098 @cindex kind
1099
1100 The @code{KIND} type parameters supported by GNU Fortran for the primitive
1101 data types are:
1102
1103 @table @code
1104
1105 @item INTEGER
1106 1, 2, 4, 8*, 16*, default: 4 (1)
1107
1108 @item LOGICAL
1109 1, 2, 4, 8*, 16*, default: 4 (1)
1110
1111 @item REAL
1112 4, 8, 10*, 16*, default: 4 (2)
1113
1114 @item COMPLEX
1115 4, 8, 10*, 16*, default: 4 (2)
1116
1117 @item CHARACTER
1118 1, 4, default: 1
1119
1120 @end table
1121
1122 @noindent
1123 * = not available on all systems @*
1124 (1) Unless -fdefault-integer-8 is used @*
1125 (2) Unless -fdefault-real-8 is used
1126
1127 @noindent
1128 The @code{KIND} value matches the storage size in bytes, except for
1129 @code{COMPLEX} where the storage size is twice as much (or both real and
1130 imaginary part are a real value of the given size).  It is recommended to use
1131 the @code{SELECTED_CHAR_KIND}, @code{SELECTED_INT_KIND} and
1132 @code{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
1133 @code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
1134 parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
1135 The available kind parameters can be found in the constant arrays
1136 @code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
1137 @code{REAL_KINDS} in the @code{ISO_FORTRAN_ENV} module
1138 (see @ref{ISO_FORTRAN_ENV}).
1139
1140
1141 @node Internal representation of LOGICAL variables
1142 @section Internal representation of LOGICAL variables
1143 @cindex logical, variable representation
1144
1145 The Fortran standard does not specify how variables of @code{LOGICAL}
1146 type are represented, beyond requiring that @code{LOGICAL} variables
1147 of default kind have the same storage size as default @code{INTEGER}
1148 and @code{REAL} variables.  The GNU Fortran internal representation is
1149 as follows.
1150
1151 A @code{LOGICAL(KIND=N)} variable is represented as an
1152 @code{INTEGER(KIND=N)} variable, however, with only two permissible
1153 values: @code{1} for @code{.TRUE.} and @code{0} for
1154 @code{.FALSE.}.  Any other integer value results in undefined behavior.
1155
1156 Note that for mixed-language programming using the
1157 @code{ISO_C_BINDING} feature, there is a @code{C_BOOL} kind that can
1158 be used to create @code{LOGICAL(KIND=C_BOOL)} variables which are
1159 interoperable with the C99 _Bool type.  The C99 _Bool type has an
1160 internal representation described in the C99 standard, which is
1161 identical to the above description, i.e. with 1 for true and 0 for
1162 false being the only permissible values.  Thus the internal
1163 representation of @code{LOGICAL} variables in GNU Fortran is identical
1164 to C99 _Bool, except for a possible difference in storage size
1165 depending on the kind.
1166
1167
1168 @node Thread-safety of the runtime library
1169 @section Thread-safety of the runtime library
1170 @cindex thread-safety, threads
1171
1172 GNU Fortran can be used in programs with multiple threads, e.g.@: by
1173 using OpenMP, by calling OS thread handling functions via the
1174 @code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
1175 being called from a multi-threaded program.
1176
1177 The GNU Fortran runtime library, (@code{libgfortran}), supports being
1178 called concurrently from multiple threads with the following
1179 exceptions. 
1180
1181 During library initialization, the C @code{getenv} function is used,
1182 which need not be thread-safe.  Similarly, the @code{getenv}
1183 function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
1184 @code{GETENV} intrinsics.  It is the responsibility of the user to
1185 ensure that the environment is not being updated concurrently when any
1186 of these actions are taking place.
1187
1188 The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
1189 implemented with the @code{system} function, which need not be
1190 thread-safe.  It is the responsibility of the user to ensure that
1191 @code{system} is not called concurrently.
1192
1193 Finally, for platforms not supporting thread-safe POSIX functions,
1194 further functionality might not be thread-safe.  For details, please
1195 consult the documentation for your operating system.
1196
1197 @c ---------------------------------------------------------------------
1198 @c Extensions
1199 @c ---------------------------------------------------------------------
1200
1201 @c Maybe this chapter should be merged with the 'Standards' section,
1202 @c whenever that is written :-)
1203
1204 @node Extensions
1205 @chapter Extensions
1206 @cindex extensions
1207
1208 The two sections below detail the extensions to standard Fortran that are
1209 implemented in GNU Fortran, as well as some of the popular or
1210 historically important extensions that are not (or not yet) implemented.
1211 For the latter case, we explain the alternatives available to GNU Fortran
1212 users, including replacement by standard-conforming code or GNU
1213 extensions.
1214
1215 @menu
1216 * Extensions implemented in GNU Fortran::
1217 * Extensions not implemented in GNU Fortran::
1218 @end menu
1219
1220
1221 @node Extensions implemented in GNU Fortran
1222 @section Extensions implemented in GNU Fortran
1223 @cindex extensions, implemented
1224
1225 GNU Fortran implements a number of extensions over standard
1226 Fortran.  This chapter contains information on their syntax and
1227 meaning.  There are currently two categories of GNU Fortran
1228 extensions, those that provide functionality beyond that provided
1229 by any standard, and those that are supported by GNU Fortran
1230 purely for backward compatibility with legacy compilers.  By default,
1231 @option{-std=gnu} allows the compiler to accept both types of
1232 extensions, but to warn about the use of the latter.  Specifying
1233 either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
1234 disables both types of extensions, and @option{-std=legacy} allows both
1235 without warning.
1236
1237 @menu
1238 * Old-style kind specifications::
1239 * Old-style variable initialization::
1240 * Extensions to namelist::
1241 * X format descriptor without count field::
1242 * Commas in FORMAT specifications::
1243 * Missing period in FORMAT specifications::
1244 * I/O item lists::
1245 * BOZ literal constants::
1246 * @code{Q} exponent-letter::
1247 * Real array indices::
1248 * Unary operators::
1249 * Implicitly convert LOGICAL and INTEGER values::
1250 * Hollerith constants support::
1251 * Cray pointers::
1252 * CONVERT specifier::
1253 * OpenMP::
1254 * Argument list functions::
1255 @end menu
1256
1257 @node Old-style kind specifications
1258 @subsection Old-style kind specifications
1259 @cindex kind, old-style
1260
1261 GNU Fortran allows old-style kind specifications in declarations.  These
1262 look like:
1263 @smallexample
1264       TYPESPEC*size x,y,z
1265 @end smallexample
1266 @noindent
1267 where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
1268 etc.), and where @code{size} is a byte count corresponding to the
1269 storage size of a valid kind for that type.  (For @code{COMPLEX}
1270 variables, @code{size} is the total size of the real and imaginary
1271 parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
1272 be of type @code{TYPESPEC} with the appropriate kind.  This is
1273 equivalent to the standard-conforming declaration
1274 @smallexample
1275       TYPESPEC(k) x,y,z
1276 @end smallexample
1277 @noindent
1278 where @code{k} is the kind parameter suitable for the intended precision.  As
1279 kind parameters are implementation-dependent, use the @code{KIND},
1280 @code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
1281 the correct value, for instance @code{REAL*8 x} can be replaced by:
1282 @smallexample
1283 INTEGER, PARAMETER :: dbl = KIND(1.0d0)
1284 REAL(KIND=dbl) :: x
1285 @end smallexample
1286
1287 @node Old-style variable initialization
1288 @subsection Old-style variable initialization
1289
1290 GNU Fortran allows old-style initialization of variables of the
1291 form:
1292 @smallexample
1293       INTEGER i/1/,j/2/
1294       REAL x(2,2) /3*0.,1./
1295 @end smallexample
1296 The syntax for the initializers is as for the @code{DATA} statement, but
1297 unlike in a @code{DATA} statement, an initializer only applies to the
1298 variable immediately preceding the initialization.  In other words,
1299 something like @code{INTEGER I,J/2,3/} is not valid.  This style of
1300 initialization is only allowed in declarations without double colons
1301 (@code{::}); the double colons were introduced in Fortran 90, which also
1302 introduced a standard syntax for initializing variables in type
1303 declarations.
1304
1305 Examples of standard-conforming code equivalent to the above example
1306 are:
1307 @smallexample
1308 ! Fortran 90
1309       INTEGER :: i = 1, j = 2
1310       REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
1311 ! Fortran 77
1312       INTEGER i, j
1313       REAL x(2,2)
1314       DATA i/1/, j/2/, x/3*0.,1./
1315 @end smallexample
1316
1317 Note that variables which are explicitly initialized in declarations
1318 or in @code{DATA} statements automatically acquire the @code{SAVE}
1319 attribute.
1320
1321 @node Extensions to namelist
1322 @subsection Extensions to namelist
1323 @cindex Namelist
1324
1325 GNU Fortran fully supports the Fortran 95 standard for namelist I/O
1326 including array qualifiers, substrings and fully qualified derived types.
1327 The output from a namelist write is compatible with namelist read.  The
1328 output has all names in upper case and indentation to column 1 after the
1329 namelist name.  Two extensions are permitted:
1330
1331 Old-style use of @samp{$} instead of @samp{&}
1332 @smallexample
1333 $MYNML
1334  X(:)%Y(2) = 1.0 2.0 3.0
1335  CH(1:4) = "abcd"
1336 $END
1337 @end smallexample
1338
1339 It should be noted that the default terminator is @samp{/} rather than
1340 @samp{&END}.
1341
1342 Querying of the namelist when inputting from stdin.  After at least
1343 one space, entering @samp{?} sends to stdout the namelist name and the names of
1344 the variables in the namelist:
1345 @smallexample
1346  ?
1347
1348 &mynml
1349  x
1350  x%y
1351  ch
1352 &end
1353 @end smallexample
1354
1355 Entering @samp{=?} outputs the namelist to stdout, as if
1356 @code{WRITE(*,NML = mynml)} had been called:
1357 @smallexample
1358 =?
1359
1360 &MYNML
1361  X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
1362  X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
1363  X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
1364  CH=abcd,  /
1365 @end smallexample
1366
1367 To aid this dialog, when input is from stdin, errors send their
1368 messages to stderr and execution continues, even if @code{IOSTAT} is set.
1369
1370 @code{PRINT} namelist is permitted.  This causes an error if
1371 @option{-std=f95} is used.
1372 @smallexample
1373 PROGRAM test_print
1374   REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
1375   NAMELIST /mynml/ x
1376   PRINT mynml
1377 END PROGRAM test_print
1378 @end smallexample
1379
1380 Expanded namelist reads are permitted.  This causes an error if 
1381 @option{-std=f95} is used.  In the following example, the first element
1382 of the array will be given the value 0.00 and the two succeeding
1383 elements will be given the values 1.00 and 2.00.
1384 @smallexample
1385 &MYNML
1386   X(1,1) = 0.00 , 1.00 , 2.00
1387 /
1388 @end smallexample
1389
1390 @node X format descriptor without count field
1391 @subsection @code{X} format descriptor without count field
1392
1393 To support legacy codes, GNU Fortran permits the count field of the
1394 @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1395 When omitted, the count is implicitly assumed to be one.
1396
1397 @smallexample
1398        PRINT 10, 2, 3
1399 10     FORMAT (I1, X, I1)
1400 @end smallexample
1401
1402 @node Commas in FORMAT specifications
1403 @subsection Commas in @code{FORMAT} specifications
1404
1405 To support legacy codes, GNU Fortran allows the comma separator
1406 to be omitted immediately before and after character string edit
1407 descriptors in @code{FORMAT} statements.
1408
1409 @smallexample
1410        PRINT 10, 2, 3
1411 10     FORMAT ('FOO='I1' BAR='I2)
1412 @end smallexample
1413
1414
1415 @node Missing period in FORMAT specifications
1416 @subsection Missing period in @code{FORMAT} specifications
1417
1418 To support legacy codes, GNU Fortran allows missing periods in format
1419 specifications if and only if @option{-std=legacy} is given on the
1420 command line.  This is considered non-conforming code and is
1421 discouraged.
1422
1423 @smallexample
1424        REAL :: value
1425        READ(*,10) value
1426 10     FORMAT ('F4')
1427 @end smallexample
1428
1429 @node I/O item lists
1430 @subsection I/O item lists
1431 @cindex I/O item lists
1432
1433 To support legacy codes, GNU Fortran allows the input item list
1434 of the @code{READ} statement, and the output item lists of the
1435 @code{WRITE} and @code{PRINT} statements, to start with a comma.
1436
1437 @node @code{Q} exponent-letter
1438 @subsection @code{Q} exponent-letter
1439 @cindex @code{Q} exponent-letter
1440
1441 GNU Fortran accepts real literal constants with an exponent-letter
1442 of @code{Q}, for example, @code{1.23Q45}.  The constant is interpreted
1443 as a @code{REAL(16)} entity on targets that suppports this type.  If
1444 the target does not support @code{REAL(16)} but has a @code{REAL(10)}
1445 type, then the real-literal-constant will be interpreted as a
1446 @code{REAL(10)} entity.  In the absence of @code{REAL(16)} and
1447 @code{REAL(10)}, an error will occur.
1448
1449 @node BOZ literal constants
1450 @subsection BOZ literal constants
1451 @cindex BOZ literal constants
1452
1453 Besides decimal constants, Fortran also supports binary (@code{b}),
1454 octal (@code{o}) and hexadecimal (@code{z}) integer constants.  The
1455 syntax is: @samp{prefix quote digits quote}, were the prefix is
1456 either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
1457 @code{"} and the digits are for binary @code{0} or @code{1}, for
1458 octal between @code{0} and @code{7}, and for hexadecimal between
1459 @code{0} and @code{F}.  (Example: @code{b'01011101'}.)
1460
1461 Up to Fortran 95, BOZ literals were only allowed to initialize
1462 integer variables in DATA statements.  Since Fortran 2003 BOZ literals
1463 are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
1464 and @code{CMPLX}; the result is the same as if the integer BOZ
1465 literal had been converted by @code{TRANSFER} to, respectively,
1466 @code{real}, @code{double precision}, @code{integer} or @code{complex}.
1467 As GNU Fortran extension the intrinsic procedures @code{FLOAT},
1468 @code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
1469
1470 As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
1471 be specified using the @code{X} prefix, in addition to the standard
1472 @code{Z} prefix.  The BOZ literal can also be specified by adding a
1473 suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
1474 equivalent.
1475
1476 Furthermore, GNU Fortran allows using BOZ literal constants outside
1477 DATA statements and the four intrinsic functions allowed by Fortran 2003.
1478 In DATA statements, in direct assignments, where the right-hand side
1479 only contains a BOZ literal constant, and for old-style initializers of
1480 the form @code{integer i /o'0173'/}, the constant is transferred
1481 as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
1482 the real part is initialized unless @code{CMPLX} is used.  In all other
1483 cases, the BOZ literal constant is converted to an @code{INTEGER} value with
1484 the largest decimal representation.  This value is then converted
1485 numerically to the type and kind of the variable in question.
1486 (For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
1487 with @code{2.0}.) As different compilers implement the extension
1488 differently, one should be careful when doing bitwise initialization
1489 of non-integer variables.
1490
1491 Note that initializing an @code{INTEGER} variable with a statement such
1492 as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
1493 than the desired result of @math{-1} when @code{i} is a 32-bit integer
1494 on a system that supports 64-bit integers.  The @samp{-fno-range-check}
1495 option can be used as a workaround for legacy code that initializes
1496 integers in this manner.
1497
1498 @node Real array indices
1499 @subsection Real array indices
1500 @cindex array, indices of type real
1501
1502 As an extension, GNU Fortran allows the use of @code{REAL} expressions
1503 or variables as array indices.
1504
1505 @node Unary operators
1506 @subsection Unary operators
1507 @cindex operators, unary
1508
1509 As an extension, GNU Fortran allows unary plus and unary minus operators
1510 to appear as the second operand of binary arithmetic operators without
1511 the need for parenthesis.
1512
1513 @smallexample
1514        X = Y * -Z
1515 @end smallexample
1516
1517 @node Implicitly convert LOGICAL and INTEGER values
1518 @subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1519 @cindex conversion, to integer
1520 @cindex conversion, to logical
1521
1522 As an extension for backwards compatibility with other compilers, GNU
1523 Fortran allows the implicit conversion of @code{LOGICAL} values to
1524 @code{INTEGER} values and vice versa.  When converting from a
1525 @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1526 zero, and @code{.TRUE.} is interpreted as one.  When converting from
1527 @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1528 @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1529
1530 @smallexample
1531         LOGICAL :: l
1532         l = 1
1533 @end smallexample
1534 @smallexample
1535         INTEGER :: i
1536         i = .TRUE.
1537 @end smallexample
1538
1539 However, there is no implicit conversion of @code{INTEGER} values in
1540 @code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
1541 in I/O operations.
1542
1543 @node Hollerith constants support
1544 @subsection Hollerith constants support
1545 @cindex Hollerith constants
1546
1547 GNU Fortran supports Hollerith constants in assignments, function
1548 arguments, and @code{DATA} and @code{ASSIGN} statements.  A Hollerith
1549 constant is written as a string of characters preceded by an integer
1550 constant indicating the character count, and the letter @code{H} or
1551 @code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
1552 @code{REAL}, or @code{complex}) or @code{LOGICAL} variable.  The
1553 constant will be padded or truncated to fit the size of the variable in
1554 which it is stored.
1555
1556 Examples of valid uses of Hollerith constants:
1557 @smallexample
1558       complex*16 x(2)
1559       data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1560       x(1) = 16HABCDEFGHIJKLMNOP
1561       call foo (4h abc)
1562 @end smallexample
1563
1564 Invalid Hollerith constants examples:
1565 @smallexample
1566       integer*4 a
1567       a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1568       a = 0H         ! At least one character is needed.
1569 @end smallexample
1570
1571 In general, Hollerith constants were used to provide a rudimentary
1572 facility for handling character strings in early Fortran compilers,
1573 prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1574 in those cases, the standard-compliant equivalent is to convert the
1575 program to use proper character strings.  On occasion, there may be a
1576 case where the intent is specifically to initialize a numeric variable
1577 with a given byte sequence.  In these cases, the same result can be
1578 obtained by using the @code{TRANSFER} statement, as in this example.
1579 @smallexample
1580       INTEGER(KIND=4) :: a
1581       a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
1582 @end smallexample
1583
1584
1585 @node Cray pointers
1586 @subsection Cray pointers
1587 @cindex pointer, Cray
1588
1589 Cray pointers are part of a non-standard extension that provides a
1590 C-like pointer in Fortran.  This is accomplished through a pair of
1591 variables: an integer "pointer" that holds a memory address, and a
1592 "pointee" that is used to dereference the pointer.
1593
1594 Pointer/pointee pairs are declared in statements of the form:
1595 @smallexample
1596         pointer ( <pointer> , <pointee> )
1597 @end smallexample
1598 or,
1599 @smallexample
1600         pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1601 @end smallexample
1602 The pointer is an integer that is intended to hold a memory address.
1603 The pointee may be an array or scalar.  A pointee can be an assumed
1604 size array---that is, the last dimension may be left unspecified by
1605 using a @code{*} in place of a value---but a pointee cannot be an
1606 assumed shape array.  No space is allocated for the pointee.
1607
1608 The pointee may have its type declared before or after the pointer
1609 statement, and its array specification (if any) may be declared
1610 before, during, or after the pointer statement.  The pointer may be
1611 declared as an integer prior to the pointer statement.  However, some
1612 machines have default integer sizes that are different than the size
1613 of a pointer, and so the following code is not portable:
1614 @smallexample
1615         integer ipt
1616         pointer (ipt, iarr)
1617 @end smallexample
1618 If a pointer is declared with a kind that is too small, the compiler
1619 will issue a warning; the resulting binary will probably not work
1620 correctly, because the memory addresses stored in the pointers may be
1621 truncated.  It is safer to omit the first line of the above example;
1622 if explicit declaration of ipt's type is omitted, then the compiler
1623 will ensure that ipt is an integer variable large enough to hold a
1624 pointer.
1625
1626 Pointer arithmetic is valid with Cray pointers, but it is not the same
1627 as C pointer arithmetic.  Cray pointers are just ordinary integers, so
1628 the user is responsible for determining how many bytes to add to a
1629 pointer in order to increment it.  Consider the following example:
1630 @smallexample
1631         real target(10)
1632         real pointee(10)
1633         pointer (ipt, pointee)
1634         ipt = loc (target)
1635         ipt = ipt + 1       
1636 @end smallexample
1637 The last statement does not set @code{ipt} to the address of
1638 @code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
1639 to @code{ipt} just adds one byte to the address stored in @code{ipt}.
1640
1641 Any expression involving the pointee will be translated to use the
1642 value stored in the pointer as the base address.
1643
1644 To get the address of elements, this extension provides an intrinsic
1645 function @code{LOC()}.  The @code{LOC()} function is equivalent to the
1646 @code{&} operator in C, except the address is cast to an integer type:
1647 @smallexample
1648         real ar(10)
1649         pointer(ipt, arpte(10))
1650         real arpte
1651         ipt = loc(ar)  ! Makes arpte is an alias for ar
1652         arpte(1) = 1.0 ! Sets ar(1) to 1.0
1653 @end smallexample
1654 The pointer can also be set by a call to the @code{MALLOC} intrinsic
1655 (see @ref{MALLOC}).
1656
1657 Cray pointees often are used to alias an existing variable.  For
1658 example:
1659 @smallexample
1660         integer target(10)
1661         integer iarr(10)
1662         pointer (ipt, iarr)
1663         ipt = loc(target)
1664 @end smallexample
1665 As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1666 @code{target}.  The optimizer, however, will not detect this aliasing, so
1667 it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
1668 a pointee in any way that violates the Fortran aliasing rules or
1669 assumptions is illegal.  It is the user's responsibility to avoid doing
1670 this; the compiler works under the assumption that no such aliasing
1671 occurs.
1672
1673 Cray pointers will work correctly when there is no aliasing (i.e., when
1674 they are used to access a dynamically allocated block of memory), and
1675 also in any routine where a pointee is used, but any variable with which
1676 it shares storage is not used.  Code that violates these rules may not
1677 run as the user intends.  This is not a bug in the optimizer; any code
1678 that violates the aliasing rules is illegal.  (Note that this is not
1679 unique to GNU Fortran; any Fortran compiler that supports Cray pointers
1680 will ``incorrectly'' optimize code with illegal aliasing.)
1681
1682 There are a number of restrictions on the attributes that can be applied
1683 to Cray pointers and pointees.  Pointees may not have the
1684 @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
1685 @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes.  Pointers
1686 may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
1687 @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
1688 may they be function results.  Pointees may not occur in more than one
1689 pointer statement.  A pointee cannot be a pointer.  Pointees cannot occur
1690 in equivalence, common, or data statements.
1691
1692 A Cray pointer may also point to a function or a subroutine.  For
1693 example, the following excerpt is valid:
1694 @smallexample
1695   implicit none
1696   external sub
1697   pointer (subptr,subpte)
1698   external subpte
1699   subptr = loc(sub)
1700   call subpte()
1701   [...]
1702   subroutine sub
1703   [...]
1704   end subroutine sub
1705 @end smallexample
1706
1707 A pointer may be modified during the course of a program, and this
1708 will change the location to which the pointee refers.  However, when
1709 pointees are passed as arguments, they are treated as ordinary
1710 variables in the invoked function.  Subsequent changes to the pointer
1711 will not change the base address of the array that was passed.
1712
1713 @node CONVERT specifier
1714 @subsection @code{CONVERT} specifier
1715 @cindex @code{CONVERT} specifier
1716
1717 GNU Fortran allows the conversion of unformatted data between little-
1718 and big-endian representation to facilitate moving of data
1719 between different systems.  The conversion can be indicated with
1720 the @code{CONVERT} specifier on the @code{OPEN} statement.
1721 @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
1722 the data format via an environment variable.
1723
1724 Valid values for @code{CONVERT} are:
1725 @itemize @w{}
1726 @item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
1727 @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
1728 @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
1729 for unformatted files.
1730 @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
1731 unformatted files.
1732 @end itemize
1733
1734 Using the option could look like this:
1735 @smallexample
1736   open(file='big.dat',form='unformatted',access='sequential', &
1737        convert='big_endian')
1738 @end smallexample
1739
1740 The value of the conversion can be queried by using
1741 @code{INQUIRE(CONVERT=ch)}.  The values returned are
1742 @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
1743
1744 @code{CONVERT} works between big- and little-endian for
1745 @code{INTEGER} values of all supported kinds and for @code{REAL}
1746 on IEEE systems of kinds 4 and 8.  Conversion between different
1747 ``extended double'' types on different architectures such as
1748 m68k and x86_64, which GNU Fortran
1749 supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
1750 probably not work.
1751
1752 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
1753 environment variable will override the CONVERT specifier in the
1754 open statement}.  This is to give control over data formats to
1755 users who do not have the source code of their program available.
1756
1757 Using anything but the native representation for unformatted data
1758 carries a significant speed overhead.  If speed in this area matters
1759 to you, it is best if you use this only for data that needs to be
1760 portable.
1761
1762 @node OpenMP
1763 @subsection OpenMP
1764 @cindex OpenMP
1765
1766 OpenMP (Open Multi-Processing) is an application programming
1767 interface (API) that supports multi-platform shared memory 
1768 multiprocessing programming in C/C++ and Fortran on many 
1769 architectures, including Unix and Microsoft Windows platforms.
1770 It consists of a set of compiler directives, library routines,
1771 and environment variables that influence run-time behavior.
1772
1773 GNU Fortran strives to be compatible to the 
1774 @uref{http://www.openmp.org/mp-documents/spec31.pdf,
1775 OpenMP Application Program Interface v3.1}.
1776
1777 To enable the processing of the OpenMP directive @code{!$omp} in
1778 free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
1779 directives in fixed form; the @code{!$} conditional compilation sentinels
1780 in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
1781 in fixed form, @command{gfortran} needs to be invoked with the
1782 @option{-fopenmp}.  This also arranges for automatic linking of the
1783 GNU OpenMP runtime library @ref{Top,,libgomp,libgomp,GNU OpenMP
1784 runtime library}.
1785
1786 The OpenMP Fortran runtime library routines are provided both in a
1787 form of a Fortran 90 module named @code{omp_lib} and in a form of
1788 a Fortran @code{include} file named @file{omp_lib.h}.
1789
1790 An example of a parallelized loop taken from Appendix A.1 of
1791 the OpenMP Application Program Interface v2.5:
1792 @smallexample
1793 SUBROUTINE A1(N, A, B)
1794   INTEGER I, N
1795   REAL B(N), A(N)
1796 !$OMP PARALLEL DO !I is private by default
1797   DO I=2,N
1798     B(I) = (A(I) + A(I-1)) / 2.0
1799   ENDDO
1800 !$OMP END PARALLEL DO
1801 END SUBROUTINE A1
1802 @end smallexample
1803
1804 Please note:
1805 @itemize
1806 @item
1807 @option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
1808 will be allocated on the stack.  When porting existing code to OpenMP,
1809 this may lead to surprising results, especially to segmentation faults
1810 if the stacksize is limited.
1811
1812 @item
1813 On glibc-based systems, OpenMP enabled applications cannot be statically
1814 linked due to limitations of the underlying pthreads-implementation.  It
1815 might be possible to get a working solution if 
1816 @command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
1817 to the command line.  However, this is not supported by @command{gcc} and
1818 thus not recommended.
1819 @end itemize
1820
1821 @node Argument list functions
1822 @subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
1823 @cindex argument list functions
1824 @cindex @code{%VAL}
1825 @cindex @code{%REF}
1826 @cindex @code{%LOC}
1827
1828 GNU Fortran supports argument list functions @code{%VAL}, @code{%REF} 
1829 and @code{%LOC} statements, for backward compatibility with g77. 
1830 It is recommended that these should be used only for code that is 
1831 accessing facilities outside of GNU Fortran, such as operating system 
1832 or windowing facilities.  It is best to constrain such uses to isolated 
1833 portions of a program--portions that deal specifically and exclusively 
1834 with low-level, system-dependent facilities.  Such portions might well 
1835 provide a portable interface for use by the program as a whole, but are 
1836 themselves not portable, and should be thoroughly tested each time they 
1837 are rebuilt using a new compiler or version of a compiler.
1838
1839 @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by 
1840 reference and @code{%LOC} passes its memory location.  Since gfortran 
1841 already passes scalar arguments by reference, @code{%REF} is in effect 
1842 a do-nothing.  @code{%LOC} has the same effect as a Fortran pointer.
1843
1844 An example of passing an argument by value to a C subroutine foo.:
1845 @smallexample
1846 C
1847 C prototype      void foo_ (float x);
1848 C
1849       external foo
1850       real*4 x
1851       x = 3.14159
1852       call foo (%VAL (x))
1853       end
1854 @end smallexample
1855
1856 For details refer to the g77 manual
1857 @uref{http://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
1858
1859 Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
1860 GNU Fortran testsuite are worth a look.
1861
1862
1863 @node Extensions not implemented in GNU Fortran
1864 @section Extensions not implemented in GNU Fortran
1865 @cindex extensions, not implemented
1866
1867 The long history of the Fortran language, its wide use and broad
1868 userbase, the large number of different compiler vendors and the lack of
1869 some features crucial to users in the first standards have lead to the
1870 existence of a number of important extensions to the language.  While
1871 some of the most useful or popular extensions are supported by the GNU
1872 Fortran compiler, not all existing extensions are supported.  This section
1873 aims at listing these extensions and offering advice on how best make
1874 code that uses them running with the GNU Fortran compiler.
1875
1876 @c More can be found here:
1877 @c   -- http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
1878 @c   -- the list of Fortran and libgfortran bugs closed as WONTFIX:
1879 @c      http://tinyurl.com/2u4h5y
1880
1881 @menu
1882 * STRUCTURE and RECORD::
1883 @c * UNION and MAP::
1884 * ENCODE and DECODE statements::
1885 * Variable FORMAT expressions::
1886 @c * Q edit descriptor::
1887 @c * AUTOMATIC statement::
1888 @c * TYPE and ACCEPT I/O Statements::
1889 @c * .XOR. operator::
1890 @c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
1891 @c * Omitted arguments in procedure call::
1892 * Alternate complex function syntax::
1893 @end menu
1894
1895
1896 @node STRUCTURE and RECORD
1897 @subsection @code{STRUCTURE} and @code{RECORD}
1898 @cindex @code{STRUCTURE}
1899 @cindex @code{RECORD}
1900
1901 Structures are user-defined aggregate data types; this functionality was
1902 standardized in Fortran 90 with an different syntax, under the name of
1903 ``derived types''.  Here is an example of code using the non portable
1904 structure syntax:
1905
1906 @example
1907 ! Declaring a structure named ``item'' and containing three fields:
1908 ! an integer ID, an description string and a floating-point price.
1909 STRUCTURE /item/
1910   INTEGER id
1911   CHARACTER(LEN=200) description
1912   REAL price
1913 END STRUCTURE
1914
1915 ! Define two variables, an single record of type ``item''
1916 ! named ``pear'', and an array of items named ``store_catalog''
1917 RECORD /item/ pear, store_catalog(100)
1918
1919 ! We can directly access the fields of both variables
1920 pear.id = 92316
1921 pear.description = "juicy D'Anjou pear"
1922 pear.price = 0.15
1923 store_catalog(7).id = 7831
1924 store_catalog(7).description = "milk bottle"
1925 store_catalog(7).price = 1.2
1926
1927 ! We can also manipulate the whole structure
1928 store_catalog(12) = pear
1929 print *, store_catalog(12)
1930 @end example
1931
1932 @noindent
1933 This code can easily be rewritten in the Fortran 90 syntax as following:
1934
1935 @example
1936 ! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
1937 ! ``TYPE name ... END TYPE''
1938 TYPE item
1939   INTEGER id
1940   CHARACTER(LEN=200) description
1941   REAL price
1942 END TYPE
1943
1944 ! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
1945 TYPE(item) pear, store_catalog(100)
1946
1947 ! Instead of using a dot (.) to access fields of a record, the
1948 ! standard syntax uses a percent sign (%)
1949 pear%id = 92316
1950 pear%description = "juicy D'Anjou pear"
1951 pear%price = 0.15
1952 store_catalog(7)%id = 7831
1953 store_catalog(7)%description = "milk bottle"
1954 store_catalog(7)%price = 1.2
1955
1956 ! Assignments of a whole variable do not change
1957 store_catalog(12) = pear
1958 print *, store_catalog(12)
1959 @end example
1960
1961
1962 @c @node UNION and MAP
1963 @c @subsection @code{UNION} and @code{MAP}
1964 @c @cindex @code{UNION}
1965 @c @cindex @code{MAP}
1966 @c
1967 @c For help writing this one, see
1968 @c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
1969 @c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm
1970
1971
1972 @node ENCODE and DECODE statements
1973 @subsection @code{ENCODE} and @code{DECODE} statements
1974 @cindex @code{ENCODE}
1975 @cindex @code{DECODE}
1976
1977 GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
1978 statements.  These statements are best replaced by @code{READ} and
1979 @code{WRITE} statements involving internal files (@code{CHARACTER}
1980 variables and arrays), which have been part of the Fortran standard since
1981 Fortran 77.  For example, replace a code fragment like
1982
1983 @smallexample
1984       INTEGER*1 LINE(80)
1985       REAL A, B, C
1986 c     ... Code that sets LINE
1987       DECODE (80, 9000, LINE) A, B, C
1988  9000 FORMAT (1X, 3(F10.5))
1989 @end smallexample
1990
1991 @noindent
1992 with the following:
1993
1994 @smallexample
1995       CHARACTER(LEN=80) LINE
1996       REAL A, B, C
1997 c     ... Code that sets LINE
1998       READ (UNIT=LINE, FMT=9000) A, B, C
1999  9000 FORMAT (1X, 3(F10.5))
2000 @end smallexample
2001
2002 Similarly, replace a code fragment like
2003
2004 @smallexample
2005       INTEGER*1 LINE(80)
2006       REAL A, B, C
2007 c     ... Code that sets A, B and C
2008       ENCODE (80, 9000, LINE) A, B, C
2009  9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2010 @end smallexample
2011
2012 @noindent
2013 with the following:
2014
2015 @smallexample
2016       CHARACTER(LEN=80) LINE
2017       REAL A, B, C
2018 c     ... Code that sets A, B and C
2019       WRITE (UNIT=LINE, FMT=9000) A, B, C
2020  9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2021 @end smallexample
2022
2023
2024 @node Variable FORMAT expressions
2025 @subsection Variable @code{FORMAT} expressions
2026 @cindex @code{FORMAT}
2027
2028 A variable @code{FORMAT} expression is format statement which includes
2029 angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}.  GNU
2030 Fortran does not support this legacy extension.  The effect of variable
2031 format expressions can be reproduced by using the more powerful (and
2032 standard) combination of internal output and string formats.  For example,
2033 replace a code fragment like this:
2034
2035 @smallexample
2036       WRITE(6,20) INT1
2037  20   FORMAT(I<N+1>)
2038 @end smallexample
2039
2040 @noindent
2041 with the following:
2042
2043 @smallexample
2044 c     Variable declaration
2045       CHARACTER(LEN=20) FMT
2046 c     
2047 c     Other code here...
2048 c
2049       WRITE(FMT,'("(I", I0, ")")') N+1
2050       WRITE(6,FMT) INT1
2051 @end smallexample
2052
2053 @noindent
2054 or with:
2055
2056 @smallexample
2057 c     Variable declaration
2058       CHARACTER(LEN=20) FMT
2059 c     
2060 c     Other code here...
2061 c
2062       WRITE(FMT,*) N+1
2063       WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
2064 @end smallexample
2065
2066
2067 @node Alternate complex function syntax
2068 @subsection Alternate complex function syntax
2069 @cindex Complex function
2070
2071 Some Fortran compilers, including @command{g77}, let the user declare
2072 complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
2073 well as @code{COMPLEX*16 FUNCTION name()}.  Both are non-standard, legacy
2074 extensions.  @command{gfortran} accepts the latter form, which is more
2075 common, but not the former.
2076
2077
2078
2079 @c ---------------------------------------------------------------------
2080 @c Mixed-Language Programming
2081 @c ---------------------------------------------------------------------
2082
2083 @node Mixed-Language Programming
2084 @chapter Mixed-Language Programming
2085 @cindex Interoperability
2086 @cindex Mixed-language programming
2087
2088 @menu
2089 * Interoperability with C::
2090 * GNU Fortran Compiler Directives::
2091 * Non-Fortran Main Program::
2092 @end menu
2093
2094 This chapter is about mixed-language interoperability, but also applies
2095 if one links Fortran code compiled by different compilers.  In most cases,
2096 use of the C Binding features of the Fortran 2003 standard is sufficient,
2097 and their use is highly recommended.
2098
2099
2100 @node Interoperability with C
2101 @section Interoperability with C
2102
2103 @menu
2104 * Intrinsic Types::
2105 * Derived Types and struct::
2106 * Interoperable Global Variables::
2107 * Interoperable Subroutines and Functions::
2108 * Working with Pointers::
2109 * Further Interoperability of Fortran with C::
2110 @end menu
2111
2112 Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
2113 standardized way to generate procedure and derived-type
2114 declarations and global variables which are interoperable with C
2115 (ISO/IEC 9899:1999).  The @code{bind(C)} attribute has been added
2116 to inform the compiler that a symbol shall be interoperable with C;
2117 also, some constraints are added.  Note, however, that not
2118 all C features have a Fortran equivalent or vice versa.  For instance,
2119 neither C's unsigned integers nor C's functions with variable number
2120 of arguments have an equivalent in Fortran.
2121
2122 Note that array dimensions are reversely ordered in C and that arrays in
2123 C always start with index 0 while in Fortran they start by default with
2124 1.  Thus, an array declaration @code{A(n,m)} in Fortran matches
2125 @code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
2126 @code{A[j-1][i-1]}.  The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
2127 assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
2128
2129 @node Intrinsic Types
2130 @subsection Intrinsic Types
2131
2132 In order to ensure that exactly the same variable type and kind is used
2133 in C and Fortran, the named constants shall be used which are defined in the
2134 @code{ISO_C_BINDING} intrinsic module.  That module contains named constants
2135 for kind parameters and character named constants for the escape sequences
2136 in C.  For a list of the constants, see @ref{ISO_C_BINDING}.
2137
2138 @node Derived Types and struct
2139 @subsection Derived Types and struct
2140
2141 For compatibility of derived types with @code{struct}, one needs to use
2142 the @code{BIND(C)} attribute in the type declaration.  For instance, the
2143 following type declaration
2144
2145 @smallexample
2146  USE ISO_C_BINDING
2147  TYPE, BIND(C) :: myType
2148    INTEGER(C_INT) :: i1, i2
2149    INTEGER(C_SIGNED_CHAR) :: i3
2150    REAL(C_DOUBLE) :: d1
2151    COMPLEX(C_FLOAT_COMPLEX) :: c1
2152    CHARACTER(KIND=C_CHAR) :: str(5)
2153  END TYPE
2154 @end smallexample
2155
2156 matches the following @code{struct} declaration in C
2157
2158 @smallexample
2159  struct @{
2160    int i1, i2;
2161    /* Note: "char" might be signed or unsigned.  */
2162    signed char i3;
2163    double d1;
2164    float _Complex c1;
2165    char str[5];
2166  @} myType;
2167 @end smallexample
2168
2169 Derived types with the C binding attribute shall not have the @code{sequence}
2170 attribute, type parameters, the @code{extends} attribute, nor type-bound
2171 procedures.  Every component must be of interoperable type and kind and may not
2172 have the @code{pointer} or @code{allocatable} attribute.  The names of the
2173 variables are irrelevant for interoperability.
2174
2175 As there exist no direct Fortran equivalents, neither unions nor structs
2176 with bit field or variable-length array members are interoperable.
2177
2178 @node Interoperable Global Variables
2179 @subsection Interoperable Global Variables
2180
2181 Variables can be made accessible from C using the C binding attribute,
2182 optionally together with specifying a binding name.  Those variables
2183 have to be declared in the declaration part of a @code{MODULE},
2184 be of interoperable type, and have neither the @code{pointer} nor
2185 the @code{allocatable} attribute.
2186
2187 @smallexample
2188   MODULE m
2189     USE myType_module
2190     USE ISO_C_BINDING
2191     integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
2192     type(myType), bind(C) :: tp
2193   END MODULE
2194 @end smallexample
2195
2196 Here, @code{_MyProject_flags} is the case-sensitive name of the variable
2197 as seen from C programs while @code{global_flag} is the case-insensitive
2198 name as seen from Fortran.  If no binding name is specified, as for
2199 @var{tp}, the C binding name is the (lowercase) Fortran binding name.
2200 If a binding name is specified, only a single variable may be after the
2201 double colon.  Note of warning: You cannot use a global variable to
2202 access @var{errno} of the C library as the C standard allows it to be
2203 a macro.  Use the @code{IERRNO} intrinsic (GNU extension) instead.
2204
2205 @node Interoperable Subroutines and Functions
2206 @subsection Interoperable Subroutines and Functions
2207
2208 Subroutines and functions have to have the @code{BIND(C)} attribute to
2209 be compatible with C.  The dummy argument declaration is relatively
2210 straightforward.  However, one needs to be careful because C uses
2211 call-by-value by default while Fortran behaves usually similar to
2212 call-by-reference.  Furthermore, strings and pointers are handled
2213 differently.  Note that only explicit size and assumed-size arrays are
2214 supported but not assumed-shape or allocatable arrays.
2215
2216 To pass a variable by value, use the @code{VALUE} attribute.
2217 Thus the following C prototype
2218
2219 @smallexample
2220 @code{int func(int i, int *j)}
2221 @end smallexample
2222
2223 matches the Fortran declaration
2224
2225 @smallexample
2226   integer(c_int) function func(i,j)
2227     use iso_c_binding, only: c_int
2228     integer(c_int), VALUE :: i
2229     integer(c_int) :: j
2230 @end smallexample
2231
2232 Note that pointer arguments also frequently need the @code{VALUE} attribute,
2233 see @ref{Working with Pointers}.
2234
2235 Strings are handled quite differently in C and Fortran.  In C a string
2236 is a @code{NUL}-terminated array of characters while in Fortran each string
2237 has a length associated with it and is thus not terminated (by e.g.
2238 @code{NUL}).  For example, if one wants to use the following C function,
2239
2240 @smallexample
2241   #include <stdio.h>
2242   void print_C(char *string) /* equivalent: char string[]  */
2243   @{
2244      printf("%s\n", string);
2245   @}
2246 @end smallexample
2247
2248 to print ``Hello World'' from Fortran, one can call it using
2249
2250 @smallexample
2251   use iso_c_binding, only: C_CHAR, C_NULL_CHAR
2252   interface
2253     subroutine print_c(string) bind(C, name="print_C")
2254       use iso_c_binding, only: c_char
2255       character(kind=c_char) :: string(*)
2256     end subroutine print_c
2257   end interface
2258   call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
2259 @end smallexample
2260
2261 As the example shows, one needs to ensure that the
2262 string is @code{NUL} terminated.  Additionally, the dummy argument
2263 @var{string} of @code{print_C} is a length-one assumed-size
2264 array; using @code{character(len=*)} is not allowed.  The example
2265 above uses @code{c_char_"Hello World"} to ensure the string
2266 literal has the right type; typically the default character
2267 kind and @code{c_char} are the same and thus @code{"Hello World"}
2268 is equivalent.  However, the standard does not guarantee this.
2269
2270 The use of strings is now further illustrated using the C library
2271 function @code{strncpy}, whose prototype is
2272
2273 @smallexample
2274   char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
2275 @end smallexample
2276
2277 The function @code{strncpy} copies at most @var{n} characters from
2278 string @var{s2} to @var{s1} and returns @var{s1}.  In the following
2279 example, we ignore the return value:
2280
2281 @smallexample
2282   use iso_c_binding
2283   implicit none
2284   character(len=30) :: str,str2
2285   interface
2286     ! Ignore the return value of strncpy -> subroutine
2287     ! "restrict" is always assumed if we do not pass a pointer
2288     subroutine strncpy(dest, src, n) bind(C)
2289       import
2290       character(kind=c_char),  intent(out) :: dest(*)
2291       character(kind=c_char),  intent(in)  :: src(*)
2292       integer(c_size_t), value, intent(in) :: n
2293     end subroutine strncpy
2294   end interface
2295   str = repeat('X',30) ! Initialize whole string with 'X'
2296   call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
2297                len(c_char_"Hello World",kind=c_size_t))
2298   print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
2299   end
2300 @end smallexample
2301
2302 The intrinsic procedures are described in @ref{Intrinsic Procedures}.
2303
2304 @node Working with Pointers
2305 @subsection Working with Pointers
2306
2307 C pointers are represented in Fortran via the special opaque derived type
2308 @code{type(c_ptr)} (with private components).  Thus one needs to
2309 use intrinsic conversion procedures to convert from or to C pointers.
2310 For example,
2311
2312 @smallexample
2313   use iso_c_binding
2314   type(c_ptr) :: cptr1, cptr2
2315   integer, target :: array(7), scalar
2316   integer, pointer :: pa(:), ps
2317   cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
2318                           ! array is contiguous if required by the C
2319                           ! procedure
2320   cptr2 = c_loc(scalar)
2321   call c_f_pointer(cptr2, ps)
2322   call c_f_pointer(cptr2, pa, shape=[7])
2323 @end smallexample
2324
2325 When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
2326 has to be passed.
2327
2328 If a pointer is a dummy-argument of an interoperable procedure, it usually
2329 has to be declared using the @code{VALUE} attribute.  @code{void*}
2330 matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
2331 matches @code{void**}.
2332
2333 Procedure pointers are handled analogously to pointers; the C type is
2334 @code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
2335 @code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
2336
2337 Let us consider two examples of actually passing a procedure pointer from
2338 C to Fortran and vice versa.  Note that these examples are also very
2339 similar to passing ordinary pointers between both languages. First,
2340 consider this code in C:
2341
2342 @smallexample
2343 /* Procedure implemented in Fortran.  */
2344 void get_values (void (*)(double));
2345
2346 /* Call-back routine we want called from Fortran.  */
2347 void
2348 print_it (double x)
2349 @{
2350   printf ("Number is %f.\n", x);
2351 @}
2352
2353 /* Call Fortran routine and pass call-back to it.  */
2354 void
2355 foobar ()
2356 @{
2357   get_values (&print_it);
2358 @}
2359 @end smallexample
2360
2361 A matching implementation for @code{get_values} in Fortran, that correctly
2362 receives the procedure pointer from C and is able to call it, is given
2363 in the following @code{MODULE}:
2364
2365 @smallexample
2366 MODULE m
2367   IMPLICIT NONE
2368
2369   ! Define interface of call-back routine.
2370   ABSTRACT INTERFACE
2371     SUBROUTINE callback (x)
2372       USE, INTRINSIC :: ISO_C_BINDING
2373       REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
2374     END SUBROUTINE callback
2375   END INTERFACE
2376
2377 CONTAINS
2378
2379   ! Define C-bound procedure.
2380   SUBROUTINE get_values (cproc) BIND(C)
2381     USE, INTRINSIC :: ISO_C_BINDING
2382     TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc
2383
2384     PROCEDURE(callback), POINTER :: proc
2385
2386     ! Convert C to Fortran procedure pointer.
2387     CALL C_F_PROCPOINTER (cproc, proc)
2388
2389     ! Call it.
2390     CALL proc (1.0_C_DOUBLE)
2391     CALL proc (-42.0_C_DOUBLE)
2392     CALL proc (18.12_C_DOUBLE)
2393   END SUBROUTINE get_values
2394
2395 END MODULE m
2396 @end smallexample
2397
2398 Next, we want to call a C routine that expects a procedure pointer argument
2399 and pass it a Fortran procedure (which clearly must be interoperable!).
2400 Again, the C function may be:
2401
2402 @smallexample
2403 int
2404 call_it (int (*func)(int), int arg)
2405 @{
2406   return func (arg);
2407 @}
2408 @end smallexample
2409
2410 It can be used as in the following Fortran code:
2411
2412 @smallexample
2413 MODULE m
2414   USE, INTRINSIC :: ISO_C_BINDING
2415   IMPLICIT NONE
2416
2417   ! Define interface of C function.
2418   INTERFACE
2419     INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
2420       USE, INTRINSIC :: ISO_C_BINDING
2421       TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
2422       INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
2423     END FUNCTION call_it
2424   END INTERFACE
2425
2426 CONTAINS
2427
2428   ! Define procedure passed to C function.
2429   ! It must be interoperable!
2430   INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
2431     INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
2432     double_it = arg + arg
2433   END FUNCTION double_it
2434
2435   ! Call C function.
2436   SUBROUTINE foobar ()
2437     TYPE(C_FUNPTR) :: cproc
2438     INTEGER(KIND=C_INT) :: i
2439
2440     ! Get C procedure pointer.
2441     cproc = C_FUNLOC (double_it)
2442
2443     ! Use it.
2444     DO i = 1_C_INT, 10_C_INT
2445       PRINT *, call_it (cproc, i)
2446     END DO
2447   END SUBROUTINE foobar
2448
2449 END MODULE m
2450 @end smallexample
2451
2452 @node Further Interoperability of Fortran with C
2453 @subsection Further Interoperability of Fortran with C
2454
2455 Assumed-shape and allocatable arrays are passed using an array descriptor
2456 (dope vector).  The internal structure of the array descriptor used
2457 by GNU Fortran is not yet documented and will change.  There will also be
2458 a Technical Specification (TS 29113) which standardizes an interoperable
2459 array descriptor.  Until then, you can use the Chasm Language
2460 Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
2461 which provide an interface to GNU Fortran's array descriptor.
2462
2463 GNU Fortran already supports the C-interoperable @code{OPTIONAL}
2464 attribute; for absent arguments, a @code{NULL} pointer is passed.
2465
2466
2467
2468 @node GNU Fortran Compiler Directives
2469 @section GNU Fortran Compiler Directives
2470
2471 The Fortran standard describes how a conforming program shall
2472 behave; however, the exact implementation is not standardized.  In order
2473 to allow the user to choose specific implementation details, compiler
2474 directives can be used to set attributes of variables and procedures
2475 which are not part of the standard.  Whether a given attribute is
2476 supported and its exact effects depend on both the operating system and
2477 on the processor; see
2478 @ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
2479 for details.
2480
2481 For procedures and procedure pointers, the following attributes can
2482 be used to change the calling convention:
2483
2484 @itemize
2485 @item @code{CDECL} -- standard C calling convention
2486 @item @code{STDCALL} -- convention where the called procedure pops the stack
2487 @item @code{FASTCALL} -- part of the arguments are passed via registers
2488 instead using the stack
2489 @end itemize
2490
2491 Besides changing the calling convention, the attributes also influence
2492 the decoration of the symbol name, e.g., by a leading underscore or by
2493 a trailing at-sign followed by the number of bytes on the stack.  When
2494 assigning a procedure to a procedure pointer, both should use the same
2495 calling convention.
2496
2497 On some systems, procedures and global variables (module variables and
2498 @code{COMMON} blocks) need special handling to be accessible when they
2499 are in a shared library.  The following attributes are available:
2500
2501 @itemize
2502 @item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
2503 @item @code{DLLIMPORT} -- reference the function or variable using a global pointer 
2504 @end itemize
2505
2506 The attributes are specified using the syntax
2507
2508 @code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
2509
2510 where in free-form source code only whitespace is allowed before @code{!GCC$}
2511 and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
2512 start in the first column.
2513
2514 For procedures, the compiler directives shall be placed into the body
2515 of the procedure; for variables and procedure pointers, they shall be in
2516 the same declaration part as the variable or procedure pointer.
2517
2518
2519
2520 @node Non-Fortran Main Program
2521 @section Non-Fortran Main Program
2522
2523 @menu
2524 * _gfortran_set_args:: Save command-line arguments
2525 * _gfortran_set_options:: Set library option flags
2526 * _gfortran_set_convert:: Set endian conversion
2527 * _gfortran_set_record_marker:: Set length of record markers
2528 * _gfortran_set_max_subrecord_length:: Set subrecord length
2529 * _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
2530 @end menu
2531
2532 Even if you are doing mixed-language programming, it is very
2533 likely that you do not need to know or use the information in this
2534 section.  Since it is about the internal structure of GNU Fortran,
2535 it may also change in GCC minor releases.
2536
2537 When you compile a @code{PROGRAM} with GNU Fortran, a function
2538 with the name @code{main} (in the symbol table of the object file)
2539 is generated, which initializes the libgfortran library and then
2540 calls the actual program which uses the name @code{MAIN__}, for
2541 historic reasons.  If you link GNU Fortran compiled procedures
2542 to, e.g., a C or C++ program or to a Fortran program compiled by
2543 a different compiler, the libgfortran library is not initialized
2544 and thus a few intrinsic procedures do not work properly, e.g.
2545 those for obtaining the command-line arguments.
2546
2547 Therefore, if your @code{PROGRAM} is not compiled with
2548 GNU Fortran and the GNU Fortran compiled procedures require
2549 intrinsics relying on the library initialization, you need to
2550 initialize the library yourself.  Using the default options,
2551 gfortran calls @code{_gfortran_set_args} and
2552 @code{_gfortran_set_options}.  The initialization of the former
2553 is needed if the called procedures access the command line
2554 (and for backtracing); the latter sets some flags based on the
2555 standard chosen or to enable backtracing.  In typical programs,
2556 it is not necessary to call any initialization function.
2557
2558 If your @code{PROGRAM} is compiled with GNU Fortran, you shall
2559 not call any of the following functions.  The libgfortran
2560 initialization functions are shown in C syntax but using C
2561 bindings they are also accessible from Fortran.
2562
2563
2564 @node _gfortran_set_args
2565 @subsection @code{_gfortran_set_args} --- Save command-line arguments
2566 @fnindex _gfortran_set_args
2567 @cindex libgfortran initialization, set_args
2568
2569 @table @asis
2570 @item @emph{Description}:
2571 @code{_gfortran_set_args} saves the command-line arguments; this
2572 initialization is required if any of the command-line intrinsics
2573 is called.  Additionally, it shall be called if backtracing is
2574 enabled (see @code{_gfortran_set_options}).
2575
2576 @item @emph{Syntax}:
2577 @code{void _gfortran_set_args (int argc, char *argv[])}
2578
2579 @item @emph{Arguments}:
2580 @multitable @columnfractions .15 .70
2581 @item @var{argc} @tab number of command line argument strings
2582 @item @var{argv} @tab the command-line argument strings; argv[0]
2583 is the pathname of the executable itself.
2584 @end multitable
2585
2586 @item @emph{Example}:
2587 @smallexample
2588 int main (int argc, char *argv[])
2589 @{
2590   /* Initialize libgfortran.  */
2591   _gfortran_set_args (argc, argv);
2592   return 0;
2593 @}
2594 @end smallexample
2595 @end table
2596
2597
2598 @node _gfortran_set_options
2599 @subsection @code{_gfortran_set_options} --- Set library option flags
2600 @fnindex _gfortran_set_options
2601 @cindex libgfortran initialization, set_options
2602
2603 @table @asis
2604 @item @emph{Description}:
2605 @code{_gfortran_set_options} sets several flags related to the Fortran
2606 standard to be used, whether backtracing should be enabled
2607 and whether range checks should be performed.  The syntax allows for
2608 upward compatibility since the number of passed flags is specified; for
2609 non-passed flags, the default value is used.  See also
2610 @pxref{Code Gen Options}.  Please note that not all flags are actually
2611 used.
2612
2613 @item @emph{Syntax}:
2614 @code{void _gfortran_set_options (int num, int options[])}
2615
2616 @item @emph{Arguments}:
2617 @multitable @columnfractions .15 .70
2618 @item @var{num} @tab number of options passed
2619 @item @var{argv} @tab The list of flag values
2620 @end multitable
2621
2622 @item @emph{option flag list}:
2623 @multitable @columnfractions .15 .70
2624 @item @var{option}[0] @tab Allowed standard; can give run-time errors
2625 if e.g. an input-output edit descriptor is invalid in a given standard.
2626 Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
2627 @code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
2628 (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
2629 @code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128), 
2630 @code{GFC_STD_F2008_OBS} (256) and GFC_STD_F2008_TS (512). Default:
2631 @code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003
2632 | GFC_STD_F2008 | GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77
2633 | GFC_STD_GNU | GFC_STD_LEGACY}.
2634 @item @var{option}[1] @tab Standard-warning flag; prints a warning to
2635 standard error.  Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
2636 @item @var{option}[2] @tab If non zero, enable pedantic checking.
2637 Default: off.
2638 @item @var{option}[3] @tab Unused.
2639 @item @var{option}[4] @tab If non zero, enable backtracing on run-time
2640 errors.  Default: off.
2641 Note: Installs a signal handler and requires command-line
2642 initialization using @code{_gfortran_set_args}.
2643 @item @var{option}[5] @tab If non zero, supports signed zeros.
2644 Default: enabled.
2645 @item @var{option}[6] @tab Enables run-time checking.  Possible values
2646 are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
2647 GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
2648 Default: disabled.
2649 @item @var{option}[7] @tab If non zero, range checking is enabled.
2650 Default: enabled.  See -frange-check (@pxref{Code Gen Options}).
2651 @end multitable
2652
2653 @item @emph{Example}:
2654 @smallexample
2655   /* Use gfortran 4.7 default options.  */
2656   static int options[] = @{68, 511, 0, 0, 1, 1, 0, 1@};
2657   _gfortran_set_options (8, &options);
2658 @end smallexample
2659 @end table
2660
2661
2662 @node _gfortran_set_convert
2663 @subsection @code{_gfortran_set_convert} --- Set endian conversion
2664 @fnindex _gfortran_set_convert
2665 @cindex libgfortran initialization, set_convert
2666
2667 @table @asis
2668 @item @emph{Description}:
2669 @code{_gfortran_set_convert} set the representation of data for
2670 unformatted files.
2671
2672 @item @emph{Syntax}:
2673 @code{void _gfortran_set_convert (int conv)}
2674
2675 @item @emph{Arguments}:
2676 @multitable @columnfractions .15 .70
2677 @item @var{conv} @tab Endian conversion, possible values:
2678 GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
2679 GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
2680 @end multitable
2681
2682 @item @emph{Example}:
2683 @smallexample
2684 int main (int argc, char *argv[])
2685 @{
2686   /* Initialize libgfortran.  */
2687   _gfortran_set_args (argc, argv);
2688   _gfortran_set_convert (1);
2689   return 0;
2690 @}
2691 @end smallexample
2692 @end table
2693
2694
2695 @node _gfortran_set_record_marker
2696 @subsection @code{_gfortran_set_record_marker} --- Set length of record markers
2697 @fnindex _gfortran_set_record_marker
2698 @cindex libgfortran initialization, set_record_marker
2699
2700 @table @asis
2701 @item @emph{Description}:
2702 @code{_gfortran_set_record_marker} sets the length of record markers
2703 for unformatted files.
2704
2705 @item @emph{Syntax}:
2706 @code{void _gfortran_set_record_marker (int val)}
2707
2708 @item @emph{Arguments}:
2709 @multitable @columnfractions .15 .70
2710 @item @var{val} @tab Length of the record marker; valid values
2711 are 4 and 8.  Default is 4.
2712 @end multitable
2713
2714 @item @emph{Example}:
2715 @smallexample
2716 int main (int argc, char *argv[])
2717 @{
2718   /* Initialize libgfortran.  */
2719   _gfortran_set_args (argc, argv);
2720   _gfortran_set_record_marker (8);
2721   return 0;
2722 @}
2723 @end smallexample
2724 @end table
2725
2726
2727 @node _gfortran_set_fpe
2728 @subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
2729 @fnindex _gfortran_set_fpe
2730 @cindex libgfortran initialization, set_fpe
2731
2732 @table @asis
2733 @item @emph{Description}:
2734 @code{_gfortran_set_fpe} enables floating point exception traps for
2735 the specified exceptions.  On most systems, this will result in a
2736 SIGFPE signal being sent and the program being aborted.
2737
2738 @item @emph{Syntax}:
2739 @code{void _gfortran_set_fpe (int val)}
2740
2741 @item @emph{Arguments}:
2742 @multitable @columnfractions .15 .70
2743 @item @var{option}[0] @tab IEEE exceptions.  Possible values are
2744 (bitwise or-ed) zero (0, default) no trapping,
2745 @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
2746 @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
2747 @code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
2748 @end multitable
2749
2750 @item @emph{Example}:
2751 @smallexample
2752 int main (int argc, char *argv[])
2753 @{
2754   /* Initialize libgfortran.  */
2755   _gfortran_set_args (argc, argv);
2756   /* FPE for invalid operations such as SQRT(-1.0).  */
2757   _gfortran_set_fpe (1);
2758   return 0;
2759 @}
2760 @end smallexample
2761 @end table
2762
2763
2764 @node _gfortran_set_max_subrecord_length
2765 @subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
2766 @fnindex _gfortran_set_max_subrecord_length
2767 @cindex libgfortran initialization, set_max_subrecord_length
2768
2769 @table @asis
2770 @item @emph{Description}:
2771 @code{_gfortran_set_max_subrecord_length} set the maximum length
2772 for a subrecord.  This option only makes sense for testing and
2773 debugging of unformatted I/O.
2774
2775 @item @emph{Syntax}:
2776 @code{void _gfortran_set_max_subrecord_length (int val)}
2777
2778 @item @emph{Arguments}:
2779 @multitable @columnfractions .15 .70
2780 @item @var{val} @tab the maximum length for a subrecord;
2781 the maximum permitted value is 2147483639, which is also
2782 the default.
2783 @end multitable
2784
2785 @item @emph{Example}:
2786 @smallexample
2787 int main (int argc, char *argv[])
2788 @{
2789   /* Initialize libgfortran.  */
2790   _gfortran_set_args (argc, argv);
2791   _gfortran_set_max_subrecord_length (8);
2792   return 0;
2793 @}
2794 @end smallexample
2795 @end table
2796
2797
2798
2799 @c Intrinsic Procedures
2800 @c ---------------------------------------------------------------------
2801
2802 @include intrinsic.texi
2803
2804
2805 @tex
2806 \blankpart
2807 @end tex
2808
2809 @c ---------------------------------------------------------------------
2810 @c Contributing
2811 @c ---------------------------------------------------------------------
2812
2813 @node Contributing
2814 @unnumbered Contributing
2815 @cindex Contributing
2816
2817 Free software is only possible if people contribute to efforts
2818 to create it.
2819 We're always in need of more people helping out with ideas
2820 and comments, writing documentation and contributing code.
2821
2822 If you want to contribute to GNU Fortran,
2823 have a look at the long lists of projects you can take on.
2824 Some of these projects are small,
2825 some of them are large;
2826 some are completely orthogonal to the rest of what is
2827 happening on GNU Fortran,
2828 but others are ``mainstream'' projects in need of enthusiastic hackers.
2829 All of these projects are important!
2830 We will eventually get around to the things here,
2831 but they are also things doable by someone who is willing and able.
2832
2833 @menu
2834 * Contributors::
2835 * Projects::
2836 * Proposed Extensions::
2837 @end menu
2838
2839
2840 @node Contributors
2841 @section Contributors to GNU Fortran
2842 @cindex Contributors
2843 @cindex Credits
2844 @cindex Authors
2845
2846 Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
2847 also the initiator of the whole project.  Thanks Andy!
2848 Most of the interface with GCC was written by @emph{Paul Brook}.
2849
2850 The following individuals have contributed code and/or
2851 ideas and significant help to the GNU Fortran project
2852 (in alphabetical order):
2853
2854 @itemize @minus
2855 @item Janne Blomqvist
2856 @item Steven Bosscher
2857 @item Paul Brook
2858 @item Tobias Burnus
2859 @item Fran@,{c}ois-Xavier Coudert
2860 @item Bud Davis
2861 @item Jerry DeLisle
2862 @item Erik Edelmann
2863 @item Bernhard Fischer
2864 @item Daniel Franke
2865 @item Richard Guenther
2866 @item Richard Henderson
2867 @item Katherine Holcomb
2868 @item Jakub Jelinek
2869 @item Niels Kristian Bech Jensen
2870 @item Steven Johnson
2871 @item Steven G. Kargl
2872 @item Thomas Koenig
2873 @item Asher Langton
2874 @item H. J. Lu
2875 @item Toon Moene
2876 @item Brooks Moses
2877 @item Andrew Pinski
2878 @item Tim Prince
2879 @item Christopher D. Rickett
2880 @item Richard Sandiford
2881 @item Tobias Schl@"uter
2882 @item Roger Sayle
2883 @item Paul Thomas
2884 @item Andy Vaught
2885 @item Feng Wang
2886 @item Janus Weil
2887 @item Daniel Kraft
2888 @end itemize
2889
2890 The following people have contributed bug reports,
2891 smaller or larger patches,
2892 and much needed feedback and encouragement for the
2893 GNU Fortran project: 
2894
2895 @itemize @minus
2896 @item Bill Clodius
2897 @item Dominique d'Humi@`eres
2898 @item Kate Hedstrom
2899 @item Erik Schnetter
2900 @item Joost VandeVondele
2901 @end itemize
2902
2903 Many other individuals have helped debug,
2904 test and improve the GNU Fortran compiler over the past few years,
2905 and we welcome you to do the same!
2906 If you already have done so,
2907 and you would like to see your name listed in the
2908 list above, please contact us.
2909
2910
2911 @node Projects
2912 @section Projects
2913
2914 @table @emph
2915
2916 @item Help build the test suite
2917 Solicit more code for donation to the test suite: the more extensive the
2918 testsuite, the smaller the risk of breaking things in the future! We can
2919 keep code private on request.
2920
2921 @item Bug hunting/squishing
2922 Find bugs and write more test cases! Test cases are especially very
2923 welcome, because it allows us to concentrate on fixing bugs instead of
2924 isolating them.  Going through the bugzilla database at
2925 @url{http://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
2926 add more information (for example, for which version does the testcase
2927 work, for which versions does it fail?) is also very helpful.
2928
2929 @end table
2930
2931
2932 @node Proposed Extensions
2933 @section Proposed Extensions
2934
2935 Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
2936 order.  Most of these are necessary to be fully compatible with
2937 existing Fortran compilers, but they are not part of the official
2938 J3 Fortran 95 standard.
2939
2940 @subsection Compiler extensions: 
2941 @itemize @bullet
2942 @item
2943 User-specified alignment rules for structures.
2944
2945 @item
2946 Automatically extend single precision constants to double.
2947
2948 @item
2949 Compile code that conserves memory by dynamically allocating common and
2950 module storage either on stack or heap.
2951
2952 @item
2953 Compile flag to generate code for array conformance checking (suggest -CC).
2954
2955 @item
2956 User control of symbol names (underscores, etc).
2957
2958 @item
2959 Compile setting for maximum size of stack frame size before spilling
2960 parts to static or heap.
2961
2962 @item
2963 Flag to force local variables into static space.
2964
2965 @item
2966 Flag to force local variables onto stack.
2967 @end itemize
2968
2969
2970 @subsection Environment Options
2971 @itemize @bullet
2972 @item
2973 Pluggable library modules for random numbers, linear algebra.
2974 LA should use BLAS calling conventions.
2975
2976 @item
2977 Environment variables controlling actions on arithmetic exceptions like
2978 overflow, underflow, precision loss---Generate NaN, abort, default.
2979 action.
2980
2981 @item
2982 Set precision for fp units that support it (i387).
2983
2984 @item
2985 Variable for setting fp rounding mode.
2986
2987 @item
2988 Variable to fill uninitialized variables with a user-defined bit
2989 pattern.
2990
2991 @item
2992 Environment variable controlling filename that is opened for that unit
2993 number.
2994
2995 @item
2996 Environment variable to clear/trash memory being freed.
2997
2998 @item
2999 Environment variable to control tracing of allocations and frees.
3000
3001 @item
3002 Environment variable to display allocated memory at normal program end.
3003
3004 @item
3005 Environment variable for filename for * IO-unit.
3006
3007 @item
3008 Environment variable for temporary file directory.
3009
3010 @item
3011 Environment variable forcing standard output to be line buffered (unix).
3012
3013 @end itemize
3014
3015
3016 @c ---------------------------------------------------------------------
3017 @c GNU General Public License
3018 @c ---------------------------------------------------------------------
3019
3020 @include gpl_v3.texi
3021
3022
3023
3024 @c ---------------------------------------------------------------------
3025 @c GNU Free Documentation License
3026 @c ---------------------------------------------------------------------
3027
3028 @include fdl.texi
3029
3030
3031
3032 @c ---------------------------------------------------------------------
3033 @c Funding Free Software
3034 @c ---------------------------------------------------------------------
3035
3036 @include funding.texi
3037
3038 @c ---------------------------------------------------------------------
3039 @c Indices
3040 @c ---------------------------------------------------------------------
3041
3042 @node Option Index
3043 @unnumbered Option Index
3044 @command{gfortran}'s command line options are indexed here without any
3045 initial @samp{-} or @samp{--}.  Where an option has both positive and
3046 negative forms (such as -foption and -fno-option), relevant entries in
3047 the manual are indexed under the most appropriate form; it may sometimes
3048 be useful to look up both forms.
3049 @printindex op
3050
3051 @node Keyword Index
3052 @unnumbered Keyword Index
3053 @printindex cp
3054
3055 @bye