gfortran.texi 109 KB
Newer Older
1
\input texinfo  @c -*-texinfo-*-
2 3
@c %**start of header
@setfilename gfortran.info
4
@set copyrights-gfortran 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
5 6 7

@include gcc-common.texi

8
@settitle The GNU Fortran Compiler
9 10 11 12 13 14 15 16 17 18

@c Create a separate index for command line options
@defcodeindex op
@c Merge the standard indexes into a single one.
@syncodeindex fn cp
@syncodeindex vr cp
@syncodeindex ky cp
@syncodeindex pg cp
@syncodeindex tp cp

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
@c TODO: The following "Part" definitions are included here temporarily
@c until they are incorporated into the official Texinfo distribution.
@c They borrow heavily from Texinfo's \unnchapentry definitions.

@tex
\gdef\part#1#2{%
  \pchapsepmacro
  \gdef\thischapter{}
  \begingroup
    \vglue\titlepagetopglue
    \titlefonts \rm
    \leftline{Part #1:@* #2}
    \vskip4pt \hrule height 4pt width \hsize \vskip4pt
  \endgroup
  \writetocentry{part}{#2}{#1}
}
\gdef\blankpart{%
  \writetocentry{blankpart}{}{}
}
% Part TOC-entry definition for summary contents.
\gdef\dosmallpartentry#1#2#3#4{%
  \vskip .5\baselineskip plus.2\baselineskip
  \begingroup
    \let\rm=\bf \rm
    \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
  \endgroup
}
\gdef\dosmallblankpartentry#1#2#3#4{%
  \vskip .5\baselineskip plus.2\baselineskip
}
% Part TOC-entry definition for regular contents.  This has to be
% equated to an existing entry to not cause problems when the PDF
% outline is created.
\gdef\dopartentry#1#2#3#4{%
  \unnchapentry{Part #2: #1}{}{#3}{#4}
}
\gdef\doblankpartentry#1#2#3#4{}
@end tex

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
@c %**end of header

@c Use with @@smallbook.

@c %** start of document

@c Cause even numbered pages to be printed on the left hand side of
@c the page and odd numbered pages to be printed on the right hand
@c side of the page.  Using this, you can print on both sides of a
@c sheet of paper and have the text on the same part of the sheet.

@c The text on right hand pages is pushed towards the right hand
@c margin and the text on left hand pages is pushed toward the left
@c hand margin.
@c (To provide the reverse effect, set bindingoffset to -0.75in.)

@c @tex
@c \global\bindingoffset=0.75in
@c \global\normaloffset =0.75in
@c @end tex

@copying
Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.

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 86
Invariant Sections being ``Funding Free Software'', the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
(see below).  A copy of the license is included in the section entitled
``GNU Free Documentation License''.

(a) The FSF's Front-Cover Text is:

     A GNU Manual

(b) The FSF's Back-Cover Text is:

     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.
@end copying

@ifinfo
102
@dircategory Software development
103
@direntry
104
* gfortran: (gfortran).                  The GNU Fortran Compiler.
105 106
@end direntry
This file documents the use and the internals of
107
the GNU Fortran compiler, (@command{gfortran}).
108 109

Published by the Free Software Foundation
Kelley Cook committed
110 111
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301 USA
112 113 114 115 116 117 118

@insertcopying
@end ifinfo


@setchapternewpage odd
@titlepage
119
@title Using GNU Fortran
120 121
@versionsubtitle
@author The @t{gfortran} team
122 123
@page
@vskip 0pt plus 1filll
124
Published by the Free Software Foundation@*
Kelley Cook committed
125 126
51 Franklin Street, Fifth Floor@*
Boston, MA 02110-1301, USA@*
127 128 129 130 131 132
@c Last printed ??ber, 19??.@*
@c Printed copies are available for $? each.@*
@c ISBN ???
@sp 1
@insertcopying
@end titlepage
133 134 135 136 137 138 139 140

@c TODO: The following "Part" definitions are included here temporarily
@c until they are incorporated into the official Texinfo distribution.

@tex
\global\let\partentry=\dosmallpartentry
\global\let\blankpartentry=\dosmallblankpartentry
@end tex
141
@summarycontents
142 143 144 145 146

@tex
\global\let\partentry=\dopartentry
\global\let\blankpartentry=\doblankpartentry
@end tex
147
@contents
148

149 150
@page

151 152 153 154 155
@c ---------------------------------------------------------------------
@c TexInfo table of contents.
@c ---------------------------------------------------------------------

@ifnottex
156
@node Top
157 158 159 160
@top Introduction
@cindex Introduction

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 165

@ifset DEVELOPMENT
@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 169
@end ifset

170 171 172 173 174
@comment
@comment  When you add a new menu item, please keep the right hand
@comment  aligned to the same column.  Do not use tabs.  This provides
@comment  better formatting.
@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 187
* Extensions::           Language extensions implemented by GNU Fortran.
* 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 192 193
* Copying::              GNU General Public License says
                         how you can copy and share GNU Fortran.
* 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 197
* Option Index::         Index of command line options
* Keyword Index::        Index of concepts
198
@end menu
199
@end ifnottex
200 201

@c ---------------------------------------------------------------------
202
@c Introduction
203 204
@c ---------------------------------------------------------------------

205 206 207 208 209 210
@node Introduction
@chapter Introduction

@c The following duplicates the text on the TexInfo table of contents.
@iftex
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 213 214 215 216 217 218 219 220
as well as its features and incompatibilities.

@ifset DEVELOPMENT
@emph{Warning:} This document, and the compiler it describes, are still
under development.  While efforts are made to keep it up-to-date, it
might not accurately reflect the status of the most recent GNU Fortran
compiler.
@end ifset
@end iftex
221

222
The GNU Fortran compiler front end was
223 224
designed initially as a free replacement for,
or alternative to, the unix @command{f95} command;
225
@command{gfortran} is the command you will use to invoke the compiler.
226

227 228 229
@menu
* About GNU Fortran::    What you should know about the GNU Fortran compiler.
* GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
230
* Preprocessing and conditional compilation:: The Fortran preprocessor
231 232
* GNU Fortran and G77::  Why we chose to start from scratch.
* Project Status::       Status of GNU Fortran, roadmap, proposed extensions.
233
* Standards::            Standards supported by GNU Fortran.
234 235 236 237 238 239 240 241 242 243
@end menu


@c ---------------------------------------------------------------------
@c About GNU Fortran
@c ---------------------------------------------------------------------

@node About GNU Fortran
@section About GNU Fortran

244 245
The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
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 250 251 252

@itemize @bullet
@item
Read a user's program,
stored in a file and containing instructions written
253
in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
254 255 256 257 258 259 260 261 262 263
This file contains @dfn{source code}.

@item
Translate the user's program into instructions a computer
can carry out more quickly than it takes to translate the
instructions in the first
place.  The result after compilation of a program is
@dfn{machine code},
code designed to be efficiently translated and processed
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 269 270 271

@item
Provide the user with information about the reasons why
the compiler is unable to create a binary from the source code.
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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
mistakes to the user.
An incorrect usage of the language causes an @dfn{error message}.

The compiler will also attempt to diagnose cases where the
user's program contains a correct usage of the language,
but instructs the computer to do something questionable.
This kind of diagnostics message is called a @dfn{warning message}.

@item
Provide optional information about the translation passes
from the source code to machine code.
This can help a user of the compiler to find the cause of
certain bugs which may not be obvious in the source code,
but may be more easily found at a lower level compiler output.
It also helps developers to find bugs in the compiler itself.

@item
Provide information in the generated machine code that can
make it easier to find bugs in the program (using a debugging tool,
called a @dfn{debugger}, such as the GNU Debugger @command{gdb}). 

@item
Locate and gather machine code already generated to
perform actions requested by statements in the user's program.
This machine code is organized into @dfn{modules} and is located
and @dfn{linked} to the user program. 
@end itemize

301
The GNU Fortran compiler consists of several components:
302 303 304 305 306 307 308 309 310

@itemize @bullet
@item
A version of the @command{gcc} command
(which also might be installed as the system's @command{cc} command)
that also understands and accepts Fortran source code.
The @command{gcc} command is the @dfn{driver} program for
all the languages in the GNU Compiler Collection (GCC);
With @command{gcc},
311
you can compile the source code of any language for
312 313 314 315 316 317 318
which a front end is available in GCC.

@item
The @command{gfortran} command itself,
which also might be installed as the
system's @command{f95} command.
@command{gfortran} is just another driver program,
319
but specifically for the Fortran compiler only.
320 321 322 323 324
The difference with @command{gcc} is that @command{gfortran}
will automatically link the correct libraries to your program.

@item
A collection of run-time libraries.
325
These libraries contain the machine code needed to support
326 327 328 329 330 331 332 333 334 335
capabilities of the Fortran language that are not directly
provided by the machine code generated by the
@command{gfortran} compilation phase,
such as intrinsic functions and subroutines,
and routines for interaction with files and the operating system.
@c and mechanisms to spawn,
@c unleash and pause threads in parallelized code.

@item
The Fortran compiler itself, (@command{f951}).
336
This is the GNU Fortran parser and code generator,
337 338 339 340 341 342 343 344 345 346
linked to and interfaced with the GCC backend library.
@command{f951} ``translates'' the source code to
assembler code.  You would typically not use this
program directly;
instead, the @command{gcc} or @command{gfortran} driver
programs will call it for you.
@end itemize


@c ---------------------------------------------------------------------
347
@c GNU Fortran and GCC
348 349
@c ---------------------------------------------------------------------

350
@node GNU Fortran and GCC
351
@section GNU Fortran and GCC
352
@cindex GNU Compiler Collection
353 354 355 356 357 358 359 360 361 362 363 364 365 366
@cindex GCC

GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
consists of a collection of front ends for various languages, which
translate the source code into a language-independent form called
@dfn{GENERIC}.  This is then processed by a common middle end which
provides optimization, and then passed to one of a collection of back
ends which generate code for different computer architectures and
operating systems.

Functionally, this is implemented with a driver program (@command{gcc})
which provides the command-line interface for the compiler.  It calls
the relevant compiler front-end program (e.g., @command{f951} for
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 373 374
driver program is also provided, which is identical to @command{gcc}
except that it automatically links the Fortran runtime libraries into the
compiled program.
375

376 377
Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
@file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
378 379 380
Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
@file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
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 385 386 387 388 389 390
This manual specifically documents the Fortran front end, which handles
the programming language's syntax and semantics.  The aspects of GCC
which relate to the optimization passes and the back-end code generation
are documented in the GCC manual; see 
@ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
The two manuals together provide a complete reference for the GNU
Fortran compiler.
391 392 393


@c ---------------------------------------------------------------------
394 395 396 397 398 399 400 401 402
@c Preprocessing and conditional compilation
@c ---------------------------------------------------------------------

@node Preprocessing and conditional compilation
@section Preprocessing and conditional compilation
@cindex CPP
@cindex FPP
@cindex Conditional compilation
@cindex Preprocessing
403
@cindex preprocessor, include file handling
404

405 406
Many Fortran compilers including GNU Fortran allow passing the source code
through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
407 408
FPP) to allow for conditional compilation.  In the case of GNU Fortran,
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 411
filename extension is @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp},
@file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}.  To manually
412 413 414
invoke the preprocessor on any file, use @option{-cpp}, to disable
preprocessing on files where the preprocessor is run automatically, use
@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 419 420
files, use the equivalent preprocessor statement @code{#include}.

If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
421 422
is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
@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 426 427

While CPP is the de-facto standard for preprocessing Fortran code,
Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
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 435
@c ---------------------------------------------------------------------

436
@node GNU Fortran and G77
437
@section GNU Fortran and G77
438
@cindex Fortran 77
439
@cindex @command{g77}
440

441 442 443 444 445 446
The GNU Fortran compiler is the successor to @command{g77}, the Fortran 
77 front end included in GCC prior to version 4.  It is an entirely new 
program that has been designed to provide Fortran 95 support and 
extensibility for future Fortran language standards, as well as providing 
backwards compatibility for Fortran 77 and nearly all of the GNU language 
extensions supported by @command{g77}.
447 448 449 450 451 452 453


@c ---------------------------------------------------------------------
@c Project Status
@c ---------------------------------------------------------------------

@node Project Status
454
@section Project Status
455 456

@quotation
457
As soon as @command{gfortran} can parse all of the statements correctly,
458 459
it will be in the ``larva'' state.
When we generate code, the ``puppa'' state.
460
When @command{gfortran} is done,
461 462 463 464 465 466 467 468 469
we'll see if it will be a beautiful butterfly,
or just a big bug....

--Andy Vaught, April 2000
@end quotation

The start of the GNU Fortran 95 project was announced on
the GCC homepage in March 18, 2000
(even though Andy had already been working on it for a while,
470
of course).
471

472 473 474 475
The GNU Fortran compiler is able to compile nearly all
standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
including a number of standard and non-standard extensions, and can be
used on real-world programs.  In particular, the supported extensions
476
include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
477 478
2008 features, including TR 15581.  However, it is still under
development and has a few remaining rough edges.
479 480 481 482 483 484 485 486 487 488 489 490 491 492

At present, the GNU Fortran compiler passes the
@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html, 
NIST Fortran 77 Test Suite}, and produces acceptable results on the
@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
It also provides respectable performance on 
the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
compiler benchmarks} and the
@uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
Livermore Fortran Kernels test}.  It has been used to compile a number of
large real-world programs, including
@uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
weather-forecasting code} and
@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 497 498 499 500 501 502 503 504

