OSDN Git Service

* invoke.texi: Use @gol at ends of lines inside @gccoptlist.
[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 2002-04-29
6 @set copyrights-g77 1995,1996,1997,1998,1999,2000,2001,2002
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{which-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.
363
364 @item
365 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
366 and encouraged Craig to rewrite the documentation in texinfo
367 format by contributing a first pass at a translation of the
368 old @file{g77-0.5.16/f/DOC} file.
369
370 @item
371 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
372 some analysis of generated code as part of an overall project
373 to improve @command{g77} code generation to at least be as good
374 as @command{f2c} used in conjunction with @command{gcc}.
375 So far, this has resulted in the three, somewhat
376 experimental, options added by @command{g77} to the @command{gcc}
377 compiler and its back end.
378
379 (These, in turn, had made their way into the @code{egcs}
380 version of the compiler, and do not exist in @command{gcc}
381 version 2.8 or versions of @command{g77} based on that version
382 of @command{gcc}.)
383
384 @item
385 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
386
387 @item
388 Thanks to Mary Cortani and the staff at Craftwork Solutions
389 (@email{support@@craftwork.com}) for all of their support.
390
391 @item
392 Many other individuals have helped debug, test, and improve @command{g77}
393 over the past several years, and undoubtedly more people
394 will be doing so in the future.
395 If you have done so, and would like
396 to see your name listed in the above list, please ask!
397 The default is that people wish to remain anonymous.
398 @end itemize
399
400 @include funding.texi
401
402 @node Funding GNU Fortran
403 @chapter Funding GNU Fortran
404 @cindex funding improvements
405 @cindex improvements, funding
406
407 James Craig Burley (@email{@value{email-burley}}), the original author
408 of @command{g77}, stopped working on it in September 1999
409 (He has a web page at @uref{@value{www-burley}}.)
410
411 GNU Fortran is currently maintained by Toon Moene
412 (@email{toon@@moene.indiv.nluug.nl}), with the help of countless other
413 volunteers.
414
415 As with other GNU software, funding is important because it can pay for
416 needed equipment, personnel, and so on.
417
418 @cindex FSF, funding the
419 @cindex funding the FSF
420 The FSF provides information on the best way to fund ongoing
421 development of GNU software (such as GNU Fortran) in documents
422 such as the ``GNUS Bulletin''.
423 Email @email{gnu@@gnu.org} for information on funding the FSF.
424
425 Another important way to support work on GNU Fortran is to volunteer
426 to help out.
427
428 Email @email{@value{email-general}} to volunteer for this work.
429
430 However, we strongly expect that there will never be a version 0.6
431 of @command{g77}.  Work on this compiler has stopped as of the release
432 of GCC 3.1, except for bug fixing.  @command{g77} will be succeeded by
433 @command{g95} - see @uref{http://g95.sourceforge.net}.
434
435 @xref{Funding,,Funding Free Software}, for more information.
436
437 @node Getting Started
438 @chapter Getting Started
439 @cindex getting started
440 @cindex new users
441 @cindex newbies
442 @cindex beginners
443
444 If you don't need help getting started reading the portions
445 of this manual that are most important to you, you should skip
446 this portion of the manual.
447
448 If you are new to compilers, especially Fortran compilers, or
449 new to how compilers are structured under UNIX and UNIX-like
450 systems, you'll want to see @ref{What is GNU Fortran?}.
451
452 If you are new to GNU compilers, or have used only one GNU
453 compiler in the past and not had to delve into how it lets
454 you manage various versions and configurations of @command{gcc},
455 you should see @ref{G77 and GCC}.
456
457 Everyone except experienced @command{g77} users should
458 see @ref{Invoking G77}.
459
460 If you're acquainted with previous versions of @command{g77},
461 you should see @ref{News,,News About GNU Fortran}.
462 Further, if you've actually used previous versions of @command{g77},
463 especially if you've written or modified Fortran code to
464 be compiled by previous versions of @command{g77}, you
465 should see @ref{Changes}.
466
467 If you intend to write or otherwise compile code that is
468 not already strictly conforming ANSI FORTRAN 77---and this
469 is probably everyone---you should see @ref{Language}.
470
471 If you run into trouble getting Fortran code to compile,
472 link, run, or work properly, you might find answers
473 if you see @ref{Debugging and Interfacing},
474 see @ref{Collected Fortran Wisdom},
475 and see @ref{Trouble}.
476 You might also find that the problems you are encountering
477 are bugs in @command{g77}---see @ref{Bugs}, for information on
478 reporting them, after reading the other material.
479
480 If you need further help with @command{g77}, or with
481 freely redistributable software in general,
482 see @ref{Service}.
483
484 If you would like to help the @command{g77} project,
485 see @ref{Funding GNU Fortran}, for information on
486 helping financially, and see @ref{Projects}, for information
487 on helping in other ways.
488
489 If you're generally curious about the future of
490 @command{g77}, see @ref{Projects}.
491 If you're curious about its past,
492 see @ref{Contributors},
493 and see @ref{Funding GNU Fortran}.
494
495 To see a few of the questions maintainers of @command{g77} have,
496 and that you might be able to answer,
497 see @ref{Open Questions}.
498
499 @ifset USING
500 @node What is GNU Fortran?
501 @chapter What is GNU Fortran?
502 @cindex concepts, basic
503 @cindex basic concepts
504
505 GNU Fortran, or @command{g77}, is designed initially as a free replacement
506 for, or alternative to, the UNIX @command{f77} command.
507 (Similarly, @command{gcc} is designed as a replacement
508 for the UNIX @command{cc} command.)
509
510 @command{g77} also is designed to fit in well with the other
511 fine GNU compilers and tools.
512
513 Sometimes these design goals conflict---in such cases, resolution
514 often is made in favor of fitting in well with Project GNU.
515 These cases are usually identified in the appropriate
516 sections of this manual.
517
518 @cindex compilers
519 As compilers, @command{g77}, @command{gcc}, and @command{f77}
520 share the following characteristics:
521
522 @itemize @bullet
523 @cindex source code
524 @cindex file, source
525 @cindex code, source
526 @cindex source file
527 @item
528 They read a user's program, stored in a file and
529 containing instructions written in the appropriate
530 language (Fortran, C, and so on).
531 This file contains @dfn{source code}.
532
533 @cindex translation of user programs
534 @cindex machine code
535 @cindex code, machine
536 @cindex mistakes
537 @item
538 They translate the user's program into instructions
539 a computer can carry out more quickly than it takes
540 to translate the instructions in the first place.
541 These instructions are called @dfn{machine code}---code
542 designed to be efficiently translated and processed
543 by a machine such as a computer.
544 Humans usually aren't as good writing machine code
545 as they are at writing Fortran or C, because
546 it is easy to make tiny mistakes writing machine code.
547 When writing Fortran or C, it is easy
548 to make big mistakes.
549
550 @cindex debugger
551 @cindex bugs, finding
552 @cindex @command{gdb}, command
553 @cindex commands, @command{gdb}
554 @item
555 They provide information in the generated machine code
556 that can make it easier to find bugs in the program
557 (using a debugging tool, called a @dfn{debugger},
558 such as @command{gdb}).
559
560 @cindex libraries
561 @cindex linking
562 @cindex @command{ld} command
563 @cindex commands, @command{ld}
564 @item
565 They locate and gather machine code already generated
566 to perform actions requested by statements in
567 the user's program.
568 This machine code is organized
569 into @dfn{libraries} and is located and gathered
570 during the @dfn{link} phase of the compilation
571 process.
572 (Linking often is thought of as a separate
573 step, because it can be directly invoked via the
574 @command{ld} command.
575 However, the @command{g77} and @command{gcc}
576 commands, as with most compiler commands, automatically
577 perform the linking step by calling on @command{ld}
578 directly, unless asked to not do so by the user.)
579
580 @cindex language, incorrect use of
581 @cindex incorrect use of language
582 @item
583 They attempt to diagnose cases where the user's
584 program contains incorrect usages of the language.
585 The @dfn{diagnostics} produced by the compiler
586 indicate the problem and the location in the user's
587 source file where the problem was first noticed.
588 The user can use this information to locate and
589 fix the problem.
590 @cindex diagnostics, incorrect
591 @cindex incorrect diagnostics
592 @cindex error messages, incorrect
593 @cindex incorrect error messages
594 (Sometimes an incorrect usage
595 of the language leads to a situation where the
596 compiler can no longer make any sense of what
597 follows---while a human might be able to---and
598 thus ends up complaining about many ``problems''
599 it encounters that, in fact, stem from just one
600 problem, usually the first one reported.)
601
602 @cindex warnings
603 @cindex questionable instructions
604 @item
605 They attempt to diagnose cases where the user's
606 program contains a correct usage of the language,
607 but instructs the computer to do something questionable.
608 These diagnostics often are in the form of @dfn{warnings},
609 instead of the @dfn{errors} that indicate incorrect
610 usage of the language.
611 @end itemize
612
613 How these actions are performed is generally under the
614 control of the user.
615 Using command-line options, the user can specify
616 how persnickety the compiler is to be regarding
617 the program (whether to diagnose questionable usage
618 of the language), how much time to spend making
619 the generated machine code run faster, and so on.
620
621 @cindex components of @command{g77}
622 @cindex @command{g77}, components of
623 @command{g77} consists of several components:
624
625 @cindex @command{gcc}, command
626 @cindex commands, @command{gcc}
627 @itemize @bullet
628 @item
629 A modified version of the @command{gcc} command, which also might be
630 installed as the system's @command{cc} command.
631 (In many cases, @command{cc} refers to the
632 system's ``native'' C compiler, which
633 might be a non-GNU compiler, or an older version
634 of @command{gcc} considered more stable or that is
635 used to build the operating system kernel.)
636
637 @cindex @command{g77}, command
638 @cindex commands, @command{g77}
639 @item
640 The @command{g77} command itself, which also might be installed as the
641 system's @command{f77} command.
642
643 @cindex libg2c library
644 @cindex libf2c library
645 @cindex libraries, libf2c
646 @cindex libraries, libg2c
647 @cindex run-time, library
648 @item
649 The @code{libg2c} run-time library.
650 This library contains the machine code needed to support
651 capabilities of the Fortran language that are not directly
652 provided by the machine code generated by the @command{g77}
653 compilation phase.
654
655 @code{libg2c} is just the unique name @command{g77} gives
656 to its version of @code{libf2c} to distinguish it from
657 any copy of @code{libf2c} installed from @command{f2c}
658 (or versions of @command{g77} that built @code{libf2c} under
659 that same name)
660 on the system.
661
662 The maintainer of @code{libf2c} currently is
663 @email{dmg@@bell-labs.com}.
664
665 @cindex @code{f771}, program
666 @cindex programs, @code{f771}
667 @cindex assembler
668 @cindex @command{as} command
669 @cindex commands, @command{as}
670 @cindex assembly code
671 @cindex code, assembly
672 @item
673 The compiler itself, internally named @code{f771}.
674
675 Note that @code{f771} does not generate machine code directly---it
676 generates @dfn{assembly code} that is a more readable form
677 of machine code, leaving the conversion to actual machine code
678 to an @dfn{assembler}, usually named @command{as}.
679 @end itemize
680
681 @command{gcc} is often thought of as ``the C compiler'' only,
682 but it does more than that.
683 Based on command-line options and the names given for files
684 on the command line, @command{gcc} determines which actions to perform, including
685 preprocessing, compiling (in a variety of possible languages), assembling,
686 and linking.
687
688 @cindex driver, gcc command as
689 @cindex @command{gcc}, command as driver
690 @cindex executable file
691 @cindex files, executable
692 @cindex cc1 program
693 @cindex programs, cc1
694 @cindex preprocessor
695 @cindex cpp program
696 @cindex programs, cpp
697 For example, the command @samp{gcc foo.c} @dfn{drives} the file
698 @file{foo.c} through the preprocessor @command{cpp}, then
699 the C compiler (internally named
700 @code{cc1}), then the assembler (usually @command{as}), then the linker
701 (@command{ld}), producing an executable program named @file{a.out} (on
702 UNIX systems).
703
704 @cindex cc1plus program
705 @cindex programs, cc1plus
706 As another example, the command @samp{gcc foo.cc} would do much the same as
707 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
708 @command{gcc} would use the C++ compiler (named @code{cc1plus}).
709
710 @cindex @code{f771}, program
711 @cindex programs, @code{f771}
712 In a GNU Fortran installation, @command{gcc} recognizes Fortran source
713 files by name just like it does C and C++ source files.
714 It knows to use the Fortran compiler named @code{f771}, instead of
715 @code{cc1} or @code{cc1plus}, to compile Fortran files.
716
717 @cindex @command{gcc}, not recognizing Fortran source
718 @cindex unrecognized file format
719 @cindex file format not recognized
720 Non-Fortran-related operation of @command{gcc} is generally
721 unaffected by installing the GNU Fortran version of @command{gcc}.
722 However, without the installed version of @command{gcc} being the
723 GNU Fortran version, @command{gcc} will not be able to compile
724 and link Fortran programs---and since @command{g77} uses @command{gcc}
725 to do most of the actual work, neither will @command{g77}!
726
727 @cindex @command{g77}, command
728 @cindex commands, @command{g77}
729 The @command{g77} command is essentially just a front-end for
730 the @command{gcc} command.
731 Fortran users will normally use @command{g77} instead of @command{gcc},
732 because @command{g77}
733 knows how to specify the libraries needed to link with Fortran programs
734 (@code{libg2c} and @code{lm}).
735 @command{g77} can still compile and link programs and
736 source files written in other languages, just like @command{gcc}.
737
738 @cindex printing version information
739 @cindex version information, printing
740 The command @samp{g77 -v} is a quick
741 way to display lots of version information for the various programs
742 used to compile a typical preprocessed Fortran source file---this
743 produces much more output than @samp{gcc -v} currently does.
744 (If it produces an error message near the end of the output---diagnostics
745 from the linker, usually @command{ld}---you might
746 have an out-of-date @code{libf2c} that improperly handles
747 complex arithmetic.)
748 In the output of this command, the line beginning @samp{GNU Fortran Front
749 End} identifies the version number of GNU Fortran; immediately
750 preceding that line is a line identifying the version of @command{gcc}
751 with which that version of @command{g77} was built.
752
753 @cindex libf2c library
754 @cindex libraries, libf2c
755 The @code{libf2c} library is distributed with GNU Fortran for
756 the convenience of its users, but is not part of GNU Fortran.
757 It contains the procedures
758 needed by Fortran programs while they are running.
759
760 @cindex in-line code
761 @cindex code, in-line
762 For example, while code generated by @command{g77} is likely
763 to do additions, subtractions, and multiplications @dfn{in line}---in
764 the actual compiled code---it is not likely to do trigonometric
765 functions this way.
766
767 Instead, operations like trigonometric
768 functions are compiled by the @code{f771} compiler
769 (invoked by @command{g77} when compiling Fortran code) into machine
770 code that, when run, calls on functions in @code{libg2c}, so
771 @code{libg2c} must be linked with almost every useful program
772 having any component compiled by GNU Fortran.
773 (As mentioned above, the @command{g77} command takes
774 care of all this for you.)
775
776 The @code{f771} program represents most of what is unique to GNU Fortran.
777 While much of the @code{libg2c} component comes from
778 the @code{libf2c} component of @command{f2c},
779 a free Fortran-to-C converter distributed by Bellcore (AT&T),
780 plus @code{libU77}, provided by Dave Love,
781 and the @command{g77} command is just a small front-end to @command{gcc},
782 @code{f771} is a combination of two rather
783 large chunks of code.
784
785 @cindex GNU Back End (GBE)
786 @cindex GBE
787 @cindex @command{gcc}, back end
788 @cindex back end, gcc
789 @cindex code generator
790 One chunk is the so-called @dfn{GNU Back End}, or GBE,
791 which knows how to generate fast code for a wide variety of processors.
792 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
793 @code{cc1plus}, and @code{f771}, plus others.
794 Often the GBE is referred to as the ``gcc back end'' or
795 even just ``gcc''---in this manual, the term GBE is used
796 whenever the distinction is important.
797
798 @cindex GNU Fortran Front End (FFE)
799 @cindex FFE
800 @cindex @command{g77}, front end
801 @cindex front end, @command{g77}
802 The other chunk of @code{f771} is the
803 majority of what is unique about GNU Fortran---the code that knows how
804 to interpret Fortran programs to determine what they are intending to
805 do, and then communicate that knowledge to the GBE for actual compilation
806 of those programs.
807 This chunk is called the @dfn{Fortran Front End} (FFE).
808 The @code{cc1} and @code{cc1plus} programs have their own front ends,
809 for the C and C++ languages, respectively.
810 These fronts ends are responsible for diagnosing
811 incorrect usage of their respective languages by the
812 programs the process, and are responsible for most of
813 the warnings about questionable constructs as well.
814 (The GBE handles producing some warnings, like those
815 concerning possible references to undefined variables.)
816
817 Because so much is shared among the compilers for various languages,
818 much of the behavior and many of the user-selectable options for these
819 compilers are similar.
820 For example, diagnostics (error messages and
821 warnings) are similar in appearance; command-line
822 options like @option{-Wall} have generally similar effects; and the quality
823 of generated code (in terms of speed and size) is roughly similar
824 (since that work is done by the shared GBE).
825
826 @node G77 and GCC
827 @chapter Compile Fortran, C, or Other Programs
828 @cindex compiling programs
829 @cindex programs, compiling
830
831 @cindex @command{gcc}, command
832 @cindex commands, @command{gcc}
833 A GNU Fortran installation includes a modified version of the @command{gcc}
834 command.
835
836 In a non-Fortran installation, @command{gcc} recognizes C, C++,
837 and Objective-C source files.
838
839 In a GNU Fortran installation, @command{gcc} also recognizes Fortran source
840 files and accepts Fortran-specific command-line options, plus some
841 command-line options that are designed to cater to Fortran users
842 but apply to other languages as well.
843
844 @xref{G++ and GCC,,Compile C; C++; Objective-C; Ada; Fortran;
845 or Java,gcc,Using the GNU Compiler Collection (GCC)},
846 for information on the way different languages are handled
847 by the GNU CC compiler (@command{gcc}).
848
849 @cindex @command{g77}, command
850 @cindex commands, @command{g77}
851 Also provided as part of GNU Fortran is the @command{g77} command.
852 The @command{g77} command is designed to make compiling and linking Fortran
853 programs somewhat easier than when using the @command{gcc} command for
854 these tasks.
855 It does this by analyzing the command line somewhat and changing it
856 appropriately before submitting it to the @command{gcc} command.
857
858 @cindex -v option
859 @cindex @command{g77} options, -v
860 @cindex options, -v
861 Use the @option{-v} option with @command{g77}
862 to see what is going on---the first line of output is the invocation
863 of the @command{gcc} command.
864
865 @include invoke.texi
866
867 @include news.texi
868
869 @set USERVISONLY
870 @include news.texi
871 @clear USERVISONLY
872
873 @node Language
874 @chapter The GNU Fortran Language
875
876 @cindex standard, ANSI FORTRAN 77
877 @cindex ANSI FORTRAN 77 standard
878 @cindex reference works
879 GNU Fortran supports a variety of extensions to, and dialects
880 of, the Fortran language.
881 Its primary base is the ANSI FORTRAN 77 standard, currently available on
882 the network at
883 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
884 or as monolithic text at
885 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
886 It offers some extensions that are popular among users
887 of UNIX @command{f77} and @command{f2c} compilers, some that
888 are popular among users of other compilers (such as Digital
889 products), some that are popular among users of the
890 newer Fortran 90 standard, and some that are introduced
891 by GNU Fortran.
892
893 @cindex textbooks
894 (If you need a text on Fortran,
895 a few freely available electronic references have pointers from
896 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
897 net project', @cite{User Notes on Fortran Programming} at
898 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
899 material might not apply specifically to @command{g77}.)
900
901 Part of what defines a particular implementation of a Fortran
902 system, such as @command{g77}, is the particular characteristics
903 of how it supports types, constants, and so on.
904 Much of this is left up to the implementation by the various
905 Fortran standards and accepted practice in the industry.
906
907 The GNU Fortran @emph{language} is described below.
908 Much of the material is organized along the same lines
909 as the ANSI FORTRAN 77 standard itself.
910
911 @xref{Other Dialects}, for information on features @command{g77} supports
912 that are not part of the GNU Fortran language.
913
914 @emph{Note}: This portion of the documentation definitely needs a lot
915 of work!
916
917 @menu
918 Relationship to the ANSI FORTRAN 77 standard:
919 * Direction of Language Development::  Where GNU Fortran is headed.
920 * Standard Support::  Degree of support for the standard.
921
922 Extensions to the ANSI FORTRAN 77 standard:
923 * Conformance::
924 * Notation Used::
925 * Terms and Concepts::
926 * Characters Lines Sequence::
927 * Data Types and Constants::
928 * Expressions::
929 * Specification Statements::
930 * Control Statements::
931 * Functions and Subroutines::
932 * Scope and Classes of Names::
933 * I/O::
934 * Fortran 90 Features::
935 @end menu
936
937 @node Direction of Language Development
938 @section Direction of Language Development
939 @cindex direction of language development
940 @cindex features, language
941 @cindex language, features
942
943 The purpose of the following description of the GNU Fortran
944 language is to promote wide portability of GNU Fortran programs.
945
946 GNU Fortran is an evolving language, due to the
947 fact that @command{g77} itself is in beta test.
948 Some current features of the language might later
949 be redefined as dialects of Fortran supported by @command{g77}
950 when better ways to express these features are added to @command{g77},
951 for example.
952 Such features would still be supported by
953 @command{g77}, but would be available only when
954 one or more command-line options were used.
955
956 The GNU Fortran @emph{language} is distinct from the
957 GNU Fortran @emph{compilation system} (@command{g77}).
958
959 For example, @command{g77} supports various dialects of
960 Fortran---in a sense, these are languages other than
961 GNU Fortran---though its primary
962 purpose is to support the GNU Fortran language, which also is
963 described in its documentation and by its implementation.
964
965 On the other hand, non-GNU compilers might offer
966 support for the GNU Fortran language, and are encouraged
967 to do so.
968
969 Currently, the GNU Fortran language is a fairly fuzzy object.
970 It represents something of a cross between what @command{g77} accepts
971 when compiling using the prevailing defaults and what this
972 document describes as being part of the language.
973
974 Future versions of @command{g77} are expected to clarify the
975 definition of the language in the documentation.
976 Often, this will mean adding new features to the language, in the form
977 of both new documentation and new support in @command{g77}.
978 However, it might occasionally mean removing a feature
979 from the language itself to ``dialect'' status.
980 In such a case, the documentation would be adjusted
981 to reflect the change, and @command{g77} itself would likely be changed
982 to require one or more command-line options to continue supporting
983 the feature.
984
985 The development of the GNU Fortran language is intended to strike
986 a balance between:
987
988 @itemize @bullet
989 @item
990 Serving as a mostly-upwards-compatible language from the
991 de facto UNIX Fortran dialect as supported by @command{f77}.
992
993 @item
994 Offering new, well-designed language features.
995 Attributes of such features include
996 not making existing code any harder to read
997 (for those who might be unaware that the new
998 features are not in use) and
999 not making state-of-the-art
1000 compilers take longer to issue diagnostics,
1001 among others.
1002
1003 @item
1004 Supporting existing, well-written code without gratuitously
1005 rejecting non-standard constructs, regardless of the origin
1006 of the code (its dialect).
1007
1008 @item
1009 Offering default behavior and command-line options to reduce
1010 and, where reasonable, eliminate the need for programmers to make
1011 any modifications to code that already works in existing
1012 production environments.
1013
1014 @item
1015 Diagnosing constructs that have different meanings in different
1016 systems, languages, and dialects, while offering clear,
1017 less ambiguous ways to express each of the different meanings
1018 so programmers can change their code appropriately.
1019 @end itemize
1020
1021 One of the biggest practical challenges for the developers of the
1022 GNU Fortran language is meeting the sometimes contradictory demands
1023 of the above items.
1024
1025 For example, a feature might be widely used in one popular environment,
1026 but the exact same code that utilizes that feature might not work
1027 as expected---perhaps it might mean something entirely different---in
1028 another popular environment.
1029
1030 Traditionally, Fortran compilers---even portable ones---have solved this
1031 problem by simply offering the appropriate feature to users of
1032 the respective systems.
1033 This approach treats users of various Fortran systems and dialects
1034 as remote ``islands'', or camps, of programmers, and assume that these
1035 camps rarely come into contact with each other (or,
1036 especially, with each other's code).
1037
1038 Project GNU takes a radically different approach to software and language
1039 design, in that it assumes that users of GNU software do not necessarily
1040 care what kind of underlying system they are using, regardless
1041 of whether they are using software (at the user-interface
1042 level) or writing it (for example, writing Fortran or C code).
1043
1044 As such, GNU users rarely need consider just what kind of underlying
1045 hardware (or, in many cases, operating system) they are using at any
1046 particular time.
1047 They can use and write software designed for a general-purpose,
1048 widely portable, heterogenous environment---the GNU environment.
1049
1050 In line with this philosophy, GNU Fortran must evolve into a product
1051 that is widely ported and portable not only in the sense that it can
1052 be successfully built, installed, and run by users, but in the larger
1053 sense that its users can use it in the same way, and expect largely the
1054 same behaviors from it, regardless of the kind of system they are using
1055 at any particular time.
1056
1057 This approach constrains the solutions @command{g77} can use to resolve
1058 conflicts between various camps of Fortran users.
1059 If these two camps disagree about what a particular construct should
1060 mean, @command{g77} cannot simply be changed to treat that particular construct as
1061 having one meaning without comment (such as a warning), lest the users
1062 expecting it to have the other meaning are unpleasantly surprised that
1063 their code misbehaves when executed.
1064
1065 The use of the ASCII backslash character in character constants is
1066 an excellent (and still somewhat unresolved) example of this kind of
1067 controversy.
1068 @xref{Backslash in Constants}.
1069 Other examples are likely to arise in the future, as @command{g77} developers
1070 strive to improve its ability to accept an ever-wider variety of existing
1071 Fortran code without requiring significant modifications to said code.
1072
1073 Development of GNU Fortran is further constrained by the desire
1074 to avoid requiring programmers to change their code.
1075 This is important because it allows programmers, administrators,
1076 and others to more faithfully evaluate and validate @command{g77}
1077 (as an overall product and as new versions are distributed)
1078 without having to support multiple versions of their programs
1079 so that they continue to work the same way on their existing
1080 systems (non-GNU perhaps, but possibly also earlier versions
1081 of @command{g77}).
1082
1083 @node Standard Support
1084 @section ANSI FORTRAN 77 Standard Support
1085 @cindex ANSI FORTRAN 77 support
1086 @cindex standard, support for
1087 @cindex support, FORTRAN 77
1088 @cindex compatibility, FORTRAN 77
1089 @cindex FORTRAN 77 compatibility
1090
1091 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
1092 In summary, the only ANSI FORTRAN 77 features @command{g77} doesn't
1093 support are those that are probably rarely used in actual code,
1094 some of which are explicitly disallowed by the Fortran 90 standard.
1095
1096 @menu
1097 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
1098 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
1099 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
1100 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
1101 @end menu
1102
1103 @node No Passing External Assumed-length
1104 @subsection No Passing External Assumed-length
1105
1106 @command{g77} disallows passing of an external procedure
1107 as an actual argument if the procedure's
1108 type is declared @code{CHARACTER*(*)}.  For example:
1109
1110 @example
1111 CHARACTER*(*) CFUNC
1112 EXTERNAL CFUNC
1113 CALL FOO(CFUNC)
1114 END
1115 @end example
1116
1117 @noindent
1118 It isn't clear whether the standard considers this conforming.
1119
1120 @node No Passing Dummy Assumed-length
1121 @subsection No Passing Dummy Assumed-length
1122
1123 @command{g77} disallows passing of a dummy procedure
1124 as an actual argument if the procedure's
1125 type is declared @code{CHARACTER*(*)}.
1126
1127 @example
1128 SUBROUTINE BAR(CFUNC)
1129 CHARACTER*(*) CFUNC
1130 EXTERNAL CFUNC
1131 CALL FOO(CFUNC)
1132 END
1133 @end example
1134
1135 @noindent
1136 It isn't clear whether the standard considers this conforming.
1137
1138 @node No Pathological Implied-DO
1139 @subsection No Pathological Implied-DO
1140
1141 The @code{DO} variable for an implied-@code{DO} construct in a
1142 @code{DATA} statement may not be used as the @code{DO} variable
1143 for an outer implied-@code{DO} construct.  For example, this
1144 fragment is disallowed by @command{g77}:
1145
1146 @smallexample
1147 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
1148 @end smallexample
1149
1150 @noindent
1151 This also is disallowed by Fortran 90, as it offers no additional
1152 capabilities and would have a variety of possible meanings.
1153
1154 Note that it is @emph{very} unlikely that any production Fortran code
1155 tries to use this unsupported construct.
1156
1157 @node No Useless Implied-DO
1158 @subsection No Useless Implied-DO
1159
1160 An array element initializer in an implied-@code{DO} construct in a
1161 @code{DATA} statement must contain at least one reference to the @code{DO}
1162 variables of each outer implied-@code{DO} construct.  For example,
1163 this fragment is disallowed by @command{g77}:
1164
1165 @smallexample
1166 DATA (A, I= 1, 1) /1./
1167 @end smallexample
1168
1169 @noindent
1170 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
1171 requirements offer no additional capabilities.
1172 However, @command{g77} doesn't necessarily diagnose all cases
1173 where this requirement is not met.
1174
1175 Note that it is @emph{very} unlikely that any production Fortran code
1176 tries to use this unsupported construct.
1177
1178 @node Conformance
1179 @section Conformance
1180
1181 (The following information augments or overrides the information in
1182 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1183 language.
1184 Chapter 1 of that document otherwise serves as the basis
1185 for the relevant aspects of GNU Fortran.)
1186
1187 The definition of the GNU Fortran language is akin to that of
1188 the ANSI FORTRAN 77 language in that it does not generally require
1189 conforming implementations to diagnose cases where programs do
1190 not conform to the language.
1191
1192 However, @command{g77} as a compiler is being developed in a way that
1193 is intended to enable it to diagnose such cases in an easy-to-understand
1194 manner.
1195
1196 A program that conforms to the GNU Fortran language should, when
1197 compiled, linked, and executed using a properly installed @command{g77}
1198 system, perform as described by the GNU Fortran language definition.
1199 Reasons for different behavior include, among others:
1200
1201 @itemize @bullet
1202 @item
1203 Use of resources (memory---heap, stack, and so on; disk space; CPU
1204 time; etc.) exceeds those of the system.
1205
1206 @item
1207 Range and/or precision of calculations required by the program
1208 exceeds that of the system.
1209
1210 @item
1211 Excessive reliance on behaviors that are system-dependent
1212 (non-portable Fortran code).
1213
1214 @item
1215 Bugs in the program.
1216
1217 @item
1218 Bug in @command{g77}.
1219
1220 @item
1221 Bugs in the system.
1222 @end itemize
1223
1224 Despite these ``loopholes'', the availability of a clear specification
1225 of the language of programs submitted to @command{g77}, as this document
1226 is intended to provide, is considered an important aspect of providing
1227 a robust, clean, predictable Fortran implementation.
1228
1229 The definition of the GNU Fortran language, while having no special
1230 legal status, can therefore be viewed as a sort of contract, or agreement.
1231 This agreement says, in essence, ``if you write a program in this language,
1232 and run it in an environment (such as a @command{g77} system) that supports
1233 this language, the program should behave in a largely predictable way''.
1234
1235 @node Notation Used
1236 @section Notation Used in This Chapter
1237
1238 (The following information augments or overrides the information in
1239 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1240 language.
1241 Chapter 1 of that document otherwise serves as the basis
1242 for the relevant aspects of GNU Fortran.)
1243
1244 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
1245 and ``must not'' and ``may not'' denote prohibition.
1246 Terms such as ``might'', ``should'', and ``can'' generally add little or
1247 nothing in the way of weight to the GNU Fortran language itself,
1248 but are used to explain or illustrate the language.
1249
1250 For example:
1251
1252 @display
1253 ``The @code{FROBNITZ} statement must precede all executable
1254 statements in a program unit, and may not specify any dummy
1255 arguments.  It may specify local or common variables and arrays.
1256 Its use should be limited to portions of the program designed to
1257 be non-portable and system-specific, because it might cause the
1258 containing program unit to behave quite differently on different
1259 systems.''
1260 @end display
1261
1262 Insofar as the GNU Fortran language is specified,
1263 the requirements and permissions denoted by the above sample statement
1264 are limited to the placement of the statement and the kinds of
1265 things it may specify.
1266 The rest of the statement---the content regarding non-portable portions
1267 of the program and the differing behavior of program units containing
1268 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
1269 language itself.
1270 That content offers advice and warnings about the @code{FROBNITZ}
1271 statement.
1272
1273 @emph{Remember:} The GNU Fortran language definition specifies
1274 both what constitutes a valid GNU Fortran program and how,
1275 given such a program, a valid GNU Fortran implementation is
1276 to interpret that program.
1277
1278 It is @emph{not} incumbent upon a valid GNU Fortran implementation
1279 to behave in any particular way, any consistent way, or any
1280 predictable way when it is asked to interpret input that is
1281 @emph{not} a valid GNU Fortran program.
1282
1283 Such input is said to have @dfn{undefined} behavior when
1284 interpreted by a valid GNU Fortran implementation, though
1285 an implementation may choose to specify behaviors for some
1286 cases of inputs that are not valid GNU Fortran programs.
1287
1288 Other notation used herein is that of the GNU texinfo format,
1289 which is used to generate printed hardcopy, on-line hypertext
1290 (Info), and on-line HTML versions, all from a single source
1291 document.
1292 This notation is used as follows:
1293
1294 @itemize @bullet
1295 @item
1296 Keywords defined by the GNU Fortran language are shown
1297 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
1298 @code{BLOCK DATA}.
1299
1300 Note that, in practice, many Fortran programs are written
1301 in lowercase---uppercase is used in this manual as a
1302 means to readily distinguish keywords and sample Fortran-related
1303 text from the prose in this document.
1304
1305 @item
1306 Portions of actual sample program, input, or output text
1307 look like this: @samp{Actual program text}.
1308
1309 Generally, uppercase is used for all Fortran-specific and
1310 Fortran-related text, though this does not always include
1311 literal text within Fortran code.
1312
1313 For example: @samp{PRINT *, 'My name is Bob'}.
1314
1315 @item
1316 A metasyntactic variable---that is, a name used in this document
1317 to serve as a placeholder for whatever text is used by the
1318 user or programmer---appears as shown in the following example:
1319
1320 ``The @code{INTEGER @var{ivar}} statement specifies that
1321 @var{ivar} is a variable or array of type @code{INTEGER}.''
1322
1323 In the above example, any valid text may be substituted for
1324 the metasyntactic variable @var{ivar} to make the statement
1325 apply to a specific instance, as long as the same text is
1326 substituted for @emph{both} occurrences of @var{ivar}.
1327
1328 @item
1329 Ellipses (``@dots{}'') are used to indicate further text that
1330 is either unimportant or expanded upon further, elsewhere.
1331
1332 @item
1333 Names of data types are in the style of Fortran 90, in most
1334 cases.
1335
1336 @xref{Kind Notation}, for information on the relationship
1337 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
1338 and the more traditional, less portably concise nomenclature
1339 (such as @code{INTEGER*4}).
1340 @end itemize
1341
1342 @node Terms and Concepts
1343 @section Fortran Terms and Concepts
1344
1345 (The following information augments or overrides the information in
1346 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1347 language.
1348 Chapter 2 of that document otherwise serves as the basis
1349 for the relevant aspects of GNU Fortran.)
1350
1351 @menu
1352 * Syntactic Items::
1353 * Statements Comments Lines::
1354 * Scope of Names and Labels::
1355 @end menu
1356
1357 @node Syntactic Items
1358 @subsection Syntactic Items
1359
1360 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
1361
1362 @cindex limits, lengths of names
1363 In GNU Fortran, a symbolic name is at least one character long,
1364 and has no arbitrary upper limit on length.
1365 However, names of entities requiring external linkage (such as
1366 external functions, external subroutines, and @code{COMMON} areas)
1367 might be restricted to some arbitrary length by the system.
1368 Such a restriction is no more constrained than that of one
1369 through six characters.
1370
1371 Underscores (@samp{_}) are accepted in symbol names after the first
1372 character (which must be a letter).
1373
1374 @node Statements Comments Lines
1375 @subsection Statements, Comments, and Lines
1376
1377 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
1378
1379 @cindex trailing comment
1380 @cindex comment
1381 @cindex characters, comment
1382 @cindex !
1383 @cindex exclamation point
1384 @cindex continuation character
1385 @cindex characters, continuation
1386 Use of an exclamation point (@samp{!}) to begin a
1387 trailing comment (a comment that extends to the end of the same
1388 source line) is permitted under the following conditions:
1389
1390 @itemize @bullet
1391 @item
1392 The exclamation point does not appear in column 6.
1393 Otherwise, it is treated as an indicator of a continuation
1394 line.
1395
1396 @item
1397 The exclamation point appears outside a character or Hollerith
1398 constant.
1399 Otherwise, the exclamation point is considered part of the
1400 constant.
1401
1402 @item
1403 The exclamation point appears to the left of any other possible
1404 trailing comment.
1405 That is, a trailing comment may contain exclamation points
1406 in their commentary text.
1407 @end itemize
1408
1409 @cindex ;
1410 @cindex semicolon
1411 @cindex statements, separated by semicolon
1412 Use of a semicolon (@samp{;}) as a statement separator
1413 is permitted under the following conditions:
1414
1415 @itemize @bullet
1416 @item
1417 The semicolon appears outside a character or Hollerith
1418 constant.
1419 Otherwise, the semicolon is considered part of the
1420 constant.
1421
1422 @item
1423 The semicolon appears to the left of a trailing comment.
1424 Otherwise, the semicolon is considered part of that
1425 comment.
1426
1427 @item
1428 Neither a logical @code{IF} statement nor a non-construct
1429 @code{WHERE} statement (a Fortran 90 feature) may be
1430 followed (in the same, possibly continued, line) by
1431 a semicolon used as a statement separator.
1432
1433 This restriction avoids the confusion
1434 that can result when reading a line such as:
1435
1436 @smallexample
1437 IF (VALIDP) CALL FOO; CALL BAR
1438 @end smallexample
1439
1440 @noindent
1441 Some readers might think the @samp{CALL BAR} is executed
1442 only if @samp{VALIDP} is @code{.TRUE.}, while others might
1443 assume its execution is unconditional.
1444
1445 (At present, @command{g77} does not diagnose code that
1446 violates this restriction.)
1447 @end itemize
1448
1449 @node Scope of Names and Labels
1450 @subsection Scope of Symbolic Names and Statement Labels
1451 @cindex scope
1452
1453 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
1454
1455 Included in the list of entities that have a scope of a
1456 program unit are construct names (a Fortran 90 feature).
1457 @xref{Construct Names}, for more information.
1458
1459 @node Characters Lines Sequence
1460 @section Characters, Lines, and Execution Sequence
1461
1462 (The following information augments or overrides the information in
1463 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1464 language.
1465 Chapter 3 of that document otherwise serves as the basis
1466 for the relevant aspects of GNU Fortran.)
1467
1468 @menu
1469 * Character Set::
1470 * Lines::
1471 * Continuation Line::
1472 * Statements::
1473 * Statement Labels::
1474 * Order::
1475 * INCLUDE::
1476 * Cpp-style directives::
1477 @end menu
1478
1479 @node Character Set
1480 @subsection GNU Fortran Character Set
1481 @cindex characters
1482
1483 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
1484
1485 Letters include uppercase letters (the twenty-six characters
1486 of the English alphabet) and lowercase letters (their lowercase
1487 equivalent).
1488 Generally, lowercase letters may be used in place of uppercase
1489 letters, though in character and Hollerith constants, they
1490 are distinct.
1491
1492 Special characters include:
1493
1494 @itemize @bullet
1495 @item
1496 @cindex ;
1497 @cindex semicolon
1498 Semicolon (@samp{;})
1499
1500 @item
1501 @cindex !
1502 @cindex exclamation point
1503 Exclamation point (@samp{!})
1504
1505 @item
1506 @cindex "
1507 @cindex double quote
1508 Double quote (@samp{"})
1509
1510 @item
1511 @cindex \
1512 @cindex backslash
1513 Backslash (@samp{\})
1514
1515 @item
1516 @cindex ?
1517 @cindex question mark
1518 Question mark (@samp{?})
1519
1520 @item
1521 @cindex #
1522 @cindex hash mark
1523 @cindex pound sign
1524 Hash mark (@samp{#})
1525
1526 @item
1527 @cindex &
1528 @cindex ampersand
1529 Ampersand (@samp{&})
1530
1531 @item
1532 @cindex %
1533 @cindex percent sign
1534 Percent sign (@samp{%})
1535
1536 @item
1537 @cindex _
1538 @cindex underscore
1539 Underscore (@samp{_})
1540
1541 @item
1542 @cindex <
1543 @cindex open angle
1544 @cindex left angle
1545 @cindex open bracket
1546 @cindex left bracket
1547 Open angle (@samp{<})
1548
1549 @item
1550 @cindex >
1551 @cindex close angle
1552 @cindex right angle
1553 @cindex close bracket
1554 @cindex right bracket
1555 Close angle (@samp{>})
1556
1557 @item
1558 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
1559 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
1560 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
1561 and @samp{:})
1562 @end itemize
1563
1564 @cindex blank
1565 @cindex space
1566 @cindex SPC
1567 Note that this document refers to @key{SPC} as @dfn{space},
1568 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
1569
1570 @node Lines
1571 @subsection Lines
1572 @cindex lines
1573 @cindex source file format
1574 @cindex source format
1575 @cindex file, source
1576 @cindex source code
1577 @cindex code, source
1578 @cindex fixed form
1579 @cindex free form
1580
1581 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
1582
1583 The way a Fortran compiler views source files depends entirely on the
1584 implementation choices made for the compiler, since those choices
1585 are explicitly left to the implementation by the published Fortran
1586 standards.
1587
1588 The GNU Fortran language mandates a view applicable to UNIX-like
1589 text files---files that are made up of an arbitrary number of lines,
1590 each with an arbitrary number of characters (sometimes called stream-based
1591 files).
1592
1593 This view does not apply to types of files that are specified as
1594 having a particular number of characters on every single line (sometimes
1595 referred to as record-based files).
1596
1597 Because a ``line in a program unit is a sequence of 72 characters'',
1598 to quote X3.9-1978, the GNU Fortran language specifies that a
1599 stream-based text file is translated to GNU Fortran lines as follows:
1600
1601 @itemize @bullet
1602 @item
1603 A newline in the file is the character that represents the end of
1604 a line of text to the underlying system.
1605 For example, on ASCII-based systems, a newline is the @key{NL}
1606 character, which has ASCII value 10 (decimal).
1607
1608 @item
1609 Each newline in the file serves to end the line of text that precedes
1610 it (and that does not contain a newline).
1611
1612 @item
1613 The end-of-file marker (@code{EOF}) also serves to end the line
1614 of text that precedes it (and that does not contain a newline).
1615
1616 @item
1617 @cindex blank
1618 @cindex space
1619 @cindex SPC
1620 Any line of text that is shorter than 72 characters is padded to that length
1621 with spaces (called ``blanks'' in the standard).
1622
1623 @item
1624 Any line of text that is longer than 72 characters is truncated to that
1625 length, but the truncated remainder must consist entirely of spaces.
1626
1627 @item
1628 Characters other than newline and the GNU Fortran character set
1629 are invalid.
1630 @end itemize
1631
1632 For the purposes of the remainder of this description of the GNU
1633 Fortran language, the translation described above has already
1634 taken place, unless otherwise specified.
1635
1636 The result of the above translation is that the source file appears,
1637 in terms of the remainder of this description of the GNU Fortran language,
1638 as if it had an arbitrary
1639 number of 72-character lines, each character being among the GNU Fortran
1640 character set.
1641
1642 For example, if the source file itself has two newlines in a row,
1643 the second newline becomes, after the above translation, a single
1644 line containing 72 spaces.
1645
1646 @node Continuation Line
1647 @subsection Continuation Line
1648 @cindex continuation line, number of
1649 @cindex lines, continuation
1650 @cindex number of continuation lines
1651 @cindex limits, continuation lines
1652
1653 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
1654
1655 A continuation line is any line that both
1656
1657 @itemize @bullet
1658 @item
1659 Contains a continuation character, and
1660
1661 @item
1662 Contains only spaces in columns 1 through 5
1663 @end itemize
1664
1665 A continuation character is any character of the GNU Fortran character set
1666 other than space (@key{SPC}) or zero (@samp{0})
1667 in column 6, or a digit (@samp{0} through @samp{9}) in column
1668 7 through 72 of a line that has only spaces to the left of that
1669 digit.
1670
1671 The continuation character is ignored as far as the content of
1672 the statement is concerned.
1673
1674 The GNU Fortran language places no limit on the number of
1675 continuation lines in a statement.
1676 In practice, the limit depends on a variety of factors, such as
1677 available memory, statement content, and so on, but no
1678 GNU Fortran system may impose an arbitrary limit.
1679
1680 @node Statements
1681 @subsection Statements
1682
1683 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
1684
1685 Statements may be written using an arbitrary number of continuation
1686 lines.
1687
1688 Statements may be separated using the semicolon (@samp{;}), except
1689 that the logical @code{IF} and non-construct @code{WHERE} statements
1690 may not be separated from subsequent statements using only a semicolon
1691 as statement separator.
1692
1693 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
1694 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
1695 statement.
1696 These alternatives may be written as normal statements---they are not
1697 subject to the restrictions of the @code{END} statement.
1698
1699 However, no statement other than @code{END} may have an initial line
1700 that appears to be an @code{END} statement---even @code{END PROGRAM},
1701 for example, must not be written as:
1702
1703 @example
1704       END
1705      &PROGRAM
1706 @end example
1707
1708 @node Statement Labels
1709 @subsection Statement Labels
1710
1711 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
1712
1713 A statement separated from its predecessor via a semicolon may be
1714 labeled as follows:
1715
1716 @itemize @bullet
1717 @item
1718 The semicolon is followed by the label for the statement,
1719 which in turn follows the label.
1720
1721 @item
1722 The label must be no more than five digits in length.
1723
1724 @item
1725 The first digit of the label for the statement is not
1726 the first non-space character on a line.
1727 Otherwise, that character is treated as a continuation
1728 character.
1729 @end itemize
1730
1731 A statement may have only one label defined for it.
1732
1733 @node Order
1734 @subsection Order of Statements and Lines
1735
1736 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
1737
1738 Generally, @code{DATA} statements may precede executable statements.
1739 However, specification statements pertaining to any entities
1740 initialized by a @code{DATA} statement must precede that @code{DATA}
1741 statement.
1742 For example,
1743 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
1744 @samp{INTEGER J} is permitted.
1745
1746 The last line of a program unit may be an @code{END} statement,
1747 or may be:
1748
1749 @itemize @bullet
1750 @item
1751 An @code{END PROGRAM} statement, if the program unit is a main program.
1752
1753 @item
1754 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
1755
1756 @item
1757 An @code{END FUNCTION} statement, if the program unit is a function.
1758
1759 @item
1760 An @code{END BLOCK DATA} statement, if the program unit is a block data.
1761 @end itemize
1762
1763 @node INCLUDE
1764 @subsection Including Source Text
1765 @cindex INCLUDE directive
1766
1767 Additional source text may be included in the processing of
1768 the source file via the @code{INCLUDE} directive:
1769
1770 @example
1771 INCLUDE @var{filename}
1772 @end example
1773
1774 @noindent
1775 The source text to be included is identified by @var{filename},
1776 which is a literal GNU Fortran character constant.
1777 The meaning and interpretation of @var{filename} depends on the
1778 implementation, but typically is a filename.
1779
1780 (@command{g77} treats it as a filename that it searches for
1781 in the current directory and/or directories specified
1782 via the @option{-I} command-line option.)
1783
1784 The effect of the @code{INCLUDE} directive is as if the
1785 included text directly replaced the directive in the source
1786 file prior to interpretation of the program.
1787 Included text may itself use @code{INCLUDE}.
1788 The depth of nested @code{INCLUDE} references depends on
1789 the implementation, but typically is a positive integer.
1790
1791 This virtual replacement treats the statements and @code{INCLUDE}
1792 directives in the included text as syntactically distinct from
1793 those in the including text.
1794
1795 Therefore, the first non-comment line of the included text
1796 must not be a continuation line.
1797 The included text must therefore have, after the non-comment
1798 lines, either an initial line (statement), an @code{INCLUDE}
1799 directive, or nothing (the end of the included text).
1800
1801 Similarly, the including text may end the @code{INCLUDE}
1802 directive with a semicolon or the end of the line, but it
1803 cannot follow an @code{INCLUDE} directive at the end of its
1804 line with a continuation line.
1805 Thus, the last statement in an included text may not be
1806 continued.
1807
1808 Any statements between two @code{INCLUDE} directives on the
1809 same line are treated as if they appeared in between the
1810 respective included texts.
1811 For example:
1812
1813 @smallexample
1814 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
1815 @end smallexample
1816
1817 @noindent
1818 If the text included by @samp{INCLUDE 'A'} constitutes
1819 a @samp{PRINT *, 'A'} statement and the text included by
1820 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
1821 then the output of the above sample program would be
1822
1823 @example
1824 A
1825 B
1826 C
1827 @end example
1828
1829 @noindent
1830 (with suitable allowances for how an implementation defines
1831 its handling of output).
1832
1833 Included text must not include itself directly or indirectly,
1834 regardless of whether the @var{filename} used to reference
1835 the text is the same.
1836
1837 Note that @code{INCLUDE} is @emph{not} a statement.
1838 As such, it is neither a non-executable or executable
1839 statement.
1840 However, if the text it includes constitutes one or more
1841 executable statements, then the placement of @code{INCLUDE}
1842 is subject to effectively the same restrictions as those
1843 on executable statements.
1844
1845 An @code{INCLUDE} directive may be continued across multiple
1846 lines as if it were a statement.
1847 This permits long names to be used for @var{filename}.
1848
1849 @node Cpp-style directives
1850 @subsection Cpp-style directives
1851 @cindex #
1852 @cindex preprocessor
1853
1854 @code{cpp} output-style @code{#} directives
1855 (@pxref{C Preprocessor Output,,, cpp, The C Preprocessor})
1856 are recognized by the compiler even
1857 when the preprocessor isn't run on the input (as it is when compiling
1858 @samp{.F} files).  (Note the distinction between these @command{cpp}
1859 @code{#} @emph{output} directives and @code{#line} @emph{input}
1860 directives.)
1861
1862 @node Data Types and Constants
1863 @section Data Types and Constants
1864
1865 (The following information augments or overrides the information in
1866 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
1867 language.
1868 Chapter 4 of that document otherwise serves as the basis
1869 for the relevant aspects of GNU Fortran.)
1870
1871 To more concisely express the appropriate types for
1872 entities, this document uses the more concise
1873 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
1874 instead of the more traditional, but less portably concise,
1875 byte-size-based nomenclature such as @code{INTEGER*4},
1876 wherever reasonable.
1877
1878 When referring to generic types---in contexts where the
1879 specific precision and range of a type are not important---this
1880 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
1881 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
1882
1883 In some cases, the context requires specification of a
1884 particular type.
1885 This document uses the @samp{KIND=} notation to accomplish
1886 this throughout, sometimes supplying the more traditional
1887 notation for clarification, though the traditional notation
1888 might not work the same way on all GNU Fortran implementations.
1889
1890 Use of @samp{KIND=} makes this document more concise because
1891 @command{g77} is able to define values for @samp{KIND=} that
1892 have the same meanings on all systems, due to the way the
1893 Fortran 90 standard specifies these values are to be used.
1894
1895 (In particular, that standard permits an implementation to
1896 arbitrarily assign nonnegative values.
1897 There are four distinct sets of assignments: one to the @code{CHARACTER}
1898 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
1899 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
1900 Implementations are free to assign these values in any order,
1901 leave gaps in the ordering of assignments, and assign more than
1902 one value to a representation.)
1903
1904 This makes @samp{KIND=} values superior to the values used
1905 in non-standard statements such as @samp{INTEGER*4}, because
1906 the meanings of the values in those statements vary from machine
1907 to machine, compiler to compiler, even operating system to
1908 operating system.
1909
1910 However, use of @samp{KIND=} is @emph{not} generally recommended
1911 when writing portable code (unless, for example, the code is
1912 going to be compiled only via @command{g77}, which is a widely
1913 ported compiler).
1914 GNU Fortran does not yet have adequate language constructs to
1915 permit use of @samp{KIND=} in a fashion that would make the
1916 code portable to Fortran 90 implementations; and, this construct
1917 is known to @emph{not} be accepted by many popular FORTRAN 77
1918 implementations, so it cannot be used in code that is to be ported
1919 to those.
1920
1921 The distinction here is that this document is able to use
1922 specific values for @samp{KIND=} to concisely document the
1923 types of various operations and operands.
1924
1925 A Fortran program should use the FORTRAN 77 designations for the
1926 appropriate GNU Fortran types---such as @code{INTEGER} for
1927 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
1928 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
1929 where no such designations exist, make use of appropriate
1930 techniques (preprocessor macros, parameters, and so on)
1931 to specify the types in a fashion that may be easily adjusted
1932 to suit each particular implementation to which the program
1933 is ported.
1934 (These types generally won't need to be adjusted for ports of
1935 @command{g77}.)
1936
1937 Further details regarding GNU Fortran data types and constants
1938 are provided below.
1939
1940 @menu
1941 * Types::
1942 * Constants::
1943 * Integer Type::
1944 * Character Type::
1945 @end menu
1946
1947 @node Types
1948 @subsection Data Types
1949
1950 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
1951
1952 GNU Fortran supports these types:
1953
1954 @enumerate
1955 @item
1956 Integer (generic type @code{INTEGER})
1957
1958 @item
1959 Real (generic type @code{REAL})
1960
1961 @item
1962 Double precision
1963
1964 @item
1965 Complex (generic type @code{COMPLEX})
1966
1967 @item
1968 Logical (generic type @code{LOGICAL})
1969
1970 @item
1971 Character (generic type @code{CHARACTER})
1972
1973 @item
1974 Double Complex
1975 @end enumerate
1976
1977 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
1978
1979 The generic types shown above are referred to in this document
1980 using only their generic type names.
1981 Such references usually indicate that any specific type (kind)
1982 of that generic type is valid.
1983
1984 For example, a context described in this document as accepting
1985 the @code{COMPLEX} type also is likely to accept the
1986 @code{DOUBLE COMPLEX} type.
1987
1988 The GNU Fortran language supports three ways to specify
1989 a specific kind of a generic type.
1990
1991 @menu
1992 * Double Notation::  As in @code{DOUBLE COMPLEX}.
1993 * Star Notation::    As in @code{INTEGER*4}.
1994 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
1995 @end menu
1996
1997 @node Double Notation
1998 @subsubsection Double Notation
1999
2000 The GNU Fortran language supports two uses of the keyword
2001 @code{DOUBLE} to specify a specific kind of type:
2002
2003 @itemize @bullet
2004 @item
2005 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
2006
2007 @item
2008 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
2009 @end itemize
2010
2011 Use one of the above forms where a type name is valid.
2012
2013 While use of this notation is popular, it doesn't scale
2014 well in a language or dialect rich in intrinsic types,
2015 as is the case for the GNU Fortran language (especially
2016 planned future versions of it).
2017
2018 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
2019 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
2020 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
2021 often are substituted for these, respectively, even though they
2022 do not always have the same meanings on all systems.
2023 (And, the fact that @samp{DOUBLE REAL} does not exist as such
2024 is an inconsistency.)
2025
2026 Therefore, this document uses ``double notation'' only on occasion
2027 for the benefit of those readers who are accustomed to it.
2028
2029 @node Star Notation
2030 @subsubsection Star Notation
2031 @cindex *@var{n} notation
2032
2033 The following notation specifies the storage size for a type:
2034
2035 @smallexample
2036 @var{generic-type}*@var{n}
2037 @end smallexample
2038
2039 @noindent
2040 @var{generic-type} must be a generic type---one of
2041 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
2042 or @code{CHARACTER}.
2043 @var{n} must be one or more digits comprising a decimal
2044 integer number greater than zero.
2045
2046 Use the above form where a type name is valid.
2047
2048 The @samp{*@var{n}} notation specifies that the amount of storage
2049 occupied by variables and array elements of that type is @var{n}
2050 times the storage occupied by a @code{CHARACTER*1} variable.
2051
2052 This notation might indicate a different degree of precision and/or
2053 range for such variables and array elements, and the functions that
2054 return values of types using this notation.
2055 It does not limit the precision or range of values of that type
2056 in any particular way---use explicit code to do that.
2057
2058 Further, the GNU Fortran language requires no particular values
2059 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
2060 notation.
2061 @command{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
2062 on all systems, for example,
2063 but not all implementations are required to do so, and @command{g77}
2064 is known to not support @code{REAL*1} on most (or all) systems.
2065
2066 As a result, except for @var{generic-type} of @code{CHARACTER},
2067 uses of this notation should be limited to isolated
2068 portions of a program that are intended to handle system-specific
2069 tasks and are expected to be non-portable.
2070
2071 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
2072 only @code{CHARACTER}, where it signifies not only the amount
2073 of storage occupied, but the number of characters in entities
2074 of that type.
2075 However, almost all Fortran compilers have supported this
2076 notation for generic types, though with a variety of meanings
2077 for @var{n}.)
2078
2079 Specifications of types using the @samp{*@var{n}} notation
2080 always are interpreted as specifications of the appropriate
2081 types described in this document using the @samp{KIND=@var{n}}
2082 notation, described below.
2083
2084 While use of this notation is popular, it doesn't serve well
2085 in the context of a widely portable dialect of Fortran, such as
2086 the GNU Fortran language.
2087
2088 For example, even on one particular machine, two or more popular
2089 Fortran compilers might well disagree on the size of a type
2090 declared @code{INTEGER*2} or @code{REAL*16}.
2091 Certainly there
2092 is known to be disagreement over such things among Fortran
2093 compilers on @emph{different} systems.
2094
2095 Further, this notation offers no elegant way to specify sizes
2096 that are not even multiples of the ``byte size'' typically
2097 designated by @code{INTEGER*1}.
2098 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
2099 certainly be possible, but would perhaps be stretching the original
2100 intent of this notation beyond the breaking point in terms
2101 of widespread readability of documentation and code making use
2102 of it.
2103
2104 Therefore, this document uses ``star notation'' only on occasion
2105 for the benefit of those readers who are accustomed to it.
2106
2107 @node Kind Notation
2108 @subsubsection Kind Notation
2109 @cindex KIND= notation
2110
2111 The following notation specifies the kind-type selector of a type:
2112
2113 @smallexample
2114 @var{generic-type}(KIND=@var{n})
2115 @end smallexample
2116
2117 @noindent
2118 Use the above form where a type name is valid.
2119
2120 @var{generic-type} must be a generic type---one of
2121 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
2122 or @code{CHARACTER}.
2123 @var{n} must be an integer initialization expression that
2124 is a positive, nonzero value.
2125
2126 Programmers are discouraged from writing these values directly
2127 into their code.
2128 Future versions of the GNU Fortran language will offer
2129 facilities that will make the writing of code portable
2130 to @command{g77} @emph{and} Fortran 90 implementations simpler.
2131
2132 However, writing code that ports to existing FORTRAN 77
2133 implementations depends on avoiding the @samp{KIND=} construct.
2134
2135 The @samp{KIND=} construct is thus useful in the context
2136 of GNU Fortran for two reasons:
2137
2138 @itemize @bullet
2139 @item
2140 It provides a means to specify a type in a fashion that
2141 is portable across all GNU Fortran implementations (though
2142 not other FORTRAN 77 and Fortran 90 implementations).
2143
2144 @item
2145 It provides a sort of Rosetta stone for this document to use
2146 to concisely describe the types of various operations and
2147 operands.
2148 @end itemize
2149
2150 The values of @var{n} in the GNU Fortran language are
2151 assigned using a scheme that:
2152
2153 @itemize @bullet
2154 @item
2155 Attempts to maximize the ability of readers
2156 of this document to quickly familiarize themselves
2157 with assignments for popular types
2158
2159 @item
2160 Provides a unique value for each specific desired
2161 meaning
2162
2163 @item
2164 Provides a means to automatically assign new values so
2165 they have a ``natural'' relationship to existing values,
2166 if appropriate, or, if no such relationship exists, will
2167 not interfere with future values assigned on the basis
2168 of such relationships
2169
2170 @item
2171 Avoids using values that are similar to values used
2172 in the existing, popular @samp{*@var{n}} notation,
2173 to prevent readers from expecting that these implied
2174 correspondences work on all GNU Fortran implementations
2175 @end itemize
2176
2177 The assignment system accomplishes this by assigning
2178 to each ``fundamental meaning'' of a specific type a
2179 unique prime number.
2180 Combinations of fundamental meanings---for example, a type
2181 that is two times the size of some other type---are assigned
2182 values of @var{n} that are the products of the values for
2183 those fundamental meanings.
2184
2185 A prime value of @var{n} is never given more than one fundamental
2186 meaning, to avoid situations where some code or system
2187 cannot reasonably provide those meanings in the form of a
2188 single type.
2189
2190 The values of @var{n} assigned so far are:
2191
2192 @table @code
2193 @item KIND=0
2194 This value is reserved for future use.
2195
2196 The planned future use is for this value to designate,
2197 explicitly, context-sensitive kind-type selection.
2198 For example, the expression @samp{1D0 * 0.1_0} would
2199 be equivalent to @samp{1D0 * 0.1D0}.
2200
2201 @item KIND=1
2202 This corresponds to the default types for
2203 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
2204 and @code{CHARACTER}, as appropriate.
2205
2206 These are the ``default'' types described in the Fortran 90 standard,
2207 though that standard does not assign any particular @samp{KIND=}
2208 value to these types.
2209
2210 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
2211 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
2212
2213 @item KIND=2
2214 This corresponds to types that occupy twice as much
2215 storage as the default types.
2216 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
2217 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
2218
2219 These are the ``double precision'' types described in the Fortran 90
2220 standard,
2221 though that standard does not assign any particular @samp{KIND=}
2222 value to these types.
2223
2224 @var{n} of 4 thus corresponds to types that occupy four times
2225 as much storage as the default types, @var{n} of 8 to types that
2226 occupy eight times as much storage, and so on.
2227
2228 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
2229 are not necessarily supported by every GNU Fortran implementation.
2230
2231 @item KIND=3
2232 This corresponds to types that occupy as much
2233 storage as the default @code{CHARACTER} type,
2234 which is the same effective type as @code{CHARACTER(KIND=1)}
2235 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
2236
2237 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
2238
2239 @var{n} of 6 thus corresponds to types that occupy twice as
2240 much storage as the @var{n}=3 types, @var{n} of 12 to types
2241 that occupy four times as much storage, and so on.
2242
2243 These are not necessarily supported by every GNU Fortran
2244 implementation.
2245
2246 @item KIND=5
2247 This corresponds to types that occupy half the
2248 storage as the default (@var{n}=1) types.
2249
2250 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
2251
2252 @var{n} of 25 thus corresponds to types that occupy one-quarter
2253 as much storage as the default types.
2254
2255 These are not necessarily supported by every GNU Fortran
2256 implementation.
2257
2258 @item KIND=7
2259 @cindex pointers
2260 This is valid only as @code{INTEGER(KIND=7)} and
2261 denotes the @code{INTEGER} type that has the smallest
2262 storage size that holds a pointer on the system.
2263
2264 A pointer representable by this type is capable of uniquely
2265 addressing a @code{CHARACTER*1} variable, array, array element,
2266 or substring.
2267
2268 (Typically this is equivalent to @code{INTEGER*4} or,
2269 on 64-bit systems, @code{INTEGER*8}.
2270 In a compatible C implementation, it typically would
2271 be the same size and semantics of the C type @code{void *}.)
2272 @end table
2273
2274 Note that these are @emph{proposed} correspondences and might change
2275 in future versions of @command{g77}---avoid writing code depending
2276 on them while @command{g77}, and therefore the GNU Fortran language
2277 it defines, is in beta testing.
2278
2279 Values not specified in the above list are reserved to
2280 future versions of the GNU Fortran language.
2281
2282 Implementation-dependent meanings will be assigned new,
2283 unique prime numbers so as to not interfere with other
2284 implementation-dependent meanings, and offer the possibility
2285 of increasing the portability of code depending on such
2286 types by offering support for them in other GNU Fortran
2287 implementations.
2288
2289 Other meanings that might be given unique values are:
2290
2291 @itemize @bullet
2292 @item
2293 Types that make use of only half their storage size for
2294 representing precision and range.
2295
2296 For example, some compilers offer options that cause
2297 @code{INTEGER} types to occupy the amount of storage
2298 that would be needed for @code{INTEGER(KIND=2)} types, but the
2299 range remains that of @code{INTEGER(KIND=1)}.
2300
2301 @item
2302 The IEEE single floating-point type.
2303
2304 @item
2305 Types with a specific bit pattern (endianness), such as the
2306 little-endian form of @code{INTEGER(KIND=1)}.
2307 These could permit, conceptually, use of portable code and
2308 implementations on data files written by existing systems.
2309 @end itemize
2310
2311 Future @emph{prime} numbers should be given meanings in as incremental
2312 a fashion as possible, to allow for flexibility and
2313 expressiveness in combining types.
2314
2315 For example, instead of defining a prime number for little-endian
2316 IEEE doubles, one prime number might be assigned the meaning
2317 ``little-endian'', another the meaning ``IEEE double'', and the
2318 value of @var{n} for a little-endian IEEE double would thus
2319 naturally be the product of those two respective assigned values.
2320 (It could even be reasonable to have IEEE values result from the
2321 products of prime values denoting exponent and fraction sizes
2322 and meanings, hidden bit usage, availability and representations
2323 of special values such as subnormals, infinities, and Not-A-Numbers
2324 (NaNs), and so on.)
2325
2326 This assignment mechanism, while not inherently required for
2327 future versions of the GNU Fortran language, is worth using
2328 because it could ease management of the ``space'' of supported
2329 types much easier in the long run.
2330
2331 The above approach suggests a mechanism for specifying inheritance
2332 of intrinsic (built-in) types for an entire, widely portable
2333 product line.
2334 It is certainly reasonable that, unlike programmers of other languages
2335 offering inheritance mechanisms that employ verbose names for classes
2336 and subclasses, along with graphical browsers to elucidate the
2337 relationships, Fortran programmers would employ
2338 a mechanism that works by multiplying prime numbers together
2339 and finding the prime factors of such products.
2340
2341 Most of the advantages for the above scheme have been explained
2342 above.
2343 One disadvantage is that it could lead to the defining,
2344 by the GNU Fortran language, of some fairly large prime numbers.
2345 This could lead to the GNU Fortran language being declared
2346 ``munitions'' by the United States Department of Defense.
2347
2348 @node Constants
2349 @subsection Constants
2350 @cindex constants
2351 @cindex types, constants
2352
2353 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
2354
2355 A @dfn{typeless constant} has one of the following forms:
2356
2357 @smallexample
2358 '@var{binary-digits}'B
2359 '@var{octal-digits}'O
2360 '@var{hexadecimal-digits}'Z
2361 '@var{hexadecimal-digits}'X
2362 @end smallexample
2363
2364 @noindent
2365 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
2366 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
2367 and @samp{0123456789ABCDEFabcdef}, respectively.
2368 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
2369 is 11, and so on.)
2370
2371 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
2372 treated as typeless.  @xref{Fortran Dialect Options,, Options
2373 Controlling Fortran Dialect}, for information on the
2374 @option{-ftypeless-boz} option.
2375
2376 Typeless constants have values that depend on the context in which
2377 they are used.
2378
2379 All other constants, called @dfn{typed constants}, are interpreted---converted
2380 to internal form---according to their inherent type.
2381 Thus, context is @emph{never} a determining factor for the type, and hence
2382 the interpretation, of a typed constant.
2383 (All constants in the ANSI FORTRAN 77 language are typed constants.)
2384
2385 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
2386 Fortran (called default INTEGER in Fortran 90),
2387 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
2388 additional precision specified is lost, and even when used in a
2389 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
2390 and @samp{1D0} is always type @code{REAL(KIND=2)}.
2391
2392 @node Integer Type
2393 @subsection Integer Type
2394
2395 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
2396
2397 An integer constant also may have one of the following forms:
2398
2399 @smallexample
2400 B'@var{binary-digits}'
2401 O'@var{octal-digits}'
2402 Z'@var{hexadecimal-digits}'
2403 X'@var{hexadecimal-digits}'
2404 @end smallexample
2405
2406 @noindent
2407 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
2408 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
2409 and @samp{0123456789ABCDEFabcdef}, respectively.
2410 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
2411 is 11, and so on.)
2412
2413 @node Character Type
2414 @subsection Character Type
2415
2416 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
2417
2418 @cindex double quoted character constants
2419 A character constant may be delimited by a pair of double quotes
2420 (@samp{"}) instead of apostrophes.
2421 In this case, an apostrophe within the constant represents
2422 a single apostrophe, while a double quote is represented in
2423 the source text of the constant by two consecutive double
2424 quotes with no intervening spaces.
2425
2426 @cindex zero-length CHARACTER
2427 @cindex null CHARACTER strings
2428 @cindex empty CHARACTER strings
2429 @cindex strings, empty
2430 @cindex CHARACTER, null
2431 A character constant may be empty (have a length of zero).
2432
2433 A character constant may include a substring specification,
2434 The value of such a constant is the value of the substring---for
2435 example, the value of @samp{'hello'(3:5)} is the same
2436 as the value of @samp{'llo'}.
2437
2438 @node Expressions
2439 @section Expressions
2440
2441 (The following information augments or overrides the information in
2442 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2443 language.
2444 Chapter 6 of that document otherwise serves as the basis
2445 for the relevant aspects of GNU Fortran.)
2446
2447 @menu
2448 * %LOC()::
2449 @end menu
2450
2451 @node %LOC()
2452 @subsection The @code{%LOC()} Construct
2453 @cindex %LOC() construct
2454
2455 @example
2456 %LOC(@var{arg})
2457 @end example
2458
2459 The @code{%LOC()} construct is an expression
2460 that yields the value of the location of its argument,
2461 @var{arg}, in memory.
2462 The size of the type of the expression depends on the system---typically,
2463 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
2464 though it is actually type @code{INTEGER(KIND=7)}.
2465
2466 The argument to @code{%LOC()} must be suitable as the
2467 left-hand side of an assignment statement.
2468 That is, it may not be a general expression involving
2469 operators such as addition, subtraction, and so on,
2470 nor may it be a constant.
2471
2472 Use of @code{%LOC()} is recommended only for code that
2473 is accessing facilities outside of GNU Fortran, such as
2474 operating system or windowing facilities.
2475 It is best to constrain such uses to isolated portions of
2476 a program---portions that deal specifically and exclusively
2477 with low-level, system-dependent facilities.
2478 Such portions might well provide a portable interface for
2479 use by the program as a whole, but are themselves not
2480 portable, and should be thoroughly tested each time they
2481 are rebuilt using a new compiler or version of a compiler.
2482
2483 Do not depend on @code{%LOC()} returning a pointer that
2484 can be safely used to @emph{define} (change) the argument.
2485 While this might work in some circumstances, it is hard
2486 to predict whether it will continue to work when a program
2487 (that works using this unsafe behavior)
2488 is recompiled using different command-line options or
2489 a different version of @command{g77}.
2490
2491 Generally, @code{%LOC()} is safe when used as an argument
2492 to a procedure that makes use of the value of the corresponding
2493 dummy argument only during its activation, and only when
2494 such use is restricted to referencing (reading) the value
2495 of the argument to @code{%LOC()}.
2496
2497 @emph{Implementation Note:} Currently, @command{g77} passes
2498 arguments (those not passed using a construct such as @code{%VAL()})
2499 by reference or descriptor, depending on the type of
2500 the actual argument.
2501 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
2502 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
2503 in fact might compile to identical code.
2504
2505 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
2506 ``pass, by value, the address of @samp{I} in memory''.
2507 While @samp{CALL FOO(I)} might use that same approach in a
2508 particular version of @command{g77}, another version or compiler
2509 might choose a different implementation, such as copy-in/copy-out,
2510 to effect the desired behavior---and which will therefore not
2511 necessarily compile to the same code as would
2512 @samp{CALL FOO(%VAL(%LOC(I)))}
2513 using the same version or compiler.
2514
2515 @xref{Debugging and Interfacing}, for detailed information on
2516 how this particular version of @command{g77} implements various
2517 constructs.
2518
2519 @node Specification Statements
2520 @section Specification Statements
2521
2522 (The following information augments or overrides the information in
2523 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2524 language.
2525 Chapter 8 of that document otherwise serves as the basis
2526 for the relevant aspects of GNU Fortran.)
2527
2528 @menu
2529 * NAMELIST::
2530 * DOUBLE COMPLEX::
2531 @end menu
2532
2533 @node NAMELIST
2534 @subsection @code{NAMELIST} Statement
2535 @cindex NAMELIST statement
2536 @cindex statements, NAMELIST
2537
2538 The @code{NAMELIST} statement, and related I/O constructs, are
2539 supported by the GNU Fortran language in essentially the same
2540 way as they are by @command{f2c}.
2541
2542 This follows Fortran 90 with the restriction that on @code{NAMELIST}
2543 input, subscripts must have the form
2544 @smallexample
2545 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
2546 @end smallexample
2547 i.e.@:
2548 @smallexample
2549 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
2550 @end smallexample
2551 is allowed, but not, say,
2552 @smallexample
2553 &xx x(:3,8::2)=1,2,3,4,5,6/
2554 @end smallexample
2555
2556 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
2557 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
2558 @smallexample
2559 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
2560 @end smallexample
2561 could be used instead of the example above.
2562
2563 @node DOUBLE COMPLEX
2564 @subsection @code{DOUBLE COMPLEX} Statement
2565 @cindex DOUBLE COMPLEX
2566
2567 @code{DOUBLE COMPLEX} is a type-statement (and type) that
2568 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
2569
2570 @node Control Statements
2571 @section Control Statements
2572
2573 (The following information augments or overrides the information in
2574 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2575 language.
2576 Chapter 11 of that document otherwise serves as the basis
2577 for the relevant aspects of GNU Fortran.)
2578
2579 @menu
2580 * DO WHILE::
2581 * END DO::
2582 * Construct Names::
2583 * CYCLE and EXIT::
2584 @end menu
2585
2586 @node DO WHILE
2587 @subsection DO WHILE
2588 @cindex DO WHILE
2589 @cindex DO
2590 @cindex MIL-STD 1753
2591
2592 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
2593 Fortran 90 standards, is provided by the GNU Fortran language.
2594 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
2595 also supported.
2596
2597 @node END DO
2598 @subsection END DO
2599 @cindex END DO
2600 @cindex MIL-STD 1753
2601
2602 The @code{END DO} statement is provided by the GNU Fortran language.
2603
2604 This statement is used in one of two ways:
2605
2606 @itemize @bullet
2607 @item
2608 The Fortran 90 meaning, in which it specifies the termination
2609 point of a single @code{DO} loop started with a @code{DO} statement
2610 that specifies no termination label.
2611
2612 @item
2613 The MIL-STD 1753 meaning, in which it specifies the termination
2614 point of one or more @code{DO} loops, all of which start with a
2615 @code{DO} statement that specify the label defined for the
2616 @code{END DO} statement.
2617
2618 This kind of @code{END DO} statement is merely a synonym for
2619 @code{CONTINUE}, except it is permitted only when the statement
2620 is labeled and a target of one or more labeled @code{DO} loops.
2621
2622 It is expected that this use of @code{END DO} will be removed from
2623 the GNU Fortran language in the future, though it is likely that
2624 it will long be supported by @command{g77} as a dialect form.
2625 @end itemize
2626
2627 @node Construct Names
2628 @subsection Construct Names
2629 @cindex construct names
2630
2631 The GNU Fortran language supports construct names as defined
2632 by the Fortran 90 standard.
2633 These names are local to the program unit and are defined
2634 as follows:
2635
2636 @smallexample
2637 @var{construct-name}: @var{block-statement}
2638 @end smallexample
2639
2640 @noindent
2641 Here, @var{construct-name} is the construct name itself;
2642 its definition is connoted by the single colon (@samp{:}); and
2643 @var{block-statement} is an @code{IF}, @code{DO},
2644 or @code{SELECT CASE} statement that begins a block.
2645
2646 A block that is given a construct name must also specify the
2647 same construct name in its termination statement:
2648
2649 @example
2650 END @var{block} @var{construct-name}
2651 @end example
2652
2653 @noindent
2654 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
2655 as appropriate.
2656
2657 @node CYCLE and EXIT
2658 @subsection The @code{CYCLE} and @code{EXIT} Statements
2659
2660 @cindex CYCLE statement
2661 @cindex EXIT statement
2662 @cindex statements, CYCLE
2663 @cindex statements, EXIT
2664 The @code{CYCLE} and @code{EXIT} statements specify that
2665 the remaining statements in the current iteration of a
2666 particular active (enclosing) @code{DO} loop are to be skipped.
2667
2668 @code{CYCLE} specifies that these statements are skipped,
2669 but the @code{END DO} statement that marks the end of the
2670 @code{DO} loop be executed---that is, the next iteration,
2671 if any, is to be started.
2672 If the statement marking the end of the @code{DO} loop is
2673 not @code{END DO}---in other words, if the loop is not
2674 a block @code{DO}---the @code{CYCLE} statement does not
2675 execute that statement, but does start the next iteration (if any).
2676
2677 @code{EXIT} specifies that the loop specified by the
2678 @code{DO} construct is terminated.
2679
2680 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
2681 is the innermost enclosing @code{DO} loop when the following
2682 forms are used:
2683
2684 @example
2685 CYCLE
2686 EXIT
2687 @end example
2688
2689 Otherwise, the following forms specify the construct name
2690 of the pertinent @code{DO} loop:
2691
2692 @example
2693 CYCLE @var{construct-name}
2694 EXIT @var{construct-name}
2695 @end example
2696
2697 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
2698 statements.
2699 However, they cannot be easily thought of as @code{GO TO} statements
2700 in obscure cases involving FORTRAN 77 loops.
2701 For example:
2702
2703 @smallexample
2704       DO 10 I = 1, 5
2705       DO 10 J = 1, 5
2706          IF (J .EQ. 5) EXIT
2707       DO 10 K = 1, 5
2708          IF (K .EQ. 3) CYCLE
2709 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
2710 20    CONTINUE
2711 @end smallexample
2712
2713 @noindent
2714 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
2715 above are equivalent to a @code{GO TO} statement to either label
2716 @samp{10} or @samp{20}.
2717
2718 To understand the effect of @code{CYCLE} and @code{EXIT} in the
2719 above fragment, it is helpful to first translate it to its equivalent
2720 using only block @code{DO} loops:
2721
2722 @smallexample
2723       DO I = 1, 5
2724          DO J = 1, 5
2725             IF (J .EQ. 5) EXIT
2726             DO K = 1, 5
2727                IF (K .EQ. 3) CYCLE
2728 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
2729             END DO
2730          END DO
2731       END DO
2732 20    CONTINUE
2733 @end smallexample
2734
2735 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
2736 to @code{GO TO} so they may be more easily understood by programmers
2737 accustomed to FORTRAN coding:
2738
2739 @smallexample
2740       DO I = 1, 5
2741          DO J = 1, 5
2742             IF (J .EQ. 5) GOTO 18
2743             DO K = 1, 5
2744                IF (K .EQ. 3) GO TO 12
2745 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
2746 12          END DO
2747          END DO
2748 18    END DO
2749 20    CONTINUE
2750 @end smallexample
2751
2752 @noindent
2753 Thus, the @code{CYCLE} statement in the innermost loop skips over
2754 the @code{PRINT} statement as it begins the next iteration of the
2755 loop, while the @code{EXIT} statement in the middle loop ends that
2756 loop but @emph{not} the outermost loop.
2757
2758 @node Functions and Subroutines
2759 @section Functions and Subroutines
2760
2761 (The following information augments or overrides the information in
2762 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
2763 language.
2764 Chapter 15 of that document otherwise serves as the basis
2765 for the relevant aspects of GNU Fortran.)
2766
2767 @menu
2768 * %VAL()::
2769 * %REF()::
2770 * %DESCR()::
2771 * Generics and Specifics::
2772 * REAL() and AIMAG() of Complex::
2773 * CMPLX() of DOUBLE PRECISION::
2774 * MIL-STD 1753::
2775 * f77/f2c Intrinsics::
2776 * Table of Intrinsic Functions::
2777 @end menu
2778
2779 @node %VAL()
2780 @subsection The @code{%VAL()} Construct
2781 @cindex %VAL() construct
2782
2783 @example
2784 %VAL(@var{arg})
2785 @end example
2786
2787 The @code{%VAL()} construct specifies that an argument,
2788 @var{arg}, is to be passed by value, instead of by reference
2789 or descriptor.
2790
2791 @code{%VAL()} is restricted to actual arguments in
2792 invocations of external procedures.
2793
2794 Use of @code{%VAL()} is recommended only for code that
2795 is accessing facilities outside of GNU Fortran, such as
2796 operating system or windowing facilities.
2797 It is best to constrain such uses to isolated portions of
2798 a program---portions the deal specifically and exclusively
2799 with low-level, system-dependent facilities.
2800 Such portions might well provide a portable interface for
2801 use by the program as a whole, but are themselves not
2802 portable, and should be thoroughly tested each time they
2803 are rebuilt using a new compiler or version of a compiler.
2804
2805 @emph{Implementation Note:} Currently, @command{g77} passes
2806 all arguments either by reference or by descriptor.
2807
2808 Thus, use of @code{%VAL()} tends to be restricted to cases
2809 where the called procedure is written in a language other
2810 than Fortran that supports call-by-value semantics.
2811 (C is an example of such a language.)
2812
2813 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
2814 for detailed information on
2815 how this particular version of @command{g77} passes arguments
2816 to procedures.
2817
2818 @node %REF()
2819 @subsection The @code{%REF()} Construct
2820 @cindex %REF() construct
2821
2822 @example
2823 %REF(@var{arg})
2824 @end example
2825
2826 The @code{%REF()} construct specifies that an argument,
2827 @var{arg}, is to be passed by reference, instead of by
2828 value or descriptor.
2829
2830 @code{%REF()} is restricted to actual arguments in
2831 invocations of external procedures.
2832
2833 Use of @code{%REF()} is recommended only for code that
2834 is accessing facilities outside of GNU Fortran, such as
2835 operating system or windowing facilities.
2836 It is best to constrain such uses to isolated portions of
2837 a program---portions the deal specifically and exclusively
2838 with low-level, system-dependent facilities.
2839 Such portions might well provide a portable interface for
2840 use by the program as a whole, but are themselves not
2841 portable, and should be thoroughly tested each time they
2842 are rebuilt using a new compiler or version of a compiler.
2843
2844 Do not depend on @code{%REF()} supplying a pointer to the
2845 procedure being invoked.
2846 While that is a likely implementation choice, other
2847 implementation choices are available that preserve Fortran
2848 pass-by-reference semantics without passing a pointer to
2849 the argument, @var{arg}.
2850 (For example, a copy-in/copy-out implementation.)
2851
2852 @emph{Implementation Note:} Currently, @command{g77} passes
2853 all arguments
2854 (other than variables and arrays of type @code{CHARACTER})
2855 by reference.
2856 Future versions of, or dialects supported by, @command{g77} might
2857 not pass @code{CHARACTER} functions by reference.
2858
2859 Thus, use of @code{%REF()} tends to be restricted to cases
2860 where @var{arg} is type @code{CHARACTER} but the called
2861 procedure accesses it via a means other than the method
2862 used for Fortran @code{CHARACTER} arguments.
2863
2864 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
2865 how this particular version of @command{g77} passes arguments
2866 to procedures.
2867
2868 @node %DESCR()
2869 @subsection The @code{%DESCR()} Construct
2870 @cindex %DESCR() construct
2871
2872 @example
2873 %DESCR(@var{arg})
2874 @end example
2875
2876 The @code{%DESCR()} construct specifies that an argument,
2877 @var{arg}, is to be passed by descriptor, instead of by
2878 value or reference.
2879
2880 @code{%DESCR()} is restricted to actual arguments in
2881 invocations of external procedures.
2882
2883 Use of @code{%DESCR()} is recommended only for code that
2884 is accessing facilities outside of GNU Fortran, such as
2885 operating system or windowing facilities.
2886 It is best to constrain such uses to isolated portions of
2887 a program---portions the deal specifically and exclusively
2888 with low-level, system-dependent facilities.
2889 Such portions might well provide a portable interface for
2890 use by the program as a whole, but are themselves not
2891 portable, and should be thoroughly tested each time they
2892 are rebuilt using a new compiler or version of a compiler.
2893
2894 Do not depend on @code{%DESCR()} supplying a pointer
2895 and/or a length passed by value
2896 to the procedure being invoked.
2897 While that is a likely implementation choice, other
2898 implementation choices are available that preserve the
2899 pass-by-reference semantics without passing a pointer to
2900 the argument, @var{arg}.
2901 (For example, a copy-in/copy-out implementation.)
2902 And, future versions of @command{g77} might change the
2903 way descriptors are implemented, such as passing a
2904 single argument pointing to a record containing the
2905 pointer/length information instead of passing that same
2906 information via two arguments as it currently does.
2907
2908 @emph{Implementation Note:} Currently, @command{g77} passes
2909 all variables and arrays of type @code{CHARACTER}
2910 by descriptor.
2911 Future versions of, or dialects supported by, @command{g77} might
2912 pass @code{CHARACTER} functions by descriptor as well.
2913
2914 Thus, use of @code{%DESCR()} tends to be restricted to cases
2915 where @var{arg} is not type @code{CHARACTER} but the called
2916 procedure accesses it via a means similar to the method
2917 used for Fortran @code{CHARACTER} arguments.
2918
2919 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
2920 how this particular version of @command{g77} passes arguments
2921 to procedures.
2922
2923 @node Generics and Specifics
2924 @subsection Generics and Specifics
2925 @cindex generic intrinsics
2926 @cindex intrinsics, generic
2927
2928 The ANSI FORTRAN 77 language defines generic and specific
2929 intrinsics.
2930 In short, the distinctions are:
2931
2932 @itemize @bullet
2933 @item
2934 @emph{Specific} intrinsics have
2935 specific types for their arguments and a specific return
2936 type.
2937
2938 @item
2939 @emph{Generic} intrinsics are treated,
2940 on a case-by-case basis in the program's source code,
2941 as one of several possible specific intrinsics.
2942
2943 Typically, a generic intrinsic has a return type that
2944 is determined by the type of one or more of its arguments.
2945 @end itemize
2946
2947 The GNU Fortran language generalizes these concepts somewhat,
2948 especially by providing intrinsic subroutines and generic
2949 intrinsics that are treated as either a specific intrinsic subroutine
2950 or a specific intrinsic function (e.g. @code{SECOND}).
2951
2952 However, GNU Fortran avoids generalizing this concept to
2953 the point where existing code would be accepted as meaning
2954 something possibly different than what was intended.
2955
2956 For example, @code{ABS} is a generic intrinsic, so all working
2957 code written using @code{ABS} of an @code{INTEGER} argument
2958 expects an @code{INTEGER} return value.
2959 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
2960 argument returns an @code{INTEGER*2} return value.
2961
2962 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
2963 an @code{INTEGER(KIND=1)} argument.
2964 Code that passes something other than an @code{INTEGER(KIND=1)}
2965 argument to @code{IABS} is not valid GNU Fortran code, because
2966 it is not clear what the author intended.
2967
2968 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
2969 is not defined by the GNU Fortran language, because the programmer
2970 might have used that construct to mean any of the following, subtly
2971 different, things:
2972
2973 @itemize @bullet
2974 @item
2975 Convert @samp{J} to @code{INTEGER(KIND=1)} first
2976 (as if @samp{IABS(INT(J))} had been written).
2977
2978 @item
2979 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
2980 (as if @samp{INT(ABS(J))} had been written).
2981
2982 @item
2983 No conversion (as if @samp{ABS(J)} had been written).
2984 @end itemize
2985
2986 The distinctions matter especially when types and values wider than
2987 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
2988 operations performing more ``arithmetic'' than absolute-value, are involved.
2989
2990 The following sample program is not a valid GNU Fortran program, but
2991 might be accepted by other compilers.
2992 If so, the output is likely to be revealing in terms of how a given
2993 compiler treats intrinsics (that normally are specific) when they
2994 are given arguments that do not conform to their stated requirements:
2995
2996 @cindex JCB002 program
2997 @smallexample
2998       PROGRAM JCB002
2999 C Version 1:
3000 C Modified 1999-02-15 (Burley) to delete my email address.
3001 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
3002 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
3003 C
3004 C Version 0:
3005 C Written by James Craig Burley 1997-02-20.
3006 C
3007 C Purpose:
3008 C Determine how compilers handle non-standard IDIM
3009 C on INTEGER*2 operands, which presumably can be
3010 C extrapolated into understanding how the compiler
3011 C generally treats specific intrinsics that are passed
3012 C arguments not of the correct types.
3013 C
3014 C If your compiler implements INTEGER*2 and INTEGER
3015 C as the same type, change all INTEGER*2 below to
3016 C INTEGER*1.
3017 C
3018       INTEGER*2 I0, I4
3019       INTEGER I1, I2, I3
3020       INTEGER*2 ISMALL, ILARGE
3021       INTEGER*2 ITOOLG, ITWO
3022       INTEGER*2 ITMP
3023       LOGICAL L2, L3, L4
3024 C
3025 C Find smallest INTEGER*2 number.
3026 C
3027       ISMALL=0
3028  10   I0 = ISMALL-1
3029       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
3030       ISMALL = I0
3031       GOTO 10
3032  20   CONTINUE
3033 C
3034 C Find largest INTEGER*2 number.
3035 C
3036       ILARGE=0
3037  30   I0 = ILARGE+1
3038       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
3039       ILARGE = I0
3040       GOTO 30
3041  40   CONTINUE
3042 C
3043 C Multiplying by two adds stress to the situation.
3044 C
3045       ITWO = 2
3046 C
3047 C Need a number that, added to -2, is too wide to fit in I*2.
3048 C
3049       ITOOLG = ISMALL
3050 C
3051 C Use IDIM the straightforward way.
3052 C
3053       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
3054 C
3055 C Calculate result for first interpretation.
3056 C
3057       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
3058 C
3059 C Calculate result for second interpretation.
3060 C
3061       ITMP = ILARGE - ISMALL
3062       I3 = (INT (ITMP)) * ITWO + ITOOLG
3063 C
3064 C Calculate result for third interpretation.
3065 C
3066       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
3067 C
3068 C Print results.
3069 C
3070       PRINT *, 'ILARGE=', ILARGE
3071       PRINT *, 'ITWO=', ITWO
3072       PRINT *, 'ITOOLG=', ITOOLG
3073       PRINT *, 'ISMALL=', ISMALL
3074       PRINT *, 'I1=', I1
3075       PRINT *, 'I2=', I2
3076       PRINT *, 'I3=', I3
3077       PRINT *, 'I4=', I4
3078       PRINT *
3079       L2 = (I1 .EQ. I2)
3080       L3 = (I1 .EQ. I3)
3081       L4 = (I1 .EQ. I4)
3082       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
3083          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
3084          STOP
3085       END IF
3086       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
3087          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
3088          STOP
3089       END IF
3090       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
3091          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
3092          STOP
3093       END IF
3094       PRINT *, 'Results need careful analysis.'
3095       END
3096 @end smallexample
3097
3098 No future version of the GNU Fortran language
3099 will likely permit specific intrinsic invocations with wrong-typed
3100 arguments (such as @code{IDIM} in the above example), since
3101 it has been determined that disagreements exist among
3102 many production compilers on the interpretation of
3103 such invocations.
3104 These disagreements strongly suggest that Fortran programmers,
3105 and certainly existing Fortran programs, disagree about the
3106 meaning of such invocations.
3107
3108 The first version of @code{JCB002} didn't accommodate some compilers'
3109 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
3110 @code{INTEGER*2}.
3111 In such a case, these compilers apparently convert both
3112 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
3113 instead of doing an @code{INTEGER*2} subtraction on the
3114 original values in @samp{I1} and @samp{I2}.
3115
3116 However, the results of the careful analyses done on the outputs
3117 of programs compiled by these various compilers show that they
3118 all implement either @samp{Interp 1} or @samp{Interp 2} above.
3119
3120 Specifically, it is believed that the new version of @code{JCB002}
3121 above will confirm that:
3122
3123 @itemize @bullet
3124 @item
3125 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
3126 @command{f77} compilers all implement @samp{Interp 1}.
3127
3128 @item
3129 IRIX 5.3 @command{f77} compiler implements @samp{Interp 2}.
3130
3131 @item
3132 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
3133 and IRIX 6.1 @command{f77} compilers all implement @samp{Interp 3}.
3134 @end itemize
3135
3136 If you get different results than the above for the stated
3137 compilers, or have results for other compilers that might be
3138 worth adding to the above list, please let us know the details
3139 (compiler product, version, machine, results, and so on).
3140
3141 @node REAL() and AIMAG() of Complex
3142 @subsection @code{REAL()} and @code{AIMAG()} of Complex
3143 @cindex @code{Real} intrinsic
3144 @cindex intrinsics, @code{Real}
3145 @cindex @code{AImag} intrinsic
3146 @cindex intrinsics, @code{AImag}
3147
3148 The GNU Fortran language disallows @code{REAL(@var{expr})}
3149 and @code{AIMAG(@var{expr})},
3150 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
3151 except when they are used in the following way:
3152
3153 @example
3154 REAL(REAL(@var{expr}))
3155 REAL(AIMAG(@var{expr}))
3156 @end example
3157
3158 @noindent
3159 The above forms explicitly specify that the desired effect
3160 is to convert the real or imaginary part of @var{expr}, which might
3161 be some @code{REAL} type other than @code{REAL(KIND=1)},
3162 to type @code{REAL(KIND=1)},
3163 and have that serve as the value of the expression.
3164
3165 The GNU Fortran language offers clearly named intrinsics to extract the
3166 real and imaginary parts of a complex entity without any
3167 conversion:
3168
3169 @example
3170 REALPART(@var{expr})
3171 IMAGPART(@var{expr})
3172 @end example
3173
3174 To express the above using typical extended FORTRAN 77,
3175 use the following constructs
3176 (when @var{expr} is @code{COMPLEX(KIND=2)}):
3177
3178 @example
3179 DBLE(@var{expr})
3180 DIMAG(@var{expr})
3181 @end example
3182
3183 The FORTRAN 77 language offers no way
3184 to explicitly specify the real and imaginary parts of a complex expression of
3185 arbitrary type, apparently as a result of requiring support for
3186 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
3187 The concepts of converting an expression to type @code{REAL(KIND=1)} and
3188 of extracting the real part of a complex expression were
3189 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
3190 they happened to have the exact same effect in that language
3191 (due to having only one @code{COMPLEX} type).
3192
3193 @emph{Note:} When @option{-ff90} is in effect,
3194 @command{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
3195 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
3196 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
3197 treated as @samp{REAL(REALPART(@var{expr}))}.
3198
3199 @xref{Ugly Complex Part Extraction}, for more information.
3200
3201 @node CMPLX() of DOUBLE PRECISION
3202 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
3203 @cindex @code{Cmplx} intrinsic
3204 @cindex intrinsics, @code{Cmplx}
3205
3206 In accordance with Fortran 90 and at least some (perhaps all)
3207 other compilers, the GNU Fortran language defines @code{CMPLX()}
3208 as always returning a result that is type @code{COMPLEX(KIND=1)}.
3209
3210 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
3211 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
3212
3213 @example
3214 CMPLX(SNGL(D1), SNGL(D2))
3215 @end example
3216
3217 (It was necessary for Fortran 90 to specify this behavior
3218 for @code{DOUBLE PRECISION} arguments, since that is
3219 the behavior mandated by FORTRAN 77.)
3220
3221 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
3222 which is provided by some FORTRAN 77 compilers to construct
3223 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
3224 operands.
3225 However, this solution does not scale well when more @code{COMPLEX} types
3226 (having various precisions and ranges) are offered by Fortran implementations.
3227
3228 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
3229 an extra argument used to specify the desired kind of complex
3230 result.
3231 However, this solution is somewhat awkward to use, and
3232 @command{g77} currently does not support it.
3233
3234 The GNU Fortran language provides a simple way to build a complex
3235 value out of two numbers, with the precise type of the value
3236 determined by the types of the two numbers (via the usual
3237 type-promotion mechanism):
3238
3239 @example
3240 COMPLEX(@var{real}, @var{imag})
3241 @end example
3242
3243 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
3244 performs no conversion other than to put them together to form a
3245 complex result of the same (complex version of real) type.
3246
3247 @xref{Complex Intrinsic}, for more information.
3248
3249 @node MIL-STD 1753
3250 @subsection MIL-STD 1753 Support
3251 @cindex MIL-STD 1753
3252
3253 The GNU Fortran language includes the MIL-STD 1753 intrinsics
3254 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
3255 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
3256 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
3257
3258 @node f77/f2c Intrinsics
3259 @subsection @command{f77}/@command{f2c} Intrinsics
3260
3261 The bit-manipulation intrinsics supported by traditional
3262 @command{f77} and by @command{f2c} are available in the GNU Fortran language.
3263 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
3264 and @code{XOR}.
3265
3266 Also supported are the intrinsics @code{CDABS},
3267 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
3268 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
3269 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
3270 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
3271 and @code{ZSQRT}.
3272
3273 @node Table of Intrinsic Functions
3274 @subsection Table of Intrinsic Functions
3275 @cindex intrinsics, table of
3276 @cindex table of intrinsics
3277
3278 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
3279
3280 The GNU Fortran language adds various functions, subroutines, types,
3281 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
3282 The complete set of intrinsics supported by the GNU Fortran language
3283 is described below.
3284
3285 Note that a name is not treated as that of an intrinsic if it is
3286 specified in an @code{EXTERNAL} statement in the same program unit;
3287 if a command-line option is used to disable the groups to which
3288 the intrinsic belongs; or if the intrinsic is not named in an
3289 @code{INTRINSIC} statement and a command-line option is used to
3290 hide the groups to which the intrinsic belongs.
3291
3292 So, it is recommended that any reference in a program unit to
3293 an intrinsic procedure that is not a standard FORTRAN 77
3294 intrinsic be accompanied by an appropriate @code{INTRINSIC}
3295 statement in that program unit.
3296 This sort of defensive programming makes it more
3297 likely that an implementation will issue a diagnostic rather
3298 than generate incorrect code for such a reference.
3299
3300 The terminology used below is based on that of the Fortran 90
3301 standard, so that the text may be more concise and accurate:
3302
3303 @itemize @bullet
3304 @item
3305 @code{OPTIONAL} means the argument may be omitted.
3306
3307 @item
3308 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
3309 (generally named @samp{A}) may be specified.
3310
3311 @item
3312 @samp{scalar} means the argument must not be an array (must
3313 be a variable or array element, or perhaps a constant if expressions
3314 are permitted).
3315
3316 @item
3317 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
3318
3319 @item
3320 @code{INTENT(IN)} means the argument must be an expression
3321 (such as a constant or a variable that is defined upon invocation
3322 of the intrinsic).
3323
3324 @item
3325 @code{INTENT(OUT)} means the argument must be definable by the
3326 invocation of the intrinsic (that is, must not be a constant nor
3327 an expression involving operators other than array reference and
3328 substring reference).
3329
3330 @item
3331 @code{INTENT(INOUT)} means the argument must be defined prior to,
3332 and definable by, invocation of the intrinsic (a combination of
3333 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
3334
3335 @item
3336 @xref{Kind Notation}, for an explanation of @code{KIND}.
3337 @end itemize
3338
3339 @ifinfo
3340 (Note that the empty lines appearing in the menu below
3341 are not intentional---they result from a bug in the
3342 GNU @command{makeinfo} program@dots{}a program that, if it
3343 did not exist, would leave this document in far worse shape!)
3344 @end ifinfo
3345
3346 @c The actual documentation for intrinsics comes from
3347 @c intdoc.texi, which in turn is automatically generated
3348 @c from the internal g77 tables in intrin.def _and_ the
3349 @c largely hand-written text in intdoc.h.  So, if you want
3350 @c to change or add to existing documentation on intrinsics,
3351 @c you probably want to edit intdoc.h.
3352 @c
3353 @set familyF77
3354 @set familyGNU
3355 @set familyASC
3356 @set familyMIL
3357 @set familyF90
3358 @clear familyVXT
3359 @clear familyFVZ
3360 @set familyF2C
3361 @set familyF2U
3362 @clear familyBADU77
3363 @include intdoc.texi
3364
3365 @node Scope and Classes of Names
3366 @section Scope and Classes of Symbolic Names
3367 @cindex symbol names, scope and classes
3368 @cindex scope
3369
3370 (The following information augments or overrides the information in
3371 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3372 language.
3373 Chapter 18 of that document otherwise serves as the basis
3374 for the relevant aspects of GNU Fortran.)
3375
3376 @menu
3377 * Underscores in Symbol Names::
3378 @end menu
3379
3380 @node Underscores in Symbol Names
3381 @subsection Underscores in Symbol Names
3382 @cindex underscore
3383
3384 Underscores (@samp{_}) are accepted in symbol names after the first
3385 character (which must be a letter).
3386
3387 @node I/O
3388 @section I/O
3389
3390 @cindex dollar sign
3391 A dollar sign at the end of an output format specification suppresses
3392 the newline at the end of the output.
3393
3394 @cindex <> edit descriptor
3395 @cindex edit descriptor, <>
3396 Edit descriptors in @code{FORMAT} statements may contain compile-time
3397 @code{INTEGER} constant expressions in angle brackets, such as
3398 @smallexample
3399 10    FORMAT (I<WIDTH>)
3400 @end smallexample
3401
3402 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
3403
3404 These Fortran 90 features are supported:
3405 @itemize @bullet
3406 @item
3407 @cindex FORMAT descriptors
3408 @cindex Z edit descriptor
3409 @cindex edit descriptor, Z
3410 @cindex O edit descriptor
3411 @cindex edit descriptor, O
3412 The @code{O} and @code{Z} edit descriptors are supported for I/O of
3413 integers in octal and hexadecimal formats, respectively.
3414 @item
3415 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
3416 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
3417 specifier is supported.
3418 @end itemize
3419
3420 @node Fortran 90 Features
3421 @section Fortran 90 Features
3422 @cindex Fortran 90
3423 @cindex extensions, from Fortran 90
3424
3425 For convenience this section collects a list (probably incomplete) of
3426 the Fortran 90 features supported by the GNU Fortran language, even if
3427 they are documented elsewhere.
3428 @xref{Characters Lines Sequence,,@asis{Characters, Lines, and Execution Sequence}},
3429 for information on additional fixed source form lexical issues.
3430 @cindex @option{-ffree-form}
3431 Further, the free source form is supported through the
3432 @option{-ffree-form} option.
3433 @cindex @option{-ff90}
3434 Other Fortran 90 features can be turned on by the @option{-ff90} option;
3435 see @ref{Fortran 90}.
3436 For information on the Fortran 90 intrinsics available,
3437 see @ref{Table of Intrinsic Functions}.
3438
3439 @table @asis
3440 @item Automatic arrays in procedures
3441 @item Character assignments
3442 @cindex character assignments
3443 In character assignments, the variable being assigned may occur on the
3444 right hand side of the assignment.
3445 @item Character strings
3446 @cindex double quoted character constants
3447 Strings may have zero length and substrings of character constants are
3448 permitted.  Character constants may be enclosed in double quotes
3449 (@code{"}) as well as single quotes.  @xref{Character Type}.
3450 @item Construct names
3451 (Symbolic tags on blocks.)  @xref{Construct Names}.
3452 @item @code{CYCLE} and @code{EXIT}
3453 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
3454 @item @code{DOUBLE COMPLEX}
3455 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement}.
3456 @item @code{DO WHILE}
3457 @xref{DO WHILE}.
3458 @item @code{END} decoration
3459 @xref{Statements}.
3460 @item @code{END DO}
3461 @xref{END DO}.
3462 @item @code{KIND}
3463 @item @code{IMPLICIT NONE}
3464 @item @code{INCLUDE} statements
3465 @xref{INCLUDE}.
3466 @item List-directed and namelist I/O on internal files
3467 @item Binary, octal and hexadecimal constants
3468 These are supported more generally than required by Fortran 90.
3469 @xref{Integer Type}.
3470 @item @samp{O} and @samp{Z} edit descriptors
3471 @item @code{NAMELIST}
3472 @xref{NAMELIST}.
3473 @item @code{OPEN} specifiers
3474 @code{STATUS='REPLACE'} is supported.
3475 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
3476 @code{STATUS='SCRATCH'} is supplied.
3477 @item @code{FORMAT} edit descriptors
3478 @cindex FORMAT descriptors
3479 @cindex Z edit descriptor
3480 @cindex edit descriptor, Z
3481 The @code{Z} edit descriptor is supported.
3482 @item Relational operators
3483 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
3484 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
3485 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
3486 @item @code{SELECT CASE}
3487 Not fully implemented.
3488 @xref{SELECT CASE on CHARACTER Type,, @code{SELECT CASE} on @code{CHARACTER} Type}.
3489 @item Specification statements
3490 A limited subset of the Fortran 90 syntax and semantics for variable
3491 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
3492 (@code{KIND} is of limited usefulness in the absence of the
3493 @code{KIND}-related intrinsics, since these intrinsics permit writing
3494 more widely portable code.)  An example of supported @code{KIND} usage
3495 is:
3496 @smallexample
3497 INTEGER (KIND=1) :: FOO=1, BAR=2
3498 CHARACTER (LEN=3) FOO
3499 @end smallexample
3500 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
3501 @end table
3502
3503 @node Other Dialects
3504 @chapter Other Dialects
3505
3506 GNU Fortran supports a variety of features that are not
3507 considered part of the GNU Fortran language itself, but
3508 are representative of various dialects of Fortran that
3509 @command{g77} supports in whole or in part.
3510
3511 Any of the features listed below might be disallowed by
3512 @command{g77} unless some command-line option is specified.
3513 Currently, some of the features are accepted using the
3514 default invocation of @command{g77}, but that might change
3515 in the future.
3516
3517 @emph{Note: This portion of the documentation definitely needs a lot
3518 of work!}
3519
3520 @menu
3521 * Source Form::       Details of fixed-form and free-form source.
3522 * Trailing Comment::  Use of @samp{/*} to start a comment.
3523 * Debug Line::        Use of @samp{D} in column 1.
3524 * Dollar Signs::      Use of @samp{$} in symbolic names.
3525 * Case Sensitivity::  Uppercase and lowercase in source files.
3526 * VXT Fortran::       @dots{}versus the GNU Fortran language.
3527 * Fortran 90::        @dots{}versus the GNU Fortran language.
3528 * Pedantic Compilation::  Enforcing the standard.
3529 * Distensions::       Misfeatures supported by GNU Fortran.
3530 @end menu
3531
3532 @node Source Form
3533 @section Source Form
3534 @cindex source file format
3535 @cindex source format
3536 @cindex file, source
3537 @cindex source code
3538 @cindex code, source
3539 @cindex fixed form
3540 @cindex free form
3541
3542 GNU Fortran accepts programs written in either fixed form or
3543 free form.
3544
3545 Fixed form
3546 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
3547 allowing tabs) and Fortran 90's fixed form.
3548
3549 Free form corresponds to
3550 Fortran 90's free form (though possibly not entirely up-to-date, and
3551 without complaining about some things that for which Fortran 90 requires
3552 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
3553
3554 The way a Fortran compiler views source files depends entirely on the
3555 implementation choices made for the compiler, since those choices
3556 are explicitly left to the implementation by the published Fortran
3557 standards.
3558 GNU Fortran currently tries to be somewhat like a few popular compilers
3559 (@command{f2c}, Digital (``DEC'') Fortran, and so on).
3560
3561 This section describes how @command{g77} interprets source lines.
3562
3563 @menu
3564 * Carriage Returns::  Carriage returns ignored.
3565 * Tabs::              Tabs converted to spaces.
3566 * Short Lines::       Short lines padded with spaces (fixed-form only).
3567 * Long Lines::        Long lines truncated.
3568 * Ampersands::        Special Continuation Lines.
3569 @end menu
3570
3571 @node Carriage Returns
3572 @subsection Carriage Returns
3573 @cindex carriage returns
3574
3575 Carriage returns (@samp{\r}) in source lines are ignored.
3576 This is somewhat different from @command{f2c}, which seems to treat them as
3577 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
3578 inside such constants.
3579
3580 @node Tabs
3581 @subsection Tabs
3582 @cindex tab character
3583 @cindex horizontal tab
3584
3585 A source line with a @key{TAB} character anywhere in it is treated as
3586 entirely significant---however long it is---instead of ending in
3587 column 72 (for fixed-form source) or 132 (for free-form source).
3588 This also is different from @command{f2c}, which encodes tabs as
3589 @samp{\t} (the ASCII @key{TAB} character) inside character
3590 and Hollerith constants, but nevertheless seems to treat the column
3591 position as if it had been affected by the canonical tab positioning.
3592
3593 @command{g77} effectively
3594 translates tabs to the appropriate number of spaces (a la the default
3595 for the UNIX @command{expand} command) before doing any other processing, other
3596 than (currently) noting whether a tab was found on a line and using this
3597 information to decide how to interpret the length of the line and continued
3598 constants.
3599
3600 @node Short Lines
3601 @subsection Short Lines
3602 @cindex short source lines
3603 @cindex space, padding with
3604 @cindex source lines, short
3605 @cindex lines, short
3606
3607 Source lines shorter than the applicable fixed-form length are treated as
3608 if they were padded with spaces to that length.
3609 (None of this is relevant to source files written in free form.)
3610
3611 This affects only
3612 continued character and Hollerith constants, and is a different
3613 interpretation than provided by some other popular compilers
3614 (although a bit more consistent with the traditional punched-card
3615 basis of Fortran and the way the Fortran standard expressed fixed
3616 source form).
3617
3618 @command{g77} might someday offer an option to warn about cases where differences
3619 might be seen as a result of this treatment, and perhaps an option to
3620 specify the alternate behavior as well.
3621
3622 Note that this padding cannot apply to lines that are effectively of
3623 infinite length---such lines are specified using command-line options
3624 like @option{-ffixed-line-length-none}, for example.
3625
3626 @node Long Lines
3627 @subsection Long Lines
3628 @cindex long source lines
3629 @cindex truncation, of long lines
3630 @cindex lines, long
3631 @cindex source lines, long
3632
3633 Source lines longer than the applicable length are truncated to that
3634 length.
3635 Currently, @command{g77} does not warn if the truncated characters are
3636 not spaces, to accommodate existing code written for systems that
3637 treated truncated text as commentary (especially in columns 73 through 80).
3638
3639 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
3640 for information on the @option{-ffixed-line-length-@var{n}} option,
3641 which can be used to set the line length applicable to fixed-form
3642 source files.
3643
3644 @node Ampersands
3645 @subsection Ampersand Continuation Line
3646 @cindex ampersand continuation line
3647 @cindex continuation line, ampersand
3648
3649 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
3650 continuation line, imitating the behavior of @command{f2c}.
3651
3652 @node Trailing Comment
3653 @section Trailing Comment
3654
3655 @cindex trailing comment
3656 @cindex comment
3657 @cindex characters, comment
3658 @cindex /*
3659 @cindex !
3660 @cindex exclamation point
3661 @command{g77} supports use of @samp{/*} to start a trailing
3662 comment.
3663 In the GNU Fortran language, @samp{!} is used for this purpose.
3664
3665 @samp{/*} is not in the GNU Fortran language
3666 because the use of @samp{/*} in a program might
3667 suggest to some readers that a block, not trailing, comment is
3668 started (and thus ended by @samp{*/}, not end of line),
3669 since that is the meaning of @samp{/*} in C.
3670
3671 Also, such readers might think they can use @samp{//} to start
3672 a trailing comment as an alternative to @samp{/*}, but
3673 @samp{//} already denotes concatenation, and such a ``comment''
3674 might actually result in a program that compiles without
3675 error (though it would likely behave incorrectly).
3676
3677 @node Debug Line
3678 @section Debug Line
3679 @cindex debug line
3680 @cindex comment line, debug
3681
3682 Use of @samp{D} or @samp{d} as the first character (column 1) of
3683 a source line denotes a debug line.
3684
3685 In turn, a debug line is treated as either a comment line
3686 or a normal line, depending on whether debug lines are enabled.
3687
3688 When treated as a comment line, a line beginning with @samp{D} or
3689 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
3690 When treated as a normal line, such a line is treated as if
3691 the first character was @key{SPC} (space).
3692
3693 (Currently, @command{g77} provides no means for treating debug
3694 lines as normal lines.)
3695
3696 @node Dollar Signs
3697 @section Dollar Signs in Symbol Names
3698 @cindex dollar sign
3699 @cindex $
3700
3701 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
3702 when the @option{-fdollar-ok} option is specified.
3703
3704 @node Case Sensitivity
3705 @section Case Sensitivity
3706 @cindex case sensitivity
3707 @cindex source file format
3708 @cindex code, source
3709 @cindex source code
3710 @cindex uppercase letters
3711 @cindex lowercase letters
3712 @cindex letters, uppercase
3713 @cindex letters, lowercase
3714
3715 GNU Fortran offers the programmer way too much flexibility in deciding
3716 how source files are to be treated vis-a-vis uppercase and lowercase
3717 characters.
3718 There are 66 useful settings that affect case sensitivity, plus 10
3719 settings that are nearly useless, with the remaining 116 settings
3720 being either redundant or useless.
3721
3722 None of these settings have any effect on the contents of comments
3723 (the text after a @samp{c} or @samp{C} in Column 1, for example)
3724 or of character or Hollerith constants.
3725 Note that things like the @samp{E} in the statement
3726 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
3727 are considered built-in keywords, and so are affected by
3728 these settings.
3729
3730 Low-level switches are identified in this section as follows:
3731
3732 @itemize @w{}
3733 @item A
3734 Source Case Conversion:
3735
3736 @itemize @w{}
3737 @item 0
3738 Preserve (see Note 1)
3739 @item 1
3740 Convert to Upper Case
3741 @item 2
3742 Convert to Lower Case
3743 @end itemize
3744
3745 @item B
3746 Built-in Keyword Matching:
3747
3748 @itemize @w{}
3749 @item 0
3750 Match Any Case (per-character basis)
3751 @item 1
3752 Match Upper Case Only
3753 @item 2
3754 Match Lower Case Only
3755 @item 3
3756 Match InitialCaps Only (see tables for spellings)
3757 @end itemize
3758
3759 @item C
3760 Built-in Intrinsic Matching:
3761
3762 @itemize @w{}
3763 @item 0
3764 Match Any Case (per-character basis)
3765 @item 1
3766 Match Upper Case Only
3767 @item 2
3768 Match Lower Case Only
3769 @item 3
3770 Match InitialCaps Only (see tables for spellings)
3771 @end itemize
3772
3773 @item D
3774 User-defined Symbol Possibilities (warnings only):
3775
3776 @itemize @w{}
3777 @item 0
3778 Allow Any Case (per-character basis)
3779 @item 1
3780 Allow Upper Case Only
3781 @item 2
3782 Allow Lower Case Only
3783 @item 3
3784 Allow InitialCaps Only (see Note 2)
3785 @end itemize
3786 @end itemize
3787
3788 Note 1: @command{g77} eventually will support @code{NAMELIST} in a manner that is
3789 consistent with these source switches---in the sense that input will be
3790 expected to meet the same requirements as source code in terms
3791 of matching symbol names and keywords (for the exponent letters).
3792
3793 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
3794 which uppercases @code{NAMELIST} input and symbol names for matching.
3795 This means not only that @code{NAMELIST} output currently shows symbol
3796 (and keyword) names in uppercase even if lower-case source
3797 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
3798 adequately supported when source case preservation (option A0)
3799 is selected.
3800
3801 If A0 is selected, a warning message will be
3802 output for each @code{NAMELIST} statement to this effect.
3803 The behavior
3804 of the program is undefined at run time if two or more symbol names
3805 appear in a given @code{NAMELIST} such that the names are identical
3806 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
3807 For complete and total elegance, perhaps there should be a warning
3808 when option A2 is selected, since the output of NAMELIST is currently
3809 in uppercase but will someday be lowercase (when a @code{libg77} is written),
3810 but that seems to be overkill for a product in beta test.
3811
3812 Note 2: Rules for InitialCaps names are:
3813
3814 @itemize @minus
3815 @item
3816 Must be a single uppercase letter, @strong{or}
3817 @item
3818 Must start with an uppercase letter and contain at least one
3819 lowercase letter.
3820 @end itemize
3821
3822 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
3823 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
3824 not.
3825 Note that most, but not all, built-in names meet these
3826 requirements---the exceptions are some of the two-letter format
3827 specifiers, such as @code{BN} and @code{BZ}.
3828
3829 Here are the names of the corresponding command-line options:
3830
3831 @smallexample
3832 A0: -fsource-case-preserve
3833 A1: -fsource-case-upper
3834 A2: -fsource-case-lower
3835
3836 B0: -fmatch-case-any
3837 B1: -fmatch-case-upper
3838 B2: -fmatch-case-lower
3839 B3: -fmatch-case-initcap
3840
3841 C0: -fintrin-case-any
3842 C1: -fintrin-case-upper
3843 C2: -fintrin-case-lower
3844 C3: -fintrin-case-initcap
3845
3846 D0: -fsymbol-case-any
3847 D1: -fsymbol-case-upper
3848 D2: -fsymbol-case-lower
3849 D3: -fsymbol-case-initcap
3850 @end smallexample
3851
3852 Useful combinations of the above settings, along with abbreviated
3853 option names that set some of these combinations all at once:
3854
3855 @smallexample
3856  1: A0--  B0---  C0---  D0---    -fcase-preserve
3857  2: A0--  B0---  C0---  D-1--
3858  3: A0--  B0---  C0---  D--2-
3859  4: A0--  B0---  C0---  D---3
3860  5: A0--  B0---  C-1--  D0---
3861  6: A0--  B0---  C-1--  D-1--
3862  7: A0--  B0---  C-1--  D--2-
3863  8: A0--  B0---  C-1--  D---3
3864  9: A0--  B0---  C--2-  D0---
3865 10: A0--  B0---  C--2-  D-1--
3866 11: A0--  B0---  C--2-  D--2-
3867 12: A0--  B0---  C--2-  D---3
3868 13: A0--  B0---  C---3  D0---
3869 14: A0--  B0---  C---3  D-1--
3870 15: A0--  B0---  C---3  D--2-
3871 16: A0--  B0---  C---3  D---3
3872 17: A0--  B-1--  C0---  D0---
3873 18: A0--  B-1--  C0---  D-1--
3874 19: A0--  B-1--  C0---  D--2-
3875 20: A0--  B-1--  C0---  D---3
3876 21: A0--  B-1--  C-1--  D0---
3877 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
3878 23: A0--  B-1--  C-1--  D--2-
3879 24: A0--  B-1--  C-1--  D---3
3880 25: A0--  B-1--  C--2-  D0---
3881 26: A0--  B-1--  C--2-  D-1--
3882 27: A0--  B-1--  C--2-  D--2-
3883 28: A0--  B-1--  C--2-  D---3
3884 29: A0--  B-1--  C---3  D0---
3885 30: A0--  B-1--  C---3  D-1--
3886 31: A0--  B-1--  C---3  D--2-
3887 32: A0--  B-1--  C---3  D---3
3888 33: A0--  B--2-  C0---  D0---
3889 34: A0--  B--2-  C0---  D-1--
3890 35: A0--  B--2-  C0---  D--2-
3891 36: A0--  B--2-  C0---  D---3
3892 37: A0--  B--2-  C-1--  D0---
3893 38: A0--  B--2-  C-1--  D-1--
3894 39: A0--  B--2-  C-1--  D--2-
3895 40: A0--  B--2-  C-1--  D---3
3896 41: A0--  B--2-  C--2-  D0---
3897 42: A0--  B--2-  C--2-  D-1--
3898 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
3899 44: A0--  B--2-  C--2-  D---3
3900 45: A0--  B--2-  C---3  D0---
3901 46: A0--  B--2-  C---3  D-1--
3902 47: A0--  B--2-  C---3  D--2-
3903 48: A0--  B--2-  C---3  D---3
3904 49: A0--  B---3  C0---  D0---
3905 50: A0--  B---3  C0---  D-1--
3906 51: A0--  B---3  C0---  D--2-
3907 52: A0--  B---3  C0---  D---3
3908 53: A0--  B---3  C-1--  D0---
3909 54: A0--  B---3  C-1--  D-1--
3910 55: A0--  B---3  C-1--  D--2-
3911 56: A0--  B---3  C-1--  D---3
3912 57: A0--  B---3  C--2-  D0---
3913 58: A0--  B---3  C--2-  D-1--
3914 59: A0--  B---3  C--2-  D--2-
3915 60: A0--  B---3  C--2-  D---3
3916 61: A0--  B---3  C---3  D0---
3917 62: A0--  B---3  C---3  D-1--
3918 63: A0--  B---3  C---3  D--2-
3919 64: A0--  B---3  C---3  D---3    -fcase-initcap
3920 65: A-1-  B01--  C01--  D01--    -fcase-upper
3921 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
3922 @end smallexample
3923
3924 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
3925 (except comments, character constants, and Hollerith strings) must
3926 be entered in uppercase.
3927 Use @option{-fcase-strict-upper} to specify this
3928 combination.
3929
3930 Number 43 is like Number 22 except all input must be lowercase.  Use
3931 @option{-fcase-strict-lower} to specify this combination.
3932
3933 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
3934 non-UNIX machines whereby all the source is translated to uppercase.
3935 Use @option{-fcase-upper} to specify this combination.
3936
3937 Number 66 is the ``canonical'' UNIX model whereby all the source is
3938 translated to lowercase.
3939 Use @option{-fcase-lower} to specify this combination.
3940
3941 There are a few nearly useless combinations:
3942
3943 @smallexample
3944 67: A-1-  B01--  C01--  D--2-
3945 68: A-1-  B01--  C01--  D---3
3946 69: A-1-  B01--  C--23  D01--
3947 70: A-1-  B01--  C--23  D--2-
3948 71: A-1-  B01--  C--23  D---3
3949 72: A--2  B01--  C0-2-  D-1--
3950 73: A--2  B01--  C0-2-  D---3
3951 74: A--2  B01--  C-1-3  D0-2-
3952 75: A--2  B01--  C-1-3  D-1--
3953 76: A--2  B01--  C-1-3  D---3
3954 @end smallexample
3955
3956 The above allow some programs to be compiled but with restrictions that
3957 make most useful programs impossible: Numbers 67 and 72 warn about
3958 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
3959 Numbers
3960 68 and 73 warn about any user-defined symbol names longer than one
3961 character that don't have at least one non-alphabetic character after
3962 the first;
3963 Numbers 69 and 74 disallow any references to intrinsics;
3964 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
3965 67+69, 68+69, 72+74, and 73+74, respectively.
3966
3967 All redundant combinations are shown in the above tables anyplace
3968 where more than one setting is shown for a low-level switch.
3969 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
3970 The ``proper'' setting in such a case is the one that copies the setting
3971 of switch A---any other setting might slightly reduce the speed of
3972 the compiler, though possibly to an unmeasurable extent.
3973
3974 All remaining combinations are useless in that they prevent successful
3975 compilation of non-null source files (source files with something other
3976 than comments).
3977
3978 @node VXT Fortran
3979 @section VXT Fortran
3980
3981 @cindex VXT extensions
3982 @cindex extensions, VXT
3983 @command{g77} supports certain constructs that
3984 have different meanings in VXT Fortran than they
3985 do in the GNU Fortran language.
3986
3987 Generally, this manual uses the invented term VXT Fortran to refer
3988 VAX FORTRAN (circa v4).
3989 That compiler offered many popular features, though not necessarily
3990 those that are specific to the VAX processor architecture,
3991 the VMS operating system,
3992 or Digital Equipment Corporation's Fortran product line.
3993 (VAX and VMS probably are trademarks of Digital Equipment
3994 Corporation.)
3995
3996 An extension offered by a Digital Fortran product that also is
3997 offered by several other Fortran products for different kinds of
3998 systems is probably going to be considered for inclusion in @command{g77}
3999 someday, and is considered a VXT Fortran feature.
4000
4001 The @option{-fvxt} option generally specifies that, where
4002 the meaning of a construct is ambiguous (means one thing
4003 in GNU Fortran and another in VXT Fortran), the VXT Fortran
4004 meaning is to be assumed.
4005
4006 @menu
4007 * Double Quote Meaning::  @samp{"2000} as octal constant.
4008 * Exclamation Point::     @samp{!} in column 6.
4009 @end menu
4010
4011 @node Double Quote Meaning
4012 @subsection Meaning of Double Quote
4013 @cindex double quotes
4014 @cindex character constants
4015 @cindex constants, character
4016 @cindex octal constants
4017 @cindex constants, octal
4018
4019 @command{g77} treats double-quote (@samp{"})
4020 as beginning an octal constant of @code{INTEGER(KIND=1)} type
4021 when the @option{-fvxt} option is specified.
4022 The form of this octal constant is
4023
4024 @example
4025 "@var{octal-digits}
4026 @end example
4027
4028 @noindent
4029 where @var{octal-digits} is a nonempty string of characters in
4030 the set @samp{01234567}.
4031
4032 For example, the @option{-fvxt} option permits this:
4033
4034 @example
4035 PRINT *, "20
4036 END
4037 @end example
4038
4039 @noindent
4040 The above program would print the value @samp{16}.
4041
4042 @xref{Integer Type}, for information on the preferred construct
4043 for integer constants specified using GNU Fortran's octal notation.
4044
4045 (In the GNU Fortran language, the double-quote character (@samp{"})
4046 delimits a character constant just as does apostrophe (@samp{'}).
4047 There is no way to allow
4048 both constructs in the general case, since statements like
4049 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
4050
4051 @node Exclamation Point
4052 @subsection Meaning of Exclamation Point in Column 6
4053 @cindex !
4054 @cindex exclamation point
4055 @cindex continuation character
4056 @cindex characters, continuation
4057 @cindex comment character
4058 @cindex characters, comment
4059
4060 @command{g77} treats an exclamation point (@samp{!}) in column 6 of
4061 a fixed-form source file
4062 as a continuation character rather than
4063 as the beginning of a comment
4064 (as it does in any other column)
4065 when the @option{-fvxt} option is specified.
4066
4067 The following program, when run, prints a message indicating
4068 whether it is interpreted according to GNU Fortran (and Fortran 90)
4069 rules or VXT Fortran rules:
4070
4071 @smallexample
4072 C234567  (This line begins in column 1.)
4073       I = 0
4074      !1
4075       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
4076       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
4077       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
4078       END
4079 @end smallexample
4080
4081 (In the GNU Fortran and Fortran 90 languages, exclamation point is
4082 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
4083 marks a line as a continuation line when it appears in column 6.)
4084
4085 @node Fortran 90
4086 @section Fortran 90
4087 @cindex compatibility, Fortran 90
4088 @cindex Fortran 90, compatibility
4089
4090 The GNU Fortran language includes a number of features that are
4091 part of Fortran 90, even when the @option{-ff90} option is not specified.
4092 The features enabled by @option{-ff90} are intended to be those that,
4093 when @option{-ff90} is not specified, would have another
4094 meaning to @command{g77}---usually meaning something invalid in the
4095 GNU Fortran language.
4096
4097 So, the purpose of @option{-ff90} is not to specify whether @command{g77} is
4098 to gratuitously reject Fortran 90 constructs.
4099 The @option{-pedantic} option specified with @option{-fno-f90} is intended
4100 to do that, although its implementation is certainly incomplete at
4101 this point.
4102
4103 When @option{-ff90} is specified:
4104
4105 @itemize @bullet
4106 @item
4107 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
4108 where @var{expr} is @code{COMPLEX} type,
4109 is the same type as the real part of @var{expr}.
4110
4111 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
4112 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
4113 not of type @code{REAL(KIND=1)}, since @option{-ff90} is specified.
4114 @end itemize
4115
4116 @node Pedantic Compilation
4117 @section Pedantic Compilation
4118 @cindex pedantic compilation
4119 @cindex compilation, pedantic
4120
4121 The @option{-fpedantic} command-line option specifies that @command{g77}
4122 is to warn about code that is not standard-conforming.
4123 This is useful for finding
4124 some extensions @command{g77} accepts that other compilers might not accept.
4125 (Note that the @option{-pedantic} and @option{-pedantic-errors} options
4126 always imply @option{-fpedantic}.)
4127
4128 With @option{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
4129 for conforming code.
4130 With @option{-ff90} in force, Fortran 90 is used.
4131
4132 The constructs for which @command{g77} issues diagnostics when @option{-fpedantic}
4133 and @option{-fno-f90} are in force are:
4134
4135 @itemize @bullet
4136 @item
4137 Automatic arrays, as in
4138
4139 @example
4140 SUBROUTINE X(N)
4141 REAL A(N)
4142 @dots{}
4143 @end example
4144
4145 @noindent
4146 where @samp{A} is not listed in any @code{ENTRY} statement,
4147 and thus is not a dummy argument.
4148
4149 @item
4150 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
4151
4152 These commas are disallowed by FORTRAN 77, but, while strictly
4153 superfluous, are syntactically elegant,
4154 especially given that commas are required in statements such
4155 as @samp{READ 99, I} and @samp{PRINT *, J}.
4156 Many compilers permit the superfluous commas for this reason.
4157
4158 @item
4159 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
4160
4161 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
4162 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
4163
4164 An example of an implicit use is the expression @samp{C*D},
4165 where @samp{C} is @code{COMPLEX(KIND=1)}
4166 and @samp{D} is @code{DOUBLE PRECISION}.
4167 This expression is prohibited by ANSI FORTRAN 77
4168 because the rules of promotion would suggest that it
4169 produce a @code{DOUBLE COMPLEX} result---a type not
4170 provided for by that standard.
4171
4172 @item
4173 Automatic conversion of numeric
4174 expressions to @code{INTEGER(KIND=1)} in contexts such as:
4175
4176 @itemize @minus
4177 @item
4178 Array-reference indexes.
4179 @item
4180 Alternate-return values.
4181 @item
4182 Computed @code{GOTO}.
4183 @item
4184 @code{FORMAT} run-time expressions (not yet supported).
4185 @item
4186 Dimension lists in specification statements.
4187 @item
4188 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
4189 @item
4190 Sizes of @code{CHARACTER} entities in specification statements.
4191 @item
4192 Kind types in specification entities (a Fortran 90 feature).
4193 @item
4194 Initial, terminal, and incrementation parameters for implied-@code{DO}
4195 constructs in @code{DATA} statements.
4196 @end itemize
4197
4198 @item
4199 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
4200 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
4201 expressions are disallowed anyway).
4202
4203 @item
4204 Zero-size array dimensions, as in:
4205
4206 @example
4207 INTEGER I(10,20,4:2)
4208 @end example
4209
4210 @item
4211 Zero-length @code{CHARACTER} entities, as in:
4212
4213 @example
4214 PRINT *, ''
4215 @end example
4216
4217 @item
4218 Substring operators applied to character constants and named
4219 constants, as in:
4220
4221 @example
4222 PRINT *, 'hello'(3:5)
4223 @end example
4224
4225 @item
4226 Null arguments passed to statement function, as in:
4227
4228 @example
4229 PRINT *, FOO(,3)
4230 @end example
4231
4232 @item
4233 Disagreement among program units regarding whether a given @code{COMMON}
4234 area is @code{SAVE}d (for targets where program units in a single source
4235 file are ``glued'' together as they typically are for UNIX development
4236 environments).
4237
4238 @item
4239 Disagreement among program units regarding the size of a
4240 named @code{COMMON} block.
4241
4242 @item
4243 Specification statements following first @code{DATA} statement.
4244
4245 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
4246 but not @samp{INTEGER I}.
4247 The @option{-fpedantic} option disallows both of these.)
4248
4249 @item
4250 Semicolon as statement separator, as in:
4251
4252 @example
4253 CALL FOO; CALL BAR
4254 @end example
4255 @c
4256 @c @item
4257 @c Comma before list of I/O items in @code{WRITE}
4258 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
4259 @c statements, as with @code{READ} (as explained above).
4260
4261 @item
4262 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
4263
4264 @item
4265 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
4266 versa.
4267
4268 @item
4269 Expressions having two arithmetic operators in a row, such
4270 as @samp{X*-Y}.
4271 @end itemize
4272
4273 If @option{-fpedantic} is specified along with @option{-ff90}, the
4274 following constructs result in diagnostics:
4275
4276 @itemize @bullet
4277 @item
4278 Use of semicolon as a statement separator on a line
4279 that has an @code{INCLUDE} directive.
4280 @end itemize
4281
4282 @node Distensions
4283 @section Distensions
4284 @cindex distensions
4285 @cindex ugly features
4286 @cindex features, ugly
4287
4288 The @option{-fugly-*} command-line options determine whether certain
4289 features supported by VAX FORTRAN and other such compilers, but considered
4290 too ugly to be in code that can be changed to use safer and/or more
4291 portable constructs, are accepted.
4292 These are humorously referred to as ``distensions'',
4293 extensions that just plain look ugly in the harsh light of day.
4294
4295 @menu
4296 * Ugly Implicit Argument Conversion::  Disabled via @option{-fno-ugly-args}.
4297 * Ugly Assumed-Size Arrays::           Enabled via @option{-fugly-assumed}.
4298 * Ugly Null Arguments::                Enabled via @option{-fugly-comma}.
4299 * Ugly Complex Part Extraction::       Enabled via @option{-fugly-complex}.
4300 * Ugly Conversion of Initializers::    Disabled via @option{-fno-ugly-init}.
4301 * Ugly Integer Conversions::           Enabled via @option{-fugly-logint}.
4302 * Ugly Assigned Labels::               Enabled via @option{-fugly-assign}.
4303 @end menu
4304
4305 @node Ugly Implicit Argument Conversion
4306 @subsection Implicit Argument Conversion
4307 @cindex Hollerith constants
4308 @cindex constants, Hollerith
4309
4310 The @option{-fno-ugly-args} option disables
4311 passing typeless and Hollerith constants as actual arguments
4312 in procedure invocations.
4313 For example:
4314
4315 @example
4316 CALL FOO(4HABCD)
4317 CALL BAR('123'O)
4318 @end example
4319
4320 @noindent
4321 These constructs can be too easily used to create non-portable
4322 code, but are not considered as ``ugly'' as others.
4323 Further, they are widely used in existing Fortran source code
4324 in ways that often are quite portable.
4325 Therefore, they are enabled by default.
4326
4327 @node Ugly Assumed-Size Arrays
4328 @subsection Ugly Assumed-Size Arrays
4329 @cindex arrays, assumed-size
4330 @cindex assumed-size arrays
4331 @cindex DIMENSION X(1)
4332
4333 The @option{-fugly-assumed} option enables
4334 the treatment of any array with a final dimension specified as @samp{1}
4335 as an assumed-size array, as if @samp{*} had been specified
4336 instead.
4337
4338 For example, @samp{DIMENSION X(1)} is treated as if it
4339 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
4340 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
4341 or @code{ENTRY} statement in the same program unit.
4342
4343 Use an explicit lower bound to avoid this interpretation.
4344 For example, @samp{DIMENSION X(1:1)} is never treated as if
4345 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
4346 Nor is @samp{DIMENSION X(2-1)} affected by this option,
4347 since that kind of expression is unlikely to have been
4348 intended to designate an assumed-size array.
4349
4350 This option is used to prevent warnings being issued about apparent
4351 out-of-bounds reference such as @samp{X(2) = 99}.
4352
4353 It also prevents the array from being used in contexts that
4354 disallow assumed-size arrays, such as @samp{PRINT *,X}.
4355 In such cases, a diagnostic is generated and the source file is
4356 not compiled.
4357
4358 The construct affected by this option is used only in old code
4359 that pre-exists the widespread acceptance of adjustable and assumed-size
4360 arrays in the Fortran community.
4361
4362 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
4363 treated if @samp{X} is listed as a dummy argument only
4364 @emph{after} the @code{DIMENSION} statement (presumably in
4365 an @code{ENTRY} statement).
4366 For example, @option{-fugly-assumed} has no effect on the
4367 following program unit:
4368
4369 @example
4370 SUBROUTINE X
4371 REAL A(1)
4372 RETURN
4373 ENTRY Y(A)
4374 PRINT *, A
4375 END
4376 @end example
4377
4378 @node Ugly Complex Part Extraction
4379 @subsection Ugly Complex Part Extraction
4380 @cindex complex values
4381 @cindex real part
4382 @cindex imaginary part
4383
4384 The @option{-fugly-complex} option enables
4385 use of the @code{REAL()} and @code{AIMAG()}
4386 intrinsics with arguments that are
4387 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
4388
4389 With @option{-ff90} in effect, these intrinsics return
4390 the unconverted real and imaginary parts (respectively)
4391 of their argument.
4392
4393 With @option{-fno-f90} in effect, these intrinsics convert
4394 the real and imaginary parts to @code{REAL(KIND=1)}, and return
4395 the result of that conversion.
4396
4397 Due to this ambiguity, the GNU Fortran language defines
4398 these constructs as invalid, except in the specific
4399 case where they are entirely and solely passed as an
4400 argument to an invocation of the @code{REAL()} intrinsic.
4401 For example,
4402
4403 @example
4404 REAL(REAL(Z))
4405 @end example
4406
4407 @noindent
4408 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
4409 and @option{-fno-ugly-complex} is in effect, because the
4410 meaning is clear.
4411
4412 @command{g77} enforces this restriction, unless @option{-fugly-complex}
4413 is specified, in which case the appropriate interpretation is
4414 chosen and no diagnostic is issued.
4415
4416 @xref{CMPAMBIG}, for information on how to cope with existing
4417 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
4418 with @code{COMPLEX(KIND=2)} arguments.
4419
4420 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
4421 intrinsic, used to extract the real part of a complex expression
4422 without conversion.
4423 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
4424 intrinsic, used to extract the imaginary part of a complex expression
4425 without conversion.
4426
4427 @node Ugly Null Arguments
4428 @subsection Ugly Null Arguments
4429 @cindex trailing comma
4430 @cindex comma, trailing
4431 @cindex characters, comma
4432 @cindex null arguments
4433 @cindex arguments, null
4434
4435 The @option{-fugly-comma} option enables use of a single trailing comma
4436 to mean ``pass an extra trailing null argument''
4437 in a list of actual arguments to an external procedure,
4438 and use of an empty list of arguments to such a procedure
4439 to mean ``pass a single null argument''.
4440
4441 @cindex omitting arguments
4442 @cindex arguments, omitting
4443 (Null arguments often are used in some procedure-calling
4444 schemes to indicate omitted arguments.)
4445
4446 For example, @samp{CALL FOO(,)} means ``pass
4447 two null arguments'', rather than ``pass one null argument''.
4448 Also, @samp{CALL BAR()} means ``pass one null argument''.
4449
4450 This construct is considered ``ugly'' because it does not
4451 provide an elegant way to pass a single null argument
4452 that is syntactically distinct from passing no arguments.
4453 That is, this construct changes the meaning of code that
4454 makes no use of the construct.
4455
4456 So, with @option{-fugly-comma} in force, @samp{CALL FOO()}
4457 and @samp{I = JFUNC()} pass a single null argument, instead
4458 of passing no arguments as required by the Fortran 77 and
4459 90 standards.
4460
4461 @emph{Note:} Many systems gracefully allow the case
4462 where a procedure call passes one extra argument that the
4463 called procedure does not expect.
4464
4465 So, in practice, there might be no difference in
4466 the behavior of a program that does @samp{CALL FOO()}
4467 or @samp{I = JFUNC()} and is compiled with @option{-fugly-comma}
4468 in force as compared to its behavior when compiled
4469 with the default, @option{-fno-ugly-comma}, in force,
4470 assuming @samp{FOO} and @samp{JFUNC} do not expect any
4471 arguments to be passed.
4472
4473 @node Ugly Conversion of Initializers
4474 @subsection Ugly Conversion of Initializers
4475
4476 The constructs disabled by @option{-fno-ugly-init} are:
4477
4478 @itemize @bullet
4479 @cindex Hollerith constants
4480 @cindex constants, Hollerith
4481 @item
4482 Use of Hollerith and typeless constants in contexts where they set
4483 initial (compile-time) values for variables, arrays, and named
4484 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
4485 type-declaration statements specifying initial values.
4486
4487 Here are some sample initializations that are disabled by the
4488 @option{-fno-ugly-init} option:
4489
4490 @example
4491 PARAMETER (VAL='9A304FFE'X)
4492 REAL*8 STRING/8HOUTPUT00/
4493 DATA VAR/4HABCD/
4494 @end example
4495
4496 @cindex character constants
4497 @cindex constants, character
4498 @item
4499 In the same contexts as above, use of character constants to initialize
4500 numeric items and vice versa (one constant per item).
4501
4502 Here are more sample initializations that are disabled by the
4503 @option{-fno-ugly-init} option:
4504
4505 @example
4506 INTEGER IA
4507 CHARACTER BELL
4508 PARAMETER (IA = 'A')
4509 PARAMETER (BELL = 7)
4510 @end example
4511
4512 @item
4513 Use of Hollerith and typeless constants on the right-hand side
4514 of assignment statements to numeric types, and in other
4515 contexts (such as passing arguments in invocations of
4516 intrinsic procedures and statement functions) that
4517 are treated as assignments to known types (the dummy
4518 arguments, in these cases).
4519
4520 Here are sample statements that are disabled by the
4521 @option{-fno-ugly-init} option:
4522
4523 @example
4524 IVAR = 4HABCD
4525 PRINT *, IMAX0(2HAB, 2HBA)
4526 @end example
4527 @end itemize
4528
4529 The above constructs, when used,
4530 can tend to result in non-portable code.
4531 But, they are widely used in existing Fortran code in ways
4532 that often are quite portable.
4533 Therefore, they are enabled by default.
4534
4535 @node Ugly Integer Conversions
4536 @subsection Ugly Integer Conversions
4537
4538 The constructs enabled via @option{-fugly-logint} are:
4539
4540 @itemize @bullet
4541 @item
4542 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
4543 dictated by
4544 context (typically implies nonportable dependencies on how a
4545 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
4546
4547 @item
4548 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
4549 statements.
4550 @end itemize
4551
4552 The above constructs are disabled by default because use
4553 of them tends to lead to non-portable code.
4554 Even existing Fortran code that uses that often turns out
4555 to be non-portable, if not outright buggy.
4556
4557 Some of this is due to differences among implementations as
4558 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
4559 @code{INTEGER} values---Fortran code that assumes a particular
4560 coding is likely to use one of the above constructs, and is
4561 also likely to not work correctly on implementations using
4562 different encodings.
4563
4564 @xref{Equivalence Versus Equality}, for more information.
4565
4566 @node Ugly Assigned Labels
4567 @subsection Ugly Assigned Labels
4568 @cindex ASSIGN statement
4569 @cindex statements, ASSIGN
4570 @cindex assigned labels
4571 @cindex pointers
4572
4573 The @option{-fugly-assign} option forces @command{g77} to use the
4574 same storage for assigned labels as it would for a normal
4575 assignment to the same variable.
4576
4577 For example, consider the following code fragment:
4578
4579 @example
4580 I = 3
4581 ASSIGN 10 TO I
4582 @end example
4583
4584 @noindent
4585 Normally, for portability and improved diagnostics, @command{g77}
4586 reserves distinct storage for a ``sibling'' of @samp{I}, used
4587 only for @code{ASSIGN} statements to that variable (along with
4588 the corresponding assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O
4589 statements that reference the variable).
4590
4591 However, some code (that violates the ANSI FORTRAN 77 standard)
4592 attempts to copy assigned labels among variables involved with
4593 @code{ASSIGN} statements, as in:
4594
4595 @example
4596 ASSIGN 10 TO I
4597 ISTATE(5) = I
4598 @dots{}
4599 J = ISTATE(ICUR)
4600 GOTO J
4601 @end example
4602
4603 @noindent
4604 Such code doesn't work under @command{g77} unless @option{-fugly-assign}
4605 is specified on the command-line, ensuring that the value of @code{I}
4606 referenced in the second line is whatever value @command{g77} uses
4607 to designate statement label @samp{10}, so the value may be
4608 copied into the @samp{ISTATE} array, later retrieved into a
4609 variable of the appropriate type (@samp{J}), and used as the target of
4610 an assigned-@code{GOTO} statement.
4611
4612 @emph{Note:} To avoid subtle program bugs,
4613 when @option{-fugly-assign} is specified,
4614 @command{g77} requires the type of variables
4615 specified in assigned-label contexts
4616 @emph{must} be the same type returned by @code{%LOC()}.
4617 On many systems, this type is effectively the same
4618 as @code{INTEGER(KIND=1)}, while, on others, it is
4619 effectively the same as @code{INTEGER(KIND=2)}.
4620
4621 Do @emph{not} depend on @command{g77} actually writing valid pointers
4622 to these variables, however.
4623 While @command{g77} currently chooses that implementation, it might
4624 be changed in the future.
4625
4626 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
4627 for implementation details on assigned-statement labels.
4628
4629 @node Compiler
4630 @chapter The GNU Fortran Compiler
4631
4632 The GNU Fortran compiler, @command{g77}, supports programs written
4633 in the GNU Fortran language and in some other dialects of Fortran.
4634
4635 Some aspects of how @command{g77} works are universal regardless
4636 of dialect, and yet are not properly part of the GNU Fortran
4637 language itself.
4638 These are described below.
4639
4640 @emph{Note: This portion of the documentation definitely needs a lot
4641 of work!}
4642
4643 @menu
4644 * Compiler Limits::
4645 * Run-time Environment Limits::
4646 * Compiler Types::
4647 * Compiler Constants::
4648 * Compiler Intrinsics::
4649 @end menu
4650
4651 @node Compiler Limits
4652 @section Compiler Limits
4653 @cindex limits, compiler
4654 @cindex compiler limits
4655
4656 @command{g77}, as with GNU tools in general, imposes few arbitrary restrictions
4657 on lengths of identifiers, number of continuation lines, number of external
4658 symbols in a program, and so on.
4659
4660 @cindex options, -Nl
4661 @cindex -Nl option
4662 @cindex options, -Nx
4663 @cindex -Nx option
4664 @cindex limits, continuation lines
4665 @cindex limits, lengths of names
4666 For example, some other Fortran compiler have an option
4667 (such as @option{-Nl@var{x}}) to increase the limit on the
4668 number of continuation lines.
4669 Also, some Fortran compilation systems have an option
4670 (such as @option{-Nx@var{x}}) to increase the limit on the
4671 number of external symbols.
4672
4673 @command{g77}, @command{gcc}, and GNU @command{ld} (the GNU linker) have
4674 no equivalent options, since they do not impose arbitrary
4675 limits in these areas.
4676
4677 @cindex rank, maximum
4678 @cindex maximum rank
4679 @cindex number of dimensions, maximum
4680 @cindex maximum number of dimensions
4681 @cindex limits, rank
4682 @cindex limits, array dimensions
4683 @command{g77} does currently limit the number of dimensions in an array
4684 to the same degree as do the Fortran standards---seven (7).
4685 This restriction might be lifted in a future version.
4686
4687 @node Run-time Environment Limits
4688 @section Run-time Environment Limits
4689 @cindex limits, run-time library
4690 @cindex wraparound
4691
4692 As a portable Fortran implementation,
4693 @command{g77} offers its users direct access to,
4694 and otherwise depends upon,
4695 the underlying facilities of the system
4696 used to build @command{g77},
4697 the system on which @command{g77} itself is used to compile programs,
4698 and the system on which the @command{g77}-compiled program is actually run.
4699 (For most users, the three systems are of the same
4700 type---combination of operating environment and hardware---often
4701 the same physical system.)
4702
4703 The run-time environment for a particular system
4704 inevitably imposes some limits on a program's use
4705 of various system facilities.
4706 These limits vary from system to system.
4707
4708 Even when such limits might be well beyond the
4709 possibility of being encountered on a particular system,
4710 the @command{g77} run-time environment
4711 has certain built-in limits,
4712 usually, but not always, stemming from intrinsics
4713 with inherently limited interfaces.
4714
4715 Currently, the @command{g77} run-time environment
4716 does not generally offer a less-limiting environment
4717 by augmenting the underlying system's own environment.
4718
4719 Therefore, code written in the GNU Fortran language,
4720 while syntactically and semantically portable,
4721 might nevertheless make non-portable assumptions
4722 about the run-time environment---assumptions that
4723 prove to be false for some particular environments.
4724
4725 The GNU Fortran language,
4726 the @command{g77} compiler and run-time environment,
4727 and the @command{g77} documentation
4728 do not yet offer comprehensive portable work-arounds for such limits,
4729 though programmers should be able to
4730 find their own in specific instances.
4731
4732 Not all of the limitations are described in this document.
4733 Some of the known limitations include:
4734
4735 @menu
4736 * Timer Wraparounds::
4737 * Year 2000 (Y2K) Problems::
4738 * Array Size::
4739 * Character-variable Length::
4740 * Year 10000 (Y10K) Problems::
4741 @end menu
4742
4743 @node Timer Wraparounds
4744 @subsection Timer Wraparounds
4745
4746 Intrinsics that return values computed from system timers,
4747 whether elapsed (wall-clock) timers,
4748 process CPU timers,
4749 or other kinds of timers,
4750 are prone to experiencing wrap-around errors
4751 (or returning wrapped-around values from successive calls)
4752 due to insufficient ranges
4753 offered by the underlying system's timers.
4754
4755 @cindex negative time
4756 @cindex short time
4757 @cindex long time
4758 Some of the symptoms of such behaviors include
4759 apparently negative time being computed for a duration,
4760 an extremely short amount of time being computed for a long duration,
4761 and an extremely long amount of time being computed for a short duration.
4762
4763 See the following for intrinsics
4764 known to have potential problems in these areas
4765 on at least some systems:
4766 @ref{CPU_Time Intrinsic},
4767 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
4768 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
4769 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
4770 @ref{Secnds Intrinsic},
4771 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
4772 @ref{System_Clock Intrinsic},
4773 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
4774 @ref{Time8 Intrinsic}.
4775
4776 @node Year 2000 (Y2K) Problems
4777 @subsection Year 2000 (Y2K) Problems
4778 @cindex Y2K compliance
4779 @cindex Year 2000 compliance
4780
4781 While the @command{g77} compiler itself is believed to
4782 be Year-2000 (Y2K) compliant,
4783 some intrinsics are not,
4784 and, potentially, some underlying systems are not,
4785 perhaps rendering some Y2K-compliant intrinsics
4786 non-compliant when used on those particular systems.
4787
4788 Fortran code that uses non-Y2K-compliant intrinsics
4789 (listed below)
4790 is, itself, almost certainly not compliant,
4791 and should be modified to use Y2K-compliant intrinsics instead.
4792
4793 Fortran code that uses no non-Y2K-compliant intrinsics,
4794 but which currently is running on a non-Y2K-compliant system,
4795 can be made more Y2K compliant by compiling and
4796 linking it for use on a new Y2K-compliant system,
4797 such as a new version of an old, non-Y2K-compliant, system.
4798
4799 Currently, information on Y2K and related issues
4800 is being maintained at
4801 @uref{http://www.gnu.org/software/year2000-list.html}.
4802
4803 See the following for intrinsics
4804 known to have potential problems in these areas
4805 on at least some systems:
4806 @ref{Date Intrinsic},
4807 @ref{IDate Intrinsic (VXT)}.
4808
4809 @cindex y2kbuggy
4810 @cindex date_y2kbuggy_0
4811 @cindex vxtidate_y2kbuggy_0
4812 @cindex G77_date_y2kbuggy_0
4813 @cindex G77_vxtidate_y2kbuggy_0
4814 The @code{libg2c} library
4815 shipped with any @command{g77} that warns
4816 about invocation of a non-Y2K-compliant intrinsic
4817 has renamed the @code{EXTERNAL} procedure names
4818 of those intrinsics.
4819 This is done so that
4820 the @code{libg2c} implementations of these intrinsics
4821 cannot be directly linked to
4822 as @code{EXTERNAL} names
4823 (which normally would avoid the non-Y2K-intrinsic warning).
4824
4825 The renamed forms of the @code{EXTERNAL} names
4826 of these renamed procedures
4827 may be linked to
4828 by appending the string @samp{_y2kbug}
4829 to the name of the procedure
4830 in the source code.
4831 For example:
4832
4833 @smallexample
4834 CHARACTER*20 STR
4835 INTEGER YY, MM, DD
4836 EXTERNAL DATE_Y2KBUG, VXTIDATE_Y2KBUG
4837 CALL DATE_Y2KBUG (STR)
4838 CALL VXTIDATE_Y2KBUG (MM, DD, YY)
4839 @end smallexample
4840
4841 (Note that the @code{EXTERNAL} statement
4842 is not actually required,
4843 since the modified names are not recognized as intrinsics
4844 by the current version of @command{g77}.
4845 But it is shown in this specific case,
4846 for purposes of illustration.)
4847
4848 The renaming of @code{EXTERNAL} procedure names of these intrinsics
4849 causes unresolved references at link time.
4850 For example, @samp{EXTERNAL DATE; CALL DATE(STR)}
4851 is normally compiled by @command{g77}
4852 as, in C, @samp{date_(&str, 20);}.
4853 This, in turn, links to the @code{date_} procedure
4854 in the @code{libE77} portion of @code{libg2c},
4855 which purposely calls a nonexistent procedure
4856 named @code{G77_date_y2kbuggy_0}.
4857 The resulting link-time error is designed, via this name,
4858 to encourage the programmer to look up the
4859 index entries to this portion of the @command{g77} documentation.
4860
4861 Generally, we recommend that the @code{EXTERNAL} method
4862 of invoking procedures in @code{libg2c}
4863 @emph{not} be used.
4864 When used, some of the correctness checking
4865 normally performed by @command{g77}
4866 is skipped.
4867
4868 In particular, it is probably better to use the
4869 @code{INTRINSIC} method of invoking
4870 non-Y2K-compliant procedures,
4871 so anyone compiling the code
4872 can quickly notice the potential Y2K problems
4873 (via the warnings printing by @command{g77})
4874 without having to even look at the code itself.
4875
4876 If there are problems linking @code{libg2c}
4877 to code compiled by @command{g77}
4878 that involve the string @samp{y2kbug},
4879 and these are not explained above,
4880 that probably indicates
4881 that a version of @code{libg2c}
4882 older than @command{g77}
4883 is being linked to,
4884 or that the new library is being linked
4885 to code compiled by an older version of @command{g77}.
4886
4887 That's because, as of the version that warns about
4888 non-Y2K-compliant intrinsic invocation,
4889 @command{g77} references the @code{libg2c} implementations
4890 of those intrinsics
4891 using new names, containing the string @samp{y2kbug}.
4892
4893 So, linking newly-compiled code
4894 (invoking one of the intrinsics in question)
4895 to an old library
4896 might yield an unresolved reference
4897 to @code{G77_date_y2kbug_0}.
4898 (The old library calls it @code{G77_date_0}.)
4899
4900 Similarly, linking previously-compiled code
4901 to a new library
4902 might yield an unresolved reference
4903 to @code{G77_vxtidate_0}.
4904 (The new library calls it @code{G77_vxtidate_y2kbug_0}.)
4905
4906 The proper fix for the above problems
4907 is to obtain the latest release of @command{g77}
4908 and related products
4909 (including @code{libg2c})
4910 and install them on all systems,
4911 then recompile, relink, and install
4912 (as appropriate)
4913 all existing Fortran programs.
4914
4915 (Normally, this sort of renaming is steadfastly avoided.
4916 In this case, however, it seems more important to highlight
4917 potential Y2K problems
4918 than to ease the transition
4919 of potentially non-Y2K-compliant code
4920 to new versions of @command{g77} and @code{libg2c}.)
4921
4922 @node Array Size
4923 @subsection Array Size
4924 @cindex limits, array size
4925 @cindex array size
4926
4927 Currently, @command{g77} uses the default @code{INTEGER} type
4928 for array indexes,
4929 which limits the sizes of single-dimension arrays
4930 on systems offering a larger address space
4931 than can be addressed by that type.
4932 (That @command{g77} puts all arrays in memory
4933 could be considered another limitation---it
4934 could use large temporary files---but that decision
4935 is left to the programmer as an implementation choice
4936 by most Fortran implementations.)
4937
4938 @c ??? Investigate this, to offer a more clear statement
4939 @c than the following paragraphs do.  -- burley 1999-02-17
4940 It is not yet clear whether this limitation
4941 never, sometimes, or always applies to the
4942 sizes of multiple-dimension arrays as a whole.
4943
4944 For example, on a system with 64-bit addresses
4945 and 32-bit default @code{INTEGER},
4946 an array with a size greater than can be addressed
4947 by a 32-bit offset
4948 can be declared using multiple dimensions.
4949 Such an array is therefore larger
4950 than a single-dimension array can be,
4951 on the same system.
4952
4953 @cindex limits, multi-dimension arrays
4954 @cindex multi-dimension arrays
4955 @cindex arrays, dimensioning
4956 Whether large multiple-dimension arrays are reliably supported
4957 depends mostly on the @command{gcc} back end (code generator)
4958 used by @command{g77}, and has not yet been fully investigated.
4959
4960 @node Character-variable Length
4961 @subsection Character-variable Length
4962 @cindex limits, on character-variable length
4963 @cindex character-variable length
4964
4965 Currently, @command{g77} uses the default @code{INTEGER} type
4966 for the lengths of @code{CHARACTER} variables
4967 and array elements.
4968
4969 This means that, for example,
4970 a system with a 64-bit address space
4971 and a 32-bit default @code{INTEGER} type
4972 does not, under @command{g77},
4973 support a @code{CHARACTER*@var{n}} declaration
4974 where @var{n} is greater than 2147483647.
4975
4976 @node Year 10000 (Y10K) Problems
4977 @subsection Year 10000 (Y10K) Problems
4978 @cindex Y10K compliance
4979 @cindex Year 10000 compliance
4980
4981 Most intrinsics returning, or computing values based on,
4982 date information are prone to Year-10000 (Y10K) problems,
4983 due to supporting only 4 digits for the year.
4984
4985 See the following for examples:
4986 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
4987 @ref{IDate Intrinsic (UNIX)},
4988 @ref{Time Intrinsic (VXT)},
4989 @ref{Date_and_Time Intrinsic}.
4990
4991 @node Compiler Types
4992 @section Compiler Types
4993 @cindex types, of data
4994 @cindex data types
4995
4996 Fortran implementations have a fair amount of freedom given them by the
4997 standard as far as how much storage space is used and how much precision
4998 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
4999 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
5000 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
5001 Further, many compilers offer so-called @samp{*@var{n}} notation, but
5002 the interpretation of @var{n} varies across compilers and target architectures.
5003
5004 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
5005 and @code{REAL(KIND=1)}
5006 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
5007 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
5008 Further, it requires that @code{COMPLEX(KIND=1)}
5009 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
5010 storage-associated (such as via @code{EQUIVALENCE})
5011 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
5012 corresponds to the real element and @samp{R(2)} to the imaginary
5013 element of the @code{COMPLEX(KIND=1)} variable.
5014
5015 (Few requirements as to precision or ranges of any of these are
5016 placed on the implementation, nor is the relationship of storage sizes of
5017 these types to the @code{CHARACTER} type specified, by the standard.)
5018
5019 @command{g77} follows the above requirements, warning when compiling
5020 a program requires placement of items in memory that contradict the
5021 requirements of the target architecture.
5022 (For example, a program can require placement of a @code{REAL(KIND=2)}
5023 on a boundary that is not an even multiple of its size, but still an
5024 even multiple of the size of a @code{REAL(KIND=1)} variable.
5025 On some target architectures, using the canonical
5026 mapping of Fortran types to underlying architectural types, such
5027 placement is prohibited by the machine definition or
5028 the Application Binary Interface (ABI) in force for
5029 the configuration defined for building @command{gcc} and @command{g77}.
5030 @command{g77} warns about such
5031 situations when it encounters them.)
5032
5033 @command{g77} follows consistent rules for configuring the mapping between Fortran
5034 types, including the @samp{*@var{n}} notation, and the underlying architectural
5035 types as accessed by a similarly-configured applicable version of the
5036 @command{gcc} compiler.
5037 These rules offer a widely portable, consistent Fortran/C
5038 environment, although they might well conflict with the expectations of
5039 users of Fortran compilers designed and written for particular
5040 architectures.
5041
5042 These rules are based on the configuration that is in force for the
5043 version of @command{gcc} built in the same release as @command{g77} (and
5044 which was therefore used to build both the @command{g77} compiler
5045 components and the @code{libg2c} run-time library):
5046
5047 @table @code
5048 @cindex REAL(KIND=1) type
5049 @cindex types, REAL(KIND=1)
5050 @item REAL(KIND=1)
5051 Same as @code{float} type.
5052
5053 @cindex REAL(KIND=2) type
5054 @cindex types, REAL(KIND=2)
5055 @item REAL(KIND=2)
5056 Same as whatever floating-point type that is twice the size
5057 of a @code{float}---usually, this is a @code{double}.
5058
5059 @cindex INTEGER(KIND=1) type
5060 @cindex types, INTEGER(KIND=1)
5061 @item INTEGER(KIND=1)
5062 Same as an integral type that is occupies the same amount
5063 of memory storage as @code{float}---usually, this is either
5064 an @code{int} or a @code{long int}.
5065
5066 @cindex LOGICAL(KIND=1) type
5067 @cindex types, LOGICAL(KIND=1)
5068 @item LOGICAL(KIND=1)
5069 Same @command{gcc} type as @code{INTEGER(KIND=1)}.
5070
5071 @cindex INTEGER(KIND=2) type
5072 @cindex types, INTEGER(KIND=2)
5073 @item INTEGER(KIND=2)
5074 Twice the size, and usually nearly twice the range,
5075 as @code{INTEGER(KIND=1)}---usually, this is either
5076 a @code{long int} or a @code{long long int}.
5077
5078 @cindex LOGICAL(KIND=2) type
5079 @cindex types, LOGICAL(KIND=2)
5080 @item LOGICAL(KIND=2)
5081 Same @command{gcc} type as @code{INTEGER(KIND=2)}.
5082
5083 @cindex INTEGER(KIND=3) type
5084 @cindex types, INTEGER(KIND=3)
5085 @item INTEGER(KIND=3)
5086 Same @command{gcc} type as signed @code{char}.
5087
5088 @cindex LOGICAL(KIND=3) type
5089 @cindex types, LOGICAL(KIND=3)
5090 @item LOGICAL(KIND=3)
5091 Same @command{gcc} type as @code{INTEGER(KIND=3)}.
5092
5093 @cindex INTEGER(KIND=6) type
5094 @cindex types, INTEGER(KIND=6)
5095 @item INTEGER(KIND=6)
5096 Twice the size, and usually nearly twice the range,
5097 as @code{INTEGER(KIND=3)}---usually, this is
5098 a @code{short}.
5099
5100 @cindex LOGICAL(KIND=6) type
5101 @cindex types, LOGICAL(KIND=6)
5102 @item LOGICAL(KIND=6)
5103 Same @command{gcc} type as @code{INTEGER(KIND=6)}.
5104
5105 @cindex COMPLEX(KIND=1) type
5106 @cindex types, COMPLEX(KIND=1)
5107 @item COMPLEX(KIND=1)
5108 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
5109 one for the imaginary part).
5110
5111 @cindex COMPLEX(KIND=2) type
5112 @cindex types, COMPLEX(KIND=2)
5113 @item COMPLEX(KIND=2)
5114 Two @code{REAL(KIND=2)} scalars.
5115
5116 @cindex *@var{n} notation
5117 @item @var{numeric-type}*@var{n}
5118 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
5119 Same as whatever @command{gcc} type occupies @var{n} times the storage
5120 space of a @command{gcc} @code{char} item.
5121
5122 @cindex DOUBLE PRECISION type
5123 @cindex types, DOUBLE PRECISION
5124 @item DOUBLE PRECISION
5125 Same as @code{REAL(KIND=2)}.
5126
5127 @cindex DOUBLE COMPLEX type
5128 @cindex types, DOUBLE COMPLEX
5129 @item DOUBLE COMPLEX
5130 Same as @code{COMPLEX(KIND=2)}.
5131 @end table
5132
5133 Note that the above are proposed correspondences and might change
5134 in future versions of @command{g77}---avoid writing code depending
5135 on them.
5136
5137 Other types supported by @command{g77}
5138 are derived from gcc types such as @code{char}, @code{short},
5139 @code{int}, @code{long int}, @code{long long int}, @code{long double},
5140 and so on.
5141 That is, whatever types @command{gcc} already supports, @command{g77} supports
5142 now or probably will support in a future version.
5143 The rules for the @samp{@var{numeric-type}*@var{n}} notation
5144 apply to these types,
5145 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
5146 assigned in a way that encourages clarity, consistency, and portability.
5147
5148 @node Compiler Constants
5149 @section Compiler Constants
5150 @cindex constants
5151 @cindex types, constants
5152
5153 @command{g77} strictly assigns types to @emph{all} constants not
5154 documented as ``typeless'' (typeless constants including @samp{'1'Z},
5155 for example).
5156 Many other Fortran compilers attempt to assign types to typed constants
5157 based on their context.
5158 This results in hard-to-find bugs, nonportable
5159 code, and is not in the spirit (though it strictly follows the letter)
5160 of the 77 and 90 standards.
5161
5162 @command{g77} might offer, in a future release, explicit constructs by
5163 which a wider variety of typeless constants may be specified, and/or
5164 user-requested warnings indicating places where @command{g77} might differ
5165 from how other compilers assign types to constants.
5166
5167 @xref{Context-Sensitive Constants}, for more information on this issue.
5168
5169 @node Compiler Intrinsics
5170 @section Compiler Intrinsics
5171
5172 @command{g77} offers an ever-widening set of intrinsics.
5173 Currently these all are procedures (functions and subroutines).
5174
5175 Some of these intrinsics are unimplemented, but their names reserved
5176 to reduce future problems with existing code as they are implemented.
5177 Others are implemented as part of the GNU Fortran language, while
5178 yet others are provided for compatibility with other dialects of
5179 Fortran but are not part of the GNU Fortran language.
5180
5181 To manage these distinctions, @command{g77} provides intrinsic @emph{groups},
5182 a facility that is simply an extension of the intrinsic groups provided
5183 by the GNU Fortran language.
5184
5185 @menu
5186 * Intrinsic Groups::  How intrinsics are grouped for easy management.
5187 * Other Intrinsics::  Intrinsics other than those in the GNU
5188                        Fortran language.
5189 @end menu
5190
5191 @node Intrinsic Groups
5192 @subsection Intrinsic Groups
5193 @cindex groups of intrinsics
5194 @cindex intrinsics, groups
5195
5196 A given specific intrinsic belongs in one or more groups.
5197 Each group is deleted, disabled, hidden, or enabled
5198 by default or a command-line option.
5199 The meaning of each term follows.
5200
5201 @table @b
5202 @cindex deleted intrinsics
5203 @cindex intrinsics, deleted
5204 @item Deleted
5205 No intrinsics are recognized as belonging to that group.
5206
5207 @cindex disabled intrinsics
5208 @cindex intrinsics, disabled
5209 @item Disabled
5210 Intrinsics are recognized as belonging to the group, but
5211 references to them (other than via the @code{INTRINSIC} statement)
5212 are disallowed through that group.
5213
5214 @cindex hidden intrinsics
5215 @cindex intrinsics, hidden
5216 @item Hidden
5217 Intrinsics in that group are recognized and enabled (if implemented)
5218 @emph{only} if the first mention of the actual name of an intrinsic
5219 in a program unit is in an @code{INTRINSIC} statement.
5220
5221 @cindex enabled intrinsics
5222 @cindex intrinsics, enabled
5223 @item Enabled
5224 Intrinsics in that group are recognized and enabled (if implemented).
5225 @end table
5226
5227 The distinction between deleting and disabling a group is illustrated
5228 by the following example.
5229 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
5230 If group @samp{FGR} is deleted, the following program unit will
5231 successfully compile, because @samp{FOO()} will be seen as a
5232 reference to an external function named @samp{FOO}:
5233
5234 @example
5235 PRINT *, FOO()
5236 END
5237 @end example
5238
5239 @noindent
5240 If group @samp{FGR} is disabled, compiling the above program will produce
5241 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
5242 or, if properly invoked, it is not enabled.
5243 To change the above program so it references an external function @samp{FOO}
5244 instead of the disabled @samp{FOO} intrinsic,
5245 add the following line to the top:
5246
5247 @example
5248 EXTERNAL FOO
5249 @end example
5250
5251 @noindent
5252 So, deleting a group tells @command{g77} to pretend as though the intrinsics in
5253 that group do not exist at all, whereas disabling it tells @command{g77} to
5254 recognize them as (disabled) intrinsics in intrinsic-like contexts.
5255
5256 Hiding a group is like enabling it, but the intrinsic must be first
5257 named in an @code{INTRINSIC} statement to be considered a reference to the
5258 intrinsic rather than to an external procedure.
5259 This might be the ``safest'' way to treat a new group of intrinsics
5260 when compiling old
5261 code, because it allows the old code to be generally written as if
5262 those new intrinsics never existed, but to be changed to use them
5263 by inserting @code{INTRINSIC} statements in the appropriate places.
5264 However, it should be the goal of development to use @code{EXTERNAL}
5265 for all names of external procedures that might be intrinsic names.
5266
5267 If an intrinsic is in more than one group, it is enabled if any of its
5268 containing groups are enabled; if not so enabled, it is hidden if
5269 any of its containing groups are hidden; if not so hidden, it is disabled
5270 if any of its containing groups are disabled; if not so disabled, it is
5271 deleted.
5272 This extra complication is necessary because some intrinsics,
5273 such as @code{IBITS}, belong to more than one group, and hence should be
5274 enabled if any of the groups to which they belong are enabled, and so
5275 on.
5276
5277 The groups are:
5278
5279 @cindex intrinsics, groups of
5280 @cindex groups of intrinsics
5281 @table @code
5282 @cindex @code{badu77} intrinsics group
5283 @item badu77
5284 UNIX intrinsics having inappropriate forms (usually functions that
5285 have intended side effects).
5286
5287 @cindex @code{gnu} intrinsics group
5288 @item gnu
5289 Intrinsics the GNU Fortran language supports that are extensions to
5290 the Fortran standards (77 and 90).
5291
5292 @cindex @command{f2c} intrinsics group
5293 @item f2c
5294 Intrinsics supported by AT&T's @command{f2c} converter and/or @code{libf2c}.
5295
5296 @cindex @code{f90} intrinsics group
5297 @item f90
5298 Fortran 90 intrinsics.
5299
5300 @cindex @code{mil} intrinsics group
5301 @item mil
5302 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
5303
5304 @cindex @code{mil} intrinsics group
5305 @item unix
5306 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
5307
5308 @cindex @code{mil} intrinsics group
5309 @item vxt
5310 VAX/VMS FORTRAN (current as of v4) intrinsics.
5311 @end table
5312
5313 @node Other Intrinsics
5314 @subsection Other Intrinsics
5315 @cindex intrinsics, others
5316 @cindex other intrinsics
5317
5318 @command{g77} supports intrinsics other than those in the GNU Fortran
5319 language proper.
5320 This set of intrinsics is described below.
5321
5322 @ifinfo
5323 (Note that the empty lines appearing in the menu below
5324 are not intentional---they result from a bug in the
5325 @code{makeinfo} program.)
5326 @end ifinfo
5327
5328 @c The actual documentation for intrinsics comes from
5329 @c intdoc.texi, which in turn is automatically generated
5330 @c from the internal g77 tables in intrin.def _and_ the
5331 @c largely hand-written text in intdoc.h.  So, if you want
5332 @c to change or add to existing documentation on intrinsics,
5333 @c you probably want to edit intdoc.h.
5334 @c
5335 @clear familyF77
5336 @clear familyGNU
5337 @clear familyASC
5338 @clear familyMIL
5339 @clear familyF90
5340 @set familyVXT
5341 @set familyFVZ
5342 @clear familyF2C
5343 @clear familyF2U
5344 @set familyBADU77
5345 @include intdoc.texi
5346
5347 @node Other Compilers
5348 @chapter Other Compilers
5349
5350 An individual Fortran source file can be compiled to
5351 an object (@file{*.o}) file instead of to the final
5352 program executable.
5353 This allows several portions of a program to be compiled
5354 at different times and linked together whenever a new
5355 version of the program is needed.
5356 However, it introduces the issue of @dfn{object compatibility}
5357 across the various object files (and libraries, or @file{*.a}
5358 files) that are linked together to produce any particular
5359 executable file.
5360
5361 Object compatibility is an issue when combining, in one
5362 program, Fortran code compiled by more than one compiler
5363 (or more than one configuration of a compiler).
5364 If the compilers
5365 disagree on how to transform the names of procedures, there
5366 will normally be errors when linking such programs.
5367 Worse, if the compilers agree on naming, but disagree on issues
5368 like how to pass parameters, return arguments, and lay out
5369 @code{COMMON} areas, the earliest detected errors might be the
5370 incorrect results produced by the program (and that assumes
5371 these errors are detected, which is not always the case).
5372
5373 Normally, @command{g77} generates code that is
5374 object-compatible with code generated by a version of
5375 @command{f2c} configured (with, for example, @file{f2c.h} definitions)
5376 to be generally compatible with @command{g77} as built by @command{gcc}.
5377 (Normally, @command{f2c} will, by default, conform to the appropriate
5378 configuration, but it is possible that older or perhaps even newer
5379 versions of @command{f2c}, or versions having certain configuration changes
5380 to @command{f2c} internals, will produce object files that are
5381 incompatible with @command{g77}.)
5382
5383 For example, a Fortran string subroutine
5384 argument will become two arguments on the C side: a @code{char *}
5385 and an @code{int} length.
5386
5387 Much of this compatibility results from the fact that
5388 @command{g77} uses the same run-time library,
5389 @code{libf2c}, used by @command{f2c},
5390 though @command{g77} gives its version the name @code{libg2c}
5391 so as to avoid conflicts when linking,
5392 installing them in the same directories,
5393 and so on.
5394
5395 Other compilers might or might not generate code that
5396 is object-compatible with @code{libg2c} and current @command{g77},
5397 and some might offer such compatibility only when explicitly
5398 selected via a command-line option to the compiler.
5399
5400 @emph{Note: This portion of the documentation definitely needs a lot
5401 of work!}
5402
5403 @menu
5404 * Dropping f2c Compatibility::  When speed is more important.
5405 * Compilers Other Than f2c::    Interoperation with code from other compilers.
5406 @end menu
5407
5408 @node Dropping f2c Compatibility
5409 @section Dropping @command{f2c} Compatibility
5410
5411 Specifying @option{-fno-f2c} allows @command{g77} to generate, in
5412 some cases, faster code, by not needing to allow to the possibility
5413 of linking with code compiled by @command{f2c}.
5414
5415 For example, this affects how @code{REAL(KIND=1)},
5416 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
5417 With @option{-fno-f2c}, they are
5418 compiled as returning the appropriate @command{gcc} type
5419 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
5420 in many configurations).
5421
5422 With @option{-ff2c} in force, they
5423 are compiled differently (with perhaps slower run-time performance)
5424 to accommodate the restrictions inherent in @command{f2c}'s use of K&R
5425 C as an intermediate language---@code{REAL(KIND=1)} functions
5426 return C's @code{double} type, while @code{COMPLEX} functions return
5427 @code{void} and use an extra argument pointing to a place for the functions to
5428 return their values.
5429
5430 It is possible that, in some cases, leaving @option{-ff2c} in force
5431 might produce faster code than using @option{-fno-f2c}.
5432 Feel free to experiment, but remember to experiment with changing the way
5433 @emph{entire programs and their Fortran libraries are compiled} at
5434 a time, since this sort of experimentation affects the interface
5435 of code generated for a Fortran source file---that is, it affects
5436 object compatibility.
5437
5438 Note that @command{f2c} compatibility is a fairly static target to achieve,
5439 though not necessarily perfectly so, since, like @command{g77}, it is
5440 still being improved.
5441 However, specifying @option{-fno-f2c} causes @command{g77}
5442 to generate code that will probably be incompatible with code
5443 generated by future versions of @command{g77} when the same option
5444 is in force.
5445 You should make sure you are always able to recompile complete
5446 programs from source code when upgrading to new versions of @command{g77}
5447 or @command{f2c}, especially when using options such as @option{-fno-f2c}.
5448
5449 Therefore, if you are using @command{g77} to compile libraries and other
5450 object files for possible future use and you don't want to require
5451 recompilation for future use with subsequent versions of @command{g77},
5452 you might want to stick with @command{f2c} compatibility for now, and
5453 carefully watch for any announcements about changes to the
5454 @command{f2c}/@code{libf2c} interface that might affect existing programs
5455 (thus requiring recompilation).
5456
5457 It is probable that a future version of @command{g77} will not,
5458 by default, generate object files compatible with @command{f2c},
5459 and that version probably would no longer use @code{libf2c}.
5460 If you expect to depend on this compatibility in the
5461 long term, use the options @samp{-ff2c -ff2c-library} when compiling
5462 all of the applicable code.
5463 This should cause future versions of @command{g77} either to produce
5464 compatible code (at the expense of the availability of some features and
5465 performance), or at the very least, to produce diagnostics.
5466
5467 (The library @command{g77} produces will no longer be named @file{libg2c}
5468 when it is no longer generally compatible with @file{libf2c}.
5469 It will likely be referred to, and, if installed as a distinct
5470 library, named @code{libg77}, or some other as-yet-unused name.)
5471
5472 @node Compilers Other Than f2c
5473 @section Compilers Other Than @command{f2c}
5474
5475 On systems with Fortran compilers other than @command{f2c} and @command{g77},
5476 code compiled by @command{g77} is not expected to work
5477 well with code compiled by the native compiler.
5478 (This is true for @command{f2c}-compiled objects as well.)
5479 Libraries compiled with the native compiler probably will have
5480 to be recompiled with @command{g77} to be used with @command{g77}-compiled code.
5481
5482 Reasons for such incompatibilities include:
5483
5484 @itemize @bullet
5485 @item
5486 There might be differences in the way names of Fortran procedures
5487 are translated for use in the system's object-file format.
5488 For example, the statement @samp{CALL FOO} might be compiled
5489 by @command{g77} to call a procedure the linker @command{ld} sees
5490 given the name @samp{_foo_}, while the apparently corresponding
5491 statement @samp{SUBROUTINE FOO} might be compiled by the
5492 native compiler to define the linker-visible name @samp{_foo},
5493 or @samp{_FOO_}, and so on.
5494
5495 @item
5496 There might be subtle type mismatches which cause subroutine arguments
5497 and function return values to get corrupted.
5498
5499 This is why simply getting @command{g77} to
5500 transform procedure names the same way a native
5501 compiler does is not usually a good idea---unless
5502 some effort has been made to ensure that, aside
5503 from the way the two compilers transform procedure
5504 names, everything else about the way they generate
5505 code for procedure interfaces is identical.
5506
5507 @item
5508 Native compilers
5509 use libraries of private I/O routines which will not be available
5510 at link time unless you have the native compiler---and you would
5511 have to explicitly ask for them.
5512
5513 For example, on the Sun you
5514 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
5515 command.
5516 @end itemize
5517
5518 @node Other Languages
5519 @chapter Other Languages
5520
5521 @emph{Note: This portion of the documentation definitely needs a lot
5522 of work!}
5523
5524 @menu
5525 * Interoperating with C and C++::
5526 @end menu
5527
5528 @node Interoperating with C and C++
5529 @section Tools and advice for interoperating with C and C++
5530
5531 @cindex C, linking with
5532 @cindex C++, linking with
5533 @cindex linking with C
5534 The following discussion assumes that you are running @command{g77} in @command{f2c}
5535 compatibility mode, i.e.@: not using @option{-fno-f2c}.
5536 It provides some
5537 advice about quick and simple techniques for linking Fortran and C (or
5538 C++), the most common requirement.
5539 For the full story consult the
5540 description of code generation.
5541 @xref{Debugging and Interfacing}.
5542
5543 When linking Fortran and C, it's usually best to use @command{g77} to do
5544 the linking so that the correct libraries are included (including the
5545 maths one).
5546 If you're linking with C++ you will want to add
5547 @option{-lstdc++}, @option{-lg++} or whatever.
5548 If you need to use another
5549 driver program (or @command{ld} directly),
5550 you can find out what linkage
5551 options @command{g77} passes by running @samp{g77 -v}.
5552
5553 @menu
5554 * C Interfacing Tools::
5555 * C Access to Type Information::
5556 * f2c Skeletons and Prototypes::
5557 * C++ Considerations::
5558 * Startup Code::
5559 @end menu
5560
5561 @node C Interfacing Tools
5562 @subsection C Interfacing Tools
5563 @pindex f2c
5564 @cindex cfortran.h
5565 @cindex Netlib
5566 Even if you don't actually use it as a compiler, @command{f2c} from
5567 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
5568 interfacing (linking) Fortran and C@.
5569 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @command{f2c}}.
5570
5571 To use @command{f2c} for this purpose you only need retrieve and
5572 build the @file{src} directory from the distribution, consult the
5573 @file{README} instructions there for machine-specifics, and install the
5574 @command{f2c} program on your path.
5575
5576 Something else that might be useful is @samp{cfortran.h} from
5577 @uref{ftp://zebra.desy.de/cfortran}.
5578 This is a fairly general tool which
5579 can be used to generate interfaces for calling in both directions
5580 between Fortran and C@.
5581 It can be used in @command{f2c} mode with
5582 @command{g77}---consult its documentation for details.
5583
5584 @node C Access to Type Information
5585 @subsection Accessing Type Information in C
5586
5587 @cindex types, Fortran/C
5588 Generally, C code written to link with
5589 @command{g77} code---calling and/or being
5590 called from Fortran---should @samp{#include <g2c.h>} to define the C
5591 versions of the Fortran types.
5592 Don't assume Fortran @code{INTEGER} types
5593 correspond to C @code{int}s, for instance; instead, declare them as
5594 @code{integer}, a type defined by @file{g2c.h}.
5595 @file{g2c.h} is installed where @command{gcc} will find it by
5596 default, assuming you use a copy of @command{gcc} compatible with
5597 @command{g77}, probably built at the same time as @command{g77}.
5598
5599 @node f2c Skeletons and Prototypes
5600 @subsection Generating Skeletons and Prototypes with @command{f2c}
5601
5602 @pindex f2c
5603 @cindex -fno-second-underscore
5604 A simple and foolproof way to write @command{g77}-callable C routines---e.g.@: to
5605 interface with an existing library---is to write a file (named, for
5606 example, @file{fred.f}) of dummy Fortran
5607 skeletons comprising just the declaration of the routine(s) and dummy
5608 arguments plus @code{END} statements.
5609 Then run @command{f2c} on file @file{fred.f} to produce @file{fred.c}
5610 into which you can edit
5611 useful code, confident the calling sequence is correct, at least.
5612 (There are some errors otherwise commonly made in generating C
5613 interfaces with @command{f2c} conventions,
5614 such as not using @code{doublereal}
5615 as the return type of a @code{REAL} @code{FUNCTION}.)
5616
5617 @pindex ftnchek
5618 @command{f2c} also can help with calling Fortran from C, using its
5619 @option{-P} option to generate C prototypes appropriate for calling the
5620 Fortran.@footnote{The files generated like this can also be used for
5621 inter-unit consistency checking of dummy and actual arguments, although
5622 the @command{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
5623 or @uref{ftp://ftp.dsm.fordham.edu} is
5624 probably better for this purpose.}
5625 If the Fortran code containing any
5626 routines to be called from C is in file @file{joe.f}, use the command
5627 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
5628 prototype information.
5629 @code{#include} this in the C which has to call
5630 the Fortran routines to make sure you get it right.
5631
5632 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
5633 between the way Fortran (including compilers like @command{g77}) and
5634 C handle arrays.
5635
5636 @node C++ Considerations
5637 @subsection C++ Considerations
5638
5639 @cindex C++
5640 @command{f2c} can be used to generate suitable code for compilation with a
5641 C++ system using the @option{-C++} option.
5642 The important thing about linking @command{g77}-compiled
5643 code with C++ is that the prototypes for the @command{g77}
5644 routines must specify C linkage to avoid name mangling.
5645 So, use an @samp{extern "C"} declaration.
5646 @command{f2c}'s @option{-C++} option will take care
5647 of this when generating skeletons or prototype files as above, and also
5648 avoid clashes with C++ reserved words in addition to those in C@.
5649
5650 @node Startup Code
5651 @subsection Startup Code
5652
5653 @cindex startup code
5654 @cindex run-time, initialization
5655 @cindex initialization, run-time
5656 Unlike with some runtime systems,
5657 it shouldn't be necessary
5658 (unless there are bugs)
5659 to use a Fortran main program unit to ensure the
5660 runtime---specifically the I/O system---is initialized.
5661
5662 However, to use the @command{g77} intrinsics @code{GETARG} and @code{IARGC},
5663 either the @code{main} routine from the @file{libg2c} library must be used,
5664 or the @code{f_setarg} routine
5665 (new as of @code{egcs} version 1.1 and @command{g77} version 0.5.23)
5666 must be called with the appropriate @code{argc} and @code{argv} arguments
5667 prior to the program calling @code{GETARG} or @code{IARGC}.
5668
5669 To provide more flexibility for mixed-language programming
5670 involving @command{g77} while allowing for shared libraries,
5671 as of @code{egcs} version 1.1 and @command{g77} version 0.5.23,
5672 @command{g77}'s @code{main} routine in @code{libg2c}
5673 does the following, in order:
5674
5675 @enumerate
5676 @item
5677 Calls @code{f_setarg}
5678 with the incoming @code{argc} and @code{argv} arguments,
5679 in the same order as for @code{main} itself.
5680
5681 This sets up the command-line environment
5682 for @code{GETARG} and @code{IARGC}.
5683
5684 @item
5685 Calls @code{f_setsig} (with no arguments).
5686
5687 This sets up the signaling and exception environment.
5688
5689 @item
5690 Calls @code{f_init} (with no arguments).
5691
5692 This initializes the I/O environment,
5693 though that should not be necessary,
5694 as all I/O functions in @code{libf2c}
5695 are believed to call @code{f_init} automatically,
5696 if necessary.
5697
5698 (A future version of @command{g77} might skip this explicit step,
5699 to speed up normal exit of a program.)
5700
5701 @item
5702 Arranges for @code{f_exit} to be called (with no arguments)
5703 when the program exits.
5704
5705 This ensures that the I/O environment is properly shut down
5706 before the program exits normally.
5707 Otherwise, output buffers might not be fully flushed,
5708 scratch files might not be deleted, and so on.
5709
5710 The simple way @code{main} does this is
5711 to call @code{f_exit} itself after calling
5712 @code{MAIN__} (in the next step).
5713
5714 However, this does not catch the cases where the program
5715 might call @code{exit} directly,
5716 instead of using the @code{EXIT} intrinsic
5717 (implemented as @code{exit_} in @code{libf2c}).
5718
5719 So, @code{main} attempts to use
5720 the operating environment's @code{onexit} or @code{atexit}
5721 facility, if available,
5722 to cause @code{f_exit} to be called automatically
5723 upon any invocation of @code{exit}.
5724
5725 @item
5726 Calls @code{MAIN__} (with no arguments).
5727
5728 This starts executing the Fortran main program unit for
5729 the application.
5730 (Both @command{g77} and @command{f2c} currently compile a main
5731 program unit so that its global name is @code{MAIN__}.)
5732
5733 @item
5734 If no @code{onexit} or @code{atexit} is provided by the system,
5735 calls @code{f_exit}.
5736
5737 @item
5738 Calls @code{exit} with a zero argument,
5739 to signal a successful program termination.
5740
5741 @item
5742 Returns a zero value to the caller,
5743 to signal a successful program termination,
5744 in case @code{exit} doesn't exit on the system.
5745 @end enumerate
5746
5747 All of the above names are C @code{extern} names,
5748 i.e.@: not mangled.
5749
5750 When using the @code{main} procedure provided by @command{g77}
5751 without a Fortran main program unit,
5752 you need to provide @code{MAIN__}
5753 as the entry point for your C code.
5754 (Make sure you link the object file that defines that
5755 entry point with the rest of your program.)
5756
5757 To provide your own @code{main} procedure
5758 in place of @command{g77}'s,
5759 make sure you specify the object file defining that procedure
5760 @emph{before} @option{-lg2c} on the @command{g77} command line.
5761 Since the @option{-lg2c} option is implicitly provided,
5762 this is usually straightforward.
5763 (Use the @option{--verbose} option to see how and where
5764 @command{g77} implicitly adds @option{-lg2c} in a command line
5765 that will link the program.
5766 Feel free to specify @option{-lg2c} explicitly,
5767 as appropriate.)
5768
5769 However, when providing your own @code{main},
5770 make sure you perform the appropriate tasks in the
5771 appropriate order.
5772 For example, if your @code{main} does not call @code{f_setarg},
5773 make sure the rest of your application does not call
5774 @code{GETARG} or @code{IARGC}.
5775
5776 And, if your @code{main} fails to ensure that @code{f_exit}
5777 is called upon program exit,
5778 some files might end up incompletely written,
5779 some scratch files might be left lying around,
5780 and some existing files being written might be left
5781 with old data not properly truncated at the end.
5782
5783 Note that, generally, the @command{g77} operating environment
5784 does not depend on a procedure named @code{MAIN__} actually
5785 being called prior to any other @command{g77}-compiled code.
5786 That is, @code{MAIN__} does not, itself,
5787 set up any important operating-environment characteristics
5788 upon which other code might depend.
5789 This might change in future versions of @command{g77},
5790 with appropriate notification in the release notes.
5791
5792 For more information, consult the source code for the above routines.
5793 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
5794 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
5795
5796 Also, the file @file{@value{path-g77}/com.c} contains the code @command{g77}
5797 uses to open-code (inline) references to @code{IARGC}.
5798
5799 @node Debugging and Interfacing
5800 @chapter Debugging and Interfacing
5801 @cindex debugging
5802 @cindex interfacing
5803 @cindex calling C routines
5804 @cindex C routines calling Fortran
5805 @cindex f2c compatibility
5806
5807 GNU Fortran currently generates code that is object-compatible with
5808 the @command{f2c} converter.
5809 Also, it avoids limitations in the current GBE, such as the
5810 inability to generate a procedure with
5811 multiple entry points, by generating code that is structured
5812 differently (in terms of procedure names, scopes, arguments, and
5813 so on) than might be expected.
5814
5815 As a result, writing code in other languages that calls on, is
5816 called by, or shares in-memory data with @command{g77}-compiled code generally
5817 requires some understanding of the way @command{g77} compiles code for
5818 various constructs.
5819
5820 Similarly, using a debugger to debug @command{g77}-compiled
5821 code, even if that debugger supports native Fortran debugging, generally
5822 requires this sort of information.
5823
5824 This section describes some of the basic information on how
5825 @command{g77} compiles code for constructs involving interfaces to other
5826 languages and to debuggers.
5827
5828 @emph{Caution:} Much or all of this information pertains to only the current
5829 release of @command{g77}, sometimes even to using certain compiler options
5830 with @command{g77} (such as @option{-fno-f2c}).
5831 Do not write code that depends on this
5832 information without clearly marking said code as nonportable and
5833 subject to review for every new release of @command{g77}.
5834 This information
5835 is provided primarily to make debugging of code generated by this
5836 particular release of @command{g77} easier for the user, and partly to make
5837 writing (generally nonportable) interface code easier.
5838 Both of these
5839 activities require tracking changes in new version of @command{g77} as they
5840 are installed, because new versions can change the behaviors
5841 described in this section.
5842
5843 @menu
5844 * Main Program Unit::  How @command{g77} compiles a main program unit.
5845 * Procedures::         How @command{g77} constructs parameter lists
5846                        for procedures.
5847 * Functions::          Functions returning floating-point or character data.
5848 * Names::              Naming of user-defined variables, procedures, etc.
5849 * Common Blocks::      Accessing common variables while debugging.
5850 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
5851 * Complex Variables::  How @command{g77} performs complex arithmetic.
5852 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
5853 * Adjustable Arrays::  Special consideration for adjustable arrays.
5854 * Alternate Entry Points::  How @command{g77} implements alternate @code{ENTRY}.
5855 * Alternate Returns::  How @command{g77} handles alternate returns.
5856 * Assigned Statement Labels::  How @command{g77} handles @code{ASSIGN}.
5857 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
5858 @end menu
5859
5860 @node Main Program Unit
5861 @section Main Program Unit (PROGRAM)
5862 @cindex PROGRAM statement
5863 @cindex statements, PROGRAM
5864
5865 When @command{g77} compiles a main program unit, it gives it the public
5866 procedure name @code{MAIN__}.
5867 The @code{libg2c} library has the actual @code{main()} procedure
5868 as is typical of C-based environments, and
5869 it is this procedure that performs some initial start-up
5870 activity and then calls @code{MAIN__}.
5871
5872 Generally, @command{g77} and @code{libg2c} are designed so that you need not
5873 include a main program unit written in Fortran in your program---it
5874 can be written in C or some other language.
5875 Especially for I/O handling, this is the case, although @command{g77} version 0.5.16
5876 includes a bug fix for @code{libg2c} that solved a problem with using the
5877 @code{OPEN} statement as the first Fortran I/O activity in a program
5878 without a Fortran main program unit.
5879
5880 However, if you don't intend to use @command{g77} (or @command{f2c}) to compile
5881 your main program unit---that is, if you intend to compile a @code{main()}
5882 procedure using some other language---you should carefully
5883 examine the code for @code{main()} in @code{libg2c}, found in the source
5884 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
5885 might need to be done by your @code{main()} in order to provide the
5886 Fortran environment your Fortran code is expecting.
5887
5888 @cindex @code{IArgC} intrinsic
5889 @cindex intrinsics, @code{IArgC}
5890 @cindex @code{GetArg} intrinsic
5891 @cindex intrinsics, @code{GetArg}
5892 For example, @code{libg2c}'s @code{main()} sets up the information used by
5893 the @code{IARGC} and @code{GETARG} intrinsics.
5894 Bypassing @code{libg2c}'s @code{main()}
5895 without providing a substitute for this activity would mean
5896 that invoking @code{IARGC} and @code{GETARG} would produce undefined
5897 results.
5898
5899 @cindex debugging
5900 @cindex main program unit, debugging
5901 @cindex main()
5902 @cindex MAIN__()
5903 @cindex .gdbinit
5904 When debugging, one implication of the fact that @code{main()}, which
5905 is the place where the debugged program ``starts'' from the
5906 debugger's point of view, is in @code{libg2c} is that you won't be
5907 starting your Fortran program at a point you recognize as your
5908 Fortran code.
5909
5910 The standard way to get around this problem is to set a break
5911 point (a one-time, or temporary, break point will do) at
5912 the entrance to @code{MAIN__}, and then run the program.
5913 A convenient way to do so is to add the @command{gdb} command
5914
5915 @example
5916 tbreak MAIN__
5917 @end example
5918
5919 @noindent
5920 to the file @file{.gdbinit} in the directory in which you're debugging
5921 (using @command{gdb}).
5922
5923 After doing this, the debugger will see the current execution
5924 point of the program as at the beginning of the main program
5925 unit of your program.
5926
5927 Of course, if you really want to set a break point at some
5928 other place in your program and just start the program
5929 running, without first breaking at @code{MAIN__},
5930 that should work fine.
5931
5932 @node Procedures
5933 @section Procedures (SUBROUTINE and FUNCTION)
5934 @cindex procedures
5935 @cindex SUBROUTINE statement
5936 @cindex statements, SUBROUTINE
5937 @cindex FUNCTION statement
5938 @cindex statements, FUNCTION
5939 @cindex signature of procedures
5940
5941 Currently, @command{g77} passes arguments via reference---specifically,
5942 by passing a pointer to the location in memory of a variable, array,
5943 array element, a temporary location that holds the result of evaluating an
5944 expression, or a temporary or permanent location that holds the value
5945 of a constant.
5946
5947 Procedures that accept @code{CHARACTER} arguments are implemented by
5948 @command{g77} so that each @code{CHARACTER} argument has two actual arguments.
5949
5950 The first argument occupies the expected position in the
5951 argument list and has the user-specified name.
5952 This argument
5953 is a pointer to an array of characters, passed by the caller.
5954
5955 The second argument is appended to the end of the user-specified
5956 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
5957 is the user-specified name.
5958 This argument is of the C type @code{ftnlen}
5959 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
5960 is the number of characters the caller has allocated in the
5961 array pointed to by the first argument.
5962
5963 A procedure will ignore the length argument if @samp{X} is not declared
5964 @code{CHARACTER*(*)}, because for other declarations, it knows the
5965 length.
5966 Not all callers necessarily ``know'' this, however, which
5967 is why they all pass the extra argument.
5968
5969 The contents of the @code{CHARACTER} argument are specified by the
5970 address passed in the first argument (named after it).
5971 The procedure can read or write these contents as appropriate.
5972
5973 When more than one @code{CHARACTER} argument is present in the argument
5974 list, the length arguments are appended in the order
5975 the original arguments appear.
5976 So @samp{CALL FOO('HI','THERE')} is implemented in
5977 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @command{g77}
5978 does not provide the trailing null bytes on the constant
5979 strings (@command{f2c} does provide them, but they are unnecessary in
5980 a Fortran environment, and you should not expect them to be
5981 there).
5982
5983 Note that the above information applies to @code{CHARACTER} variables and
5984 arrays @strong{only}.
5985 It does @strong{not} apply to external @code{CHARACTER}
5986 functions or to intrinsic @code{CHARACTER} functions.
5987 That is, no second length argument is passed to @samp{FOO} in this case:
5988
5989 @example
5990 CHARACTER X
5991 EXTERNAL X
5992 CALL FOO(X)
5993 @end example
5994
5995 @noindent
5996 Nor does @samp{FOO} expect such an argument in this case:
5997
5998 @example
5999 SUBROUTINE FOO(X)
6000 CHARACTER X
6001 EXTERNAL X
6002 @end example
6003
6004 Because of this implementation detail, if a program has a bug
6005 such that there is disagreement as to whether an argument is
6006 a procedure, and the type of the argument is @code{CHARACTER}, subtle
6007 symptoms might appear.
6008
6009 @node Functions
6010 @section Functions (FUNCTION and RETURN)
6011 @cindex functions
6012 @cindex FUNCTION statement
6013 @cindex statements, FUNCTION
6014 @cindex RETURN statement
6015 @cindex statements, RETURN
6016 @cindex return type of functions
6017
6018 @command{g77} handles in a special way functions that return the following
6019 types:
6020
6021 @itemize @bullet
6022 @item
6023 @code{CHARACTER}
6024 @item
6025 @code{COMPLEX}
6026 @item
6027 @code{REAL(KIND=1)}
6028 @end itemize
6029
6030 For @code{CHARACTER}, @command{g77} implements a subroutine (a C function
6031 returning @code{void})
6032 with two arguments prepended: @samp{__g77_result}, which the caller passes
6033 as a pointer to a @code{char} array expected to hold the return value,
6034 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
6035 specifying the length of the return value as declared in the calling
6036 program.
6037 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
6038 to determine the size of the array that @samp{__g77_result} points to;
6039 otherwise, it ignores that argument.
6040
6041 For @code{COMPLEX}, when @option{-ff2c} is in
6042 force, @command{g77} implements
6043 a subroutine with one argument prepended: @samp{__g77_result}, which the
6044 caller passes as a pointer to a variable of the type of the function.
6045 The called function writes the return value into this variable instead
6046 of returning it as a function value.
6047 When @option{-fno-f2c} is in force,
6048 @command{g77} implements a @code{COMPLEX} function as @command{gcc}'s
6049 @samp{__complex__ float} or @samp{__complex__ double} function
6050 (or an emulation thereof, when @option{-femulate-complex} is in effect),
6051 returning the result of the function in the same way as @command{gcc} would.
6052
6053 For @code{REAL(KIND=1)}, when @option{-ff2c} is in force, @command{g77} implements
6054 a function that actually returns @code{REAL(KIND=2)} (typically
6055 C's @code{double} type).
6056 When @option{-fno-f2c} is in force, @code{REAL(KIND=1)}
6057 functions return @code{float}.
6058
6059 @node Names
6060 @section Names
6061 @cindex symbol names
6062 @cindex transforming symbol names
6063
6064 Fortran permits each implementation to decide how to represent
6065 names as far as how they're seen in other contexts, such as debuggers
6066 and when interfacing to other languages, and especially as far
6067 as how casing is handled.
6068
6069 External names---names of entities that are public, or ``accessible'',
6070 to all modules in a program---normally have an underscore (@samp{_})
6071 appended by @command{g77},
6072 to generate code that is compatible with @command{f2c}.
6073 External names include names of Fortran things like common blocks,
6074 external procedures (subroutines and functions, but not including
6075 statement functions, which are internal procedures), and entry point
6076 names.
6077
6078 However, use of the @option{-fno-underscoring} option
6079 disables this kind of transformation of external names (though inhibiting
6080 the transformation certainly improves the chances of colliding with
6081 incompatible externals written in other languages---but that
6082 might be intentional.
6083
6084 @cindex -fno-underscoring option
6085 @cindex options, -fno-underscoring
6086 @cindex -fno-second-underscore option
6087 @cindex options, -fno-underscoring
6088 When @option{-funderscoring} is in force, any name (external or local)
6089 that already has at least one underscore in it is
6090 implemented by @command{g77} by appending two underscores.
6091 (This second underscore can be disabled via the
6092 @option{-fno-second-underscore} option.)
6093 External names are changed this way for @command{f2c} compatibility.
6094 Local names are changed this way to avoid collisions with external names
6095 that are different in the source code---@command{f2c} does the same thing, but
6096 there's no compatibility issue there except for user expectations while
6097 debugging.
6098
6099 For example:
6100
6101 @example
6102 Max_Cost = 0
6103 @end example
6104
6105 @cindex debugging
6106 @noindent
6107 Here, a user would, in the debugger, refer to this variable using the
6108 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
6109 as described below).
6110 (We hope to improve @command{g77} in this regard in the future---don't
6111 write scripts depending on this behavior!
6112 Also, consider experimenting with the @option{-fno-underscoring}
6113 option to try out debugging without having to massage names by
6114 hand like this.)
6115
6116 @command{g77} provides a number of command-line options that allow the user
6117 to control how case mapping is handled for source files.
6118 The default is the traditional UNIX model for Fortran compilers---names
6119 are mapped to lower case.
6120 Other command-line options can be specified to map names to upper
6121 case, or to leave them exactly as written in the source file.
6122
6123 For example:
6124
6125 @example
6126 Foo = 9.436
6127 @end example
6128
6129 @noindent
6130 Here, it is normally the case that the variable assigned will be named
6131 @samp{foo}.
6132 This would be the name to enter when using a debugger to
6133 access the variable.
6134
6135 However, depending on the command-line options specified, the
6136 name implemented by @command{g77} might instead be @samp{FOO} or even
6137 @samp{Foo}, thus affecting how debugging is done.
6138
6139 Also:
6140
6141 @example
6142 Call Foo
6143 @end example
6144
6145 @noindent
6146 This would normally call a procedure that, if it were in a separate C program,
6147 be defined starting with the line:
6148
6149 @example
6150 void foo_()
6151 @end example
6152
6153 @noindent
6154 However, @command{g77} command-line options could be used to change the casing
6155 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
6156 procedure instead of @samp{foo_}, and the @option{-fno-underscoring} option
6157 could be used to inhibit the appending of the underscore to the name.
6158
6159 @node Common Blocks
6160 @section Common Blocks (COMMON)
6161 @cindex common blocks
6162 @cindex @code{COMMON} statement
6163 @cindex statements, @code{COMMON}
6164
6165 @command{g77} names and lays out @code{COMMON} areas
6166 the same way @command{f2c} does,
6167 for compatibility with @command{f2c}.
6168
6169 @node Local Equivalence Areas
6170 @section Local Equivalence Areas (EQUIVALENCE)
6171 @cindex equivalence areas
6172 @cindex local equivalence areas
6173 @cindex EQUIVALENCE statement
6174 @cindex statements, EQUIVALENCE
6175
6176 @command{g77} treats storage-associated areas involving a @code{COMMON}
6177 block as explained in the section on common blocks.
6178
6179 A local @code{EQUIVALENCE} area is a collection of variables and arrays
6180 connected to each other in any way via @code{EQUIVALENCE}, none of which are
6181 listed in a @code{COMMON} statement.
6182
6183 (@emph{Note:} @command{g77} version 0.5.18 and earlier chose the name
6184 for @var{x} using a different method when more than one name was
6185 in the list of names of entities placed at the beginning of the
6186 array.
6187 Though the documentation specified that the first name listed in
6188 the @code{EQUIVALENCE} statements was chosen for @var{x}, @command{g77}
6189 in fact chose the name using a method that was so complicated,
6190 it seemed easier to change it to an alphabetical sort than to describe the
6191 previous method in the documentation.)
6192
6193 @node Complex Variables
6194 @section Complex Variables (COMPLEX)
6195 @cindex complex variables
6196 @cindex imaginary part
6197 @cindex COMPLEX statement
6198 @cindex statements, COMPLEX
6199
6200 As of 0.5.20, @command{g77} defaults to handling @code{COMPLEX} types
6201 (and related intrinsics, constants, functions, and so on)
6202 in a manner that
6203 makes direct debugging involving these types in Fortran
6204 language mode difficult.
6205
6206 Essentially, @command{g77} implements these types using an
6207 internal construct similar to C's @code{struct}, at least
6208 as seen by the @command{gcc} back end.
6209
6210 Currently, the back end, when outputting debugging info with
6211 the compiled code for the assembler to digest, does not detect
6212 these @code{struct} types as being substitutes for Fortran
6213 complex.
6214 As a result, the Fortran language modes of debuggers such as
6215 @command{gdb} see these types as C @code{struct} types, which
6216 they might or might not support.
6217
6218 Until this is fixed, switch to C language mode to work with
6219 entities of @code{COMPLEX} type and then switch back to Fortran language
6220 mode afterward.
6221 (In @command{gdb}, this is accomplished via @samp{set lang c} and
6222 either @samp{set lang fortran} or @samp{set lang auto}.)
6223
6224 @node Arrays
6225 @section Arrays (DIMENSION)
6226 @cindex DIMENSION statement
6227 @cindex statements, DIMENSION
6228 @cindex array ordering
6229 @cindex ordering, array
6230 @cindex column-major ordering
6231 @cindex row-major ordering
6232 @cindex arrays
6233
6234 Fortran uses ``column-major ordering'' in its arrays.
6235 This differs from other languages, such as C, which use ``row-major ordering''.
6236 The difference is that, with Fortran, array elements adjacent to
6237 each other in memory differ in the @emph{first} subscript instead of
6238 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
6239 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
6240
6241 This consideration
6242 affects not only interfacing with and debugging Fortran code,
6243 it can greatly affect how code is designed and written, especially
6244 when code speed and size is a concern.
6245
6246 Fortran also differs from C, a popular language for interfacing and
6247 to support directly in debuggers, in the way arrays are treated.
6248 In C, arrays are single-dimensional and have interesting relationships
6249 to pointers, neither of which is true for Fortran.
6250 As a result, dealing with Fortran arrays from within
6251 an environment limited to C concepts can be challenging.
6252
6253 For example, accessing the array element @samp{A(5,10,20)} is easy enough
6254 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
6255 are needed.
6256 First, C would treat the A array as a single-dimension array.
6257 Second, C does not understand low bounds for arrays as does Fortran.
6258 Third, C assumes a low bound of zero (0), while Fortran defaults to a
6259 low bound of one (1) and can supports an arbitrary low bound.
6260 Therefore, calculations must be done
6261 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
6262 calculations require knowing the dimensions of @samp{A}.
6263
6264 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
6265 @samp{A(5,10,20)} would be:
6266
6267 @example
6268   (5-2)
6269 + (10-1)*(11-2+1)
6270 + (20-0)*(11-2+1)*(21-1+1)
6271 = 4293
6272 @end example
6273
6274 @noindent
6275 So the C equivalent in this case would be @samp{a[4293]}.
6276
6277 When using a debugger directly on Fortran code, the C equivalent
6278 might not work, because some debuggers cannot understand the notion
6279 of low bounds other than zero.  However, unlike @command{f2c}, @command{g77}
6280 does inform the GBE that a multi-dimensional array (like @samp{A}
6281 in the above example) is really multi-dimensional, rather than a
6282 single-dimensional array, so at least the dimensionality of the array
6283 is preserved.
6284
6285 Debuggers that understand Fortran should have no trouble with
6286 non-zero low bounds, but for non-Fortran debuggers, especially
6287 C debuggers, the above example might have a C equivalent of
6288 @samp{a[4305]}.
6289 This calculation is arrived at by eliminating the subtraction
6290 of the lower bound in the first parenthesized expression on each
6291 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
6292 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
6293 Actually, the implication of
6294 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
6295 but that @samp{a[20][10][5]} produces the equivalent of
6296 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
6297
6298 Come to think of it, perhaps
6299 the behavior is due to the debugger internally compensating for
6300 the lower bounds by offsetting the base address of @samp{a}, leaving
6301 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
6302 its first element as identified by subscripts equal to the
6303 corresponding lower bounds).
6304
6305 You know, maybe nobody really needs to use arrays.
6306
6307 @node Adjustable Arrays
6308 @section Adjustable Arrays (DIMENSION)
6309 @cindex arrays, adjustable
6310 @cindex adjustable arrays
6311 @cindex arrays, automatic
6312 @cindex automatic arrays
6313 @cindex DIMENSION statement
6314 @cindex statements, DIMENSION
6315 @cindex dimensioning arrays
6316 @cindex arrays, dimensioning
6317
6318 Adjustable and automatic arrays in Fortran require the implementation
6319 (in this
6320 case, the @command{g77} compiler) to ``memorize'' the expressions that
6321 dimension the arrays each time the procedure is invoked.
6322 This is so that subsequent changes to variables used in those
6323 expressions, made during execution of the procedure, do not
6324 have any effect on the dimensions of those arrays.
6325
6326 For example:
6327
6328 @example
6329 REAL ARRAY(5)
6330 DATA ARRAY/5*2/
6331 CALL X(ARRAY, 5)
6332 END
6333 SUBROUTINE X(A, N)
6334 DIMENSION A(N)
6335 N = 20
6336 PRINT *, N, A
6337 END
6338 @end example
6339
6340 @noindent
6341 Here, the implementation should, when running the program, print something
6342 like:
6343
6344 @example
6345 20   2.  2.  2.  2.  2.
6346 @end example
6347
6348 @noindent
6349 Note that this shows that while the value of @samp{N} was successfully
6350 changed, the size of the @samp{A} array remained at 5 elements.
6351
6352 To support this, @command{g77} generates code that executes before any user
6353 code (and before the internally generated computed @code{GOTO} to handle
6354 alternate entry points, as described below) that evaluates each
6355 (nonconstant) expression in the list of subscripts for an
6356 array, and saves the result of each such evaluation to be used when
6357 determining the size of the array (instead of re-evaluating the
6358 expressions).
6359
6360 So, in the above example, when @samp{X} is first invoked, code is
6361 executed that copies the value of @samp{N} to a temporary.
6362 And that same temporary serves as the actual high bound for the single
6363 dimension of the @samp{A} array (the low bound being the constant 1).
6364 Since the user program cannot (legitimately) change the value
6365 of the temporary during execution of the procedure, the size
6366 of the array remains constant during each invocation.
6367
6368 For alternate entry points, the code @command{g77} generates takes into
6369 account the possibility that a dummy adjustable array is not actually
6370 passed to the actual entry point being invoked at that time.
6371 In that case, the public procedure implementing the entry point
6372 passes to the master private procedure implementing all the
6373 code for the entry points a @code{NULL} pointer where a pointer to that
6374 adjustable array would be expected.
6375 The @command{g77}-generated code
6376 doesn't attempt to evaluate any of the expressions in the subscripts
6377 for an array if the pointer to that array is @code{NULL} at run time in
6378 such cases.
6379 (Don't depend on this particular implementation
6380 by writing code that purposely passes @code{NULL} pointers where the
6381 callee expects adjustable arrays, even if you know the callee
6382 won't reference the arrays---nor should you pass @code{NULL} pointers
6383 for any dummy arguments used in calculating the bounds of such
6384 arrays or leave undefined any values used for that purpose in
6385 COMMON---because the way @command{g77} implements these things might
6386 change in the future!)
6387
6388 @node Alternate Entry Points
6389 @section Alternate Entry Points (ENTRY)
6390 @cindex alternate entry points
6391 @cindex entry points
6392 @cindex ENTRY statement
6393 @cindex statements, ENTRY
6394
6395 The GBE does not understand the general concept of
6396 alternate entry points as Fortran provides via the ENTRY statement.
6397 @command{g77} gets around this by using an approach to compiling procedures
6398 having at least one @code{ENTRY} statement that is almost identical to the
6399 approach used by @command{f2c}.
6400 (An alternate approach could be used that
6401 would probably generate faster, but larger, code that would also
6402 be a bit easier to debug.)
6403
6404 Information on how @command{g77} implements @code{ENTRY} is provided for those
6405 trying to debug such code.
6406 The choice of implementation seems
6407 unlikely to affect code (compiled in other languages) that interfaces
6408 to such code.
6409
6410 @command{g77} compiles exactly one public procedure for the primary entry
6411 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
6412 That is, in terms of the public interface, there is no difference
6413 between
6414
6415 @example
6416 SUBROUTINE X
6417 END
6418 SUBROUTINE Y
6419 END
6420 @end example
6421
6422 @noindent
6423 and:
6424
6425 @example
6426 SUBROUTINE X
6427 ENTRY Y
6428 END
6429 @end example
6430
6431 The difference between the above two cases lies in the code compiled
6432 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
6433 for the second case, an extra internal procedure is compiled.
6434
6435 For every Fortran procedure with at least one @code{ENTRY}
6436 statement, @command{g77} compiles an extra procedure
6437 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
6438 the name of the primary entry point (which, in the above case,
6439 using the standard compiler options, would be @samp{x_} in C).
6440
6441 This extra procedure is compiled as a private procedure---that is,
6442 a procedure not accessible by name to separately compiled modules.
6443 It contains all the code in the program unit, including the code
6444 for the primary entry point plus for every entry point.
6445 (The code for each public procedure is quite short, and explained later.)
6446
6447 The extra procedure has some other interesting characteristics.
6448
6449 The argument list for this procedure is invented by @command{g77}.
6450 It contains
6451 a single integer argument named @samp{__g77_which_entrypoint},
6452 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
6453 entry point index---0 for the primary entry point, 1 for the
6454 first entry point (the first @code{ENTRY} statement encountered), 2 for
6455 the second entry point, and so on.
6456
6457 It also contains, for functions returning @code{CHARACTER} and
6458 (when @option{-ff2c} is in effect) @code{COMPLEX} functions,
6459 and for functions returning different types among the
6460 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
6461 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
6462 is expected at run time to contain a pointer to where to store
6463 the result of the entry point.
6464 For @code{CHARACTER} functions, this
6465 storage area is an array of the appropriate number of characters;
6466 for @code{COMPLEX} functions, it is the appropriate area for the return
6467 type; for multiple-return-type functions, it is a union of all the supported return
6468 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
6469 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
6470 is not supported by @command{g77}).
6471
6472 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
6473 by yet another argument named @samp{__g77_length} that, at run time,
6474 specifies the caller's expected length of the returned value.
6475 Note that only @code{CHARACTER*(*)} functions and entry points actually
6476 make use of this argument, even though it is always passed by
6477 all callers of public @code{CHARACTER} functions (since the caller does not
6478 generally know whether such a function is @code{CHARACTER*(*)} or whether
6479 there are any other callers that don't have that information).
6480
6481 The rest of the argument list is the union of all the arguments
6482 specified for all the entry points (in their usual forms, e.g.
6483 @code{CHARACTER} arguments have extra length arguments, all appended at
6484 the end of this list).
6485 This is considered the ``master list'' of
6486 arguments.
6487
6488 The code for this procedure has, before the code for the first
6489 executable statement, code much like that for the following Fortran
6490 statement:
6491
6492 @smallexample
6493        GOTO (100000,100001,100002), __g77_which_entrypoint
6494 100000 @dots{}code for primary entry point@dots{}
6495 100001 @dots{}code immediately following first ENTRY statement@dots{}
6496 100002 @dots{}code immediately following second ENTRY statement@dots{}
6497 @end smallexample
6498
6499 @noindent
6500 (Note that invalid Fortran statement labels and variable names
6501 are used in the above example to highlight the fact that it
6502 represents code generated by the @command{g77} internals, not code to be
6503 written by the user.)
6504
6505 It is this code that, when the procedure is called, picks which
6506 entry point to start executing.
6507
6508 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
6509 example), those procedures are fairly simple.
6510 Their interfaces
6511 are just like they would be if they were self-contained procedures
6512 (without @code{ENTRY}), of course, since that is what the callers
6513 expect.
6514 Their code consists of simply calling the private
6515 procedure, described above, with the appropriate extra arguments
6516 (the entry point index, and perhaps a pointer to a multiple-type-
6517 return variable, local to the public procedure, that contains
6518 all the supported returnable non-character types).
6519 For arguments
6520 that are not listed for a given entry point that are listed for
6521 other entry points, and therefore that are in the ``master list''
6522 for the private procedure, null pointers (in C, the @code{NULL} macro)
6523 are passed.
6524 Also, for entry points that are part of a multiple-type-
6525 returning function, code is compiled after the call of the private
6526 procedure to extract from the multi-type union the appropriate result,
6527 depending on the type of the entry point in question, returning
6528 that result to the original caller.
6529
6530 When debugging a procedure containing alternate entry points, you
6531 can either set a break point on the public procedure itself (e.g.
6532 a break point on @samp{X} or @samp{Y}) or on the private procedure that
6533 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
6534 If you do the former, you should use the debugger's command to
6535 ``step into'' the called procedure to get to the actual code; with
6536 the latter approach, the break point leaves you right at the
6537 actual code, skipping over the public entry point and its call
6538 to the private procedure (unless you have set a break point there
6539 as well, of course).
6540
6541 Further, the list of dummy arguments that is visible when the
6542 private procedure is active is going to be the expanded version
6543 of the list for whichever particular entry point is active,
6544 as explained above, and the way in which return values are
6545 handled might well be different from how they would be handled
6546 for an equivalent single-entry function.
6547
6548 @node Alternate Returns
6549 @section Alternate Returns (SUBROUTINE and RETURN)
6550 @cindex subroutines
6551 @cindex alternate returns
6552 @cindex SUBROUTINE statement
6553 @cindex statements, SUBROUTINE
6554 @cindex RETURN statement
6555 @cindex statements, RETURN
6556
6557 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
6558 @samp{CALL X(*50)}) are implemented by @command{g77} as functions returning
6559 the C @code{int} type.
6560 The actual alternate-return arguments are omitted from the calling sequence.
6561 Instead, the caller uses
6562 the return value to do a rough equivalent of the Fortran
6563 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
6564 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
6565 function), and the callee just returns whatever integer
6566 is specified in the @code{RETURN} statement for the subroutine
6567 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
6568 by @samp{RETURN}
6569 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
6570
6571 @node Assigned Statement Labels
6572 @section Assigned Statement Labels (ASSIGN and GOTO)
6573 @cindex assigned statement labels
6574 @cindex statement labels, assigned
6575 @cindex ASSIGN statement
6576 @cindex statements, ASSIGN
6577 @cindex GOTO statement
6578 @cindex statements, GOTO
6579
6580 For portability to machines where a pointer (such as to a label,
6581 which is how @command{g77} implements @code{ASSIGN} and its relatives,
6582 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
6583 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @command{g77}
6584 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
6585 than it does the numerical value in that variable, unless the
6586 variable is wide enough (can hold enough bits).
6587
6588 In particular, while @command{g77} implements
6589
6590 @example
6591 I = 10
6592 @end example
6593
6594 @noindent
6595 as, in C notation, @samp{i = 10;}, it implements
6596
6597 @example
6598 ASSIGN 10 TO I
6599 @end example
6600
6601 @noindent
6602 as, in GNU's extended C notation (for the label syntax),
6603 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
6604 of the Fortran label @samp{10} to make the syntax C-like; @command{g77} doesn't
6605 actually generate the name @samp{L10} or any other name like that,
6606 since debuggers cannot access labels anyway).
6607
6608 While this currently means that an @code{ASSIGN} statement does not
6609 overwrite the numeric contents of its target variable, @emph{do not}
6610 write any code depending on this feature.
6611 @command{g77} has already changed this implementation across
6612 versions and might do so in the future.
6613 This information is provided only to make debugging Fortran programs
6614 compiled with the current version of @command{g77} somewhat easier.
6615 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
6616 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
6617 means @command{g77} has decided it can store the pointer to the label directly
6618 into @samp{I} itself.
6619
6620 @xref{Ugly Assigned Labels}, for information on a command-line option
6621 to force @command{g77} to use the same storage for both normal and
6622 assigned-label uses of a variable.
6623
6624 @node Run-time Library Errors
6625 @section Run-time Library Errors
6626 @cindex IOSTAT=
6627 @cindex error values
6628 @cindex error messages
6629 @cindex messages, run-time
6630 @cindex I/O, errors
6631
6632 The @code{libg2c} library currently has the following table to relate
6633 error code numbers, returned in @code{IOSTAT=} variables, to messages.
6634 This information should, in future versions of this document, be
6635 expanded upon to include detailed descriptions of each message.
6636
6637 In line with good coding practices, any of the numbers in the
6638 list below should @emph{not} be directly written into Fortran
6639 code you write.
6640 Instead, make a separate @code{INCLUDE} file that defines
6641 @code{PARAMETER} names for them, and use those in your code,
6642 so you can more easily change the actual numbers in the future.
6643
6644 The information below is culled from the definition
6645 of @code{F_err} in @file{f/runtime/libI77/err.c} in the
6646 @command{g77} source tree.
6647
6648 @smallexample
6649 100: "error in format"
6650 101: "illegal unit number"
6651 102: "formatted io not allowed"
6652 103: "unformatted io not allowed"
6653 104: "direct io not allowed"
6654 105: "sequential io not allowed"
6655 106: "can't backspace file"
6656 107: "null file name"
6657 108: "can't stat file"
6658 109: "unit not connected"
6659 110: "off end of record"
6660 111: "truncation failed in endfile"
6661 112: "incomprehensible list input"
6662 113: "out of free space"
6663 114: "unit not connected"
6664 115: "read unexpected character"
6665 116: "bad logical input field"
6666 117: "bad variable type"
6667 118: "bad namelist name"
6668 119: "variable not in namelist"
6669 120: "no end record"
6670 121: "variable count incorrect"
6671 122: "subscript for scalar variable"
6672 123: "invalid array section"
6673 124: "substring out of bounds"
6674 125: "subscript out of bounds"
6675 126: "can't read file"
6676 127: "can't write file"
6677 128: "'new' file exists"
6678 129: "can't append to file"
6679 130: "non-positive record number"
6680 131: "I/O started while already doing I/O"
6681 @end smallexample
6682
6683 @node Collected Fortran Wisdom
6684 @chapter Collected Fortran Wisdom
6685 @cindex wisdom
6686 @cindex legacy code
6687 @cindex code, legacy
6688 @cindex writing code
6689 @cindex code, writing
6690
6691 Most users of @command{g77} can be divided into two camps:
6692
6693 @itemize @bullet
6694 @item
6695 Those writing new Fortran code to be compiled by @command{g77}.
6696
6697 @item
6698 Those using @command{g77} to compile existing, ``legacy'' code.
6699 @end itemize
6700
6701 Users writing new code generally understand most of the necessary
6702 aspects of Fortran to write ``mainstream'' code, but often need
6703 help deciding how to handle problems, such as the construction
6704 of libraries containing @code{BLOCK DATA}.
6705
6706 Users dealing with ``legacy'' code sometimes don't have much
6707 experience with Fortran, but believe that the code they're compiling
6708 already works when compiled by other compilers (and might
6709 not understand why, as is sometimes the case, it doesn't work
6710 when compiled by @command{g77}).
6711
6712 The following information is designed to help users do a better job
6713 coping with existing, ``legacy'' Fortran code, and with writing
6714 new code as well.
6715
6716 @menu
6717 * Advantages Over f2c::        If @command{f2c} is so great, why @command{g77}?
6718 * Block Data and Libraries::   How @command{g77} solves a common problem.
6719 * Loops::                      Fortran @code{DO} loops surprise many people.
6720 * Working Programs::           Getting programs to work should be done first.
6721 * Overly Convenient Options::  Temptations to avoid, habits to not form.
6722 * Faster Programs::            Everybody wants these, but at what cost?
6723 @end menu
6724
6725 @node Advantages Over f2c
6726 @section Advantages Over f2c
6727
6728 Without @command{f2c}, @command{g77} would have taken much longer to
6729 do and probably not been as good for quite a while.
6730 Sometimes people who notice how much @command{g77} depends on, and
6731 documents encouragement to use, @command{f2c} ask why @command{g77}
6732 was created if @command{f2c} already existed.
6733
6734 This section gives some basic answers to these questions, though it
6735 is not intended to be comprehensive.
6736
6737 @menu
6738 * Language Extensions::  Features used by Fortran code.
6739 * Diagnostic Abilities:: Abilities to spot problems early.
6740 * Compiler Options::     Features helpful to accommodate legacy code, etc.
6741 * Compiler Speed::       Speed of the compilation process.
6742 * Program Speed::        Speed of the generated, optimized code.
6743 * Ease of Debugging::    Debugging ease-of-use at the source level.
6744 * Character and Hollerith Constants::  A byte saved is a byte earned.
6745 @end menu
6746
6747 @node Language Extensions
6748 @subsection Language Extensions
6749
6750 @command{g77} offers several extensions to FORTRAN 77 language that @command{f2c}
6751 doesn't:
6752
6753 @itemize @bullet
6754 @item
6755 Automatic arrays
6756
6757 @item
6758 @code{CYCLE} and @code{EXIT}
6759
6760 @item
6761 Construct names
6762
6763 @item
6764 @code{SELECT CASE}
6765
6766 @item
6767 @code{KIND=} and @code{LEN=} notation
6768
6769 @item
6770 Semicolon as statement separator
6771
6772 @item
6773 Constant expressions in @code{FORMAT} statements
6774 (such as @samp{FORMAT(I<J>)},
6775 where @samp{J} is a @code{PARAMETER} named constant)
6776
6777 @item
6778 @code{MvBits} intrinsic
6779
6780 @item
6781 @code{libU77} (Unix-compatibility) library,
6782 with routines known to compiler as intrinsics
6783 (so they work even when compiler options are used
6784 to change the interfaces used by Fortran routines)
6785 @end itemize
6786
6787 @command{g77} also implements iterative @code{DO} loops
6788 so that they work even in the presence of certain ``extreme'' inputs,
6789 unlike @command{f2c}.
6790 @xref{Loops}.
6791
6792 However, @command{f2c} offers a few that @command{g77} doesn't, such as:
6793
6794 @itemize @bullet
6795 @item
6796 Intrinsics in @code{PARAMETER} statements
6797
6798 @item
6799 Array bounds expressions (such as @samp{REAL M(N(2))})
6800
6801 @item
6802 @code{AUTOMATIC} statement
6803 @end itemize
6804
6805 It is expected that @command{g77} will offer some or all of these missing
6806 features at some time in the future.
6807
6808 @node Diagnostic Abilities
6809 @subsection Diagnostic Abilities
6810
6811 @command{g77} offers better diagnosis of problems in @code{FORMAT} statements.
6812 @command{f2c} doesn't, for example, emit any diagnostic for
6813 @samp{FORMAT(XZFAJG10324)},
6814 leaving that to be diagnosed, at run time, by
6815 the @code{libf2c} run-time library.
6816
6817 @node Compiler Options
6818 @subsection Compiler Options
6819
6820 @command{g77} offers compiler options that @command{f2c} doesn't,
6821 most of which are designed to more easily accommodate
6822 legacy code:
6823
6824 @itemize @bullet
6825 @item
6826 Two that control the automatic appending of extra
6827 underscores to external names
6828
6829 @item
6830 One that allows dollar signs (@samp{$}) in symbol names
6831
6832 @item
6833 A variety that control acceptance of various
6834 ``ugly'' constructs
6835
6836 @item
6837 Several that specify acceptable use of upper and lower case
6838 in the source code
6839
6840 @item
6841 Many that enable, disable, delete, or hide
6842 groups of intrinsics
6843
6844 @item
6845 One to specify the length of fixed-form source lines
6846 (normally 72)
6847
6848 @item
6849 One to specify the the source code is written in
6850 Fortran-90-style free-form
6851 @end itemize
6852
6853 However, @command{f2c} offers a few that @command{g77} doesn't,
6854 like an option to have @code{REAL} default to @code{REAL*8}.
6855 It is expected that @command{g77} will offer all of the
6856 missing options pertinent to being a Fortran compiler
6857 at some time in the future.
6858
6859 @node Compiler Speed
6860 @subsection Compiler Speed
6861
6862 Saving the steps of writing and then rereading C code is a big reason
6863 why @command{g77} should be able to compile code much faster than using
6864 @command{f2c} in conjunction with the equivalent invocation of @command{gcc}.
6865
6866 However, due to @command{g77}'s youth, lots of self-checking is still being
6867 performed.
6868 As a result, this improvement is as yet unrealized
6869 (though the potential seems to be there for quite a big speedup
6870 in the future).
6871 It is possible that, as of version 0.5.18, @command{g77}
6872 is noticeably faster compiling many Fortran source files than using
6873 @command{f2c} in conjunction with @command{gcc}.
6874
6875 @node Program Speed
6876 @subsection Program Speed
6877
6878 @command{g77} has the potential to better optimize code than @command{f2c},
6879 even when @command{gcc} is used to compile the output of @command{f2c},
6880 because @command{f2c} must necessarily
6881 translate Fortran into a somewhat lower-level language (C) that cannot
6882 preserve all the information that is potentially useful for optimization,
6883 while @command{g77} can gather, preserve, and transmit that information directly
6884 to the GBE.
6885
6886 For example, @command{g77} implements @code{ASSIGN} and assigned
6887 @code{GOTO} using direct assignment of pointers to labels and direct
6888 jumps to labels, whereas @command{f2c} maps the assigned labels to
6889 integer values and then uses a C @code{switch} statement to encode
6890 the assigned @code{GOTO} statements.
6891
6892 However, as is typical, theory and reality don't quite match, at least
6893 not in all cases, so it is still the case that @command{f2c} plus @command{gcc}
6894 can generate code that is faster than @command{g77}.
6895
6896 Version 0.5.18 of @command{g77} offered default
6897 settings and options, via patches to the @command{gcc}
6898 back end, that allow for better program speed, though
6899 some of these improvements also affected the performance
6900 of programs translated by @command{f2c} and then compiled
6901 by @command{g77}'s version of @command{gcc}.
6902
6903 Version 0.5.20 of @command{g77} offers further performance
6904 improvements, at least one of which (alias analysis) is
6905 not generally applicable to @command{f2c} (though @command{f2c}
6906 could presumably be changed to also take advantage of
6907 this new capability of the @command{gcc} back end, assuming
6908 this is made available in an upcoming release of @command{gcc}).
6909
6910 @node Ease of Debugging
6911 @subsection Ease of Debugging
6912
6913 Because @command{g77} compiles directly to assembler code like @command{gcc},
6914 instead of translating to an intermediate language (C) as does @command{f2c},
6915 support for debugging can be better for @command{g77} than @command{f2c}.
6916
6917 However, although @command{g77} might be somewhat more ``native'' in terms of
6918 debugging support than @command{f2c} plus @command{gcc}, there still are a lot
6919 of things ``not quite right''.
6920 Many of the important ones should be resolved in the near future.
6921
6922 For example, @command{g77} doesn't have to worry about reserved names
6923 like @command{f2c} does.
6924 Given @samp{FOR = WHILE}, @command{f2c} must necessarily
6925 translate this to something @emph{other} than
6926 @samp{for = while;}, because C reserves those words.
6927
6928 However, @command{g77} does still uses things like an extra level of indirection
6929 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
6930 yet support multiple entry points.
6931
6932 Another example is that, given
6933
6934 @smallexample
6935 COMMON A, B
6936 EQUIVALENCE (B, C)
6937 @end smallexample
6938
6939 @noindent
6940 the @command{g77} user should be able to access the variables directly, by name,
6941 without having to traverse C-like structures and unions, while @command{f2c}
6942 is unlikely to ever offer this ability (due to limitations in the
6943 C language).
6944
6945 However, due to apparent bugs in the back end, @command{g77} currently doesn't
6946 take advantage of this facility at all---it doesn't emit any debugging
6947 information for @code{COMMON} and @code{EQUIVALENCE} areas,
6948 other than information
6949 on the array of @code{char} it creates (and, in the case
6950 of local @code{EQUIVALENCE}, names) for each such area.
6951
6952 Yet another example is arrays.
6953 @command{g77} represents them to the debugger
6954 using the same ``dimensionality'' as in the source code, while @command{f2c}
6955 must necessarily convert them all to one-dimensional arrays to fit
6956 into the confines of the C language.
6957 However, the level of support
6958 offered by debuggers for interactive Fortran-style access to arrays
6959 as compiled by @command{g77} can vary widely.
6960 In some cases, it can actually
6961 be an advantage that @command{f2c} converts everything to widely supported
6962 C semantics.
6963
6964 In fairness, @command{g77} could do many of the things @command{f2c} does
6965 to get things working at least as well as @command{f2c}---for now,
6966 the developers prefer making @command{g77} work the
6967 way they think it is supposed to, and finding help improving the
6968 other products (the back end of @command{gcc}; @command{gdb}; and so on)
6969 to get things working properly.
6970
6971 @node Character and Hollerith Constants
6972 @subsection Character and Hollerith Constants
6973 @cindex character constants
6974 @cindex constants, character
6975 @cindex Hollerith constants
6976 @cindex constants, Hollerith
6977 @cindex trailing null byte
6978 @cindex null byte, trailing
6979 @cindex zero byte, trailing
6980
6981 To avoid the extensive hassle that would be needed to avoid this,
6982 @command{f2c} uses C character constants to encode character and Hollerith
6983 constants.
6984 That means a constant like @samp{'HELLO'} is translated to
6985 @samp{"hello"} in C, which further means that an extra null byte is
6986 present at the end of the constant.
6987 This null byte is superfluous.
6988
6989 @command{g77} does not generate such null bytes.
6990 This represents significant
6991 savings of resources, such as on systems where @file{/dev/null} or
6992 @file{/dev/zero} represent bottlenecks in the systems' performance,
6993 because @command{g77} simply asks for fewer zeros from the operating
6994 system than @command{f2c}.
6995 (Avoiding spurious use of zero bytes, each byte typically have
6996 eight zero bits, also reduces the liabilities in case
6997 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
6998
6999 @node Block Data and Libraries
7000 @section Block Data and Libraries
7001 @cindex block data and libraries
7002 @cindex BLOCK DATA statement
7003 @cindex statements, BLOCK DATA
7004 @cindex libraries, containing BLOCK DATA
7005 @cindex f2c compatibility
7006 @cindex compatibility, f2c
7007
7008 To ensure that block data program units are linked, especially a concern
7009 when they are put into libraries, give each one a name (as in
7010 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
7011 statement in every program unit that uses any common block
7012 initialized by the corresponding @code{BLOCK DATA}.
7013 @command{g77} currently compiles a @code{BLOCK DATA} as if it were a
7014 @code{SUBROUTINE},
7015 that is, it generates an actual procedure having the appropriate name.
7016 The procedure does nothing but return immediately if it happens to be
7017 called.
7018 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
7019 same program unit, @command{g77} assumes there exists a @samp{BLOCK DATA FOO}
7020 in the program and ensures that by generating a
7021 reference to it so the linker will make sure it is present.
7022 (Specifically, @command{g77} outputs in the data section a static pointer to the
7023 external name @samp{FOO}.)
7024
7025 The implementation @command{g77} currently uses to make this work is
7026 one of the few things not compatible with @command{f2c} as currently
7027 shipped.
7028 @command{f2c} currently does nothing with @samp{EXTERNAL FOO} except
7029 issue a warning that @samp{FOO} is not otherwise referenced,
7030 and, for @samp{BLOCK DATA FOO},
7031 @command{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
7032 The upshot is that you shouldn't mix @command{f2c} and @command{g77} in
7033 this particular case.
7034 If you use @command{f2c} to compile @samp{BLOCK DATA FOO},
7035 then any @command{g77}-compiled program unit that says @samp{EXTERNAL FOO}
7036 will result in an unresolved reference when linked.
7037 If you do the
7038 opposite, then @samp{FOO} might not be linked in under various
7039 circumstances (such as when @samp{FOO} is in a library, or you're
7040 using a ``clever'' linker---so clever, it produces a broken program
7041 with little or no warning by omitting initializations of global data
7042 because they are contained in unreferenced procedures).
7043
7044 The changes you make to your code to make @command{g77} handle this situation,
7045 however, appear to be a widely portable way to handle it.
7046 That is, many systems permit it (as they should, since the
7047 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
7048 is a block data program unit), and of the ones
7049 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
7050 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
7051 program units.
7052
7053 Here is the recommended approach to modifying a program containing
7054 a program unit such as the following:
7055
7056 @smallexample
7057 BLOCK DATA FOO
7058 COMMON /VARS/ X, Y, Z
7059 DATA X, Y, Z / 3., 4., 5. /
7060 END
7061 @end smallexample
7062
7063 @noindent
7064 If the above program unit might be placed in a library module, then
7065 ensure that every program unit in every program that references that
7066 particular @code{COMMON} area uses the @code{EXTERNAL} statement
7067 to force the area to be initialized.
7068
7069 For example, change a program unit that starts with
7070
7071 @smallexample
7072 INTEGER FUNCTION CURX()
7073 COMMON /VARS/ X, Y, Z
7074 CURX = X
7075 END
7076 @end smallexample
7077
7078 @noindent
7079 so that it uses the @code{EXTERNAL} statement, as in:
7080
7081 @smallexample
7082 INTEGER FUNCTION CURX()
7083 COMMON /VARS/ X, Y, Z
7084 EXTERNAL FOO
7085 CURX = X
7086 END
7087 @end smallexample
7088
7089 @noindent
7090 That way, @samp{CURX} is compiled by @command{g77} (and many other
7091 compilers) so that the linker knows it must include @samp{FOO},
7092 the @code{BLOCK DATA} program unit that sets the initial values
7093 for the variables in @samp{VAR}, in the executable program.
7094
7095 @node Loops
7096 @section Loops
7097 @cindex DO statement
7098 @cindex statements, DO
7099 @cindex trips, number of
7100 @cindex number of trips
7101
7102 The meaning of a @code{DO} loop in Fortran is precisely specified
7103 in the Fortran standard@dots{}and is quite different from what
7104 many programmers might expect.
7105
7106 In particular, Fortran iterative @code{DO} loops are implemented as if
7107 the number of trips through the loop is calculated @emph{before}
7108 the loop is entered.
7109
7110 The number of trips for a loop is calculated from the @var{start},
7111 @var{end}, and @var{increment} values specified in a statement such as:
7112
7113 @smallexample
7114 DO @var{iter} = @var{start}, @var{end}, @var{increment}
7115 @end smallexample
7116
7117 @noindent
7118 The trip count is evaluated using a fairly simple formula
7119 based on the three values following the @samp{=} in the
7120 statement, and it is that trip count that is effectively
7121 decremented during each iteration of the loop.
7122 If, at the beginning of an iteration of the loop, the
7123 trip count is zero or negative, the loop terminates.
7124 The per-loop-iteration modifications to @var{iter} are not
7125 related to determining whether to terminate the loop.
7126
7127 There are two important things to remember about the trip
7128 count:
7129
7130 @itemize @bullet
7131 @item
7132 It can be @emph{negative}, in which case it is
7133 treated as if it was zero---meaning the loop is
7134 not executed at all.
7135
7136 @item
7137 The type used to @emph{calculate} the trip count
7138 is the same type as @var{iter}, but the final
7139 calculation, and thus the type of the trip
7140 count itself, always is @code{INTEGER(KIND=1)}.
7141 @end itemize
7142
7143 These two items mean that there are loops that cannot
7144 be written in straightforward fashion using the Fortran @code{DO}.
7145
7146 For example, on a system with the canonical 32-bit two's-complement
7147 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
7148
7149 @smallexample
7150 DO I = -2000000000, 2000000000
7151 @end smallexample
7152
7153 @noindent
7154 Although the @var{start} and @var{end} values are well within
7155 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
7156 The expected trip count is 40000000001, which is outside
7157 the range of @code{INTEGER(KIND=1)} on many systems.
7158
7159 Instead, the above loop should be constructed this way:
7160
7161 @smallexample
7162 I = -2000000000
7163 DO
7164   IF (I .GT. 2000000000) EXIT
7165   @dots{}
7166   I = I + 1
7167 END DO
7168 @end smallexample
7169
7170 @noindent
7171 The simple @code{DO} construct and the @code{EXIT} statement
7172 (used to leave the innermost loop)
7173 are F90 features that @command{g77} supports.
7174
7175 Some Fortran compilers have buggy implementations of @code{DO},
7176 in that they don't follow the standard.
7177 They implement @code{DO} as a straightforward translation
7178 to what, in C, would be a @code{for} statement.
7179 Instead of creating a temporary variable to hold the trip count
7180 as calculated at run time, these compilers
7181 use the iteration variable @var{iter} to control
7182 whether the loop continues at each iteration.
7183
7184 The bug in such an implementation shows up when the
7185 trip count is within the range of the type of @var{iter},
7186 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
7187 exceeds that range.  For example:
7188
7189 @smallexample
7190 DO I = 2147483600, 2147483647
7191 @end smallexample
7192
7193 @noindent
7194 A loop started by the above statement will work as implemented
7195 by @command{g77}, but the use, by some compilers, of a
7196 more C-like implementation akin to
7197
7198 @smallexample
7199 for (i = 2147483600; i <= 2147483647; ++i)
7200 @end smallexample
7201
7202 @noindent
7203 produces a loop that does not terminate, because @samp{i}
7204 can never be greater than 2147483647, since incrementing it
7205 beyond that value overflows @samp{i}, setting it to -2147483648.
7206 This is a large, negative number that still is less than 2147483647.
7207
7208 Another example of unexpected behavior of @code{DO} involves
7209 using a nonintegral iteration variable @var{iter}, that is,
7210 a @code{REAL} variable.
7211 Consider the following program:
7212
7213 @smallexample
7214       DATA BEGIN, END, STEP /.1, .31, .007/
7215       DO 10 R = BEGIN, END, STEP
7216          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
7217          PRINT *,R
7218 10    CONTINUE
7219       PRINT *,'LAST = ',R
7220       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
7221       END
7222 @end smallexample
7223
7224 @noindent
7225 A C-like view of @code{DO} would hold that the two ``exclamatory''
7226 @code{PRINT} statements are never executed.
7227 However, this is the output of running the above program
7228 as compiled by @command{g77} on a GNU/Linux ix86 system:
7229
7230 @smallexample
7231  .100000001
7232  .107000001
7233  .114
7234  .120999999
7235  @dots{}
7236  .289000005
7237  .296000004
7238  .303000003
7239 LAST =   .310000002
7240  .310000002 .LE.   .310000002!!
7241 @end smallexample
7242
7243 Note that one of the two checks in the program turned up
7244 an apparent violation of the programmer's expectation---yet,
7245 the loop is correctly implemented by @command{g77}, in that
7246 it has 30 iterations.
7247 This trip count of 30 is correct when evaluated using
7248 the floating-point representations for the @var{begin},
7249 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
7250 ix86 are used.
7251 On other systems, an apparently more accurate trip count
7252 of 31 might result, but, nevertheless, @command{g77} is
7253 faithfully following the Fortran standard, and the result
7254 is not what the author of the sample program above
7255 apparently expected.
7256 (Such other systems might, for different values in the @code{DATA}
7257 statement, violate the other programmer's expectation,
7258 for example.)
7259
7260 Due to this combination of imprecise representation
7261 of floating-point values and the often-misunderstood
7262 interpretation of @code{DO} by standard-conforming
7263 compilers such as @command{g77}, use of @code{DO} loops
7264 with @code{REAL} iteration
7265 variables is not recommended.
7266 Such use can be caught by specifying @option{-Wsurprising}.
7267 @xref{Warning Options}, for more information on this
7268 option.
7269
7270 @node Working Programs
7271 @section Working Programs
7272
7273 Getting Fortran programs to work in the first place can be
7274 quite a challenge---even when the programs already work on
7275 other systems, or when using other compilers.
7276
7277 @command{g77} offers some facilities that might be useful for
7278 tracking down bugs in such programs.
7279
7280 @menu
7281 * Not My Type::
7282 * Variables Assumed To Be Zero::
7283 * Variables Assumed To Be Saved::
7284 * Unwanted Variables::
7285 * Unused Arguments::
7286 * Surprising Interpretations of Code::
7287 * Aliasing Assumed To Work::
7288 * Output Assumed To Flush::
7289 * Large File Unit Numbers::
7290 * Floating-point precision::
7291 * Inconsistent Calling Sequences::
7292 @end menu
7293
7294 @node Not My Type
7295 @subsection Not My Type
7296 @cindex mistyped variables
7297 @cindex variables, mistyped
7298 @cindex mistyped functions
7299 @cindex functions, mistyped
7300 @cindex implicit typing
7301
7302 A fruitful source of bugs in Fortran source code is use, or
7303 mis-use, of Fortran's implicit-typing feature, whereby the
7304 type of a variable, array, or function is determined by the
7305 first character of its name.
7306
7307 Simple cases of this include statements like @samp{LOGX=9.227},
7308 without a statement such as @samp{REAL LOGX}.
7309 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
7310 type, with the result of the assignment being that it is given
7311 the value @samp{9}.
7312
7313 More involved cases include a function that is defined starting
7314 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
7315 Any caller of this function that does not also declare @samp{IPS}
7316 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
7317 is likely to assume it returns
7318 @code{INTEGER}, or some other type, leading to invalid results
7319 or even program crashes.
7320
7321 The @option{-Wimplicit} option might catch failures to
7322 properly specify the types of
7323 variables, arrays, and functions in the code.
7324
7325 However, in code that makes heavy use of Fortran's
7326 implicit-typing facility, this option might produce so
7327 many warnings about cases that are working, it would be
7328 hard to find the one or two that represent bugs.
7329 This is why so many experienced Fortran programmers strongly
7330 recommend widespread use of the @code{IMPLICIT NONE} statement,
7331 despite it not being standard FORTRAN 77, to completely turn
7332 off implicit typing.
7333 (@command{g77} supports @code{IMPLICIT NONE}, as do almost all
7334 FORTRAN 77 compilers.)
7335
7336 Note that @option{-Wimplicit} catches only implicit typing of
7337 @emph{names}.
7338 It does not catch implicit typing of expressions such
7339 as @samp{X**(2/3)}.
7340 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
7341 is equivalent to @samp{X**0}, due to the way Fortran expressions
7342 are given types and then evaluated.
7343 (In this particular case, the programmer probably wanted
7344 @samp{X**(2./3.)}.)
7345
7346 @node Variables Assumed To Be Zero
7347 @subsection Variables Assumed To Be Zero
7348 @cindex zero-initialized variables
7349 @cindex variables, assumed to be zero
7350 @cindex uninitialized variables
7351
7352 Many Fortran programs were developed on systems that provided
7353 automatic initialization of all, or some, variables and arrays
7354 to zero.
7355 As a result, many of these programs depend, sometimes
7356 inadvertently, on this behavior, though to do so violates
7357 the Fortran standards.
7358
7359 You can ask @command{g77} for this behavior by specifying the
7360 @option{-finit-local-zero} option when compiling Fortran code.
7361 (You might want to specify @option{-fno-automatic} as well,
7362 to avoid code-size inflation for non-optimized compilations.)
7363
7364 Note that a program that works better when compiled with the
7365 @option{-finit-local-zero} option
7366 is almost certainly depending on a particular system's,
7367 or compiler's, tendency to initialize some variables to zero.
7368 It might be worthwhile finding such cases and fixing them,
7369 using techniques such as compiling with the @option{-O -Wuninitialized}
7370 options using @command{g77}.
7371
7372 @node Variables Assumed To Be Saved
7373 @subsection Variables Assumed To Be Saved
7374 @cindex variables, retaining values across calls
7375 @cindex saved variables
7376 @cindex static variables
7377
7378 Many Fortran programs were developed on systems that
7379 saved the values of all, or some, variables and arrays
7380 across procedure calls.
7381 As a result, many of these programs depend, sometimes
7382 inadvertently, on being able to assign a value to a
7383 variable, perform a @code{RETURN} to a calling procedure,
7384 and, upon subsequent invocation, reference the previously
7385 assigned variable to obtain the value.
7386
7387 They expect this despite not using the @code{SAVE} statement
7388 to specify that the value in a variable is expected to survive
7389 procedure returns and calls.
7390 Depending on variables and arrays to retain values across
7391 procedure calls without using @code{SAVE} to require it violates
7392 the Fortran standards.
7393
7394 You can ask @command{g77} to assume @code{SAVE} is specified for all
7395 relevant (local) variables and arrays by using the
7396 @option{-fno-automatic} option.
7397
7398 Note that a program that works better when compiled with the
7399 @option{-fno-automatic} option
7400 is almost certainly depending on not having to use
7401 the @code{SAVE} statement as required by the Fortran standard.
7402 It might be worthwhile finding such cases and fixing them,
7403 using techniques such as compiling with the @samp{-O -Wuninitialized}
7404 options using @command{g77}.
7405
7406 @node Unwanted Variables
7407 @subsection Unwanted Variables
7408
7409 The @option{-Wunused} option can find bugs involving
7410 implicit typing, sometimes
7411 more easily than using @option{-Wimplicit} in code that makes
7412 heavy use of implicit typing.
7413 An unused variable or array might indicate that the
7414 spelling for its declaration is different from that of
7415 its intended uses.
7416
7417 Other than cases involving typos, unused variables rarely
7418 indicate actual bugs in a program.
7419 However, investigating such cases thoroughly has, on occasion,
7420 led to the discovery of code that had not been completely
7421 written---where the programmer wrote declarations as needed
7422 for the whole algorithm, wrote some or even most of the code
7423 for that algorithm, then got distracted and forgot that the
7424 job was not complete.
7425
7426 @node Unused Arguments
7427 @subsection Unused Arguments
7428 @cindex unused arguments
7429 @cindex arguments, unused
7430
7431 As with unused variables, It is possible that unused arguments
7432 to a procedure might indicate a bug.
7433 Compile with @samp{-W -Wunused} option to catch cases of
7434 unused arguments.
7435
7436 Note that @option{-W} also enables warnings regarding overflow
7437 of floating-point constants under certain circumstances.
7438
7439 @node Surprising Interpretations of Code
7440 @subsection Surprising Interpretations of Code
7441
7442 The @option{-Wsurprising} option can help find bugs involving
7443 expression evaluation or in
7444 the way @code{DO} loops with non-integral iteration variables
7445 are handled.
7446 Cases found by this option might indicate a difference of
7447 interpretation between the author of the code involved, and
7448 a standard-conforming compiler such as @command{g77}.
7449 Such a difference might produce actual bugs.
7450
7451 In any case, changing the code to explicitly do what the
7452 programmer might have expected it to do, so @command{g77} and
7453 other compilers are more likely to follow the programmer's
7454 expectations, might be worthwhile, especially if such changes
7455 make the program work better.
7456
7457 @node Aliasing Assumed To Work
7458 @subsection Aliasing Assumed To Work
7459 @cindex -falias-check option
7460 @cindex options, -falias-check
7461 @cindex -fargument-alias option
7462 @cindex options, -fargument-alias
7463 @cindex -fargument-noalias option
7464 @cindex options, -fargument-noalias
7465 @cindex -fno-argument-noalias-global option
7466 @cindex options, -fno-argument-noalias-global
7467 @cindex aliasing
7468 @cindex anti-aliasing
7469 @cindex overlapping arguments
7470 @cindex overlays
7471 @cindex association, storage
7472 @cindex storage association
7473 @cindex scheduling of reads and writes
7474 @cindex reads and writes, scheduling
7475
7476 The @option{-falias-check}, @option{-fargument-alias},
7477 @option{-fargument-noalias},
7478 and @option{-fno-argument-noalias-global} options,
7479 introduced in version 0.5.20 and
7480 @command{g77}'s version 2.7.2.2.f.2 of @command{gcc},
7481 were withdrawn as of @command{g77} version 0.5.23
7482 due to their not being supported by @command{gcc} version 2.8.
7483
7484 These options control the assumptions regarding aliasing
7485 (overlapping) of writes and reads to main memory (core) made
7486 by the @command{gcc} back end.
7487
7488 The information below still is useful, but applies to
7489 only those versions of @command{g77} that support the
7490 alias analysis implied by support for these options.
7491
7492 These options are effective only when compiling with @option{-O}
7493 (specifying any level other than @option{-O0})
7494 or with @option{-falias-check}.
7495
7496 The default for Fortran code is @option{-fargument-noalias-global}.
7497 (The default for C code and code written in other C-based languages
7498 is @option{-fargument-alias}.
7499 These defaults apply regardless of whether you use @command{g77} or
7500 @command{gcc} to compile your code.)
7501
7502 Note that, on some systems, compiling with @option{-fforce-addr} in
7503 effect can produce more optimal code when the default aliasing
7504 options are in effect (and when optimization is enabled).
7505
7506 If your program is not working when compiled with optimization,
7507 it is possible it is violating the Fortran standards (77 and 90)
7508 by relying on the ability to ``safely'' modify variables and
7509 arrays that are aliased, via procedure calls, to other variables
7510 and arrays, without using @code{EQUIVALENCE} to explicitly
7511 set up this kind of aliasing.
7512
7513 (The FORTRAN 77 standard's prohibition of this sort of
7514 overlap, generally referred to therein as ``storage
7515 assocation'', appears in Sections 15.9.3.6.
7516 This prohibition allows implementations, such as @command{g77},
7517 to, for example, implement the passing of procedures and
7518 even values in @code{COMMON} via copy operations into local,
7519 perhaps more efficiently accessed temporaries at entry to a
7520 procedure, and, where appropriate, via copy operations back
7521 out to their original locations in memory at exit from that
7522 procedure, without having to take into consideration the
7523 order in which the local copies are updated by the code,
7524 among other things.)
7525
7526 To test this hypothesis, try compiling your program with
7527 the @option{-fargument-alias} option, which causes the
7528 compiler to revert to assumptions essentially the same as
7529 made by versions of @command{g77} prior to 0.5.20.
7530
7531 If the program works using this option, that strongly suggests
7532 that the bug is in your program.
7533 Finding and fixing the bug(s) should result in a program that
7534 is more standard-conforming and that can be compiled by @command{g77}
7535 in a way that results in a faster executable.
7536
7537 (You might want to try compiling with @option{-fargument-noalias},
7538 a kind of half-way point, to see if the problem is limited to
7539 aliasing between dummy arguments and @code{COMMON} variables---this
7540 option assumes that such aliasing is not done, while still allowing
7541 aliasing among dummy arguments.)
7542
7543 An example of aliasing that is invalid according to the standards
7544 is shown in the following program, which might @emph{not} produce
7545 the expected results when executed:
7546
7547 @smallexample
7548 I = 1
7549 CALL FOO(I, I)
7550 PRINT *, I
7551 END
7552
7553 SUBROUTINE FOO(J, K)
7554 J = J + K
7555 K = J * K
7556 PRINT *, J, K
7557 END
7558 @end smallexample
7559
7560 The above program attempts to use the temporary aliasing of the
7561 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
7562 pathological behavior---the simultaneous changing of the values
7563 of @emph{both} @samp{J} and @samp{K} when either one of them
7564 is written.
7565
7566 The programmer likely expects the program to print these values:
7567
7568 @example
7569 2  4
7570 4
7571 @end example
7572
7573 However, since the program is not standard-conforming, an
7574 implementation's behavior when running it is undefined, because
7575 subroutine @samp{FOO} modifies at least one of the arguments,
7576 and they are aliased with each other.
7577 (Even if one of the assignment statements was deleted, the
7578 program would still violate these rules.
7579 This kind of on-the-fly aliasing is permitted by the standard
7580 only when none of the aliased items are defined, or written,
7581 while the aliasing is in effect.)
7582
7583 As a practical example, an optimizing compiler might schedule
7584 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
7585 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
7586 resulting in the following output:
7587
7588 @example
7589 2  2
7590 2
7591 @end example
7592
7593 Essentially, compilers are promised (by the standard and, therefore,
7594 by programmers who write code they claim to be standard-conforming)
7595 that if they cannot detect aliasing via static analysis of a single
7596 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
7597 such aliasing exists.
7598 In such cases, compilers are free to assume that an assignment to
7599 one variable will not change the value of another variable, allowing
7600 it to avoid generating code to re-read the value of the other
7601 variable, to re-schedule reads and writes, and so on, to produce
7602 a faster executable.
7603
7604 The same promise holds true for arrays (as seen by the called
7605 procedure)---an element of one dummy array cannot be aliased
7606 with, or overlap, any element of another dummy array or be
7607 in a @code{COMMON} area known to the procedure.
7608
7609 (These restrictions apply only when the procedure defines, or
7610 writes to, one of the aliased variables or arrays.)
7611
7612 Unfortunately, there is no way to find @emph{all} possible cases of
7613 violations of the prohibitions against aliasing in Fortran code.
7614 Static analysis is certainly imperfect, as is run-time analysis,
7615 since neither can catch all violations.
7616 (Static analysis can catch all likely violations, and some that
7617 might never actually happen, while run-time analysis can catch
7618 only those violations that actually happen during a particular run.
7619 Neither approach can cope with programs mixing Fortran code with
7620 routines written in other languages, however.)
7621
7622 Currently, @command{g77} provides neither static nor run-time facilities
7623 to detect any cases of this problem, although other products might.
7624 Run-time facilities are more likely to be offered by future
7625 versions of @command{g77}, though patches improving @command{g77} so that
7626 it provides either form of detection are welcome.
7627
7628 @node Output Assumed To Flush
7629 @subsection Output Assumed To Flush
7630 @cindex ALWAYS_FLUSH
7631 @cindex synchronous write errors
7632 @cindex disk full
7633 @cindex flushing output
7634 @cindex fflush()
7635 @cindex I/O, flushing
7636 @cindex output, flushing
7637 @cindex writes, flushing
7638 @cindex NFS
7639 @cindex network file system
7640
7641 For several versions prior to 0.5.20, @command{g77} configured its
7642 version of the @code{libf2c} run-time library so that one of
7643 its configuration macros, @code{ALWAYS_FLUSH}, was defined.
7644
7645 This was done as a result of a belief that many programs expected
7646 output to be flushed to the operating system (under UNIX, via
7647 the @code{fflush()} library call) with the result that errors,
7648 such as disk full, would be immediately flagged via the
7649 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
7650
7651 Because of the adverse effects this approach had on the performance
7652 of many programs, @command{g77} no longer configures @code{libf2c}
7653 (now named @code{libg2c} in its @command{g77} incarnation)
7654 to always flush output.
7655
7656 If your program depends on this behavior, either insert the
7657 appropriate @samp{CALL FLUSH} statements, or modify the sources
7658 to the @code{libg2c}, rebuild and reinstall @command{g77}, and
7659 relink your programs with the modified library.
7660
7661 (Ideally, @code{libg2c} would offer the choice at run-time, so
7662 that a compile-time option to @command{g77} or @command{f2c} could
7663 result in generating the appropriate calls to flushing or
7664 non-flushing library routines.)
7665
7666 Some Fortran programs require output
7667 (writes) to be flushed to the operating system (under UNIX,
7668 via the @code{fflush()} library call) so that errors,
7669 such as disk full, are immediately flagged via the relevant
7670 @code{ERR=} and @code{IOSTAT=} mechanism, instead of such
7671 errors being flagged later as subsequent writes occur, forcing
7672 the previously written data to disk, or when the file is
7673 closed.
7674
7675 Essentially, the difference can be viewed as synchronous error
7676 reporting (immediate flagging of errors during writes) versus
7677 asynchronous, or, more precisely, buffered error reporting
7678 (detection of errors might be delayed).
7679
7680 @code{libg2c} supports flagging write errors immediately when
7681 it is built with the @code{ALWAYS_FLUSH} macro defined.
7682 This results in a @code{libg2c} that runs slower, sometimes
7683 quite a bit slower, under certain circumstances---for example,
7684 accessing files via the networked file system NFS---but the
7685 effect can be more reliable, robust file I/O.
7686
7687 If you know that Fortran programs requiring this level of precision
7688 of error reporting are to be compiled using the
7689 version of @command{g77} you are building, you might wish to
7690 modify the @command{g77} source tree so that the version of
7691 @code{libg2c} is built with the @code{ALWAYS_FLUSH} macro
7692 defined, enabling this behavior.
7693
7694 To do this, find this line in @file{@value{path-libf2c}/f2c.h} in
7695 your @command{g77} source tree:
7696
7697 @example
7698 /* #define ALWAYS_FLUSH */
7699 @end example
7700
7701 Remove the leading @samp{/*@w{ }},
7702 so the line begins with @samp{#define},
7703 and the trailing @samp{@w{ }*/}.
7704
7705 Then build or rebuild @command{g77} as appropriate.
7706
7707 @node Large File Unit Numbers
7708 @subsection Large File Unit Numbers
7709 @cindex MXUNIT
7710 @cindex unit numbers
7711 @cindex maximum unit number
7712 @cindex illegal unit number
7713 @cindex increasing maximum unit number
7714
7715 If your program crashes at run time with a message including
7716 the text @samp{illegal unit number}, that probably is
7717 a message from the run-time library, @code{libg2c}.
7718
7719 The message means that your program has attempted to use a
7720 file unit number that is out of the range accepted by
7721 @code{libg2c}.
7722 Normally, this range is 0 through 99, and the high end
7723 of the range is controlled by a @code{libg2c} source-file
7724 macro named @code{MXUNIT}.
7725
7726 If you can easily change your program to use unit numbers
7727 in the range 0 through 99, you should do so.
7728
7729 As distributed, whether as part of @command{f2c} or @command{g77},
7730 @code{libf2c} accepts file unit numbers only in the range
7731 0 through 99.
7732 For example, a statement such as @samp{WRITE (UNIT=100)} causes
7733 a run-time crash in @code{libf2c}, because the unit number,
7734 100, is out of range.
7735
7736 If you know that Fortran programs at your installation require
7737 the use of unit numbers higher than 99, you can change the
7738 value of the @code{MXUNIT} macro, which represents the maximum unit
7739 number, to an appropriately higher value.
7740
7741 To do this, edit the file @file{@value{path-libf2c}/libI77/fio.h} in your
7742 @command{g77} source tree, changing the following line:
7743
7744 @example
7745 #define MXUNIT 100
7746 @end example
7747
7748 Change the line so that the value of @code{MXUNIT} is defined to be
7749 at least one @emph{greater} than the maximum unit number used by
7750 the Fortran programs on your system.
7751
7752 (For example, a program that does @samp{WRITE (UNIT=255)} would require
7753 @code{MXUNIT} set to at least 256 to avoid crashing.)
7754
7755 Then build or rebuild @command{g77} as appropriate.
7756
7757 @emph{Note:} Changing this macro has @emph{no} effect on other limits
7758 your system might place on the number of files open at the same time.
7759 That is, the macro might allow a program to do @samp{WRITE (UNIT=100)},
7760 but the library and operating system underlying @code{libf2c} might
7761 disallow it if many other files have already been opened (via @code{OPEN} or
7762 implicitly via @code{READ}, @code{WRITE}, and so on).
7763 Information on how to increase these other limits should be found
7764 in your system's documentation.
7765
7766 @node Floating-point precision
7767 @subsection Floating-point precision
7768
7769 @cindex IEEE 754 conformance
7770 @cindex conformance, IEEE 754
7771 @cindex floating-point, precision
7772 @cindex ix86 floating-point
7773 @cindex x86 floating-point
7774 If your program depends on exact IEEE 754 floating-point handling it may
7775 help on some systems---specifically x86 or m68k hardware---to use
7776 the @option{-ffloat-store} option or to reset the precision flag on the
7777 floating-point unit.
7778 @xref{Optimize Options}.
7779
7780 However, it might be better simply to put the FPU into double precision
7781 mode and not take the performance hit of @option{-ffloat-store}.  On x86
7782 and m68k GNU systems you can do this with a technique similar to that
7783 for turning on floating-point exceptions
7784 (@pxref{Floating-point Exception Handling}).
7785 The control word could be set to double precision by some code like this
7786 one:
7787 @smallexample
7788 #include <fpu_control.h>
7789 @{
7790   fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
7791   _FPU_SETCW(cw);
7792 @}
7793 @end smallexample
7794 (It is not clear whether this has any effect on the operation of the GNU
7795 maths library, but we have no evidence of it causing trouble.)
7796
7797 Some targets (such as the Alpha) may need special options for full IEEE
7798 conformance.
7799 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using
7800 the GNU Compiler Collection (GCC)}.
7801
7802 @node Inconsistent Calling Sequences
7803 @subsection Inconsistent Calling Sequences
7804
7805 @pindex ftnchek
7806 @cindex floating-point, errors
7807 @cindex ix86 FPU stack
7808 @cindex x86 FPU stack
7809 Code containing inconsistent calling sequences in the same file is
7810 normally rejected---see @ref{GLOBALS}.
7811 (Use, say, @command{ftnchek} to ensure
7812 consistency across source files.
7813 @xref{f2c Skeletons and Prototypes,,
7814 Generating Skeletons and Prototypes with @command{f2c}}.)
7815
7816 Mysterious errors, which may appear to be code generation problems, can
7817 appear specifically on the x86 architecture with some such
7818 inconsistencies.  On x86 hardware, floating-point return values of
7819 functions are placed on the floating-point unit's register stack, not
7820 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
7821 @code{FUNCTION} as some other sort of procedure, or vice versa,
7822 scrambles the floating-point stack.  This may break unrelated code
7823 executed later.  Similarly if, say, external C routines are written
7824 incorrectly.
7825
7826 @node Overly Convenient Options
7827 @section Overly Convenient Command-line Options
7828 @cindex overly convenient options
7829 @cindex options, overly convenient
7830
7831 These options should be used only as a quick-and-dirty way to determine
7832 how well your program will run under different compilation models
7833 without having to change the source.
7834 Some are more problematic
7835 than others, depending on how portable and maintainable you want the
7836 program to be (and, of course, whether you are allowed to change it
7837 at all is crucial).
7838
7839 You should not continue to use these command-line options to compile
7840 a given program, but rather should make changes to the source code:
7841
7842 @table @code
7843 @cindex -finit-local-zero option
7844 @cindex options, -finit-local-zero
7845 @item -finit-local-zero
7846 (This option specifies that any uninitialized local variables
7847 and arrays have default initialization to binary zeros.)
7848
7849 Many other compilers do this automatically, which means lots of
7850 Fortran code developed with those compilers depends on it.
7851
7852 It is safer (and probably
7853 would produce a faster program) to find the variables and arrays that
7854 need such initialization and provide it explicitly via @code{DATA}, so that
7855 @option{-finit-local-zero} is not needed.
7856
7857 Consider using @option{-Wuninitialized} (which requires @option{-O}) to
7858 find likely candidates, but
7859 do not specify @option{-finit-local-zero} or @option{-fno-automatic},
7860 or this technique won't work.
7861
7862 @cindex -fno-automatic option
7863 @cindex options, -fno-automatic
7864 @item -fno-automatic
7865 (This option specifies that all local variables and arrays
7866 are to be treated as if they were named in @code{SAVE} statements.)
7867
7868 Many other compilers do this automatically, which means lots of
7869 Fortran code developed with those compilers depends on it.
7870
7871 The effect of this is that all non-automatic variables and arrays
7872 are made static, that is, not placed on the stack or in heap storage.
7873 This might cause a buggy program to appear to work better.
7874 If so, rather than relying on this command-line option (and hoping all
7875 compilers provide the equivalent one), add @code{SAVE}
7876 statements to some or all program unit sources, as appropriate.
7877 Consider using @option{-Wuninitialized} (which requires @option{-O})
7878 to find likely candidates, but
7879 do not specify @option{-finit-local-zero} or @option{-fno-automatic},
7880 or this technique won't work.
7881
7882 The default is @option{-fautomatic}, which tells @command{g77} to try
7883 and put variables and arrays on the stack (or in fast registers)
7884 where possible and reasonable.
7885 This tends to make programs faster.
7886
7887 @cindex automatic arrays
7888 @cindex arrays, automatic
7889 @emph{Note:} Automatic variables and arrays are not affected
7890 by this option.
7891 These are variables and arrays that are @emph{necessarily} automatic,
7892 either due to explicit statements, or due to the way they are
7893 declared.
7894 Examples include local variables and arrays not given the
7895 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
7896 and local arrays declared with non-constant bounds (automatic
7897 arrays).
7898 Currently, @command{g77} supports only automatic arrays, not
7899 @code{RECURSIVE} procedures or other means of explicitly
7900 specifying that variables or arrays are automatic.
7901
7902 @cindex -f@var{group}-intrinsics-hide option
7903 @cindex options, -f@var{group}-intrinsics-hide
7904 @item -f@var{group}-intrinsics-hide
7905 Change the source code to use @code{EXTERNAL} for any external procedure
7906 that might be the name of an intrinsic.
7907 It is easy to find these using @option{-f@var{group}-intrinsics-disable}.
7908 @end table
7909
7910 @node Faster Programs
7911 @section Faster Programs
7912 @cindex speed, of programs
7913 @cindex programs, speeding up
7914
7915 Aside from the usual @command{gcc} options, such as @option{-O},
7916 @option{-ffast-math}, and so on, consider trying some of the
7917 following approaches to speed up your program (once you get
7918 it working).
7919
7920 @menu
7921 * Aligned Data::
7922 * Prefer Automatic Uninitialized Variables::
7923 * Avoid f2c Compatibility::
7924 * Use Submodel Options::
7925 @end menu
7926
7927 @node Aligned Data
7928 @subsection Aligned Data
7929 @cindex alignment
7930 @cindex data, aligned
7931 @cindex stack, aligned
7932 @cindex aligned data
7933 @cindex aligned stack
7934 @cindex Pentium optimizations
7935 @cindex optimization, for Pentium
7936
7937 On some systems, such as those with Pentium Pro CPUs, programs
7938 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
7939 might run much slower
7940 than possible due to the compiler not aligning these 64-bit
7941 values to 64-bit boundaries in memory.
7942 (The effect also is present, though
7943 to a lesser extent, on the 586 (Pentium) architecture.)
7944
7945 The Intel x86 architecture generally ensures that these programs will
7946 work on all its implementations,
7947 but particular implementations (such as Pentium Pro)
7948 perform better with more strict alignment.
7949 (Such behavior isn't unique to the Intel x86 architecture.)
7950 Other architectures might @emph{demand} 64-bit alignment
7951 of 64-bit data.
7952
7953 There are a variety of approaches to use to address this problem:
7954
7955 @itemize @bullet
7956 @item
7957 @cindex @code{COMMON} layout
7958 @cindex layout of @code{COMMON} blocks
7959 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
7960 that the variables and arrays with the widest alignment
7961 guidelines come first.
7962
7963 For example, on most systems, this would mean placing
7964 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
7965 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
7966 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
7967 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
7968 and @code{INTEGER(KIND=3)} entities.
7969
7970 The reason to use such placement is it makes it more likely
7971 that your data will be aligned properly, without requiring
7972 you to do detailed analysis of each aggregate (@code{COMMON}
7973 and @code{EQUIVALENCE}) area.
7974
7975 Specifically, on systems where the above guidelines are
7976 appropriate, placing @code{CHARACTER} entities before
7977 @code{REAL(KIND=2)} entities can work just as well,
7978 but only if the number of bytes occupied by the @code{CHARACTER}
7979 entities is divisible by the recommended alignment for
7980 @code{REAL(KIND=2)}.
7981
7982 By ordering the placement of entities in aggregate
7983 areas according to the simple guidelines above, you
7984 avoid having to carefully count the number of bytes
7985 occupied by each entity to determine whether the
7986 actual alignment of each subsequent entity meets the
7987 alignment guidelines for the type of that entity.
7988
7989 If you don't ensure correct alignment of @code{COMMON} elements, the
7990 compiler may be forced by some systems to violate the Fortran semantics by
7991 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
7992 If the unfortunate practice is employed of overlaying different types of
7993 data in the @code{COMMON} block, the different variants
7994 of this block may become misaligned with respect to each other.
7995 Even if your platform doesn't require strict alignment,
7996 @code{COMMON} should be laid out as above for portability.
7997 (Unfortunately the FORTRAN 77 standard didn't anticipate this
7998 possible requirement, which is compiler-independent on a given platform.)
7999
8000 @item
8001 @cindex -malign-double option
8002 @cindex options, -malign-double
8003 Use the (x86-specific) @option{-malign-double} option when compiling
8004 programs for the Pentium and Pentium Pro architectures (called 586
8005 and 686 in the @command{gcc} configuration subsystem).
8006 The warning about this in the @command{gcc} manual isn't
8007 generally relevant to Fortran,
8008 but using it will force @code{COMMON} to be padded if necessary to align
8009 @code{DOUBLE PRECISION} data.
8010
8011 When @code{DOUBLE PRECISION} data is forcibly aligned
8012 in @code{COMMON} by @command{g77} due to specifying @option{-malign-double},
8013 @command{g77} issues a warning about the need to
8014 insert padding.
8015
8016 In this case, each and every program unit that uses
8017 the same @code{COMMON} area
8018 must specify the same layout of variables and their types
8019 for that area
8020 and be compiled with @option{-malign-double} as well.
8021 @command{g77} will issue warnings in each case,
8022 but as long as every program unit using that area
8023 is compiled with the same warnings,
8024 the resulting object files should work when linked together
8025 unless the program makes additional assumptions about
8026 @code{COMMON} area layouts that are outside the scope
8027 of the FORTRAN 77 standard,
8028 or uses @code{EQUIVALENCE} or different layouts
8029 in ways that assume no padding is ever inserted by the compiler.
8030
8031 @item
8032 Ensure that @file{crt0.o} or @file{crt1.o}
8033 on your system guarantees a 64-bit
8034 aligned stack for @code{main()}.
8035 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
8036 but we don't know of any other x86 setups where it will be right.
8037 Read your system's documentation to determine if
8038 it is appropriate to upgrade to a more recent version
8039 to obtain the optimal alignment.
8040 @end itemize
8041
8042 Progress is being made on making this work
8043 ``out of the box'' on future versions of @command{g77},
8044 @command{gcc}, and some of the relevant operating systems
8045 (such as GNU/Linux).
8046
8047 @cindex alignment testing
8048 @cindex testing alignment
8049 A package that tests the degree to which a Fortran compiler
8050 (such as @command{g77})
8051 aligns 64-bit floating-point variables and arrays
8052 is available at @uref{ftp://alpha.gnu.org/gnu/g77/align/}.
8053
8054 @node Prefer Automatic Uninitialized Variables
8055 @subsection Prefer Automatic Uninitialized Variables
8056
8057 If you're using @option{-fno-automatic} already, you probably
8058 should change your code to allow compilation with @option{-fautomatic}
8059 (the default), to allow the program to run faster.
8060
8061 Similarly, you should be able to use @option{-fno-init-local-zero}
8062 (the default) instead of @option{-finit-local-zero}.
8063 This is because it is rare that every variable affected by these
8064 options in a given program actually needs to
8065 be so affected.
8066
8067 For example, @option{-fno-automatic}, which effectively @code{SAVE}s
8068 every local non-automatic variable and array, affects even things like
8069 @code{DO} iteration
8070 variables, which rarely need to be @code{SAVE}d, and this often reduces
8071 run-time performances.
8072 Similarly, @option{-fno-init-local-zero} forces such
8073 variables to be initialized to zero---when @code{SAVE}d (such as when
8074 @option{-fno-automatic}), this by itself generally affects only
8075 startup time for a program, but when not @code{SAVE}d,
8076 it can slow down the procedure every time it is called.
8077
8078 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
8079 for information on the @option{-fno-automatic} and
8080 @option{-finit-local-zero} options and how to convert
8081 their use into selective changes in your own code.
8082
8083 @node Avoid f2c Compatibility
8084 @subsection Avoid f2c Compatibility
8085 @cindex -fno-f2c option
8086 @cindex options, -fno-f2c
8087 @cindex @command{f2c} compatibility
8088 @cindex compatibility, @command{f2c}
8089
8090 If you aren't linking with any code compiled using
8091 @command{f2c}, try using the @option{-fno-f2c} option when
8092 compiling @emph{all} the code in your program.
8093 (Note that @code{libf2c} is @emph{not} an example of code
8094 that is compiled using @command{f2c}---it is compiled by a C
8095 compiler, typically @command{gcc}.)
8096
8097 @node Use Submodel Options
8098 @subsection Use Submodel Options
8099 @cindex submodels
8100
8101 Using an appropriate @option{-m} option to generate specific code for your
8102 CPU may be worthwhile, though it may mean the executable won't run on
8103 other versions of the CPU that don't support the same instruction set.
8104 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using the
8105 GNU Compiler Collection (GCC)}.  For instance on an x86 system the
8106 compiler might have
8107 been built---as shown by @samp{g77 -v}---for the target
8108 @samp{i386-pc-linux-gnu}, i.e.@: an @samp{i386} CPU@.  In that case to
8109 generate code best optimized for a Pentium you could use the option
8110 @option{-march=pentium}.
8111
8112 For recent CPUs that don't have explicit support in the released version
8113 of @command{gcc}, it @emph{might} still be possible to get improvements
8114 with certain @option{-m} options.
8115
8116 @option{-fomit-frame-pointer} can help performance on x86 systems and
8117 others.  It will, however, inhibit debugging on the systems on which it
8118 is not turned on anyway by @option{-O}.
8119
8120 @node Trouble
8121 @chapter Known Causes of Trouble with GNU Fortran
8122 @cindex bugs, known
8123 @cindex installation trouble
8124 @cindex known causes of trouble
8125
8126 This section describes known problems that affect users of GNU Fortran.
8127 Most of these are not GNU Fortran bugs per se---if they were, we would
8128 fix them.
8129 But the result for a user might be like the result of a bug.
8130
8131 Some of these problems are due to bugs in other software, some are
8132 missing features that are too much work to add, and some are places
8133 where people's opinions differ as to what is best.
8134
8135 To find out about major bugs discovered in the current release and
8136 possible workarounds for them, see
8137 @uref{ftp://alpha.gnu.org/g77.plan}.
8138
8139 (Note that some of this portion of the manual is lifted
8140 directly from the @command{gcc} manual, with minor modifications
8141 to tailor it to users of @command{g77}.
8142 Anytime a bug seems to have more to do with the @command{gcc}
8143 portion of @command{g77}, see
8144 @ref{Trouble,,Known Causes of Trouble with GCC,
8145 gcc,Using the GNU Compiler Collection (GCC)}.)
8146
8147 @menu
8148 * But-bugs::         Bugs really in other programs or elsewhere.
8149 * Known Bugs::       Bugs known to be in this version of @command{g77}.
8150 * Missing Features:: Features we already know we want to add later.
8151 * Disappointments::  Regrettable things we can't change.
8152 * Non-bugs::         Things we think are right, but some others disagree.
8153 * Warnings and Errors::  Which problems in your code get warnings,
8154                         and which get errors.
8155 @end menu
8156
8157 @node But-bugs
8158 @section Bugs Not In GNU Fortran
8159 @cindex but-bugs
8160
8161 These are bugs to which the maintainers often have to reply,
8162 ``but that isn't a bug in @command{g77}@dots{}''.
8163 Some of these already are fixed in new versions of other
8164 software; some still need to be fixed; some are problems
8165 with how @command{g77} is installed or is being used;
8166 some are the result of bad hardware that causes software
8167 to misbehave in sometimes bizarre ways;
8168 some just cannot be addressed at this time until more
8169 is known about the problem.
8170
8171 Please don't re-report these bugs to the @command{g77} maintainers---if
8172 you must remind someone how important it is to you that the problem
8173 be fixed, talk to the people responsible for the other products
8174 identified below, but preferably only after you've tried the
8175 latest versions of those products.
8176 The @command{g77} maintainers have their hands full working on
8177 just fixing and improving @command{g77}, without serving as a
8178 clearinghouse for all bugs that happen to affect @command{g77}
8179 users.
8180
8181 @xref{Collected Fortran Wisdom}, for information on behavior
8182 of Fortran programs, and the programs that compile them, that
8183 might be @emph{thought} to indicate bugs.
8184
8185 @menu
8186 * Signal 11 and Friends::  Strange behavior by any software.
8187 * Cannot Link Fortran Programs::  Unresolved references.
8188 * Large Common Blocks::    Problems on older GNU/Linux systems.
8189 * Debugger Problems::      When the debugger crashes.
8190 * NeXTStep Problems::      Misbehaving executables.
8191 * Stack Overflow::         More misbehaving executables.
8192 * Nothing Happens::        Less behaving executables.
8193 * Strange Behavior at Run Time::  Executables misbehaving due to
8194                             bugs in your program.
8195 * Floating-point Errors::  The results look wrong, but@dots{}.
8196 @end menu
8197
8198 @node Signal 11 and Friends
8199 @subsection Signal 11 and Friends
8200 @cindex signal 11
8201 @cindex hardware errors
8202
8203 A whole variety of strange behaviors can occur when the
8204 software, or the way you are using the software,
8205 stresses the hardware in a way that triggers hardware bugs.
8206 This might seem hard to believe, but it happens frequently
8207 enough that there exist documents explaining in detail
8208 what the various causes of the problems are, what
8209 typical symptoms look like, and so on.
8210
8211 Generally these problems are referred to in this document
8212 as ``signal 11'' crashes, because the Linux kernel, running
8213 on the most popular hardware (the Intel x86 line), often
8214 stresses the hardware more than other popular operating
8215 systems.
8216 When hardware problems do occur under GNU/Linux on x86
8217 systems, these often manifest themselves as ``signal 11''
8218 problems, as illustrated by the following diagnostic:
8219
8220 @smallexample
8221 sh# @kbd{g77 myprog.f}
8222 gcc: Internal compiler error: program f771 got fatal signal 11
8223 sh#
8224 @end smallexample
8225
8226 It is @emph{very} important to remember that the above
8227 message is @emph{not} the only one that indicates a
8228 hardware problem, nor does it always indicate a hardware
8229 problem.
8230
8231 In particular, on systems other than those running the Linux
8232 kernel, the message might appear somewhat or very different,
8233 as it will if the error manifests itself while running a
8234 program other than the @command{g77} compiler.
8235 For example,
8236 it will appear somewhat different when running your program,
8237 when running Emacs, and so on.
8238
8239 How to cope with such problems is well beyond the scope
8240 of this manual.
8241
8242 However, users of Linux-based systems (such as GNU/Linux)
8243 should review @uref{http://www.bitwizard.nl/sig11/}, a source
8244 of detailed information on diagnosing hardware problems,
8245 by recognizing their common symptoms.
8246
8247 Users of other operating systems and hardware might
8248 find this reference useful as well.
8249 If you know of similar material for another hardware/software
8250 combination, please let us know so we can consider including
8251 a reference to it in future versions of this manual.
8252
8253 @node Cannot Link Fortran Programs
8254 @subsection Cannot Link Fortran Programs
8255 @cindex unresolved reference (various)
8256 @cindex linking error for user code
8257 @cindex code, user
8258 @cindex @command{ld}, error linking user code
8259 @cindex @command{ld}, can't find strange names
8260 On some systems, perhaps just those with out-of-date (shared?)
8261 libraries, unresolved-reference errors happen when linking @command{g77}-compiled
8262 programs (which should be done using @command{g77}).
8263
8264 If this happens to you, try appending @option{-lc} to the command you
8265 use to link the program, e.g. @samp{g77 foo.f -lc}.
8266 @command{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
8267 but it cannot also specify @option{-lc} because not all systems have a
8268 file named @file{libc.a}.
8269
8270 It is unclear at this point whether there are legitimately installed
8271 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
8272 by @command{g77}.
8273
8274 @cindex undefined reference (_main)
8275 @cindex linking error, user code
8276 @cindex @command{ld}, error linking user code
8277 @cindex code, user
8278 @cindex @command{ld}, can't find @samp{_main}
8279 If your program doesn't link due to unresolved references to names
8280 like @samp{_main}, make sure you're using the @command{g77} command to do the
8281 link, since this command ensures that the necessary libraries are
8282 loaded by specifying @samp{-lg2c -lm} when it invokes the @command{gcc}
8283 command to do the actual link.
8284 (Use the @option{-v} option to discover
8285 more about what actually happens when you use the @command{g77} and @command{gcc}
8286 commands.)
8287
8288 Also, try specifying @option{-lc} as the last item on the @command{g77}
8289 command line, in case that helps.
8290
8291 @node Large Common Blocks
8292 @subsection Large Common Blocks
8293 @cindex common blocks, large
8294 @cindex large common blocks
8295 @cindex linking, errors
8296 @cindex @command{ld}, errors
8297 @cindex errors, linker
8298 On some older GNU/Linux systems, programs with common blocks larger
8299 than 16MB cannot be linked without some kind of error
8300 message being produced.
8301
8302 This is a bug in older versions of @command{ld}, fixed in
8303 more recent versions of @code{binutils}, such as version 2.6.
8304
8305 @node Debugger Problems
8306 @subsection Debugger Problems
8307 @cindex @command{gdb}, support
8308 @cindex support, @command{gdb}
8309 There are some known problems when using @command{gdb} on code
8310 compiled by @command{g77}.
8311 Inadequate investigation as of the release of 0.5.16 results in not
8312 knowing which products are the culprit, but @file{gdb-4.14} definitely
8313 crashes when, for example, an attempt is made to print the contents
8314 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
8315 machines, plus some others.
8316 Attempts to access assumed-size arrays are
8317 also known to crash recent versions of @command{gdb}.
8318 (@command{gdb}'s Fortran support was done for a different compiler
8319 and isn't properly compatible with @command{g77}.)
8320
8321 @node NeXTStep Problems
8322 @subsection NeXTStep Problems
8323 @cindex NeXTStep problems
8324 @cindex bus error
8325 @cindex segmentation violation
8326 Developers of Fortran code on NeXTStep (all architectures) have to
8327 watch out for the following problem when writing programs with
8328 large, statically allocated (i.e. non-stack based) data structures
8329 (common blocks, saved arrays).
8330
8331 Due to the way the native loader (@file{/bin/ld}) lays out
8332 data structures in virtual memory, it is very easy to create an
8333 executable wherein the @samp{__DATA} segment overlaps (has addresses in
8334 common) with the @samp{UNIX STACK} segment.
8335
8336 This leads to all sorts of trouble, from the executable simply not
8337 executing, to bus errors.
8338 The NeXTStep command line tool @command{ebadexec} points to
8339 the problem as follows:
8340
8341 @smallexample
8342 % @kbd{/bin/ebadexec a.out}
8343 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
8344 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
8345 STACK segment (truncated address = 0x400000 rounded size =
8346 0x3c00000) of executable file: a.out
8347 @end smallexample
8348
8349 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
8350 stack segment.)
8351
8352 This can be cured by assigning the @samp{__DATA} segment
8353 (virtual) addresses beyond the stack segment.
8354 A conservative
8355 estimate for this is from address 6000000 (hexadecimal) onwards---this
8356 has always worked for me [Toon Moene]:
8357
8358 @smallexample
8359 % @kbd{g77 -segaddr __DATA 6000000 test.f}
8360 % @kbd{ebadexec a.out}
8361 ebadexec: file: a.out appears to be executable
8362 %
8363 @end smallexample
8364
8365 Browsing through @file{@value{path-g77}/Makefile.in},
8366 you will find that the @code{f771} program itself also has to be
8367 linked with these flags---it has large statically allocated
8368 data structures.
8369 (Version 0.5.18 reduces this somewhat, but probably
8370 not enough.)
8371
8372 (The above item was contributed by Toon Moene
8373 (@email{toon@@moene.indiv.nluug.nl}).)
8374
8375 @node Stack Overflow
8376 @subsection Stack Overflow
8377 @cindex stack, overflow
8378 @cindex segmentation violation
8379 @command{g77} code might fail at runtime (probably with a ``segmentation
8380 violation'') due to overflowing the stack.
8381 This happens most often on systems with an environment
8382 that provides substantially more heap space (for use
8383 when arbitrarily allocating and freeing memory) than stack
8384 space.
8385
8386 Often this can be cured by
8387 increasing or removing your shell's limit on stack usage, typically
8388 using @kbd{limit stacksize} (in @command{csh} and derivatives) or
8389 @kbd{ulimit -s} (in @command{sh} and derivatives).
8390
8391 Increasing the allowed stack size might, however, require
8392 changing some operating system or system configuration parameters.
8393
8394 You might be able to work around the problem by compiling with the
8395 @option{-fno-automatic} option to reduce stack usage, probably at the
8396 expense of speed.
8397
8398 @command{g77}, on most machines, puts many variables and arrays on the stack
8399 where possible, and can be configured (by changing
8400 @code{FFECOM_sizeMAXSTACKITEM} in @file{@value{path-g77}/com.c}) to force
8401 smaller-sized entities into static storage (saving
8402 on stack space) or permit larger-sized entities to be put on the
8403 stack (which can improve run-time performance, as it presents
8404 more opportunities for the GBE to optimize the generated code).
8405
8406 @emph{Note:} Putting more variables and arrays on the stack
8407 might cause problems due to system-dependent limits on stack size.
8408 Also, the value of @code{FFECOM_sizeMAXSTACKITEM} has no
8409 effect on automatic variables and arrays.
8410 @xref{But-bugs}, for more information.
8411 @emph{Note:} While @code{libg2c} places a limit on the range
8412 of Fortran file-unit numbers, the underlying library and operating
8413 system might impose different kinds of limits.
8414 For example, some systems limit the number of files simultaneously
8415 open by a running program.
8416 Information on how to increase these limits should be found
8417 in your system's documentation.
8418
8419 @cindex automatic arrays
8420 @cindex arrays, automatic
8421 However, if your program uses large automatic arrays
8422 (for example, has declarations like @samp{REAL A(N)} where
8423 @samp{A} is a local array and @samp{N} is a dummy or
8424 @code{COMMON} variable that can have a large value),
8425 neither use of @option{-fno-automatic},
8426 nor changing the cut-off point for @command{g77} for using the stack,
8427 will solve the problem by changing the placement of these
8428 large arrays, as they are @emph{necessarily} automatic.
8429
8430 @command{g77} currently provides no means to specify that
8431 automatic arrays are to be allocated on the heap instead
8432 of the stack.
8433 So, other than increasing the stack size, your best bet is to
8434 change your source code to avoid large automatic arrays.
8435 Methods for doing this currently are outside the scope of
8436 this document.
8437
8438 (@emph{Note:} If your system puts stack and heap space in the
8439 same memory area, such that they are effectively combined, then
8440 a stack overflow probably indicates a program that is either
8441 simply too large for the system, or buggy.)
8442
8443 @node Nothing Happens
8444 @subsection Nothing Happens
8445 @cindex nothing happens
8446 @cindex naming programs
8447 @cindex @command{test} programs
8448 @cindex programs, @command{test}
8449 It is occasionally reported that a ``simple'' program,
8450 such as a ``Hello, World!'' program, does nothing when
8451 it is run, even though the compiler reported no errors,
8452 despite the program containing nothing other than a
8453 simple @code{PRINT} statement.
8454
8455 This most often happens because the program has been
8456 compiled and linked on a UNIX system and named @command{test},
8457 though other names can lead to similarly unexpected
8458 run-time behavior on various systems.
8459
8460 Essentially this problem boils down to giving
8461 your program a name that is already known to
8462 the shell you are using to identify some other program,
8463 which the shell continues to execute instead of your
8464 program when you invoke it via, for example:
8465
8466 @smallexample
8467 sh# @kbd{test}
8468 sh#
8469 @end smallexample
8470
8471 Under UNIX and many other system, a simple command name
8472 invokes a searching mechanism that might well not choose
8473 the program located in the current working directory if
8474 there is another alternative (such as the @command{test}
8475 command commonly installed on UNIX systems).
8476
8477 The reliable way to invoke a program you just linked in
8478 the current directory under UNIX is to specify it using
8479 an explicit pathname, as in:
8480
8481 @smallexample
8482 sh# @kbd{./test}
8483  Hello, World!
8484 sh#
8485 @end smallexample
8486
8487 Users who encounter this problem should take the time to
8488 read up on how their shell searches for commands, how to
8489 set their search path, and so on.
8490 The relevant UNIX commands to learn about include
8491 @command{man}, @command{info} (on GNU systems), @command{setenv} (or
8492 @command{set} and @command{env}), @command{which}, and @command{find}.
8493
8494 @node Strange Behavior at Run Time
8495 @subsection Strange Behavior at Run Time
8496 @cindex segmentation violation
8497 @cindex bus error
8498 @cindex overwritten data
8499 @cindex data, overwritten
8500 @command{g77} code might fail at runtime with ``segmentation violation'',
8501 ``bus error'', or even something as subtle as a procedure call
8502 overwriting a variable or array element that it is not supposed
8503 to touch.
8504
8505 These can be symptoms of a wide variety of actual bugs that
8506 occurred earlier during the program's run, but manifested
8507 themselves as @emph{visible} problems some time later.
8508
8509 Overflowing the bounds of an array---usually by writing beyond
8510 the end of it---is one of two kinds of bug that often occurs
8511 in Fortran code.
8512 (Compile your code with the @option{-fbounds-check} option
8513 to catch many of these kinds of errors at program run time.)
8514
8515 The other kind of bug is a mismatch between the actual arguments
8516 passed to a procedure and the dummy arguments as declared by that
8517 procedure.
8518
8519 Both of these kinds of bugs, and some others as well, can be
8520 difficult to track down, because the bug can change its behavior,
8521 or even appear to not occur, when using a debugger.
8522
8523 That is, these bugs can be quite sensitive to data, including
8524 data representing the placement of other data in memory (that is,
8525 pointers, such as the placement of stack frames in memory).
8526
8527 @command{g77} now offers the
8528 ability to catch and report some of these problems at compile, link, or
8529 run time, such as by generating code to detect references to
8530 beyond the bounds of most arrays (except assumed-size arrays),
8531 and checking for agreement between calling and called procedures.
8532 Future improvements are likely to be made in the procedure-mismatch area,
8533 at least.
8534
8535 In the meantime, finding and fixing the programming
8536 bugs that lead to these behaviors is, ultimately, the user's
8537 responsibility, as difficult as that task can sometimes be.
8538
8539 @cindex infinite spaces printed
8540 @cindex space, endless printing of
8541 @cindex libc, non-ANSI or non-default
8542 @cindex C library
8543 @cindex linking against non-standard library
8544 @cindex Solaris
8545 One runtime problem that has been observed might have a simple solution.
8546 If a formatted @code{WRITE} produces an endless stream of spaces, check
8547 that your program is linked against the correct version of the C library.
8548 The configuration process takes care to account for your
8549 system's normal @file{libc} not being ANSI-standard, which will
8550 otherwise cause this behaviour.
8551 If your system's default library is
8552 ANSI-standard and you subsequently link against a non-ANSI one, there
8553 might be problems such as this one.
8554
8555 Specifically, on Solaris2 systems,
8556 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
8557
8558 @node Floating-point Errors
8559 @subsection Floating-point Errors
8560 @cindex floating-point errors
8561 @cindex rounding errors
8562 @cindex inconsistent floating-point results
8563 @cindex results, inconsistent
8564 Some programs appear to produce inconsistent floating-point
8565 results compiled by @command{g77} versus by other compilers.
8566
8567 Often the reason for this behavior is the fact that floating-point
8568 values are represented on almost all Fortran systems by
8569 @emph{approximations}, and these approximations are inexact
8570 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
8571 0.7, 0.8, 0.9, 1.1, and so on.
8572 Most Fortran systems, including all current ports of @command{g77},
8573 use binary arithmetic to represent these approximations.
8574
8575 Therefore, the exact value of any floating-point approximation
8576 as manipulated by @command{g77}-compiled code is representable by
8577 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
8578 so on (just keep dividing by two) through the precision of the
8579 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
8580 @code{REAL(KIND=2)}), then multiplying the sum by a integral
8581 power of two (in Fortran, by @samp{2**N}) that typically is between
8582 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
8583 @code{REAL(KIND=2)}, then multiplying by -1 if the number
8584 is negative.
8585
8586 So, a value like 0.2 is exactly represented in decimal---since
8587 it is a fraction, @samp{2/10}, with a denominator that is compatible
8588 with the base of the number system (base 10).
8589 However, @samp{2/10} cannot be represented by any finite number
8590 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
8591 be exactly represented in binary notation.
8592
8593 (On the other hand, decimal notation can represent any binary
8594 number in a finite number of digits.
8595 Decimal notation cannot do so with ternary, or base-3,
8596 notation, which would represent floating-point numbers as
8597 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
8598 After all, no finite number of decimal digits can exactly
8599 represent @samp{1/3}.
8600 Fortunately, few systems use ternary notation.)
8601
8602 Moreover, differences in the way run-time I/O libraries convert
8603 between these approximations and the decimal representation often
8604 used by programmers and the programs they write can result in
8605 apparent differences between results that do not actually exist,
8606 or exist to such a small degree that they usually are not worth
8607 worrying about.
8608
8609 For example, consider the following program:
8610
8611 @smallexample
8612 PRINT *, 0.2
8613 END
8614 @end smallexample
8615
8616 When compiled by @command{g77}, the above program might output
8617 @samp{0.20000003}, while another compiler might produce a
8618 executable that outputs @samp{0.2}.
8619
8620 This particular difference is due to the fact that, currently,
8621 conversion of floating-point values by the @code{libg2c} library,
8622 used by @command{g77}, handles only double-precision values.
8623
8624 Since @samp{0.2} in the program is a single-precision value, it
8625 is converted to double precision (still in binary notation)
8626 before being converted back to decimal.
8627 The conversion to binary appends @emph{binary} zero digits to the
8628 original value---which, again, is an inexact approximation of
8629 0.2---resulting in an approximation that is much less exact
8630 than is connoted by the use of double precision.
8631
8632 (The appending of binary zero digits has essentially the same
8633 effect as taking a particular decimal approximation of
8634 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
8635 zeros to it, producing @samp{0.33333330000000000}.
8636 Treating the resulting decimal approximation as if it really
8637 had 18 or so digits of valid precision would make it seem
8638 a very poor approximation of @samp{1/3}.)
8639
8640 As a result of converting the single-precision approximation
8641 to double precision by appending binary zeros, the conversion
8642 of the resulting double-precision
8643 value to decimal produces what looks like an incorrect
8644 result, when in fact the result is @emph{inexact}, and
8645 is probably no less inaccurate or imprecise an approximation
8646 of 0.2 than is produced by other compilers that happen to output
8647 the converted value as ``exactly'' @samp{0.2}.
8648 (Some compilers behave in a way that can make them appear
8649 to retain more accuracy across a conversion of a single-precision
8650 constant to double precision.
8651 @xref{Context-Sensitive Constants}, to see why
8652 this practice is illusory and even dangerous.)
8653
8654 Note that a more exact approximation of the constant is
8655 computed when the program is changed to specify a
8656 double-precision constant:
8657
8658 @smallexample
8659 PRINT *, 0.2D0
8660 END
8661 @end smallexample
8662
8663 Future versions of @command{g77} and/or @code{libg2c} might convert
8664 single-precision values directly to decimal,
8665 instead of converting them to double precision first.
8666 This would tend to result in output that is more consistent
8667 with that produced by some other Fortran implementations.
8668
8669 A useful source of information on floating-point computation is David
8670 Goldberg, `What Every Computer Scientist Should Know About
8671 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
8672 5-48.
8673 An online version is available at
8674 @uref{http://docs.sun.com/},
8675 and there is a supplemented version, in PostScript form, at
8676 @uref{http://www.validgh.com/goldberg/paper.ps}.
8677
8678 Information related to the IEEE 754
8679 floating-point standard by a leading light can be found at
8680 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status/};
8681 see also slides from the short course referenced from
8682 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
8683 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
8684 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
8685 and library code for GNU/Linux x86 systems.
8686
8687 The supplement to the PostScript-formatted Goldberg document,
8688 referenced above, is available in HTML format.
8689 See `Differences Among IEEE 754 Implementations' by Doug Priest,
8690 available online at
8691 @uref{http://www.validgh.com/goldberg/addendum.html}.
8692 This document explores some of the issues surrounding computing
8693 of extended (80-bit) results on processors such as the x86,
8694 especially when those results are arbitrarily truncated
8695 to 32-bit or 64-bit values by the compiler
8696 as ``spills''.
8697
8698 @cindex spills of floating-point results
8699 @cindex 80-bit spills
8700 @cindex truncation, of floating-point values
8701 (@emph{Note:} @command{g77} specifically, and @command{gcc} generally,
8702 does arbitrarily truncate 80-bit results during spills
8703 as of this writing.
8704 It is not yet clear whether a future version of
8705 the GNU compiler suite will offer 80-bit spills
8706 as an option, or perhaps even as the default behavior.)
8707
8708 @c xref would be different between editions:
8709 The GNU C library provides routines for controlling the FPU, and other
8710 documentation about this.
8711
8712 @xref{Floating-point precision}, regarding IEEE 754 conformance.
8713
8714 @include bugs.texi
8715
8716 @node Missing Features
8717 @section Missing Features
8718
8719 This section lists features we know are missing from @command{g77},
8720 and which we want to add someday.
8721 (There is no priority implied in the ordering below.)
8722
8723 @menu
8724 GNU Fortran language:
8725 * Better Source Model::
8726 * Fortran 90 Support::
8727 * Intrinsics in PARAMETER Statements::
8728 * Arbitrary Concatenation::
8729 * SELECT CASE on CHARACTER Type::
8730 * RECURSIVE Keyword::
8731 * Popular Non-standard Types::
8732 * Full Support for Compiler Types::
8733 * Array Bounds Expressions::
8734 * POINTER Statements::
8735 * Sensible Non-standard Constructs::
8736 * READONLY Keyword::
8737 * FLUSH Statement::
8738 * Expressions in FORMAT Statements::
8739 * Explicit Assembler Code::
8740 * Q Edit Descriptor::
8741
8742 GNU Fortran dialects:
8743 * Old-style PARAMETER Statements::
8744 * TYPE and ACCEPT I/O Statements::
8745 * STRUCTURE UNION RECORD MAP::
8746 * OPEN CLOSE and INQUIRE Keywords::
8747 * ENCODE and DECODE::
8748 * AUTOMATIC Statement::
8749 * Suppressing Space Padding::
8750 * Fortran Preprocessor::
8751 * Bit Operations on Floating-point Data::
8752 * Really Ugly Character Assignments::
8753
8754 New facilities:
8755 * POSIX Standard::
8756 * Floating-point Exception Handling::
8757 * Nonportable Conversions::
8758 * Large Automatic Arrays::
8759 * Support for Threads::
8760 * Increasing Precision/Range::
8761 * Enabling Debug Lines::
8762
8763 Better diagnostics:
8764 * Better Warnings::
8765 * Gracefully Handle Sensible Bad Code::
8766 * Non-standard Conversions::
8767 * Non-standard Intrinsics::
8768 * Modifying DO Variable::
8769 * Better Pedantic Compilation::
8770 * Warn About Implicit Conversions::
8771 * Invalid Use of Hollerith Constant::
8772 * Dummy Array Without Dimensioning Dummy::
8773 * Invalid FORMAT Specifiers::
8774 * Ambiguous Dialects::
8775 * Unused Labels::
8776 * Informational Messages::
8777
8778 Run-time facilities:
8779 * Uninitialized Variables at Run Time::
8780 * Portable Unformatted Files::
8781 * Better List-directed I/O::
8782 * Default to Console I/O::
8783
8784 Debugging:
8785 * Labels Visible to Debugger::
8786 @end menu
8787
8788 @node Better Source Model
8789 @subsection Better Source Model
8790
8791 @command{g77} needs to provide, as the default source-line model,
8792 a ``pure visual'' mode, where
8793 the interpretation of a source program in this mode can be accurately
8794 determined by a user looking at a traditionally displayed rendition
8795 of the program (assuming the user knows whether the program is fixed
8796 or free form).
8797
8798 The design should assume the user cannot tell tabs from spaces
8799 and cannot see trailing spaces on lines, but has canonical tab stops
8800 and, for fixed-form source, has the ability to always know exactly
8801 where column 72 is (since the Fortran standard itself requires
8802 this for fixed-form source).
8803
8804 This would change the default treatment of fixed-form source
8805 to not treat lines with tabs as if they were infinitely long---instead,
8806 they would end at column 72 just as if the tabs were replaced
8807 by spaces in the canonical way.
8808
8809 As part of this, provide common alternate models (Digital, @command{f2c},
8810 and so on) via command-line options.
8811 This includes allowing arbitrarily long
8812 lines for free-form source as well as fixed-form source and providing
8813 various limits and diagnostics as appropriate.
8814
8815 @cindex sequence numbers
8816 @cindex columns 73 through 80
8817 Also, @command{g77} should offer, perhaps even default to, warnings
8818 when characters beyond the last valid column are anything other
8819 than spaces.
8820 This would mean code with ``sequence numbers'' in columns 73 through 80
8821 would be rejected, and there's a lot of that kind of code around,
8822 but one of the most frequent bugs encountered by new users is
8823 accidentally writing fixed-form source code into and beyond
8824 column 73.
8825 So, maybe the users of old code would be able to more easily handle
8826 having to specify, say, a @option{-Wno-col73to80} option.
8827
8828 @node Fortran 90 Support
8829 @subsection Fortran 90 Support
8830 @cindex Fortran 90, support
8831 @cindex support, Fortran 90
8832
8833 @command{g77} does not support many of the features that
8834 distinguish Fortran 90 (and, now, Fortran 95) from
8835 ANSI FORTRAN 77.
8836
8837 Some Fortran 90 features are supported, because they
8838 make sense to offer even to die-hard users of F77.
8839 For example, many of them codify various ways F77 has
8840 been extended to meet users' needs during its tenure,
8841 so @command{g77} might as well offer them as the primary
8842 way to meet those same needs, even if it offers compatibility
8843 with one or more of the ways those needs were met
8844 by other F77 compilers in the industry.
8845
8846 Still, many important F90 features are not supported,
8847 because no attempt has been made to research each and
8848 every feature and assess its viability in @command{g77}.
8849 In the meantime, users who need those features must
8850 use Fortran 90 compilers anyway, and the best approach
8851 to adding some F90 features to GNU Fortran might well be
8852 to fund a comprehensive project to create GNU Fortran 95.
8853
8854 @node Intrinsics in PARAMETER Statements
8855 @subsection Intrinsics in @code{PARAMETER} Statements
8856 @cindex PARAMETER statement
8857 @cindex statements, PARAMETER
8858
8859 @command{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
8860
8861 Related to this, @command{g77} doesn't allow non-integral
8862 exponentiation in @code{PARAMETER} statements, such as
8863 @samp{PARAMETER (R=2**.25)}.
8864 It is unlikely @command{g77} will ever support this feature,
8865 as doing it properly requires complete emulation of
8866 a target computer's floating-point facilities when
8867 building @command{g77} as a cross-compiler.
8868 But, if the @command{gcc} back end is enhanced to provide
8869 such a facility, @command{g77} will likely use that facility
8870 in implementing this feature soon afterwards.
8871
8872 @node Arbitrary Concatenation
8873 @subsection Arbitrary Concatenation
8874 @cindex concatenation
8875 @cindex CHARACTER*(*)
8876 @cindex run-time, dynamic allocation
8877
8878 @command{g77} doesn't support arbitrary operands for concatenation
8879 in contexts where run-time allocation is required.
8880 For example:
8881
8882 @smallexample
8883 SUBROUTINE X(A)
8884 CHARACTER*(*) A
8885 CALL FOO(A // 'suffix')
8886 @end smallexample
8887
8888 @node SELECT CASE on CHARACTER Type
8889 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
8890
8891 Character-type selector/cases for @code{SELECT CASE} currently
8892 are not supported.
8893
8894 @node RECURSIVE Keyword
8895 @subsection @code{RECURSIVE} Keyword
8896 @cindex RECURSIVE keyword
8897 @cindex keywords, RECURSIVE
8898 @cindex recursion, lack of
8899 @cindex lack of recursion
8900
8901 @command{g77} doesn't support the @code{RECURSIVE} keyword that
8902 F90 compilers do.
8903 Nor does it provide any means for compiling procedures
8904 designed to do recursion.
8905
8906 All recursive code can be rewritten to not use recursion,
8907 but the result is not pretty.
8908
8909 @node Increasing Precision/Range
8910 @subsection Increasing Precision/Range
8911 @cindex -r8
8912 @cindex -qrealsize=8
8913 @cindex -i8
8914 @cindex f2c
8915 @cindex increasing precision
8916 @cindex precision, increasing
8917 @cindex increasing range
8918 @cindex range, increasing
8919 @cindex Toolpack
8920 @cindex Netlib
8921
8922 Some compilers, such as @command{f2c}, have an option (@option{-r8},
8923 @option{-qrealsize=8} or
8924 similar) that provides automatic treatment of @code{REAL}
8925 entities such that they have twice the storage size, and
8926 a corresponding increase in the range and precision, of what
8927 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
8928 (This affects @code{COMPLEX} the same way.)
8929
8930 They also typically offer another option (@option{-i8}) to increase
8931 @code{INTEGER} entities so they are twice as large
8932 (with roughly twice as much range).
8933
8934 (There are potential pitfalls in using these options.)
8935
8936 @command{g77} does not yet offer any option that performs these
8937 kinds of transformations.
8938 Part of the problem is the lack of detailed specifications regarding
8939 exactly how these options affect the interpretation of constants,
8940 intrinsics, and so on.
8941
8942 Until @command{g77} addresses this need, programmers could improve
8943 the portability of their code by modifying it to not require
8944 compile-time options to produce correct results.
8945 Some free tools are available which may help, specifically
8946 in Toolpack (which one would expect to be sound) and the @file{fortran}
8947 section of the Netlib repository.
8948
8949 Use of preprocessors can provide a fairly portable means
8950 to work around the lack of widely portable methods in the Fortran
8951 language itself (though increasing acceptance of Fortran 90 would
8952 alleviate this problem).
8953
8954 @node Popular Non-standard Types
8955 @subsection Popular Non-standard Types
8956 @cindex @code{INTEGER*2} support
8957 @cindex types, @code{INTEGER*2}
8958 @cindex @code{LOGICAL*1} support
8959 @cindex types, @code{LOGICAL*1}
8960
8961 @command{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
8962 and similar.
8963 In the meantime, version 0.5.18 provides rudimentary support
8964 for them.
8965
8966 @node Full Support for Compiler Types
8967 @subsection Full Support for Compiler Types
8968
8969 @cindex @code{REAL*16} support
8970 @cindex types, @code{REAL*16}
8971 @cindex @code{INTEGER*8} support
8972 @cindex types, @code{INTEGER*8}
8973 @command{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
8974 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
8975 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
8976 This means providing intrinsic support, and maybe constant
8977 support (using F90 syntax) as well, and, for most
8978 machines will result in automatic support of @code{INTEGER*1},
8979 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
8980 and so on.
8981
8982 @node Array Bounds Expressions
8983 @subsection Array Bounds Expressions
8984 @cindex array elements, in adjustable array bounds
8985 @cindex function references, in adjustable array bounds
8986 @cindex array bounds, adjustable
8987 @cindex @code{DIMENSION} statement
8988 @cindex statements, @code{DIMENSION}
8989
8990 @command{g77} doesn't support more general expressions to dimension
8991 arrays, such as array element references, function
8992 references, etc.
8993
8994 For example, @command{g77} currently does not accept the following:
8995
8996 @smallexample
8997 SUBROUTINE X(M, N)
8998 INTEGER N(10), M(N(2), N(1))
8999 @end smallexample
9000
9001 @node POINTER Statements
9002 @subsection POINTER Statements
9003 @cindex POINTER statement
9004 @cindex statements, POINTER
9005 @cindex Cray pointers
9006
9007 @command{g77} doesn't support pointers or allocatable objects
9008 (other than automatic arrays).
9009 This set of features is
9010 probably considered just behind intrinsics
9011 in @code{PARAMETER} statements on the list of large,
9012 important things to add to @command{g77}.
9013
9014 In the meantime, consider using the @code{INTEGER(KIND=7)}
9015 declaration to specify that a variable must be
9016 able to hold a pointer.
9017 This construct is not portable to other non-GNU compilers,
9018 but it is portable to all machines GNU Fortran supports
9019 when @command{g77} is used.
9020
9021 @xref{Functions and Subroutines}, for information on
9022 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
9023 constructs, which are useful for passing pointers to
9024 procedures written in languages other than Fortran.
9025
9026 @node Sensible Non-standard Constructs
9027 @subsection Sensible Non-standard Constructs
9028
9029 @command{g77} rejects things other compilers accept,
9030 like @samp{INTRINSIC SQRT,SQRT}.
9031 As time permits in the future, some of these things that are easy for
9032 humans to read and write and unlikely to be intended to mean something
9033 else will be accepted by @command{g77} (though @option{-fpedantic} should
9034 trigger warnings about such non-standard constructs).
9035
9036 Until @command{g77} no longer gratuitously rejects sensible code,
9037 you might as well fix your code
9038 to be more standard-conforming and portable.
9039
9040 The kind of case that is important to except from the
9041 recommendation to change your code is one where following
9042 good coding rules would force you to write non-standard
9043 code that nevertheless has a clear meaning.
9044
9045 For example, when writing an @code{INCLUDE} file that
9046 defines a common block, it might be appropriate to
9047 include a @code{SAVE} statement for the common block
9048 (such as @samp{SAVE /CBLOCK/}), so that variables
9049 defined in the common block retain their values even
9050 when all procedures declaring the common block become
9051 inactive (return to their callers).
9052
9053 However, putting @code{SAVE} statements in an @code{INCLUDE}
9054 file would prevent otherwise standard-conforming code
9055 from also specifying the @code{SAVE} statement, by itself,
9056 to indicate that all local variables and arrays are to
9057 have the @code{SAVE} attribute.
9058
9059 For this reason, @command{g77} already has been changed to
9060 allow this combination, because although the general
9061 problem of gratuitously rejecting unambiguous and
9062 ``safe'' constructs still exists in @command{g77}, this
9063 particular construct was deemed useful enough that
9064 it was worth fixing @command{g77} for just this case.
9065
9066 So, while there is no need to change your code
9067 to avoid using this particular construct, there
9068 might be other, equally appropriate but non-standard
9069 constructs, that you shouldn't have to stop using
9070 just because @command{g77} (or any other compiler)
9071 gratuitously rejects it.
9072
9073 Until the general problem is solved, if you have
9074 any such construct you believe is worthwhile
9075 using (e.g. not just an arbitrary, redundant
9076 specification of an attribute), please submit a
9077 bug report with an explanation, so we can consider
9078 fixing @command{g77} just for cases like yours.
9079
9080 @node READONLY Keyword
9081 @subsection @code{READONLY} Keyword
9082 @cindex READONLY
9083
9084 Support for @code{READONLY}, in @code{OPEN} statements,
9085 requires @code{libg2c} support,
9086 to make sure that @samp{CLOSE(@dots{},STATUS='DELETE')}
9087 does not delete a file opened on a unit
9088 with the @code{READONLY} keyword,
9089 and perhaps to trigger a fatal diagnostic
9090 if a @code{WRITE} or @code{PRINT}
9091 to such a unit is attempted.
9092
9093 @emph{Note:} It is not sufficient for @command{g77} and @code{libg2c}
9094 (its version of @code{libf2c})
9095 to assume that @code{READONLY} does not need some kind of explicit support
9096 at run time,
9097 due to UNIX systems not (generally) needing it.
9098 @command{g77} is not just a UNIX-based compiler!
9099
9100 Further, mounting of non-UNIX filesystems on UNIX systems
9101 (such as via NFS)
9102 might require proper @code{READONLY} support.
9103
9104 @cindex SHARED
9105 (Similar issues might be involved with supporting the @code{SHARED}
9106 keyword.)
9107
9108 @node FLUSH Statement
9109 @subsection @code{FLUSH} Statement
9110
9111 @command{g77} could perhaps use a @code{FLUSH} statement that
9112 does what @samp{CALL FLUSH} does,
9113 but that supports @samp{*} as the unit designator (same unit as for
9114 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
9115 specifiers.
9116
9117 @node Expressions in FORMAT Statements
9118 @subsection Expressions in @code{FORMAT} Statements
9119 @cindex FORMAT statement
9120 @cindex statements, FORMAT
9121
9122 @command{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
9123 Supporting this requires a significant redesign or replacement
9124 of @code{libg2c}.
9125
9126 However, @command{g77} does support
9127 this construct when the expression is constant
9128 (as of version 0.5.22).
9129 For example:
9130
9131 @smallexample
9132       PARAMETER (IWIDTH = 12)
9133 10    FORMAT (I<IWIDTH>)
9134 @end smallexample
9135
9136 Otherwise, at least for output (@code{PRINT} and
9137 @code{WRITE}), Fortran code making use of this feature can
9138 be rewritten to avoid it by constructing the @code{FORMAT}
9139 string in a @code{CHARACTER} variable or array, then
9140 using that variable or array in place of the @code{FORMAT}
9141 statement label to do the original @code{PRINT} or @code{WRITE}.
9142
9143 Many uses of this feature on input can be rewritten this way
9144 as well, but not all can.
9145 For example, this can be rewritten:
9146
9147 @smallexample
9148       READ 20, I
9149 20    FORMAT (I<J>)
9150 @end smallexample
9151
9152 However, this cannot, in general, be rewritten, especially
9153 when @code{ERR=} and @code{END=} constructs are employed:
9154
9155 @smallexample
9156       READ 30, J, I
9157 30    FORMAT (I<J>)
9158 @end smallexample
9159
9160 @node Explicit Assembler Code
9161 @subsection Explicit Assembler Code
9162
9163 @command{g77} needs to provide some way, a la @command{gcc}, for @command{g77}
9164 code to specify explicit assembler code.
9165
9166 @node Q Edit Descriptor
9167 @subsection Q Edit Descriptor
9168 @cindex FORMAT statement
9169 @cindex Q edit descriptor
9170 @cindex edit descriptor, Q
9171
9172 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
9173 (This is meant to get the number of characters remaining in an input record.)
9174 Supporting this requires a significant redesign or replacement
9175 of @code{libg2c}.
9176
9177 A workaround might be using internal I/O or the stream-based intrinsics.
9178 @xref{FGetC Intrinsic (subroutine)}.
9179
9180 @node Old-style PARAMETER Statements
9181 @subsection Old-style PARAMETER Statements
9182 @cindex PARAMETER statement
9183 @cindex statements, PARAMETER
9184
9185 @command{g77} doesn't accept @samp{PARAMETER I=1}.
9186 Supporting this obsolete form of
9187 the @code{PARAMETER} statement would not be particularly hard, as most of the
9188 parsing code is already in place and working.
9189
9190 Until time/money is
9191 spent implementing it, you might as well fix your code to use the
9192 standard form, @samp{PARAMETER (I=1)} (possibly needing
9193 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
9194 otherwise, in the obsolete form of @code{PARAMETER}, the
9195 type of the variable is set from the type of the constant being
9196 assigned to it).
9197
9198 @node TYPE and ACCEPT I/O Statements
9199 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
9200 @cindex TYPE statement
9201 @cindex statements, TYPE
9202 @cindex ACCEPT statement
9203 @cindex statements, ACCEPT
9204
9205 @command{g77} doesn't support the I/O statements @code{TYPE} and
9206 @code{ACCEPT}.
9207 These are common extensions that should be easy to support,
9208 but also are fairly easy to work around in user code.
9209
9210 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
9211 by @samp{PRINT fmt,list}.
9212 And, any @samp{ACCEPT fmt,list} statement can be
9213 replaced by @samp{READ fmt,list}.
9214
9215 @node STRUCTURE UNION RECORD MAP
9216 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
9217 @cindex STRUCTURE statement
9218 @cindex statements, STRUCTURE
9219 @cindex UNION statement
9220 @cindex statements, UNION
9221 @cindex RECORD statement
9222 @cindex statements, RECORD
9223 @cindex MAP statement
9224 @cindex statements, MAP
9225
9226 @command{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
9227 @code{MAP}.
9228 This set of extensions is quite a bit
9229 lower on the list of large, important things to add to @command{g77}, partly
9230 because it requires a great deal of work either upgrading or
9231 replacing @code{libg2c}.
9232
9233 @node OPEN CLOSE and INQUIRE Keywords
9234 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
9235 @cindex disposition of files
9236 @cindex OPEN statement
9237 @cindex statements, OPEN
9238 @cindex CLOSE statement
9239 @cindex statements, CLOSE
9240 @cindex INQUIRE statement
9241 @cindex statements, INQUIRE
9242
9243 @command{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
9244 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
9245 These extensions are easy to add to @command{g77} itself, but
9246 require much more work on @code{libg2c}.
9247
9248 @cindex FORM='PRINT'
9249 @cindex ANS carriage control
9250 @cindex carriage control
9251 @pindex asa
9252 @pindex fpr
9253 @command{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
9254 translate the traditional `carriage control' characters in column 1 of
9255 output to use backspaces, carriage returns and the like.  However
9256 programs exist to translate them in output files (or standard output).
9257 These are typically called either @command{fpr} or @command{asa}.  You can get
9258 a version of @command{asa} from
9259 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
9260 systems which will probably build easily on other systems.
9261 Alternatively, @command{fpr} is in BSD distributions in various archive
9262 sites.
9263
9264 @c (Can both programs can be used in a pipeline,
9265 @c with a named input file,
9266 @c and/or with a named output file???)
9267
9268 @node ENCODE and DECODE
9269 @subsection @code{ENCODE} and @code{DECODE}
9270 @cindex ENCODE statement
9271 @cindex statements, ENCODE
9272 @cindex DECODE statement
9273 @cindex statements, DECODE
9274
9275 @command{g77} doesn't support @code{ENCODE} or @code{DECODE}.
9276
9277 These statements are best replaced by READ and WRITE statements
9278 involving internal files (CHARACTER variables and arrays).
9279
9280 For example, replace a code fragment like
9281
9282 @smallexample
9283       INTEGER*1 LINE(80)
9284 @dots{}
9285       DECODE (80, 9000, LINE) A, B, C
9286 @dots{}
9287 9000  FORMAT (1X, 3(F10.5))
9288 @end smallexample
9289
9290 @noindent
9291 with:
9292
9293 @smallexample
9294       CHARACTER*80 LINE
9295 @dots{}
9296       READ (UNIT=LINE, FMT=9000) A, B, C
9297 @dots{}
9298 9000  FORMAT (1X, 3(F10.5))
9299 @end smallexample
9300
9301 Similarly, replace a code fragment like
9302
9303 @smallexample
9304       INTEGER*1 LINE(80)
9305 @dots{}
9306       ENCODE (80, 9000, LINE) A, B, C
9307 @dots{}
9308 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
9309 @end smallexample
9310
9311 @noindent
9312 with:
9313
9314 @smallexample
9315       CHARACTER*80 LINE
9316 @dots{}
9317       WRITE (UNIT=LINE, FMT=9000) A, B, C
9318 @dots{}
9319 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
9320 @end smallexample
9321
9322 It is entirely possible that @code{ENCODE} and @code{DECODE} will
9323 be supported by a future version of @command{g77}.
9324
9325 @node AUTOMATIC Statement
9326 @subsection @code{AUTOMATIC} Statement
9327 @cindex @code{AUTOMATIC} statement
9328 @cindex statements, @code{AUTOMATIC}
9329 @cindex automatic variables
9330 @cindex variables, automatic
9331
9332 @command{g77} doesn't support the @code{AUTOMATIC} statement that
9333 @command{f2c} does.
9334
9335 @code{AUTOMATIC} would identify a variable or array
9336 as not being @code{SAVE}'d, which is normally the default,
9337 but which would be especially useful for code that, @emph{generally},
9338 needed to be compiled with the @option{-fno-automatic} option.
9339
9340 @code{AUTOMATIC} also would serve as a hint to the compiler that placing
9341 the variable or array---even a very large array--on the stack is acceptable.
9342
9343 @code{AUTOMATIC} would not, by itself, designate the containing procedure
9344 as recursive.
9345
9346 @code{AUTOMATIC} should work syntactically like @code{SAVE},
9347 in that @code{AUTOMATIC} with no variables listed should apply to
9348 all pertinent variables and arrays
9349 (which would not include common blocks or their members).
9350
9351 Variables and arrays denoted as @code{AUTOMATIC}
9352 would not be permitted to be initialized via @code{DATA}
9353 or other specification of any initial values,
9354 requiring explicit initialization,
9355 such as via assignment statements.
9356
9357 @cindex UNSAVE
9358 @cindex STATIC
9359 Perhaps @code{UNSAVE} and @code{STATIC},
9360 as strict semantic opposites to @code{SAVE} and @code{AUTOMATIC},
9361 should be provided as well.
9362
9363 @node Suppressing Space Padding
9364 @subsection Suppressing Space Padding of Source Lines
9365
9366 @command{g77} should offer VXT-Fortran-style suppression of virtual
9367 spaces at the end of a source line
9368 if an appropriate command-line option is specified.
9369
9370 This affects cases where
9371 a character constant is continued onto the next line in a fixed-form
9372 source file, as in the following example:
9373
9374 @smallexample
9375 10    PRINT *,'HOW MANY
9376      1 SPACES?'
9377 @end smallexample
9378
9379 @noindent
9380 @command{g77}, and many other compilers, virtually extend
9381 the continued line through column 72 with spaces that become part
9382 of the character constant, but Digital Fortran normally didn't,
9383 leaving only one space between @samp{MANY} and @samp{SPACES?}
9384 in the output of the above statement.
9385
9386 Fairly recently, at least one version of Digital Fortran
9387 was enhanced to provide the other behavior when a
9388 command-line option is specified, apparently due to demand
9389 from readers of the USENET group @file{comp.lang.fortran}
9390 to offer conformance to this widespread practice in the
9391 industry.
9392 @command{g77} should return the favor by offering conformance
9393 to Digital's approach to handling the above example.
9394
9395 @node Fortran Preprocessor
9396 @subsection Fortran Preprocessor
9397
9398 @command{g77} should offer a preprocessor designed specifically
9399 for Fortran to replace @samp{cpp -traditional}.
9400 There are several out there worth evaluating, at least.
9401
9402 Such a preprocessor would recognize Hollerith constants,
9403 properly parse comments and character constants, and so on.
9404 It might also recognize, process, and thus preprocess
9405 files included via the @code{INCLUDE} directive.
9406
9407 @node Bit Operations on Floating-point Data
9408 @subsection Bit Operations on Floating-point Data
9409 @cindex @code{And} intrinsic
9410 @cindex intrinsics, @code{And}
9411 @cindex @code{Or} intrinsic
9412 @cindex intrinsics, @code{Or}
9413 @cindex @code{Shift} intrinsic
9414 @cindex intrinsics, @code{Shift}
9415
9416 @command{g77} does not allow @code{REAL} and other non-integral types for
9417 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
9418
9419 For example, this program is rejected by @command{g77}, because
9420 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
9421
9422 @smallexample
9423 DATA A/7.54/, B/9.112/
9424 PRINT *, IAND(A, B)
9425 END
9426 @end smallexample
9427
9428 @node Really Ugly Character Assignments
9429 @subsection Really Ugly Character Assignments
9430
9431 An option such as @option{-fugly-char} should be provided
9432 to allow
9433
9434 @smallexample
9435 REAL*8 A1
9436 DATA A1 / '12345678' /
9437 @end smallexample
9438
9439 and:
9440
9441 @smallexample
9442 REAL*8 A1
9443 A1 = 'ABCDEFGH'
9444 @end smallexample
9445
9446 @node POSIX Standard
9447 @subsection @code{POSIX} Standard
9448
9449 @command{g77} should support the POSIX standard for Fortran.
9450
9451 @node Floating-point Exception Handling
9452 @subsection Floating-point Exception Handling
9453 @cindex floating-point, exceptions
9454 @cindex exceptions, floating-point
9455 @cindex FPE handling
9456 @cindex NaN values
9457
9458 The @command{gcc} backend and, consequently, @command{g77}, currently provides no
9459 general control over whether or not floating-point exceptions are trapped or
9460 ignored.
9461 (Ignoring them typically results in NaN values being
9462 propagated in systems that conform to IEEE 754.)
9463 The behaviour is normally inherited from the system-dependent startup
9464 code, though some targets, such as the Alpha, have code generation
9465 options which change the behaviour.
9466
9467 Most systems provide some C-callable mechanism to change this; this can
9468 be invoked at startup using @command{gcc}'s @code{constructor} attribute.
9469 For example, just compiling and linking the following C code with your
9470 program will turn on exception trapping for the ``common'' exceptions
9471 on a GNU system using glibc 2.2 or newer:
9472
9473 @smallexample
9474 #define _GNU_SOURCE 1
9475 #include <fenv.h>
9476 static void __attribute__ ((constructor))
9477 trapfpe ()
9478 @{
9479   /* Enable some exceptions.  At startup all exceptions are masked.  */
9480   
9481   feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
9482 @}
9483 @end smallexample
9484
9485 A convenient trick is to compile this something like:
9486 @smallexample
9487 gcc -o libtrapfpe.a trapfpe.c
9488 @end smallexample
9489 and then use it by adding @option{-trapfpe} to the @command{g77} command line
9490 when linking.
9491
9492 @node Nonportable Conversions
9493 @subsection Nonportable Conversions
9494 @cindex nonportable conversions
9495 @cindex conversions, nonportable
9496
9497 @command{g77} doesn't accept some particularly nonportable,
9498 silent data-type conversions such as @code{LOGICAL}
9499 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
9500 is type @code{REAL}), that other compilers might
9501 quietly accept.
9502
9503 Some of these conversions are accepted by @command{g77}
9504 when the @option{-fugly-logint} option is specified.
9505 Perhaps it should accept more or all of them.
9506
9507 @node Large Automatic Arrays
9508 @subsection Large Automatic Arrays
9509 @cindex automatic arrays
9510 @cindex arrays, automatic
9511
9512 Currently, automatic arrays always are allocated on the stack.
9513 For situations where the stack cannot be made large enough,
9514 @command{g77} should offer a compiler option that specifies
9515 allocation of automatic arrays in heap storage.
9516
9517 @node Support for Threads
9518 @subsection Support for Threads
9519 @cindex threads
9520 @cindex parallel processing
9521
9522 Neither the code produced by @command{g77} nor the @code{libg2c} library
9523 are thread-safe, nor does @command{g77} have support for parallel processing
9524 (other than the instruction-level parallelism available on some
9525 processors).
9526 A package such as PVM might help here.
9527
9528 @node Enabling Debug Lines
9529 @subsection Enabling Debug Lines
9530 @cindex debug line
9531 @cindex comment line, debug
9532
9533 An option such as @option{-fdebug-lines} should be provided
9534 to turn fixed-form lines beginning with @samp{D}
9535 to be treated as if they began with a space,
9536 instead of as if they began with a @samp{C}
9537 (as comment lines).
9538
9539 @node Better Warnings
9540 @subsection Better Warnings
9541
9542 Because of how @command{g77} generates code via the back end,
9543 it doesn't always provide warnings the user wants.
9544 Consider:
9545
9546 @smallexample
9547 PROGRAM X
9548 PRINT *, A
9549 END
9550 @end smallexample
9551
9552 Currently, the above is not flagged as a case of
9553 using an uninitialized variable,
9554 because @command{g77} generates a run-time library call that looks,
9555 to the GBE, like it might actually @emph{modify} @samp{A} at run time.
9556 (And, in fact, depending on the previous run-time library call,
9557 it would!)
9558
9559 Fixing this requires one of the following:
9560
9561 @itemize @bullet
9562 @item
9563 Switch to new library, @code{libg77}, that provides
9564 a more ``clean'' interface,
9565 vis-a-vis input, output, and modified arguments,
9566 so the GBE can tell what's going on.
9567
9568 This would provide a pretty big performance improvement,
9569 at least theoretically, and, ultimately, in practice,
9570 for some types of code.
9571
9572 @item
9573 Have @command{g77} pass a pointer to a temporary
9574 containing a copy of @samp{A},
9575 instead of to @samp{A} itself.
9576 The GBE would then complain about the copy operation
9577 involving a potentially uninitialized variable.
9578
9579 This might also provide a performance boost for some code,
9580 because @samp{A} might then end up living in a register,
9581 which could help with inner loops.
9582
9583 @item
9584 Have @command{g77} use a GBE construct similar to @code{ADDR_EXPR}
9585 but with extra information on the fact that the
9586 item pointed to won't be modified
9587 (a la @code{const} in C).
9588
9589 Probably the best solution for now, but not quite trivial
9590 to implement in the general case.
9591 @end itemize
9592
9593 @node Gracefully Handle Sensible Bad Code
9594 @subsection Gracefully Handle Sensible Bad Code
9595
9596 @command{g77} generally should continue processing for
9597 warnings and recoverable (user) errors whenever possible---that
9598 is, it shouldn't gratuitously make bad or useless code.
9599
9600 For example:
9601
9602 @smallexample
9603 INTRINSIC ZABS
9604 CALL FOO(ZABS)
9605 END
9606 @end smallexample
9607
9608 @noindent
9609 When compiling the above with @option{-ff2c-intrinsics-disable},
9610 @command{g77} should indeed complain about passing @code{ZABS},
9611 but it still should compile, instead of rejecting
9612 the entire @code{CALL} statement.
9613 (Some of this is related to improving
9614 the compiler internals to improve how statements are analyzed.)
9615
9616 @node Non-standard Conversions
9617 @subsection Non-standard Conversions
9618
9619 @option{-Wconversion} and related should flag places where non-standard
9620 conversions are found.
9621 Perhaps much of this would be part of @option{-Wugly*}.
9622
9623 @node Non-standard Intrinsics
9624 @subsection Non-standard Intrinsics
9625
9626 @command{g77} needs a new option, like @option{-Wintrinsics}, to warn about use of
9627 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
9628 This would help find code that might fail silently when ported to another
9629 compiler.
9630
9631 @node Modifying DO Variable
9632 @subsection Modifying @code{DO} Variable
9633
9634 @command{g77} should warn about modifying @code{DO} variables
9635 via @code{EQUIVALENCE}.
9636 (The internal information gathered to produce this warning
9637 might also be useful in setting the
9638 internal ``doiter'' flag for a variable or even array
9639 reference within a loop, since that might produce faster code someday.)
9640
9641 For example, this code is invalid, so @command{g77} should warn about
9642 the invalid assignment to @samp{NOTHER}:
9643
9644 @smallexample
9645 EQUIVALENCE (I, NOTHER)
9646 DO I = 1, 100
9647    IF (I.EQ. 10) NOTHER = 20
9648 END DO
9649 @end smallexample
9650
9651 @node Better Pedantic Compilation
9652 @subsection Better Pedantic Compilation
9653
9654 @command{g77} needs to support @option{-fpedantic} more thoroughly,
9655 and use it only to generate
9656 warnings instead of rejecting constructs outright.
9657 Have it warn:
9658 if a variable that dimensions an array is not a dummy or placed
9659 explicitly in @code{COMMON} (F77 does not allow it to be
9660 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
9661 follow statement-function-definition statements; about all sorts of
9662 syntactic extensions.
9663
9664 @node Warn About Implicit Conversions
9665 @subsection Warn About Implicit Conversions
9666
9667 @command{g77} needs a @option{-Wpromotions} option to warn if source code appears
9668 to expect automatic, silent, and
9669 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
9670 constants to @code{REAL(KIND=2)} based on context.
9671
9672 For example, it would warn about cases like this:
9673
9674 @smallexample
9675 DOUBLE PRECISION FOO
9676 PARAMETER (TZPHI = 9.435784839284958)
9677 FOO = TZPHI * 3D0
9678 @end smallexample
9679
9680 @node Invalid Use of Hollerith Constant
9681 @subsection Invalid Use of Hollerith Constant
9682
9683 @command{g77} should disallow statements like @samp{RETURN 2HAB},
9684 which are invalid in both source forms
9685 (unlike @samp{RETURN (2HAB)},
9686 which probably still makes no sense but at least can
9687 be reliably parsed).
9688 Fixed-form processing rejects it, but not free-form, except
9689 in a way that is a bit difficult to understand.
9690
9691 @node Dummy Array Without Dimensioning Dummy
9692 @subsection Dummy Array Without Dimensioning Dummy
9693
9694 @command{g77} should complain when a list of dummy arguments containing an
9695 adjustable dummy array does
9696 not also contain every variable listed in the dimension list of the
9697 adjustable array.
9698
9699 Currently, @command{g77} does complain about a variable that
9700 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
9701 area, but this needs to be extended to catch cases where it doesn't appear in
9702 every dummy list that also lists any arrays it dimensions.
9703
9704 For example, @command{g77} should warn about the entry point @samp{ALT}
9705 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
9706 list of arguments:
9707
9708 @smallexample
9709 SUBROUTINE PRIMARY(ARRAY, ISIZE)
9710 REAL ARRAY(ISIZE)
9711 ENTRY ALT(ARRAY)
9712 @end smallexample
9713
9714 @node Invalid FORMAT Specifiers
9715 @subsection Invalid FORMAT Specifiers
9716
9717 @command{g77} should check @code{FORMAT} specifiers for validity
9718 as it does @code{FORMAT} statements.
9719
9720 For example, a diagnostic would be produced for:
9721
9722 @smallexample
9723 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
9724 @end smallexample
9725
9726 @node Ambiguous Dialects
9727 @subsection Ambiguous Dialects
9728
9729 @command{g77} needs a set of options such as @option{-Wugly*}, @option{-Wautomatic},
9730 @option{-Wvxt}, @option{-Wf90}, and so on.
9731 These would warn about places in the user's source where ambiguities
9732 are found, helpful in resolving ambiguities in the program's
9733 dialect or dialects.
9734
9735 @node Unused Labels
9736 @subsection Unused Labels
9737
9738 @command{g77} should warn about unused labels when @option{-Wunused} is in effect.
9739
9740 @node Informational Messages
9741 @subsection Informational Messages
9742
9743 @command{g77} needs an option to suppress information messages (notes).
9744 @option{-w} does this but also suppresses warnings.
9745 The default should be to suppress info messages.
9746
9747 Perhaps info messages should simply be eliminated.
9748
9749 @node Uninitialized Variables at Run Time
9750 @subsection Uninitialized Variables at Run Time
9751
9752 @command{g77} needs an option to initialize everything (not otherwise
9753 explicitly initialized) to ``weird''
9754 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
9755 largest-magnitude integers, would help track down references to
9756 some kinds of uninitialized variables at run time.
9757
9758 Note that use of the options @samp{-O -Wuninitialized} can catch
9759 many such bugs at compile time.
9760
9761 @node Portable Unformatted Files
9762 @subsection Portable Unformatted Files
9763
9764 @cindex unformatted files
9765 @cindex file formats
9766 @cindex binary data
9767 @cindex byte ordering
9768 @command{g77} has no facility for exchanging unformatted files with systems
9769 using different number formats---even differing only in endianness (byte
9770 order)---or written by other compilers.  Some compilers provide
9771 facilities at least for doing byte-swapping during unformatted I/O.
9772
9773 It is unrealistic to expect to cope with exchanging unformatted files
9774 with arbitrary other compiler runtimes, but the @command{g77} runtime
9775 should at least be able to read files written by @command{g77} on systems
9776 with different number formats, particularly if they differ only in byte
9777 order.
9778
9779 In case you do need to write a program to translate to or from
9780 @command{g77} (@code{libf2c}) unformatted files, they are written as
9781 follows:
9782 @table @asis
9783 @item Sequential
9784 Unformatted sequential records consist of
9785 @enumerate
9786 @item
9787 A number giving the length of the record contents;
9788 @item
9789 the length of record contents again (for backspace).
9790 @end enumerate
9791
9792 The record length is of C type
9793 @code{long}; this means that it is 8 bytes on 64-bit systems such as
9794 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
9795 Consequently such files cannot be exchanged between 64-bit and 32-bit
9796 systems, even with the same basic number format.
9797 @item Direct access
9798 Unformatted direct access files form a byte stream of length
9799 @var{records}*@var{recl} bytes, where @var{records} is the maximum
9800 record number (@code{REC=@var{records}}) written and @var{recl} is the
9801 record length in bytes specified in the @code{OPEN} statement
9802 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
9803 the relevant @code{WRITE} statement.  Dummy records with arbitrary
9804 contents appear in the file in place of records which haven't been
9805 written.
9806 @end table
9807
9808 Thus for exchanging a sequential or direct access unformatted file
9809 between big- and little-endian 32-bit systems using IEEE 754 floating
9810 point it would be sufficient to reverse the bytes in consecutive words
9811 in the file if, and @emph{only} if, only @code{REAL*4}, @code{COMPLEX},
9812 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
9813 @command{g77}.
9814
9815 If necessary, it is possible to do byte-oriented i/o with @command{g77}'s
9816 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
9817 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
9818 array or a set of scalars.
9819
9820 @cindex HDF
9821 @cindex PDB
9822 If you need to exchange binary data between arbitrary system and
9823 compiler variations, we recommend using a portable binary format with
9824 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
9825 or PACT's PDB@footnote{No, not @emph{that} one.}
9826 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
9827 say, CDF or XDR, HDF-like systems write in the native number formats and
9828 only incur overhead when they are read on a system with a different
9829 format.)  A future @command{g77} runtime library should use such
9830 techniques.
9831
9832 @node Better List-directed I/O
9833 @subsection Better List-directed I/O
9834
9835 Values output using list-directed I/O
9836 (@samp{PRINT *, R, D})
9837 should be written with a field width, precision, and so on
9838 appropriate for the type (precision) of each value.
9839
9840 (Currently, no distinction is made between single-precision
9841 and double-precision values
9842 by @code{libf2c}.)
9843
9844 It is likely this item will require the @code{libg77} project
9845 to be undertaken.
9846
9847 In the meantime, use of formatted I/O is recommended.
9848 While it might be of little consolation,
9849 @command{g77} does support @samp{FORMAT(F<WIDTH>.4)}, for example,
9850 as long as @samp{WIDTH} is defined as a named constant
9851 (via @code{PARAMETER}).
9852 That at least allows some compile-time specification
9853 of the precision of a data type,
9854 perhaps controlled by preprocessing directives.
9855
9856 @node Default to Console I/O
9857 @subsection Default to Console I/O
9858
9859 The default I/O units,
9860 specified by @samp{READ @var{fmt}},
9861 @samp{READ (UNIT=*)},
9862 @samp{WRITE (UNIT=*)}, and
9863 @samp{PRINT @var{fmt}},
9864 should not be units 5 (input) and 6 (output),
9865 but, rather, unit numbers not normally available
9866 for use in statements such as @code{OPEN} and @code{CLOSE}.
9867
9868 Changing this would allow a program to connect units 5 and 6
9869 to files via @code{OPEN},
9870 but still use @samp{READ (UNIT=*)} and @samp{PRINT}
9871 to do I/O to the ``console''.
9872
9873 This change probably requires the @code{libg77} project.
9874
9875 @node Labels Visible to Debugger
9876 @subsection Labels Visible to Debugger
9877
9878 @command{g77} should output debugging information for statements labels,
9879 for use by debuggers that know how to support them.
9880 Same with weirder things like construct names.
9881 It is not yet known if any debug formats or debuggers support these.
9882
9883 @node Disappointments
9884 @section Disappointments and Misunderstandings
9885
9886 These problems are perhaps regrettable, but we don't know any practical
9887 way around them for now.
9888
9889 @menu
9890 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
9891                                               external name @samp{foo_}.
9892 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
9893                                               and @samp{SUBROUTINE FOO}.
9894 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
9895 @end menu
9896
9897 @node Mangling of Names
9898 @subsection Mangling of Names in Source Code
9899 @cindex naming issues
9900 @cindex external names
9901 @cindex common blocks
9902 @cindex name space
9903 @cindex underscore
9904
9905 The current external-interface design, which includes naming of
9906 external procedures, COMMON blocks, and the library interface,
9907 has various usability problems, including things like adding
9908 underscores where not really necessary (and preventing easier
9909 inter-language operability) and yet not providing complete
9910 namespace freedom for user C code linked with Fortran apps (due
9911 to the naming of functions in the library, among other things).
9912
9913 Project GNU should at least get all this ``right'' for systems
9914 it fully controls, such as the Hurd, and provide defaults and
9915 options for compatibility with existing systems and interoperability
9916 with popular existing compilers.
9917
9918 @node Multiple Definitions of External Names
9919 @subsection Multiple Definitions of External Names
9920 @cindex block data
9921 @cindex BLOCK DATA statement
9922 @cindex statements, BLOCK DATA
9923 @cindex @code{COMMON} statement
9924 @cindex statements, @code{COMMON}
9925 @cindex naming conflicts
9926
9927 @command{g77} doesn't allow a common block and an external procedure or
9928 @code{BLOCK DATA} to have the same name.
9929 Some systems allow this, but @command{g77} does not,
9930 to be compatible with @command{f2c}.
9931
9932 @command{g77} could special-case the way it handles
9933 @code{BLOCK DATA}, since it is not compatible with @command{f2c} in this
9934 particular area (necessarily, since @command{g77} offers an
9935 important feature here), but
9936 it is likely that such special-casing would be very annoying to people
9937 with programs that use @samp{EXTERNAL FOO}, with no other mention of
9938 @samp{FOO} in the same program unit, to refer to external procedures, since
9939 the result would be that @command{g77} would treat these references as requests to
9940 force-load BLOCK DATA program units.
9941
9942 In that case, if @command{g77} modified
9943 names of @code{BLOCK DATA} so they could have the same names as
9944 @code{COMMON}, users
9945 would find that their programs wouldn't link because the @samp{FOO} procedure
9946 didn't have its name translated the same way.
9947
9948 (Strictly speaking,
9949 @command{g77} could emit a null-but-externally-satisfying definition of
9950 @samp{FOO} with its name transformed as if it had been a
9951 @code{BLOCK DATA}, but that probably invites more trouble than it's
9952 worth.)
9953
9954 @node Limitation on Implicit Declarations
9955 @subsection Limitation on Implicit Declarations
9956 @cindex IMPLICIT CHARACTER*(*) statement
9957 @cindex statements, IMPLICIT CHARACTER*(*)
9958
9959 @command{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
9960 This is not standard-conforming.
9961
9962 @node Non-bugs
9963 @section Certain Changes We Don't Want to Make
9964
9965 This section lists changes that people frequently request, but which
9966 we do not make because we think GNU Fortran is better without them.
9967
9968 @menu
9969 * Backslash in Constants::           Why @samp{'\\'} is a constant that
9970                                        is one, not two, characters long.
9971 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
9972                                        @samp{COMMON VAR}.
9973 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
9974 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
9975                                        single-precision constant,
9976                                        and might be interpreted as
9977                                        @samp{9.435785} or similar.
9978 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
9979 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
9980                                        not behave as expected.
9981 @end menu
9982
9983 @node Backslash in Constants
9984 @subsection Backslash in Constants
9985 @cindex backslash
9986 @cindex @command{f77} support
9987 @cindex support, @command{f77}
9988
9989 In the opinion of many experienced Fortran users,
9990 @option{-fno-backslash} should be the default, not @option{-fbackslash},
9991 as currently set by @command{g77}.
9992
9993 First of all, you can always specify
9994 @option{-fno-backslash} to turn off this processing.
9995
9996 Despite not being within the spirit (though apparently within the
9997 letter) of the ANSI FORTRAN 77 standard, @command{g77} defaults to
9998 @option{-fbackslash} because that is what most UNIX @command{f77} commands
9999 default to, and apparently lots of code depends on this feature.
10000
10001 This is a particularly troubling issue.
10002 The use of a C construct in the midst of Fortran code
10003 is bad enough, worse when it makes existing Fortran
10004 programs stop working (as happens when programs written
10005 for non-UNIX systems are ported to UNIX systems with
10006 compilers that provide the @option{-fbackslash} feature
10007 as the default---sometimes with no option to turn it off).
10008
10009 The author of GNU Fortran wished, for reasons of linguistic
10010 purity, to make @option{-fno-backslash} the default for GNU
10011 Fortran and thus require users of UNIX @command{f77} and @command{f2c}
10012 to specify @option{-fbackslash} to get the UNIX behavior.
10013
10014 However, the realization that @command{g77} is intended as
10015 a replacement for @emph{UNIX} @command{f77}, caused the author
10016 to choose to make @command{g77} as compatible with
10017 @command{f77} as feasible, which meant making @option{-fbackslash}
10018 the default.
10019
10020 The primary focus on compatibility is at the source-code
10021 level, and the question became ``What will users expect
10022 a replacement for @command{f77} to do, by default?''
10023 Although at least one UNIX @command{f77} does not provide
10024 @option{-fbackslash} as a default, it appears that
10025 the majority of them do, which suggests that
10026 the majority of code that is compiled by UNIX @command{f77}
10027 compilers expects @option{-fbackslash} to be the default.
10028
10029 It is probably the case that more code exists
10030 that would @emph{not} work with @option{-fbackslash}
10031 in force than code that requires it be in force.
10032
10033 However, most of @emph{that} code is not being compiled
10034 with @command{f77},
10035 and when it is, new build procedures (shell scripts,
10036 makefiles, and so on) must be set up anyway so that
10037 they work under UNIX.
10038 That makes a much more natural and safe opportunity for
10039 non-UNIX users to adapt their build procedures for
10040 @command{g77}'s default of @option{-fbackslash} than would
10041 exist for the majority of UNIX @command{f77} users who
10042 would have to modify existing, working build procedures
10043 to explicitly specify @option{-fbackslash} if that was
10044 not the default.
10045
10046 One suggestion has been to configure the default for
10047 @option{-fbackslash} (and perhaps other options as well)
10048 based on the configuration of @command{g77}.
10049
10050 This is technically quite straightforward, but will be avoided
10051 even in cases where not configuring defaults to be
10052 dependent on a particular configuration greatly inconveniences
10053 some users of legacy code.
10054
10055 Many users appreciate the GNU compilers because they provide an
10056 environment that is uniform across machines.
10057 These users would be
10058 inconvenienced if the compiler treated things like the
10059 format of the source code differently on certain machines.
10060
10061 Occasionally users write programs intended only for a particular machine
10062 type.
10063 On these occasions, the users would benefit if the GNU Fortran compiler
10064 were to support by default the same dialect as the other compilers on
10065 that machine.
10066 But such applications are rare.
10067 And users writing a
10068 program to run on more than one type of machine cannot possibly benefit
10069 from this kind of compatibility.
10070 (This is consistent with the design goals for @command{gcc}.
10071 To change them for @command{g77}, you must first change them
10072 for @command{gcc}.
10073 Do not ask the maintainers of @command{g77} to do this for you,
10074 or to disassociate @command{g77} from the widely understood, if
10075 not widely agreed-upon, goals for GNU compilers in general.)
10076
10077 This is why GNU Fortran does and will treat backslashes in the same
10078 fashion on all types of machines (by default).
10079 @xref{Direction of Language Development}, for more information on
10080 this overall philosophy guiding the development of the GNU Fortran
10081 language.
10082
10083 Of course, users strongly concerned about portability should indicate
10084 explicitly in their build procedures which options are expected
10085 by their source code, or write source code that has as few such
10086 expectations as possible.
10087
10088 For example, avoid writing code that depends on backslash (@samp{\})
10089 being interpreted either way in particular, such as by
10090 starting a program unit with:
10091
10092 @smallexample
10093 CHARACTER BACKSL
10094 PARAMETER (BACKSL = '\\')
10095 @end smallexample
10096
10097 @noindent
10098 Then, use concatenation of @samp{BACKSL} anyplace a backslash
10099 is desired.
10100 In this way, users can write programs which have the same meaning
10101 in many Fortran dialects.
10102
10103 (However, this technique does not work for Hollerith constants---which
10104 is just as well, since the only generally portable uses for Hollerith
10105 constants are in places where character constants can and should
10106 be used instead, for readability.)
10107
10108 @node Initializing Before Specifying
10109 @subsection Initializing Before Specifying
10110 @cindex initialization, statement placement
10111 @cindex placing initialization statements
10112
10113 @command{g77} does not allow @samp{DATA VAR/1/} to appear in the
10114 source code before @samp{COMMON VAR},
10115 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
10116 In general, @command{g77} requires initialization of a variable
10117 or array to be specified @emph{after} all other specifications
10118 of attributes (type, size, placement, and so on) of that variable
10119 or array are specified (though @emph{confirmation} of data type is
10120 permitted).
10121
10122 It is @emph{possible} @command{g77} will someday allow all of this,
10123 even though it is not allowed by the FORTRAN 77 standard.
10124
10125 Then again, maybe it is better to have
10126 @command{g77} always require placement of @code{DATA}
10127 so that it can possibly immediately write constants
10128 to the output file, thus saving time and space.
10129
10130 That is, @samp{DATA A/1000000*1/} should perhaps always
10131 be immediately writable to canonical assembler, unless it's already known
10132 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
10133 and to do this it cannot be followed by @samp{COMMON A}.
10134
10135 @node Context-Sensitive Intrinsicness
10136 @subsection Context-Sensitive Intrinsicness
10137 @cindex intrinsics, context-sensitive
10138 @cindex context-sensitive intrinsics
10139
10140 @command{g77} treats procedure references to @emph{possible} intrinsic
10141 names as always enabling their intrinsic nature, regardless of
10142 whether the @emph{form} of the reference is valid for that
10143 intrinsic.
10144
10145 For example, @samp{CALL SQRT} is interpreted by @command{g77} as
10146 an invalid reference to the @code{SQRT} intrinsic function,
10147 because the reference is a subroutine invocation.
10148
10149 First, @command{g77} recognizes the statement @samp{CALL SQRT}
10150 as a reference to a @emph{procedure} named @samp{SQRT}, not
10151 to a @emph{variable} with that name (as it would for a statement
10152 such as @samp{V = SQRT}).
10153
10154 Next, @command{g77} establishes that, in the program unit being compiled,
10155 @code{SQRT} is an intrinsic---not a subroutine that
10156 happens to have the same name as an intrinsic (as would be
10157 the case if, for example, @samp{EXTERNAL SQRT} was present).
10158
10159 Finally, @command{g77} recognizes that the @emph{form} of the
10160 reference is invalid for that particular intrinsic.
10161 That is, it recognizes that it is invalid for an intrinsic
10162 @emph{function}, such as @code{SQRT}, to be invoked as
10163 a @emph{subroutine}.
10164
10165 At that point, @command{g77} issues a diagnostic.
10166
10167 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
10168 references an external subroutine of their own, not an
10169 intrinsic function.
10170
10171 However, @command{g77} knows about intrinsic
10172 subroutines, not just functions, and is able to support both having
10173 the same names, for example.
10174
10175 As a result of this, @command{g77} rejects calls
10176 to intrinsics that are not subroutines, and function invocations
10177 of intrinsics that are not functions, just as it (and most compilers)
10178 rejects invocations of intrinsics with the wrong number (or types)
10179 of arguments.
10180
10181 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
10182 a user-written subroutine named @samp{SQRT}.
10183
10184 @node Context-Sensitive Constants
10185 @subsection Context-Sensitive Constants
10186 @cindex constants, context-sensitive
10187 @cindex context-sensitive constants
10188
10189 @command{g77} does not use context to determine the types of
10190 constants or named constants (@code{PARAMETER}), except
10191 for (non-standard) typeless constants such as @samp{'123'O}.
10192
10193 For example, consider the following statement:
10194
10195 @smallexample
10196 PRINT *, 9.435784839284958 * 2D0
10197 @end smallexample
10198
10199 @noindent
10200 @command{g77} will interpret the (truncated) constant
10201 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
10202 constant, because the suffix @code{D0} is not specified.
10203
10204 As a result, the output of the above statement when
10205 compiled by @command{g77} will appear to have ``less precision''
10206 than when compiled by other compilers.
10207
10208 In these and other cases, some compilers detect the
10209 fact that a single-precision constant is used in
10210 a double-precision context and therefore interpret the
10211 single-precision constant as if it was @emph{explicitly}
10212 specified as a double-precision constant.
10213 (This has the effect of appending @emph{decimal}, not
10214 @emph{binary}, zeros to the fractional part of the
10215 number---producing different computational results.)
10216
10217 The reason this misfeature is dangerous is that a slight,
10218 apparently innocuous change to the source code can change
10219 the computational results.
10220 Consider:
10221
10222 @smallexample
10223 REAL ALMOST, CLOSE
10224 DOUBLE PRECISION FIVE
10225 PARAMETER (ALMOST = 5.000000000001)
10226 FIVE = 5
10227 CLOSE = 5.000000000001
10228 PRINT *, 5.000000000001 - FIVE
10229 PRINT *, ALMOST - FIVE
10230 PRINT *, CLOSE - FIVE
10231 END
10232 @end smallexample
10233
10234 @noindent
10235 Running the above program should
10236 result in the same value being
10237 printed three times.
10238 With @command{g77} as the compiler,
10239 it does.
10240
10241 However, compiled by many other compilers,
10242 running the above program would print
10243 two or three distinct values, because
10244 in two or three of the statements, the
10245 constant @samp{5.000000000001}, which
10246 on most systems is exactly equal to @samp{5.}
10247 when interpreted as a single-precision constant,
10248 is instead interpreted as a double-precision
10249 constant, preserving the represented
10250 precision.
10251 However, this ``clever'' promotion of
10252 type does not extend to variables or,
10253 in some compilers, to named constants.
10254
10255 Since programmers often are encouraged to replace manifest
10256 constants or permanently-assigned variables with named
10257 constants (@code{PARAMETER} in Fortran), and might need
10258 to replace some constants with variables having the same
10259 values for pertinent portions of code,
10260 it is important that compilers treat code so modified in the
10261 same way so that the results of such programs are the same.
10262 @command{g77} helps in this regard by treating constants just
10263 the same as variables in terms of determining their types
10264 in a context-independent way.
10265
10266 Still, there is a lot of existing Fortran code that has
10267 been written to depend on the way other compilers freely
10268 interpret constants' types based on context, so anything
10269 @command{g77} can do to help flag cases of this in such code
10270 could be very helpful.
10271
10272 @node Equivalence Versus Equality
10273 @subsection Equivalence Versus Equality
10274 @cindex .EQV., with integer operands
10275 @cindex comparing logical expressions
10276 @cindex logical expressions, comparing
10277
10278 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
10279 is not supported, except via @option{-fugly-logint}, which is not
10280 recommended except for legacy code (where the behavior expected
10281 by the @emph{code} is assumed).
10282
10283 Legacy code should be changed, as resources permit, to use @code{.EQV.}
10284 and @code{.NEQV.} instead, as these are permitted by the various
10285 Fortran standards.
10286
10287 New code should never be written expecting @code{.EQ.} or @code{.NE.}
10288 to work if either of its operands is @code{LOGICAL}.
10289
10290 The problem with supporting this ``feature'' is that there is
10291 unlikely to be consensus on how it works, as illustrated by the
10292 following sample program:
10293
10294 @smallexample
10295 LOGICAL L,M,N
10296 DATA L,M,N /3*.FALSE./
10297 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
10298 END
10299 @end smallexample
10300
10301 The issue raised by the above sample program is: what is the
10302 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
10303 @code{LOGICAL} operands?
10304
10305 Some programmers will argue that it is the same as the precedence
10306 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
10307 operands.
10308 By this interpretation, the subexpression @samp{M.EQ.N} must be
10309 evaluated first in the above program, resulting in a program that,
10310 when run, does not execute the @code{PRINT} statement.
10311
10312 Other programmers will argue that the precedence is the same as
10313 the precedence for @code{.EQV.}, which is restricted by the standards
10314 to @code{LOGICAL} operands.
10315 By this interpretation, the subexpression @samp{L.AND.M} must be
10316 evaluated first, resulting in a program that @emph{does} execute
10317 the @code{PRINT} statement.
10318
10319 Assigning arbitrary semantic interpretations to syntactic expressions
10320 that might legitimately have more than one ``obvious'' interpretation
10321 is generally unwise.
10322
10323 The creators of the various Fortran standards have done a good job
10324 in this case, requiring a distinct set of operators (which have their
10325 own distinct precedence) to compare @code{LOGICAL} operands.
10326 This requirement results in expression syntax with more certain
10327 precedence (without requiring substantial context), making it easier
10328 for programmers to read existing code.
10329 @command{g77} will avoid muddying up elements of the Fortran language
10330 that were well-designed in the first place.
10331
10332 (Ask C programmers about the precedence of expressions such as
10333 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
10334 you, without knowing more context, whether the @samp{&} and @samp{-}
10335 operators are infix (binary) or unary!)
10336
10337 Most dangerous of all is the fact that,
10338 even assuming consensus on its meaning,
10339 an expression like @samp{L.AND.M.EQ.N},
10340 if it is the result of a typographical error,
10341 doesn't @emph{look} like it has such a typo.
10342 Even experienced Fortran programmers would not likely notice that
10343 @samp{L.AND.M.EQV.N} was, in fact, intended.
10344
10345 So, this is a prime example of a circumstance in which
10346 a quality compiler diagnoses the code,
10347 instead of leaving it up to someone debugging it
10348 to know to turn on special compiler options
10349 that might diagnose it.
10350
10351 @node Order of Side Effects
10352 @subsection Order of Side Effects
10353 @cindex side effects, order of evaluation
10354 @cindex order of evaluation, side effects
10355
10356 @command{g77} does not necessarily produce code that, when run, performs
10357 side effects (such as those performed by function invocations)
10358 in the same order as in some other compiler---or even in the same
10359 order as another version, port, or invocation (using different
10360 command-line options) of @command{g77}.
10361
10362 It is never safe to depend on the order of evaluation of side effects.
10363 For example, an expression like this may very well behave differently
10364 from one compiler to another:
10365
10366 @smallexample
10367 J = IFUNC() - IFUNC()
10368 @end smallexample
10369
10370 @noindent
10371 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
10372 order.
10373 Either invocation might happen first.
10374 If @samp{IFUNC} returns 5 the first time it is invoked, and
10375 returns 12 the second time, @samp{J} might end up with the
10376 value @samp{7}, or it might end up with @samp{-7}.
10377
10378 Generally, in Fortran, procedures with side-effects intended to
10379 be visible to the caller are best designed as @emph{subroutines},
10380 not functions.
10381 Examples of such side-effects include:
10382
10383 @itemize @bullet
10384 @item
10385 The generation of random numbers
10386 that are intended to influence return values.
10387
10388 @item
10389 Performing I/O
10390 (other than internal I/O to local variables).
10391
10392 @item
10393 Updating information in common blocks.
10394 @end itemize
10395
10396 An example of a side-effect that is not intended to be visible
10397 to the caller is a function that maintains a cache of recently
10398 calculated results, intended solely to speed repeated invocations
10399 of the function with identical arguments.
10400 Such a function can be safely used in expressions, because
10401 if the compiler optimizes away one or more calls to the
10402 function, operation of the program is unaffected (aside
10403 from being speeded up).
10404
10405 @node Warnings and Errors
10406 @section Warning Messages and Error Messages
10407
10408 @cindex error messages
10409 @cindex warnings vs errors
10410 @cindex messages, warning and error
10411 The GNU compiler can produce two kinds of diagnostics: errors and
10412 warnings.
10413 Each kind has a different purpose:
10414
10415 @itemize @w{}
10416 @item
10417 @emph{Errors} report problems that make it impossible to compile your
10418 program.
10419 GNU Fortran reports errors with the source file name, line
10420 number, and column within the line where the problem is apparent.
10421
10422 @item
10423 @emph{Warnings} report other unusual conditions in your code that
10424 @emph{might} indicate a problem, although compilation can (and does)
10425 proceed.
10426 Warning messages also report the source file name, line number,
10427 and column information,
10428 but include the text @samp{warning:} to distinguish them
10429 from error messages.
10430 @end itemize
10431
10432 Warnings might indicate danger points where you should check to make sure
10433 that your program really does what you intend; or the use of obsolete
10434 features; or the use of nonstandard features of GNU Fortran.
10435 Many warnings are issued only if you ask for them, with one of the
10436 @option{-W} options (for instance, @option{-Wall} requests a variety of
10437 useful warnings).
10438
10439 @emph{Note:} Currently, the text of the line and a pointer to the column
10440 is printed in most @command{g77} diagnostics.
10441
10442 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
10443 more detail on these and related command-line options.
10444
10445 @node Open Questions
10446 @chapter Open Questions
10447
10448 Please consider offering useful answers to these questions!
10449
10450 @itemize @bullet
10451 @item
10452 @code{LOC()} and other intrinsics are probably somewhat misclassified.
10453 Is the a need for more precise classification of intrinsics, and if so,
10454 what are the appropriate groupings?
10455 Is there a need to individually
10456 enable/disable/delete/hide intrinsics from the command line?
10457 @end itemize
10458
10459 @node Bugs
10460 @chapter Reporting Bugs
10461 @cindex bugs
10462 @cindex reporting bugs
10463
10464 Your bug reports play an essential role in making GNU Fortran reliable.
10465
10466 When you encounter a problem, the first thing to do is to see if it is
10467 already known.
10468 @xref{Trouble}.
10469 If it isn't known, then you should report the problem.
10470
10471 Reporting a bug might help you by bringing a solution to your problem, or
10472 it might not.
10473 (If it does not, look in the service directory; see
10474 @ref{Service}.)
10475 In any case, the principal function of a bug report is
10476 to help the entire community by making the next version of GNU Fortran work
10477 better.
10478 Bug reports are your contribution to the maintenance of GNU Fortran.
10479
10480 Since the maintainers are very overloaded, we cannot respond to every
10481 bug report.
10482 However, if the bug has not been fixed, we are likely to
10483 send you a patch and ask you to tell us whether it works.
10484
10485 In order for a bug report to serve its purpose, you must include the
10486 information that makes for fixing the bug.
10487
10488 @menu
10489 * Criteria: Bug Criteria.    Have you really found a bug?
10490 * Where: Bug Lists.          Where to send your bug report.
10491 * Reporting: Bug Reporting.  How to report a bug effectively.
10492 @end menu
10493
10494 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
10495 for information on problems we already know about.
10496
10497 @xref{Service,,How To Get Help with GNU Fortran},
10498 for information on where to ask for help.
10499
10500 @node Bug Criteria
10501 @section Have You Found a Bug?
10502 @cindex bug criteria
10503
10504 If you are not sure whether you have found a bug, here are some guidelines:
10505
10506 @itemize @bullet
10507 @cindex fatal signal
10508 @cindex core dump
10509 @item
10510 If the compiler gets a fatal signal, for any input whatever, that is a
10511 compiler bug.
10512 Reliable compilers never crash---they just remain obsolete.
10513
10514 @cindex invalid assembly code
10515 @cindex assembly code, invalid
10516 @item
10517 If the compiler produces invalid assembly code, for any input whatever,
10518 @c (except an @code{asm} statement),
10519 that is a compiler bug, unless the
10520 compiler reports errors (not just warnings) which would ordinarily
10521 prevent the assembler from being run.
10522
10523 @cindex undefined behavior
10524 @cindex undefined function value
10525 @item
10526 If the compiler produces valid assembly code that does not correctly
10527 execute the input source code, that is a compiler bug.
10528
10529 However, you must double-check to make sure, because you might have run
10530 into an incompatibility between GNU Fortran and traditional Fortran.
10531 @c (@pxref{Incompatibilities}).
10532 These incompatibilities might be considered
10533 bugs, but they are inescapable consequences of valuable features.
10534
10535 Or you might have a program whose behavior is undefined, which happened
10536 by chance to give the desired results with another Fortran compiler.
10537 It is best to check the relevant Fortran standard thoroughly if
10538 it is possible that the program indeed does something undefined.
10539
10540 After you have localized the error to a single source line, it should
10541 be easy to check for these things.
10542 If your program is correct and well defined, you have found
10543 a compiler bug.
10544
10545 It might help if, in your submission, you identified the specific
10546 language in the relevant Fortran standard that specifies the
10547 desired behavior, if it isn't likely to be obvious and agreed-upon
10548 by all Fortran users.
10549
10550 @item
10551 If the compiler produces an error message for valid input, that is a
10552 compiler bug.
10553
10554 @cindex invalid input
10555 @item
10556 If the compiler does not produce an error message for invalid input,
10557 that is a compiler bug.
10558 However, you should note that your idea of
10559 ``invalid input'' might be someone else's idea
10560 of ``an extension'' or ``support for traditional practice''.
10561
10562 @item
10563 If you are an experienced user of Fortran compilers, your suggestions
10564 for improvement of GNU Fortran are welcome in any case.
10565 @end itemize
10566
10567 Many, perhaps most, bug reports against @command{g77} turn out to
10568 be bugs in the user's code.
10569 While we find such bug reports educational, they sometimes take
10570 a considerable amount of time to track down or at least respond
10571 to---time we could be spending making @command{g77}, not some user's
10572 code, better.
10573
10574 Some steps you can take to verify that the bug is not certainly
10575 in the code you're compiling with @command{g77}:
10576
10577 @itemize @bullet
10578 @item
10579 Compile your code using the @command{g77} options @samp{-W -Wall -O}.
10580 These options enable many useful warning; the @option{-O} option
10581 enables flow analysis that enables the uninitialized-variable
10582 warning.
10583
10584 If you investigate the warnings and find evidence of possible bugs
10585 in your code, fix them first and retry @command{g77}.
10586
10587 @item
10588 Compile your code using the @command{g77} options @option{-finit-local-zero},
10589 @option{-fno-automatic}, @option{-ffloat-store}, and various
10590 combinations thereof.
10591
10592 If your code works with any of these combinations, that is not
10593 proof that the bug isn't in @command{g77}---a @command{g77} bug exposed
10594 by your code might simply be avoided, or have a different, more subtle
10595 effect, when different options are used---but it can be a
10596 strong indicator that your code is making unwarranted assumptions
10597 about the Fortran dialect and/or underlying machine it is
10598 being compiled and run on.
10599
10600 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10601 for information on the @option{-fno-automatic} and
10602 @option{-finit-local-zero} options and how to convert
10603 their use into selective changes in your own code.
10604
10605 @item
10606 @pindex ftnchek
10607 Validate your code with @command{ftnchek} or a similar code-checking
10608 tool.
10609 @command{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
10610 or @uref{ftp://ftp.dsm.fordham.edu}.
10611
10612 @pindex make
10613 @cindex Makefile example
10614 Here are some sample @file{Makefile} rules using @command{ftnchek}
10615 ``project'' files to do cross-file checking and @command{sfmakedepend}
10616 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
10617 to maintain dependencies automatically.
10618 These assume the use of GNU @command{make}.
10619
10620 @smallexample
10621 # Dummy suffix for ftnchek targets:
10622 .SUFFIXES: .chek
10623 .PHONY: chekall
10624
10625 # How to compile .f files (for implicit rule):
10626 FC = g77
10627 # Assume `include' directory:
10628 FFLAGS = -Iinclude -g -O -Wall
10629
10630 # Flags for ftnchek:
10631 CHEK1 = -array=0 -include=includes -noarray
10632 CHEK2 = -nonovice -usage=1 -notruncation
10633 CHEKFLAGS = $(CHEK1) $(CHEK2)
10634
10635 # Run ftnchek with all the .prj files except the one corresponding
10636 # to the target's root:
10637 %.chek : %.f ; \
10638   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
10639     -noextern -library $<
10640
10641 # Derive a project file from a source file:
10642 %.prj : %.f ; \
10643   ftnchek $(CHEKFLAGS) -noextern -project -library $<
10644
10645 # The list of objects is assumed to be in variable OBJS.
10646 # Sources corresponding to the objects:
10647 SRCS = $(OBJS:%.o=%.f)
10648 # ftnchek project files:
10649 PRJS = $(OBJS:%.o=%.prj)
10650
10651 # Build the program
10652 prog: $(OBJS) ; \
10653   $(FC) -o $@ $(OBJS)
10654
10655 chekall: $(PRJS) ; \
10656   ftnchek $(CHEKFLAGS) $(PRJS)
10657
10658 prjs: $(PRJS)
10659
10660 # For Emacs M-x find-tag:
10661 TAGS: $(SRCS) ; \
10662   etags $(SRCS)
10663
10664 # Rebuild dependencies:
10665 depend: ; \
10666   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
10667 @end smallexample
10668
10669 @item
10670 Try your code out using other Fortran compilers, such as @command{f2c}.
10671 If it does not work on at least one other compiler (assuming the
10672 compiler supports the features the code needs), that is a strong
10673 indicator of a bug in the code.
10674
10675 However, even if your code works on many compilers @emph{except}
10676 @command{g77}, that does @emph{not} mean the bug is in @command{g77}.
10677 It might mean the bug is in your code, and that @command{g77} simply
10678 exposes it more readily than other compilers.
10679 @end itemize
10680
10681 @node Bug Lists
10682 @section Where to Report Bugs
10683 @cindex bug report mailing lists
10684 @kindex @value{email-bugs}
10685 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
10686
10687 Often people think of posting bug reports to a newsgroup instead of
10688 mailing them.
10689 This sometimes appears to work, but it has one problem which can be
10690 crucial: a newsgroup posting does not contain a mail path back to the
10691 sender.
10692 Thus, if maintainers need more information, they might be unable
10693 to reach you.  For this reason, you should always send bug reports by
10694 mail to the proper mailing list.
10695
10696 As a last resort, send bug reports on paper to:
10697
10698 @example
10699 GNU Compiler Bugs
10700 Free Software Foundation
10701 59 Temple Place - Suite 330
10702 Boston, MA 02111-1307, USA
10703 @end example
10704
10705 @node Bug Reporting
10706 @section How to Report Bugs
10707 @cindex compiler bugs, reporting
10708
10709 The fundamental principle of reporting bugs usefully is this:
10710 @strong{report all the facts}.
10711 If you are not sure whether to state a
10712 fact or leave it out, state it!
10713
10714 Often people omit facts because they think they know what causes the
10715 problem and they conclude that some details don't matter.
10716 Thus, you might
10717 assume that the name of the variable you use in an example does not matter.
10718 Well, probably it doesn't, but one cannot be sure.
10719 Perhaps the bug is a
10720 stray memory reference which happens to fetch from the location where that
10721 name is stored in memory; perhaps, if the name were different, the contents
10722 of that location would fool the compiler into doing the right thing despite
10723 the bug.
10724 Play it safe and give a specific, complete example.
10725 That is the
10726 easiest thing for you to do, and the most helpful.
10727
10728 Keep in mind that the purpose of a bug report is to enable someone to
10729 fix the bug if it is not known.
10730 It isn't very important what happens if
10731 the bug is already known.
10732 Therefore, always write your bug reports on
10733 the assumption that the bug is not known.
10734
10735 Sometimes people give a few sketchy facts and ask, ``Does this ring a
10736 bell?''
10737 This cannot help us fix a bug, so it is rarely helpful.
10738 We respond by asking for enough details to enable us to investigate.
10739 You might as well expedite matters by sending them to begin with.
10740 (Besides, there are enough bells ringing around here as it is.)
10741
10742 Try to make your bug report self-contained.
10743 If we have to ask you for
10744 more information, it is best if you include all the previous information
10745 in your response, as well as the information that was missing.
10746
10747 Please report each bug in a separate message.
10748 This makes it easier for
10749 us to track which bugs have been fixed and to forward your bugs reports
10750 to the appropriate maintainer.
10751
10752 Do not compress and encode any part of your bug report using programs
10753 such as @file{uuencode}.
10754 If you do so it will slow down the processing
10755 of your bug.
10756 If you must submit multiple large files, use @file{shar},
10757 which allows us to read your message without having to run any
10758 decompression programs.
10759
10760 (As a special exception for GNU Fortran bug-reporting, at least
10761 for now, if you are sending more than a few lines of code, if
10762 your program's source file format contains ``interesting'' things
10763 like trailing spaces or strange characters, or if you need to
10764 include binary data files, it is acceptable to put all the
10765 files together in a @command{tar} archive, and, whether you need to
10766 do that, it is acceptable to then compress the single file (@command{tar}
10767 archive or source file)
10768 using @command{gzip} and encode it via @command{uuencode}.
10769 Do not use any MIME stuff---the current maintainer can't decode this.
10770 Using @command{compress} instead of @command{gzip} is acceptable, assuming
10771 you have licensed the use of the patented algorithm in
10772 @command{compress} from Unisys.)
10773
10774 To enable someone to investigate the bug, you should include all these
10775 things:
10776
10777 @itemize @bullet
10778 @item
10779 The version of GNU Fortran.
10780 You can get this by running @command{g77} with the @option{-v} option.
10781 (Ignore any error messages that might be displayed
10782 when the linker is run.)
10783
10784 Without this, we won't know whether there is any point in looking for
10785 the bug in the current version of GNU Fortran.
10786
10787 @item
10788 @cindex preprocessor
10789 @cindex cpp program
10790 @cindex programs, cpp
10791 @pindex cpp
10792 A complete input file that will reproduce the bug.
10793
10794 If your source file(s) require preprocessing
10795 (for example, their names have suffixes like
10796 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
10797 and the bug is in the compiler proper (@file{f771})
10798 or in a subsequent phase of processing,
10799 run your source file through the C preprocessor
10800 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
10801 Then, include the contents of @var{newfile} in the bug report.
10802 (When you do this, use the same preprocessor options---such as
10803 @option{-I}, @option{-D}, and @option{-U}---that you used in actual
10804 compilation.)
10805
10806 A single statement is not enough of an example.
10807 In order to compile it,
10808 it must be embedded in a complete file of compiler input.
10809 The bug might depend on the details of how this is done.
10810
10811 Without a real example one can compile,
10812 all anyone can do about your bug report is wish you luck.
10813 It would be futile to try to guess how to provoke the bug.
10814 For example, bugs in register allocation and reloading
10815 can depend on every little detail of the source and include files
10816 that trigger them.
10817
10818 @item
10819 @cindex included files
10820 @cindex INCLUDE directive
10821 @cindex directive, INCLUDE
10822 @cindex #include directive
10823 @cindex directive, #include
10824 Note that you should include with your bug report any files
10825 included by the source file
10826 (via the @code{#include} or @code{INCLUDE} directive)
10827 that you send, and any files they include, and so on.
10828
10829 It is not necessary to replace
10830 the @code{#include} and @code{INCLUDE} directives
10831 with the actual files in the version of the source file that
10832 you send, but it might make submitting the bug report easier
10833 in the end.
10834 However, be sure to @emph{reproduce} the bug using the @emph{exact}
10835 version of the source material you submit, to avoid wild-goose
10836 chases.
10837
10838 @item
10839 The command arguments you gave GNU Fortran to compile that example
10840 and observe the bug.  For example, did you use @option{-O}?  To guarantee
10841 you won't omit something important, list all the options.
10842
10843 If we were to try to guess the arguments, we would probably guess wrong
10844 and then we would not encounter the bug.
10845
10846 @item
10847 The type of machine you are using, and the operating system name and
10848 version number.
10849 (Much of this information is printed by @samp{g77 -v}---if you
10850 include that, send along any additional info you have that you
10851 don't see clearly represented in that output.)
10852
10853 @item
10854 The operands you gave to the @command{configure} command when you installed
10855 the compiler.
10856
10857 @item
10858 A complete list of any modifications you have made to the compiler
10859 source.  (We don't promise to investigate the bug unless it happens in
10860 an unmodified compiler.  But if you've made modifications and don't tell
10861 us, then you are sending us on a wild-goose chase.)
10862
10863 Be precise about these changes.  A description in English is not
10864 enough---send a context diff for them.
10865
10866 Adding files of your own (such as a machine description for a machine we
10867 don't support) is a modification of the compiler source.
10868
10869 @item
10870 Details of any other deviations from the standard procedure for installing
10871 GNU Fortran.
10872
10873 @item
10874 A description of what behavior you observe that you believe is
10875 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
10876 ``The assembler instruction at line 208 in the output is incorrect.''
10877
10878 Of course, if the bug is that the compiler gets a fatal signal, then one
10879 can't miss it.  But if the bug is incorrect output, the maintainer might
10880 not notice unless it is glaringly wrong.  None of us has time to study
10881 all the assembler code from a 50-line Fortran program just on the chance that
10882 one instruction might be wrong.  We need @emph{you} to do this part!
10883
10884 Even if the problem you experience is a fatal signal, you should still
10885 say so explicitly.  Suppose something strange is going on, such as, your
10886 copy of the compiler is out of synch, or you have encountered a bug in
10887 the C library on your system.  (This has happened!)  Your copy might
10888 crash and the copy here would not.  If you @i{said} to expect a crash,
10889 then when the compiler here fails to crash, we would know that the bug
10890 was not happening.  If you don't say to expect a crash, then we would
10891 not know whether the bug was happening.  We would not be able to draw
10892 any conclusion from our observations.
10893
10894 If the problem is a diagnostic when building GNU Fortran with some other
10895 compiler, say whether it is a warning or an error.
10896
10897 Often the observed symptom is incorrect output when your program is run.
10898 Sad to say, this is not enough information unless the program is short
10899 and simple.  None of us has time to study a large program to figure out
10900 how it would work if compiled correctly, much less which line of it was
10901 compiled wrong.  So you will have to do that.  Tell us which source line
10902 it is, and what incorrect result happens when that line is executed.  A
10903 person who understands the program can find this as easily as finding a
10904 bug in the program itself.
10905
10906 @item
10907 If you send examples of assembler code output from GNU Fortran,
10908 please use @option{-g} when you make them.  The debugging information
10909 includes source line numbers which are essential for correlating the
10910 output with the input.
10911
10912 @item
10913 If you wish to mention something in the GNU Fortran source, refer to it by
10914 context, not by line number.
10915
10916 The line numbers in the development sources don't match those in your
10917 sources.  Your line numbers would convey no convenient information to the
10918 maintainers.
10919
10920 @item
10921 Additional information from a debugger might enable someone to find a
10922 problem on a machine which he does not have available.  However, you
10923 need to think when you collect this information if you want it to have
10924 any chance of being useful.
10925
10926 @cindex backtrace for bug reports
10927 For example, many people send just a backtrace, but that is never
10928 useful by itself.  A simple backtrace with arguments conveys little
10929 about GNU Fortran because the compiler is largely data-driven; the same
10930 functions are called over and over for different RTL insns, doing
10931 different things depending on the details of the insn.
10932
10933 Most of the arguments listed in the backtrace are useless because they
10934 are pointers to RTL list structure.  The numeric values of the
10935 pointers, which the debugger prints in the backtrace, have no
10936 significance whatever; all that matters is the contents of the objects
10937 they point to (and most of the contents are other such pointers).
10938
10939 In addition, most compiler passes consist of one or more loops that
10940 scan the RTL insn sequence.  The most vital piece of information about
10941 such a loop---which insn it has reached---is usually in a local variable,
10942 not in an argument.
10943
10944 @findex debug_rtx
10945 What you need to provide in addition to a backtrace are the values of
10946 the local variables for several stack frames up.  When a local
10947 variable or an argument is an RTX, first print its value and then use
10948 the GDB command @command{pr} to print the RTL expression that it points
10949 to.  (If GDB doesn't run on your machine, use your debugger to call
10950 the function @code{debug_rtx} with the RTX as an argument.)  In
10951 general, whenever a variable is a pointer, its value is no use
10952 without the data it points to.
10953 @end itemize
10954
10955 Here are some things that are not necessary:
10956
10957 @itemize @bullet
10958 @item
10959 A description of the envelope of the bug.
10960
10961 Often people who encounter a bug spend a lot of time investigating
10962 which changes to the input file will make the bug go away and which
10963 changes will not affect it.
10964
10965 This is often time consuming and not very useful, because the way we
10966 will find the bug is by running a single example under the debugger with
10967 breakpoints, not by pure deduction from a series of examples.  You might
10968 as well save your time for something else.
10969
10970 Of course, if you can find a simpler example to report @emph{instead} of
10971 the original one, that is a convenience.  Errors in the output will be
10972 easier to spot, running under the debugger will take less time, etc.
10973 Most GNU Fortran bugs involve just one function, so the most straightforward
10974 way to simplify an example is to delete all the function definitions
10975 except the one where the bug occurs.  Those earlier in the file may be
10976 replaced by external declarations if the crucial function depends on
10977 them.  (Exception: inline functions might affect compilation of functions
10978 defined later in the file.)
10979
10980 However, simplification is not vital; if you don't want to do this,
10981 report the bug anyway and send the entire test case you used.
10982
10983 @item
10984 In particular, some people insert conditionals @samp{#ifdef BUG} around
10985 a statement which, if removed, makes the bug not happen.  These are just
10986 clutter; we won't pay any attention to them anyway.  Besides, you should
10987 send us preprocessor output, and that can't have conditionals.
10988
10989 @item
10990 A patch for the bug.
10991
10992 A patch for the bug is useful if it is a good one.  But don't omit the
10993 necessary information, such as the test case, on the assumption that a
10994 patch is all we need.  We might see problems with your patch and decide
10995 to fix the problem another way, or we might not understand it at all.
10996
10997 Sometimes with a program as complicated as GNU Fortran it is very hard to
10998 construct an example that will make the program follow a certain path
10999 through the code.  If you don't send the example, we won't be able to
11000 construct one, so we won't be able to verify that the bug is fixed.
11001
11002 And if we can't understand what bug you are trying to fix, or why your
11003 patch should be an improvement, we won't install it.  A test case will
11004 help us to understand.
11005
11006 See @uref{http://gcc.gnu.org/contribute.html}
11007 for guidelines on how to make it easy for us to
11008 understand and install your patches.
11009
11010 @item
11011 A guess about what the bug is or what it depends on.
11012
11013 Such guesses are usually wrong.  Even the maintainer can't guess right
11014 about such things without first using the debugger to find the facts.
11015
11016 @item
11017 A core dump file.
11018
11019 We have no way of examining a core dump for your type of machine
11020 unless we have an identical system---and if we do have one,
11021 we should be able to reproduce the crash ourselves.
11022 @end itemize
11023
11024 @node Service
11025 @chapter How To Get Help with GNU Fortran
11026
11027 If you need help installing, using or changing GNU Fortran, there are two
11028 ways to find it:
11029
11030 @itemize @bullet
11031 @item
11032 Look in the service directory for someone who might help you for a fee.
11033 The service directory is found in the file named @file{SERVICE} in the
11034 GNU CC distribution.
11035
11036 @item
11037 Send a message to @email{@value{email-help}}.
11038 @end itemize
11039
11040 @end ifset
11041 @ifset INTERNALS
11042 @node Adding Options
11043 @chapter Adding Options
11044 @cindex options, adding
11045 @cindex adding options
11046
11047 To add a new command-line option to @command{g77}, first decide
11048 what kind of option you wish to add.
11049 Search the @command{g77} and @command{gcc} documentation for one
11050 or more options that is most closely like the one you want to add
11051 (in terms of what kind of effect it has, and so on) to
11052 help clarify its nature.
11053
11054 @itemize @bullet
11055 @item
11056 @emph{Fortran options} are options that apply only
11057 when compiling Fortran programs.
11058 They are accepted by @command{g77} and @command{gcc}, but
11059 they apply only when compiling Fortran programs.
11060
11061 @item
11062 @emph{Compiler options} are options that apply
11063 when compiling most any kind of program.
11064 @end itemize
11065
11066 @emph{Fortran options} are listed in the file
11067 @file{@value{path-g77}/lang-options.h},
11068 which is used during the build of @command{gcc} to
11069 build a list of all options that are accepted by
11070 at least one language's compiler.
11071 This list goes into the @code{documented_lang_options} array
11072 in @file{gcc/toplev.c}, which uses this array to
11073 determine whether a particular option should be
11074 offered to the linked-in front end for processing
11075 by calling @code{lang_option_decode}, which, for
11076 @command{g77}, is in @file{@value{path-g77}/com.c} and just
11077 calls @code{ffe_decode_option}.
11078
11079 If the linked-in front end ``rejects'' a
11080 particular option passed to it, @file{toplev.c}
11081 just ignores the option, because @emph{some}
11082 language's compiler is willing to accept it.
11083
11084 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
11085 to work, even though Fortran compilation does
11086 not currently support the @option{-fno-asm} option;
11087 even though the @code{f771} version of @code{lang_decode_option}
11088 rejects @option{-fno-asm}, @file{toplev.c} doesn't
11089 produce a diagnostic because some other language (C)
11090 does accept it.
11091
11092 This also means that commands like
11093 @samp{g77 -fno-asm foo.f} yield no diagnostics,
11094 despite the fact that no phase of the command was
11095 able to recognize and process @option{-fno-asm}---perhaps
11096 a warning about this would be helpful if it were
11097 possible.
11098
11099 Code that processes Fortran options is found in
11100 @file{@value{path-g77}/top.c}, function @code{ffe_decode_option}.
11101 This code needs to check positive and negative forms
11102 of each option.
11103
11104 The defaults for Fortran options are set in their
11105 global definitions, also found in @file{@value{path-g77}/top.c}.
11106 Many of these defaults are actually macros defined
11107 in @file{@value{path-g77}/target.h}, since they might be
11108 machine-specific.
11109 However, since, in practice, GNU compilers
11110 should behave the same way on all configurations
11111 (especially when it comes to language constructs),
11112 the practice of setting defaults in @file{target.h}
11113 is likely to be deprecated and, ultimately, stopped
11114 in future versions of @command{g77}.
11115
11116 Accessor macros for Fortran options, used by code
11117 in the @command{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
11118
11119 @emph{Compiler options} are listed in @file{gcc/toplev.c}
11120 in the array @code{f_options}.
11121 An option not listed in @code{lang_options} is
11122 looked up in @code{f_options} and handled from there.
11123
11124 The defaults for compiler options are set in the
11125 global definitions for the corresponding variables,
11126 some of which are in @file{gcc/toplev.c}.
11127
11128 You can set different defaults for @emph{Fortran-oriented}
11129 or @emph{Fortran-reticent} compiler options by changing
11130 the source code of @command{g77} and rebuilding.
11131 How to do this depends on the version of @command{g77}:
11132
11133 @table @code
11134 @item G77 0.5.24 (EGCS 1.1)
11135 @itemx G77 0.5.25 (EGCS 1.2 - which became GCC 2.95)
11136 Change the @code{lang_init_options} routine in @file{gcc/gcc/f/com.c}.
11137
11138 (Note that these versions of @command{g77}
11139 perform internal consistency checking automatically
11140 when the @option{-fversion} option is specified.)
11141
11142 @item G77 0.5.23
11143 @itemx G77 0.5.24 (EGCS 1.0)
11144 Change the way @code{f771} handles the @option{-fset-g77-defaults}
11145 option, which is always provided as the first option when
11146 called by @command{g77} or @command{gcc}.
11147
11148 This code is in @code{ffe_decode_options} in @file{@value{path-g77}/top.c}.
11149 Have it change just the variables that you want to default
11150 to a different setting for Fortran compiles compared to
11151 compiles of other languages.
11152
11153 The @option{-fset-g77-defaults} option is passed to @code{f771}
11154 automatically because of the specification information
11155 kept in @file{@value{path-g77}/lang-specs.h}.
11156 This file tells the @command{gcc} command how to recognize,
11157 in this case, Fortran source files (those to be preprocessed,
11158 and those that are not), and further, how to invoke the
11159 appropriate programs (including @code{f771}) to process
11160 those source files.
11161
11162 It is in @file{@value{path-g77}/lang-specs.h} that @option{-fset-g77-defaults},
11163 @option{-fversion}, and other options are passed, as appropriate,
11164 even when the user has not explicitly specified them.
11165 Other ``internal'' options such as @option{-quiet} also
11166 are passed via this mechanism.
11167 @end table
11168
11169 @node Projects
11170 @chapter Projects
11171 @cindex projects
11172
11173 If you want to contribute to @command{g77} by doing research,
11174 design, specification, documentation, coding, or testing,
11175 the following information should give you some ideas.
11176 More relevant information might be available from
11177 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
11178
11179 @menu
11180 * Efficiency::               Make @command{g77} itself compile code faster.
11181 * Better Optimization::      Teach @command{g77} to generate faster code.
11182 * Simplify Porting::         Make @command{g77} easier to configure, build,
11183                              and install.
11184 * More Extensions::          Features many users won't know to ask for.
11185 * Machine Model::            @command{g77} should better leverage @command{gcc}.
11186 * Internals Documentation::  Make maintenance easier.
11187 * Internals Improvements::   Make internals more robust.
11188 * Better Diagnostics::       Make using @command{g77} on new code easier.
11189 @end menu
11190
11191 @node Efficiency
11192 @section Improve Efficiency
11193 @cindex efficiency
11194
11195 Don't bother doing any performance analysis until most of the
11196 following items are taken care of, because there's no question
11197 they represent serious space/time problems, although some of
11198 them show up only given certain kinds of (popular) input.
11199
11200 @itemize @bullet
11201 @item
11202 Improve @code{malloc} package and its uses to specify more info about
11203 memory pools and, where feasible, use obstacks to implement them.
11204
11205 @item
11206 Skip over uninitialized portions of aggregate areas (arrays,
11207 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
11208 This would reduce memory usage for large initialized aggregate
11209 areas, even ones with only one initialized element.
11210
11211 As of version 0.5.18, a portion of this item has already been
11212 accomplished.
11213
11214 @item
11215 Prescan the statement (in @file{sta.c}) so that the nature of the statement
11216 is determined as much as possible by looking entirely at its form,
11217 and not looking at any context (previous statements, including types
11218 of symbols).
11219 This would allow ripping out of the statement-confirmation,
11220 symbol retraction/confirmation, and diagnostic inhibition
11221 mechanisms.
11222 Plus, it would result in much-improved diagnostics.
11223 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
11224 is not a subroutine intrinsic, would result actual error instead of the
11225 unimplemented-statement catch-all.
11226
11227 @item
11228 Throughout @command{g77}, don't pass line/column pairs where
11229 a simple @code{ffewhere} type, which points to the error as much as is
11230 desired by the configuration, will do, and don't pass @code{ffelexToken} types
11231 where a simple @code{ffewhere} type will do.
11232 Then, allow new default
11233 configuration of @code{ffewhere} such that the source line text is not
11234 preserved, and leave it to things like Emacs' next-error function
11235 to point to them (now that @samp{next-error} supports column,
11236 or, perhaps, character-offset, numbers).
11237 The change in calling sequences should improve performance somewhat,
11238 as should not having to save source lines.
11239 (Whether this whole
11240 item will improve performance is questionable, but it should
11241 improve maintainability.)
11242
11243 @item
11244 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
11245 as regards the assembly output.
11246 Some of this might require improving
11247 the back end, but lots of improvement in space/time required in @command{g77}
11248 itself can be fairly easily obtained without touching the back end.
11249 Maybe type-conversion, where necessary, can be speeded up as well in
11250 cases like the one shown (converting the @samp{2} into @samp{2.}).
11251
11252 @item
11253 If analysis shows it to be worthwhile, optimize @file{lex.c}.
11254
11255 @item
11256 Consider redesigning @file{lex.c} to not need any feedback
11257 during tokenization, by keeping track of enough parse state on its
11258 own.
11259 @end itemize
11260
11261 @node Better Optimization
11262 @section Better Optimization
11263 @cindex optimization, better
11264 @cindex code generation, improving
11265
11266 Much of this work should be put off until after @command{g77} has
11267 all the features necessary for its widespread acceptance as a
11268 useful F77 compiler.
11269 However, perhaps this work can be done in parallel during
11270 the feature-adding work.
11271
11272 @itemize @bullet
11273 @item
11274 Do the equivalent of the trick of putting @samp{extern inline} in front
11275 of every function definition in @code{libg2c} and #include'ing the resulting
11276 file in @command{f2c}+@command{gcc}---that is, inline all run-time-library functions
11277 that are at all worth inlining.
11278 (Some of this has already been done, such as for integral exponentiation.)
11279
11280 @item
11281 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
11282 and it's clear that types line up
11283 and @samp{CHAR_VAR} is addressable or not a @code{VAR_DECL},
11284 make @samp{CHAR_VAR}, not a
11285 temporary, be the receiver for @samp{CHAR_FUNC}.
11286 (This is now done for @code{COMPLEX} variables.)
11287
11288 @item
11289 Design and implement Fortran-specific optimizations that don't
11290 really belong in the back end, or where the front end needs to
11291 give the back end more info than it currently does.
11292
11293 @item
11294 Design and implement a new run-time library interface, with the
11295 code going into @code{libgcc} so no special linking is required to
11296 link Fortran programs using standard language features.
11297 This library
11298 would speed up lots of things, from I/O (using precompiled formats,
11299 doing just one, or, at most, very few, calls for arrays or array sections,
11300 and so on) to general computing (array/section implementations of
11301 various intrinsics, implementation of commonly performed loops that
11302 aren't likely to be optimally compiled otherwise, etc.).
11303
11304 Among the important things the library would do are:
11305
11306 @itemize @bullet
11307 @item
11308 Be a one-stop-shop-type
11309 library, hence shareable and usable by all, in that what are now
11310 library-build-time options in @code{libg2c} would be moved at least to the
11311 @command{g77} compile phase, if not to finer grains (such as choosing how
11312 list-directed I/O formatting is done by default at @code{OPEN} time, for
11313 preconnected units via options or even statements in the main program
11314 unit, maybe even on a per-I/O basis with appropriate pragma-like
11315 devices).
11316 @end itemize
11317
11318 @item
11319 Probably requiring the new library design, change interface to
11320 normally have @code{COMPLEX} functions return their values in the way
11321 @command{gcc} would if they were declared @code{__complex__ float},
11322 rather than using
11323 the mechanism currently used by @code{CHARACTER} functions (whereby the
11324 functions are compiled as returning void and their first arg is
11325 a pointer to where to store the result).
11326 (Don't append underscores to
11327 external names for @code{COMPLEX} functions in some cases once @command{g77} uses
11328 @command{gcc} rather than @command{f2c} calling conventions.)
11329
11330 @item
11331 Do something useful with @code{doiter} references where possible.
11332 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
11333 a @code{DO} loop that uses @samp{I} as the
11334 iteration variable, and the back end might find that info useful
11335 in determining whether it needs to read @samp{I} back into a register after
11336 the call.
11337 (It normally has to do that, unless it knows @samp{FOO} never
11338 modifies its passed-by-reference argument, which is rarely the case
11339 for Fortran-77 code.)
11340 @end itemize
11341
11342 @node Simplify Porting
11343 @section Simplify Porting
11344 @cindex porting, simplify
11345 @cindex simplify porting
11346
11347 Making @command{g77} easier to configure, port, build, and install, either
11348 as a single-system compiler or as a cross-compiler, would be
11349 very useful.
11350
11351 @itemize @bullet
11352 @item
11353 A new library (replacing @code{libg2c}) should improve portability as well as
11354 produce more optimal code.
11355 Further, @command{g77} and the new library should
11356 conspire to simplify naming of externals, such as by removing unnecessarily
11357 added underscores, and to reduce/eliminate the possibility of naming
11358 conflicts, while making debugger more straightforward.
11359
11360 Also, it should
11361 make multi-language applications more feasible, such as by providing
11362 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
11363 descriptors.
11364
11365 @item
11366 Possibly related to a new library, @command{g77} should produce the equivalent
11367 of a @command{gcc} @samp{main(argc, argv)} function when it compiles a
11368 main program unit, instead of compiling something that must be
11369 called by a library
11370 implementation of @code{main()}.
11371
11372 This would do many useful things such as
11373 provide more flexibility in terms of setting up exception handling,
11374 not requiring programmers to start their debugging sessions with
11375 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
11376
11377 @item
11378 The GBE needs to understand the difference between alignment
11379 requirements and desires.
11380 For example, on Intel x86 machines, @command{g77} currently imposes
11381 overly strict alignment requirements, due to the back end, but it
11382 would be useful for Fortran and C programmers to be able to override
11383 these @emph{recommendations} as long as they don't violate the actual
11384 processor @emph{requirements}.
11385 @end itemize
11386
11387 @node More Extensions
11388 @section More Extensions
11389 @cindex extensions, more
11390
11391 These extensions are not the sort of things users ask for ``by name'',
11392 but they might improve the usability of @command{g77}, and Fortran in
11393 general, in the long run.
11394 Some of these items really pertain to improving @command{g77} internals
11395 so that some popular extensions can be more easily supported.
11396
11397 @itemize @bullet
11398 @item
11399 Look through all the documentation on the GNU Fortran language,
11400 dialects, compiler, missing features, bugs, and so on.
11401 Many mentions of incomplete or missing features are
11402 sprinkled throughout.
11403 It is not worth repeating them here.
11404
11405 @item
11406 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
11407 named and unnamed.
11408 The idea is to provide a forward-looking, effective
11409 replacement for things like the old-style @code{PARAMETER} statement
11410 when people
11411 really need typelessness in a maintainable, portable, clearly documented
11412 way.
11413 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
11414 and whatever else might come along.
11415 (This is not really a call for polymorphism per se, just
11416 an ability to express limited, syntactic polymorphism.)
11417
11418 @item
11419 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
11420
11421 @item
11422 Support arbitrary file unit numbers, instead of limiting them
11423 to 0 through @samp{MXUNIT-1}.
11424 (This is a @code{libg2c} issue.)
11425
11426 @item
11427 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
11428 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
11429 later @code{UNIT=} in the first example is invalid.
11430 Make sure this is what users of this feature would expect.
11431
11432 @item
11433 Currently @command{g77} disallows @samp{READ(1'10)} since
11434 it is an obnoxious syntax, but
11435 supporting it might be pretty easy if needed.
11436 More details are needed, such
11437 as whether general expressions separated by an apostrophe are supported,
11438 or maybe the record number can be a general expression, and so on.
11439
11440 @item
11441 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
11442 fully.
11443 Currently there is no support at all
11444 for @code{%FILL} in @code{STRUCTURE} and related syntax,
11445 whereas the rest of the
11446 stuff has at least some parsing support.
11447 This requires either major
11448 changes to @code{libg2c} or its replacement.
11449
11450 @item
11451 F90 and @command{g77} probably disagree about label scoping relative to
11452 @code{INTERFACE} and @code{END INTERFACE}, and their contained
11453 procedure interface bodies (blocks?).
11454
11455 @item
11456 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
11457 since that was added after S8.112.
11458
11459 @item
11460 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
11461 with the final form of the standard (it was vague at S8.112).
11462
11463 @item
11464 It seems to be an ``open'' question whether a file, immediately after being
11465 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
11466 might be nice to offer an option of opening to ``undefined'' status, requiring
11467 an explicit absolute-positioning operation to be performed before any
11468 other (besides @code{CLOSE}) to assist in making applications port to systems
11469 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
11470 @end itemize
11471
11472 @node Machine Model
11473 @section Machine Model
11474
11475 This items pertain to generalizing @command{g77}'s view of
11476 the machine model to more fully accept whatever the GBE
11477 provides it via its configuration.
11478
11479 @itemize @bullet
11480 @item
11481 Switch to using @code{REAL_VALUE_TYPE} to represent floating-point constants
11482 exclusively so the target float format need not be required.
11483 This
11484 means changing the way @command{g77} handles initialization of aggregate areas
11485 having more than one type, such as @code{REAL} and @code{INTEGER},
11486 because currently
11487 it initializes them as if they were arrays of @code{char} and uses the
11488 bit patterns of the constants of the various types in them to determine
11489 what to stuff in elements of the arrays.
11490
11491 @item
11492 Rely more and more on back-end info and capabilities, especially in the
11493 area of constants (where having the @command{g77} front-end's IL just store
11494 the appropriate tree nodes containing constants might be best).
11495
11496 @item
11497 Suite of C and Fortran programs that a user/administrator can run on a
11498 machine to help determine the configuration for @command{g77} before building
11499 and help determine if the compiler works (especially with whatever
11500 libraries are installed) after building.
11501 @end itemize
11502
11503 @node Internals Documentation
11504 @section Internals Documentation
11505
11506 Better info on how @command{g77} works and how to port it is needed.
11507
11508 @xref{Front End}, which contains some information
11509 on @command{g77} internals.
11510
11511 @node Internals Improvements
11512 @section Internals Improvements
11513
11514 Some more items that would make @command{g77} more reliable
11515 and easier to maintain:
11516
11517 @itemize @bullet
11518 @item
11519 Generally make expression handling focus
11520 more on critical syntax stuff, leaving semantics to callers.
11521 For example,
11522 anything a caller can check, semantically, let it do so, rather
11523 than having @file{expr.c} do it.
11524 (Exceptions might include things like
11525 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
11526 it seems
11527 important to preserve the left-to-right-in-source order of production
11528 of diagnostics.)
11529
11530 @item
11531 Come up with better naming conventions for @option{-D} to establish requirements
11532 to achieve desired implementation dialect via @file{proj.h}.
11533
11534 @item
11535 Clean up used tokens and @code{ffewhere}s in @code{ffeglobal_terminate_1}.
11536
11537 @item
11538 Replace @file{sta.c} @code{outpooldisp} mechanism with @code{malloc_pool_use}.
11539
11540 @item
11541 Check for @code{opANY} in more places in @file{com.c}, @file{std.c},
11542 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
11543 (after determining if there is indeed no real need for it).
11544
11545 @item
11546 Utility to read and check @file{bad.def} messages and their references in the
11547 code, to make sure calls are consistent with message templates.
11548
11549 @item
11550 Search and fix @samp{&ffe@dots{}} and similar so that
11551 @samp{ffe@dots{}ptr@dots{}} macros are
11552 available instead (a good argument for wishing this could have written all
11553 this stuff in C++, perhaps).
11554 On the other hand, it's questionable whether this sort of
11555 improvement is really necessary, given the availability of
11556 tools such as Emacs and Perl, which make finding any
11557 address-taking of structure members easy enough?
11558
11559 @item
11560 Some modules truly export the member names of their structures (and the
11561 structures themselves), maybe fix this, and fix other modules that just
11562 appear to as well (by appending @samp{_}, though it'd be ugly and probably
11563 not worth the time).
11564
11565 @item
11566 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
11567 in @file{proj.h}
11568 and use them throughout @command{g77} source code (especially in the definitions
11569 of access macros in @samp{.h} files) so they can be tailored
11570 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
11571
11572 @item
11573 Decorate throughout with @code{const} and other such stuff.
11574
11575 @item
11576 All F90 notational derivations in the source code are still based
11577 on the S8.112 version of the draft standard.
11578 Probably should update
11579 to the official standard, or put documentation of the rules as used
11580 in the code@dots{}uh@dots{}in the code.
11581
11582 @item
11583 Some @code{ffebld_new} calls (those outside of @file{ffeexpr.c} or
11584 inside but invoked via paths not involving @code{ffeexpr_lhs} or
11585 @code{ffeexpr_rhs}) might be creating things
11586 in improper pools, leading to such things staying around too long or
11587 (doubtful, but possible and dangerous) not long enough.
11588
11589 @item
11590 Some @code{ffebld_list_new} (or whatever) calls might not be matched by
11591 @code{ffebld_list_bottom} (or whatever) calls, which might someday matter.
11592 (It definitely is not a problem just yet.)
11593
11594 @item
11595 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
11596 due to alignment/mismatch or other problems---they end up without
11597 @code{ffestorag} objects, so maybe the backend (and other parts of the front
11598 end) can notice that and handle like an @code{opANY} (do what it wants, just
11599 don't complain or crash).
11600 Most of this seems to have been addressed
11601 by now, but a code review wouldn't hurt.
11602 @end itemize
11603
11604 @node Better Diagnostics
11605 @section Better Diagnostics
11606
11607 These are things users might not ask about, or that need to
11608 be looked into, before worrying about.
11609 Also here are items that involve reducing unnecessary diagnostic
11610 clutter.
11611
11612 @itemize @bullet
11613 @item
11614 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
11615 lengths, type classes, and so on),
11616 @code{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
11617 it specifies.
11618
11619 @item
11620 Speed up and improve error handling for data when repeat-count is
11621 specified.
11622 For example, don't output 20 unnecessary messages after the
11623 first necessary one for:
11624
11625 @smallexample
11626 INTEGER X(20)
11627 CONTINUE
11628 DATA (X(I), J= 1, 20) /20*5/
11629 END
11630 @end smallexample
11631
11632 @noindent
11633 (The @code{CONTINUE} statement ensures the @code{DATA} statement
11634 is processed in the context of executable, not specification,
11635 statements.)
11636 @end itemize
11637
11638 @include ffe.texi
11639
11640 @end ifset
11641
11642 @ifset USING
11643 @node Diagnostics
11644 @chapter Diagnostics
11645 @cindex diagnostics
11646
11647 Some diagnostics produced by @command{g77} require sufficient explanation
11648 that the explanations are given below, and the diagnostics themselves
11649 identify the appropriate explanation.
11650
11651 Identification uses the GNU Info format---specifically, the @command{info}
11652 command that displays the explanation is given within square
11653 brackets in the diagnostic.
11654 For example:
11655
11656 @smallexample
11657 foo.f:5: Invalid statement [info -f g77 M FOOEY]
11658 @end smallexample
11659
11660 More details about the above diagnostic is found in the @command{g77} Info
11661 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
11662 which is displayed by typing the UNIX command
11663 @samp{info -f g77 M FOOEY}.
11664
11665 Other Info readers, such as EMACS, may be just as easily used to display
11666 the pertinent node.
11667 In the above example, @samp{g77} is the Info document name,
11668 @samp{M} is the top-level menu item to select,
11669 and, in that node (named @samp{Diagnostics}, the name of
11670 this chapter, which is the very text you're reading now),
11671 @samp{FOOEY} is the menu item to select.
11672
11673 @iftex
11674 In this printed version of the @command{g77} manual, the above example
11675 points to a section, below, entitled @samp{FOOEY}---though, of course,
11676 as the above is just a sample, no such section exists.
11677 @end iftex
11678
11679 @menu
11680 * CMPAMBIG::    Ambiguous use of intrinsic.
11681 * EXPIMP::      Intrinsic used explicitly and implicitly.
11682 * INTGLOB::     Intrinsic also used as name of global.
11683 * LEX::         Various lexer messages
11684 * GLOBALS::     Disagreements about globals.
11685 * LINKFAIL::    When linking @code{f771} fails.
11686 * Y2KBAD::      Use of non-Y2K-compliant intrinsic.
11687 @end menu
11688
11689 @node CMPAMBIG
11690 @section @code{CMPAMBIG}
11691
11692 @noindent
11693 @smallexample
11694 Ambiguous use of intrinsic @var{intrinsic} @dots{}
11695 @end smallexample
11696
11697 The type of the argument to the invocation of the @var{intrinsic}
11698 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
11699 Typically, it is @code{COMPLEX(KIND=2)}, also known as
11700 @code{DOUBLE COMPLEX}.
11701
11702 The interpretation of this invocation depends on the particular
11703 dialect of Fortran for which the code was written.
11704 Some dialects convert the real part of the argument to
11705 @code{REAL(KIND=1)}, thus losing precision; other dialects,
11706 and Fortran 90, do no such conversion.
11707
11708 So, GNU Fortran rejects such invocations except under certain
11709 circumstances, to avoid making an incorrect assumption that results
11710 in generating the wrong code.
11711
11712 To determine the dialect of the program unit, perhaps even whether
11713 that particular invocation is properly coded, determine how the
11714 result of the intrinsic is used.
11715
11716 The result of @var{intrinsic} is expected (by the original programmer)
11717 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
11718
11719 @itemize @bullet
11720 @item
11721 It is passed as an argument to a procedure that explicitly or
11722 implicitly declares that argument @code{REAL(KIND=1)}.
11723
11724 For example,
11725 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
11726 statement specifying the dummy argument corresponding to an
11727 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
11728 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
11729 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
11730 of @code{REAL(KIND=2)}.
11731
11732 @item
11733 It is used in a context that would otherwise not include
11734 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
11735 invocation as @code{REAL(KIND=2)} would result in unnecessary
11736 promotions and (typically) more expensive operations on the
11737 wider type.
11738
11739 For example:
11740
11741 @smallexample
11742 DOUBLE COMPLEX Z
11743 @dots{}
11744 R(1) = T * REAL(Z)
11745 @end smallexample
11746
11747 The above example suggests the programmer expected the real part
11748 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
11749 multiplied by @samp{T} (presumed, along with @samp{R} above, to
11750 be type @code{REAL(KIND=1)}).
11751
11752 Otherwise, the conversion would have to be delayed until after
11753 the multiplication, requiring not only an extra conversion
11754 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
11755 expensive multiplication (a double-precision multiplication instead
11756 of a single-precision one).
11757 @end itemize
11758
11759 The result of @var{intrinsic} is expected (by the original programmer)
11760 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
11761
11762 @itemize @bullet
11763 @item
11764 It is passed as an argument to a procedure that explicitly or
11765 implicitly declares that argument @code{REAL(KIND=2)}.
11766
11767 For example, a procedure specifying a @code{DOUBLE PRECISION}
11768 dummy argument corresponding to an
11769 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
11770 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
11771 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
11772 of @code{REAL(KIND=1)}.
11773
11774 @item
11775 It is used in an expression context that includes
11776 other @code{REAL(KIND=2)} operands,
11777 or is assigned to a @code{REAL(KIND=2)} variable or array element.
11778
11779 For example:
11780
11781 @smallexample
11782 DOUBLE COMPLEX Z
11783 DOUBLE PRECISION R, T
11784 @dots{}
11785 R(1) = T * REAL(Z)
11786 @end smallexample
11787
11788 The above example suggests the programmer expected the real part
11789 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
11790 by the @code{REAL()} intrinsic.
11791
11792 Otherwise, the conversion would have to be immediately followed
11793 by a conversion back to @code{REAL(KIND=2)}, losing
11794 the original, full precision of the real part of @code{Z},
11795 before being multiplied by @samp{T}.
11796 @end itemize
11797
11798 Once you have determined whether a particular invocation of @var{intrinsic}
11799 expects the Fortran 90 interpretation, you can:
11800
11801 @itemize @bullet
11802 @item
11803 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
11804 @code{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
11805 is @code{AIMAG})
11806 if it expected the Fortran 90 interpretation.
11807
11808 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
11809 some other type, such as @code{COMPLEX*32}, you should use the
11810 appropriate intrinsic, such as the one to convert to @code{REAL*16}
11811 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
11812 @code{QIMAG()} in place of @code{DIMAG()}).
11813
11814 @item
11815 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
11816 otherwise.
11817 This converts to @code{REAL(KIND=1)} in all working
11818 Fortran compilers.
11819 @end itemize
11820
11821 If you don't want to change the code, and you are certain that all
11822 ambiguous invocations of @var{intrinsic} in the source file have
11823 the same expectation regarding interpretation, you can:
11824
11825 @itemize @bullet
11826 @item
11827 Compile with the @command{g77} option @option{-ff90}, to enable the
11828 Fortran 90 interpretation.
11829
11830 @item
11831 Compile with the @command{g77} options @samp{-fno-f90 -fugly-complex},
11832 to enable the non-Fortran-90 interpretations.
11833 @end itemize
11834
11835 @xref{REAL() and AIMAG() of Complex}, for more information on this
11836 issue.
11837
11838 Note: If the above suggestions don't produce enough evidence
11839 as to whether a particular program expects the Fortran 90
11840 interpretation of this ambiguous invocation of @var{intrinsic},
11841 there is one more thing you can try.
11842
11843 If you have access to most or all the compilers used on the
11844 program to create successfully tested and deployed executables,
11845 read the documentation for, and @emph{also} test out, each compiler
11846 to determine how it treats the @var{intrinsic} intrinsic in
11847 this case.
11848 (If all the compilers don't agree on an interpretation, there
11849 might be lurking bugs in the deployed versions of the program.)
11850
11851 The following sample program might help:
11852
11853 @cindex JCB003 program
11854 @smallexample
11855       PROGRAM JCB003
11856 C
11857 C Written by James Craig Burley 1997-02-23.
11858 C
11859 C Determine how compilers handle non-standard REAL
11860 C and AIMAG on DOUBLE COMPLEX operands.
11861 C
11862       DOUBLE COMPLEX Z
11863       REAL R
11864       Z = (3.3D0, 4.4D0)
11865       R = Z
11866       CALL DUMDUM(Z, R)
11867       R = REAL(Z) - R
11868       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
11869       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
11870       R = 4.4D0
11871       CALL DUMDUM(Z, R)
11872       R = AIMAG(Z) - R
11873       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
11874       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
11875       END
11876 C
11877 C Just to make sure compiler doesn't use naive flow
11878 C analysis to optimize away careful work above,
11879 C which might invalidate results....
11880 C
11881       SUBROUTINE DUMDUM(Z, R)
11882       DOUBLE COMPLEX Z
11883       REAL R
11884       END
11885 @end smallexample
11886
11887 If the above program prints contradictory results on a
11888 particular compiler, run away!
11889
11890 @node EXPIMP
11891 @section @code{EXPIMP}
11892
11893 @noindent
11894 @smallexample
11895 Intrinsic @var{intrinsic} referenced @dots{}
11896 @end smallexample
11897
11898 The @var{intrinsic} is explicitly declared in one program
11899 unit in the source file and implicitly used as an intrinsic
11900 in another program unit in the same source file.
11901
11902 This diagnostic is designed to catch cases where a program
11903 might depend on using the name @var{intrinsic} as an intrinsic
11904 in one program unit and as a global name (such as the name
11905 of a subroutine or function) in another, but @command{g77} recognizes
11906 the name as an intrinsic in both cases.
11907
11908 After verifying that the program unit making implicit use
11909 of the intrinsic is indeed written expecting the intrinsic,
11910 add an @samp{INTRINSIC @var{intrinsic}} statement to that
11911 program unit to prevent this warning.
11912
11913 This and related warnings are disabled by using
11914 the @option{-Wno-globals} option when compiling.
11915
11916 Note that this warning is not issued for standard intrinsics.
11917 Standard intrinsics include those described in the FORTRAN 77
11918 standard and, if @option{-ff90} is specified, those described
11919 in the Fortran 90 standard.
11920 Such intrinsics are not as likely to be confused with user
11921 procedures as intrinsics provided as extensions to the
11922 standard by @command{g77}.
11923
11924 @node INTGLOB
11925 @section @code{INTGLOB}
11926
11927 @noindent
11928 @smallexample
11929 Same name `@var{intrinsic}' given @dots{}
11930 @end smallexample
11931
11932 The name @var{intrinsic} is used for a global entity (a common
11933 block or a program unit) in one program unit and implicitly
11934 used as an intrinsic in another program unit.
11935
11936 This diagnostic is designed to catch cases where a program
11937 intends to use a name entirely as a global name, but @command{g77}
11938 recognizes the name as an intrinsic in the program unit that
11939 references the name, a situation that would likely produce
11940 incorrect code.
11941
11942 For example:
11943
11944 @smallexample
11945 INTEGER FUNCTION TIME()
11946 @dots{}
11947 END
11948 @dots{}
11949 PROGRAM SAMP
11950 INTEGER TIME
11951 PRINT *, 'Time is ', TIME()
11952 END
11953 @end smallexample
11954
11955 The above example defines a program unit named @samp{TIME}, but
11956 the reference to @samp{TIME} in the main program unit @samp{SAMP}
11957 is normally treated by @command{g77} as a reference to the intrinsic
11958 @code{TIME()} (unless a command-line option that prevents such
11959 treatment has been specified).
11960
11961 As a result, the program @samp{SAMP} will @emph{not}
11962 invoke the @samp{TIME} function in the same source file.
11963
11964 Since @command{g77} recognizes @code{libU77} procedures as
11965 intrinsics, and since some existing code uses the same names
11966 for its own procedures as used by some @code{libU77}
11967 procedures, this situation is expected to arise often enough
11968 to make this sort of warning worth issuing.
11969
11970 After verifying that the program unit making implicit use
11971 of the intrinsic is indeed written expecting the intrinsic,
11972 add an @samp{INTRINSIC @var{intrinsic}} statement to that
11973 program unit to prevent this warning.
11974
11975 Or, if you believe the program unit is designed to invoke the
11976 program-defined procedure instead of the intrinsic (as
11977 recognized by @command{g77}), add an @samp{EXTERNAL @var{intrinsic}}
11978 statement to the program unit that references the name to
11979 prevent this warning.
11980
11981 This and related warnings are disabled by using
11982 the @option{-Wno-globals} option when compiling.
11983
11984 Note that this warning is not issued for standard intrinsics.
11985 Standard intrinsics include those described in the FORTRAN 77
11986 standard and, if @option{-ff90} is specified, those described
11987 in the Fortran 90 standard.
11988 Such intrinsics are not as likely to be confused with user
11989 procedures as intrinsics provided as extensions to the
11990 standard by @command{g77}.
11991
11992 @node LEX
11993 @section @code{LEX}
11994
11995 @noindent
11996 @smallexample
11997 Unrecognized character @dots{}
11998 Invalid first character @dots{}
11999 Line too long @dots{}
12000 Non-numeric character @dots{}
12001 Continuation indicator @dots{}
12002 Label at @dots{} invalid with continuation line indicator @dots{}
12003 Character constant @dots{}
12004 Continuation line @dots{}
12005 Statement at @dots{} begins with invalid token
12006 @end smallexample
12007
12008 Although the diagnostics identify specific problems, they can
12009 be produced when general problems such as the following occur:
12010
12011 @itemize @bullet
12012 @item
12013 The source file contains something other than Fortran code.
12014
12015 If the code in the file does not look like many of the examples
12016 elsewhere in this document, it might not be Fortran code.
12017 (Note that Fortran code often is written in lower case letters,
12018 while the examples in this document use upper case letters,
12019 for stylistic reasons.)
12020
12021 For example, if the file contains lots of strange-looking
12022 characters, it might be APL source code; if it contains lots
12023 of parentheses, it might be Lisp source code; if it
12024 contains lots of bugs, it might be C++ source code.
12025
12026 @item
12027 The source file contains free-form Fortran code, but @option{-ffree-form}
12028 was not specified on the command line to compile it.
12029
12030 Free form is a newer form for Fortran code.
12031 The older, classic form is called fixed form.
12032
12033 @cindex continuation character
12034 @cindex characters, continuation
12035 Fixed-form code is visually fairly distinctive, because
12036 numerical labels and comments are all that appear in
12037 the first five columns of a line, the sixth column is
12038 reserved to denote continuation lines,
12039 and actual statements start at or beyond column 7.
12040 Spaces generally are not significant, so if you
12041 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
12042 you are looking at fixed-form code.
12043 @cindex *
12044 @cindex asterisk
12045 Comment lines are indicated by the letter @samp{C} or the symbol
12046 @samp{*} in column 1.
12047 @cindex trailing comment
12048 @cindex comment
12049 @cindex characters, comment
12050 @cindex !
12051 @cindex exclamation point
12052 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
12053 which many compilers support.)
12054
12055 Free-form code is distinguished from fixed-form source
12056 primarily by the fact that statements may start anywhere.
12057 (If lots of statements start in columns 1 through 6,
12058 that's a strong indicator of free-form source.)
12059 Consecutive keywords must be separated by spaces, so
12060 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
12061 There are no comment lines per se, but @samp{!} starts a
12062 comment anywhere in a line (other than within a character or
12063 Hollerith constant).
12064
12065 @xref{Source Form}, for more information.
12066
12067 @item
12068 The source file is in fixed form and has been edited without
12069 sensitivity to the column requirements.
12070
12071 Statements in fixed-form code must be entirely contained within
12072 columns 7 through 72 on a given line.
12073 Starting them ``early'' is more likely to result in diagnostics
12074 than finishing them ``late'', though both kinds of errors are
12075 often caught at compile time.
12076
12077 For example, if the following code fragment is edited by following
12078 the commented instructions literally, the result, shown afterward,
12079 would produce a diagnostic when compiled:
12080
12081 @smallexample
12082 C On XYZZY systems, remove "C" on next line:
12083 C     CALL XYZZY_RESET
12084 @end smallexample
12085
12086 The result of editing the above line might be:
12087
12088 @smallexample
12089 C On XYZZY systems, remove "C" on next line:
12090      CALL XYZZY_RESET
12091 @end smallexample
12092
12093 However, that leaves the first @samp{C} in the @code{CALL}
12094 statement in column 6, making it a comment line, which is
12095 not really what the author intended, and which is likely
12096 to result in one of the above-listed diagnostics.
12097
12098 @emph{Replacing} the @samp{C} in column 1 with a space
12099 is the proper change to make, to ensure the @code{CALL}
12100 keyword starts in or after column 7.
12101
12102 Another common mistake like this is to forget that fixed-form
12103 source lines are significant through only column 72, and that,
12104 normally, any text beyond column 72 is ignored or is diagnosed
12105 at compile time.
12106
12107 @xref{Source Form}, for more information.
12108
12109 @item
12110 The source file requires preprocessing, and the preprocessing
12111 is not being specified at compile time.
12112
12113 A source file containing lines beginning with @code{#define},
12114 @code{#include}, @code{#if}, and so on is likely one that
12115 requires preprocessing.
12116
12117 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
12118 the file normally will be compiled @emph{without} preprocessing
12119 by @command{g77}.
12120
12121 Change the file's suffix from @samp{.f} to @samp{.F}
12122 (or, on systems with case-insensitive file names,
12123 to @samp{.fpp} or @samp{.FPP}),
12124 from @samp{.for} to @samp{.fpp},
12125 or from @samp{.FOR} to @samp{.FPP}.
12126 @command{g77} compiles files with such names @emph{with}
12127 preprocessing.
12128
12129 @pindex cpp
12130 @cindex preprocessor
12131 @cindex cpp program
12132 @cindex programs, cpp
12133 @cindex @option{-x f77-cpp-input} option
12134 @cindex options, @option{-x f77-cpp-input}
12135 Or, learn how to use @command{gcc}'s @option{-x} option to specify
12136 the language @samp{f77-cpp-input} for Fortran files that
12137 require preprocessing.
12138 @xref{Overall Options,,Options Controlling the Kind of
12139 Output,gcc,Using the GNU Compiler Collection (GCC)}.
12140
12141 @item
12142 The source file is preprocessed, and the results of preprocessing
12143 result in syntactic errors that are not necessarily obvious to
12144 someone examining the source file itself.
12145
12146 Examples of errors resulting from preprocessor macro expansion
12147 include exceeding the line-length limit, improperly starting,
12148 terminating, or incorporating the apostrophe or double-quote in
12149 a character constant, improperly forming a Hollerith constant,
12150 and so on.
12151
12152 @xref{Overall Options,,Options Controlling the Kind of Output},
12153 for suggestions about how to use, and not use, preprocessing
12154 for Fortran code.
12155 @end itemize
12156
12157 @node GLOBALS
12158 @section @code{GLOBALS}
12159
12160 @noindent
12161 @smallexample
12162 Global name @var{name} defined at @dots{} already defined@dots{}
12163 Global name @var{name} at @dots{} has different type@dots{}
12164 Too many arguments passed to @var{name} at @dots{}
12165 Too few arguments passed to @var{name} at @dots{}
12166 Argument #@var{n} of @var{name} is @dots{}
12167 @end smallexample
12168
12169 These messages all identify disagreements about the
12170 global procedure named @var{name} among different program units
12171 (usually including @var{name} itself).
12172
12173 Whether a particular disagreement is reported
12174 as a warning or an error
12175 can depend on the relative order
12176 of the disagreeing portions of the source file.
12177
12178 Disagreements between a procedure invocation
12179 and the @emph{subsequent} procedure itself
12180 are, usually, diagnosed as errors
12181 when the procedure itself @emph{precedes} the invocation.
12182 Other disagreements are diagnosed via warnings.
12183
12184 @cindex forward references
12185 @cindex in-line code
12186 @cindex compilation, in-line
12187 This distinction, between warnings and errors,
12188 is due primarily to the present tendency of the @command{gcc} back end
12189 to inline only those procedure invocations that are
12190 @emph{preceded} by the corresponding procedure definitions.
12191 If the @command{gcc} back end is changed
12192 to inline ``forward references'',
12193 in which invocations precede definitions,
12194 the @command{g77} front end will be changed
12195 to treat both orderings as errors, accordingly.
12196
12197 The sorts of disagreements that are diagnosed by @command{g77} include
12198 whether a procedure is a subroutine or function;
12199 if it is a function, the type of the return value of the procedure;
12200 the number of arguments the procedure accepts;
12201 and the type of each argument.
12202
12203 Disagreements regarding global names among program units
12204 in a Fortran program @emph{should} be fixed in the code itself.
12205 However, if that is not immediately practical,
12206 and the code has been working for some time,
12207 it is possible it will work
12208 when compiled with the @option{-fno-globals} option.
12209
12210 The @option{-fno-globals} option
12211 causes these diagnostics to all be warnings
12212 and disables all inlining of references to global procedures
12213 (to avoid subsequent compiler crashes and bad-code generation).
12214 Use of the @option{-Wno-globals} option as well as @option{-fno-globals}
12215 suppresses all of these diagnostics.
12216 (@option{-Wno-globals} by itself disables only the warnings,
12217 not the errors.)
12218
12219 After using @option{-fno-globals} to work around these problems,
12220 it is wise to stop using that option and address them by fixing
12221 the Fortran code, because such problems, while they might not
12222 actually result in bugs on some systems, indicate that the code
12223 is not as portable as it could be.
12224 In particular, the code might appear to work on a particular
12225 system, but have bugs that affect the reliability of the data
12226 without exhibiting any other outward manifestations of the bugs.
12227
12228 @node LINKFAIL
12229 @section @code{LINKFAIL}
12230
12231 @noindent
12232 On AIX 4.1, @command{g77} might not build with the native (non-GNU) tools
12233 due to a linker bug in coping with the @option{-bbigtoc} option which
12234 leads to a @samp{Relocation overflow} error.  The GNU linker is not
12235 recommended on current AIX versions, though; it was developed under a
12236 now-unsupported version.  This bug is said to be fixed by `update PTF
12237 U455193 for APAR IX75823'.
12238
12239 Compiling with @option{-mminimal-toc}
12240 might solve this problem, e.g.@: by adding
12241 @smallexample
12242 BOOT_CFLAGS='-mminimal-toc -O2 -g'
12243 @end smallexample
12244 to the @code{make bootstrap} command line.
12245
12246 @node Y2KBAD
12247 @section @code{Y2KBAD}
12248 @cindex Y2K compliance
12249 @cindex Year 2000 compliance
12250
12251 @noindent
12252 @smallexample
12253 Intrinsic `@var{name}', invoked at (^), known to be non-Y2K-compliant@dots{}
12254 @end smallexample
12255
12256 This diagnostic indicates that
12257 the specific intrinsic invoked by the name @var{name}
12258 is known to have an interface
12259 that is not Year-2000 (Y2K) compliant.
12260
12261 @xref{Year 2000 (Y2K) Problems}.
12262
12263 @end ifset
12264
12265 @node Index
12266 @unnumbered Index
12267
12268 @printindex cp
12269 @bye