OSDN Git Service

Separate user and internals manuals.
[pf3gnuchains/gcc-fork.git] / gcc / f / g77.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename g77.info
4
5 @set last-update 2001-11-20
6 @set copyrights-g77 1995,1996,1997,1998,1999,2000,2001
7
8 @include root.texi
9
10 @c This tells @include'd files that they're part of the overall G77 doc
11 @c set.  (They might be part of a higher-level doc set too.)
12 @set DOC-G77
13
14 @c @setfilename useg77.info
15 @c @setfilename portg77.info
16 @c To produce the full manual, use the "g77.info" setfilename, and
17 @c make sure the following do NOT begin with '@c' (and the @clear lines DO)
18 @set INTERNALS
19 @set USING
20 @c To produce a user-only manual, use the "useg77.info" setfilename, and
21 @c make sure the following does NOT begin with '@c':
22 @c @clear INTERNALS
23 @c To produce a porter-only manual, use the "portg77.info" setfilename,
24 @c and make sure the following does NOT begin with '@c':
25 @c @clear USING
26
27 @c 6/27/96 FSF DO wants smallbook fmt for 1st bound edition. (from gcc.texi)
28 @c @smallbook
29
30 @c i also commented out the finalout command, so if there *are* any
31 @c overfulls, you'll (hopefully) see the rectangle in the right hand
32 @c margin. -- burley 1999-03-13 (from mew's comment in gcc.texi).
33 @c @finalout
34
35 @macro gcctabopt{body}
36 @code{\body\}
37 @end macro
38 @macro gccoptlist{body}
39 @smallexample
40 \body\
41 @end smallexample
42 @end macro
43 @c Makeinfo handles the above macro OK, TeX needs manual line breaks;
44 @c they get lost at some point in handling the macro.  But if @macro is
45 @c used here rather than @alias, it produces double line breaks.
46 @iftex
47 @alias gol = *
48 @end iftex
49 @ifnottex
50 @macro gol
51 @end macro
52 @end ifnottex
53
54 @ifset INTERNALS
55 @ifset USING
56 @settitle Using and Porting GNU Fortran
57 @end ifset
58 @end ifset
59 @c seems reasonable to assume at least one of INTERNALS or USING is set...
60 @ifclear INTERNALS
61 @settitle Using GNU Fortran
62 @end ifclear
63 @ifclear USING
64 @settitle Porting GNU Fortran
65 @end ifclear
66 @c then again, have some fun
67 @ifclear INTERNALS
68 @ifclear USING
69 @settitle Doing Squat with GNU Fortran
70 @end ifclear
71 @end ifclear
72
73 @syncodeindex fn cp
74 @syncodeindex vr cp
75 @c %**end of header
76
77 @c Cause even numbered pages to be printed on the left hand side of
78 @c the page and odd numbered pages to be printed on the right hand
79 @c side of the page.  Using this, you can print on both sides of a
80 @c sheet of paper and have the text on the same part of the sheet.
81
82 @c The text on right hand pages is pushed towards the right hand
83 @c margin and the text on left hand pages is pushed toward the left
84 @c hand margin.
85 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
86
87 @c @tex
88 @c \global\bindingoffset=0.75in
89 @c \global\normaloffset =0.75in
90 @c @end tex
91
92 @ifinfo
93 @dircategory Programming
94 @direntry
95 * g77: (g77).                  The GNU Fortran compiler.
96 @end direntry
97 @ifset INTERNALS
98 @ifset USING
99 This file documents the use and the internals of the GNU Fortran (@command{g77})
100 compiler.
101 It corresponds to the @value{which-g77} version of @command{g77}.
102 @end ifset
103 @end ifset
104 @ifclear USING
105 This file documents the internals of the GNU Fortran (@command{g77}) compiler.
106 It corresponds to the @value{which-g77} version of @command{g77}.
107 @end ifclear
108 @ifclear INTERNALS
109 This file documents the use of the GNU Fortran (@command{g77}) compiler.
110 It corresponds to the @value{which-g77} version of @command{g77}.
111 @end ifclear
112
113 Published by the Free Software Foundation
114 59 Temple Place - Suite 330
115 Boston, MA 02111-1307 USA
116
117 Copyright (C) @value{copyrights-g77} Free Software Foundation, Inc.
118
119
120 Permission is granted to copy, distribute and/or modify this document
121 under the terms of the GNU Free Documentation License, Version 1.1 or
122 any later version published by the Free Software Foundation; with the
123 Invariant Sections being ``GNU General Public License'' and ``Funding
124 Free Software'', the Front-Cover
125 texts being (a) (see below), and with the Back-Cover Texts being (b)
126 (see below).  A copy of the license is included in the section entitled
127 ``GNU Free Documentation License''.
128
129 (a) The FSF's Front-Cover Text is:
130
131      A GNU Manual
132
133 (b) The FSF's Back-Cover Text is:
134
135      You have freedom to copy and modify this GNU Manual, like GNU
136      software.  Copies published by the Free Software Foundation raise
137      funds for GNU development.
138 @end ifinfo
139
140 Contributed by James Craig Burley (@email{@value{email-burley}}).
141 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
142 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
143
144 @setchapternewpage odd
145 @c @finalout
146 @titlepage
147 @ifset INTERNALS
148 @ifset USING
149 @center @titlefont{Using and Porting GNU Fortran}
150
151 @end ifset
152 @end ifset
153 @ifclear INTERNALS
154 @title Using GNU Fortran
155 @end ifclear
156 @ifclear USING
157 @title Porting GNU Fortran
158 @end ifclear
159 @sp 2
160 @center James Craig Burley
161 @sp 3
162 @center Last updated @value{last-update}
163 @sp 1
164 @center for version @value{version-g77}
165 @page
166 @vskip 0pt plus 1filll
167 Copyright @copyright{} @value{copyrights-g77} Free Software Foundation, Inc.
168 @sp 2
169 For the @value{which-g77} Version*
170 @sp 1
171 Published by the Free Software Foundation @*
172 59 Temple Place - Suite 330@*
173 Boston, MA 02111-1307, USA@*
174 @c Last printed ??ber, 19??.@*
175 @c Printed copies are available for $? each.@*
176 @c ISBN ???
177 @sp 1
178 Permission is granted to copy, distribute and/or modify this document
179 under the terms of the GNU Free Documentation License, Version 1.1 or
180 any later version published by the Free Software Foundation; with the
181 Invariant Sections being ``GNU General Public License'' and ``Funding
182 Free Software'', the Front-Cover
183 texts being (a) (see below), and with the Back-Cover Texts being (b)
184 (see below).  A copy of the license is included in the section entitled
185 ``GNU Free Documentation License''.
186
187 (a) The FSF's Front-Cover Text is:
188
189      A GNU Manual
190
191 (b) The FSF's Back-Cover Text is:
192
193      You have freedom to copy and modify this GNU Manual, like GNU
194      software.  Copies published by the Free Software Foundation raise
195      funds for GNU development.
196 @end titlepage
197 @summarycontents
198 @contents
199 @page
200
201 @node Top, Copying,, (DIR)
202 @top Introduction
203 @cindex Introduction
204
205 @ifset INTERNALS
206 @ifset USING
207 This manual documents how to run, install and port @command{g77},
208 as well as its new features and incompatibilities,
209 and how to report bugs.
210 It corresponds to the @value{which-g77} version of @command{g77}.
211 @end ifset
212 @end ifset
213
214 @ifclear INTERNALS
215 This manual documents how to run and install @command{g77},
216 as well as its new features and incompatibilities, and how to report
217 bugs.
218 It corresponds to the @value{which-g77} version of @command{g77}.
219 @end ifclear
220 @ifclear USING
221 This manual documents how to port @command{g77},
222 as well as its new features and incompatibilities,
223 and how to report bugs.
224 It corresponds to the @value{which-g77} version of @command{g77}.
225 @end ifclear
226
227 @ifset DEVELOPMENT
228 @emph{Warning:} This document is still under development,
229 and might not accurately reflect the @command{g77} code base
230 of which it is a part.
231 Efforts are made to keep it somewhat up-to-date,
232 but they are particularly concentrated
233 on any version of this information
234 that is distributed as part of a @emph{released} @command{g77}.
235
236 In particular, while this document is intended to apply to
237 the @value{which-g77} version of @command{g77},
238 only an official @emph{release} of that version
239 is expected to contain documentation that is
240 most consistent with the @command{g77} product in that version.
241 @end ifset
242
243 @menu
244 * Copying::         GNU General Public License says
245                     how you can copy and share GNU Fortran.
246 * GNU Free Documentation License::
247                     How you can copy and share this manual.
248 * Contributors::    People who have contributed to GNU Fortran.
249 * Funding::         How to help assure continued work for free software.
250 * Funding GNU Fortran::  How to help assure continued work on GNU Fortran.
251 @ifset USING
252 * Getting Started:: Finding your way around this manual.
253 * What is GNU Fortran?::  How @command{g77} fits into the universe.
254 * G77 and GCC::     You can compile Fortran, C, or other programs.
255 * Invoking G77::    Command options supported by @command{g77}.
256 * News::            News about recent releases of @command{g77}.
257 * Changes::         User-visible changes to recent releases of @command{g77}.
258 * Language::        The GNU Fortran language.
259 * Compiler::        The GNU Fortran compiler.
260 * Other Dialects::  Dialects of Fortran supported by @command{g77}.
261 * Other Compilers:: Fortran compilers other than @command{g77}.
262 * Other Languages:: Languages other than Fortran.
263 * Debugging and Interfacing::  How @command{g77} generates code.
264 * Collected Fortran Wisdom::  How to avoid Trouble.
265 * Trouble::         If you have trouble with GNU Fortran.
266 * Open Questions::  Things we'd like to know.
267 * Bugs::            How, why, and where to report bugs.
268 * Service::         How to find suppliers of support for GNU Fortran.
269 @end ifset
270 @ifset INTERNALS
271 * Adding Options::  Guidance on teaching @command{g77} about new options.
272 * Projects::        Projects for @command{g77} internals hackers.
273 * Front End::       Design and implementation of the @command{g77} front end.
274 @end ifset
275
276 * M: Diagnostics.   Diagnostics produced by @command{g77}.
277
278 * Index::           Index of concepts and symbol names.
279 @end menu
280 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
281
282 @include gpl.texi
283
284 @include fdl.texi
285
286 @node Contributors
287 @unnumbered Contributors to GNU Fortran
288 @cindex contributors
289 @cindex credits
290
291 In addition to James Craig Burley, who wrote the front end,
292 many people have helped create and improve GNU Fortran.
293
294 @itemize @bullet
295 @item
296 The packaging and compiler portions of GNU Fortran are based largely
297 on the GNU CC compiler.
298 @xref{Contributors,,Contributors to GCC,gcc,Using the GNU Compiler
299 Collection (GCC)},
300 for more information.
301
302 @item
303 The run-time library used by GNU Fortran is a repackaged version
304 of the @code{libf2c} library (combined from the @code{libF77} and
305 @code{libI77} libraries) provided as part of @command{f2c}, available for
306 free from @code{netlib} sites on the Internet.
307
308 @item
309 Cygnus Support and The Free Software Foundation contributed
310 significant money and/or equipment to Craig's efforts.
311
312 @item
313 The following individuals served as alpha testers prior to @command{g77}'s
314 public release.  This work consisted of testing, researching, sometimes
315 debugging, and occasionally providing small amounts of code and fixes
316 for @command{g77}, plus offering plenty of helpful advice to Craig:
317
318 @itemize @w{}
319 @item
320 Jonathan Corbet
321 @item
322 Dr.@: Mark Fernyhough
323 @item
324 Takafumi Hayashi (The University of Aizu)---@email{takafumi@@u-aizu.ac.jp}
325 @item
326 Kate Hedstrom
327 @item
328 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
329 @item
330 Dr.@: A. O. V. Le Blanc
331 @item
332 Dave Love
333 @item
334 Rick Lutowski
335 @item
336 Toon Moene
337 @item
338 Rick Niles
339 @item
340 Derk Reefman
341 @item
342 Wayne K. Schroll
343 @item
344 Bill Thorson
345 @item
346 Pedro A. M. Vazquez
347 @item
348 Ian Watson
349 @end itemize
350
351 @item
352 Dave Love (@email{d.love@@dl.ac.uk})
353 wrote the libU77 part of the run-time library.
354
355 @item
356 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
357 provided the patch to add rudimentary support
358 for @code{INTEGER*1}, @code{INTEGER*2}, and
359 @code{LOGICAL*1}.
360 This inspired Craig to add further support,
361 even though the resulting support
362 would still be incomplete, because version 0.6 is still
363 a ways off.
364
365 @item
366 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
367 and encouraged Craig to rewrite the documentation in texinfo
368 format by contributing a first pass at a translation of the
369 old @file{g77-0.5.16/f/DOC} file.
370
371 @item
372 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
373 some analysis of generated code as part of an overall project
374 to improve @command{g77} code generation to at least be as good
375 as @command{f2c} used in conjunction with @command{gcc}.
376 So far, this has resulted in the three, somewhat
377 experimental, options added by @command{g77} to the @command{gcc}
378 compiler and its back end.
379
380 (These, in turn, had made their way into the @code{egcs}
381 version of the compiler, and do not exist in @command{gcc}
382 version 2.8 or versions of @command{g77} based on that version
383 of @command{gcc}.)
384
385 @item
386 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
387
388 @item
389 Thanks to Mary Cortani and the staff at Craftwork Solutions
390 (@email{support@@craftwork.com}) for all of their support.
391
392 @item
393 Many other individuals have helped debug, test, and improve @command{g77}
394 over the past several years, and undoubtedly more people
395 will be doing so in the future.
396 If you have done so, and would like
397 to see your name listed in the above list, please ask!
398 The default is that people wish to remain anonymous.
399 @end itemize
400
401 @include funding.texi
402
403 @node Funding GNU Fortran
404 @chapter Funding GNU Fortran
405 @cindex funding improvements
406 @cindex improvements, funding
407
408 James Craig Burley (@email{@value{email-burley}}), the original author
409 of @command{g77}, stopped working on it in September 1999
410 (He has a web page at @uref{@value{www-burley}}.)
411
412 GNU Fortran is currently maintained by Toon Moene
413 (@email{toon@@moene.indiv.nluug.nl}), with the help of countless other
414 volunteers.
415
416 As with other GNU software, funding is important because it can pay for
417 needed equipment, personnel, and so on.
418
419 @cindex FSF, funding the
420 @cindex funding the FSF
421 The FSF provides information on the best way to fund ongoing
422 development of GNU software (such as GNU Fortran) in documents
423 such as the ``GNUS Bulletin''.
424 Email @email{gnu@@gnu.org} for information on funding the FSF.
425
426 Another important way to support work on GNU Fortran is to volunteer
427 to help out.
428 Work is needed on documentation, testing, porting
429 to various machines, and in some cases, coding (although major
430 changes planned for version 0.6 make it difficult to add manpower to this
431 area).
432
433 Email @email{@value{email-general}} to volunteer for this work.
434
435 However, we strongly expect that there will never be a version 0.6
436 of @command{g77}.  Work on this compiler has stopped as of the release
437 of GCC 3.1, except for bug fixing.  @command{g77} will be succeeded by
438 @command{g95} - see @uref{http://g95.sourceforge.net}.
439
440 @xref{Funding,,Funding Free Software}, for more information.
441
442 @node Getting Started
443 @chapter Getting Started
444 @cindex getting started
445 @cindex new users
446 @cindex newbies
447 @cindex beginners
448
449 If you don't need help getting started reading the portions
450 of this manual that are most important to you, you should skip
451 this portion of the manual.
452
453 If you are new to compilers, especially Fortran compilers, or
454 new to how compilers are structured under UNIX and UNIX-like
455 systems, you'll want to see @ref{What is GNU Fortran?}.
456
457 If you are new to GNU compilers, or have used only one GNU
458 compiler in the past and not had to delve into how it lets
459 you manage various versions and configurations of @command{gcc},
460 you should see @ref{G77 and GCC}.
461
462 Everyone except experienced @command{g77} users should
463 see @ref{Invoking G77}.
464
465 If you're acquainted with previous versions of @command{g77},
466 you should see @ref{News,,News About GNU Fortran}.
467 Further, if you've actually used previous versions of @command{g77},
468 especially if you've written or modified Fortran code to
469 be compiled by previous versions of @command{g77}, you
470 should see @ref{Changes}.
471
472 If you intend to write or otherwise compile code that is
473 not already strictly conforming ANSI FORTRAN 77---and this
474 is probably everyone---you should see @ref{Language}.
475
476 If you run into trouble getting Fortran code to compile,
477 link, run, or work properly, you might find answers
478 if you see @ref{Debugging and Interfacing},
479 see @ref{Collected Fortran Wisdom},
480 and see @ref{Trouble}.
481 You might also find that the problems you are encountering
482 are bugs in @command{g77}---see @ref{Bugs}, for information on
483 reporting them, after reading the other material.
484
485 If you need further help with @command{g77}, or with
486 freely redistributable software in general,
487 see @ref{Service}.
488
489 If you would like to help the @command{g77} project,
490 see @ref{Funding GNU Fortran}, for information on
491 helping financially, and see @ref{Projects}, for information
492 on helping in other ways.
493
494 If you're generally curious about the future of
495 @command{g77}, see @ref{Projects}.
496 If you're curious about its past,
497 see @ref{Contributors},
498 and see @ref{Funding GNU Fortran}.
499
500 To see a few of the questions maintainers of @command{g77} have,
501 and that you might be able to answer,
502 see @ref{Open Questions}.
503
504 @ifset USING
505 @node What is GNU Fortran?
506 @chapter What is GNU Fortran?
507 @cindex concepts, basic
508 @cindex basic concepts
509
510 GNU Fortran, or @command{g77}, is designed initially as a free replacement
511 for, or alternative to, the UNIX @command{f77} command.
512 (Similarly, @command{gcc} is designed as a replacement
513 for the UNIX @command{cc} command.)
514
515 @command{g77} also is designed to fit in well with the other
516 fine GNU compilers and tools.
517
518 Sometimes these design goals conflict---in such cases, resolution
519 often is made in favor of fitting in well with Project GNU.
520 These cases are usually identified in the appropriate
521 sections of this manual.
522
523 @cindex compilers
524 As compilers, @command{g77}, @command{gcc}, and @command{f77}
525 share the following characteristics:
526
527 @itemize @bullet
528 @cindex source code
529 @cindex file, source
530 @cindex code, source
531 @cindex source file
532 @item
533 They read a user's program, stored in a file and
534 containing instructions written in the appropriate
535 language (Fortran, C, and so on).
536 This file contains @dfn{source code}.
537
538 @cindex translation of user programs
539 @cindex machine code
540 @cindex code, machine
541 @cindex mistakes
542 @item
543 They translate the user's program into instructions
544 a computer can carry out more quickly than it takes
545 to translate the instructions in the first place.
546 These instructions are called @dfn{machine code}---code
547 designed to be efficiently translated and processed
548 by a machine such as a computer.
549 Humans usually aren't as good writing machine code
550 as they are at writing Fortran or C, because
551 it is easy to make tiny mistakes writing machine code.
552 When writing Fortran or C, it is easy
553 to make big mistakes.
554
555 @cindex debugger
556 @cindex bugs, finding
557 @cindex @command{gdb}, command
558 @cindex commands, @command{gdb}
559 @item
560 They provide information in the generated machine code
561 that can make it easier to find bugs in the program
562 (using a debugging tool, called a @dfn{debugger},
563 such as @command{gdb}).
564
565 @cindex libraries
566 @cindex linking
567 @cindex @command{ld} command
568 @cindex commands, @command{ld}
569 @item
570 They locate and gather machine code already generated
571 to perform actions requested by statements in
572 the user's program.
573 This machine code is organized
574 into @dfn{libraries} and is located and gathered
575 during the @dfn{link} phase of the compilation
576 process.
577 (Linking often is thought of as a separate
578 step, because it can be directly invoked via the
579 @command{ld} command.
580 However, the @command{g77} and @command{gcc}
581 commands, as with most compiler commands, automatically
582 perform the linking step by calling on @command{ld}
583 directly, unless asked to not do so by the user.)
584
585 @cindex language, incorrect use of
586 @cindex incorrect use of language
587 @item
588 They attempt to diagnose cases where the user's
589 program contains incorrect usages of the language.
590 The @dfn{diagnostics} produced by the compiler
591 indicate the problem and the location in the user's
592 source file where the problem was first noticed.
593 The user can use this information to locate and
594 fix the problem.
595 @cindex diagnostics, incorrect
596 @cindex incorrect diagnostics
597 @cindex error messages, incorrect
598 @cindex incorrect error messages
599 (Sometimes an incorrect usage
600 of the language leads to a situation where the
601 compiler can no longer make any sense of what
602 follows---while a human might be able to---and
603 thus ends up complaining about many ``problems''
604 it encounters that, in fact, stem from just one
605 problem, usually the first one reported.)
606
607 @cindex warnings
608 @cindex questionable instructions
609 @item
610 They attempt to diagnose cases where the user's
611 program contains a correct usage of the language,
612 but instructs the computer to do something questionable.
613 These diagnostics often are in the form of @dfn{warnings},
614 instead of the @dfn{errors} that indicate incorrect
615 usage of the language.
616 @end itemize
617
618 How these actions are performed is generally under the
619 control of the user.
620 Using command-line options, the user can specify
621 how persnickety the compiler is to be regarding
622 the program (whether to diagnose questionable usage
623 of the language), how much time to spend making
624 the generated machine code run faster, and so on.
625
626 @cindex components of @command{g77}
627 @cindex @command{g77}, components of
628 @command{g77} consists of several components:
629
630 @cindex @command{gcc}, command
631 @cindex commands, @command{gcc}
632 @itemize @bullet
633 @item
634 A modified version of the @command{gcc} command, which also might be
635 installed as the system's @command{cc} command.
636 (In many cases, @command{cc} refers to the
637 system's ``native'' C compiler, which
638 might be a non-GNU compiler, or an older version
639 of @command{gcc} considered more stable or that is
640 used to build the operating system kernel.)
641
642 @cindex @command{g77}, command
643 @cindex commands, @command{g77}
644 @item
645 The @command{g77} command itself, which also might be installed as the
646 system's @command{f77} command.
647
648 @cindex libg2c library
649 @cindex libf2c library
650 @cindex libraries, libf2c
651 @cindex libraries, libg2c
652 @cindex run-time, library
653 @item
654 The @code{libg2c} run-time library.
655 This library contains the machine code needed to support
656 capabilities of the Fortran language that are not directly
657 provided by the machine code generated by the @command{g77}
658 compilation phase.
659
660 @code{libg2c} is just the unique name @command{g77} gives
661 to its version of @code{libf2c} to distinguish it from
662 any copy of @code{libf2c} installed from @command{f2c}
663 (or versions of @command{g77} that built @code{libf2c} under
664 that same name)
665 on the system.
666
667 The maintainer of @code{libf2c} currently is
668 @email{dmg@@bell-labs.com}.
669
670 @cindex @code{f771}, program
671 @cindex programs, @code{f771}
672 @cindex assembler
673 @cindex @command{as} command
674 @cindex commands, @command{as}
675 @cindex assembly code
676 @cindex code, assembly
677 @item
678 The compiler itself, internally named @code{f771}.
679
680 Note that @code{f771} does not generate machine code directly---it
681 generates @dfn{assembly code} that is a more readable form
682 of machine code, leaving the conversion to actual machine code
683 to an @dfn{assembler}, usually named @command{as}.
684 @end itemize
685
686 @command{gcc} is often thought of as ``the C compiler'' only,
687 but it does more than that.
688 Based on command-line options and the names given for files
689 on the command line, @command{gcc} determines which actions to perform, including
690 preprocessing, compiling (in a variety of possible languages), assembling,
691 and linking.
692
693 @cindex driver, gcc command as
694 @cindex @command{gcc}, command as driver
695 @cindex executable file
696 @cindex files, executable
697 @cindex cc1 program
698 @cindex programs, cc1
699 @cindex preprocessor
700 @cindex cpp program
701 @cindex programs, cpp
702 For example, the command @samp{gcc foo.c} @dfn{drives} the file
703 @file{foo.c} through the preprocessor @command{cpp}, then
704 the C compiler (internally named
705 @code{cc1}), then the assembler (usually @command{as}), then the linker
706 (@command{ld}), producing an executable program named @file{a.out} (on
707 UNIX systems).
708
709 @cindex cc1plus program
710 @cindex programs, cc1plus
711 As another example, the command @samp{gcc foo.cc} would do much the same as
712 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
713 @command{gcc} would use the C++ compiler (named @code{cc1plus}).
714
715 @cindex @code{f771}, program
716 @cindex programs, @code{f771}
717 In a GNU Fortran installation, @command{gcc} recognizes Fortran source
718 files by name just like it does C and C++ source files.
719 It knows to use the Fortran compiler named @code{f771}, instead of
720 @code{cc1} or @code{cc1plus}, to compile Fortran files.
721
722 @cindex @command{gcc}, not recognizing Fortran source
723 @cindex unrecognized file format
724 @cindex file format not recognized
725 Non-Fortran-related operation of @command{gcc} is generally
726 unaffected by installing the GNU Fortran version of @command{gcc}.
727 However, without the installed version of @command{gcc} being the
728 GNU Fortran version, @command{gcc} will not be able to compile
729 and link Fortran programs---and since @command{g77} uses @command{gcc}
730 to do most of the actual work, neither will @command{g77}!
731
732 @cindex @command{g77}, command
733 @cindex commands, @command{g77}
734 The @command{g77} command is essentially just a front-end for
735 the @command{gcc} command.
736 Fortran users will normally use @command{g77} instead of @command{gcc},
737 because @command{g77}
738 knows how to specify the libraries needed to link with Fortran programs
739 (@code{libg2c} and @code{lm}).
740 @command{g77} can still compile and link programs and
741 source files written in other languages, just like @command{gcc}.
742
743 @cindex printing version information
744 @cindex version information, printing
745 The command @samp{g77 -v} is a quick
746 way to display lots of version information for the various programs
747 used to compile a typical preprocessed Fortran source file---this
748 produces much more output than @samp{gcc -v} currently does.
749 (If it produces an error message near the end of the output---diagnostics
750 from the linker, usually @command{ld}---you might
751 have an out-of-date @code{libf2c} that improperly handles
752 complex arithmetic.)
753 In the output of this command, the line beginning @samp{GNU Fortran Front
754 End} identifies the version number of GNU Fortran; immediately
755 preceding that line is a line identifying the version of @command{gcc}
756 with which that version of @command{g77} was built.
757
758 @cindex libf2c library
759 @cindex libraries, libf2c
760 The @code{libf2c} library is distributed with GNU Fortran for
761 the convenience of its users, but is not part of GNU Fortran.
762 It contains the procedures
763 needed by Fortran programs while they are running.
764
765 @cindex in-line code
766 @cindex code, in-line
767 For example, while code generated by @command{g77} is likely
768 to do additions, subtractions, and multiplications @dfn{in line}---in
769 the actual compiled code---it is not likely to do trigonometric
770 functions this way.
771
772 Instead, operations like trigonometric
773 functions are compiled by the @code{f771} compiler
774 (invoked by @command{g77} when compiling Fortran code) into machine
775 code that, when run, calls on functions in @code{libg2c}, so
776 @code{libg2c} must be linked with almost every useful program
777 having any component compiled by GNU Fortran.
778 (As mentioned above, the @command{g77} command takes
779 care of all this for you.)
780
781 The @code{f771} program represents most of what is unique to GNU Fortran.
782 While much of the @code{libg2c} component comes from
783 the @code{libf2c} component of @command{f2c},
784 a free Fortran-to-C converter distributed by Bellcore (AT&T),
785 plus @code{libU77}, provided by Dave Love,
786 and the @command{g77} command is just a small front-end to @command{gcc},
787 @code{f771} is a combination of two rather
788 large chunks of code.
789
790 @cindex GNU Back End (GBE)
791 @cindex GBE
792 @cindex @command{gcc}, back end
793 @cindex back end, gcc
794 @cindex code generator
795 One chunk is the so-called @dfn{GNU Back End}, or GBE,
796 which knows how to generate fast code for a wide variety of processors.
797 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
798 @code{cc1plus}, and @code{f771}, plus others.
799 Often the GBE is referred to as the ``gcc back end'' or
800 even just ``gcc''---in this manual, the term GBE is used
801 whenever the distinction is important.
802
803 @cindex GNU Fortran Front End (FFE)
804 @cindex FFE
805 @cindex @command{g77}, front end
806 @cindex front end, @command{g77}
807 The other chunk of @code{f771} is the
808 majority of what is unique about GNU Fortran---the code that knows how
809 to interpret Fortran programs to determine what they are intending to
810 do, and then communicate that knowledge to the GBE for actual compilation
811 of those programs.
812 This chunk is called the @dfn{Fortran Front End} (FFE).
813 The @code{cc1} and @code{cc1plus} programs have their own front ends,
814 for the C and C++ languages, respectively.
815 These fronts ends are responsible for diagnosing
816 incorrect usage of their respective languages by the
817 programs the process, and are responsible for most of
818 the warnings about questionable constructs as well.
819 (The GBE handles producing some warnings, like those
820 concerning possible references to undefined variables.)
821
822 Because so much is shared among the compilers for various languages,
823 much of the behavior and many of the user-selectable options for these
824 compilers are similar.
825 For example, diagnostics (error messages and
826 warnings) are similar in appearance; command-line
827 options like @option{-Wall} have generally similar effects; and the quality
828 of generated code (in terms of speed and size) is roughly similar
829 (since that work is done by the shared GBE).
830
831 @node G77 and GCC
832 @chapter Compile Fortran, C, or Other Programs
833 @cindex compiling programs
834 @cindex programs, compiling
835
836 @cindex @command{gcc}, command
837 @cindex commands, @command{gcc}
838 A GNU Fortran installation includes a modified version of the @command{gcc}
839 command.
840
841 In a non-Fortran installation, @command{gcc} recognizes C, C++,
842 and Objective-C source files.
843
844 In a GNU Fortran installation, @command{gcc} also recognizes Fortran source
845 files and accepts Fortran-specific command-line options, plus some
846 command-line options that are designed to cater to Fortran users
847 but apply to other languages as well.
848
849 @xref{G++ and GCC,,Compile C; C++; Objective-C; Ada; CHILL; Fortran;
850 or Java,gcc,Using the GNU Compiler Collection (GCC)},
851 for information on the way different languages are handled
852 by the GNU CC compiler (@command{gcc}).
853
854 @cindex @command{g77}, command
855 @cindex commands, @command{g77}
856 Also provided as part of GNU Fortran is the @command{g77} command.
857 The @command{g77} command is designed to make compiling and linking Fortran
858 programs somewhat easier than when using the @command{gcc} command for
859 these tasks.
860 It does this by analyzing the command line somewhat and changing it
861 appropriately before submitting it to the @command{gcc} command.
862
863 @cindex -v option
864 @cindex @command{g77} options, -v
865 @cindex options, -v
866 Use the @option{-v} option with @command{g77}
867 to see what is going on---the first line of output is the invocation
868 of the @command{gcc} command.
869
870 @include invoke.texi
871
872 @include news.texi
873
874 @set USERVISONLY
875 @include news.texi
876 @clear USERVISONLY
877
878 @node Language
879 @chapter The GNU Fortran Language
880
881 @cindex standard, ANSI FORTRAN 77
882 @cindex ANSI FORTRAN 77 standard
883 @cindex reference works
884 GNU Fortran supports a variety of extensions to, and dialects
885 of, the Fortran language.
886 Its primary base is the ANSI FORTRAN 77 standard, currently available on
887 the network at
888 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
889 or as monolithic text at
890 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
891 It offers some extensions that are popular among users
892 of UNIX @command{f77} and @command{f2c} compilers, some that
893 are popular among users of other compilers (such as Digital
894 products), some that are popular among users of the
895 newer Fortran 90 standard, and some that are introduced
896 by GNU Fortran.
897
898 @cindex textbooks
899 (If you need a text on Fortran,
900 a few freely available electronic references have pointers from
901 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
902 net project', @cite{User Notes on Fortran Programming} at
903 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
904 material might not apply specifically to @command{g77}.)
905
906 Part of what defines a particular implementation of a Fortran
907 system, such as @command{g77}, is the particular characteristics
908 of how it supports types, constants, and so on.
909 Much of this is left up to the implementation by the various
910 Fortran standards and accepted practice in the industry.
911
912 The GNU Fortran @emph{language} is described below.
913 Much of the material is organized along the same lines
914 as the ANSI FORTRAN 77 standard itself.
915
916 @xref{Other Dialects}, for information on features @command{g77} supports
917 that are not part of the GNU Fortran language.
918
919 @emph{Note}: This portion of the documentation definitely needs a lot
920 of work!
921
922 @menu
923 Relationship to the ANSI FORTRAN 77 standard:
924 * Direction of Language Development::  Where GNU Fortran is headed.
925 * Standard Support::  Degree of support for the standard.
926
927 Extensions to the ANSI FORTRAN 77 standard:
928 * Conformance::
929 * Notation Used::
930 * Terms and Concepts::
931 * Characters Lines Sequence::
932 * Data Types and Constants::
933 * Expressions::
934 * Specification Statements::
935 * Control Statements::
936 * Functions and Subroutines::
937 * Scope and Classes of Names::
938 * I/O::
939 * Fortran 90 Features::
940 @end menu
941
942 @node Direction of Language Development
943 @section Direction of Language Development
944 @cindex direction of language development
945 @cindex features, language
946 @cindex language, features
947
948 The purpose of the following description of the GNU Fortran
949 language is to promote wide portability of GNU Fortran programs.
950
951 GNU Fortran is an evolving language, due to the
952 fact that @command{g77} itself is in beta test.
953 Some current features of the language might later
954 be redefined as dialects of Fortran supported by @command{g77}
955 when better ways to express these features are added to @command{g77},
956 for example.
957 Such features would still be supported by
958 @command{g77}, but would be available only when
959 one or more command-line options were used.
960
961 The GNU Fortran @emph{language} is distinct from the
962 GNU Fortran @emph{compilation system} (@command{g77}).
963
964 For example, @command{g77} supports various dialects of
965 Fortran---in a sense, these are languages other than
966 GNU Fortran---though its primary
967 purpose is to support the GNU Fortran language, which also is
968 described in its documentation and by its implementation.
969
970 On the other hand, non-GNU compilers might offer
971 support for the GNU Fortran language, and are encouraged
972 to do so.
973
974 Currently, the GNU Fortran language is a fairly fuzzy object.
975 It represents something of a cross between what @command{g77} accepts
976 when compiling using the prevailing defaults and what this
977 document describes as being part of the language.
978
979 Future versions of @command{g77} are expected to clarify the
980 definition of the language in the documentation.
981 Often, this will mean adding new features to the language, in the form
982 of both new documentation and new support in @command{g77}.
983 However, it might occasionally mean removing a feature
984 from the language itself to ``dialect'' status.
985 In such a case, the documentation would be adjusted
986 to reflect the change, and @command{g77} itself would likely be changed
987 to require one or more command-line options to continue supporting
988 the feature.
989
990 The development of the GNU Fortran language is intended to strike
991 a balance between:
992
993 @itemize @bullet
994 @item
995 Serving as a mostly-upwards-compatible language from the
996 de facto UNIX Fortran dialect as supported by @command{f77}.
997
998 @item
999 Offering new, well-designed language features.
1000 Attributes of such features include
1001 not making existing code any harder to read
1002 (for those who might be unaware that the new
1003 features are not in use) and
1004 not making state-of-the-art
1005 compilers take longer to issue diagnostics,
1006 among others.
1007
1008 @item
1009 Supporting existing, well-written code without gratuitously
1010 rejecting non-standard constructs, regardless of the origin
1011 of the code (its dialect).
1012
1013 @item
1014 Offering default behavior and command-line options to reduce
1015 and, where reasonable, eliminate the need for programmers to make
1016 any modifications to code that already works in existing
1017 production environments.
1018
1019 @item
1020 Diagnosing constructs that have different meanings in different
1021 systems, languages, and dialects, while offering clear,
1022 less ambiguous ways to express each of the different meanings
1023 so programmers can change their code appropriately.
1024 @end itemize
1025
1026 One of the biggest practical challenges for the developers of the
1027 GNU Fortran language is meeting the sometimes contradictory demands
1028 of the above items.
1029
1030 For example, a feature might be widely used in one popular environment,
1031 but the exact same code that utilizes that feature might not work
1032 as expected---perhaps it might mean something entirely different---in
1033 another popular environment.
1034
1035 Traditionally, Fortran compilers---even portable ones---have solved this
1036 problem by simply offering the appropriate feature to users of
1037 the respective systems.
1038 This approach treats users of various Fortran systems and dialects
1039 as remote ``islands'', or camps, of programmers, and assume that these
1040 camps rarely come into contact with each other (or,
1041 especially, with each other's code).
1042
1043 Project GNU takes a radically different approach to software and language
1044 design, in that it assumes that users of GNU software do not necessarily
1045 care what kind of underlying system they are using, regardless
1046 of whether they are using software (at the user-interface
1047 level) or writing it (for example, writing Fortran or C code).
1048
1049 As such, GNU users rarely need consider just what kind of underlying
1050 hardware (or, in many cases, operating system) they are using at any
1051 particular time.
1052 They can use and write software designed for a general-purpose,
1053 widely portable, heterogenous environment---the GNU environment.
1054
1055 In line with this philosophy, GNU Fortran must evolve into a product
1056 that is widely ported and portable not only in the sense that it can
1057 be successfully built, installed, and run by users, but in the larger
1058 sense that its users can use it in the same way, and expect largely the
1059 same behaviors from it, regardless of the kind of system they are using
1060 at any particular time.
1061
1062 This approach constrains the solutions @command{g77} can use to resolve
1063 conflicts between various camps of Fortran users.
1064 If these two camps disagree about what a particular construct should
1065 mean, @command{g77} cannot simply be changed to treat that particular construct as
1066 having one meaning without comment (such as a warning), lest the users
1067 expecting it to have the other meaning are unpleasantly surprised that
1068 their code misbehaves when executed.
1069
1070 The use of the ASCII backslash character in character constants is
1071 an excellent (and still somewhat unresolved) example of this kind of
1072 controversy.
1073 @xref{Backslash in Constants}.
1074 Other examples are likely to arise in the future, as @command{g77} developers
1075 strive to improve its ability to accept an ever-wider variety of existing
1076 Fortran code without requiring significant modifications to said code.
1077
1078 Development of GNU Fortran is further constrained by the desire
1079 to avoid requiring programmers to change their code.
1080 This is important because it allows programmers, administrators,
1081 and others to more faithfully evaluate and validate @command{g77}
1082 (as an overall product and as new versions are distributed)
1083 without having to support multiple versions of their programs
1084 so that they continue to work the same way on their existing
1085 systems (non-GNU perhaps, but possibly also earlier versions
1086 of @command{g77}).
1087
1088 @node Standard Support
1089 @section ANSI FORTRAN 77 Standard Support
1090 @cindex ANSI FORTRAN 77 support
1091 @cindex standard, support for
1092 @cindex support, FORTRAN 77
1093 @cindex compatibility, FORTRAN 77
1094 @cindex FORTRAN 77 compatibility
1095
1096 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
1097 In summary, the only ANSI FORTRAN 77 features @command{g77} doesn't
1098 support are those that are probably rarely used in actual code,
1099 some of which are explicitly disallowed by the Fortran 90 standard.
1100
1101 @menu
1102 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
1103 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
1104 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
1105 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
1106 @end menu
1107
1108 @node No Passing External Assumed-length
1109 @subsection No Passing External Assumed-length
1110
1111 @command{g77} disallows passing of an external procedure
1112 as an actual argument if the procedure's
1113 type is declared @code{CHARACTER*(*)}.  For example:
1114
1115 @example
1116 CHARACTER*(*) CFUNC
1117 EXTERNAL CFUNC
1118 CALL FOO(CFUNC)
1119 END
1120 @end example
1121
1122 @noindent
1123 It isn't clear whether the standard considers this conforming.
1124
1125 @node No Passing Dummy Assumed-length
1126 @subsection No Passing Dummy Assumed-length
1127
1128 @command{g77} disallows passing of a dummy procedure
1129 as an actual argument if the procedure's
1130 type is declared @code{CHARACTER*(*)}.
1131
1132 @example
1133 SUBROUTINE BAR(CFUNC)
1134 CHARACTER*(*) CFUNC
1135 EXTERNAL CFUNC
1136 CALL FOO(CFUNC)
1137 END
1138 @end example
1139
1140 @noindent
1141 It isn't clear whether the standard considers this conforming.
1142
1143 @node No Pathological Implied-DO
1144 @subsection No Pathological Implied-DO
1145
1146 The @code{DO} variable for an implied-@code{DO} construct in a
1147 @code{DATA} statement may not be used as the @code{DO} variable
1148 for an outer implied-@code{DO} construct.  For example, this
1149 fragment is disallowed by @command{g77}:
1150
1151 @smallexample
1152 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
1153 @end smallexample
1154
1155 @noindent
1156 This also is disallowed by Fortran 90, as it offers no additional
1157 capabilities and would have a variety of possible meanings.
1158
1159 Note that it is @emph{very} unlikely that any production Fortran code
1160 tries to use this unsupported construct.
1161
1162 @node No Useless Implied-DO
1163 @subsection No Useless Implied-DO
1164
1165 An array element initializer in an implied-@code{DO} construct in a
1166 @code{DATA} statement must contain at least one reference to the @code{DO}
1167 variables of each outer implied-@code{DO} construct.  For example,
1168 this fragment is disallowed by @command{g77}:
1169
1170 @smallexample
1171 DATA (A, I= 1, 1) /1./
1172 @end smallexample
1173
1174 @noindent
1175 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
1176 requirements offer no additional capabilities.
1177 However, @command{g77} doesn't necessarily diagnose all cases
1178 where this requirement is not met.
1179
1180 Note that it is @emph{very} unlikely that any production Fortran code
1181 tries to use this unsupported construct.
1182
1183 @node Conformance
1184 @section Conformance
1185
1186 (The following information augments or overrides the information in
1187 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1188 language.
1189 Chapter 1 of that document otherwise serves as the basis
1190 for the relevant aspects of GNU Fortran.)
1191
1192 The definition of the GNU Fortran language is akin to that of
1193 the ANSI FORTRAN 77 language in that it does not generally require
1194 conforming implementations to diagnose cases where programs do
1195 not conform to the language.
1196
1197 However, @command{g77} as a compiler is being developed in a way that
1198 is intended to enable it to diagnose such cases in an easy-to-understand
1199 manner.
1200
1201 A program that conforms to the GNU Fortran language should, when
1202 compiled, linked, and executed using a properly installed @command{g77}
1203 system, perform as described by the GNU Fortran language definition.
1204 Reasons for different behavior include, among others:
1205
1206 @itemize @bullet
1207 @item
1208 Use of resources (memory---heap, stack, and so on; disk space; CPU
1209 time; etc.) exceeds those of the system.
1210
1211 @item
1212 Range and/or precision of calculations required by the program
1213 exceeds that of the system.
1214
1215 @item
1216 Excessive reliance on behaviors that are system-dependent
1217 (non-portable Fortran code).
1218
1219 @item
1220 Bugs in the program.
1221
1222 @item
1223 Bug in @command{g77}.
1224
1225 @item
1226 Bugs in the system.
1227 @end itemize
1228
1229 Despite these ``loopholes'', the availability of a clear specification
1230 of the language of programs submitted to @command{g77}, as this document
1231 is intended to provide, is considered an important aspect of providing
1232 a robust, clean, predictable Fortran implementation.
1233
1234 The definition of the GNU Fortran language, while having no special
1235 legal status, can therefore be viewed as a sort of contract, or agreement.
1236 This agreement says, in essence, ``if you write a program in this language,
1237 and run it in an environment (such as a @command{g77} system) that supports
1238 this language, the program should behave in a largely predictable way''.
1239
1240 @node Notation Used
1241 @section Notation Used in This Chapter
1242
1243 (The following information augments or overrides the information in
1244 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1245 language.
1246 Chapter 1 of that document otherwise serves as the basis
1247 for the relevant aspects of GNU Fortran.)
1248
1249 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
1250 and ``must not'' and ``may not'' denote prohibition.
1251 Terms such as ``might'', ``should'', and ``can'' generally add little or
1252 nothing in the way of weight to the GNU Fortran language itself,
1253 but are used to explain or illustrate the language.
1254
1255 For example:
1256
1257 @display
1258 ``The @code{FROBNITZ} statement must precede all executable
1259 statements in a program unit, and may not specify any dummy
1260 arguments.  It may specify local or common variables and arrays.
1261 Its use should be limited to portions of the program designed to
1262 be non-portable and system-specific, because it might cause the
1263 containing program unit to behave quite differently on different
1264 systems.''
1265 @end display
1266
1267 Insofar as the GNU Fortran language is specified,
1268 the requirements and permissions denoted by the above sample statement
1269 are limited to the placement of the statement and the kinds of
1270 things it may specify.
1271 The rest of the statement---the content regarding non-portable portions
1272 of the program and the differing behavior of program units containing
1273 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
1274 language itself.
1275 That content offers advice and warnings about the @code{FROBNITZ}
1276 statement.
1277
1278 @emph{Remember:} The GNU Fortran language definition specifies
1279 both what constitutes a valid GNU Fortran program and how,
1280 given such a program, a valid GNU Fortran implementation is
1281 to interpret that program.
1282
1283 It is @emph{not} incumbent upon a valid GNU Fortran implementation
1284 to behave in any particular way, any consistent way, or any
1285 predictable way when it is asked to interpret input that is
1286 @emph{not} a valid GNU Fortran program.
1287
1288 Such input is said to have @dfn{undefined} behavior when
1289 interpreted by a valid GNU Fortran implementation, though
1290 an implementation may choose to specify behaviors for some
1291 cases of inputs that are not valid GNU Fortran programs.
1292
1293 Other notation used herein is that of the GNU texinfo format,
1294 which is used to generate printed hardcopy, on-line hypertext
1295 (Info), and on-line HTML versions, all from a single source
1296 document.
1297 This notation is used as follows:
1298
1299 @itemize @bullet
1300 @item
1301 Keywords defined by the GNU Fortran language are shown
1302 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
1303 @code{BLOCK DATA}.
1304
1305 Note that, in practice, many Fortran programs are written
1306 in lowercase---uppercase is used in this manual as a
1307 means to readily distinguish keywords and sample Fortran-related
1308 text from the prose in this document.
1309
1310 @item
1311 Portions of actual sample program, input, or output text
1312 look like this: @samp{Actual program text}.
1313
1314 Generally, uppercase is used for all Fortran-specific and
1315 Fortran-related text, though this does not always include
1316 literal text within Fortran code.
1317
1318 For example: @samp{PRINT *, 'My name is Bob'}.
1319
1320 @item
1321 A metasyntactic variable---that is, a name used in this document
1322 to serve as a placeholder for whatever text is used by the
1323 user or programmer---appears as shown in the following example:
1324
1325 ``The @code{INTEGER @var{ivar}} statement specifies that
1326 @var{ivar} is a variable or array of type @code{INTEGER}.''
1327
1328 In the above example, any valid text may be substituted for
1329 the metasyntactic variable @var{ivar} to make the statement
1330 apply to a specific instance, as long as the same text is
1331 substituted for @emph{both} occurrences of @var{ivar}.
1332
1333 @item
1334 Ellipses (``@dots{}'') are used to indicate further text that
1335 is either unimportant or expanded upon further, elsewhere.
1336
1337 @item
1338 Names of data types are in the style of Fortran 90, in most
1339 cases.
1340
1341 @xref{Kind Notation}, for information on the relationship
1342 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
1343 and the more traditional, less portably concise nomenclature
1344 (such as @code{INTEGER*4}).
1345 @end itemize
1346
1347 @node Terms and Concepts
1348 @section Fortran Terms and Concepts
1349
1350 (The following information augments or overrides the information in
1351 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1352 language.
1353 Chapter 2 of that document otherwise serves as the basis
1354 for the relevant aspects of GNU Fortran.)
1355
1356 @menu
1357 * Syntactic Items::
1358 * Statements Comments Lines::
1359 * Scope of Names and Labels::
1360 @end menu
1361
1362 @node Syntactic Items
1363 @subsection Syntactic Items
1364
1365 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
1366
1367 @cindex limits, lengths of names
1368 In GNU Fortran, a symbolic name is at least one character long,
1369 and has no arbitrary upper limit on length.
1370 However, names of entities requiring external linkage (such as
1371 external functions, external subroutines, and @code{COMMON} areas)
1372 might be restricted to some arbitrary length by the system.
1373 Such a restriction is no more constrained than that of one
1374 through six characters.
1375
1376 Underscores (@samp{_}) are accepted in symbol names after the first
1377 character (which must be a letter).
1378
1379 @node Statements Comments Lines
1380 @subsection Statements, Comments, and Lines
1381
1382 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
1383
1384 @cindex trailing comment
1385 @cindex comment
1386 @cindex characters, comment
1387 @cindex !
1388 @cindex exclamation point
1389 @cindex continuation character
1390 @cindex characters, continuation
1391 Use of an exclamation point (@samp{!}) to begin a
1392 trailing comment (a comment that extends to the end of the same
1393 source line) is permitted under the following conditions:
1394
1395 @itemize @bullet
1396 @item
1397 The exclamation point does not appear in column 6.
1398 Otherwise, it is treated as an indicator of a continuation
1399 line.
1400
1401 @item
1402 The exclamation point appears outside a character or Hollerith
1403 constant.
1404 Otherwise, the exclamation point is considered part of the
1405 constant.
1406
1407 @item
1408 The exclamation point appears to the left of any other possible
1409 trailing comment.
1410 That is, a trailing comment may contain exclamation points
1411 in their commentary text.
1412 @end itemize
1413
1414 @cindex ;
1415 @cindex semicolon
1416 @cindex statements, separated by semicolon
1417 Use of a semicolon (@samp{;}) as a statement separator
1418 is permitted under the following conditions:
1419
1420 @itemize @bullet
1421 @item
1422 The semicolon appears outside a character or Hollerith
1423 constant.
1424 Otherwise, the semicolon is considered part of the
1425 constant.
1426
1427 @item
1428 The semicolon appears to the left of a trailing comment.
1429 Otherwise, the semicolon is considered part of that
1430 comment.
1431
1432 @item
1433 Neither a logical @code{IF} statement nor a non-construct
1434 @code{WHERE} statement (a Fortran 90 feature) may be
1435 followed (in the same, possibly continued, line) by
1436 a semicolon used as a statement separator.
1437
1438 This restriction avoids the confusion
1439 that can result when reading a line such as:
1440
1441 @smallexample
1442 IF (VALIDP) CALL FOO; CALL BAR
1443 @end smallexample
1444
1445 @noindent
1446 Some readers might think the @samp{CALL BAR} is executed
1447 only if @samp{VALIDP} is @code{.TRUE.}, while others might
1448 assume its execution is unconditional.
1449
1450 (At present, @command{g77} does not diagnose code that
1451 violates this restriction.)
1452 @end itemize
1453
1454 @node Scope of Names and Labels
1455 @subsection Scope of Symbolic Names and Statement Labels
1456 @cindex scope
1457
1458 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
1459
1460 Included in the list of entities that have a scope of a
1461 program unit are construct names (a Fortran 90 feature).
1462 @xref{Construct Names}, for more information.
1463
1464 @node Characters Lines Sequence
1465 @section Characters, Lines, and Execution Sequence
1466
1467 (The following information augments or overrides the information in
1468 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1469 language.
1470 Chapter 3 of that document otherwise serves as the basis
1471 for the relevant aspects of GNU Fortran.)
1472
1473 @menu
1474 * Character Set::
1475 * Lines::
1476 * Continuation Line::
1477 * Statements::
1478 * Statement Labels::
1479 * Order::
1480 * INCLUDE::
1481 * Cpp-style directives::
1482 @end menu
1483
1484 @node Character Set
1485 @subsection GNU Fortran Character Set
1486 @cindex characters
1487
1488 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
1489
1490 Letters include uppercase letters (the twenty-six characters
1491 of the English alphabet) and lowercase letters (their lowercase
1492 equivalent).
1493 Generally, lowercase letters may be used in place of uppercase
1494 letters, though in character and Hollerith constants, they
1495 are distinct.
1496
1497 Special characters include:
1498
1499 @itemize @bullet
1500 @item
1501 @cindex ;
1502 @cindex semicolon
1503 Semicolon (@samp{;})
1504
1505 @item
1506 @cindex !
1507 @cindex exclamation point
1508 Exclamation point (@samp{!})
1509
1510 @item
1511 @cindex "
1512 @cindex double quote
1513 Double quote (@samp{"})
1514
1515 @item
1516 @cindex \
1517 @cindex backslash
1518 Backslash (@samp{\})
1519
1520 @item
1521 @cindex ?
1522 @cindex question mark
1523 Question mark (@samp{?})
1524
1525 @item
1526 @cindex #
1527 @cindex hash mark
1528 @cindex pound sign
1529 Hash mark (@samp{#})
1530
1531 @item
1532 @cindex &
1533 @cindex ampersand
1534 Ampersand (@samp{&})
1535
1536 @item
1537 @cindex %
1538 @cindex percent sign
1539 Percent sign (@samp{%})
1540
1541 @item
1542 @cindex _
1543 @cindex underscore
1544 Underscore (@samp{_})
1545
1546 @item
1547 @cindex <
1548 @cindex open angle
1549 @cindex left angle
1550 @cindex open bracket
1551 @cindex left bracket
1552 Open angle (@samp{<})
1553
1554 @item
1555 @cindex >
1556 @cindex close angle
1557 @cindex right angle
1558 @cindex close bracket
1559 @cindex right bracket
1560 Close angle (@samp{>})
1561
1562 @item
1563 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
1564 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
1565 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
1566 and @samp{:})
1567 @end itemize
1568
1569 @cindex blank
1570 @cindex space
1571 @cindex SPC
1572 Note that this document refers to @key{SPC} as @dfn{space},
1573 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
1574
1575 @node Lines
1576 @subsection Lines
1577 @cindex lines
1578 @cindex source file format
1579 @cindex source format
1580 @cindex file, source
1581 @cindex source code
1582 @cindex code, source
1583 @cindex fixed form
1584 @cindex free form
1585
1586 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
1587
1588 The way a Fortran compiler views source files depends entirely on the
1589 implementation choices made for the compiler, since those choices
1590 are explicitly left to the implementation by the published Fortran
1591 standards.
1592
1593 The GNU Fortran language mandates a view applicable to UNIX-like
1594 text files---files that are made up of an arbitrary number of lines,
1595 each with an arbitrary number of characters (sometimes called stream-based
1596 files).
1597
1598 This view does not apply to types of files that are specified as
1599 having a particular number of characters on every single line (sometimes
1600 referred to as record-based files).
1601
1602 Because a ``line in a program unit is a sequence of 72 characters'',
1603 to quote X3.9-1978, the GNU Fortran language specifies that a
1604 stream-based text file is translated to GNU Fortran lines as follows:
1605
1606 @itemize @bullet
1607 @item
1608 A newline in the file is the character that represents the end of
1609 a line of text to the underlying system.
1610 For example, on ASCII-based systems, a newline is the @key{NL}
1611 character, which has ASCII value 10 (decimal).
1612
1613 @item
1614 Each newline in the file serves to end the line of text that precedes
1615 it (and that does not contain a newline).
1616
1617 @item
1618 The end-of-file marker (@code{EOF}) also serves to end the line
1619 of text that precedes it (and that does not contain a newline).
1620
1621 @item
1622 @cindex blank
1623 @cindex space
1624 @cindex SPC
1625 Any line of text that is shorter than 72 characters is padded to that length
1626 with spaces (called ``blanks'' in the standard).
1627
1628 @item
1629 Any line of text that is longer than 72 characters is truncated to that
1630 length, but the truncated remainder must consist entirely of spaces.
1631
1632 @item
1633 Characters other than newline and the GNU Fortran character set
1634 are invalid.
1635 @end itemize
1636
1637 For the purposes of the remainder of this description of the GNU
1638 Fortran language, the translation described above has already
1639 taken place, unless otherwise specified.
1640
1641 The result of the above translation is that the source file appears,
1642 in terms of the remainder of this description of the GNU Fortran language,
1643 as if it had an arbitrary
1644 number of 72-character lines, each character being among the GNU Fortran
1645 character set.
1646
1647 For example, if the source file itself has two newlines in a row,
1648 the second newline becomes, after the above translation, a single
1649 line containing 72 spaces.
1650
1651 @node Continuation Line
1652 @subsection Continuation Line
1653 @cindex continuation line, number of
1654 @cindex lines, continuation
1655 @cindex number of continuation lines
1656 @cindex limits, continuation lines
1657
1658 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
1659
1660 A continuation line is any line that both
1661
1662 @itemize @bullet
1663 @item
1664 Contains a continuation character, and
1665
1666 @item
1667 Contains only spaces in columns 1 through 5
1668 @end itemize
1669
1670 A continuation character is any character of the GNU Fortran character set
1671 other than space (@key{SPC}) or zero (@samp{0})
1672 in column 6, or a digit (@samp{0} through @samp{9}) in column
1673 7 through 72 of a line that has only spaces to the left of that
1674 digit.
1675
1676 The continuation character is ignored as far as the content of
1677 the statement is concerned.
1678
1679 The GNU Fortran language places no limit on the number of
1680 continuation lines in a statement.
1681 In practice, the limit depends on a variety of factors, such as
1682 available memory, statement content, and so on, but no
1683 GNU Fortran system may impose an arbitrary limit.
1684
1685 @node Statements
1686 @subsection Statements
1687
1688 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
1689
1690 Statements may be written using an arbitrary number of continuation
1691 lines.
1692
1693 Statements may be separated using the semicolon (@samp{;}), except
1694 that the logical @code{IF} and non-construct @code{WHERE} statements
1695 may not be separated from subsequent statements using only a semicolon
1696 as statement separator.
1697
1698 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
1699 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
1700 statement.
1701 These alternatives may be written as normal statements---they are not
1702 subject to the restrictions of the @code{END} statement.
1703
1704 However, no statement other than @code{END} may have an initial line
1705 that appears to be an @code{END} statement---even @code{END PROGRAM},
1706 for example, must not be written as:
1707
1708 @example
1709       END
1710      &PROGRAM
1711 @end example
1712
1713 @node Statement Labels
1714 @subsection Statement Labels
1715
1716 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
1717
1718 A statement separated from its predecessor via a semicolon may be
1719 labeled as follows:
1720
1721 @itemize @bullet
1722 @item
1723 The semicolon is followed by the label for the statement,
1724 which in turn follows the label.
1725
1726 @item
1727 The label must be no more than five digits in length.
1728
1729 @item
1730 The first digit of the label for the statement is not
1731 the first non-space character on a line.
1732 Otherwise, that character is treated as a continuation
1733 character.
1734 @end itemize
1735
1736 A statement may have only one label defined for it.
1737
1738 @node Order
1739 @subsection Order of Statements and Lines
1740
1741 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
1742
1743 Generally, @code{DATA} statements may precede executable statements.
1744 However, specification statements pertaining to any entities
1745 initialized by a @code{DATA} statement must precede that @code{DATA}
1746 statement.
1747 For example,
1748 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
1749 @samp{INTEGER J} is permitted.
1750
1751 The last line of a program unit may be an @code{END} statement,
1752 or may be:
1753
1754 @itemize @bullet
1755 @item
1756 An @code{END PROGRAM} statement, if the program unit is a main program.
1757
1758 @item
1759 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
1760
1761 @item
1762 An @code{END FUNCTION} statement, if the program unit is a function.
1763
1764 @item
1765 An @code{END BLOCK DATA} statement, if the program unit is a block data.
1766 @end itemize
1767
1768 @node INCLUDE
1769 @subsection Including Source Text
1770 @cindex INCLUDE directive
1771
1772 Additional source text may be included in the processing of
1773 the source file via the @code{INCLUDE} directive:
1774
1775 @example
1776 INCLUDE @var{filename}
1777 @end example
1778
1779 @noindent
1780 The source text to be included is identified by @var{filename},
1781 which is a literal GNU Fortran character constant.
1782 The meaning and interpretation of @var{filename} depends on the
1783 implementation, but typically is a filename.
1784
1785 (@command{g77} treats it as a filename that it searches for
1786 in the current directory and/or directories specified
1787 via the @option{-I} command-line option.)
1788
1789 The effect of the @code{INCLUDE} directive is as if the
1790 included text directly replaced the directive in the source
1791 file prior to interpretation of the program.
1792 Included text may itself use @code{INCLUDE}.
1793 The depth of nested @code{INCLUDE} references depends on
1794 the implementation, but typically is a positive integer.
1795
1796 This virtual replacement treats the statements and @code{INCLUDE}
1797 directives in the included text as syntactically distinct from
1798 those in the including text.
1799
1800 Therefore, the first non-comment line of the included text
1801 must not be a continuation line.
1802 The included text must therefore have, after the non-comment
1803 lines, either an initial line (statement), an @code{INCLUDE}
1804 directive, or nothing (the end of the included text).
1805
1806 Similarly, the including text may end the @code{INCLUDE}
1807 directive with a semicolon or the end of the line, but it
1808 cannot follow an @code{INCLUDE} directive at the end of its
1809 line with a continuation line.
1810 Thus, the last statement in an included text may not be
1811 continued.
1812
1813 Any statements between two @code{INCLUDE} directives on the
1814 same line are treated as if they appeared in between the
1815 respective included texts.
1816 For example:
1817
1818 @smallexample
1819 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
1820 @end smallexample
1821
1822 @noindent
1823 If the text included by @samp{INCLUDE 'A'} constitutes
1824 a @samp{PRINT *, 'A'} statement and the text included by
1825 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
1826 then the output of the above sample program would be
1827
1828 @example
1829 A
1830 B
1831 C
1832 @end example
1833
1834 @noindent
1835 (with suitable allowances for how an implementation defines
1836 its handling of output).
1837
1838 Included text must not include itself directly or indirectly,
1839 regardless of whether the @var{filename} used to reference
1840 the text is the same.
1841
1842 Note that @code{INCLUDE} is @emph{not} a statement.
1843 As such, it is neither a non-executable or executable
1844 statement.
1845 However, if the text it includes constitutes one or more
1846 executable statements, then the placement of @code{INCLUDE}
1847 is subject to effectively the same restrictions as those
1848 on executable statements.
1849
1850 An @code{INCLUDE} directive may be continued across multiple
1851 lines as if it were a statement.
1852 This permits long names to be used for @var{filename}.
1853
1854 @node Cpp-style directives
1855 @subsection Cpp-style directives
1856 @cindex #
1857 @cindex preprocessor
1858
1859 @code{cpp} output-style @code{#} directives
1860 (@pxref{C Preprocessor Output,,, cpp, The C Preprocessor})
1861 are recognized by the compiler even
1862 when the preprocessor isn't run on the input (as it is when compiling
1863 @samp{.F} files).  (Note the distinction between these @command{cpp}
1864 @code{#} @emph{output} directives and @code{#line} @emph{input}
1865 directives.)
1866
1867 @node Data Types and Constants
1868 @section Data Types and Constants
1869
1870 (The following information augments or overrides the information in
1871 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1872 language.
1873 Chapter 4 of that document otherwise serves as the basis
1874 for the relevant aspects of GNU Fortran.)
1875
1876 To more concisely express the appropriate types for
1877 entities, this document uses the more concise
1878 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
1879 instead of the more traditional, but less portably concise,
1880 byte-size-based nomenclature such as @code{INTEGER*4},
1881 wherever reasonable.
1882
1883 When referring to generic types---in contexts where the
1884 specific precision and range of a type are not important---this
1885 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
1886 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
1887
1888 In some cases, the context requires specification of a
1889 particular type.
1890 This document uses the @samp{KIND=} notation to accomplish
1891 this throughout, sometimes supplying the more traditional
1892 notation for clarification, though the traditional notation
1893 might not work the same way on all GNU Fortran implementations.
1894
1895 Use of @samp{KIND=} makes this document more concise because
1896 @command{g77} is able to define values for @samp{KIND=} that
1897 have the same meanings on all systems, due to the way the
1898 Fortran 90 standard specifies these values are to be used.
1899
1900 (In particular, that standard permits an implementation to
1901 arbitrarily assign nonnegative values.
1902 There are four distinct sets of assignments: one to the @code{CHARACTER}
1903 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
1904 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
1905 Implementations are free to assign these values in any order,
1906 leave gaps in the ordering of assignments, and assign more than
1907 one value to a representation.)
1908
1909 This makes @samp{KIND=} values superior to the values used
1910 in non-standard statements such as @samp{INTEGER*4}, because
1911 the meanings of the values in those statements vary from machine
1912 to machine, compiler to compiler, even operating system to
1913 operating system.
1914
1915 However, use of @samp{KIND=} is @emph{not} generally recommended
1916 when writing portable code (unless, for example, the code is
1917 going to be compiled only via @command{g77}, which is a widely
1918 ported compiler).
1919 GNU Fortran does not yet have adequate language constructs to
1920 permit use of @samp{KIND=} in a fashion that would make the
1921 code portable to Fortran 90 implementations; and, this construct
1922 is known to @emph{not} be accepted by many popular FORTRAN 77
1923 implementations, so it cannot be used in code that is to be ported
1924 to those.
1925
1926 The distinction here is that this document is able to use
1927 specific values for @samp{KIND=} to concisely document the
1928 types of various operations and operands.
1929
1930 A Fortran program should use the FORTRAN 77 designations for the
1931 appropriate GNU Fortran types---such as @code{INTEGER} for
1932 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
1933 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
1934 where no such designations exist, make use of appropriate
1935 techniques (preprocessor macros, parameters, and so on)
1936 to specify the types in a fashion that may be easily adjusted
1937 to suit each particular implementation to which the program
1938 is ported.
1939 (These types generally won't need to be adjusted for ports of
1940 @command{g77}.)
1941
1942 Further details regarding GNU Fortran data types and constants
1943 are provided below.
1944
1945 @menu
1946 * Types::
1947 * Constants::
1948 * Integer Type::
1949 * Character Type::
1950 @end menu
1951
1952 @node Types
1953 @subsection Data Types
1954
1955 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
1956
1957 GNU Fortran supports these types:
1958
1959 @enumerate
1960 @item
1961 Integer (generic type @code{INTEGER})
1962
1963 @item
1964 Real (generic type @code{REAL})
1965
1966 @item
1967 Double precision
1968
1969 @item
1970 Complex (generic type @code{COMPLEX})
1971
1972 @item
1973 Logical (generic type @code{LOGICAL})
1974
1975 @item
1976 Character (generic type @code{CHARACTER})
1977
1978 @item
1979 Double Complex
1980 @end enumerate
1981
1982 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
1983
1984 The generic types shown above are referred to in this document
1985 using only their generic type names.
1986 Such references usually indicate that any specific type (kind)
1987 of that generic type is valid.
1988
1989 For example, a context described in this document as accepting
1990 the @code{COMPLEX} type also is likely to accept the
1991 @code{DOUBLE COMPLEX} type.
1992
1993 The GNU Fortran language supports three ways to specify
1994 a specific kind of a generic type.
1995
1996 @menu
1997 * Double Notation::  As in @code{DOUBLE COMPLEX}.
1998 * Star Notation::    As in @code{INTEGER*4}.
1999 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
2000 @end menu
2001
2002 @node Double Notation
2003 @subsubsection Double Notation
2004
2005 The GNU Fortran language supports two uses of the keyword
2006 @code{DOUBLE} to specify a specific kind of type:
2007
2008 @itemize @bullet
2009 @item
2010 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
2011
2012 @item
2013 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
2014 @end itemize
2015
2016 Use one of the above forms where a type name is valid.
2017
2018 While use of this notation is popular, it doesn't scale
2019 well in a language or dialect rich in intrinsic types,
2020 as is the case for the GNU Fortran language (especially
2021 planned future versions of it).
2022
2023 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
2024 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
2025 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
2026 often are substituted for these, respectively, even though they
2027 do not always have the same meanings on all systems.
2028 (And, the fact that @samp{DOUBLE REAL} does not exist as such
2029 is an inconsistency.)
2030
2031 Therefore, this document uses ``double notation'' only on occasion
2032 for the benefit of those readers who are accustomed to it.
2033
2034 @node Star Notation
2035 @subsubsection Star Notation
2036 @cindex *@var{n} notation
2037
2038 The following notation specifies the storage size for a type:
2039
2040 @smallexample
2041 @var{generic-type}*@var{n}
2042 @end smallexample
2043
2044 @noindent
2045 @var{generic-type} must be a generic type---one of
2046 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
2047 or @code{CHARACTER}.
2048 @var{n} must be one or more digits comprising a decimal
2049 integer number greater than zero.
2050
2051 Use the above form where a type name is valid.
2052
2053 The @samp{*@var{n}} notation specifies that the amount of storage
2054 occupied by variables and array elements of that type is @var{n}
2055 times the storage occupied by a @code{CHARACTER*1} variable.
2056
2057 This notation might indicate a different degree of precision and/or
2058 range for such variables and array elements, and the functions that
2059 return values of types using this notation.
2060 It does not limit the precision or range of values of that type
2061 in any particular way---use explicit code to do that.
2062
2063 Further, the GNU Fortran language requires no particular values
2064 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
2065 notation.
2066 @command{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
2067 on all systems, for example,
2068 but not all implementations are required to do so, and @command{g77}
2069 is known to not support @code{REAL*1} on most (or all) systems.
2070
2071 As a result, except for @var{generic-type} of @code{CHARACTER},
2072 uses of this notation should be limited to isolated
2073 portions of a program that are intended to handle system-specific
2074 tasks and are expected to be non-portable.
2075
2076 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
2077 only @code{CHARACTER}, where it signifies not only the amount
2078 of storage occupied, but the number of characters in entities
2079 of that type.
2080 However, almost all Fortran compilers have supported this
2081 notation for generic types, though with a variety of meanings
2082 for @var{n}.)
2083
2084 Specifications of types using the @samp{*@var{n}} notation
2085 always are interpreted as specifications of the appropriate
2086 types described in this document using the @samp{KIND=@var{n}}
2087 notation, described below.
2088
2089 While use of this notation is popular, it doesn't serve well
2090 in the context of a widely portable dialect of Fortran, such as
2091 the GNU Fortran language.
2092
2093 For example, even on one particular machine, two or more popular
2094 Fortran compilers might well disagree on the size of a type
2095 declared @code{INTEGER*2} or @code{REAL*16}.
2096 Certainly there
2097 is known to be disagreement over such things among Fortran
2098 compilers on @emph{different} systems.
2099
2100 Further, this notation offers no elegant way to specify sizes
2101 that are not even multiples of the ``byte size'' typically
2102 designated by @code{INTEGER*1}.
2103 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
2104 certainly be possible, but would perhaps be stretching the original
2105 intent of this notation beyond the breaking point in terms
2106 of widespread readability of documentation and code making use
2107 of it.
2108
2109 Therefore, this document uses ``star notation'' only on occasion
2110 for the benefit of those readers who are accustomed to it.
2111
2112 @node Kind Notation
2113 @subsubsection Kind Notation
2114 @cindex KIND= notation
2115
2116 The following notation specifies the kind-type selector of a type:
2117
2118 @smallexample
2119 @var{generic-type}(KIND=@var{n})
2120 @end smallexample
2121
2122 @noindent
2123 Use the above form where a type name is valid.
2124
2125 @var{generic-type} must be a generic type---one of
2126 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
2127 or @code{CHARACTER}.
2128 @var{n} must be an integer initialization expression that
2129 is a positive, nonzero value.
2130
2131 Programmers are discouraged from writing these values directly
2132 into their code.
2133 Future versions of the GNU Fortran language will offer
2134 facilities that will make the writing of code portable
2135 to @command{g77} @emph{and} Fortran 90 implementations simpler.
2136
2137 However, writing code that ports to existing FORTRAN 77
2138 implementations depends on avoiding the @samp{KIND=} construct.
2139
2140 The @samp{KIND=} construct is thus useful in the context
2141 of GNU Fortran for two reasons:
2142
2143 @itemize @bullet
2144 @item
2145 It provides a means to specify a type in a fashion that
2146 is portable across all GNU Fortran implementations (though
2147 not other FORTRAN 77 and Fortran 90 implementations).
2148
2149 @item
2150 It provides a sort of Rosetta stone for this document to use
2151 to concisely describe the types of various operations and
2152 operands.
2153 @end itemize
2154
2155 The values of @var{n} in the GNU Fortran language are
2156 assigned using a scheme that:
2157
2158 @itemize @bullet
2159 @item
2160 Attempts to maximize the ability of readers
2161 of this document to quickly familiarize themselves
2162 with assignments for popular types
2163
2164 @item
2165 Provides a unique value for each specific desired
2166 meaning
2167
2168 @item
2169 Provides a means to automatically assign new values so
2170 they have a ``natural'' relationship to existing values,
2171 if appropriate, or, if no such relationship exists, will
2172 not interfere with future values assigned on the basis
2173 of such relationships
2174
2175 @item
2176 Avoids using values that are similar to values used
2177 in the existing, popular @samp{*@var{n}} notation,
2178 to prevent readers from expecting that these implied
2179 correspondences work on all GNU Fortran implementations
2180 @end itemize
2181
2182 The assignment system accomplishes this by assigning
2183 to each ``fundamental meaning'' of a specific type a
2184 unique prime number.
2185 Combinations of fundamental meanings---for example, a type
2186 that is two times the size of some other type---are assigned
2187 values of @var{n} that are the products of the values for
2188 those fundamental meanings.
2189
2190 A prime value of @var{n} is never given more than one fundamental
2191 meaning, to avoid situations where some code or system
2192 cannot reasonably provide those meanings in the form of a
2193 single type.
2194
2195 The values of @var{n} assigned so far are:
2196
2197 @table @code
2198 @item KIND=0
2199 This value is reserved for future use.
2200
2201 The planned future use is for this value to designate,
2202 explicitly, context-sensitive kind-type selection.
2203 For example, the expression @samp{1D0 * 0.1_0} would
2204 be equivalent to @samp{1D0 * 0.1D0}.
2205
2206 @item KIND=1
2207 This corresponds to the default types for
2208 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
2209 and @code{CHARACTER}, as appropriate.
2210
2211 These are the ``default'' types described in the Fortran 90 standard,
2212 though that standard does not assign any particular @samp{KIND=}
2213 value to these types.
2214
2215 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
2216 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
2217
2218 @item KIND=2
2219 This corresponds to types that occupy twice as much
2220 storage as the default types.
2221 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
2222 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
2223
2224 These are the ``double precision'' types described in the Fortran 90
2225 standard,
2226 though that standard does not assign any particular @samp{KIND=}
2227 value to these types.
2228
2229 @var{n} of 4 thus corresponds to types that occupy four times
2230 as much storage as the default types, @var{n} of 8 to types that
2231 occupy eight times as much storage, and so on.
2232
2233 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
2234 are not necessarily supported by every GNU Fortran implementation.
2235
2236 @item KIND=3
2237 This corresponds to types that occupy as much
2238 storage as the default @code{CHARACTER} type,
2239 which is the same effective type as @code{CHARACTER(KIND=1)}
2240 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
2241
2242 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
2243
2244 @var{n} of 6 thus corresponds to types that occupy twice as
2245 much storage as the @var{n}=3 types, @var{n} of 12 to types
2246 that occupy four times as much storage, and so on.
2247
2248 These are not necessarily supported by every GNU Fortran
2249 implementation.
2250
2251 @item KIND=5
2252 This corresponds to types that occupy half the
2253 storage as the default (@var{n}=1) types.
2254
2255 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
2256
2257 @var{n} of 25 thus corresponds to types that occupy one-quarter
2258 as much storage as the default types.
2259
2260 These are not necessarily supported by every GNU Fortran
2261 implementation.
2262
2263 @item KIND=7
2264 @cindex pointers
2265 This is valid only as @code{INTEGER(KIND=7)} and
2266 denotes the @code{INTEGER} type that has the smallest
2267 storage size that holds a pointer on the system.
2268
2269 A pointer representable by this type is capable of uniquely
2270 addressing a @code{CHARACTER*1} variable, array, array element,
2271 or substring.
2272
2273 (Typically this is equivalent to @code{INTEGER*4} or,
2274 on 64-bit systems, @code{INTEGER*8}.
2275 In a compatible C implementation, it typically would
2276 be the same size and semantics of the C type @code{void *}.)
2277 @end table
2278
2279 Note that these are @emph{proposed} correspondences and might change
2280 in future versions of @command{g77}---avoid writing code depending
2281 on them while @command{g77}, and therefore the GNU Fortran language
2282 it defines, is in beta testing.
2283
2284 Values not specified in the above list are reserved to
2285 future versions of the GNU Fortran language.
2286
2287 Implementation-dependent meanings will be assigned new,
2288 unique prime numbers so as to not interfere with other
2289 implementation-dependent meanings, and offer the possibility
2290 of increasing the portability of code depending on such
2291 types by offering support for them in other GNU Fortran
2292 implementations.
2293
2294 Other meanings that might be given unique values are:
2295
2296 @itemize @bullet
2297 @item
2298 Types that make use of only half their storage size for
2299 representing precision and range.
2300
2301 For example, some compilers offer options that cause
2302 @code{INTEGER} types to occupy the amount of storage
2303 that would be needed for @code{INTEGER(KIND=2)} types, but the
2304 range remains that of @code{INTEGER(KIND=1)}.
2305
2306 @item
2307 The IEEE single floating-point type.
2308
2309 @item
2310 Types with a specific bit pattern (endianness), such as the
2311 little-endian form of @code{INTEGER(KIND=1)}.
2312 These could permit, conceptually, use of portable code and
2313 implementations on data files written by existing systems.
2314 @end itemize
2315
2316 Future @emph{prime} numbers should be given meanings in as incremental
2317 a fashion as possible, to allow for flexibility and
2318 expressiveness in combining types.
2319
2320 For example, instead of defining a prime number for little-endian
2321 IEEE doubles, one prime number might be assigned the meaning
2322 ``little-endian'', another the meaning ``IEEE double'', and the
2323 value of @var{n} for a little-endian IEEE double would thus
2324 naturally be the product of those two respective assigned values.
2325 (It could even be reasonable to have IEEE values result from the
2326 products of prime values denoting exponent and fraction sizes
2327 and meanings, hidden bit usage, availability and representations
2328 of special values such as subnormals, infinities, and Not-A-Numbers
2329 (NaNs), and so on.)
2330
2331 This assignment mechanism, while not inherently required for
2332 future versions of the GNU Fortran language, is worth using
2333 because it could ease management of the ``space'' of supported
2334 types much easier in the long run.
2335
2336 The above approach suggests a mechanism for specifying inheritance
2337 of intrinsic (built-in) types for an entire, widely portable
2338 product line.
2339 It is certainly reasonable that, unlike programmers of other languages
2340 offering inheritance mechanisms that employ verbose names for classes
2341 and subclasses, along with graphical browsers to elucidate the
2342 relationships, Fortran programmers would employ
2343 a mechanism that works by multiplying prime numbers together
2344 and finding the prime factors of such products.
2345
2346 Most of the advantages for the above scheme have been explained
2347 above.
2348 One disadvantage is that it could lead to the defining,
2349 by the GNU Fortran language, of some fairly large prime numbers.
2350 This could lead to the GNU Fortran language being declared
2351 ``munitions'' by the United States Department of Defense.
2352
2353 @node Constants
2354 @subsection Constants
2355 @cindex constants
2356 @cindex types, constants
2357
2358 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
2359
2360 A @dfn{typeless constant} has one of the following forms:
2361
2362 @smallexample
2363 '@var{binary-digits}'B
2364 '@var{octal-digits}'O
2365 '@var{hexadecimal-digits}'Z
2366 '@var{hexadecimal-digits}'X
2367 @end smallexample
2368
2369 @noindent
2370 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
2371 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
2372 and @samp{0123456789ABCDEFabcdef}, respectively.
2373 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
2374 is 11, and so on.)
2375
2376 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
2377 treated as typeless.  @xref{Fortran Dialect Options,, Options
2378 Controlling Fortran Dialect}, for information on the
2379 @option{-ftypeless-boz} option.
2380
2381 Typeless constants have values that depend on the context in which
2382 they are used.
2383
2384 All other constants, called @dfn{typed constants}, are interpreted---converted
2385 to internal form---according to their inherent type.
2386 Thus, context is @emph{never} a determining factor for the type, and hence
2387 the interpretation, of a typed constant.
2388 (All constants in the ANSI FORTRAN 77 language are typed constants.)
2389
2390 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
2391 Fortran (called default INTEGER in Fortran 90),
2392 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
2393 additional precision specified is lost, and even when used in a
2394 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
2395 and @samp{1D0} is always type @code{REAL(KIND=2)}.
2396
2397 @node Integer Type
2398 @subsection Integer Type
2399
2400 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
2401
2402 An integer constant also may have one of the following forms:
2403
2404 @smallexample
2405 B'@var{binary-digits}'
2406 O'@var{octal-digits}'
2407 Z'@var{hexadecimal-digits}'
2408 X'@var{hexadecimal-digits}'
2409 @end smallexample
2410
2411 @noindent
2412 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
2413 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
2414 and @samp{0123456789ABCDEFabcdef}, respectively.
2415 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
2416 is 11, and so on.)
2417
2418 @node Character Type
2419 @subsection Character Type
2420
2421 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
2422
2423 @cindex double quoted character constants
2424 A character constant may be delimited by a pair of double quotes
2425 (@samp{"}) instead of apostrophes.
2426 In this case, an apostrophe within the constant represents
2427 a single apostrophe, while a double quote is represented in
2428 the source text of the constant by two consecutive double
2429 quotes with no intervening spaces.
2430
2431 @cindex zero-length CHARACTER
2432 @cindex null CHARACTER strings
2433 @cindex empty CHARACTER strings
2434 @cindex strings, empty
2435 @cindex CHARACTER, null
2436 A character constant may be empty (have a length of zero).
2437
2438 A character constant may include a substring specification,
2439 The value of such a constant is the value of the substring---for
2440 example, the value of @samp{'hello'(3:5)} is the same
2441 as the value of @samp{'llo'}.
2442
2443 @node Expressions
2444 @section Expressions
2445
2446 (The following information augments or overrides the information in
2447 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2448 language.
2449 Chapter 6 of that document otherwise serves as the basis
2450 for the relevant aspects of GNU Fortran.)
2451
2452 @menu
2453 * %LOC()::
2454 @end menu
2455
2456 @node %LOC()
2457 @subsection The @code{%LOC()} Construct
2458 @cindex %LOC() construct
2459
2460 @example
2461 %LOC(@var{arg})
2462 @end example
2463
2464 The @code{%LOC()} construct is an expression
2465 that yields the value of the location of its argument,
2466 @var{arg}, in memory.
2467 The size of the type of the expression depends on the system---typically,
2468 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
2469 though it is actually type @code{INTEGER(KIND=7)}.
2470
2471 The argument to @code{%LOC()} must be suitable as the
2472 left-hand side of an assignment statement.
2473 That is, it may not be a general expression involving
2474 operators such as addition, subtraction, and so on,
2475 nor may it be a constant.
2476
2477 Use of @code{%LOC()} is recommended only for code that
2478 is accessing facilities outside of GNU Fortran, such as
2479 operating system or windowing facilities.
2480 It is best to constrain such uses to isolated portions of
2481 a program---portions that deal specifically and exclusively
2482 with low-level, system-dependent facilities.
2483 Such portions might well provide a portable interface for
2484 use by the program as a whole, but are themselves not
2485 portable, and should be thoroughly tested each time they
2486 are rebuilt using a new compiler or version of a compiler.
2487
2488 Do not depend on @code{%LOC()} returning a pointer that
2489 can be safely used to @emph{define} (change) the argument.
2490 While this might work in some circumstances, it is hard
2491 to predict whether it will continue to work when a program
2492 (that works using this unsafe behavior)
2493 is recompiled using different command-line options or
2494 a different version of @command{g77}.
2495
2496 Generally, @code{%LOC()} is safe when used as an argument
2497 to a procedure that makes use of the value of the corresponding
2498 dummy argument only during its activation, and only when
2499 such use is restricted to referencing (reading) the value
2500 of the argument to @code{%LOC()}.
2501
2502 @emph{Implementation Note:} Currently, @command{g77} passes
2503 arguments (those not passed using a construct such as @code{%VAL()})
2504 by reference or descriptor, depending on the type of
2505 the actual argument.
2506 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
2507 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
2508 in fact might compile to identical code.
2509
2510 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
2511 ``pass, by value, the address of @samp{I} in memory''.
2512 While @samp{CALL FOO(I)} might use that same approach in a
2513 particular version of @command{g77}, another version or compiler
2514 might choose a different implementation, such as copy-in/copy-out,
2515 to effect the desired behavior---and which will therefore not
2516 necessarily compile to the same code as would
2517 @samp{CALL FOO(%VAL(%LOC(I)))}
2518 using the same version or compiler.
2519
2520 @xref{Debugging and Interfacing}, for detailed information on
2521 how this particular version of @command{g77} implements various
2522 constructs.
2523
2524 @node Specification Statements
2525 @section Specification Statements
2526
2527 (The following information augments or overrides the information in
2528 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2529 language.
2530 Chapter 8 of that document otherwise serves as the basis
2531 for the relevant aspects of GNU Fortran.)
2532
2533 @menu
2534 * NAMELIST::
2535 * DOUBLE COMPLEX::
2536 @end menu
2537
2538 @node NAMELIST
2539 @subsection @code{NAMELIST} Statement
2540 @cindex NAMELIST statement
2541 @cindex statements, NAMELIST
2542
2543 The @code{NAMELIST} statement, and related I/O constructs, are
2544 supported by the GNU Fortran language in essentially the same
2545 way as they are by @command{f2c}.
2546
2547 This follows Fortran 90 with the restriction that on @code{NAMELIST}
2548 input, subscripts must have the form
2549 @smallexample
2550 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
2551 @end smallexample
2552 i.e.@:
2553 @smallexample
2554 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
2555 @end smallexample
2556 is allowed, but not, say,
2557 @smallexample
2558 &xx x(:3,8::2)=1,2,3,4,5,6/
2559 @end smallexample
2560
2561 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
2562 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
2563 @smallexample
2564 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
2565 @end smallexample
2566 could be used instead of the example above.
2567
2568 @node DOUBLE COMPLEX
2569 @subsection @code{DOUBLE COMPLEX} Statement
2570 @cindex DOUBLE COMPLEX
2571
2572 @code{DOUBLE COMPLEX} is a type-statement (and type) that
2573 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
2574
2575 @node Control Statements
2576 @section Control Statements
2577
2578 (The following information augments or overrides the information in
2579 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2580 language.
2581 Chapter 11 of that document otherwise serves as the basis
2582 for the relevant aspects of GNU Fortran.)
2583
2584 @menu
2585 * DO WHILE::
2586 * END DO::
2587 * Construct Names::
2588 * CYCLE and EXIT::
2589 @end menu
2590
2591 @node DO WHILE
2592 @subsection DO WHILE
2593 @cindex DO WHILE
2594 @cindex DO
2595 @cindex MIL-STD 1753
2596
2597 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
2598 Fortran 90 standards, is provided by the GNU Fortran language.
2599 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
2600 also supported.
2601
2602 @node END DO
2603 @subsection END DO
2604 @cindex END DO
2605 @cindex MIL-STD 1753
2606
2607 The @code{END DO} statement is provided by the GNU Fortran language.
2608
2609 This statement is used in one of two ways:
2610
2611 @itemize @bullet
2612 @item
2613 The Fortran 90 meaning, in which it specifies the termination
2614 point of a single @code{DO} loop started with a @code{DO} statement
2615 that specifies no termination label.
2616
2617 @item
2618 The MIL-STD 1753 meaning, in which it specifies the termination
2619 point of one or more @code{DO} loops, all of which start with a
2620 @code{DO} statement that specify the label defined for the
2621 @code{END DO} statement.
2622
2623 This kind of @code{END DO} statement is merely a synonym for
2624 @code{CONTINUE}, except it is permitted only when the statement
2625 is labeled and a target of one or more labeled @code{DO} loops.
2626
2627 It is expected that this use of @code{END DO} will be removed from
2628 the GNU Fortran language in the future, though it is likely that
2629 it will long be supported by @command{g77} as a dialect form.
2630 @end itemize
2631
2632 @node Construct Names
2633 @subsection Construct Names
2634 @cindex construct names
2635
2636 The GNU Fortran language supports construct names as defined
2637 by the Fortran 90 standard.
2638 These names are local to the program unit and are defined
2639 as follows:
2640
2641 @smallexample
2642 @var{construct-name}: @var{block-statement}
2643 @end smallexample
2644
2645 @noindent
2646 Here, @var{construct-name} is the construct name itself;
2647 its definition is connoted by the single colon (@samp{:}); and
2648 @var{block-statement} is an @code{IF}, @code{DO},
2649 or @code{SELECT CASE} statement that begins a block.
2650
2651 A block that is given a construct name must also specify the
2652 same construct name in its termination statement:
2653
2654 @example
2655 END @var{block} @var{construct-name}
2656 @end example
2657
2658 @noindent
2659 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
2660 as appropriate.
2661
2662 @node CYCLE and EXIT
2663 @subsection The @code{CYCLE} and @code{EXIT} Statements
2664
2665 @cindex CYCLE statement
2666 @cindex EXIT statement
2667 @cindex statements, CYCLE
2668 @cindex statements, EXIT
2669 The @code{CYCLE} and @code{EXIT} statements specify that
2670 the remaining statements in the current iteration of a
2671 particular active (enclosing) @code{DO} loop are to be skipped.
2672
2673 @code{CYCLE} specifies that these statements are skipped,
2674 but the @code{END DO} statement that marks the end of the
2675 @code{DO} loop be executed---that is, the next iteration,
2676 if any, is to be started.
2677 If the statement marking the end of the @code{DO} loop is
2678 not @code{END DO}---in other words, if the loop is not
2679 a block @code{DO}---the @code{CYCLE} statement does not
2680 execute that statement, but does start the next iteration (if any).
2681
2682 @code{EXIT} specifies that the loop specified by the
2683 @code{DO} construct is terminated.
2684
2685 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
2686 is the innermost enclosing @code{DO} loop when the following
2687 forms are used:
2688
2689 @example
2690 CYCLE
2691 EXIT
2692 @end example
2693
2694 Otherwise, the following forms specify the construct name
2695 of the pertinent @code{DO} loop:
2696
2697 @example
2698 CYCLE @var{construct-name}
2699 EXIT @var{construct-name}
2700 @end example
2701
2702 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
2703 statements.
2704 However, they cannot be easily thought of as @code{GO TO} statements
2705 in obscure cases involving FORTRAN 77 loops.
2706 For example:
2707
2708 @smallexample
2709       DO 10 I = 1, 5
2710       DO 10 J = 1, 5
2711          IF (J .EQ. 5) EXIT
2712       DO 10 K = 1, 5
2713          IF (K .EQ. 3) CYCLE
2714 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
2715 20    CONTINUE
2716 @end smallexample
2717
2718 @noindent
2719 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
2720 above are equivalent to a @code{GO TO} statement to either label
2721 @samp{10} or @samp{20}.
2722
2723 To understand the effect of @code{CYCLE} and @code{EXIT} in the
2724 above fragment, it is helpful to first translate it to its equivalent
2725 using only block @code{DO} loops:
2726
2727 @smallexample
2728       DO I = 1, 5
2729          DO J = 1, 5
2730             IF (J .EQ. 5) EXIT
2731             DO K = 1, 5
2732                IF (K .EQ. 3) CYCLE
2733 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
2734             END DO
2735          END DO
2736       END DO
2737 20    CONTINUE
2738 @end smallexample
2739
2740 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
2741 to @code{GO TO} so they may be more easily understood by programmers
2742 accustomed to FORTRAN coding:
2743
2744 @smallexample
2745       DO I = 1, 5
2746          DO J = 1, 5
2747             IF (J .EQ. 5) GOTO 18
2748             DO K = 1, 5
2749                IF (K .EQ. 3) GO TO 12
2750 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
2751 12          END DO
2752          END DO
2753 18    END DO
2754 20    CONTINUE
2755 @end smallexample
2756
2757 @noindent
2758 Thus, the @code{CYCLE} statement in the innermost loop skips over
2759 the @code{PRINT} statement as it begins the next iteration of the
2760 loop, while the @code{EXIT} statement in the middle loop ends that
2761 loop but @emph{not} the outermost loop.
2762
2763 @node Functions and Subroutines
2764 @section Functions and Subroutines
2765
2766 (The following information augments or overrides the information in
2767 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2768 language.
2769 Chapter 15 of that document otherwise serves as the basis
2770 for the relevant aspects of GNU Fortran.)
2771
2772 @menu
2773 * %VAL()::
2774 * %REF()::
2775 * %DESCR()::
2776 * Generics and Specifics::
2777 * REAL() and AIMAG() of Complex::
2778 * CMPLX() of DOUBLE PRECISION::
2779 * MIL-STD 1753::
2780 * f77/f2c Intrinsics::
2781 * Table of Intrinsic Functions::
2782 @end menu
2783
2784 @node %VAL()
2785 @subsection The @code{%VAL()} Construct
2786 @cindex %VAL() construct
2787
2788 @example
2789 %VAL(@var{arg})
2790 @end example
2791
2792 The @code{%VAL()} construct specifies that an argument,
2793 @var{arg}, is to be passed by value, instead of by reference
2794 or descriptor.
2795
2796 @code{%VAL()} is restricted to actual arguments in
2797 invocations of external procedures.
2798
2799 Use of @code{%VAL()} is recommended only for code that
2800 is accessing facilities outside of GNU Fortran, such as
2801 operating system or windowing facilities.
2802 It is best to constrain such uses to isolated portions of
2803 a program---portions the deal specifically and exclusively
2804 with low-level, system-dependent facilities.
2805 Such portions might well provide a portable interface for
2806 use by the program as a whole, but are themselves not
2807 portable, and should be thoroughly tested each time they
2808 are rebuilt using a new compiler or version of a compiler.
2809
2810 @emph{Implementation Note:} Currently, @command{g77} passes
2811 all arguments either by reference or by descriptor.
2812
2813 Thus, use of @code{%VAL()} tends to be restricted to cases
2814 where the called procedure is written in a language other
2815 than Fortran that supports call-by-value semantics.
2816 (C is an example of such a language.)
2817
2818 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
2819 for detailed information on
2820 how this particular version of @command{g77} passes arguments
2821 to procedures.
2822
2823 @node %REF()
2824 @subsection The @code{%REF()} Construct
2825 @cindex %REF() construct
2826
2827 @example
2828 %REF(@var{arg})
2829 @end example
2830
2831 The @code{%REF()} construct specifies that an argument,
2832 @var{arg}, is to be passed by reference, instead of by
2833 value or descriptor.
2834
2835 @code{%REF()} is restricted to actual arguments in
2836 invocations of external procedures.
2837
2838 Use of @code{%REF()} is recommended only for code that
2839 is accessing facilities outside of GNU Fortran, such as
2840 operating system or windowing facilities.
2841 It is best to constrain such uses to isolated portions of
2842 a program---portions the deal specifically and exclusively
2843 with low-level, system-dependent facilities.
2844 Such portions might well provide a portable interface for
2845 use by the program as a whole, but are themselves not
2846 portable, and should be thoroughly tested each time they
2847 are rebuilt using a new compiler or version of a compiler.
2848
2849 Do not depend on @code{%REF()} supplying a pointer to the
2850 procedure being invoked.
2851 While that is a likely implementation choice, other
2852 implementation choices are available that preserve Fortran
2853 pass-by-reference semantics without passing a pointer to
2854 the argument, @var{arg}.
2855 (For example, a copy-in/copy-out implementation.)
2856
2857 @emph{Implementation Note:} Currently, @command{g77} passes
2858 all arguments
2859 (other than variables and arrays of type @code{CHARACTER})
2860 by reference.
2861 Future versions of, or dialects supported by, @command{g77} might
2862 not pass @code{CHARACTER} functions by reference.
2863
2864 Thus, use of @code{%REF()} tends to be restricted to cases
2865 where @var{arg} is type @code{CHARACTER} but the called
2866 procedure accesses it via a means other than the method
2867 used for Fortran @code{CHARACTER} arguments.
2868
2869 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
2870 how this particular version of @command{g77} passes arguments
2871 to procedures.
2872
2873 @node %DESCR()
2874 @subsection The @code{%DESCR()} Construct
2875 @cindex %DESCR() construct
2876
2877 @example
2878 %DESCR(@var{arg})
2879 @end example
2880
2881 The @code{%DESCR()} construct specifies that an argument,
2882 @var{arg}, is to be passed by descriptor, instead of by
2883 value or reference.
2884
2885 @code{%DESCR()} is restricted to actual arguments in
2886 invocations of external procedures.
2887
2888 Use of @code{%DESCR()} is recommended only for code that
2889 is accessing facilities outside of GNU Fortran, such as
2890 operating system or windowing facilities.
2891 It is best to constrain such uses to isolated portions of
2892 a program---portions the deal specifically and exclusively
2893 with low-level, system-dependent facilities.
2894 Such portions might well provide a portable interface for
2895 use by the program as a whole, but are themselves not
2896 portable, and should be thoroughly tested each time they
2897 are rebuilt using a new compiler or version of a compiler.
2898
2899 Do not depend on @code{%DESCR()} supplying a pointer
2900 and/or a length passed by value
2901 to the procedure being invoked.
2902 While that is a likely implementation choice, other
2903 implementation choices are available that preserve the
2904 pass-by-reference semantics without passing a pointer to
2905 the argument, @var{arg}.
2906 (For example, a copy-in/copy-out implementation.)
2907 And, future versions of @command{g77} might change the
2908 way descriptors are implemented, such as passing a
2909 single argument pointing to a record containing the
2910 pointer/length information instead of passing that same
2911 information via two arguments as it currently does.
2912
2913 @emph{Implementation Note:} Currently, @command{g77} passes
2914 all variables and arrays of type @code{CHARACTER}
2915 by descriptor.
2916 Future versions of, or dialects supported by, @command{g77} might
2917 pass @code{CHARACTER} functions by descriptor as well.
2918
2919 Thus, use of @code{%DESCR()} tends to be restricted to cases
2920 where @var{arg} is not type @code{CHARACTER} but the called
2921 procedure accesses it via a means similar to the method
2922 used for Fortran @code{CHARACTER} arguments.
2923
2924 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
2925 how this particular version of @command{g77} passes arguments
2926 to procedures.
2927
2928 @node Generics and Specifics
2929 @subsection Generics and Specifics
2930 @cindex generic intrinsics
2931 @cindex intrinsics, generic
2932
2933 The ANSI FORTRAN 77 language defines generic and specific
2934 intrinsics.
2935 In short, the distinctions are:
2936
2937 @itemize @bullet
2938 @item
2939 @emph{Specific} intrinsics have
2940 specific types for their arguments and a specific return
2941 type.
2942
2943 @item
2944 @emph{Generic} intrinsics are treated,
2945 on a case-by-case basis in the program's source code,
2946 as one of several possible specific intrinsics.
2947
2948 Typically, a generic intrinsic has a return type that
2949 is determined by the type of one or more of its arguments.
2950 @end itemize
2951
2952 The GNU Fortran language generalizes these concepts somewhat,
2953 especially by providing intrinsic subroutines and generic
2954 intrinsics that are treated as either a specific intrinsic subroutine
2955 or a specific intrinsic function (e.g. @code{SECOND}).
2956
2957 However, GNU Fortran avoids generalizing this concept to
2958 the point where existing code would be accepted as meaning
2959 something possibly different than what was intended.
2960
2961 For example, @code{ABS} is a generic intrinsic, so all working
2962 code written using @code{ABS} of an @code{INTEGER} argument
2963 expects an @code{INTEGER} return value.
2964 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
2965 argument returns an @code{INTEGER*2} return value.
2966
2967 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
2968 an @code{INTEGER(KIND=1)} argument.
2969 Code that passes something other than an @code{INTEGER(KIND=1)}
2970 argument to @code{IABS} is not valid GNU Fortran code, because
2971 it is not clear what the author intended.
2972
2973 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
2974 is not defined by the GNU Fortran language, because the programmer
2975 might have used that construct to mean any of the following, subtly
2976 different, things:
2977
2978 @itemize @bullet
2979 @item
2980 Convert @samp{J} to @code{INTEGER(KIND=1)} first
2981 (as if @samp{IABS(INT(J))} had been written).
2982
2983 @item
2984 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
2985 (as if @samp{INT(ABS(J))} had been written).
2986
2987 @item
2988 No conversion (as if @samp{ABS(J)} had been written).
2989 @end itemize
2990
2991 The distinctions matter especially when types and values wider than
2992 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
2993 operations performing more ``arithmetic'' than absolute-value, are involved.
2994
2995 The following sample program is not a valid GNU Fortran program, but
2996 might be accepted by other compilers.
2997 If so, the output is likely to be revealing in terms of how a given
2998 compiler treats intrinsics (that normally are specific) when they
2999 are given arguments that do not conform to their stated requirements:
3000
3001 @cindex JCB002 program
3002 @smallexample
3003       PROGRAM JCB002
3004 C Version 1:
3005 C Modified 1999-02-15 (Burley) to delete my email address.
3006 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
3007 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
3008 C
3009 C Version 0:
3010 C Written by James Craig Burley 1997-02-20.
3011 C
3012 C Purpose:
3013 C Determine how compilers handle non-standard IDIM
3014 C on INTEGER*2 operands, which presumably can be
3015 C extrapolated into understanding how the compiler
3016 C generally treats specific intrinsics that are passed
3017 C arguments not of the correct types.
3018 C
3019 C If your compiler implements INTEGER*2 and INTEGER
3020 C as the same type, change all INTEGER*2 below to
3021 C INTEGER*1.
3022 C
3023       INTEGER*2 I0, I4
3024       INTEGER I1, I2, I3
3025       INTEGER*2 ISMALL, ILARGE
3026       INTEGER*2 ITOOLG, ITWO
3027       INTEGER*2 ITMP
3028       LOGICAL L2, L3, L4
3029 C
3030 C Find smallest INTEGER*2 number.
3031 C
3032       ISMALL=0
3033  10   I0 = ISMALL-1
3034       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
3035       ISMALL = I0
3036       GOTO 10
3037  20   CONTINUE
3038 C
3039 C Find largest INTEGER*2 number.
3040 C
3041       ILARGE=0
3042  30   I0 = ILARGE+1
3043       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
3044       ILARGE = I0
3045       GOTO 30
3046  40   CONTINUE
3047 C
3048 C Multiplying by two adds stress to the situation.
3049 C
3050       ITWO = 2
3051 C
3052 C Need a number that, added to -2, is too wide to fit in I*2.
3053 C
3054       ITOOLG = ISMALL
3055 C
3056 C Use IDIM the straightforward way.
3057 C
3058       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
3059 C
3060 C Calculate result for first interpretation.
3061 C
3062       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
3063 C
3064 C Calculate result for second interpretation.
3065 C
3066       ITMP = ILARGE - ISMALL
3067       I3 = (INT (ITMP)) * ITWO + ITOOLG
3068 C
3069 C Calculate result for third interpretation.
3070 C
3071       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
3072 C
3073 C Print results.
3074 C
3075       PRINT *, 'ILARGE=', ILARGE
3076       PRINT *, 'ITWO=', ITWO
3077       PRINT *, 'ITOOLG=', ITOOLG
3078       PRINT *, 'ISMALL=', ISMALL
3079       PRINT *, 'I1=', I1
3080       PRINT *, 'I2=', I2
3081       PRINT *, 'I3=', I3
3082       PRINT *, 'I4=', I4
3083       PRINT *
3084       L2 = (I1 .EQ. I2)
3085       L3 = (I1 .EQ. I3)
3086       L4 = (I1 .EQ. I4)
3087       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
3088          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
3089          STOP
3090       END IF
3091       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
3092          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
3093          STOP
3094       END IF
3095       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
3096          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
3097          STOP
3098       END IF
3099       PRINT *, 'Results need careful analysis.'
3100       END
3101 @end smallexample
3102
3103 No future version of the GNU Fortran language
3104 will likely permit specific intrinsic invocations with wrong-typed
3105 arguments (such as @code{IDIM} in the above example), since
3106 it has been determined that disagreements exist among
3107 many production compilers on the interpretation of
3108 such invocations.
3109 These disagreements strongly suggest that Fortran programmers,
3110 and certainly existing Fortran programs, disagree about the
3111 meaning of such invocations.
3112
3113 The first version of @code{JCB002} didn't accommodate some compilers'
3114 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
3115 @code{INTEGER*2}.
3116 In such a case, these compilers apparently convert both
3117 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
3118 instead of doing an @code{INTEGER*2} subtraction on the
3119 original values in @samp{I1} and @samp{I2}.
3120
3121 However, the results of the careful analyses done on the outputs
3122 of programs compiled by these various compilers show that they
3123 all implement either @samp{Interp 1} or @samp{Interp 2} above.
3124
3125 Specifically, it is believed that the new version of @code{JCB002}
3126 above will confirm that:
3127
3128 @itemize @bullet
3129 @item
3130 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
3131 @command{f77} compilers all implement @samp{Interp 1}.
3132
3133 @item
3134 IRIX 5.3 @command{f77} compiler implements @samp{Interp 2}.
3135
3136 @item
3137 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
3138 and IRIX 6.1 @command{f77} compilers all implement @samp{Interp 3}.
3139 @end itemize
3140
3141 If you get different results than the above for the stated
3142 compilers, or have results for other compilers that might be
3143 worth adding to the above list, please let us know the details
3144 (compiler product, version, machine, results, and so on).
3145
3146 @node REAL() and AIMAG() of Complex
3147 @subsection @code{REAL()} and @code{AIMAG()} of Complex
3148 @cindex @code{Real} intrinsic
3149 @cindex intrinsics, @code{Real}
3150 @cindex @code{AImag} intrinsic
3151 @cindex intrinsics, @code{AImag}
3152
3153 The GNU Fortran language disallows @code{REAL(@var{expr})}
3154 and @code{AIMAG(@var{expr})},
3155 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
3156 except when they are used in the following way:
3157
3158 @example
3159 REAL(REAL(@var{expr}))
3160 REAL(AIMAG(@var{expr}))
3161 @end example
3162
3163 @noindent
3164 The above forms explicitly specify that the desired effect
3165 is to convert the real or imaginary part of @var{expr}, which might
3166 be some @code{REAL} type other than @code{REAL(KIND=1)},
3167 to type @code{REAL(KIND=1)},
3168 and have that serve as the value of the expression.
3169
3170 The GNU Fortran language offers clearly named intrinsics to extract the
3171 real and imaginary parts of a complex entity without any
3172 conversion:
3173
3174 @example
3175 REALPART(@var{expr})
3176 IMAGPART(@var{expr})
3177 @end example
3178
3179 To express the above using typical extended FORTRAN 77,
3180 use the following constructs
3181 (when @var{expr} is @code{COMPLEX(KIND=2)}):
3182
3183 @example
3184 DBLE(@var{expr})
3185 DIMAG(@var{expr})
3186 @end example
3187
3188 The FORTRAN 77 language offers no way
3189 to explicitly specify the real and imaginary parts of a complex expression of
3190 arbitrary type, apparently as a result of requiring support for
3191 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
3192 The concepts of converting an expression to type @code{REAL(KIND=1)} and
3193 of extracting the real part of a complex expression were
3194 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
3195 they happened to have the exact same effect in that language
3196 (due to having only one @code{COMPLEX} type).
3197
3198 @emph{Note:} When @option{-ff90} is in effect,
3199 @command{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
3200 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
3201 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
3202 treated as @samp{REAL(REALPART(@var{expr}))}.
3203
3204 @xref{Ugly Complex Part Extraction}, for more information.
3205
3206 @node CMPLX() of DOUBLE PRECISION
3207 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
3208 @cindex @code{Cmplx} intrinsic
3209 @cindex intrinsics, @code{Cmplx}
3210
3211 In accordance with Fortran 90 and at least some (perhaps all)
3212 other compilers, the GNU Fortran language defines @code{CMPLX()}
3213 as always returning a result that is type @code{COMPLEX(KIND=1)}.
3214
3215 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
3216 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
3217
3218 @example
3219 CMPLX(SNGL(D1), SNGL(D2))
3220 @end example
3221
3222 (It was necessary for Fortran 90 to specify this behavior
3223 for @code{DOUBLE PRECISION} arguments, since that is
3224 the behavior mandated by FORTRAN 77.)
3225
3226 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
3227 which is provided by some FORTRAN 77 compilers to construct
3228 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
3229 operands.
3230 However, this solution does not scale well when more @code{COMPLEX} types
3231 (having various precisions and ranges) are offered by Fortran implementations.
3232
3233 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
3234 an extra argument used to specify the desired kind of complex
3235 result.
3236 However, this solution is somewhat awkward to use, and
3237 @command{g77} currently does not support it.
3238
3239 The GNU Fortran language provides a simple way to build a complex
3240 value out of two numbers, with the precise type of the value
3241 determined by the types of the two numbers (via the usual
3242 type-promotion mechanism):
3243
3244 @example
3245 COMPLEX(@var{real}, @var{imag})
3246 @end example
3247
3248 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
3249 performs no conversion other than to put them together to form a
3250 complex result of the same (complex version of real) type.
3251
3252 @xref{Complex Intrinsic}, for more information.
3253
3254 @node MIL-STD 1753
3255 @subsection MIL-STD 1753 Support
3256 @cindex MIL-STD 1753
3257
3258 The GNU Fortran language includes the MIL-STD 1753 intrinsics
3259 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
3260 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
3261 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
3262
3263 @node f77/f2c Intrinsics
3264 @subsection @command{f77}/@command{f2c} Intrinsics
3265
3266 The bit-manipulation intrinsics supported by traditional
3267 @command{f77} and by @command{f2c} are available in the GNU Fortran language.
3268 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
3269 and @code{XOR}.
3270
3271 Also supported are the intrinsics @code{CDABS},
3272 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
3273 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
3274 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
3275 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
3276 and @code{ZSQRT}.
3277
3278 @node Table of Intrinsic Functions
3279 @subsection Table of Intrinsic Functions
3280 @cindex intrinsics, table of
3281 @cindex table of intrinsics
3282
3283 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
3284
3285 The GNU Fortran language adds various functions, subroutines, types,
3286 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
3287 The complete set of intrinsics supported by the GNU Fortran language
3288 is described below.
3289
3290 Note that a name is not treated as that of an intrinsic if it is
3291 specified in an @code{EXTERNAL} statement in the same program unit;
3292 if a command-line option is used to disable the groups to which
3293 the intrinsic belongs; or if the intrinsic is not named in an
3294 @code{INTRINSIC} statement and a command-line option is used to
3295 hide the groups to which the intrinsic belongs.
3296
3297 So, it is recommended that any reference in a program unit to
3298 an intrinsic procedure that is not a standard FORTRAN 77
3299 intrinsic be accompanied by an appropriate @code{INTRINSIC}
3300 statement in that program unit.
3301 This sort of defensive programming makes it more
3302 likely that an implementation will issue a diagnostic rather
3303 than generate incorrect code for such a reference.
3304
3305 The terminology used below is based on that of the Fortran 90
3306 standard, so that the text may be more concise and accurate:
3307
3308 @itemize @bullet
3309 @item
3310 @code{OPTIONAL} means the argument may be omitted.
3311
3312 @item
3313 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
3314 (generally named @samp{A}) may be specified.
3315
3316 @item
3317 @samp{scalar} means the argument must not be an array (must
3318 be a variable or array element, or perhaps a constant if expressions
3319 are permitted).
3320
3321 @item
3322 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
3323
3324 @item
3325 @code{INTENT(IN)} means the argument must be an expression
3326 (such as a constant or a variable that is defined upon invocation
3327 of the intrinsic).
3328
3329 @item
3330 @code{INTENT(OUT)} means the argument must be definable by the
3331 invocation of the intrinsic (that is, must not be a constant nor
3332 an expression involving operators other than array reference and
3333 substring reference).
3334
3335 @item
3336 @code{INTENT(INOUT)} means the argument must be defined prior to,
3337 and definable by, invocation of the intrinsic (a combination of
3338 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
3339
3340 @item
3341 @xref{Kind Notation}, for an explanation of @code{KIND}.
3342 @end itemize
3343
3344 @ifinfo
3345 (Note that the empty lines appearing in the menu below
3346 are not intentional---they result from a bug in the
3347 GNU @command{makeinfo} program@dots{}a program that, if it
3348 did not exist, would leave this document in far worse shape!)
3349 @end ifinfo
3350
3351 @c The actual documentation for intrinsics comes from
3352 @c intdoc.texi, which in turn is automatically generated
3353 @c from the internal g77 tables in intrin.def _and_ the
3354 @c largely hand-written text in intdoc.h.  So, if you want
3355 @c to change or add to existing documentation on intrinsics,
3356 @c you probably want to edit intdoc.h.
3357 @c
3358 @set familyF77
3359 @set familyGNU
3360 @set familyASC
3361 @set familyMIL
3362 @set familyF90
3363 @clear familyVXT
3364 @clear familyFVZ
3365 @set familyF2C
3366 @set familyF2U
3367 @clear familyBADU77
3368 @include intdoc.texi
3369
3370 @node Scope and Classes of Names
3371 @section Scope and Classes of Symbolic Names
3372 @cindex symbol names, scope and classes
3373 @cindex scope
3374
3375 (The following information augments or overrides the information in
3376 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3377 language.
3378 Chapter 18 of that document otherwise serves as the basis
3379 for the relevant aspects of GNU Fortran.)
3380
3381 @menu
3382 * Underscores in Symbol Names::
3383 @end menu
3384
3385 @node Underscores in Symbol Names
3386 @subsection Underscores in Symbol Names
3387 @cindex underscore
3388
3389 Underscores (@samp{_}) are accepted in symbol names after the first
3390 character (which must be a letter).
3391
3392 @node I/O
3393 @section I/O
3394
3395 @cindex dollar sign
3396 A dollar sign at the end of an output format specification suppresses
3397 the newline at the end of the output.
3398
3399 @cindex <> edit descriptor
3400 @cindex edit descriptor, <>
3401 Edit descriptors in @code{FORMAT} statements may contain compile-time
3402 @code{INTEGER} constant expressions in angle brackets, such as
3403 @smallexample
3404 10    FORMAT (I<WIDTH>)
3405 @end smallexample
3406
3407 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
3408
3409 These Fortran 90 features are supported:
3410 @itemize @bullet
3411 @item
3412 @cindex FORMAT descriptors
3413 @cindex Z edit descriptor
3414 @cindex edit descriptor, Z
3415 @cindex O edit descriptor
3416 @cindex edit descriptor, O
3417 The @code{O} and @code{Z} edit descriptors are supported for I/O of
3418 integers in octal and hexadecimal formats, respectively.
3419 @item
3420 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
3421 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
3422 specifier is supported.
3423 @end itemize
3424
3425 @node Fortran 90 Features
3426 @section Fortran 90 Features
3427 @cindex Fortran 90
3428 @cindex extensions, from Fortran 90
3429
3430 For convenience this section collects a list (probably incomplete) of
3431 the Fortran 90 features supported by the GNU Fortran language, even if
3432 they are documented elsewhere.
3433 @xref{Characters Lines Sequence,,@asis{Characters, Lines, and Execution Sequence}},
3434 for information on additional fixed source form lexical issues.
3435 @cindex @option{-ffree-form}
3436 Further, the free source form is supported through the
3437 @option{-ffree-form} option.
3438 @cindex @option{-ff90}
3439 Other Fortran 90 features can be turned on by the @option{-ff90} option;
3440 see @ref{Fortran 90}.
3441 For information on the Fortran 90 intrinsics available,
3442 see @ref{Table of Intrinsic Functions}.
3443
3444 @table @asis
3445 @item Automatic arrays in procedures
3446 @item Character assignments
3447 @cindex character assignments
3448 In character assignments, the variable being assigned may occur on the
3449 right hand side of the assignment.
3450 @item Character strings
3451 @cindex double quoted character constants
3452 Strings may have zero length and substrings of character constants are
3453 permitted.  Character constants may be enclosed in double quotes
3454 (@code{"}) as well as single quotes.  @xref{Character Type}.
3455 @item Construct names
3456 (Symbolic tags on blocks.)  @xref{Construct Names}.
3457 @item @code{CYCLE} and @code{EXIT}
3458 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
3459 @item @code{DOUBLE COMPLEX}
3460 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement}.
3461 @item @code{DO WHILE}
3462 @xref{DO WHILE}.
3463 @item @code{END} decoration
3464 @xref{Statements}.
3465 @item @code{END DO}
3466 @xref{END DO}.
3467 @item @code{KIND}
3468 @item @code{IMPLICIT NONE}
3469 @item @code{INCLUDE} statements
3470 @xref{INCLUDE}.
3471 @item List-directed and namelist I/O on internal files
3472 @item Binary, octal and hexadecimal constants
3473 These are supported more generally than required by Fortran 90.
3474 @xref{Integer Type}.
3475 @item @samp{O} and @samp{Z} edit descriptors
3476 @item @code{NAMELIST}
3477 @xref{NAMELIST}.
3478 @item @code{OPEN} specifiers
3479 @code{STATUS='REPLACE'} is supported.
3480 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
3481 @code{STATUS='SCRATCH'} is supplied.
3482 @item @code{FORMAT} edit descriptors
3483 @cindex FORMAT descriptors
3484 @cindex Z edit descriptor
3485 @cindex edit descriptor, Z
3486 The @code{Z} edit descriptor is supported.
3487 @item Relational operators
3488 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
3489 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
3490 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
3491 @item @code{SELECT CASE}
3492 Not fully implemented.
3493 @xref{SELECT CASE on CHARACTER Type,, @code{SELECT CASE} on @code{CHARACTER} Type}.
3494 @item Specification statements
3495 A limited subset of the Fortran 90 syntax and semantics for variable
3496 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
3497 (@code{KIND} is of limited usefulness in the absence of the
3498 @code{KIND}-related intrinsics, since these intrinsics permit writing
3499 more widely portable code.)  An example of supported @code{KIND} usage
3500 is:
3501 @smallexample
3502 INTEGER (KIND=1) :: FOO=1, BAR=2
3503 CHARACTER (LEN=3) FOO
3504 @end smallexample
3505 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
3506 @end table
3507
3508 @node Other Dialects
3509 @chapter Other Dialects
3510
3511 GNU Fortran supports a variety of features that are not
3512 considered part of the GNU Fortran language itself, but
3513 are representative of various dialects of Fortran that
3514 @command{g77} supports in whole or in part.
3515
3516 Any of the features listed below might be disallowed by
3517 @command{g77} unless some command-line option is specified.
3518 Currently, some of the features are accepted using the
3519 default invocation of @command{g77}, but that might change
3520 in the future.
3521
3522 @emph{Note: This portion of the documentation definitely needs a lot
3523 of work!}
3524
3525 @menu
3526 * Source Form::       Details of fixed-form and free-form source.
3527 * Trailing Comment::  Use of @samp{/*} to start a comment.
3528 * Debug Line::        Use of @samp{D} in column 1.
3529 * Dollar Signs::      Use of @samp{$} in symbolic names.
3530 * Case Sensitivity::  Uppercase and lowercase in source files.
3531 * VXT Fortran::       @dots{}versus the GNU Fortran language.
3532 * Fortran 90::        @dots{}versus the GNU Fortran language.
3533 * Pedantic Compilation::  Enforcing the standard.
3534 * Distensions::       Misfeatures supported by GNU Fortran.
3535 @end menu
3536
3537 @node Source Form
3538 @section Source Form
3539 @cindex source file format
3540 @cindex source format
3541 @cindex file, source
3542 @cindex source code
3543 @cindex code, source
3544 @cindex fixed form
3545 @cindex free form
3546
3547 GNU Fortran accepts programs written in either fixed form or
3548 free form.
3549
3550 Fixed form
3551 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
3552 allowing tabs) and Fortran 90's fixed form.
3553
3554 Free form corresponds to
3555 Fortran 90's free form (though possibly not entirely up-to-date, and
3556 without complaining about some things that for which Fortran 90 requires
3557 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
3558
3559 The way a Fortran compiler views source files depends entirely on the
3560 implementation choices made for the compiler, since those choices
3561 are explicitly left to the implementation by the published Fortran
3562 standards.
3563 GNU Fortran currently tries to be somewhat like a few popular compilers
3564 (@command{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
3565 definition along with more
3566 flexibility offered by command-line options is likely to be offered
3567 in version 0.6.
3568
3569 This section describes how @command{g77} interprets source lines.
3570
3571 @menu
3572 * Carriage Returns::  Carriage returns ignored.
3573 * Tabs::              Tabs converted to spaces.
3574 * Short Lines::       Short lines padded with spaces (fixed-form only).
3575 * Long Lines::        Long lines truncated.
3576 * Ampersands::        Special Continuation Lines.
3577 @end menu
3578
3579 @node Carriage Returns
3580 @subsection Carriage Returns
3581 @cindex carriage returns
3582
3583 Carriage returns (@samp{\r}) in source lines are ignored.
3584 This is somewhat different from @command{f2c}, which seems to treat them as
3585 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
3586 inside such constants.
3587
3588 @node Tabs
3589 @subsection Tabs
3590 @cindex tab character
3591 @cindex horizontal tab
3592
3593 A source line with a @key{TAB} character anywhere in it is treated as
3594 entirely significant---however long it is---instead of ending in
3595 column 72 (for fixed-form source) or 132 (for free-form source).
3596 This also is different from @command{f2c}, which encodes tabs as
3597 @samp{\t} (the ASCII @key{TAB} character) inside character
3598 and Hollerith constants, but nevertheless seems to treat the column
3599 position as if it had been affected by the canonical tab positioning.
3600
3601 @command{g77} effectively
3602 translates tabs to the appropriate number of spaces (a la the default
3603 for the UNIX @command{expand} command) before doing any other processing, other
3604 than (currently) noting whether a tab was found on a line and using this
3605 information to decide how to interpret the length of the line and continued
3606 constants.
3607
3608 Note that this default behavior probably will change for version 0.6,
3609 when it will presumably be available via a command-line option.
3610 The default as of version 0.6 is planned to be a ``pure visual''
3611 model, where tabs are immediately
3612 converted to spaces and otherwise have no effect, so the way a typical
3613 user sees source lines produces a consistent result no matter how the
3614 spacing in those source lines is actually implemented via tabs, spaces,
3615 and trailing tabs/spaces before newline.
3616 Command-line options are likely to be added to specify whether all or
3617 just-tabbed lines are to be extended to 132 or full input-line length,
3618 and perhaps even an option will be added to specify the truncated-line
3619 behavior to which some Digital compilers default (and which affects
3620 the way continued character/Hollerith constants are interpreted).
3621
3622 @node Short Lines
3623 @subsection Short Lines
3624 @cindex short source lines
3625 @cindex space, padding with
3626 @cindex source lines, short
3627 @cindex lines, short
3628
3629 Source lines shorter than the applicable fixed-form length are treated as
3630 if they were padded with spaces to that length.
3631 (None of this is relevant to source files written in free form.)
3632
3633 This affects only
3634 continued character and Hollerith constants, and is a different
3635 interpretation than provided by some other popular compilers
3636 (although a bit more consistent with the traditional punched-card
3637 basis of Fortran and the way the Fortran standard expressed fixed
3638 source form).
3639
3640 @command{g77} might someday offer an option to warn about cases where differences
3641 might be seen as a result of this treatment, and perhaps an option to
3642 specify the alternate behavior as well.
3643
3644 Note that this padding cannot apply to lines that are effectively of
3645 infinite length---such lines are specified using command-line options
3646 like @option{-ffixed-line-length-none}, for example.
3647
3648 @node Long Lines
3649 @subsection Long Lines
3650 @cindex long source lines
3651 @cindex truncation, of long lines
3652 @cindex lines, long
3653 @cindex source lines, long
3654
3655 Source lines longer than the applicable length are truncated to that
3656 length.
3657 Currently, @command{g77} does not warn if the truncated characters are
3658 not spaces, to accommodate existing code written for systems that
3659 treated truncated text as commentary (especially in columns 73 through 80).
3660
3661 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
3662 for information on the @option{-ffixed-line-length-@var{n}} option,
3663 which can be used to set the line length applicable to fixed-form
3664 source files.
3665
3666 @node Ampersands
3667 @subsection Ampersand Continuation Line
3668 @cindex ampersand continuation line
3669 @cindex continuation line, ampersand
3670
3671 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
3672 continuation line, imitating the behavior of @command{f2c}.
3673
3674 @node Trailing Comment
3675 @section Trailing Comment
3676
3677 @cindex trailing comment
3678 @cindex comment
3679 @cindex characters, comment
3680 @cindex /*
3681 @cindex !
3682 @cindex exclamation point
3683 @command{g77} supports use of @samp{/*} to start a trailing
3684 comment.
3685 In the GNU Fortran language, @samp{!} is used for this purpose.
3686
3687 @samp{/*} is not in the GNU Fortran language
3688 because the use of @samp{/*} in a program might
3689 suggest to some readers that a block, not trailing, comment is
3690 started (and thus ended by @samp{*/}, not end of line),
3691 since that is the meaning of @samp{/*} in C.
3692
3693 Also, such readers might think they can use @samp{//} to start
3694 a trailing comment as an alternative to @samp{/*}, but
3695 @samp{//} already denotes concatenation, and such a ``comment''
3696 might actually result in a program that compiles without
3697 error (though it would likely behave incorrectly).
3698
3699 @node Debug Line
3700 @section Debug Line
3701 @cindex debug line
3702 @cindex comment line, debug
3703
3704 Use of @samp{D} or @samp{d} as the first character (column 1) of
3705 a source line denotes a debug line.
3706
3707 In turn, a debug line is treated as either a comment line
3708 or a normal line, depending on whether debug lines are enabled.
3709
3710 When treated as a comment line, a line beginning with @samp{D} or
3711 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
3712 When treated as a normal line, such a line is treated as if
3713 the first character was @key{SPC} (space).
3714
3715 (Currently, @command{g77} provides no means for treating debug
3716 lines as normal lines.)
3717
3718 @node Dollar Signs
3719 @section Dollar Signs in Symbol Names
3720 @cindex dollar sign
3721 @cindex $
3722
3723 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
3724 when the @option{-fdollar-ok} option is specified.
3725
3726 @node Case Sensitivity
3727 @section Case Sensitivity
3728 @cindex case sensitivity
3729 @cindex source file format
3730 @cindex code, source
3731 @cindex source code
3732 @cindex uppercase letters
3733 @cindex lowercase letters
3734 @cindex letters, uppercase
3735 @cindex letters, lowercase
3736
3737 GNU Fortran offers the programmer way too much flexibility in deciding
3738 how source files are to be treated vis-a-vis uppercase and lowercase
3739 characters.
3740 There are 66 useful settings that affect case sensitivity, plus 10
3741 settings that are nearly useless, with the remaining 116 settings
3742 being either redundant or useless.
3743
3744 None of these settings have any effect on the contents of comments
3745 (the text after a @samp{c} or @samp{C} in Column 1, for example)
3746 or of character or Hollerith constants.
3747 Note that things like the @samp{E} in the statement
3748 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
3749 are considered built-in keywords, and so are affected by
3750 these settings.
3751
3752 Low-level switches are identified in this section as follows:
3753
3754 @itemize @w{}
3755 @item A
3756 Source Case Conversion:
3757
3758 @itemize @w{}
3759 @item 0
3760 Preserve (see Note 1)
3761 @item 1
3762 Convert to Upper Case
3763 @item 2
3764 Convert to Lower Case
3765 @end itemize
3766
3767 @item B
3768 Built-in Keyword Matching:
3769
3770 @itemize @w{}
3771 @item 0
3772 Match Any Case (per-character basis)
3773 @item 1
3774 Match Upper Case Only
3775 @item 2
3776 Match Lower Case Only
3777 @item 3
3778 Match InitialCaps Only (see tables for spellings)
3779 @end itemize
3780
3781 @item C
3782 Built-in Intrinsic Matching:
3783
3784 @itemize @w{}
3785 @item 0
3786 Match Any Case (per-character basis)
3787 @item 1
3788 Match Upper Case Only
3789 @item 2
3790 Match Lower Case Only
3791 @item 3
3792 Match InitialCaps Only (see tables for spellings)
3793 @end itemize
3794
3795 @item D
3796 User-defined Symbol Possibilities (warnings only):
3797
3798 @itemize @w{}
3799 @item 0
3800 Allow Any Case (per-character basis)
3801 @item 1
3802 Allow Upper Case Only
3803 @item 2
3804 Allow Lower Case Only
3805 @item 3
3806 Allow InitialCaps Only (see Note 2)
3807 @end itemize
3808 @end itemize
3809
3810 Note 1: @command{g77} eventually will support @code{NAMELIST} in a manner that is
3811 consistent with these source switches---in the sense that input will be
3812 expected to meet the same requirements as source code in terms
3813 of matching symbol names and keywords (for the exponent letters).
3814
3815 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
3816 which uppercases @code{NAMELIST} input and symbol names for matching.
3817 This means not only that @code{NAMELIST} output currently shows symbol
3818 (and keyword) names in uppercase even if lower-case source
3819 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
3820 adequately supported when source case preservation (option A0)
3821 is selected.
3822
3823 If A0 is selected, a warning message will be
3824 output for each @code{NAMELIST} statement to this effect.
3825 The behavior
3826 of the program is undefined at run time if two or more symbol names
3827 appear in a given @code{NAMELIST} such that the names are identical
3828 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
3829 For complete and total elegance, perhaps there should be a warning
3830 when option A2 is selected, since the output of NAMELIST is currently
3831 in uppercase but will someday be lowercase (when a @code{libg77} is written),
3832 but that seems to be overkill for a product in beta test.
3833
3834 Note 2: Rules for InitialCaps names are:
3835
3836 @itemize @minus
3837 @item
3838 Must be a single uppercase letter, @strong{or}
3839 @item
3840 Must start with an uppercase letter and contain at least one
3841 lowercase letter.
3842 @end itemize
3843
3844 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
3845 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
3846 not.
3847 Note that most, but not all, built-in names meet these
3848 requirements---the exceptions are some of the two-letter format
3849 specifiers, such as @code{BN} and @code{BZ}.
3850
3851 Here are the names of the corresponding command-line options:
3852
3853 @smallexample
3854 A0: -fsource-case-preserve
3855 A1: -fsource-case-upper
3856 A2: -fsource-case-lower
3857
3858 B0: -fmatch-case-any
3859 B1: -fmatch-case-upper
3860 B2: -fmatch-case-lower
3861 B3: -fmatch-case-initcap
3862
3863 C0: -fintrin-case-any
3864 C1: -fintrin-case-upper
3865 C2: -fintrin-case-lower
3866 C3: -fintrin-case-initcap
3867
3868 D0: -fsymbol-case-any
3869 D1: -fsymbol-case-upper
3870 D2: -fsymbol-case-lower
3871 D3: -fsymbol-case-initcap
3872 @end smallexample
3873
3874 Useful combinations of the above settings, along with abbreviated
3875 option names that set some of these combinations all at once:
3876
3877 @smallexample
3878  1: A0--  B0---  C0---  D0---    -fcase-preserve
3879  2: A0--  B0---  C0---  D-1--
3880  3: A0--  B0---  C0---  D--2-
3881  4: A0--  B0---  C0---  D---3
3882  5: A0--  B0---  C-1--  D0---
3883  6: A0--  B0---  C-1--  D-1--
3884  7: A0--  B0---  C-1--  D--2-
3885  8: A0--  B0---  C-1--  D---3
3886  9: A0--  B0---  C--2-  D0---
3887 10: A0--  B0---  C--2-  D-1--
3888 11: A0--  B0---  C--2-  D--2-
3889 12: A0--  B0---  C--2-  D---3
3890 13: A0--  B0---  C---3  D0---
3891 14: A0--  B0---  C---3  D-1--
3892 15: A0--  B0---  C---3  D--2-
3893 16: A0--  B0---  C---3  D---3
3894 17: A0--  B-1--  C0---  D0---
3895 18: A0--  B-1--  C0---  D-1--
3896 19: A0--  B-1--  C0---  D--2-
3897 20: A0--  B-1--  C0---  D---3
3898 21: A0--  B-1--  C-1--  D0---
3899 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
3900 23: A0--  B-1--  C-1--  D--2-
3901 24: A0--  B-1--  C-1--  D---3
3902 25: A0--  B-1--  C--2-  D0---
3903 26: A0--  B-1--  C--2-  D-1--
3904 27: A0--  B-1--  C--2-  D--2-
3905 28: A0--  B-1--  C--2-  D---3
3906 29: A0--  B-1--  C---3  D0---
3907 30: A0--  B-1--  C---3  D-1--
3908 31: A0--  B-1--  C---3  D--2-
3909 32: A0--  B-1--  C---3  D---3
3910 33: A0--  B--2-  C0---  D0---
3911 34: A0--  B--2-  C0---  D-1--
3912 35: A0--  B--2-  C0---  D--2-
3913 36: A0--  B--2-  C0---  D---3
3914 37: A0--  B--2-  C-1--  D0---
3915 38: A0--  B--2-  C-1--  D-1--
3916 39: A0--  B--2-  C-1--  D--2-
3917 40: A0--  B--2-  C-1--  D---3
3918 41: A0--  B--2-  C--2-  D0---
3919 42: A0--  B--2-  C--2-  D-1--
3920 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
3921 44: A0--  B--2-  C--2-  D---3
3922 45: A0--  B--2-  C---3  D0---
3923 46: A0--  B--2-  C---3  D-1--
3924 47: A0--  B--2-  C---3  D--2-
3925 48: A0--  B--2-  C---3  D---3
3926 49: A0--  B---3  C0---  D0---
3927 50: A0--  B---3  C0---  D-1--
3928 51: A0--  B---3  C0---  D--2-
3929 52: A0--  B---3  C0---  D---3
3930 53: A0--  B---3  C-1--  D0---
3931 54: A0--  B---3  C-1--  D-1--
3932 55: A0--  B---3  C-1--  D--2-
3933 56: A0--  B---3  C-1--  D---3
3934 57: A0--  B---3  C--2-  D0---
3935 58: A0--  B---3  C--2-  D-1--
3936 59: A0--  B---3  C--2-  D--2-
3937 60: A0--  B---3  C--2-  D---3
3938 61: A0--  B---3  C---3  D0---
3939 62: A0--  B---3  C---3  D-1--
3940 63: A0--  B---3  C---3  D--2-
3941 64: A0--  B---3  C---3  D---3    -fcase-initcap
3942 65: A-1-  B01--  C01--  D01--    -fcase-upper
3943 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
3944 @end smallexample
3945
3946 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
3947 (except comments, character constants, and Hollerith strings) must
3948 be entered in uppercase.
3949 Use @option{-fcase-strict-upper} to specify this
3950 combination.
3951
3952 Number 43 is like Number 22 except all input must be lowercase.  Use
3953 @option{-fcase-strict-lower} to specify this combination.
3954
3955 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
3956 non-UNIX machines whereby all the source is translated to uppercase.
3957 Use @option{-fcase-upper} to specify this combination.
3958
3959 Number 66 is the ``canonical'' UNIX model whereby all the source is
3960 translated to lowercase.
3961 Use @option{-fcase-lower} to specify this combination.
3962
3963 There are a few nearly useless combinations:
3964
3965 @smallexample
3966 67: A-1-  B01--  C01--  D--2-
3967 68: A-1-  B01--  C01--  D---3
3968 69: A-1-  B01--  C--23  D01--
3969 70: A-1-  B01--  C--23  D--2-
3970 71: A-1-  B01--  C--23  D---3
3971 72: A--2  B01--  C0-2-  D-1--
3972 73: A--2  B01--  C0-2-  D---3
3973 74: A--2  B01--  C-1-3  D0-2-
3974 75: A--2  B01--  C-1-3  D-1--
3975 76: A--2  B01--  C-1-3  D---3
3976 @end smallexample
3977
3978 The above allow some programs to be compiled but with restrictions that
3979 make most useful programs impossible: Numbers 67 and 72 warn about
3980 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
3981 Numbers
3982 68 and 73 warn about any user-defined symbol names longer than one
3983 character that don't have at least one non-alphabetic character after
3984 the first;
3985 Numbers 69 and 74 disallow any references to intrinsics;
3986 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
3987 67+69, 68+69, 72+74, and 73+74, respectively.
3988
3989 All redundant combinations are shown in the above tables anyplace
3990 where more than one setting is shown for a low-level switch.
3991 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
3992 The ``proper'' setting in such a case is the one that copies the setting
3993 of switch A---any other setting might slightly reduce the speed of
3994 the compiler, though possibly to an unmeasurable extent.
3995
3996 All remaining combinations are useless in that they prevent successful
3997 compilation of non-null source files (source files with something other
3998 than comments).
3999
4000 @node VXT Fortran
4001 @section VXT Fortran
4002
4003 @cindex VXT extensions
4004 @cindex extensions, VXT
4005 @command{g77} supports certain constructs that
4006 have different meanings in VXT Fortran than they
4007 do in the GNU Fortran language.
4008
4009 Generally, this manual uses the invented term VXT Fortran to refer
4010 VAX FORTRAN (circa v4).
4011 That compiler offered many popular features, though not necessarily
4012 those that are specific to the VAX processor architecture,
4013 the VMS operating system,
4014 or Digital Equipment Corporation's Fortran product line.
4015 (VAX and VMS probably are trademarks of Digital Equipment
4016 Corporation.)
4017
4018 An extension offered by a Digital Fortran product that also is
4019 offered by several other Fortran products for different kinds of
4020 systems is probably going to be considered for inclusion in @command{g77}
4021 someday, and is considered a VXT Fortran feature.
4022
4023 The @option{-fvxt} option generally specifies that, where
4024 the meaning of a construct is ambiguous (means one thing
4025 in GNU Fortran and another in VXT Fortran), the VXT Fortran
4026 meaning is to be assumed.
4027
4028 @menu
4029 * Double Quote Meaning::  @samp{"2000} as octal constant.
4030 * Exclamation Point::     @samp{!} in column 6.
4031 @end menu
4032
4033 @node Double Quote Meaning
4034 @subsection Meaning of Double Quote
4035 @cindex double quotes
4036 @cindex character constants
4037 @cindex constants, character
4038 @cindex octal constants
4039 @cindex constants, octal
4040
4041 @command{g77} treats double-quote (@samp{"})
4042 as beginning an octal constant of @code{INTEGER(KIND=1)} type
4043 when the @option{-fvxt} option is specified.
4044 The form of this octal constant is
4045
4046 @example
4047 "@var{octal-digits}
4048 @end example
4049
4050 @noindent
4051 where @var{octal-digits} is a nonempty string of characters in
4052 the set @samp{01234567}.
4053
4054 For example, the @option{-fvxt} option permits this:
4055
4056 @example
4057 PRINT *, "20
4058 END
4059 @end example
4060
4061 @noindent
4062 The above program would print the value @samp{16}.
4063
4064 @xref{Integer Type}, for information on the preferred construct
4065 for integer constants specified using GNU Fortran's octal notation.
4066
4067 (In the GNU Fortran language, the double-quote character (@samp{"})
4068 delimits a character constant just as does apostrophe (@samp{'}).
4069 There is no way to allow
4070 both constructs in the general case, since statements like
4071 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
4072
4073 @node Exclamation Point
4074 @subsection Meaning of Exclamation Point in Column 6
4075 @cindex !
4076 @cindex exclamation point
4077 @cindex continuation character
4078 @cindex characters, continuation
4079 @cindex comment character
4080 @cindex characters, comment
4081
4082 @command{g77} treats an exclamation point (@samp{!}) in column 6 of
4083 a fixed-form source file
4084 as a continuation character rather than
4085 as the beginning of a comment
4086 (as it does in any other column)
4087 when the @option{-fvxt} option is specified.
4088
4089 The following program, when run, prints a message indicating
4090 whether it is interpreted according to GNU Fortran (and Fortran 90)
4091 rules or VXT Fortran rules:
4092
4093 @smallexample
4094 C234567  (This line begins in column 1.)
4095       I = 0
4096      !1
4097       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
4098       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
4099       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
4100       END
4101 @end smallexample
4102
4103 (In the GNU Fortran and Fortran 90 languages, exclamation point is
4104 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
4105 marks a line as a continuation line when it appears in column 6.)
4106
4107 @node Fortran 90
4108 @section Fortran 90
4109 @cindex compatibility, Fortran 90
4110 @cindex Fortran 90, compatibility
4111
4112 The GNU Fortran language includes a number of features that are
4113 part of Fortran 90, even when the @option{-ff90} option is not specified.
4114 The features enabled by @option{-ff90} are intended to be those that,
4115 when @option{-ff90} is not specified, would have another
4116 meaning to @command{g77}---usually meaning something invalid in the
4117 GNU Fortran language.
4118
4119 So, the purpose of @option{-ff90} is not to specify whether @command{g77} is
4120 to gratuitously reject Fortran 90 constructs.
4121 The @option{-pedantic} option specified with @option{-fno-f90} is intended
4122 to do that, although its implementation is certainly incomplete at
4123 this point.
4124
4125 When @option{-ff90} is specified:
4126
4127 @itemize @bullet
4128 @item
4129 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
4130 where @var{expr} is @code{COMPLEX} type,
4131 is the same type as the real part of @var{expr}.
4132
4133 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
4134 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
4135 not of type @code{REAL(KIND=1)}, since @option{-ff90} is specified.
4136 @end itemize
4137
4138 @node Pedantic Compilation
4139 @section Pedantic Compilation
4140 @cindex pedantic compilation
4141 @cindex compilation, pedantic
4142
4143 The @option{-fpedantic} command-line option specifies that @command{g77}
4144 is to warn about code that is not standard-conforming.
4145 This is useful for finding
4146 some extensions @command{g77} accepts that other compilers might not accept.
4147 (Note that the @option{-pedantic} and @option{-pedantic-errors} options
4148 always imply @option{-fpedantic}.)
4149
4150 With @option{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
4151 for conforming code.
4152 With @option{-ff90} in force, Fortran 90 is used.
4153
4154 The constructs for which @command{g77} issues diagnostics when @option{-fpedantic}
4155 and @option{-fno-f90} are in force are:
4156
4157 @itemize @bullet
4158 @item
4159 Automatic arrays, as in
4160
4161 @example
4162 SUBROUTINE X(N)
4163 REAL A(N)
4164 @dots{}
4165 @end example
4166
4167 @noindent
4168 where @samp{A} is not listed in any @code{ENTRY} statement,
4169 and thus is not a dummy argument.
4170
4171 @item
4172 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
4173
4174 These commas are disallowed by FORTRAN 77, but, while strictly
4175 superfluous, are syntactically elegant,
4176 especially given that commas are required in statements such
4177 as @samp{READ 99, I} and @samp{PRINT *, J}.
4178 Many compilers permit the superfluous commas for this reason.
4179
4180 @item
4181 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
4182
4183 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
4184 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
4185
4186 An example of an implicit use is the expression @samp{C*D},
4187 where @samp{C} is @code{COMPLEX(KIND=1)}
4188 and @samp{D} is @code{DOUBLE PRECISION}.
4189 This expression is prohibited by ANSI FORTRAN 77
4190 because the rules of promotion would suggest that it
4191 produce a @code{DOUBLE COMPLEX} result---a type not
4192 provided for by that standard.
4193
4194 @item
4195 Automatic conversion of numeric
4196 expressions to @code{INTEGER(KIND=1)} in contexts such as:
4197
4198 @itemize @minus
4199 @item
4200 Array-reference indexes.
4201 @item
4202 Alternate-return values.
4203 @item
4204 Computed @code{GOTO}.
4205 @item
4206 @code{FORMAT} run-time expressions (not yet supported).
4207 @item
4208 Dimension lists in specification statements.
4209 @item
4210 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
4211 @item
4212 Sizes of @code{CHARACTER} entities in specification statements.
4213 @item
4214 Kind types in specification entities (a Fortran 90 feature).
4215 @item
4216 Initial, terminal, and incrementation parameters for implied-@code{DO}
4217 constructs in @code{DATA} statements.
4218 @end itemize
4219
4220 @item
4221 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
4222 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
4223 expressions are disallowed anyway).
4224
4225 @item
4226 Zero-size array dimensions, as in:
4227
4228 @example
4229 INTEGER I(10,20,4:2)
4230 @end example
4231
4232 @item
4233 Zero-length @code{CHARACTER} entities, as in:
4234
4235 @example
4236 PRINT *, ''
4237 @end example
4238
4239 @item
4240 Substring operators applied to character constants and named
4241 constants, as in:
4242
4243 @example
4244 PRINT *, 'hello'(3:5)
4245 @end example
4246
4247 @item
4248 Null arguments passed to statement function, as in:
4249
4250 @example
4251 PRINT *, FOO(,3)
4252 @end example
4253
4254 @item
4255 Disagreement among program units regarding whether a given @code{COMMON}
4256 area is @code{SAVE}d (for targets where program units in a single source
4257 file are ``glued'' together as they typically are for UNIX development
4258 environments).
4259
4260 @item
4261 Disagreement among program units regarding the size of a
4262 named @code{COMMON} block.
4263
4264 @item
4265 Specification statements following first @code{DATA} statement.
4266
4267 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
4268 but not @samp{INTEGER I}.
4269 The @option{-fpedantic} option disallows both of these.)
4270
4271 @item
4272 Semicolon as statement separator, as in:
4273
4274 @example
4275 CALL FOO; CALL BAR
4276 @end example
4277 @c
4278 @c @item
4279 @c Comma before list of I/O items in @code{WRITE}
4280 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
4281 @c statements, as with @code{READ} (as explained above).
4282
4283 @item
4284 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
4285
4286 @item
4287 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
4288 versa.
4289
4290 @item
4291 Expressions having two arithmetic operators in a row, such
4292 as @samp{X*-Y}.
4293 @end itemize
4294
4295 If @option{-fpedantic} is specified along with @option{-ff90}, the
4296 following constructs result in diagnostics:
4297
4298 @itemize @bullet
4299 @item
4300 Use of semicolon as a statement separator on a line
4301 that has an @code{INCLUDE} directive.
4302 @end itemize
4303
4304 @node Distensions
4305 @section Distensions
4306 @cindex distensions
4307 @cindex ugly features
4308 @cindex features, ugly
4309
4310 The @option{-fugly-*} command-line options determine whether certain
4311 features supported by VAX FORTRAN and other such compilers, but considered
4312 too ugly to be in code that can be changed to use safer and/or more
4313 portable constructs, are accepted.
4314 These are humorously referred to as ``distensions'',
4315 extensions that just plain look ugly in the harsh light of day.
4316
4317 @menu
4318 * Ugly Implicit Argument Conversion::  Disabled via @option{-fno-ugly-args}.
4319 * Ugly Assumed-Size Arrays::           Enabled via @option{-fugly-assumed}.
4320 * Ugly Null Arguments::                Enabled via @option{-fugly-comma}.
4321 * Ugly Complex Part Extraction::       Enabled via @option{-fugly-complex}.
4322 * Ugly Conversion of Initializers::    Disabled via @option{-fno-ugly-init}.
4323 * Ugly Integer Conversions::           Enabled via @option{-fugly-logint}.
4324 * Ugly Assigned Labels::               Enabled via @option{-fugly-assign}.
4325 @end menu
4326
4327 @node Ugly Implicit Argument Conversion
4328 @subsection Implicit Argument Conversion
4329 @cindex Hollerith constants
4330 @cindex constants, Hollerith
4331
4332 The @option{-fno-ugly-args} option disables
4333 passing typeless and Hollerith constants as actual arguments
4334 in procedure invocations.
4335 For example:
4336
4337 @example
4338 CALL FOO(4HABCD)
4339 CALL BAR('123'O)
4340 @end example
4341
4342 @noindent
4343 These constructs can be too easily used to create non-portable
4344 code, but are not considered as ``ugly'' as others.
4345 Further, they are widely used in existing Fortran source code
4346 in ways that often are quite portable.
4347 Therefore, they are enabled by default.
4348
4349 @node Ugly Assumed-Size Arrays
4350 @subsection Ugly Assumed-Size Arrays
4351 @cindex arrays, assumed-size
4352 @cindex assumed-size arrays
4353 @cindex DIMENSION X(1)
4354
4355 The @option{-fugly-assumed} option enables
4356 the treatment of any array with a final dimension specified as @samp{1}
4357 as an assumed-size array, as if @samp{*} had been specified
4358 instead.
4359
4360 For example, @samp{DIMENSION X(1)} is treated as if it
4361 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
4362 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
4363 or @code{ENTRY} statement in the same program unit.
4364
4365 Use an explicit lower bound to avoid this interpretation.
4366 For example, @samp{DIMENSION X(1:1)} is never treated as if
4367 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
4368 Nor is @samp{DIMENSION X(2-1)} affected by this option,
4369 since that kind of expression is unlikely to have been
4370 intended to designate an assumed-size array.
4371
4372 This option is used to prevent warnings being issued about apparent
4373 out-of-bounds reference such as @samp{X(2) = 99}.
4374
4375 It also prevents the array from being used in contexts that
4376 disallow assumed-size arrays, such as @samp{PRINT *,X}.
4377 In such cases, a diagnostic is generated and the source file is
4378 not compiled.
4379
4380 The construct affected by this option is used only in old code
4381 that pre-exists the widespread acceptance of adjustable and assumed-size
4382 arrays in the Fortran community.
4383
4384 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
4385 treated if @samp{X} is listed as a dummy argument only
4386 @emph{after} the @code{DIMENSION} statement (presumably in
4387 an @code{ENTRY} statement).
4388 For example, @option{-fugly-assumed} has no effect on the
4389 following program unit:
4390
4391 @example
4392 SUBROUTINE X
4393 REAL A(1)
4394 RETURN
4395 ENTRY Y(A)
4396 PRINT *, A
4397 END
4398 @end example
4399
4400 @node Ugly Complex Part Extraction
4401 @subsection Ugly Complex Part Extraction
4402 @cindex complex values
4403 @cindex real part
4404 @cindex imaginary part
4405
4406 The @option{-fugly-complex} option enables
4407 use of the @code{REAL()} and @code{AIMAG()}
4408 intrinsics with arguments that are
4409 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
4410
4411 With @option{-ff90} in effect, these intrinsics return
4412 the unconverted real and imaginary parts (respectively)
4413 of their argument.
4414
4415 With @option{-fno-f90} in effect, these intrinsics convert
4416 the real and imaginary parts to @code{REAL(KIND=1)}, and return
4417 the result of that conversion.
4418
4419 Due to this ambiguity, the GNU Fortran language defines
4420 these constructs as invalid, except in the specific
4421 case where they are entirely and solely passed as an
4422 argument to an invocation of the @code{REAL()} intrinsic.
4423 For example,
4424
4425 @example
4426 REAL(REAL(Z))
4427 @end example
4428
4429 @noindent
4430 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
4431 and @option{-fno-ugly-complex} is in effect, because the
4432 meaning is clear.
4433
4434 @command{g77} enforces this restriction, unless @option{-fugly-complex}
4435 is specified, in which case the appropriate interpretation is
4436 chosen and no diagnostic is issued.
4437
4438 @xref{CMPAMBIG}, for information on how to cope with existing
4439 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
4440 with @code{COMPLEX(KIND=2)} arguments.
4441
4442 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
4443 intrinsic, used to extract the real part of a complex expression
4444 without conversion.
4445 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
4446 intrinsic, used to extract the imaginary part of a complex expression
4447 without conversion.
4448
4449 @node Ugly Null Arguments
4450 @subsection Ugly Null Arguments
4451 @cindex trailing comma
4452 @cindex comma, trailing
4453 @cindex characters, comma
4454 @cindex null arguments
4455 @cindex arguments, null
4456
4457 The @option{-fugly-comma} option enables use of a single trailing comma
4458 to mean ``pass an extra trailing null argument''
4459 in a list of actual arguments to an external procedure,
4460 and use of an empty list of arguments to such a procedure
4461 to mean ``pass a single null argument''.
4462
4463 @cindex omitting arguments
4464 @cindex arguments, omitting
4465 (Null arguments often are used in some procedure-calling
4466 schemes to indicate omitted arguments.)
4467
4468 For example, @samp{CALL FOO(,)} means ``pass
4469 two null arguments'', rather than ``pass one null argument''.
4470 Also, @samp{CALL BAR()} means ``pass one null argument''.
4471
4472 This construct is considered ``ugly'' because it does not
4473 provide an elegant way to pass a single null argument
4474 that is syntactically distinct from passing no arguments.
4475 That is, this construct changes the meaning of code that
4476 makes no use of the construct.
4477
4478 So, with @option{-fugly-comma} in force, @samp{CALL FOO()}
4479 and @samp{I = JFUNC()} pass a single null argument, instead
4480 of passing no arguments as required by the Fortran 77 and
4481 90 standards.
4482
4483 @emph{Note:} Many systems gracefully allow the case
4484 where a procedure call passes one extra argument that the
4485 called procedure does not expect.
4486
4487 So, in practice, there might be no difference in
4488 the behavior of a program that does @samp{CALL FOO()}
4489 or @samp{I = JFUNC()} and is compiled with @option{-fugly-comma}
4490 in force as compared to its behavior when compiled
4491 with the default, @option{-fno-ugly-comma}, in force,
4492 assuming @samp{FOO} and @samp{JFUNC} do not expect any
4493 arguments to be passed.
4494
4495 @node Ugly Conversion of Initializers
4496 @subsection Ugly Conversion of Initializers
4497
4498 The constructs disabled by @option{-fno-ugly-init} are:
4499
4500 @itemize @bullet
4501 @cindex Hollerith constants
4502 @cindex constants, Hollerith
4503 @item
4504 Use of Hollerith and typeless constants in contexts where they set
4505 initial (compile-time) values for variables, arrays, and named
4506 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
4507 type-declaration statements specifying initial values.
4508
4509 Here are some sample initializations that are disabled by the
4510 @option{-fno-ugly-init} option:
4511
4512 @example
4513 PARAMETER (VAL='9A304FFE'X)
4514 REAL*8 STRING/8HOUTPUT00/
4515 DATA VAR/4HABCD/
4516 @end example
4517
4518 @cindex character constants
4519 @cindex constants, character
4520 @item
4521 In the same contexts as above, use of character constants to initialize
4522 numeric items and vice versa (one constant per item).
4523
4524 Here are more sample initializations that are disabled by the
4525 @option{-fno-ugly-init} option:
4526
4527 @example
4528 INTEGER IA
4529 CHARACTER BELL
4530 PARAMETER (IA = 'A')
4531 PARAMETER (BELL = 7)
4532 @end example
4533
4534 @item
4535 Use of Hollerith and typeless constants on the right-hand side
4536 of assignment statements to numeric types, and in other
4537 contexts (such as passing arguments in invocations of
4538 intrinsic procedures and statement functions) that
4539 are treated as assignments to known types (the dummy
4540 arguments, in these cases).
4541
4542 Here are sample statements that are disabled by the
4543 @option{-fno-ugly-init} option:
4544
4545 @example
4546 IVAR = 4HABCD
4547 PRINT *, IMAX0(2HAB, 2HBA)
4548 @end example
4549 @end itemize
4550
4551 The above constructs, when used,
4552 can tend to result in non-portable code.
4553 But, they are widely used in existing Fortran code in ways
4554 that often are quite portable.
4555 Therefore, they are enabled by default.
4556
4557 @node Ugly Integer Conversions
4558 @subsection Ugly Integer Conversions
4559
4560 The constructs enabled via @option{-fugly-logint} are:
4561
4562 @itemize @bullet
4563 @item
4564 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
4565 dictated by
4566 context (typically implies nonportable dependencies on how a
4567 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
4568
4569 @item
4570 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
4571 statements.
4572 @end itemize
4573
4574 The above constructs are disabled by default because use
4575 of them tends to lead to non-portable code.
4576 Even existing Fortran code that uses that often turns out
4577 to be non-portable, if not outright buggy.
4578
4579 Some of this is due to differences among implementations as
4580 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
4581 @code{INTEGER} values---Fortran code that assumes a particular
4582 coding is likely to use one of the above constructs, and is
4583 also likely to not work correctly on implementations using
4584 different encodings.
4585
4586 @xref{Equivalence Versus Equality}, for more information.
4587
4588 @node Ugly Assigned Labels
4589 @subsection Ugly Assigned Labels
4590 @cindex ASSIGN statement
4591 @cindex statements, ASSIGN
4592 @cindex assigned labels
4593 @cindex pointers
4594
4595 The @option{-fugly-assign} option forces @command{g77} to use the
4596 same storage for assigned labels as it would for a normal
4597 assignment to the same variable.
4598
4599 For example, consider the following code fragment:
4600
4601 @example
4602 I = 3
4603 ASSIGN 10 TO I
4604 @end example
4605
4606 @noindent
4607 Normally, for portability and improved diagnostics, @command{g77}
4608 reserves distinct storage for a ``sibling'' of @samp{I}, used
4609 only for @code{ASSIGN} statements to that variable (along with
4610 the corresponding assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O
4611 statements that reference the variable).
4612
4613 However, some code (that violates the ANSI FORTRAN 77 standard)
4614 attempts to copy assigned labels among variables involved with
4615 @code{ASSIGN} statements, as in:
4616
4617 @example
4618 ASSIGN 10 TO I
4619 ISTATE(5) = I
4620 @dots{}
4621 J = ISTATE(ICUR)
4622 GOTO J
4623 @end example
4624
4625 @noindent
4626 Such code doesn't work under @command{g77} unless @option{-fugly-assign}
4627 is specified on the command-line, ensuring that the value of @code{I}
4628 referenced in the second line is whatever value @command{g77} uses
4629 to designate statement label @samp{10}, so the value may be
4630 copied into the @samp{ISTATE} array, later retrieved into a
4631 variable of the appropriate type (@samp{J}), and used as the target of
4632 an assigned-@code{GOTO} statement.
4633
4634 @emph{Note:} To avoid subtle program bugs,
4635 when @option{-fugly-assign} is specified,
4636 @command{g77} requires the type of variables
4637 specified in assigned-label contexts
4638 @emph{must} be the same type returned by @code{%LOC()}.
4639 On many systems, this type is effectively the same
4640 as @code{INTEGER(KIND=1)}, while, on others, it is
4641 effectively the same as @code{INTEGER(KIND=2)}.
4642
4643 Do @emph{not} depend on @command{g77} actually writing valid pointers
4644 to these variables, however.
4645 While @command{g77} currently chooses that implementation, it might
4646 be changed in the future.
4647
4648 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
4649 for implementation details on assigned-statement labels.
4650
4651 @node Compiler
4652 @chapter The GNU Fortran Compiler
4653
4654 The GNU Fortran compiler, @command{g77}, supports programs written
4655 in the GNU Fortran language and in some other dialects of Fortran.
4656
4657 Some aspects of how @command{g77} works are universal regardless
4658 of dialect, and yet are not properly part of the GNU Fortran
4659 language itself.
4660 These are described below.
4661
4662 @emph{Note: This portion of the documentation definitely needs a lot
4663 of work!}
4664
4665 @menu
4666 * Compiler Limits::
4667 * Run-time Environment Limits::
4668 * Compiler Types::
4669 * Compiler Constants::
4670 * Compiler Intrinsics::
4671 @end menu
4672
4673 @node Compiler Limits
4674 @section Compiler Limits
4675 @cindex limits, compiler
4676 @cindex compiler limits
4677
4678 @command{g77}, as with GNU tools in general, imposes few arbitrary restrictions
4679 on lengths of identifiers, number of continuation lines, number of external
4680 symbols in a program, and so on.
4681
4682 @cindex options, -Nl
4683 @cindex -Nl option
4684 @cindex options, -Nx
4685 @cindex -Nx option
4686 @cindex limits, continuation lines
4687 @cindex limits, lengths of names
4688 For example, some other Fortran compiler have an option
4689 (such as @option{-Nl@var{x}}) to increase the limit on the
4690 number of continuation lines.
4691 Also, some Fortran compilation systems have an option
4692 (such as @option{-Nx@var{x}}) to increase the limit on the
4693 number of external symbols.
4694
4695 @command{g77}, @command{gcc}, and GNU @command{ld} (the GNU linker) have
4696 no equivalent options, since they do not impose arbitrary
4697 limits in these areas.
4698
4699 @cindex rank, maximum
4700 @cindex maximum rank
4701 @cindex number of dimensions, maximum
4702 @cindex maximum number of dimensions
4703 @cindex limits, rank
4704 @cindex limits, array dimensions
4705 @command{g77} does currently limit the number of dimensions in an array
4706 to the same degree as do the Fortran standards---seven (7).
4707 This restriction might be lifted in a future version.
4708
4709 @node Run-time Environment Limits
4710 @section Run-time Environment Limits
4711 @cindex limits, run-time library
4712 @cindex wraparound
4713
4714 As a portable Fortran implementation,
4715 @command{g77} offers its users direct access to,
4716 and otherwise depends upon,
4717 the underlying facilities of the system
4718 used to build @command{g77},
4719 the system on which @command{g77} itself is used to compile programs,
4720 and the system on which the @command{g77}-compiled program is actually run.
4721 (For most users, the three systems are of the same
4722 type---combination of operating environment and hardware---often
4723 the same physical system.)
4724
4725 The run-time environment for a particular system
4726 inevitably imposes some limits on a program's use
4727 of various system facilities.
4728 These limits vary from system to system.
4729
4730 Even when such limits might be well beyond the
4731 possibility of being encountered on a particular system,
4732 the @command{g77} run-time environment
4733 has certain built-in limits,
4734 usually, but not always, stemming from intrinsics
4735 with inherently limited interfaces.
4736
4737 Currently, the @command{g77} run-time environment
4738 does not generally offer a less-limiting environment
4739 by augmenting the underlying system's own environment.
4740
4741 Therefore, code written in the GNU Fortran language,
4742 while syntactically and semantically portable,
4743 might nevertheless make non-portable assumptions
4744 about the run-time environment---assumptions that
4745 prove to be false for some particular environments.
4746
4747 The GNU Fortran language,
4748 the @command{g77} compiler and run-time environment,
4749 and the @command{g77} documentation
4750 do not yet offer comprehensive portable work-arounds for such limits,
4751 though programmers should be able to
4752 find their own in specific instances.
4753
4754 Not all of the limitations are described in this document.
4755 Some of the known limitations include:
4756
4757 @menu
4758 * Timer Wraparounds::
4759 * Year 2000 (Y2K) Problems::
4760 * Array Size::
4761 * Character-variable Length::
4762 * Year 10000 (Y10K) Problems::
4763 @end menu
4764
4765 @node Timer Wraparounds
4766 @subsection Timer Wraparounds
4767
4768 Intrinsics that return values computed from system timers,
4769 whether elapsed (wall-clock) timers,
4770 process CPU timers,
4771 or other kinds of timers,
4772 are prone to experiencing wrap-around errors
4773 (or returning wrapped-around values from successive calls)
4774 due to insufficient ranges
4775 offered by the underlying system's timers.
4776
4777 @cindex negative time
4778 @cindex short time
4779 @cindex long time
4780 Some of the symptoms of such behaviors include
4781 apparently negative time being computed for a duration,
4782 an extremely short amount of time being computed for a long duration,
4783 and an extremely long amount of time being computed for a short duration.
4784
4785 See the following for intrinsics
4786 known to have potential problems in these areas
4787 on at least some systems:
4788 @ref{CPU_Time Intrinsic},
4789 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
4790 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
4791 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
4792 @ref{Secnds Intrinsic},
4793 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
4794 @ref{System_Clock Intrinsic},
4795 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
4796 @ref{Time8 Intrinsic}.
4797
4798 @node Year 2000 (Y2K) Problems
4799 @subsection Year 2000 (Y2K) Problems
4800 @cindex Y2K compliance
4801 @cindex Year 2000 compliance
4802
4803 While the @command{g77} compiler itself is believed to
4804 be Year-2000 (Y2K) compliant,
4805 some intrinsics are not,
4806 and, potentially, some underlying systems are not,
4807 perhaps rendering some Y2K-compliant intrinsics
4808 non-compliant when used on those particular systems.
4809
4810 Fortran code that uses non-Y2K-compliant intrinsics
4811 (listed below)
4812 is, itself, almost certainly not compliant,
4813 and should be modified to use Y2K-compliant intrinsics instead.
4814
4815 Fortran code that uses no non-Y2K-compliant intrinsics,
4816 but which currently is running on a non-Y2K-compliant system,
4817 can be made more Y2K compliant by compiling and
4818 linking it for use on a new Y2K-compliant system,
4819 such as a new version of an old, non-Y2K-compliant, system.
4820
4821 Currently, information on Y2K and related issues
4822 is being maintained at
4823 @uref{http://www.gnu.org/software/year2000-list.html}.
4824
4825 See the following for intrinsics
4826 known to have potential problems in these areas
4827 on at least some systems:
4828 @ref{Date Intrinsic},
4829 @ref{IDate Intrinsic (VXT)}.
4830
4831 @cindex y2kbuggy
4832 @cindex date_y2kbuggy_0
4833 @cindex vxtidate_y2kbuggy_0
4834 @cindex G77_date_y2kbuggy_0
4835 @cindex G77_vxtidate_y2kbuggy_0
4836 The @code{libg2c} library
4837 shipped with any @command{g77} that warns
4838 about invocation of a non-Y2K-compliant intrinsic
4839 has renamed the @code{EXTERNAL} procedure names
4840 of those intrinsics.
4841 This is done so that
4842 the @code{libg2c} implementations of these intrinsics
4843 cannot be directly linked to
4844 as @code{EXTERNAL} names
4845 (which normally would avoid the non-Y2K-intrinsic warning).
4846
4847 The renamed forms of the @code{EXTERNAL} names
4848 of these renamed procedures
4849 may be linked to
4850 by appending the string @samp{_y2kbug}
4851 to the name of the procedure
4852 in the source code.
4853 For example:
4854
4855 @smallexample
4856 CHARACTER*20 STR
4857 INTEGER YY, MM, DD
4858 EXTERNAL DATE_Y2KBUG, VXTIDATE_Y2KBUG
4859 CALL DATE_Y2KBUG (STR)
4860 CALL VXTIDATE_Y2KBUG (MM, DD, YY)
4861 @end smallexample
4862
4863 (Note that the @code{EXTERNAL} statement
4864 is not actually required,
4865 since the modified names are not recognized as intrinsics
4866 by the current version of @command{g77}.
4867 But it is shown in this specific case,
4868 for purposes of illustration.)
4869
4870 The renaming of @code{EXTERNAL} procedure names of these intrinsics
4871 causes unresolved references at link time.
4872 For example, @samp{EXTERNAL DATE; CALL DATE(STR)}
4873 is normally compiled by @command{g77}
4874 as, in C, @samp{date_(&str, 20);}.
4875 This, in turn, links to the @code{date_} procedure
4876 in the @code{libE77} portion of @code{libg2c},
4877 which purposely calls a nonexistent procedure
4878 named @code{G77_date_y2kbuggy_0}.
4879 The resulting link-time error is designed, via this name,
4880 to encourage the programmer to look up the
4881 index entries to this portion of the @command{g77} documentation.
4882
4883 Generally, we recommend that the @code{EXTERNAL} method
4884 of invoking procedures in @code{libg2c}
4885 @emph{not} be used.
4886 When used, some of the correctness checking
4887 normally performed by @command{g77}
4888 is skipped.
4889
4890 In particular, it is probably better to use the
4891 @code{INTRINSIC} method of invoking
4892 non-Y2K-compliant procedures,
4893 so anyone compiling the code
4894 can quickly notice the potential Y2K problems
4895 (via the warnings printing by @command{g77})
4896 without having to even look at the code itself.
4897
4898 If there are problems linking @code{libg2c}
4899 to code compiled by @command{g77}
4900 that involve the string @samp{y2kbug},
4901 and these are not explained above,
4902 that probably indicates
4903 that a version of @code{libg2c}
4904 older than @command{g77}
4905 is being linked to,
4906 or that the new library is being linked
4907 to code compiled by an older version of @command{g77}.
4908
4909 That's because, as of the version that warns about
4910 non-Y2K-compliant intrinsic invocation,
4911 @command{g77} references the @code{libg2c} implementations
4912 of those intrinsics
4913 using new names, containing the string @samp{y2kbug}.
4914
4915 So, linking newly-compiled code
4916 (invoking one of the intrinsics in question)
4917 to an old library
4918 might yield an unresolved reference
4919 to @code{G77_date_y2kbug_0}.
4920 (The old library calls it @code{G77_date_0}.)
4921
4922 Similarly, linking previously-compiled code
4923 to a new library
4924 might yield an unresolved reference
4925 to @code{G77_vxtidate_0}.
4926 (The new library calls it @code{G77_vxtidate_y2kbug_0}.)
4927
4928 The proper fix for the above problems
4929 is to obtain the latest release of @command{g77}
4930 and related products
4931 (including @code{libg2c})
4932 and install them on all systems,
4933 then recompile, relink, and install
4934 (as appropriate)
4935 all existing Fortran programs.
4936
4937 (Normally, this sort of renaming is steadfastly avoided.
4938 In this case, however, it seems more important to highlight
4939 potential Y2K problems
4940 than to ease the transition
4941 of potentially non-Y2K-compliant code
4942 to new versions of @command{g77} and @code{libg2c}.)
4943
4944 @node Array Size
4945 @subsection Array Size
4946 @cindex limits, array size
4947 @cindex array size
4948
4949 Currently, @command{g77} uses the default @code{INTEGER} type
4950 for array indexes,
4951 which limits the sizes of single-dimension arrays
4952 on systems offering a larger address space
4953 than can be addressed by that type.
4954 (That @command{g77} puts all arrays in memory
4955 could be considered another limitation---it
4956 could use large temporary files---but that decision
4957 is left to the programmer as an implementation choice
4958 by most Fortran implementations.)
4959
4960 @c ??? Investigate this, to offer a more clear statement
4961 @c than the following paragraphs do.  -- burley 1999-02-17
4962 It is not yet clear whether this limitation
4963 never, sometimes, or always applies to the
4964 sizes of multiple-dimension arrays as a whole.
4965
4966 For example, on a system with 64-bit addresses
4967 and 32-bit default @code{INTEGER},
4968 an array with a size greater than can be addressed
4969 by a 32-bit offset
4970 can be declared using multiple dimensions.
4971 Such an array is therefore larger
4972 than a single-dimension array can be,
4973 on the same system.
4974
4975 @cindex limits, multi-dimension arrays
4976 @cindex multi-dimension arrays
4977 @cindex arrays, dimensioning
4978 Whether large multiple-dimension arrays are reliably supported
4979 depends mostly on the @command{gcc} back end (code generator)
4980 used by @command{g77}, and has not yet been fully investigated.
4981
4982 @node Character-variable Length
4983 @subsection Character-variable Length
4984 @cindex limits, on character-variable length
4985 @cindex character-variable length
4986
4987 Currently, @command{g77} uses the default @code{INTEGER} type
4988 for the lengths of @code{CHARACTER} variables
4989 and array elements.
4990
4991 This means that, for example,
4992 a system with a 64-bit address space
4993 and a 32-bit default @code{INTEGER} type
4994 does not, under @command{g77},
4995 support a @code{CHARACTER*@var{n}} declaration
4996 where @var{n} is greater than 2147483647.
4997
4998 @node Year 10000 (Y10K) Problems
4999 @subsection Year 10000 (Y10K) Problems
5000 @cindex Y10K compliance
5001 @cindex Year 10000 compliance
5002
5003 Most intrinsics returning, or computing values based on,
5004 date information are prone to Year-10000 (Y10K) problems,
5005 due to supporting only 4 digits for the year.
5006
5007 See the following for examples:
5008 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
5009 @ref{IDate Intrinsic (UNIX)},
5010 @ref{Time Intrinsic (VXT)},
5011 @ref{Date_and_Time Intrinsic}.
5012
5013 @node Compiler Types
5014 @section Compiler Types
5015 @cindex types, of data
5016 @cindex data types
5017
5018 Fortran implementations have a fair amount of freedom given them by the
5019 standard as far as how much storage space is used and how much precision
5020 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
5021 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
5022 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
5023 Further, many compilers offer so-called @samp{*@var{n}} notation, but
5024 the interpretation of @var{n} varies across compilers and target architectures.
5025
5026 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
5027 and @code{REAL(KIND=1)}
5028 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
5029 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
5030 Further, it requires that @code{COMPLEX(KIND=1)}
5031 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
5032 storage-associated (such as via @code{EQUIVALENCE})
5033 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
5034 corresponds to the real element and @samp{R(2)} to the imaginary
5035 element of the @code{COMPLEX(KIND=1)} variable.
5036
5037 (Few requirements as to precision or ranges of any of these are
5038 placed on the implementation, nor is the relationship of storage sizes of
5039 these types to the @code{CHARACTER} type specified, by the standard.)
5040
5041 @command{g77} follows the above requirements, warning when compiling
5042 a program requires placement of items in memory that contradict the
5043 requirements of the target architecture.
5044 (For example, a program can require placement of a @code{REAL(KIND=2)}
5045 on a boundary that is not an even multiple of its size, but still an
5046 even multiple of the size of a @code{REAL(KIND=1)} variable.
5047 On some target architectures, using the canonical
5048 mapping of Fortran types to underlying architectural types, such
5049 placement is prohibited by the machine definition or
5050 the Application Binary Interface (ABI) in force for
5051 the configuration defined for building @command{gcc} and @command{g77}.
5052 @command{g77} warns about such
5053 situations when it encounters them.)
5054
5055 @command{g77} follows consistent rules for configuring the mapping between Fortran
5056 types, including the @samp{*@var{n}} notation, and the underlying architectural
5057 types as accessed by a similarly-configured applicable version of the
5058 @command{gcc} compiler.
5059 These rules offer a widely portable, consistent Fortran/C
5060 environment, although they might well conflict with the expectations of
5061 users of Fortran compilers designed and written for particular
5062 architectures.
5063
5064 These rules are based on the configuration that is in force for the
5065 version of @command{gcc} built in the same release as @command{g77} (and
5066 which was therefore used to build both the @command{g77} compiler
5067 components and the @code{libg2c} run-time library):
5068
5069 @table @code
5070 @cindex REAL(KIND=1) type
5071 @cindex types, REAL(KIND=1)
5072 @item REAL(KIND=1)
5073 Same as @code{float} type.
5074
5075 @cindex REAL(KIND=2) type
5076 @cindex types, REAL(KIND=2)
5077 @item REAL(KIND=2)
5078 Same as whatever floating-point type that is twice the size
5079 of a @code{float}---usually, this is a @code{double}.
5080
5081 @cindex INTEGER(KIND=1) type
5082 @cindex types, INTEGER(KIND=1)
5083 @item INTEGER(KIND=1)
5084 Same as an integral type that is occupies the same amount
5085 of memory storage as @code{float}---usually, this is either
5086 an @code{int} or a @code{long int}.
5087
5088 @cindex LOGICAL(KIND=1) type
5089 @cindex types, LOGICAL(KIND=1)
5090 @item LOGICAL(KIND=1)
5091 Same @command{gcc} type as @code{INTEGER(KIND=1)}.
5092
5093 @cindex INTEGER(KIND=2) type
5094 @cindex types, INTEGER(KIND=2)
5095 @item INTEGER(KIND=2)
5096 Twice the size, and usually nearly twice the range,
5097 as @code{INTEGER(KIND=1)}---usually, this is either
5098 a @code{long int} or a @code{long long int}.
5099
5100 @cindex LOGICAL(KIND=2) type
5101 @cindex types, LOGICAL(KIND=2)
5102 @item LOGICAL(KIND=2)
5103 Same @command{gcc} type as @code{INTEGER(KIND=2)}.
5104
5105 @cindex INTEGER(KIND=3) type
5106 @cindex types, INTEGER(KIND=3)
5107 @item INTEGER(KIND=3)
5108 Same @command{gcc} type as signed @code{char}.
5109
5110 @cindex LOGICAL(KIND=3) type
5111 @cindex types, LOGICAL(KIND=3)
5112 @item LOGICAL(KIND=3)
5113 Same @command{gcc} type as @code{INTEGER(KIND=3)}.
5114
5115 @cindex INTEGER(KIND=6) type
5116 @cindex types, INTEGER(KIND=6)
5117 @item INTEGER(KIND=6)
5118 Twice the size, and usually nearly twice the range,
5119 as @code{INTEGER(KIND=3)}---usually, this is
5120 a @code{short}.
5121
5122 @cindex LOGICAL(KIND=6) type
5123 @cindex types, LOGICAL(KIND=6)
5124 @item LOGICAL(KIND=6)
5125 Same @command{gcc} type as @code{INTEGER(KIND=6)}.
5126
5127 @cindex COMPLEX(KIND=1) type
5128 @cindex types, COMPLEX(KIND=1)
5129 @item COMPLEX(KIND=1)
5130 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
5131 one for the imaginary part).
5132
5133 @cindex COMPLEX(KIND=2) type
5134 @cindex types, COMPLEX(KIND=2)
5135 @item COMPLEX(KIND=2)
5136 Two @code{REAL(KIND=2)} scalars.
5137
5138 @cindex *@var{n} notation
5139 @item @var{numeric-type}*@var{n}
5140 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
5141 Same as whatever @command{gcc} type occupies @var{n} times the storage
5142 space of a @command{gcc} @code{char} item.
5143
5144 @cindex DOUBLE PRECISION type
5145 @cindex types, DOUBLE PRECISION
5146 @item DOUBLE PRECISION
5147 Same as @code{REAL(KIND=2)}.
5148
5149 @cindex DOUBLE COMPLEX type
5150 @cindex types, DOUBLE COMPLEX
5151 @item DOUBLE COMPLEX
5152 Same as @code{COMPLEX(KIND=2)}.
5153 @end table
5154
5155 Note that the above are proposed correspondences and might change
5156 in future versions of @command{g77}---avoid writing code depending
5157 on them.
5158
5159 Other types supported by @command{g77}
5160 are derived from gcc types such as @code{char}, @code{short},
5161 @code{int}, @code{long int}, @code{long long int}, @code{long double},
5162 and so on.
5163 That is, whatever types @command{gcc} already supports, @command{g77} supports
5164 now or probably will support in a future version.
5165 The rules for the @samp{@var{numeric-type}*@var{n}} notation
5166 apply to these types,
5167 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
5168 assigned in a way that encourages clarity, consistency, and portability.
5169
5170 @node Compiler Constants
5171 @section Compiler Constants
5172 @cindex constants
5173 @cindex types, constants
5174
5175 @command{g77} strictly assigns types to @emph{all} constants not
5176 documented as ``typeless'' (typeless constants including @samp{'1'Z},
5177 for example).
5178 Many other Fortran compilers attempt to assign types to typed constants
5179 based on their context.
5180 This results in hard-to-find bugs, nonportable
5181 code, and is not in the spirit (though it strictly follows the letter)
5182 of the 77 and 90 standards.
5183
5184 @command{g77} might offer, in a future release, explicit constructs by
5185 which a wider variety of typeless constants may be specified, and/or
5186 user-requested warnings indicating places where @command{g77} might differ
5187 from how other compilers assign types to constants.
5188
5189 @xref{Context-Sensitive Constants}, for more information on this issue.
5190
5191 @node Compiler Intrinsics
5192 @section Compiler Intrinsics
5193
5194 @command{g77} offers an ever-widening set of intrinsics.
5195 Currently these all are procedures (functions and subroutines).
5196
5197 Some of these intrinsics are unimplemented, but their names reserved
5198 to reduce future problems with existing code as they are implemented.
5199 Others are implemented as part of the GNU Fortran language, while
5200 yet others are provided for compatibility with other dialects of
5201 Fortran but are not part of the GNU Fortran language.
5202
5203 To manage these distinctions, @command{g77} provides intrinsic @emph{groups},
5204 a facility that is simply an extension of the intrinsic groups provided
5205 by the GNU Fortran language.
5206
5207 @menu
5208 * Intrinsic Groups::  How intrinsics are grouped for easy management.
5209 * Other Intrinsics::  Intrinsics other than those in the GNU
5210                        Fortran language.
5211 @end menu
5212
5213 @node Intrinsic Groups
5214 @subsection Intrinsic Groups
5215 @cindex groups of intrinsics
5216 @cindex intrinsics, groups
5217
5218 A given specific intrinsic belongs in one or more groups.
5219 Each group is deleted, disabled, hidden, or enabled
5220 by default or a command-line option.
5221 The meaning of each term follows.
5222
5223 @table @b
5224 @cindex deleted intrinsics
5225 @cindex intrinsics, deleted
5226 @item Deleted
5227 No intrinsics are recognized as belonging to that group.
5228
5229 @cindex disabled intrinsics
5230 @cindex intrinsics, disabled
5231 @item Disabled
5232 Intrinsics are recognized as belonging to the group, but
5233 references to them (other than via the @code{INTRINSIC} statement)
5234 are disallowed through that group.
5235
5236 @cindex hidden intrinsics
5237 @cindex intrinsics, hidden
5238 @item Hidden
5239 Intrinsics in that group are recognized and enabled (if implemented)
5240 @emph{only} if the first mention of the actual name of an intrinsic
5241 in a program unit is in an @code{INTRINSIC} statement.
5242
5243 @cindex enabled intrinsics
5244 @cindex intrinsics, enabled
5245 @item Enabled
5246 Intrinsics in that group are recognized and enabled (if implemented).
5247 @end table
5248
5249 The distinction between deleting and disabling a group is illustrated
5250 by the following example.
5251 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
5252 If group @samp{FGR} is deleted, the following program unit will
5253 successfully compile, because @samp{FOO()} will be seen as a
5254 reference to an external function named @samp{FOO}:
5255
5256 @example
5257 PRINT *, FOO()
5258 END
5259 @end example
5260
5261 @noindent
5262 If group @samp{FGR} is disabled, compiling the above program will produce
5263 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
5264 or, if properly invoked, it is not enabled.
5265 To change the above program so it references an external function @samp{FOO}
5266 instead of the disabled @samp{FOO} intrinsic,
5267 add the following line to the top:
5268
5269 @example
5270 EXTERNAL FOO
5271 @end example
5272
5273 @noindent
5274 So, deleting a group tells @command{g77} to pretend as though the intrinsics in
5275 that group do not exist at all, whereas disabling it tells @command{g77} to
5276 recognize them as (disabled) intrinsics in intrinsic-like contexts.
5277
5278 Hiding a group is like enabling it, but the intrinsic must be first
5279 named in an @code{INTRINSIC} statement to be considered a reference to the
5280 intrinsic rather than to an external procedure.
5281 This might be the ``safest'' way to treat a new group of intrinsics
5282 when compiling old
5283 code, because it allows the old code to be generally written as if
5284 those new intrinsics never existed, but to be changed to use them
5285 by inserting @code{INTRINSIC} statements in the appropriate places.
5286 However, it should be the goal of development to use @code{EXTERNAL}
5287 for all names of external procedures that might be intrinsic names.
5288
5289 If an intrinsic is in more than one group, it is enabled if any of its
5290 containing groups are enabled; if not so enabled, it is hidden if
5291 any of its containing groups are hidden; if not so hidden, it is disabled
5292 if any of its containing groups are disabled; if not so disabled, it is
5293 deleted.
5294 This extra complication is necessary because some intrinsics,
5295 such as @code{IBITS}, belong to more than one group, and hence should be
5296 enabled if any of the groups to which they belong are enabled, and so
5297 on.
5298
5299 The groups are:
5300
5301 @cindex intrinsics, groups of
5302 @cindex groups of intrinsics
5303 @table @code
5304 @cindex @code{badu77} intrinsics group
5305 @item badu77
5306 UNIX intrinsics having inappropriate forms (usually functions that
5307 have intended side effects).
5308
5309 @cindex @code{gnu} intrinsics group
5310 @item gnu
5311 Intrinsics the GNU Fortran language supports that are extensions to
5312 the Fortran standards (77 and 90).
5313
5314 @cindex @command{f2c} intrinsics group
5315 @item f2c
5316 Intrinsics supported by AT&T's @command{f2c} converter and/or @code{libf2c}.
5317
5318 @cindex @code{f90} intrinsics group
5319 @item f90
5320 Fortran 90 intrinsics.
5321
5322 @cindex @code{mil} intrinsics group
5323 @item mil
5324 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
5325
5326 @cindex @code{mil} intrinsics group
5327 @item unix
5328 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
5329
5330 @cindex @code{mil} intrinsics group
5331 @item vxt
5332 VAX/VMS FORTRAN (current as of v4) intrinsics.
5333 @end table
5334
5335 @node Other Intrinsics
5336 @subsection Other Intrinsics
5337 @cindex intrinsics, others
5338 @cindex other intrinsics
5339
5340 @command{g77} supports intrinsics other than those in the GNU Fortran
5341 language proper.
5342 This set of intrinsics is described below.
5343
5344 @ifinfo
5345 (Note that the empty lines appearing in the menu below
5346 are not intentional---they result from a bug in the
5347 @code{makeinfo} program.)
5348 @end ifinfo
5349
5350 @c The actual documentation for intrinsics comes from
5351 @c intdoc.texi, which in turn is automatically generated
5352 @c from the internal g77 tables in intrin.def _and_ the
5353 @c largely hand-written text in intdoc.h.  So, if you want
5354 @c to change or add to existing documentation on intrinsics,
5355 @c you probably want to edit intdoc.h.
5356 @c
5357 @clear familyF77
5358 @clear familyGNU
5359 @clear familyASC
5360 @clear familyMIL
5361 @clear familyF90
5362 @set familyVXT
5363 @set familyFVZ
5364 @clear familyF2C
5365 @clear familyF2U
5366 @set familyBADU77
5367 @include intdoc.texi
5368
5369 @node Other Compilers
5370 @chapter Other Compilers
5371
5372 An individual Fortran source file can be compiled to
5373 an object (@file{*.o}) file instead of to the final
5374 program executable.
5375 This allows several portions of a program to be compiled
5376 at different times and linked together whenever a new
5377 version of the program is needed.
5378 However, it introduces the issue of @dfn{object compatibility}
5379 across the various object files (and libraries, or @file{*.a}
5380 files) that are linked together to produce any particular
5381 executable file.
5382
5383 Object compatibility is an issue when combining, in one
5384 program, Fortran code compiled by more than one compiler
5385 (or more than one configuration of a compiler).
5386 If the compilers
5387 disagree on how to transform the names of procedures, there
5388 will normally be errors when linking such programs.
5389 Worse, if the compilers agree on naming, but disagree on issues
5390 like how to pass parameters, return arguments, and lay out
5391 @code{COMMON} areas, the earliest detected errors might be the
5392 incorrect results produced by the program (and that assumes
5393 these errors are detected, which is not always the case).
5394
5395 Normally, @command{g77} generates code that is
5396 object-compatible with code generated by a version of
5397 @command{f2c} configured (with, for example, @file{f2c.h} definitions)
5398 to be generally compatible with @command{g77} as built by @command{gcc}.
5399 (Normally, @command{f2c} will, by default, conform to the appropriate
5400 configuration, but it is possible that older or perhaps even newer
5401 versions of @command{f2c}, or versions having certain configuration changes
5402 to @command{f2c} internals, will produce object files that are
5403 incompatible with @command{g77}.)
5404
5405 For example, a Fortran string subroutine
5406 argument will become two arguments on the C side: a @code{char *}
5407 and an @code{int} length.
5408
5409 Much of this compatibility results from the fact that
5410 @command{g77} uses the same run-time library,
5411 @code{libf2c}, used by @command{f2c},
5412 though @command{g77} gives its version the name @code{libg2c}
5413 so as to avoid conflicts when linking,
5414 installing them in the same directories,
5415 and so on.
5416
5417 Other compilers might or might not generate code that
5418 is object-compatible with @code{libg2c} and current @command{g77},
5419 and some might offer such compatibility only when explicitly
5420 selected via a command-line option to the compiler.
5421
5422 @emph{Note: This portion of the documentation definitely needs a lot
5423 of work!}
5424
5425 @menu
5426 * Dropping f2c Compatibility::  When speed is more important.
5427 * Compilers Other Than f2c::    Interoperation with code from other compilers.
5428 @end menu
5429
5430 @node Dropping f2c Compatibility
5431 @section Dropping @command{f2c} Compatibility
5432
5433 Specifying @option{-fno-f2c} allows @command{g77} to generate, in
5434 some cases, faster code, by not needing to allow to the possibility
5435 of linking with code compiled by @command{f2c}.
5436
5437 For example, this affects how @code{REAL(KIND=1)},
5438 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
5439 With @option{-fno-f2c}, they are
5440 compiled as returning the appropriate @command{gcc} type
5441 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
5442 in many configurations).
5443
5444 With @option{-ff2c} in force, they
5445 are compiled differently (with perhaps slower run-time performance)
5446 to accommodate the restrictions inherent in @command{f2c}'s use of K&R
5447 C as an intermediate language---@code{REAL(KIND=1)} functions
5448 return C's @code{double} type, while @code{COMPLEX} functions return
5449 @code{void} and use an extra argument pointing to a place for the functions to
5450 return their values.
5451
5452 It is possible that, in some cases, leaving @option{-ff2c} in force
5453 might produce faster code than using @option{-fno-f2c}.
5454 Feel free to experiment, but remember to experiment with changing the way
5455 @emph{entire programs and their Fortran libraries are compiled} at
5456 a time, since this sort of experimentation affects the interface
5457 of code generated for a Fortran source file---that is, it affects
5458 object compatibility.
5459
5460 Note that @command{f2c} compatibility is a fairly static target to achieve,
5461 though not necessarily perfectly so, since, like @command{g77}, it is
5462 still being improved.
5463 However, specifying @option{-fno-f2c} causes @command{g77}
5464 to generate code that will probably be incompatible with code
5465 generated by future versions of @command{g77} when the same option
5466 is in force.
5467 You should make sure you are always able to recompile complete
5468 programs from source code when upgrading to new versions of @command{g77}
5469 or @command{f2c}, especially when using options such as @option{-fno-f2c}.
5470
5471 Therefore, if you are using @command{g77} to compile libraries and other
5472 object files for possible future use and you don't want to require
5473 recompilation for future use with subsequent versions of @command{g77},
5474 you might want to stick with @command{f2c} compatibility for now, and
5475 carefully watch for any announcements about changes to the
5476 @command{f2c}/@code{libf2c} interface that might affect existing programs
5477 (thus requiring recompilation).
5478
5479 It is probable that a future version of @command{g77} will not,
5480 by default, generate object files compatible with @command{f2c},
5481 and that version probably would no longer use @code{libf2c}.
5482 If you expect to depend on this compatibility in the
5483 long term, use the options @samp{-ff2c -ff2c-library} when compiling
5484 all of the applicable code.
5485 This should cause future versions of @command{g77} either to produce
5486 compatible code (at the expense of the availability of some features and
5487 performance), or at the very least, to produce diagnostics.
5488
5489 (The library @command{g77} produces will no longer be named @file{libg2c}
5490 when it is no longer generally compatible with @file{libf2c}.
5491 It will likely be referred to, and, if installed as a distinct
5492 library, named @code{libg77}, or some other as-yet-unused name.)
5493
5494 @node Compilers Other Than f2c
5495 @section Compilers Other Than @command{f2c}
5496
5497 On systems with Fortran compilers other than @command{f2c} and @command{g77},
5498 code compiled by @command{g77} is not expected to work
5499 well with code compiled by the native compiler.
5500 (This is true for @command{f2c}-compiled objects as well.)
5501 Libraries compiled with the native compiler probably will have
5502 to be recompiled with @command{g77} to be used with @command{g77}-compiled code.
5503
5504 Reasons for such incompatibilities include:
5505
5506 @itemize @bullet
5507 @item
5508 There might be differences in the way names of Fortran procedures
5509 are translated for use in the system's object-file format.
5510 For example, the statement @samp{CALL FOO} might be compiled
5511 by @command{g77} to call a procedure the linker @command{ld} sees
5512 given the name @samp{_foo_}, while the apparently corresponding
5513 statement @samp{SUBROUTINE FOO} might be compiled by the
5514 native compiler to define the linker-visible name @samp{_foo},
5515 or @samp{_FOO_}, and so on.
5516
5517 @item
5518 There might be subtle type mismatches which cause subroutine arguments
5519 and function return values to get corrupted.
5520
5521 This is why simply getting @command{g77} to
5522 transform procedure names the same way a native
5523 compiler does is not usually a good idea---unless
5524 some effort has been made to ensure that, aside
5525 from the way the two compilers transform procedure
5526 names, everything else about the way they generate
5527 code for procedure interfaces is identical.
5528
5529 @item
5530 Native compilers
5531 use libraries of private I/O routines which will not be available
5532 at link time unless you have the native compiler---and you would
5533 have to explicitly ask for them.
5534
5535 For example, on the Sun you
5536 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
5537 command.
5538 @end itemize
5539
5540 @node Other Languages
5541 @chapter Other Languages
5542
5543 @emph{Note: This portion of the documentation definitely needs a lot
5544 of work!}
5545
5546 @menu
5547 * Interoperating with C and C++::
5548 @end menu
5549
5550 @node Interoperating with C and C++
5551 @section Tools and advice for interoperating with C and C++
5552
5553 @cindex C, linking with
5554 @cindex C++, linking with
5555 @cindex linking with C
5556 The following discussion assumes that you are running @command{g77} in @command{f2c}
5557 compatibility mode, i.e.@: not using @option{-fno-f2c}.
5558 It provides some
5559 advice about quick and simple techniques for linking Fortran and C (or
5560 C++), the most common requirement.
5561 For the full story consult the
5562 description of code generation.
5563 @xref{Debugging and Interfacing}.
5564
5565 When linking Fortran and C, it's usually best to use @command{g77} to do
5566 the linking so that the correct libraries are included (including the
5567 maths one).
5568 If you're linking with C++ you will want to add
5569 @option{-lstdc++}, @option{-lg++} or whatever.
5570 If you need to use another
5571 driver program (or @command{ld} directly),
5572 you can find out what linkage
5573 options @command{g77} passes by running @samp{g77 -v}.
5574
5575 @menu
5576 * C Interfacing Tools::
5577 * C Access to Type Information::
5578 * f2c Skeletons and Prototypes::
5579 * C++ Considerations::
5580 * Startup Code::
5581 @end menu
5582
5583 @node C Interfacing Tools
5584 @subsection C Interfacing Tools
5585 @pindex f2c
5586 @cindex cfortran.h
5587 @cindex Netlib
5588 Even if you don't actually use it as a compiler, @command{f2c} from
5589 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
5590 interfacing (linking) Fortran and C@.
5591 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @command{f2c}}.
5592
5593 To use @command{f2c} for this purpose you only need retrieve and
5594 build the @file{src} directory from the distribution, consult the
5595 @file{README} instructions there for machine-specifics, and install the
5596 @command{f2c} program on your path.
5597
5598 Something else that might be useful is @samp{cfortran.h} from
5599 @uref{ftp://zebra.desy.de/cfortran}.
5600 This is a fairly general tool which
5601 can be used to generate interfaces for calling in both directions
5602 between Fortran and C@.
5603 It can be used in @command{f2c} mode with
5604 @command{g77}---consult its documentation for details.
5605
5606 @node C Access to Type Information
5607 @subsection Accessing Type Information in C
5608
5609 @cindex types, Fortran/C
5610 Generally, C code written to link with
5611 @command{g77} code---calling and/or being
5612 called from Fortran---should @samp{#include <g2c.h>} to define the C
5613 versions of the Fortran types.
5614 Don't assume Fortran @code{INTEGER} types
5615 correspond to C @code{int}s, for instance; instead, declare them as
5616 @code{integer}, a type defined by @file{g2c.h}.
5617 @file{g2c.h} is installed where @command{gcc} will find it by
5618 default, assuming you use a copy of @command{gcc} compatible with
5619 @command{g77}, probably built at the same time as @command{g77}.
5620
5621 @node f2c Skeletons and Prototypes
5622 @subsection Generating Skeletons and Prototypes with @command{f2c}
5623
5624 @pindex f2c
5625 @cindex -fno-second-underscore
5626 A simple and foolproof way to write @command{g77}-callable C routines---e.g.@: to
5627 interface with an existing library---is to write a file (named, for
5628 example, @file{fred.f}) of dummy Fortran
5629 skeletons comprising just the declaration of the routine(s) and dummy
5630 arguments plus @code{END} statements.
5631 Then run @command{f2c} on file @file{fred.f} to produce @file{fred.c}
5632 into which you can edit
5633 useful code, confident the calling sequence is correct, at least.
5634 (There are some errors otherwise commonly made in generating C
5635 interfaces with @command{f2c} conventions,
5636 such as not using @code{doublereal}
5637 as the return type of a @code{REAL} @code{FUNCTION}.)
5638
5639 @pindex ftnchek
5640 @command{f2c} also can help with calling Fortran from C, using its
5641 @option{-P} option to generate C prototypes appropriate for calling the
5642 Fortran.@footnote{The files generated like this can also be used for
5643 inter-unit consistency checking of dummy and actual arguments, although
5644 the @command{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
5645 or @uref{ftp://ftp.dsm.fordham.edu} is
5646 probably better for this purpose.}
5647 If the Fortran code containing any
5648 routines to be called from C is in file @file{joe.f}, use the command
5649 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
5650 prototype information.
5651 @code{#include} this in the C which has to call
5652 the Fortran routines to make sure you get it right.
5653
5654 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
5655 between the way Fortran (including compilers like @command{g77}) and
5656 C handle arrays.
5657
5658 @node C++ Considerations
5659 @subsection C++ Considerations
5660
5661 @cindex C++
5662 @command{f2c} can be used to generate suitable code for compilation with a
5663 C++ system using the @option{-C++} option.
5664 The important thing about linking @command{g77}-compiled
5665 code with C++ is that the prototypes for the @command{g77}
5666 routines must specify C linkage to avoid name mangling.
5667 So, use an @samp{extern "C"} declaration.
5668 @command{f2c}'s @option{-C++} option will take care
5669 of this when generating skeletons or prototype files as above, and also
5670 avoid clashes with C++ reserved words in addition to those in C@.
5671
5672 @node Startup Code
5673 @subsection Startup Code
5674
5675 @cindex startup code
5676 @cindex run-time, initialization
5677 @cindex initialization, run-time
5678 Unlike with some runtime systems,
5679 it shouldn't be necessary
5680 (unless there are bugs)
5681 to use a Fortran main program unit to ensure the
5682 runtime---specifically the I/O system---is initialized.
5683
5684 However, to use the @command{g77} intrinsics @code{GETARG} and @code{IARGC},
5685 either the @code{main} routine from the @file{libg2c} library must be used,
5686 or the @code{f_setarg} routine
5687 (new as of @code{egcs} version 1.1 and @command{g77} version 0.5.23)
5688 must be called with the appropriate @code{argc} and @code{argv} arguments
5689 prior to the program calling @code{GETARG} or @code{IARGC}.
5690
5691 To provide more flexibility for mixed-language programming
5692 involving @command{g77} while allowing for shared libraries,
5693 as of @code{egcs} version 1.1 and @command{g77} version 0.5.23,
5694 @command{g77}'s @code{main} routine in @code{libg2c}
5695 does the following, in order:
5696
5697 @enumerate
5698 @item
5699 Calls @code{f_setarg}
5700 with the incoming @code{argc} and @code{argv} arguments,
5701 in the same order as for @code{main} itself.
5702
5703 This sets up the command-line environment
5704 for @code{GETARG} and @code{IARGC}.
5705
5706 @item
5707 Calls @code{f_setsig} (with no arguments).
5708
5709 This sets up the signaling and exception environment.
5710
5711 @item
5712 Calls @code{f_init} (with no arguments).
5713
5714 This initializes the I/O environment,
5715 though that should not be necessary,
5716 as all I/O functions in @code{libf2c}
5717 are believed to call @code{f_init} automatically,
5718 if necessary.
5719
5720 (A future version of @command{g77} might skip this explicit step,
5721 to speed up normal exit of a program.)
5722
5723 @item
5724 Arranges for @code{f_exit} to be called (with no arguments)
5725 when the program exits.
5726
5727 This ensures that the I/O environment is properly shut down
5728 before the program exits normally.
5729 Otherwise, output buffers might not be fully flushed,
5730 scratch files might not be deleted, and so on.
5731
5732 The simple way @code{main} does this is
5733 to call @code{f_exit} itself after calling
5734 @code{MAIN__} (in the next step).
5735
5736 However, this does not catch the cases where the program
5737 might call @code{exit} directly,
5738 instead of using the @code{EXIT} intrinsic
5739 (implemented as @code{exit_} in @code{libf2c}).
5740
5741 So, @code{main} attempts to use
5742 the operating environment's @code{onexit} or @code{atexit}
5743 facility, if available,
5744 to cause @code{f_exit} to be called automatically
5745 upon any invocation of @code{exit}.
5746
5747 @item
5748 Calls @code{MAIN__} (with no arguments).
5749
5750 This starts executing the Fortran main program unit for
5751 the application.
5752 (Both @command{g77} and @command{f2c} currently compile a main
5753 program unit so that its global name is @code{MAIN__}.)
5754
5755 @item
5756 If no @code{onexit} or @code{atexit} is provided by the system,
5757 calls @code{f_exit}.
5758
5759 @item
5760 Calls @code{exit} with a zero argument,
5761 to signal a successful program termination.
5762
5763 @item
5764 Returns a zero value to the caller,
5765 to signal a successful program termination,
5766 in case @code{exit} doesn't exit on the system.
5767 @end enumerate
5768
5769 All of the above names are C @code{extern} names,
5770 i.e.@: not mangled.
5771
5772 When using the @code{main} procedure provided by @command{g77}
5773 without a Fortran main program unit,
5774 you need to provide @code{MAIN__}
5775 as the entry point for your C code.
5776 (Make sure you link the object file that defines that
5777 entry point with the rest of your program.)
5778
5779 To provide your own @code{main} procedure
5780 in place of @command{g77}'s,
5781 make sure you specify the object file defining that procedure
5782 @emph{before} @option{-lg2c} on the @command{g77} command line.
5783 Since the @option{-lg2c} option is implicitly provided,
5784 this is usually straightforward.
5785 (Use the @option{--verbose} option to see how and where
5786 @command{g77} implicitly adds @option{-lg2c} in a command line
5787 that will link the program.
5788 Feel free to specify @option{-lg2c} explicitly,
5789 as appropriate.)
5790
5791 However, when providing your own @code{main},
5792 make sure you perform the appropriate tasks in the
5793 appropriate order.
5794 For example, if your @code{main} does not call @code{f_setarg},
5795 make sure the rest of your application does not call
5796 @code{GETARG} or @code{IARGC}.
5797
5798 And, if your @code{main} fails to ensure that @code{f_exit}
5799 is called upon program exit,
5800 some files might end up incompletely written,
5801 some scratch files might be left lying around,
5802 and some existing files being written might be left
5803 with old data not properly truncated at the end.
5804
5805 Note that, generally, the @command{g77} operating environment
5806 does not depend on a procedure named @code{MAIN__} actually
5807 being called prior to any other @command{g77}-compiled code.
5808 That is, @code{MAIN__} does not, itself,
5809 set up any important operating-environment characteristics
5810 upon which other code might depend.
5811 This might change in future versions of @command{g77},
5812 with appropriate notification in the release notes.
5813
5814 For more information, consult the source code for the above routines.
5815 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
5816 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
5817
5818 Also, the file @file{@value{path-g77}/com.c} contains the code @command{g77}
5819 uses to open-code (inline) references to @code{IARGC}.
5820
5821 @node Debugging and Interfacing
5822 @chapter Debugging and Interfacing
5823 @cindex debugging
5824 @cindex interfacing
5825 @cindex calling C routines
5826 @cindex C routines calling Fortran
5827 @cindex f2c compatibility
5828
5829 GNU Fortran currently generates code that is object-compatible with
5830 the @command{f2c} converter.
5831 Also, it avoids limitations in the current GBE, such as the
5832 inability to generate a procedure with
5833 multiple entry points, by generating code that is structured
5834 differently (in terms of procedure names, scopes, arguments, and
5835 so on) than might be expected.
5836
5837 As a result, writing code in other languages that calls on, is
5838 called by, or shares in-memory data with @command{g77}-compiled code generally
5839 requires some understanding of the way @command{g77} compiles code for
5840 various constructs.
5841
5842 Similarly, using a debugger to debug @command{g77}-compiled
5843 code, even if that debugger supports native Fortran debugging, generally
5844 requires this sort of information.
5845
5846 This section describes some of the basic information on how
5847 @command{g77} compiles code for constructs involving interfaces to other
5848 languages and to debuggers.
5849
5850 @emph{Caution:} Much or all of this information pertains to only the current
5851 release of @command{g77}, sometimes even to using certain compiler options
5852 with @command{g77} (such as @option{-fno-f2c}).
5853 Do not write code that depends on this
5854 information without clearly marking said code as nonportable and
5855 subject to review for every new release of @command{g77}.
5856 This information
5857 is provided primarily to make debugging of code generated by this
5858 particular release of @command{g77} easier for the user, and partly to make
5859 writing (generally nonportable) interface code easier.
5860 Both of these
5861 activities require tracking changes in new version of @command{g77} as they
5862 are installed, because new versions can change the behaviors
5863 described in this section.
5864
5865 @menu
5866 * Main Program Unit::  How @command{g77} compiles a main program unit.
5867 * Procedures::         How @command{g77} constructs parameter lists
5868                        for procedures.
5869 * Functions::          Functions returning floating-point or character data.
5870 * Names::              Naming of user-defined variables, procedures, etc.
5871 * Common Blocks::      Accessing common variables while debugging.
5872 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
5873 * Complex Variables::  How @command{g77} performs complex arithmetic.
5874 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
5875 * Adjustable Arrays::  Special consideration for adjustable arrays.
5876 * Alternate Entry Points::  How @command{g77} implements alternate @code{ENTRY}.
5877 * Alternate Returns::  How @command{g77} handles alternate returns.
5878 * Assigned Statement Labels::  How @command{g77} handles @code{ASSIGN}.
5879 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
5880 @end menu
5881
5882 @node Main Program Unit
5883 @section Main Program Unit (PROGRAM)
5884 @cindex PROGRAM statement
5885 @cindex statements, PROGRAM
5886
5887 When @command{g77} compiles a main program unit, it gives it the public
5888 procedure name @code{MAIN__}.
5889 The @code{libg2c} library has the actual @code{main()} procedure
5890 as is typical of C-based environments, and
5891 it is this procedure that performs some initial start-up
5892 activity and then calls @code{MAIN__}.
5893
5894 Generally, @command{g77} and @code{libg2c} are designed so that you need not
5895 include a main program unit written in Fortran in your program---it
5896 can be written in C or some other language.
5897 Especially for I/O handling, this is the case, although @command{g77} version 0.5.16
5898 includes a bug fix for @code{libg2c} that solved a problem with using the
5899 @code{OPEN} statement as the first Fortran I/O activity in a program
5900 without a Fortran main program unit.
5901
5902 However, if you don't intend to use @command{g77} (or @command{f2c}) to compile
5903 your main program unit---that is, if you intend to compile a @code{main()}
5904 procedure using some other language---you should carefully
5905 examine the code for @code{main()} in @code{libg2c}, found in the source
5906 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
5907 might need to be done by your @code{main()} in order to provide the
5908 Fortran environment your Fortran code is expecting.
5909
5910 @cindex @code{IArgC} intrinsic
5911 @cindex intrinsics, @code{IArgC}
5912 @cindex @code{GetArg} intrinsic
5913 @cindex intrinsics, @code{GetArg}
5914 For example, @code{libg2c}'s @code{main()} sets up the information used by
5915 the @code{IARGC} and @code{GETARG} intrinsics.
5916 Bypassing @code{libg2c}'s @code{main()}
5917 without providing a substitute for this activity would mean
5918 that invoking @code{IARGC} and @code{GETARG} would produce undefined
5919 results.
5920
5921 @cindex debugging
5922 @cindex main program unit, debugging
5923 @cindex main()
5924 @cindex MAIN__()
5925 @cindex .gdbinit
5926 When debugging, one implication of the fact that @code{main()}, which
5927 is the place where the debugged program ``starts'' from the
5928 debugger's point of view, is in @code{libg2c} is that you won't be
5929 starting your Fortran program at a point you recognize as your
5930 Fortran code.
5931
5932 The standard way to get around this problem is to set a break
5933 point (a one-time, or temporary, break point will do) at
5934 the entrance to @code{MAIN__}, and then run the program.
5935 A convenient way to do so is to add the @command{gdb} command
5936
5937 @example
5938 tbreak MAIN__
5939 @end example
5940
5941 @noindent
5942 to the file @file{.gdbinit} in the directory in which you're debugging
5943 (using @command{gdb}).
5944
5945 After doing this, the debugger will see the current execution
5946 point of the program as at the beginning of the main program
5947 unit of your program.
5948
5949 Of course, if you really want to set a break point at some
5950 other place in your program and just start the program
5951 running, without first breaking at @code{MAIN__},
5952 that should work fine.
5953
5954 @node Procedures
5955 @section Procedures (SUBROUTINE and FUNCTION)
5956 @cindex procedures
5957 @cindex SUBROUTINE statement
5958 @cindex statements, SUBROUTINE
5959 @cindex FUNCTION statement
5960 @cindex statements, FUNCTION
5961 @cindex signature of procedures
5962
5963 Currently, @command{g77} passes arguments via reference---specifically,
5964 by passing a pointer to the location in memory of a variable, array,
5965 array element, a temporary location that holds the result of evaluating an
5966 expression, or a temporary or permanent location that holds the value
5967 of a constant.
5968
5969 Procedures that accept @code{CHARACTER} arguments are implemented by
5970 @command{g77} so that each @code{CHARACTER} argument has two actual arguments.
5971
5972 The first argument occupies the expected position in the
5973 argument list and has the user-specified name.
5974 This argument
5975 is a pointer to an array of characters, passed by the caller.
5976
5977 The second argument is appended to the end of the user-specified
5978 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
5979 is the user-specified name.
5980 This argument is of the C type @code{ftnlen}
5981 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
5982 is the number of characters the caller has allocated in the
5983 array pointed to by the first argument.
5984
5985 A procedure will ignore the length argument if @samp{X} is not declared
5986 @code{CHARACTER*(*)}, because for other declarations, it knows the
5987 length.
5988 Not all callers necessarily ``know'' this, however, which
5989 is why they all pass the extra argument.
5990
5991 The contents of the @code{CHARACTER} argument are specified by the
5992 address passed in the first argument (named after it).
5993 The procedure can read or write these contents as appropriate.
5994
5995 When more than one @code{CHARACTER} argument is present in the argument
5996 list, the length arguments are appended in the order
5997 the original arguments appear.
5998 So @samp{CALL FOO('HI','THERE')} is implemented in
5999 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @command{g77}
6000 does not provide the trailing null bytes on the constant
6001 strings (@command{f2c} does provide them, but they are unnecessary in
6002 a Fortran environment, and you should not expect them to be
6003 there).
6004
6005 Note that the above information applies to @code{CHARACTER} variables and
6006 arrays @strong{only}.
6007 It does @strong{not} apply to external @code{CHARACTER}
6008 functions or to intrinsic @code{CHARACTER} functions.
6009 That is, no second length argument is passed to @samp{FOO} in this case:
6010
6011 @example
6012 CHARACTER X
6013 EXTERNAL X
6014 CALL FOO(X)
6015 @end example
6016
6017 @noindent
6018 Nor does @samp{FOO} expect such an argument in this case:
6019
6020 @example
6021 SUBROUTINE FOO(X)
6022 CHARACTER X
6023 EXTERNAL X
6024 @end example
6025
6026 Because of this implementation detail, if a program has a bug
6027 such that there is disagreement as to whether an argument is
6028 a procedure, and the type of the argument is @code{CHARACTER}, subtle
6029 symptoms might appear.
6030
6031 @node Functions
6032 @section Functions (FUNCTION and RETURN)
6033 @cindex functions
6034 @cindex FUNCTION statement
6035 @cindex statements, FUNCTION
6036 @cindex RETURN statement
6037 @cindex statements, RETURN
6038 @cindex return type of functions
6039
6040 @command{g77} handles in a special way functions that return the following
6041 types:
6042
6043 @itemize @bullet
6044 @item
6045 @code{CHARACTER}
6046 @item
6047 @code{COMPLEX}
6048 @item
6049 @code{REAL(KIND=1)}
6050 @end itemize
6051
6052 For @code{CHARACTER}, @command{g77} implements a subroutine (a C function
6053 returning @code{void})
6054 with two arguments prepended: @samp{__g77_result}, which the caller passes
6055 as a pointer to a @code{char} array expected to hold the return value,
6056 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
6057 specifying the length of the return value as declared in the calling
6058 program.
6059 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
6060 to determine the size of the array that @samp{__g77_result} points to;
6061 otherwise, it ignores that argument.
6062
6063 For @code{COMPLEX}, when @option{-ff2c} is in
6064 force, @command{g77} implements
6065 a subroutine with one argument prepended: @samp{__g77_result}, which the
6066 caller passes as a pointer to a variable of the type of the function.
6067 The called function writes the return value into this variable instead
6068 of returning it as a function value.
6069 When @option{-fno-f2c} is in force,
6070 @command{g77} implements a @code{COMPLEX} function as @command{gcc}'s
6071 @samp{__complex__ float} or @samp{__complex__ double} function
6072 (or an emulation thereof, when @option{-femulate-complex} is in effect),
6073 returning the result of the function in the same way as @command{gcc} would.
6074
6075 For @code{REAL(KIND=1)}, when @option{-ff2c} is in force, @command{g77} implements
6076 a function that actually returns @code{REAL(KIND=2)} (typically
6077 C's @code{double} type).
6078 When @option{-fno-f2c} is in force, @code{REAL(KIND=1)}
6079 functions return @code{float}.
6080
6081 @node Names
6082 @section Names
6083 @cindex symbol names
6084 @cindex transforming symbol names
6085
6086 Fortran permits each implementation to decide how to represent
6087 names as far as how they're seen in other contexts, such as debuggers
6088 and when interfacing to other languages, and especially as far
6089 as how casing is handled.
6090
6091 External names---names of entities that are public, or ``accessible'',
6092 to all modules in a program---normally have an underscore (@samp{_})
6093 appended by @command{g77},
6094 to generate code that is compatible with @command{f2c}.
6095 External names include names of Fortran things like common blocks,
6096 external procedures (subroutines and functions, but not including
6097 statement functions, which are internal procedures), and entry point
6098 names.
6099
6100 However, use of the @option{-fno-underscoring} option
6101 disables this kind of transformation of external names (though inhibiting
6102 the transformation certainly improves the chances of colliding with
6103 incompatible externals written in other languages---but that
6104 might be intentional.
6105
6106 @cindex -fno-underscoring option
6107 @cindex options, -fno-underscoring
6108 @cindex -fno-second-underscore option
6109 @cindex options, -fno-underscoring
6110 When @option{-funderscoring} is in force, any name (external or local)
6111 that already has at least one underscore in it is
6112 implemented by @command{g77} by appending two underscores.
6113 (This second underscore can be disabled via the
6114 @option{-fno-second-underscore} option.)
6115 External names are changed this way for @command{f2c} compatibility.
6116 Local names are changed this way to avoid collisions with external names
6117 that are different in the source code---@command{f2c} does the same thing, but
6118 there's no compatibility issue there except for user expectations while
6119 debugging.
6120
6121 For example:
6122
6123 @example
6124 Max_Cost = 0
6125 @end example
6126
6127 @cindex debugging
6128 @noindent
6129 Here, a user would, in the debugger, refer to this variable using the
6130 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
6131 as described below).
6132 (We hope to improve @command{g77} in this regard in the future---don't
6133 write scripts depending on this behavior!
6134 Also, consider experimenting with the @option{-fno-underscoring}
6135 option to try out debugging without having to massage names by
6136 hand like this.)
6137
6138 @command{g77} provides a number of command-line options that allow the user
6139 to control how case mapping is handled for source files.
6140 The default is the traditional UNIX model for Fortran compilers---names
6141 are mapped to lower case.
6142 Other command-line options can be specified to map names to upper
6143 case, or to leave them exactly as written in the source file.
6144
6145 For example:
6146
6147 @example
6148 Foo = 9.436
6149 @end example
6150
6151 @noindent
6152 Here, it is normally the case that the variable assigned will be named
6153 @samp{foo}.
6154 This would be the name to enter when using a debugger to
6155 access the variable.
6156
6157 However, depending on the command-line options specified, the
6158 name implemented by @command{g77} might instead be @samp{FOO} or even
6159 @samp{Foo}, thus affecting how debugging is done.
6160
6161 Also:
6162
6163 @example
6164 Call Foo
6165 @end example
6166
6167 @noindent
6168 This would normally call a procedure that, if it were in a separate C program,
6169 be defined starting with the line:
6170
6171 @example
6172 void foo_()
6173 @end example
6174
6175 @noindent
6176 However, @command{g77} command-line options could be used to change the casing
6177 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
6178 procedure instead of @samp{foo_}, and the @option{-fno-underscoring} option
6179 could be used to inhibit the appending of the underscore to the name.
6180
6181 @node Common Blocks
6182 @section Common Blocks (COMMON)
6183 @cindex common blocks
6184 @cindex @code{COMMON} statement
6185 @cindex statements, @code{COMMON}
6186
6187 @command{g77} names and lays out @code{COMMON} areas
6188 the same way @command{f2c} does,
6189 for compatibility with @command{f2c}.
6190
6191 @node Local Equivalence Areas
6192 @section Local Equivalence Areas (EQUIVALENCE)
6193 @cindex equivalence areas
6194 @cindex local equivalence areas
6195 @cindex EQUIVALENCE statement
6196 @cindex statements, EQUIVALENCE
6197
6198 @command{g77} treats storage-associated areas involving a @code{COMMON}
6199 block as explained in the section on common blocks.
6200
6201 A local @code{EQUIVALENCE} area is a collection of variables and arrays
6202 connected to each other in any way via @code{EQUIVALENCE}, none of which are
6203 listed in a @code{COMMON} statement.
6204
6205 (@emph{Note:} @command{g77} version 0.5.18 and earlier chose the name
6206 for @var{x} using a different method when more than one name was
6207 in the list of names of entities placed at the beginning of the
6208 array.
6209 Though the documentation specified that the first name listed in
6210 the @code{EQUIVALENCE} statements was chosen for @var{x}, @command{g77}
6211 in fact chose the name using a method that was so complicated,
6212 it seemed easier to change it to an alphabetical sort than to describe the
6213 previous method in the documentation.)
6214
6215 @node Complex Variables
6216 @section Complex Variables (COMPLEX)
6217 @cindex complex variables
6218 @cindex imaginary part
6219 @cindex COMPLEX statement
6220 @cindex statements, COMPLEX
6221
6222 As of 0.5.20, @command{g77} defaults to handling @code{COMPLEX} types
6223 (and related intrinsics, constants, functions, and so on)
6224 in a manner that
6225 makes direct debugging involving these types in Fortran
6226 language mode difficult.
6227
6228 Essentially, @command{g77} implements these types using an
6229 internal construct similar to C's @code{struct}, at least
6230 as seen by the @command{gcc} back end.
6231
6232 Currently, the back end, when outputting debugging info with
6233 the compiled code for the assembler to digest, does not detect
6234 these @code{struct} types as being substitutes for Fortran
6235 complex.
6236 As a result, the Fortran language modes of debuggers such as
6237 @command{gdb} see these types as C @code{struct} types, which
6238 they might or might not support.
6239
6240 Until this is fixed, switch to C language mode to work with
6241 entities of @code{COMPLEX} type and then switch back to Fortran language
6242 mode afterward.
6243 (In @command{gdb}, this is accomplished via @samp{set lang c} and
6244 either @samp{set lang fortran} or @samp{set lang auto}.)
6245
6246 @node Arrays
6247 @section Arrays (DIMENSION)
6248 @cindex DIMENSION statement
6249 @cindex statements, DIMENSION
6250 @cindex array ordering
6251 @cindex ordering, array
6252 @cindex column-major ordering
6253 @cindex row-major ordering
6254 @cindex arrays
6255
6256 Fortran uses ``column-major ordering'' in its arrays.
6257 This differs from other languages, such as C, which use ``row-major ordering''.
6258 The difference is that, with Fortran, array elements adjacent to
6259 each other in memory differ in the @emph{first} subscript instead of
6260 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
6261 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
6262
6263 This consideration
6264 affects not only interfacing with and debugging Fortran code,
6265 it can greatly affect how code is designed and written, especially
6266 when code speed and size is a concern.
6267
6268 Fortran also differs from C, a popular language for interfacing and
6269 to support directly in debuggers, in the way arrays are treated.
6270 In C, arrays are single-dimensional and have interesting relationships
6271 to pointers, neither of which is true for Fortran.
6272 As a result, dealing with Fortran arrays from within
6273 an environment limited to C concepts can be challenging.
6274
6275 For example, accessing the array element @samp{A(5,10,20)} is easy enough
6276 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
6277 are needed.
6278 First, C would treat the A array as a single-dimension array.
6279 Second, C does not understand low bounds for arrays as does Fortran.
6280 Third, C assumes a low bound of zero (0), while Fortran defaults to a
6281 low bound of one (1) and can supports an arbitrary low bound.
6282 Therefore, calculations must be done
6283 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
6284 calculations require knowing the dimensions of @samp{A}.
6285
6286 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
6287 @samp{A(5,10,20)} would be:
6288
6289 @example
6290   (5-2)
6291 + (10-1)*(11-2+1)
6292 + (20-0)*(11-2+1)*(21-1+1)
6293 = 4293
6294 @end example
6295
6296 @noindent
6297 So the C equivalent in this case would be @samp{a[4293]}.
6298
6299 When using a debugger directly on Fortran code, the C equivalent
6300 might not work, because some debuggers cannot understand the notion
6301 of low bounds other than zero.  However, unlike @command{f2c}, @command{g77}
6302 does inform the GBE that a multi-dimensional array (like @samp{A}
6303 in the above example) is really multi-dimensional, rather than a
6304 single-dimensional array, so at least the dimensionality of the array
6305 is preserved.
6306
6307 Debuggers that understand Fortran should have no trouble with
6308 non-zero low bounds, but for non-Fortran debuggers, especially
6309 C debuggers, the above example might have a C equivalent of
6310 @samp{a[4305]}.
6311 This calculation is arrived at by eliminating the subtraction
6312 of the lower bound in the first parenthesized expression on each
6313 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
6314 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
6315 Actually, the implication of
6316 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
6317 but that @samp{a[20][10][5]} produces the equivalent of
6318 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
6319
6320 Come to think of it, perhaps
6321 the behavior is due to the debugger internally compensating for
6322 the lower bounds by offsetting the base address of @samp{a}, leaving
6323 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
6324 its first element as identified by subscripts equal to the
6325 corresponding lower bounds).
6326
6327 You know, maybe nobody really needs to use arrays.
6328
6329 @node Adjustable Arrays
6330 @section Adjustable Arrays (DIMENSION)
6331 @cindex arrays, adjustable
6332 @cindex adjustable arrays
6333 @cindex arrays, automatic
6334 @cindex automatic arrays
6335 @cindex DIMENSION statement
6336 @cindex statements, DIMENSION
6337 @cindex dimensioning arrays
6338 @cindex arrays, dimensioning
6339
6340 Adjustable and automatic arrays in Fortran require the implementation
6341 (in this
6342 case, the @command{g77} compiler) to ``memorize'' the expressions that
6343 dimension the arrays each time the procedure is invoked.
6344 This is so that subsequent changes to variables used in those
6345 expressions, made during execution of the procedure, do not
6346 have any effect on the dimensions of those arrays.
6347
6348 For example:
6349
6350 @example
6351 REAL ARRAY(5)
6352 DATA ARRAY/5*2/
6353 CALL X(ARRAY, 5)
6354 END
6355 SUBROUTINE X(A, N)
6356 DIMENSION A(N)
6357 N = 20
6358 PRINT *, N, A
6359 END
6360 @end example
6361
6362 @noindent
6363 Here, the implementation should, when running the program, print something
6364 like:
6365
6366 @example
6367 20   2.  2.  2.  2.  2.
6368 @end example
6369
6370 @noindent
6371 Note that this shows that while the value of @samp{N} was successfully
6372 changed, the size of the @samp{A} array remained at 5 elements.
6373
6374 To support this, @command{g77} generates code that executes before any user
6375 code (and before the internally generated computed @code{GOTO} to handle
6376 alternate entry points, as described below) that evaluates each
6377 (nonconstant) expression in the list of subscripts for an
6378 array, and saves the result of each such evaluation to be used when
6379 determining the size of the array (instead of re-evaluating the
6380 expressions).
6381
6382 So, in the above example, when @samp{X} is first invoked, code is
6383 executed that copies the value of @samp{N} to a temporary.
6384 And that same temporary serves as the actual high bound for the single
6385 dimension of the @samp{A} array (the low bound being the constant 1).
6386 Since the user program cannot (legitimately) change the value
6387 of the temporary during execution of the procedure, the size
6388 of the array remains constant during each invocation.
6389
6390 For alternate entry points, the code @command{g77} generates takes into
6391 account the possibility that a dummy adjustable array is not actually
6392 passed to the actual entry point being invoked at that time.
6393 In that case, the public procedure implementing the entry point
6394 passes to the master private procedure implementing all the
6395 code for the entry points a @code{NULL} pointer where a pointer to that
6396 adjustable array would be expected.
6397 The @command{g77}-generated code
6398 doesn't attempt to evaluate any of the expressions in the subscripts
6399 for an array if the pointer to that array is @code{NULL} at run time in
6400 such cases.
6401 (Don't depend on this particular implementation
6402 by writing code that purposely passes @code{NULL} pointers where the
6403 callee expects adjustable arrays, even if you know the callee
6404 won't reference the arrays---nor should you pass @code{NULL} pointers
6405 for any dummy arguments used in calculating the bounds of such
6406 arrays or leave undefined any values used for that purpose in
6407 COMMON---because the way @command{g77} implements these things might
6408 change in the future!)
6409
6410 @node Alternate Entry Points
6411 @section Alternate Entry Points (ENTRY)
6412 @cindex alternate entry points
6413 @cindex entry points
6414 @cindex ENTRY statement
6415 @cindex statements, ENTRY
6416
6417 The GBE does not understand the general concept of
6418 alternate entry points as Fortran provides via the ENTRY statement.
6419 @command{g77} gets around this by using an approach to compiling procedures
6420 having at least one @code{ENTRY} statement that is almost identical to the
6421 approach used by @command{f2c}.
6422 (An alternate approach could be used that
6423 would probably generate faster, but larger, code that would also
6424 be a bit easier to debug.)
6425
6426 Information on how @command{g77} implements @code{ENTRY} is provided for those
6427 trying to debug such code.
6428 The choice of implementation seems
6429 unlikely to affect code (compiled in other languages) that interfaces
6430 to such code.
6431
6432 @command{g77} compiles exactly one public procedure for the primary entry
6433 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
6434 That is, in terms of the public interface, there is no difference
6435 between
6436
6437 @example
6438 SUBROUTINE X
6439 END
6440 SUBROUTINE Y
6441 END
6442 @end example
6443
6444 @noindent
6445 and:
6446
6447 @example
6448 SUBROUTINE X
6449 ENTRY Y
6450 END
6451 @end example
6452
6453 The difference between the above two cases lies in the code compiled
6454 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
6455 for the second case, an extra internal procedure is compiled.
6456
6457 For every Fortran procedure with at least one @code{ENTRY}
6458 statement, @command{g77} compiles an extra procedure
6459 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
6460 the name of the primary entry point (which, in the above case,
6461 using the standard compiler options, would be @samp{x_} in C).
6462
6463 This extra procedure is compiled as a private procedure---that is,
6464 a procedure not accessible by name to separately compiled modules.
6465 It contains all the code in the program unit, including the code
6466 for the primary entry point plus for every entry point.
6467 (The code for each public procedure is quite short, and explained later.)
6468
6469 The extra procedure has some other interesting characteristics.
6470
6471 The argument list for this procedure is invented by @command{g77}.
6472 It contains
6473 a single integer argument named @samp{__g77_which_entrypoint},
6474 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
6475 entry point index---0 for the primary entry point, 1 for the
6476 first entry point (the first @code{ENTRY} statement encountered), 2 for
6477 the second entry point, and so on.
6478
6479 It also contains, for functions returning @code{CHARACTER} and
6480 (when @option{-ff2c} is in effect) @code{COMPLEX} functions,
6481 and for functions returning different types among the
6482 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
6483 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
6484 is expected at run time to contain a pointer to where to store
6485 the result of the entry point.
6486 For @code{CHARACTER} functions, this
6487 storage area is an array of the appropriate number of characters;
6488 for @code{COMPLEX} functions, it is the appropriate area for the return
6489 type; for multiple-return-type functions, it is a union of all the supported return
6490 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
6491 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
6492 is not supported by @command{g77}).
6493
6494 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
6495 by yet another argument named @samp{__g77_length} that, at run time,
6496 specifies the caller's expected length of the returned value.
6497 Note that only @code{CHARACTER*(*)} functions and entry points actually
6498 make use of this argument, even though it is always passed by
6499 all callers of public @code{CHARACTER} functions (since the caller does not
6500 generally know whether such a function is @code{CHARACTER*(*)} or whether
6501 there are any other callers that don't have that information).
6502
6503 The rest of the argument list is the union of all the arguments
6504 specified for all the entry points (in their usual forms, e.g.
6505 @code{CHARACTER} arguments have extra length arguments, all appended at
6506 the end of this list).
6507 This is considered the ``master list'' of
6508 arguments.
6509
6510 The code for this procedure has, before the code for the first
6511 executable statement, code much like that for the following Fortran
6512 statement:
6513
6514 @smallexample
6515        GOTO (100000,100001,100002), __g77_which_entrypoint
6516 100000 @dots{}code for primary entry point@dots{}
6517 100001 @dots{}code immediately following first ENTRY statement@dots{}
6518 100002 @dots{}code immediately following second ENTRY statement@dots{}
6519 @end smallexample
6520
6521 @noindent
6522 (Note that invalid Fortran statement labels and variable names
6523 are used in the above example to highlight the fact that it
6524 represents code generated by the @command{g77} internals, not code to be
6525 written by the user.)
6526
6527 It is this code that, when the procedure is called, picks which
6528 entry point to start executing.
6529
6530 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
6531 example), those procedures are fairly simple.
6532 Their interfaces
6533 are just like they would be if they were self-contained procedures
6534 (without @code{ENTRY}), of course, since that is what the callers
6535 expect.
6536 Their code consists of simply calling the private
6537 procedure, described above, with the appropriate extra arguments
6538 (the entry point index, and perhaps a pointer to a multiple-type-
6539 return variable, local to the public procedure, that contains
6540 all the supported returnable non-character types).
6541 For arguments
6542 that are not listed for a given entry point that are listed for
6543 other entry points, and therefore that are in the ``master list''
6544 for the private procedure, null pointers (in C, the @code{NULL} macro)
6545 are passed.
6546 Also, for entry points that are part of a multiple-type-
6547 returning function, code is compiled after the call of the private
6548 procedure to extract from the multi-type union the appropriate result,
6549 depending on the type of the entry point in question, returning
6550 that result to the original caller.
6551
6552 When debugging a procedure containing alternate entry points, you
6553 can either set a break point on the public procedure itself (e.g.
6554 a break point on @samp{X} or @samp{Y}) or on the private procedure that
6555 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
6556 If you do the former, you should use the debugger's command to
6557 ``step into'' the called procedure to get to the actual code; with
6558 the latter approach, the break point leaves you right at the
6559 actual code, skipping over the public entry point and its call
6560 to the private procedure (unless you have set a break point there
6561 as well, of course).
6562
6563 Further, the list of dummy arguments that is visible when the
6564 private procedure is active is going to be the expanded version
6565 of the list for whichever particular entry point is active,
6566 as explained above, and the way in which return values are
6567 handled might well be different from how they would be handled
6568 for an equivalent single-entry function.
6569
6570 @node Alternate Returns
6571 @section Alternate Returns (SUBROUTINE and RETURN)
6572 @cindex subroutines
6573 @cindex alternate returns
6574 @cindex SUBROUTINE statement
6575 @cindex statements, SUBROUTINE
6576 @cindex RETURN statement
6577 @cindex statements, RETURN
6578
6579 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
6580 @samp{CALL X(*50)}) are implemented by @command{g77} as functions returning
6581 the C @code{int} type.
6582 The actual alternate-return arguments are omitted from the calling sequence.
6583 Instead, the caller uses
6584 the return value to do a rough equivalent of the Fortran
6585 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
6586 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
6587 function), and the callee just returns whatever integer
6588 is specified in the @code{RETURN} statement for the subroutine
6589 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
6590 by @samp{RETURN}
6591 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
6592
6593 @node Assigned Statement Labels
6594 @section Assigned Statement Labels (ASSIGN and GOTO)
6595 @cindex assigned statement labels
6596 @cindex statement labels, assigned
6597 @cindex ASSIGN statement
6598 @cindex statements, ASSIGN
6599 @cindex GOTO statement
6600 @cindex statements, GOTO
6601
6602 For portability to machines where a pointer (such as to a label,
6603 which is how @command{g77} implements @code{ASSIGN} and its relatives,
6604 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
6605 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @command{g77}
6606 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
6607 than it does the numerical value in that variable, unless the
6608 variable is wide enough (can hold enough bits).
6609
6610 In particular, while @command{g77} implements
6611
6612 @example
6613 I = 10
6614 @end example
6615
6616 @noindent
6617 as, in C notation, @samp{i = 10;}, it implements
6618
6619 @example
6620 ASSIGN 10 TO I
6621 @end example
6622
6623 @noindent
6624 as, in GNU's extended C notation (for the label syntax),
6625 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
6626 of the Fortran label @samp{10} to make the syntax C-like; @command{g77} doesn't
6627 actually generate the name @samp{L10} or any other name like that,
6628 since debuggers cannot access labels anyway).
6629
6630 While this currently means that an @code{ASSIGN} statement does not
6631 overwrite the numeric contents of its target variable, @emph{do not}
6632 write any code depending on this feature.
6633 @command{g77} has already changed this implementation across
6634 versions and might do so in the future.
6635 This information is provided only to make debugging Fortran programs
6636 compiled with the current version of @command{g77} somewhat easier.
6637 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
6638 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
6639 means @command{g77} has decided it can store the pointer to the label directly
6640 into @samp{I} itself.
6641
6642 @xref{Ugly Assigned Labels}, for information on a command-line option
6643 to force @command{g77} to use the same storage for both normal and
6644 assigned-label uses of a variable.
6645
6646 @node Run-time Library Errors
6647 @section Run-time Library Errors
6648 @cindex IOSTAT=
6649 @cindex error values
6650 @cindex error messages
6651 @cindex messages, run-time
6652 @cindex I/O, errors
6653
6654 The @code{libg2c} library currently has the following table to relate
6655 error code numbers, returned in @code{IOSTAT=} variables, to messages.
6656 This information should, in future versions of this document, be
6657 expanded upon to include detailed descriptions of each message.
6658
6659 In line with good coding practices, any of the numbers in the
6660 list below should @emph{not} be directly written into Fortran
6661 code you write.
6662 Instead, make a separate @code{INCLUDE} file that defines
6663 @code{PARAMETER} names for them, and use those in your code,
6664 so you can more easily change the actual numbers in the future.
6665
6666 The information below is culled from the definition
6667 of @code{F_err} in @file{f/runtime/libI77/err.c} in the
6668 @command{g77} source tree.
6669
6670 @smallexample
6671 100: "error in format"
6672 101: "illegal unit number"
6673 102: "formatted io not allowed"
6674 103: "unformatted io not allowed"
6675 104: "direct io not allowed"
6676 105: "sequential io not allowed"
6677 106: "can't backspace file"
6678 107: "null file name"
6679 108: "can't stat file"
6680 109: "unit not connected"
6681 110: "off end of record"
6682 111: "truncation failed in endfile"
6683 112: "incomprehensible list input"
6684 113: "out of free space"
6685 114: "unit not connected"
6686 115: "read unexpected character"
6687 116: "bad logical input field"
6688 117: "bad variable type"
6689 118: "bad namelist name"
6690 119: "variable not in namelist"
6691 120: "no end record"
6692 121: "variable count incorrect"
6693 122: "subscript for scalar variable"
6694 123: "invalid array section"
6695 124: "substring out of bounds"
6696 125: "subscript out of bounds"
6697 126: "can't read file"
6698 127: "can't write file"
6699 128: "'new' file exists"
6700 129: "can't append to file"
6701 130: "non-positive record number"
6702 131: "I/O started while already doing I/O"
6703 @end smallexample
6704
6705 @node Collected Fortran Wisdom
6706 @chapter Collected Fortran Wisdom
6707 @cindex wisdom
6708 @cindex legacy code
6709 @cindex code, legacy
6710 @cindex writing code
6711 @cindex code, writing
6712
6713 Most users of @command{g77} can be divided into two camps:
6714
6715 @itemize @bullet
6716 @item
6717 Those writing new Fortran code to be compiled by @command{g77}.
6718
6719 @item
6720 Those using @command{g77} to compile existing, ``legacy'' code.
6721 @end itemize
6722
6723 Users writing new code generally understand most of the necessary
6724 aspects of Fortran to write ``mainstream'' code, but often need
6725 help deciding how to handle problems, such as the construction
6726 of libraries containing @code{BLOCK DATA}.
6727
6728 Users dealing with ``legacy'' code sometimes don't have much
6729 experience with Fortran, but believe that the code they're compiling
6730 already works when compiled by other compilers (and might
6731 not understand why, as is sometimes the case, it doesn't work
6732 when compiled by @command{g77}).
6733
6734 The following information is designed to help users do a better job
6735 coping with existing, ``legacy'' Fortran code, and with writing
6736 new code as well.
6737
6738 @menu
6739 * Advantages Over f2c::        If @command{f2c} is so great, why @command{g77}?
6740 * Block Data and Libraries::   How @command{g77} solves a common problem.
6741 * Loops::                      Fortran @code{DO} loops surprise many people.
6742 * Working Programs::           Getting programs to work should be done first.
6743 * Overly Convenient Options::  Temptations to avoid, habits to not form.
6744 * Faster Programs::            Everybody wants these, but at what cost?
6745 @end menu
6746
6747 @node Advantages Over f2c
6748 @section Advantages Over f2c
6749
6750 Without @command{f2c}, @command{g77} would have taken much longer to
6751 do and probably not been as good for quite a while.
6752 Sometimes people who notice how much @command{g77} depends on, and
6753 documents encouragement to use, @command{f2c} ask why @command{g77}
6754 was created if @command{f2c} already existed.
6755
6756 This section gives some basic answers to these questions, though it
6757 is not intended to be comprehensive.
6758
6759 @menu
6760 * Language Extensions::  Features used by Fortran code.
6761 * Diagnostic Abilities:: Abilities to spot problems early.
6762 * Compiler Options::     Features helpful to accommodate legacy code, etc.
6763 * Compiler Speed::       Speed of the compilation process.
6764 * Program Speed::        Speed of the generated, optimized code.
6765 * Ease of Debugging::    Debugging ease-of-use at the source level.
6766 * Character and Hollerith Constants::  A byte saved is a byte earned.
6767 @end menu
6768
6769 @node Language Extensions
6770 @subsection Language Extensions
6771
6772 @command{g77} offers several extensions to FORTRAN 77 language that @command{f2c}
6773 doesn't:
6774
6775 @itemize @bullet
6776 @item
6777 Automatic arrays
6778
6779 @item
6780 @code{CYCLE} and @code{EXIT}
6781
6782 @item
6783 Construct names
6784
6785 @item
6786 @code{SELECT CASE}
6787
6788 @item
6789 @code{KIND=} and @code{LEN=} notation
6790
6791 @item
6792 Semicolon as statement separator
6793
6794 @item
6795 Constant expressions in @code{FORMAT} statements
6796 (such as @samp{FORMAT(I<J>)},
6797 where @samp{J} is a @code{PARAMETER} named constant)
6798
6799 @item
6800 @code{MvBits} intrinsic
6801
6802 @item
6803 @code{libU77} (Unix-compatibility) library,
6804 with routines known to compiler as intrinsics
6805 (so they work even when compiler options are used
6806 to change the interfaces used by Fortran routines)
6807 @end itemize
6808
6809 @command{g77} also implements iterative @code{DO} loops
6810 so that they work even in the presence of certain ``extreme'' inputs,
6811 unlike @command{f2c}.
6812 @xref{Loops}.
6813
6814 However, @command{f2c} offers a few that @command{g77} doesn't, such as:
6815
6816 @itemize @bullet
6817 @item
6818 Intrinsics in @code{PARAMETER} statements
6819
6820 @item
6821 Array bounds expressions (such as @samp{REAL M(N(2))})
6822
6823 @item
6824 @code{AUTOMATIC} statement
6825 @end itemize
6826
6827 It is expected that @command{g77} will offer some or all of these missing
6828 features at some time in the future.
6829
6830 @node Diagnostic Abilities
6831 @subsection Diagnostic Abilities
6832
6833 @command{g77} offers better diagnosis of problems in @code{FORMAT} statements.
6834 @command{f2c} doesn't, for example, emit any diagnostic for
6835 @samp{FORMAT(XZFAJG10324)},
6836 leaving that to be diagnosed, at run time, by
6837 the @code{libf2c} run-time library.
6838
6839 @node Compiler Options
6840 @subsection Compiler Options
6841
6842 @command{g77} offers compiler options that @command{f2c} doesn't,
6843 most of which are designed to more easily accommodate
6844 legacy code:
6845
6846 @itemize @bullet
6847 @item
6848 Two that control the automatic appending of extra
6849 underscores to external names
6850
6851 @item
6852 One that allows dollar signs (@samp{$}) in symbol names
6853
6854 @item
6855 A variety that control acceptance of various
6856 ``ugly'' constructs
6857
6858 @item
6859 Several that specify acceptable use of upper and lower case
6860 in the source code
6861
6862 @item
6863 Many that enable, disable, delete, or hide
6864 groups of intrinsics
6865
6866 @item
6867 One to specify the length of fixed-form source lines
6868 (normally 72)
6869
6870 @item
6871 One to specify the the source code is written in
6872 Fortran-90-style free-form
6873 @end itemize
6874
6875 However, @command{f2c} offers a few that @command{g77} doesn't,
6876 like an option to have @code{REAL} default to @code{REAL*8}.
6877 It is expected that @command{g77} will offer all of the
6878 missing options pertinent to being a Fortran compiler
6879 at some time in the future.
6880
6881 @node Compiler Speed
6882 @subsection Compiler Speed
6883
6884 Saving the steps of writing and then rereading C code is a big reason
6885 why @command{g77} should be able to compile code much faster than using
6886 @command{f2c} in conjunction with the equivalent invocation of @command{gcc}.
6887
6888 However, due to @command{g77}'s youth, lots of self-checking is still being
6889 performed.
6890 As a result, this improvement is as yet unrealized
6891 (though the potential seems to be there for quite a big speedup
6892 in the future).
6893 It is possible that, as of version 0.5.18, @command{g77}
6894 is noticeably faster compiling many Fortran source files than using
6895 @command{f2c} in conjunction with @command{gcc}.
6896
6897 @node Program Speed
6898 @subsection Program Speed
6899
6900 @command{g77} has the potential to better optimize code than @command{f2c},
6901 even when @command{gcc} is used to compile the output of @command{f2c},
6902 because @command{f2c} must necessarily
6903 translate Fortran into a somewhat lower-level language (C) that cannot
6904 preserve all the information that is potentially useful for optimization,
6905 while @command{g77} can gather, preserve, and transmit that information directly
6906 to the GBE.
6907
6908 For example, @command{g77} implements @code{ASSIGN} and assigned
6909 @code{GOTO} using direct assignment of pointers to labels and direct
6910 jumps to labels, whereas @command{f2c} maps the assigned labels to
6911 integer values and then uses a C @code{switch} statement to encode
6912 the assigned @code{GOTO} statements.
6913
6914 However, as is typical, theory and reality don't quite match, at least
6915 not in all cases, so it is still the case that @command{f2c} plus @command{gcc}
6916 can generate code that is faster than @command{g77}.
6917
6918 Version 0.5.18 of @command{g77} offered default
6919 settings and options, via patches to the @command{gcc}
6920 back end, that allow for better program speed, though
6921 some of these improvements also affected the performance
6922 of programs translated by @command{f2c} and then compiled
6923 by @command{g77}'s version of @command{gcc}.
6924
6925 Version 0.5.20 of @command{g77} offers further performance
6926 improvements, at least one of which (alias analysis) is
6927 not generally applicable to @command{f2c} (though @command{f2c}
6928 could presumably be changed to also take advantage of
6929 this new capability of the @command{gcc} back end, assuming
6930 this is made available in an upcoming release of @command{gcc}).
6931
6932 @node Ease of Debugging
6933 @subsection Ease of Debugging
6934
6935 Because @command{g77} compiles directly to assembler code like @command{gcc},
6936 instead of translating to an intermediate language (C) as does @command{f2c},
6937 support for debugging can be better for @command{g77} than @command{f2c}.
6938
6939 However, although @command{g77} might be somewhat more ``native'' in terms of
6940 debugging support than @command{f2c} plus @command{gcc}, there still are a lot
6941 of things ``not quite right''.
6942 Many of the important ones should be resolved in the near future.
6943
6944 For example, @command{g77} doesn't have to worry about reserved names
6945 like @command{f2c} does.
6946 Given @samp{FOR = WHILE}, @command{f2c} must necessarily
6947 translate this to something @emph{other} than
6948 @samp{for = while;}, because C reserves those words.
6949
6950 However, @command{g77} does still uses things like an extra level of indirection
6951 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
6952 yet support multiple entry points.
6953
6954 Another example is that, given
6955
6956 @smallexample
6957 COMMON A, B
6958 EQUIVALENCE (B, C)
6959 @end smallexample
6960
6961 @noindent
6962 the @command{g77} user should be able to access the variables directly, by name,
6963 without having to traverse C-like structures and unions, while @command{f2c}
6964 is unlikely to ever offer this ability (due to limitations in the
6965 C language).
6966
6967 However, due to apparent bugs in the back end, @command{g77} currently doesn't
6968 take advantage of this facility at all---it doesn't emit any debugging
6969 information for @code{COMMON} and @code{EQUIVALENCE} areas,
6970 other than information
6971 on the array of @code{char} it creates (and, in the case
6972 of local @code{EQUIVALENCE}, names) for each such area.
6973
6974 Yet another example is arrays.
6975 @command{g77} represents them to the debugger
6976 using the same ``dimensionality'' as in the source code, while @command{f2c}
6977 must necessarily convert them all to one-dimensional arrays to fit
6978 into the confines of the C language.
6979 However, the level of support
6980 offered by debuggers for interactive Fortran-style access to arrays
6981 as compiled by @command{g77} can vary widely.
6982 In some cases, it can actually
6983 be an advantage that @command{f2c} converts everything to widely supported
6984 C semantics.
6985
6986 In fairness, @command{g77} could do many of the things @command{f2c} does
6987 to get things working at least as well as @command{f2c}---for now,
6988 the developers prefer making @command{g77} work the
6989 way they think it is supposed to, and finding help improving the
6990 other products (the back end of @command{gcc}; @command{gdb}; and so on)
6991 to get things working properly.
6992
6993 @node Character and Hollerith Constants
6994 @subsection Character and Hollerith Constants
6995 @cindex character constants
6996 @cindex constants, character
6997 @cindex Hollerith constants
6998 @cindex constants, Hollerith
6999 @cindex trailing null byte
7000 @cindex null byte, trailing
7001 @cindex zero byte, trailing
7002
7003 To avoid the extensive hassle that would be needed to avoid this,
7004 @command{f2c} uses C character constants to encode character and Hollerith
7005 constants.
7006 That means a constant like @samp{'HELLO'} is translated to
7007 @samp{"hello"} in C, which further means that an extra null byte is
7008 present at the end of the constant.
7009 This null byte is superfluous.
7010
7011 @command{g77} does not generate such null bytes.
7012 This represents significant
7013 savings of resources, such as on systems where @file{/dev/null} or
7014 @file{/dev/zero} represent bottlenecks in the systems' performance,
7015 because @command{g77} simply asks for fewer zeros from the operating
7016 system than @command{f2c}.
7017 (Avoiding spurious use of zero bytes, each byte typically have
7018 eight zero bits, also reduces the liabilities in case
7019 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
7020
7021 @node Block Data and Libraries
7022 @section Block Data and Libraries
7023 @cindex block data and libraries
7024 @cindex BLOCK DATA statement
7025 @cindex statements, BLOCK DATA
7026 @cindex libraries, containing BLOCK DATA
7027 @cindex f2c compatibility
7028 @cindex compatibility, f2c
7029
7030 To ensure that block data program units are linked, especially a concern
7031 when they are put into libraries, give each one a name (as in
7032 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
7033 statement in every program unit that uses any common block
7034 initialized by the corresponding @code{BLOCK DATA}.
7035 @command{g77} currently compiles a @code{BLOCK DATA} as if it were a
7036 @code{SUBROUTINE},
7037 that is, it generates an actual procedure having the appropriate name.
7038 The procedure does nothing but return immediately if it happens to be
7039 called.
7040 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
7041 same program unit, @command{g77} assumes there exists a @samp{BLOCK DATA FOO}
7042 in the program and ensures that by generating a
7043 reference to it so the linker will make sure it is present.
7044 (Specifically, @command{g77} outputs in the data section a static pointer to the
7045 external name @samp{FOO}.)
7046
7047 The implementation @command{g77} currently uses to make this work is
7048 one of the few things not compatible with @command{f2c} as currently
7049 shipped.
7050 @command{f2c} currently does nothing with @samp{EXTERNAL FOO} except
7051 issue a warning that @samp{FOO} is not otherwise referenced,
7052 and, for @samp{BLOCK DATA FOO},
7053 @command{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
7054 The upshot is that you shouldn't mix @command{f2c} and @command{g77} in
7055 this particular case.
7056 If you use @command{f2c} to compile @samp{BLOCK DATA FOO},
7057 then any @command{g77}-compiled program unit that says @samp{EXTERNAL FOO}
7058 will result in an unresolved reference when linked.
7059 If you do the
7060 opposite, then @samp{FOO} might not be linked in under various
7061 circumstances (such as when @samp{FOO} is in a library, or you're
7062 using a ``clever'' linker---so clever, it produces a broken program
7063 with little or no warning by omitting initializations of global data
7064 because they are contained in unreferenced procedures).
7065
7066 The changes you make to your code to make @command{g77} handle this situation,
7067 however, appear to be a widely portable way to handle it.
7068 That is, many systems permit it (as they should, since the
7069 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
7070 is a block data program unit), and of the ones
7071 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
7072 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
7073 program units.
7074
7075 Here is the recommended approach to modifying a program containing
7076 a program unit such as the following:
7077
7078 @smallexample
7079 BLOCK DATA FOO
7080 COMMON /VARS/ X, Y, Z
7081 DATA X, Y, Z / 3., 4., 5. /
7082 END
7083 @end smallexample
7084
7085 @noindent
7086 If the above program unit might be placed in a library module, then
7087 ensure that every program unit in every program that references that
7088 particular @code{COMMON} area uses the @code{EXTERNAL} statement
7089 to force the area to be initialized.
7090
7091 For example, change a program unit that starts with
7092
7093 @smallexample
7094 INTEGER FUNCTION CURX()
7095 COMMON /VARS/ X, Y, Z
7096 CURX = X
7097 END
7098 @end smallexample
7099
7100 @noindent
7101 so that it uses the @code{EXTERNAL} statement, as in:
7102
7103 @smallexample
7104 INTEGER FUNCTION CURX()
7105 COMMON /VARS/ X, Y, Z
7106 EXTERNAL FOO
7107 CURX = X
7108 END
7109 @end smallexample
7110
7111 @noindent
7112 That way, @samp{CURX} is compiled by @command{g77} (and many other
7113 compilers) so that the linker knows it must include @samp{FOO},
7114 the @code{BLOCK DATA} program unit that sets the initial values
7115 for the variables in @samp{VAR}, in the executable program.
7116
7117 @node Loops
7118 @section Loops
7119 @cindex DO statement
7120 @cindex statements, DO
7121 @cindex trips, number of
7122 @cindex number of trips
7123
7124 The meaning of a @code{DO} loop in Fortran is precisely specified
7125 in the Fortran standard@dots{}and is quite different from what
7126 many programmers might expect.
7127
7128 In particular, Fortran iterative @code{DO} loops are implemented as if
7129 the number of trips through the loop is calculated @emph{before}
7130 the loop is entered.
7131
7132 The number of trips for a loop is calculated from the @var{start},
7133 @var{end}, and @var{increment} values specified in a statement such as:
7134
7135 @smallexample
7136 DO @var{iter} = @var{start}, @var{end}, @var{increment}
7137 @end smallexample
7138
7139 @noindent
7140 The trip count is evaluated using a fairly simple formula
7141 based on the three values following the @samp{=} in the
7142 statement, and it is that trip count that is effectively
7143 decremented during each iteration of the loop.
7144 If, at the beginning of an iteration of the loop, the
7145 trip count is zero or negative, the loop terminates.
7146 The per-loop-iteration modifications to @var{iter} are not
7147 related to determining whether to terminate the loop.
7148
7149 There are two important things to remember about the trip
7150 count:
7151
7152 @itemize @bullet
7153 @item
7154 It can be @emph{negative}, in which case it is
7155 treated as if it was zero---meaning the loop is
7156 not executed at all.
7157
7158 @item
7159 The type used to @emph{calculate} the trip count
7160 is the same type as @var{iter}, but the final
7161 calculation, and thus the type of the trip
7162 count itself, always is @code{INTEGER(KIND=1)}.
7163 @end itemize
7164
7165 These two items mean that there are loops that cannot
7166 be written in straightforward fashion using the Fortran @code{DO}.
7167
7168 For example, on a system with the canonical 32-bit two's-complement
7169 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
7170
7171 @smallexample
7172 DO I = -2000000000, 2000000000
7173 @end smallexample
7174
7175 @noindent
7176 Although the @var{start} and @var{end} values are well within
7177 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
7178 The expected trip count is 40000000001, which is outside
7179 the range of @code{INTEGER(KIND=1)} on many systems.
7180
7181 Instead, the above loop should be constructed this way:
7182
7183 @smallexample
7184 I = -2000000000
7185 DO
7186   IF (I .GT. 2000000000) EXIT
7187   @dots{}
7188   I = I + 1
7189 END DO
7190 @end smallexample
7191
7192 @noindent
7193 The simple @code{DO} construct and the @code{EXIT} statement
7194 (used to leave the innermost loop)
7195 are F90 features that @command{g77} supports.
7196
7197 Some Fortran compilers have buggy implementations of @code{DO},
7198 in that they don't follow the standard.
7199 They implement @code{DO} as a straightforward translation
7200 to what, in C, would be a @code{for} statement.
7201 Instead of creating a temporary variable to hold the trip count
7202 as calculated at run time, these compilers
7203 use the iteration variable @var{iter} to control
7204 whether the loop continues at each iteration.
7205
7206 The bug in such an implementation shows up when the
7207 trip count is within the range of the type of @var{iter},
7208 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
7209 exceeds that range.  For example:
7210
7211 @smallexample
7212 DO I = 2147483600, 2147483647
7213 @end smallexample
7214
7215 @noindent
7216 A loop started by the above statement will work as implemented
7217 by @command{g77}, but the use, by some compilers, of a
7218 more C-like implementation akin to
7219
7220 @smallexample
7221 for (i = 2147483600; i <= 2147483647; ++i)
7222 @end smallexample
7223
7224 @noindent
7225 produces a loop that does not terminate, because @samp{i}
7226 can never be greater than 2147483647, since incrementing it
7227 beyond that value overflows @samp{i}, setting it to -2147483648.
7228 This is a large, negative number that still is less than 2147483647.
7229
7230 Another example of unexpected behavior of @code{DO} involves
7231 using a nonintegral iteration variable @var{iter}, that is,
7232 a @code{REAL} variable.
7233 Consider the following program:
7234
7235 @smallexample
7236       DATA BEGIN, END, STEP /.1, .31, .007/
7237       DO 10 R = BEGIN, END, STEP
7238          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
7239          PRINT *,R
7240 10    CONTINUE
7241       PRINT *,'LAST = ',R
7242       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
7243       END
7244 @end smallexample
7245
7246 @noindent
7247 A C-like view of @code{DO} would hold that the two ``exclamatory''
7248 @code{PRINT} statements are never executed.
7249 However, this is the output of running the above program
7250 as compiled by @command{g77} on a GNU/Linux ix86 system:
7251
7252 @smallexample
7253  .100000001
7254  .107000001
7255  .114
7256  .120999999
7257  @dots{}
7258  .289000005
7259  .296000004
7260  .303000003
7261 LAST =   .310000002
7262  .310000002 .LE.   .310000002!!
7263 @end smallexample
7264
7265 Note that one of the two checks in the program turned up
7266 an apparent violation of the programmer's expectation---yet,
7267 the loop is correctly implemented by @command{g77}, in that
7268 it has 30 iterations.
7269 This trip count of 30 is correct when evaluated using
7270 the floating-point representations for the @var{begin},
7271 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
7272 ix86 are used.
7273 On other systems, an apparently more accurate trip count
7274 of 31 might result, but, nevertheless, @command{g77} is
7275 faithfully following the Fortran standard, and the result
7276 is not what the author of the sample program above
7277 apparently expected.
7278 (Such other systems might, for different values in the @code{DATA}
7279 statement, violate the other programmer's expectation,
7280 for example.)
7281
7282 Due to this combination of imprecise representation
7283 of floating-point values and the often-misunderstood
7284 interpretation of @code{DO} by standard-conforming
7285 compilers such as @command{g77}, use of @code{DO} loops
7286 with @code{REAL} iteration
7287 variables is not recommended.
7288 Such use can be caught by specifying @option{-Wsurprising}.
7289 @xref{Warning Options}, for more information on this
7290 option.
7291
7292 @node Working Programs
7293 @section Working Programs
7294
7295 Getting Fortran programs to work in the first place can be
7296 quite a challenge---even when the programs already work on
7297 other systems, or when using other compilers.
7298
7299 @command{g77} offers some facilities that might be useful for
7300 tracking down bugs in such programs.
7301
7302 @menu
7303 * Not My Type::
7304 * Variables Assumed To Be Zero::
7305 * Variables Assumed To Be Saved::
7306 * Unwanted Variables::
7307 * Unused Arguments::
7308 * Surprising Interpretations of Code::
7309 * Aliasing Assumed To Work::
7310 * Output Assumed To Flush::
7311 * Large File Unit Numbers::
7312 * Floating-point precision::
7313 * Inconsistent Calling Sequences::
7314 @end menu
7315
7316 @node Not My Type
7317 @subsection Not My Type
7318 @cindex mistyped variables
7319 @cindex variables, mistyped
7320 @cindex mistyped functions
7321 @cindex functions, mistyped
7322 @cindex implicit typing
7323
7324 A fruitful source of bugs in Fortran source code is use, or
7325 mis-use, of Fortran's implicit-typing feature, whereby the
7326 type of a variable, array, or function is determined by the
7327 first character of its name.
7328
7329 Simple cases of this include statements like @samp{LOGX=9.227},
7330 without a statement such as @samp{REAL LOGX}.
7331 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
7332 type, with the result of the assignment being that it is given
7333 the value @samp{9}.
7334
7335 More involved cases include a function that is defined starting
7336 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
7337 Any caller of this function that does not also declare @samp{IPS}
7338 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
7339 is likely to assume it returns
7340 @code{INTEGER}, or some other type, leading to invalid results
7341 or even program crashes.
7342
7343 The @option{-Wimplicit} option might catch failures to
7344 properly specify the types of
7345 variables, arrays, and functions in the code.
7346
7347 However, in code that makes heavy use of Fortran's
7348 implicit-typing facility, this option might produce so
7349 many warnings about cases that are working, it would be
7350 hard to find the one or two that represent bugs.
7351 This is why so many experienced Fortran programmers strongly
7352 recommend widespread use of the @code{IMPLICIT NONE} statement,
7353 despite it not being standard FORTRAN 77, to completely turn
7354 off implicit typing.
7355 (@command{g77} supports @code{IMPLICIT NONE}, as do almost all
7356 FORTRAN 77 compilers.)
7357
7358 Note that @option{-Wimplicit} catches only implicit typing of
7359 @emph{names}.
7360 It does not catch implicit typing of expressions such
7361 as @samp{X**(2/3)}.
7362 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
7363 is equivalent to @samp{X**0}, due to the way Fortran expressions
7364 are given types and then evaluated.
7365 (In this particular case, the programmer probably wanted
7366 @samp{X**(2./3.)}.)
7367
7368 @node Variables Assumed To Be Zero
7369 @subsection Variables Assumed To Be Zero
7370 @cindex zero-initialized variables
7371 @cindex variables, assumed to be zero
7372 @cindex uninitialized variables
7373
7374 Many Fortran programs were developed on systems that provided
7375 automatic initialization of all, or some, variables and arrays
7376 to zero.
7377 As a result, many of these programs depend, sometimes
7378 inadvertently, on this behavior, though to do so violates
7379 the Fortran standards.
7380
7381 You can ask @command{g77} for this behavior by specifying the
7382 @option{-finit-local-zero} option when compiling Fortran code.
7383 (You might want to specify @option{-fno-automatic} as well,
7384 to avoid code-size inflation for non-optimized compilations.)
7385
7386 Note that a program that works better when compiled with the
7387 @option{-finit-local-zero} option
7388 is almost certainly depending on a particular system's,
7389 or compiler's, tendency to initialize some variables to zero.
7390 It might be worthwhile finding such cases and fixing them,
7391 using techniques such as compiling with the @option{-O -Wuninitialized}
7392 options using @command{g77}.
7393
7394 @node Variables Assumed To Be Saved
7395 @subsection Variables Assumed To Be Saved
7396 @cindex variables, retaining values across calls
7397 @cindex saved variables
7398 @cindex static variables
7399
7400 Many Fortran programs were developed on systems that
7401 saved the values of all, or some, variables and arrays
7402 across procedure calls.
7403 As a result, many of these programs depend, sometimes
7404 inadvertently, on being able to assign a value to a
7405 variable, perform a @code{RETURN} to a calling procedure,
7406 and, upon subsequent invocation, reference the previously
7407 assigned variable to obtain the value.
7408
7409 They expect this despite not using the @code{SAVE} statement
7410 to specify that the value in a variable is expected to survive
7411 procedure returns and calls.
7412 Depending on variables and arrays to retain values across
7413 procedure calls without using @code{SAVE} to require it violates
7414 the Fortran standards.
7415
7416 You can ask @command{g77} to assume @code{SAVE} is specified for all
7417 relevant (local) variables and arrays by using the
7418 @option{-fno-automatic} option.
7419
7420 Note that a program that works better when compiled with the
7421 @option{-fno-automatic} option
7422 is almost certainly depending on not having to use
7423 the @code{SAVE} statement as required by the Fortran standard.
7424 It might be worthwhile finding such cases and fixing them,
7425 using techniques such as compiling with the @samp{-O -Wuninitialized}
7426 options using @command{g77}.
7427
7428 @node Unwanted Variables
7429 @subsection Unwanted Variables
7430
7431 The @option{-Wunused} option can find bugs involving
7432 implicit typing, sometimes
7433 more easily than using @option{-Wimplicit} in code that makes
7434 heavy use of implicit typing.
7435 An unused variable or array might indicate that the
7436 spelling for its declaration is different from that of
7437 its intended uses.
7438
7439 Other than cases involving typos, unused variables rarely
7440 indicate actual bugs in a program.
7441 However, investigating such cases thoroughly has, on occasion,
7442 led to the discovery of code that had not been completely
7443 written---where the programmer wrote declarations as needed
7444 for the whole algorithm, wrote some or even most of the code
7445 for that algorithm, then got distracted and forgot that the
7446 job was not complete.
7447
7448 @node Unused Arguments
7449 @subsection Unused Arguments
7450 @cindex unused arguments
7451 @cindex arguments, unused
7452
7453 As with unused variables, It is possible that unused arguments
7454 to a procedure might indicate a bug.
7455 Compile with @samp{-W -Wunused} option to catch cases of
7456 unused arguments.
7457
7458 Note that @option{-W} also enables warnings regarding overflow
7459 of floating-point constants under certain circumstances.
7460
7461 @node Surprising Interpretations of Code
7462 @subsection Surprising Interpretations of Code
7463
7464 The @option{-Wsurprising} option can help find bugs involving
7465 expression evaluation or in
7466 the way @code{DO} loops with non-integral iteration variables
7467 are handled.
7468 Cases found by this option might indicate a difference of
7469 interpretation between the author of the code involved, and
7470 a standard-conforming compiler such as @command{g77}.
7471 Such a difference might produce actual bugs.
7472
7473 In any case, changing the code to explicitly do what the
7474 programmer might have expected it to do, so @command{g77} and
7475 other compilers are more likely to follow the programmer's
7476 expectations, might be worthwhile, especially if such changes
7477 make the program work better.
7478
7479 @node Aliasing Assumed To Work
7480 @subsection Aliasing Assumed To Work
7481 @cindex -falias-check option
7482 @cindex options, -falias-check
7483 @cindex -fargument-alias option
7484 @cindex options, -fargument-alias
7485 @cindex -fargument-noalias option
7486 @cindex options, -fargument-noalias
7487 @cindex -fno-argument-noalias-global option
7488 @cindex options, -fno-argument-noalias-global
7489 @cindex aliasing
7490 @cindex anti-aliasing
7491 @cindex overlapping arguments
7492 @cindex overlays
7493 @cindex association, storage
7494 @cindex storage association
7495 @cindex scheduling of reads and writes
7496 @cindex reads and writes, scheduling
7497
7498 The @option{-falias-check}, @option{-fargument-alias},
7499 @option{-fargument-noalias},
7500 and @option{-fno-argument-noalias-global} options,
7501 introduced in version 0.5.20 and
7502 @command{g77}'s version 2.7.2.2.f.2 of @command{gcc},
7503 were withdrawn as of @command{g77} version 0.5.23
7504 due to their not being supported by @command{gcc} version 2.8.
7505
7506 These options control the assumptions regarding aliasing
7507 (overlapping) of writes and reads to main memory (core) made
7508 by the @command{gcc} back end.
7509
7510 The information below still is useful, but applies to
7511 only those versions of @command{g77} that support the
7512 alias analysis implied by support for these options.
7513
7514 These options are effective only when compiling with @option{-O}
7515 (specifying any level other than @option{-O0})
7516 or with @option{-falias-check}.
7517
7518 The default for Fortran code is @option{-fargument-noalias-global}.
7519 (The default for C code and code written in other C-based languages
7520 is @option{-fargument-alias}.
7521 These defaults apply regardless of whether you use @command{g77} or
7522 @command{gcc} to compile your code.)
7523
7524 Note that, on some systems, compiling with @option{-fforce-addr} in
7525 effect can produce more optimal code when the default aliasing
7526 options are in effect (and when optimization is enabled).
7527
7528 If your program is not working when compiled with optimization,
7529 it is possible it is violating the Fortran standards (77 and 90)
7530 by relying on the ability to ``safely'' modify variables and
7531 arrays that are aliased, via procedure calls, to other variables
7532 and arrays, without using @code{EQUIVALENCE} to explicitly
7533 set up this kind of aliasing.
7534
7535 (The FORTRAN 77 standard's prohibition of this sort of
7536 overlap, generally referred to therein as ``storage
7537 assocation'', appears in Sections 15.9.3.6.
7538 This prohibition allows implementations, such as @command{g77},
7539 to, for example, implement the passing of procedures and
7540 even values in @code{COMMON} via copy operations into local,
7541 perhaps more efficiently accessed temporaries at entry to a
7542 procedure, and, where appropriate, via copy operations back
7543 out to their original locations in memory at exit from that
7544 procedure, without having to take into consideration the
7545 order in which the local copies are updated by the code,
7546 among other things.)
7547
7548 To test this hypothesis, try compiling your program with
7549 the @option{-fargument-alias} option, which causes the
7550 compiler to revert to assumptions essentially the same as
7551 made by versions of @command{g77} prior to 0.5.20.
7552
7553 If the program works using this option, that strongly suggests
7554 that the bug is in your program.
7555 Finding and fixing the bug(s) should result in a program that
7556 is more standard-conforming and that can be compiled by @command{g77}
7557 in a way that results in a faster executable.
7558
7559 (You might want to try compiling with @option{-fargument-noalias},
7560 a kind of half-way point, to see if the problem is limited to
7561 aliasing between dummy arguments and @code{COMMON} variables---this
7562 option assumes that such aliasing is not done, while still allowing
7563 aliasing among dummy arguments.)
7564
7565 An example of aliasing that is invalid according to the standards
7566 is shown in the following program, which might @emph{not} produce
7567 the expected results when executed:
7568
7569 @smallexample
7570 I = 1
7571 CALL FOO(I, I)
7572 PRINT *, I
7573 END
7574
7575 SUBROUTINE FOO(J, K)
7576 J = J + K
7577 K = J * K
7578 PRINT *, J, K
7579 END
7580 @end smallexample
7581
7582 The above program attempts to use the temporary aliasing of the
7583 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
7584 pathological behavior---the simultaneous changing of the values
7585 of @emph{both} @samp{J} and @samp{K} when either one of them
7586 is written.
7587
7588 The programmer likely expects the program to print these values:
7589
7590 @example
7591 2  4
7592 4
7593 @end example
7594
7595 However, since the program is not standard-conforming, an
7596 implementation's behavior when running it is undefined, because
7597 subroutine @samp{FOO} modifies at least one of the arguments,
7598 and they are aliased with each other.
7599 (Even if one of the assignment statements was deleted, the
7600 program would still violate these rules.
7601 This kind of on-the-fly aliasing is permitted by the standard
7602 only when none of the aliased items are defined, or written,
7603 while the aliasing is in effect.)
7604
7605 As a practical example, an optimizing compiler might schedule
7606 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
7607 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
7608 resulting in the following output:
7609
7610 @example
7611 2  2
7612 2
7613 @end example
7614
7615 Essentially, compilers are promised (by the standard and, therefore,
7616 by programmers who write code they claim to be standard-conforming)
7617 that if they cannot detect aliasing via static analysis of a single
7618 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
7619 such aliasing exists.
7620 In such cases, compilers are free to assume that an assignment to
7621 one variable will not change the value of another variable, allowing
7622 it to avoid generating code to re-read the value of the other
7623 variable, to re-schedule reads and writes, and so on, to produce
7624 a faster executable.
7625
7626 The same promise holds true for arrays (as seen by the called
7627 procedure)---an element of one dummy array cannot be aliased
7628 with, or overlap, any element of another dummy array or be
7629 in a @code{COMMON} area known to the procedure.
7630
7631 (These restrictions apply only when the procedure defines, or
7632 writes to, one of the aliased variables or arrays.)
7633
7634 Unfortunately, there is no way to find @emph{all} possible cases of
7635 violations of the prohibitions against aliasing in Fortran code.
7636 Static analysis is certainly imperfect, as is run-time analysis,
7637 since neither can catch all violations.
7638 (Static analysis can catch all likely violations, and some that
7639 might never actually happen, while run-time analysis can catch
7640 only those violations that actually happen during a particular run.
7641 Neither approach can cope with programs mixing Fortran code with
7642 routines written in other languages, however.)
7643
7644 Currently, @command{g77} provides neither static nor run-time facilities
7645 to detect any cases of this problem, although other products might.
7646 Run-time facilities are more likely to be offered by future
7647 versions of @command{g77}, though patches improving @command{g77} so that
7648 it provides either form of detection are welcome.
7649
7650 @node Output Assumed To Flush
7651 @subsection Output Assumed To Flush
7652 @cindex ALWAYS_FLUSH
7653 @cindex synchronous write errors
7654 @cindex disk full
7655 @cindex flushing output
7656 @cindex fflush()
7657 @cindex I/O, flushing
7658 @cindex output, flushing
7659 @cindex writes, flushing
7660 @cindex NFS
7661 @cindex network file system
7662
7663 For several versions prior to 0.5.20, @command{g77} configured its
7664 version of the @code{libf2c} run-time library so that one of
7665 its configuration macros, @code{ALWAYS_FLUSH}, was defined.
7666
7667 This was done as a result of a belief that many programs expected
7668 output to be flushed to the operating system (under UNIX, via
7669 the @code{fflush()} library call) with the result that errors,
7670 such as disk full, would be immediately flagged via the
7671 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
7672
7673 Because of the adverse effects this approach had on the performance
7674 of many programs, @command{g77} no longer configures @code{libf2c}
7675 (now named @code{libg2c} in its @command{g77} incarnation)
7676 to always flush output.
7677
7678 If your program depends on this behavior, either insert the
7679 appropriate @samp{CALL FLUSH} statements, or modify the sources
7680 to the @code{libg2c}, rebuild and reinstall @command{g77}, and
7681 relink your programs with the modified library.
7682
7683 (Ideally, @code{libg2c} would offer the choice at run-time, so
7684 that a compile-time option to @command{g77} or @command{f2c} could
7685 result in generating the appropriate calls to flushing or
7686 non-flushing library routines.)
7687
7688 Some Fortran programs require output
7689 (writes) to be flushed to the operating system (under UNIX,
7690 via the @code{fflush()} library call) so that errors,
7691 such as disk full, are immediately flagged via the relevant
7692 @code{ERR=} and @code{IOSTAT=} mechanism, instead of such
7693 errors being flagged later as subsequent writes occur, forcing
7694 the previously written data to disk, or when the file is
7695 closed.
7696
7697 Essentially, the difference can be viewed as synchronous error
7698 reporting (immediate flagging of errors during writes) versus
7699 asynchronous, or, more precisely, buffered error reporting
7700 (detection of errors might be delayed).
7701
7702 @code{libg2c} supports flagging write errors immediately when
7703 it is built with the @code{ALWAYS_FLUSH} macro defined.
7704 This results in a @code{libg2c} that runs slower, sometimes
7705 quite a bit slower, under certain circumstances---for example,
7706 accessing files via the networked file system NFS---but the
7707 effect can be more reliable, robust file I/O.
7708
7709 If you know that Fortran programs requiring this level of precision
7710 of error reporting are to be compiled using the
7711 version of @command{g77} you are building, you might wish to
7712 modify the @command{g77} source tree so that the version of
7713 @code{libg2c} is built with the @code{ALWAYS_FLUSH} macro
7714 defined, enabling this behavior.
7715
7716 To do this, find this line in @file{@value{path-libf2c}/f2c.h} in
7717 your @command{g77} source tree:
7718
7719 @example
7720 /* #define ALWAYS_FLUSH */
7721 @end example
7722
7723 Remove the leading @samp{/*@w{ }},
7724 so the line begins with @samp{#define},
7725 and the trailing @samp{@w{ }*/}.
7726
7727 Then build or rebuild @command{g77} as appropriate.
7728
7729 @node Large File Unit Numbers
7730 @subsection Large File Unit Numbers
7731 @cindex MXUNIT
7732 @cindex unit numbers
7733 @cindex maximum unit number
7734 @cindex illegal unit number
7735 @cindex increasing maximum unit number
7736
7737 If your program crashes at run time with a message including
7738 the text @samp{illegal unit number}, that probably is
7739 a message from the run-time library, @code{libg2c}.
7740
7741 The message means that your program has attempted to use a
7742 file unit number that is out of the range accepted by
7743 @code{libg2c}.
7744 Normally, this range is 0 through 99, and the high end
7745 of the range is controlled by a @code{libg2c} source-file
7746 macro named @code{MXUNIT}.
7747
7748 If you can easily change your program to use unit numbers
7749 in the range 0 through 99, you should do so.
7750
7751 As distributed, whether as part of @command{f2c} or @command{g77},
7752 @code{libf2c} accepts file unit numbers only in the range
7753 0 through 99.
7754 For example, a statement such as @samp{WRITE (UNIT=100)} causes
7755 a run-time crash in @code{libf2c}, because the unit number,
7756 100, is out of range.
7757
7758 If you know that Fortran programs at your installation require
7759 the use of unit numbers higher than 99, you can change the
7760 value of the @code{MXUNIT} macro, which represents the maximum unit
7761 number, to an appropriately higher value.
7762
7763 To do this, edit the file @file{@value{path-libf2c}/libI77/fio.h} in your
7764 @command{g77} source tree, changing the following line:
7765
7766 @example
7767 #define MXUNIT 100
7768 @end example
7769
7770 Change the line so that the value of @code{MXUNIT} is defined to be
7771 at least one @emph{greater} than the maximum unit number used by
7772 the Fortran programs on your system.
7773
7774 (For example, a program that does @samp{WRITE (UNIT=255)} would require
7775 @code{MXUNIT} set to at least 256 to avoid crashing.)
7776
7777 Then build or rebuild @command{g77} as appropriate.
7778
7779 @emph{Note:} Changing this macro has @emph{no} effect on other limits
7780 your system might place on the number of files open at the same time.
7781 That is, the macro might allow a program to do @samp{WRITE (UNIT=100)},
7782 but the library and operating system underlying @code{libf2c} might
7783 disallow it if many other files have already been opened (via @code{OPEN} or
7784 implicitly via @code{READ}, @code{WRITE}, and so on).
7785 Information on how to increase these other limits should be found
7786 in your system's documentation.
7787
7788 @node Floating-point precision
7789 @subsection Floating-point precision
7790
7791 @cindex IEEE 754 conformance
7792 @cindex conformance, IEEE 754
7793 @cindex floating-point, precision
7794 @cindex ix86 floating-point
7795 @cindex x86 floating-point
7796 If your program depends on exact IEEE 754 floating-point handling it may
7797 help on some systems---specifically x86 or m68k hardware---to use
7798 the @option{-ffloat-store} option or to reset the precision flag on the
7799 floating-point unit.
7800 @xref{Optimize Options}.
7801
7802 However, it might be better simply to put the FPU into double precision
7803 mode and not take the performance hit of @option{-ffloat-store}.  On x86
7804 and m68k GNU systems you can do this with a technique similar to that
7805 for turning on floating-point exceptions
7806 (@pxref{Floating-point Exception Handling}).
7807 The control word could be set to double precision by some code like this
7808 one:
7809 @smallexample
7810 #include <fpu_control.h>
7811 @{
7812   fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
7813   _FPU_SETCW(cw);
7814 @}
7815 @end smallexample
7816 (It is not clear whether this has any effect on the operation of the GNU
7817 maths library, but we have no evidence of it causing trouble.)
7818
7819 Some targets (such as the Alpha) may need special options for full IEEE
7820 conformance.
7821 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using
7822 the GNU Compiler Collection (GCC)}.
7823
7824 @node Inconsistent Calling Sequences
7825 @subsection Inconsistent Calling Sequences
7826
7827 @pindex ftnchek
7828 @cindex floating-point, errors
7829 @cindex ix86 FPU stack
7830 @cindex x86 FPU stack
7831 Code containing inconsistent calling sequences in the same file is
7832 normally rejected---see @ref{GLOBALS}.
7833 (Use, say, @command{ftnchek} to ensure
7834 consistency across source files.
7835 @xref{f2c Skeletons and Prototypes,,
7836 Generating Skeletons and Prototypes with @command{f2c}}.)
7837
7838 Mysterious errors, which may appear to be code generation problems, can
7839 appear specifically on the x86 architecture with some such
7840 inconsistencies.  On x86 hardware, floating-point return values of
7841 functions are placed on the floating-point unit's register stack, not
7842 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
7843 @code{FUNCTION} as some other sort of procedure, or vice versa,
7844 scrambles the floating-point stack.  This may break unrelated code
7845 executed later.  Similarly if, say, external C routines are written
7846 incorrectly.
7847
7848 @node Overly Convenient Options
7849 @section Overly Convenient Command-line Options
7850 @cindex overly convenient options
7851 @cindex options, overly convenient
7852
7853 These options should be used only as a quick-and-dirty way to determine
7854 how well your program will run under different compilation models
7855 without having to change the source.
7856 Some are more problematic
7857 than others, depending on how portable and maintainable you want the
7858 program to be (and, of course, whether you are allowed to change it
7859 at all is crucial).
7860
7861 You should not continue to use these command-line options to compile
7862 a given program, but rather should make changes to the source code:
7863
7864 @table @code
7865 @cindex -finit-local-zero option
7866 @cindex options, -finit-local-zero
7867 @item -finit-local-zero
7868 (This option specifies that any uninitialized local variables
7869 and arrays have default initialization to binary zeros.)
7870
7871 Many other compilers do this automatically, which means lots of
7872 Fortran code developed with those compilers depends on it.
7873
7874 It is safer (and probably
7875 would produce a faster program) to find the variables and arrays that
7876 need such initialization and provide it explicitly via @code{DATA}, so that
7877 @option{-finit-local-zero} is not needed.
7878
7879 Consider using @option{-Wuninitialized} (which requires @option{-O}) to
7880 find likely candidates, but
7881 do not specify @option{-finit-local-zero} or @option{-fno-automatic},
7882 or this technique won't work.
7883
7884 @cindex -fno-automatic option
7885 @cindex options, -fno-automatic
7886 @item -fno-automatic
7887 (This option specifies that all local variables and arrays
7888 are to be treated as if they were named in @code{SAVE} statements.)
7889
7890 Many other compilers do this automatically, which means lots of
7891 Fortran code developed with those compilers depends on it.
7892
7893 The effect of this is that all non-automatic variables and arrays
7894 are made static, that is, not placed on the stack or in heap storage.
7895 This might cause a buggy program to appear to work better.
7896 If so, rather than relying on this command-line option (and hoping all
7897 compilers provide the equivalent one), add @code{SAVE}
7898 statements to some or all program unit sources, as appropriate.
7899 Consider using @option{-Wuninitialized} (which requires @option{-O})
7900 to find likely candidates, but
7901 do not specify @option{-finit-local-zero} or @option{-fno-automatic},
7902 or this technique won't work.
7903
7904 The default is @option{-fautomatic}, which tells @command{g77} to try
7905 and put variables and arrays on the stack (or in fast registers)
7906 where possible and reasonable.
7907 This tends to make programs faster.
7908
7909 @cindex automatic arrays
7910 @cindex arrays, automatic
7911 @emph{Note:} Automatic variables and arrays are not affected
7912 by this option.
7913 These are variables and arrays that are @emph{necessarily} automatic,
7914 either due to explicit statements, or due to the way they are
7915 declared.
7916 Examples include local variables and arrays not given the
7917 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
7918 and local arrays declared with non-constant bounds (automatic
7919 arrays).
7920 Currently, @command{g77} supports only automatic arrays, not
7921 @code{RECURSIVE} procedures or other means of explicitly
7922 specifying that variables or arrays are automatic.
7923
7924 @cindex -f@var{group}-intrinsics-hide option
7925 @cindex options, -f@var{group}-intrinsics-hide
7926 @item -f@var{group}-intrinsics-hide
7927 Change the source code to use @code{EXTERNAL} for any external procedure
7928 that might be the name of an intrinsic.
7929 It is easy to find these using @option{-f@var{group}-intrinsics-disable}.
7930 @end table
7931
7932 @node Faster Programs
7933 @section Faster Programs
7934 @cindex speed, of programs
7935 @cindex programs, speeding up
7936
7937 Aside from the usual @command{gcc} options, such as @option{-O},
7938 @option{-ffast-math}, and so on, consider trying some of the
7939 following approaches to speed up your program (once you get
7940 it working).
7941
7942 @menu
7943 * Aligned Data::
7944 * Prefer Automatic Uninitialized Variables::
7945 * Avoid f2c Compatibility::
7946 * Use Submodel Options::
7947 @end menu
7948
7949 @node Aligned Data
7950 @subsection Aligned Data
7951 @cindex alignment
7952 @cindex data, aligned
7953 @cindex stack, aligned
7954 @cindex aligned data
7955 @cindex aligned stack
7956 @cindex Pentium optimizations
7957 @cindex optimization, for Pentium
7958
7959 On some systems, such as those with Pentium Pro CPUs, programs
7960 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
7961 might run much slower
7962 than possible due to the compiler not aligning these 64-bit
7963 values to 64-bit boundaries in memory.
7964 (The effect also is present, though
7965 to a lesser extent, on the 586 (Pentium) architecture.)
7966
7967 The Intel x86 architecture generally ensures that these programs will
7968 work on all its implementations,
7969 but particular implementations (such as Pentium Pro)
7970 perform better with more strict alignment.
7971 (Such behavior isn't unique to the Intel x86 architecture.)
7972 Other architectures might @emph{demand} 64-bit alignment
7973 of 64-bit data.
7974
7975 There are a variety of approaches to use to address this problem:
7976
7977 @itemize @bullet
7978 @item
7979 @cindex @code{COMMON} layout
7980 @cindex layout of @code{COMMON} blocks
7981 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
7982 that the variables and arrays with the widest alignment
7983 guidelines come first.
7984
7985 For example, on most systems, this would mean placing
7986 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
7987 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
7988 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
7989 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
7990 and @code{INTEGER(KIND=3)} entities.
7991
7992 The reason to use such placement is it makes it more likely
7993 that your data will be aligned properly, without requiring
7994 you to do detailed analysis of each aggregate (@code{COMMON}
7995 and @code{EQUIVALENCE}) area.
7996
7997 Specifically, on systems where the above guidelines are
7998 appropriate, placing @code{CHARACTER} entities before
7999 @code{REAL(KIND=2)} entities can work just as well,
8000 but only if the number of bytes occupied by the @code{CHARACTER}
8001 entities is divisible by the recommended alignment for
8002 @code{REAL(KIND=2)}.
8003
8004 By ordering the placement of entities in aggregate
8005 areas according to the simple guidelines above, you
8006 avoid having to carefully count the number of bytes
8007 occupied by each entity to determine whether the
8008 actual alignment of each subsequent entity meets the
8009 alignment guidelines for the type of that entity.
8010
8011 If you don't ensure correct alignment of @code{COMMON} elements, the
8012 compiler may be forced by some systems to violate the Fortran semantics by
8013 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
8014 If the unfortunate practice is employed of overlaying different types of
8015 data in the @code{COMMON} block, the different variants
8016 of this block may become misaligned with respect to each other.
8017 Even if your platform doesn't require strict alignment,
8018 @code{COMMON} should be laid out as above for portability.
8019 (Unfortunately the FORTRAN 77 standard didn't anticipate this
8020 possible requirement, which is compiler-independent on a given platform.)
8021
8022 @item
8023 @cindex -malign-double option
8024 @cindex options, -malign-double
8025 Use the (x86-specific) @option{-malign-double} option when compiling
8026 programs for the Pentium and Pentium Pro architectures (called 586
8027 and 686 in the @command{gcc} configuration subsystem).
8028 The warning about this in the @command{gcc} manual isn't
8029 generally relevant to Fortran,
8030 but using it will force @code{COMMON} to be padded if necessary to align
8031 @code{DOUBLE PRECISION} data.
8032
8033 When @code{DOUBLE PRECISION} data is forcibly aligned
8034 in @code{COMMON} by @command{g77} due to specifying @option{-malign-double},
8035 @command{g77} issues a warning about the need to
8036 insert padding.
8037
8038 In this case, each and every program unit that uses
8039 the same @code{COMMON} area
8040 must specify the same layout of variables and their types
8041 for that area
8042 and be compiled with @option{-malign-double} as well.
8043 @command{g77} will issue warnings in each case,
8044 but as long as every program unit using that area
8045 is compiled with the same warnings,
8046 the resulting object files should work when linked together
8047 unless the program makes additional assumptions about
8048 @code{COMMON} area layouts that are outside the scope
8049 of the FORTRAN 77 standard,
8050 or uses @code{EQUIVALENCE} or different layouts
8051 in ways that assume no padding is ever inserted by the compiler.
8052
8053 @item
8054 Ensure that @file{crt0.o} or @file{crt1.o}
8055 on your system guarantees a 64-bit
8056 aligned stack for @code{main()}.
8057 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
8058 but we don't know of any other x86 setups where it will be right.
8059 Read your system's documentation to determine if
8060 it is appropriate to upgrade to a more recent version
8061 to obtain the optimal alignment.
8062 @end itemize
8063
8064 Progress is being made on making this work
8065 ``out of the box'' on future versions of @command{g77},
8066 @command{gcc}, and some of the relevant operating systems
8067 (such as GNU/Linux).
8068
8069 @cindex alignment testing
8070 @cindex testing alignment
8071 A package that tests the degree to which a Fortran compiler
8072 (such as @command{g77})
8073 aligns 64-bit floating-point variables and arrays
8074 is available at @uref{ftp://alpha.gnu.org/gnu/g77/align/}.
8075
8076 @node Prefer Automatic Uninitialized Variables
8077 @subsection Prefer Automatic Uninitialized Variables
8078
8079 If you're using @option{-fno-automatic} already, you probably
8080 should change your code to allow compilation with @option{-fautomatic}
8081 (the default), to allow the program to run faster.
8082
8083 Similarly, you should be able to use @option{-fno-init-local-zero}
8084 (the default) instead of @option{-finit-local-zero}.
8085 This is because it is rare that every variable affected by these
8086 options in a given program actually needs to
8087 be so affected.
8088
8089 For example, @option{-fno-automatic}, which effectively @code{SAVE}s
8090 every local non-automatic variable and array, affects even things like
8091 @code{DO} iteration
8092 variables, which rarely need to be @code{SAVE}d, and this often reduces
8093 run-time performances.
8094 Similarly, @option{-fno-init-local-zero} forces such
8095 variables to be initialized to zero---when @code{SAVE}d (such as when
8096 @option{-fno-automatic}), this by itself generally affects only
8097 startup time for a program, but when not @code{SAVE}d,
8098 it can slow down the procedure every time it is called.
8099
8100 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
8101 for information on the @option{-fno-automatic} and
8102 @option{-finit-local-zero} options and how to convert
8103 their use into selective changes in your own code.
8104
8105 @node Avoid f2c Compatibility
8106 @subsection Avoid f2c Compatibility
8107 @cindex -fno-f2c option
8108 @cindex options, -fno-f2c
8109 @cindex @command{f2c} compatibility
8110 @cindex compatibility, @command{f2c}
8111
8112 If you aren't linking with any code compiled using
8113 @command{f2c}, try using the @option{-fno-f2c} option when
8114 compiling @emph{all} the code in your program.
8115 (Note that @code{libf2c} is @emph{not} an example of code
8116 that is compiled using @command{f2c}---it is compiled by a C
8117 compiler, typically @command{gcc}.)
8118
8119 @node Use Submodel Options
8120 @subsection Use Submodel Options
8121 @cindex submodels
8122
8123 Using an appropriate @option{-m} option to generate specific code for your
8124 CPU may be worthwhile, though it may mean the executable won't run on
8125 other versions of the CPU that don't support the same instruction set.
8126 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using the
8127 GNU Compiler Collection (GCC)}.  For instance on an x86 system the
8128 compiler might have
8129 been built---as shown by @samp{g77 -v}---for the target
8130 @samp{i386-pc-linux-gnu}, i.e.@: an @samp{i386} CPU@.  In that case to
8131 generate code best optimized for a Pentium you could use the option
8132 @option{-march=pentium}.
8133
8134 For recent CPUs that don't have explicit support in the released version
8135 of @command{gcc}, it @emph{might} still be possible to get improvements
8136 with certain @option{-m} options.
8137
8138 @option{-fomit-frame-pointer} can help performance on x86 systems and
8139 others.  It will, however, inhibit debugging on the systems on which it
8140 is not turned on anyway by @option{-O}.
8141
8142 @node Trouble
8143 @chapter Known Causes of Trouble with GNU Fortran
8144 @cindex bugs, known
8145 @cindex installation trouble
8146 @cindex known causes of trouble
8147
8148 This section describes known problems that affect users of GNU Fortran.
8149 Most of these are not GNU Fortran bugs per se---if they were, we would
8150 fix them.
8151 But the result for a user might be like the result of a bug.
8152
8153 Some of these problems are due to bugs in other software, some are
8154 missing features that are too much work to add, and some are places
8155 where people's opinions differ as to what is best.
8156
8157 To find out about major bugs discovered in the current release and
8158 possible workarounds for them, see
8159 @uref{ftp://alpha.gnu.org/g77.plan}.
8160
8161 (Note that some of this portion of the manual is lifted
8162 directly from the @command{gcc} manual, with minor modifications
8163 to tailor it to users of @command{g77}.
8164 Anytime a bug seems to have more to do with the @command{gcc}
8165 portion of @command{g77}, see
8166 @ref{Trouble,,Known Causes of Trouble with GCC,
8167 gcc,Using the GNU Compiler Collection (GCC)}.)
8168
8169 @menu
8170 * But-bugs::         Bugs really in other programs or elsewhere.
8171 * Known Bugs::       Bugs known to be in this version of @command{g77}.
8172 * Missing Features:: Features we already know we want to add later.
8173 * Disappointments::  Regrettable things we can't change.
8174 * Non-bugs::         Things we think are right, but some others disagree.
8175 * Warnings and Errors::  Which problems in your code get warnings,
8176                         and which get errors.
8177 @end menu
8178
8179 @node But-bugs
8180 @section Bugs Not In GNU Fortran
8181 @cindex but-bugs
8182
8183 These are bugs to which the maintainers often have to reply,
8184 ``but that isn't a bug in @command{g77}@dots{}''.
8185 Some of these already are fixed in new versions of other
8186 software; some still need to be fixed; some are problems
8187 with how @command{g77} is installed or is being used;
8188 some are the result of bad hardware that causes software
8189 to misbehave in sometimes bizarre ways;
8190 some just cannot be addressed at this time until more
8191 is known about the problem.
8192
8193 Please don't re-report these bugs to the @command{g77} maintainers---if
8194 you must remind someone how important it is to you that the problem
8195 be fixed, talk to the people responsible for the other products
8196 identified below, but preferably only after you've tried the
8197 latest versions of those products.
8198 The @command{g77} maintainers have their hands full working on
8199 just fixing and improving @command{g77}, without serving as a
8200 clearinghouse for all bugs that happen to affect @command{g77}
8201 users.
8202
8203 @xref{Collected Fortran Wisdom}, for information on behavior
8204 of Fortran programs, and the programs that compile them, that
8205 might be @emph{thought} to indicate bugs.
8206
8207 @menu
8208 * Signal 11 and Friends::  Strange behavior by any software.
8209 * Cannot Link Fortran Programs::  Unresolved references.
8210 * Large Common Blocks::    Problems on older GNU/Linux systems.
8211 * Debugger Problems::      When the debugger crashes.
8212 * NeXTStep Problems::      Misbehaving executables.
8213 * Stack Overflow::         More misbehaving executables.
8214 * Nothing Happens::        Less behaving executables.
8215 * Strange Behavior at Run Time::  Executables misbehaving due to
8216                             bugs in your program.
8217 * Floating-point Errors::  The results look wrong, but@dots{}.
8218 @end menu
8219
8220 @node Signal 11 and Friends
8221 @subsection Signal 11 and Friends
8222 @cindex signal 11
8223 @cindex hardware errors
8224
8225 A whole variety of strange behaviors can occur when the
8226 software, or the way you are using the software,
8227 stresses the hardware in a way that triggers hardware bugs.
8228 This might seem hard to believe, but it happens frequently
8229 enough that there exist documents explaining in detail
8230 what the various causes of the problems are, what
8231 typical symptoms look like, and so on.
8232
8233 Generally these problems are referred to in this document
8234 as ``signal 11'' crashes, because the Linux kernel, running
8235 on the most popular hardware (the Intel x86 line), often
8236 stresses the hardware more than other popular operating
8237 systems.
8238 When hardware problems do occur under GNU/Linux on x86
8239 systems, these often manifest themselves as ``signal 11''
8240 problems, as illustrated by the following diagnostic:
8241
8242 @smallexample
8243 sh# @kbd{g77 myprog.f}
8244 gcc: Internal compiler error: program f771 got fatal signal 11
8245 sh#
8246 @end smallexample
8247
8248 It is @emph{very} important to remember that the above
8249 message is @emph{not} the only one that indicates a
8250 hardware problem, nor does it always indicate a hardware
8251 problem.
8252
8253 In particular, on systems other than those running the Linux
8254 kernel, the message might appear somewhat or very different,
8255 as it will if the error manifests itself while running a
8256 program other than the @command{g77} compiler.
8257 For example,
8258 it will appear somewhat different when running your program,
8259 when running Emacs, and so on.
8260
8261 How to cope with such problems is well beyond the scope
8262 of this manual.
8263
8264 However, users of Linux-based systems (such as GNU/Linux)
8265 should review @uref{http://www.bitwizard.nl/sig11/}, a source
8266 of detailed information on diagnosing hardware problems,
8267 by recognizing their common symptoms.
8268
8269 Users of other operating systems and hardware might
8270 find this reference useful as well.
8271 If you know of similar material for another hardware/software
8272 combination, please let us know so we can consider including
8273 a reference to it in future versions of this manual.
8274
8275 @node Cannot Link Fortran Programs
8276 @subsection Cannot Link Fortran Programs
8277 @cindex unresolved reference (various)
8278 @cindex linking error for user code
8279 @cindex code, user
8280 @cindex @command{ld}, error linking user code
8281 @cindex @command{ld}, can't find strange names
8282 On some systems, perhaps just those with out-of-date (shared?)
8283 libraries, unresolved-reference errors happen when linking @command{g77}-compiled
8284 programs (which should be done using @command{g77}).
8285
8286 If this happens to you, try appending @option{-lc} to the command you
8287 use to link the program, e.g. @samp{g77 foo.f -lc}.
8288 @command{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
8289 but it cannot also specify @option{-lc} because not all systems have a
8290 file named @file{libc.a}.
8291
8292 It is unclear at this point whether there are legitimately installed
8293 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
8294 by @command{g77}.
8295
8296 @cindex undefined reference (_main)
8297 @cindex linking error, user code
8298 @cindex @command{ld}, error linking user code
8299 @cindex code, user
8300 @cindex @command{ld}, can't find @samp{_main}
8301 If your program doesn't link due to unresolved references to names
8302 like @samp{_main}, make sure you're using the @command{g77} command to do the
8303 link, since this command ensures that the necessary libraries are
8304 loaded by specifying @samp{-lg2c -lm} when it invokes the @command{gcc}
8305 command to do the actual link.
8306 (Use the @option{-v} option to discover
8307 more about what actually happens when you use the @command{g77} and @command{gcc}
8308 commands.)
8309
8310 Also, try specifying @option{-lc} as the last item on the @command{g77}
8311 command line, in case that helps.
8312
8313 @node Large Common Blocks
8314 @subsection Large Common Blocks
8315 @cindex common blocks, large
8316 @cindex large common blocks
8317 @cindex linking, errors
8318 @cindex @command{ld}, errors
8319 @cindex errors, linker
8320 On some older GNU/Linux systems, programs with common blocks larger
8321 than 16MB cannot be linked without some kind of error
8322 message being produced.
8323
8324 This is a bug in older versions of @command{ld}, fixed in
8325 more recent versions of @code{binutils}, such as version 2.6.
8326
8327 @node Debugger Problems
8328 @subsection Debugger Problems
8329 @cindex @command{gdb}, support
8330 @cindex support, @command{gdb}
8331 There are some known problems when using @command{gdb} on code
8332 compiled by @command{g77}.
8333 Inadequate investigation as of the release of 0.5.16 results in not
8334 knowing which products are the culprit, but @file{gdb-4.14} definitely
8335 crashes when, for example, an attempt is made to print the contents
8336 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
8337 machines, plus some others.
8338 Attempts to access assumed-size arrays are
8339 also known to crash recent versions of @command{gdb}.
8340 (@command{gdb}'s Fortran support was done for a different compiler
8341 and isn't properly compatible with @command{g77}.)
8342
8343 @node NeXTStep Problems
8344 @subsection NeXTStep Problems
8345 @cindex NeXTStep problems
8346 @cindex bus error
8347 @cindex segmentation violation
8348 Developers of Fortran code on NeXTStep (all architectures) have to
8349 watch out for the following problem when writing programs with
8350 large, statically allocated (i.e. non-stack based) data structures
8351 (common blocks, saved arrays).
8352
8353 Due to the way the native loader (@file{/bin/ld}) lays out
8354 data structures in virtual memory, it is very easy to create an
8355 executable wherein the @samp{__DATA} segment overlaps (has addresses in
8356 common) with the @samp{UNIX STACK} segment.
8357
8358 This leads to all sorts of trouble, from the executable simply not
8359 executing, to bus errors.
8360 The NeXTStep command line tool @command{ebadexec} points to
8361 the problem as follows:
8362
8363 @smallexample
8364 % @kbd{/bin/ebadexec a.out}
8365 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
8366 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
8367 STACK segment (truncated address = 0x400000 rounded size =
8368 0x3c00000) of executable file: a.out
8369 @end smallexample
8370
8371 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
8372 stack segment.)
8373
8374 This can be cured by assigning the @samp{__DATA} segment
8375 (virtual) addresses beyond the stack segment.
8376 A conservative
8377 estimate for this is from address 6000000 (hexadecimal) onwards---this
8378 has always worked for me [Toon Moene]:
8379
8380 @smallexample
8381 % @kbd{g77 -segaddr __DATA 6000000 test.f}
8382 % @kbd{ebadexec a.out}
8383 ebadexec: file: a.out appears to be executable
8384 %
8385 @end smallexample
8386
8387 Browsing through @file{@value{path-g77}/Makefile.in},
8388 you will find that the @code{f771} program itself also has to be
8389 linked with these flags---it has large statically allocated
8390 data structures.
8391 (Version 0.5.18 reduces this somewhat, but probably
8392 not enough.)
8393
8394 (The above item was contributed by Toon Moene
8395 (@email{toon@@moene.indiv.nluug.nl}).)
8396
8397 @node Stack Overflow
8398 @subsection Stack Overflow
8399 @cindex stack, overflow
8400 @cindex segmentation violation
8401 @command{g77} code might fail at runtime (probably with a ``segmentation
8402 violation'') due to overflowing the stack.
8403 This happens most often on systems with an environment
8404 that provides substantially more heap space (for use
8405 when arbitrarily allocating and freeing memory) than stack
8406 space.
8407
8408 Often this can be cured by
8409 increasing or removing your shell's limit on stack usage, typically
8410 using @kbd{limit stacksize} (in @command{csh} and derivatives) or
8411 @kbd{ulimit -s} (in @command{sh} and derivatives).
8412
8413 Increasing the allowed stack size might, however, require
8414 changing some operating system or system configuration parameters.
8415
8416 You might be able to work around the problem by compiling with the
8417 @option{-fno-automatic} option to reduce stack usage, probably at the
8418 expense of speed.
8419
8420 @command{g77}, on most machines, puts many variables and arrays on the stack
8421 where possible, and can be configured (by changing
8422 @code{FFECOM_sizeMAXSTACKITEM} in @file{@value{path-g77}/com.c}) to force
8423 smaller-sized entities into static storage (saving
8424 on stack space) or permit larger-sized entities to be put on the
8425 stack (which can improve run-time performance, as it presents
8426 more opportunities for the GBE to optimize the generated code).
8427
8428 @emph{Note:} Putting more variables and arrays on the stack
8429 might cause problems due to system-dependent limits on stack size.
8430 Also, the value of @code{FFECOM_sizeMAXSTACKITEM} has no
8431 effect on automatic variables and arrays.
8432 @xref{But-bugs}, for more information.
8433 @emph{Note:} While @code{libg2c} places a limit on the range
8434 of Fortran file-unit numbers, the underlying library and operating
8435 system might impose different kinds of limits.
8436 For example, some systems limit the number of files simultaneously
8437 open by a running program.
8438 Information on how to increase these limits should be found
8439 in your system's documentation.
8440
8441 @cindex automatic arrays
8442 @cindex arrays, automatic
8443 However, if your program uses large automatic arrays
8444 (for example, has declarations like @samp{REAL A(N)} where
8445 @samp{A} is a local array and @samp{N} is a dummy or
8446 @code{COMMON} variable that can have a large value),
8447 neither use of @option{-fno-automatic},
8448 nor changing the cut-off point for @command{g77} for using the stack,
8449 will solve the problem by changing the placement of these
8450 large arrays, as they are @emph{necessarily} automatic.
8451
8452 @command{g77} currently provides no means to specify that
8453 automatic arrays are to be allocated on the heap instead
8454 of the stack.
8455 So, other than increasing the stack size, your best bet is to
8456 change your source code to avoid large automatic arrays.
8457 Methods for doing this currently are outside the scope of
8458 this document.
8459
8460 (@emph{Note:} If your system puts stack and heap space in the
8461 same memory area, such that they are effectively combined, then
8462 a stack overflow probably indicates a program that is either
8463 simply too large for the system, or buggy.)
8464
8465 @node Nothing Happens
8466 @subsection Nothing Happens
8467 @cindex nothing happens
8468 @cindex naming programs
8469 @cindex @command{test} programs
8470 @cindex programs, @command{test}
8471 It is occasionally reported that a ``simple'' program,
8472 such as a ``Hello, World!'' program, does nothing when
8473 it is run, even though the compiler reported no errors,
8474 despite the program containing nothing other than a
8475 simple @code{PRINT} statement.
8476
8477 This most often happens because the program has been
8478 compiled and linked on a UNIX system and named @command{test},
8479 though other names can lead to similarly unexpected
8480 run-time behavior on various systems.
8481
8482 Essentially this problem boils down to giving
8483 your program a name that is already known to
8484 the shell you are using to identify some other program,
8485 which the shell continues to execute instead of your
8486 program when you invoke it via, for example:
8487
8488 @smallexample
8489 sh# @kbd{test}
8490 sh#
8491 @end smallexample
8492
8493 Under UNIX and many other system, a simple command name
8494 invokes a searching mechanism that might well not choose
8495 the program located in the current working directory if
8496 there is another alternative (such as the @command{test}
8497 command commonly installed on UNIX systems).
8498
8499 The reliable way to invoke a program you just linked in
8500 the current directory under UNIX is to specify it using
8501 an explicit pathname, as in:
8502
8503 @smallexample
8504 sh# @kbd{./test}
8505  Hello, World!
8506 sh#
8507 @end smallexample
8508
8509 Users who encounter this problem should take the time to
8510 read up on how their shell searches for commands, how to
8511 set their search path, and so on.
8512 The relevant UNIX commands to learn about include
8513 @command{man}, @command{info} (on GNU systems), @command{setenv} (or
8514 @command{set} and @command{env}), @command{which}, and @command{find}.
8515
8516 @node Strange Behavior at Run Time
8517 @subsection Strange Behavior at Run Time
8518 @cindex segmentation violation
8519 @cindex bus error
8520 @cindex overwritten data
8521 @cindex data, overwritten
8522 @command{g77} code might fail at runtime with ``segmentation violation'',
8523 ``bus error'', or even something as subtle as a procedure call
8524 overwriting a variable or array element that it is not supposed
8525 to touch.
8526
8527 These can be symptoms of a wide variety of actual bugs that
8528 occurred earlier during the program's run, but manifested
8529 themselves as @emph{visible} problems some time later.
8530
8531 Overflowing the bounds of an array---usually by writing beyond
8532 the end of it---is one of two kinds of bug that often occurs
8533 in Fortran code.
8534 (Compile your code with the @option{-fbounds-check} option
8535 to catch many of these kinds of errors at program run time.)
8536
8537 The other kind of bug is a mismatch between the actual arguments
8538 passed to a procedure and the dummy arguments as declared by that
8539 procedure.
8540
8541 Both of these kinds of bugs, and some others as well, can be
8542 difficult to track down, because the bug can change its behavior,
8543 or even appear to not occur, when using a debugger.
8544
8545 That is, these bugs can be quite sensitive to data, including
8546 data representing the placement of other data in memory (that is,
8547 pointers, such as the placement of stack frames in memory).
8548
8549 @command{g77} now offers the
8550 ability to catch and report some of these problems at compile, link, or
8551 run time, such as by generating code to detect references to
8552 beyond the bounds of most arrays (except assumed-size arrays),
8553 and checking for agreement between calling and called procedures.
8554 Future improvements are likely to be made in the procedure-mismatch area,
8555 at least.
8556
8557 In the meantime, finding and fixing the programming
8558 bugs that lead to these behaviors is, ultimately, the user's
8559 responsibility, as difficult as that task can sometimes be.
8560
8561 @cindex infinite spaces printed
8562 @cindex space, endless printing of
8563 @cindex libc, non-ANSI or non-default
8564 @cindex C library
8565 @cindex linking against non-standard library
8566 @cindex Solaris
8567 One runtime problem that has been observed might have a simple solution.
8568 If a formatted @code{WRITE} produces an endless stream of spaces, check
8569 that your program is linked against the correct version of the C library.
8570 The configuration process takes care to account for your
8571 system's normal @file{libc} not being ANSI-standard, which will
8572 otherwise cause this behaviour.
8573 If your system's default library is
8574 ANSI-standard and you subsequently link against a non-ANSI one, there
8575 might be problems such as this one.
8576
8577 Specifically, on Solaris2 systems,
8578 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
8579
8580 @node Floating-point Errors
8581 @subsection Floating-point Errors
8582 @cindex floating-point errors
8583 @cindex rounding errors
8584 @cindex inconsistent floating-point results
8585 @cindex results, inconsistent
8586 Some programs appear to produce inconsistent floating-point
8587 results compiled by @command{g77} versus by other compilers.
8588
8589 Often the reason for this behavior is the fact that floating-point
8590 values are represented on almost all Fortran systems by
8591 @emph{approximations}, and these approximations are inexact
8592 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
8593 0.7, 0.8, 0.9, 1.1, and so on.
8594 Most Fortran systems, including all current ports of @command{g77},
8595 use binary arithmetic to represent these approximations.
8596
8597 Therefore, the exact value of any floating-point approximation
8598 as manipulated by @command{g77}-compiled code is representable by
8599 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
8600 so on (just keep dividing by two) through the precision of the
8601 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
8602 @code{REAL(KIND=2)}), then multiplying the sum by a integral
8603 power of two (in Fortran, by @samp{2**N}) that typically is between
8604 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
8605 @code{REAL(KIND=2)}, then multiplying by -1 if the number
8606 is negative.
8607
8608 So, a value like 0.2 is exactly represented in decimal---since
8609 it is a fraction, @samp{2/10}, with a denominator that is compatible
8610 with the base of the number system (base 10).
8611 However, @samp{2/10} cannot be represented by any finite number
8612 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
8613 be exactly represented in binary notation.
8614
8615 (On the other hand, decimal notation can represent any binary
8616 number in a finite number of digits.
8617 Decimal notation cannot do so with ternary, or base-3,
8618 notation, which would represent floating-point numbers as
8619 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
8620 After all, no finite number of decimal digits can exactly
8621 represent @samp{1/3}.
8622 Fortunately, few systems use ternary notation.)
8623
8624 Moreover, differences in the way run-time I/O libraries convert
8625 between these approximations and the decimal representation often
8626 used by programmers and the programs they write can result in
8627 apparent differences between results that do not actually exist,
8628 or exist to such a small degree that they usually are not worth
8629 worrying about.
8630
8631 For example, consider the following program:
8632
8633 @smallexample
8634 PRINT *, 0.2
8635 END
8636 @end smallexample
8637
8638 When compiled by @command{g77}, the above program might output
8639 @samp{0.20000003}, while another compiler might produce a
8640 executable that outputs @samp{0.2}.
8641
8642 This particular difference is due to the fact that, currently,
8643 conversion of floating-point values by the @code{libg2c} library,
8644 used by @command{g77}, handles only double-precision values.
8645
8646 Since @samp{0.2} in the program is a single-precision value, it
8647 is converted to double precision (still in binary notation)
8648 before being converted back to decimal.
8649 The conversion to binary appends @emph{binary} zero digits to the
8650 original value---which, again, is an inexact approximation of
8651 0.2---resulting in an approximation that is much less exact
8652 than is connoted by the use of double precision.
8653
8654 (The appending of binary zero digits has essentially the same
8655 effect as taking a particular decimal approximation of
8656 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
8657 zeros to it, producing @samp{0.33333330000000000}.
8658 Treating the resulting decimal approximation as if it really
8659 had 18 or so digits of valid precision would make it seem
8660 a very poor approximation of @samp{1/3}.)
8661
8662 As a result of converting the single-precision approximation
8663 to double precision by appending binary zeros, the conversion
8664 of the resulting double-precision
8665 value to decimal produces what looks like an incorrect
8666 result, when in fact the result is @emph{inexact}, and
8667 is probably no less inaccurate or imprecise an approximation
8668 of 0.2 than is produced by other compilers that happen to output
8669 the converted value as ``exactly'' @samp{0.2}.
8670 (Some compilers behave in a way that can make them appear
8671 to retain more accuracy across a conversion of a single-precision
8672 constant to double precision.
8673 @xref{Context-Sensitive Constants}, to see why
8674 this practice is illusory and even dangerous.)
8675
8676 Note that a more exact approximation of the constant is
8677 computed when the program is changed to specify a
8678 double-precision constant:
8679
8680 @smallexample
8681 PRINT *, 0.2D0
8682 END
8683 @end smallexample
8684
8685 Future versions of @command{g77} and/or @code{libg2c} might convert
8686 single-precision values directly to decimal,
8687 instead of converting them to double precision first.
8688 This would tend to result in output that is more consistent
8689 with that produced by some other Fortran implementations.
8690
8691 A useful source of information on floating-point computation is David
8692 Goldberg, `What Every Computer Scientist Should Know About
8693 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
8694 5-48.
8695 An online version is available at
8696 @uref{http://docs.sun.com/},
8697 and there is a supplemented version, in PostScript form, at
8698 @uref{http://www.validgh.com/goldberg/paper.ps}.
8699
8700 Information related to the IEEE 754
8701 floating-point standard by a leading light can be found at
8702 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status/};
8703 see also slides from the short course referenced from
8704 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
8705 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
8706 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
8707 and library code for GNU/Linux x86 systems.
8708
8709 The supplement to the PostScript-formatted Goldberg document,
8710 referenced above, is available in HTML format.
8711 See `Differences Among IEEE 754 Implementations' by Doug Priest,
8712 available online at
8713 @uref{http://www.validgh.com/goldberg/addendum.html}.
8714 This document explores some of the issues surrounding computing
8715 of extended (80-bit) results on processors such as the x86,
8716 especially when those results are arbitrarily truncated
8717 to 32-bit or 64-bit values by the compiler
8718 as ``spills''.
8719
8720 @cindex spills of floating-point results
8721 @cindex 80-bit spills
8722 @cindex truncation, of floating-point values
8723 (@emph{Note:} @command{g77} specifically, and @command{gcc} generally,
8724 does arbitrarily truncate 80-bit results during spills
8725 as of this writing.
8726 It is not yet clear whether a future version of
8727 the GNU compiler suite will offer 80-bit spills
8728 as an option, or perhaps even as the default behavior.)
8729
8730 @c xref would be different between editions:
8731 The GNU C library provides routines for controlling the FPU, and other
8732 documentation about this.
8733
8734 @xref{Floating-point precision}, regarding IEEE 754 conformance.
8735
8736 @include bugs.texi
8737
8738 @node Missing Features
8739 @section Missing Features
8740
8741 This section lists features we know are missing from @command{g77},
8742 and which we want to add someday.
8743 (There is no priority implied in the ordering below.)
8744
8745 @menu
8746 GNU Fortran language:
8747 * Better Source Model::
8748 * Fortran 90 Support::
8749 * Intrinsics in PARAMETER Statements::
8750 * Arbitrary Concatenation::
8751 * SELECT CASE on CHARACTER Type::
8752 * RECURSIVE Keyword::
8753 * Popular Non-standard Types::
8754 * Full Support for Compiler Types::
8755 * Array Bounds Expressions::
8756 * POINTER Statements::
8757 * Sensible Non-standard Constructs::
8758 * READONLY Keyword::
8759 * FLUSH Statement::
8760 * Expressions in FORMAT Statements::
8761 * Explicit Assembler Code::
8762 * Q Edit Descriptor::
8763
8764 GNU Fortran dialects:
8765 * Old-style PARAMETER Statements::
8766 * TYPE and ACCEPT I/O Statements::
8767 * STRUCTURE UNION RECORD MAP::
8768 * OPEN CLOSE and INQUIRE Keywords::
8769 * ENCODE and DECODE::
8770 * AUTOMATIC Statement::
8771 * Suppressing Space Padding::
8772 * Fortran Preprocessor::
8773 * Bit Operations on Floating-point Data::
8774 * Really Ugly Character Assignments::
8775
8776 New facilities:
8777 * POSIX Standard::
8778 * Floating-point Exception Handling::
8779 * Nonportable Conversions::
8780 * Large Automatic Arrays::
8781 * Support for Threads::
8782 * Increasing Precision/Range::
8783 * Enabling Debug Lines::
8784
8785 Better diagnostics:
8786 * Better Warnings::
8787 * Gracefully Handle Sensible Bad Code::
8788 * Non-standard Conversions::
8789 * Non-standard Intrinsics::
8790 * Modifying DO Variable::
8791 * Better Pedantic Compilation::
8792 * Warn About Implicit Conversions::
8793 * Invalid Use of Hollerith Constant::
8794 * Dummy Array Without Dimensioning Dummy::
8795 * Invalid FORMAT Specifiers::
8796 * Ambiguous Dialects::
8797 * Unused Labels::
8798 * Informational Messages::
8799
8800 Run-time facilities:
8801 * Uninitialized Variables at Run Time::
8802 * Portable Unformatted Files::
8803 * Better List-directed I/O::
8804 * Default to Console I/O::
8805
8806 Debugging:
8807 * Labels Visible to Debugger::
8808 @end menu
8809
8810 @node Better Source Model
8811 @subsection Better Source Model
8812
8813 @command{g77} needs to provide, as the default source-line model,
8814 a ``pure visual'' mode, where
8815 the interpretation of a source program in this mode can be accurately
8816 determined by a user looking at a traditionally displayed rendition
8817 of the program (assuming the user knows whether the program is fixed
8818 or free form).
8819
8820 The design should assume the user cannot tell tabs from spaces
8821 and cannot see trailing spaces on lines, but has canonical tab stops
8822 and, for fixed-form source, has the ability to always know exactly
8823 where column 72 is (since the Fortran standard itself requires
8824 this for fixed-form source).
8825
8826 This would change the default treatment of fixed-form source
8827 to not treat lines with tabs as if they were infinitely long---instead,
8828 they would end at column 72 just as if the tabs were replaced
8829 by spaces in the canonical way.
8830
8831 As part of this, provide common alternate models (Digital, @command{f2c},
8832 and so on) via command-line options.
8833 This includes allowing arbitrarily long
8834 lines for free-form source as well as fixed-form source and providing
8835 various limits and diagnostics as appropriate.
8836
8837 @cindex sequence numbers
8838 @cindex columns 73 through 80
8839 Also, @command{g77} should offer, perhaps even default to, warnings
8840 when characters beyond the last valid column are anything other
8841 than spaces.
8842 This would mean code with ``sequence numbers'' in columns 73 through 80
8843 would be rejected, and there's a lot of that kind of code around,
8844 but one of the most frequent bugs encountered by new users is
8845 accidentally writing fixed-form source code into and beyond
8846 column 73.
8847 So, maybe the users of old code would be able to more easily handle
8848 having to specify, say, a @option{-Wno-col73to80} option.
8849
8850 @node Fortran 90 Support
8851 @subsection Fortran 90 Support
8852 @cindex Fortran 90, support
8853 @cindex support, Fortran 90
8854
8855 @command{g77} does not support many of the features that
8856 distinguish Fortran 90 (and, now, Fortran 95) from
8857 ANSI FORTRAN 77.
8858
8859 Some Fortran 90 features are supported, because they
8860 make sense to offer even to die-hard users of F77.
8861 For example, many of them codify various ways F77 has
8862 been extended to meet users' needs during its tenure,
8863 so @command{g77} might as well offer them as the primary
8864 way to meet those same needs, even if it offers compatibility
8865 with one or more of the ways those needs were met
8866 by other F77 compilers in the industry.
8867
8868 Still, many important F90 features are not supported,
8869 because no attempt has been made to research each and
8870 every feature and assess its viability in @command{g77}.
8871 In the meantime, users who need those features must
8872 use Fortran 90 compilers anyway, and the best approach
8873 to adding some F90 features to GNU Fortran might well be
8874 to fund a comprehensive project to create GNU Fortran 95.
8875
8876 @node Intrinsics in PARAMETER Statements
8877 @subsection Intrinsics in @code{PARAMETER} Statements
8878 @cindex PARAMETER statement
8879 @cindex statements, PARAMETER
8880
8881 @command{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
8882 This feature is considered to be absolutely vital, even though it
8883 is not standard-conforming, and is scheduled for version 0.6.
8884
8885 Related to this, @command{g77} doesn't allow non-integral
8886 exponentiation in @code{PARAMETER} statements, such as
8887 @samp{PARAMETER (R=2**.25)}.
8888 It is unlikely @command{g77} will ever support this feature,
8889 as doing it properly requires complete emulation of
8890 a target computer's floating-point facilities when
8891 building @command{g77} as a cross-compiler.
8892 But, if the @command{gcc} back end is enhanced to provide
8893 such a facility, @command{g77} will likely use that facility
8894 in implementing this feature soon afterwards.
8895
8896 @node Arbitrary Concatenation
8897 @subsection Arbitrary Concatenation
8898 @cindex concatenation
8899 @cindex CHARACTER*(*)
8900 @cindex run-time, dynamic allocation
8901
8902 @command{g77} doesn't support arbitrary operands for concatenation
8903 in contexts where run-time allocation is required.
8904 For example:
8905
8906 @smallexample
8907 SUBROUTINE X(A)
8908 CHARACTER*(*) A
8909 CALL FOO(A // 'suffix')
8910 @end smallexample
8911
8912 @node SELECT CASE on CHARACTER Type
8913 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
8914
8915 Character-type selector/cases for @code{SELECT CASE} currently
8916 are not supported.
8917
8918 @node RECURSIVE Keyword
8919 @subsection @code{RECURSIVE} Keyword
8920 @cindex RECURSIVE keyword
8921 @cindex keywords, RECURSIVE
8922 @cindex recursion, lack of
8923 @cindex lack of recursion
8924
8925 @command{g77} doesn't support the @code{RECURSIVE} keyword that
8926 F90 compilers do.
8927 Nor does it provide any means for compiling procedures
8928 designed to do recursion.
8929
8930 All recursive code can be rewritten to not use recursion,
8931 but the result is not pretty.
8932
8933 @node Increasing Precision/Range
8934 @subsection Increasing Precision/Range
8935 @cindex -r8
8936 @cindex -qrealsize=8
8937 @cindex -i8
8938 @cindex f2c
8939 @cindex increasing precision
8940 @cindex precision, increasing
8941 @cindex increasing range
8942 @cindex range, increasing
8943 @cindex Toolpack
8944 @cindex Netlib
8945
8946 Some compilers, such as @command{f2c}, have an option (@option{-r8},
8947 @option{-qrealsize=8} or
8948 similar) that provides automatic treatment of @code{REAL}
8949 entities such that they have twice the storage size, and
8950 a corresponding increase in the range and precision, of what
8951 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
8952 (This affects @code{COMPLEX} the same way.)
8953
8954 They also typically offer another option (@option{-i8}) to increase
8955 @code{INTEGER} entities so they are twice as large
8956 (with roughly twice as much range).
8957
8958 (There are potential pitfalls in using these options.)
8959
8960 @command{g77} does not yet offer any option that performs these
8961 kinds of transformations.
8962 Part of the problem is the lack of detailed specifications regarding
8963 exactly how these options affect the interpretation of constants,
8964 intrinsics, and so on.
8965
8966 Until @command{g77} addresses this need, programmers could improve
8967 the portability of their code by modifying it to not require
8968 compile-time options to produce correct results.
8969 Some free tools are available which may help, specifically
8970 in Toolpack (which one would expect to be sound) and the @file{fortran}
8971 section of the Netlib repository.
8972
8973 Use of preprocessors can provide a fairly portable means
8974 to work around the lack of widely portable methods in the Fortran
8975 language itself (though increasing acceptance of Fortran 90 would
8976 alleviate this problem).
8977
8978 @node Popular Non-standard Types
8979 @subsection Popular Non-standard Types
8980 @cindex @code{INTEGER*2} support
8981 @cindex types, @code{INTEGER*2}
8982 @cindex @code{LOGICAL*1} support
8983 @cindex types, @code{LOGICAL*1}
8984
8985 @command{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
8986 and similar.
8987 Version 0.6 will provide full support for this very
8988 popular set of features.
8989 In the meantime, version 0.5.18 provides rudimentary support
8990 for them.
8991
8992 @node Full Support for Compiler Types
8993 @subsection Full Support for Compiler Types
8994
8995 @cindex @code{REAL*16} support
8996 @cindex types, @code{REAL*16}
8997 @cindex @code{INTEGER*8} support
8998 @cindex types, @code{INTEGER*8}
8999 @command{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
9000 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
9001 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
9002 This means providing intrinsic support, and maybe constant
9003 support (using F90 syntax) as well, and, for most
9004 machines will result in automatic support of @code{INTEGER*1},
9005 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
9006 and so on.
9007 This is scheduled for version 0.6.
9008
9009 @node Array Bounds Expressions
9010 @subsection Array Bounds Expressions
9011 @cindex array elements, in adjustable array bounds
9012 @cindex function references, in adjustable array bounds
9013 @cindex array bounds, adjustable
9014 @cindex @code{DIMENSION} statement
9015 @cindex statements, @code{DIMENSION}
9016
9017 @command{g77} doesn't support more general expressions to dimension
9018 arrays, such as array element references, function
9019 references, etc.
9020
9021 For example, @command{g77} currently does not accept the following:
9022
9023 @smallexample
9024 SUBROUTINE X(M, N)
9025 INTEGER N(10), M(N(2), N(1))
9026 @end smallexample
9027
9028 @node POINTER Statements
9029 @subsection POINTER Statements
9030 @cindex POINTER statement
9031 @cindex statements, POINTER
9032 @cindex Cray pointers
9033
9034 @command{g77} doesn't support pointers or allocatable objects
9035 (other than automatic arrays).
9036 This set of features is
9037 probably considered just behind intrinsics
9038 in @code{PARAMETER} statements on the list of large,
9039 important things to add to @command{g77}.
9040
9041 In the meantime, consider using the @code{INTEGER(KIND=7)}
9042 declaration to specify that a variable must be
9043 able to hold a pointer.
9044 This construct is not portable to other non-GNU compilers,
9045 but it is portable to all machines GNU Fortran supports
9046 when @command{g77} is used.
9047
9048 @xref{Functions and Subroutines}, for information on
9049 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
9050 constructs, which are useful for passing pointers to
9051 procedures written in languages other than Fortran.
9052
9053 @node Sensible Non-standard Constructs
9054 @subsection Sensible Non-standard Constructs
9055
9056 @command{g77} rejects things other compilers accept,
9057 like @samp{INTRINSIC SQRT,SQRT}.
9058 As time permits in the future, some of these things that are easy for
9059 humans to read and write and unlikely to be intended to mean something
9060 else will be accepted by @command{g77} (though @option{-fpedantic} should
9061 trigger warnings about such non-standard constructs).
9062
9063 Until @command{g77} no longer gratuitously rejects sensible code,
9064 you might as well fix your code
9065 to be more standard-conforming and portable.
9066
9067 The kind of case that is important to except from the
9068 recommendation to change your code is one where following
9069 good coding rules would force you to write non-standard
9070 code that nevertheless has a clear meaning.
9071
9072 For example, when writing an @code{INCLUDE} file that
9073 defines a common block, it might be appropriate to
9074 include a @code{SAVE} statement for the common block
9075 (such as @samp{SAVE /CBLOCK/}), so that variables
9076 defined in the common block retain their values even
9077 when all procedures declaring the common block become
9078 inactive (return to their callers).
9079
9080 However, putting @code{SAVE} statements in an @code{INCLUDE}
9081 file would prevent otherwise standard-conforming code
9082 from also specifying the @code{SAVE} statement, by itself,
9083 to indicate that all local variables and arrays are to
9084 have the @code{SAVE} attribute.
9085
9086 For this reason, @command{g77} already has been changed to
9087 allow this combination, because although the general
9088 problem of gratuitously rejecting unambiguous and
9089 ``safe'' constructs still exists in @command{g77}, this
9090 particular construct was deemed useful enough that
9091 it was worth fixing @command{g77} for just this case.
9092
9093 So, while there is no need to change your code
9094 to avoid using this particular construct, there
9095 might be other, equally appropriate but non-standard
9096 constructs, that you shouldn't have to stop using
9097 just because @command{g77} (or any other compiler)
9098 gratuitously rejects it.
9099
9100 Until the general problem is solved, if you have
9101 any such construct you believe is worthwhile
9102 using (e.g. not just an arbitrary, redundant
9103 specification of an attribute), please submit a
9104 bug report with an explanation, so we can consider
9105 fixing @command{g77} just for cases like yours.
9106
9107 @node READONLY Keyword
9108 @subsection @code{READONLY} Keyword
9109 @cindex READONLY
9110
9111 Support for @code{READONLY}, in @code{OPEN} statements,
9112 requires @code{libg2c} support,
9113 to make sure that @samp{CLOSE(@dots{},STATUS='DELETE')}
9114 does not delete a file opened on a unit
9115 with the @code{READONLY} keyword,
9116 and perhaps to trigger a fatal diagnostic
9117 if a @code{WRITE} or @code{PRINT}
9118 to such a unit is attempted.
9119
9120 @emph{Note:} It is not sufficient for @command{g77} and @code{libg2c}
9121 (its version of @code{libf2c})
9122 to assume that @code{READONLY} does not need some kind of explicit support
9123 at run time,
9124 due to UNIX systems not (generally) needing it.
9125 @command{g77} is not just a UNIX-based compiler!
9126
9127 Further, mounting of non-UNIX filesystems on UNIX systems
9128 (such as via NFS)
9129 might require proper @code{READONLY} support.
9130
9131 @cindex SHARED
9132 (Similar issues might be involved with supporting the @code{SHARED}
9133 keyword.)
9134
9135 @node FLUSH Statement
9136 @subsection @code{FLUSH} Statement
9137
9138 @command{g77} could perhaps use a @code{FLUSH} statement that
9139 does what @samp{CALL FLUSH} does,
9140 but that supports @samp{*} as the unit designator (same unit as for
9141 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
9142 specifiers.
9143
9144 @node Expressions in FORMAT Statements
9145 @subsection Expressions in @code{FORMAT} Statements
9146 @cindex FORMAT statement
9147 @cindex statements, FORMAT
9148
9149 @command{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
9150 Supporting this requires a significant redesign or replacement
9151 of @code{libg2c}.
9152
9153 However, @command{g77} does support
9154 this construct when the expression is constant
9155 (as of version 0.5.22).
9156 For example:
9157
9158 @smallexample
9159       PARAMETER (IWIDTH = 12)
9160 10    FORMAT (I<IWIDTH>)
9161 @end smallexample
9162
9163 Otherwise, at least for output (@code{PRINT} and
9164 @code{WRITE}), Fortran code making use of this feature can
9165 be rewritten to avoid it by constructing the @code{FORMAT}
9166 string in a @code{CHARACTER} variable or array, then
9167 using that variable or array in place of the @code{FORMAT}
9168 statement label to do the original @code{PRINT} or @code{WRITE}.
9169
9170 Many uses of this feature on input can be rewritten this way
9171 as well, but not all can.
9172 For example, this can be rewritten:
9173
9174 @smallexample
9175       READ 20, I
9176 20    FORMAT (I<J>)
9177 @end smallexample
9178
9179 However, this cannot, in general, be rewritten, especially
9180 when @code{ERR=} and @code{END=} constructs are employed:
9181
9182 @smallexample
9183       READ 30, J, I
9184 30    FORMAT (I<J>)
9185 @end smallexample
9186
9187 @node Explicit Assembler Code
9188 @subsection Explicit Assembler Code
9189
9190 @command{g77} needs to provide some way, a la @command{gcc}, for @command{g77}
9191 code to specify explicit assembler code.
9192
9193 @node Q Edit Descriptor
9194 @subsection Q Edit Descriptor
9195 @cindex FORMAT statement
9196 @cindex Q edit descriptor
9197 @cindex edit descriptor, Q
9198
9199 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
9200 (This is meant to get the number of characters remaining in an input record.)
9201 Supporting this requires a significant redesign or replacement
9202 of @code{libg2c}.
9203
9204 A workaround might be using internal I/O or the stream-based intrinsics.
9205 @xref{FGetC Intrinsic (subroutine)}.
9206
9207 @node Old-style PARAMETER Statements
9208 @subsection Old-style PARAMETER Statements
9209 @cindex PARAMETER statement
9210 @cindex statements, PARAMETER
9211
9212 @command{g77} doesn't accept @samp{PARAMETER I=1}.
9213 Supporting this obsolete form of
9214 the @code{PARAMETER} statement would not be particularly hard, as most of the
9215 parsing code is already in place and working.
9216
9217 Until time/money is
9218 spent implementing it, you might as well fix your code to use the
9219 standard form, @samp{PARAMETER (I=1)} (possibly needing
9220 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
9221 otherwise, in the obsolete form of @code{PARAMETER}, the
9222 type of the variable is set from the type of the constant being
9223 assigned to it).
9224
9225 @node TYPE and ACCEPT I/O Statements
9226 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
9227 @cindex TYPE statement
9228 @cindex statements, TYPE
9229 @cindex ACCEPT statement
9230 @cindex statements, ACCEPT
9231
9232 @command{g77} doesn't support the I/O statements @code{TYPE} and
9233 @code{ACCEPT}.
9234 These are common extensions that should be easy to support,
9235 but also are fairly easy to work around in user code.
9236
9237 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
9238 by @samp{PRINT fmt,list}.
9239 And, any @samp{ACCEPT fmt,list} statement can be
9240 replaced by @samp{READ fmt,list}.
9241
9242 @node STRUCTURE UNION RECORD MAP
9243 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
9244 @cindex STRUCTURE statement
9245 @cindex statements, STRUCTURE
9246 @cindex UNION statement
9247 @cindex statements, UNION
9248 @cindex RECORD statement
9249 @cindex statements, RECORD
9250 @cindex MAP statement
9251 @cindex statements, MAP
9252
9253 @command{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
9254 @code{MAP}.
9255 This set of extensions is quite a bit
9256 lower on the list of large, important things to add to @command{g77}, partly
9257 because it requires a great deal of work either upgrading or
9258 replacing @code{libg2c}.
9259
9260 @node OPEN CLOSE and INQUIRE Keywords
9261 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
9262 @cindex disposition of files
9263 @cindex OPEN statement
9264 @cindex statements, OPEN
9265 @cindex CLOSE statement
9266 @cindex statements, CLOSE
9267 @cindex INQUIRE statement
9268 @cindex statements, INQUIRE
9269
9270 @command{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
9271 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
9272 These extensions are easy to add to @command{g77} itself, but
9273 require much more work on @code{libg2c}.
9274
9275 @cindex FORM='PRINT'
9276 @cindex ANS carriage control
9277 @cindex carriage control
9278 @pindex asa
9279 @pindex fpr
9280 @command{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
9281 translate the traditional `carriage control' characters in column 1 of
9282 output to use backspaces, carriage returns and the like.  However
9283 programs exist to translate them in output files (or standard output).
9284 These are typically called either @command{fpr} or @command{asa}.  You can get
9285 a version of @command{asa} from
9286 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
9287 systems which will probably build easily on other systems.
9288 Alternatively, @command{fpr} is in BSD distributions in various archive
9289 sites.
9290
9291 @c (Can both programs can be used in a pipeline,
9292 @c with a named input file,
9293 @c and/or with a named output file???)
9294
9295 @node ENCODE and DECODE
9296 @subsection @code{ENCODE} and @code{DECODE}
9297 @cindex ENCODE statement
9298 @cindex statements, ENCODE
9299 @cindex DECODE statement
9300 @cindex statements, DECODE
9301
9302 @command{g77} doesn't support @code{ENCODE} or @code{DECODE}.
9303
9304 These statements are best replaced by READ and WRITE statements
9305 involving internal files (CHARACTER variables and arrays).
9306
9307 For example, replace a code fragment like
9308
9309 @smallexample
9310       INTEGER*1 LINE(80)
9311 @dots{}
9312       DECODE (80, 9000, LINE) A, B, C
9313 @dots{}
9314 9000  FORMAT (1X, 3(F10.5))
9315 @end smallexample
9316
9317 @noindent
9318 with:
9319
9320 @smallexample
9321       CHARACTER*80 LINE
9322 @dots{}
9323       READ (UNIT=LINE, FMT=9000) A, B, C
9324 @dots{}
9325 9000  FORMAT (1X, 3(F10.5))
9326 @end smallexample
9327
9328 Similarly, replace a code fragment like
9329
9330 @smallexample
9331       INTEGER*1 LINE(80)
9332 @dots{}
9333       ENCODE (80, 9000, LINE) A, B, C
9334 @dots{}
9335 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
9336 @end smallexample
9337
9338 @noindent
9339 with:
9340
9341 @smallexample
9342       CHARACTER*80 LINE
9343 @dots{}
9344       WRITE (UNIT=LINE, FMT=9000) A, B, C
9345 @dots{}
9346 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
9347 @end smallexample
9348
9349 It is entirely possible that @code{ENCODE} and @code{DECODE} will
9350 be supported by a future version of @command{g77}.
9351
9352 @node AUTOMATIC Statement
9353 @subsection @code{AUTOMATIC} Statement
9354 @cindex @code{AUTOMATIC} statement
9355 @cindex statements, @code{AUTOMATIC}
9356 @cindex automatic variables
9357 @cindex variables, automatic
9358
9359 @command{g77} doesn't support the @code{AUTOMATIC} statement that
9360 @command{f2c} does.
9361
9362 @code{AUTOMATIC} would identify a variable or array
9363 as not being @code{SAVE}'d, which is normally the default,
9364 but which would be especially useful for code that, @emph{generally},
9365 needed to be compiled with the @option{-fno-automatic} option.
9366
9367 @code{AUTOMATIC} also would serve as a hint to the compiler that placing
9368 the variable or array---even a very large array--on the stack is acceptable.
9369
9370 @code{AUTOMATIC} would not, by itself, designate the containing procedure
9371 as recursive.
9372
9373 @code{AUTOMATIC} should work syntactically like @code{SAVE},
9374 in that @code{AUTOMATIC} with no variables listed should apply to
9375 all pertinent variables and arrays
9376 (which would not include common blocks or their members).
9377
9378 Variables and arrays denoted as @code{AUTOMATIC}
9379 would not be permitted to be initialized via @code{DATA}
9380 or other specification of any initial values,
9381 requiring explicit initialization,
9382 such as via assignment statements.
9383
9384 @cindex UNSAVE
9385 @cindex STATIC
9386 Perhaps @code{UNSAVE} and @code{STATIC},
9387 as strict semantic opposites to @code{SAVE} and @code{AUTOMATIC},
9388 should be provided as well.
9389
9390 @node Suppressing Space Padding
9391 @subsection Suppressing Space Padding of Source Lines
9392
9393 @command{g77} should offer VXT-Fortran-style suppression of virtual
9394 spaces at the end of a source line
9395 if an appropriate command-line option is specified.
9396
9397 This affects cases where
9398 a character constant is continued onto the next line in a fixed-form
9399 source file, as in the following example:
9400
9401 @smallexample
9402 10    PRINT *,'HOW MANY
9403      1 SPACES?'
9404 @end smallexample
9405
9406 @noindent
9407 @command{g77}, and many other compilers, virtually extend
9408 the continued line through column 72 with spaces that become part
9409 of the character constant, but Digital Fortran normally didn't,
9410 leaving only one space between @samp{MANY} and @samp{SPACES?}
9411 in the output of the above statement.
9412
9413 Fairly recently, at least one version of Digital Fortran
9414 was enhanced to provide the other behavior when a
9415 command-line option is specified, apparently due to demand
9416 from readers of the USENET group @file{comp.lang.fortran}
9417 to offer conformance to this widespread practice in the
9418 industry.
9419 @command{g77} should return the favor by offering conformance
9420 to Digital's approach to handling the above example.
9421
9422 @node Fortran Preprocessor
9423 @subsection Fortran Preprocessor
9424
9425 @command{g77} should offer a preprocessor designed specifically
9426 for Fortran to replace @samp{cpp -traditional}.
9427 There are several out there worth evaluating, at least.
9428
9429 Such a preprocessor would recognize Hollerith constants,
9430 properly parse comments and character constants, and so on.
9431 It might also recognize, process, and thus preprocess
9432 files included via the @code{INCLUDE} directive.
9433
9434 @node Bit Operations on Floating-point Data
9435 @subsection Bit Operations on Floating-point Data
9436 @cindex @code{And} intrinsic
9437 @cindex intrinsics, @code{And}
9438 @cindex @code{Or} intrinsic
9439 @cindex intrinsics, @code{Or}
9440 @cindex @code{Shift} intrinsic
9441 @cindex intrinsics, @code{Shift}
9442
9443 @command{g77} does not allow @code{REAL} and other non-integral types for
9444 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
9445
9446 For example, this program is rejected by @command{g77}, because
9447 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
9448
9449 @smallexample
9450 DATA A/7.54/, B/9.112/
9451 PRINT *, IAND(A, B)
9452 END
9453 @end smallexample
9454
9455 @node Really Ugly Character Assignments
9456 @subsection Really Ugly Character Assignments
9457
9458 An option such as @option{-fugly-char} should be provided
9459 to allow
9460
9461 @smallexample
9462 REAL*8 A1
9463 DATA A1 / '12345678' /
9464 @end smallexample
9465
9466 and:
9467
9468 @smallexample
9469 REAL*8 A1
9470 A1 = 'ABCDEFGH'
9471 @end smallexample
9472
9473 @node POSIX Standard
9474 @subsection @code{POSIX} Standard
9475
9476 @command{g77} should support the POSIX standard for Fortran.
9477
9478 @node Floating-point Exception Handling
9479 @subsection Floating-point Exception Handling
9480 @cindex floating-point, exceptions
9481 @cindex exceptions, floating-point
9482 @cindex FPE handling
9483 @cindex NaN values
9484
9485 The @command{gcc} backend and, consequently, @command{g77}, currently provides no
9486 general control over whether or not floating-point exceptions are trapped or
9487 ignored.
9488 (Ignoring them typically results in NaN values being
9489 propagated in systems that conform to IEEE 754.)
9490 The behaviour is normally inherited from the system-dependent startup
9491 code, though some targets, such as the Alpha, have code generation
9492 options which change the behaviour.
9493
9494 Most systems provide some C-callable mechanism to change this; this can
9495 be invoked at startup using @command{gcc}'s @code{constructor} attribute.
9496 For example, just compiling and linking the following C code with your
9497 program will turn on exception trapping for the ``common'' exceptions
9498 on a GNU system using glibc 2.2 or newer:
9499
9500 @smallexample
9501 #define _GNU_SOURCE 1
9502 #include <fenv.h>
9503 static void __attribute__ ((constructor))
9504 trapfpe ()
9505 @{
9506   /* Enable some exceptions.  At startup all exceptions are masked.  */
9507   
9508   feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
9509 @}
9510 @end smallexample
9511
9512 A convenient trick is to compile this something like:
9513 @smallexample
9514 gcc -o libtrapfpe.a trapfpe.c
9515 @end smallexample
9516 and then use it by adding @option{-trapfpe} to the @command{g77} command line
9517 when linking.
9518
9519 @node Nonportable Conversions
9520 @subsection Nonportable Conversions
9521 @cindex nonportable conversions
9522 @cindex conversions, nonportable
9523
9524 @command{g77} doesn't accept some particularly nonportable,
9525 silent data-type conversions such as @code{LOGICAL}
9526 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
9527 is type @code{REAL}), that other compilers might
9528 quietly accept.
9529
9530 Some of these conversions are accepted by @command{g77}
9531 when the @option{-fugly-logint} option is specified.
9532 Perhaps it should accept more or all of them.
9533
9534 @node Large Automatic Arrays
9535 @subsection Large Automatic Arrays
9536 @cindex automatic arrays
9537 @cindex arrays, automatic
9538
9539 Currently, automatic arrays always are allocated on the stack.
9540 For situations where the stack cannot be made large enough,
9541 @command{g77} should offer a compiler option that specifies
9542 allocation of automatic arrays in heap storage.
9543
9544 @node Support for Threads
9545 @subsection Support for Threads
9546 @cindex threads
9547 @cindex parallel processing
9548
9549 Neither the code produced by @command{g77} nor the @code{libg2c} library
9550 are thread-safe, nor does @command{g77} have support for parallel processing
9551 (other than the instruction-level parallelism available on some
9552 processors).
9553 A package such as PVM might help here.
9554
9555 @node Enabling Debug Lines
9556 @subsection Enabling Debug Lines
9557 @cindex debug line
9558 @cindex comment line, debug
9559
9560 An option such as @option{-fdebug-lines} should be provided
9561 to turn fixed-form lines beginning with @samp{D}
9562 to be treated as if they began with a space,
9563 instead of as if they began with a @samp{C}
9564 (as comment lines).
9565
9566 @node Better Warnings
9567 @subsection Better Warnings
9568
9569 Because of how @command{g77} generates code via the back end,
9570 it doesn't always provide warnings the user wants.
9571 Consider:
9572
9573 @smallexample
9574 PROGRAM X
9575 PRINT *, A
9576 END
9577 @end smallexample
9578
9579 Currently, the above is not flagged as a case of
9580 using an uninitialized variable,
9581 because @command{g77} generates a run-time library call that looks,
9582 to the GBE, like it might actually @emph{modify} @samp{A} at run time.
9583 (And, in fact, depending on the previous run-time library call,
9584 it would!)
9585
9586 Fixing this requires one of the following:
9587
9588 @itemize @bullet
9589 @item
9590 Switch to new library, @code{libg77}, that provides
9591 a more ``clean'' interface,
9592 vis-a-vis input, output, and modified arguments,
9593 so the GBE can tell what's going on.
9594
9595 This would provide a pretty big performance improvement,
9596 at least theoretically, and, ultimately, in practice,
9597 for some types of code.
9598
9599 @item
9600 Have @command{g77} pass a pointer to a temporary
9601 containing a copy of @samp{A},
9602 instead of to @samp{A} itself.
9603 The GBE would then complain about the copy operation
9604 involving a potentially uninitialized variable.
9605
9606 This might also provide a performance boost for some code,
9607 because @samp{A} might then end up living in a register,
9608 which could help with inner loops.
9609
9610 @item
9611 Have @command{g77} use a GBE construct similar to @code{ADDR_EXPR}
9612 but with extra information on the fact that the
9613 item pointed to won't be modified
9614 (a la @code{const} in C).
9615
9616 Probably the best solution for now, but not quite trivial
9617 to implement in the general case.
9618 Worth considering after @command{g77} 0.6 is considered
9619 pretty solid.
9620 @end itemize
9621
9622 @node Gracefully Handle Sensible Bad Code
9623 @subsection Gracefully Handle Sensible Bad Code
9624
9625 @command{g77} generally should continue processing for
9626 warnings and recoverable (user) errors whenever possible---that
9627 is, it shouldn't gratuitously make bad or useless code.
9628
9629 For example:
9630
9631 @smallexample
9632 INTRINSIC ZABS
9633 CALL FOO(ZABS)
9634 END
9635 @end smallexample
9636
9637 @noindent
9638 When compiling the above with @option{-ff2c-intrinsics-disable},
9639 @command{g77} should indeed complain about passing @code{ZABS},
9640 but it still should compile, instead of rejecting
9641 the entire @code{CALL} statement.
9642 (Some of this is related to improving
9643 the compiler internals to improve how statements are analyzed.)
9644
9645 @node Non-standard Conversions
9646 @subsection Non-standard Conversions
9647
9648 @option{-Wconversion} and related should flag places where non-standard
9649 conversions are found.
9650 Perhaps much of this would be part of @option{-Wugly*}.
9651
9652 @node Non-standard Intrinsics
9653 @subsection Non-standard Intrinsics
9654
9655 @command{g77} needs a new option, like @option{-Wintrinsics}, to warn about use of
9656 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
9657 This would help find code that might fail silently when ported to another
9658 compiler.
9659
9660 @node Modifying DO Variable
9661 @subsection Modifying @code{DO} Variable
9662
9663 @command{g77} should warn about modifying @code{DO} variables
9664 via @code{EQUIVALENCE}.
9665 (The internal information gathered to produce this warning
9666 might also be useful in setting the
9667 internal ``doiter'' flag for a variable or even array
9668 reference within a loop, since that might produce faster code someday.)
9669
9670 For example, this code is invalid, so @command{g77} should warn about
9671 the invalid assignment to @samp{NOTHER}:
9672
9673 @smallexample
9674 EQUIVALENCE (I, NOTHER)
9675 DO I = 1, 100
9676    IF (I.EQ. 10) NOTHER = 20
9677 END DO
9678 @end smallexample
9679
9680 @node Better Pedantic Compilation
9681 @subsection Better Pedantic Compilation
9682
9683 @command{g77} needs to support @option{-fpedantic} more thoroughly,
9684 and use it only to generate
9685 warnings instead of rejecting constructs outright.
9686 Have it warn:
9687 if a variable that dimensions an array is not a dummy or placed
9688 explicitly in @code{COMMON} (F77 does not allow it to be
9689 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
9690 follow statement-function-definition statements; about all sorts of
9691 syntactic extensions.
9692
9693 @node Warn About Implicit Conversions
9694 @subsection Warn About Implicit Conversions
9695
9696 @command{g77} needs a @option{-Wpromotions} option to warn if source code appears
9697 to expect automatic, silent, and
9698 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
9699 constants to @code{REAL(KIND=2)} based on context.
9700
9701 For example, it would warn about cases like this:
9702
9703 @smallexample
9704 DOUBLE PRECISION FOO
9705 PARAMETER (TZPHI = 9.435784839284958)
9706 FOO = TZPHI * 3D0
9707 @end smallexample
9708
9709 @node Invalid Use of Hollerith Constant
9710 @subsection Invalid Use of Hollerith Constant
9711
9712 @command{g77} should disallow statements like @samp{RETURN 2HAB},
9713 which are invalid in both source forms
9714 (unlike @samp{RETURN (2HAB)},
9715 which probably still makes no sense but at least can
9716 be reliably parsed).
9717 Fixed-form processing rejects it, but not free-form, except
9718 in a way that is a bit difficult to understand.
9719
9720 @node Dummy Array Without Dimensioning Dummy
9721 @subsection Dummy Array Without Dimensioning Dummy
9722
9723 @command{g77} should complain when a list of dummy arguments containing an
9724 adjustable dummy array does
9725 not also contain every variable listed in the dimension list of the
9726 adjustable array.
9727
9728 Currently, @command{g77} does complain about a variable that
9729 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
9730 area, but this needs to be extended to catch cases where it doesn't appear in
9731 every dummy list that also lists any arrays it dimensions.
9732
9733 For example, @command{g77} should warn about the entry point @samp{ALT}
9734 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
9735 list of arguments:
9736
9737 @smallexample
9738 SUBROUTINE PRIMARY(ARRAY, ISIZE)
9739 REAL ARRAY(ISIZE)
9740 ENTRY ALT(ARRAY)
9741 @end smallexample
9742
9743 @node Invalid FORMAT Specifiers
9744 @subsection Invalid FORMAT Specifiers
9745
9746 @command{g77} should check @code{FORMAT} specifiers for validity
9747 as it does @code{FORMAT} statements.
9748
9749 For example, a diagnostic would be produced for:
9750
9751 @smallexample
9752 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
9753 @end smallexample
9754
9755 @node Ambiguous Dialects
9756 @subsection Ambiguous Dialects
9757
9758 @command{g77} needs a set of options such as @option{-Wugly*}, @option{-Wautomatic},
9759 @option{-Wvxt}, @option{-Wf90}, and so on.
9760 These would warn about places in the user's source where ambiguities
9761 are found, helpful in resolving ambiguities in the program's
9762 dialect or dialects.
9763
9764 @node Unused Labels
9765 @subsection Unused Labels
9766
9767 @command{g77} should warn about unused labels when @option{-Wunused} is in effect.
9768
9769 @node Informational Messages
9770 @subsection Informational Messages
9771
9772 @command{g77} needs an option to suppress information messages (notes).
9773 @option{-w} does this but also suppresses warnings.
9774 The default should be to suppress info messages.
9775
9776 Perhaps info messages should simply be eliminated.
9777
9778 @node Uninitialized Variables at Run Time
9779 @subsection Uninitialized Variables at Run Time
9780
9781 @command{g77} needs an option to initialize everything (not otherwise
9782 explicitly initialized) to ``weird''
9783 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
9784 largest-magnitude integers, would help track down references to
9785 some kinds of uninitialized variables at run time.
9786
9787 Note that use of the options @samp{-O -Wuninitialized} can catch
9788 many such bugs at compile time.
9789
9790 @node Portable Unformatted Files
9791 @subsection Portable Unformatted Files
9792
9793 @cindex unformatted files
9794 @cindex file formats
9795 @cindex binary data
9796 @cindex byte ordering
9797 @command{g77} has no facility for exchanging unformatted files with systems
9798 using different number formats---even differing only in endianness (byte
9799 order)---or written by other compilers.  Some compilers provide
9800 facilities at least for doing byte-swapping during unformatted I/O.
9801
9802 It is unrealistic to expect to cope with exchanging unformatted files
9803 with arbitrary other compiler runtimes, but the @command{g77} runtime
9804 should at least be able to read files written by @command{g77} on systems
9805 with different number formats, particularly if they differ only in byte
9806 order.
9807
9808 In case you do need to write a program to translate to or from
9809 @command{g77} (@code{libf2c}) unformatted files, they are written as
9810 follows:
9811 @table @asis
9812 @item Sequential
9813 Unformatted sequential records consist of
9814 @enumerate
9815 @item
9816 A number giving the length of the record contents;
9817 @item
9818 the length of record contents again (for backspace).
9819 @end enumerate
9820
9821 The record length is of C type
9822 @code{long}; this means that it is 8 bytes on 64-bit systems such as
9823 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
9824 Consequently such files cannot be exchanged between 64-bit and 32-bit
9825 systems, even with the same basic number format.
9826 @item Direct access
9827 Unformatted direct access files form a byte stream of length
9828 @var{records}*@var{recl} bytes, where @var{records} is the maximum
9829 record number (@code{REC=@var{records}}) written and @var{recl} is the
9830 record length in bytes specified in the @code{OPEN} statement
9831 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
9832 the relevant @code{WRITE} statement.  Dummy records with arbitrary
9833 contents appear in the file in place of records which haven't been
9834 written.
9835 @end table
9836
9837 Thus for exchanging a sequential or direct access unformatted file
9838 between big- and little-endian 32-bit systems using IEEE 754 floating
9839 point it would be sufficient to reverse the bytes in consecutive words
9840 in the file if, and @emph{only} if, only @code{REAL*4}, @code{COMPLEX},
9841 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
9842 @command{g77}.
9843
9844 If necessary, it is possible to do byte-oriented i/o with @command{g77}'s
9845 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
9846 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
9847 array or a set of scalars.
9848
9849 @cindex HDF
9850 @cindex PDB
9851 If you need to exchange binary data between arbitrary system and
9852 compiler variations, we recommend using a portable binary format with
9853 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
9854 or PACT's PDB@footnote{No, not @emph{that} one.}
9855 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
9856 say, CDF or XDR, HDF-like systems write in the native number formats and
9857 only incur overhead when they are read on a system with a different
9858 format.)  A future @command{g77} runtime library should use such
9859 techniques.
9860
9861 @node Better List-directed I/O
9862 @subsection Better List-directed I/O
9863
9864 Values output using list-directed I/O
9865 (@samp{PRINT *, R, D})
9866 should be written with a field width, precision, and so on
9867 appropriate for the type (precision) of each value.
9868
9869 (Currently, no distinction is made between single-precision
9870 and double-precision values
9871 by @code{libf2c}.)
9872
9873 It is likely this item will require the @code{libg77} project
9874 to be undertaken.
9875
9876 In the meantime, use of formatted I/O is recommended.
9877 While it might be of little consolation,
9878 @command{g77} does support @samp{FORMAT(F<WIDTH>.4)}, for example,
9879 as long as @samp{WIDTH} is defined as a named constant
9880 (via @code{PARAMETER}).
9881 That at least allows some compile-time specification
9882 of the precision of a data type,
9883 perhaps controlled by preprocessing directives.
9884
9885 @node Default to Console I/O
9886 @subsection Default to Console I/O
9887
9888 The default I/O units,
9889 specified by @samp{READ @var{fmt}},
9890 @samp{READ (UNIT=*)},
9891 @samp{WRITE (UNIT=*)}, and
9892 @samp{PRINT @var{fmt}},
9893 should not be units 5 (input) and 6 (output),
9894 but, rather, unit numbers not normally available
9895 for use in statements such as @code{OPEN} and @code{CLOSE}.
9896
9897 Changing this would allow a program to connect units 5 and 6
9898 to files via @code{OPEN},
9899 but still use @samp{READ (UNIT=*)} and @samp{PRINT}
9900 to do I/O to the ``console''.
9901
9902 This change probably requires the @code{libg77} project.
9903
9904 @node Labels Visible to Debugger
9905 @subsection Labels Visible to Debugger
9906
9907 @command{g77} should output debugging information for statements labels,
9908 for use by debuggers that know how to support them.
9909 Same with weirder things like construct names.
9910 It is not yet known if any debug formats or debuggers support these.
9911
9912 @node Disappointments
9913 @section Disappointments and Misunderstandings
9914
9915 These problems are perhaps regrettable, but we don't know any practical
9916 way around them for now.
9917
9918 @menu
9919 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
9920                                               external name @samp{foo_}.
9921 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
9922                                               and @samp{SUBROUTINE FOO}.
9923 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
9924 @end menu
9925
9926 @node Mangling of Names
9927 @subsection Mangling of Names in Source Code
9928 @cindex naming issues
9929 @cindex external names
9930 @cindex common blocks
9931 @cindex name space
9932 @cindex underscore
9933
9934 The current external-interface design, which includes naming of
9935 external procedures, COMMON blocks, and the library interface,
9936 has various usability problems, including things like adding
9937 underscores where not really necessary (and preventing easier
9938 inter-language operability) and yet not providing complete
9939 namespace freedom for user C code linked with Fortran apps (due
9940 to the naming of functions in the library, among other things).
9941
9942 Project GNU should at least get all this ``right'' for systems
9943 it fully controls, such as the Hurd, and provide defaults and
9944 options for compatibility with existing systems and interoperability
9945 with popular existing compilers.
9946
9947 @node Multiple Definitions of External Names
9948 @subsection Multiple Definitions of External Names
9949 @cindex block data
9950 @cindex BLOCK DATA statement
9951 @cindex statements, BLOCK DATA
9952 @cindex @code{COMMON} statement
9953 @cindex statements, @code{COMMON}
9954 @cindex naming conflicts
9955
9956 @command{g77} doesn't allow a common block and an external procedure or
9957 @code{BLOCK DATA} to have the same name.
9958 Some systems allow this, but @command{g77} does not,
9959 to be compatible with @command{f2c}.
9960
9961 @command{g77} could special-case the way it handles
9962 @code{BLOCK DATA}, since it is not compatible with @command{f2c} in this
9963 particular area (necessarily, since @command{g77} offers an
9964 important feature here), but
9965 it is likely that such special-casing would be very annoying to people
9966 with programs that use @samp{EXTERNAL FOO}, with no other mention of
9967 @samp{FOO} in the same program unit, to refer to external procedures, since
9968 the result would be that @command{g77} would treat these references as requests to
9969 force-load BLOCK DATA program units.
9970
9971 In that case, if @command{g77} modified
9972 names of @code{BLOCK DATA} so they could have the same names as
9973 @code{COMMON}, users
9974 would find that their programs wouldn't link because the @samp{FOO} procedure
9975 didn't have its name translated the same way.
9976
9977 (Strictly speaking,
9978 @command{g77} could emit a null-but-externally-satisfying definition of
9979 @samp{FOO} with its name transformed as if it had been a
9980 @code{BLOCK DATA}, but that probably invites more trouble than it's
9981 worth.)
9982
9983 @node Limitation on Implicit Declarations
9984 @subsection Limitation on Implicit Declarations
9985 @cindex IMPLICIT CHARACTER*(*) statement
9986 @cindex statements, IMPLICIT CHARACTER*(*)
9987
9988 @command{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
9989 This is not standard-conforming.
9990
9991 @node Non-bugs
9992 @section Certain Changes We Don't Want to Make
9993
9994 This section lists changes that people frequently request, but which
9995 we do not make because we think GNU Fortran is better without them.
9996
9997 @menu
9998 * Backslash in Constants::           Why @samp{'\\'} is a constant that
9999                                        is one, not two, characters long.
10000 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
10001                                        @samp{COMMON VAR}.
10002 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
10003 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
10004                                        single-precision constant,
10005                                        and might be interpreted as
10006                                        @samp{9.435785} or similar.
10007 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
10008 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
10009                                        not behave as expected.
10010 @end menu
10011
10012 @node Backslash in Constants
10013 @subsection Backslash in Constants
10014 @cindex backslash
10015 @cindex @command{f77} support
10016 @cindex support, @command{f77}
10017
10018 In the opinion of many experienced Fortran users,
10019 @option{-fno-backslash} should be the default, not @option{-fbackslash},
10020 as currently set by @command{g77}.
10021
10022 First of all, you can always specify
10023 @option{-fno-backslash} to turn off this processing.
10024
10025 Despite not being within the spirit (though apparently within the
10026 letter) of the ANSI FORTRAN 77 standard, @command{g77} defaults to
10027 @option{-fbackslash} because that is what most UNIX @command{f77} commands
10028 default to, and apparently lots of code depends on this feature.
10029
10030 This is a particularly troubling issue.
10031 The use of a C construct in the midst of Fortran code
10032 is bad enough, worse when it makes existing Fortran
10033 programs stop working (as happens when programs written
10034 for non-UNIX systems are ported to UNIX systems with
10035 compilers that provide the @option{-fbackslash} feature
10036 as the default---sometimes with no option to turn it off).
10037
10038 The author of GNU Fortran wished, for reasons of linguistic
10039 purity, to make @option{-fno-backslash} the default for GNU
10040 Fortran and thus require users of UNIX @command{f77} and @command{f2c}
10041 to specify @option{-fbackslash} to get the UNIX behavior.
10042
10043 However, the realization that @command{g77} is intended as
10044 a replacement for @emph{UNIX} @command{f77}, caused the author
10045 to choose to make @command{g77} as compatible with
10046 @command{f77} as feasible, which meant making @option{-fbackslash}
10047 the default.
10048
10049 The primary focus on compatibility is at the source-code
10050 level, and the question became ``What will users expect
10051 a replacement for @command{f77} to do, by default?''
10052 Although at least one UNIX @command{f77} does not provide
10053 @option{-fbackslash} as a default, it appears that
10054 the majority of them do, which suggests that
10055 the majority of code that is compiled by UNIX @command{f77}
10056 compilers expects @option{-fbackslash} to be the default.
10057
10058 It is probably the case that more code exists
10059 that would @emph{not} work with @option{-fbackslash}
10060 in force than code that requires it be in force.
10061
10062 However, most of @emph{that} code is not being compiled
10063 with @command{f77},
10064 and when it is, new build procedures (shell scripts,
10065 makefiles, and so on) must be set up anyway so that
10066 they work under UNIX.
10067 That makes a much more natural and safe opportunity for
10068 non-UNIX users to adapt their build procedures for
10069 @command{g77}'s default of @option{-fbackslash} than would
10070 exist for the majority of UNIX @command{f77} users who
10071 would have to modify existing, working build procedures
10072 to explicitly specify @option{-fbackslash} if that was
10073 not the default.
10074
10075 One suggestion has been to configure the default for
10076 @option{-fbackslash} (and perhaps other options as well)
10077 based on the configuration of @command{g77}.
10078
10079 This is technically quite straightforward, but will be avoided
10080 even in cases where not configuring defaults to be
10081 dependent on a particular configuration greatly inconveniences
10082 some users of legacy code.
10083
10084 Many users appreciate the GNU compilers because they provide an
10085 environment that is uniform across machines.
10086 These users would be
10087 inconvenienced if the compiler treated things like the
10088 format of the source code differently on certain machines.
10089
10090 Occasionally users write programs intended only for a particular machine
10091 type.
10092 On these occasions, the users would benefit if the GNU Fortran compiler
10093 were to support by default the same dialect as the other compilers on
10094 that machine.
10095 But such applications are rare.
10096 And users writing a
10097 program to run on more than one type of machine cannot possibly benefit
10098 from this kind of compatibility.
10099 (This is consistent with the design goals for @command{gcc}.
10100 To change them for @command{g77}, you must first change them
10101 for @command{gcc}.
10102 Do not ask the maintainers of @command{g77} to do this for you,
10103 or to disassociate @command{g77} from the widely understood, if
10104 not widely agreed-upon, goals for GNU compilers in general.)
10105
10106 This is why GNU Fortran does and will treat backslashes in the same
10107 fashion on all types of machines (by default).
10108 @xref{Direction of Language Development}, for more information on
10109 this overall philosophy guiding the development of the GNU Fortran
10110 language.
10111
10112 Of course, users strongly concerned about portability should indicate
10113 explicitly in their build procedures which options are expected
10114 by their source code, or write source code that has as few such
10115 expectations as possible.
10116
10117 For example, avoid writing code that depends on backslash (@samp{\})
10118 being interpreted either way in particular, such as by
10119 starting a program unit with:
10120
10121 @smallexample
10122 CHARACTER BACKSL
10123 PARAMETER (BACKSL = '\\')
10124 @end smallexample
10125
10126 @noindent
10127 Then, use concatenation of @samp{BACKSL} anyplace a backslash
10128 is desired.
10129 In this way, users can write programs which have the same meaning
10130 in many Fortran dialects.
10131
10132 (However, this technique does not work for Hollerith constants---which
10133 is just as well, since the only generally portable uses for Hollerith
10134 constants are in places where character constants can and should
10135 be used instead, for readability.)
10136
10137 @node Initializing Before Specifying
10138 @subsection Initializing Before Specifying
10139 @cindex initialization, statement placement
10140 @cindex placing initialization statements
10141
10142 @command{g77} does not allow @samp{DATA VAR/1/} to appear in the
10143 source code before @samp{COMMON VAR},
10144 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
10145 In general, @command{g77} requires initialization of a variable
10146 or array to be specified @emph{after} all other specifications
10147 of attributes (type, size, placement, and so on) of that variable
10148 or array are specified (though @emph{confirmation} of data type is
10149 permitted).
10150
10151 It is @emph{possible} @command{g77} will someday allow all of this,
10152 even though it is not allowed by the FORTRAN 77 standard.
10153
10154 Then again, maybe it is better to have
10155 @command{g77} always require placement of @code{DATA}
10156 so that it can possibly immediately write constants
10157 to the output file, thus saving time and space.
10158
10159 That is, @samp{DATA A/1000000*1/} should perhaps always
10160 be immediately writable to canonical assembler, unless it's already known
10161 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
10162 and to do this it cannot be followed by @samp{COMMON A}.
10163
10164 @node Context-Sensitive Intrinsicness
10165 @subsection Context-Sensitive Intrinsicness
10166 @cindex intrinsics, context-sensitive
10167 @cindex context-sensitive intrinsics
10168
10169 @command{g77} treats procedure references to @emph{possible} intrinsic
10170 names as always enabling their intrinsic nature, regardless of
10171 whether the @emph{form} of the reference is valid for that
10172 intrinsic.
10173
10174 For example, @samp{CALL SQRT} is interpreted by @command{g77} as
10175 an invalid reference to the @code{SQRT} intrinsic function,
10176 because the reference is a subroutine invocation.
10177
10178 First, @command{g77} recognizes the statement @samp{CALL SQRT}
10179 as a reference to a @emph{procedure} named @samp{SQRT}, not
10180 to a @emph{variable} with that name (as it would for a statement
10181 such as @samp{V = SQRT}).
10182
10183 Next, @command{g77} establishes that, in the program unit being compiled,
10184 @code{SQRT} is an intrinsic---not a subroutine that
10185 happens to have the same name as an intrinsic (as would be
10186 the case if, for example, @samp{EXTERNAL SQRT} was present).
10187
10188 Finally, @command{g77} recognizes that the @emph{form} of the
10189 reference is invalid for that particular intrinsic.
10190 That is, it recognizes that it is invalid for an intrinsic
10191 @emph{function}, such as @code{SQRT}, to be invoked as
10192 a @emph{subroutine}.
10193
10194 At that point, @command{g77} issues a diagnostic.
10195
10196 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
10197 references an external subroutine of their own, not an
10198 intrinsic function.
10199
10200 However, @command{g77} knows about intrinsic
10201 subroutines, not just functions, and is able to support both having
10202 the same names, for example.
10203
10204 As a result of this, @command{g77} rejects calls
10205 to intrinsics that are not subroutines, and function invocations
10206 of intrinsics that are not functions, just as it (and most compilers)
10207 rejects invocations of intrinsics with the wrong number (or types)
10208 of arguments.
10209
10210 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
10211 a user-written subroutine named @samp{SQRT}.
10212
10213 @node Context-Sensitive Constants
10214 @subsection Context-Sensitive Constants
10215 @cindex constants, context-sensitive
10216 @cindex context-sensitive constants
10217
10218 @command{g77} does not use context to determine the types of
10219 constants or named constants (@code{PARAMETER}), except
10220 for (non-standard) typeless constants such as @samp{'123'O}.
10221
10222 For example, consider the following statement:
10223
10224 @smallexample
10225 PRINT *, 9.435784839284958 * 2D0
10226 @end smallexample
10227
10228 @noindent
10229 @command{g77} will interpret the (truncated) constant
10230 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
10231 constant, because the suffix @code{D0} is not specified.
10232
10233 As a result, the output of the above statement when
10234 compiled by @command{g77} will appear to have ``less precision''
10235 than when compiled by other compilers.
10236
10237 In these and other cases, some compilers detect the
10238 fact that a single-precision constant is used in
10239 a double-precision context and therefore interpret the
10240 single-precision constant as if it was @emph{explicitly}
10241 specified as a double-precision constant.
10242 (This has the effect of appending @emph{decimal}, not
10243 @emph{binary}, zeros to the fractional part of the
10244 number---producing different computational results.)
10245
10246 The reason this misfeature is dangerous is that a slight,
10247 apparently innocuous change to the source code can change
10248 the computational results.
10249 Consider:
10250
10251 @smallexample
10252 REAL ALMOST, CLOSE
10253 DOUBLE PRECISION FIVE
10254 PARAMETER (ALMOST = 5.000000000001)
10255 FIVE = 5
10256 CLOSE = 5.000000000001
10257 PRINT *, 5.000000000001 - FIVE
10258 PRINT *, ALMOST - FIVE
10259 PRINT *, CLOSE - FIVE
10260 END
10261 @end smallexample
10262
10263 @noindent
10264 Running the above program should
10265 result in the same value being
10266 printed three times.
10267 With @command{g77} as the compiler,
10268 it does.
10269
10270 However, compiled by many other compilers,
10271 running the above program would print
10272 two or three distinct values, because
10273 in two or three of the statements, the
10274 constant @samp{5.000000000001}, which
10275 on most systems is exactly equal to @samp{5.}
10276 when interpreted as a single-precision constant,
10277 is instead interpreted as a double-precision
10278 constant, preserving the represented
10279 precision.
10280 However, this ``clever'' promotion of
10281 type does not extend to variables or,
10282 in some compilers, to named constants.
10283
10284 Since programmers often are encouraged to replace manifest
10285 constants or permanently-assigned variables with named
10286 constants (@code{PARAMETER} in Fortran), and might need
10287 to replace some constants with variables having the same
10288 values for pertinent portions of code,
10289 it is important that compilers treat code so modified in the
10290 same way so that the results of such programs are the same.
10291 @command{g77} helps in this regard by treating constants just
10292 the same as variables in terms of determining their types
10293 in a context-independent way.
10294
10295 Still, there is a lot of existing Fortran code that has
10296 been written to depend on the way other compilers freely
10297 interpret constants' types based on context, so anything
10298 @command{g77} can do to help flag cases of this in such code
10299 could be very helpful.
10300
10301 @node Equivalence Versus Equality
10302 @subsection Equivalence Versus Equality
10303 @cindex .EQV., with integer operands
10304 @cindex comparing logical expressions
10305 @cindex logical expressions, comparing
10306
10307 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
10308 is not supported, except via @option{-fugly-logint}, which is not
10309 recommended except for legacy code (where the behavior expected
10310 by the @emph{code} is assumed).
10311
10312 Legacy code should be changed, as resources permit, to use @code{.EQV.}
10313 and @code{.NEQV.} instead, as these are permitted by the various
10314 Fortran standards.
10315
10316 New code should never be written expecting @code{.EQ.} or @code{.NE.}
10317 to work if either of its operands is @code{LOGICAL}.
10318
10319 The problem with supporting this ``feature'' is that there is
10320 unlikely to be consensus on how it works, as illustrated by the
10321 following sample program:
10322
10323 @smallexample
10324 LOGICAL L,M,N
10325 DATA L,M,N /3*.FALSE./
10326 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
10327 END
10328 @end smallexample
10329
10330 The issue raised by the above sample program is: what is the
10331 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
10332 @code{LOGICAL} operands?
10333
10334 Some programmers will argue that it is the same as the precedence
10335 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
10336 operands.
10337 By this interpretation, the subexpression @samp{M.EQ.N} must be
10338 evaluated first in the above program, resulting in a program that,
10339 when run, does not execute the @code{PRINT} statement.
10340
10341 Other programmers will argue that the precedence is the same as
10342 the precedence for @code{.EQV.}, which is restricted by the standards
10343 to @code{LOGICAL} operands.
10344 By this interpretation, the subexpression @samp{L.AND.M} must be
10345 evaluated first, resulting in a program that @emph{does} execute
10346 the @code{PRINT} statement.
10347
10348 Assigning arbitrary semantic interpretations to syntactic expressions
10349 that might legitimately have more than one ``obvious'' interpretation
10350 is generally unwise.
10351
10352 The creators of the various Fortran standards have done a good job
10353 in this case, requiring a distinct set of operators (which have their
10354 own distinct precedence) to compare @code{LOGICAL} operands.
10355 This requirement results in expression syntax with more certain
10356 precedence (without requiring substantial context), making it easier
10357 for programmers to read existing code.
10358 @command{g77} will avoid muddying up elements of the Fortran language
10359 that were well-designed in the first place.
10360
10361 (Ask C programmers about the precedence of expressions such as
10362 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
10363 you, without knowing more context, whether the @samp{&} and @samp{-}
10364 operators are infix (binary) or unary!)
10365
10366 Most dangerous of all is the fact that,
10367 even assuming consensus on its meaning,
10368 an expression like @samp{L.AND.M.EQ.N},
10369 if it is the result of a typographical error,
10370 doesn't @emph{look} like it has such a typo.
10371 Even experienced Fortran programmers would not likely notice that
10372 @samp{L.AND.M.EQV.N} was, in fact, intended.
10373
10374 So, this is a prime example of a circumstance in which
10375 a quality compiler diagnoses the code,
10376 instead of leaving it up to someone debugging it
10377 to know to turn on special compiler options
10378 that might diagnose it.
10379
10380 @node Order of Side Effects
10381 @subsection Order of Side Effects
10382 @cindex side effects, order of evaluation
10383 @cindex order of evaluation, side effects
10384
10385 @command{g77} does not necessarily produce code that, when run, performs
10386 side effects (such as those performed by function invocations)
10387 in the same order as in some other compiler---or even in the same
10388 order as another version, port, or invocation (using different
10389 command-line options) of @command{g77}.
10390
10391 It is never safe to depend on the order of evaluation of side effects.
10392 For example, an expression like this may very well behave differently
10393 from one compiler to another:
10394
10395 @smallexample
10396 J = IFUNC() - IFUNC()
10397 @end smallexample
10398
10399 @noindent
10400 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
10401 order.
10402 Either invocation might happen first.
10403 If @samp{IFUNC} returns 5 the first time it is invoked, and
10404 returns 12 the second time, @samp{J} might end up with the
10405 value @samp{7}, or it might end up with @samp{-7}.
10406
10407 Generally, in Fortran, procedures with side-effects intended to
10408 be visible to the caller are best designed as @emph{subroutines},
10409 not functions.
10410 Examples of such side-effects include:
10411
10412 @itemize @bullet
10413 @item
10414 The generation of random numbers
10415 that are intended to influence return values.
10416
10417 @item
10418 Performing I/O
10419 (other than internal I/O to local variables).
10420
10421 @item
10422 Updating information in common blocks.
10423 @end itemize
10424
10425 An example of a side-effect that is not intended to be visible
10426 to the caller is a function that maintains a cache of recently
10427 calculated results, intended solely to speed repeated invocations
10428 of the function with identical arguments.
10429 Such a function can be safely used in expressions, because
10430 if the compiler optimizes away one or more calls to the
10431 function, operation of the program is unaffected (aside
10432 from being speeded up).
10433
10434 @node Warnings and Errors
10435 @section Warning Messages and Error Messages
10436
10437 @cindex error messages
10438 @cindex warnings vs errors
10439 @cindex messages, warning and error
10440 The GNU compiler can produce two kinds of diagnostics: errors and
10441 warnings.
10442 Each kind has a different purpose:
10443
10444 @itemize @w{}
10445 @item
10446 @emph{Errors} report problems that make it impossible to compile your
10447 program.
10448 GNU Fortran reports errors with the source file name, line
10449 number, and column within the line where the problem is apparent.
10450
10451 @item
10452 @emph{Warnings} report other unusual conditions in your code that
10453 @emph{might} indicate a problem, although compilation can (and does)
10454 proceed.
10455 Warning messages also report the source file name, line number,
10456 and column information,
10457 but include the text @samp{warning:} to distinguish them
10458 from error messages.
10459 @end itemize
10460
10461 Warnings might indicate danger points where you should check to make sure
10462 that your program really does what you intend; or the use of obsolete
10463 features; or the use of nonstandard features of GNU Fortran.
10464 Many warnings are issued only if you ask for them, with one of the
10465 @option{-W} options (for instance, @option{-Wall} requests a variety of
10466 useful warnings).
10467
10468 @emph{Note:} Currently, the text of the line and a pointer to the column
10469 is printed in most @command{g77} diagnostics.
10470 Probably, as of version 0.6, @command{g77} will
10471 no longer print the text of the source line, instead printing
10472 the column number following the file name and line number in
10473 a form that GNU Emacs recognizes.
10474 This change is expected to speed up and reduce the memory usage
10475 of the @command{g77} compiler.
10476 @c
10477 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
10478 @c
10479 @c GNU Fortran always tries to compile your program if possible; it never
10480 @c gratuitously rejects a program whose meaning is clear merely because
10481 @c (for instance) it fails to conform to a standard.  In some cases,
10482 @c however, the Fortran standard specifies that certain extensions are
10483 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
10484 @c compiler.  The @option{-pedantic} option tells GNU Fortran to issue warnings
10485 @c in such cases; @option{-pedantic-errors} says to make them errors instead.
10486 @c This does not mean that @emph{all} non-ANSI constructs get warnings
10487 @c or errors.
10488
10489 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
10490 more detail on these and related command-line options.
10491
10492 @node Open Questions
10493 @chapter Open Questions
10494
10495 Please consider offering useful answers to these questions!
10496
10497 @itemize @bullet
10498 @item
10499 @code{LOC()} and other intrinsics are probably somewhat misclassified.
10500 Is the a need for more precise classification of intrinsics, and if so,
10501 what are the appropriate groupings?
10502 Is there a need to individually
10503 enable/disable/delete/hide intrinsics from the command line?
10504 @end itemize
10505
10506 @node Bugs
10507 @chapter Reporting Bugs
10508 @cindex bugs
10509 @cindex reporting bugs
10510
10511 Your bug reports play an essential role in making GNU Fortran reliable.
10512
10513 When you encounter a problem, the first thing to do is to see if it is
10514 already known.
10515 @xref{Trouble}.
10516 If it isn't known, then you should report the problem.
10517
10518 Reporting a bug might help you by bringing a solution to your problem, or
10519 it might not.
10520 (If it does not, look in the service directory; see
10521 @ref{Service}.)
10522 In any case, the principal function of a bug report is
10523 to help the entire community by making the next version of GNU Fortran work
10524 better.
10525 Bug reports are your contribution to the maintenance of GNU Fortran.
10526
10527 Since the maintainers are very overloaded, we cannot respond to every
10528 bug report.
10529 However, if the bug has not been fixed, we are likely to
10530 send you a patch and ask you to tell us whether it works.
10531
10532 In order for a bug report to serve its purpose, you must include the
10533 information that makes for fixing the bug.
10534
10535 @menu
10536 * Criteria: Bug Criteria.    Have you really found a bug?
10537 * Where: Bug Lists.          Where to send your bug report.
10538 * Reporting: Bug Reporting.  How to report a bug effectively.
10539 @end menu
10540
10541 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
10542 for information on problems we already know about.
10543
10544 @xref{Service,,How To Get Help with GNU Fortran},
10545 for information on where to ask for help.
10546
10547 @node Bug Criteria
10548 @section Have You Found a Bug?
10549 @cindex bug criteria
10550
10551 If you are not sure whether you have found a bug, here are some guidelines:
10552
10553 @itemize @bullet
10554 @cindex fatal signal
10555 @cindex core dump
10556 @item
10557 If the compiler gets a fatal signal, for any input whatever, that is a
10558 compiler bug.
10559 Reliable compilers never crash---they just remain obsolete.
10560
10561 @cindex invalid assembly code
10562 @cindex assembly code, invalid
10563 @item
10564 If the compiler produces invalid assembly code, for any input whatever,
10565 @c (except an @code{asm} statement),
10566 that is a compiler bug, unless the
10567 compiler reports errors (not just warnings) which would ordinarily
10568 prevent the assembler from being run.
10569
10570 @cindex undefined behavior
10571 @cindex undefined function value
10572 @item
10573 If the compiler produces valid assembly code that does not correctly
10574 execute the input source code, that is a compiler bug.
10575
10576 However, you must double-check to make sure, because you might have run
10577 into an incompatibility between GNU Fortran and traditional Fortran.
10578 @c (@pxref{Incompatibilities}).
10579 These incompatibilities might be considered
10580 bugs, but they are inescapable consequences of valuable features.
10581
10582 Or you might have a program whose behavior is undefined, which happened
10583 by chance to give the desired results with another Fortran compiler.
10584 It is best to check the relevant Fortran standard thoroughly if
10585 it is possible that the program indeed does something undefined.
10586
10587 After you have localized the error to a single source line, it should
10588 be easy to check for these things.
10589 If your program is correct and well defined, you have found
10590 a compiler bug.
10591
10592 It might help if, in your submission, you identified the specific
10593 language in the relevant Fortran standard that specifies the
10594 desired behavior, if it isn't likely to be obvious and agreed-upon
10595 by all Fortran users.
10596
10597 @item
10598 If the compiler produces an error message for valid input, that is a
10599 compiler bug.
10600
10601 @cindex invalid input
10602 @item
10603 If the compiler does not produce an error message for invalid input,
10604 that is a compiler bug.
10605 However, you should note that your idea of
10606 ``invalid input'' might be someone else's idea
10607 of ``an extension'' or ``support for traditional practice''.
10608
10609 @item
10610 If you are an experienced user of Fortran compilers, your suggestions
10611 for improvement of GNU Fortran are welcome in any case.
10612 @end itemize
10613
10614 Many, perhaps most, bug reports against @command{g77} turn out to
10615 be bugs in the user's code.
10616 While we find such bug reports educational, they sometimes take
10617 a considerable amount of time to track down or at least respond
10618 to---time we could be spending making @command{g77}, not some user's
10619 code, better.
10620
10621 Some steps you can take to verify that the bug is not certainly
10622 in the code you're compiling with @command{g77}:
10623
10624 @itemize @bullet
10625 @item
10626 Compile your code using the @command{g77} options @samp{-W -Wall -O}.
10627 These options enable many useful warning; the @option{-O} option
10628 enables flow analysis that enables the uninitialized-variable
10629 warning.
10630
10631 If you investigate the warnings and find evidence of possible bugs
10632 in your code, fix them first and retry @command{g77}.
10633
10634 @item
10635 Compile your code using the @command{g77} options @option{-finit-local-zero},
10636 @option{-fno-automatic}, @option{-ffloat-store}, and various
10637 combinations thereof.
10638
10639 If your code works with any of these combinations, that is not
10640 proof that the bug isn't in @command{g77}---a @command{g77} bug exposed
10641 by your code might simply be avoided, or have a different, more subtle
10642 effect, when different options are used---but it can be a
10643 strong indicator that your code is making unwarranted assumptions
10644 about the Fortran dialect and/or underlying machine it is
10645 being compiled and run on.
10646
10647 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10648 for information on the @option{-fno-automatic} and
10649 @option{-finit-local-zero} options and how to convert
10650 their use into selective changes in your own code.
10651
10652 @item
10653 @pindex ftnchek
10654 Validate your code with @command{ftnchek} or a similar code-checking
10655 tool.
10656 @command{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
10657 or @uref{ftp://ftp.dsm.fordham.edu}.
10658
10659 @pindex make
10660 @cindex Makefile example
10661 Here are some sample @file{Makefile} rules using @command{ftnchek}
10662 ``project'' files to do cross-file checking and @command{sfmakedepend}
10663 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
10664 to maintain dependencies automatically.
10665 These assume the use of GNU @command{make}.
10666
10667 @smallexample
10668 # Dummy suffix for ftnchek targets:
10669 .SUFFIXES: .chek
10670 .PHONY: chekall
10671
10672 # How to compile .f files (for implicit rule):
10673 FC = g77
10674 # Assume `include' directory:
10675 FFLAGS = -Iinclude -g -O -Wall
10676
10677 # Flags for ftnchek:
10678 CHEK1 = -array=0 -include=includes -noarray
10679 CHEK2 = -nonovice -usage=1 -notruncation
10680 CHEKFLAGS = $(CHEK1) $(CHEK2)
10681
10682 # Run ftnchek with all the .prj files except the one corresponding
10683 # to the target's root:
10684 %.chek : %.f ; \
10685   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
10686     -noextern -library $<
10687
10688 # Derive a project file from a source file:
10689 %.prj : %.f ; \
10690   ftnchek $(CHEKFLAGS) -noextern -project -library $<
10691
10692 # The list of objects is assumed to be in variable OBJS.
10693 # Sources corresponding to the objects:
10694 SRCS = $(OBJS:%.o=%.f)
10695 # ftnchek project files:
10696 PRJS = $(OBJS:%.o=%.prj)
10697
10698 # Build the program
10699 prog: $(OBJS) ; \
10700   $(FC) -o $@ $(OBJS)
10701
10702 chekall: $(PRJS) ; \
10703   ftnchek $(CHEKFLAGS) $(PRJS)
10704
10705 prjs: $(PRJS)
10706
10707 # For Emacs M-x find-tag:
10708 TAGS: $(SRCS) ; \
10709   etags $(SRCS)
10710
10711 # Rebuild dependencies:
10712 depend: ; \
10713   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
10714 @end smallexample
10715
10716 @item
10717 Try your code out using other Fortran compilers, such as @command{f2c}.
10718 If it does not work on at least one other compiler (assuming the
10719 compiler supports the features the code needs), that is a strong
10720 indicator of a bug in the code.
10721
10722 However, even if your code works on many compilers @emph{except}
10723 @command{g77}, that does @emph{not} mean the bug is in @command{g77}.
10724 It might mean the bug is in your code, and that @command{g77} simply
10725 exposes it more readily than other compilers.
10726 @end itemize
10727
10728 @node Bug Lists
10729 @section Where to Report Bugs
10730 @cindex bug report mailing lists
10731 @kindex @value{email-bugs}
10732 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
10733
10734 Often people think of posting bug reports to a newsgroup instead of
10735 mailing them.
10736 This sometimes appears to work, but it has one problem which can be
10737 crucial: a newsgroup posting does not contain a mail path back to the
10738 sender.
10739 Thus, if maintainers need more information, they might be unable
10740 to reach you.  For this reason, you should always send bug reports by
10741 mail to the proper mailing list.
10742
10743 As a last resort, send bug reports on paper to:
10744
10745 @example
10746 GNU Compiler Bugs
10747 Free Software Foundation
10748 59 Temple Place - Suite 330
10749 Boston, MA 02111-1307, USA
10750 @end example
10751
10752 @node Bug Reporting
10753 @section How to Report Bugs
10754 @cindex compiler bugs, reporting
10755
10756 The fundamental principle of reporting bugs usefully is this:
10757 @strong{report all the facts}.
10758 If you are not sure whether to state a
10759 fact or leave it out, state it!
10760
10761 Often people omit facts because they think they know what causes the
10762 problem and they conclude that some details don't matter.
10763 Thus, you might
10764 assume that the name of the variable you use in an example does not matter.
10765 Well, probably it doesn't, but one cannot be sure.
10766 Perhaps the bug is a
10767 stray memory reference which happens to fetch from the location where that
10768 name is stored in memory; perhaps, if the name were different, the contents
10769 of that location would fool the compiler into doing the right thing despite
10770 the bug.
10771 Play it safe and give a specific, complete example.
10772 That is the
10773 easiest thing for you to do, and the most helpful.
10774
10775 Keep in mind that the purpose of a bug report is to enable someone to
10776 fix the bug if it is not known.
10777 It isn't very important what happens if
10778 the bug is already known.
10779 Therefore, always write your bug reports on
10780 the assumption that the bug is not known.
10781
10782 Sometimes people give a few sketchy facts and ask, ``Does this ring a
10783 bell?''
10784 This cannot help us fix a bug, so it is rarely helpful.
10785 We respond by asking for enough details to enable us to investigate.
10786 You might as well expedite matters by sending them to begin with.
10787 (Besides, there are enough bells ringing around here as it is.)
10788
10789 Try to make your bug report self-contained.
10790 If we have to ask you for
10791 more information, it is best if you include all the previous information
10792 in your response, as well as the information that was missing.
10793
10794 Please report each bug in a separate message.
10795 This makes it easier for
10796 us to track which bugs have been fixed and to forward your bugs reports
10797 to the appropriate maintainer.
10798
10799 Do not compress and encode any part of your bug report using programs
10800 such as @file{uuencode}.
10801 If you do so it will slow down the processing
10802 of your bug.
10803 If you must submit multiple large files, use @file{shar},
10804 which allows us to read your message without having to run any
10805 decompression programs.
10806
10807 (As a special exception for GNU Fortran bug-reporting, at least
10808 for now, if you are sending more than a few lines of code, if
10809 your program's source file format contains ``interesting'' things
10810 like trailing spaces or strange characters, or if you need to
10811 include binary data files, it is acceptable to put all the
10812 files together in a @command{tar} archive, and, whether you need to
10813 do that, it is acceptable to then compress the single file (@command{tar}
10814 archive or source file)
10815 using @command{gzip} and encode it via @command{uuencode}.
10816 Do not use any MIME stuff---the current maintainer can't decode this.
10817 Using @command{compress} instead of @command{gzip} is acceptable, assuming
10818 you have licensed the use of the patented algorithm in
10819 @command{compress} from Unisys.)
10820
10821 To enable someone to investigate the bug, you should include all these
10822 things:
10823
10824 @itemize @bullet
10825 @item
10826 The version of GNU Fortran.
10827 You can get this by running @command{g77} with the @option{-v} option.
10828 (Ignore any error messages that might be displayed
10829 when the linker is run.)
10830
10831 Without this, we won't know whether there is any point in looking for
10832 the bug in the current version of GNU Fortran.
10833
10834 @item
10835 @cindex preprocessor
10836 @cindex cpp program
10837 @cindex programs, cpp
10838 @pindex cpp
10839 A complete input file that will reproduce the bug.
10840
10841 If your source file(s) require preprocessing
10842 (for example, their names have suffixes like
10843 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
10844 and the bug is in the compiler proper (@file{f771})
10845 or in a subsequent phase of processing,
10846 run your source file through the C preprocessor
10847 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
10848 Then, include the contents of @var{newfile} in the bug report.
10849 (When you do this, use the same preprocessor options---such as
10850 @option{-I}, @option{-D}, and @option{-U}---that you used in actual
10851 compilation.)
10852
10853 A single statement is not enough of an example.
10854 In order to compile it,
10855 it must be embedded in a complete file of compiler input.
10856 The bug might depend on the details of how this is done.
10857
10858 Without a real example one can compile,
10859 all anyone can do about your bug report is wish you luck.
10860 It would be futile to try to guess how to provoke the bug.
10861 For example, bugs in register allocation and reloading
10862 can depend on every little detail of the source and include files
10863 that trigger them.
10864
10865 @item
10866 @cindex included files
10867 @cindex INCLUDE directive
10868 @cindex directive, INCLUDE
10869 @cindex #include directive
10870 @cindex directive, #include
10871 Note that you should include with your bug report any files
10872 included by the source file
10873 (via the @code{#include} or @code{INCLUDE} directive)
10874 that you send, and any files they include, and so on.
10875
10876 It is not necessary to replace
10877 the @code{#include} and @code{INCLUDE} directives
10878 with the actual files in the version of the source file that
10879 you send, but it might make submitting the bug report easier
10880 in the end.
10881 However, be sure to @emph{reproduce} the bug using the @emph{exact}
10882 version of the source material you submit, to avoid wild-goose
10883 chases.
10884
10885 @item
10886 The command arguments you gave GNU Fortran to compile that example
10887 and observe the bug.  For example, did you use @option{-O}?  To guarantee
10888 you won't omit something important, list all the options.
10889
10890 If we were to try to guess the arguments, we would probably guess wrong
10891 and then we would not encounter the bug.
10892
10893 @item
10894 The type of machine you are using, and the operating system name and
10895 version number.
10896 (Much of this information is printed by @samp{g77 -v}---if you
10897 include that, send along any additional info you have that you
10898 don't see clearly represented in that output.)
10899
10900 @item
10901 The operands you gave to the @command{configure} command when you installed
10902 the compiler.
10903
10904 @item
10905 A complete list of any modifications you have made to the compiler
10906 source.  (We don't promise to investigate the bug unless it happens in
10907 an unmodified compiler.  But if you've made modifications and don't tell
10908 us, then you are sending us on a wild-goose chase.)
10909
10910 Be precise about these changes.  A description in English is not
10911 enough---send a context diff for them.
10912
10913 Adding files of your own (such as a machine description for a machine we
10914 don't support) is a modification of the compiler source.
10915
10916 @item
10917 Details of any other deviations from the standard procedure for installing
10918 GNU Fortran.
10919
10920 @item
10921 A description of what behavior you observe that you believe is
10922 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
10923 ``The assembler instruction at line 208 in the output is incorrect.''
10924
10925 Of course, if the bug is that the compiler gets a fatal signal, then one
10926 can't miss it.  But if the bug is incorrect output, the maintainer might
10927 not notice unless it is glaringly wrong.  None of us has time to study
10928 all the assembler code from a 50-line Fortran program just on the chance that
10929 one instruction might be wrong.  We need @emph{you} to do this part!
10930
10931 Even if the problem you experience is a fatal signal, you should still
10932 say so explicitly.  Suppose something strange is going on, such as, your
10933 copy of the compiler is out of synch, or you have encountered a bug in
10934 the C library on your system.  (This has happened!)  Your copy might
10935 crash and the copy here would not.  If you @i{said} to expect a crash,
10936 then when the compiler here fails to crash, we would know that the bug
10937 was not happening.  If you don't say to expect a crash, then we would
10938 not know whether the bug was happening.  We would not be able to draw
10939 any conclusion from our observations.
10940
10941 If the problem is a diagnostic when building GNU Fortran with some other
10942 compiler, say whether it is a warning or an error.
10943
10944 Often the observed symptom is incorrect output when your program is run.
10945 Sad to say, this is not enough information unless the program is short
10946 and simple.  None of us has time to study a large program to figure out
10947 how it would work if compiled correctly, much less which line of it was
10948 compiled wrong.  So you will have to do that.  Tell us which source line
10949 it is, and what incorrect result happens when that line is executed.  A
10950 person who understands the program can find this as easily as finding a
10951 bug in the program itself.
10952
10953 @item
10954 If you send examples of assembler code output from GNU Fortran,
10955 please use @option{-g} when you make them.  The debugging information
10956 includes source line numbers which are essential for correlating the
10957 output with the input.
10958
10959 @item
10960 If you wish to mention something in the GNU Fortran source, refer to it by
10961 context, not by line number.
10962
10963 The line numbers in the development sources don't match those in your
10964 sources.  Your line numbers would convey no convenient information to the
10965 maintainers.
10966
10967 @item
10968 Additional information from a debugger might enable someone to find a
10969 problem on a machine which he does not have available.  However, you
10970 need to think when you collect this information if you want it to have
10971 any chance of being useful.
10972
10973 @cindex backtrace for bug reports
10974 For example, many people send just a backtrace, but that is never
10975 useful by itself.  A simple backtrace with arguments conveys little
10976 about GNU Fortran because the compiler is largely data-driven; the same
10977 functions are called over and over for different RTL insns, doing
10978 different things depending on the details of the insn.
10979
10980 Most of the arguments listed in the backtrace are useless because they
10981 are pointers to RTL list structure.  The numeric values of the
10982 pointers, which the debugger prints in the backtrace, have no
10983 significance whatever; all that matters is the contents of the objects
10984 they point to (and most of the contents are other such pointers).
10985
10986 In addition, most compiler passes consist of one or more loops that
10987 scan the RTL insn sequence.  The most vital piece of information about
10988 such a loop---which insn it has reached---is usually in a local variable,
10989 not in an argument.
10990
10991 @findex debug_rtx
10992 What you need to provide in addition to a backtrace are the values of
10993 the local variables for several stack frames up.  When a local
10994 variable or an argument is an RTX, first print its value and then use
10995 the GDB command @command{pr} to print the RTL expression that it points
10996 to.  (If GDB doesn't run on your machine, use your debugger to call
10997 the function @code{debug_rtx} with the RTX as an argument.)  In
10998 general, whenever a variable is a pointer, its value is no use
10999 without the data it points to.
11000 @end itemize
11001
11002 Here are some things that are not necessary:
11003
11004 @itemize @bullet
11005 @item
11006 A description of the envelope of the bug.
11007
11008 Often people who encounter a bug spend a lot of time investigating
11009 which changes to the input file will make the bug go away and which
11010 changes will not affect it.
11011
11012 This is often time consuming and not very useful, because the way we
11013 will find the bug is by running a single example under the debugger with
11014 breakpoints, not by pure deduction from a series of examples.  You might
11015 as well save your time for something else.
11016
11017 Of course, if you can find a simpler example to report @emph{instead} of
11018 the original one, that is a convenience.  Errors in the output will be
11019 easier to spot, running under the debugger will take less time, etc.
11020 Most GNU Fortran bugs involve just one function, so the most straightforward
11021 way to simplify an example is to delete all the function definitions
11022 except the one where the bug occurs.  Those earlier in the file may be
11023 replaced by external declarations if the crucial function depends on
11024 them.  (Exception: inline functions might affect compilation of functions
11025 defined later in the file.)
11026
11027 However, simplification is not vital; if you don't want to do this,
11028 report the bug anyway and send the entire test case you used.
11029
11030 @item
11031 In particular, some people insert conditionals @samp{#ifdef BUG} around
11032 a statement which, if removed, makes the bug not happen.  These are just
11033 clutter; we won't pay any attention to them anyway.  Besides, you should
11034 send us preprocessor output, and that can't have conditionals.
11035
11036 @item
11037 A patch for the bug.
11038
11039 A patch for the bug is useful if it is a good one.  But don't omit the
11040 necessary information, such as the test case, on the assumption that a
11041 patch is all we need.  We might see problems with your patch and decide
11042 to fix the problem another way, or we might not understand it at all.
11043
11044 Sometimes with a program as complicated as GNU Fortran it is very hard to
11045 construct an example that will make the program follow a certain path
11046 through the code.  If you don't send the example, we won't be able to
11047 construct one, so we won't be able to verify that the bug is fixed.
11048
11049 And if we can't understand what bug you are trying to fix, or why your
11050 patch should be an improvement, we won't install it.  A test case will
11051 help us to understand.
11052
11053 See @uref{http://gcc.gnu.org/contribute.html}
11054 for guidelines on how to make it easy for us to
11055 understand and install your patches.
11056
11057 @item
11058 A guess about what the bug is or what it depends on.
11059
11060 Such guesses are usually wrong.  Even the maintainer can't guess right
11061 about such things without first using the debugger to find the facts.
11062
11063 @item
11064 A core dump file.
11065
11066 We have no way of examining a core dump for your type of machine
11067 unless we have an identical system---and if we do have one,
11068 we should be able to reproduce the crash ourselves.
11069 @end itemize
11070
11071 @node Service
11072 @chapter How To Get Help with GNU Fortran
11073
11074 If you need help installing, using or changing GNU Fortran, there are two
11075 ways to find it:
11076
11077 @itemize @bullet
11078 @item
11079 Look in the service directory for someone who might help you for a fee.
11080 The service directory is found in the file named @file{SERVICE} in the
11081 GNU CC distribution.
11082
11083 @item
11084 Send a message to @email{@value{email-help}}.
11085 @end itemize
11086
11087 @end ifset
11088 @ifset INTERNALS
11089 @node Adding Options
11090 @chapter Adding Options
11091 @cindex options, adding
11092 @cindex adding options
11093
11094 To add a new command-line option to @command{g77}, first decide
11095 what kind of option you wish to add.
11096 Search the @command{g77} and @command{gcc} documentation for one
11097 or more options that is most closely like the one you want to add
11098 (in terms of what kind of effect it has, and so on) to
11099 help clarify its nature.
11100
11101 @itemize @bullet
11102 @item
11103 @emph{Fortran options} are options that apply only
11104 when compiling Fortran programs.
11105 They are accepted by @command{g77} and @command{gcc}, but
11106 they apply only when compiling Fortran programs.
11107
11108 @item
11109 @emph{Compiler options} are options that apply
11110 when compiling most any kind of program.
11111 @end itemize
11112
11113 @emph{Fortran options} are listed in the file
11114 @file{@value{path-g77}/lang-options.h},
11115 which is used during the build of @command{gcc} to
11116 build a list of all options that are accepted by
11117 at least one language's compiler.
11118 This list goes into the @code{documented_lang_options} array
11119 in @file{gcc/toplev.c}, which uses this array to
11120 determine whether a particular option should be
11121 offered to the linked-in front end for processing
11122 by calling @code{lang_option_decode}, which, for
11123 @command{g77}, is in @file{@value{path-g77}/com.c} and just
11124 calls @code{ffe_decode_option}.
11125
11126 If the linked-in front end ``rejects'' a
11127 particular option passed to it, @file{toplev.c}
11128 just ignores the option, because @emph{some}
11129 language's compiler is willing to accept it.
11130
11131 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
11132 to work, even though Fortran compilation does
11133 not currently support the @option{-fno-asm} option;
11134 even though the @code{f771} version of @code{lang_decode_option}
11135 rejects @option{-fno-asm}, @file{toplev.c} doesn't
11136 produce a diagnostic because some other language (C)
11137 does accept it.
11138
11139 This also means that commands like
11140 @samp{g77 -fno-asm foo.f} yield no diagnostics,
11141 despite the fact that no phase of the command was
11142 able to recognize and process @option{-fno-asm}---perhaps
11143 a warning about this would be helpful if it were
11144 possible.
11145
11146 Code that processes Fortran options is found in
11147 @file{@value{path-g77}/top.c}, function @code{ffe_decode_option}.
11148 This code needs to check positive and negative forms
11149 of each option.
11150
11151 The defaults for Fortran options are set in their
11152 global definitions, also found in @file{@value{path-g77}/top.c}.
11153 Many of these defaults are actually macros defined
11154 in @file{@value{path-g77}/target.h}, since they might be
11155 machine-specific.
11156 However, since, in practice, GNU compilers
11157 should behave the same way on all configurations
11158 (especially when it comes to language constructs),
11159 the practice of setting defaults in @file{target.h}
11160 is likely to be deprecated and, ultimately, stopped
11161 in future versions of @command{g77}.
11162
11163 Accessor macros for Fortran options, used by code
11164 in the @command{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
11165
11166 @emph{Compiler options} are listed in @file{gcc/toplev.c}
11167 in the array @code{f_options}.
11168 An option not listed in @code{lang_options} is
11169 looked up in @code{f_options} and handled from there.
11170
11171 The defaults for compiler options are set in the
11172 global definitions for the corresponding variables,
11173 some of which are in @file{gcc/toplev.c}.
11174
11175 You can set different defaults for @emph{Fortran-oriented}
11176 or @emph{Fortran-reticent} compiler options by changing
11177 the source code of @command{g77} and rebuilding.
11178 How to do this depends on the version of @command{g77}:
11179
11180 @table @code
11181 @item G77 0.5.24 (EGCS 1.1)
11182 @itemx G77 0.5.25 (EGCS 1.2 - which became GCC 2.95)
11183 Change the @code{lang_init_options} routine in @file{gcc/gcc/f/com.c}.
11184
11185 (Note that these versions of @command{g77}
11186 perform internal consistency checking automatically
11187 when the @option{-fversion} option is specified.)
11188
11189 @item G77 0.5.23
11190 @itemx G77 0.5.24 (EGCS 1.0)
11191 Change the way @code{f771} handles the @option{-fset-g77-defaults}
11192 option, which is always provided as the first option when
11193 called by @command{g77} or @command{gcc}.
11194
11195 This code is in @code{ffe_decode_options} in @file{@value{path-g77}/top.c}.
11196 Have it change just the variables that you want to default
11197 to a different setting for Fortran compiles compared to
11198 compiles of other languages.
11199
11200 The @option{-fset-g77-defaults} option is passed to @code{f771}
11201 automatically because of the specification information
11202 kept in @file{@value{path-g77}/lang-specs.h}.
11203 This file tells the @command{gcc} command how to recognize,
11204 in this case, Fortran source files (those to be preprocessed,
11205 and those that are not), and further, how to invoke the
11206 appropriate programs (including @code{f771}) to process
11207 those source files.
11208
11209 It is in @file{@value{path-g77}/lang-specs.h} that @option{-fset-g77-defaults},
11210 @option{-fversion}, and other options are passed, as appropriate,
11211 even when the user has not explicitly specified them.
11212 Other ``internal'' options such as @option{-quiet} also
11213 are passed via this mechanism.
11214 @end table
11215
11216 @node Projects
11217 @chapter Projects
11218 @cindex projects
11219
11220 If you want to contribute to @command{g77} by doing research,
11221 design, specification, documentation, coding, or testing,
11222 the following information should give you some ideas.
11223 More relevant information might be available from
11224 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
11225
11226 @menu
11227 * Efficiency::               Make @command{g77} itself compile code faster.
11228 * Better Optimization::      Teach @command{g77} to generate faster code.
11229 * Simplify Porting::         Make @command{g77} easier to configure, build,
11230                              and install.
11231 * More Extensions::          Features many users won't know to ask for.
11232 * Machine Model::            @command{g77} should better leverage @command{gcc}.
11233 * Internals Documentation::  Make maintenance easier.
11234 * Internals Improvements::   Make internals more robust.
11235 * Better Diagnostics::       Make using @command{g77} on new code easier.
11236 @end menu
11237
11238 @node Efficiency
11239 @section Improve Efficiency
11240 @cindex efficiency
11241
11242 Don't bother doing any performance analysis until most of the
11243 following items are taken care of, because there's no question
11244 they represent serious space/time problems, although some of
11245 them show up only given certain kinds of (popular) input.
11246
11247 @itemize @bullet
11248 @item
11249 Improve @code{malloc} package and its uses to specify more info about
11250 memory pools and, where feasible, use obstacks to implement them.
11251
11252 @item
11253 Skip over uninitialized portions of aggregate areas (arrays,
11254 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
11255 This would reduce memory usage for large initialized aggregate
11256 areas, even ones with only one initialized element.
11257
11258 As of version 0.5.18, a portion of this item has already been
11259 accomplished.
11260
11261 @item
11262 Prescan the statement (in @file{sta.c}) so that the nature of the statement
11263 is determined as much as possible by looking entirely at its form,
11264 and not looking at any context (previous statements, including types
11265 of symbols).
11266 This would allow ripping out of the statement-confirmation,
11267 symbol retraction/confirmation, and diagnostic inhibition
11268 mechanisms.
11269 Plus, it would result in much-improved diagnostics.
11270 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
11271 is not a subroutine intrinsic, would result actual error instead of the
11272 unimplemented-statement catch-all.
11273
11274 @item
11275 Throughout @command{g77}, don't pass line/column pairs where
11276 a simple @code{ffewhere} type, which points to the error as much as is
11277 desired by the configuration, will do, and don't pass @code{ffelexToken} types
11278 where a simple @code{ffewhere} type will do.
11279 Then, allow new default
11280 configuration of @code{ffewhere} such that the source line text is not
11281 preserved, and leave it to things like Emacs' next-error function
11282 to point to them (now that @samp{next-error} supports column,
11283 or, perhaps, character-offset, numbers).
11284 The change in calling sequences should improve performance somewhat,
11285 as should not having to save source lines.
11286 (Whether this whole
11287 item will improve performance is questionable, but it should
11288 improve maintainability.)
11289
11290 @item
11291 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
11292 as regards the assembly output.
11293 Some of this might require improving
11294 the back end, but lots of improvement in space/time required in @command{g77}
11295 itself can be fairly easily obtained without touching the back end.
11296 Maybe type-conversion, where necessary, can be speeded up as well in
11297 cases like the one shown (converting the @samp{2} into @samp{2.}).
11298
11299 @item
11300 If analysis shows it to be worthwhile, optimize @file{lex.c}.
11301
11302 @item
11303 Consider redesigning @file{lex.c} to not need any feedback
11304 during tokenization, by keeping track of enough parse state on its
11305 own.
11306 @end itemize
11307
11308 @node Better Optimization
11309 @section Better Optimization
11310 @cindex optimization, better
11311 @cindex code generation, improving
11312
11313 Much of this work should be put off until after @command{g77} has
11314 all the features necessary for its widespread acceptance as a
11315 useful F77 compiler.
11316 However, perhaps this work can be done in parallel during
11317 the feature-adding work.
11318
11319 @itemize @bullet
11320 @item
11321 Do the equivalent of the trick of putting @samp{extern inline} in front
11322 of every function definition in @code{libg2c} and #include'ing the resulting
11323 file in @command{f2c}+@command{gcc}---that is, inline all run-time-library functions
11324 that are at all worth inlining.
11325 (Some of this has already been done, such as for integral exponentiation.)
11326
11327 @item
11328 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
11329 and it's clear that types line up
11330 and @samp{CHAR_VAR} is addressable or not a @code{VAR_DECL},
11331 make @samp{CHAR_VAR}, not a
11332 temporary, be the receiver for @samp{CHAR_FUNC}.
11333 (This is now done for @code{COMPLEX} variables.)
11334
11335 @item
11336 Design and implement Fortran-specific optimizations that don't
11337 really belong in the back end, or where the front end needs to
11338 give the back end more info than it currently does.
11339
11340 @item
11341 Design and implement a new run-time library interface, with the
11342 code going into @code{libgcc} so no special linking is required to
11343 link Fortran programs using standard language features.
11344 This library
11345 would speed up lots of things, from I/O (using precompiled formats,
11346 doing just one, or, at most, very few, calls for arrays or array sections,
11347 and so on) to general computing (array/section implementations of
11348 various intrinsics, implementation of commonly performed loops that
11349 aren't likely to be optimally compiled otherwise, etc.).
11350
11351 Among the important things the library would do are:
11352
11353 @itemize @bullet
11354 @item
11355 Be a one-stop-shop-type
11356 library, hence shareable and usable by all, in that what are now
11357 library-build-time options in @code{libg2c} would be moved at least to the
11358 @command{g77} compile phase, if not to finer grains (such as choosing how
11359 list-directed I/O formatting is done by default at @code{OPEN} time, for
11360 preconnected units via options or even statements in the main program
11361 unit, maybe even on a per-I/O basis with appropriate pragma-like
11362 devices).
11363 @end itemize
11364
11365 @item
11366 Probably requiring the new library design, change interface to
11367 normally have @code{COMPLEX} functions return their values in the way
11368 @command{gcc} would if they were declared @code{__complex__ float},
11369 rather than using
11370 the mechanism currently used by @code{CHARACTER} functions (whereby the
11371 functions are compiled as returning void and their first arg is
11372 a pointer to where to store the result).
11373 (Don't append underscores to
11374 external names for @code{COMPLEX} functions in some cases once @command{g77} uses
11375 @command{gcc} rather than @command{f2c} calling conventions.)
11376
11377 @item
11378 Do something useful with @code{doiter} references where possible.
11379 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
11380 a @code{DO} loop that uses @samp{I} as the
11381 iteration variable, and the back end might find that info useful
11382 in determining whether it needs to read @samp{I} back into a register after
11383 the call.
11384 (It normally has to do that, unless it knows @samp{FOO} never
11385 modifies its passed-by-reference argument, which is rarely the case
11386 for Fortran-77 code.)
11387 @end itemize
11388
11389 @node Simplify Porting
11390 @section Simplify Porting
11391 @cindex porting, simplify
11392 @cindex simplify porting
11393
11394 Making @command{g77} easier to configure, port, build, and install, either
11395 as a single-system compiler or as a cross-compiler, would be
11396 very useful.
11397
11398 @itemize @bullet
11399 @item
11400 A new library (replacing @code{libg2c}) should improve portability as well as
11401 produce more optimal code.
11402 Further, @command{g77} and the new library should
11403 conspire to simplify naming of externals, such as by removing unnecessarily
11404 added underscores, and to reduce/eliminate the possibility of naming
11405 conflicts, while making debugger more straightforward.
11406
11407 Also, it should
11408 make multi-language applications more feasible, such as by providing
11409 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
11410 descriptors.
11411
11412 @item
11413 Possibly related to a new library, @command{g77} should produce the equivalent
11414 of a @command{gcc} @samp{main(argc, argv)} function when it compiles a
11415 main program unit, instead of compiling something that must be
11416 called by a library
11417 implementation of @code{main()}.
11418
11419 This would do many useful things such as
11420 provide more flexibility in terms of setting up exception handling,
11421 not requiring programmers to start their debugging sessions with
11422 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
11423
11424 @item
11425 The GBE needs to understand the difference between alignment
11426 requirements and desires.
11427 For example, on Intel x86 machines, @command{g77} currently imposes
11428 overly strict alignment requirements, due to the back end, but it
11429 would be useful for Fortran and C programmers to be able to override
11430 these @emph{recommendations} as long as they don't violate the actual
11431 processor @emph{requirements}.
11432 @end itemize
11433
11434 @node More Extensions
11435 @section More Extensions
11436 @cindex extensions, more
11437
11438 These extensions are not the sort of things users ask for ``by name'',
11439 but they might improve the usability of @command{g77}, and Fortran in
11440 general, in the long run.
11441 Some of these items really pertain to improving @command{g77} internals
11442 so that some popular extensions can be more easily supported.
11443
11444 @itemize @bullet
11445 @item
11446 Look through all the documentation on the GNU Fortran language,
11447 dialects, compiler, missing features, bugs, and so on.
11448 Many mentions of incomplete or missing features are
11449 sprinkled throughout.
11450 It is not worth repeating them here.
11451
11452 @item
11453 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
11454 named and unnamed.
11455 The idea is to provide a forward-looking, effective
11456 replacement for things like the old-style @code{PARAMETER} statement
11457 when people
11458 really need typelessness in a maintainable, portable, clearly documented
11459 way.
11460 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
11461 and whatever else might come along.
11462 (This is not really a call for polymorphism per se, just
11463 an ability to express limited, syntactic polymorphism.)
11464
11465 @item
11466 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
11467
11468 @item
11469 Support arbitrary file unit numbers, instead of limiting them
11470 to 0 through @samp{MXUNIT-1}.
11471 (This is a @code{libg2c} issue.)
11472
11473 @item
11474 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
11475 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
11476 later @code{UNIT=} in the first example is invalid.
11477 Make sure this is what users of this feature would expect.
11478
11479 @item
11480 Currently @command{g77} disallows @samp{READ(1'10)} since
11481 it is an obnoxious syntax, but
11482 supporting it might be pretty easy if needed.
11483 More details are needed, such
11484 as whether general expressions separated by an apostrophe are supported,
11485 or maybe the record number can be a general expression, and so on.
11486
11487 @item
11488 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
11489 fully.
11490 Currently there is no support at all
11491 for @code{%FILL} in @code{STRUCTURE} and related syntax,
11492 whereas the rest of the
11493 stuff has at least some parsing support.
11494 This requires either major
11495 changes to @code{libg2c} or its replacement.
11496
11497 @item
11498 F90 and @command{g77} probably disagree about label scoping relative to
11499 @code{INTERFACE} and @code{END INTERFACE}, and their contained
11500 procedure interface bodies (blocks?).
11501
11502 @item
11503 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
11504 since that was added after S8.112.
11505
11506 @item
11507 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
11508 with the final form of the standard (it was vague at S8.112).
11509
11510 @item
11511 It seems to be an ``open'' question whether a file, immediately after being
11512 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
11513 might be nice to offer an option of opening to ``undefined'' status, requiring
11514 an explicit absolute-positioning operation to be performed before any
11515 other (besides @code{CLOSE}) to assist in making applications port to systems
11516 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
11517 @end itemize
11518
11519 @node Machine Model
11520 @section Machine Model
11521
11522 This items pertain to generalizing @command{g77}'s view of
11523 the machine model to more fully accept whatever the GBE
11524 provides it via its configuration.
11525
11526 @itemize @bullet
11527 @item
11528 Switch to using @code{REAL_VALUE_TYPE} to represent floating-point constants
11529 exclusively so the target float format need not be required.
11530 This
11531 means changing the way @command{g77} handles initialization of aggregate areas
11532 having more than one type, such as @code{REAL} and @code{INTEGER},
11533 because currently
11534 it initializes them as if they were arrays of @code{char} and uses the
11535 bit patterns of the constants of the various types in them to determine
11536 what to stuff in elements of the arrays.
11537
11538 @item
11539 Rely more and more on back-end info and capabilities, especially in the
11540 area of constants (where having the @command{g77} front-end's IL just store
11541 the appropriate tree nodes containing constants might be best).
11542
11543 @item
11544 Suite of C and Fortran programs that a user/administrator can run on a
11545 machine to help determine the configuration for @command{g77} before building
11546 and help determine if the compiler works (especially with whatever
11547 libraries are installed) after building.
11548 @end itemize
11549
11550 @node Internals Documentation
11551 @section Internals Documentation
11552
11553 Better info on how @command{g77} works and how to port it is needed.
11554 Much of this should be done only after the redesign planned for
11555 0.6 is complete.
11556
11557 @xref{Front End}, which contains some information
11558 on @command{g77} internals.
11559
11560 @node Internals Improvements
11561 @section Internals Improvements
11562
11563 Some more items that would make @command{g77} more reliable
11564 and easier to maintain:
11565
11566 @itemize @bullet
11567 @item
11568 Generally make expression handling focus
11569 more on critical syntax stuff, leaving semantics to callers.
11570 For example,
11571 anything a caller can check, semantically, let it do so, rather
11572 than having @file{expr.c} do it.
11573 (Exceptions might include things like
11574 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
11575 it seems
11576 important to preserve the left-to-right-in-source order of production
11577 of diagnostics.)
11578
11579 @item
11580 Come up with better naming conventions for @option{-D} to establish requirements
11581 to achieve desired implementation dialect via @file{proj.h}.
11582
11583 @item
11584 Clean up used tokens and @code{ffewhere}s in @code{ffeglobal_terminate_1}.
11585
11586 @item
11587 Replace @file{sta.c} @code{outpooldisp} mechanism with @code{malloc_pool_use}.
11588
11589 @item
11590 Check for @code{opANY} in more places in @file{com.c}, @file{std.c},
11591 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
11592 (after determining if there is indeed no real need for it).
11593
11594 @item
11595 Utility to read and check @file{bad.def} messages and their references in the
11596 code, to make sure calls are consistent with message templates.
11597
11598 @item
11599 Search and fix @samp{&ffe@dots{}} and similar so that
11600 @samp{ffe@dots{}ptr@dots{}} macros are
11601 available instead (a good argument for wishing this could have written all
11602 this stuff in C++, perhaps).
11603 On the other hand, it's questionable whether this sort of
11604 improvement is really necessary, given the availability of
11605 tools such as Emacs and Perl, which make finding any
11606 address-taking of structure members easy enough?
11607
11608 @item
11609 Some modules truly export the member names of their structures (and the
11610 structures themselves), maybe fix this, and fix other modules that just
11611 appear to as well (by appending @samp{_}, though it'd be ugly and probably
11612 not worth the time).
11613
11614 @item
11615 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
11616 in @file{proj.h}
11617 and use them throughout @command{g77} source code (especially in the definitions
11618 of access macros in @samp{.h} files) so they can be tailored
11619 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
11620
11621 @item
11622 Decorate throughout with @code{const} and other such stuff.
11623
11624 @item
11625 All F90 notational derivations in the source code are still based
11626 on the S8.112 version of the draft standard.
11627 Probably should update
11628 to the official standard, or put documentation of the rules as used
11629 in the code@dots{}uh@dots{}in the code.
11630
11631 @item
11632 Some @code{ffebld_new} calls (those outside of @file{ffeexpr.c} or
11633 inside but invoked via paths not involving @code{ffeexpr_lhs} or
11634 @code{ffeexpr_rhs}) might be creating things
11635 in improper pools, leading to such things staying around too long or
11636 (doubtful, but possible and dangerous) not long enough.
11637
11638 @item
11639 Some @code{ffebld_list_new} (or whatever) calls might not be matched by
11640 @code{ffebld_list_bottom} (or whatever) calls, which might someday matter.
11641 (It definitely is not a problem just yet.)
11642
11643 @item
11644 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
11645 due to alignment/mismatch or other problems---they end up without
11646 @code{ffestorag} objects, so maybe the backend (and other parts of the front
11647 end) can notice that and handle like an @code{opANY} (do what it wants, just
11648 don't complain or crash).
11649 Most of this seems to have been addressed
11650 by now, but a code review wouldn't hurt.
11651 @end itemize
11652
11653 @node Better Diagnostics
11654 @section Better Diagnostics
11655
11656 These are things users might not ask about, or that need to
11657 be looked into, before worrying about.
11658 Also here are items that involve reducing unnecessary diagnostic
11659 clutter.
11660
11661 @itemize @bullet
11662 @item
11663 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
11664 lengths, type classes, and so on),
11665 @code{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
11666 it specifies.
11667
11668 @item
11669 Speed up and improve error handling for data when repeat-count is
11670 specified.
11671 For example, don't output 20 unnecessary messages after the
11672 first necessary one for:
11673
11674 @smallexample
11675 INTEGER X(20)
11676 CONTINUE
11677 DATA (X(I), J= 1, 20) /20*5/
11678 END
11679 @end smallexample
11680
11681 @noindent
11682 (The @code{CONTINUE} statement ensures the @code{DATA} statement
11683 is processed in the context of executable, not specification,
11684 statements.)
11685 @end itemize
11686
11687 @include ffe.texi
11688
11689 @end ifset
11690
11691 @ifset USING
11692 @node Diagnostics
11693 @chapter Diagnostics
11694 @cindex diagnostics
11695
11696 Some diagnostics produced by @command{g77} require sufficient explanation
11697 that the explanations are given below, and the diagnostics themselves
11698 identify the appropriate explanation.
11699
11700 Identification uses the GNU Info format---specifically, the @command{info}
11701 command that displays the explanation is given within square
11702 brackets in the diagnostic.
11703 For example:
11704
11705 @smallexample
11706 foo.f:5: Invalid statement [info -f g77 M FOOEY]
11707 @end smallexample
11708
11709 More details about the above diagnostic is found in the @command{g77} Info
11710 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
11711 which is displayed by typing the UNIX command
11712 @samp{info -f g77 M FOOEY}.
11713
11714 Other Info readers, such as EMACS, may be just as easily used to display
11715 the pertinent node.
11716 In the above example, @samp{g77} is the Info document name,
11717 @samp{M} is the top-level menu item to select,
11718 and, in that node (named @samp{Diagnostics}, the name of
11719 this chapter, which is the very text you're reading now),
11720 @samp{FOOEY} is the menu item to select.
11721
11722 @iftex
11723 In this printed version of the @command{g77} manual, the above example
11724 points to a section, below, entitled @samp{FOOEY}---though, of course,
11725 as the above is just a sample, no such section exists.
11726 @end iftex
11727
11728 @menu
11729 * CMPAMBIG::    Ambiguous use of intrinsic.
11730 * EXPIMP::      Intrinsic used explicitly and implicitly.
11731 * INTGLOB::     Intrinsic also used as name of global.
11732 * LEX::         Various lexer messages
11733 * GLOBALS::     Disagreements about globals.
11734 * LINKFAIL::    When linking @code{f771} fails.
11735 * Y2KBAD::      Use of non-Y2K-compliant intrinsic.
11736 @end menu
11737
11738 @node CMPAMBIG
11739 @section @code{CMPAMBIG}
11740
11741 @noindent
11742 @smallexample
11743 Ambiguous use of intrinsic @var{intrinsic} @dots{}
11744 @end smallexample
11745
11746 The type of the argument to the invocation of the @var{intrinsic}
11747 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
11748 Typically, it is @code{COMPLEX(KIND=2)}, also known as
11749 @code{DOUBLE COMPLEX}.
11750
11751 The interpretation of this invocation depends on the particular
11752 dialect of Fortran for which the code was written.
11753 Some dialects convert the real part of the argument to
11754 @code{REAL(KIND=1)}, thus losing precision; other dialects,
11755 and Fortran 90, do no such conversion.
11756
11757 So, GNU Fortran rejects such invocations except under certain
11758 circumstances, to avoid making an incorrect assumption that results
11759 in generating the wrong code.
11760
11761 To determine the dialect of the program unit, perhaps even whether
11762 that particular invocation is properly coded, determine how the
11763 result of the intrinsic is used.
11764
11765 The result of @var{intrinsic} is expected (by the original programmer)
11766 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
11767
11768 @itemize @bullet
11769 @item
11770 It is passed as an argument to a procedure that explicitly or
11771 implicitly declares that argument @code{REAL(KIND=1)}.
11772
11773 For example,
11774 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
11775 statement specifying the dummy argument corresponding to an
11776 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
11777 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
11778 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
11779 of @code{REAL(KIND=2)}.
11780
11781 @item
11782 It is used in a context that would otherwise not include
11783 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
11784 invocation as @code{REAL(KIND=2)} would result in unnecessary
11785 promotions and (typically) more expensive operations on the
11786 wider type.
11787
11788 For example:
11789
11790 @smallexample
11791 DOUBLE COMPLEX Z
11792 @dots{}
11793 R(1) = T * REAL(Z)
11794 @end smallexample
11795
11796 The above example suggests the programmer expected the real part
11797 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
11798 multiplied by @samp{T} (presumed, along with @samp{R} above, to
11799 be type @code{REAL(KIND=1)}).
11800
11801 Otherwise, the conversion would have to be delayed until after
11802 the multiplication, requiring not only an extra conversion
11803 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
11804 expensive multiplication (a double-precision multiplication instead
11805 of a single-precision one).
11806 @end itemize
11807
11808 The result of @var{intrinsic} is expected (by the original programmer)
11809 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
11810
11811 @itemize @bullet
11812 @item
11813 It is passed as an argument to a procedure that explicitly or
11814 implicitly declares that argument @code{REAL(KIND=2)}.
11815
11816 For example, a procedure specifying a @code{DOUBLE PRECISION}
11817 dummy argument corresponding to an
11818 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
11819 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
11820 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
11821 of @code{REAL(KIND=1)}.
11822
11823 @item
11824 It is used in an expression context that includes
11825 other @code{REAL(KIND=2)} operands,
11826 or is assigned to a @code{REAL(KIND=2)} variable or array element.
11827
11828 For example:
11829
11830 @smallexample
11831 DOUBLE COMPLEX Z
11832 DOUBLE PRECISION R, T
11833 @dots{}
11834 R(1) = T * REAL(Z)
11835 @end smallexample
11836
11837 The above example suggests the programmer expected the real part
11838 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
11839 by the @code{REAL()} intrinsic.
11840
11841 Otherwise, the conversion would have to be immediately followed
11842 by a conversion back to @code{REAL(KIND=2)}, losing
11843 the original, full precision of the real part of @code{Z},
11844 before being multiplied by @samp{T}.
11845 @end itemize
11846
11847 Once you have determined whether a particular invocation of @var{intrinsic}
11848 expects the Fortran 90 interpretation, you can:
11849
11850 @itemize @bullet
11851 @item
11852 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
11853 @code{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
11854 is @code{AIMAG})
11855 if it expected the Fortran 90 interpretation.
11856
11857 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
11858 some other type, such as @code{COMPLEX*32}, you should use the
11859 appropriate intrinsic, such as the one to convert to @code{REAL*16}
11860 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
11861 @code{QIMAG()} in place of @code{DIMAG()}).
11862
11863 @item
11864 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
11865 otherwise.
11866 This converts to @code{REAL(KIND=1)} in all working
11867 Fortran compilers.
11868 @end itemize
11869
11870 If you don't want to change the code, and you are certain that all
11871 ambiguous invocations of @var{intrinsic} in the source file have
11872 the same expectation regarding interpretation, you can:
11873
11874 @itemize @bullet
11875 @item
11876 Compile with the @command{g77} option @option{-ff90}, to enable the
11877 Fortran 90 interpretation.
11878
11879 @item
11880 Compile with the @command{g77} options @samp{-fno-f90 -fugly-complex},
11881 to enable the non-Fortran-90 interpretations.
11882 @end itemize
11883
11884 @xref{REAL() and AIMAG() of Complex}, for more information on this
11885 issue.
11886
11887 Note: If the above suggestions don't produce enough evidence
11888 as to whether a particular program expects the Fortran 90
11889 interpretation of this ambiguous invocation of @var{intrinsic},
11890 there is one more thing you can try.
11891
11892 If you have access to most or all the compilers used on the
11893 program to create successfully tested and deployed executables,
11894 read the documentation for, and @emph{also} test out, each compiler
11895 to determine how it treats the @var{intrinsic} intrinsic in
11896 this case.
11897 (If all the compilers don't agree on an interpretation, there
11898 might be lurking bugs in the deployed versions of the program.)
11899
11900 The following sample program might help:
11901
11902 @cindex JCB003 program
11903 @smallexample
11904       PROGRAM JCB003
11905 C
11906 C Written by James Craig Burley 1997-02-23.
11907 C
11908 C Determine how compilers handle non-standard REAL
11909 C and AIMAG on DOUBLE COMPLEX operands.
11910 C
11911       DOUBLE COMPLEX Z
11912       REAL R
11913       Z = (3.3D0, 4.4D0)
11914       R = Z
11915       CALL DUMDUM(Z, R)
11916       R = REAL(Z) - R
11917       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
11918       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
11919       R = 4.4D0
11920       CALL DUMDUM(Z, R)
11921       R = AIMAG(Z) - R
11922       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
11923       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
11924       END
11925 C
11926 C Just to make sure compiler doesn't use naive flow
11927 C analysis to optimize away careful work above,
11928 C which might invalidate results....
11929 C
11930       SUBROUTINE DUMDUM(Z, R)
11931       DOUBLE COMPLEX Z
11932       REAL R
11933       END
11934 @end smallexample
11935
11936 If the above program prints contradictory results on a
11937 particular compiler, run away!
11938
11939 @node EXPIMP
11940 @section @code{EXPIMP}
11941
11942 @noindent
11943 @smallexample
11944 Intrinsic @var{intrinsic} referenced @dots{}
11945 @end smallexample
11946
11947 The @var{intrinsic} is explicitly declared in one program
11948 unit in the source file and implicitly used as an intrinsic
11949 in another program unit in the same source file.
11950
11951 This diagnostic is designed to catch cases where a program
11952 might depend on using the name @var{intrinsic} as an intrinsic
11953 in one program unit and as a global name (such as the name
11954 of a subroutine or function) in another, but @command{g77} recognizes
11955 the name as an intrinsic in both cases.
11956
11957 After verifying that the program unit making implicit use
11958 of the intrinsic is indeed written expecting the intrinsic,
11959 add an @samp{INTRINSIC @var{intrinsic}} statement to that
11960 program unit to prevent this warning.
11961
11962 This and related warnings are disabled by using
11963 the @option{-Wno-globals} option when compiling.
11964
11965 Note that this warning is not issued for standard intrinsics.
11966 Standard intrinsics include those described in the FORTRAN 77
11967 standard and, if @option{-ff90} is specified, those described
11968 in the Fortran 90 standard.
11969 Such intrinsics are not as likely to be confused with user
11970 procedures as intrinsics provided as extensions to the
11971 standard by @command{g77}.
11972
11973 @node INTGLOB
11974 @section @code{INTGLOB}
11975
11976 @noindent
11977 @smallexample
11978 Same name `@var{intrinsic}' given @dots{}
11979 @end smallexample
11980
11981 The name @var{intrinsic} is used for a global entity (a common
11982 block or a program unit) in one program unit and implicitly
11983 used as an intrinsic in another program unit.
11984
11985 This diagnostic is designed to catch cases where a program
11986 intends to use a name entirely as a global name, but @command{g77}
11987 recognizes the name as an intrinsic in the program unit that
11988 references the name, a situation that would likely produce
11989 incorrect code.
11990
11991 For example:
11992
11993 @smallexample
11994 INTEGER FUNCTION TIME()
11995 @dots{}
11996 END
11997 @dots{}
11998 PROGRAM SAMP
11999 INTEGER TIME
12000 PRINT *, 'Time is ', TIME()
12001 END
12002 @end smallexample
12003
12004 The above example defines a program unit named @samp{TIME}, but
12005 the reference to @samp{TIME} in the main program unit @samp{SAMP}
12006 is normally treated by @command{g77} as a reference to the intrinsic
12007 @code{TIME()} (unless a command-line option that prevents such
12008 treatment has been specified).
12009
12010 As a result, the program @samp{SAMP} will @emph{not}
12011 invoke the @samp{TIME} function in the same source file.
12012
12013 Since @command{g77} recognizes @code{libU77} procedures as
12014 intrinsics, and since some existing code uses the same names
12015 for its own procedures as used by some @code{libU77}
12016 procedures, this situation is expected to arise often enough
12017 to make this sort of warning worth issuing.
12018
12019 After verifying that the program unit making implicit use
12020 of the intrinsic is indeed written expecting the intrinsic,
12021 add an @samp{INTRINSIC @var{intrinsic}} statement to that
12022 program unit to prevent this warning.
12023
12024 Or, if you believe the program unit is designed to invoke the
12025 program-defined procedure instead of the intrinsic (as
12026 recognized by @command{g77}), add an @samp{EXTERNAL @var{intrinsic}}
12027 statement to the program unit that references the name to
12028 prevent this warning.
12029
12030 This and related warnings are disabled by using
12031 the @option{-Wno-globals} option when compiling.
12032
12033 Note that this warning is not issued for standard intrinsics.
12034 Standard intrinsics include those described in the FORTRAN 77
12035 standard and, if @option{-ff90} is specified, those described
12036 in the Fortran 90 standard.
12037 Such intrinsics are not as likely to be confused with user
12038 procedures as intrinsics provided as extensions to the
12039 standard by @command{g77}.
12040
12041 @node LEX
12042 @section @code{LEX}
12043
12044 @noindent
12045 @smallexample
12046 Unrecognized character @dots{}
12047 Invalid first character @dots{}
12048 Line too long @dots{}
12049 Non-numeric character @dots{}
12050 Continuation indicator @dots{}
12051 Label at @dots{} invalid with continuation line indicator @dots{}
12052 Character constant @dots{}
12053 Continuation line @dots{}
12054 Statement at @dots{} begins with invalid token
12055 @end smallexample
12056
12057 Although the diagnostics identify specific problems, they can
12058 be produced when general problems such as the following occur:
12059
12060 @itemize @bullet
12061 @item
12062 The source file contains something other than Fortran code.
12063
12064 If the code in the file does not look like many of the examples
12065 elsewhere in this document, it might not be Fortran code.
12066 (Note that Fortran code often is written in lower case letters,
12067 while the examples in this document use upper case letters,
12068 for stylistic reasons.)
12069
12070 For example, if the file contains lots of strange-looking
12071 characters, it might be APL source code; if it contains lots
12072 of parentheses, it might be Lisp source code; if it
12073 contains lots of bugs, it might be C++ source code.
12074
12075 @item
12076 The source file contains free-form Fortran code, but @option{-ffree-form}
12077 was not specified on the command line to compile it.
12078
12079 Free form is a newer form for Fortran code.
12080 The older, classic form is called fixed form.
12081
12082 @cindex continuation character
12083 @cindex characters, continuation
12084 Fixed-form code is visually fairly distinctive, because
12085 numerical labels and comments are all that appear in
12086 the first five columns of a line, the sixth column is
12087 reserved to denote continuation lines,
12088 and actual statements start at or beyond column 7.
12089 Spaces generally are not significant, so if you
12090 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
12091 you are looking at fixed-form code.
12092 @cindex *
12093 @cindex asterisk
12094 Comment lines are indicated by the letter @samp{C} or the symbol
12095 @samp{*} in column 1.
12096 @cindex trailing comment
12097 @cindex comment
12098 @cindex characters, comment
12099 @cindex !
12100 @cindex exclamation point
12101 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
12102 which many compilers support.)
12103
12104 Free-form code is distinguished from fixed-form source
12105 primarily by the fact that statements may start anywhere.
12106 (If lots of statements start in columns 1 through 6,
12107 that's a strong indicator of free-form source.)
12108 Consecutive keywords must be separated by spaces, so
12109 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
12110 There are no comment lines per se, but @samp{!} starts a
12111 comment anywhere in a line (other than within a character or
12112 Hollerith constant).
12113
12114 @xref{Source Form}, for more information.
12115
12116 @item
12117 The source file is in fixed form and has been edited without
12118 sensitivity to the column requirements.
12119
12120 Statements in fixed-form code must be entirely contained within
12121 columns 7 through 72 on a given line.
12122 Starting them ``early'' is more likely to result in diagnostics
12123 than finishing them ``late'', though both kinds of errors are
12124 often caught at compile time.
12125
12126 For example, if the following code fragment is edited by following
12127 the commented instructions literally, the result, shown afterward,
12128 would produce a diagnostic when compiled:
12129
12130 @smallexample
12131 C On XYZZY systems, remove "C" on next line:
12132 C     CALL XYZZY_RESET
12133 @end smallexample
12134
12135 The result of editing the above line might be:
12136
12137 @smallexample
12138 C On XYZZY systems, remove "C" on next line:
12139      CALL XYZZY_RESET
12140 @end smallexample
12141
12142 However, that leaves the first @samp{C} in the @code{CALL}
12143 statement in column 6, making it a comment line, which is
12144 not really what the author intended, and which is likely
12145 to result in one of the above-listed diagnostics.
12146
12147 @emph{Replacing} the @samp{C} in column 1 with a space
12148 is the proper change to make, to ensure the @code{CALL}
12149 keyword starts in or after column 7.
12150
12151 Another common mistake like this is to forget that fixed-form
12152 source lines are significant through only column 72, and that,
12153 normally, any text beyond column 72 is ignored or is diagnosed
12154 at compile time.
12155
12156 @xref{Source Form}, for more information.
12157
12158 @item
12159 The source file requires preprocessing, and the preprocessing
12160 is not being specified at compile time.
12161
12162 A source file containing lines beginning with @code{#define},
12163 @code{#include}, @code{#if}, and so on is likely one that
12164 requires preprocessing.
12165
12166 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
12167 the file normally will be compiled @emph{without} preprocessing
12168 by @command{g77}.
12169
12170 Change the file's suffix from @samp{.f} to @samp{.F}
12171 (or, on systems with case-insensitive file names,
12172 to @samp{.fpp} or @samp{.FPP}),
12173 from @samp{.for} to @samp{.fpp},
12174 or from @samp{.FOR} to @samp{.FPP}.
12175 @command{g77} compiles files with such names @emph{with}
12176 preprocessing.
12177
12178 @pindex cpp
12179 @cindex preprocessor
12180 @cindex cpp program
12181 @cindex programs, cpp
12182 @cindex @option{-x f77-cpp-input} option
12183 @cindex options, @option{-x f77-cpp-input}
12184 Or, learn how to use @command{gcc}'s @option{-x} option to specify
12185 the language @samp{f77-cpp-input} for Fortran files that
12186 require preprocessing.
12187 @xref{Overall Options,,Options Controlling the Kind of
12188 Output,gcc,Using the GNU Compiler Collection (GCC)}.
12189
12190 @item
12191 The source file is preprocessed, and the results of preprocessing
12192 result in syntactic errors that are not necessarily obvious to
12193 someone examining the source file itself.
12194
12195 Examples of errors resulting from preprocessor macro expansion
12196 include exceeding the line-length limit, improperly starting,
12197 terminating, or incorporating the apostrophe or double-quote in
12198 a character constant, improperly forming a Hollerith constant,
12199 and so on.
12200
12201 @xref{Overall Options,,Options Controlling the Kind of Output},
12202 for suggestions about how to use, and not use, preprocessing
12203 for Fortran code.
12204 @end itemize
12205
12206 @node GLOBALS
12207 @section @code{GLOBALS}
12208
12209 @noindent
12210 @smallexample
12211 Global name @var{name} defined at @dots{} already defined@dots{}
12212 Global name @var{name} at @dots{} has different type@dots{}
12213 Too many arguments passed to @var{name} at @dots{}
12214 Too few arguments passed to @var{name} at @dots{}
12215 Argument #@var{n} of @var{name} is @dots{}
12216 @end smallexample
12217
12218 These messages all identify disagreements about the
12219 global procedure named @var{name} among different program units
12220 (usually including @var{name} itself).
12221
12222 Whether a particular disagreement is reported
12223 as a warning or an error
12224 can depend on the relative order
12225 of the disagreeing portions of the source file.
12226
12227 Disagreements between a procedure invocation
12228 and the @emph{subsequent} procedure itself
12229 are, usually, diagnosed as errors
12230 when the procedure itself @emph{precedes} the invocation.
12231 Other disagreements are diagnosed via warnings.
12232
12233 @cindex forward references
12234 @cindex in-line code
12235 @cindex compilation, in-line
12236 This distinction, between warnings and errors,
12237 is due primarily to the present tendency of the @command{gcc} back end
12238 to inline only those procedure invocations that are
12239 @emph{preceded} by the corresponding procedure definitions.
12240 If the @command{gcc} back end is changed
12241 to inline ``forward references'',
12242 in which invocations precede definitions,
12243 the @command{g77} front end will be changed
12244 to treat both orderings as errors, accordingly.
12245
12246 The sorts of disagreements that are diagnosed by @command{g77} include
12247 whether a procedure is a subroutine or function;
12248 if it is a function, the type of the return value of the procedure;
12249 the number of arguments the procedure accepts;
12250 and the type of each argument.
12251
12252 Disagreements regarding global names among program units
12253 in a Fortran program @emph{should} be fixed in the code itself.
12254 However, if that is not immediately practical,
12255 and the code has been working for some time,
12256 it is possible it will work
12257 when compiled with the @option{-fno-globals} option.
12258
12259 The @option{-fno-globals} option
12260 causes these diagnostics to all be warnings
12261 and disables all inlining of references to global procedures
12262 (to avoid subsequent compiler crashes and bad-code generation).
12263 Use of the @option{-Wno-globals} option as well as @option{-fno-globals}
12264 suppresses all of these diagnostics.
12265 (@option{-Wno-globals} by itself disables only the warnings,
12266 not the errors.)
12267
12268 After using @option{-fno-globals} to work around these problems,
12269 it is wise to stop using that option and address them by fixing
12270 the Fortran code, because such problems, while they might not
12271 actually result in bugs on some systems, indicate that the code
12272 is not as portable as it could be.
12273 In particular, the code might appear to work on a particular
12274 system, but have bugs that affect the reliability of the data
12275 without exhibiting any other outward manifestations of the bugs.
12276
12277 @node LINKFAIL
12278 @section @code{LINKFAIL}
12279
12280 @noindent
12281 On AIX 4.1, @command{g77} might not build with the native (non-GNU) tools
12282 due to a linker bug in coping with the @option{-bbigtoc} option which
12283 leads to a @samp{Relocation overflow} error.  The GNU linker is not
12284 recommended on current AIX versions, though; it was developed under a
12285 now-unsupported version.  This bug is said to be fixed by `update PTF
12286 U455193 for APAR IX75823'.
12287
12288 Compiling with @option{-mminimal-toc}
12289 might solve this problem, e.g.@: by adding
12290 @smallexample
12291 BOOT_CFLAGS='-mminimal-toc -O2 -g'
12292 @end smallexample
12293 to the @code{make bootstrap} command line.
12294
12295 @node Y2KBAD
12296 @section @code{Y2KBAD}
12297 @cindex Y2K compliance
12298 @cindex Year 2000 compliance
12299
12300 @noindent
12301 @smallexample
12302 Intrinsic `@var{name}', invoked at (^), known to be non-Y2K-compliant@dots{}
12303 @end smallexample
12304
12305 This diagnostic indicates that
12306 the specific intrinsic invoked by the name @var{name}
12307 is known to have an interface
12308 that is not Year-2000 (Y2K) compliant.
12309
12310 @xref{Year 2000 (Y2K) Problems}.
12311
12312 @end ifset
12313
12314 @node Index
12315 @unnumbered Index
12316
12317 @printindex cp
12318 @bye