Among other things, the GNU Fortran compiler is intended as a replacement
for G77.  At this point, nearly all programs that could be compiled with
G77 can be compiled with GNU Fortran, although there are a few minor known
regressions.

The primary work remaining to be done on GNU Fortran falls into three
categories: bug fixing (primarily regarding the treatment of invalid code
and providing useful error messages), improving the compiler optimizations
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 509 510
@c ---------------------------------------------------------------------
@c Standards
@c ---------------------------------------------------------------------
511

512
@node Standards
513
@section Standards
514
@cindex Standards
515

516 517 518 519
@menu
* Varying Length Character Strings::
@end menu

520 521 522
The GNU Fortran compiler implements
ISO/IEC 1539:1997 (Fortran 95).  As such, it can also compile essentially all
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 527 528 529 530
1539-1:2004 (Fortran 2003), ISO/IEC 1539-1:2010 (Fortran 2008) and
future Fortran standards.  Partial support of the Fortran 2003 and
Fortran 2008 standard is already provided; the current status of the
support is reported in the @ref{Fortran 2003 status} and
@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 536 537 538 539 540 541

@node Varying Length Character Strings
@subsection Varying Length Character Strings
@cindex Varying length character strings
@cindex Varying length strings
@cindex strings, varying length

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 546 547 548
@uref{http://www.fortran.com/@/iso_varying_string.f95} and at
@uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.


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 559 560
@c ---------------------------------------------------------------------
@c Compiler Options
@c ---------------------------------------------------------------------
561

562
@include invoke.texi
563

564 565 566 567 568

@c ---------------------------------------------------------------------
@c Runtime
@c ---------------------------------------------------------------------

569 570
@node Runtime
@chapter Runtime:  Influencing runtime behavior with environment variables
571
@cindex environment variable
572

Kazu Hirata committed
573
The behavior of the @command{gfortran} can be influenced by
574
environment variables.
575 576 577

Malformed environment variables are silently ignored.

578
@menu
579
* TMPDIR:: Directory for scratch files
580 581 582
* GFORTRAN_STDIN_UNIT:: Unit number for standard input
* GFORTRAN_STDOUT_UNIT:: Unit number for standard output
* GFORTRAN_STDERR_UNIT:: Unit number for standard error
583 584
* GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units.
* GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
585 586 587 588
* GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
* GFORTRAN_DEFAULT_RECL:: Default record length for new files
* 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 592
@end menu

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
@node TMPDIR
@section @env{TMPDIR}---Directory for scratch files

When opening a file with @code{STATUS='SCRATCH'}, GNU Fortran tries to
create the file in one of the potential directories by testing each
directory in the order below.

@enumerate
@item
The environment variable @env{TMPDIR}, if it exists.

@item
On the MinGW target, the directory returned by the @code{GetTempPath}
function. Alternatively, on the Cygwin target, the @env{TMP} and
@env{TEMP} environment variables, if they exist, in that order.

@item
The @code{P_tmpdir} macro if it is defined, otherwise the directory
@file{/tmp}.
@end enumerate

614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
@node GFORTRAN_STDIN_UNIT
@section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input

This environment variable can be used to select the unit number
preconnected to standard input.  This must be a positive integer.
The default value is 5.

@node GFORTRAN_STDOUT_UNIT
@section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output

This environment variable can be used to select the unit number
preconnected to standard output.  This must be a positive integer.
The default value is 6.

@node GFORTRAN_STDERR_UNIT
@section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error

This environment variable can be used to select the unit number
preconnected to standard error.  This must be a positive integer.
The default value is 0.

@node GFORTRAN_UNBUFFERED_ALL
636
@section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
637

638 639
This environment variable controls whether all I/O is unbuffered.  If
the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
640
unbuffered.  This will slow down small sequential reads and writes.  If
641 642
the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
This is the default.
643

644
@node GFORTRAN_UNBUFFERED_PRECONNECTED
645
@section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
646 647

The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
648
whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered.  If 
649
the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered.  This
650 651 652
will slow down small sequential reads and writes.  If the first letter
is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.  This is the default.

653 654 655 656 657
@node GFORTRAN_SHOW_LOCUS
@section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors

If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
line numbers for runtime errors are printed.  If the first letter is
658
@samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
659
for runtime errors.  The default is to print the location.
660 661 662 663 664 665

@node GFORTRAN_OPTIONAL_PLUS
@section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted

If the first letter is @samp{y}, @samp{Y} or @samp{1},
a plus sign is printed
Kazu Hirata committed
666
where permitted by the Fortran standard.  If the first letter
667
is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
668
in most cases.  Default is not to print plus signs.
669 670 671 672

@node GFORTRAN_DEFAULT_RECL
@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files

673 674 675 676
This environment variable specifies the default record length, in
bytes, for files which are opened without a @code{RECL} tag in the
@code{OPEN} statement.  This must be a positive integer.  The
default value is 1073741824 bytes (1 GB).
677 678 679 680 681 682 683 684 685 686 687

@node GFORTRAN_LIST_SEPARATOR
@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output

This environment variable specifies the separator when writing
list-directed output.  It may contain any number of spaces and
at most one comma.  If you specify this on the command line,
be sure to quote spaces, as in
@smallexample
$ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
@end smallexample
688
when @command{a.out} is the compiled Fortran program that you want to run.
689 690
Default is a single space.

691
@node GFORTRAN_CONVERT_UNIT
692
@section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
693

694
By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
695
to change the representation of data for unformatted files.
696
The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
697
@smallexample
698
GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
exception: mode ':' unit_list | unit_list ;
unit_list: unit_spec | unit_list unit_spec ;
unit_spec: INTEGER | INTEGER '-' INTEGER ;
@end smallexample
The variable consists of an optional default mode, followed by
a list of optional exceptions, which are separated by semicolons
from the preceding default and each other.  Each exception consists
of a format and a comma-separated list of units.  Valid values for
the modes are the same as for the @code{CONVERT} specifier:

@itemize @w{}
@item @code{NATIVE} Use the native format.  This is the default.
@item @code{SWAP} Swap between little- and big-endian.
@item @code{LITTLE_ENDIAN} Use the little-endian format
714
for unformatted files.
715 716 717
@item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
@end itemize
A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
718
Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
719 720 721 722 723 724
@itemize @w{}
@item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
@item @code{'little_endian;native:10-20,25'}  Do all unformatted I/O 
in little_endian mode, except for units 10 to 20 and 25, which are in
native format.
@item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
725 726
@end itemize

727
Setting the environment variables should be done on the command
728 729 730
line or via the @command{export}
command for @command{sh}-compatible shells and via @command{setenv}
for @command{csh}-compatible shells.
731

732
Example for @command{sh}:
733 734 735 736 737
@smallexample
$ gfortran foo.f90
$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
@end smallexample

738
Example code for @command{csh}:
739 740 741 742 743 744 745 746 747 748 749 750 751 752
@smallexample
% gfortran foo.f90
% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
% ./a.out
@end smallexample

Using anything but the native representation for unformatted data
carries a significant speed overhead.  If speed in this area matters
to you, it is best if you use this only for data that needs to be
portable.

@xref{CONVERT specifier}, for an alternative way to specify the
data representation for unformatted files.  @xref{Runtime Options}, for
setting a default data representation for the whole program.  The
753
@code{CONVERT} specifier overrides the @option{-fconvert} compile options.
754

755 756 757 758 759
@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
environment variable will override the CONVERT specifier in the
open statement}.  This is to give control over data formats to
users who do not have the source code of their program available.

760 761 762
@node GFORTRAN_ERROR_BACKTRACE
@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors

763 764 765 766 767 768
If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
@samp{Y} or @samp{1} (only the first letter is relevant) then a
backtrace is printed when a serious run-time error occurs.  To disable
the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
Default is to print a backtrace unless the @option{-fno-backtrace}
compile option was used.
769 770

@c =====================================================================
771
@c PART II: LANGUAGE REFERENCE
772 773 774
@c =====================================================================

@tex
775
\part{II}{Language Reference}
776 777 778
@end tex

@c ---------------------------------------------------------------------
779
@c Fortran 2003 and 2008 Status
780 781
@c ---------------------------------------------------------------------

782 783 784 785 786 787
@node Fortran 2003 and 2008 status
@chapter Fortran 2003 and 2008 Status

@menu
* Fortran 2003 status::
* Fortran 2008 status::
788
* TS 29113 status::
789 790
@end menu

791
@node Fortran 2003 status
792
@section Fortran 2003 status
793

794
GNU Fortran supports several Fortran 2003 features; an incomplete
795 796
list can be found below.  See also the
@uref{http://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
797 798

@itemize
799 800
@item Procedure pointers including procedure-pointer components with
@code{PASS} attribute.
801

802 803 804 805
@item Procedures which are bound to a derived type (type-bound procedures)
including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and
operators bound to a type.

Mike Stump committed
806
@item Abstract interfaces and type extension with the possibility to
807 808 809 810
override type-bound procedures or to have deferred binding.

@item Polymorphic entities (``@code{CLASS}'') for derived types -- including
@code{SAME_TYPE_AS}, @code{EXTENDS_TYPE_OF} and @code{SELECT TYPE}.
811
Note that unlimited polymorphism is currently not supported.
812

813
@item Generic interface names, which have the same name as derived types,
814 815 816 817
are now supported. This allows one to write constructor functions.  Note
that Fortran does not support static constructor functions.  For static
variables, only default initialization or structure-constructor
initialization are available.
818 819 820 821 822 823 824 825 826 827 828 829 830

@item The @code{ASSOCIATE} construct.

@item Interoperability with C including enumerations, 

@item In structure constructors the components with default values may be
omitted.

@item Extensions to the @code{ALLOCATE} statement, allowing for a
type-specification with type parameter and for allocation and initialization
from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE}
optionally return an error message string via @code{ERRMSG=}.

831
@item Reallocation on assignment: If an intrinsic assignment is
832
used, an allocatable variable on the left-hand side is automatically allocated
833 834 835
(if unallocated) or reallocated (if the shape is different). Currently, scalar
deferred character length left-hand sides are correctly handled but arrays
are not yet fully implemented.
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850

@item Transferring of allocations via @code{MOVE_ALLOC}.

@item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually
to derived-type components.

@item In pointer assignments, the lower bound may be specified and
the remapping of elements is supported.

@item For pointers an @code{INTENT} may be specified which affect the
association status not the value of the pointer target.

@item Intrinsics @code{command_argument_count}, @code{get_command},
@code{get_command_argument}, and @code{get_environment_variable}.

851
@item Support for Unicode characters (ISO 10646) and UTF-8, including
852 853 854 855 856
the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions.

@item Support for binary, octal and hexadecimal (BOZ) constants in the
intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}.

857 858 859
@item Support for namelist variables with allocatable and pointer
attribute and nonconstant length type parameter.

860
@item
861
@cindex array, constructors
862
@cindex @code{[...]}
863
Array constructors using square brackets.  That is, @code{[...]} rather
864 865
than @code{(/.../)}.  Type-specification for array constructors like
@code{(/ some-type :: ... /)}.
866

867 868 869 870 871 872
@item Extensions to the specification and initialization expressions,
including the support for intrinsics with real and complex arguments.

@item Support for the asynchronous input/output syntax; however, the
data transfer is currently always synchronously performed. 

873 874
@item
@cindex @code{FLUSH} statement
875
@cindex statement, @code{FLUSH}
876 877 878 879 880 881 882 883 884
@code{FLUSH} statement.

