OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / fortran / gfortran.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename gfortran.info
4 @set copyrights-gfortran 1999-2007
5
6 @include gcc-common.texi
7
8 @settitle The GNU Fortran Compiler
9
10 @c Create a separate index for command line options
11 @defcodeindex op
12 @c Merge the standard indexes into a single one.
13 @syncodeindex fn cp
14 @syncodeindex vr cp
15 @syncodeindex ky cp
16 @syncodeindex pg cp
17 @syncodeindex tp cp
18
19 @c TODO: The following "Part" definitions are included here temporarily
20 @c until they are incorporated into the official Texinfo distribution.
21 @c They borrow heavily from Texinfo's \unnchapentry definitions.
22
23 @tex
24 \gdef\part#1#2{%
25   \pchapsepmacro
26   \gdef\thischapter{}
27   \begingroup
28     \vglue\titlepagetopglue
29     \titlefonts \rm
30     \leftline{Part #1:@* #2}
31     \vskip4pt \hrule height 4pt width \hsize \vskip4pt
32   \endgroup
33   \writetocentry{part}{#2}{#1}
34 }
35 \gdef\blankpart{%
36   \writetocentry{blankpart}{}{}
37 }
38 % Part TOC-entry definition for summary contents.
39 \gdef\dosmallpartentry#1#2#3#4{%
40   \vskip .5\baselineskip plus.2\baselineskip
41   \begingroup
42     \let\rm=\bf \rm
43     \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
44   \endgroup
45 }
46 \gdef\dosmallblankpartentry#1#2#3#4{%
47   \vskip .5\baselineskip plus.2\baselineskip
48 }
49 % Part TOC-entry definition for regular contents.  This has to be
50 % equated to an existing entry to not cause problems when the PDF
51 % outline is created.
52 \gdef\dopartentry#1#2#3#4{%
53   \unnchapentry{Part #2: #1}{}{#3}{#4}
54 }
55 \gdef\doblankpartentry#1#2#3#4{}
56 @end tex
57
58 @c %**end of header
59
60 @c Use with @@smallbook.
61
62 @c %** start of document
63
64 @c Cause even numbered pages to be printed on the left hand side of
65 @c the page and odd numbered pages to be printed on the right hand
66 @c side of the page.  Using this, you can print on both sides of a
67 @c sheet of paper and have the text on the same part of the sheet.
68
69 @c The text on right hand pages is pushed towards the right hand
70 @c margin and the text on left hand pages is pushed toward the left
71 @c hand margin.
72 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
73
74 @c @tex
75 @c \global\bindingoffset=0.75in
76 @c \global\normaloffset =0.75in
77 @c @end tex
78
79 @copying
80 Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
81
82 Permission is granted to copy, distribute and/or modify this document
83 under the terms of the GNU Free Documentation License, Version 1.1 or
84 any later version published by the Free Software Foundation; with the
85 Invariant Sections being ``GNU General Public License'' and ``Funding
86 Free Software'', the Front-Cover
87 texts being (a) (see below), and with the Back-Cover Texts being (b)
88 (see below).  A copy of the license is included in the section entitled
89 ``GNU Free Documentation License''.
90
91 (a) The FSF's Front-Cover Text is:
92
93      A GNU Manual
94
95 (b) The FSF's Back-Cover Text is:
96
97      You have freedom to copy and modify this GNU Manual, like GNU
98      software.  Copies published by the Free Software Foundation raise
99      funds for GNU development.
100 @end copying
101
102 @ifinfo
103 @dircategory Software development
104 @direntry
105 * gfortran: (gfortran).                  The GNU Fortran Compiler.
106 @end direntry
107 This file documents the use and the internals of
108 the GNU Fortran compiler, (@command{gfortran}).
109
110 Published by the Free Software Foundation
111 51 Franklin Street, Fifth Floor
112 Boston, MA 02110-1301 USA
113
114 @insertcopying
115 @end ifinfo
116
117
118 @setchapternewpage odd
119 @titlepage
120 @title Using GNU Fortran
121 @versionsubtitle
122 @author The @t{gfortran} team
123 @page
124 @vskip 0pt plus 1filll
125 Published by the Free Software Foundation@*
126 51 Franklin Street, Fifth Floor@*
127 Boston, MA 02110-1301, USA@*
128 @c Last printed ??ber, 19??.@*
129 @c Printed copies are available for $? each.@*
130 @c ISBN ???
131 @sp 1
132 @insertcopying
133 @end titlepage
134
135 @c TODO: The following "Part" definitions are included here temporarily
136 @c until they are incorporated into the official Texinfo distribution.
137
138 @tex
139 \global\let\partentry=\dosmallpartentry
140 \global\let\blankpartentry=\dosmallblankpartentry
141 @end tex
142 @summarycontents
143
144 @tex
145 \global\let\partentry=\dopartentry
146 \global\let\blankpartentry=\doblankpartentry
147 @end tex
148 @contents
149
150 @page
151
152 @c ---------------------------------------------------------------------
153 @c TexInfo table of contents.
154 @c ---------------------------------------------------------------------
155
156 @ifnottex
157 @node Top
158 @top Introduction
159 @cindex Introduction
160
161 This manual documents the use of @command{gfortran}, 
162 the GNU Fortran compiler. You can find in this manual how to invoke
163 @command{gfortran}, as well as its features and incompatibilities.
164
165 @ifset DEVELOPMENT
166 @emph{Warning:} This document, and the compiler it describes, are still
167 under development.  While efforts are made to keep it up-to-date, it might
168 not accurately reflect the status of the most recent GNU Fortran compiler.
169 @end ifset
170
171 @comment
172 @comment  When you add a new menu item, please keep the right hand
173 @comment  aligned to the same column.  Do not use tabs.  This provides
174 @comment  better formatting.
175 @comment
176 @menu
177 * Introduction::
178
179 Part I: Invoking GNU Fortran
180 * Invoking GNU Fortran:: Command options supported by @command{gfortran}.
181 * Runtime::              Influencing runtime behavior with environment variables.
182
183 Part II: Language Reference
184 * Fortran 2003 status::  Fortran 2003 features supported by GNU Fortran.
185 * Extensions::           Language extensions implemented by GNU Fortran.
186 * Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
187
188 * Contributing::         How you can help.
189 * Copying::              GNU General Public License says
190                          how you can copy and share GNU Fortran.
191 * GNU Free Documentation License::
192                          How you can copy and share this manual.
193 * Funding::              How to help assure continued work for free software.
194 * Option Index::         Index of command line options
195 * Keyword Index::        Index of concepts
196 @end menu
197 @end ifnottex
198
199 @c ---------------------------------------------------------------------
200 @c Introduction
201 @c ---------------------------------------------------------------------
202
203 @node Introduction
204 @chapter Introduction
205
206 @c The following duplicates the text on the TexInfo table of contents.
207 @iftex
208 This manual documents the use of @command{gfortran}, the GNU Fortran
209 compiler. You can find in this manual how to invoke @command{gfortran},
210 as well as its features and incompatibilities.
211
212 @ifset DEVELOPMENT
213 @emph{Warning:} This document, and the compiler it describes, are still
214 under development.  While efforts are made to keep it up-to-date, it
215 might not accurately reflect the status of the most recent GNU Fortran
216 compiler.
217 @end ifset
218 @end iftex
219
220 The GNU Fortran compiler front end was
221 designed initially as a free replacement for,
222 or alternative to, the unix @command{f95} command;
223 @command{gfortran} is the command you'll use to invoke the compiler.
224
225 @menu
226 * About GNU Fortran::    What you should know about the GNU Fortran compiler.
227 * GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
228 * Preprocessing and conditional compilation:: The Fortran preprocessor
229 * GNU Fortran and G77::  Why we chose to start from scratch.
230 * Project Status::       Status of GNU Fortran, roadmap, proposed extensions.
231 * Standards::            Standards supported by GNU Fortran.
232 @end menu
233
234
235 @c ---------------------------------------------------------------------
236 @c About GNU Fortran
237 @c ---------------------------------------------------------------------
238
239 @node About GNU Fortran
240 @section About GNU Fortran
241
242 The GNU Fortran compiler is still in an early state of development.
243 It can generate code for most constructs and expressions,
244 but much work remains to be done.
245
246 When the GNU Fortran compiler is finished,
247 it will do everything you expect from any decent compiler: 
248
249 @itemize @bullet
250 @item
251 Read a user's program,
252 stored in a file and containing instructions written
253 in Fortran 77, Fortran 90, Fortran 95 or Fortran 2003.
254 This file contains @dfn{source code}.
255
256 @item
257 Translate the user's program into instructions a computer
258 can carry out more quickly than it takes to translate the
259 instructions in the first
260 place.  The result after compilation of a program is
261 @dfn{machine code},
262 code designed to be efficiently translated and processed
263 by a machine such as your computer.
264 Humans usually aren't as good writing machine code
265 as they are at writing Fortran (or C++, Ada, or Java),
266 because is easy to make tiny mistakes writing machine code.
267
268 @item
269 Provide the user with information about the reasons why
270 the compiler is unable to create a binary from the source code.
271 Usually this will be the case if the source code is flawed.
272 When writing Fortran, it is easy to make big mistakes.
273 The Fortran 90 requires that the compiler can point out
274 mistakes to the user.
275 An incorrect usage of the language causes an @dfn{error message}.
276
277 The compiler will also attempt to diagnose cases where the
278 user's program contains a correct usage of the language,
279 but instructs the computer to do something questionable.
280 This kind of diagnostics message is called a @dfn{warning message}.
281
282 @item
283 Provide optional information about the translation passes
284 from the source code to machine code.
285 This can help a user of the compiler to find the cause of
286 certain bugs which may not be obvious in the source code,
287 but may be more easily found at a lower level compiler output.
288 It also helps developers to find bugs in the compiler itself.
289
290 @item
291 Provide information in the generated machine code that can
292 make it easier to find bugs in the program (using a debugging tool,
293 called a @dfn{debugger}, such as the GNU Debugger @command{gdb}). 
294
295 @item
296 Locate and gather machine code already generated to
297 perform actions requested by statements in the user's program.
298 This machine code is organized into @dfn{modules} and is located
299 and @dfn{linked} to the user program. 
300 @end itemize
301
302 The GNU Fortran compiler consists of several components:
303
304 @itemize @bullet
305 @item
306 A version of the @command{gcc} command
307 (which also might be installed as the system's @command{cc} command)
308 that also understands and accepts Fortran source code.
309 The @command{gcc} command is the @dfn{driver} program for
310 all the languages in the GNU Compiler Collection (GCC);
311 With @command{gcc},
312 you can compile the source code of any language for
313 which a front end is available in GCC.
314
315 @item
316 The @command{gfortran} command itself,
317 which also might be installed as the
318 system's @command{f95} command.
319 @command{gfortran} is just another driver program,
320 but specifically for the Fortran compiler only.
321 The difference with @command{gcc} is that @command{gfortran}
322 will automatically link the correct libraries to your program.
323
324 @item
325 A collection of run-time libraries.
326 These libraries contain the machine code needed to support
327 capabilities of the Fortran language that are not directly
328 provided by the machine code generated by the
329 @command{gfortran} compilation phase,
330 such as intrinsic functions and subroutines,
331 and routines for interaction with files and the operating system.
332 @c and mechanisms to spawn,
333 @c unleash and pause threads in parallelized code.
334
335 @item
336 The Fortran compiler itself, (@command{f951}).
337 This is the GNU Fortran parser and code generator,
338 linked to and interfaced with the GCC backend library.
339 @command{f951} ``translates'' the source code to
340 assembler code.  You would typically not use this
341 program directly;
342 instead, the @command{gcc} or @command{gfortran} driver
343 programs will call it for you.
344 @end itemize
345
346
347 @c ---------------------------------------------------------------------
348 @c GNU Fortran and GCC
349 @c ---------------------------------------------------------------------
350
351 @node GNU Fortran and GCC
352 @section GNU Fortran and GCC
353 @cindex GNU Compiler Collection
354 @cindex GCC
355
356 GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
357 consists of a collection of front ends for various languages, which
358 translate the source code into a language-independent form called
359 @dfn{GENERIC}.  This is then processed by a common middle end which
360 provides optimization, and then passed to one of a collection of back
361 ends which generate code for different computer architectures and
362 operating systems.
363
364 Functionally, this is implemented with a driver program (@command{gcc})
365 which provides the command-line interface for the compiler.  It calls
366 the relevant compiler front-end program (e.g., @command{f951} for
367 Fortran) for each file in the source code, and then calls the assembler
368 and linker as appropriate to produce the compiled output. In a copy of
369 GCC which has been compiled with Fortran language support enabled,
370 @command{gcc} will recognize files with @file{.f}, @file{.f90}, @file{.f95},
371 and @file{.f03} extensions as Fortran source code, and compile it
372 accordingly.  A @command{gfortran} driver program is also provided,
373 which is identical to @command{gcc} except that it automatically links
374 the Fortran runtime libraries into the compiled program.
375
376 This manual specifically documents the Fortran front end, which handles
377 the programming language's syntax and semantics.  The aspects of GCC
378 which relate to the optimization passes and the back-end code generation
379 are documented in the GCC manual; see 
380 @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
381 The two manuals together provide a complete reference for the GNU
382 Fortran compiler.
383
384
385 @c ---------------------------------------------------------------------
386 @c Preprocessing and conditional compilation
387 @c ---------------------------------------------------------------------
388
389 @node Preprocessing and conditional compilation
390 @section Preprocessing and conditional compilation
391 @cindex CPP
392 @cindex FPP
393 @cindex Conditional compilation
394 @cindex Preprocessing
395
396 Many Fortran compilers including GNU Fortran allow to pass the source code
397 through a C preprocessor (CPP; sometimes also called Fortran preprocessor,
398 FPP) to allow for conditional compilation. In case of GNU Fortran
399 this is the GNU C Preprocessor in the traditional mode. On systems with
400 case-preserving file names, the preprocessor is automatically invoked if the
401 file extension is @code{.F}, @code{.F90}, @code{.F95} or @code{.F03};
402 otherwise use for fixed-format code the option @code{-x f77-cpp-input}
403 and for free-format code @code{-x f95-cpp-input}. Invocation of the
404 preprocessor can be suppressed using @code{-x f77} or @code{-x f95}.
405
406 If the GNU Fortran invoked the preprocessor, @code{__GFORTRAN__}
407 is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
408 @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
409 compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
410
411 While CPP is the de-facto standard for preprocessing Fortran code,
412 Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
413 Conditional Compilation, which is not widely used and not directly
414 supported by the GNU Fortran compiler. You can use the program coco
415 to preprocess such files (@uref{http://users.erols.com/dnagle/coco.html}).
416
417
418 @c ---------------------------------------------------------------------
419 @c GNU Fortran and G77
420 @c ---------------------------------------------------------------------
421
422 @node GNU Fortran and G77
423 @section GNU Fortran and G77
424 @cindex Fortran 77
425 @cindex @command{g77}
426
427 The GNU Fortran compiler is the successor to @command{g77}, the Fortran 
428 77 front end included in GCC prior to version 4.  It is an entirely new 
429 program that has been designed to provide Fortran 95 support and 
430 extensibility for future Fortran language standards, as well as providing 
431 backwards compatibility for Fortran 77 and nearly all of the GNU language 
432 extensions supported by @command{g77}.
433
434
435 @c ---------------------------------------------------------------------
436 @c Project Status
437 @c ---------------------------------------------------------------------
438
439 @node Project Status
440 @section Project Status
441
442 @quotation
443 As soon as @command{gfortran} can parse all of the statements correctly,
444 it will be in the ``larva'' state.
445 When we generate code, the ``puppa'' state.
446 When @command{gfortran} is done,
447 we'll see if it will be a beautiful butterfly,
448 or just a big bug....
449
450 --Andy Vaught, April 2000
451 @end quotation
452
453 The start of the GNU Fortran 95 project was announced on
454 the GCC homepage in March 18, 2000
455 (even though Andy had already been working on it for a while,
456 of course).
457
458 The GNU Fortran compiler is able to compile nearly all
459 standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
460 including a number of standard and non-standard extensions, and can be
461 used on real-world programs.  In particular, the supported extensions
462 include OpenMP, Cray-style pointers, and several Fortran 2003 features
463 such as enumeration, stream I/O, and some of the enhancements to
464 allocatable array support from TR 15581.  However, it is still under
465 development and has a few remaining rough edges.
466
467 At present, the GNU Fortran compiler passes the
468 @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html, 
469 NIST Fortran 77 Test Suite}, and produces acceptable results on the
470 @uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
471 It also provides respectable performance on 
472 the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
473 compiler benchmarks} and the
474 @uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
475 Livermore Fortran Kernels test}.  It has been used to compile a number of
476 large real-world programs, including
477 @uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
478 weather-forecasting code} and
479 @uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum 
480 chemistry package}; see @url{http://gcc.gnu.org/wiki/GfortranApps} for an
481 extended list.
482
483 Among other things, the GNU Fortran compiler is intended as a replacement
484 for G77.  At this point, nearly all programs that could be compiled with
485 G77 can be compiled with GNU Fortran, although there are a few minor known
486 regressions.
487
488 The primary work remaining to be done on GNU Fortran falls into three
489 categories: bug fixing (primarily regarding the treatment of invalid code
490 and providing useful error messages), improving the compiler optimizations
491 and the performance of compiled code, and extending the compiler to support
492 future standards---in particular, Fortran 2003.
493
494
495 @c ---------------------------------------------------------------------
496 @c Standards
497 @c ---------------------------------------------------------------------
498
499 @node Standards
500 @section Standards
501 @cindex Standards
502
503 The GNU Fortran compiler implements
504 ISO/IEC 1539:1997 (Fortran 95).  As such, it can also compile essentially all
505 standard-compliant Fortran 90 and Fortran 77 programs.   It also supports
506 the ISO/IEC TR-15581 enhancements to allocatable arrays, and
507 the @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
508 OpenMP Application Program Interface v2.5} specification.
509
510 In the future, the GNU Fortran compiler may also support other standard 
511 variants of and extensions to the Fortran language.  These include
512 ISO/IEC 1539-1:2004 (Fortran 2003).
513
514
515 @c =====================================================================
516 @c PART I: INVOCATION REFERENCE
517 @c =====================================================================
518
519 @tex
520 \part{I}{Invoking GNU Fortran}
521 @end tex
522
523 @c ---------------------------------------------------------------------
524 @c Compiler Options
525 @c ---------------------------------------------------------------------
526
527 @include invoke.texi
528
529
530 @c ---------------------------------------------------------------------
531 @c Runtime
532 @c ---------------------------------------------------------------------
533
534 @node Runtime
535 @chapter Runtime:  Influencing runtime behavior with environment variables
536 @cindex environment variable
537
538 The behavior of the @command{gfortran} can be influenced by
539 environment variables.
540
541 Malformed environment variables are silently ignored.
542
543 @menu
544 * GFORTRAN_STDIN_UNIT:: Unit number for standard input
545 * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
546 * GFORTRAN_STDERR_UNIT:: Unit number for standard error
547 * GFORTRAN_USE_STDERR:: Send library output to standard error
548 * GFORTRAN_TMPDIR:: Directory for scratch files
549 * GFORTRAN_UNBUFFERED_n:: Don't buffer I/O for specific unit.
550 * GFORTRAN_UNBUFFERED_ALL:: Don't buffer I/O for all units.
551 * GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
552 * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
553 * GFORTRAN_DEFAULT_RECL:: Default record length for new files
554 * GFORTRAN_LIST_SEPARATOR::  Separator for list output
555 * GFORTRAN_CONVERT_UNIT::  Set endianness for unformatted I/O
556 * GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors
557 * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
558 @end menu
559
560 @node GFORTRAN_STDIN_UNIT
561 @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
562
563 This environment variable can be used to select the unit number
564 preconnected to standard input.  This must be a positive integer.
565 The default value is 5.
566
567 @node GFORTRAN_STDOUT_UNIT
568 @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
569
570 This environment variable can be used to select the unit number
571 preconnected to standard output.  This must be a positive integer.
572 The default value is 6.
573
574 @node GFORTRAN_STDERR_UNIT
575 @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
576
577 This environment variable can be used to select the unit number
578 preconnected to standard error.  This must be a positive integer.
579 The default value is 0.
580
581 @node GFORTRAN_USE_STDERR
582 @section @env{GFORTRAN_USE_STDERR}---Send library output to standard error
583
584 This environment variable controls where library output is sent.
585 If the first letter is @samp{y}, @samp{Y} or @samp{1}, standard
586 error is used. If the first letter is @samp{n}, @samp{N} or
587 @samp{0}, standard output is used.
588
589 @node GFORTRAN_TMPDIR
590 @section @env{GFORTRAN_TMPDIR}---Directory for scratch files
591
592 This environment variable controls where scratch files are
593 created.  If this environment variable is missing,
594 GNU Fortran searches for the environment variable @env{TMP}.  If
595 this is also missing, the default is @file{/tmp}.
596
597 @node GFORTRAN_UNBUFFERED_n
598 @section @env{GFORTRAN_UNBUFFERED_n}---Don't buffer I/O on unit n
599
600 Environment variables named @env{GFORTRAN_UNBUFFERED_n}, where
601 @samp{n} is an integer, control whether I/O on unit @samp{n} is
602 unbuffered.  If the first letter is @samp{y}, @samp{Y} or @samp{1},
603 I/O is unbuffered. This will slow down small sequential reads and
604 writes.  If the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is
605 buffered.  This is the default.
606
607 @node GFORTRAN_UNBUFFERED_ALL
608 @section @env{GFORTRAN_UNBUFFERED_ALL}---Don't buffer I/O on all units
609
610 This environment variable controls whether all I/O is unbuffered.  If
611 the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
612 unbuffered. This will slow down small sequential reads and writes.  If
613 the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
614 This is the default.
615
616 @node GFORTRAN_SHOW_LOCUS
617 @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
618
619 If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
620 line numbers for runtime errors are printed.  If the first letter is
621 @samp{n}, @samp{N} or @samp{0}, don't print filename and line numbers
622 for runtime errors. The default is to print the location.
623
624 @node GFORTRAN_OPTIONAL_PLUS
625 @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
626
627 If the first letter is @samp{y}, @samp{Y} or @samp{1},
628 a plus sign is printed
629 where permitted by the Fortran standard.  If the first letter
630 is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
631 in most cases. Default is not to print plus signs.
632
633 @node GFORTRAN_DEFAULT_RECL
634 @section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
635
636 This environment variable specifies the default record length, in
637 bytes, for files which are opened without a @code{RECL} tag in the
638 @code{OPEN} statement.  This must be a positive integer.  The
639 default value is 1073741824 bytes (1 GB).
640
641 @node GFORTRAN_LIST_SEPARATOR
642 @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
643
644 This environment variable specifies the separator when writing
645 list-directed output.  It may contain any number of spaces and
646 at most one comma.  If you specify this on the command line,
647 be sure to quote spaces, as in
648 @smallexample
649 $ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
650 @end smallexample
651 when @command{a.out} is the compiled Fortran program that you want to run.
652 Default is a single space.
653
654 @node GFORTRAN_CONVERT_UNIT
655 @section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
656
657 By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
658 to change the representation of data for unformatted files.
659 The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
660 @smallexample
661 GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
662 mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
663 exception: mode ':' unit_list | unit_list ;
664 unit_list: unit_spec | unit_list unit_spec ;
665 unit_spec: INTEGER | INTEGER '-' INTEGER ;
666 @end smallexample
667 The variable consists of an optional default mode, followed by
668 a list of optional exceptions, which are separated by semicolons
669 from the preceding default and each other.  Each exception consists
670 of a format and a comma-separated list of units.  Valid values for
671 the modes are the same as for the @code{CONVERT} specifier:
672
673 @itemize @w{}
674 @item @code{NATIVE} Use the native format.  This is the default.
675 @item @code{SWAP} Swap between little- and big-endian.
676 @item @code{LITTLE_ENDIAN} Use the little-endian format
677         for unformatted files.
678 @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
679 @end itemize
680 A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
681 Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
682 @itemize @w{}
683 @item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
684 @item @code{'little_endian;native:10-20,25'}  Do all unformatted I/O 
685 in little_endian mode, except for units 10 to 20 and 25, which are in
686 native format.
687 @item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
688 @end itemize
689
690 Setting the environment variables should be done on the command
691 line or via the @command{export}
692 command for @command{sh}-compatible shells and via @command{setenv}
693 for @command{csh}-compatible shells.
694
695 Example for @command{sh}:
696 @smallexample
697 $ gfortran foo.f90
698 $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
699 @end smallexample
700
701 Example code for @command{csh}:
702 @smallexample
703 % gfortran foo.f90
704 % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
705 % ./a.out
706 @end smallexample
707
708 Using anything but the native representation for unformatted data
709 carries a significant speed overhead.  If speed in this area matters
710 to you, it is best if you use this only for data that needs to be
711 portable.
712
713 @xref{CONVERT specifier}, for an alternative way to specify the
714 data representation for unformatted files.  @xref{Runtime Options}, for
715 setting a default data representation for the whole program.  The
716 @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
717
718 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
719 environment variable will override the CONVERT specifier in the
720 open statement}.  This is to give control over data formats to
721 users who do not have the source code of their program available.
722
723 @node GFORTRAN_ERROR_DUMPCORE
724 @section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errors
725
726 If the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
727 @samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
728 then library run-time errors cause core dumps. To disable the core
729 dumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Default
730 is not to core dump unless the @option{-fdump-core} compile option
731 was used.
732
733 @node GFORTRAN_ERROR_BACKTRACE
734 @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
735
736 If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to
737 @samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
738 then a backtrace is printed when a run-time error occurs.
739 To disable the backtracing, set the variable to
740 @samp{n}, @samp{N}, @samp{0}. Default is not to print a backtrace
741 unless the @option{-fbacktrace} compile option
742 was used.
743
744 @c =====================================================================
745 @c PART II: LANGUAGE REFERENCE
746 @c =====================================================================
747
748 @tex
749 \part{II}{Language Reference}
750 @end tex
751
752 @c ---------------------------------------------------------------------
753 @c Fortran 2003 Status
754 @c ---------------------------------------------------------------------
755
756 @node Fortran 2003 status
757 @chapter Fortran 2003 Status
758
759 Although GNU Fortran focuses on implementing the Fortran 95
760 standard for the time being, a few Fortran 2003 features are currently
761 available.
762
763 @itemize
764 @item 
765 Intrinsics @code{command_argument_count}, @code{get_command},
766 @code{get_command_argument}, @code{get_environment_variable}, and
767 @code{move_alloc}.
768
769 @item 
770 @cindex array, constructors
771 @cindex @code{[...]}
772 Array constructors using square brackets. That is, @code{[...]} rather
773 than @code{(/.../)}.
774
775 @item
776 @cindex @code{FLUSH} statement
777 @cindex statement, @code{FLUSH}
778 @code{FLUSH} statement.
779
780 @item
781 @cindex @code{IOMSG=} specifier
782 @code{IOMSG=} specifier for I/O statements.
783
784 @item
785 @cindex @code{ENUM} statement
786 @cindex @code{ENUMERATOR} statement
787 @cindex statement, @code{ENUM}
788 @cindex statement, @code{ENUMERATOR}
789 @opindex @code{fshort-enums}
790 Support for the declaration of enumeration constants via the
791 @code{ENUM} and @code{ENUMERATOR} statements.  Interoperability with
792 @command{gcc} is guaranteed also for the case where the
793 @command{-fshort-enums} command line option is given.
794
795 @item
796 @cindex TR 15581
797 TR 15581:
798 @itemize
799 @item
800 @cindex @code{ALLOCATABLE} dummy arguments
801 @code{ALLOCATABLE} dummy arguments.
802 @item
803 @cindex @code{ALLOCATABLE} function results
804 @code{ALLOCATABLE} function results
805 @item
806 @cindex @code{ALLOCATABLE} components of derived types
807 @code{ALLOCATABLE} components of derived types
808 @end itemize
809
810 @item
811 @cindex @code{STREAM} I/O
812 @cindex @code{ACCESS='STREAM'} I/O
813 The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
814 allowing I/O without any record structure.
815
816 @item
817 Namelist input/output for internal files.
818
819 @item
820 @cindex @code{PROTECTED} statement
821 @cindex statement, @code{PROTECTED}
822 The @code{PROTECTED} statement and attribute.
823
824 @item
825 @cindex @code{VALUE} statement
826 @cindex statement, @code{VALUE}
827 The @code{VALUE} statement and attribute.
828
829 @item
830 @cindex @code{VOLATILE} statement
831 @cindex statement, @code{VOLATILE}
832 The @code{VOLATILE} statement and attribute.
833
834 @item
835 @cindex @code{IMPORT} statement
836 @cindex statement, @code{IMPORT}
837 The @code{IMPORT} statement, allowing to import
838 host-associated derived types.
839
840 @item
841 @cindex @code{USE, INTRINSIC} statement
842 @cindex statement, @code{USE, INTRINSIC}
843 @cindex @code{ISO_FORTRAN_ENV} statement
844 @cindex statement, @code{ISO_FORTRAN_ENV}
845 @code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
846 attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
847 @code{OMP_LIB} and @code{OMP_LIB_KINDS}.
848
849 @item
850 Renaming of operators in the @code{USE} statement.
851
852 @item
853 @cindex ISO C Bindings
854 Interoperability with C (ISO C Bindings)
855
856 @end itemize
857
858
859 @c ---------------------------------------------------------------------
860 @c Extensions
861 @c ---------------------------------------------------------------------
862
863 @c Maybe this chapter should be merged with the 'Standards' section,
864 @c whenever that is written :-)
865
866 @node Extensions
867 @chapter Extensions
868 @cindex Extension
869
870 GNU Fortran implements a number of extensions over standard
871 Fortran. This chapter contains information on their syntax and
872 meaning.  There are currently two categories of GNU Fortran
873 extensions, those that provide functionality beyond that provided
874 by any standard, and those that are supported by GNU Fortran
875 purely for backward compatibility with legacy compilers.  By default,
876 @option{-std=gnu} allows the compiler to accept both types of
877 extensions, but to warn about the use of the latter.  Specifying
878 either @option{-std=f95} or @option{-std=f2003} disables both types
879 of extensions, and @option{-std=legacy} allows both without warning.
880
881 @menu
882 * Old-style kind specifications::
883 * Old-style variable initialization::
884 * Extensions to namelist::
885 * X format descriptor without count field::
886 * Commas in FORMAT specifications::
887 * Missing period in FORMAT specifications::
888 * I/O item lists::
889 * BOZ literal constants::
890 * Real array indices::
891 * Unary operators::
892 * Implicitly convert LOGICAL and INTEGER values::
893 * Hollerith constants support::
894 * Cray pointers::
895 * CONVERT specifier::
896 * OpenMP::
897 * Argument list functions::
898 @end menu
899
900 @node Old-style kind specifications
901 @section Old-style kind specifications
902 @cindex kind, old-style
903
904 GNU Fortran allows old-style kind specifications in declarations. These
905 look like:
906 @smallexample
907       TYPESPEC*size x,y,z
908 @end smallexample
909 @noindent
910 where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
911 etc.), and where @code{size} is a byte count corresponding to the
912 storage size of a valid kind for that type.  (For @code{COMPLEX}
913 variables, @code{size} is the total size of the real and imaginary
914 parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
915 be of type @code{TYPESPEC} with the appropriate kind.  This is
916 equivalent to the standard-conforming declaration
917 @smallexample
918       TYPESPEC(k) x,y,z
919 @end smallexample
920 @noindent
921 where @code{k} is equal to @code{size} for most types, but is equal to
922 @code{size/2} for the @code{COMPLEX} type.
923
924 @node Old-style variable initialization
925 @section Old-style variable initialization
926
927 GNU Fortran allows old-style initialization of variables of the
928 form:
929 @smallexample
930       INTEGER i/1/,j/2/
931       REAL x(2,2) /3*0.,1./
932 @end smallexample
933 The syntax for the initializers is as for the @code{DATA} statement, but
934 unlike in a @code{DATA} statement, an initializer only applies to the
935 variable immediately preceding the initialization.  In other words,
936 something like @code{INTEGER I,J/2,3/} is not valid.  This style of
937 initialization is only allowed in declarations without double colons
938 (@code{::}); the double colons were introduced in Fortran 90, which also
939 introduced a standard syntax for initializing variables in type
940 declarations.
941
942 Examples of standard-conforming code equivalent to the above example
943 are:
944 @smallexample
945 ! Fortran 90
946       INTEGER :: i = 1, j = 2
947       REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
948 ! Fortran 77
949       INTEGER i, j
950       REAL x(2,2)
951       DATA i/1/, j/2/, x/3*0.,1./
952 @end smallexample
953
954 Note that variables which are explicitly initialized in declarations
955 or in @code{DATA} statements automatically acquire the @code{SAVE}
956 attribute.
957
958 @node Extensions to namelist
959 @section Extensions to namelist
960 @cindex Namelist
961
962 GNU Fortran fully supports the Fortran 95 standard for namelist I/O
963 including array qualifiers, substrings and fully qualified derived types.
964 The output from a namelist write is compatible with namelist read.  The
965 output has all names in upper case and indentation to column 1 after the
966 namelist name.  Two extensions are permitted:
967
968 Old-style use of @samp{$} instead of @samp{&}
969 @smallexample
970 $MYNML
971  X(:)%Y(2) = 1.0 2.0 3.0
972  CH(1:4) = "abcd"
973 $END
974 @end smallexample
975
976 It should be noted that the default terminator is @samp{/} rather than
977 @samp{&END}.
978
979 Querying of the namelist when inputting from stdin. After at least
980 one space, entering @samp{?} sends to stdout the namelist name and the names of
981 the variables in the namelist:
982 @smallexample
983  ?
984
985 &mynml
986  x
987  x%y
988  ch
989 &end
990 @end smallexample
991
992 Entering @samp{=?} outputs the namelist to stdout, as if
993 @code{WRITE(*,NML = mynml)} had been called:
994 @smallexample
995 =?
996
997 &MYNML
998  X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
999  X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
1000  X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
1001  CH=abcd,  /
1002 @end smallexample
1003
1004 To aid this dialog, when input is from stdin, errors send their
1005 messages to stderr and execution continues, even if @code{IOSTAT} is set.
1006
1007 @code{PRINT} namelist is permitted.  This causes an error if
1008 @option{-std=f95} is used.
1009 @smallexample
1010 PROGRAM test_print
1011   REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
1012   NAMELIST /mynml/ x
1013   PRINT mynml
1014 END PROGRAM test_print
1015 @end smallexample
1016
1017 Expanded namelist reads are permitted.  This causes an error if 
1018 @option{-std=f95} is used.  In the following example, the first element
1019 of the array will be given the value 0.00 and the two succeeding
1020 elements will be given the values 1.00 and 2.00.
1021 @smallexample
1022 &MYNML
1023   X(1,1) = 0.00 , 1.00 , 2.00
1024 /
1025 @end smallexample
1026
1027 @node X format descriptor without count field
1028 @section @code{X} format descriptor without count field
1029
1030 To support legacy codes, GNU Fortran permits the count field of the
1031 @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1032 When omitted, the count is implicitly assumed to be one.
1033
1034 @smallexample
1035        PRINT 10, 2, 3
1036 10     FORMAT (I1, X, I1)
1037 @end smallexample
1038
1039 @node Commas in FORMAT specifications
1040 @section Commas in @code{FORMAT} specifications
1041
1042 To support legacy codes, GNU Fortran allows the comma separator
1043 to be omitted immediately before and after character string edit
1044 descriptors in @code{FORMAT} statements.
1045
1046 @smallexample
1047        PRINT 10, 2, 3
1048 10     FORMAT ('FOO='I1' BAR='I2)
1049 @end smallexample
1050
1051
1052 @node Missing period in FORMAT specifications
1053 @section Missing period in @code{FORMAT} specifications
1054
1055 To support legacy codes, GNU Fortran allows missing periods in format
1056 specifications if and only if @option{-std=legacy} is given on the
1057 command line.  This is considered non-conforming code and is
1058 discouraged.
1059
1060 @smallexample
1061        REAL :: value
1062        READ(*,10) value
1063 10     FORMAT ('F4')
1064 @end smallexample
1065
1066 @node I/O item lists
1067 @section I/O item lists
1068 @cindex I/O item lists
1069
1070 To support legacy codes, GNU Fortran allows the input item list
1071 of the @code{READ} statement, and the output item lists of the
1072 @code{WRITE} and @code{PRINT} statements, to start with a comma.
1073
1074 @node BOZ literal constants
1075 @section BOZ literal constants
1076 @cindex BOZ literal constants
1077
1078 As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
1079 be specified using the X prefix, in addition to the standard Z prefix.
1080 BOZ literal constants can also be specified by adding a suffix to the
1081 string. For example, @code{Z'ABC'} and @code{'ABC'Z} are equivalent.
1082
1083 The Fortran standard restricts the appearance of a BOZ literal constant
1084 to the @code{DATA} statement, and it is expected to be assigned to an
1085 @code{INTEGER} variable.  GNU Fortran permits a BOZ literal to appear in
1086 any initialization expression as well as assignment statements.
1087
1088 Attempts to use a BOZ literal constant to do a bitwise initialization of
1089 a variable can lead to confusion.  A BOZ literal constant is converted
1090 to an @code{INTEGER} value with the kind type with the largest decimal
1091 representation, and this value is then converted numerically to the type
1092 and kind of the variable in question.  Thus, one should not expect a
1093 bitwise copy of the BOZ literal constant to be assigned to a @code{REAL}
1094 variable.
1095
1096 Similarly, initializing an @code{INTEGER} variable with a statement such
1097 as @code{DATA i/Z'FFFFFFFF'/} will produce an integer overflow rather
1098 than the desired result of @math{-1} when @code{i} is a 32-bit integer
1099 on a system that supports 64-bit integers.  The @samp{-fno-range-check}
1100 option can be used as a workaround for legacy code that initializes
1101 integers in this manner.
1102
1103 @node Real array indices
1104 @section Real array indices
1105 @cindex array, indices of type real
1106
1107 As an extension, GNU Fortran allows the use of @code{REAL} expressions
1108 or variables as array indices.
1109
1110 @node Unary operators
1111 @section Unary operators
1112 @cindex operators, unary
1113
1114 As an extension, GNU Fortran allows unary plus and unary minus operators
1115 to appear as the second operand of binary arithmetic operators without
1116 the need for parenthesis.
1117
1118 @smallexample
1119        X = Y * -Z
1120 @end smallexample
1121
1122 @node Implicitly convert LOGICAL and INTEGER values
1123 @section Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1124 @cindex conversion, to integer
1125 @cindex conversion, to logical
1126
1127 As an extension for backwards compatibility with other compilers, GNU
1128 Fortran allows the implicit conversion of @code{LOGICAL} values to
1129 @code{INTEGER} values and vice versa.  When converting from a
1130 @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1131 zero, and @code{.TRUE.} is interpreted as one.  When converting from
1132 @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1133 @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1134
1135 @smallexample
1136        INTEGER :: i = 1
1137        IF (i) PRINT *, 'True'
1138 @end smallexample
1139
1140 @node Hollerith constants support
1141 @section Hollerith constants support
1142 @cindex Hollerith constants
1143
1144 GNU Fortran supports Hollerith constants in assignments, function
1145 arguments, and @code{DATA} and @code{ASSIGN} statements.  A Hollerith
1146 constant is written as a string of characters preceded by an integer
1147 constant indicating the character count, and the letter @code{H} or
1148 @code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
1149 @code{REAL}, or @code{complex}) or @code{LOGICAL} variable.  The
1150 constant will be padded or truncated to fit the size of the variable in
1151 which it is stored.
1152
1153 Examples of valid uses of Hollerith constants:
1154 @smallexample
1155       complex*16 x(2)
1156       data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1157       x(1) = 16HABCDEFGHIJKLMNOP
1158       call foo (4h abc)
1159 @end smallexample
1160
1161 Invalid Hollerith constants examples:
1162 @smallexample
1163       integer*4 a
1164       a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1165       a = 0H         ! At least one character is needed.
1166 @end smallexample
1167
1168 In general, Hollerith constants were used to provide a rudimentary
1169 facility for handling character strings in early Fortran compilers,
1170 prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1171 in those cases, the standard-compliant equivalent is to convert the
1172 program to use proper character strings.  On occasion, there may be a
1173 case where the intent is specifically to initialize a numeric variable
1174 with a given byte sequence.  In these cases, the same result can be
1175 obtained by using the @code{TRANSFER} statement, as in this example.
1176 @smallexample
1177       INTEGER(KIND=4) :: a
1178       a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
1179 @end smallexample
1180
1181
1182 @node Cray pointers
1183 @section Cray pointers
1184 @cindex pointer, cray
1185
1186 Cray pointers are part of a non-standard extension that provides a
1187 C-like pointer in Fortran.  This is accomplished through a pair of
1188 variables: an integer "pointer" that holds a memory address, and a
1189 "pointee" that is used to dereference the pointer.
1190
1191 Pointer/pointee pairs are declared in statements of the form:
1192 @smallexample
1193         pointer ( <pointer> , <pointee> )
1194 @end smallexample
1195 or,
1196 @smallexample
1197         pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1198 @end smallexample
1199 The pointer is an integer that is intended to hold a memory address.
1200 The pointee may be an array or scalar.  A pointee can be an assumed
1201 size array---that is, the last dimension may be left unspecified by
1202 using a @code{*} in place of a value---but a pointee cannot be an
1203 assumed shape array.  No space is allocated for the pointee.
1204
1205 The pointee may have its type declared before or after the pointer
1206 statement, and its array specification (if any) may be declared
1207 before, during, or after the pointer statement.  The pointer may be
1208 declared as an integer prior to the pointer statement.  However, some
1209 machines have default integer sizes that are different than the size
1210 of a pointer, and so the following code is not portable:
1211 @smallexample
1212         integer ipt
1213         pointer (ipt, iarr)
1214 @end smallexample
1215 If a pointer is declared with a kind that is too small, the compiler
1216 will issue a warning; the resulting binary will probably not work
1217 correctly, because the memory addresses stored in the pointers may be
1218 truncated.  It is safer to omit the first line of the above example;
1219 if explicit declaration of ipt's type is omitted, then the compiler
1220 will ensure that ipt is an integer variable large enough to hold a
1221 pointer.
1222
1223 Pointer arithmetic is valid with Cray pointers, but it is not the same
1224 as C pointer arithmetic.  Cray pointers are just ordinary integers, so
1225 the user is responsible for determining how many bytes to add to a
1226 pointer in order to increment it.  Consider the following example:
1227 @smallexample
1228         real target(10)
1229         real pointee(10)
1230         pointer (ipt, pointee)
1231         ipt = loc (target)
1232         ipt = ipt + 1       
1233 @end smallexample
1234 The last statement does not set @code{ipt} to the address of
1235 @code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
1236 to @code{ipt} just adds one byte to the address stored in @code{ipt}.
1237
1238 Any expression involving the pointee will be translated to use the
1239 value stored in the pointer as the base address.
1240
1241 To get the address of elements, this extension provides an intrinsic
1242 function @code{LOC()}.  The @code{LOC()} function is equivalent to the
1243 @code{&} operator in C, except the address is cast to an integer type:
1244 @smallexample
1245         real ar(10)
1246         pointer(ipt, arpte(10))
1247         real arpte
1248         ipt = loc(ar)  ! Makes arpte is an alias for ar
1249         arpte(1) = 1.0 ! Sets ar(1) to 1.0
1250 @end smallexample
1251 The pointer can also be set by a call to the @code{MALLOC} intrinsic
1252 (see @ref{MALLOC}).
1253
1254 Cray pointees often are used to alias an existing variable.  For
1255 example:
1256 @smallexample
1257         integer target(10)
1258         integer iarr(10)
1259         pointer (ipt, iarr)
1260         ipt = loc(target)
1261 @end smallexample
1262 As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1263 @code{target}. The optimizer, however, will not detect this aliasing, so
1264 it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
1265 a pointee in any way that violates the Fortran aliasing rules or
1266 assumptions is illegal. It is the user's responsibility to avoid doing
1267 this; the compiler works under the assumption that no such aliasing
1268 occurs.
1269
1270 Cray pointers will work correctly when there is no aliasing (i.e., when
1271 they are used to access a dynamically allocated block of memory), and
1272 also in any routine where a pointee is used, but any variable with which
1273 it shares storage is not used.  Code that violates these rules may not
1274 run as the user intends.  This is not a bug in the optimizer; any code
1275 that violates the aliasing rules is illegal.  (Note that this is not
1276 unique to GNU Fortran; any Fortran compiler that supports Cray pointers
1277 will ``incorrectly'' optimize code with illegal aliasing.)
1278
1279 There are a number of restrictions on the attributes that can be applied
1280 to Cray pointers and pointees.  Pointees may not have the
1281 @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
1282 @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
1283 may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
1284 @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes.
1285 Pointees may not occur in more than one pointer statement.  A pointee
1286 cannot be a pointer.  Pointees cannot occur in equivalence, common, or
1287 data statements.
1288
1289 A Cray pointer may also point to a function or a subroutine.  For
1290 example, the following excerpt is valid:
1291 @smallexample
1292   implicit none
1293   external sub
1294   pointer (subptr,subpte)
1295   external subpte
1296   subptr = loc(sub)
1297   call subpte()
1298   [...]
1299   subroutine sub
1300   [...]
1301   end subroutine sub
1302 @end smallexample
1303
1304 A pointer may be modified during the course of a program, and this
1305 will change the location to which the pointee refers.  However, when
1306 pointees are passed as arguments, they are treated as ordinary
1307 variables in the invoked function.  Subsequent changes to the pointer
1308 will not change the base address of the array that was passed.
1309
1310 @node CONVERT specifier
1311 @section CONVERT specifier
1312 @cindex CONVERT specifier
1313
1314 GNU Fortran allows the conversion of unformatted data between little-
1315 and big-endian representation to facilitate moving of data
1316 between different systems.  The conversion can be indicated with
1317 the @code{CONVERT} specifier on the @code{OPEN} statement.
1318 @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
1319 the data format via an environment variable.
1320
1321 Valid values for @code{CONVERT} are:
1322 @itemize @w{}
1323 @item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
1324 @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
1325 @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
1326         for unformatted files.
1327 @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
1328         unformatted files.
1329 @end itemize
1330
1331 Using the option could look like this:
1332 @smallexample
1333   open(file='big.dat',form='unformatted',access='sequential', &
1334        convert='big_endian')
1335 @end smallexample
1336
1337 The value of the conversion can be queried by using
1338 @code{INQUIRE(CONVERT=ch)}.  The values returned are
1339 @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
1340
1341 @code{CONVERT} works between big- and little-endian for
1342 @code{INTEGER} values of all supported kinds and for @code{REAL}
1343 on IEEE systems of kinds 4 and 8.  Conversion between different
1344 ``extended double'' types on different architectures such as
1345 m68k and x86_64, which GNU Fortran
1346 supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
1347 probably not work.
1348
1349 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
1350 environment variable will override the CONVERT specifier in the
1351 open statement}.  This is to give control over data formats to
1352 users who do not have the source code of their program available.
1353
1354 Using anything but the native representation for unformatted data
1355 carries a significant speed overhead.  If speed in this area matters
1356 to you, it is best if you use this only for data that needs to be
1357 portable.
1358
1359 @node OpenMP
1360 @section OpenMP
1361 @cindex OpenMP
1362
1363 GNU Fortran attempts to be OpenMP Application Program Interface v2.5
1364 compatible when invoked with the @option{-fopenmp} option.  GNU Fortran
1365 then generates parallelized code according to the OpenMP directives
1366 used in the source.  The OpenMP Fortran runtime library
1367 routines are provided both in a form of a Fortran 90 module named
1368 @code{omp_lib} and in a form of a Fortran @code{include} file named
1369 @file{omp_lib.h}.
1370
1371 For details refer to the actual
1372 @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
1373 OpenMP Application Program Interface v2.5} specification.
1374
1375 @node Argument list functions
1376 @section Argument list functions %VAL, %REF and %LOC
1377 @cindex argument list functions
1378 @cindex %VAL
1379 @cindex %REF
1380 @cindex %LOC
1381
1382 GNU Fortran supports argument list functions @code{%VAL}, @code{%REF} 
1383 and @code{%LOC} statements, for backward compatibility with g77. 
1384 It is recommended that these should be used only for code that is 
1385 accessing facilities outside of GNU Fortran, such as operating system 
1386 or windowing facilities. It is best to constrain such uses to isolated 
1387 portions of a program--portions that deal specifically and exclusively 
1388 with low-level, system-dependent facilities. Such portions might well 
1389 provide a portable interface for use by the program as a whole, but are 
1390 themselves not portable, and should be thoroughly tested each time they 
1391 are rebuilt using a new compiler or version of a compiler.
1392
1393 @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by 
1394 reference and @code{%LOC} passes its memory location.  Since gfortran 
1395 already passes scalar arguments by reference, @code{%REF} is in effect 
1396 a do-nothing.  @code{%LOC} has the same effect as a fortran pointer.
1397
1398 An example of passing an argument by value to a C subroutine foo.:
1399 @smallexample
1400 C
1401 C prototype      void foo_ (float x);
1402 C
1403       external foo
1404       real*4 x
1405       x = 3.14159
1406       call foo (%VAL (x))
1407       end
1408 @end smallexample
1409
1410 For details refer to the g77 manual
1411 @uref{http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top}.
1412
1413 Also, the gfortran testsuite c_by_val.f and its partner c_by_val.c are
1414 worth a look.
1415
1416 @c ---------------------------------------------------------------------
1417 @c Intrinsic Procedures
1418 @c ---------------------------------------------------------------------
1419
1420 @include intrinsic.texi
1421
1422
1423 @tex
1424 \blankpart
1425 @end tex
1426
1427 @c ---------------------------------------------------------------------
1428 @c Contributing
1429 @c ---------------------------------------------------------------------
1430
1431 @node Contributing
1432 @unnumbered Contributing
1433 @cindex Contributing
1434
1435 Free software is only possible if people contribute to efforts
1436 to create it.
1437 We're always in need of more people helping out with ideas
1438 and comments, writing documentation and contributing code.
1439
1440 If you want to contribute to GNU Fortran,
1441 have a look at the long lists of projects you can take on.
1442 Some of these projects are small,
1443 some of them are large;
1444 some are completely orthogonal to the rest of what is
1445 happening on GNU Fortran,
1446 but others are ``mainstream'' projects in need of enthusiastic hackers.
1447 All of these projects are important!
1448 We'll eventually get around to the things here,
1449 but they are also things doable by someone who is willing and able.
1450
1451 @menu
1452 * Contributors::
1453 * Projects::
1454 * Proposed Extensions::
1455 @end menu
1456
1457
1458 @node Contributors
1459 @section Contributors to GNU Fortran
1460 @cindex Contributors
1461 @cindex Credits
1462 @cindex Authors
1463
1464 Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
1465 also the initiator of the whole project.  Thanks Andy!
1466 Most of the interface with GCC was written by @emph{Paul Brook}.
1467
1468 The following individuals have contributed code and/or
1469 ideas and significant help to the GNU Fortran project
1470 (in no particular order):
1471
1472 @itemize @minus
1473 @item Andy Vaught
1474 @item Katherine Holcomb
1475 @item Tobias Schl@"uter
1476 @item Steven Bosscher
1477 @item Toon Moene
1478 @item Tim Prince
1479 @item Niels Kristian Bech Jensen
1480 @item Steven Johnson
1481 @item Paul Brook
1482 @item Feng Wang
1483 @item Bud Davis
1484 @item Paul Thomas
1485 @item Fran@,{c}ois-Xavier Coudert
1486 @item Steven G. Kargl
1487 @item Jerry Delisle
1488 @item Janne Blomqvist
1489 @item Erik Edelmann
1490 @item Thomas Koenig
1491 @item Asher Langton
1492 @item Jakub Jelinek
1493 @item Roger Sayle
1494 @item H.J. Lu
1495 @item Richard Henderson
1496 @item Richard Sandiford
1497 @item Richard Guenther
1498 @item Bernhard Fischer
1499 @end itemize
1500
1501 The following people have contributed bug reports,
1502 smaller or larger patches,
1503 and much needed feedback and encouragement for the
1504 GNU Fortran project: 
1505
1506 @itemize @minus
1507 @item Erik Schnetter
1508 @item Bill Clodius
1509 @item Kate Hedstrom
1510 @end itemize
1511
1512 Many other individuals have helped debug,
1513 test and improve the GNU Fortran compiler over the past few years,
1514 and we welcome you to do the same!
1515 If you already have done so,
1516 and you would like to see your name listed in the
1517 list above, please contact us.
1518
1519
1520 @node Projects
1521 @section Projects
1522
1523 @table @emph
1524
1525 @item Help build the test suite
1526 Solicit more code for donation to the test suite.
1527 We can keep code private on request.
1528
1529 @item Bug hunting/squishing
1530 Find bugs and write more test cases!
1531 Test cases are especially very welcome,
1532 because it allows us to concentrate on fixing bugs
1533 instead of isolating them.
1534
1535 @item Smaller projects (``bug'' fixes):
1536   @itemize @minus
1537   @item Allow init exprs to be numbers raised to integer powers.
1538   @item Implement correct rounding.
1539   @item Implement F restrictions on Fortran 95 syntax.
1540   @item See about making Emacs-parsable error messages.
1541   @end itemize
1542 @end table
1543
1544 If you wish to work on the runtime libraries,
1545 please contact a project maintainer.
1546 @c TODO: email!
1547
1548
1549 @node Proposed Extensions
1550 @section Proposed Extensions
1551
1552 Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
1553 order.  Most of these are necessary to be fully compatible with
1554 existing Fortran compilers, but they are not part of the official
1555 J3 Fortran 95 standard.
1556
1557 @subsection Compiler extensions: 
1558 @itemize @bullet
1559 @item
1560 User-specified alignment rules for structures.
1561
1562 @item
1563 Flag to generate @code{Makefile} info.
1564
1565 @item
1566 Automatically extend single precision constants to double.
1567
1568 @item
1569 Compile code that conserves memory by dynamically allocating common and
1570 module storage either on stack or heap.
1571
1572 @item
1573 Compile flag to generate code for array conformance checking (suggest -CC).
1574
1575 @item
1576 User control of symbol names (underscores, etc).
1577
1578 @item
1579 Compile setting for maximum size of stack frame size before spilling
1580 parts to static or heap.
1581
1582 @item
1583 Flag to force local variables into static space.
1584
1585 @item
1586 Flag to force local variables onto stack.
1587
1588 @item
1589 Flag for maximum errors before ending compile.
1590
1591 @item
1592 Option to initialize otherwise uninitialized integer and floating
1593 point variables.
1594 @end itemize
1595
1596
1597 @subsection Environment Options
1598 @itemize @bullet
1599 @item
1600 Pluggable library modules for random numbers, linear algebra.
1601 LA should use BLAS calling conventions.
1602
1603 @item
1604 Environment variables controlling actions on arithmetic exceptions like
1605 overflow, underflow, precision loss---Generate NaN, abort, default.
1606 action.
1607
1608 @item
1609 Set precision for fp units that support it (i387).
1610
1611 @item
1612 Variable for setting fp rounding mode.
1613
1614 @item
1615 Variable to fill uninitialized variables with a user-defined bit
1616 pattern.
1617
1618 @item
1619 Environment variable controlling filename that is opened for that unit
1620 number.
1621
1622 @item
1623 Environment variable to clear/trash memory being freed.
1624
1625 @item
1626 Environment variable to control tracing of allocations and frees.
1627
1628 @item
1629 Environment variable to display allocated memory at normal program end.
1630
1631 @item
1632 Environment variable for filename for * IO-unit.
1633
1634 @item
1635 Environment variable for temporary file directory.
1636
1637 @item
1638 Environment variable forcing standard output to be line buffered (unix).
1639
1640 @end itemize
1641
1642
1643 @c ---------------------------------------------------------------------
1644 @c GNU General Public License
1645 @c ---------------------------------------------------------------------
1646
1647 @include gpl.texi
1648
1649
1650
1651 @c ---------------------------------------------------------------------
1652 @c GNU Free Documentation License
1653 @c ---------------------------------------------------------------------
1654
1655 @include fdl.texi
1656
1657
1658
1659 @c ---------------------------------------------------------------------
1660 @c Funding Free Software
1661 @c ---------------------------------------------------------------------
1662
1663 @include funding.texi
1664
1665 @c ---------------------------------------------------------------------
1666 @c Indices
1667 @c ---------------------------------------------------------------------
1668
1669 @node Option Index
1670 @unnumbered Option Index
1671 @command{gfortran}'s command line options are indexed here without any
1672 initial @samp{-} or @samp{--}. Where an option has both positive and
1673 negative forms (such as -foption and -fno-option), relevant entries in
1674 the manual are indexed under the most appropriate form; it may sometimes
1675 be useful to look up both forms.
1676 @printindex op
1677
1678 @node Keyword Index
1679 @unnumbered Keyword Index
1680 @printindex cp
1681
1682 @bye