@item
@cindex @code{IOMSG=} specifier
@code{IOMSG=} specifier for I/O statements.

@item
@cindex @code{ENUM} statement
@cindex @code{ENUMERATOR} statement
885 886
@cindex statement, @code{ENUM}
@cindex statement, @code{ENUMERATOR}
887
@opindex @code{fshort-enums}
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
Support for the declaration of enumeration constants via the
@code{ENUM} and @code{ENUMERATOR} statements.  Interoperability with
@command{gcc} is guaranteed also for the case where the
@command{-fshort-enums} command line option is given.

@item
@cindex TR 15581
TR 15581:
@itemize
@item
@cindex @code{ALLOCATABLE} dummy arguments
@code{ALLOCATABLE} dummy arguments.
@item
@cindex @code{ALLOCATABLE} function results
@code{ALLOCATABLE} function results
@item
@cindex @code{ALLOCATABLE} components of derived types
@code{ALLOCATABLE} components of derived types
@end itemize

@item
@cindex @code{STREAM} I/O
@cindex @code{ACCESS='STREAM'} I/O
The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
allowing I/O without any record structure.

@item
Namelist input/output for internal files.

917 918 919 920
@item Further I/O extensions: Rounding during formatted output, using of
a decimal comma instead of a decimal point, setting whether a plus sign
should appear for positive numbers.

921
@item
922 923
@cindex @code{PROTECTED} statement
@cindex statement, @code{PROTECTED}
924 925 926
The @code{PROTECTED} statement and attribute.

@item
927 928
@cindex @code{VALUE} statement
@cindex statement, @code{VALUE}
929 930 931
The @code{VALUE} statement and attribute.

@item
932 933
@cindex @code{VOLATILE} statement
@cindex statement, @code{VOLATILE}
934 935 936
The @code{VOLATILE} statement and attribute.

@item
937 938
@cindex @code{IMPORT} statement
@cindex statement, @code{IMPORT}
939 940 941
The @code{IMPORT} statement, allowing to import
host-associated derived types.

942 943 944 945 946
@item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported,
which contains parameters of the I/O units, storage sizes. Additionally,
procedures for C interoperability are available in the @code{ISO_C_BINDING}
module.

947
@item
948 949 950 951
@cindex @code{USE, INTRINSIC} statement
@cindex statement, @code{USE, INTRINSIC}
@cindex @code{ISO_FORTRAN_ENV} statement
@cindex statement, @code{ISO_FORTRAN_ENV}
952 953
@code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
954
@code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS}.
955

Tobias Burnus committed
956 957 958
@item
Renaming of operators in the @code{USE} statement.

959 960 961
@end itemize


962 963 964
@node Fortran 2008 status
@section Fortran 2008 status

965 966 967 968 969 970 971 972 973 974
The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally
known as Fortran 2008.  The official version is available from International
Organization for Standardization (ISO) or its national member organizations.
The the final draft (FDIS) can be downloaded free of charge from
@url{http://www.nag.co.uk/@/sc22wg5/@/links.html}.  Fortran is developed by the
Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the
International Organization for Standardization and the International
Electrotechnical Commission (IEC).  This group is known as
@uref{http://www.nag.co.uk/sc22wg5/, WG5}.

975 976
The GNU Fortran compiler supports several of the new features of Fortran 2008;
the @uref{http://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
about the current Fortran 2008 implementation status.  In particular, the
following is implemented.

@itemize
@item The @option{-std=f2008} option and support for the file extensions 
@file{.f08} and @file{.F08}.

@item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
which returns a unique file unit, thus preventing inadvertent use of the
same unit in different parts of the program.

@item The @code{g0} format descriptor and unlimited format items.

@item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH},
@code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0},
@code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1},
@code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}.

@item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH},
@code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible;
@code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}).

@item Support of the @code{PARITY} intrinsic functions.

@item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for
counting the number of leading and trailing zero bits, @code{POPCNT} and
@code{POPPAR} for counting the number of one bits and returning the parity;
@code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons;
@code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts,
@code{MASKL} and @code{MASKR} for simple left and right justified masks,
@code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA},
@code{SHIFTL} and @code{SHIFTR} for shift operations, and the
transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}.

@item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine.

@item Support for the @code{STORAGE_SIZE} intrinsic inquiry function.

@item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type
1016 1017 1018 1019 1020 1021 1022
parameters and the array-valued named constants @code{INTEGER_KINDS},
@code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of
the intrinsic module @code{ISO_FORTRAN_ENV}.

@item The module procedures @code{C_SIZEOF} of the intrinsic module
@code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS}
of @code{ISO_FORTRAN_ENV}.
1023

1024 1025 1026 1027 1028
@item Coarray support for serial programs with @option{-fcoarray=single} flag
and experimental support for multiple images with the @option{-fcoarray=lib}
flag.

@item The @code{DO CONCURRENT} construct is supported.
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069

@item The @code{BLOCK} construct is supported.

@item The @code{STOP} and the new @code{ERROR STOP} statements now
support all constant expressions.

@item Support for the @code{CONTIGUOUS} attribute.

@item Support for @code{ALLOCATE} with @code{MOLD}.

@item Support for the @code{IMPURE} attribute for procedures, which
allows for @code{ELEMENTAL} procedures without the restrictions of
@code{PURE}.

@item Null pointers (including @code{NULL()}) and not-allocated variables
can be used as actual argument to optional non-pointer, non-allocatable
dummy arguments, denoting an absent argument.

@item Non-pointer variables with @code{TARGET} attribute can be used as
actual argument to @code{POINTER} dummies with @code{INTENT(IN)}.

@item Pointers including procedure pointers and those in a derived
type (pointer components) can now be initialized by a target instead
of only by @code{NULL}.

@item The @code{EXIT} statement (with construct-name) can be now be
used to leave not only the @code{DO} but also the @code{ASSOCIATE},
@code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE}
constructs.

@item Internal procedures can now be used as actual argument.

@item Minor features: obsolesce diagnostics for @code{ENTRY} with
@option{-std=f2008}; a line may start with a semicolon; for internal
and module procedures @code{END} can be used instead of
@code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND}
now also takes a @code{RADIX} argument; intrinsic types are supported
for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures
can be declared in a single @code{PROCEDURE} statement; implied-shape
arrays are supported for named constants (@code{PARAMETER}).
@end itemize
1070

1071

1072

1073 1074
@node TS 29113 status
@section Technical Specification 29113 Status
1075

1076 1077 1078 1079
GNU Fortran supports some of the new features of the Technical
Specification (TS) 29113 on Further Interoperability of Fortran with C.
The @uref{http://gcc.gnu.org/wiki/TS29113Status, wiki} has some information
about the current TS 29113 implementation status.  In particular, the
1080 1081 1082
following is implemented.

@itemize
1083 1084 1085 1086 1087 1088 1089 1090 1091
@item The @option{-std=f2008ts} option.

@item The @code{OPTIONAL} attribute is allowed for dummy arguments
of @code{BIND(C) procedures.}

@item The RANK intrinsic is supported.

@item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS}
attribute is compatible with TS 29113.
1092 1093 1094 1095
@end itemize



1096 1097 1098 1099 1100 1101 1102
@c ---------------------------------------------------------------------
@c Compiler Characteristics
@c ---------------------------------------------------------------------

@node Compiler Characteristics
@chapter Compiler Characteristics

1103 1104 1105
This chapter describes certain characteristics of the GNU Fortran
compiler, that are not specified by the Fortran standard, but which
might in some way or another become visible to the programmer.
1106 1107 1108

@menu
* KIND Type Parameters::
1109
* Internal representation of LOGICAL variables::
1110
* Thread-safety of the runtime library::
1111
* Data consistency and durability::
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
@end menu


@node KIND Type Parameters
@section KIND Type Parameters
@cindex kind

The @code{KIND} type parameters supported by GNU Fortran for the primitive
data types are:

@table @code

@item INTEGER
1, 2, 4, 8*, 16*, default: 4 (1)

@item LOGICAL
1, 2, 4, 8*, 16*, default: 4 (1)

@item REAL
1131
4, 8, 10*, 16*, default: 4 (2)
1132 1133

@item COMPLEX
1134
4, 8, 10*, 16*, default: 4 (2)
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149

@item CHARACTER
1, 4, default: 1

@end table

@noindent
* = not available on all systems @*
(1) Unless -fdefault-integer-8 is used @*
(2) Unless -fdefault-real-8 is used

@noindent
The @code{KIND} value matches the storage size in bytes, except for
@code{COMPLEX} where the storage size is twice as much (or both real and
imaginary part are a real value of the given size).  It is recommended to use
1150 1151 1152 1153 1154 1155 1156 1157
the @code{SELECTED_CHAR_KIND}, @code{SELECTED_INT_KIND} and
@code{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
@code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
The available kind parameters can be found in the constant arrays
@code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
@code{REAL_KINDS} in the @code{ISO_FORTRAN_ENV} module
(see @ref{ISO_FORTRAN_ENV}).
1158 1159


1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
@node Internal representation of LOGICAL variables
@section Internal representation of LOGICAL variables
@cindex logical, variable representation

The Fortran standard does not specify how variables of @code{LOGICAL}
type are represented, beyond requiring that @code{LOGICAL} variables
of default kind have the same storage size as default @code{INTEGER}
and @code{REAL} variables.  The GNU Fortran internal representation is
as follows.

A @code{LOGICAL(KIND=N)} variable is represented as an
@code{INTEGER(KIND=N)} variable, however, with only two permissible
values: @code{1} for @code{.TRUE.} and @code{0} for
1173
@code{.FALSE.}.  Any other integer value results in undefined behavior.
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

Note that for mixed-language programming using the
@code{ISO_C_BINDING} feature, there is a @code{C_BOOL} kind that can
be used to create @code{LOGICAL(KIND=C_BOOL)} variables which are
interoperable with the C99 _Bool type.  The C99 _Bool type has an
internal representation described in the C99 standard, which is
identical to the above description, i.e. with 1 for true and 0 for
false being the only permissible values.  Thus the internal
representation of @code{LOGICAL} variables in GNU Fortran is identical
to C99 _Bool, except for a possible difference in storage size
depending on the kind.

1186 1187 1188 1189 1190

@node Thread-safety of the runtime library
@section Thread-safety of the runtime library
@cindex thread-safety, threads

1191
GNU Fortran can be used in programs with multiple threads, e.g.@: by
1192 1193 1194 1195
using OpenMP, by calling OS thread handling functions via the
@code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
being called from a multi-threaded program.

1196
The GNU Fortran runtime library, (@code{libgfortran}), supports being
1197 1198 1199
called concurrently from multiple threads with the following
exceptions. 

1200 1201
During library initialization, the C @code{getenv} function is used,
which need not be thread-safe.  Similarly, the @code{getenv}
1202 1203 1204 1205 1206 1207
function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
@code{GETENV} intrinsics.  It is the responsibility of the user to
ensure that the environment is not being updated concurrently when any
of these actions are taking place.

The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
1208
implemented with the @code{system} function, which need not be
1209
thread-safe.  It is the responsibility of the user to ensure that
1210
@code{system} is not called concurrently.
1211

1212 1213 1214
Finally, for platforms not supporting thread-safe POSIX functions,
further functionality might not be thread-safe.  For details, please
consult the documentation for your operating system.
1215

1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290

@node Data consistency and durability
@section Data consistency and durability
@cindex consistency, durability

This section contains a brief overview of data and metadata
consistency and durability issues when doing I/O.

With respect to durability, GNU Fortran makes no effort to ensure that
data is committed to stable storage. If this is required, the GNU
Fortran programmer can use the intrinsic @code{FNUM} to retrieve the
low level file descriptor corresponding to an open Fortran unit. Then,
using e.g. the @code{ISO_C_BINDING} feature, one can call the
underlying system call to flush dirty data to stable storage, such as
@code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd,
F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call
fsync:

@smallexample
  ! Declare the interface for POSIX fsync function
  interface
    function fsync (fd) bind(c,name="fsync")
    use iso_c_binding, only: c_int
      integer(c_int), value :: fd
      integer(c_int) :: fsync
    end function fsync
  end interface

  ! Variable declaration
  integer :: ret

  ! Opening unit 10
  open (10,file="foo")

  ! ...
  ! Perform I/O on unit 10
  ! ...

  ! Flush and sync
  flush(10)
  ret = fsync(fnum(10))

  ! Handle possible error
  if (ret /= 0) stop "Error calling FSYNC"
@end smallexample

With respect to consistency, for regular files GNU Fortran uses
buffered I/O in order to improve performance. This buffer is flushed
automatically when full and in some other situations, e.g. when
closing a unit. It can also be explicitly flushed with the
@code{FLUSH} statement. Also, the buffering can be turned off with the
@code{GFORTRAN_UNBUFFERED_ALL} and
@code{GFORTRAN_UNBUFFERED_PRECONNECTED} environment variables. Special
files, such as terminals and pipes, are always unbuffered. Sometimes,
however, further things may need to be done in order to allow other
processes to see data that GNU Fortran has written, as follows.

The Windows platform supports a relaxed metadata consistency model,
where file metadata is written to the directory lazily. This means
that, for instance, the @code{dir} command can show a stale size for a
file. One can force a directory metadata update by closing the unit,
or by calling @code{_commit} on the file descriptor. Note, though,
that @code{_commit} will force all dirty data to stable storage, which
is often a very slow operation.

The Network File System (NFS) implements a relaxed consistency model
called open-to-close consistency. Closing a file forces dirty data and
metadata to be flushed to the server, and opening a file forces the
client to contact the server in order to revalidate cached
data. @code{fsync} will also force a flush of dirty data and metadata
to the server. Similar to @code{open} and @code{close}, acquiring and
releasing @code{fcntl} file locks, if the server supports them, will
also force cache validation and flushing dirty data and metadata.


1291 1292 1293 1294 1295 1296 1297 1298 1299
@c ---------------------------------------------------------------------
@c Extensions
@c ---------------------------------------------------------------------

@c Maybe this chapter should be merged with the 'Standards' section,
@c whenever that is written :-)

@node Extensions
@chapter Extensions
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
@cindex extensions

The two sections below detail the extensions to standard Fortran that are
implemented in GNU Fortran, as well as some of the popular or
historically important extensions that are not (or not yet) implemented.
For the latter case, we explain the alternatives available to GNU Fortran
users, including replacement by standard-conforming code or GNU
extensions.

@menu
* Extensions implemented in GNU Fortran::
* Extensions not implemented in GNU Fortran::
@end menu


@node Extensions implemented in GNU Fortran
@section Extensions implemented in GNU Fortran
@cindex extensions, implemented
1318

1319
GNU Fortran implements a number of extensions over standard
1320
Fortran.  This chapter contains information on their syntax and
1321
meaning.  There are currently two categories of GNU Fortran
1322
extensions, those that provide functionality beyond that provided
1323
by any standard, and those that are supported by GNU Fortran
1324 1325 1326
purely for backward compatibility with legacy compilers.  By default,
@option{-std=gnu} allows the compiler to accept both types of
extensions, but to warn about the use of the latter.  Specifying
1327 1328 1329
either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
disables both types of extensions, and @option{-std=legacy} allows both
without warning.
1330 1331 1332 1333

@menu
* Old-style kind specifications::
* Old-style variable initialization::
1334
* Extensions to namelist::
1335
* X format descriptor without count field::
1336
* Commas in FORMAT specifications::
1337
* Missing period in FORMAT specifications::
1338
* I/O item lists::
1339
* BOZ literal constants::
1340
* @code{Q} exponent-letter::
1341 1342
* Real array indices::
* Unary operators::
1343
* Implicitly convert LOGICAL and INTEGER values::
1344
* Hollerith constants support::
Asher Langton committed
1345
* Cray pointers::
1346
* CONVERT specifier::
1347
* OpenMP::
1348
* Argument list functions::
1349
@end menu
1350

1351
@node Old-style kind specifications
1352
@subsection Old-style kind specifications
1353
@cindex kind, old-style
1354

1355
GNU Fortran allows old-style kind specifications in declarations.  These
1356
look like:
1357
@smallexample
1358
      TYPESPEC*size x,y,z
1359
@end smallexample
1360
@noindent
1361
where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
1362 1363 1364 1365 1366 1367
etc.), and where @code{size} is a byte count corresponding to the
storage size of a valid kind for that type.  (For @code{COMPLEX}
variables, @code{size} is the total size of the real and imaginary
parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
be of type @code{TYPESPEC} with the appropriate kind.  This is
equivalent to the standard-conforming declaration
1368 1369 1370
@smallexample
      TYPESPEC(k) x,y,z
@end smallexample
1371
@noindent
1372 1373 1374 1375 1376 1377 1378 1379
where @code{k} is the kind parameter suitable for the intended precision.  As
kind parameters are implementation-dependent, use the @code{KIND},
@code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
the correct value, for instance @code{REAL*8 x} can be replaced by:
@smallexample
INTEGER, PARAMETER :: dbl = KIND(1.0d0)
REAL(KIND=dbl) :: x
@end smallexample
1380 1381

@node Old-style variable initialization
1382
@subsection Old-style variable initialization
1383

1384
GNU Fortran allows old-style initialization of variables of the
1385 1386
form:
@smallexample
1387 1388
      INTEGER i/1/,j/2/
      REAL x(2,2) /3*0.,1./
1389
@end smallexample
1390
The syntax for the initializers is as for the @code{DATA} statement, but
1391
unlike in a @code{DATA} statement, an initializer only applies to the
1392 1393 1394 1395
variable immediately preceding the initialization.  In other words,
something like @code{INTEGER I,J/2,3/} is not valid.  This style of
initialization is only allowed in declarations without double colons
(@code{::}); the double colons were introduced in Fortran 90, which also
Kazu Hirata committed
1396
introduced a standard syntax for initializing variables in type
1397 1398 1399 1400
declarations.

Examples of standard-conforming code equivalent to the above example
are:
1401 1402
@smallexample
! Fortran 90
1403 1404
      INTEGER :: i = 1, j = 2
      REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
1405
! Fortran 77
1406 1407 1408
      INTEGER i, j
      REAL x(2,2)
      DATA i/1/, j/2/, x/3*0.,1./
1409
@end smallexample
1410

1411 1412 1413
Note that variables which are explicitly initialized in declarations
or in @code{DATA} statements automatically acquire the @code{SAVE}
attribute.
1414

1415
@node Extensions to namelist
1416
@subsection Extensions to namelist
1417 1418
@cindex Namelist

1419
GNU Fortran fully supports the Fortran 95 standard for namelist I/O
1420 1421 1422 1423 1424
including array qualifiers, substrings and fully qualified derived types.
The output from a namelist write is compatible with namelist read.  The
output has all names in upper case and indentation to column 1 after the
namelist name.  Two extensions are permitted:

1425
Old-style use of @samp{$} instead of @samp{&}
1426 1427 1428 1429 1430 1431 1432
@smallexample
$MYNML
 X(:)%Y(2) = 1.0 2.0 3.0
 CH(1:4) = "abcd"
$END
@end smallexample

1433 1434
It should be noted that the default terminator is @samp{/} rather than
@samp{&END}.
1435

1436
Querying of the namelist when inputting from stdin.  After at least
1437
one space, entering @samp{?} sends to stdout the namelist name and the names of
1438 1439
the variables in the namelist:
@smallexample
1440
 ?
1441 1442 1443 1444 1445 1446 1447 1448

&mynml
 x
 x%y
 ch
&end
@end smallexample

1449 1450
Entering @samp{=?} outputs the namelist to stdout, as if
@code{WRITE(*,NML = mynml)} had been called:
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
@smallexample
=?

&MYNML
 X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
 X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
 X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
 CH=abcd,  /
@end smallexample

1461
To aid this dialog, when input is from stdin, errors send their
1462
messages to stderr and execution continues, even if @code{IOSTAT} is set.
1463

1464 1465
@code{PRINT} namelist is permitted.  This causes an error if
@option{-std=f95} is used.
1466 1467 1468 1469 1470 1471 1472 1473
@smallexample
PROGRAM test_print
  REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
  NAMELIST /mynml/ x
  PRINT mynml
END PROGRAM test_print
@end smallexample

1474 1475 1476 1477
Expanded namelist reads are permitted.  This causes an error if 
@option{-std=f95} is used.  In the following example, the first element
of the array will be given the value 0.00 and the two succeeding
elements will be given the values 1.00 and 2.00.
1478 1479 1480 1481 1482 1483
@smallexample
&MYNML
  X(1,1) = 0.00 , 1.00 , 2.00
/
@end smallexample

1484
@node X format descriptor without count field
1485
@subsection @code{X} format descriptor without count field
1486

1487 1488 1489
To support legacy codes, GNU Fortran permits the count field of the
@code{X} edit descriptor in @code{FORMAT} statements to be omitted.
When omitted, the count is implicitly assumed to be one.
1490 1491 1492 1493 1494 1495 1496

@smallexample
       PRINT 10, 2, 3
10     FORMAT (I1, X, I1)
@end smallexample

@node Commas in FORMAT specifications
1497
@subsection Commas in @code{FORMAT} specifications
1498

1499
To support legacy codes, GNU Fortran allows the comma separator
1500
to be omitted immediately before and after character string edit
1501
descriptors in @code{FORMAT} statements.
1502 1503 1504 1505 1506 1507

@smallexample
       PRINT 10, 2, 3
10     FORMAT ('FOO='I1' BAR='I2)
@end smallexample

1508 1509

@node Missing period in FORMAT specifications
1510
@subsection Missing period in @code{FORMAT} specifications
1511

1512
To support legacy codes, GNU Fortran allows missing periods in format
1513 1514 1515
specifications if and only if @option{-std=legacy} is given on the
command line.  This is considered non-conforming code and is
discouraged.
1516 1517 1518 1519 1520 1521 1522

@smallexample
       REAL :: value
       READ(*,10) value
10     FORMAT ('F4')
@end smallexample

1523
@node I/O item lists
1524
@subsection I/O item lists
1525 1526
@cindex I/O item lists

1527
To support legacy codes, GNU Fortran allows the input item list
1528 1529
of the @code{READ} statement, and the output item lists of the
@code{WRITE} and @code{PRINT} statements, to start with a comma.
1530

1531 1532 1533 1534 1535 1536
@node @code{Q} exponent-letter
@subsection @code{Q} exponent-letter
@cindex @code{Q} exponent-letter

GNU Fortran accepts real literal constants with an exponent-letter
of @code{Q}, for example, @code{1.23Q45}.  The constant is interpreted
1537
as a @code{REAL(16)} entity on targets that support this type.  If
1538 1539 1540 1541 1542
the target does not support @code{REAL(16)} but has a @code{REAL(10)}
type, then the real-literal-constant will be interpreted as a
@code{REAL(10)} entity.  In the absence of @code{REAL(16)} and
@code{REAL(10)}, an error will occur.

1543
@node BOZ literal constants
1544
@subsection BOZ literal constants
1545
@cindex BOZ literal constants
1546

1547
Besides decimal constants, Fortran also supports binary (@code{b}),
1548
octal (@code{o}) and hexadecimal (@code{z}) integer constants.  The
1549 1550 1551 1552
syntax is: @samp{prefix quote digits quote}, were the prefix is
either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
@code{"} and the digits are for binary @code{0} or @code{1}, for
octal between @code{0} and @code{7}, and for hexadecimal between
1553
@code{0} and @code{F}.  (Example: @code{b'01011101'}.)
1554 1555

Up to Fortran 95, BOZ literals were only allowed to initialize
1556
integer variables in DATA statements.  Since Fortran 2003 BOZ literals
1557 1558 1559 1560
are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
and @code{CMPLX}; the result is the same as if the integer BOZ
literal had been converted by @code{TRANSFER} to, respectively,
@code{real}, @code{double precision}, @code{integer} or @code{complex}.
1561 1562
As GNU Fortran extension the intrinsic procedures @code{FLOAT},
@code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
1563

1564
As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
1565
be specified using the @code{X} prefix, in addition to the standard
1566
@code{Z} prefix.  The BOZ literal can also be specified by adding a
1567 1568 1569 1570 1571 1572 1573 1574
suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
equivalent.

Furthermore, GNU Fortran allows using BOZ literal constants outside
DATA statements and the four intrinsic functions allowed by Fortran 2003.
In DATA statements, in direct assignments, where the right-hand side
only contains a BOZ literal constant, and for old-style initializers of
the form @code{integer i /o'0173'/}, the constant is transferred
1575
as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
1576
the real part is initialized unless @code{CMPLX} is used.  In all other
1577
cases, the BOZ literal constant is converted to an @code{INTEGER} value with
1578 1579
the largest decimal representation.  This value is then converted
numerically to the type and kind of the variable in question.
1580
(For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
1581 1582 1583 1584 1585 1586
with @code{2.0}.) As different compilers implement the extension
differently, one should be careful when doing bitwise initialization
of non-integer variables.

Note that initializing an @code{INTEGER} variable with a statement such
as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
1587 1588 1589 1590
than the desired result of @math{-1} when @code{i} is a 32-bit integer
on a system that supports 64-bit integers.  The @samp{-fno-range-check}
option can be used as a workaround for legacy code that initializes
integers in this manner.
1591 1592

@node Real array indices
1593
@subsection Real array indices
1594
@cindex array, indices of type real
1595

1596 1597
As an extension, GNU Fortran allows the use of @code{REAL} expressions
or variables as array indices.
1598 1599

@node Unary operators
1600
@subsection Unary operators
1601
@cindex operators, unary
1602

1603 1604 1605
As an extension, GNU Fortran allows unary plus and unary minus operators
to appear as the second operand of binary arithmetic operators without
the need for parenthesis.
1606 1607 1608 1609 1610

@smallexample
       X = Y * -Z
@end smallexample

1611
@node Implicitly convert LOGICAL and INTEGER values
1612
@subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1613 1614
@cindex conversion, to integer
@cindex conversion, to logical
1615

1616 1617 1618 1619 1620 1621
As an extension for backwards compatibility with other compilers, GNU
Fortran allows the implicit conversion of @code{LOGICAL} values to
@code{INTEGER} values and vice versa.  When converting from a
@code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
zero, and @code{.TRUE.} is interpreted as one.  When converting from
@code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1622
@code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1623 1624

@smallexample
1625 1626 1627 1628 1629 1630
        LOGICAL :: l
        l = 1
@end smallexample
@smallexample
        INTEGER :: i
        i = .TRUE.
1631 1632
@end smallexample

1633 1634 1635
However, there is no implicit conversion of @code{INTEGER} values in
@code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
in I/O operations.
1636

1637
@node Hollerith constants support
1638
@subsection Hollerith constants support
1639 1640
@cindex Hollerith constants

1641 1642
GNU Fortran supports Hollerith constants in assignments, function
arguments, and @code{DATA} and @code{ASSIGN} statements.  A Hollerith
Kazu Hirata committed
1643
constant is written as a string of characters preceded by an integer
1644 1645 1646 1647 1648
constant indicating the character count, and the letter @code{H} or
@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
@code{REAL}, or @code{complex}) or @code{LOGICAL} variable.  The
constant will be padded or truncated to fit the size of the variable in
which it is stored.
1649

1650
Examples of valid uses of Hollerith constants:
1651
@smallexample
1652 1653 1654 1655
      complex*16 x(2)
      data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
      x(1) = 16HABCDEFGHIJKLMNOP
      call foo (4h abc)
1656 1657 1658 1659
@end smallexample

Invalid Hollerith constants examples:
@smallexample
1660 1661 1662
      integer*4 a
      a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
      a = 0H         ! At least one character is needed.
1663 1664
@end smallexample

1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
In general, Hollerith constants were used to provide a rudimentary
facility for handling character strings in early Fortran compilers,
prior to the introduction of @code{CHARACTER} variables in Fortran 77;
in those cases, the standard-compliant equivalent is to convert the
program to use proper character strings.  On occasion, there may be a
case where the intent is specifically to initialize a numeric variable
with a given byte sequence.  In these cases, the same result can be
obtained by using the @code{TRANSFER} statement, as in this example.
@smallexample
      INTEGER(KIND=4) :: a
      a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
@end smallexample


Asher Langton committed
1679
@node Cray pointers
1680 1681
@subsection Cray pointers
@cindex pointer, Cray
Asher Langton committed
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697

Cray pointers are part of a non-standard extension that provides a
C-like pointer in Fortran.  This is accomplished through a pair of
variables: an integer "pointer" that holds a memory address, and a
"pointee" that is used to dereference the pointer.

Pointer/pointee pairs are declared in statements of the form:
@smallexample
        pointer ( <pointer> , <pointee> )
@end smallexample
or,
@smallexample
        pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
@end smallexample
The pointer is an integer that is intended to hold a memory address.
The pointee may be an array or scalar.  A pointee can be an assumed
1698
size array---that is, the last dimension may be left unspecified by
1699 1700
using a @code{*} in place of a value---but a pointee cannot be an
assumed shape array.  No space is allocated for the pointee.
Asher Langton committed
1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730

The pointee may have its type declared before or after the pointer
statement, and its array specification (if any) may be declared
before, during, or after the pointer statement.  The pointer may be
declared as an integer prior to the pointer statement.  However, some
machines have default integer sizes that are different than the size
of a pointer, and so the following code is not portable:
@smallexample
        integer ipt
        pointer (ipt, iarr)
@end smallexample
If a pointer is declared with a kind that is too small, the compiler
will issue a warning; the resulting binary will probably not work
correctly, because the memory addresses stored in the pointers may be
truncated.  It is safer to omit the first line of the above example;
if explicit declaration of ipt's type is omitted, then the compiler
will ensure that ipt is an integer variable large enough to hold a
pointer.

Pointer arithmetic is valid with Cray pointers, but it is not the same
as C pointer arithmetic.  Cray pointers are just ordinary integers, so
the user is responsible for determining how many bytes to add to a
pointer in order to increment it.  Consider the following example:
@smallexample
        real target(10)
        real pointee(10)
        pointer (ipt, pointee)
        ipt = loc (target)
        ipt = ipt + 1       
@end smallexample
1731 1732 1733
The last statement does not set @code{ipt} to the address of
@code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
to @code{ipt} just adds one byte to the address stored in @code{ipt}.
Asher Langton committed
1734 1735

Any expression involving the pointee will be translated to use the
1736
value stored in the pointer as the base address.
Asher Langton committed
1737 1738

To get the address of elements, this extension provides an intrinsic
1739 1740
function @code{LOC()}.  The @code{LOC()} function is equivalent to the
@code{&} operator in C, except the address is cast to an integer type:
Asher Langton committed
1741 1742 1743 1744 1745 1746 1747
@smallexample
        real ar(10)
        pointer(ipt, arpte(10))
        real arpte
        ipt = loc(ar)  ! Makes arpte is an alias for ar
        arpte(1) = 1.0 ! Sets ar(1) to 1.0
@end smallexample
1748 1749 1750
The pointer can also be set by a call to the @code{MALLOC} intrinsic
(see @ref{MALLOC}).

Asher Langton committed
1751 1752 1753 1754 1755 1756 1757 1758
Cray pointees often are used to alias an existing variable.  For
example:
@smallexample
        integer target(10)
        integer iarr(10)
        pointer (ipt, iarr)
        ipt = loc(target)
@end smallexample
1759
As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1760
@code{target}.  The optimizer, however, will not detect this aliasing, so
1761 1762
it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
a pointee in any way that violates the Fortran aliasing rules or
1763
assumptions is illegal.  It is the user's responsibility to avoid doing
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
this; the compiler works under the assumption that no such aliasing
occurs.

Cray pointers will work correctly when there is no aliasing (i.e., when
they are used to access a dynamically allocated block of memory), and
also in any routine where a pointee is used, but any variable with which
it shares storage is not used.  Code that violates these rules may not
run as the user intends.  This is not a bug in the optimizer; any code
that violates the aliasing rules is illegal.  (Note that this is not
unique to GNU Fortran; any Fortran compiler that supports Cray pointers
will ``incorrectly'' optimize code with illegal aliasing.)

There are a number of restrictions on the attributes that can be applied
to Cray pointers and pointees.  Pointees may not have the
@code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
1779
@code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes.  Pointers
1780
may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
1781
@code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
1782
may they be function results.  Pointees may not occur in more than one
1783 1784
pointer statement.  A pointee cannot be a pointer.  Pointees cannot occur
in equivalence, common, or data statements.
Asher Langton committed
1785

1786 1787
A Cray pointer may also point to a function or a subroutine.  For
example, the following excerpt is valid:
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
@smallexample
  implicit none
  external sub
  pointer (subptr,subpte)
  external subpte
  subptr = loc(sub)
  call subpte()
  [...]
  subroutine sub
  [...]
  end subroutine sub
@end smallexample

Asher Langton committed
1801 1802 1803 1804 1805 1806
A pointer may be modified during the course of a program, and this
will change the location to which the pointee refers.  However, when
pointees are passed as arguments, they are treated as ordinary
variables in the invoked function.  Subsequent changes to the pointer
will not change the base address of the array that was passed.

1807
@node CONVERT specifier
1808 1809
@subsection @code{CONVERT} specifier
@cindex @code{CONVERT} specifier
1810

1811
GNU Fortran allows the conversion of unformatted data between little-
1812
and big-endian representation to facilitate moving of data
1813
between different systems.  The conversion can be indicated with
1814
the @code{CONVERT} specifier on the @code{OPEN} statement.
1815 1816
@xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
the data format via an environment variable.
1817 1818 1819 1820 1821

Valid values for @code{CONVERT} are:
@itemize @w{}
@item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
@item @code{CONVERT='SWAP'} Swap between little- and big-endian.
1822
@item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
1823
for unformatted files.
1824
@item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
1825
unformatted files.
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
@end itemize

Using the option could look like this:
@smallexample
  open(file='big.dat',form='unformatted',access='sequential', &
       convert='big_endian')
@end smallexample

The value of the conversion can be queried by using
@code{INQUIRE(CONVERT=ch)}.  The values returned are
@code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.

@code{CONVERT} works between big- and little-endian for
@code{INTEGER} values of all supported kinds and for @code{REAL}
1840
on IEEE systems of kinds 4 and 8.  Conversion between different
1841
``extended double'' types on different architectures such as
1842
m68k and x86_64, which GNU Fortran
1843 1844
supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
probably not work.
1845

1846 1847 1848
@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
environment variable will override the CONVERT specifier in the
open statement}.  This is to give control over data formats to
1849
users who do not have the source code of their program available.
1850 1851 1852 1853 1854 1855

Using anything but the native representation for unformatted data
carries a significant speed overhead.  If speed in this area matters
to you, it is best if you use this only for data that needs to be
portable.

1856
@node OpenMP
1857
@subsection OpenMP
1858 1859
@cindex OpenMP

1860 1861 1862 1863 1864 1865 1866 1867
OpenMP (Open Multi-Processing) is an application programming
interface (API) that supports multi-platform shared memory 
multiprocessing programming in C/C++ and Fortran on many 
architectures, including Unix and Microsoft Windows platforms.
It consists of a set of compiler directives, library routines,
and environment variables that influence run-time behavior.

GNU Fortran strives to be compatible to the 
1868 1869
@uref{http://www.openmp.org/mp-documents/spec31.pdf,
OpenMP Application Program Interface v3.1}.
1870 1871 1872 1873 1874 1875

To enable the processing of the OpenMP directive @code{!$omp} in
free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
directives in fixed form; the @code{!$} conditional compilation sentinels
in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
in fixed form, @command{gfortran} needs to be invoked with the
1876
@option{-fopenmp}.  This also arranges for automatic linking of the
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900
GNU OpenMP runtime library @ref{Top,,libgomp,libgomp,GNU OpenMP
runtime library}.

The OpenMP Fortran runtime library routines are provided both in a
form of a Fortran 90 module named @code{omp_lib} and in a form of
a Fortran @code{include} file named @file{omp_lib.h}.

An example of a parallelized loop taken from Appendix A.1 of
the OpenMP Application Program Interface v2.5:
@smallexample
SUBROUTINE A1(N, A, B)
  INTEGER I, N
  REAL B(N), A(N)
!$OMP PARALLEL DO !I is private by default
  DO I=2,N
    B(I) = (A(I) + A(I-1)) / 2.0
  ENDDO
!$OMP END PARALLEL DO
END SUBROUTINE A1
@end smallexample

Please note:
@itemize
@item
1901
@option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
1902
will be allocated on the stack.  When porting existing code to OpenMP,
1903 1904 1905 1906
this may lead to surprising results, especially to segmentation faults
if the stacksize is limited.

@item
1907
On glibc-based systems, OpenMP enabled applications cannot be statically
1908
linked due to limitations of the underlying pthreads-implementation.  It
1909 1910
might be possible to get a working solution if 
@command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
1911
to the command line.  However, this is not supported by @command{gcc} and
1912 1913
thus not recommended.
@end itemize
1914

1915
@node Argument list functions
1916
@subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
1917
@cindex argument list functions
1918 1919 1920
@cindex @code{%VAL}
@cindex @code{%REF}
@cindex @code{%LOC}
1921 1922 1923 1924 1925

GNU Fortran supports argument list functions @code{%VAL}, @code{%REF} 
and @code{%LOC} statements, for backward compatibility with g77. 
It is recommended that these should be used only for code that is 
accessing facilities outside of GNU Fortran, such as operating system 
1926
or windowing facilities.  It is best to constrain such uses to isolated 
1927
portions of a program--portions that deal specifically and exclusively 
1928
with low-level, system-dependent facilities.  Such portions might well 
1929 1930 1931 1932 1933 1934 1935
provide a portable interface for use by the program as a whole, but are 
themselves not portable, and should be thoroughly tested each time they 
are rebuilt using a new compiler or version of a compiler.

@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by 
reference and @code{%LOC} passes its memory location.  Since gfortran 
already passes scalar arguments by reference, @code{%REF} is in effect 
1936
a do-nothing.  @code{%LOC} has the same effect as a Fortran pointer.
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950

An example of passing an argument by value to a C subroutine foo.:
@smallexample
C
C prototype      void foo_ (float x);
C
      external foo
      real*4 x
      x = 3.14159
      call foo (%VAL (x))
      end
@end smallexample

For details refer to the g77 manual
1951
@uref{http://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
1952

1953 1954
Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
GNU Fortran testsuite are worth a look.
1955 1956 1957 1958 1959 1960 1961 1962 1963


@node Extensions not implemented in GNU Fortran
@section Extensions not implemented in GNU Fortran
@cindex extensions, not implemented

The long history of the Fortran language, its wide use and broad
userbase, the large number of different compiler vendors and the lack of
some features crucial to users in the first standards have lead to the
1964
existence of a number of important extensions to the language.  While
1965
some of the most useful or popular extensions are supported by the GNU
1966
Fortran compiler, not all existing extensions are supported.  This section
1967 1968 1969 1970 1971
aims at listing these extensions and offering advice on how best make
code that uses them running with the GNU Fortran compiler.

@c More can be found here:
@c   -- http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
1972
@c   -- the list of Fortran and libgfortran bugs closed as WONTFIX:
1973 1974 1975 1976 1977 1978
@c      http://tinyurl.com/2u4h5y

@menu
* STRUCTURE and RECORD::
@c * UNION and MAP::
* ENCODE and DECODE statements::
1979
* Variable FORMAT expressions::
1980 1981 1982 1983 1984
@c * Q edit descriptor::
@c * AUTOMATIC statement::
@c * TYPE and ACCEPT I/O Statements::
@c * .XOR. operator::
@c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
1985 1986
@c * Omitted arguments in procedure call::
* Alternate complex function syntax::
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
@end menu


@node STRUCTURE and RECORD
@subsection @code{STRUCTURE} and @code{RECORD}
@cindex @code{STRUCTURE}
@cindex @code{RECORD}

Structures are user-defined aggregate data types; this functionality was
standardized in Fortran 90 with an different syntax, under the name of
1997
``derived types''.  Here is an example of code using the non portable
1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
structure syntax:

@example
! Declaring a structure named ``item'' and containing three fields:
! an integer ID, an description string and a floating-point price.
STRUCTURE /item/
  INTEGER id
  CHARACTER(LEN=200) description
  REAL price
END STRUCTURE

! Define two variables, an single record of type ``item''
! named ``pear'', and an array of items named ``store_catalog''
RECORD /item/ pear, store_catalog(100)

! We can directly access the fields of both variables
pear.id = 92316
pear.description = "juicy D'Anjou pear"
pear.price = 0.15
store_catalog(7).id = 7831
store_catalog(7).description = "milk bottle"
store_catalog(7).price = 1.2

2021
! We can also manipulate the whole structure
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049
store_catalog(12) = pear
print *, store_catalog(12)
@end example

@noindent
This code can easily be rewritten in the Fortran 90 syntax as following:

@example
! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
! ``TYPE name ... END TYPE''
TYPE item
  INTEGER id
  CHARACTER(LEN=200) description
  REAL price
END TYPE

! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
TYPE(item) pear, store_catalog(100)

! Instead of using a dot (.) to access fields of a record, the
! standard syntax uses a percent sign (%)
pear%id = 92316
pear%description = "juicy D'Anjou pear"
pear%price = 0.15
store_catalog(7)%id = 7831
store_catalog(7)%description = "milk bottle"
store_catalog(7)%price = 1.2

2050
! Assignments of a whole variable do not change
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
store_catalog(12) = pear
print *, store_catalog(12)
@end example


@c @node UNION and MAP
@c @subsection @code{UNION} and @code{MAP}
@c @cindex @code{UNION}
@c @cindex @code{MAP}
@c
@c For help writing this one, see
@c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
@c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm


@node ENCODE and DECODE statements
@subsection @code{ENCODE} and @code{DECODE} statements
@cindex @code{ENCODE}
@cindex @code{DECODE}

2071
GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
2072 2073 2074
statements.  These statements are best replaced by @code{READ} and
@code{WRITE} statements involving internal files (@code{CHARACTER}
variables and arrays), which have been part of the Fortran standard since
2075
Fortran 77.  For example, replace a code fragment like
2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109

@smallexample
      INTEGER*1 LINE(80)
      REAL A, B, C
c     ... Code that sets LINE
      DECODE (80, 9000, LINE) A, B, C
 9000 FORMAT (1X, 3(F10.5))
@end smallexample

@noindent
with the following:

@smallexample
      CHARACTER(LEN=80) LINE
      REAL A, B, C
c     ... Code that sets LINE
      READ (UNIT=LINE, FMT=9000) A, B, C
 9000 FORMAT (1X, 3(F10.5))
@end smallexample

Similarly, replace a code fragment like

@smallexample
      INTEGER*1 LINE(80)
      REAL A, B, C
c     ... Code that sets A, B and C
      ENCODE (80, 9000, LINE) A, B, C
 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
@end smallexample

@noindent
with the following:

@smallexample
2110
      CHARACTER(LEN=80) LINE
2111 2112 2113 2114 2115 2116 2117
      REAL A, B, C
c     ... Code that sets A, B and C
      WRITE (UNIT=LINE, FMT=9000) A, B, C
 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
@end smallexample


2118 2119 2120 2121 2122
@node Variable FORMAT expressions
@subsection Variable @code{FORMAT} expressions
@cindex @code{FORMAT}

A variable @code{FORMAT} expression is format statement which includes
2123 2124
angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}.  GNU
Fortran does not support this legacy extension.  The effect of variable
2125
format expressions can be reproduced by using the more powerful (and
2126
standard) combination of internal output and string formats.  For example,
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138
replace a code fragment like this:

@smallexample
      WRITE(6,20) INT1
 20   FORMAT(I<N+1>)
@end smallexample

@noindent
with the following:

@smallexample
c     Variable declaration
2139
      CHARACTER(LEN=20) FMT
2140 2141 2142 2143
c     
c     Other code here...
c
      WRITE(FMT,'("(I", I0, ")")') N+1
2144
      WRITE(6,FMT) INT1
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160
@end smallexample

@noindent
or with:

@smallexample
c     Variable declaration
      CHARACTER(LEN=20) FMT
c     
c     Other code here...
c
      WRITE(FMT,*) N+1
      WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
@end smallexample


2161 2162 2163 2164 2165 2166
@node Alternate complex function syntax
@subsection Alternate complex function syntax
@cindex Complex function

Some Fortran compilers, including @command{g77}, let the user declare
complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
2167 2168
well as @code{COMPLEX*16 FUNCTION name()}.  Both are non-standard, legacy
extensions.  @command{gfortran} accepts the latter form, which is more
2169 2170 2171 2172
common, but not the former.



2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
@c ---------------------------------------------------------------------
@c Mixed-Language Programming
@c ---------------------------------------------------------------------

@node Mixed-Language Programming
@chapter Mixed-Language Programming
@cindex Interoperability
@cindex Mixed-language programming

@menu
* Interoperability with C::
2184
* GNU Fortran Compiler Directives::
2185 2186 2187 2188
* Non-Fortran Main Program::
@end menu

This chapter is about mixed-language interoperability, but also applies
2189
if one links Fortran code compiled by different compilers.  In most cases,
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201
use of the C Binding features of the Fortran 2003 standard is sufficient,
and their use is highly recommended.


@node Interoperability with C
@section Interoperability with C

@menu
* Intrinsic Types::
* Derived Types and struct::
* Interoperable Global Variables::
* Interoperable Subroutines and Functions::
2202 2203
* Working with Pointers::
* Further Interoperability of Fortran with C::
2204 2205 2206 2207 2208
@end menu

Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
standardized way to generate procedure and derived-type
declarations and global variables which are interoperable with C
2209
(ISO/IEC 9899:1999).  The @code{bind(C)} attribute has been added
2210
to inform the compiler that a symbol shall be interoperable with C;
2211 2212
also, some constraints are added.  Note, however, that not
all C features have a Fortran equivalent or vice versa.  For instance,
2213 2214 2215
neither C's unsigned integers nor C's functions with variable number
of arguments have an equivalent in Fortran.

2216
Note that array dimensions are reversely ordered in C and that arrays in
2217
C always start with index 0 while in Fortran they start by default with
2218
1.  Thus, an array declaration @code{A(n,m)} in Fortran matches
2219
@code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
2220
@code{A[j-1][i-1]}.  The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
2221
assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
2222 2223 2224 2225 2226 2227

@node Intrinsic Types
@subsection Intrinsic Types

In order to ensure that exactly the same variable type and kind is used
in C and Fortran, the named constants shall be used which are defined in the
2228
@code{ISO_C_BINDING} intrinsic module.  That module contains named constants
2229
for kind parameters and character named constants for the escape sequences
2230
in C.  For a list of the constants, see @ref{ISO_C_BINDING}.
2231 2232 2233 2234 2235

@node Derived Types and struct
@subsection Derived Types and struct

For compatibility of derived types with @code{struct}, one needs to use
2236
the @code{BIND(C)} attribute in the type declaration.  For instance, the
2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264
following type declaration

@smallexample
 USE ISO_C_BINDING
 TYPE, BIND(C) :: myType
   INTEGER(C_INT) :: i1, i2
   INTEGER(C_SIGNED_CHAR) :: i3
   REAL(C_DOUBLE) :: d1
   COMPLEX(C_FLOAT_COMPLEX) :: c1
   CHARACTER(KIND=C_CHAR) :: str(5)
 END TYPE
@end smallexample

matches the following @code{struct} declaration in C

@smallexample
 struct @{
   int i1, i2;
   /* Note: "char" might be signed or unsigned.  */
   signed char i3;
   double d1;
   float _Complex c1;
   char str[5];
 @} myType;
@end smallexample

Derived types with the C binding attribute shall not have the @code{sequence}
attribute, type parameters, the @code{extends} attribute, nor type-bound
2265 2266
procedures.  Every component must be of interoperable type and kind and may not
have the @code{pointer} or @code{allocatable} attribute.  The names of the
2267 2268 2269 2270 2271 2272 2273 2274 2275
variables are irrelevant for interoperability.

As there exist no direct Fortran equivalents, neither unions nor structs
with bit field or variable-length array members are interoperable.

@node Interoperable Global Variables
@subsection Interoperable Global Variables

Variables can be made accessible from C using the C binding attribute,
2276
optionally together with specifying a binding name.  Those variables
2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291
have to be declared in the declaration part of a @code{MODULE},
be of interoperable type, and have neither the @code{pointer} nor
the @code{allocatable} attribute.

@smallexample
  MODULE m
    USE myType_module
    USE ISO_C_BINDING
    integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
    type(myType), bind(C) :: tp
  END MODULE
@end smallexample

Here, @code{_MyProject_flags} is the case-sensitive name of the variable
as seen from C programs while @code{global_flag} is the case-insensitive
2292
name as seen from Fortran.  If no binding name is specified, as for
2293 2294
@var{tp}, the C binding name is the (lowercase) Fortran binding name.
If a binding name is specified, only a single variable may be after the
2295
double colon.  Note of warning: You cannot use a global variable to
2296
access @var{errno} of the C library as the C standard allows it to be
2297
a macro.  Use the @code{IERRNO} intrinsic (GNU extension) instead.
2298 2299 2300 2301 2302

@node Interoperable Subroutines and Functions
@subsection Interoperable Subroutines and Functions

Subroutines and functions have to have the @code{BIND(C)} attribute to
2303 2304
be compatible with C.  The dummy argument declaration is relatively
straightforward.  However, one needs to be careful because C uses
2305
call-by-value by default while Fortran behaves usually similar to
2306 2307
call-by-reference.  Furthermore, strings and pointers are handled
differently.  Note that only explicit size and assumed-size arrays are
2308
supported but not assumed-shape or allocatable arrays.
2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319

To pass a variable by value, use the @code{VALUE} attribute.
Thus the following C prototype

@smallexample
@code{int func(int i, int *j)}
@end smallexample

matches the Fortran declaration

@smallexample
2320 2321 2322 2323
  integer(c_int) function func(i,j)
    use iso_c_binding, only: c_int
    integer(c_int), VALUE :: i
    integer(c_int) :: j
2324 2325
@end smallexample

2326 2327
Note that pointer arguments also frequently need the @code{VALUE} attribute,
see @ref{Working with Pointers}.
2328

2329
Strings are handled quite differently in C and Fortran.  In C a string
2330 2331
is a @code{NUL}-terminated array of characters while in Fortran each string
has a length associated with it and is thus not terminated (by e.g.
2332
@code{NUL}).  For example, if one wants to use the following C function,
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355

@smallexample
  #include <stdio.h>
  void print_C(char *string) /* equivalent: char string[]  */
  @{
     printf("%s\n", string);
  @}
@end smallexample

to print ``Hello World'' from Fortran, one can call it using

@smallexample
  use iso_c_binding, only: C_CHAR, C_NULL_CHAR
  interface
    subroutine print_c(string) bind(C, name="print_C")
      use iso_c_binding, only: c_char
      character(kind=c_char) :: string(*)
    end subroutine print_c
  end interface
  call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
@end smallexample

As the example shows, one needs to ensure that the
2356
string is @code{NUL} terminated.  Additionally, the dummy argument
2357
@var{string} of @code{print_C} is a length-one assumed-size
2358
array; using @code{character(len=*)} is not allowed.  The example
2359 2360 2361
above uses @code{c_char_"Hello World"} to ensure the string
literal has the right type; typically the default character
kind and @code{c_char} are the same and thus @code{"Hello World"}
2362
is equivalent.  However, the standard does not guarantee this.
2363

2364
The use of strings is now further illustrated using the C library
2365 2366 2367 2368 2369 2370 2371
function @code{strncpy}, whose prototype is

@smallexample
  char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
@end smallexample

The function @code{strncpy} copies at most @var{n} characters from
2372
string @var{s2} to @var{s1} and returns @var{s1}.  In the following
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395
example, we ignore the return value:

@smallexample
  use iso_c_binding
  implicit none
  character(len=30) :: str,str2
  interface
    ! Ignore the return value of strncpy -> subroutine
    ! "restrict" is always assumed if we do not pass a pointer
    subroutine strncpy(dest, src, n) bind(C)
      import
      character(kind=c_char),  intent(out) :: dest(*)
      character(kind=c_char),  intent(in)  :: src(*)
      integer(c_size_t), value, intent(in) :: n
    end subroutine strncpy
  end interface
  str = repeat('X',30) ! Initialize whole string with 'X'
  call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
               len(c_char_"Hello World",kind=c_size_t))
  print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
  end
@end smallexample

2396 2397 2398 2399 2400 2401
The intrinsic procedures are described in @ref{Intrinsic Procedures}.

@node Working with Pointers
@subsection Working with Pointers

C pointers are represented in Fortran via the special opaque derived type
2402
@code{type(c_ptr)} (with private components).  Thus one needs to
2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419
use intrinsic conversion procedures to convert from or to C pointers.
For example,

@smallexample
  use iso_c_binding
  type(c_ptr) :: cptr1, cptr2
  integer, target :: array(7), scalar
  integer, pointer :: pa(:), ps
  cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
                          ! array is contiguous if required by the C
                          ! procedure
  cptr2 = c_loc(scalar)
  call c_f_pointer(cptr2, ps)
  call c_f_pointer(cptr2, pa, shape=[7])
@end smallexample

When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
2420 2421 2422 2423 2424 2425
has to be passed.

If a pointer is a dummy-argument of an interoperable procedure, it usually
has to be declared using the @code{VALUE} attribute.  @code{void*}
matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
matches @code{void**}.
2426 2427 2428

Procedure pointers are handled analogously to pointers; the C type is
@code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
2429
@code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
2430

2431
Let us consider two examples of actually passing a procedure pointer from
2432
C to Fortran and vice versa.  Note that these examples are also very
2433 2434
similar to passing ordinary pointers between both languages. First,
consider this code in C:
2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544

@smallexample
/* Procedure implemented in Fortran.  */
void get_values (void (*)(double));

/* Call-back routine we want called from Fortran.  */
void
print_it (double x)
@{
  printf ("Number is %f.\n", x);
@}

/* Call Fortran routine and pass call-back to it.  */
void
foobar ()
@{
  get_values (&print_it);
@}
@end smallexample

A matching implementation for @code{get_values} in Fortran, that correctly
receives the procedure pointer from C and is able to call it, is given
in the following @code{MODULE}:

@smallexample
MODULE m
  IMPLICIT NONE

  ! Define interface of call-back routine.
  ABSTRACT INTERFACE
    SUBROUTINE callback (x)
      USE, INTRINSIC :: ISO_C_BINDING
      REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
    END SUBROUTINE callback
  END INTERFACE

CONTAINS

  ! Define C-bound procedure.
  SUBROUTINE get_values (cproc) BIND(C)
    USE, INTRINSIC :: ISO_C_BINDING
    TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc

    PROCEDURE(callback), POINTER :: proc

    ! Convert C to Fortran procedure pointer.
    CALL C_F_PROCPOINTER (cproc, proc)

    ! Call it.
    CALL proc (1.0_C_DOUBLE)
    CALL proc (-42.0_C_DOUBLE)
    CALL proc (18.12_C_DOUBLE)
  END SUBROUTINE get_values

END MODULE m
@end smallexample

Next, we want to call a C routine that expects a procedure pointer argument
and pass it a Fortran procedure (which clearly must be interoperable!).
Again, the C function may be:

@smallexample
int
call_it (int (*func)(int), int arg)
@{
  return func (arg);
@}
@end smallexample

It can be used as in the following Fortran code:

@smallexample
MODULE m
  USE, INTRINSIC :: ISO_C_BINDING
  IMPLICIT NONE

  ! Define interface of C function.
  INTERFACE
    INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
      USE, INTRINSIC :: ISO_C_BINDING
      TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
      INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
    END FUNCTION call_it
  END INTERFACE

CONTAINS

  ! Define procedure passed to C function.
  ! It must be interoperable!
  INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
    INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
    double_it = arg + arg
  END FUNCTION double_it

  ! Call C function.
  SUBROUTINE foobar ()
    TYPE(C_FUNPTR) :: cproc
    INTEGER(KIND=C_INT) :: i

    ! Get C procedure pointer.
    cproc = C_FUNLOC (double_it)

    ! Use it.
    DO i = 1_C_INT, 10_C_INT
      PRINT *, call_it (cproc, i)
    END DO
  END SUBROUTINE foobar

END MODULE m
@end smallexample
2545 2546 2547 2548 2549

@node Further Interoperability of Fortran with C
@subsection Further Interoperability of Fortran with C

Assumed-shape and allocatable arrays are passed using an array descriptor
2550 2551
(dope vector).  The internal structure of the array descriptor used
by GNU Fortran is not yet documented and will change.  There will also be
2552
a Technical Specification (TS 29113) which standardizes an interoperable
2553
array descriptor.  Until then, you can use the Chasm Language
2554 2555 2556
Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
which provide an interface to GNU Fortran's array descriptor.

2557 2558
GNU Fortran already supports the C-interoperable @code{OPTIONAL}
attribute; for absent arguments, a @code{NULL} pointer is passed.
2559

2560 2561 2562 2563 2564


@node GNU Fortran Compiler Directives
@section GNU Fortran Compiler Directives

2565
The Fortran standard describes how a conforming program shall
2566
behave; however, the exact implementation is not standardized.  In order
2567 2568
to allow the user to choose specific implementation details, compiler
directives can be used to set attributes of variables and procedures
2569
which are not part of the standard.  Whether a given attribute is
2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586
supported and its exact effects depend on both the operating system and
on the processor; see
@ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
for details.

For procedures and procedure pointers, the following attributes can
be used to change the calling convention:

@itemize
@item @code{CDECL} -- standard C calling convention
@item @code{STDCALL} -- convention where the called procedure pops the stack
@item @code{FASTCALL} -- part of the arguments are passed via registers
instead using the stack
@end itemize

Besides changing the calling convention, the attributes also influence
the decoration of the symbol name, e.g., by a leading underscore or by
2587
a trailing at-sign followed by the number of bytes on the stack.  When
2588 2589 2590 2591 2592
assigning a procedure to a procedure pointer, both should use the same
calling convention.

On some systems, procedures and global variables (module variables and
@code{COMMON} blocks) need special handling to be accessible when they
2593
are in a shared library.  The following attributes are available:
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613

@itemize
@item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
@item @code{DLLIMPORT} -- reference the function or variable using a global pointer 
@end itemize

The attributes are specified using the syntax

@code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}

where in free-form source code only whitespace is allowed before @code{!GCC$}
and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
start in the first column.

For procedures, the compiler directives shall be placed into the body
of the procedure; for variables and procedure pointers, they shall be in
the same declaration part as the variable or procedure pointer.



2614 2615 2616 2617 2618 2619 2620 2621 2622
@node Non-Fortran Main Program
@section Non-Fortran Main Program

@menu
* _gfortran_set_args:: Save command-line arguments
* _gfortran_set_options:: Set library option flags
* _gfortran_set_convert:: Set endian conversion
* _gfortran_set_record_marker:: Set length of record markers
* _gfortran_set_max_subrecord_length:: Set subrecord length
2623
* _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
2624 2625 2626 2627
@end menu

Even if you are doing mixed-language programming, it is very
likely that you do not need to know or use the information in this
2628
section.  Since it is about the internal structure of GNU Fortran,
2629 2630 2631 2632 2633 2634
it may also change in GCC minor releases.

When you compile a @code{PROGRAM} with GNU Fortran, a function
with the name @code{main} (in the symbol table of the object file)
is generated, which initializes the libgfortran library and then
calls the actual program which uses the name @code{MAIN__}, for
2635
historic reasons.  If you link GNU Fortran compiled procedures
2636 2637 2638 2639 2640 2641 2642 2643
to, e.g., a C or C++ program or to a Fortran program compiled by
a different compiler, the libgfortran library is not initialized
and thus a few intrinsic procedures do not work properly, e.g.
those for obtaining the command-line arguments.

Therefore, if your @code{PROGRAM} is not compiled with
GNU Fortran and the GNU Fortran compiled procedures require
intrinsics relying on the library initialization, you need to
2644
initialize the library yourself.  Using the default options,
2645
gfortran calls @code{_gfortran_set_args} and
2646
@code{_gfortran_set_options}.  The initialization of the former
2647 2648
is needed if the called procedures access the command line
(and for backtracing); the latter sets some flags based on the
2649
standard chosen or to enable backtracing.  In typical programs,
2650 2651 2652
it is not necessary to call any initialization function.

If your @code{PROGRAM} is compiled with GNU Fortran, you shall
2653
not call any of the following functions.  The libgfortran
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666
initialization functions are shown in C syntax but using C
bindings they are also accessible from Fortran.


@node _gfortran_set_args
@subsection @code{_gfortran_set_args} --- Save command-line arguments
@fnindex _gfortran_set_args
@cindex libgfortran initialization, set_args

@table @asis
@item @emph{Description}:
@code{_gfortran_set_args} saves the command-line arguments; this
initialization is required if any of the command-line intrinsics
2667
is called.  Additionally, it shall be called if backtracing is
2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699
enabled (see @code{_gfortran_set_options}).

@item @emph{Syntax}:
@code{void _gfortran_set_args (int argc, char *argv[])}

@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@item @var{argc} @tab number of command line argument strings
@item @var{argv} @tab the command-line argument strings; argv[0]
is the pathname of the executable itself.
@end multitable

@item @emph{Example}:
@smallexample
int main (int argc, char *argv[])
@{
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  return 0;
@}
@end smallexample
@end table


@node _gfortran_set_options
@subsection @code{_gfortran_set_options} --- Set library option flags
@fnindex _gfortran_set_options
@cindex libgfortran initialization, set_options

@table @asis
@item @emph{Description}:
@code{_gfortran_set_options} sets several flags related to the Fortran
2700
standard to be used, whether backtracing should be enabled
2701
and whether range checks should be performed.  The syntax allows for
2702
upward compatibility since the number of passed flags is specified; for
2703 2704
non-passed flags, the default value is used.  See also
@pxref{Code Gen Options}.  Please note that not all flags are actually
2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722
used.

@item @emph{Syntax}:
@code{void _gfortran_set_options (int num, int options[])}

@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@item @var{num} @tab number of options passed
@item @var{argv} @tab The list of flag values
@end multitable

@item @emph{option flag list}:
@multitable @columnfractions .15 .70
@item @var{option}[0] @tab Allowed standard; can give run-time errors
if e.g. an input-output edit descriptor is invalid in a given standard.
Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
@code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
(8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
2723
@code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128), 
2724
@code{GFC_STD_F2008_OBS} (256) and GFC_STD_F2008_TS (512). Default:
2725
@code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003
2726
| GFC_STD_F2008 | GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77
2727
| GFC_STD_GNU | GFC_STD_LEGACY}.
2728
@item @var{option}[1] @tab Standard-warning flag; prints a warning to
2729
standard error.  Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
2730 2731
@item @var{option}[2] @tab If non zero, enable pedantic checking.
Default: off.
2732
@item @var{option}[3] @tab Unused.
2733
@item @var{option}[4] @tab If non zero, enable backtracing on run-time
2734
errors.  Default: off.
2735 2736 2737 2738
Note: Installs a signal handler and requires command-line
initialization using @code{_gfortran_set_args}.
@item @var{option}[5] @tab If non zero, supports signed zeros.
Default: enabled.
2739
@item @var{option}[6] @tab Enables run-time checking.  Possible values
2740
are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
2741
GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
2742 2743 2744 2745 2746
Default: disabled.
@end multitable

@item @emph{Example}:
@smallexample
2747 2748 2749
  /* Use gfortran 4.8 default options.  */
  static int options[] = @{68, 511, 0, 0, 1, 1, 0@};
  _gfortran_set_options (7, &options);
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793
@end smallexample
@end table


@node _gfortran_set_convert
@subsection @code{_gfortran_set_convert} --- Set endian conversion
@fnindex _gfortran_set_convert
@cindex libgfortran initialization, set_convert

@table @asis
@item @emph{Description}:
@code{_gfortran_set_convert} set the representation of data for
unformatted files.

@item @emph{Syntax}:
@code{void _gfortran_set_convert (int conv)}

@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@item @var{conv} @tab Endian conversion, possible values:
GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
@end multitable

@item @emph{Example}:
@smallexample
int main (int argc, char *argv[])
@{
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_convert (1);
  return 0;
@}
@end smallexample
@end table


@node _gfortran_set_record_marker
@subsection @code{_gfortran_set_record_marker} --- Set length of record markers
@fnindex _gfortran_set_record_marker
@cindex libgfortran initialization, set_record_marker

@table @asis
@item @emph{Description}:
2794
@code{_gfortran_set_record_marker} sets the length of record markers
2795 2796 2797 2798 2799 2800 2801 2802
for unformatted files.

@item @emph{Syntax}:
@code{void _gfortran_set_record_marker (int val)}

@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@item @var{val} @tab Length of the record marker; valid values
2803
are 4 and 8.  Default is 4.
2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818
@end multitable

@item @emph{Example}:
@smallexample
int main (int argc, char *argv[])
@{
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_record_marker (8);
  return 0;
@}
@end smallexample
@end table


2819
@node _gfortran_set_fpe
2820
@subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
2821 2822 2823 2824 2825
@fnindex _gfortran_set_fpe
@cindex libgfortran initialization, set_fpe

@table @asis
@item @emph{Description}:
2826 2827 2828
@code{_gfortran_set_fpe} enables floating point exception traps for
the specified exceptions.  On most systems, this will result in a
SIGFPE signal being sent and the program being aborted.
2829 2830 2831 2832 2833 2834

@item @emph{Syntax}:
@code{void _gfortran_set_fpe (int val)}

@item @emph{Arguments}:
@multitable @columnfractions .15 .70
2835
@item @var{option}[0] @tab IEEE exceptions.  Possible values are
2836 2837 2838
(bitwise or-ed) zero (0, default) no trapping,
@code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
@code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
2839
@code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855
@end multitable

@item @emph{Example}:
@smallexample
int main (int argc, char *argv[])
@{
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  /* FPE for invalid operations such as SQRT(-1.0).  */
  _gfortran_set_fpe (1);
  return 0;
@}
@end smallexample
@end table


2856 2857 2858 2859 2860 2861 2862 2863
@node _gfortran_set_max_subrecord_length
@subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
@fnindex _gfortran_set_max_subrecord_length
@cindex libgfortran initialization, set_max_subrecord_length

@table @asis
@item @emph{Description}:
@code{_gfortran_set_max_subrecord_length} set the maximum length
2864
for a subrecord.  This option only makes sense for testing and
2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888
debugging of unformatted I/O.

@item @emph{Syntax}:
@code{void _gfortran_set_max_subrecord_length (int val)}

@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@item @var{val} @tab the maximum length for a subrecord;
the maximum permitted value is 2147483639, which is also
the default.
@end multitable

@item @emph{Example}:
@smallexample
int main (int argc, char *argv[])
@{
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_max_subrecord_length (8);
  return 0;
@}
@end smallexample
@end table

2889 2890


2891
@c Intrinsic Procedures
2892
@c ---------------------------------------------------------------------
2893

2894 2895 2896 2897 2898 2899 2900
@include intrinsic.texi


@tex
\blankpart
@end tex

2901
@c ---------------------------------------------------------------------
2902 2903 2904 2905
@c Contributing
@c ---------------------------------------------------------------------

@node Contributing
2906
@unnumbered Contributing
2907 2908 2909 2910 2911 2912 2913
@cindex Contributing

Free software is only possible if people contribute to efforts
to create it.
We're always in need of more people helping out with ideas
and comments, writing documentation and contributing code.

2914
If you want to contribute to GNU Fortran,
2915 2916 2917 2918
have a look at the long lists of projects you can take on.
Some of these projects are small,
some of them are large;
some are completely orthogonal to the rest of what is
2919
happening on GNU Fortran,
2920 2921
but others are ``mainstream'' projects in need of enthusiastic hackers.
All of these projects are important!
2922
We will eventually get around to the things here,
2923 2924 2925 2926 2927
but they are also things doable by someone who is willing and able.

@menu
* Contributors::
* Projects::
2928
* Proposed Extensions::
2929 2930 2931 2932
@end menu


@node Contributors
2933
@section Contributors to GNU Fortran
2934 2935 2936 2937 2938 2939 2940 2941 2942
@cindex Contributors
@cindex Credits
@cindex Authors

Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
also the initiator of the whole project.  Thanks Andy!
Most of the interface with GCC was written by @emph{Paul Brook}.

The following individuals have contributed code and/or
2943
ideas and significant help to the GNU Fortran project
2944
(in alphabetical order):
2945 2946

@itemize @minus
2947
@item Janne Blomqvist
2948 2949
@item Steven Bosscher
@item Paul Brook
2950
@item Tobias Burnus
2951
@item Fran@,{c}ois-Xavier Coudert
2952 2953
@item Bud Davis
@item Jerry DeLisle
2954
@item Erik Edelmann
2955 2956 2957 2958 2959 2960 2961 2962 2963
@item Bernhard Fischer
@item Daniel Franke
@item Richard Guenther
@item Richard Henderson
@item Katherine Holcomb
@item Jakub Jelinek
@item Niels Kristian Bech Jensen
@item Steven Johnson
@item Steven G. Kargl
2964 2965
@item Thomas Koenig
@item Asher Langton
2966 2967 2968 2969 2970 2971
@item H. J. Lu
@item Toon Moene
@item Brooks Moses
@item Andrew Pinski
@item Tim Prince
@item Christopher D. Rickett
2972
@item Richard Sandiford
2973 2974 2975 2976 2977 2978
@item Tobias Schl@"uter
@item Roger Sayle
@item Paul Thomas
@item Andy Vaught
@item Feng Wang
@item Janus Weil
2979
@item Daniel Kraft
2980 2981 2982 2983 2984
@end itemize

The following people have contributed bug reports,
smaller or larger patches,
and much needed feedback and encouragement for the
2985
GNU Fortran project: 
2986 2987 2988

@itemize @minus
@item Bill Clodius
2989
@item Dominique d'Humi@`eres
2990
@item Kate Hedstrom
2991
@item Erik Schnetter
2992
@item Joost VandeVondele
2993 2994 2995
@end itemize

Many other individuals have helped debug,
2996
test and improve the GNU Fortran compiler over the past few years,
2997
and we welcome you to do the same!
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008
If you already have done so,
and you would like to see your name listed in the
list above, please contact us.


@node Projects
@section Projects

@table @emph

@item Help build the test suite
3009 3010 3011
Solicit more code for donation to the test suite: the more extensive the
testsuite, the smaller the risk of breaking things in the future! We can
keep code private on request.
3012 3013

@item Bug hunting/squishing
3014 3015
Find bugs and write more test cases! Test cases are especially very
welcome, because it allows us to concentrate on fixing bugs instead of
3016 3017
isolating them.  Going through the bugzilla database at
@url{http://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
3018 3019
add more information (for example, for which version does the testcase
work, for which versions does it fail?) is also very helpful.
3020

3021
@end table
3022 3023


3024 3025
@node Proposed Extensions
@section Proposed Extensions
3026

3027 3028 3029 3030
Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
order.  Most of these are necessary to be fully compatible with
existing Fortran compilers, but they are not part of the official
J3 Fortran 95 standard.
3031

3032 3033 3034 3035
@subsection Compiler extensions: 
@itemize @bullet
@item
User-specified alignment rules for structures.
3036

3037 3038
@item
Automatically extend single precision constants to double.
3039

3040 3041 3042
@item
Compile code that conserves memory by dynamically allocating common and
module storage either on stack or heap.
3043

3044 3045
@item
Compile flag to generate code for array conformance checking (suggest -CC).
3046

3047 3048
@item
User control of symbol names (underscores, etc).
3049

3050 3051 3052
@item
Compile setting for maximum size of stack frame size before spilling
parts to static or heap.
3053

3054
@item
3055
Flag to force local variables into static space.
3056 3057

@item
3058 3059 3060 3061 3062 3063
Flag to force local variables onto stack.
@end itemize


@subsection Environment Options
@itemize @bullet
3064
@item
3065 3066 3067
Pluggable library modules for random numbers, linear algebra.
LA should use BLAS calling conventions.

3068
@item
3069 3070 3071 3072
Environment variables controlling actions on arithmetic exceptions like
overflow, underflow, precision loss---Generate NaN, abort, default.
action.

3073
@item
3074
Set precision for fp units that support it (i387).
3075

3076
@item
3077
Variable for setting fp rounding mode.
3078

3079
@item
3080 3081
Variable to fill uninitialized variables with a user-defined bit
pattern.
3082 3083

@item
3084 3085
Environment variable controlling filename that is opened for that unit
number.
3086 3087

@item
3088
Environment variable to clear/trash memory being freed.
3089 3090

@item
3091
Environment variable to control tracing of allocations and frees.
3092

3093
@item
3094
Environment variable to display allocated memory at normal program end.
3095

3096
@item
3097 3098 3099 3100 3101 3102 3103
Environment variable for filename for * IO-unit.

@item
Environment variable for temporary file directory.

@item
Environment variable forcing standard output to be line buffered (unix).
3104

3105 3106 3107 3108
@end itemize


@c ---------------------------------------------------------------------
3109 3110 3111
@c GNU General Public License
@c ---------------------------------------------------------------------

3112
@include gpl_v3.texi
3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130



@c ---------------------------------------------------------------------
@c GNU Free Documentation License
@c ---------------------------------------------------------------------

@include fdl.texi



@c ---------------------------------------------------------------------
@c Funding Free Software
@c ---------------------------------------------------------------------

@include funding.texi

@c ---------------------------------------------------------------------
3131
@c Indices
3132
@c ---------------------------------------------------------------------
3133

3134
@node Option Index
3135
@unnumbered Option Index
3136
@command{gfortran}'s command line options are indexed here without any
3137
initial @samp{-} or @samp{--}.  Where an option has both positive and
3138 3139 3140
negative forms (such as -foption and -fno-option), relevant entries in
the manual are indexed under the most appropriate form; it may sometimes
be useful to look up both forms.
3141 3142 3143
@printindex op

@node Keyword Index
3144
@unnumbered Keyword Index
3145 3146 3147
@printindex cp

@bye