OSDN Git Service

2001-09-28 Robert Anderson <rwa@alumni.princeton.edu>
[pf3gnuchains/gcc-fork.git] / gcc / f / g77.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename g77.info
4
5 @set last-update 2001-06-10
6 @set copyrights-g77 1995,1996,1997,1998,1999,2000,2001
7
8 @include root.texi
9
10 @c This tells @include'd files that they're part of the overall G77 doc
11 @c set.  (They might be part of a higher-level doc set too.)
12 @set DOC-G77
13
14 @c @setfilename useg77.info
15 @c @setfilename portg77.info
16 @c To produce the full manual, use the "g77.info" setfilename, and
17 @c make sure the following do NOT begin with '@c' (and the @clear lines DO)
18 @set INTERNALS
19 @set USING
20 @c To produce a user-only manual, use the "useg77.info" setfilename, and
21 @c make sure the following does NOT begin with '@c':
22 @c @clear INTERNALS
23 @c To produce a porter-only manual, use the "portg77.info" setfilename,
24 @c and make sure the following does NOT begin with '@c':
25 @c @clear USING
26
27 @c 6/27/96 FSF DO wants smallbook fmt for 1st bound edition. (from gcc.texi)
28 @c @smallbook
29
30 @c i also commented out the finalout command, so if there *are* any
31 @c overfulls, you'll (hopefully) see the rectangle in the right hand
32 @c margin. -- burley 1999-03-13 (from mew's comment in gcc.texi).
33 @c @finalout
34
35 @ifset INTERNALS
36 @ifset USING
37 @settitle Using and Porting GNU Fortran
38 @end ifset
39 @end ifset
40 @c seems reasonable to assume at least one of INTERNALS or USING is set...
41 @ifclear INTERNALS
42 @settitle Using GNU Fortran
43 @end ifclear
44 @ifclear USING
45 @settitle Porting GNU Fortran
46 @end ifclear
47 @c then again, have some fun
48 @ifclear INTERNALS
49 @ifclear USING
50 @settitle Doing Squat with GNU Fortran
51 @end ifclear
52 @end ifclear
53
54 @syncodeindex fn cp
55 @syncodeindex vr cp
56 @c %**end of header
57
58 @c Cause even numbered pages to be printed on the left hand side of
59 @c the page and odd numbered pages to be printed on the right hand
60 @c side of the page.  Using this, you can print on both sides of a
61 @c sheet of paper and have the text on the same part of the sheet.
62
63 @c The text on right hand pages is pushed towards the right hand
64 @c margin and the text on left hand pages is pushed toward the left
65 @c hand margin.
66 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
67
68 @c @tex
69 @c \global\bindingoffset=0.75in
70 @c \global\normaloffset =0.75in
71 @c @end tex
72
73 @ifinfo
74 @dircategory Programming
75 @direntry
76 * g77: (g77).                  The GNU Fortran compiler.
77 @end direntry
78 @ifset INTERNALS
79 @ifset USING
80 This file documents the use and the internals of the GNU Fortran (@code{g77})
81 compiler.
82 It corresponds to the @value{which-g77} version of @code{g77}.
83 @end ifset
84 @end ifset
85 @ifclear USING
86 This file documents the internals of the GNU Fortran (@code{g77}) compiler.
87 It corresponds to the @value{which-g77} version of @code{g77}.
88 @end ifclear
89 @ifclear INTERNALS
90 This file documents the use of the GNU Fortran (@code{g77}) compiler.
91 It corresponds to the @value{which-g77} version of @code{g77}.
92 @end ifclear
93
94 Published by the Free Software Foundation
95 59 Temple Place - Suite 330
96 Boston, MA 02111-1307 USA
97
98 Copyright (C) @value{copyrights-g77} Free Software Foundation, Inc.
99
100
101 Permission is granted to copy, distribute and/or modify this document
102 under the terms of the GNU Free Documentation License, Version 1.1 or
103 any later version published by the Free Software Foundation; with the
104 Invariant Sections being ``GNU General Public License'' and ``Funding
105 Free Software'', the Front-Cover
106 texts being (a) (see below), and with the Back-Cover Texts being (b)
107 (see below).  A copy of the license is included in the section entitled
108 ``GNU Free Documentation License''.
109
110 (a) The FSF's Front-Cover Text is:
111
112      A GNU Manual
113
114 (b) The FSF's Back-Cover Text is:
115
116      You have freedom to copy and modify this GNU Manual, like GNU
117      software.  Copies published by the Free Software Foundation raise
118      funds for GNU development.
119 @end ifinfo
120
121 Contributed by James Craig Burley (@email{@value{email-burley}}).
122 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
123 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
124
125 @setchapternewpage odd
126 @c @finalout
127 @titlepage
128 @ifset INTERNALS
129 @ifset USING
130 @center @titlefont{Using and Porting GNU Fortran}
131
132 @end ifset
133 @end ifset
134 @ifclear INTERNALS
135 @title Using GNU Fortran
136 @end ifclear
137 @ifclear USING
138 @title Porting GNU Fortran
139 @end ifclear
140 @sp 2
141 @center James Craig Burley
142 @sp 3
143 @center Last updated @value{last-update}
144 @sp 1
145 @center for version @value{version-g77}
146 @page
147 @vskip 0pt plus 1filll
148 Copyright @copyright{} @value{copyrights-g77} Free Software Foundation, Inc.
149 @sp 2
150 For the @value{which-g77} Version*
151 @sp 1
152 Published by the Free Software Foundation @*
153 59 Temple Place - Suite 330@*
154 Boston, MA 02111-1307, USA@*
155 @c Last printed ??ber, 19??.@*
156 @c Printed copies are available for $? each.@*
157 @c ISBN ???
158 @sp 1
159 Permission is granted to copy, distribute and/or modify this document
160 under the terms of the GNU Free Documentation License, Version 1.1 or
161 any later version published by the Free Software Foundation; with the
162 Invariant Sections being ``GNU General Public License'' and ``Funding
163 Free Software'', the Front-Cover
164 texts being (a) (see below), and with the Back-Cover Texts being (b)
165 (see below).  A copy of the license is included in the section entitled
166 ``GNU Free Documentation License''.
167
168 (a) The FSF's Front-Cover Text is:
169
170      A GNU Manual
171
172 (b) The FSF's Back-Cover Text is:
173
174      You have freedom to copy and modify this GNU Manual, like GNU
175      software.  Copies published by the Free Software Foundation raise
176      funds for GNU development.
177 @end titlepage
178 @summarycontents
179 @contents
180 @page
181
182 @ifinfo
183
184 @node Top, Copying,, (DIR)
185 @top Introduction
186 @cindex Introduction
187
188 @ifset INTERNALS
189 @ifset USING
190 This manual documents how to run, install and port @code{g77},
191 as well as its new features and incompatibilities,
192 and how to report bugs.
193 It corresponds to the @value{which-g77} version of @code{g77}.
194 @end ifset
195 @end ifset
196
197 @ifclear INTERNALS
198 This manual documents how to run and install @code{g77},
199 as well as its new features and incompatibilities, and how to report
200 bugs.
201 It corresponds to the @value{which-g77} version of @code{g77}.
202 @end ifclear
203 @ifclear USING
204 This manual documents how to port @code{g77},
205 as well as its new features and incompatibilities,
206 and how to report bugs.
207 It corresponds to the @value{which-g77} version of @code{g77}.
208 @end ifclear
209
210 @end ifinfo
211
212 @ifset DEVELOPMENT
213 @emph{Warning:} This document is still under development,
214 and might not accurately reflect the @code{g77} code base
215 of which it is a part.
216 Efforts are made to keep it somewhat up-to-date,
217 but they are particularly concentrated
218 on any version of this information
219 that is distributed as part of a @emph{released} @code{g77}.
220
221 In particular, while this document is intended to apply to
222 the @value{which-g77} version of @code{g77},
223 only an official @emph{release} of that version
224 is expected to contain documentation that is
225 most consistent with the @code{g77} product in that version.
226 @end ifset
227
228 @menu
229 * Copying::         GNU General Public License says
230                     how you can copy and share GNU Fortran.
231 * GNU Free Documentation License::
232                     How you can copy and share this manual.
233 * Contributors::    People who have contributed to GNU Fortran.
234 * Funding::         How to help assure continued work for free software.
235 * Funding GNU Fortran::  How to help assure continued work on GNU Fortran.
236 @ifset USING
237 * Getting Started:: Finding your way around this manual.
238 * What is GNU Fortran?::  How @code{g77} fits into the universe.
239 * G77 and GCC::     You can compile Fortran, C, or other programs.
240 * Invoking G77::    Command options supported by @code{g77}.
241 * News::            News about recent releases of @code{g77}.
242 * Changes::         User-visible changes to recent releases of @code{g77}.
243 * Language::        The GNU Fortran language.
244 * Compiler::        The GNU Fortran compiler.
245 * Other Dialects::  Dialects of Fortran supported by @code{g77}.
246 * Other Compilers:: Fortran compilers other than @code{g77}.
247 * Other Languages:: Languages other than Fortran.
248 * Debugging and Interfacing::  How @code{g77} generates code.
249 * Collected Fortran Wisdom::  How to avoid Trouble.
250 * Trouble::         If you have trouble with GNU Fortran.
251 * Open Questions::  Things we'd like to know.
252 * Bugs::            How, why, and where to report bugs.
253 * Service::         How to find suppliers of support for GNU Fortran.
254 @end ifset
255 @ifset INTERNALS
256 * Adding Options::  Guidance on teaching @code{g77} about new options.
257 * Projects::        Projects for @code{g77} internals hackers.
258 * Front End::       Design and implementation of the @code{g77} front end.
259 @end ifset
260
261 * M: Diagnostics.   Diagnostics produced by @code{g77}.
262
263 * Index::           Index of concepts and symbol names.
264 @end menu
265 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
266
267 @include gpl.texi
268
269 @include fdl.texi
270
271 @node Contributors
272 @unnumbered Contributors to GNU Fortran
273 @cindex contributors
274 @cindex credits
275
276 In addition to James Craig Burley, who wrote the front end,
277 many people have helped create and improve GNU Fortran.
278
279 @itemize @bullet
280 @item
281 The packaging and compiler portions of GNU Fortran are based largely
282 on the GNU CC compiler.
283 @xref{Contributors,,Contributors to GNU CC,gcc,Using and Porting GNU CC},
284 for more information.
285
286 @item
287 The run-time library used by GNU Fortran is a repackaged version
288 of the @code{libf2c} library (combined from the @code{libF77} and
289 @code{libI77} libraries) provided as part of @code{f2c}, available for
290 free from @code{netlib} sites on the Internet.
291
292 @item
293 Cygnus Support and The Free Software Foundation contributed
294 significant money and/or equipment to Craig's efforts.
295
296 @item
297 The following individuals served as alpha testers prior to @code{g77}'s
298 public release.  This work consisted of testing, researching, sometimes
299 debugging, and occasionally providing small amounts of code and fixes
300 for @code{g77}, plus offering plenty of helpful advice to Craig:
301
302 @itemize @w{}
303 @item
304 Jonathan Corbet
305 @item
306 Dr.@: Mark Fernyhough
307 @item
308 Takafumi Hayashi (The University of Aizu)---@email{takafumi@@u-aizu.ac.jp}
309 @item
310 Kate Hedstrom
311 @item
312 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
313 @item
314 Dr.@: A. O. V. Le Blanc
315 @item
316 Dave Love
317 @item
318 Rick Lutowski
319 @item
320 Toon Moene
321 @item
322 Rick Niles
323 @item
324 Derk Reefman
325 @item
326 Wayne K. Schroll
327 @item
328 Bill Thorson
329 @item
330 Pedro A. M. Vazquez
331 @item
332 Ian Watson
333 @end itemize
334
335 @item
336 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
337 provided the patch to add rudimentary support
338 for @code{INTEGER*1}, @code{INTEGER*2}, and
339 @code{LOGICAL*1}.
340 This inspired Craig to add further support,
341 even though the resulting support
342 would still be incomplete, because version 0.6 is still
343 a ways off.
344
345 @item
346 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
347 and encouraged Craig to rewrite the documentation in texinfo
348 format by contributing a first pass at a translation of the
349 old @file{g77-0.5.16/f/DOC} file.
350
351 @item
352 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
353 some analysis of generated code as part of an overall project
354 to improve @code{g77} code generation to at least be as good
355 as @code{f2c} used in conjunction with @code{gcc}.
356 So far, this has resulted in the three, somewhat
357 experimental, options added by @code{g77} to the @code{gcc}
358 compiler and its back end.
359
360 (These, in turn, had made their way into the @code{egcs}
361 version of the compiler, and do not exist in @code{gcc}
362 version 2.8 or versions of @code{g77} based on that version
363 of @code{gcc}.)
364
365 @item
366 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
367
368 @item
369 Thanks to Mary Cortani and the staff at Craftwork Solutions
370 (@email{support@@craftwork.com}) for all of their support.
371
372 @item
373 Many other individuals have helped debug, test, and improve @code{g77}
374 over the past several years, and undoubtedly more people
375 will be doing so in the future.
376 If you have done so, and would like
377 to see your name listed in the above list, please ask!
378 The default is that people wish to remain anonymous.
379 @end itemize
380
381 @include funding.texi
382
383 @node Funding GNU Fortran
384 @chapter Funding GNU Fortran
385 @cindex funding improvements
386 @cindex improvements, funding
387
388 James Craig Burley (@email{@value{email-burley}}), the original author
389 of g77, stopped working on it in September 1999
390 (He has a web page at @uref{@value{www-burley}}.)
391
392 GNU Fortran is currently maintained by Toon Moene
393 (@email{toon@@moene.indiv.nluug.nl}), with the help of countless other
394 volunteers.
395
396 As with other GNU software, funding is important because it can pay for
397 needed equipment, personnel, and so on.
398
399 @cindex FSF, funding the
400 @cindex funding the FSF
401 The FSF provides information on the best way to fund ongoing
402 development of GNU software (such as GNU Fortran) in documents
403 such as the ``GNUS Bulletin''.
404 Email @email{gnu@@gnu.org} for information on funding the FSF.
405
406 Another important way to support work on GNU Fortran is to volunteer
407 to help out.
408 Work is needed on documentation, testing, porting
409 to various machines, and in some cases, coding (although major
410 changes planned for version 0.6 make it difficult to add manpower to this
411 area).
412 Email @email{@value{email-general}} to volunteer for this work.
413
414 @xref{Funding,,Funding Free Software}, for more information.
415
416 @node Getting Started
417 @chapter Getting Started
418 @cindex getting started
419 @cindex new users
420 @cindex newbies
421 @cindex beginners
422
423 If you don't need help getting started reading the portions
424 of this manual that are most important to you, you should skip
425 this portion of the manual.
426
427 If you are new to compilers, especially Fortran compilers, or
428 new to how compilers are structured under UNIX and UNIX-like
429 systems, you'll want to see @ref{What is GNU Fortran?}.
430
431 If you are new to GNU compilers, or have used only one GNU
432 compiler in the past and not had to delve into how it lets
433 you manage various versions and configurations of @code{gcc},
434 you should see @ref{G77 and GCC}.
435
436 Everyone except experienced @code{g77} users should
437 see @ref{Invoking G77}.
438
439 If you're acquainted with previous versions of @code{g77},
440 you should see @ref{News,,News About GNU Fortran}.
441 Further, if you've actually used previous versions of @code{g77},
442 especially if you've written or modified Fortran code to
443 be compiled by previous versions of @code{g77}, you
444 should see @ref{Changes}.
445
446 If you intend to write or otherwise compile code that is
447 not already strictly conforming ANSI FORTRAN 77---and this
448 is probably everyone---you should see @ref{Language}.
449
450 If you run into trouble getting Fortran code to compile,
451 link, run, or work properly, you might find answers
452 if you see @ref{Debugging and Interfacing},
453 see @ref{Collected Fortran Wisdom},
454 and see @ref{Trouble}.
455 You might also find that the problems you are encountering
456 are bugs in @code{g77}---see @ref{Bugs}, for information on
457 reporting them, after reading the other material.
458
459 If you need further help with @code{g77}, or with
460 freely redistributable software in general,
461 see @ref{Service}.
462
463 If you would like to help the @code{g77} project,
464 see @ref{Funding GNU Fortran}, for information on
465 helping financially, and see @ref{Projects}, for information
466 on helping in other ways.
467
468 If you're generally curious about the future of
469 @code{g77}, see @ref{Projects}.
470 If you're curious about its past,
471 see @ref{Contributors},
472 and see @ref{Funding GNU Fortran}.
473
474 To see a few of the questions maintainers of @code{g77} have,
475 and that you might be able to answer,
476 see @ref{Open Questions}.
477
478 @ifset USING
479 @node What is GNU Fortran?
480 @chapter What is GNU Fortran?
481 @cindex concepts, basic
482 @cindex basic concepts
483
484 GNU Fortran, or @code{g77}, is designed initially as a free replacement
485 for, or alternative to, the UNIX @code{f77} command.
486 (Similarly, @code{gcc} is designed as a replacement
487 for the UNIX @code{cc} command.)
488
489 @code{g77} also is designed to fit in well with the other
490 fine GNU compilers and tools.
491
492 Sometimes these design goals conflict---in such cases, resolution
493 often is made in favor of fitting in well with Project GNU.
494 These cases are usually identified in the appropriate
495 sections of this manual.
496
497 @cindex compilers
498 As compilers, @code{g77}, @code{gcc}, and @code{f77}
499 share the following characteristics:
500
501 @itemize @bullet
502 @cindex source code
503 @cindex file, source
504 @cindex code, source
505 @cindex source file
506 @item
507 They read a user's program, stored in a file and
508 containing instructions written in the appropriate
509 language (Fortran, C, and so on).
510 This file contains @dfn{source code}.
511
512 @cindex translation of user programs
513 @cindex machine code
514 @cindex code, machine
515 @cindex mistakes
516 @item
517 They translate the user's program into instructions
518 a computer can carry out more quickly than it takes
519 to translate the instructions in the first place.
520 These instructions are called @dfn{machine code}---code
521 designed to be efficiently translated and processed
522 by a machine such as a computer.
523 Humans usually aren't as good writing machine code
524 as they are at writing Fortran or C, because
525 it is easy to make tiny mistakes writing machine code.
526 When writing Fortran or C, it is easy
527 to make big mistakes.
528
529 @cindex debugger
530 @cindex bugs, finding
531 @cindex @code{gdb}, command
532 @cindex commands, @code{gdb}
533 @item
534 They provide information in the generated machine code
535 that can make it easier to find bugs in the program
536 (using a debugging tool, called a @dfn{debugger},
537 such as @code{gdb}).
538
539 @cindex libraries
540 @cindex linking
541 @cindex @code{ld} command
542 @cindex commands, @code{ld}
543 @item
544 They locate and gather machine code already generated
545 to perform actions requested by statements in
546 the user's program.
547 This machine code is organized
548 into @dfn{libraries} and is located and gathered
549 during the @dfn{link} phase of the compilation
550 process.
551 (Linking often is thought of as a separate
552 step, because it can be directly invoked via the
553 @code{ld} command.
554 However, the @code{g77} and @code{gcc}
555 commands, as with most compiler commands, automatically
556 perform the linking step by calling on @code{ld}
557 directly, unless asked to not do so by the user.)
558
559 @cindex language, incorrect use of
560 @cindex incorrect use of language
561 @item
562 They attempt to diagnose cases where the user's
563 program contains incorrect usages of the language.
564 The @dfn{diagnostics} produced by the compiler
565 indicate the problem and the location in the user's
566 source file where the problem was first noticed.
567 The user can use this information to locate and
568 fix the problem.
569 @cindex diagnostics, incorrect
570 @cindex incorrect diagnostics
571 @cindex error messages, incorrect
572 @cindex incorrect error messages
573 (Sometimes an incorrect usage
574 of the language leads to a situation where the
575 compiler can no longer make any sense of what
576 follows---while a human might be able to---and
577 thus ends up complaining about many ``problems''
578 it encounters that, in fact, stem from just one
579 problem, usually the first one reported.)
580
581 @cindex warnings
582 @cindex questionable instructions
583 @item
584 They attempt to diagnose cases where the user's
585 program contains a correct usage of the language,
586 but instructs the computer to do something questionable.
587 These diagnostics often are in the form of @dfn{warnings},
588 instead of the @dfn{errors} that indicate incorrect
589 usage of the language.
590 @end itemize
591
592 How these actions are performed is generally under the
593 control of the user.
594 Using command-line options, the user can specify
595 how persnickety the compiler is to be regarding
596 the program (whether to diagnose questionable usage
597 of the language), how much time to spend making
598 the generated machine code run faster, and so on.
599
600 @cindex components of g77
601 @cindex @code{g77}, components of
602 @code{g77} consists of several components:
603
604 @cindex @code{gcc}, command
605 @cindex commands, @code{gcc}
606 @itemize @bullet
607 @item
608 A modified version of the @code{gcc} command, which also might be
609 installed as the system's @code{cc} command.
610 (In many cases, @code{cc} refers to the
611 system's ``native'' C compiler, which
612 might be a non-GNU compiler, or an older version
613 of @code{gcc} considered more stable or that is
614 used to build the operating system kernel.)
615
616 @cindex @code{g77}, command
617 @cindex commands, @code{g77}
618 @item
619 The @code{g77} command itself, which also might be installed as the
620 system's @code{f77} command.
621
622 @cindex libg2c library
623 @cindex libf2c library
624 @cindex libraries, libf2c
625 @cindex libraries, libg2c
626 @cindex run-time, library
627 @item
628 The @code{libg2c} run-time library.
629 This library contains the machine code needed to support
630 capabilities of the Fortran language that are not directly
631 provided by the machine code generated by the @code{g77}
632 compilation phase.
633
634 @code{libg2c} is just the unique name @code{g77} gives
635 to its version of @code{libf2c} to distinguish it from
636 any copy of @code{libf2c} installed from @code{f2c}
637 (or versions of @code{g77} that built @code{libf2c} under
638 that same name)
639 on the system.
640
641 The maintainer of @code{libf2c} currently is
642 @email{dmg@@bell-labs.com}.
643
644 @cindex @code{f771}, program
645 @cindex programs, @code{f771}
646 @cindex assembler
647 @cindex @code{as} command
648 @cindex commands, @code{as}
649 @cindex assembly code
650 @cindex code, assembly
651 @item
652 The compiler itself, internally named @code{f771}.
653
654 Note that @code{f771} does not generate machine code directly---it
655 generates @dfn{assembly code} that is a more readable form
656 of machine code, leaving the conversion to actual machine code
657 to an @dfn{assembler}, usually named @code{as}.
658 @end itemize
659
660 @code{gcc} is often thought of as ``the C compiler'' only,
661 but it does more than that.
662 Based on command-line options and the names given for files
663 on the command line, @code{gcc} determines which actions to perform, including
664 preprocessing, compiling (in a variety of possible languages), assembling,
665 and linking.
666
667 @cindex driver, gcc command as
668 @cindex @code{gcc}, command as driver
669 @cindex executable file
670 @cindex files, executable
671 @cindex cc1 program
672 @cindex programs, cc1
673 @cindex preprocessor
674 @cindex cpp program
675 @cindex programs, cpp
676 For example, the command @samp{gcc foo.c} @dfn{drives} the file
677 @file{foo.c} through the preprocessor @code{cpp}, then
678 the C compiler (internally named
679 @code{cc1}), then the assembler (usually @code{as}), then the linker
680 (@code{ld}), producing an executable program named @file{a.out} (on
681 UNIX systems).
682
683 @cindex cc1plus program
684 @cindex programs, cc1plus
685 As another example, the command @samp{gcc foo.cc} would do much the same as
686 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
687 @code{gcc} would use the C++ compiler (named @code{cc1plus}).
688
689 @cindex @code{f771}, program
690 @cindex programs, @code{f771}
691 In a GNU Fortran installation, @code{gcc} recognizes Fortran source
692 files by name just like it does C and C++ source files.
693 It knows to use the Fortran compiler named @code{f771}, instead of
694 @code{cc1} or @code{cc1plus}, to compile Fortran files.
695
696 @cindex @code{gcc}, not recognizing Fortran source
697 @cindex unrecognized file format
698 @cindex file format not recognized
699 Non-Fortran-related operation of @code{gcc} is generally
700 unaffected by installing the GNU Fortran version of @code{gcc}.
701 However, without the installed version of @code{gcc} being the
702 GNU Fortran version, @code{gcc} will not be able to compile
703 and link Fortran programs---and since @code{g77} uses @code{gcc}
704 to do most of the actual work, neither will @code{g77}!
705
706 @cindex @code{g77}, command
707 @cindex commands, @code{g77}
708 The @code{g77} command is essentially just a front-end for
709 the @code{gcc} command.
710 Fortran users will normally use @code{g77} instead of @code{gcc},
711 because @code{g77}
712 knows how to specify the libraries needed to link with Fortran programs
713 (@code{libg2c} and @code{lm}).
714 @code{g77} can still compile and link programs and
715 source files written in other languages, just like @code{gcc}.
716
717 @cindex printing version information
718 @cindex version information, printing
719 The command @samp{g77 -v} is a quick
720 way to display lots of version information for the various programs
721 used to compile a typical preprocessed Fortran source file---this
722 produces much more output than @samp{gcc -v} currently does.
723 (If it produces an error message near the end of the output---diagnostics
724 from the linker, usually @code{ld}---you might
725 have an out-of-date @code{libf2c} that improperly handles
726 complex arithmetic.)
727 In the output of this command, the line beginning @samp{GNU Fortran Front
728 End} identifies the version number of GNU Fortran; immediately
729 preceding that line is a line identifying the version of @code{gcc}
730 with which that version of @code{g77} was built.
731
732 @cindex libf2c library
733 @cindex libraries, libf2c
734 The @code{libf2c} library is distributed with GNU Fortran for
735 the convenience of its users, but is not part of GNU Fortran.
736 It contains the procedures
737 needed by Fortran programs while they are running.
738
739 @cindex in-line code
740 @cindex code, in-line
741 For example, while code generated by @code{g77} is likely
742 to do additions, subtractions, and multiplications @dfn{in line}---in
743 the actual compiled code---it is not likely to do trigonometric
744 functions this way.
745
746 Instead, operations like trigonometric
747 functions are compiled by the @code{f771} compiler
748 (invoked by @code{g77} when compiling Fortran code) into machine
749 code that, when run, calls on functions in @code{libg2c}, so
750 @code{libg2c} must be linked with almost every useful program
751 having any component compiled by GNU Fortran.
752 (As mentioned above, the @code{g77} command takes
753 care of all this for you.)
754
755 The @code{f771} program represents most of what is unique to GNU Fortran.
756 While much of the @code{libg2c} component comes from
757 the @code{libf2c} component of @code{f2c},
758 a free Fortran-to-C converter distributed by Bellcore (AT&T),
759 plus @code{libU77}, provided by Dave Love,
760 and the @code{g77} command is just a small front-end to @code{gcc},
761 @code{f771} is a combination of two rather
762 large chunks of code.
763
764 @cindex GNU Back End (GBE)
765 @cindex GBE
766 @cindex @code{gcc}, back end
767 @cindex back end, gcc
768 @cindex code generator
769 One chunk is the so-called @dfn{GNU Back End}, or GBE,
770 which knows how to generate fast code for a wide variety of processors.
771 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
772 @code{cc1plus}, and @code{f771}, plus others.
773 Often the GBE is referred to as the ``gcc back end'' or
774 even just ``gcc''---in this manual, the term GBE is used
775 whenever the distinction is important.
776
777 @cindex GNU Fortran Front End (FFE)
778 @cindex FFE
779 @cindex @code{g77}, front end
780 @cindex front end, @code{g77}
781 The other chunk of @code{f771} is the
782 majority of what is unique about GNU Fortran---the code that knows how
783 to interpret Fortran programs to determine what they are intending to
784 do, and then communicate that knowledge to the GBE for actual compilation
785 of those programs.
786 This chunk is called the @dfn{Fortran Front End} (FFE).
787 The @code{cc1} and @code{cc1plus} programs have their own front ends,
788 for the C and C++ languages, respectively.
789 These fronts ends are responsible for diagnosing
790 incorrect usage of their respective languages by the
791 programs the process, and are responsible for most of
792 the warnings about questionable constructs as well.
793 (The GBE handles producing some warnings, like those
794 concerning possible references to undefined variables.)
795
796 Because so much is shared among the compilers for various languages,
797 much of the behavior and many of the user-selectable options for these
798 compilers are similar.
799 For example, diagnostics (error messages and
800 warnings) are similar in appearance; command-line
801 options like @samp{-Wall} have generally similar effects; and the quality
802 of generated code (in terms of speed and size) is roughly similar
803 (since that work is done by the shared GBE).
804
805 @node G77 and GCC
806 @chapter Compile Fortran, C, or Other Programs
807 @cindex compiling programs
808 @cindex programs, compiling
809
810 @cindex @code{gcc}, command
811 @cindex commands, @code{gcc}
812 A GNU Fortran installation includes a modified version of the @code{gcc}
813 command.
814
815 In a non-Fortran installation, @code{gcc} recognizes C, C++,
816 and Objective-C source files.
817
818 In a GNU Fortran installation, @code{gcc} also recognizes Fortran source
819 files and accepts Fortran-specific command-line options, plus some
820 command-line options that are designed to cater to Fortran users
821 but apply to other languages as well.
822
823 @xref{G++ and GCC,,Compile C; C++; or Objective-C,gcc,Using and Porting GNU CC},
824 for information on the way different languages are handled
825 by the GNU CC compiler (@code{gcc}).
826
827 @cindex @code{g77}, command
828 @cindex commands, @code{g77}
829 Also provided as part of GNU Fortran is the @code{g77} command.
830 The @code{g77} command is designed to make compiling and linking Fortran
831 programs somewhat easier than when using the @code{gcc} command for
832 these tasks.
833 It does this by analyzing the command line somewhat and changing it
834 appropriately before submitting it to the @code{gcc} command.
835
836 @cindex -v option
837 @cindex @code{g77} options, -v
838 @cindex options, -v
839 Use the @samp{-v} option with @code{g77}
840 to see what is going on---the first line of output is the invocation
841 of the @code{gcc} command.
842
843 @node Invoking G77
844 @chapter GNU Fortran Command Options
845 @cindex GNU Fortran command options
846 @cindex command options
847 @cindex options, GNU Fortran command
848
849 The @code{g77} command supports all the options supported by the
850 @code{gcc} command.
851 @xref{Invoking GCC,,GNU CC Command Options,gcc,Using and Porting GNU CC},
852 for information
853 on the non-Fortran-specific aspects of the @code{gcc} command (and,
854 therefore, the @code{g77} command).
855
856 @cindex options, negative forms
857 @cindex negative forms of options
858 All @code{gcc} and @code{g77} options
859 are accepted both by @code{g77} and by @code{gcc}
860 (as well as any other drivers built at the same time,
861 such as @code{g++}),
862 since adding @code{g77} to the @code{gcc} distribution
863 enables acceptance of @code{g77}-specific options
864 by all of the relevant drivers.
865
866 In some cases, options have positive and negative forms;
867 the negative form of @samp{-ffoo} would be @samp{-fno-foo}.
868 This manual documents only one of these two forms, whichever
869 one is not the default.
870
871 @menu
872 * Option Summary::      Brief list of all @code{g77} options,
873                         without explanations.
874 * Overall Options::     Controlling the kind of output:
875                         an executable, object files, assembler files,
876                         or preprocessed source.
877 * Shorthand Options::   Options that are shorthand for other options.
878 * Fortran Dialect Options::  Controlling the variant of Fortran language
879                              compiled.
880 * Warning Options::     How picky should the compiler be?
881 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
882 * Optimize Options::    How much optimization?
883 * Preprocessor Options:: Controlling header files and macro definitions.
884                          Also, getting dependency information for Make.
885 * Directory Options::   Where to find header files and libraries.
886                         Where to find the compiler executable files.
887 * Code Gen Options::    Specifying conventions for function calls, data layout
888                         and register usage.
889 * Environment Variables:: Env vars that affect GNU Fortran.
890 @end menu
891
892 @node Option Summary
893 @section Option Summary
894
895 Here is a summary of all the options specific to GNU Fortran, grouped
896 by type.  Explanations are in the following sections.
897
898 @table @emph
899 @item Overall Options
900 @xref{Overall Options,,Options Controlling the Kind of Output}.
901 @smallexample
902 -fversion  -fset-g77-defaults  -fno-silent
903 @end smallexample
904
905 @item Shorthand Options
906 @xref{Shorthand Options}.
907 @smallexample
908 -ff66  -fno-f66  -ff77  -fno-f77  -fno-ugly
909 @end smallexample
910
911 @item Fortran Language Options
912 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
913 @smallexample
914 -ffree-form  -fno-fixed-form  -ff90
915 -fvxt  -fdollar-ok  -fno-backslash
916 -fno-ugly-args  -fno-ugly-assign  -fno-ugly-assumed
917 -fugly-comma  -fugly-complex  -fugly-init  -fugly-logint
918 -fonetrip  -ftypeless-boz
919 -fintrin-case-initcap  -fintrin-case-upper
920 -fintrin-case-lower  -fintrin-case-any
921 -fmatch-case-initcap  -fmatch-case-upper
922 -fmatch-case-lower  -fmatch-case-any
923 -fsource-case-upper  -fsource-case-lower
924 -fsource-case-preserve
925 -fsymbol-case-initcap  -fsymbol-case-upper
926 -fsymbol-case-lower  -fsymbol-case-any
927 -fcase-strict-upper  -fcase-strict-lower
928 -fcase-initcap  -fcase-upper  -fcase-lower  -fcase-preserve
929 -ff2c-intrinsics-delete  -ff2c-intrinsics-hide
930 -ff2c-intrinsics-disable  -ff2c-intrinsics-enable
931 -fbadu77-intrinsics-delete  -fbadu77-intrinsics-hide
932 -fbadu77-intrinsics-disable  -fbadu77-intrinsics-enable
933 -ff90-intrinsics-delete  -ff90-intrinsics-hide
934 -ff90-intrinsics-disable  -ff90-intrinsics-enable
935 -fgnu-intrinsics-delete  -fgnu-intrinsics-hide
936 -fgnu-intrinsics-disable  -fgnu-intrinsics-enable
937 -fmil-intrinsics-delete  -fmil-intrinsics-hide
938 -fmil-intrinsics-disable  -fmil-intrinsics-enable
939 -funix-intrinsics-delete  -funix-intrinsics-hide
940 -funix-intrinsics-disable  -funix-intrinsics-enable
941 -fvxt-intrinsics-delete  -fvxt-intrinsics-hide
942 -fvxt-intrinsics-disable  -fvxt-intrinsics-enable
943 -ffixed-line-length-@var{n}  -ffixed-line-length-none
944 @end smallexample
945
946 @item Warning Options
947 @xref{Warning Options,,Options to Request or Suppress Warnings}.
948 @smallexample
949 -fsyntax-only  -pedantic  -pedantic-errors  -fpedantic
950 -w  -Wno-globals  -Wimplicit  -Wunused  -Wuninitialized
951 -Wall  -Wsurprising
952 -Werror  -W
953 @end smallexample
954
955 @item Debugging Options
956 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
957 @smallexample
958 -g
959 @end smallexample
960
961 @item Optimization Options
962 @xref{Optimize Options,,Options that Control Optimization}.
963 @smallexample
964 -malign-double
965 -ffloat-store  -fforce-mem  -fforce-addr  -fno-inline
966 -ffast-math  -fstrength-reduce  -frerun-cse-after-loop
967 -funsafe-math-optimizations -fno-trapping-math
968 -fexpensive-optimizations  -fdelayed-branch
969 -fschedule-insns  -fschedule-insn2  -fcaller-saves
970 -funroll-loops  -funroll-all-loops
971 -fno-move-all-movables  -fno-reduce-all-givs
972 -fno-rerun-loop-opt
973 @end smallexample
974
975 @item Directory Options
976 @xref{Directory Options,,Options for Directory Search}.
977 @smallexample
978 -I@var{dir}  -I-
979 @end smallexample
980
981 @item Code Generation Options
982 @xref{Code Gen Options,,Options for Code Generation Conventions}.
983 @smallexample
984 -fno-automatic  -finit-local-zero  -fno-f2c
985 -ff2c-library  -fno-underscoring  -fno-ident
986 -fpcc-struct-return  -freg-struct-return
987 -fshort-double  -fno-common  -fpack-struct
988 -fzeros  -fno-second-underscore
989 -femulate-complex
990 -falias-check  -fargument-alias
991 -fargument-noalias  -fno-argument-noalias-global
992 -fno-globals  -fflatten-arrays
993 -fbounds-check  -ffortran-bounds-check
994 @end smallexample
995 @end table
996
997 @menu
998 * Overall Options::     Controlling the kind of output:
999                         an executable, object files, assembler files,
1000                         or preprocessed source.
1001 * Shorthand Options::   Options that are shorthand for other options.
1002 * Fortran Dialect Options::  Controlling the variant of Fortran language
1003                              compiled.
1004 * Warning Options::     How picky should the compiler be?
1005 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1006 * Optimize Options::    How much optimization?
1007 * Preprocessor Options:: Controlling header files and macro definitions.
1008                          Also, getting dependency information for Make.
1009 * Directory Options::   Where to find header files and libraries.
1010                         Where to find the compiler executable files.
1011 * Code Gen Options::    Specifying conventions for function calls, data layout
1012                         and register usage.
1013 @end menu
1014
1015 @node Overall Options
1016 @section Options Controlling the Kind of Output
1017 @cindex overall options
1018 @cindex options, overall
1019
1020 Compilation can involve as many as four stages: preprocessing, code
1021 generation (often what is really meant by the term ``compilation''),
1022 assembly, and linking, always in that order.  The first three
1023 stages apply to an individual source file, and end by producing an
1024 object file; linking combines all the object files (those newly
1025 compiled, and those specified as input) into an executable file.
1026
1027 @cindex file name suffix
1028 @cindex suffixes, file name
1029 @cindex file name extension
1030 @cindex extensions, file name
1031 @cindex file type
1032 @cindex types, file
1033 For any given input file, the file name suffix determines what kind of
1034 program is contained in the file---that is, the language in which the
1035 program is written is generally indicated by the suffix.
1036 Suffixes specific to GNU Fortran are listed below.
1037 @xref{Overall Options,,gcc,Using and Porting GNU CC}, for
1038 information on suffixes recognized by GNU CC.
1039
1040 @table @code
1041 @cindex .f filename suffix
1042 @cindex .for filename suffix
1043 @cindex .FOR filename suffix
1044 @item @var{file}.f
1045 @item @var{file}.for
1046 @item @var{file}.FOR
1047 Fortran source code that should not be preprocessed.
1048
1049 Such source code cannot contain any preprocessor directives, such
1050 as @code{#include}, @code{#define}, @code{#if}, and so on.
1051
1052 You can force @samp{.f} files to be preprocessed by @code{cpp} by using
1053 @samp{-x f77-cpp-input}.
1054 @xref{LEX}.
1055
1056 @cindex preprocessor
1057 @cindex C preprocessor
1058 @cindex cpp preprocessor
1059 @cindex Fortran preprocessor
1060 @cindex cpp program
1061 @cindex programs, cpp
1062 @cindex .F filename suffix
1063 @cindex .fpp filename suffix
1064 @cindex .FPP filename suffix
1065 @item @var{file}.F
1066 @item @var{file}.fpp
1067 @item @var{file}.FPP
1068 Fortran source code that must be preprocessed (by the C preprocessor
1069 @code{cpp}, which is part of GNU CC).
1070
1071 Note that preprocessing is not extended to the contents of
1072 files included by the @code{INCLUDE} directive---the @code{#include}
1073 preprocessor directive must be used instead.
1074
1075 @cindex Ratfor preprocessor
1076 @cindex programs, @code{ratfor}
1077 @cindex @samp{.r} filename suffix
1078 @cindex @code{ratfor}
1079 @item @var{file}.r
1080 Ratfor source code, which must be preprocessed by the @code{ratfor}
1081 command, which is available separately (as it is not yet part of the GNU
1082 Fortran distribution).
1083 One version in Fortran, adapted for use with @code{g77}, is at
1084 @uref{ftp://members.aol.com/n8tm/rat7.uue} (of uncertain copyright
1085 status).  Another, public domain version in C is at
1086 @uref{http://sepwww.stanford.edu/sep/prof/ratfor.shar.2}.
1087 @end table
1088
1089 UNIX users typically use the @file{@var{file}.f} and @file{@var{file}.F}
1090 nomenclature.
1091 Users of other operating systems, especially those that cannot
1092 distinguish upper-case
1093 letters from lower-case letters in their file names, typically use
1094 the @file{@var{file}.for} and @file{@var{file}.fpp} nomenclature.
1095
1096 @cindex #define
1097 @cindex #include
1098 @cindex #if
1099 Use of the preprocessor @code{cpp} allows use of C-like
1100 constructs such as @code{#define} and @code{#include}, but can
1101 lead to unexpected, even mistaken, results due to Fortran's source file
1102 format.
1103 It is recommended that use of the C preprocessor
1104 be limited to @code{#include} and, in
1105 conjunction with @code{#define}, only @code{#if} and related directives,
1106 thus avoiding in-line macro expansion entirely.
1107 This recommendation applies especially
1108 when using the traditional fixed source form.
1109 With free source form,
1110 fewer unexpected transformations are likely to happen, but use of
1111 constructs such as Hollerith and character constants can nevertheless
1112 present problems, especially when these are continued across multiple
1113 source lines.
1114 These problems result, primarily, from differences between the way
1115 such constants are interpreted by the C preprocessor and by a Fortran
1116 compiler.
1117
1118 Another example of a problem that results from using the C preprocessor
1119 is that a Fortran comment line that happens to contain any
1120 characters ``interesting'' to the C preprocessor,
1121 such as a backslash at the end of the line,
1122 is not recognized by the preprocessor as a comment line,
1123 so instead of being passed through ``raw'',
1124 the line is edited according to the rules for the preprocessor.
1125 For example, the backslash at the end of the line is removed,
1126 along with the subsequent newline, resulting in the next
1127 line being effectively commented out---unfortunate if that
1128 line is a non-comment line of important code!
1129
1130 @emph{Note:} The @samp{-traditional} and @samp{-undef} flags are supplied
1131 to @code{cpp} by default, to help avoid unpleasant surprises.
1132 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
1133 gcc,Using and Porting GNU CC}.
1134 This means that ANSI C preprocessor features (such as the @samp{#}
1135 operator) aren't available, and only variables in the C reserved
1136 namespace (generally, names with a leading underscore) are liable to
1137 substitution by C predefines.
1138 Thus, if you want to do system-specific
1139 tests, use, for example, @samp{#ifdef __linux__} rather than @samp{#ifdef linux}.
1140 Use the @samp{-v} option to see exactly how the preprocessor is invoked.
1141
1142 @cindex /*
1143 Unfortunately, the @samp{-traditional} flag will not avoid an error from
1144 anything that @code{cpp} sees as an unterminated C comment, such as:
1145 @smallexample
1146 C Some Fortran compilers accept /* as starting
1147 C an inline comment.
1148 @end smallexample
1149 @xref{Trailing Comment}.
1150
1151 The following options that affect overall processing are recognized
1152 by the @code{g77} and @code{gcc} commands in a GNU Fortran installation:
1153
1154 @table @code
1155 @cindex -fversion option
1156 @cindex options, -fversion
1157 @cindex printing version information
1158 @cindex version information, printing
1159 @cindex consistency checks
1160 @cindex internal consistency checks
1161 @cindex checks, of internal consistency
1162 @item -fversion
1163 Ensure that the @code{g77}-specific version of the compiler phase is reported,
1164 if run,
1165 and, starting in @code{egcs} version 1.1,
1166 that internal consistency checks in the @file{f771} program are run.
1167
1168 This option is supplied automatically when @samp{-v} or @samp{--verbose}
1169 is specified as a command-line option for @code{g77} or @code{gcc}
1170 and when the resulting commands compile Fortran source files.
1171
1172 @cindex -fset-g77-defaults option
1173 @cindex options, -fset-g77-defaults
1174 @item -fset-g77-defaults
1175 @emph{Version info:}
1176 This option was obsolete as of @code{egcs}
1177 version 1.1.
1178 The effect is instead achieved
1179 by the @code{lang_init_options} routine
1180 in @file{gcc/gcc/f/com.c}.
1181
1182 @cindex consistency checks
1183 @cindex internal consistency checks
1184 @cindex checks, of internal consistency
1185 Set up whatever @code{gcc} options are to apply to Fortran
1186 compilations, and avoid running internal consistency checks
1187 that might take some time.
1188
1189 This option is supplied automatically when compiling Fortran code
1190 via the @code{g77} or @code{gcc} command.
1191 The description of this option is provided so that users seeing
1192 it in the output of, say, @samp{g77 -v} understand why it is
1193 there.
1194
1195 @cindex modifying g77
1196 @cindex code, modifying
1197 Also, developers who run @code{f771} directly might want to specify it
1198 by hand to get the same defaults as they would running @code{f771}
1199 via @code{g77} or @code{gcc}.
1200 However, such developers should, after linking a new @code{f771}
1201 executable, invoke it without this option once,
1202 e.g. via @kbd{./f771 -quiet < /dev/null},
1203 to ensure that they have not introduced any
1204 internal inconsistencies (such as in the table of
1205 intrinsics) before proceeding---@code{g77} will crash
1206 with a diagnostic if it detects an inconsistency.
1207
1208 @cindex -fno-silent option
1209 @cindex options, -fno-silent
1210 @cindex f2c compatibility
1211 @cindex compatibility, f2c
1212 @cindex status, compilation
1213 @cindex compilation, status
1214 @cindex reporting compilation status
1215 @cindex printing compilation status
1216 @item -fno-silent
1217 Print (to @code{stderr}) the names of the program units as
1218 they are compiled, in a form similar to that used by popular
1219 UNIX @code{f77} implementations and @code{f2c}.
1220 @end table
1221
1222 @xref{Overall Options,,Options Controlling the Kind of Output,
1223 gcc,Using and Porting GNU CC}, for information
1224 on more options that control the overall operation of the @code{gcc} command
1225 (and, by extension, the @code{g77} command).
1226
1227 @node Shorthand Options
1228 @section Shorthand Options
1229 @cindex shorthand options
1230 @cindex options, shorthand
1231 @cindex macro options
1232 @cindex options, macro
1233
1234 The following options serve as ``shorthand''
1235 for other options accepted by the compiler:
1236
1237 @table @code
1238 @cindex -fugly option
1239 @cindex options, -fugly
1240 @item -fugly
1241 @cindex ugly features
1242 @cindex features, ugly
1243 @emph{Note:} This option is no longer supported.
1244 The information, below, is provided to aid
1245 in the conversion of old scripts.
1246
1247 Specify that certain ``ugly'' constructs are to be quietly accepted.
1248 Same as:
1249
1250 @smallexample
1251 -fugly-args -fugly-assign -fugly-assumed
1252 -fugly-comma -fugly-complex -fugly-init
1253 -fugly-logint
1254 @end smallexample
1255
1256 These constructs are considered inappropriate to use in new
1257 or well-maintained portable Fortran code, but widely used
1258 in old code.
1259 @xref{Distensions}, for more information.
1260
1261 @cindex -fno-ugly option
1262 @cindex options, -fno-ugly
1263 @item -fno-ugly
1264 @cindex ugly features
1265 @cindex features, ugly
1266 Specify that all ``ugly'' constructs are to be noisily rejected.
1267 Same as:
1268
1269 @smallexample
1270 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1271 -fno-ugly-comma -fno-ugly-complex -fno-ugly-init
1272 -fno-ugly-logint
1273 @end smallexample
1274
1275 @xref{Distensions}, for more information.
1276
1277 @cindex -ff66 option
1278 @cindex options, -ff66
1279 @item -ff66
1280 @cindex FORTRAN 66
1281 @cindex compatibility, FORTRAN 66
1282 Specify that the program is written in idiomatic FORTRAN 66.
1283 Same as @samp{-fonetrip -fugly-assumed}.
1284
1285 The @samp{-fno-f66} option is the inverse of @samp{-ff66}.
1286 As such, it is the same as @samp{-fno-onetrip -fno-ugly-assumed}.
1287
1288 The meaning of this option is likely to be refined as future
1289 versions of @code{g77} provide more compatibility with other
1290 existing and obsolete Fortran implementations.
1291
1292 @cindex -ff77 option
1293 @cindex options, -ff77
1294 @item -ff77
1295 @cindex UNIX f77
1296 @cindex f2c compatibility
1297 @cindex compatibility, f2c
1298 @cindex f77 compatibility
1299 @cindex compatibility, f77
1300 Specify that the program is written in idiomatic UNIX FORTRAN 77
1301 and/or the dialect accepted by the @code{f2c} product.
1302 Same as @samp{-fbackslash -fno-typeless-boz}.
1303
1304 The meaning of this option is likely to be refined as future
1305 versions of @code{g77} provide more compatibility with other
1306 existing and obsolete Fortran implementations.
1307
1308 @cindex -fno-f77 option
1309 @cindex options, -fno-f77
1310 @item -fno-f77
1311 @cindex UNIX f77
1312 The @samp{-fno-f77} option is @emph{not} the inverse
1313 of @samp{-ff77}.
1314 It specifies that the program is not written in idiomatic UNIX
1315 FORTRAN 77 or @code{f2c}, but in a more widely portable dialect.
1316 @samp{-fno-f77} is the same as @samp{-fno-backslash}.
1317
1318 The meaning of this option is likely to be refined as future
1319 versions of @code{g77} provide more compatibility with other
1320 existing and obsolete Fortran implementations.
1321 @end table
1322
1323 @node Fortran Dialect Options
1324 @section Options Controlling Fortran Dialect
1325 @cindex dialect options
1326 @cindex language, dialect options
1327 @cindex options, dialect
1328
1329 The following options control the dialect of Fortran
1330 that the compiler accepts:
1331
1332 @table @code
1333 @cindex -ffree-form option
1334 @cindex options, -ffree-form
1335 @cindex -fno-fixed-form option
1336 @cindex options, -fno-fixed-form
1337 @cindex source file format
1338 @cindex free form
1339 @cindex fixed form
1340 @cindex Fortran 90, features
1341 @item -ffree-form
1342 @item -fno-fixed-form
1343 Specify that the source file is written in free form
1344 (introduced in Fortran 90) instead of the more-traditional fixed form.
1345
1346 @cindex -ff90 option
1347 @cindex options, -ff90
1348 @cindex Fortran 90, features
1349 @item -ff90
1350 Allow certain Fortran-90 constructs.
1351
1352 This option controls whether certain
1353 Fortran 90 constructs are recognized.
1354 (Other Fortran 90 constructs
1355 might or might not be recognized depending on other options such as
1356 @samp{-fvxt}, @samp{-ff90-intrinsics-enable}, and the
1357 current level of support for Fortran 90.)
1358
1359 @xref{Fortran 90}, for more information.
1360
1361 @cindex -fvxt option
1362 @cindex options, -fvxt
1363 @item -fvxt
1364 @cindex Fortran 90, features
1365 @cindex VXT extensions
1366 Specify the treatment of certain constructs that have different
1367 meanings depending on whether the code is written in
1368 GNU Fortran (based on FORTRAN 77 and akin to Fortran 90)
1369 or VXT Fortran (more like VAX FORTRAN).
1370
1371 The default is @samp{-fno-vxt}.
1372 @samp{-fvxt} specifies that the VXT Fortran interpretations
1373 for those constructs are to be chosen.
1374
1375 @xref{VXT Fortran}, for more information.
1376
1377 @cindex -fdollar-ok option
1378 @cindex options, -fdollar-ok
1379 @item -fdollar-ok
1380 @cindex dollar sign
1381 @cindex symbol names
1382 @cindex character set
1383 Allow @samp{$} as a valid character in a symbol name.
1384
1385 @cindex -fno-backslash option
1386 @cindex options, -fno-backslash
1387 @item -fno-backslash
1388 @cindex backslash
1389 @cindex character constants
1390 @cindex Hollerith constants
1391 Specify that @samp{\} is not to be specially interpreted in character
1392 and Hollerith constants a la C and many UNIX Fortran compilers.
1393
1394 For example, with @samp{-fbackslash} in effect, @samp{A\nB} specifies
1395 three characters, with the second one being newline.
1396 With @samp{-fno-backslash}, it specifies four characters,
1397 @samp{A}, @samp{\}, @samp{n}, and @samp{B}.
1398
1399 Note that @code{g77} implements a fairly general form of backslash
1400 processing that is incompatible with the narrower forms supported
1401 by some other compilers.
1402 For example, @samp{'A\003B'} is a three-character string in @code{g77},
1403 whereas other compilers that support backslash might not support
1404 the three-octal-digit form, and thus treat that string as longer
1405 than three characters.
1406
1407 @xref{Backslash in Constants}, for
1408 information on why @samp{-fbackslash} is the default
1409 instead of @samp{-fno-backslash}.
1410
1411 @cindex -fno-ugly-args option
1412 @cindex options, -fno-ugly-args
1413 @item -fno-ugly-args
1414 Disallow passing Hollerith and typeless constants as actual
1415 arguments (for example, @samp{CALL FOO(4HABCD)}).
1416
1417 @xref{Ugly Implicit Argument Conversion}, for more information.
1418
1419 @cindex -fugly-assign option
1420 @cindex options, -fugly-assign
1421 @item -fugly-assign
1422 Use the same storage for a given variable regardless of
1423 whether it is used to hold an assigned-statement label
1424 (as in @samp{ASSIGN 10 TO I}) or used to hold numeric data
1425 (as in @samp{I = 3}).
1426
1427 @xref{Ugly Assigned Labels}, for more information.
1428
1429 @cindex -fugly-assumed option
1430 @cindex options, -fugly-assumed
1431 @item -fugly-assumed
1432 Assume any dummy array with a final dimension specified as @samp{1}
1433 is really an assumed-size array, as if @samp{*} had been specified
1434 for the final dimension instead of @samp{1}.
1435
1436 For example, @samp{DIMENSION X(1)} is treated as if it
1437 had read @samp{DIMENSION X(*)}.
1438
1439 @xref{Ugly Assumed-Size Arrays}, for more information.
1440
1441 @cindex -fugly-comma option
1442 @cindex options, -fugly-comma
1443 @item -fugly-comma
1444 In an external-procedure invocation,
1445 treat a trailing comma in the argument list
1446 as specification of a trailing null argument,
1447 and treat an empty argument list
1448 as specification of a single null argument.
1449
1450 For example, @samp{CALL FOO(,)} is treated as
1451 @samp{CALL FOO(%VAL(0), %VAL(0))}.
1452 That is, @emph{two} null arguments are specified
1453 by the procedure call when @samp{-fugly-comma} is in force.
1454 And @samp{F = FUNC()} is treated as @samp{F = FUNC(%VAL(0))}.
1455
1456 The default behavior, @samp{-fno-ugly-comma}, is to ignore
1457 a single trailing comma in an argument list.
1458 So, by default, @samp{CALL FOO(X,)} is treated
1459 exactly the same as @samp{CALL FOO(X)}.
1460
1461 @xref{Ugly Null Arguments}, for more information.
1462
1463 @cindex -fugly-complex option
1464 @cindex options, -fugly-complex
1465 @item -fugly-complex
1466 Do not complain about @samp{REAL(@var{expr})} or
1467 @samp{AIMAG(@var{expr})} when @var{expr} is a @code{COMPLEX}
1468 type other than @code{COMPLEX(KIND=1)}---usually
1469 this is used to permit @code{COMPLEX(KIND=2)}
1470 (@code{DOUBLE COMPLEX}) operands.
1471
1472 The @samp{-ff90} option controls the interpretation
1473 of this construct.
1474
1475 @xref{Ugly Complex Part Extraction}, for more information.
1476
1477 @cindex -fno-ugly-init option
1478 @cindex options, -fno-ugly-init
1479 @item -fno-ugly-init
1480 Disallow use of Hollerith and typeless constants as initial
1481 values (in @code{PARAMETER} and @code{DATA} statements), and
1482 use of character constants to
1483 initialize numeric types and vice versa.
1484
1485 For example, @samp{DATA I/'F'/, CHRVAR/65/, J/4HABCD/} is disallowed by
1486 @samp{-fno-ugly-init}.
1487
1488 @xref{Ugly Conversion of Initializers}, for more information.
1489
1490 @cindex -fugly-logint option
1491 @cindex options, -fugly-logint
1492 @item -fugly-logint
1493 Treat @code{INTEGER} and @code{LOGICAL} variables and
1494 expressions as potential stand-ins for each other.
1495
1496 For example, automatic conversion between @code{INTEGER} and
1497 @code{LOGICAL} is enabled, for many contexts, via this option.
1498
1499 @xref{Ugly Integer Conversions}, for more information.
1500
1501 @cindex -fonetrip option
1502 @cindex options, -fonetrip
1503 @item -fonetrip
1504 @cindex FORTRAN 66
1505 @cindex @code{DO} loops, one-trip
1506 @cindex one-trip @code{DO} loops
1507 @cindex @code{DO} loops, zero-trip
1508 @cindex zero-trip @code{DO} loops
1509 @cindex compatibility, FORTRAN 66
1510 Executable iterative @code{DO} loops are to be executed at
1511 least once each time they are reached.
1512
1513 ANSI FORTRAN 77 and more recent versions of the Fortran standard
1514 specify that the body of an iterative @code{DO} loop is not executed
1515 if the number of iterations calculated from the parameters of the
1516 loop is less than 1.
1517 (For example, @samp{DO 10 I = 1, 0}.)
1518 Such a loop is called a @dfn{zero-trip loop}.
1519
1520 Prior to ANSI FORTRAN 77, many compilers implemented @code{DO} loops
1521 such that the body of a loop would be executed at least once, even
1522 if the iteration count was zero.
1523 Fortran code written assuming this behavior is said to require
1524 @dfn{one-trip loops}.
1525 For example, some code written to the FORTRAN 66 standard
1526 expects this behavior from its @code{DO} loops, although that
1527 standard did not specify this behavior.
1528
1529 The @samp{-fonetrip} option specifies that the source file(s) being
1530 compiled require one-trip loops.
1531
1532 This option affects only those loops specified by the (iterative) @code{DO}
1533 statement and by implied-@code{DO} lists in I/O statements.
1534 Loops specified by implied-@code{DO} lists in @code{DATA} and
1535 specification (non-executable) statements are not affected.
1536
1537 @cindex -ftypeless-boz option
1538 @cindex options, -ftypeless-boz
1539 @cindex prefix-radix constants
1540 @cindex constants, prefix-radix
1541 @cindex constants, types
1542 @cindex types, constants
1543 @item -ftypeless-boz
1544 Specifies that prefix-radix non-decimal constants, such as
1545 @samp{Z'ABCD'}, are typeless instead of @code{INTEGER(KIND=1)}.
1546
1547 You can test for yourself whether a particular compiler treats
1548 the prefix form as @code{INTEGER(KIND=1)} or typeless by running the
1549 following program:
1550
1551 @smallexample
1552 EQUIVALENCE (I, R)
1553 R = Z'ABCD1234'
1554 J = Z'ABCD1234'
1555 IF (J .EQ. I) PRINT *, 'Prefix form is TYPELESS'
1556 IF (J .NE. I) PRINT *, 'Prefix form is INTEGER'
1557 END
1558 @end smallexample
1559
1560 Reports indicate that many compilers process this form as
1561 @code{INTEGER(KIND=1)}, though a few as typeless, and at least one
1562 based on a command-line option specifying some kind of
1563 compatibility.
1564
1565 @cindex -fintrin-case-initcap option
1566 @cindex options, -fintrin-case-initcap
1567 @item -fintrin-case-initcap
1568 @cindex -fintrin-case-upper option
1569 @cindex options, -fintrin-case-upper
1570 @item -fintrin-case-upper
1571 @cindex -fintrin-case-lower option
1572 @cindex options, -fintrin-case-lower
1573 @item -fintrin-case-lower
1574 @cindex -fintrin-case-any option
1575 @cindex options, -fintrin-case-any
1576 @item -fintrin-case-any
1577 Specify expected case for intrinsic names.
1578 @samp{-fintrin-case-lower} is the default.
1579
1580 @cindex -fmatch-case-initcap option
1581 @cindex options, -fmatch-case-initcap
1582 @item -fmatch-case-initcap
1583 @cindex -fmatch-case-upper option
1584 @cindex options, -fmatch-case-upper
1585 @item -fmatch-case-upper
1586 @cindex -fmatch-case-lower option
1587 @cindex options, -fmatch-case-lower
1588 @item -fmatch-case-lower
1589 @cindex -fmatch-case-any option
1590 @cindex options, -fmatch-case-any
1591 @item -fmatch-case-any
1592 Specify expected case for keywords.
1593 @samp{-fmatch-case-lower} is the default.
1594
1595 @cindex -fsource-case-upper option
1596 @cindex options, -fsource-case-upper
1597 @item -fsource-case-upper
1598 @cindex -fsource-case-lower option
1599 @cindex options, -fsource-case-lower
1600 @item -fsource-case-lower
1601 @cindex -fsource-case-preserve option
1602 @cindex options, -fsource-case-preserve
1603 @item -fsource-case-preserve
1604 Specify whether source text other than character and Hollerith constants
1605 is to be translated to uppercase, to lowercase, or preserved as is.
1606 @samp{-fsource-case-lower} is the default.
1607
1608 @cindex -fsymbol-case-initcap option
1609 @cindex options, -fsymbol-case-initcap
1610 @item -fsymbol-case-initcap
1611 @cindex -fsymbol-case-upper option
1612 @cindex options, -fsymbol-case-upper
1613 @item -fsymbol-case-upper
1614 @cindex -fsymbol-case-lower option
1615 @cindex options, -fsymbol-case-lower
1616 @item -fsymbol-case-lower
1617 @cindex -fsymbol-case-any option
1618 @cindex options, -fsymbol-case-any
1619 @item -fsymbol-case-any
1620 Specify valid cases for user-defined symbol names.
1621 @samp{-fsymbol-case-any} is the default.
1622
1623 @cindex -fcase-strict-upper option
1624 @cindex options, -fcase-strict-upper
1625 @item -fcase-strict-upper
1626 Same as @samp{-fintrin-case-upper -fmatch-case-upper -fsource-case-preserve
1627 -fsymbol-case-upper}.
1628 (Requires all pertinent source to be in uppercase.)
1629
1630 @cindex -fcase-strict-lower option
1631 @cindex options, -fcase-strict-lower
1632 @item -fcase-strict-lower
1633 Same as @samp{-fintrin-case-lower -fmatch-case-lower -fsource-case-preserve
1634 -fsymbol-case-lower}.
1635 (Requires all pertinent source to be in lowercase.)
1636
1637 @cindex -fcase-initcap option
1638 @cindex options, -fcase-initcap
1639 @item -fcase-initcap
1640 Same as @samp{-fintrin-case-initcap -fmatch-case-initcap -fsource-case-preserve
1641 -fsymbol-case-initcap}.
1642 (Requires all pertinent source to be in initial capitals,
1643 as in @samp{Print *,SqRt(Value)}.)
1644
1645 @cindex -fcase-upper option
1646 @cindex options, -fcase-upper
1647 @item -fcase-upper
1648 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-upper
1649 -fsymbol-case-any}.
1650 (Maps all pertinent source to uppercase.)
1651
1652 @cindex -fcase-lower option
1653 @cindex options, -fcase-lower
1654 @item -fcase-lower
1655 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-lower
1656 -fsymbol-case-any}.
1657 (Maps all pertinent source to lowercase.)
1658
1659 @cindex -fcase-preserve option
1660 @cindex options, -fcase-preserve
1661 @item -fcase-preserve
1662 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-preserve
1663 -fsymbol-case-any}.
1664 (Preserves all case in user-defined symbols,
1665 while allowing any-case matching of intrinsics and keywords.
1666 For example, @samp{call Foo(i,I)} would pass two @emph{different}
1667 variables named @samp{i} and @samp{I} to a procedure named @samp{Foo}.)
1668
1669 @cindex -fbadu77-intrinsics-delete option
1670 @cindex options, -fbadu77-intrinsics-delete
1671 @item -fbadu77-intrinsics-delete
1672 @cindex -fbadu77-intrinsics-hide option
1673 @cindex options, -fbadu77-intrinsics-hide
1674 @item -fbadu77-intrinsics-hide
1675 @cindex -fbadu77-intrinsics-disable option
1676 @cindex options, -fbadu77-intrinsics-disable
1677 @item -fbadu77-intrinsics-disable
1678 @cindex -fbadu77-intrinsics-enable option
1679 @cindex options, -fbadu77-intrinsics-enable
1680 @item -fbadu77-intrinsics-enable
1681 @cindex @code{badu77} intrinsics
1682 @cindex intrinsics, @code{badu77}
1683 Specify status of UNIX intrinsics having inappropriate forms.
1684 @samp{-fbadu77-intrinsics-enable} is the default.
1685 @xref{Intrinsic Groups}.
1686
1687 @cindex -ff2c-intrinsics-delete option
1688 @cindex options, -ff2c-intrinsics-delete
1689 @item -ff2c-intrinsics-delete
1690 @cindex -ff2c-intrinsics-hide option
1691 @cindex options, -ff2c-intrinsics-hide
1692 @item -ff2c-intrinsics-hide
1693 @cindex -ff2c-intrinsics-disable option
1694 @cindex options, -ff2c-intrinsics-disable
1695 @item -ff2c-intrinsics-disable
1696 @cindex -ff2c-intrinsics-enable option
1697 @cindex options, -ff2c-intrinsics-enable
1698 @item -ff2c-intrinsics-enable
1699 @cindex @code{f2c} intrinsics
1700 @cindex intrinsics, @code{f2c}
1701 Specify status of f2c-specific intrinsics.
1702 @samp{-ff2c-intrinsics-enable} is the default.
1703 @xref{Intrinsic Groups}.
1704
1705 @cindex -ff90-intrinsics-delete option
1706 @cindex options, -ff90-intrinsics-delete
1707 @item -ff90-intrinsics-delete
1708 @cindex -ff90-intrinsics-hide option
1709 @cindex options, -ff90-intrinsics-hide
1710 @item -ff90-intrinsics-hide
1711 @cindex -ff90-intrinsics-disable option
1712 @cindex options, -ff90-intrinsics-disable
1713 @item -ff90-intrinsics-disable
1714 @cindex -ff90-intrinsics-enable option
1715 @cindex options, -ff90-intrinsics-enable
1716 @item -ff90-intrinsics-enable
1717 @cindex Fortran 90, intrinsics
1718 @cindex intrinsics, Fortran 90
1719 Specify status of F90-specific intrinsics.
1720 @samp{-ff90-intrinsics-enable} is the default.
1721 @xref{Intrinsic Groups}.
1722
1723 @cindex -fgnu-intrinsics-delete option
1724 @cindex options, -fgnu-intrinsics-delete
1725 @item -fgnu-intrinsics-delete
1726 @cindex -fgnu-intrinsics-hide option
1727 @cindex options, -fgnu-intrinsics-hide
1728 @item -fgnu-intrinsics-hide
1729 @cindex -fgnu-intrinsics-disable option
1730 @cindex options, -fgnu-intrinsics-disable
1731 @item -fgnu-intrinsics-disable
1732 @cindex -fgnu-intrinsics-enable option
1733 @cindex options, -fgnu-intrinsics-enable
1734 @item -fgnu-intrinsics-enable
1735 @cindex Digital Fortran features
1736 @cindex @code{COMPLEX} intrinsics
1737 @cindex intrinsics, @code{COMPLEX}
1738 Specify status of Digital's COMPLEX-related intrinsics.
1739 @samp{-fgnu-intrinsics-enable} is the default.
1740 @xref{Intrinsic Groups}.
1741
1742 @cindex -fmil-intrinsics-delete option
1743 @cindex options, -fmil-intrinsics-delete
1744 @item -fmil-intrinsics-delete
1745 @cindex -fmil-intrinsics-hide option
1746 @cindex options, -fmil-intrinsics-hide
1747 @item -fmil-intrinsics-hide
1748 @cindex -fmil-intrinsics-disable option
1749 @cindex options, -fmil-intrinsics-disable
1750 @item -fmil-intrinsics-disable
1751 @cindex -fmil-intrinsics-enable option
1752 @cindex options, -fmil-intrinsics-enable
1753 @item -fmil-intrinsics-enable
1754 @cindex MIL-STD 1753
1755 @cindex intrinsics, MIL-STD 1753
1756 Specify status of MIL-STD-1753-specific intrinsics.
1757 @samp{-fmil-intrinsics-enable} is the default.
1758 @xref{Intrinsic Groups}.
1759
1760 @cindex -funix-intrinsics-delete option
1761 @cindex options, -funix-intrinsics-delete
1762 @item -funix-intrinsics-delete
1763 @cindex -funix-intrinsics-hide option
1764 @cindex options, -funix-intrinsics-hide
1765 @item -funix-intrinsics-hide
1766 @cindex -funix-intrinsics-disable option
1767 @cindex options, -funix-intrinsics-disable
1768 @item -funix-intrinsics-disable
1769 @cindex -funix-intrinsics-enable option
1770 @cindex options, -funix-intrinsics-enable
1771 @item -funix-intrinsics-enable
1772 @cindex UNIX intrinsics
1773 @cindex intrinsics, UNIX
1774 Specify status of UNIX intrinsics.
1775 @samp{-funix-intrinsics-enable} is the default.
1776 @xref{Intrinsic Groups}.
1777
1778 @cindex -fvxt-intrinsics-delete option
1779 @cindex options, -fvxt-intrinsics-delete
1780 @item -fvxt-intrinsics-delete
1781 @cindex -fvxt-intrinsics-hide option
1782 @cindex options, -fvxt-intrinsics-hide
1783 @item -fvxt-intrinsics-hide
1784 @cindex -fvxt-intrinsics-disable option
1785 @cindex options, -fvxt-intrinsics-disable
1786 @item -fvxt-intrinsics-disable
1787 @cindex -fvxt-intrinsics-enable option
1788 @cindex options, -fvxt-intrinsics-enable
1789 @item -fvxt-intrinsics-enable
1790 @cindex VXT intrinsics
1791 @cindex intrinsics, VXT
1792 Specify status of VXT intrinsics.
1793 @samp{-fvxt-intrinsics-enable} is the default.
1794 @xref{Intrinsic Groups}.
1795
1796 @cindex -ffixed-line-length-@var{n} option
1797 @cindex options, -ffixed-line-length-@var{n}
1798 @item -ffixed-line-length-@var{n}
1799 @cindex source file format
1800 @cindex lines, length
1801 @cindex length of source lines
1802 @cindex fixed form
1803 @cindex limits, lengths of source lines
1804 Set column after which characters are ignored in typical fixed-form
1805 lines in the source file, and through which spaces are assumed (as
1806 if padded to that length) after the ends of short fixed-form lines.
1807
1808 @cindex card image
1809 @cindex extended-source option
1810 Popular values for @var{n} include 72 (the
1811 standard and the default), 80 (card image), and 132 (corresponds
1812 to ``extended-source'' options in some popular compilers).
1813 @var{n} may be @samp{none}, meaning that the entire line is meaningful
1814 and that continued character constants never have implicit spaces appended
1815 to them to fill out the line.
1816 @samp{-ffixed-line-length-0} means the same thing as
1817 @samp{-ffixed-line-length-none}.
1818
1819 @xref{Source Form}, for more information.
1820 @end table
1821
1822 @node Warning Options
1823 @section Options to Request or Suppress Warnings
1824 @cindex options, warnings
1825 @cindex warnings, suppressing
1826 @cindex messages, warning
1827 @cindex suppressing warnings
1828
1829 Warnings are diagnostic messages that report constructions which
1830 are not inherently erroneous but which are risky or suggest there
1831 might have been an error.
1832
1833 You can request many specific warnings with options beginning @samp{-W},
1834 for example @samp{-Wimplicit} to request warnings on implicit
1835 declarations.  Each of these specific warning options also has a
1836 negative form beginning @samp{-Wno-} to turn off warnings;
1837 for example, @samp{-Wno-implicit}.  This manual lists only one of the
1838 two forms, whichever is not the default.
1839
1840 These options control the amount and kinds of warnings produced by GNU
1841 Fortran:
1842
1843 @table @code
1844 @cindex syntax checking
1845 @cindex -fsyntax-only option
1846 @cindex options, -fsyntax-only
1847 @item -fsyntax-only
1848 Check the code for syntax errors, but don't do anything beyond that.
1849
1850 @cindex -pedantic option
1851 @cindex options, -pedantic
1852 @item -pedantic
1853 Issue warnings for uses of extensions to ANSI FORTRAN 77.
1854 @samp{-pedantic} also applies to C-language constructs where they
1855 occur in GNU Fortran source files, such as use of @samp{\e} in a
1856 character constant within a directive like @samp{#include}.
1857
1858 Valid ANSI FORTRAN 77 programs should compile properly with or without
1859 this option.
1860 However, without this option, certain GNU extensions and traditional
1861 Fortran features are supported as well.
1862 With this option, many of them are rejected.
1863
1864 Some users try to use @samp{-pedantic} to check programs for strict ANSI
1865 conformance.
1866 They soon find that it does not do quite what they want---it finds some
1867 non-ANSI practices, but not all.
1868 However, improvements to @code{g77} in this area are welcome.
1869
1870 @cindex -pedantic-errors option
1871 @cindex options, -pedantic-errors
1872 @item -pedantic-errors
1873 Like @samp{-pedantic}, except that errors are produced rather than
1874 warnings.
1875
1876 @cindex -fpedantic option
1877 @cindex options, -fpedantic
1878 @item -fpedantic
1879 Like @samp{-pedantic}, but applies only to Fortran constructs.
1880
1881 @cindex -w option
1882 @cindex options, -w
1883 @item -w
1884 Inhibit all warning messages.
1885
1886 @cindex -Wno-globals option
1887 @cindex options, -Wno-globals
1888 @item -Wno-globals
1889 @cindex global names, warning
1890 @cindex warnings, global names
1891 Inhibit warnings about use of a name as both a global name
1892 (a subroutine, function, or block data program unit, or a
1893 common block) and implicitly as the name of an intrinsic
1894 in a source file.
1895
1896 Also inhibit warnings about inconsistent invocations and/or
1897 definitions of global procedures (function and subroutines).
1898 Such inconsistencies include different numbers of arguments
1899 and different types of arguments.
1900
1901 @cindex -Wimplicit option
1902 @cindex options, -Wimplicit
1903 @item -Wimplicit
1904 @cindex implicit declaration, warning
1905 @cindex warnings, implicit declaration
1906 @cindex -u option
1907 @cindex /WARNINGS=DECLARATIONS switch
1908 @cindex IMPLICIT NONE, similar effect
1909 @cindex effecting IMPLICIT NONE
1910 Warn whenever a variable, array, or function is implicitly
1911 declared.
1912 Has an effect similar to using the @code{IMPLICIT NONE} statement
1913 in every program unit.
1914 (Some Fortran compilers provide this feature by an option
1915 named @samp{-u} or @samp{/WARNINGS=DECLARATIONS}.)
1916
1917 @cindex -Wunused option
1918 @cindex options, -Wunused
1919 @item -Wunused
1920 @cindex unused variables
1921 @cindex variables, unused
1922 Warn whenever a variable is unused aside from its declaration.
1923
1924 @cindex -Wuninitialized option
1925 @cindex options, -Wuninitialized
1926 @item -Wuninitialized
1927 @cindex uninitialized variables
1928 @cindex variables, uninitialized
1929 Warn whenever an automatic variable is used without first being initialized.
1930
1931 These warnings are possible only in optimizing compilation,
1932 because they require data-flow information that is computed only
1933 when optimizing.  If you don't specify @samp{-O}, you simply won't
1934 get these warnings.
1935
1936 These warnings occur only for variables that are candidates for
1937 register allocation.  Therefore, they do not occur for a variable
1938 @c that is declared @code{VOLATILE}, or
1939 whose address is taken, or whose size
1940 is other than 1, 2, 4 or 8 bytes.  Also, they do not occur for
1941 arrays, even when they are in registers.
1942
1943 Note that there might be no warning about a variable that is used only
1944 to compute a value that itself is never used, because such
1945 computations may be deleted by data-flow analysis before the warnings
1946 are printed.
1947
1948 These warnings are made optional because GNU Fortran is not smart
1949 enough to see all the reasons why the code might be correct
1950 despite appearing to have an error.  Here is one example of how
1951 this can happen:
1952
1953 @example
1954 SUBROUTINE DISPAT(J)
1955 IF (J.EQ.1) I=1
1956 IF (J.EQ.2) I=4
1957 IF (J.EQ.3) I=5
1958 CALL FOO(I)
1959 END
1960 @end example
1961
1962 @noindent
1963 If the value of @code{J} is always 1, 2 or 3, then @code{I} is
1964 always initialized, but GNU Fortran doesn't know this.  Here is
1965 another common case:
1966
1967 @example
1968 SUBROUTINE MAYBE(FLAG)
1969 LOGICAL FLAG
1970 IF (FLAG) VALUE = 9.4
1971 @dots{}
1972 IF (FLAG) PRINT *, VALUE
1973 END
1974 @end example
1975
1976 @noindent
1977 This has no bug because @code{VALUE} is used only if it is set.
1978
1979 @cindex -Wall option
1980 @cindex options, -Wall
1981 @item -Wall
1982 @cindex all warnings
1983 @cindex warnings, all
1984 The @samp{-Wunused} and @samp{-Wuninitialized} options combined.
1985 These are all the
1986 options which pertain to usage that we recommend avoiding and that we
1987 believe is easy to avoid.
1988 (As more warnings are added to @code{g77}, some might
1989 be added to the list enabled by @samp{-Wall}.)
1990 @end table
1991
1992 The remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}
1993 because they warn about constructions that we consider reasonable to
1994 use, on occasion, in clean programs.
1995
1996 @table @code
1997 @c @item -W
1998 @c Print extra warning messages for these events:
1999 @c
2000 @c @itemize @bullet
2001 @c @item
2002 @c If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused
2003 @c arguments.
2004 @c
2005 @c @end itemize
2006 @c
2007 @cindex -Wsurprising option
2008 @cindex options, -Wsurprising
2009 @item -Wsurprising
2010 Warn about ``suspicious'' constructs that are interpreted
2011 by the compiler in a way that might well be surprising to
2012 someone reading the code.
2013 These differences can result in subtle, compiler-dependent
2014 (even machine-dependent) behavioral differences.
2015 The constructs warned about include:
2016
2017 @itemize @bullet
2018 @item
2019 Expressions having two arithmetic operators in a row, such
2020 as @samp{X*-Y}.
2021 Such a construct is nonstandard, and can produce
2022 unexpected results in more complicated situations such
2023 as @samp{X**-Y*Z}.
2024 @code{g77}, along with many other compilers, interprets
2025 this example differently than many programmers, and a few
2026 other compilers.
2027 Specifically, @code{g77} interprets @samp{X**-Y*Z} as
2028 @samp{(X**(-Y))*Z}, while others might think it should
2029 be interpreted as @samp{X**(-(Y*Z))}.
2030
2031 A revealing example is the constant expression @samp{2**-2*1.},
2032 which @code{g77} evaluates to .25, while others might evaluate
2033 it to 0., the difference resulting from the way precedence affects
2034 type promotion.
2035
2036 (The @samp{-fpedantic} option also warns about expressions
2037 having two arithmetic operators in a row.)
2038
2039 @item
2040 Expressions with a unary minus followed by an operand and then
2041 a binary operator other than plus or minus.
2042 For example, @samp{-2**2} produces a warning, because
2043 the precedence is @samp{-(2**2)}, yielding -4, not
2044 @samp{(-2)**2}, which yields 4, and which might represent
2045 what a programmer expects.
2046
2047 An example of an expression producing different results
2048 in a surprising way is @samp{-I*S}, where @var{I} holds
2049 the value @samp{-2147483648} and @var{S} holds @samp{0.5}.
2050 On many systems, negating @var{I} results in the same
2051 value, not a positive number, because it is already the
2052 lower bound of what an @code{INTEGER(KIND=1)} variable can hold.
2053 So, the expression evaluates to a positive number, while
2054 the ``expected'' interpretation, @samp{(-I)*S}, would
2055 evaluate to a negative number.
2056
2057 Even cases such as @samp{-I*J} produce warnings,
2058 even though, in most configurations and situations,
2059 there is no computational difference between the
2060 results of the two interpretations---the purpose
2061 of this warning is to warn about differing interpretations
2062 and encourage a better style of coding, not to identify
2063 only those places where bugs might exist in the user's
2064 code.
2065
2066 @cindex DO statement
2067 @cindex statements, DO
2068 @item
2069 @code{DO} loops with @code{DO} variables that are not
2070 of integral type---that is, using @code{REAL}
2071 variables as loop control variables.
2072 Although such loops can be written to work in the
2073 ``obvious'' way, the way @code{g77} is required by the
2074 Fortran standard to interpret such code is likely to
2075 be quite different from the way many programmers expect.
2076 (This is true of all @code{DO} loops, but the differences
2077 are pronounced for non-integral loop control variables.)
2078
2079 @xref{Loops}, for more information.
2080 @end itemize
2081
2082 @cindex -Werror option
2083 @cindex options, -Werror
2084 @item -Werror
2085 Make all warnings into errors.
2086
2087 @cindex -W option
2088 @cindex options, -W
2089 @item -W
2090 @cindex extra warnings
2091 @cindex warnings, extra
2092 Turns on ``extra warnings'' and, if optimization is specified
2093 via @samp{-O}, the @samp{-Wuninitialized} option.
2094 (This might change in future versions of @code{g77}.)
2095
2096 ``Extra warnings'' are issued for:
2097
2098 @itemize @bullet
2099 @item
2100 @cindex unused parameters
2101 @cindex parameters, unused
2102 @cindex unused arguments
2103 @cindex arguments, unused
2104 @cindex unused dummies
2105 @cindex dummies, unused
2106 Unused parameters to a procedure (when @samp{-Wunused} also is
2107 specified).
2108
2109 @item
2110 @cindex overflow
2111 Overflows involving floating-point constants (not available
2112 for certain configurations).
2113 @end itemize
2114 @end table
2115
2116 @xref{Warning Options,,Options to Request or Suppress Warnings,
2117 gcc,Using and Porting GNU CC}, for information on more options offered
2118 by the GBE shared by @code{g77}, @code{gcc}, and other GNU compilers.
2119
2120 Some of these have no effect when compiling programs written in Fortran:
2121
2122 @table @code
2123 @cindex -Wcomment option
2124 @cindex options, -Wcomment
2125 @item -Wcomment
2126 @cindex -Wformat option
2127 @cindex options, -Wformat
2128 @item -Wformat
2129 @cindex -Wparentheses option
2130 @cindex options, -Wparentheses
2131 @item -Wparentheses
2132 @cindex -Wswitch option
2133 @cindex options, -Wswitch
2134 @item -Wswitch
2135 @cindex -Wtraditional option
2136 @cindex options, -Wtraditional
2137 @item -Wtraditional
2138 @cindex -Wshadow option
2139 @cindex options, -Wshadow
2140 @item -Wshadow
2141 @cindex -Wid-clash-@var{len} option
2142 @cindex options, -Wid-clash-@var{len}
2143 @item -Wid-clash-@var{len}
2144 @cindex -Wlarger-than-@var{len} option
2145 @cindex options, -Wlarger-than-@var{len}
2146 @item -Wlarger-than-@var{len}
2147 @cindex -Wconversion option
2148 @cindex options, -Wconversion
2149 @item -Wconversion
2150 @cindex -Waggregate-return option
2151 @cindex options, -Waggregate-return
2152 @item -Waggregate-return
2153 @cindex -Wredundant-decls option
2154 @cindex options, -Wredundant-decls
2155 @item -Wredundant-decls
2156 @cindex unsupported warnings
2157 @cindex warnings, unsupported
2158 These options all could have some relevant meaning for
2159 GNU Fortran programs, but are not yet supported.
2160 @end table
2161
2162 @node Debugging Options
2163 @section Options for Debugging Your Program or GNU Fortran
2164 @cindex options, debugging
2165 @cindex debugging information options
2166
2167 GNU Fortran has various special options that are used for debugging
2168 either your program or @code{g77}.
2169
2170 @table @code
2171 @cindex -g option
2172 @cindex options, -g
2173 @item -g
2174 Produce debugging information in the operating system's native format
2175 (stabs, COFF, XCOFF, or DWARF).  GDB can work with this debugging
2176 information.
2177 @end table
2178
2179 @xref{Debugging Options,,Options for Debugging Your Program or GNU CC,
2180 gcc,Using and Porting GNU CC}, for more information on debugging options.
2181
2182 @node Optimize Options
2183 @section Options That Control Optimization
2184 @cindex optimize options
2185 @cindex options, optimization
2186
2187 Most Fortran users will want to use no optimization when
2188 developing and testing programs, and use @samp{-O} or @samp{-O2} when
2189 compiling programs for late-cycle testing and for production use.
2190 However, note that certain diagnostics---such as for uninitialized
2191 variables---depend on the flow analysis done by @samp{-O}, i.e.@: you
2192 must use @samp{-O} or @samp{-O2} to get such diagnostics.
2193
2194 The following flags have particular applicability when
2195 compiling Fortran programs:
2196
2197 @table @code
2198 @cindex -malign-double option
2199 @cindex options, -malign-double
2200 @item -malign-double
2201 (Intel x86 architecture only.)
2202
2203 Noticeably improves performance of @code{g77} programs making
2204 heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data
2205 on some systems.
2206 In particular, systems using Pentium, Pentium Pro, 586, and
2207 686 implementations
2208 of the i386 architecture execute programs faster when
2209 @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data are
2210 aligned on 64-bit boundaries
2211 in memory.
2212
2213 This option can, at least, make benchmark results more consistent
2214 across various system configurations, versions of the program,
2215 and data sets.
2216
2217 @emph{Note:} The warning in the @code{gcc} documentation about
2218 this option does not apply, generally speaking, to Fortran
2219 code compiled by @code{g77}.
2220
2221 @xref{Aligned Data}, for more information on alignment issues.
2222
2223 @emph{Also also note:} The negative form of @samp{-malign-double}
2224 is @samp{-mno-align-double}, not @samp{-benign-double}.
2225
2226 @cindex -ffloat-store option
2227 @cindex options, -ffloat-store
2228 @item -ffloat-store
2229 @cindex IEEE 754 conformance
2230 @cindex conformance, IEEE 754
2231 @cindex floating-point, precision
2232 Might help a Fortran program that depends on exact IEEE conformance on
2233 some machines, but might slow down a program that doesn't.
2234
2235 This option is effective when the floating-point unit is set to work in
2236 IEEE 854 `extended precision'---as it typically is on x86 and m68k GNU
2237 systems---rather than IEEE 754 double precision.  @samp{-ffloat-store}
2238 tries to remove the extra precision by spilling data from floating-point
2239 registers into memory and this typically involves a big performance
2240 hit.  However, it doesn't affect intermediate results, so that it is
2241 only partially effective.  `Excess precision' is avoided in code like:
2242 @smallexample
2243 a = b + c
2244 d = a * e
2245 @end smallexample
2246 but not in code like:
2247 @smallexample
2248       d = (b + c) * e
2249 @end smallexample
2250
2251 For another, potentially better, way of controlling the precision,
2252 see @ref{Floating-point precision}.
2253
2254 @cindex -fforce-mem option
2255 @cindex options, -fforce-mem
2256 @item -fforce-mem
2257 @cindex -fforce-addr option
2258 @cindex options, -fforce-addr
2259 @item -fforce-addr
2260 @cindex loops, speeding up
2261 @cindex speed, of loops
2262 Might improve optimization of loops.
2263
2264 @cindex -fno-inline option
2265 @cindex options, -fno-inline
2266 @item -fno-inline
2267 @cindex in-line code
2268 @cindex compilation, in-line
2269 @c DL: Only relevant for -O3?
2270 Don't compile statement functions inline.
2271 Might reduce the size of a program unit---which might be at
2272 expense of some speed (though it should compile faster).
2273 Note that if you are not optimizing, no functions can be expanded inline.
2274
2275 @cindex -ffast-math option
2276 @cindex options, -ffast-math
2277 @item -ffast-math
2278 @cindex IEEE 754 conformance
2279 @cindex conformance, IEEE 754
2280 Might allow some programs designed to not be too dependent
2281 on IEEE behavior for floating-point to run faster, or die trying.
2282 Sets @samp{-funsafe-math-optimizations}, and
2283 @samp{-fno-trapping-math}.
2284
2285 @cindex -funsafe-math-optimizations option
2286 @cindex options, -funsafe-math-optimizations
2287 @item -funsafe-math-optimizations
2288 Allow optimizations that may be give incorrect results
2289 for certain IEEE inputs.
2290
2291 @cindex -fno-trapping-math option
2292 @cindex options, -fno-trapping-math
2293 @item -fno-trapping-math
2294 Allow the compiler to assume that floating-point arithmetic
2295 will not generate traps on any inputs.  This is useful, for
2296 example, when running a program using IEEE "non-stop"
2297 floating-point arithmetic.
2298
2299 @cindex -fstrength-reduce option
2300 @cindex options, -fstrength-reduce
2301 @item -fstrength-reduce
2302 @cindex loops, speeding up
2303 @cindex speed, of loops
2304 @c DL: normally defaulted?
2305 Might make some loops run faster.
2306
2307 @cindex -frerun-cse-after-loop option
2308 @cindex options, -frerun-cse-after-loop
2309 @item -frerun-cse-after-loop
2310 @cindex -fexpensive-optimizations option
2311 @cindex options, -fexpensive-optimizations
2312 @c DL: This is -O2?
2313 @item -fexpensive-optimizations
2314 @cindex -fdelayed-branch option
2315 @cindex options, -fdelayed-branch
2316 @item -fdelayed-branch
2317 @cindex -fschedule-insns option
2318 @cindex options, -fschedule-insns
2319 @item -fschedule-insns
2320 @cindex -fschedule-insns2 option
2321 @cindex options, -fschedule-insns2
2322 @item -fschedule-insns2
2323 @cindex -fcaller-saves option
2324 @cindex options, -fcaller-saves
2325 @item -fcaller-saves
2326 Might improve performance on some code.
2327
2328 @cindex -funroll-loops option
2329 @cindex options, -funroll-loops
2330 @item -funroll-loops
2331 @cindex loops, unrolling
2332 @cindex unrolling loops
2333 @cindex loops, optimizing
2334 @cindex indexed (iterative) @code{DO}
2335 @cindex iterative @code{DO}
2336 @c DL: fixme: Craig doesn't like `indexed' but f95 doesn't seem to
2337 @c provide a suitable term
2338 @c CB: I've decided on `iterative', for the time being, and changed
2339 @c my previous, rather bizarre, use of `imperative' to that
2340 @c (though `precomputed-trip' would be a more precise adjective)
2341 Typically improves performance on code using iterative @code{DO} loops by
2342 unrolling them and is probably generally appropriate for Fortran, though
2343 it is not turned on at any optimization level.
2344 Note that outer loop unrolling isn't done specifically; decisions about
2345 whether to unroll a loop are made on the basis of its instruction count.
2346
2347 @c DL: Fixme: This should obviously go somewhere else...
2348 Also, no `loop discovery'@footnote{@dfn{loop discovery} refers to the
2349 process by which a compiler, or indeed any reader of a program,
2350 determines which portions of the program are more likely to be executed
2351 repeatedly as it is being run.  Such discovery typically is done early
2352 when compiling using optimization techniques, so the ``discovered''
2353 loops get more attention---and more run-time resources, such as
2354 registers---from the compiler.  It is easy to ``discover'' loops that are
2355 constructed out of looping constructs in the language
2356 (such as Fortran's @code{DO}).  For some programs, ``discovering'' loops
2357 constructed out of lower-level constructs (such as @code{IF} and
2358 @code{GOTO}) can lead to generation of more optimal code
2359 than otherwise.} is done, so only loops written with @code{DO}
2360 benefit from loop optimizations, including---but not limited
2361 to---unrolling.  Loops written with @code{IF} and @code{GOTO} are not
2362 currently recognized as such.  This option unrolls only iterative
2363 @code{DO} loops, not @code{DO WHILE} loops.
2364
2365 @cindex -funroll-all-loops option
2366 @cindex options, -funroll-all-loops
2367 @cindex DO WHILE
2368 @item -funroll-all-loops
2369 @c DL: Check my understanding of -funroll-all-loops v. -funroll-loops is correct.
2370 Probably improves performance on code using @code{DO WHILE} loops by
2371 unrolling them in addition to iterative @code{DO} loops.  In the absence
2372 of @code{DO WHILE}, this option is equivalent to @samp{-funroll-loops}
2373 but possibly slower.
2374
2375 @item -fno-move-all-movables
2376 @cindex -fno-move-all-movables option
2377 @cindex options, -fno-move-all-movables
2378 @item -fno-reduce-all-givs
2379 @cindex -fno-reduce-all-givs option
2380 @cindex options, -fno-reduce-all-givs
2381 @item -fno-rerun-loop-opt
2382 @cindex -fno-rerun-loop-opt option
2383 @cindex options, -fno-rerun-loop-opt
2384 @emph{Version info:}
2385 These options are not supported by
2386 versions of @code{g77} based on @code{gcc} version 2.8.
2387
2388 Each of these might improve performance on some code.
2389
2390 Analysis of Fortran code optimization and the resulting
2391 optimizations triggered by the above options were
2392 contributed by Toon Moene (@email{toon@@moene.indiv.nluug.nl}).
2393
2394 These three options are intended to be removed someday, once
2395 they have helped determine the efficacy of various
2396 approaches to improving the performance of Fortran code.
2397
2398 Please let us know how use of these options affects
2399 the performance of your production code.
2400 We're particularly interested in code that runs faster
2401 when these options are @emph{disabled}, and in
2402 non-Fortran code that benefits when they are
2403 @emph{enabled} via the above @code{gcc} command-line options.
2404 @end table
2405
2406 @xref{Optimize Options,,Options That Control Optimization,
2407 gcc,Using and Porting GNU CC}, for more information on options
2408 to optimize the generated machine code.
2409
2410 @node Preprocessor Options
2411 @section Options Controlling the Preprocessor
2412 @cindex preprocessor options
2413 @cindex options, preprocessor
2414 @cindex cpp program
2415 @cindex programs, cpp
2416
2417 These options control the C preprocessor, which is run on each C source
2418 file before actual compilation.
2419
2420 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
2421 gcc,Using and Porting GNU CC}, for information on C preprocessor options.
2422
2423 @cindex INCLUDE directive
2424 @cindex directive, INCLUDE
2425 Some of these options also affect how @code{g77} processes the
2426 @code{INCLUDE} directive.
2427 Since this directive is processed even when preprocessing
2428 is not requested, it is not described in this section.
2429 @xref{Directory Options,,Options for Directory Search}, for
2430 information on how @code{g77} processes the @code{INCLUDE} directive.
2431
2432 However, the @code{INCLUDE} directive does not apply
2433 preprocessing to the contents of the included file itself.
2434
2435 Therefore, any file that contains preprocessor directives
2436 (such as @code{#include}, @code{#define}, and @code{#if})
2437 must be included via the @code{#include} directive, not
2438 via the @code{INCLUDE} directive.
2439 Therefore, any file containing preprocessor directives,
2440 if included, is necessarily included by a file that itself
2441 contains preprocessor directives.
2442
2443 @node Directory Options
2444 @section Options for Directory Search
2445 @cindex directory, options
2446 @cindex options, directory search
2447 @cindex search path
2448
2449 These options affect how the @code{cpp} preprocessor searches
2450 for files specified via the @code{#include} directive.
2451 Therefore, when compiling Fortran programs, they are meaningful
2452 when the preprocessor is used.
2453
2454 @cindex INCLUDE directive
2455 @cindex directive, INCLUDE
2456 Some of these options also affect how @code{g77} searches
2457 for files specified via the @code{INCLUDE} directive,
2458 although files included by that directive are not,
2459 themselves, preprocessed.
2460 These options are:
2461
2462 @table @code
2463 @cindex -I- option
2464 @cindex options, -I-
2465 @item -I-
2466 @cindex -Idir option
2467 @cindex options, -Idir
2468 @item -I@var{dir}
2469 @cindex directory, search paths for inclusion
2470 @cindex inclusion, directory search paths for
2471 @cindex search paths, for included files
2472 @cindex paths, search
2473 These affect interpretation of the @code{INCLUDE} directive
2474 (as well as of the @code{#include} directive of the @code{cpp}
2475 preprocessor).
2476
2477 Note that @samp{-I@var{dir}} must be specified @emph{without} any
2478 spaces between @samp{-I} and the directory name---that is,
2479 @samp{-Ifoo/bar} is valid, but @samp{-I foo/bar}
2480 is rejected by the @code{g77} compiler (though the preprocessor supports
2481 the latter form).
2482 @c this is due to toplev.c's inflexible option processing
2483 Also note that the general behavior of @samp{-I} and
2484 @code{INCLUDE} is pretty much the same as of @samp{-I} with
2485 @code{#include} in the @code{cpp} preprocessor, with regard to
2486 looking for @file{header.gcc} files and other such things.
2487
2488 @xref{Directory Options,,Options for Directory Search,
2489 gcc,Using and Porting GNU CC}, for information on the @samp{-I} option.
2490 @end table
2491
2492 @node Code Gen Options
2493 @section Options for Code Generation Conventions
2494 @cindex code generation, conventions
2495 @cindex options, code generation
2496 @cindex run-time, options
2497
2498 These machine-independent options control the interface conventions
2499 used in code generation.
2500
2501 Most of them have both positive and negative forms; the negative form
2502 of @samp{-ffoo} would be @samp{-fno-foo}.  In the table below, only
2503 one of the forms is listed---the one which is not the default.  You
2504 can figure out the other form by either removing @samp{no-} or adding
2505 it.
2506
2507 @table @code
2508 @cindex -fno-automatic option
2509 @cindex options, -fno-automatic
2510 @item -fno-automatic
2511 @cindex SAVE statement
2512 @cindex statements, SAVE
2513 Treat each program unit as if the @code{SAVE} statement was specified
2514 for every local variable and array referenced in it.
2515 Does not affect common blocks.
2516 (Some Fortran compilers provide this option under
2517 the name @samp{-static}.)
2518
2519 @cindex -finit-local-zero option
2520 @cindex options, -finit-local-zero
2521 @item -finit-local-zero
2522 @cindex DATA statement
2523 @cindex statements, DATA
2524 @cindex initialization, of local variables
2525 @cindex variables, initialization of
2526 @cindex uninitialized variables
2527 @cindex variables, uninitialized
2528 Specify that variables and arrays that are local to a program unit
2529 (not in a common block and not passed as an argument) are to be initialized
2530 to binary zeros.
2531
2532 Since there is a run-time penalty for initialization of variables
2533 that are not given the @code{SAVE} attribute, it might be a
2534 good idea to also use @samp{-fno-automatic} with @samp{-finit-local-zero}.
2535
2536 @cindex -fno-f2c option
2537 @cindex options, -fno-f2c
2538 @item -fno-f2c
2539 @cindex @code{f2c} compatibility
2540 @cindex compatibility, @code{f2c}
2541 Do not generate code designed to be compatible with code generated
2542 by @code{f2c}; use the GNU calling conventions instead.
2543
2544 The @code{f2c} calling conventions require functions that return
2545 type @code{REAL(KIND=1)} to actually return the C type @code{double},
2546 and functions that return type @code{COMPLEX} to return the
2547 values via an extra argument in the calling sequence that points
2548 to where to store the return value.
2549 Under the GNU calling conventions, such functions simply return
2550 their results as they would in GNU C---@code{REAL(KIND=1)} functions
2551 return the C type @code{float}, and @code{COMPLEX} functions
2552 return the GNU C type @code{complex} (or its @code{struct}
2553 equivalent).
2554
2555 This does not affect the generation of code that interfaces with the
2556 @code{libg2c} library.
2557
2558 However, because the @code{libg2c} library uses @code{f2c}
2559 calling conventions, @code{g77} rejects attempts to pass
2560 intrinsics implemented by routines in this library as actual
2561 arguments when @samp{-fno-f2c} is used, to avoid bugs when
2562 they are actually called by code expecting the GNU calling
2563 conventions to work.
2564
2565 For example, @samp{INTRINSIC ABS;CALL FOO(ABS)} is
2566 rejected when @samp{-fno-f2c} is in force.
2567 (Future versions of the @code{g77} run-time library might
2568 offer routines that provide GNU-callable versions of the
2569 routines that implement the @code{f2c}-callable intrinsics
2570 that may be passed as actual arguments, so that
2571 valid programs need not be rejected when @samp{-fno-f2c}
2572 is used.)
2573
2574 @strong{Caution:} If @samp{-fno-f2c} is used when compiling any
2575 source file used in a program, it must be used when compiling
2576 @emph{all} Fortran source files used in that program.
2577
2578 @c seems kinda dumb to tell people about an option they can't use -- jcb
2579 @c then again, we want users building future-compatible libraries with it.
2580 @cindex -ff2c-library option
2581 @cindex options, -ff2c-library
2582 @item -ff2c-library
2583 Specify that use of @code{libg2c} (or the original @code{libf2c})
2584 is required.
2585 This is the default for the current version of @code{g77}.
2586
2587 Currently it is not
2588 valid to specify @samp{-fno-f2c-library}.
2589 This option is provided so users can specify it in shell
2590 scripts that build programs and libraries that require the
2591 @code{libf2c} library, even when being compiled by future
2592 versions of @code{g77} that might otherwise default to
2593 generating code for an incompatible library.
2594
2595 @cindex -fno-underscoring option
2596 @cindex options, -fno-underscoring
2597 @item -fno-underscoring
2598 @cindex underscore
2599 @cindex symbol names, underscores
2600 @cindex transforming symbol names
2601 @cindex symbol names, transforming
2602 Do not transform names of entities specified in the Fortran
2603 source file by appending underscores to them.
2604
2605 With @samp{-funderscoring} in effect, @code{g77} appends two underscores
2606 to names with underscores and one underscore to external names with
2607 no underscores.  (@code{g77} also appends two underscores to internal
2608 names with underscores to avoid naming collisions with external names.
2609 The @samp{-fno-second-underscore} option disables appending of the
2610 second underscore in all cases.)
2611
2612 This is done to ensure compatibility with code produced by many
2613 UNIX Fortran compilers, including @code{f2c}, which perform the
2614 same transformations.
2615
2616 Use of @samp{-fno-underscoring} is not recommended unless you are
2617 experimenting with issues such as integration of (GNU) Fortran into
2618 existing system environments (vis-a-vis existing libraries, tools, and
2619 so on).
2620
2621 For example, with @samp{-funderscoring}, and assuming other defaults like
2622 @samp{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
2623 external functions while @samp{my_var} and @samp{lvar} are local variables,
2624 a statement like
2625
2626 @smallexample
2627 I = J() + MAX_COUNT (MY_VAR, LVAR)
2628 @end smallexample
2629
2630 @noindent
2631 is implemented as something akin to:
2632
2633 @smallexample
2634 i = j_() + max_count__(&my_var__, &lvar);
2635 @end smallexample
2636
2637 With @samp{-fno-underscoring}, the same statement is implemented as:
2638
2639 @smallexample
2640 i = j() + max_count(&my_var, &lvar);
2641 @end smallexample
2642
2643 Use of @samp{-fno-underscoring} allows direct specification of
2644 user-defined names while debugging and when interfacing @code{g77}-compiled
2645 code with other languages.
2646
2647 Note that just because the names match does @emph{not} mean that the
2648 interface implemented by @code{g77} for an external name matches the
2649 interface implemented by some other language for that same name.
2650 That is, getting code produced by @code{g77} to link to code produced
2651 by some other compiler using this or any other method can be only a
2652 small part of the overall solution---getting the code generated by
2653 both compilers to agree on issues other than naming can require
2654 significant effort, and, unlike naming disagreements, linkers normally
2655 cannot detect disagreements in these other areas.
2656
2657 Also, note that with @samp{-fno-underscoring}, the lack of appended
2658 underscores introduces the very real possibility that a user-defined
2659 external name will conflict with a name in a system library, which
2660 could make finding unresolved-reference bugs quite difficult in some
2661 cases---they might occur at program run time, and show up only as
2662 buggy behavior at run time.
2663
2664 In future versions of @code{g77}, we hope to improve naming and linking
2665 issues so that debugging always involves using the names as they appear
2666 in the source, even if the names as seen by the linker are mangled to
2667 prevent accidental linking between procedures with incompatible
2668 interfaces.
2669
2670 @cindex -fno-second-underscore option
2671 @cindex options, -fno-second-underscore
2672 @item -fno-second-underscore
2673 @cindex underscore
2674 @cindex symbol names, underscores
2675 @cindex transforming symbol names
2676 @cindex symbol names, transforming
2677 Do not append a second underscore to names of entities specified
2678 in the Fortran source file.
2679
2680 This option has no effect if @samp{-fno-underscoring} is
2681 in effect.
2682
2683 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
2684 is implemented as a reference to the link-time external symbol
2685 @samp{max_count_}, instead of @samp{max_count__}.
2686
2687 @cindex -fno-ident option
2688 @cindex options, -fno-ident
2689 @item -fno-ident
2690 Ignore the @samp{#ident} directive.
2691
2692 @cindex -fzeros option
2693 @cindex options, -fzeros
2694 @item -fzeros
2695 Treat initial values of zero as if they were any other value.
2696
2697 As of version 0.5.18, @code{g77} normally treats @code{DATA} and
2698 other statements that are used to specify initial values of zero
2699 for variables and arrays as if no values were actually specified,
2700 in the sense that no diagnostics regarding multiple initializations
2701 are produced.
2702
2703 This is done to speed up compiling of programs that initialize
2704 large arrays to zeros.
2705
2706 Use @samp{-fzeros} to revert to the simpler, slower behavior
2707 that can catch multiple initializations by keeping track of
2708 all initializations, zero or otherwise.
2709
2710 @emph{Caution:} Future versions of @code{g77} might disregard this option
2711 (and its negative form, the default) or interpret it somewhat
2712 differently.
2713 The interpretation changes will affect only non-standard
2714 programs; standard-conforming programs should not be affected.
2715
2716 @cindex -femulate-complex option
2717 @cindex options, -femulate-complex
2718 @item -femulate-complex
2719 Implement @code{COMPLEX} arithmetic via emulation,
2720 instead of using the facilities of
2721 the @code{gcc} back end that provide direct support of
2722 @code{complex} arithmetic.
2723
2724 (@code{gcc} had some bugs in its back-end support
2725 for @code{complex} arithmetic, due primarily to the support not being
2726 completed as of version 2.8.1 and @code{egcs} 1.1.2.)
2727
2728 Use @samp{-femulate-complex} if you suspect code-generation bugs,
2729 or experience compiler crashes,
2730 that might result from @code{g77} using the @code{COMPLEX} support
2731 in the @code{gcc} back end.
2732 If using that option fixes the bugs or crashes you are seeing,
2733 that indicates a likely @code{g77} bugs
2734 (though, all compiler crashes are considered bugs),
2735 so, please report it.
2736 (Note that the known bugs, now believed fixed, produced compiler crashes
2737 rather than causing the generation of incorrect code.)
2738
2739 Use of this option should not affect how Fortran code compiled
2740 by @code{g77} works in terms of its interfaces to other code,
2741 e.g. that compiled by @code{f2c}.
2742
2743 @emph{Caution:} Future versions of @code{g77} might ignore both forms
2744 of this option.
2745
2746 @cindex -falias-check option
2747 @cindex options, -falias-check
2748 @cindex -fargument-alias option
2749 @cindex options, -fargument-alias
2750 @cindex -fargument-noalias option
2751 @cindex options, -fargument-noalias
2752 @cindex -fno-argument-noalias-global option
2753 @cindex options, -fno-argument-noalias-global
2754 @item -falias-check
2755 @item -fargument-alias
2756 @item -fargument-noalias
2757 @item -fno-argument-noalias-global
2758 @emph{Version info:}
2759 These options are not supported by
2760 versions of @code{g77} based on @code{gcc} version 2.8.
2761
2762 These options specify to what degree aliasing
2763 (overlap)
2764 is permitted between
2765 arguments (passed as pointers) and @code{COMMON} (external, or
2766 public) storage.
2767
2768 The default for Fortran code, as mandated by the FORTRAN 77 and
2769 Fortran 90 standards, is @samp{-fargument-noalias-global}.
2770 The default for code written in the C language family is
2771 @samp{-fargument-alias}.
2772
2773 Note that, on some systems, compiling with @samp{-fforce-addr} in
2774 effect can produce more optimal code when the default aliasing
2775 options are in effect (and when optimization is enabled).
2776
2777 @xref{Aliasing Assumed To Work}, for detailed information on the implications
2778 of compiling Fortran code that depends on the ability to alias dummy
2779 arguments.
2780
2781 @cindex -fno-globals option
2782 @cindex options, -fno-globals
2783 @item -fno-globals
2784 @cindex global names, warning
2785 @cindex warnings, global names
2786 @cindex in-line code
2787 @cindex compilation, in-line
2788 Disable diagnostics about inter-procedural
2789 analysis problems, such as disagreements about the
2790 type of a function or a procedure's argument,
2791 that might cause a compiler crash when attempting
2792 to inline a reference to a procedure within a
2793 program unit.
2794 (The diagnostics themselves are still produced, but
2795 as warnings, unless @samp{-Wno-globals} is specified,
2796 in which case no relevant diagnostics are produced.)
2797
2798 Further, this option disables such inlining, to
2799 avoid compiler crashes resulting from incorrect
2800 code that would otherwise be diagnosed.
2801
2802 As such, this option might be quite useful when
2803 compiling existing, ``working'' code that happens
2804 to have a few bugs that do not generally show themselves,
2805 but which @code{g77} diagnoses.
2806
2807 Use of this option therefore has the effect of
2808 instructing @code{g77} to behave more like it did
2809 up through version 0.5.19.1, when it paid little or
2810 no attention to disagreements between program units
2811 about a procedure's type and argument information,
2812 and when it performed no inlining of procedures
2813 (except statement functions).
2814
2815 Without this option, @code{g77} defaults to performing
2816 the potentially inlining procedures as it started doing
2817 in version 0.5.20, but as of version 0.5.21, it also
2818 diagnoses disagreements that might cause such inlining
2819 to crash the compiler as (fatal) errors,
2820 and warns about similar disagreements
2821 that are currently believed to not
2822 likely to result in the compiler later crashing
2823 or producing incorrect code.
2824
2825 @cindex -fflatten-arrays option
2826 @item -fflatten-arrays
2827 @cindex array performance
2828 @cindex arrays, flattening
2829 Use back end's C-like constructs
2830 (pointer plus offset)
2831 instead of its @code{ARRAY_REF} construct
2832 to handle all array references.
2833
2834 @emph{Note:} This option is not supported.
2835 It is intended for use only by @code{g77} developers,
2836 to evaluate code-generation issues.
2837 It might be removed at any time.
2838
2839 @cindex -fbounds-check option
2840 @cindex -ffortran-bounds-check option
2841 @item -fbounds-check
2842 @itemx -ffortran-bounds-check
2843 @cindex bounds checking
2844 @cindex range checking
2845 @cindex array bounds checking
2846 @cindex subscript checking
2847 @cindex substring checking
2848 @cindex checking subscripts
2849 @cindex checking substrings
2850 Enable generation of run-time checks for array subscripts
2851 and substring start and end points
2852 against the (locally) declared minimum and maximum values.
2853
2854 The current implementation uses the @code{libf2c}
2855 library routine @code{s_rnge} to print the diagnostic.
2856
2857 However, whereas @code{f2c} generates a single check per
2858 reference for a multi-dimensional array, of the computed
2859 offset against the valid offset range (0 through the size of the array),
2860 @code{g77} generates a single check per @emph{subscript} expression.
2861 This catches some cases of potential bugs that @code{f2c} does not,
2862 such as references to below the beginning of an assumed-size array.
2863
2864 @code{g77} also generates checks for @code{CHARACTER} substring references,
2865 something @code{f2c} currently does not do.
2866
2867 Use the new @samp{-ffortran-bounds-check} option
2868 to specify bounds-checking for only the Fortran code you are compiling,
2869 not necessarily for code written in other languages.
2870
2871 @emph{Note:} To provide more detailed information on the offending subscript,
2872 @code{g77} provides the @code{libg2c} run-time library routine @code{s_rnge}
2873 with somewhat differently-formatted information.
2874 Here's a sample diagnostic:
2875
2876 @smallexample
2877 Subscript out of range on file line 4, procedure rnge.f/bf.
2878 Attempt to access the -6-th element of variable b[subscript-2-of-2].
2879 Aborted
2880 @end smallexample
2881
2882 The above message indicates that the offending source line is
2883 line 4 of the file @file{rnge.f},
2884 within the program unit (or statement function) named @samp{bf}.
2885 The offended array is named @samp{b}.
2886 The offended array dimension is the second for a two-dimensional array,
2887 and the offending, computed subscript expression was @samp{-6}.
2888
2889 For a @code{CHARACTER} substring reference, the second line has
2890 this appearance:
2891
2892 @smallexample
2893 Attempt to access the 11-th element of variable a[start-substring].
2894 @end smallexample
2895
2896 This indicates that the offended @code{CHARACTER} variable or array
2897 is named @samp{a},
2898 the offended substring position is the starting (leftmost) position,
2899 and the offending substring expression is @samp{11}.
2900
2901 (Though the verbage of @code{s_rnge} is not ideal
2902 for the purpose of the @code{g77} compiler,
2903 the above information should provide adequate diagnostic abilities
2904 to it users.)
2905 @end table
2906
2907 @xref{Code Gen Options,,Options for Code Generation Conventions,
2908 gcc,Using and Porting GNU CC}, for information on more options
2909 offered by the GBE
2910 shared by @code{g77}, @code{gcc}, and other GNU compilers.
2911
2912 Some of these do @emph{not} work when compiling programs written in Fortran:
2913
2914 @table @code
2915 @cindex -fpcc-struct-return option
2916 @cindex options, -fpcc-struct-return
2917 @item -fpcc-struct-return
2918 @cindex -freg-struct-return option
2919 @cindex options, -freg-struct-return
2920 @item -freg-struct-return
2921 You should not use these except strictly the same way as you
2922 used them to build the version of @code{libg2c} with which
2923 you will be linking all code compiled by @code{g77} with the
2924 same option.
2925
2926 @cindex -fshort-double option
2927 @cindex options, -fshort-double
2928 @item -fshort-double
2929 This probably either has no effect on Fortran programs, or
2930 makes them act loopy.
2931
2932 @cindex -fno-common option
2933 @cindex options, -fno-common
2934 @item -fno-common
2935 Do not use this when compiling Fortran programs,
2936 or there will be Trouble.
2937
2938 @cindex -fpack-struct option
2939 @cindex options, -fpack-struct
2940 @item -fpack-struct
2941 This probably will break any calls to the @code{libg2c} library,
2942 at the very least, even if it is built with the same option.
2943 @end table
2944
2945 @node Environment Variables
2946 @section Environment Variables Affecting GNU Fortran
2947 @cindex environment variables
2948
2949 GNU Fortran currently does not make use of any environment
2950 variables to control its operation above and beyond those
2951 that affect the operation of @code{gcc}.
2952
2953 @xref{Environment Variables,,Environment Variables Affecting GNU CC,
2954 gcc,Using and Porting GNU CC}, for information on environment
2955 variables.
2956
2957 @include news.texi
2958
2959 @set USERVISONLY
2960 @include news.texi
2961 @clear USERVISONLY
2962
2963 @node Language
2964 @chapter The GNU Fortran Language
2965
2966 @cindex standard, ANSI FORTRAN 77
2967 @cindex ANSI FORTRAN 77 standard
2968 @cindex reference works
2969 GNU Fortran supports a variety of extensions to, and dialects
2970 of, the Fortran language.
2971 Its primary base is the ANSI FORTRAN 77 standard, currently available on
2972 the network at
2973 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
2974 or as monolithic text at
2975 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
2976 It offers some extensions that are popular among users
2977 of UNIX @code{f77} and @code{f2c} compilers, some that
2978 are popular among users of other compilers (such as Digital
2979 products), some that are popular among users of the
2980 newer Fortran 90 standard, and some that are introduced
2981 by GNU Fortran.
2982
2983 @cindex textbooks
2984 (If you need a text on Fortran,
2985 a few freely available electronic references have pointers from
2986 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
2987 net project', @cite{User Notes on Fortran Programming} at
2988 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
2989 material might not apply specifically to @code{g77}.)
2990
2991 Part of what defines a particular implementation of a Fortran
2992 system, such as @code{g77}, is the particular characteristics
2993 of how it supports types, constants, and so on.
2994 Much of this is left up to the implementation by the various
2995 Fortran standards and accepted practice in the industry.
2996
2997 The GNU Fortran @emph{language} is described below.
2998 Much of the material is organized along the same lines
2999 as the ANSI FORTRAN 77 standard itself.
3000
3001 @xref{Other Dialects}, for information on features @code{g77} supports
3002 that are not part of the GNU Fortran language.
3003
3004 @emph{Note}: This portion of the documentation definitely needs a lot
3005 of work!
3006
3007 @menu
3008 Relationship to the ANSI FORTRAN 77 standard:
3009 * Direction of Language Development::  Where GNU Fortran is headed.
3010 * Standard Support::  Degree of support for the standard.
3011
3012 Extensions to the ANSI FORTRAN 77 standard:
3013 * Conformance::
3014 * Notation Used::
3015 * Terms and Concepts::
3016 * Characters Lines Sequence::
3017 * Data Types and Constants::
3018 * Expressions::
3019 * Specification Statements::
3020 * Control Statements::
3021 * Functions and Subroutines::
3022 * Scope and Classes of Names::
3023 * I/O::
3024 * Fortran 90 Features::
3025 @end menu
3026
3027 @node Direction of Language Development
3028 @section Direction of Language Development
3029 @cindex direction of language development
3030 @cindex features, language
3031 @cindex language, features
3032
3033 The purpose of the following description of the GNU Fortran
3034 language is to promote wide portability of GNU Fortran programs.
3035
3036 GNU Fortran is an evolving language, due to the
3037 fact that @code{g77} itself is in beta test.
3038 Some current features of the language might later
3039 be redefined as dialects of Fortran supported by @code{g77}
3040 when better ways to express these features are added to @code{g77},
3041 for example.
3042 Such features would still be supported by
3043 @code{g77}, but would be available only when
3044 one or more command-line options were used.
3045
3046 The GNU Fortran @emph{language} is distinct from the
3047 GNU Fortran @emph{compilation system} (@code{g77}).
3048
3049 For example, @code{g77} supports various dialects of
3050 Fortran---in a sense, these are languages other than
3051 GNU Fortran---though its primary
3052 purpose is to support the GNU Fortran language, which also is
3053 described in its documentation and by its implementation.
3054
3055 On the other hand, non-GNU compilers might offer
3056 support for the GNU Fortran language, and are encouraged
3057 to do so.
3058
3059 Currently, the GNU Fortran language is a fairly fuzzy object.
3060 It represents something of a cross between what @code{g77} accepts
3061 when compiling using the prevailing defaults and what this
3062 document describes as being part of the language.
3063
3064 Future versions of @code{g77} are expected to clarify the
3065 definition of the language in the documentation.
3066 Often, this will mean adding new features to the language, in the form
3067 of both new documentation and new support in @code{g77}.
3068 However, it might occasionally mean removing a feature
3069 from the language itself to ``dialect'' status.
3070 In such a case, the documentation would be adjusted
3071 to reflect the change, and @code{g77} itself would likely be changed
3072 to require one or more command-line options to continue supporting
3073 the feature.
3074
3075 The development of the GNU Fortran language is intended to strike
3076 a balance between:
3077
3078 @itemize @bullet
3079 @item
3080 Serving as a mostly-upwards-compatible language from the
3081 de facto UNIX Fortran dialect as supported by @code{f77}.
3082
3083 @item
3084 Offering new, well-designed language features.
3085 Attributes of such features include
3086 not making existing code any harder to read
3087 (for those who might be unaware that the new
3088 features are not in use) and
3089 not making state-of-the-art
3090 compilers take longer to issue diagnostics,
3091 among others.
3092
3093 @item
3094 Supporting existing, well-written code without gratuitously
3095 rejecting non-standard constructs, regardless of the origin
3096 of the code (its dialect).
3097
3098 @item
3099 Offering default behavior and command-line options to reduce
3100 and, where reasonable, eliminate the need for programmers to make
3101 any modifications to code that already works in existing
3102 production environments.
3103
3104 @item
3105 Diagnosing constructs that have different meanings in different
3106 systems, languages, and dialects, while offering clear,
3107 less ambiguous ways to express each of the different meanings
3108 so programmers can change their code appropriately.
3109 @end itemize
3110
3111 One of the biggest practical challenges for the developers of the
3112 GNU Fortran language is meeting the sometimes contradictory demands
3113 of the above items.
3114
3115 For example, a feature might be widely used in one popular environment,
3116 but the exact same code that utilizes that feature might not work
3117 as expected---perhaps it might mean something entirely different---in
3118 another popular environment.
3119
3120 Traditionally, Fortran compilers---even portable ones---have solved this
3121 problem by simply offering the appropriate feature to users of
3122 the respective systems.
3123 This approach treats users of various Fortran systems and dialects
3124 as remote ``islands'', or camps, of programmers, and assume that these
3125 camps rarely come into contact with each other (or,
3126 especially, with each other's code).
3127
3128 Project GNU takes a radically different approach to software and language
3129 design, in that it assumes that users of GNU software do not necessarily
3130 care what kind of underlying system they are using, regardless
3131 of whether they are using software (at the user-interface
3132 level) or writing it (for example, writing Fortran or C code).
3133
3134 As such, GNU users rarely need consider just what kind of underlying
3135 hardware (or, in many cases, operating system) they are using at any
3136 particular time.
3137 They can use and write software designed for a general-purpose,
3138 widely portable, heterogenous environment---the GNU environment.
3139
3140 In line with this philosophy, GNU Fortran must evolve into a product
3141 that is widely ported and portable not only in the sense that it can
3142 be successfully built, installed, and run by users, but in the larger
3143 sense that its users can use it in the same way, and expect largely the
3144 same behaviors from it, regardless of the kind of system they are using
3145 at any particular time.
3146
3147 This approach constrains the solutions @code{g77} can use to resolve
3148 conflicts between various camps of Fortran users.
3149 If these two camps disagree about what a particular construct should
3150 mean, @code{g77} cannot simply be changed to treat that particular construct as
3151 having one meaning without comment (such as a warning), lest the users
3152 expecting it to have the other meaning are unpleasantly surprised that
3153 their code misbehaves when executed.
3154
3155 The use of the ASCII backslash character in character constants is
3156 an excellent (and still somewhat unresolved) example of this kind of
3157 controversy.
3158 @xref{Backslash in Constants}.
3159 Other examples are likely to arise in the future, as @code{g77} developers
3160 strive to improve its ability to accept an ever-wider variety of existing
3161 Fortran code without requiring significant modifications to said code.
3162
3163 Development of GNU Fortran is further constrained by the desire
3164 to avoid requiring programmers to change their code.
3165 This is important because it allows programmers, administrators,
3166 and others to more faithfully evaluate and validate @code{g77}
3167 (as an overall product and as new versions are distributed)
3168 without having to support multiple versions of their programs
3169 so that they continue to work the same way on their existing
3170 systems (non-GNU perhaps, but possibly also earlier versions
3171 of @code{g77}).
3172
3173 @node Standard Support
3174 @section ANSI FORTRAN 77 Standard Support
3175 @cindex ANSI FORTRAN 77 support
3176 @cindex standard, support for
3177 @cindex support, FORTRAN 77
3178 @cindex compatibility, FORTRAN 77
3179 @cindex FORTRAN 77 compatibility
3180
3181 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
3182 In summary, the only ANSI FORTRAN 77 features @code{g77} doesn't
3183 support are those that are probably rarely used in actual code,
3184 some of which are explicitly disallowed by the Fortran 90 standard.
3185
3186 @menu
3187 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
3188 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
3189 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
3190 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
3191 @end menu
3192
3193 @node No Passing External Assumed-length
3194 @subsection No Passing External Assumed-length
3195
3196 @code{g77} disallows passing of an external procedure
3197 as an actual argument if the procedure's
3198 type is declared @code{CHARACTER*(*)}.  For example:
3199
3200 @example
3201 CHARACTER*(*) CFUNC
3202 EXTERNAL CFUNC
3203 CALL FOO(CFUNC)
3204 END
3205 @end example
3206
3207 @noindent
3208 It isn't clear whether the standard considers this conforming.
3209
3210 @node No Passing Dummy Assumed-length
3211 @subsection No Passing Dummy Assumed-length
3212
3213 @code{g77} disallows passing of a dummy procedure
3214 as an actual argument if the procedure's
3215 type is declared @code{CHARACTER*(*)}.
3216
3217 @example
3218 SUBROUTINE BAR(CFUNC)
3219 CHARACTER*(*) CFUNC
3220 EXTERNAL CFUNC
3221 CALL FOO(CFUNC)
3222 END
3223 @end example
3224
3225 @noindent
3226 It isn't clear whether the standard considers this conforming.
3227
3228 @node No Pathological Implied-DO
3229 @subsection No Pathological Implied-DO
3230
3231 The @code{DO} variable for an implied-@code{DO} construct in a
3232 @code{DATA} statement may not be used as the @code{DO} variable
3233 for an outer implied-@code{DO} construct.  For example, this
3234 fragment is disallowed by @code{g77}:
3235
3236 @smallexample
3237 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
3238 @end smallexample
3239
3240 @noindent
3241 This also is disallowed by Fortran 90, as it offers no additional
3242 capabilities and would have a variety of possible meanings.
3243
3244 Note that it is @emph{very} unlikely that any production Fortran code
3245 tries to use this unsupported construct.
3246
3247 @node No Useless Implied-DO
3248 @subsection No Useless Implied-DO
3249
3250 An array element initializer in an implied-@code{DO} construct in a
3251 @code{DATA} statement must contain at least one reference to the @code{DO}
3252 variables of each outer implied-@code{DO} construct.  For example,
3253 this fragment is disallowed by @code{g77}:
3254
3255 @smallexample
3256 DATA (A, I= 1, 1) /1./
3257 @end smallexample
3258
3259 @noindent
3260 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
3261 requirements offer no additional capabilities.
3262 However, @code{g77} doesn't necessarily diagnose all cases
3263 where this requirement is not met.
3264
3265 Note that it is @emph{very} unlikely that any production Fortran code
3266 tries to use this unsupported construct.
3267
3268 @node Conformance
3269 @section Conformance
3270
3271 (The following information augments or overrides the information in
3272 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3273 language.
3274 Chapter 1 of that document otherwise serves as the basis
3275 for the relevant aspects of GNU Fortran.)
3276
3277 The definition of the GNU Fortran language is akin to that of
3278 the ANSI FORTRAN 77 language in that it does not generally require
3279 conforming implementations to diagnose cases where programs do
3280 not conform to the language.
3281
3282 However, @code{g77} as a compiler is being developed in a way that
3283 is intended to enable it to diagnose such cases in an easy-to-understand
3284 manner.
3285
3286 A program that conforms to the GNU Fortran language should, when
3287 compiled, linked, and executed using a properly installed @code{g77}
3288 system, perform as described by the GNU Fortran language definition.
3289 Reasons for different behavior include, among others:
3290
3291 @itemize @bullet
3292 @item
3293 Use of resources (memory---heap, stack, and so on; disk space; CPU
3294 time; etc.) exceeds those of the system.
3295
3296 @item
3297 Range and/or precision of calculations required by the program
3298 exceeds that of the system.
3299
3300 @item
3301 Excessive reliance on behaviors that are system-dependent
3302 (non-portable Fortran code).
3303
3304 @item
3305 Bugs in the program.
3306
3307 @item
3308 Bug in @code{g77}.
3309
3310 @item
3311 Bugs in the system.
3312 @end itemize
3313
3314 Despite these ``loopholes'', the availability of a clear specification
3315 of the language of programs submitted to @code{g77}, as this document
3316 is intended to provide, is considered an important aspect of providing
3317 a robust, clean, predictable Fortran implementation.
3318
3319 The definition of the GNU Fortran language, while having no special
3320 legal status, can therefore be viewed as a sort of contract, or agreement.
3321 This agreement says, in essence, ``if you write a program in this language,
3322 and run it in an environment (such as a @code{g77} system) that supports
3323 this language, the program should behave in a largely predictable way''.
3324
3325 @node Notation Used
3326 @section Notation Used in This Chapter
3327
3328 (The following information augments or overrides the information in
3329 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3330 language.
3331 Chapter 1 of that document otherwise serves as the basis
3332 for the relevant aspects of GNU Fortran.)
3333
3334 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
3335 and ``must not'' and ``may not'' denote prohibition.
3336 Terms such as ``might'', ``should'', and ``can'' generally add little or
3337 nothing in the way of weight to the GNU Fortran language itself,
3338 but are used to explain or illustrate the language.
3339
3340 For example:
3341
3342 @display
3343 ``The @code{FROBNITZ} statement must precede all executable
3344 statements in a program unit, and may not specify any dummy
3345 arguments.  It may specify local or common variables and arrays.
3346 Its use should be limited to portions of the program designed to
3347 be non-portable and system-specific, because it might cause the
3348 containing program unit to behave quite differently on different
3349 systems.''
3350 @end display
3351
3352 Insofar as the GNU Fortran language is specified,
3353 the requirements and permissions denoted by the above sample statement
3354 are limited to the placement of the statement and the kinds of
3355 things it may specify.
3356 The rest of the statement---the content regarding non-portable portions
3357 of the program and the differing behavior of program units containing
3358 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
3359 language itself.
3360 That content offers advice and warnings about the @code{FROBNITZ}
3361 statement.
3362
3363 @emph{Remember:} The GNU Fortran language definition specifies
3364 both what constitutes a valid GNU Fortran program and how,
3365 given such a program, a valid GNU Fortran implementation is
3366 to interpret that program.
3367
3368 It is @emph{not} incumbent upon a valid GNU Fortran implementation
3369 to behave in any particular way, any consistent way, or any
3370 predictable way when it is asked to interpret input that is
3371 @emph{not} a valid GNU Fortran program.
3372
3373 Such input is said to have @dfn{undefined} behavior when
3374 interpreted by a valid GNU Fortran implementation, though
3375 an implementation may choose to specify behaviors for some
3376 cases of inputs that are not valid GNU Fortran programs.
3377
3378 Other notation used herein is that of the GNU texinfo format,
3379 which is used to generate printed hardcopy, on-line hypertext
3380 (Info), and on-line HTML versions, all from a single source
3381 document.
3382 This notation is used as follows:
3383
3384 @itemize @bullet
3385 @item
3386 Keywords defined by the GNU Fortran language are shown
3387 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
3388 @code{BLOCK DATA}.
3389
3390 Note that, in practice, many Fortran programs are written
3391 in lowercase---uppercase is used in this manual as a
3392 means to readily distinguish keywords and sample Fortran-related
3393 text from the prose in this document.
3394
3395 @item
3396 Portions of actual sample program, input, or output text
3397 look like this: @samp{Actual program text}.
3398
3399 Generally, uppercase is used for all Fortran-specific and
3400 Fortran-related text, though this does not always include
3401 literal text within Fortran code.
3402
3403 For example: @samp{PRINT *, 'My name is Bob'}.
3404
3405 @item
3406 A metasyntactic variable---that is, a name used in this document
3407 to serve as a placeholder for whatever text is used by the
3408 user or programmer---appears as shown in the following example:
3409
3410 ``The @code{INTEGER @var{ivar}} statement specifies that
3411 @var{ivar} is a variable or array of type @code{INTEGER}.''
3412
3413 In the above example, any valid text may be substituted for
3414 the metasyntactic variable @var{ivar} to make the statement
3415 apply to a specific instance, as long as the same text is
3416 substituted for @emph{both} occurrences of @var{ivar}.
3417
3418 @item
3419 Ellipses (``@dots{}'') are used to indicate further text that
3420 is either unimportant or expanded upon further, elsewhere.
3421
3422 @item
3423 Names of data types are in the style of Fortran 90, in most
3424 cases.
3425
3426 @xref{Kind Notation}, for information on the relationship
3427 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
3428 and the more traditional, less portably concise nomenclature
3429 (such as @code{INTEGER*4}).
3430 @end itemize
3431
3432 @node Terms and Concepts
3433 @section Fortran Terms and Concepts
3434
3435 (The following information augments or overrides the information in
3436 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3437 language.
3438 Chapter 2 of that document otherwise serves as the basis
3439 for the relevant aspects of GNU Fortran.)
3440
3441 @menu
3442 * Syntactic Items::
3443 * Statements Comments Lines::
3444 * Scope of Names and Labels::
3445 @end menu
3446
3447 @node Syntactic Items
3448 @subsection Syntactic Items
3449
3450 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
3451
3452 @cindex limits, lengths of names
3453 In GNU Fortran, a symbolic name is at least one character long,
3454 and has no arbitrary upper limit on length.
3455 However, names of entities requiring external linkage (such as
3456 external functions, external subroutines, and @code{COMMON} areas)
3457 might be restricted to some arbitrary length by the system.
3458 Such a restriction is no more constrained than that of one
3459 through six characters.
3460
3461 Underscores (@samp{_}) are accepted in symbol names after the first
3462 character (which must be a letter).
3463
3464 @node Statements Comments Lines
3465 @subsection Statements, Comments, and Lines
3466
3467 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
3468
3469 @cindex trailing comment
3470 @cindex comment
3471 @cindex characters, comment
3472 @cindex !
3473 @cindex exclamation point
3474 @cindex continuation character
3475 @cindex characters, continuation
3476 Use of an exclamation point (@samp{!}) to begin a
3477 trailing comment (a comment that extends to the end of the same
3478 source line) is permitted under the following conditions:
3479
3480 @itemize @bullet
3481 @item
3482 The exclamation point does not appear in column 6.
3483 Otherwise, it is treated as an indicator of a continuation
3484 line.
3485
3486 @item
3487 The exclamation point appears outside a character or Hollerith
3488 constant.
3489 Otherwise, the exclamation point is considered part of the
3490 constant.
3491
3492 @item
3493 The exclamation point appears to the left of any other possible
3494 trailing comment.
3495 That is, a trailing comment may contain exclamation points
3496 in their commentary text.
3497 @end itemize
3498
3499 @cindex ;
3500 @cindex semicolon
3501 @cindex statements, separated by semicolon
3502 Use of a semicolon (@samp{;}) as a statement separator
3503 is permitted under the following conditions:
3504
3505 @itemize @bullet
3506 @item
3507 The semicolon appears outside a character or Hollerith
3508 constant.
3509 Otherwise, the semicolon is considered part of the
3510 constant.
3511
3512 @item
3513 The semicolon appears to the left of a trailing comment.
3514 Otherwise, the semicolon is considered part of that
3515 comment.
3516
3517 @item
3518 Neither a logical @code{IF} statement nor a non-construct
3519 @code{WHERE} statement (a Fortran 90 feature) may be
3520 followed (in the same, possibly continued, line) by
3521 a semicolon used as a statement separator.
3522
3523 This restriction avoids the confusion
3524 that can result when reading a line such as:
3525
3526 @smallexample
3527 IF (VALIDP) CALL FOO; CALL BAR
3528 @end smallexample
3529
3530 @noindent
3531 Some readers might think the @samp{CALL BAR} is executed
3532 only if @samp{VALIDP} is @code{.TRUE.}, while others might
3533 assume its execution is unconditional.
3534
3535 (At present, @code{g77} does not diagnose code that
3536 violates this restriction.)
3537 @end itemize
3538
3539 @node Scope of Names and Labels
3540 @subsection Scope of Symbolic Names and Statement Labels
3541 @cindex scope
3542
3543 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
3544
3545 Included in the list of entities that have a scope of a
3546 program unit are construct names (a Fortran 90 feature).
3547 @xref{Construct Names}, for more information.
3548
3549 @node Characters Lines Sequence
3550 @section Characters, Lines, and Execution Sequence
3551
3552 (The following information augments or overrides the information in
3553 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3554 language.
3555 Chapter 3 of that document otherwise serves as the basis
3556 for the relevant aspects of GNU Fortran.)
3557
3558 @menu
3559 * Character Set::
3560 * Lines::
3561 * Continuation Line::
3562 * Statements::
3563 * Statement Labels::
3564 * Order::
3565 * INCLUDE::
3566 * Cpp-style directives::
3567 @end menu
3568
3569 @node Character Set
3570 @subsection GNU Fortran Character Set
3571 @cindex characters
3572
3573 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
3574
3575 Letters include uppercase letters (the twenty-six characters
3576 of the English alphabet) and lowercase letters (their lowercase
3577 equivalent).
3578 Generally, lowercase letters may be used in place of uppercase
3579 letters, though in character and Hollerith constants, they
3580 are distinct.
3581
3582 Special characters include:
3583
3584 @itemize @bullet
3585 @item
3586 @cindex ;
3587 @cindex semicolon
3588 Semicolon (@samp{;})
3589
3590 @item
3591 @cindex !
3592 @cindex exclamation point
3593 Exclamation point (@samp{!})
3594
3595 @item
3596 @cindex "
3597 @cindex double quote
3598 Double quote (@samp{"})
3599
3600 @item
3601 @cindex \
3602 @cindex backslash
3603 Backslash (@samp{\})
3604
3605 @item
3606 @cindex ?
3607 @cindex question mark
3608 Question mark (@samp{?})
3609
3610 @item
3611 @cindex #
3612 @cindex hash mark
3613 @cindex pound sign
3614 Hash mark (@samp{#})
3615
3616 @item
3617 @cindex &
3618 @cindex ampersand
3619 Ampersand (@samp{&})
3620
3621 @item
3622 @cindex %
3623 @cindex percent sign
3624 Percent sign (@samp{%})
3625
3626 @item
3627 @cindex _
3628 @cindex underscore
3629 Underscore (@samp{_})
3630
3631 @item
3632 @cindex <
3633 @cindex open angle
3634 @cindex left angle
3635 @cindex open bracket
3636 @cindex left bracket
3637 Open angle (@samp{<})
3638
3639 @item
3640 @cindex >
3641 @cindex close angle
3642 @cindex right angle
3643 @cindex close bracket
3644 @cindex right bracket
3645 Close angle (@samp{>})
3646
3647 @item
3648 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
3649 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
3650 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
3651 and @samp{:})
3652 @end itemize
3653
3654 @cindex blank
3655 @cindex space
3656 @cindex SPC
3657 Note that this document refers to @key{SPC} as @dfn{space},
3658 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
3659
3660 @node Lines
3661 @subsection Lines
3662 @cindex lines
3663 @cindex source file format
3664 @cindex source format
3665 @cindex file, source
3666 @cindex source code
3667 @cindex code, source
3668 @cindex fixed form
3669 @cindex free form
3670
3671 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
3672
3673 The way a Fortran compiler views source files depends entirely on the
3674 implementation choices made for the compiler, since those choices
3675 are explicitly left to the implementation by the published Fortran
3676 standards.
3677
3678 The GNU Fortran language mandates a view applicable to UNIX-like
3679 text files---files that are made up of an arbitrary number of lines,
3680 each with an arbitrary number of characters (sometimes called stream-based
3681 files).
3682
3683 This view does not apply to types of files that are specified as
3684 having a particular number of characters on every single line (sometimes
3685 referred to as record-based files).
3686
3687 Because a ``line in a program unit is a sequence of 72 characters'',
3688 to quote X3.9-1978, the GNU Fortran language specifies that a
3689 stream-based text file is translated to GNU Fortran lines as follows:
3690
3691 @itemize @bullet
3692 @item
3693 A newline in the file is the character that represents the end of
3694 a line of text to the underlying system.
3695 For example, on ASCII-based systems, a newline is the @key{NL}
3696 character, which has ASCII value 10 (decimal).
3697
3698 @item
3699 Each newline in the file serves to end the line of text that precedes
3700 it (and that does not contain a newline).
3701
3702 @item
3703 The end-of-file marker (@code{EOF}) also serves to end the line
3704 of text that precedes it (and that does not contain a newline).
3705
3706 @item
3707 @cindex blank
3708 @cindex space
3709 @cindex SPC
3710 Any line of text that is shorter than 72 characters is padded to that length
3711 with spaces (called ``blanks'' in the standard).
3712
3713 @item
3714 Any line of text that is longer than 72 characters is truncated to that
3715 length, but the truncated remainder must consist entirely of spaces.
3716
3717 @item
3718 Characters other than newline and the GNU Fortran character set
3719 are invalid.
3720 @end itemize
3721
3722 For the purposes of the remainder of this description of the GNU
3723 Fortran language, the translation described above has already
3724 taken place, unless otherwise specified.
3725
3726 The result of the above translation is that the source file appears,
3727 in terms of the remainder of this description of the GNU Fortran language,
3728 as if it had an arbitrary
3729 number of 72-character lines, each character being among the GNU Fortran
3730 character set.
3731
3732 For example, if the source file itself has two newlines in a row,
3733 the second newline becomes, after the above translation, a single
3734 line containing 72 spaces.
3735
3736 @node Continuation Line
3737 @subsection Continuation Line
3738 @cindex continuation line, number of
3739 @cindex lines, continuation
3740 @cindex number of continuation lines
3741 @cindex limits, continuation lines
3742
3743 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
3744
3745 A continuation line is any line that both
3746
3747 @itemize @bullet
3748 @item
3749 Contains a continuation character, and
3750
3751 @item
3752 Contains only spaces in columns 1 through 5
3753 @end itemize
3754
3755 A continuation character is any character of the GNU Fortran character set
3756 other than space (@key{SPC}) or zero (@samp{0})
3757 in column 6, or a digit (@samp{0} through @samp{9}) in column
3758 7 through 72 of a line that has only spaces to the left of that
3759 digit.
3760
3761 The continuation character is ignored as far as the content of
3762 the statement is concerned.
3763
3764 The GNU Fortran language places no limit on the number of
3765 continuation lines in a statement.
3766 In practice, the limit depends on a variety of factors, such as
3767 available memory, statement content, and so on, but no
3768 GNU Fortran system may impose an arbitrary limit.
3769
3770 @node Statements
3771 @subsection Statements
3772
3773 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
3774
3775 Statements may be written using an arbitrary number of continuation
3776 lines.
3777
3778 Statements may be separated using the semicolon (@samp{;}), except
3779 that the logical @code{IF} and non-construct @code{WHERE} statements
3780 may not be separated from subsequent statements using only a semicolon
3781 as statement separator.
3782
3783 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
3784 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
3785 statement.
3786 These alternatives may be written as normal statements---they are not
3787 subject to the restrictions of the @code{END} statement.
3788
3789 However, no statement other than @code{END} may have an initial line
3790 that appears to be an @code{END} statement---even @code{END PROGRAM},
3791 for example, must not be written as:
3792
3793 @example
3794       END
3795      &PROGRAM
3796 @end example
3797
3798 @node Statement Labels
3799 @subsection Statement Labels
3800
3801 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
3802
3803 A statement separated from its predecessor via a semicolon may be
3804 labeled as follows:
3805
3806 @itemize @bullet
3807 @item
3808 The semicolon is followed by the label for the statement,
3809 which in turn follows the label.
3810
3811 @item
3812 The label must be no more than five digits in length.
3813
3814 @item
3815 The first digit of the label for the statement is not
3816 the first non-space character on a line.
3817 Otherwise, that character is treated as a continuation
3818 character.
3819 @end itemize
3820
3821 A statement may have only one label defined for it.
3822
3823 @node Order
3824 @subsection Order of Statements and Lines
3825
3826 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
3827
3828 Generally, @code{DATA} statements may precede executable statements.
3829 However, specification statements pertaining to any entities
3830 initialized by a @code{DATA} statement must precede that @code{DATA}
3831 statement.
3832 For example,
3833 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
3834 @samp{INTEGER J} is permitted.
3835
3836 The last line of a program unit may be an @code{END} statement,
3837 or may be:
3838
3839 @itemize @bullet
3840 @item
3841 An @code{END PROGRAM} statement, if the program unit is a main program.
3842
3843 @item
3844 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
3845
3846 @item
3847 An @code{END FUNCTION} statement, if the program unit is a function.
3848
3849 @item
3850 An @code{END BLOCK DATA} statement, if the program unit is a block data.
3851 @end itemize
3852
3853 @node INCLUDE
3854 @subsection Including Source Text
3855 @cindex INCLUDE directive
3856
3857 Additional source text may be included in the processing of
3858 the source file via the @code{INCLUDE} directive:
3859
3860 @example
3861 INCLUDE @var{filename}
3862 @end example
3863
3864 @noindent
3865 The source text to be included is identified by @var{filename},
3866 which is a literal GNU Fortran character constant.
3867 The meaning and interpretation of @var{filename} depends on the
3868 implementation, but typically is a filename.
3869
3870 (@code{g77} treats it as a filename that it searches for
3871 in the current directory and/or directories specified
3872 via the @samp{-I} command-line option.)
3873
3874 The effect of the @code{INCLUDE} directive is as if the
3875 included text directly replaced the directive in the source
3876 file prior to interpretation of the program.
3877 Included text may itself use @code{INCLUDE}.
3878 The depth of nested @code{INCLUDE} references depends on
3879 the implementation, but typically is a positive integer.
3880
3881 This virtual replacement treats the statements and @code{INCLUDE}
3882 directives in the included text as syntactically distinct from
3883 those in the including text.
3884
3885 Therefore, the first non-comment line of the included text
3886 must not be a continuation line.
3887 The included text must therefore have, after the non-comment
3888 lines, either an initial line (statement), an @code{INCLUDE}
3889 directive, or nothing (the end of the included text).
3890
3891 Similarly, the including text may end the @code{INCLUDE}
3892 directive with a semicolon or the end of the line, but it
3893 cannot follow an @code{INCLUDE} directive at the end of its
3894 line with a continuation line.
3895 Thus, the last statement in an included text may not be
3896 continued.
3897
3898 Any statements between two @code{INCLUDE} directives on the
3899 same line are treated as if they appeared in between the
3900 respective included texts.
3901 For example:
3902
3903 @smallexample
3904 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
3905 @end smallexample
3906
3907 @noindent
3908 If the text included by @samp{INCLUDE 'A'} constitutes
3909 a @samp{PRINT *, 'A'} statement and the text included by
3910 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
3911 then the output of the above sample program would be
3912
3913 @example
3914 A
3915 B
3916 C
3917 @end example
3918
3919 @noindent
3920 (with suitable allowances for how an implementation defines
3921 its handling of output).
3922
3923 Included text must not include itself directly or indirectly,
3924 regardless of whether the @var{filename} used to reference
3925 the text is the same.
3926
3927 Note that @code{INCLUDE} is @emph{not} a statement.
3928 As such, it is neither a non-executable or executable
3929 statement.
3930 However, if the text it includes constitutes one or more
3931 executable statements, then the placement of @code{INCLUDE}
3932 is subject to effectively the same restrictions as those
3933 on executable statements.
3934
3935 An @code{INCLUDE} directive may be continued across multiple
3936 lines as if it were a statement.
3937 This permits long names to be used for @var{filename}.
3938
3939 @node Cpp-style directives
3940 @subsection Cpp-style directives
3941 @cindex #
3942 @cindex preprocessor
3943
3944 @code{cpp} output-style @code{#} directives
3945 (@pxref{C Preprocessor Output,,, cpp, The C Preprocessor})
3946 are recognized by the compiler even
3947 when the preprocessor isn't run on the input (as it is when compiling
3948 @samp{.F} files).  (Note the distinction between these @code{cpp}
3949 @code{#} @emph{output} directives and @code{#line} @emph{input}
3950 directives.)
3951
3952 @node Data Types and Constants
3953 @section Data Types and Constants
3954
3955 (The following information augments or overrides the information in
3956 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3957 language.
3958 Chapter 4 of that document otherwise serves as the basis
3959 for the relevant aspects of GNU Fortran.)
3960
3961 To more concisely express the appropriate types for
3962 entities, this document uses the more concise
3963 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
3964 instead of the more traditional, but less portably concise,
3965 byte-size-based nomenclature such as @code{INTEGER*4},
3966 wherever reasonable.
3967
3968 When referring to generic types---in contexts where the
3969 specific precision and range of a type are not important---this
3970 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
3971 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
3972
3973 In some cases, the context requires specification of a
3974 particular type.
3975 This document uses the @samp{KIND=} notation to accomplish
3976 this throughout, sometimes supplying the more traditional
3977 notation for clarification, though the traditional notation
3978 might not work the same way on all GNU Fortran implementations.
3979
3980 Use of @samp{KIND=} makes this document more concise because
3981 @code{g77} is able to define values for @samp{KIND=} that
3982 have the same meanings on all systems, due to the way the
3983 Fortran 90 standard specifies these values are to be used.
3984
3985 (In particular, that standard permits an implementation to
3986 arbitrarily assign nonnegative values.
3987 There are four distinct sets of assignments: one to the @code{CHARACTER}
3988 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
3989 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
3990 Implementations are free to assign these values in any order,
3991 leave gaps in the ordering of assignments, and assign more than
3992 one value to a representation.)
3993
3994 This makes @samp{KIND=} values superior to the values used
3995 in non-standard statements such as @samp{INTEGER*4}, because
3996 the meanings of the values in those statements vary from machine
3997 to machine, compiler to compiler, even operating system to
3998 operating system.
3999
4000 However, use of @samp{KIND=} is @emph{not} generally recommended
4001 when writing portable code (unless, for example, the code is
4002 going to be compiled only via @code{g77}, which is a widely
4003 ported compiler).
4004 GNU Fortran does not yet have adequate language constructs to
4005 permit use of @samp{KIND=} in a fashion that would make the
4006 code portable to Fortran 90 implementations; and, this construct
4007 is known to @emph{not} be accepted by many popular FORTRAN 77
4008 implementations, so it cannot be used in code that is to be ported
4009 to those.
4010
4011 The distinction here is that this document is able to use
4012 specific values for @samp{KIND=} to concisely document the
4013 types of various operations and operands.
4014
4015 A Fortran program should use the FORTRAN 77 designations for the
4016 appropriate GNU Fortran types---such as @code{INTEGER} for
4017 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
4018 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
4019 where no such designations exist, make use of appropriate
4020 techniques (preprocessor macros, parameters, and so on)
4021 to specify the types in a fashion that may be easily adjusted
4022 to suit each particular implementation to which the program
4023 is ported.
4024 (These types generally won't need to be adjusted for ports of
4025 @code{g77}.)
4026
4027 Further details regarding GNU Fortran data types and constants
4028 are provided below.
4029
4030 @menu
4031 * Types::
4032 * Constants::
4033 * Integer Type::
4034 * Character Type::
4035 @end menu
4036
4037 @node Types
4038 @subsection Data Types
4039
4040 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
4041
4042 GNU Fortran supports these types:
4043
4044 @enumerate
4045 @item
4046 Integer (generic type @code{INTEGER})
4047
4048 @item
4049 Real (generic type @code{REAL})
4050
4051 @item
4052 Double precision
4053
4054 @item
4055 Complex (generic type @code{COMPLEX})
4056
4057 @item
4058 Logical (generic type @code{LOGICAL})
4059
4060 @item
4061 Character (generic type @code{CHARACTER})
4062
4063 @item
4064 Double Complex
4065 @end enumerate
4066
4067 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
4068
4069 The generic types shown above are referred to in this document
4070 using only their generic type names.
4071 Such references usually indicate that any specific type (kind)
4072 of that generic type is valid.
4073
4074 For example, a context described in this document as accepting
4075 the @code{COMPLEX} type also is likely to accept the
4076 @code{DOUBLE COMPLEX} type.
4077
4078 The GNU Fortran language supports three ways to specify
4079 a specific kind of a generic type.
4080
4081 @menu
4082 * Double Notation::  As in @code{DOUBLE COMPLEX}.
4083 * Star Notation::    As in @code{INTEGER*4}.
4084 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
4085 @end menu
4086
4087 @node Double Notation
4088 @subsubsection Double Notation
4089
4090 The GNU Fortran language supports two uses of the keyword
4091 @code{DOUBLE} to specify a specific kind of type:
4092
4093 @itemize @bullet
4094 @item
4095 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
4096
4097 @item
4098 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
4099 @end itemize
4100
4101 Use one of the above forms where a type name is valid.
4102
4103 While use of this notation is popular, it doesn't scale
4104 well in a language or dialect rich in intrinsic types,
4105 as is the case for the GNU Fortran language (especially
4106 planned future versions of it).
4107
4108 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
4109 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
4110 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
4111 often are substituted for these, respectively, even though they
4112 do not always have the same meanings on all systems.
4113 (And, the fact that @samp{DOUBLE REAL} does not exist as such
4114 is an inconsistency.)
4115
4116 Therefore, this document uses ``double notation'' only on occasion
4117 for the benefit of those readers who are accustomed to it.
4118
4119 @node Star Notation
4120 @subsubsection Star Notation
4121 @cindex *@var{n} notation
4122
4123 The following notation specifies the storage size for a type:
4124
4125 @smallexample
4126 @var{generic-type}*@var{n}
4127 @end smallexample
4128
4129 @noindent
4130 @var{generic-type} must be a generic type---one of
4131 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4132 or @code{CHARACTER}.
4133 @var{n} must be one or more digits comprising a decimal
4134 integer number greater than zero.
4135
4136 Use the above form where a type name is valid.
4137
4138 The @samp{*@var{n}} notation specifies that the amount of storage
4139 occupied by variables and array elements of that type is @var{n}
4140 times the storage occupied by a @code{CHARACTER*1} variable.
4141
4142 This notation might indicate a different degree of precision and/or
4143 range for such variables and array elements, and the functions that
4144 return values of types using this notation.
4145 It does not limit the precision or range of values of that type
4146 in any particular way---use explicit code to do that.
4147
4148 Further, the GNU Fortran language requires no particular values
4149 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
4150 notation.
4151 @code{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
4152 on all systems, for example,
4153 but not all implementations are required to do so, and @code{g77}
4154 is known to not support @code{REAL*1} on most (or all) systems.
4155
4156 As a result, except for @var{generic-type} of @code{CHARACTER},
4157 uses of this notation should be limited to isolated
4158 portions of a program that are intended to handle system-specific
4159 tasks and are expected to be non-portable.
4160
4161 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
4162 only @code{CHARACTER}, where it signifies not only the amount
4163 of storage occupied, but the number of characters in entities
4164 of that type.
4165 However, almost all Fortran compilers have supported this
4166 notation for generic types, though with a variety of meanings
4167 for @var{n}.)
4168
4169 Specifications of types using the @samp{*@var{n}} notation
4170 always are interpreted as specifications of the appropriate
4171 types described in this document using the @samp{KIND=@var{n}}
4172 notation, described below.
4173
4174 While use of this notation is popular, it doesn't serve well
4175 in the context of a widely portable dialect of Fortran, such as
4176 the GNU Fortran language.
4177
4178 For example, even on one particular machine, two or more popular
4179 Fortran compilers might well disagree on the size of a type
4180 declared @code{INTEGER*2} or @code{REAL*16}.
4181 Certainly there
4182 is known to be disagreement over such things among Fortran
4183 compilers on @emph{different} systems.
4184
4185 Further, this notation offers no elegant way to specify sizes
4186 that are not even multiples of the ``byte size'' typically
4187 designated by @code{INTEGER*1}.
4188 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
4189 certainly be possible, but would perhaps be stretching the original
4190 intent of this notation beyond the breaking point in terms
4191 of widespread readability of documentation and code making use
4192 of it.
4193
4194 Therefore, this document uses ``star notation'' only on occasion
4195 for the benefit of those readers who are accustomed to it.
4196
4197 @node Kind Notation
4198 @subsubsection Kind Notation
4199 @cindex KIND= notation
4200
4201 The following notation specifies the kind-type selector of a type:
4202
4203 @smallexample
4204 @var{generic-type}(KIND=@var{n})
4205 @end smallexample
4206
4207 @noindent
4208 Use the above form where a type name is valid.
4209
4210 @var{generic-type} must be a generic type---one of
4211 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4212 or @code{CHARACTER}.
4213 @var{n} must be an integer initialization expression that
4214 is a positive, nonzero value.
4215
4216 Programmers are discouraged from writing these values directly
4217 into their code.
4218 Future versions of the GNU Fortran language will offer
4219 facilities that will make the writing of code portable
4220 to @code{g77} @emph{and} Fortran 90 implementations simpler.
4221
4222 However, writing code that ports to existing FORTRAN 77
4223 implementations depends on avoiding the @samp{KIND=} construct.
4224
4225 The @samp{KIND=} construct is thus useful in the context
4226 of GNU Fortran for two reasons:
4227
4228 @itemize @bullet
4229 @item
4230 It provides a means to specify a type in a fashion that
4231 is portable across all GNU Fortran implementations (though
4232 not other FORTRAN 77 and Fortran 90 implementations).
4233
4234 @item
4235 It provides a sort of Rosetta stone for this document to use
4236 to concisely describe the types of various operations and
4237 operands.
4238 @end itemize
4239
4240 The values of @var{n} in the GNU Fortran language are
4241 assigned using a scheme that:
4242
4243 @itemize @bullet
4244 @item
4245 Attempts to maximize the ability of readers
4246 of this document to quickly familiarize themselves
4247 with assignments for popular types
4248
4249 @item
4250 Provides a unique value for each specific desired
4251 meaning
4252
4253 @item
4254 Provides a means to automatically assign new values so
4255 they have a ``natural'' relationship to existing values,
4256 if appropriate, or, if no such relationship exists, will
4257 not interfere with future values assigned on the basis
4258 of such relationships
4259
4260 @item
4261 Avoids using values that are similar to values used
4262 in the existing, popular @samp{*@var{n}} notation,
4263 to prevent readers from expecting that these implied
4264 correspondences work on all GNU Fortran implementations
4265 @end itemize
4266
4267 The assignment system accomplishes this by assigning
4268 to each ``fundamental meaning'' of a specific type a
4269 unique prime number.
4270 Combinations of fundamental meanings---for example, a type
4271 that is two times the size of some other type---are assigned
4272 values of @var{n} that are the products of the values for
4273 those fundamental meanings.
4274
4275 A prime value of @var{n} is never given more than one fundamental
4276 meaning, to avoid situations where some code or system
4277 cannot reasonably provide those meanings in the form of a
4278 single type.
4279
4280 The values of @var{n} assigned so far are:
4281
4282 @table @code
4283 @item KIND=0
4284 This value is reserved for future use.
4285
4286 The planned future use is for this value to designate,
4287 explicitly, context-sensitive kind-type selection.
4288 For example, the expression @samp{1D0 * 0.1_0} would
4289 be equivalent to @samp{1D0 * 0.1D0}.
4290
4291 @item KIND=1
4292 This corresponds to the default types for
4293 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
4294 and @code{CHARACTER}, as appropriate.
4295
4296 These are the ``default'' types described in the Fortran 90 standard,
4297 though that standard does not assign any particular @samp{KIND=}
4298 value to these types.
4299
4300 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
4301 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
4302
4303 @item KIND=2
4304 This corresponds to types that occupy twice as much
4305 storage as the default types.
4306 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
4307 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
4308
4309 These are the ``double precision'' types described in the Fortran 90
4310 standard,
4311 though that standard does not assign any particular @samp{KIND=}
4312 value to these types.
4313
4314 @var{n} of 4 thus corresponds to types that occupy four times
4315 as much storage as the default types, @var{n} of 8 to types that
4316 occupy eight times as much storage, and so on.
4317
4318 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
4319 are not necessarily supported by every GNU Fortran implementation.
4320
4321 @item KIND=3
4322 This corresponds to types that occupy as much
4323 storage as the default @code{CHARACTER} type,
4324 which is the same effective type as @code{CHARACTER(KIND=1)}
4325 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
4326
4327 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
4328
4329 @var{n} of 6 thus corresponds to types that occupy twice as
4330 much storage as the @var{n}=3 types, @var{n} of 12 to types
4331 that occupy four times as much storage, and so on.
4332
4333 These are not necessarily supported by every GNU Fortran
4334 implementation.
4335
4336 @item KIND=5
4337 This corresponds to types that occupy half the
4338 storage as the default (@var{n}=1) types.
4339
4340 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
4341
4342 @var{n} of 25 thus corresponds to types that occupy one-quarter
4343 as much storage as the default types.
4344
4345 These are not necessarily supported by every GNU Fortran
4346 implementation.
4347
4348 @item KIND=7
4349 @cindex pointers
4350 This is valid only as @code{INTEGER(KIND=7)} and
4351 denotes the @code{INTEGER} type that has the smallest
4352 storage size that holds a pointer on the system.
4353
4354 A pointer representable by this type is capable of uniquely
4355 addressing a @code{CHARACTER*1} variable, array, array element,
4356 or substring.
4357
4358 (Typically this is equivalent to @code{INTEGER*4} or,
4359 on 64-bit systems, @code{INTEGER*8}.
4360 In a compatible C implementation, it typically would
4361 be the same size and semantics of the C type @code{void *}.)
4362 @end table
4363
4364 Note that these are @emph{proposed} correspondences and might change
4365 in future versions of @code{g77}---avoid writing code depending
4366 on them while @code{g77}, and therefore the GNU Fortran language
4367 it defines, is in beta testing.
4368
4369 Values not specified in the above list are reserved to
4370 future versions of the GNU Fortran language.
4371
4372 Implementation-dependent meanings will be assigned new,
4373 unique prime numbers so as to not interfere with other
4374 implementation-dependent meanings, and offer the possibility
4375 of increasing the portability of code depending on such
4376 types by offering support for them in other GNU Fortran
4377 implementations.
4378
4379 Other meanings that might be given unique values are:
4380
4381 @itemize @bullet
4382 @item
4383 Types that make use of only half their storage size for
4384 representing precision and range.
4385
4386 For example, some compilers offer options that cause
4387 @code{INTEGER} types to occupy the amount of storage
4388 that would be needed for @code{INTEGER(KIND=2)} types, but the
4389 range remains that of @code{INTEGER(KIND=1)}.
4390
4391 @item
4392 The IEEE single floating-point type.
4393
4394 @item
4395 Types with a specific bit pattern (endianness), such as the
4396 little-endian form of @code{INTEGER(KIND=1)}.
4397 These could permit, conceptually, use of portable code and
4398 implementations on data files written by existing systems.
4399 @end itemize
4400
4401 Future @emph{prime} numbers should be given meanings in as incremental
4402 a fashion as possible, to allow for flexibility and
4403 expressiveness in combining types.
4404
4405 For example, instead of defining a prime number for little-endian
4406 IEEE doubles, one prime number might be assigned the meaning
4407 ``little-endian'', another the meaning ``IEEE double'', and the
4408 value of @var{n} for a little-endian IEEE double would thus
4409 naturally be the product of those two respective assigned values.
4410 (It could even be reasonable to have IEEE values result from the
4411 products of prime values denoting exponent and fraction sizes
4412 and meanings, hidden bit usage, availability and representations
4413 of special values such as subnormals, infinities, and Not-A-Numbers
4414 (NaNs), and so on.)
4415
4416 This assignment mechanism, while not inherently required for
4417 future versions of the GNU Fortran language, is worth using
4418 because it could ease management of the ``space'' of supported
4419 types much easier in the long run.
4420
4421 The above approach suggests a mechanism for specifying inheritance
4422 of intrinsic (built-in) types for an entire, widely portable
4423 product line.
4424 It is certainly reasonable that, unlike programmers of other languages
4425 offering inheritance mechanisms that employ verbose names for classes
4426 and subclasses, along with graphical browsers to elucidate the
4427 relationships, Fortran programmers would employ
4428 a mechanism that works by multiplying prime numbers together
4429 and finding the prime factors of such products.
4430
4431 Most of the advantages for the above scheme have been explained
4432 above.
4433 One disadvantage is that it could lead to the defining,
4434 by the GNU Fortran language, of some fairly large prime numbers.
4435 This could lead to the GNU Fortran language being declared
4436 ``munitions'' by the United States Department of Defense.
4437
4438 @node Constants
4439 @subsection Constants
4440 @cindex constants
4441 @cindex types, constants
4442
4443 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
4444
4445 A @dfn{typeless constant} has one of the following forms:
4446
4447 @smallexample
4448 '@var{binary-digits}'B
4449 '@var{octal-digits}'O
4450 '@var{hexadecimal-digits}'Z
4451 '@var{hexadecimal-digits}'X
4452 @end smallexample
4453
4454 @noindent
4455 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
4456 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
4457 and @samp{0123456789ABCDEFabcdef}, respectively.
4458 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
4459 is 11, and so on.)
4460
4461 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
4462 treated as typeless.  @xref{Fortran Dialect Options,, Options
4463 Controlling Fortran Dialect}, for information on the
4464 @samp{-ftypeless-boz} option.
4465
4466 Typeless constants have values that depend on the context in which
4467 they are used.
4468
4469 All other constants, called @dfn{typed constants}, are interpreted---converted
4470 to internal form---according to their inherent type.
4471 Thus, context is @emph{never} a determining factor for the type, and hence
4472 the interpretation, of a typed constant.
4473 (All constants in the ANSI FORTRAN 77 language are typed constants.)
4474
4475 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
4476 Fortran (called default INTEGER in Fortran 90),
4477 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
4478 additional precision specified is lost, and even when used in a
4479 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
4480 and @samp{1D0} is always type @code{REAL(KIND=2)}.
4481
4482 @node Integer Type
4483 @subsection Integer Type
4484
4485 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
4486
4487 An integer constant also may have one of the following forms:
4488
4489 @smallexample
4490 B'@var{binary-digits}'
4491 O'@var{octal-digits}'
4492 Z'@var{hexadecimal-digits}'
4493 X'@var{hexadecimal-digits}'
4494 @end smallexample
4495
4496 @noindent
4497 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
4498 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
4499 and @samp{0123456789ABCDEFabcdef}, respectively.
4500 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
4501 is 11, and so on.)
4502
4503 @node Character Type
4504 @subsection Character Type
4505
4506 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
4507
4508 @cindex double quoted character constants
4509 A character constant may be delimited by a pair of double quotes
4510 (@samp{"}) instead of apostrophes.
4511 In this case, an apostrophe within the constant represents
4512 a single apostrophe, while a double quote is represented in
4513 the source text of the constant by two consecutive double
4514 quotes with no intervening spaces.
4515
4516 @cindex zero-length CHARACTER
4517 @cindex null CHARACTER strings
4518 @cindex empty CHARACTER strings
4519 @cindex strings, empty
4520 @cindex CHARACTER, null
4521 A character constant may be empty (have a length of zero).
4522
4523 A character constant may include a substring specification,
4524 The value of such a constant is the value of the substring---for
4525 example, the value of @samp{'hello'(3:5)} is the same
4526 as the value of @samp{'llo'}.
4527
4528 @node Expressions
4529 @section Expressions
4530
4531 (The following information augments or overrides the information in
4532 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4533 language.
4534 Chapter 6 of that document otherwise serves as the basis
4535 for the relevant aspects of GNU Fortran.)
4536
4537 @menu
4538 * %LOC()::
4539 @end menu
4540
4541 @node %LOC()
4542 @subsection The @code{%LOC()} Construct
4543 @cindex %LOC() construct
4544
4545 @example
4546 %LOC(@var{arg})
4547 @end example
4548
4549 The @code{%LOC()} construct is an expression
4550 that yields the value of the location of its argument,
4551 @var{arg}, in memory.
4552 The size of the type of the expression depends on the system---typically,
4553 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
4554 though it is actually type @code{INTEGER(KIND=7)}.
4555
4556 The argument to @code{%LOC()} must be suitable as the
4557 left-hand side of an assignment statement.
4558 That is, it may not be a general expression involving
4559 operators such as addition, subtraction, and so on,
4560 nor may it be a constant.
4561
4562 Use of @code{%LOC()} is recommended only for code that
4563 is accessing facilities outside of GNU Fortran, such as
4564 operating system or windowing facilities.
4565 It is best to constrain such uses to isolated portions of
4566 a program---portions that deal specifically and exclusively
4567 with low-level, system-dependent facilities.
4568 Such portions might well provide a portable interface for
4569 use by the program as a whole, but are themselves not
4570 portable, and should be thoroughly tested each time they
4571 are rebuilt using a new compiler or version of a compiler.
4572
4573 Do not depend on @code{%LOC()} returning a pointer that
4574 can be safely used to @emph{define} (change) the argument.
4575 While this might work in some circumstances, it is hard
4576 to predict whether it will continue to work when a program
4577 (that works using this unsafe behavior)
4578 is recompiled using different command-line options or
4579 a different version of @code{g77}.
4580
4581 Generally, @code{%LOC()} is safe when used as an argument
4582 to a procedure that makes use of the value of the corresponding
4583 dummy argument only during its activation, and only when
4584 such use is restricted to referencing (reading) the value
4585 of the argument to @code{%LOC()}.
4586
4587 @emph{Implementation Note:} Currently, @code{g77} passes
4588 arguments (those not passed using a construct such as @code{%VAL()})
4589 by reference or descriptor, depending on the type of
4590 the actual argument.
4591 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
4592 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
4593 in fact might compile to identical code.
4594
4595 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
4596 ``pass, by value, the address of @samp{I} in memory''.
4597 While @samp{CALL FOO(I)} might use that same approach in a
4598 particular version of @code{g77}, another version or compiler
4599 might choose a different implementation, such as copy-in/copy-out,
4600 to effect the desired behavior---and which will therefore not
4601 necessarily compile to the same code as would
4602 @samp{CALL FOO(%VAL(%LOC(I)))}
4603 using the same version or compiler.
4604
4605 @xref{Debugging and Interfacing}, for detailed information on
4606 how this particular version of @code{g77} implements various
4607 constructs.
4608
4609 @node Specification Statements
4610 @section Specification Statements
4611
4612 (The following information augments or overrides the information in
4613 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4614 language.
4615 Chapter 8 of that document otherwise serves as the basis
4616 for the relevant aspects of GNU Fortran.)
4617
4618 @menu
4619 * NAMELIST::
4620 * DOUBLE COMPLEX::
4621 @end menu
4622
4623 @node NAMELIST
4624 @subsection @code{NAMELIST} Statement
4625 @cindex NAMELIST statement
4626 @cindex statements, NAMELIST
4627
4628 The @code{NAMELIST} statement, and related I/O constructs, are
4629 supported by the GNU Fortran language in essentially the same
4630 way as they are by @code{f2c}.
4631
4632 This follows Fortran 90 with the restriction that on @code{NAMELIST}
4633 input, subscripts must have the form
4634 @smallexample
4635 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
4636 @end smallexample
4637 i.e.@:
4638 @smallexample
4639 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
4640 @end smallexample
4641 is allowed, but not, say,
4642 @smallexample
4643 &xx x(:3,8::2)=1,2,3,4,5,6/
4644 @end smallexample
4645
4646 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
4647 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
4648 @smallexample
4649 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
4650 @end smallexample
4651 could be used instead of the example above.
4652
4653 @node DOUBLE COMPLEX
4654 @subsection @code{DOUBLE COMPLEX} Statement
4655 @cindex DOUBLE COMPLEX
4656
4657 @code{DOUBLE COMPLEX} is a type-statement (and type) that
4658 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
4659
4660 @node Control Statements
4661 @section Control Statements
4662
4663 (The following information augments or overrides the information in
4664 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4665 language.
4666 Chapter 11 of that document otherwise serves as the basis
4667 for the relevant aspects of GNU Fortran.)
4668
4669 @menu
4670 * DO WHILE::
4671 * END DO::
4672 * Construct Names::
4673 * CYCLE and EXIT::
4674 @end menu
4675
4676 @node DO WHILE
4677 @subsection DO WHILE
4678 @cindex DO WHILE
4679 @cindex DO
4680 @cindex MIL-STD 1753
4681
4682 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
4683 Fortran 90 standards, is provided by the GNU Fortran language.
4684 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
4685 also supported.
4686
4687 @node END DO
4688 @subsection END DO
4689 @cindex END DO
4690 @cindex MIL-STD 1753
4691
4692 The @code{END DO} statement is provided by the GNU Fortran language.
4693
4694 This statement is used in one of two ways:
4695
4696 @itemize @bullet
4697 @item
4698 The Fortran 90 meaning, in which it specifies the termination
4699 point of a single @code{DO} loop started with a @code{DO} statement
4700 that specifies no termination label.
4701
4702 @item
4703 The MIL-STD 1753 meaning, in which it specifies the termination
4704 point of one or more @code{DO} loops, all of which start with a
4705 @code{DO} statement that specify the label defined for the
4706 @code{END DO} statement.
4707
4708 This kind of @code{END DO} statement is merely a synonym for
4709 @code{CONTINUE}, except it is permitted only when the statement
4710 is labeled and a target of one or more labeled @code{DO} loops.
4711
4712 It is expected that this use of @code{END DO} will be removed from
4713 the GNU Fortran language in the future, though it is likely that
4714 it will long be supported by @code{g77} as a dialect form.
4715 @end itemize
4716
4717 @node Construct Names
4718 @subsection Construct Names
4719 @cindex construct names
4720
4721 The GNU Fortran language supports construct names as defined
4722 by the Fortran 90 standard.
4723 These names are local to the program unit and are defined
4724 as follows:
4725
4726 @smallexample
4727 @var{construct-name}: @var{block-statement}
4728 @end smallexample
4729
4730 @noindent
4731 Here, @var{construct-name} is the construct name itself;
4732 its definition is connoted by the single colon (@samp{:}); and
4733 @var{block-statement} is an @code{IF}, @code{DO},
4734 or @code{SELECT CASE} statement that begins a block.
4735
4736 A block that is given a construct name must also specify the
4737 same construct name in its termination statement:
4738
4739 @example
4740 END @var{block} @var{construct-name}
4741 @end example
4742
4743 @noindent
4744 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
4745 as appropriate.
4746
4747 @node CYCLE and EXIT
4748 @subsection The @code{CYCLE} and @code{EXIT} Statements
4749
4750 @cindex CYCLE statement
4751 @cindex EXIT statement
4752 @cindex statements, CYCLE
4753 @cindex statements, EXIT
4754 The @code{CYCLE} and @code{EXIT} statements specify that
4755 the remaining statements in the current iteration of a
4756 particular active (enclosing) @code{DO} loop are to be skipped.
4757
4758 @code{CYCLE} specifies that these statements are skipped,
4759 but the @code{END DO} statement that marks the end of the
4760 @code{DO} loop be executed---that is, the next iteration,
4761 if any, is to be started.
4762 If the statement marking the end of the @code{DO} loop is
4763 not @code{END DO}---in other words, if the loop is not
4764 a block @code{DO}---the @code{CYCLE} statement does not
4765 execute that statement, but does start the next iteration (if any).
4766
4767 @code{EXIT} specifies that the loop specified by the
4768 @code{DO} construct is terminated.
4769
4770 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
4771 is the innermost enclosing @code{DO} loop when the following
4772 forms are used:
4773
4774 @example
4775 CYCLE
4776 EXIT
4777 @end example
4778
4779 Otherwise, the following forms specify the construct name
4780 of the pertinent @code{DO} loop:
4781
4782 @example
4783 CYCLE @var{construct-name}
4784 EXIT @var{construct-name}
4785 @end example
4786
4787 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
4788 statements.
4789 However, they cannot be easily thought of as @code{GO TO} statements
4790 in obscure cases involving FORTRAN 77 loops.
4791 For example:
4792
4793 @smallexample
4794       DO 10 I = 1, 5
4795       DO 10 J = 1, 5
4796          IF (J .EQ. 5) EXIT
4797       DO 10 K = 1, 5
4798          IF (K .EQ. 3) CYCLE
4799 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
4800 20    CONTINUE
4801 @end smallexample
4802
4803 @noindent
4804 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
4805 above are equivalent to a @code{GO TO} statement to either label
4806 @samp{10} or @samp{20}.
4807
4808 To understand the effect of @code{CYCLE} and @code{EXIT} in the
4809 above fragment, it is helpful to first translate it to its equivalent
4810 using only block @code{DO} loops:
4811
4812 @smallexample
4813       DO I = 1, 5
4814          DO J = 1, 5
4815             IF (J .EQ. 5) EXIT
4816             DO K = 1, 5
4817                IF (K .EQ. 3) CYCLE
4818 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
4819             END DO
4820          END DO
4821       END DO
4822 20    CONTINUE
4823 @end smallexample
4824
4825 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
4826 to @code{GO TO} so they may be more easily understood by programmers
4827 accustomed to FORTRAN coding:
4828
4829 @smallexample
4830       DO I = 1, 5
4831          DO J = 1, 5
4832             IF (J .EQ. 5) GOTO 18
4833             DO K = 1, 5
4834                IF (K .EQ. 3) GO TO 12
4835 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
4836 12          END DO
4837          END DO
4838 18    END DO
4839 20    CONTINUE
4840 @end smallexample
4841
4842 @noindent
4843 Thus, the @code{CYCLE} statement in the innermost loop skips over
4844 the @code{PRINT} statement as it begins the next iteration of the
4845 loop, while the @code{EXIT} statement in the middle loop ends that
4846 loop but @emph{not} the outermost loop.
4847
4848 @node Functions and Subroutines
4849 @section Functions and Subroutines
4850
4851 (The following information augments or overrides the information in
4852 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4853 language.
4854 Chapter 15 of that document otherwise serves as the basis
4855 for the relevant aspects of GNU Fortran.)
4856
4857 @menu
4858 * %VAL()::
4859 * %REF()::
4860 * %DESCR()::
4861 * Generics and Specifics::
4862 * REAL() and AIMAG() of Complex::
4863 * CMPLX() of DOUBLE PRECISION::
4864 * MIL-STD 1753::
4865 * f77/f2c Intrinsics::
4866 * Table of Intrinsic Functions::
4867 @end menu
4868
4869 @node %VAL()
4870 @subsection The @code{%VAL()} Construct
4871 @cindex %VAL() construct
4872
4873 @example
4874 %VAL(@var{arg})
4875 @end example
4876
4877 The @code{%VAL()} construct specifies that an argument,
4878 @var{arg}, is to be passed by value, instead of by reference
4879 or descriptor.
4880
4881 @code{%VAL()} is restricted to actual arguments in
4882 invocations of external procedures.
4883
4884 Use of @code{%VAL()} is recommended only for code that
4885 is accessing facilities outside of GNU Fortran, such as
4886 operating system or windowing facilities.
4887 It is best to constrain such uses to isolated portions of
4888 a program---portions the deal specifically and exclusively
4889 with low-level, system-dependent facilities.
4890 Such portions might well provide a portable interface for
4891 use by the program as a whole, but are themselves not
4892 portable, and should be thoroughly tested each time they
4893 are rebuilt using a new compiler or version of a compiler.
4894
4895 @emph{Implementation Note:} Currently, @code{g77} passes
4896 all arguments either by reference or by descriptor.
4897
4898 Thus, use of @code{%VAL()} tends to be restricted to cases
4899 where the called procedure is written in a language other
4900 than Fortran that supports call-by-value semantics.
4901 (C is an example of such a language.)
4902
4903 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
4904 for detailed information on
4905 how this particular version of @code{g77} passes arguments
4906 to procedures.
4907
4908 @node %REF()
4909 @subsection The @code{%REF()} Construct
4910 @cindex %REF() construct
4911
4912 @example
4913 %REF(@var{arg})
4914 @end example
4915
4916 The @code{%REF()} construct specifies that an argument,
4917 @var{arg}, is to be passed by reference, instead of by
4918 value or descriptor.
4919
4920 @code{%REF()} is restricted to actual arguments in
4921 invocations of external procedures.
4922
4923 Use of @code{%REF()} is recommended only for code that
4924 is accessing facilities outside of GNU Fortran, such as
4925 operating system or windowing facilities.
4926 It is best to constrain such uses to isolated portions of
4927 a program---portions the deal specifically and exclusively
4928 with low-level, system-dependent facilities.
4929 Such portions might well provide a portable interface for
4930 use by the program as a whole, but are themselves not
4931 portable, and should be thoroughly tested each time they
4932 are rebuilt using a new compiler or version of a compiler.
4933
4934 Do not depend on @code{%REF()} supplying a pointer to the
4935 procedure being invoked.
4936 While that is a likely implementation choice, other
4937 implementation choices are available that preserve Fortran
4938 pass-by-reference semantics without passing a pointer to
4939 the argument, @var{arg}.
4940 (For example, a copy-in/copy-out implementation.)
4941
4942 @emph{Implementation Note:} Currently, @code{g77} passes
4943 all arguments
4944 (other than variables and arrays of type @code{CHARACTER})
4945 by reference.
4946 Future versions of, or dialects supported by, @code{g77} might
4947 not pass @code{CHARACTER} functions by reference.
4948
4949 Thus, use of @code{%REF()} tends to be restricted to cases
4950 where @var{arg} is type @code{CHARACTER} but the called
4951 procedure accesses it via a means other than the method
4952 used for Fortran @code{CHARACTER} arguments.
4953
4954 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
4955 how this particular version of @code{g77} passes arguments
4956 to procedures.
4957
4958 @node %DESCR()
4959 @subsection The @code{%DESCR()} Construct
4960 @cindex %DESCR() construct
4961
4962 @example
4963 %DESCR(@var{arg})
4964 @end example
4965
4966 The @code{%DESCR()} construct specifies that an argument,
4967 @var{arg}, is to be passed by descriptor, instead of by
4968 value or reference.
4969
4970 @code{%DESCR()} is restricted to actual arguments in
4971 invocations of external procedures.
4972
4973 Use of @code{%DESCR()} is recommended only for code that
4974 is accessing facilities outside of GNU Fortran, such as
4975 operating system or windowing facilities.
4976 It is best to constrain such uses to isolated portions of
4977 a program---portions the deal specifically and exclusively
4978 with low-level, system-dependent facilities.
4979 Such portions might well provide a portable interface for
4980 use by the program as a whole, but are themselves not
4981 portable, and should be thoroughly tested each time they
4982 are rebuilt using a new compiler or version of a compiler.
4983
4984 Do not depend on @code{%DESCR()} supplying a pointer
4985 and/or a length passed by value
4986 to the procedure being invoked.
4987 While that is a likely implementation choice, other
4988 implementation choices are available that preserve the
4989 pass-by-reference semantics without passing a pointer to
4990 the argument, @var{arg}.
4991 (For example, a copy-in/copy-out implementation.)
4992 And, future versions of @code{g77} might change the
4993 way descriptors are implemented, such as passing a
4994 single argument pointing to a record containing the
4995 pointer/length information instead of passing that same
4996 information via two arguments as it currently does.
4997
4998 @emph{Implementation Note:} Currently, @code{g77} passes
4999 all variables and arrays of type @code{CHARACTER}
5000 by descriptor.
5001 Future versions of, or dialects supported by, @code{g77} might
5002 pass @code{CHARACTER} functions by descriptor as well.
5003
5004 Thus, use of @code{%DESCR()} tends to be restricted to cases
5005 where @var{arg} is not type @code{CHARACTER} but the called
5006 procedure accesses it via a means similar to the method
5007 used for Fortran @code{CHARACTER} arguments.
5008
5009 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5010 how this particular version of @code{g77} passes arguments
5011 to procedures.
5012
5013 @node Generics and Specifics
5014 @subsection Generics and Specifics
5015 @cindex generic intrinsics
5016 @cindex intrinsics, generic
5017
5018 The ANSI FORTRAN 77 language defines generic and specific
5019 intrinsics.
5020 In short, the distinctions are:
5021
5022 @itemize @bullet
5023 @item
5024 @emph{Specific} intrinsics have
5025 specific types for their arguments and a specific return
5026 type.
5027
5028 @item
5029 @emph{Generic} intrinsics are treated,
5030 on a case-by-case basis in the program's source code,
5031 as one of several possible specific intrinsics.
5032
5033 Typically, a generic intrinsic has a return type that
5034 is determined by the type of one or more of its arguments.
5035 @end itemize
5036
5037 The GNU Fortran language generalizes these concepts somewhat,
5038 especially by providing intrinsic subroutines and generic
5039 intrinsics that are treated as either a specific intrinsic subroutine
5040 or a specific intrinsic function (e.g. @code{SECOND}).
5041
5042 However, GNU Fortran avoids generalizing this concept to
5043 the point where existing code would be accepted as meaning
5044 something possibly different than what was intended.
5045
5046 For example, @code{ABS} is a generic intrinsic, so all working
5047 code written using @code{ABS} of an @code{INTEGER} argument
5048 expects an @code{INTEGER} return value.
5049 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
5050 argument returns an @code{INTEGER*2} return value.
5051
5052 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
5053 an @code{INTEGER(KIND=1)} argument.
5054 Code that passes something other than an @code{INTEGER(KIND=1)}
5055 argument to @code{IABS} is not valid GNU Fortran code, because
5056 it is not clear what the author intended.
5057
5058 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
5059 is not defined by the GNU Fortran language, because the programmer
5060 might have used that construct to mean any of the following, subtly
5061 different, things:
5062
5063 @itemize @bullet
5064 @item
5065 Convert @samp{J} to @code{INTEGER(KIND=1)} first
5066 (as if @samp{IABS(INT(J))} had been written).
5067
5068 @item
5069 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
5070 (as if @samp{INT(ABS(J))} had been written).
5071
5072 @item
5073 No conversion (as if @samp{ABS(J)} had been written).
5074 @end itemize
5075
5076 The distinctions matter especially when types and values wider than
5077 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
5078 operations performing more ``arithmetic'' than absolute-value, are involved.
5079
5080 The following sample program is not a valid GNU Fortran program, but
5081 might be accepted by other compilers.
5082 If so, the output is likely to be revealing in terms of how a given
5083 compiler treats intrinsics (that normally are specific) when they
5084 are given arguments that do not conform to their stated requirements:
5085
5086 @cindex JCB002 program
5087 @smallexample
5088       PROGRAM JCB002
5089 C Version 1:
5090 C Modified 1999-02-15 (Burley) to delete my email address.
5091 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
5092 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
5093 C
5094 C Version 0:
5095 C Written by James Craig Burley 1997-02-20.
5096 C
5097 C Purpose:
5098 C Determine how compilers handle non-standard IDIM
5099 C on INTEGER*2 operands, which presumably can be
5100 C extrapolated into understanding how the compiler
5101 C generally treats specific intrinsics that are passed
5102 C arguments not of the correct types.
5103 C
5104 C If your compiler implements INTEGER*2 and INTEGER
5105 C as the same type, change all INTEGER*2 below to
5106 C INTEGER*1.
5107 C
5108       INTEGER*2 I0, I4
5109       INTEGER I1, I2, I3
5110       INTEGER*2 ISMALL, ILARGE
5111       INTEGER*2 ITOOLG, ITWO
5112       INTEGER*2 ITMP
5113       LOGICAL L2, L3, L4
5114 C
5115 C Find smallest INTEGER*2 number.
5116 C
5117       ISMALL=0
5118  10   I0 = ISMALL-1
5119       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
5120       ISMALL = I0
5121       GOTO 10
5122  20   CONTINUE
5123 C
5124 C Find largest INTEGER*2 number.
5125 C
5126       ILARGE=0
5127  30   I0 = ILARGE+1
5128       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
5129       ILARGE = I0
5130       GOTO 30
5131  40   CONTINUE
5132 C
5133 C Multiplying by two adds stress to the situation.
5134 C
5135       ITWO = 2
5136 C
5137 C Need a number that, added to -2, is too wide to fit in I*2.
5138 C
5139       ITOOLG = ISMALL
5140 C
5141 C Use IDIM the straightforward way.
5142 C
5143       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
5144 C
5145 C Calculate result for first interpretation.
5146 C
5147       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
5148 C
5149 C Calculate result for second interpretation.
5150 C
5151       ITMP = ILARGE - ISMALL
5152       I3 = (INT (ITMP)) * ITWO + ITOOLG
5153 C
5154 C Calculate result for third interpretation.
5155 C
5156       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
5157 C
5158 C Print results.
5159 C
5160       PRINT *, 'ILARGE=', ILARGE
5161       PRINT *, 'ITWO=', ITWO
5162       PRINT *, 'ITOOLG=', ITOOLG
5163       PRINT *, 'ISMALL=', ISMALL
5164       PRINT *, 'I1=', I1
5165       PRINT *, 'I2=', I2
5166       PRINT *, 'I3=', I3
5167       PRINT *, 'I4=', I4
5168       PRINT *
5169       L2 = (I1 .EQ. I2)
5170       L3 = (I1 .EQ. I3)
5171       L4 = (I1 .EQ. I4)
5172       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
5173          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
5174          STOP
5175       END IF
5176       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
5177          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
5178          STOP
5179       END IF
5180       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
5181          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
5182          STOP
5183       END IF
5184       PRINT *, 'Results need careful analysis.'
5185       END
5186 @end smallexample
5187
5188 No future version of the GNU Fortran language
5189 will likely permit specific intrinsic invocations with wrong-typed
5190 arguments (such as @code{IDIM} in the above example), since
5191 it has been determined that disagreements exist among
5192 many production compilers on the interpretation of
5193 such invocations.
5194 These disagreements strongly suggest that Fortran programmers,
5195 and certainly existing Fortran programs, disagree about the
5196 meaning of such invocations.
5197
5198 The first version of @code{JCB002} didn't accommodate some compilers'
5199 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
5200 @code{INTEGER*2}.
5201 In such a case, these compilers apparently convert both
5202 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
5203 instead of doing an @code{INTEGER*2} subtraction on the
5204 original values in @samp{I1} and @samp{I2}.
5205
5206 However, the results of the careful analyses done on the outputs
5207 of programs compiled by these various compilers show that they
5208 all implement either @samp{Interp 1} or @samp{Interp 2} above.
5209
5210 Specifically, it is believed that the new version of @code{JCB002}
5211 above will confirm that:
5212
5213 @itemize @bullet
5214 @item
5215 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
5216 @code{f77} compilers all implement @samp{Interp 1}.
5217
5218 @item
5219 IRIX 5.3 @code{f77} compiler implements @samp{Interp 2}.
5220
5221 @item
5222 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
5223 and IRIX 6.1 @code{f77} compilers all implement @samp{Interp 3}.
5224 @end itemize
5225
5226 If you get different results than the above for the stated
5227 compilers, or have results for other compilers that might be
5228 worth adding to the above list, please let us know the details
5229 (compiler product, version, machine, results, and so on).
5230
5231 @node REAL() and AIMAG() of Complex
5232 @subsection @code{REAL()} and @code{AIMAG()} of Complex
5233 @cindex @code{Real} intrinsic
5234 @cindex intrinsics, @code{Real}
5235 @cindex @code{AImag} intrinsic
5236 @cindex intrinsics, @code{AImag}
5237
5238 The GNU Fortran language disallows @code{REAL(@var{expr})}
5239 and @code{AIMAG(@var{expr})},
5240 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
5241 except when they are used in the following way:
5242
5243 @example
5244 REAL(REAL(@var{expr}))
5245 REAL(AIMAG(@var{expr}))
5246 @end example
5247
5248 @noindent
5249 The above forms explicitly specify that the desired effect
5250 is to convert the real or imaginary part of @var{expr}, which might
5251 be some @code{REAL} type other than @code{REAL(KIND=1)},
5252 to type @code{REAL(KIND=1)},
5253 and have that serve as the value of the expression.
5254
5255 The GNU Fortran language offers clearly named intrinsics to extract the
5256 real and imaginary parts of a complex entity without any
5257 conversion:
5258
5259 @example
5260 REALPART(@var{expr})
5261 IMAGPART(@var{expr})
5262 @end example
5263
5264 To express the above using typical extended FORTRAN 77,
5265 use the following constructs
5266 (when @var{expr} is @code{COMPLEX(KIND=2)}):
5267
5268 @example
5269 DBLE(@var{expr})
5270 DIMAG(@var{expr})
5271 @end example
5272
5273 The FORTRAN 77 language offers no way
5274 to explicitly specify the real and imaginary parts of a complex expression of
5275 arbitrary type, apparently as a result of requiring support for
5276 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
5277 The concepts of converting an expression to type @code{REAL(KIND=1)} and
5278 of extracting the real part of a complex expression were
5279 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
5280 they happened to have the exact same effect in that language
5281 (due to having only one @code{COMPLEX} type).
5282
5283 @emph{Note:} When @samp{-ff90} is in effect,
5284 @code{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
5285 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
5286 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
5287 treated as @samp{REAL(REALPART(@var{expr}))}.
5288
5289 @xref{Ugly Complex Part Extraction}, for more information.
5290
5291 @node CMPLX() of DOUBLE PRECISION
5292 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
5293 @cindex @code{Cmplx} intrinsic
5294 @cindex intrinsics, @code{Cmplx}
5295
5296 In accordance with Fortran 90 and at least some (perhaps all)
5297 other compilers, the GNU Fortran language defines @code{CMPLX()}
5298 as always returning a result that is type @code{COMPLEX(KIND=1)}.
5299
5300 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
5301 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
5302
5303 @example
5304 CMPLX(SNGL(D1), SNGL(D2))
5305 @end example
5306
5307 (It was necessary for Fortran 90 to specify this behavior
5308 for @code{DOUBLE PRECISION} arguments, since that is
5309 the behavior mandated by FORTRAN 77.)
5310
5311 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
5312 which is provided by some FORTRAN 77 compilers to construct
5313 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
5314 operands.
5315 However, this solution does not scale well when more @code{COMPLEX} types
5316 (having various precisions and ranges) are offered by Fortran implementations.
5317
5318 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
5319 an extra argument used to specify the desired kind of complex
5320 result.
5321 However, this solution is somewhat awkward to use, and
5322 @code{g77} currently does not support it.
5323
5324 The GNU Fortran language provides a simple way to build a complex
5325 value out of two numbers, with the precise type of the value
5326 determined by the types of the two numbers (via the usual
5327 type-promotion mechanism):
5328
5329 @example
5330 COMPLEX(@var{real}, @var{imag})
5331 @end example
5332
5333 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
5334 performs no conversion other than to put them together to form a
5335 complex result of the same (complex version of real) type.
5336
5337 @xref{Complex Intrinsic}, for more information.
5338
5339 @node MIL-STD 1753
5340 @subsection MIL-STD 1753 Support
5341 @cindex MIL-STD 1753
5342
5343 The GNU Fortran language includes the MIL-STD 1753 intrinsics
5344 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
5345 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
5346 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
5347
5348 @node f77/f2c Intrinsics
5349 @subsection @code{f77}/@code{f2c} Intrinsics
5350
5351 The bit-manipulation intrinsics supported by traditional
5352 @code{f77} and by @code{f2c} are available in the GNU Fortran language.
5353 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
5354 and @code{XOR}.
5355
5356 Also supported are the intrinsics @code{CDABS},
5357 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
5358 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
5359 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
5360 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
5361 and @code{ZSQRT}.
5362
5363 @node Table of Intrinsic Functions
5364 @subsection Table of Intrinsic Functions
5365 @cindex intrinsics, table of
5366 @cindex table of intrinsics
5367
5368 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
5369
5370 The GNU Fortran language adds various functions, subroutines, types,
5371 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
5372 The complete set of intrinsics supported by the GNU Fortran language
5373 is described below.
5374
5375 Note that a name is not treated as that of an intrinsic if it is
5376 specified in an @code{EXTERNAL} statement in the same program unit;
5377 if a command-line option is used to disable the groups to which
5378 the intrinsic belongs; or if the intrinsic is not named in an
5379 @code{INTRINSIC} statement and a command-line option is used to
5380 hide the groups to which the intrinsic belongs.
5381
5382 So, it is recommended that any reference in a program unit to
5383 an intrinsic procedure that is not a standard FORTRAN 77
5384 intrinsic be accompanied by an appropriate @code{INTRINSIC}
5385 statement in that program unit.
5386 This sort of defensive programming makes it more
5387 likely that an implementation will issue a diagnostic rather
5388 than generate incorrect code for such a reference.
5389
5390 The terminology used below is based on that of the Fortran 90
5391 standard, so that the text may be more concise and accurate:
5392
5393 @itemize @bullet
5394 @item
5395 @code{OPTIONAL} means the argument may be omitted.
5396
5397 @item
5398 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
5399 (generally named @samp{A}) may be specified.
5400
5401 @item
5402 @samp{scalar} means the argument must not be an array (must
5403 be a variable or array element, or perhaps a constant if expressions
5404 are permitted).
5405
5406 @item
5407 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
5408
5409 @item
5410 @code{INTENT(IN)} means the argument must be an expression
5411 (such as a constant or a variable that is defined upon invocation
5412 of the intrinsic).
5413
5414 @item
5415 @code{INTENT(OUT)} means the argument must be definable by the
5416 invocation of the intrinsic (that is, must not be a constant nor
5417 an expression involving operators other than array reference and
5418 substring reference).
5419
5420 @item
5421 @code{INTENT(INOUT)} means the argument must be defined prior to,
5422 and definable by, invocation of the intrinsic (a combination of
5423 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
5424
5425 @item
5426 @xref{Kind Notation}, for an explanation of @code{KIND}.
5427 @end itemize
5428
5429 @ifinfo
5430 (Note that the empty lines appearing in the menu below
5431 are not intentional---they result from a bug in the
5432 GNU @code{makeinfo} program@dots{}a program that, if it
5433 did not exist, would leave this document in far worse shape!)
5434 @end ifinfo
5435
5436 @c The actual documentation for intrinsics comes from
5437 @c intdoc.texi, which in turn is automatically generated
5438 @c from the internal g77 tables in intrin.def _and_ the
5439 @c largely hand-written text in intdoc.h.  So, if you want
5440 @c to change or add to existing documentation on intrinsics,
5441 @c you probably want to edit intdoc.h.
5442 @c
5443 @set familyF77
5444 @set familyGNU
5445 @set familyASC
5446 @set familyMIL
5447 @set familyF90
5448 @clear familyVXT
5449 @clear familyFVZ
5450 @set familyF2C
5451 @set familyF2U
5452 @clear familyBADU77
5453 @include intdoc.texi
5454
5455 @node Scope and Classes of Names
5456 @section Scope and Classes of Symbolic Names
5457 @cindex symbol names, scope and classes
5458 @cindex scope
5459
5460 (The following information augments or overrides the information in
5461 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5462 language.
5463 Chapter 18 of that document otherwise serves as the basis
5464 for the relevant aspects of GNU Fortran.)
5465
5466 @menu
5467 * Underscores in Symbol Names::
5468 @end menu
5469
5470 @node Underscores in Symbol Names
5471 @subsection Underscores in Symbol Names
5472 @cindex underscore
5473
5474 Underscores (@samp{_}) are accepted in symbol names after the first
5475 character (which must be a letter).
5476
5477 @node I/O
5478 @section I/O
5479
5480 @cindex dollar sign
5481 A dollar sign at the end of an output format specification suppresses
5482 the newline at the end of the output.
5483
5484 @cindex <> edit descriptor
5485 @cindex edit descriptor, <>
5486 Edit descriptors in @code{FORMAT} statements may contain compile-time
5487 @code{INTEGER} constant expressions in angle brackets, such as
5488 @smallexample
5489 10    FORMAT (I<WIDTH>)
5490 @end smallexample
5491
5492 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
5493
5494 These Fortran 90 features are supported:
5495 @itemize @bullet
5496 @item
5497 @cindex FORMAT descriptors
5498 @cindex Z edit descriptor
5499 @cindex edit descriptor, Z
5500 @cindex O edit descriptor
5501 @cindex edit descriptor, O
5502 The @code{O} and @code{Z} edit descriptors are supported for I/O of
5503 integers in octal and hexadecimal formats, respectively.
5504 @item
5505 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
5506 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
5507 specifier is supported.
5508 @end itemize
5509
5510 @node Fortran 90 Features
5511 @section Fortran 90 Features
5512 @cindex Fortran 90
5513 @cindex extensions, from Fortran 90
5514
5515 For convenience this section collects a list (probably incomplete) of
5516 the Fortran 90 features supported by the GNU Fortran language, even if
5517 they are documented elsewhere.
5518 @xref{Characters Lines Sequence,,@asis{Characters, Lines, and Execution Sequence}},
5519 for information on additional fixed source form lexical issues.
5520 @cindex @samp{-ffree-form}
5521 Further, the free source form is supported through the
5522 @samp{-ffree-form} option.
5523 @cindex @samp{-ff90}
5524 Other Fortran 90 features can be turned on by the @samp{-ff90} option;
5525 see @ref{Fortran 90}.
5526 For information on the Fortran 90 intrinsics available,
5527 see @ref{Table of Intrinsic Functions}.
5528
5529 @table @asis
5530 @item Automatic arrays in procedures
5531 @item Character assignments
5532 @cindex character assignments
5533 In character assignments, the variable being assigned may occur on the
5534 right hand side of the assignment.
5535 @item Character strings
5536 @cindex double quoted character constants
5537 Strings may have zero length and substrings of character constants are
5538 permitted.  Character constants may be enclosed in double quotes
5539 (@code{"}) as well as single quotes.  @xref{Character Type}.
5540 @item Construct names
5541 (Symbolic tags on blocks.)  @xref{Construct Names}.
5542 @item @code{CYCLE} and @code{EXIT}
5543 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
5544 @item @code{DOUBLE COMPLEX}
5545 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement}.
5546 @item @code{DO WHILE}
5547 @xref{DO WHILE}.
5548 @item @code{END} decoration
5549 @xref{Statements}.
5550 @item @code{END DO}
5551 @xref{END DO}.
5552 @item @code{KIND}
5553 @item @code{IMPLICIT NONE}
5554 @item @code{INCLUDE} statements
5555 @xref{INCLUDE}.
5556 @item List-directed and namelist I/O on internal files
5557 @item Binary, octal and hexadecimal constants
5558 These are supported more generally than required by Fortran 90.
5559 @xref{Integer Type}.
5560 @item @samp{O} and @samp{Z} edit descriptors
5561 @item @code{NAMELIST}
5562 @xref{NAMELIST}.
5563 @item @code{OPEN} specifiers
5564 @code{STATUS='REPLACE'} is supported.
5565 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
5566 @code{STATUS='SCRATCH'} is supplied.
5567 @item @code{FORMAT} edit descriptors
5568 @cindex FORMAT descriptors
5569 @cindex Z edit descriptor
5570 @cindex edit descriptor, Z
5571 The @code{Z} edit descriptor is supported.
5572 @item Relational operators
5573 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
5574 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
5575 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
5576 @item @code{SELECT CASE}
5577 Not fully implemented.
5578 @xref{SELECT CASE on CHARACTER Type,, @code{SELECT CASE} on @code{CHARACTER} Type}.
5579 @item Specification statements
5580 A limited subset of the Fortran 90 syntax and semantics for variable
5581 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
5582 (@code{KIND} is of limited usefulness in the absence of the
5583 @code{KIND}-related intrinsics, since these intrinsics permit writing
5584 more widely portable code.)  An example of supported @code{KIND} usage
5585 is:
5586 @smallexample
5587 INTEGER (KIND=1) :: FOO=1, BAR=2
5588 CHARACTER (LEN=3) FOO
5589 @end smallexample
5590 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
5591 @end table
5592
5593 @node Other Dialects
5594 @chapter Other Dialects
5595
5596 GNU Fortran supports a variety of features that are not
5597 considered part of the GNU Fortran language itself, but
5598 are representative of various dialects of Fortran that
5599 @code{g77} supports in whole or in part.
5600
5601 Any of the features listed below might be disallowed by
5602 @code{g77} unless some command-line option is specified.
5603 Currently, some of the features are accepted using the
5604 default invocation of @code{g77}, but that might change
5605 in the future.
5606
5607 @emph{Note: This portion of the documentation definitely needs a lot
5608 of work!}
5609
5610 @menu
5611 * Source Form::       Details of fixed-form and free-form source.
5612 * Trailing Comment::  Use of @samp{/*} to start a comment.
5613 * Debug Line::        Use of @samp{D} in column 1.
5614 * Dollar Signs::      Use of @samp{$} in symbolic names.
5615 * Case Sensitivity::  Uppercase and lowercase in source files.
5616 * VXT Fortran::       @dots{}versus the GNU Fortran language.
5617 * Fortran 90::        @dots{}versus the GNU Fortran language.
5618 * Pedantic Compilation::  Enforcing the standard.
5619 * Distensions::       Misfeatures supported by GNU Fortran.
5620 @end menu
5621
5622 @node Source Form
5623 @section Source Form
5624 @cindex source file format
5625 @cindex source format
5626 @cindex file, source
5627 @cindex source code
5628 @cindex code, source
5629 @cindex fixed form
5630 @cindex free form
5631
5632 GNU Fortran accepts programs written in either fixed form or
5633 free form.
5634
5635 Fixed form
5636 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
5637 allowing tabs) and Fortran 90's fixed form.
5638
5639 Free form corresponds to
5640 Fortran 90's free form (though possibly not entirely up-to-date, and
5641 without complaining about some things that for which Fortran 90 requires
5642 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
5643
5644 The way a Fortran compiler views source files depends entirely on the
5645 implementation choices made for the compiler, since those choices
5646 are explicitly left to the implementation by the published Fortran
5647 standards.
5648 GNU Fortran currently tries to be somewhat like a few popular compilers
5649 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
5650 definition along with more
5651 flexibility offered by command-line options is likely to be offered
5652 in version 0.6.
5653
5654 This section describes how @code{g77} interprets source lines.
5655
5656 @menu
5657 * Carriage Returns::  Carriage returns ignored.
5658 * Tabs::              Tabs converted to spaces.
5659 * Short Lines::       Short lines padded with spaces (fixed-form only).
5660 * Long Lines::        Long lines truncated.
5661 * Ampersands::        Special Continuation Lines.
5662 @end menu
5663
5664 @node Carriage Returns
5665 @subsection Carriage Returns
5666 @cindex carriage returns
5667
5668 Carriage returns (@samp{\r}) in source lines are ignored.
5669 This is somewhat different from @code{f2c}, which seems to treat them as
5670 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
5671 inside such constants.
5672
5673 @node Tabs
5674 @subsection Tabs
5675 @cindex tab character
5676 @cindex horizontal tab
5677
5678 A source line with a @key{TAB} character anywhere in it is treated as
5679 entirely significant---however long it is---instead of ending in
5680 column 72 (for fixed-form source) or 132 (for free-form source).
5681 This also is different from @code{f2c}, which encodes tabs as
5682 @samp{\t} (the ASCII @key{TAB} character) inside character
5683 and Hollerith constants, but nevertheless seems to treat the column
5684 position as if it had been affected by the canonical tab positioning.
5685
5686 @code{g77} effectively
5687 translates tabs to the appropriate number of spaces (a la the default
5688 for the UNIX @code{expand} command) before doing any other processing, other
5689 than (currently) noting whether a tab was found on a line and using this
5690 information to decide how to interpret the length of the line and continued
5691 constants.
5692
5693 Note that this default behavior probably will change for version 0.6,
5694 when it will presumably be available via a command-line option.
5695 The default as of version 0.6 is planned to be a ``pure visual''
5696 model, where tabs are immediately
5697 converted to spaces and otherwise have no effect, so the way a typical
5698 user sees source lines produces a consistent result no matter how the
5699 spacing in those source lines is actually implemented via tabs, spaces,
5700 and trailing tabs/spaces before newline.
5701 Command-line options are likely to be added to specify whether all or
5702 just-tabbed lines are to be extended to 132 or full input-line length,
5703 and perhaps even an option will be added to specify the truncated-line
5704 behavior to which some Digital compilers default (and which affects
5705 the way continued character/Hollerith constants are interpreted).
5706
5707 @node Short Lines
5708 @subsection Short Lines
5709 @cindex short source lines
5710 @cindex space, padding with
5711 @cindex source lines, short
5712 @cindex lines, short
5713
5714 Source lines shorter than the applicable fixed-form length are treated as
5715 if they were padded with spaces to that length.
5716 (None of this is relevant to source files written in free form.)
5717
5718 This affects only
5719 continued character and Hollerith constants, and is a different
5720 interpretation than provided by some other popular compilers
5721 (although a bit more consistent with the traditional punched-card
5722 basis of Fortran and the way the Fortran standard expressed fixed
5723 source form).
5724
5725 @code{g77} might someday offer an option to warn about cases where differences
5726 might be seen as a result of this treatment, and perhaps an option to
5727 specify the alternate behavior as well.
5728
5729 Note that this padding cannot apply to lines that are effectively of
5730 infinite length---such lines are specified using command-line options
5731 like @samp{-ffixed-line-length-none}, for example.
5732
5733 @node Long Lines
5734 @subsection Long Lines
5735 @cindex long source lines
5736 @cindex truncation, of long lines
5737 @cindex lines, long
5738 @cindex source lines, long
5739
5740 Source lines longer than the applicable length are truncated to that
5741 length.
5742 Currently, @code{g77} does not warn if the truncated characters are
5743 not spaces, to accommodate existing code written for systems that
5744 treated truncated text as commentary (especially in columns 73 through 80).
5745
5746 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
5747 for information on the @samp{-ffixed-line-length-@var{n}} option,
5748 which can be used to set the line length applicable to fixed-form
5749 source files.
5750
5751 @node Ampersands
5752 @subsection Ampersand Continuation Line
5753 @cindex ampersand continuation line
5754 @cindex continuation line, ampersand
5755
5756 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
5757 continuation line, imitating the behavior of @code{f2c}.
5758
5759 @node Trailing Comment
5760 @section Trailing Comment
5761
5762 @cindex trailing comment
5763 @cindex comment
5764 @cindex characters, comment
5765 @cindex /*
5766 @cindex !
5767 @cindex exclamation point
5768 @code{g77} supports use of @samp{/*} to start a trailing
5769 comment.
5770 In the GNU Fortran language, @samp{!} is used for this purpose.
5771
5772 @samp{/*} is not in the GNU Fortran language
5773 because the use of @samp{/*} in a program might
5774 suggest to some readers that a block, not trailing, comment is
5775 started (and thus ended by @samp{*/}, not end of line),
5776 since that is the meaning of @samp{/*} in C.
5777
5778 Also, such readers might think they can use @samp{//} to start
5779 a trailing comment as an alternative to @samp{/*}, but
5780 @samp{//} already denotes concatenation, and such a ``comment''
5781 might actually result in a program that compiles without
5782 error (though it would likely behave incorrectly).
5783
5784 @node Debug Line
5785 @section Debug Line
5786 @cindex debug line
5787 @cindex comment line, debug
5788
5789 Use of @samp{D} or @samp{d} as the first character (column 1) of
5790 a source line denotes a debug line.
5791
5792 In turn, a debug line is treated as either a comment line
5793 or a normal line, depending on whether debug lines are enabled.
5794
5795 When treated as a comment line, a line beginning with @samp{D} or
5796 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
5797 When treated as a normal line, such a line is treated as if
5798 the first character was @key{SPC} (space).
5799
5800 (Currently, @code{g77} provides no means for treating debug
5801 lines as normal lines.)
5802
5803 @node Dollar Signs
5804 @section Dollar Signs in Symbol Names
5805 @cindex dollar sign
5806 @cindex $
5807
5808 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
5809 when the @samp{-fdollar-ok} option is specified.
5810
5811 @node Case Sensitivity
5812 @section Case Sensitivity
5813 @cindex case sensitivity
5814 @cindex source file format
5815 @cindex code, source
5816 @cindex source code
5817 @cindex uppercase letters
5818 @cindex lowercase letters
5819 @cindex letters, uppercase
5820 @cindex letters, lowercase
5821
5822 GNU Fortran offers the programmer way too much flexibility in deciding
5823 how source files are to be treated vis-a-vis uppercase and lowercase
5824 characters.
5825 There are 66 useful settings that affect case sensitivity, plus 10
5826 settings that are nearly useless, with the remaining 116 settings
5827 being either redundant or useless.
5828
5829 None of these settings have any effect on the contents of comments
5830 (the text after a @samp{c} or @samp{C} in Column 1, for example)
5831 or of character or Hollerith constants.
5832 Note that things like the @samp{E} in the statement
5833 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
5834 are considered built-in keywords, and so are affected by
5835 these settings.
5836
5837 Low-level switches are identified in this section as follows:
5838
5839 @itemize @w{}
5840 @item A
5841 Source Case Conversion:
5842
5843 @itemize @w{}
5844 @item 0
5845 Preserve (see Note 1)
5846 @item 1
5847 Convert to Upper Case
5848 @item 2
5849 Convert to Lower Case
5850 @end itemize
5851
5852 @item B
5853 Built-in Keyword Matching:
5854
5855 @itemize @w{}
5856 @item 0
5857 Match Any Case (per-character basis)
5858 @item 1
5859 Match Upper Case Only
5860 @item 2
5861 Match Lower Case Only
5862 @item 3
5863 Match InitialCaps Only (see tables for spellings)
5864 @end itemize
5865
5866 @item C
5867 Built-in Intrinsic Matching:
5868
5869 @itemize @w{}
5870 @item 0
5871 Match Any Case (per-character basis)
5872 @item 1
5873 Match Upper Case Only
5874 @item 2
5875 Match Lower Case Only
5876 @item 3
5877 Match InitialCaps Only (see tables for spellings)
5878 @end itemize
5879
5880 @item D
5881 User-defined Symbol Possibilities (warnings only):
5882
5883 @itemize @w{}
5884 @item 0
5885 Allow Any Case (per-character basis)
5886 @item 1
5887 Allow Upper Case Only
5888 @item 2
5889 Allow Lower Case Only
5890 @item 3
5891 Allow InitialCaps Only (see Note 2)
5892 @end itemize
5893 @end itemize
5894
5895 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
5896 consistent with these source switches---in the sense that input will be
5897 expected to meet the same requirements as source code in terms
5898 of matching symbol names and keywords (for the exponent letters).
5899
5900 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
5901 which uppercases @code{NAMELIST} input and symbol names for matching.
5902 This means not only that @code{NAMELIST} output currently shows symbol
5903 (and keyword) names in uppercase even if lower-case source
5904 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
5905 adequately supported when source case preservation (option A0)
5906 is selected.
5907
5908 If A0 is selected, a warning message will be
5909 output for each @code{NAMELIST} statement to this effect.
5910 The behavior
5911 of the program is undefined at run time if two or more symbol names
5912 appear in a given @code{NAMELIST} such that the names are identical
5913 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
5914 For complete and total elegance, perhaps there should be a warning
5915 when option A2 is selected, since the output of NAMELIST is currently
5916 in uppercase but will someday be lowercase (when a @code{libg77} is written),
5917 but that seems to be overkill for a product in beta test.
5918
5919 Note 2: Rules for InitialCaps names are:
5920
5921 @itemize @minus
5922 @item
5923 Must be a single uppercase letter, @strong{or}
5924 @item
5925 Must start with an uppercase letter and contain at least one
5926 lowercase letter.
5927 @end itemize
5928
5929 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
5930 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
5931 not.
5932 Note that most, but not all, built-in names meet these
5933 requirements---the exceptions are some of the two-letter format
5934 specifiers, such as @code{BN} and @code{BZ}.
5935
5936 Here are the names of the corresponding command-line options:
5937
5938 @smallexample
5939 A0: -fsource-case-preserve
5940 A1: -fsource-case-upper
5941 A2: -fsource-case-lower
5942
5943 B0: -fmatch-case-any
5944 B1: -fmatch-case-upper
5945 B2: -fmatch-case-lower
5946 B3: -fmatch-case-initcap
5947
5948 C0: -fintrin-case-any
5949 C1: -fintrin-case-upper
5950 C2: -fintrin-case-lower
5951 C3: -fintrin-case-initcap
5952
5953 D0: -fsymbol-case-any
5954 D1: -fsymbol-case-upper
5955 D2: -fsymbol-case-lower
5956 D3: -fsymbol-case-initcap
5957 @end smallexample
5958
5959 Useful combinations of the above settings, along with abbreviated
5960 option names that set some of these combinations all at once:
5961
5962 @smallexample
5963  1: A0--  B0---  C0---  D0---    -fcase-preserve
5964  2: A0--  B0---  C0---  D-1--
5965  3: A0--  B0---  C0---  D--2-
5966  4: A0--  B0---  C0---  D---3
5967  5: A0--  B0---  C-1--  D0---
5968  6: A0--  B0---  C-1--  D-1--
5969  7: A0--  B0---  C-1--  D--2-
5970  8: A0--  B0---  C-1--  D---3
5971  9: A0--  B0---  C--2-  D0---
5972 10: A0--  B0---  C--2-  D-1--
5973 11: A0--  B0---  C--2-  D--2-
5974 12: A0--  B0---  C--2-  D---3
5975 13: A0--  B0---  C---3  D0---
5976 14: A0--  B0---  C---3  D-1--
5977 15: A0--  B0---  C---3  D--2-
5978 16: A0--  B0---  C---3  D---3
5979 17: A0--  B-1--  C0---  D0---
5980 18: A0--  B-1--  C0---  D-1--
5981 19: A0--  B-1--  C0---  D--2-
5982 20: A0--  B-1--  C0---  D---3
5983 21: A0--  B-1--  C-1--  D0---
5984 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
5985 23: A0--  B-1--  C-1--  D--2-
5986 24: A0--  B-1--  C-1--  D---3
5987 25: A0--  B-1--  C--2-  D0---
5988 26: A0--  B-1--  C--2-  D-1--
5989 27: A0--  B-1--  C--2-  D--2-
5990 28: A0--  B-1--  C--2-  D---3
5991 29: A0--  B-1--  C---3  D0---
5992 30: A0--  B-1--  C---3  D-1--
5993 31: A0--  B-1--  C---3  D--2-
5994 32: A0--  B-1--  C---3  D---3
5995 33: A0--  B--2-  C0---  D0---
5996 34: A0--  B--2-  C0---  D-1--
5997 35: A0--  B--2-  C0---  D--2-
5998 36: A0--  B--2-  C0---  D---3
5999 37: A0--  B--2-  C-1--  D0---
6000 38: A0--  B--2-  C-1--  D-1--
6001 39: A0--  B--2-  C-1--  D--2-
6002 40: A0--  B--2-  C-1--  D---3
6003 41: A0--  B--2-  C--2-  D0---
6004 42: A0--  B--2-  C--2-  D-1--
6005 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
6006 44: A0--  B--2-  C--2-  D---3
6007 45: A0--  B--2-  C---3  D0---
6008 46: A0--  B--2-  C---3  D-1--
6009 47: A0--  B--2-  C---3  D--2-
6010 48: A0--  B--2-  C---3  D---3
6011 49: A0--  B---3  C0---  D0---
6012 50: A0--  B---3  C0---  D-1--
6013 51: A0--  B---3  C0---  D--2-
6014 52: A0--  B---3  C0---  D---3
6015 53: A0--  B---3  C-1--  D0---
6016 54: A0--  B---3  C-1--  D-1--
6017 55: A0--  B---3  C-1--  D--2-
6018 56: A0--  B---3  C-1--  D---3
6019 57: A0--  B---3  C--2-  D0---
6020 58: A0--  B---3  C--2-  D-1--
6021 59: A0--  B---3  C--2-  D--2-
6022 60: A0--  B---3  C--2-  D---3
6023 61: A0--  B---3  C---3  D0---
6024 62: A0--  B---3  C---3  D-1--
6025 63: A0--  B---3  C---3  D--2-
6026 64: A0--  B---3  C---3  D---3    -fcase-initcap
6027 65: A-1-  B01--  C01--  D01--    -fcase-upper
6028 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
6029 @end smallexample
6030
6031 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
6032 (except comments, character constants, and Hollerith strings) must
6033 be entered in uppercase.
6034 Use @samp{-fcase-strict-upper} to specify this
6035 combination.
6036
6037 Number 43 is like Number 22 except all input must be lowercase.  Use
6038 @samp{-fcase-strict-lower} to specify this combination.
6039
6040 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
6041 non-UNIX machines whereby all the source is translated to uppercase.
6042 Use @samp{-fcase-upper} to specify this combination.
6043
6044 Number 66 is the ``canonical'' UNIX model whereby all the source is
6045 translated to lowercase.
6046 Use @samp{-fcase-lower} to specify this combination.
6047
6048 There are a few nearly useless combinations:
6049
6050 @smallexample
6051 67: A-1-  B01--  C01--  D--2-
6052 68: A-1-  B01--  C01--  D---3
6053 69: A-1-  B01--  C--23  D01--
6054 70: A-1-  B01--  C--23  D--2-
6055 71: A-1-  B01--  C--23  D---3
6056 72: A--2  B01--  C0-2-  D-1--
6057 73: A--2  B01--  C0-2-  D---3
6058 74: A--2  B01--  C-1-3  D0-2-
6059 75: A--2  B01--  C-1-3  D-1--
6060 76: A--2  B01--  C-1-3  D---3
6061 @end smallexample
6062
6063 The above allow some programs to be compiled but with restrictions that
6064 make most useful programs impossible: Numbers 67 and 72 warn about
6065 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
6066 Numbers
6067 68 and 73 warn about any user-defined symbol names longer than one
6068 character that don't have at least one non-alphabetic character after
6069 the first;
6070 Numbers 69 and 74 disallow any references to intrinsics;
6071 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
6072 67+69, 68+69, 72+74, and 73+74, respectively.
6073
6074 All redundant combinations are shown in the above tables anyplace
6075 where more than one setting is shown for a low-level switch.
6076 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
6077 The ``proper'' setting in such a case is the one that copies the setting
6078 of switch A---any other setting might slightly reduce the speed of
6079 the compiler, though possibly to an unmeasurable extent.
6080
6081 All remaining combinations are useless in that they prevent successful
6082 compilation of non-null source files (source files with something other
6083 than comments).
6084
6085 @node VXT Fortran
6086 @section VXT Fortran
6087
6088 @cindex VXT extensions
6089 @cindex extensions, VXT
6090 @code{g77} supports certain constructs that
6091 have different meanings in VXT Fortran than they
6092 do in the GNU Fortran language.
6093
6094 Generally, this manual uses the invented term VXT Fortran to refer
6095 VAX FORTRAN (circa v4).
6096 That compiler offered many popular features, though not necessarily
6097 those that are specific to the VAX processor architecture,
6098 the VMS operating system,
6099 or Digital Equipment Corporation's Fortran product line.
6100 (VAX and VMS probably are trademarks of Digital Equipment
6101 Corporation.)
6102
6103 An extension offered by a Digital Fortran product that also is
6104 offered by several other Fortran products for different kinds of
6105 systems is probably going to be considered for inclusion in @code{g77}
6106 someday, and is considered a VXT Fortran feature.
6107
6108 The @samp{-fvxt} option generally specifies that, where
6109 the meaning of a construct is ambiguous (means one thing
6110 in GNU Fortran and another in VXT Fortran), the VXT Fortran
6111 meaning is to be assumed.
6112
6113 @menu
6114 * Double Quote Meaning::  @samp{"2000} as octal constant.
6115 * Exclamation Point::     @samp{!} in column 6.
6116 @end menu
6117
6118 @node Double Quote Meaning
6119 @subsection Meaning of Double Quote
6120 @cindex double quotes
6121 @cindex character constants
6122 @cindex constants, character
6123 @cindex octal constants
6124 @cindex constants, octal
6125
6126 @code{g77} treats double-quote (@samp{"})
6127 as beginning an octal constant of @code{INTEGER(KIND=1)} type
6128 when the @samp{-fvxt} option is specified.
6129 The form of this octal constant is
6130
6131 @example
6132 "@var{octal-digits}
6133 @end example
6134
6135 @noindent
6136 where @var{octal-digits} is a nonempty string of characters in
6137 the set @samp{01234567}.
6138
6139 For example, the @samp{-fvxt} option permits this:
6140
6141 @example
6142 PRINT *, "20
6143 END
6144 @end example
6145
6146 @noindent
6147 The above program would print the value @samp{16}.
6148
6149 @xref{Integer Type}, for information on the preferred construct
6150 for integer constants specified using GNU Fortran's octal notation.
6151
6152 (In the GNU Fortran language, the double-quote character (@samp{"})
6153 delimits a character constant just as does apostrophe (@samp{'}).
6154 There is no way to allow
6155 both constructs in the general case, since statements like
6156 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
6157
6158 @node Exclamation Point
6159 @subsection Meaning of Exclamation Point in Column 6
6160 @cindex !
6161 @cindex exclamation point
6162 @cindex continuation character
6163 @cindex characters, continuation
6164 @cindex comment character
6165 @cindex characters, comment
6166
6167 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
6168 a fixed-form source file
6169 as a continuation character rather than
6170 as the beginning of a comment
6171 (as it does in any other column)
6172 when the @samp{-fvxt} option is specified.
6173
6174 The following program, when run, prints a message indicating
6175 whether it is interpreted according to GNU Fortran (and Fortran 90)
6176 rules or VXT Fortran rules:
6177
6178 @smallexample
6179 C234567  (This line begins in column 1.)
6180       I = 0
6181      !1
6182       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
6183       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
6184       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
6185       END
6186 @end smallexample
6187
6188 (In the GNU Fortran and Fortran 90 languages, exclamation point is
6189 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
6190 marks a line as a continuation line when it appears in column 6.)
6191
6192 @node Fortran 90
6193 @section Fortran 90
6194 @cindex compatibility, Fortran 90
6195 @cindex Fortran 90, compatibility
6196
6197 The GNU Fortran language includes a number of features that are
6198 part of Fortran 90, even when the @samp{-ff90} option is not specified.
6199 The features enabled by @samp{-ff90} are intended to be those that,
6200 when @samp{-ff90} is not specified, would have another
6201 meaning to @code{g77}---usually meaning something invalid in the
6202 GNU Fortran language.
6203
6204 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
6205 to gratuitously reject Fortran 90 constructs.
6206 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
6207 to do that, although its implementation is certainly incomplete at
6208 this point.
6209
6210 When @samp{-ff90} is specified:
6211
6212 @itemize @bullet
6213 @item
6214 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
6215 where @var{expr} is @code{COMPLEX} type,
6216 is the same type as the real part of @var{expr}.
6217
6218 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
6219 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
6220 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
6221 @end itemize
6222
6223 @node Pedantic Compilation
6224 @section Pedantic Compilation
6225 @cindex pedantic compilation
6226 @cindex compilation, pedantic
6227
6228 The @samp{-fpedantic} command-line option specifies that @code{g77}
6229 is to warn about code that is not standard-conforming.
6230 This is useful for finding
6231 some extensions @code{g77} accepts that other compilers might not accept.
6232 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
6233 always imply @samp{-fpedantic}.)
6234
6235 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
6236 for conforming code.
6237 With @samp{-ff90} in force, Fortran 90 is used.
6238
6239 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
6240 and @samp{-fno-f90} are in force are:
6241
6242 @itemize @bullet
6243 @item
6244 Automatic arrays, as in
6245
6246 @example
6247 SUBROUTINE X(N)
6248 REAL A(N)
6249 @dots{}
6250 @end example
6251
6252 @noindent
6253 where @samp{A} is not listed in any @code{ENTRY} statement,
6254 and thus is not a dummy argument.
6255
6256 @item
6257 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
6258
6259 These commas are disallowed by FORTRAN 77, but, while strictly
6260 superfluous, are syntactically elegant,
6261 especially given that commas are required in statements such
6262 as @samp{READ 99, I} and @samp{PRINT *, J}.
6263 Many compilers permit the superfluous commas for this reason.
6264
6265 @item
6266 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
6267
6268 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
6269 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
6270
6271 An example of an implicit use is the expression @samp{C*D},
6272 where @samp{C} is @code{COMPLEX(KIND=1)}
6273 and @samp{D} is @code{DOUBLE PRECISION}.
6274 This expression is prohibited by ANSI FORTRAN 77
6275 because the rules of promotion would suggest that it
6276 produce a @code{DOUBLE COMPLEX} result---a type not
6277 provided for by that standard.
6278
6279 @item
6280 Automatic conversion of numeric
6281 expressions to @code{INTEGER(KIND=1)} in contexts such as:
6282
6283 @itemize @minus
6284 @item
6285 Array-reference indexes.
6286 @item
6287 Alternate-return values.
6288 @item
6289 Computed @code{GOTO}.
6290 @item
6291 @code{FORMAT} run-time expressions (not yet supported).
6292 @item
6293 Dimension lists in specification statements.
6294 @item
6295 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
6296 @item
6297 Sizes of @code{CHARACTER} entities in specification statements.
6298 @item
6299 Kind types in specification entities (a Fortran 90 feature).
6300 @item
6301 Initial, terminal, and incrementation parameters for implied-@code{DO}
6302 constructs in @code{DATA} statements.
6303 @end itemize
6304
6305 @item
6306 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
6307 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
6308 expressions are disallowed anyway).
6309
6310 @item
6311 Zero-size array dimensions, as in:
6312
6313 @example
6314 INTEGER I(10,20,4:2)
6315 @end example
6316
6317 @item
6318 Zero-length @code{CHARACTER} entities, as in:
6319
6320 @example
6321 PRINT *, ''
6322 @end example
6323
6324 @item
6325 Substring operators applied to character constants and named
6326 constants, as in:
6327
6328 @example
6329 PRINT *, 'hello'(3:5)
6330 @end example
6331
6332 @item
6333 Null arguments passed to statement function, as in:
6334
6335 @example
6336 PRINT *, FOO(,3)
6337 @end example
6338
6339 @item
6340 Disagreement among program units regarding whether a given @code{COMMON}
6341 area is @code{SAVE}d (for targets where program units in a single source
6342 file are ``glued'' together as they typically are for UNIX development
6343 environments).
6344
6345 @item
6346 Disagreement among program units regarding the size of a
6347 named @code{COMMON} block.
6348
6349 @item
6350 Specification statements following first @code{DATA} statement.
6351
6352 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
6353 but not @samp{INTEGER I}.
6354 The @samp{-fpedantic} option disallows both of these.)
6355
6356 @item
6357 Semicolon as statement separator, as in:
6358
6359 @example
6360 CALL FOO; CALL BAR
6361 @end example
6362 @c
6363 @c @item
6364 @c Comma before list of I/O items in @code{WRITE}
6365 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
6366 @c statements, as with @code{READ} (as explained above).
6367
6368 @item
6369 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
6370
6371 @item
6372 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
6373 versa.
6374
6375 @item
6376 Expressions having two arithmetic operators in a row, such
6377 as @samp{X*-Y}.
6378 @end itemize
6379
6380 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
6381 following constructs result in diagnostics:
6382
6383 @itemize @bullet
6384 @item
6385 Use of semicolon as a statement separator on a line
6386 that has an @code{INCLUDE} directive.
6387 @end itemize
6388
6389 @node Distensions
6390 @section Distensions
6391 @cindex distensions
6392 @cindex ugly features
6393 @cindex features, ugly
6394
6395 The @samp{-fugly-*} command-line options determine whether certain
6396 features supported by VAX FORTRAN and other such compilers, but considered
6397 too ugly to be in code that can be changed to use safer and/or more
6398 portable constructs, are accepted.
6399 These are humorously referred to as ``distensions'',
6400 extensions that just plain look ugly in the harsh light of day.
6401
6402 @menu
6403 * Ugly Implicit Argument Conversion::  Disabled via @samp{-fno-ugly-args}.
6404 * Ugly Assumed-Size Arrays::           Enabled via @samp{-fugly-assumed}.
6405 * Ugly Null Arguments::                Enabled via @samp{-fugly-comma}.
6406 * Ugly Complex Part Extraction::       Enabled via @samp{-fugly-complex}.
6407 * Ugly Conversion of Initializers::    Disabled via @samp{-fno-ugly-init}.
6408 * Ugly Integer Conversions::           Enabled via @samp{-fugly-logint}.
6409 * Ugly Assigned Labels::               Enabled via @samp{-fugly-assign}.
6410 @end menu
6411
6412 @node Ugly Implicit Argument Conversion
6413 @subsection Implicit Argument Conversion
6414 @cindex Hollerith constants
6415 @cindex constants, Hollerith
6416
6417 The @samp{-fno-ugly-args} option disables
6418 passing typeless and Hollerith constants as actual arguments
6419 in procedure invocations.
6420 For example:
6421
6422 @example
6423 CALL FOO(4HABCD)
6424 CALL BAR('123'O)
6425 @end example
6426
6427 @noindent
6428 These constructs can be too easily used to create non-portable
6429 code, but are not considered as ``ugly'' as others.
6430 Further, they are widely used in existing Fortran source code
6431 in ways that often are quite portable.
6432 Therefore, they are enabled by default.
6433
6434 @node Ugly Assumed-Size Arrays
6435 @subsection Ugly Assumed-Size Arrays
6436 @cindex arrays, assumed-size
6437 @cindex assumed-size arrays
6438 @cindex DIMENSION X(1)
6439
6440 The @samp{-fugly-assumed} option enables
6441 the treatment of any array with a final dimension specified as @samp{1}
6442 as an assumed-size array, as if @samp{*} had been specified
6443 instead.
6444
6445 For example, @samp{DIMENSION X(1)} is treated as if it
6446 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
6447 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
6448 or @code{ENTRY} statement in the same program unit.
6449
6450 Use an explicit lower bound to avoid this interpretation.
6451 For example, @samp{DIMENSION X(1:1)} is never treated as if
6452 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
6453 Nor is @samp{DIMENSION X(2-1)} affected by this option,
6454 since that kind of expression is unlikely to have been
6455 intended to designate an assumed-size array.
6456
6457 This option is used to prevent warnings being issued about apparent
6458 out-of-bounds reference such as @samp{X(2) = 99}.
6459
6460 It also prevents the array from being used in contexts that
6461 disallow assumed-size arrays, such as @samp{PRINT *,X}.
6462 In such cases, a diagnostic is generated and the source file is
6463 not compiled.
6464
6465 The construct affected by this option is used only in old code
6466 that pre-exists the widespread acceptance of adjustable and assumed-size
6467 arrays in the Fortran community.
6468
6469 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
6470 treated if @samp{X} is listed as a dummy argument only
6471 @emph{after} the @code{DIMENSION} statement (presumably in
6472 an @code{ENTRY} statement).
6473 For example, @samp{-fugly-assumed} has no effect on the
6474 following program unit:
6475
6476 @example
6477 SUBROUTINE X
6478 REAL A(1)
6479 RETURN
6480 ENTRY Y(A)
6481 PRINT *, A
6482 END
6483 @end example
6484
6485 @node Ugly Complex Part Extraction
6486 @subsection Ugly Complex Part Extraction
6487 @cindex complex values
6488 @cindex real part
6489 @cindex imaginary part
6490
6491 The @samp{-fugly-complex} option enables
6492 use of the @code{REAL()} and @code{AIMAG()}
6493 intrinsics with arguments that are
6494 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
6495
6496 With @samp{-ff90} in effect, these intrinsics return
6497 the unconverted real and imaginary parts (respectively)
6498 of their argument.
6499
6500 With @samp{-fno-f90} in effect, these intrinsics convert
6501 the real and imaginary parts to @code{REAL(KIND=1)}, and return
6502 the result of that conversion.
6503
6504 Due to this ambiguity, the GNU Fortran language defines
6505 these constructs as invalid, except in the specific
6506 case where they are entirely and solely passed as an
6507 argument to an invocation of the @code{REAL()} intrinsic.
6508 For example,
6509
6510 @example
6511 REAL(REAL(Z))
6512 @end example
6513
6514 @noindent
6515 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
6516 and @samp{-fno-ugly-complex} is in effect, because the
6517 meaning is clear.
6518
6519 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
6520 is specified, in which case the appropriate interpretation is
6521 chosen and no diagnostic is issued.
6522
6523 @xref{CMPAMBIG}, for information on how to cope with existing
6524 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
6525 with @code{COMPLEX(KIND=2)} arguments.
6526
6527 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
6528 intrinsic, used to extract the real part of a complex expression
6529 without conversion.
6530 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
6531 intrinsic, used to extract the imaginary part of a complex expression
6532 without conversion.
6533
6534 @node Ugly Null Arguments
6535 @subsection Ugly Null Arguments
6536 @cindex trailing comma
6537 @cindex comma, trailing
6538 @cindex characters, comma
6539 @cindex null arguments
6540 @cindex arguments, null
6541
6542 The @samp{-fugly-comma} option enables use of a single trailing comma
6543 to mean ``pass an extra trailing null argument''
6544 in a list of actual arguments to an external procedure,
6545 and use of an empty list of arguments to such a procedure
6546 to mean ``pass a single null argument''.
6547
6548 @cindex omitting arguments
6549 @cindex arguments, omitting
6550 (Null arguments often are used in some procedure-calling
6551 schemes to indicate omitted arguments.)
6552
6553 For example, @samp{CALL FOO(,)} means ``pass
6554 two null arguments'', rather than ``pass one null argument''.
6555 Also, @samp{CALL BAR()} means ``pass one null argument''.
6556
6557 This construct is considered ``ugly'' because it does not
6558 provide an elegant way to pass a single null argument
6559 that is syntactically distinct from passing no arguments.
6560 That is, this construct changes the meaning of code that
6561 makes no use of the construct.
6562
6563 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
6564 and @samp{I = JFUNC()} pass a single null argument, instead
6565 of passing no arguments as required by the Fortran 77 and
6566 90 standards.
6567
6568 @emph{Note:} Many systems gracefully allow the case
6569 where a procedure call passes one extra argument that the
6570 called procedure does not expect.
6571
6572 So, in practice, there might be no difference in
6573 the behavior of a program that does @samp{CALL FOO()}
6574 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
6575 in force as compared to its behavior when compiled
6576 with the default, @samp{-fno-ugly-comma}, in force,
6577 assuming @samp{FOO} and @samp{JFUNC} do not expect any
6578 arguments to be passed.
6579
6580 @node Ugly Conversion of Initializers
6581 @subsection Ugly Conversion of Initializers
6582
6583 The constructs disabled by @samp{-fno-ugly-init} are:
6584
6585 @itemize @bullet
6586 @cindex Hollerith constants
6587 @cindex constants, Hollerith
6588 @item
6589 Use of Hollerith and typeless constants in contexts where they set
6590 initial (compile-time) values for variables, arrays, and named
6591 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
6592 type-declaration statements specifying initial values.
6593
6594 Here are some sample initializations that are disabled by the
6595 @samp{-fno-ugly-init} option:
6596
6597 @example
6598 PARAMETER (VAL='9A304FFE'X)
6599 REAL*8 STRING/8HOUTPUT00/
6600 DATA VAR/4HABCD/
6601 @end example
6602
6603 @cindex character constants
6604 @cindex constants, character
6605 @item
6606 In the same contexts as above, use of character constants to initialize
6607 numeric items and vice versa (one constant per item).
6608
6609 Here are more sample initializations that are disabled by the
6610 @samp{-fno-ugly-init} option:
6611
6612 @example
6613 INTEGER IA
6614 CHARACTER BELL
6615 PARAMETER (IA = 'A')
6616 PARAMETER (BELL = 7)
6617 @end example
6618
6619 @item
6620 Use of Hollerith and typeless constants on the right-hand side
6621 of assignment statements to numeric types, and in other
6622 contexts (such as passing arguments in invocations of
6623 intrinsic procedures and statement functions) that
6624 are treated as assignments to known types (the dummy
6625 arguments, in these cases).
6626
6627 Here are sample statements that are disabled by the
6628 @samp{-fno-ugly-init} option:
6629
6630 @example
6631 IVAR = 4HABCD
6632 PRINT *, IMAX0(2HAB, 2HBA)
6633 @end example
6634 @end itemize
6635
6636 The above constructs, when used,
6637 can tend to result in non-portable code.
6638 But, they are widely used in existing Fortran code in ways
6639 that often are quite portable.
6640 Therefore, they are enabled by default.
6641
6642 @node Ugly Integer Conversions
6643 @subsection Ugly Integer Conversions
6644
6645 The constructs enabled via @samp{-fugly-logint} are:
6646
6647 @itemize @bullet
6648 @item
6649 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
6650 dictated by
6651 context (typically implies nonportable dependencies on how a
6652 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
6653
6654 @item
6655 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
6656 statements.
6657 @end itemize
6658
6659 The above constructs are disabled by default because use
6660 of them tends to lead to non-portable code.
6661 Even existing Fortran code that uses that often turns out
6662 to be non-portable, if not outright buggy.
6663
6664 Some of this is due to differences among implementations as
6665 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
6666 @code{INTEGER} values---Fortran code that assumes a particular
6667 coding is likely to use one of the above constructs, and is
6668 also likely to not work correctly on implementations using
6669 different encodings.
6670
6671 @xref{Equivalence Versus Equality}, for more information.
6672
6673 @node Ugly Assigned Labels
6674 @subsection Ugly Assigned Labels
6675 @cindex ASSIGN statement
6676 @cindex statements, ASSIGN
6677 @cindex assigned labels
6678 @cindex pointers
6679
6680 The @samp{-fugly-assign} option forces @code{g77} to use the
6681 same storage for assigned labels as it would for a normal
6682 assignment to the same variable.
6683
6684 For example, consider the following code fragment:
6685
6686 @example
6687 I = 3
6688 ASSIGN 10 TO I
6689 @end example
6690
6691 @noindent
6692 Normally, for portability and improved diagnostics, @code{g77}
6693 reserves distinct storage for a ``sibling'' of @samp{I}, used
6694 only for @code{ASSIGN} statements to that variable (along with
6695 the corresponding assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O
6696 statements that reference the variable).
6697
6698 However, some code (that violates the ANSI FORTRAN 77 standard)
6699 attempts to copy assigned labels among variables involved with
6700 @code{ASSIGN} statements, as in:
6701
6702 @example
6703 ASSIGN 10 TO I
6704 ISTATE(5) = I
6705 @dots{}
6706 J = ISTATE(ICUR)
6707 GOTO J
6708 @end example
6709
6710 @noindent
6711 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
6712 is specified on the command-line, ensuring that the value of @code{I}
6713 referenced in the second line is whatever value @code{g77} uses
6714 to designate statement label @samp{10}, so the value may be
6715 copied into the @samp{ISTATE} array, later retrieved into a
6716 variable of the appropriate type (@samp{J}), and used as the target of
6717 an assigned-@code{GOTO} statement.
6718
6719 @emph{Note:} To avoid subtle program bugs,
6720 when @samp{-fugly-assign} is specified,
6721 @code{g77} requires the type of variables
6722 specified in assigned-label contexts
6723 @emph{must} be the same type returned by @code{%LOC()}.
6724 On many systems, this type is effectively the same
6725 as @code{INTEGER(KIND=1)}, while, on others, it is
6726 effectively the same as @code{INTEGER(KIND=2)}.
6727
6728 Do @emph{not} depend on @code{g77} actually writing valid pointers
6729 to these variables, however.
6730 While @code{g77} currently chooses that implementation, it might
6731 be changed in the future.
6732
6733 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
6734 for implementation details on assigned-statement labels.
6735
6736 @node Compiler
6737 @chapter The GNU Fortran Compiler
6738
6739 The GNU Fortran compiler, @code{g77}, supports programs written
6740 in the GNU Fortran language and in some other dialects of Fortran.
6741
6742 Some aspects of how @code{g77} works are universal regardless
6743 of dialect, and yet are not properly part of the GNU Fortran
6744 language itself.
6745 These are described below.
6746
6747 @emph{Note: This portion of the documentation definitely needs a lot
6748 of work!}
6749
6750 @menu
6751 * Compiler Limits::
6752 * Run-time Environment Limits::
6753 * Compiler Types::
6754 * Compiler Constants::
6755 * Compiler Intrinsics::
6756 @end menu
6757
6758 @node Compiler Limits
6759 @section Compiler Limits
6760 @cindex limits, compiler
6761 @cindex compiler limits
6762
6763 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
6764 on lengths of identifiers, number of continuation lines, number of external
6765 symbols in a program, and so on.
6766
6767 @cindex options, -Nl
6768 @cindex -Nl option
6769 @cindex options, -Nx
6770 @cindex -Nx option
6771 @cindex limits, continuation lines
6772 @cindex limits, lengths of names
6773 For example, some other Fortran compiler have an option
6774 (such as @samp{-Nl@var{x}}) to increase the limit on the
6775 number of continuation lines.
6776 Also, some Fortran compilation systems have an option
6777 (such as @samp{-Nx@var{x}}) to increase the limit on the
6778 number of external symbols.
6779
6780 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
6781 no equivalent options, since they do not impose arbitrary
6782 limits in these areas.
6783
6784 @cindex rank, maximum
6785 @cindex maximum rank
6786 @cindex number of dimensions, maximum
6787 @cindex maximum number of dimensions
6788 @cindex limits, rank
6789 @cindex limits, array dimensions
6790 @code{g77} does currently limit the number of dimensions in an array
6791 to the same degree as do the Fortran standards---seven (7).
6792 This restriction might be lifted in a future version.
6793
6794 @node Run-time Environment Limits
6795 @section Run-time Environment Limits
6796 @cindex limits, run-time library
6797 @cindex wraparound
6798
6799 As a portable Fortran implementation,
6800 @code{g77} offers its users direct access to,
6801 and otherwise depends upon,
6802 the underlying facilities of the system
6803 used to build @code{g77},
6804 the system on which @code{g77} itself is used to compile programs,
6805 and the system on which the @code{g77}-compiled program is actually run.
6806 (For most users, the three systems are of the same
6807 type---combination of operating environment and hardware---often
6808 the same physical system.)
6809
6810 The run-time environment for a particular system
6811 inevitably imposes some limits on a program's use
6812 of various system facilities.
6813 These limits vary from system to system.
6814
6815 Even when such limits might be well beyond the
6816 possibility of being encountered on a particular system,
6817 the @code{g77} run-time environment
6818 has certain built-in limits,
6819 usually, but not always, stemming from intrinsics
6820 with inherently limited interfaces.
6821
6822 Currently, the @code{g77} run-time environment
6823 does not generally offer a less-limiting environment
6824 by augmenting the underlying system's own environment.
6825
6826 Therefore, code written in the GNU Fortran language,
6827 while syntactically and semantically portable,
6828 might nevertheless make non-portable assumptions
6829 about the run-time environment---assumptions that
6830 prove to be false for some particular environments.
6831
6832 The GNU Fortran language,
6833 the @code{g77} compiler and run-time environment,
6834 and the @code{g77} documentation
6835 do not yet offer comprehensive portable work-arounds for such limits,
6836 though programmers should be able to
6837 find their own in specific instances.
6838
6839 Not all of the limitations are described in this document.
6840 Some of the known limitations include:
6841
6842 @menu
6843 * Timer Wraparounds::
6844 * Year 2000 (Y2K) Problems::
6845 * Array Size::
6846 * Character-variable Length::
6847 * Year 10000 (Y10K) Problems::
6848 @end menu
6849
6850 @node Timer Wraparounds
6851 @subsection Timer Wraparounds
6852
6853 Intrinsics that return values computed from system timers,
6854 whether elapsed (wall-clock) timers,
6855 process CPU timers,
6856 or other kinds of timers,
6857 are prone to experiencing wrap-around errors
6858 (or returning wrapped-around values from successive calls)
6859 due to insufficient ranges
6860 offered by the underlying system's timers.
6861
6862 @cindex negative time
6863 @cindex short time
6864 @cindex long time
6865 Some of the symptoms of such behaviors include
6866 apparently negative time being computed for a duration,
6867 an extremely short amount of time being computed for a long duration,
6868 and an extremely long amount of time being computed for a short duration.
6869
6870 See the following for intrinsics
6871 known to have potential problems in these areas
6872 on at least some systems:
6873 @ref{CPU_Time Intrinsic},
6874 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
6875 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
6876 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
6877 @ref{Secnds Intrinsic},
6878 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
6879 @ref{System_Clock Intrinsic},
6880 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
6881 @ref{Time8 Intrinsic}.
6882
6883 @node Year 2000 (Y2K) Problems
6884 @subsection Year 2000 (Y2K) Problems
6885 @cindex Y2K compliance
6886 @cindex Year 2000 compliance
6887
6888 While the @code{g77} compiler itself is believed to
6889 be Year-2000 (Y2K) compliant,
6890 some intrinsics are not,
6891 and, potentially, some underlying systems are not,
6892 perhaps rendering some Y2K-compliant intrinsics
6893 non-compliant when used on those particular systems.
6894
6895 Fortran code that uses non-Y2K-compliant intrinsics
6896 (listed below)
6897 is, itself, almost certainly not compliant,
6898 and should be modified to use Y2K-compliant intrinsics instead.
6899
6900 Fortran code that uses no non-Y2K-compliant intrinsics,
6901 but which currently is running on a non-Y2K-compliant system,
6902 can be made more Y2K compliant by compiling and
6903 linking it for use on a new Y2K-compliant system,
6904 such as a new version of an old, non-Y2K-compliant, system.
6905
6906 Currently, information on Y2K and related issues
6907 is being maintained at
6908 @uref{http://www.gnu.org/software/year2000-list.html}.
6909
6910 See the following for intrinsics
6911 known to have potential problems in these areas
6912 on at least some systems:
6913 @ref{Date Intrinsic},
6914 @ref{IDate Intrinsic (VXT)}.
6915
6916 @cindex y2kbuggy
6917 @cindex date_y2kbuggy_0
6918 @cindex vxtidate_y2kbuggy_0
6919 @cindex G77_date_y2kbuggy_0
6920 @cindex G77_vxtidate_y2kbuggy_0
6921 The @code{libg2c} library
6922 shipped with any @code{g77} that warns
6923 about invocation of a non-Y2K-compliant intrinsic
6924 has renamed the @code{EXTERNAL} procedure names
6925 of those intrinsics.
6926 This is done so that
6927 the @code{libg2c} implementations of these intrinsics
6928 cannot be directly linked to
6929 as @code{EXTERNAL} names
6930 (which normally would avoid the non-Y2K-intrinsic warning).
6931
6932 The renamed forms of the @code{EXTERNAL} names
6933 of these renamed procedures
6934 may be linked to
6935 by appending the string @samp{_y2kbug}
6936 to the name of the procedure
6937 in the source code.
6938 For example:
6939
6940 @smallexample
6941 CHARACTER*20 STR
6942 INTEGER YY, MM, DD
6943 EXTERNAL DATE_Y2KBUG, VXTIDATE_Y2KBUG
6944 CALL DATE_Y2KBUG (STR)
6945 CALL VXTIDATE_Y2KBUG (MM, DD, YY)
6946 @end smallexample
6947
6948 (Note that the @code{EXTERNAL} statement
6949 is not actually required,
6950 since the modified names are not recognized as intrinsics
6951 by the current version of @code{g77}.
6952 But it is shown in this specific case,
6953 for purposes of illustration.)
6954
6955 The renaming of @code{EXTERNAL} procedure names of these intrinsics
6956 causes unresolved references at link time.
6957 For example, @samp{EXTERNAL DATE; CALL DATE(STR)}
6958 is normally compiled by @code{g77}
6959 as, in C, @samp{date_(&str, 20);}.
6960 This, in turn, links to the @code{date_} procedure
6961 in the @code{libE77} portion of @code{libg2c},
6962 which purposely calls a nonexistent procedure
6963 named @code{G77_date_y2kbuggy_0}.
6964 The resulting link-time error is designed, via this name,
6965 to encourage the programmer to look up the
6966 index entries to this portion of the @code{g77} documentation.
6967
6968 Generally, we recommend that the @code{EXTERNAL} method
6969 of invoking procedures in @code{libg2c}
6970 @emph{not} be used.
6971 When used, some of the correctness checking
6972 normally performed by @code{g77}
6973 is skipped.
6974
6975 In particular, it is probably better to use the
6976 @code{INTRINSIC} method of invoking
6977 non-Y2K-compliant procedures,
6978 so anyone compiling the code
6979 can quickly notice the potential Y2K problems
6980 (via the warnings printing by @code{g77})
6981 without having to even look at the code itself.
6982
6983 If there are problems linking @code{libg2c}
6984 to code compiled by @code{g77}
6985 that involve the string @samp{y2kbug},
6986 and these are not explained above,
6987 that probably indicates
6988 that a version of @code{libg2c}
6989 older than @code{g77}
6990 is being linked to,
6991 or that the new library is being linked
6992 to code compiled by an older version of @code{g77}.
6993
6994 That's because, as of the version that warns about
6995 non-Y2K-compliant intrinsic invocation,
6996 @code{g77} references the @code{libg2c} implementations
6997 of those intrinsics
6998 using new names, containing the string @samp{y2kbug}.
6999
7000 So, linking newly-compiled code
7001 (invoking one of the intrinsics in question)
7002 to an old library
7003 might yield an unresolved reference
7004 to @code{G77_date_y2kbug_0}.
7005 (The old library calls it @code{G77_date_0}.)
7006
7007 Similarly, linking previously-compiled code
7008 to a new library
7009 might yield an unresolved reference
7010 to @code{G77_vxtidate_0}.
7011 (The new library calls it @code{G77_vxtidate_y2kbug_0}.)
7012
7013 The proper fix for the above problems
7014 is to obtain the latest release of @code{g77}
7015 and related products
7016 (including @code{libg2c})
7017 and install them on all systems,
7018 then recompile, relink, and install
7019 (as appropriate)
7020 all existing Fortran programs.
7021
7022 (Normally, this sort of renaming is steadfastly avoided.
7023 In this case, however, it seems more important to highlight
7024 potential Y2K problems
7025 than to ease the transition
7026 of potentially non-Y2K-compliant code
7027 to new versions of @code{g77} and @code{libg2c}.)
7028
7029 @node Array Size
7030 @subsection Array Size
7031 @cindex limits, array size
7032 @cindex array size
7033
7034 Currently, @code{g77} uses the default @code{INTEGER} type
7035 for array indexes,
7036 which limits the sizes of single-dimension arrays
7037 on systems offering a larger address space
7038 than can be addressed by that type.
7039 (That @code{g77} puts all arrays in memory
7040 could be considered another limitation---it
7041 could use large temporary files---but that decision
7042 is left to the programmer as an implementation choice
7043 by most Fortran implementations.)
7044
7045 @c ??? Investigate this, to offer a more clear statement
7046 @c than the following paragraphs do.  -- burley 1999-02-17
7047 It is not yet clear whether this limitation
7048 never, sometimes, or always applies to the
7049 sizes of multiple-dimension arrays as a whole.
7050
7051 For example, on a system with 64-bit addresses
7052 and 32-bit default @code{INTEGER},
7053 an array with a size greater than can be addressed
7054 by a 32-bit offset
7055 can be declared using multiple dimensions.
7056 Such an array is therefore larger
7057 than a single-dimension array can be,
7058 on the same system.
7059
7060 @cindex limits, multi-dimension arrays
7061 @cindex multi-dimension arrays
7062 @cindex arrays, dimensioning
7063 Whether large multiple-dimension arrays are reliably supported
7064 depends mostly on the @code{gcc} back end (code generator)
7065 used by @code{g77}, and has not yet been fully investigated.
7066
7067 @node Character-variable Length
7068 @subsection Character-variable Length
7069 @cindex limits, on character-variable length
7070 @cindex character-variable length
7071
7072 Currently, @code{g77} uses the default @code{INTEGER} type
7073 for the lengths of @code{CHARACTER} variables
7074 and array elements.
7075
7076 This means that, for example,
7077 a system with a 64-bit address space
7078 and a 32-bit default @code{INTEGER} type
7079 does not, under @code{g77},
7080 support a @code{CHARACTER*@var{n}} declaration
7081 where @var{n} is greater than 2147483647.
7082
7083 @node Year 10000 (Y10K) Problems
7084 @subsection Year 10000 (Y10K) Problems
7085 @cindex Y10K compliance
7086 @cindex Year 10000 compliance
7087
7088 Most intrinsics returning, or computing values based on,
7089 date information are prone to Year-10000 (Y10K) problems,
7090 due to supporting only 4 digits for the year.
7091
7092 See the following for examples:
7093 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
7094 @ref{IDate Intrinsic (UNIX)},
7095 @ref{Time Intrinsic (VXT)},
7096 @ref{Date_and_Time Intrinsic}.
7097
7098 @node Compiler Types
7099 @section Compiler Types
7100 @cindex types, of data
7101 @cindex data types
7102
7103 Fortran implementations have a fair amount of freedom given them by the
7104 standard as far as how much storage space is used and how much precision
7105 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
7106 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
7107 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
7108 Further, many compilers offer so-called @samp{*@var{n}} notation, but
7109 the interpretation of @var{n} varies across compilers and target architectures.
7110
7111 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
7112 and @code{REAL(KIND=1)}
7113 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
7114 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
7115 Further, it requires that @code{COMPLEX(KIND=1)}
7116 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
7117 storage-associated (such as via @code{EQUIVALENCE})
7118 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
7119 corresponds to the real element and @samp{R(2)} to the imaginary
7120 element of the @code{COMPLEX(KIND=1)} variable.
7121
7122 (Few requirements as to precision or ranges of any of these are
7123 placed on the implementation, nor is the relationship of storage sizes of
7124 these types to the @code{CHARACTER} type specified, by the standard.)
7125
7126 @code{g77} follows the above requirements, warning when compiling
7127 a program requires placement of items in memory that contradict the
7128 requirements of the target architecture.
7129 (For example, a program can require placement of a @code{REAL(KIND=2)}
7130 on a boundary that is not an even multiple of its size, but still an
7131 even multiple of the size of a @code{REAL(KIND=1)} variable.
7132 On some target architectures, using the canonical
7133 mapping of Fortran types to underlying architectural types, such
7134 placement is prohibited by the machine definition or
7135 the Application Binary Interface (ABI) in force for
7136 the configuration defined for building @code{gcc} and @code{g77}.
7137 @code{g77} warns about such
7138 situations when it encounters them.)
7139
7140 @code{g77} follows consistent rules for configuring the mapping between Fortran
7141 types, including the @samp{*@var{n}} notation, and the underlying architectural
7142 types as accessed by a similarly-configured applicable version of the
7143 @code{gcc} compiler.
7144 These rules offer a widely portable, consistent Fortran/C
7145 environment, although they might well conflict with the expectations of
7146 users of Fortran compilers designed and written for particular
7147 architectures.
7148
7149 These rules are based on the configuration that is in force for the
7150 version of @code{gcc} built in the same release as @code{g77} (and
7151 which was therefore used to build both the @code{g77} compiler
7152 components and the @code{libg2c} run-time library):
7153
7154 @table @code
7155 @cindex REAL(KIND=1) type
7156 @cindex types, REAL(KIND=1)
7157 @item REAL(KIND=1)
7158 Same as @code{float} type.
7159
7160 @cindex REAL(KIND=2) type
7161 @cindex types, REAL(KIND=2)
7162 @item REAL(KIND=2)
7163 Same as whatever floating-point type that is twice the size
7164 of a @code{float}---usually, this is a @code{double}.
7165
7166 @cindex INTEGER(KIND=1) type
7167 @cindex types, INTEGER(KIND=1)
7168 @item INTEGER(KIND=1)
7169 Same as an integral type that is occupies the same amount
7170 of memory storage as @code{float}---usually, this is either
7171 an @code{int} or a @code{long int}.
7172
7173 @cindex LOGICAL(KIND=1) type
7174 @cindex types, LOGICAL(KIND=1)
7175 @item LOGICAL(KIND=1)
7176 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
7177
7178 @cindex INTEGER(KIND=2) type
7179 @cindex types, INTEGER(KIND=2)
7180 @item INTEGER(KIND=2)
7181 Twice the size, and usually nearly twice the range,
7182 as @code{INTEGER(KIND=1)}---usually, this is either
7183 a @code{long int} or a @code{long long int}.
7184
7185 @cindex LOGICAL(KIND=2) type
7186 @cindex types, LOGICAL(KIND=2)
7187 @item LOGICAL(KIND=2)
7188 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
7189
7190 @cindex INTEGER(KIND=3) type
7191 @cindex types, INTEGER(KIND=3)
7192 @item INTEGER(KIND=3)
7193 Same @code{gcc} type as signed @code{char}.
7194
7195 @cindex LOGICAL(KIND=3) type
7196 @cindex types, LOGICAL(KIND=3)
7197 @item LOGICAL(KIND=3)
7198 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
7199
7200 @cindex INTEGER(KIND=6) type
7201 @cindex types, INTEGER(KIND=6)
7202 @item INTEGER(KIND=6)
7203 Twice the size, and usually nearly twice the range,
7204 as @code{INTEGER(KIND=3)}---usually, this is
7205 a @code{short}.
7206
7207 @cindex LOGICAL(KIND=6) type
7208 @cindex types, LOGICAL(KIND=6)
7209 @item LOGICAL(KIND=6)
7210 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
7211
7212 @cindex COMPLEX(KIND=1) type
7213 @cindex types, COMPLEX(KIND=1)
7214 @item COMPLEX(KIND=1)
7215 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
7216 one for the imaginary part).
7217
7218 @cindex COMPLEX(KIND=2) type
7219 @cindex types, COMPLEX(KIND=2)
7220 @item COMPLEX(KIND=2)
7221 Two @code{REAL(KIND=2)} scalars.
7222
7223 @cindex *@var{n} notation
7224 @item @var{numeric-type}*@var{n}
7225 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
7226 Same as whatever @code{gcc} type occupies @var{n} times the storage
7227 space of a @code{gcc} @code{char} item.
7228
7229 @cindex DOUBLE PRECISION type
7230 @cindex types, DOUBLE PRECISION
7231 @item DOUBLE PRECISION
7232 Same as @code{REAL(KIND=2)}.
7233
7234 @cindex DOUBLE COMPLEX type
7235 @cindex types, DOUBLE COMPLEX
7236 @item DOUBLE COMPLEX
7237 Same as @code{COMPLEX(KIND=2)}.
7238 @end table
7239
7240 Note that the above are proposed correspondences and might change
7241 in future versions of @code{g77}---avoid writing code depending
7242 on them.
7243
7244 Other types supported by @code{g77}
7245 are derived from gcc types such as @code{char}, @code{short},
7246 @code{int}, @code{long int}, @code{long long int}, @code{long double},
7247 and so on.
7248 That is, whatever types @code{gcc} already supports, @code{g77} supports
7249 now or probably will support in a future version.
7250 The rules for the @samp{@var{numeric-type}*@var{n}} notation
7251 apply to these types,
7252 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
7253 assigned in a way that encourages clarity, consistency, and portability.
7254
7255 @node Compiler Constants
7256 @section Compiler Constants
7257 @cindex constants
7258 @cindex types, constants
7259
7260 @code{g77} strictly assigns types to @emph{all} constants not
7261 documented as ``typeless'' (typeless constants including @samp{'1'Z},
7262 for example).
7263 Many other Fortran compilers attempt to assign types to typed constants
7264 based on their context.
7265 This results in hard-to-find bugs, nonportable
7266 code, and is not in the spirit (though it strictly follows the letter)
7267 of the 77 and 90 standards.
7268
7269 @code{g77} might offer, in a future release, explicit constructs by
7270 which a wider variety of typeless constants may be specified, and/or
7271 user-requested warnings indicating places where @code{g77} might differ
7272 from how other compilers assign types to constants.
7273
7274 @xref{Context-Sensitive Constants}, for more information on this issue.
7275
7276 @node Compiler Intrinsics
7277 @section Compiler Intrinsics
7278
7279 @code{g77} offers an ever-widening set of intrinsics.
7280 Currently these all are procedures (functions and subroutines).
7281
7282 Some of these intrinsics are unimplemented, but their names reserved
7283 to reduce future problems with existing code as they are implemented.
7284 Others are implemented as part of the GNU Fortran language, while
7285 yet others are provided for compatibility with other dialects of
7286 Fortran but are not part of the GNU Fortran language.
7287
7288 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
7289 a facility that is simply an extension of the intrinsic groups provided
7290 by the GNU Fortran language.
7291
7292 @menu
7293 * Intrinsic Groups::  How intrinsics are grouped for easy management.
7294 * Other Intrinsics::  Intrinsics other than those in the GNU
7295                        Fortran language.
7296 @end menu
7297
7298 @node Intrinsic Groups
7299 @subsection Intrinsic Groups
7300 @cindex groups of intrinsics
7301 @cindex intrinsics, groups
7302
7303 A given specific intrinsic belongs in one or more groups.
7304 Each group is deleted, disabled, hidden, or enabled
7305 by default or a command-line option.
7306 The meaning of each term follows.
7307
7308 @table @b
7309 @cindex deleted intrinsics
7310 @cindex intrinsics, deleted
7311 @item Deleted
7312 No intrinsics are recognized as belonging to that group.
7313
7314 @cindex disabled intrinsics
7315 @cindex intrinsics, disabled
7316 @item Disabled
7317 Intrinsics are recognized as belonging to the group, but
7318 references to them (other than via the @code{INTRINSIC} statement)
7319 are disallowed through that group.
7320
7321 @cindex hidden intrinsics
7322 @cindex intrinsics, hidden
7323 @item Hidden
7324 Intrinsics in that group are recognized and enabled (if implemented)
7325 @emph{only} if the first mention of the actual name of an intrinsic
7326 in a program unit is in an @code{INTRINSIC} statement.
7327
7328 @cindex enabled intrinsics
7329 @cindex intrinsics, enabled
7330 @item Enabled
7331 Intrinsics in that group are recognized and enabled (if implemented).
7332 @end table
7333
7334 The distinction between deleting and disabling a group is illustrated
7335 by the following example.
7336 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
7337 If group @samp{FGR} is deleted, the following program unit will
7338 successfully compile, because @samp{FOO()} will be seen as a
7339 reference to an external function named @samp{FOO}:
7340
7341 @example
7342 PRINT *, FOO()
7343 END
7344 @end example
7345
7346 @noindent
7347 If group @samp{FGR} is disabled, compiling the above program will produce
7348 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
7349 or, if properly invoked, it is not enabled.
7350 To change the above program so it references an external function @samp{FOO}
7351 instead of the disabled @samp{FOO} intrinsic,
7352 add the following line to the top:
7353
7354 @example
7355 EXTERNAL FOO
7356 @end example
7357
7358 @noindent
7359 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
7360 that group do not exist at all, whereas disabling it tells @code{g77} to
7361 recognize them as (disabled) intrinsics in intrinsic-like contexts.
7362
7363 Hiding a group is like enabling it, but the intrinsic must be first
7364 named in an @code{INTRINSIC} statement to be considered a reference to the
7365 intrinsic rather than to an external procedure.
7366 This might be the ``safest'' way to treat a new group of intrinsics
7367 when compiling old
7368 code, because it allows the old code to be generally written as if
7369 those new intrinsics never existed, but to be changed to use them
7370 by inserting @code{INTRINSIC} statements in the appropriate places.
7371 However, it should be the goal of development to use @code{EXTERNAL}
7372 for all names of external procedures that might be intrinsic names.
7373
7374 If an intrinsic is in more than one group, it is enabled if any of its
7375 containing groups are enabled; if not so enabled, it is hidden if
7376 any of its containing groups are hidden; if not so hidden, it is disabled
7377 if any of its containing groups are disabled; if not so disabled, it is
7378 deleted.
7379 This extra complication is necessary because some intrinsics,
7380 such as @code{IBITS}, belong to more than one group, and hence should be
7381 enabled if any of the groups to which they belong are enabled, and so
7382 on.
7383
7384 The groups are:
7385
7386 @cindex intrinsics, groups of
7387 @cindex groups of intrinsics
7388 @table @code
7389 @cindex @code{badu77} intrinsics group
7390 @item badu77
7391 UNIX intrinsics having inappropriate forms (usually functions that
7392 have intended side effects).
7393
7394 @cindex @code{gnu} intrinsics group
7395 @item gnu
7396 Intrinsics the GNU Fortran language supports that are extensions to
7397 the Fortran standards (77 and 90).
7398
7399 @cindex @code{f2c} intrinsics group
7400 @item f2c
7401 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
7402
7403 @cindex @code{f90} intrinsics group
7404 @item f90
7405 Fortran 90 intrinsics.
7406
7407 @cindex @code{mil} intrinsics group
7408 @item mil
7409 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
7410
7411 @cindex @code{mil} intrinsics group
7412 @item unix
7413 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
7414
7415 @cindex @code{mil} intrinsics group
7416 @item vxt
7417 VAX/VMS FORTRAN (current as of v4) intrinsics.
7418 @end table
7419
7420 @node Other Intrinsics
7421 @subsection Other Intrinsics
7422 @cindex intrinsics, others
7423 @cindex other intrinsics
7424
7425 @code{g77} supports intrinsics other than those in the GNU Fortran
7426 language proper.
7427 This set of intrinsics is described below.
7428
7429 @ifinfo
7430 (Note that the empty lines appearing in the menu below
7431 are not intentional---they result from a bug in the
7432 @code{makeinfo} program.)
7433 @end ifinfo
7434
7435 @c The actual documentation for intrinsics comes from
7436 @c intdoc.texi, which in turn is automatically generated
7437 @c from the internal g77 tables in intrin.def _and_ the
7438 @c largely hand-written text in intdoc.h.  So, if you want
7439 @c to change or add to existing documentation on intrinsics,
7440 @c you probably want to edit intdoc.h.
7441 @c
7442 @clear familyF77
7443 @clear familyGNU
7444 @clear familyASC
7445 @clear familyMIL
7446 @clear familyF90
7447 @set familyVXT
7448 @set familyFVZ
7449 @clear familyF2C
7450 @clear familyF2U
7451 @set familyBADU77
7452 @include intdoc.texi
7453
7454 @node Other Compilers
7455 @chapter Other Compilers
7456
7457 An individual Fortran source file can be compiled to
7458 an object (@file{*.o}) file instead of to the final
7459 program executable.
7460 This allows several portions of a program to be compiled
7461 at different times and linked together whenever a new
7462 version of the program is needed.
7463 However, it introduces the issue of @dfn{object compatibility}
7464 across the various object files (and libraries, or @file{*.a}
7465 files) that are linked together to produce any particular
7466 executable file.
7467
7468 Object compatibility is an issue when combining, in one
7469 program, Fortran code compiled by more than one compiler
7470 (or more than one configuration of a compiler).
7471 If the compilers
7472 disagree on how to transform the names of procedures, there
7473 will normally be errors when linking such programs.
7474 Worse, if the compilers agree on naming, but disagree on issues
7475 like how to pass parameters, return arguments, and lay out
7476 @code{COMMON} areas, the earliest detected errors might be the
7477 incorrect results produced by the program (and that assumes
7478 these errors are detected, which is not always the case).
7479
7480 Normally, @code{g77} generates code that is
7481 object-compatible with code generated by a version of
7482 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
7483 to be generally compatible with @code{g77} as built by @code{gcc}.
7484 (Normally, @code{f2c} will, by default, conform to the appropriate
7485 configuration, but it is possible that older or perhaps even newer
7486 versions of @code{f2c}, or versions having certain configuration changes
7487 to @code{f2c} internals, will produce object files that are
7488 incompatible with @code{g77}.)
7489
7490 For example, a Fortran string subroutine
7491 argument will become two arguments on the C side: a @code{char *}
7492 and an @code{int} length.
7493
7494 Much of this compatibility results from the fact that
7495 @code{g77} uses the same run-time library,
7496 @code{libf2c}, used by @code{f2c},
7497 though @code{g77} gives its version the name @code{libg2c}
7498 so as to avoid conflicts when linking,
7499 installing them in the same directories,
7500 and so on.
7501
7502 Other compilers might or might not generate code that
7503 is object-compatible with @code{libg2c} and current @code{g77},
7504 and some might offer such compatibility only when explicitly
7505 selected via a command-line option to the compiler.
7506
7507 @emph{Note: This portion of the documentation definitely needs a lot
7508 of work!}
7509
7510 @menu
7511 * Dropping f2c Compatibility::  When speed is more important.
7512 * Compilers Other Than f2c::    Interoperation with code from other compilers.
7513 @end menu
7514
7515 @node Dropping f2c Compatibility
7516 @section Dropping @code{f2c} Compatibility
7517
7518 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
7519 some cases, faster code, by not needing to allow to the possibility
7520 of linking with code compiled by @code{f2c}.
7521
7522 For example, this affects how @code{REAL(KIND=1)},
7523 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
7524 With @samp{-fno-f2c}, they are
7525 compiled as returning the appropriate @code{gcc} type
7526 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
7527 in many configurations).
7528
7529 With @samp{-ff2c} in force, they
7530 are compiled differently (with perhaps slower run-time performance)
7531 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
7532 C as an intermediate language---@code{REAL(KIND=1)} functions
7533 return C's @code{double} type, while @code{COMPLEX} functions return
7534 @code{void} and use an extra argument pointing to a place for the functions to
7535 return their values.
7536
7537 It is possible that, in some cases, leaving @samp{-ff2c} in force
7538 might produce faster code than using @samp{-fno-f2c}.
7539 Feel free to experiment, but remember to experiment with changing the way
7540 @emph{entire programs and their Fortran libraries are compiled} at
7541 a time, since this sort of experimentation affects the interface
7542 of code generated for a Fortran source file---that is, it affects
7543 object compatibility.
7544
7545 Note that @code{f2c} compatibility is a fairly static target to achieve,
7546 though not necessarily perfectly so, since, like @code{g77}, it is
7547 still being improved.
7548 However, specifying @samp{-fno-f2c} causes @code{g77}
7549 to generate code that will probably be incompatible with code
7550 generated by future versions of @code{g77} when the same option
7551 is in force.
7552 You should make sure you are always able to recompile complete
7553 programs from source code when upgrading to new versions of @code{g77}
7554 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
7555
7556 Therefore, if you are using @code{g77} to compile libraries and other
7557 object files for possible future use and you don't want to require
7558 recompilation for future use with subsequent versions of @code{g77},
7559 you might want to stick with @code{f2c} compatibility for now, and
7560 carefully watch for any announcements about changes to the
7561 @code{f2c}/@code{libf2c} interface that might affect existing programs
7562 (thus requiring recompilation).
7563
7564 It is probable that a future version of @code{g77} will not,
7565 by default, generate object files compatible with @code{f2c},
7566 and that version probably would no longer use @code{libf2c}.
7567 If you expect to depend on this compatibility in the
7568 long term, use the options @samp{-ff2c -ff2c-library} when compiling
7569 all of the applicable code.
7570 This should cause future versions of @code{g77} either to produce
7571 compatible code (at the expense of the availability of some features and
7572 performance), or at the very least, to produce diagnostics.
7573
7574 (The library @code{g77} produces will no longer be named @file{libg2c}
7575 when it is no longer generally compatible with @file{libf2c}.
7576 It will likely be referred to, and, if installed as a distinct
7577 library, named @code{libg77}, or some other as-yet-unused name.)
7578
7579 @node Compilers Other Than f2c
7580 @section Compilers Other Than @code{f2c}
7581
7582 On systems with Fortran compilers other than @code{f2c} and @code{g77},
7583 code compiled by @code{g77} is not expected to work
7584 well with code compiled by the native compiler.
7585 (This is true for @code{f2c}-compiled objects as well.)
7586 Libraries compiled with the native compiler probably will have
7587 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
7588
7589 Reasons for such incompatibilities include:
7590
7591 @itemize @bullet
7592 @item
7593 There might be differences in the way names of Fortran procedures
7594 are translated for use in the system's object-file format.
7595 For example, the statement @samp{CALL FOO} might be compiled
7596 by @code{g77} to call a procedure the linker @code{ld} sees
7597 given the name @samp{_foo_}, while the apparently corresponding
7598 statement @samp{SUBROUTINE FOO} might be compiled by the
7599 native compiler to define the linker-visible name @samp{_foo},
7600 or @samp{_FOO_}, and so on.
7601
7602 @item
7603 There might be subtle type mismatches which cause subroutine arguments
7604 and function return values to get corrupted.
7605
7606 This is why simply getting @code{g77} to
7607 transform procedure names the same way a native
7608 compiler does is not usually a good idea---unless
7609 some effort has been made to ensure that, aside
7610 from the way the two compilers transform procedure
7611 names, everything else about the way they generate
7612 code for procedure interfaces is identical.
7613
7614 @item
7615 Native compilers
7616 use libraries of private I/O routines which will not be available
7617 at link time unless you have the native compiler---and you would
7618 have to explicitly ask for them.
7619
7620 For example, on the Sun you
7621 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
7622 command.
7623 @end itemize
7624
7625 @node Other Languages
7626 @chapter Other Languages
7627
7628 @emph{Note: This portion of the documentation definitely needs a lot
7629 of work!}
7630
7631 @menu
7632 * Interoperating with C and C++::
7633 @end menu
7634
7635 @node Interoperating with C and C++
7636 @section Tools and advice for interoperating with C and C++
7637
7638 @cindex C, linking with
7639 @cindex C++, linking with
7640 @cindex linking with C
7641 The following discussion assumes that you are running @code{g77} in @code{f2c}
7642 compatibility mode, i.e.@: not using @samp{-fno-f2c}.
7643 It provides some
7644 advice about quick and simple techniques for linking Fortran and C (or
7645 C++), the most common requirement.
7646 For the full story consult the
7647 description of code generation.
7648 @xref{Debugging and Interfacing}.
7649
7650 When linking Fortran and C, it's usually best to use @code{g77} to do
7651 the linking so that the correct libraries are included (including the
7652 maths one).
7653 If you're linking with C++ you will want to add
7654 @samp{-lstdc++}, @samp{-lg++} or whatever.
7655 If you need to use another
7656 driver program (or @code{ld} directly),
7657 you can find out what linkage
7658 options @code{g77} passes by running @samp{g77 -v}.
7659
7660 @menu
7661 * C Interfacing Tools::
7662 * C Access to Type Information::
7663 * f2c Skeletons and Prototypes::
7664 * C++ Considerations::
7665 * Startup Code::
7666 @end menu
7667
7668 @node C Interfacing Tools
7669 @subsection C Interfacing Tools
7670 @pindex f2c
7671 @cindex cfortran.h
7672 @cindex Netlib
7673 Even if you don't actually use it as a compiler, @code{f2c} from
7674 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
7675 interfacing (linking) Fortran and C@.
7676 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
7677
7678 To use @code{f2c} for this purpose you only need retrieve and
7679 build the @file{src} directory from the distribution, consult the
7680 @file{README} instructions there for machine-specifics, and install the
7681 @code{f2c} program on your path.
7682
7683 Something else that might be useful is @samp{cfortran.h} from
7684 @uref{ftp://zebra.desy.de/cfortran}.
7685 This is a fairly general tool which
7686 can be used to generate interfaces for calling in both directions
7687 between Fortran and C@.
7688 It can be used in @code{f2c} mode with
7689 @code{g77}---consult its documentation for details.
7690
7691 @node C Access to Type Information
7692 @subsection Accessing Type Information in C
7693
7694 @cindex types, Fortran/C
7695 Generally, C code written to link with
7696 @code{g77} code---calling and/or being
7697 called from Fortran---should @samp{#include <g2c.h>} to define the C
7698 versions of the Fortran types.
7699 Don't assume Fortran @code{INTEGER} types
7700 correspond to C @code{int}s, for instance; instead, declare them as
7701 @code{integer}, a type defined by @file{g2c.h}.
7702 @file{g2c.h} is installed where @code{gcc} will find it by
7703 default, assuming you use a copy of @code{gcc} compatible with
7704 @code{g77}, probably built at the same time as @code{g77}.
7705
7706 @node f2c Skeletons and Prototypes
7707 @subsection Generating Skeletons and Prototypes with @code{f2c}
7708
7709 @pindex f2c
7710 @cindex -fno-second-underscore
7711 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@: to
7712 interface with an existing library---is to write a file (named, for
7713 example, @file{fred.f}) of dummy Fortran
7714 skeletons comprising just the declaration of the routine(s) and dummy
7715 arguments plus @code{END} statements.
7716 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
7717 into which you can edit
7718 useful code, confident the calling sequence is correct, at least.
7719 (There are some errors otherwise commonly made in generating C
7720 interfaces with @code{f2c} conventions,
7721 such as not using @code{doublereal}
7722 as the return type of a @code{REAL} @code{FUNCTION}.)
7723
7724 @pindex ftnchek
7725 @code{f2c} also can help with calling Fortran from C, using its
7726 @samp{-P} option to generate C prototypes appropriate for calling the
7727 Fortran.@footnote{The files generated like this can also be used for
7728 inter-unit consistency checking of dummy and actual arguments, although
7729 the @code{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
7730 or @uref{ftp://ftp.dsm.fordham.edu} is
7731 probably better for this purpose.}
7732 If the Fortran code containing any
7733 routines to be called from C is in file @file{joe.f}, use the command
7734 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
7735 prototype information.
7736 @code{#include} this in the C which has to call
7737 the Fortran routines to make sure you get it right.
7738
7739 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
7740 between the way Fortran (including compilers like @code{g77}) and
7741 C handle arrays.
7742
7743 @node C++ Considerations
7744 @subsection C++ Considerations
7745
7746 @cindex C++
7747 @code{f2c} can be used to generate suitable code for compilation with a
7748 C++ system using the @samp{-C++} option.
7749 The important thing about linking @code{g77}-compiled
7750 code with C++ is that the prototypes for the @code{g77}
7751 routines must specify C linkage to avoid name mangling.
7752 So, use an @samp{extern "C"} declaration.
7753 @code{f2c}'s @samp{-C++} option will take care
7754 of this when generating skeletons or prototype files as above, and also
7755 avoid clashes with C++ reserved words in addition to those in C@.
7756
7757 @node Startup Code
7758 @subsection Startup Code
7759
7760 @cindex startup code
7761 @cindex run-time, initialization
7762 @cindex initialization, run-time
7763 Unlike with some runtime systems,
7764 it shouldn't be necessary
7765 (unless there are bugs)
7766 to use a Fortran main program unit to ensure the
7767 runtime---specifically the I/O system---is initialized.
7768
7769 However, to use the @code{g77} intrinsics @code{GETARG} and @code{IARGC},
7770 either the @code{main} routine from the @file{libg2c} library must be used,
7771 or the @code{f_setarg} routine
7772 (new as of @code{egcs} version 1.1 and @code{g77} version 0.5.23)
7773 must be called with the appropriate @code{argc} and @code{argv} arguments
7774 prior to the program calling @code{GETARG} or @code{IARGC}.
7775
7776 To provide more flexibility for mixed-language programming
7777 involving @code{g77} while allowing for shared libraries,
7778 as of @code{egcs} version 1.1 and @code{g77} version 0.5.23,
7779 @code{g77}'s @code{main} routine in @code{libg2c}
7780 does the following, in order:
7781
7782 @enumerate
7783 @item
7784 Calls @code{f_setarg}
7785 with the incoming @code{argc} and @code{argv} arguments,
7786 in the same order as for @code{main} itself.
7787
7788 This sets up the command-line environment
7789 for @code{GETARG} and @code{IARGC}.
7790
7791 @item
7792 Calls @code{f_setsig} (with no arguments).
7793
7794 This sets up the signaling and exception environment.
7795
7796 @item
7797 Calls @code{f_init} (with no arguments).
7798
7799 This initializes the I/O environment,
7800 though that should not be necessary,
7801 as all I/O functions in @code{libf2c}
7802 are believed to call @code{f_init} automatically,
7803 if necessary.
7804
7805 (A future version of @code{g77} might skip this explicit step,
7806 to speed up normal exit of a program.)
7807
7808 @item
7809 Arranges for @code{f_exit} to be called (with no arguments)
7810 when the program exits.
7811
7812 This ensures that the I/O environment is properly shut down
7813 before the program exits normally.
7814 Otherwise, output buffers might not be fully flushed,
7815 scratch files might not be deleted, and so on.
7816
7817 The simple way @code{main} does this is
7818 to call @code{f_exit} itself after calling
7819 @code{MAIN__} (in the next step).
7820
7821 However, this does not catch the cases where the program
7822 might call @code{exit} directly,
7823 instead of using the @code{EXIT} intrinsic
7824 (implemented as @code{exit_} in @code{libf2c}).
7825
7826 So, @code{main} attempts to use
7827 the operating environment's @code{onexit} or @code{atexit}
7828 facility, if available,
7829 to cause @code{f_exit} to be called automatically
7830 upon any invocation of @code{exit}.
7831
7832 @item
7833 Calls @code{MAIN__} (with no arguments).
7834
7835 This starts executing the Fortran main program unit for
7836 the application.
7837 (Both @code{g77} and @code{f2c} currently compile a main
7838 program unit so that its global name is @code{MAIN__}.)
7839
7840 @item
7841 If no @code{onexit} or @code{atexit} is provided by the system,
7842 calls @code{f_exit}.
7843
7844 @item
7845 Calls @code{exit} with a zero argument,
7846 to signal a successful program termination.
7847
7848 @item
7849 Returns a zero value to the caller,
7850 to signal a successful program termination,
7851 in case @code{exit} doesn't exit on the system.
7852 @end enumerate
7853
7854 All of the above names are C @code{extern} names,
7855 i.e.@: not mangled.
7856
7857 When using the @code{main} procedure provided by @code{g77}
7858 without a Fortran main program unit,
7859 you need to provide @code{MAIN__}
7860 as the entry point for your C code.
7861 (Make sure you link the object file that defines that
7862 entry point with the rest of your program.)
7863
7864 To provide your own @code{main} procedure
7865 in place of @code{g77}'s,
7866 make sure you specify the object file defining that procedure
7867 @emph{before} @samp{-lg2c} on the @code{g77} command line.
7868 Since the @samp{-lg2c} option is implicitly provided,
7869 this is usually straightforward.
7870 (Use the @samp{--verbose} option to see how and where
7871 @code{g77} implicitly adds @samp{-lg2c} in a command line
7872 that will link the program.
7873 Feel free to specify @samp{-lg2c} explicitly,
7874 as appropriate.)
7875
7876 However, when providing your own @code{main},
7877 make sure you perform the appropriate tasks in the
7878 appropriate order.
7879 For example, if your @code{main} does not call @code{f_setarg},
7880 make sure the rest of your application does not call
7881 @code{GETARG} or @code{IARGC}.
7882
7883 And, if your @code{main} fails to ensure that @code{f_exit}
7884 is called upon program exit,
7885 some files might end up incompletely written,
7886 some scratch files might be left lying around,
7887 and some existing files being written might be left
7888 with old data not properly truncated at the end.
7889
7890 Note that, generally, the @code{g77} operating environment
7891 does not depend on a procedure named @code{MAIN__} actually
7892 being called prior to any other @code{g77}-compiled code.
7893 That is, @code{MAIN__} does not, itself,
7894 set up any important operating-environment characteristics
7895 upon which other code might depend.
7896 This might change in future versions of @code{g77},
7897 with appropriate notification in the release notes.
7898
7899 For more information, consult the source code for the above routines.
7900 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
7901 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
7902
7903 Also, the file @file{@value{path-g77}/com.c} contains the code @code{g77}
7904 uses to open-code (inline) references to @code{IARGC}.
7905
7906 @node Debugging and Interfacing
7907 @chapter Debugging and Interfacing
7908 @cindex debugging
7909 @cindex interfacing
7910 @cindex calling C routines
7911 @cindex C routines calling Fortran
7912 @cindex f2c compatibility
7913
7914 GNU Fortran currently generates code that is object-compatible with
7915 the @code{f2c} converter.
7916 Also, it avoids limitations in the current GBE, such as the
7917 inability to generate a procedure with
7918 multiple entry points, by generating code that is structured
7919 differently (in terms of procedure names, scopes, arguments, and
7920 so on) than might be expected.
7921
7922 As a result, writing code in other languages that calls on, is
7923 called by, or shares in-memory data with @code{g77}-compiled code generally
7924 requires some understanding of the way @code{g77} compiles code for
7925 various constructs.
7926
7927 Similarly, using a debugger to debug @code{g77}-compiled
7928 code, even if that debugger supports native Fortran debugging, generally
7929 requires this sort of information.
7930
7931 This section describes some of the basic information on how
7932 @code{g77} compiles code for constructs involving interfaces to other
7933 languages and to debuggers.
7934
7935 @emph{Caution:} Much or all of this information pertains to only the current
7936 release of @code{g77}, sometimes even to using certain compiler options
7937 with @code{g77} (such as @samp{-fno-f2c}).
7938 Do not write code that depends on this
7939 information without clearly marking said code as nonportable and
7940 subject to review for every new release of @code{g77}.
7941 This information
7942 is provided primarily to make debugging of code generated by this
7943 particular release of @code{g77} easier for the user, and partly to make
7944 writing (generally nonportable) interface code easier.
7945 Both of these
7946 activities require tracking changes in new version of @code{g77} as they
7947 are installed, because new versions can change the behaviors
7948 described in this section.
7949
7950 @menu
7951 * Main Program Unit::  How @code{g77} compiles a main program unit.
7952 * Procedures::         How @code{g77} constructs parameter lists
7953                        for procedures.
7954 * Functions::          Functions returning floating-point or character data.
7955 * Names::              Naming of user-defined variables, procedures, etc.
7956 * Common Blocks::      Accessing common variables while debugging.
7957 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
7958 * Complex Variables::  How @code{g77} performs complex arithmetic.
7959 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
7960 * Adjustable Arrays::  Special consideration for adjustable arrays.
7961 * Alternate Entry Points::  How @code{g77} implements alternate @code{ENTRY}.
7962 * Alternate Returns::  How @code{g77} handles alternate returns.
7963 * Assigned Statement Labels::  How @code{g77} handles @code{ASSIGN}.
7964 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
7965 @end menu
7966
7967 @node Main Program Unit
7968 @section Main Program Unit (PROGRAM)
7969 @cindex PROGRAM statement
7970 @cindex statements, PROGRAM
7971
7972 When @code{g77} compiles a main program unit, it gives it the public
7973 procedure name @code{MAIN__}.
7974 The @code{libg2c} library has the actual @code{main()} procedure
7975 as is typical of C-based environments, and
7976 it is this procedure that performs some initial start-up
7977 activity and then calls @code{MAIN__}.
7978
7979 Generally, @code{g77} and @code{libg2c} are designed so that you need not
7980 include a main program unit written in Fortran in your program---it
7981 can be written in C or some other language.
7982 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
7983 includes a bug fix for @code{libg2c} that solved a problem with using the
7984 @code{OPEN} statement as the first Fortran I/O activity in a program
7985 without a Fortran main program unit.
7986
7987 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
7988 your main program unit---that is, if you intend to compile a @code{main()}
7989 procedure using some other language---you should carefully
7990 examine the code for @code{main()} in @code{libg2c}, found in the source
7991 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
7992 might need to be done by your @code{main()} in order to provide the
7993 Fortran environment your Fortran code is expecting.
7994
7995 @cindex @code{IArgC} intrinsic
7996 @cindex intrinsics, @code{IArgC}
7997 @cindex @code{GetArg} intrinsic
7998 @cindex intrinsics, @code{GetArg}
7999 For example, @code{libg2c}'s @code{main()} sets up the information used by
8000 the @code{IARGC} and @code{GETARG} intrinsics.
8001 Bypassing @code{libg2c}'s @code{main()}
8002 without providing a substitute for this activity would mean
8003 that invoking @code{IARGC} and @code{GETARG} would produce undefined
8004 results.
8005
8006 @cindex debugging
8007 @cindex main program unit, debugging
8008 @cindex main()
8009 @cindex MAIN__()
8010 @cindex .gdbinit
8011 When debugging, one implication of the fact that @code{main()}, which
8012 is the place where the debugged program ``starts'' from the
8013 debugger's point of view, is in @code{libg2c} is that you won't be
8014 starting your Fortran program at a point you recognize as your
8015 Fortran code.
8016
8017 The standard way to get around this problem is to set a break
8018 point (a one-time, or temporary, break point will do) at
8019 the entrance to @code{MAIN__}, and then run the program.
8020 A convenient way to do so is to add the @code{gdb} command
8021
8022 @example
8023 tbreak MAIN__
8024 @end example
8025
8026 @noindent
8027 to the file @file{.gdbinit} in the directory in which you're debugging
8028 (using @code{gdb}).
8029
8030 After doing this, the debugger will see the current execution
8031 point of the program as at the beginning of the main program
8032 unit of your program.
8033
8034 Of course, if you really want to set a break point at some
8035 other place in your program and just start the program
8036 running, without first breaking at @code{MAIN__},
8037 that should work fine.
8038
8039 @node Procedures
8040 @section Procedures (SUBROUTINE and FUNCTION)
8041 @cindex procedures
8042 @cindex SUBROUTINE statement
8043 @cindex statements, SUBROUTINE
8044 @cindex FUNCTION statement
8045 @cindex statements, FUNCTION
8046 @cindex signature of procedures
8047
8048 Currently, @code{g77} passes arguments via reference---specifically,
8049 by passing a pointer to the location in memory of a variable, array,
8050 array element, a temporary location that holds the result of evaluating an
8051 expression, or a temporary or permanent location that holds the value
8052 of a constant.
8053
8054 Procedures that accept @code{CHARACTER} arguments are implemented by
8055 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
8056
8057 The first argument occupies the expected position in the
8058 argument list and has the user-specified name.
8059 This argument
8060 is a pointer to an array of characters, passed by the caller.
8061
8062 The second argument is appended to the end of the user-specified
8063 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
8064 is the user-specified name.
8065 This argument is of the C type @code{ftnlen}
8066 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
8067 is the number of characters the caller has allocated in the
8068 array pointed to by the first argument.
8069
8070 A procedure will ignore the length argument if @samp{X} is not declared
8071 @code{CHARACTER*(*)}, because for other declarations, it knows the
8072 length.
8073 Not all callers necessarily ``know'' this, however, which
8074 is why they all pass the extra argument.
8075
8076 The contents of the @code{CHARACTER} argument are specified by the
8077 address passed in the first argument (named after it).
8078 The procedure can read or write these contents as appropriate.
8079
8080 When more than one @code{CHARACTER} argument is present in the argument
8081 list, the length arguments are appended in the order
8082 the original arguments appear.
8083 So @samp{CALL FOO('HI','THERE')} is implemented in
8084 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
8085 does not provide the trailing null bytes on the constant
8086 strings (@code{f2c} does provide them, but they are unnecessary in
8087 a Fortran environment, and you should not expect them to be
8088 there).
8089
8090 Note that the above information applies to @code{CHARACTER} variables and
8091 arrays @strong{only}.
8092 It does @strong{not} apply to external @code{CHARACTER}
8093 functions or to intrinsic @code{CHARACTER} functions.
8094 That is, no second length argument is passed to @samp{FOO} in this case:
8095
8096 @example
8097 CHARACTER X
8098 EXTERNAL X
8099 CALL FOO(X)
8100 @end example
8101
8102 @noindent
8103 Nor does @samp{FOO} expect such an argument in this case:
8104
8105 @example
8106 SUBROUTINE FOO(X)
8107 CHARACTER X
8108 EXTERNAL X
8109 @end example
8110
8111 Because of this implementation detail, if a program has a bug
8112 such that there is disagreement as to whether an argument is
8113 a procedure, and the type of the argument is @code{CHARACTER}, subtle
8114 symptoms might appear.
8115
8116 @node Functions
8117 @section Functions (FUNCTION and RETURN)
8118 @cindex functions
8119 @cindex FUNCTION statement
8120 @cindex statements, FUNCTION
8121 @cindex RETURN statement
8122 @cindex statements, RETURN
8123 @cindex return type of functions
8124
8125 @code{g77} handles in a special way functions that return the following
8126 types:
8127
8128 @itemize @bullet
8129 @item
8130 @code{CHARACTER}
8131 @item
8132 @code{COMPLEX}
8133 @item
8134 @code{REAL(KIND=1)}
8135 @end itemize
8136
8137 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
8138 returning @code{void})
8139 with two arguments prepended: @samp{__g77_result}, which the caller passes
8140 as a pointer to a @code{char} array expected to hold the return value,
8141 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
8142 specifying the length of the return value as declared in the calling
8143 program.
8144 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
8145 to determine the size of the array that @samp{__g77_result} points to;
8146 otherwise, it ignores that argument.
8147
8148 For @code{COMPLEX}, when @samp{-ff2c} is in
8149 force, @code{g77} implements
8150 a subroutine with one argument prepended: @samp{__g77_result}, which the
8151 caller passes as a pointer to a variable of the type of the function.
8152 The called function writes the return value into this variable instead
8153 of returning it as a function value.
8154 When @samp{-fno-f2c} is in force,
8155 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
8156 @samp{__complex__ float} or @samp{__complex__ double} function
8157 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
8158 returning the result of the function in the same way as @code{gcc} would.
8159
8160 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
8161 a function that actually returns @code{REAL(KIND=2)} (typically
8162 C's @code{double} type).
8163 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
8164 functions return @code{float}.
8165
8166 @node Names
8167 @section Names
8168 @cindex symbol names
8169 @cindex transforming symbol names
8170
8171 Fortran permits each implementation to decide how to represent
8172 names as far as how they're seen in other contexts, such as debuggers
8173 and when interfacing to other languages, and especially as far
8174 as how casing is handled.
8175
8176 External names---names of entities that are public, or ``accessible'',
8177 to all modules in a program---normally have an underscore (@samp{_})
8178 appended by @code{g77},
8179 to generate code that is compatible with @code{f2c}.
8180 External names include names of Fortran things like common blocks,
8181 external procedures (subroutines and functions, but not including
8182 statement functions, which are internal procedures), and entry point
8183 names.
8184
8185 However, use of the @samp{-fno-underscoring} option
8186 disables this kind of transformation of external names (though inhibiting
8187 the transformation certainly improves the chances of colliding with
8188 incompatible externals written in other languages---but that
8189 might be intentional.
8190
8191 @cindex -fno-underscoring option
8192 @cindex options, -fno-underscoring
8193 @cindex -fno-second-underscore option
8194 @cindex options, -fno-underscoring
8195 When @samp{-funderscoring} is in force, any name (external or local)
8196 that already has at least one underscore in it is
8197 implemented by @code{g77} by appending two underscores.
8198 (This second underscore can be disabled via the
8199 @samp{-fno-second-underscore} option.)
8200 External names are changed this way for @code{f2c} compatibility.
8201 Local names are changed this way to avoid collisions with external names
8202 that are different in the source code---@code{f2c} does the same thing, but
8203 there's no compatibility issue there except for user expectations while
8204 debugging.
8205
8206 For example:
8207
8208 @example
8209 Max_Cost = 0
8210 @end example
8211
8212 @cindex debugging
8213 @noindent
8214 Here, a user would, in the debugger, refer to this variable using the
8215 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
8216 as described below).
8217 (We hope to improve @code{g77} in this regard in the future---don't
8218 write scripts depending on this behavior!
8219 Also, consider experimenting with the @samp{-fno-underscoring}
8220 option to try out debugging without having to massage names by
8221 hand like this.)
8222
8223 @code{g77} provides a number of command-line options that allow the user
8224 to control how case mapping is handled for source files.
8225 The default is the traditional UNIX model for Fortran compilers---names
8226 are mapped to lower case.
8227 Other command-line options can be specified to map names to upper
8228 case, or to leave them exactly as written in the source file.
8229
8230 For example:
8231
8232 @example
8233 Foo = 9.436
8234 @end example
8235
8236 @noindent
8237 Here, it is normally the case that the variable assigned will be named
8238 @samp{foo}.
8239 This would be the name to enter when using a debugger to
8240 access the variable.
8241
8242 However, depending on the command-line options specified, the
8243 name implemented by @code{g77} might instead be @samp{FOO} or even
8244 @samp{Foo}, thus affecting how debugging is done.
8245
8246 Also:
8247
8248 @example
8249 Call Foo
8250 @end example
8251
8252 @noindent
8253 This would normally call a procedure that, if it were in a separate C program,
8254 be defined starting with the line:
8255
8256 @example
8257 void foo_()
8258 @end example
8259
8260 @noindent
8261 However, @code{g77} command-line options could be used to change the casing
8262 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
8263 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
8264 could be used to inhibit the appending of the underscore to the name.
8265
8266 @node Common Blocks
8267 @section Common Blocks (COMMON)
8268 @cindex common blocks
8269 @cindex @code{COMMON} statement
8270 @cindex statements, @code{COMMON}
8271
8272 @code{g77} names and lays out @code{COMMON} areas
8273 the same way @code{f2c} does,
8274 for compatibility with @code{f2c}.
8275
8276 @node Local Equivalence Areas
8277 @section Local Equivalence Areas (EQUIVALENCE)
8278 @cindex equivalence areas
8279 @cindex local equivalence areas
8280 @cindex EQUIVALENCE statement
8281 @cindex statements, EQUIVALENCE
8282
8283 @code{g77} treats storage-associated areas involving a @code{COMMON}
8284 block as explained in the section on common blocks.
8285
8286 A local @code{EQUIVALENCE} area is a collection of variables and arrays
8287 connected to each other in any way via @code{EQUIVALENCE}, none of which are
8288 listed in a @code{COMMON} statement.
8289
8290 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
8291 for @var{x} using a different method when more than one name was
8292 in the list of names of entities placed at the beginning of the
8293 array.
8294 Though the documentation specified that the first name listed in
8295 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
8296 in fact chose the name using a method that was so complicated,
8297 it seemed easier to change it to an alphabetical sort than to describe the
8298 previous method in the documentation.)
8299
8300 @node Complex Variables
8301 @section Complex Variables (COMPLEX)
8302 @cindex complex variables
8303 @cindex imaginary part
8304 @cindex COMPLEX statement
8305 @cindex statements, COMPLEX
8306
8307 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
8308 (and related intrinsics, constants, functions, and so on)
8309 in a manner that
8310 makes direct debugging involving these types in Fortran
8311 language mode difficult.
8312
8313 Essentially, @code{g77} implements these types using an
8314 internal construct similar to C's @code{struct}, at least
8315 as seen by the @code{gcc} back end.
8316
8317 Currently, the back end, when outputting debugging info with
8318 the compiled code for the assembler to digest, does not detect
8319 these @code{struct} types as being substitutes for Fortran
8320 complex.
8321 As a result, the Fortran language modes of debuggers such as
8322 @code{gdb} see these types as C @code{struct} types, which
8323 they might or might not support.
8324
8325 Until this is fixed, switch to C language mode to work with
8326 entities of @code{COMPLEX} type and then switch back to Fortran language
8327 mode afterward.
8328 (In @code{gdb}, this is accomplished via @samp{set lang c} and
8329 either @samp{set lang fortran} or @samp{set lang auto}.)
8330
8331 @node Arrays
8332 @section Arrays (DIMENSION)
8333 @cindex DIMENSION statement
8334 @cindex statements, DIMENSION
8335 @cindex array ordering
8336 @cindex ordering, array
8337 @cindex column-major ordering
8338 @cindex row-major ordering
8339 @cindex arrays
8340
8341 Fortran uses ``column-major ordering'' in its arrays.
8342 This differs from other languages, such as C, which use ``row-major ordering''.
8343 The difference is that, with Fortran, array elements adjacent to
8344 each other in memory differ in the @emph{first} subscript instead of
8345 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
8346 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
8347
8348 This consideration
8349 affects not only interfacing with and debugging Fortran code,
8350 it can greatly affect how code is designed and written, especially
8351 when code speed and size is a concern.
8352
8353 Fortran also differs from C, a popular language for interfacing and
8354 to support directly in debuggers, in the way arrays are treated.
8355 In C, arrays are single-dimensional and have interesting relationships
8356 to pointers, neither of which is true for Fortran.
8357 As a result, dealing with Fortran arrays from within
8358 an environment limited to C concepts can be challenging.
8359
8360 For example, accessing the array element @samp{A(5,10,20)} is easy enough
8361 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
8362 are needed.
8363 First, C would treat the A array as a single-dimension array.
8364 Second, C does not understand low bounds for arrays as does Fortran.
8365 Third, C assumes a low bound of zero (0), while Fortran defaults to a
8366 low bound of one (1) and can supports an arbitrary low bound.
8367 Therefore, calculations must be done
8368 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
8369 calculations require knowing the dimensions of @samp{A}.
8370
8371 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
8372 @samp{A(5,10,20)} would be:
8373
8374 @example
8375   (5-2)
8376 + (10-1)*(11-2+1)
8377 + (20-0)*(11-2+1)*(21-1+1)
8378 = 4293
8379 @end example
8380
8381 @noindent
8382 So the C equivalent in this case would be @samp{a[4293]}.
8383
8384 When using a debugger directly on Fortran code, the C equivalent
8385 might not work, because some debuggers cannot understand the notion
8386 of low bounds other than zero.  However, unlike @code{f2c}, @code{g77}
8387 does inform the GBE that a multi-dimensional array (like @samp{A}
8388 in the above example) is really multi-dimensional, rather than a
8389 single-dimensional array, so at least the dimensionality of the array
8390 is preserved.
8391
8392 Debuggers that understand Fortran should have no trouble with
8393 non-zero low bounds, but for non-Fortran debuggers, especially
8394 C debuggers, the above example might have a C equivalent of
8395 @samp{a[4305]}.
8396 This calculation is arrived at by eliminating the subtraction
8397 of the lower bound in the first parenthesized expression on each
8398 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
8399 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
8400 Actually, the implication of
8401 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
8402 but that @samp{a[20][10][5]} produces the equivalent of
8403 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
8404
8405 Come to think of it, perhaps
8406 the behavior is due to the debugger internally compensating for
8407 the lower bounds by offsetting the base address of @samp{a}, leaving
8408 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
8409 its first element as identified by subscripts equal to the
8410 corresponding lower bounds).
8411
8412 You know, maybe nobody really needs to use arrays.
8413
8414 @node Adjustable Arrays
8415 @section Adjustable Arrays (DIMENSION)
8416 @cindex arrays, adjustable
8417 @cindex adjustable arrays
8418 @cindex arrays, automatic
8419 @cindex automatic arrays
8420 @cindex DIMENSION statement
8421 @cindex statements, DIMENSION
8422 @cindex dimensioning arrays
8423 @cindex arrays, dimensioning
8424
8425 Adjustable and automatic arrays in Fortran require the implementation
8426 (in this
8427 case, the @code{g77} compiler) to ``memorize'' the expressions that
8428 dimension the arrays each time the procedure is invoked.
8429 This is so that subsequent changes to variables used in those
8430 expressions, made during execution of the procedure, do not
8431 have any effect on the dimensions of those arrays.
8432
8433 For example:
8434
8435 @example
8436 REAL ARRAY(5)
8437 DATA ARRAY/5*2/
8438 CALL X(ARRAY, 5)
8439 END
8440 SUBROUTINE X(A, N)
8441 DIMENSION A(N)
8442 N = 20
8443 PRINT *, N, A
8444 END
8445 @end example
8446
8447 @noindent
8448 Here, the implementation should, when running the program, print something
8449 like:
8450
8451 @example
8452 20   2.  2.  2.  2.  2.
8453 @end example
8454
8455 @noindent
8456 Note that this shows that while the value of @samp{N} was successfully
8457 changed, the size of the @samp{A} array remained at 5 elements.
8458
8459 To support this, @code{g77} generates code that executes before any user
8460 code (and before the internally generated computed @code{GOTO} to handle
8461 alternate entry points, as described below) that evaluates each
8462 (nonconstant) expression in the list of subscripts for an
8463 array, and saves the result of each such evaluation to be used when
8464 determining the size of the array (instead of re-evaluating the
8465 expressions).
8466
8467 So, in the above example, when @samp{X} is first invoked, code is
8468 executed that copies the value of @samp{N} to a temporary.
8469 And that same temporary serves as the actual high bound for the single
8470 dimension of the @samp{A} array (the low bound being the constant 1).
8471 Since the user program cannot (legitimately) change the value
8472 of the temporary during execution of the procedure, the size
8473 of the array remains constant during each invocation.
8474
8475 For alternate entry points, the code @code{g77} generates takes into
8476 account the possibility that a dummy adjustable array is not actually
8477 passed to the actual entry point being invoked at that time.
8478 In that case, the public procedure implementing the entry point
8479 passes to the master private procedure implementing all the
8480 code for the entry points a @code{NULL} pointer where a pointer to that
8481 adjustable array would be expected.
8482 The @code{g77}-generated code
8483 doesn't attempt to evaluate any of the expressions in the subscripts
8484 for an array if the pointer to that array is @code{NULL} at run time in
8485 such cases.
8486 (Don't depend on this particular implementation
8487 by writing code that purposely passes @code{NULL} pointers where the
8488 callee expects adjustable arrays, even if you know the callee
8489 won't reference the arrays---nor should you pass @code{NULL} pointers
8490 for any dummy arguments used in calculating the bounds of such
8491 arrays or leave undefined any values used for that purpose in
8492 COMMON---because the way @code{g77} implements these things might
8493 change in the future!)
8494
8495 @node Alternate Entry Points
8496 @section Alternate Entry Points (ENTRY)
8497 @cindex alternate entry points
8498 @cindex entry points
8499 @cindex ENTRY statement
8500 @cindex statements, ENTRY
8501
8502 The GBE does not understand the general concept of
8503 alternate entry points as Fortran provides via the ENTRY statement.
8504 @code{g77} gets around this by using an approach to compiling procedures
8505 having at least one @code{ENTRY} statement that is almost identical to the
8506 approach used by @code{f2c}.
8507 (An alternate approach could be used that
8508 would probably generate faster, but larger, code that would also
8509 be a bit easier to debug.)
8510
8511 Information on how @code{g77} implements @code{ENTRY} is provided for those
8512 trying to debug such code.
8513 The choice of implementation seems
8514 unlikely to affect code (compiled in other languages) that interfaces
8515 to such code.
8516
8517 @code{g77} compiles exactly one public procedure for the primary entry
8518 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
8519 That is, in terms of the public interface, there is no difference
8520 between
8521
8522 @example
8523 SUBROUTINE X
8524 END
8525 SUBROUTINE Y
8526 END
8527 @end example
8528
8529 @noindent
8530 and:
8531
8532 @example
8533 SUBROUTINE X
8534 ENTRY Y
8535 END
8536 @end example
8537
8538 The difference between the above two cases lies in the code compiled
8539 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
8540 for the second case, an extra internal procedure is compiled.
8541
8542 For every Fortran procedure with at least one @code{ENTRY}
8543 statement, @code{g77} compiles an extra procedure
8544 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
8545 the name of the primary entry point (which, in the above case,
8546 using the standard compiler options, would be @samp{x_} in C).
8547
8548 This extra procedure is compiled as a private procedure---that is,
8549 a procedure not accessible by name to separately compiled modules.
8550 It contains all the code in the program unit, including the code
8551 for the primary entry point plus for every entry point.
8552 (The code for each public procedure is quite short, and explained later.)
8553
8554 The extra procedure has some other interesting characteristics.
8555
8556 The argument list for this procedure is invented by @code{g77}.
8557 It contains
8558 a single integer argument named @samp{__g77_which_entrypoint},
8559 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
8560 entry point index---0 for the primary entry point, 1 for the
8561 first entry point (the first @code{ENTRY} statement encountered), 2 for
8562 the second entry point, and so on.
8563
8564 It also contains, for functions returning @code{CHARACTER} and
8565 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
8566 and for functions returning different types among the
8567 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
8568 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
8569 is expected at run time to contain a pointer to where to store
8570 the result of the entry point.
8571 For @code{CHARACTER} functions, this
8572 storage area is an array of the appropriate number of characters;
8573 for @code{COMPLEX} functions, it is the appropriate area for the return
8574 type; for multiple-return-type functions, it is a union of all the supported return
8575 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
8576 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
8577 is not supported by @code{g77}).
8578
8579 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
8580 by yet another argument named @samp{__g77_length} that, at run time,
8581 specifies the caller's expected length of the returned value.
8582 Note that only @code{CHARACTER*(*)} functions and entry points actually
8583 make use of this argument, even though it is always passed by
8584 all callers of public @code{CHARACTER} functions (since the caller does not
8585 generally know whether such a function is @code{CHARACTER*(*)} or whether
8586 there are any other callers that don't have that information).
8587
8588 The rest of the argument list is the union of all the arguments
8589 specified for all the entry points (in their usual forms, e.g.
8590 @code{CHARACTER} arguments have extra length arguments, all appended at
8591 the end of this list).
8592 This is considered the ``master list'' of
8593 arguments.
8594
8595 The code for this procedure has, before the code for the first
8596 executable statement, code much like that for the following Fortran
8597 statement:
8598
8599 @smallexample
8600        GOTO (100000,100001,100002), __g77_which_entrypoint
8601 100000 @dots{}code for primary entry point@dots{}
8602 100001 @dots{}code immediately following first ENTRY statement@dots{}
8603 100002 @dots{}code immediately following second ENTRY statement@dots{}
8604 @end smallexample
8605
8606 @noindent
8607 (Note that invalid Fortran statement labels and variable names
8608 are used in the above example to highlight the fact that it
8609 represents code generated by the @code{g77} internals, not code to be
8610 written by the user.)
8611
8612 It is this code that, when the procedure is called, picks which
8613 entry point to start executing.
8614
8615 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
8616 example), those procedures are fairly simple.
8617 Their interfaces
8618 are just like they would be if they were self-contained procedures
8619 (without @code{ENTRY}), of course, since that is what the callers
8620 expect.
8621 Their code consists of simply calling the private
8622 procedure, described above, with the appropriate extra arguments
8623 (the entry point index, and perhaps a pointer to a multiple-type-
8624 return variable, local to the public procedure, that contains
8625 all the supported returnable non-character types).
8626 For arguments
8627 that are not listed for a given entry point that are listed for
8628 other entry points, and therefore that are in the ``master list''
8629 for the private procedure, null pointers (in C, the @code{NULL} macro)
8630 are passed.
8631 Also, for entry points that are part of a multiple-type-
8632 returning function, code is compiled after the call of the private
8633 procedure to extract from the multi-type union the appropriate result,
8634 depending on the type of the entry point in question, returning
8635 that result to the original caller.
8636
8637 When debugging a procedure containing alternate entry points, you
8638 can either set a break point on the public procedure itself (e.g.
8639 a break point on @samp{X} or @samp{Y}) or on the private procedure that
8640 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
8641 If you do the former, you should use the debugger's command to
8642 ``step into'' the called procedure to get to the actual code; with
8643 the latter approach, the break point leaves you right at the
8644 actual code, skipping over the public entry point and its call
8645 to the private procedure (unless you have set a break point there
8646 as well, of course).
8647
8648 Further, the list of dummy arguments that is visible when the
8649 private procedure is active is going to be the expanded version
8650 of the list for whichever particular entry point is active,
8651 as explained above, and the way in which return values are
8652 handled might well be different from how they would be handled
8653 for an equivalent single-entry function.
8654
8655 @node Alternate Returns
8656 @section Alternate Returns (SUBROUTINE and RETURN)
8657 @cindex subroutines
8658 @cindex alternate returns
8659 @cindex SUBROUTINE statement
8660 @cindex statements, SUBROUTINE
8661 @cindex RETURN statement
8662 @cindex statements, RETURN
8663
8664 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
8665 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
8666 the C @code{int} type.
8667 The actual alternate-return arguments are omitted from the calling sequence.
8668 Instead, the caller uses
8669 the return value to do a rough equivalent of the Fortran
8670 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
8671 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
8672 function), and the callee just returns whatever integer
8673 is specified in the @code{RETURN} statement for the subroutine
8674 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
8675 by @samp{RETURN}
8676 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
8677
8678 @node Assigned Statement Labels
8679 @section Assigned Statement Labels (ASSIGN and GOTO)
8680 @cindex assigned statement labels
8681 @cindex statement labels, assigned
8682 @cindex ASSIGN statement
8683 @cindex statements, ASSIGN
8684 @cindex GOTO statement
8685 @cindex statements, GOTO
8686
8687 For portability to machines where a pointer (such as to a label,
8688 which is how @code{g77} implements @code{ASSIGN} and its relatives,
8689 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
8690 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
8691 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
8692 than it does the numerical value in that variable, unless the
8693 variable is wide enough (can hold enough bits).
8694
8695 In particular, while @code{g77} implements
8696
8697 @example
8698 I = 10
8699 @end example
8700
8701 @noindent
8702 as, in C notation, @samp{i = 10;}, it implements
8703
8704 @example
8705 ASSIGN 10 TO I
8706 @end example
8707
8708 @noindent
8709 as, in GNU's extended C notation (for the label syntax),
8710 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
8711 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
8712 actually generate the name @samp{L10} or any other name like that,
8713 since debuggers cannot access labels anyway).
8714
8715 While this currently means that an @code{ASSIGN} statement does not
8716 overwrite the numeric contents of its target variable, @emph{do not}
8717 write any code depending on this feature.
8718 @code{g77} has already changed this implementation across
8719 versions and might do so in the future.
8720 This information is provided only to make debugging Fortran programs
8721 compiled with the current version of @code{g77} somewhat easier.
8722 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
8723 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
8724 means @code{g77} has decided it can store the pointer to the label directly
8725 into @samp{I} itself.
8726
8727 @xref{Ugly Assigned Labels}, for information on a command-line option
8728 to force @code{g77} to use the same storage for both normal and
8729 assigned-label uses of a variable.
8730
8731 @node Run-time Library Errors
8732 @section Run-time Library Errors
8733 @cindex IOSTAT=
8734 @cindex error values
8735 @cindex error messages
8736 @cindex messages, run-time
8737 @cindex I/O, errors
8738
8739 The @code{libg2c} library currently has the following table to relate
8740 error code numbers, returned in @code{IOSTAT=} variables, to messages.
8741 This information should, in future versions of this document, be
8742 expanded upon to include detailed descriptions of each message.
8743
8744 In line with good coding practices, any of the numbers in the
8745 list below should @emph{not} be directly written into Fortran
8746 code you write.
8747 Instead, make a separate @code{INCLUDE} file that defines
8748 @code{PARAMETER} names for them, and use those in your code,
8749 so you can more easily change the actual numbers in the future.
8750
8751 The information below is culled from the definition
8752 of @code{F_err} in @file{f/runtime/libI77/err.c} in the
8753 @code{g77} source tree.
8754
8755 @smallexample
8756 100: "error in format"
8757 101: "illegal unit number"
8758 102: "formatted io not allowed"
8759 103: "unformatted io not allowed"
8760 104: "direct io not allowed"
8761 105: "sequential io not allowed"
8762 106: "can't backspace file"
8763 107: "null file name"
8764 108: "can't stat file"
8765 109: "unit not connected"
8766 110: "off end of record"
8767 111: "truncation failed in endfile"
8768 112: "incomprehensible list input"
8769 113: "out of free space"
8770 114: "unit not connected"
8771 115: "read unexpected character"
8772 116: "bad logical input field"
8773 117: "bad variable type"
8774 118: "bad namelist name"
8775 119: "variable not in namelist"
8776 120: "no end record"
8777 121: "variable count incorrect"
8778 122: "subscript for scalar variable"
8779 123: "invalid array section"
8780 124: "substring out of bounds"
8781 125: "subscript out of bounds"
8782 126: "can't read file"
8783 127: "can't write file"
8784 128: "'new' file exists"
8785 129: "can't append to file"
8786 130: "non-positive record number"
8787 131: "I/O started while already doing I/O"
8788 @end smallexample
8789
8790 @node Collected Fortran Wisdom
8791 @chapter Collected Fortran Wisdom
8792 @cindex wisdom
8793 @cindex legacy code
8794 @cindex code, legacy
8795 @cindex writing code
8796 @cindex code, writing
8797
8798 Most users of @code{g77} can be divided into two camps:
8799
8800 @itemize @bullet
8801 @item
8802 Those writing new Fortran code to be compiled by @code{g77}.
8803
8804 @item
8805 Those using @code{g77} to compile existing, ``legacy'' code.
8806 @end itemize
8807
8808 Users writing new code generally understand most of the necessary
8809 aspects of Fortran to write ``mainstream'' code, but often need
8810 help deciding how to handle problems, such as the construction
8811 of libraries containing @code{BLOCK DATA}.
8812
8813 Users dealing with ``legacy'' code sometimes don't have much
8814 experience with Fortran, but believe that the code they're compiling
8815 already works when compiled by other compilers (and might
8816 not understand why, as is sometimes the case, it doesn't work
8817 when compiled by @code{g77}).
8818
8819 The following information is designed to help users do a better job
8820 coping with existing, ``legacy'' Fortran code, and with writing
8821 new code as well.
8822
8823 @menu
8824 * Advantages Over f2c::        If @code{f2c} is so great, why @code{g77}?
8825 * Block Data and Libraries::   How @code{g77} solves a common problem.
8826 * Loops::                      Fortran @code{DO} loops surprise many people.
8827 * Working Programs::           Getting programs to work should be done first.
8828 * Overly Convenient Options::  Temptations to avoid, habits to not form.
8829 * Faster Programs::            Everybody wants these, but at what cost?
8830 @end menu
8831
8832 @node Advantages Over f2c
8833 @section Advantages Over f2c
8834
8835 Without @code{f2c}, @code{g77} would have taken much longer to
8836 do and probably not been as good for quite a while.
8837 Sometimes people who notice how much @code{g77} depends on, and
8838 documents encouragement to use, @code{f2c} ask why @code{g77}
8839 was created if @code{f2c} already existed.
8840
8841 This section gives some basic answers to these questions, though it
8842 is not intended to be comprehensive.
8843
8844 @menu
8845 * Language Extensions::  Features used by Fortran code.
8846 * Diagnostic Abilities:: Abilities to spot problems early.
8847 * Compiler Options::     Features helpful to accommodate legacy code, etc.
8848 * Compiler Speed::       Speed of the compilation process.
8849 * Program Speed::        Speed of the generated, optimized code.
8850 * Ease of Debugging::    Debugging ease-of-use at the source level.
8851 * Character and Hollerith Constants::  A byte saved is a byte earned.
8852 @end menu
8853
8854 @node Language Extensions
8855 @subsection Language Extensions
8856
8857 @code{g77} offers several extensions to FORTRAN 77 language that @code{f2c}
8858 doesn't:
8859
8860 @itemize @bullet
8861 @item
8862 Automatic arrays
8863
8864 @item
8865 @code{CYCLE} and @code{EXIT}
8866
8867 @item
8868 Construct names
8869
8870 @item
8871 @code{SELECT CASE}
8872
8873 @item
8874 @code{KIND=} and @code{LEN=} notation
8875
8876 @item
8877 Semicolon as statement separator
8878
8879 @item
8880 Constant expressions in @code{FORMAT} statements
8881 (such as @samp{FORMAT(I<J>)},
8882 where @samp{J} is a @code{PARAMETER} named constant)
8883
8884 @item
8885 @code{MvBits} intrinsic
8886
8887 @item
8888 @code{libU77} (Unix-compatibility) library,
8889 with routines known to compiler as intrinsics
8890 (so they work even when compiler options are used
8891 to change the interfaces used by Fortran routines)
8892 @end itemize
8893
8894 @code{g77} also implements iterative @code{DO} loops
8895 so that they work even in the presence of certain ``extreme'' inputs,
8896 unlike @code{f2c}.
8897 @xref{Loops}.
8898
8899 However, @code{f2c} offers a few that @code{g77} doesn't, such as:
8900
8901 @itemize @bullet
8902 @item
8903 Intrinsics in @code{PARAMETER} statements
8904
8905 @item
8906 Array bounds expressions (such as @samp{REAL M(N(2))})
8907
8908 @item
8909 @code{AUTOMATIC} statement
8910 @end itemize
8911
8912 It is expected that @code{g77} will offer some or all of these missing
8913 features at some time in the future.
8914
8915 @node Diagnostic Abilities
8916 @subsection Diagnostic Abilities
8917
8918 @code{g77} offers better diagnosis of problems in @code{FORMAT} statements.
8919 @code{f2c} doesn't, for example, emit any diagnostic for
8920 @samp{FORMAT(XZFAJG10324)},
8921 leaving that to be diagnosed, at run time, by
8922 the @code{libf2c} run-time library.
8923
8924 @node Compiler Options
8925 @subsection Compiler Options
8926
8927 @code{g77} offers compiler options that @code{f2c} doesn't,
8928 most of which are designed to more easily accommodate
8929 legacy code:
8930
8931 @itemize @bullet
8932 @item
8933 Two that control the automatic appending of extra
8934 underscores to external names
8935
8936 @item
8937 One that allows dollar signs (@samp{$}) in symbol names
8938
8939 @item
8940 A variety that control acceptance of various
8941 ``ugly'' constructs
8942
8943 @item
8944 Several that specify acceptable use of upper and lower case
8945 in the source code
8946
8947 @item
8948 Many that enable, disable, delete, or hide
8949 groups of intrinsics
8950
8951 @item
8952 One to specify the length of fixed-form source lines
8953 (normally 72)
8954
8955 @item
8956 One to specify the the source code is written in
8957 Fortran-90-style free-form
8958 @end itemize
8959
8960 However, @code{f2c} offers a few that @code{g77} doesn't,
8961 like an option to have @code{REAL} default to @code{REAL*8}.
8962 It is expected that @code{g77} will offer all of the
8963 missing options pertinent to being a Fortran compiler
8964 at some time in the future.
8965
8966 @node Compiler Speed
8967 @subsection Compiler Speed
8968
8969 Saving the steps of writing and then rereading C code is a big reason
8970 why @code{g77} should be able to compile code much faster than using
8971 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
8972
8973 However, due to @code{g77}'s youth, lots of self-checking is still being
8974 performed.
8975 As a result, this improvement is as yet unrealized
8976 (though the potential seems to be there for quite a big speedup
8977 in the future).
8978 It is possible that, as of version 0.5.18, @code{g77}
8979 is noticeably faster compiling many Fortran source files than using
8980 @code{f2c} in conjunction with @code{gcc}.
8981
8982 @node Program Speed
8983 @subsection Program Speed
8984
8985 @code{g77} has the potential to better optimize code than @code{f2c},
8986 even when @code{gcc} is used to compile the output of @code{f2c},
8987 because @code{f2c} must necessarily
8988 translate Fortran into a somewhat lower-level language (C) that cannot
8989 preserve all the information that is potentially useful for optimization,
8990 while @code{g77} can gather, preserve, and transmit that information directly
8991 to the GBE.
8992
8993 For example, @code{g77} implements @code{ASSIGN} and assigned
8994 @code{GOTO} using direct assignment of pointers to labels and direct
8995 jumps to labels, whereas @code{f2c} maps the assigned labels to
8996 integer values and then uses a C @code{switch} statement to encode
8997 the assigned @code{GOTO} statements.
8998
8999 However, as is typical, theory and reality don't quite match, at least
9000 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
9001 can generate code that is faster than @code{g77}.
9002
9003 Version 0.5.18 of @code{g77} offered default
9004 settings and options, via patches to the @code{gcc}
9005 back end, that allow for better program speed, though
9006 some of these improvements also affected the performance
9007 of programs translated by @code{f2c} and then compiled
9008 by @code{g77}'s version of @code{gcc}.
9009
9010 Version 0.5.20 of @code{g77} offers further performance
9011 improvements, at least one of which (alias analysis) is
9012 not generally applicable to @code{f2c} (though @code{f2c}
9013 could presumably be changed to also take advantage of
9014 this new capability of the @code{gcc} back end, assuming
9015 this is made available in an upcoming release of @code{gcc}).
9016
9017 @node Ease of Debugging
9018 @subsection Ease of Debugging
9019
9020 Because @code{g77} compiles directly to assembler code like @code{gcc},
9021 instead of translating to an intermediate language (C) as does @code{f2c},
9022 support for debugging can be better for @code{g77} than @code{f2c}.
9023
9024 However, although @code{g77} might be somewhat more ``native'' in terms of
9025 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
9026 of things ``not quite right''.
9027 Many of the important ones should be resolved in the near future.
9028
9029 For example, @code{g77} doesn't have to worry about reserved names
9030 like @code{f2c} does.
9031 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
9032 translate this to something @emph{other} than
9033 @samp{for = while;}, because C reserves those words.
9034
9035 However, @code{g77} does still uses things like an extra level of indirection
9036 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
9037 yet support multiple entry points.
9038
9039 Another example is that, given
9040
9041 @smallexample
9042 COMMON A, B
9043 EQUIVALENCE (B, C)
9044 @end smallexample
9045
9046 @noindent
9047 the @code{g77} user should be able to access the variables directly, by name,
9048 without having to traverse C-like structures and unions, while @code{f2c}
9049 is unlikely to ever offer this ability (due to limitations in the
9050 C language).
9051
9052 However, due to apparent bugs in the back end, @code{g77} currently doesn't
9053 take advantage of this facility at all---it doesn't emit any debugging
9054 information for @code{COMMON} and @code{EQUIVALENCE} areas,
9055 other than information
9056 on the array of @code{char} it creates (and, in the case
9057 of local @code{EQUIVALENCE}, names) for each such area.
9058
9059 Yet another example is arrays.
9060 @code{g77} represents them to the debugger
9061 using the same ``dimensionality'' as in the source code, while @code{f2c}
9062 must necessarily convert them all to one-dimensional arrays to fit
9063 into the confines of the C language.
9064 However, the level of support
9065 offered by debuggers for interactive Fortran-style access to arrays
9066 as compiled by @code{g77} can vary widely.
9067 In some cases, it can actually
9068 be an advantage that @code{f2c} converts everything to widely supported
9069 C semantics.
9070
9071 In fairness, @code{g77} could do many of the things @code{f2c} does
9072 to get things working at least as well as @code{f2c}---for now,
9073 the developers prefer making @code{g77} work the
9074 way they think it is supposed to, and finding help improving the
9075 other products (the back end of @code{gcc}; @code{gdb}; and so on)
9076 to get things working properly.
9077
9078 @node Character and Hollerith Constants
9079 @subsection Character and Hollerith Constants
9080 @cindex character constants
9081 @cindex constants, character
9082 @cindex Hollerith constants
9083 @cindex constants, Hollerith
9084 @cindex trailing null byte
9085 @cindex null byte, trailing
9086 @cindex zero byte, trailing
9087
9088 To avoid the extensive hassle that would be needed to avoid this,
9089 @code{f2c} uses C character constants to encode character and Hollerith
9090 constants.
9091 That means a constant like @samp{'HELLO'} is translated to
9092 @samp{"hello"} in C, which further means that an extra null byte is
9093 present at the end of the constant.
9094 This null byte is superfluous.
9095
9096 @code{g77} does not generate such null bytes.
9097 This represents significant
9098 savings of resources, such as on systems where @file{/dev/null} or
9099 @file{/dev/zero} represent bottlenecks in the systems' performance,
9100 because @code{g77} simply asks for fewer zeros from the operating
9101 system than @code{f2c}.
9102 (Avoiding spurious use of zero bytes, each byte typically have
9103 eight zero bits, also reduces the liabilities in case
9104 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
9105
9106 @node Block Data and Libraries
9107 @section Block Data and Libraries
9108 @cindex block data and libraries
9109 @cindex BLOCK DATA statement
9110 @cindex statements, BLOCK DATA
9111 @cindex libraries, containing BLOCK DATA
9112 @cindex f2c compatibility
9113 @cindex compatibility, f2c
9114
9115 To ensure that block data program units are linked, especially a concern
9116 when they are put into libraries, give each one a name (as in
9117 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
9118 statement in every program unit that uses any common block
9119 initialized by the corresponding @code{BLOCK DATA}.
9120 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
9121 @code{SUBROUTINE},
9122 that is, it generates an actual procedure having the appropriate name.
9123 The procedure does nothing but return immediately if it happens to be
9124 called.
9125 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
9126 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
9127 in the program and ensures that by generating a
9128 reference to it so the linker will make sure it is present.
9129 (Specifically, @code{g77} outputs in the data section a static pointer to the
9130 external name @samp{FOO}.)
9131
9132 The implementation @code{g77} currently uses to make this work is
9133 one of the few things not compatible with @code{f2c} as currently
9134 shipped.
9135 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
9136 issue a warning that @samp{FOO} is not otherwise referenced,
9137 and, for @samp{BLOCK DATA FOO},
9138 @code{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
9139 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
9140 this particular case.
9141 If you use @code{f2c} to compile @samp{BLOCK DATA FOO},
9142 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
9143 will result in an unresolved reference when linked.
9144 If you do the
9145 opposite, then @samp{FOO} might not be linked in under various
9146 circumstances (such as when @samp{FOO} is in a library, or you're
9147 using a ``clever'' linker---so clever, it produces a broken program
9148 with little or no warning by omitting initializations of global data
9149 because they are contained in unreferenced procedures).
9150
9151 The changes you make to your code to make @code{g77} handle this situation,
9152 however, appear to be a widely portable way to handle it.
9153 That is, many systems permit it (as they should, since the
9154 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
9155 is a block data program unit), and of the ones
9156 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
9157 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
9158 program units.
9159
9160 Here is the recommended approach to modifying a program containing
9161 a program unit such as the following:
9162
9163 @smallexample
9164 BLOCK DATA FOO
9165 COMMON /VARS/ X, Y, Z
9166 DATA X, Y, Z / 3., 4., 5. /
9167 END
9168 @end smallexample
9169
9170 @noindent
9171 If the above program unit might be placed in a library module, then
9172 ensure that every program unit in every program that references that
9173 particular @code{COMMON} area uses the @code{EXTERNAL} statement
9174 to force the area to be initialized.
9175
9176 For example, change a program unit that starts with
9177
9178 @smallexample
9179 INTEGER FUNCTION CURX()
9180 COMMON /VARS/ X, Y, Z
9181 CURX = X
9182 END
9183 @end smallexample
9184
9185 @noindent
9186 so that it uses the @code{EXTERNAL} statement, as in:
9187
9188 @smallexample
9189 INTEGER FUNCTION CURX()
9190 COMMON /VARS/ X, Y, Z
9191 EXTERNAL FOO
9192 CURX = X
9193 END
9194 @end smallexample
9195
9196 @noindent
9197 That way, @samp{CURX} is compiled by @code{g77} (and many other
9198 compilers) so that the linker knows it must include @samp{FOO},
9199 the @code{BLOCK DATA} program unit that sets the initial values
9200 for the variables in @samp{VAR}, in the executable program.
9201
9202 @node Loops
9203 @section Loops
9204 @cindex DO statement
9205 @cindex statements, DO
9206 @cindex trips, number of
9207 @cindex number of trips
9208
9209 The meaning of a @code{DO} loop in Fortran is precisely specified
9210 in the Fortran standard@dots{}and is quite different from what
9211 many programmers might expect.
9212
9213 In particular, Fortran iterative @code{DO} loops are implemented as if
9214 the number of trips through the loop is calculated @emph{before}
9215 the loop is entered.
9216
9217 The number of trips for a loop is calculated from the @var{start},
9218 @var{end}, and @var{increment} values specified in a statement such as:
9219
9220 @smallexample
9221 DO @var{iter} = @var{start}, @var{end}, @var{increment}
9222 @end smallexample
9223
9224 @noindent
9225 The trip count is evaluated using a fairly simple formula
9226 based on the three values following the @samp{=} in the
9227 statement, and it is that trip count that is effectively
9228 decremented during each iteration of the loop.
9229 If, at the beginning of an iteration of the loop, the
9230 trip count is zero or negative, the loop terminates.
9231 The per-loop-iteration modifications to @var{iter} are not
9232 related to determining whether to terminate the loop.
9233
9234 There are two important things to remember about the trip
9235 count:
9236
9237 @itemize @bullet
9238 @item
9239 It can be @emph{negative}, in which case it is
9240 treated as if it was zero---meaning the loop is
9241 not executed at all.
9242
9243 @item
9244 The type used to @emph{calculate} the trip count
9245 is the same type as @var{iter}, but the final
9246 calculation, and thus the type of the trip
9247 count itself, always is @code{INTEGER(KIND=1)}.
9248 @end itemize
9249
9250 These two items mean that there are loops that cannot
9251 be written in straightforward fashion using the Fortran @code{DO}.
9252
9253 For example, on a system with the canonical 32-bit two's-complement
9254 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
9255
9256 @smallexample
9257 DO I = -2000000000, 2000000000
9258 @end smallexample
9259
9260 @noindent
9261 Although the @var{start} and @var{end} values are well within
9262 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
9263 The expected trip count is 40000000001, which is outside
9264 the range of @code{INTEGER(KIND=1)} on many systems.
9265
9266 Instead, the above loop should be constructed this way:
9267
9268 @smallexample
9269 I = -2000000000
9270 DO
9271   IF (I .GT. 2000000000) EXIT
9272   @dots{}
9273   I = I + 1
9274 END DO
9275 @end smallexample
9276
9277 @noindent
9278 The simple @code{DO} construct and the @code{EXIT} statement
9279 (used to leave the innermost loop)
9280 are F90 features that @code{g77} supports.
9281
9282 Some Fortran compilers have buggy implementations of @code{DO},
9283 in that they don't follow the standard.
9284 They implement @code{DO} as a straightforward translation
9285 to what, in C, would be a @code{for} statement.
9286 Instead of creating a temporary variable to hold the trip count
9287 as calculated at run time, these compilers
9288 use the iteration variable @var{iter} to control
9289 whether the loop continues at each iteration.
9290
9291 The bug in such an implementation shows up when the
9292 trip count is within the range of the type of @var{iter},
9293 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
9294 exceeds that range.  For example:
9295
9296 @smallexample
9297 DO I = 2147483600, 2147483647
9298 @end smallexample
9299
9300 @noindent
9301 A loop started by the above statement will work as implemented
9302 by @code{g77}, but the use, by some compilers, of a
9303 more C-like implementation akin to
9304
9305 @smallexample
9306 for (i = 2147483600; i <= 2147483647; ++i)
9307 @end smallexample
9308
9309 @noindent
9310 produces a loop that does not terminate, because @samp{i}
9311 can never be greater than 2147483647, since incrementing it
9312 beyond that value overflows @samp{i}, setting it to -2147483648.
9313 This is a large, negative number that still is less than 2147483647.
9314
9315 Another example of unexpected behavior of @code{DO} involves
9316 using a nonintegral iteration variable @var{iter}, that is,
9317 a @code{REAL} variable.
9318 Consider the following program:
9319
9320 @smallexample
9321       DATA BEGIN, END, STEP /.1, .31, .007/
9322       DO 10 R = BEGIN, END, STEP
9323          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
9324          PRINT *,R
9325 10    CONTINUE
9326       PRINT *,'LAST = ',R
9327       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
9328       END
9329 @end smallexample
9330
9331 @noindent
9332 A C-like view of @code{DO} would hold that the two ``exclamatory''
9333 @code{PRINT} statements are never executed.
9334 However, this is the output of running the above program
9335 as compiled by @code{g77} on a GNU/Linux ix86 system:
9336
9337 @smallexample
9338  .100000001
9339  .107000001
9340  .114
9341  .120999999
9342  @dots{}
9343  .289000005
9344  .296000004
9345  .303000003
9346 LAST =   .310000002
9347  .310000002 .LE.   .310000002!!
9348 @end smallexample
9349
9350 Note that one of the two checks in the program turned up
9351 an apparent violation of the programmer's expectation---yet,
9352 the loop is correctly implemented by @code{g77}, in that
9353 it has 30 iterations.
9354 This trip count of 30 is correct when evaluated using
9355 the floating-point representations for the @var{begin},
9356 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
9357 ix86 are used.
9358 On other systems, an apparently more accurate trip count
9359 of 31 might result, but, nevertheless, @code{g77} is
9360 faithfully following the Fortran standard, and the result
9361 is not what the author of the sample program above
9362 apparently expected.
9363 (Such other systems might, for different values in the @code{DATA}
9364 statement, violate the other programmer's expectation,
9365 for example.)
9366
9367 Due to this combination of imprecise representation
9368 of floating-point values and the often-misunderstood
9369 interpretation of @code{DO} by standard-conforming
9370 compilers such as @code{g77}, use of @code{DO} loops
9371 with @code{REAL} iteration
9372 variables is not recommended.
9373 Such use can be caught by specifying @samp{-Wsurprising}.
9374 @xref{Warning Options}, for more information on this
9375 option.
9376
9377 @node Working Programs
9378 @section Working Programs
9379
9380 Getting Fortran programs to work in the first place can be
9381 quite a challenge---even when the programs already work on
9382 other systems, or when using other compilers.
9383
9384 @code{g77} offers some facilities that might be useful for
9385 tracking down bugs in such programs.
9386
9387 @menu
9388 * Not My Type::
9389 * Variables Assumed To Be Zero::
9390 * Variables Assumed To Be Saved::
9391 * Unwanted Variables::
9392 * Unused Arguments::
9393 * Surprising Interpretations of Code::
9394 * Aliasing Assumed To Work::
9395 * Output Assumed To Flush::
9396 * Large File Unit Numbers::
9397 * Floating-point precision::
9398 * Inconsistent Calling Sequences::
9399 @end menu
9400
9401 @node Not My Type
9402 @subsection Not My Type
9403 @cindex mistyped variables
9404 @cindex variables, mistyped
9405 @cindex mistyped functions
9406 @cindex functions, mistyped
9407 @cindex implicit typing
9408
9409 A fruitful source of bugs in Fortran source code is use, or
9410 mis-use, of Fortran's implicit-typing feature, whereby the
9411 type of a variable, array, or function is determined by the
9412 first character of its name.
9413
9414 Simple cases of this include statements like @samp{LOGX=9.227},
9415 without a statement such as @samp{REAL LOGX}.
9416 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
9417 type, with the result of the assignment being that it is given
9418 the value @samp{9}.
9419
9420 More involved cases include a function that is defined starting
9421 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
9422 Any caller of this function that does not also declare @samp{IPS}
9423 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
9424 is likely to assume it returns
9425 @code{INTEGER}, or some other type, leading to invalid results
9426 or even program crashes.
9427
9428 The @samp{-Wimplicit} option might catch failures to
9429 properly specify the types of
9430 variables, arrays, and functions in the code.
9431
9432 However, in code that makes heavy use of Fortran's
9433 implicit-typing facility, this option might produce so
9434 many warnings about cases that are working, it would be
9435 hard to find the one or two that represent bugs.
9436 This is why so many experienced Fortran programmers strongly
9437 recommend widespread use of the @code{IMPLICIT NONE} statement,
9438 despite it not being standard FORTRAN 77, to completely turn
9439 off implicit typing.
9440 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
9441 FORTRAN 77 compilers.)
9442
9443 Note that @samp{-Wimplicit} catches only implicit typing of
9444 @emph{names}.
9445 It does not catch implicit typing of expressions such
9446 as @samp{X**(2/3)}.
9447 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
9448 is equivalent to @samp{X**0}, due to the way Fortran expressions
9449 are given types and then evaluated.
9450 (In this particular case, the programmer probably wanted
9451 @samp{X**(2./3.)}.)
9452
9453 @node Variables Assumed To Be Zero
9454 @subsection Variables Assumed To Be Zero
9455 @cindex zero-initialized variables
9456 @cindex variables, assumed to be zero
9457 @cindex uninitialized variables
9458
9459 Many Fortran programs were developed on systems that provided
9460 automatic initialization of all, or some, variables and arrays
9461 to zero.
9462 As a result, many of these programs depend, sometimes
9463 inadvertently, on this behavior, though to do so violates
9464 the Fortran standards.
9465
9466 You can ask @code{g77} for this behavior by specifying the
9467 @samp{-finit-local-zero} option when compiling Fortran code.
9468 (You might want to specify @samp{-fno-automatic} as well,
9469 to avoid code-size inflation for non-optimized compilations.)
9470
9471 Note that a program that works better when compiled with the
9472 @samp{-finit-local-zero} option
9473 is almost certainly depending on a particular system's,
9474 or compiler's, tendency to initialize some variables to zero.
9475 It might be worthwhile finding such cases and fixing them,
9476 using techniques such as compiling with the @samp{-O -Wuninitialized}
9477 options using @code{g77}.
9478
9479 @node Variables Assumed To Be Saved
9480 @subsection Variables Assumed To Be Saved
9481 @cindex variables, retaining values across calls
9482 @cindex saved variables
9483 @cindex static variables
9484
9485 Many Fortran programs were developed on systems that
9486 saved the values of all, or some, variables and arrays
9487 across procedure calls.
9488 As a result, many of these programs depend, sometimes
9489 inadvertently, on being able to assign a value to a
9490 variable, perform a @code{RETURN} to a calling procedure,
9491 and, upon subsequent invocation, reference the previously
9492 assigned variable to obtain the value.
9493
9494 They expect this despite not using the @code{SAVE} statement
9495 to specify that the value in a variable is expected to survive
9496 procedure returns and calls.
9497 Depending on variables and arrays to retain values across
9498 procedure calls without using @code{SAVE} to require it violates
9499 the Fortran standards.
9500
9501 You can ask @code{g77} to assume @code{SAVE} is specified for all
9502 relevant (local) variables and arrays by using the
9503 @samp{-fno-automatic} option.
9504
9505 Note that a program that works better when compiled with the
9506 @samp{-fno-automatic} option
9507 is almost certainly depending on not having to use
9508 the @code{SAVE} statement as required by the Fortran standard.
9509 It might be worthwhile finding such cases and fixing them,
9510 using techniques such as compiling with the @samp{-O -Wuninitialized}
9511 options using @code{g77}.
9512
9513 @node Unwanted Variables
9514 @subsection Unwanted Variables
9515
9516 The @samp{-Wunused} option can find bugs involving
9517 implicit typing, sometimes
9518 more easily than using @samp{-Wimplicit} in code that makes
9519 heavy use of implicit typing.
9520 An unused variable or array might indicate that the
9521 spelling for its declaration is different from that of
9522 its intended uses.
9523
9524 Other than cases involving typos, unused variables rarely
9525 indicate actual bugs in a program.
9526 However, investigating such cases thoroughly has, on occasion,
9527 led to the discovery of code that had not been completely
9528 written---where the programmer wrote declarations as needed
9529 for the whole algorithm, wrote some or even most of the code
9530 for that algorithm, then got distracted and forgot that the
9531 job was not complete.
9532
9533 @node Unused Arguments
9534 @subsection Unused Arguments
9535 @cindex unused arguments
9536 @cindex arguments, unused
9537
9538 As with unused variables, It is possible that unused arguments
9539 to a procedure might indicate a bug.
9540 Compile with @samp{-W -Wunused} option to catch cases of
9541 unused arguments.
9542
9543 Note that @samp{-W} also enables warnings regarding overflow
9544 of floating-point constants under certain circumstances.
9545
9546 @node Surprising Interpretations of Code
9547 @subsection Surprising Interpretations of Code
9548
9549 The @samp{-Wsurprising} option can help find bugs involving
9550 expression evaluation or in
9551 the way @code{DO} loops with non-integral iteration variables
9552 are handled.
9553 Cases found by this option might indicate a difference of
9554 interpretation between the author of the code involved, and
9555 a standard-conforming compiler such as @code{g77}.
9556 Such a difference might produce actual bugs.
9557
9558 In any case, changing the code to explicitly do what the
9559 programmer might have expected it to do, so @code{g77} and
9560 other compilers are more likely to follow the programmer's
9561 expectations, might be worthwhile, especially if such changes
9562 make the program work better.
9563
9564 @node Aliasing Assumed To Work
9565 @subsection Aliasing Assumed To Work
9566 @cindex -falias-check option
9567 @cindex options, -falias-check
9568 @cindex -fargument-alias option
9569 @cindex options, -fargument-alias
9570 @cindex -fargument-noalias option
9571 @cindex options, -fargument-noalias
9572 @cindex -fno-argument-noalias-global option
9573 @cindex options, -fno-argument-noalias-global
9574 @cindex aliasing
9575 @cindex anti-aliasing
9576 @cindex overlapping arguments
9577 @cindex overlays
9578 @cindex association, storage
9579 @cindex storage association
9580 @cindex scheduling of reads and writes
9581 @cindex reads and writes, scheduling
9582
9583 The @samp{-falias-check}, @samp{-fargument-alias},
9584 @samp{-fargument-noalias},
9585 and @samp{-fno-argument-noalias-global} options,
9586 introduced in version 0.5.20 and
9587 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
9588 were withdrawn as of @code{g77} version 0.5.23
9589 due to their not being supported by @code{gcc} version 2.8.
9590
9591 These options control the assumptions regarding aliasing
9592 (overlapping) of writes and reads to main memory (core) made
9593 by the @code{gcc} back end.
9594
9595 The information below still is useful, but applies to
9596 only those versions of @code{g77} that support the
9597 alias analysis implied by support for these options.
9598
9599 These options are effective only when compiling with @samp{-O}
9600 (specifying any level other than @samp{-O0})
9601 or with @samp{-falias-check}.
9602
9603 The default for Fortran code is @samp{-fargument-noalias-global}.
9604 (The default for C code and code written in other C-based languages
9605 is @samp{-fargument-alias}.
9606 These defaults apply regardless of whether you use @code{g77} or
9607 @code{gcc} to compile your code.)
9608
9609 Note that, on some systems, compiling with @samp{-fforce-addr} in
9610 effect can produce more optimal code when the default aliasing
9611 options are in effect (and when optimization is enabled).
9612
9613 If your program is not working when compiled with optimization,
9614 it is possible it is violating the Fortran standards (77 and 90)
9615 by relying on the ability to ``safely'' modify variables and
9616 arrays that are aliased, via procedure calls, to other variables
9617 and arrays, without using @code{EQUIVALENCE} to explicitly
9618 set up this kind of aliasing.
9619
9620 (The FORTRAN 77 standard's prohibition of this sort of
9621 overlap, generally referred to therein as ``storage
9622 assocation'', appears in Sections 15.9.3.6.
9623 This prohibition allows implementations, such as @code{g77},
9624 to, for example, implement the passing of procedures and
9625 even values in @code{COMMON} via copy operations into local,
9626 perhaps more efficiently accessed temporaries at entry to a
9627 procedure, and, where appropriate, via copy operations back
9628 out to their original locations in memory at exit from that
9629 procedure, without having to take into consideration the
9630 order in which the local copies are updated by the code,
9631 among other things.)
9632
9633 To test this hypothesis, try compiling your program with
9634 the @samp{-fargument-alias} option, which causes the
9635 compiler to revert to assumptions essentially the same as
9636 made by versions of @code{g77} prior to 0.5.20.
9637
9638 If the program works using this option, that strongly suggests
9639 that the bug is in your program.
9640 Finding and fixing the bug(s) should result in a program that
9641 is more standard-conforming and that can be compiled by @code{g77}
9642 in a way that results in a faster executable.
9643
9644 (You might want to try compiling with @samp{-fargument-noalias},
9645 a kind of half-way point, to see if the problem is limited to
9646 aliasing between dummy arguments and @code{COMMON} variables---this
9647 option assumes that such aliasing is not done, while still allowing
9648 aliasing among dummy arguments.)
9649
9650 An example of aliasing that is invalid according to the standards
9651 is shown in the following program, which might @emph{not} produce
9652 the expected results when executed:
9653
9654 @smallexample
9655 I = 1
9656 CALL FOO(I, I)
9657 PRINT *, I
9658 END
9659
9660 SUBROUTINE FOO(J, K)
9661 J = J + K
9662 K = J * K
9663 PRINT *, J, K
9664 END
9665 @end smallexample
9666
9667 The above program attempts to use the temporary aliasing of the
9668 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
9669 pathological behavior---the simultaneous changing of the values
9670 of @emph{both} @samp{J} and @samp{K} when either one of them
9671 is written.
9672
9673 The programmer likely expects the program to print these values:
9674
9675 @example
9676 2  4
9677 4
9678 @end example
9679
9680 However, since the program is not standard-conforming, an
9681 implementation's behavior when running it is undefined, because
9682 subroutine @samp{FOO} modifies at least one of the arguments,
9683 and they are aliased with each other.
9684 (Even if one of the assignment statements was deleted, the
9685 program would still violate these rules.
9686 This kind of on-the-fly aliasing is permitted by the standard
9687 only when none of the aliased items are defined, or written,
9688 while the aliasing is in effect.)
9689
9690 As a practical example, an optimizing compiler might schedule
9691 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
9692 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
9693 resulting in the following output:
9694
9695 @example
9696 2  2
9697 2
9698 @end example
9699
9700 Essentially, compilers are promised (by the standard and, therefore,
9701 by programmers who write code they claim to be standard-conforming)
9702 that if they cannot detect aliasing via static analysis of a single
9703 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
9704 such aliasing exists.
9705 In such cases, compilers are free to assume that an assignment to
9706 one variable will not change the value of another variable, allowing
9707 it to avoid generating code to re-read the value of the other
9708 variable, to re-schedule reads and writes, and so on, to produce
9709 a faster executable.
9710
9711 The same promise holds true for arrays (as seen by the called
9712 procedure)---an element of one dummy array cannot be aliased
9713 with, or overlap, any element of another dummy array or be
9714 in a @code{COMMON} area known to the procedure.
9715
9716 (These restrictions apply only when the procedure defines, or
9717 writes to, one of the aliased variables or arrays.)
9718
9719 Unfortunately, there is no way to find @emph{all} possible cases of
9720 violations of the prohibitions against aliasing in Fortran code.
9721 Static analysis is certainly imperfect, as is run-time analysis,
9722 since neither can catch all violations.
9723 (Static analysis can catch all likely violations, and some that
9724 might never actually happen, while run-time analysis can catch
9725 only those violations that actually happen during a particular run.
9726 Neither approach can cope with programs mixing Fortran code with
9727 routines written in other languages, however.)
9728
9729 Currently, @code{g77} provides neither static nor run-time facilities
9730 to detect any cases of this problem, although other products might.
9731 Run-time facilities are more likely to be offered by future
9732 versions of @code{g77}, though patches improving @code{g77} so that
9733 it provides either form of detection are welcome.
9734
9735 @node Output Assumed To Flush
9736 @subsection Output Assumed To Flush
9737 @cindex ALWAYS_FLUSH
9738 @cindex synchronous write errors
9739 @cindex disk full
9740 @cindex flushing output
9741 @cindex fflush()
9742 @cindex I/O, flushing
9743 @cindex output, flushing
9744 @cindex writes, flushing
9745 @cindex NFS
9746 @cindex network file system
9747
9748 For several versions prior to 0.5.20, @code{g77} configured its
9749 version of the @code{libf2c} run-time library so that one of
9750 its configuration macros, @code{ALWAYS_FLUSH}, was defined.
9751
9752 This was done as a result of a belief that many programs expected
9753 output to be flushed to the operating system (under UNIX, via
9754 the @code{fflush()} library call) with the result that errors,
9755 such as disk full, would be immediately flagged via the
9756 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
9757
9758 Because of the adverse effects this approach had on the performance
9759 of many programs, @code{g77} no longer configures @code{libf2c}
9760 (now named @code{libg2c} in its @code{g77} incarnation)
9761 to always flush output.
9762
9763 If your program depends on this behavior, either insert the
9764 appropriate @samp{CALL FLUSH} statements, or modify the sources
9765 to the @code{libg2c}, rebuild and reinstall @code{g77}, and
9766 relink your programs with the modified library.
9767
9768 (Ideally, @code{libg2c} would offer the choice at run-time, so
9769 that a compile-time option to @code{g77} or @code{f2c} could
9770 result in generating the appropriate calls to flushing or
9771 non-flushing library routines.)
9772
9773 Some Fortran programs require output
9774 (writes) to be flushed to the operating system (under UNIX,
9775 via the @code{fflush()} library call) so that errors,
9776 such as disk full, are immediately flagged via the relevant
9777 @code{ERR=} and @code{IOSTAT=} mechanism, instead of such
9778 errors being flagged later as subsequent writes occur, forcing
9779 the previously written data to disk, or when the file is
9780 closed.
9781
9782 Essentially, the difference can be viewed as synchronous error
9783 reporting (immediate flagging of errors during writes) versus
9784 asynchronous, or, more precisely, buffered error reporting
9785 (detection of errors might be delayed).
9786
9787 @code{libg2c} supports flagging write errors immediately when
9788 it is built with the @code{ALWAYS_FLUSH} macro defined.
9789 This results in a @code{libg2c} that runs slower, sometimes
9790 quite a bit slower, under certain circumstances---for example,
9791 accessing files via the networked file system NFS---but the
9792 effect can be more reliable, robust file I/O.
9793
9794 If you know that Fortran programs requiring this level of precision
9795 of error reporting are to be compiled using the
9796 version of @code{g77} you are building, you might wish to
9797 modify the @code{g77} source tree so that the version of
9798 @code{libg2c} is built with the @code{ALWAYS_FLUSH} macro
9799 defined, enabling this behavior.
9800
9801 To do this, find this line in @file{@value{path-libf2c}/f2c.h} in
9802 your @code{g77} source tree:
9803
9804 @example
9805 /* #define ALWAYS_FLUSH */
9806 @end example
9807
9808 Remove the leading @samp{/*@w{ }},
9809 so the line begins with @samp{#define},
9810 and the trailing @samp{@w{ }*/}.
9811
9812 Then build or rebuild @code{g77} as appropriate.
9813
9814 @node Large File Unit Numbers
9815 @subsection Large File Unit Numbers
9816 @cindex MXUNIT
9817 @cindex unit numbers
9818 @cindex maximum unit number
9819 @cindex illegal unit number
9820 @cindex increasing maximum unit number
9821
9822 If your program crashes at run time with a message including
9823 the text @samp{illegal unit number}, that probably is
9824 a message from the run-time library, @code{libg2c}.
9825
9826 The message means that your program has attempted to use a
9827 file unit number that is out of the range accepted by
9828 @code{libg2c}.
9829 Normally, this range is 0 through 99, and the high end
9830 of the range is controlled by a @code{libg2c} source-file
9831 macro named @code{MXUNIT}.
9832
9833 If you can easily change your program to use unit numbers
9834 in the range 0 through 99, you should do so.
9835
9836 As distributed, whether as part of @code{f2c} or @code{g77},
9837 @code{libf2c} accepts file unit numbers only in the range
9838 0 through 99.
9839 For example, a statement such as @samp{WRITE (UNIT=100)} causes
9840 a run-time crash in @code{libf2c}, because the unit number,
9841 100, is out of range.
9842
9843 If you know that Fortran programs at your installation require
9844 the use of unit numbers higher than 99, you can change the
9845 value of the @code{MXUNIT} macro, which represents the maximum unit
9846 number, to an appropriately higher value.
9847
9848 To do this, edit the file @file{@value{path-libf2c}/libI77/fio.h} in your
9849 @code{g77} source tree, changing the following line:
9850
9851 @example
9852 #define MXUNIT 100
9853 @end example
9854
9855 Change the line so that the value of @code{MXUNIT} is defined to be
9856 at least one @emph{greater} than the maximum unit number used by
9857 the Fortran programs on your system.
9858
9859 (For example, a program that does @samp{WRITE (UNIT=255)} would require
9860 @code{MXUNIT} set to at least 256 to avoid crashing.)
9861
9862 Then build or rebuild @code{g77} as appropriate.
9863
9864 @emph{Note:} Changing this macro has @emph{no} effect on other limits
9865 your system might place on the number of files open at the same time.
9866 That is, the macro might allow a program to do @samp{WRITE (UNIT=100)},
9867 but the library and operating system underlying @code{libf2c} might
9868 disallow it if many other files have already been opened (via @code{OPEN} or
9869 implicitly via @code{READ}, @code{WRITE}, and so on).
9870 Information on how to increase these other limits should be found
9871 in your system's documentation.
9872
9873 @node Floating-point precision
9874 @subsection Floating-point precision
9875
9876 @cindex IEEE 754 conformance
9877 @cindex conformance, IEEE 754
9878 @cindex floating-point, precision
9879 @cindex ix86 floating-point
9880 @cindex x86 floating-point
9881 If your program depends on exact IEEE 754 floating-point handling it may
9882 help on some systems---specifically x86 or m68k hardware---to use
9883 the @samp{-ffloat-store} option or to reset the precision flag on the
9884 floating-point unit.
9885 @xref{Optimize Options}.
9886
9887 However, it might be better simply to put the FPU into double precision
9888 mode and not take the performance hit of @samp{-ffloat-store}.  On x86
9889 and m68k GNU systems you can do this with a technique similar to that
9890 for turning on floating-point exceptions
9891 (@pxref{Floating-point Exception Handling}).
9892 The control word could be set to double precision by some code like this
9893 one:
9894 @smallexample
9895 #include <fpu_control.h>
9896 @{
9897   fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
9898   _FPU_SETCW(cw);
9899 @}
9900 @end smallexample
9901 (It is not clear whether this has any effect on the operation of the GNU
9902 maths library, but we have no evidence of it causing trouble.)
9903
9904 Some targets (such as the Alpha) may need special options for full IEEE
9905 conformance.
9906 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and Porting GNU CC}.
9907
9908 @node Inconsistent Calling Sequences
9909 @subsection Inconsistent Calling Sequences
9910
9911 @pindex ftnchek
9912 @cindex floating-point, errors
9913 @cindex ix86 FPU stack
9914 @cindex x86 FPU stack
9915 Code containing inconsistent calling sequences in the same file is
9916 normally rejected---see @ref{GLOBALS}.
9917 (Use, say, @code{ftnchek} to ensure
9918 consistency across source files.
9919 @xref{f2c Skeletons and Prototypes,,
9920 Generating Skeletons and Prototypes with @code{f2c}}.)
9921
9922 Mysterious errors, which may appear to be code generation problems, can
9923 appear specifically on the x86 architecture with some such
9924 inconsistencies.  On x86 hardware, floating-point return values of
9925 functions are placed on the floating-point unit's register stack, not
9926 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
9927 @code{FUNCTION} as some other sort of procedure, or vice versa,
9928 scrambles the floating-point stack.  This may break unrelated code
9929 executed later.  Similarly if, say, external C routines are written
9930 incorrectly.
9931
9932 @node Overly Convenient Options
9933 @section Overly Convenient Command-line Options
9934 @cindex overly convenient options
9935 @cindex options, overly convenient
9936
9937 These options should be used only as a quick-and-dirty way to determine
9938 how well your program will run under different compilation models
9939 without having to change the source.
9940 Some are more problematic
9941 than others, depending on how portable and maintainable you want the
9942 program to be (and, of course, whether you are allowed to change it
9943 at all is crucial).
9944
9945 You should not continue to use these command-line options to compile
9946 a given program, but rather should make changes to the source code:
9947
9948 @table @code
9949 @cindex -finit-local-zero option
9950 @cindex options, -finit-local-zero
9951 @item -finit-local-zero
9952 (This option specifies that any uninitialized local variables
9953 and arrays have default initialization to binary zeros.)
9954
9955 Many other compilers do this automatically, which means lots of
9956 Fortran code developed with those compilers depends on it.
9957
9958 It is safer (and probably
9959 would produce a faster program) to find the variables and arrays that
9960 need such initialization and provide it explicitly via @code{DATA}, so that
9961 @samp{-finit-local-zero} is not needed.
9962
9963 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
9964 find likely candidates, but
9965 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
9966 or this technique won't work.
9967
9968 @cindex -fno-automatic option
9969 @cindex options, -fno-automatic
9970 @item -fno-automatic
9971 (This option specifies that all local variables and arrays
9972 are to be treated as if they were named in @code{SAVE} statements.)
9973
9974 Many other compilers do this automatically, which means lots of
9975 Fortran code developed with those compilers depends on it.
9976
9977 The effect of this is that all non-automatic variables and arrays
9978 are made static, that is, not placed on the stack or in heap storage.
9979 This might cause a buggy program to appear to work better.
9980 If so, rather than relying on this command-line option (and hoping all
9981 compilers provide the equivalent one), add @code{SAVE}
9982 statements to some or all program unit sources, as appropriate.
9983 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
9984 to find likely candidates, but
9985 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
9986 or this technique won't work.
9987
9988 The default is @samp{-fautomatic}, which tells @code{g77} to try
9989 and put variables and arrays on the stack (or in fast registers)
9990 where possible and reasonable.
9991 This tends to make programs faster.
9992
9993 @cindex automatic arrays
9994 @cindex arrays, automatic
9995 @emph{Note:} Automatic variables and arrays are not affected
9996 by this option.
9997 These are variables and arrays that are @emph{necessarily} automatic,
9998 either due to explicit statements, or due to the way they are
9999 declared.
10000 Examples include local variables and arrays not given the
10001 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
10002 and local arrays declared with non-constant bounds (automatic
10003 arrays).
10004 Currently, @code{g77} supports only automatic arrays, not
10005 @code{RECURSIVE} procedures or other means of explicitly
10006 specifying that variables or arrays are automatic.
10007
10008 @cindex -f@var{group}-intrinsics-hide option
10009 @cindex options, -f@var{group}-intrinsics-hide
10010 @item -f@var{group}-intrinsics-hide
10011 Change the source code to use @code{EXTERNAL} for any external procedure
10012 that might be the name of an intrinsic.
10013 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
10014 @end table
10015
10016 @node Faster Programs
10017 @section Faster Programs
10018 @cindex speed, of programs
10019 @cindex programs, speeding up
10020
10021 Aside from the usual @code{gcc} options, such as @samp{-O},
10022 @samp{-ffast-math}, and so on, consider trying some of the
10023 following approaches to speed up your program (once you get
10024 it working).
10025
10026 @menu
10027 * Aligned Data::
10028 * Prefer Automatic Uninitialized Variables::
10029 * Avoid f2c Compatibility::
10030 * Use Submodel Options::
10031 @end menu
10032
10033 @node Aligned Data
10034 @subsection Aligned Data
10035 @cindex alignment
10036 @cindex data, aligned
10037 @cindex stack, aligned
10038 @cindex aligned data
10039 @cindex aligned stack
10040 @cindex Pentium optimizations
10041 @cindex optimization, for Pentium
10042
10043 On some systems, such as those with Pentium Pro CPUs, programs
10044 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
10045 might run much slower
10046 than possible due to the compiler not aligning these 64-bit
10047 values to 64-bit boundaries in memory.
10048 (The effect also is present, though
10049 to a lesser extent, on the 586 (Pentium) architecture.)
10050
10051 The Intel x86 architecture generally ensures that these programs will
10052 work on all its implementations,
10053 but particular implementations (such as Pentium Pro)
10054 perform better with more strict alignment.
10055 (Such behavior isn't unique to the Intel x86 architecture.)
10056 Other architectures might @emph{demand} 64-bit alignment
10057 of 64-bit data.
10058
10059 There are a variety of approaches to use to address this problem:
10060
10061 @itemize @bullet
10062 @item
10063 @cindex @code{COMMON} layout
10064 @cindex layout of @code{COMMON} blocks
10065 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
10066 that the variables and arrays with the widest alignment
10067 guidelines come first.
10068
10069 For example, on most systems, this would mean placing
10070 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
10071 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
10072 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
10073 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
10074 and @code{INTEGER(KIND=3)} entities.
10075
10076 The reason to use such placement is it makes it more likely
10077 that your data will be aligned properly, without requiring
10078 you to do detailed analysis of each aggregate (@code{COMMON}
10079 and @code{EQUIVALENCE}) area.
10080
10081 Specifically, on systems where the above guidelines are
10082 appropriate, placing @code{CHARACTER} entities before
10083 @code{REAL(KIND=2)} entities can work just as well,
10084 but only if the number of bytes occupied by the @code{CHARACTER}
10085 entities is divisible by the recommended alignment for
10086 @code{REAL(KIND=2)}.
10087
10088 By ordering the placement of entities in aggregate
10089 areas according to the simple guidelines above, you
10090 avoid having to carefully count the number of bytes
10091 occupied by each entity to determine whether the
10092 actual alignment of each subsequent entity meets the
10093 alignment guidelines for the type of that entity.
10094
10095 If you don't ensure correct alignment of @code{COMMON} elements, the
10096 compiler may be forced by some systems to violate the Fortran semantics by
10097 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
10098 If the unfortunate practice is employed of overlaying different types of
10099 data in the @code{COMMON} block, the different variants
10100 of this block may become misaligned with respect to each other.
10101 Even if your platform doesn't require strict alignment,
10102 @code{COMMON} should be laid out as above for portability.
10103 (Unfortunately the FORTRAN 77 standard didn't anticipate this
10104 possible requirement, which is compiler-independent on a given platform.)
10105
10106 @item
10107 @cindex -malign-double option
10108 @cindex options, -malign-double
10109 Use the (x86-specific) @samp{-malign-double} option when compiling
10110 programs for the Pentium and Pentium Pro architectures (called 586
10111 and 686 in the @code{gcc} configuration subsystem).
10112 The warning about this in the @code{gcc} manual isn't
10113 generally relevant to Fortran,
10114 but using it will force @code{COMMON} to be padded if necessary to align
10115 @code{DOUBLE PRECISION} data.
10116
10117 When @code{DOUBLE PRECISION} data is forcibly aligned
10118 in @code{COMMON} by @code{g77} due to specifying @samp{-malign-double},
10119 @code{g77} issues a warning about the need to
10120 insert padding.
10121
10122 In this case, each and every program unit that uses
10123 the same @code{COMMON} area
10124 must specify the same layout of variables and their types
10125 for that area
10126 and be compiled with @samp{-malign-double} as well.
10127 @code{g77} will issue warnings in each case,
10128 but as long as every program unit using that area
10129 is compiled with the same warnings,
10130 the resulting object files should work when linked together
10131 unless the program makes additional assumptions about
10132 @code{COMMON} area layouts that are outside the scope
10133 of the FORTRAN 77 standard,
10134 or uses @code{EQUIVALENCE} or different layouts
10135 in ways that assume no padding is ever inserted by the compiler.
10136
10137 @item
10138 Ensure that @file{crt0.o} or @file{crt1.o}
10139 on your system guarantees a 64-bit
10140 aligned stack for @code{main()}.
10141 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
10142 but we don't know of any other x86 setups where it will be right.
10143 Read your system's documentation to determine if
10144 it is appropriate to upgrade to a more recent version
10145 to obtain the optimal alignment.
10146 @end itemize
10147
10148 Progress is being made on making this work
10149 ``out of the box'' on future versions of @code{g77},
10150 @code{gcc}, and some of the relevant operating systems
10151 (such as GNU/Linux).
10152
10153 @cindex alignment testing
10154 @cindex testing alignment
10155 A package that tests the degree to which a Fortran compiler
10156 (such as @code{g77})
10157 aligns 64-bit floating-point variables and arrays
10158 is available at @uref{ftp://alpha.gnu.org/gnu/g77/align/}.
10159
10160 @node Prefer Automatic Uninitialized Variables
10161 @subsection Prefer Automatic Uninitialized Variables
10162
10163 If you're using @samp{-fno-automatic} already, you probably
10164 should change your code to allow compilation with @samp{-fautomatic}
10165 (the default), to allow the program to run faster.
10166
10167 Similarly, you should be able to use @samp{-fno-init-local-zero}
10168 (the default) instead of @samp{-finit-local-zero}.
10169 This is because it is rare that every variable affected by these
10170 options in a given program actually needs to
10171 be so affected.
10172
10173 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
10174 every local non-automatic variable and array, affects even things like
10175 @code{DO} iteration
10176 variables, which rarely need to be @code{SAVE}d, and this often reduces
10177 run-time performances.
10178 Similarly, @samp{-fno-init-local-zero} forces such
10179 variables to be initialized to zero---when @code{SAVE}d (such as when
10180 @samp{-fno-automatic}), this by itself generally affects only
10181 startup time for a program, but when not @code{SAVE}d,
10182 it can slow down the procedure every time it is called.
10183
10184 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10185 for information on the @samp{-fno-automatic} and
10186 @samp{-finit-local-zero} options and how to convert
10187 their use into selective changes in your own code.
10188
10189 @node Avoid f2c Compatibility
10190 @subsection Avoid f2c Compatibility
10191 @cindex -fno-f2c option
10192 @cindex options, -fno-f2c
10193 @cindex @code{f2c} compatibility
10194 @cindex compatibility, @code{f2c}
10195
10196 If you aren't linking with any code compiled using
10197 @code{f2c}, try using the @samp{-fno-f2c} option when
10198 compiling @emph{all} the code in your program.
10199 (Note that @code{libf2c} is @emph{not} an example of code
10200 that is compiled using @code{f2c}---it is compiled by a C
10201 compiler, typically @code{gcc}.)
10202
10203 @node Use Submodel Options
10204 @subsection Use Submodel Options
10205 @cindex submodels
10206
10207 Using an appropriate @samp{-m} option to generate specific code for your
10208 CPU may be worthwhile, though it may mean the executable won't run on
10209 other versions of the CPU that don't support the same instruction set.
10210 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
10211 Porting GNU CC}.  For instance on an x86 system the compiler might have
10212 been built---as shown by @samp{g77 -v}---for the target
10213 @samp{i386-pc-linux-gnu}, i.e.@: an @samp{i386} CPU@.  In that case to
10214 generate code best optimized for a Pentium you could use the option
10215 @samp{-march=pentium}.
10216
10217 For recent CPUs that don't have explicit support in the released version
10218 of @code{gcc}, it @emph{might} still be possible to get improvements
10219 with certain @samp{-m} options.
10220
10221 @samp{-fomit-frame-pointer} can help performance on x86 systems and
10222 others.  It will, however, inhibit debugging on the systems on which it
10223 is not turned on anyway by @samp{-O}.
10224
10225 @node Trouble
10226 @chapter Known Causes of Trouble with GNU Fortran
10227 @cindex bugs, known
10228 @cindex installation trouble
10229 @cindex known causes of trouble
10230
10231 This section describes known problems that affect users of GNU Fortran.
10232 Most of these are not GNU Fortran bugs per se---if they were, we would
10233 fix them.
10234 But the result for a user might be like the result of a bug.
10235
10236 Some of these problems are due to bugs in other software, some are
10237 missing features that are too much work to add, and some are places
10238 where people's opinions differ as to what is best.
10239
10240 To find out about major bugs discovered in the current release and
10241 possible workarounds for them, see
10242 @uref{ftp://alpha.gnu.org/g77.plan}.
10243
10244 (Note that some of this portion of the manual is lifted
10245 directly from the @code{gcc} manual, with minor modifications
10246 to tailor it to users of @code{g77}.
10247 Anytime a bug seems to have more to do with the @code{gcc}
10248 portion of @code{g77}, see
10249 @ref{Trouble,,Known Causes of Trouble with GNU CC,
10250 gcc,Using and Porting GNU CC}.)
10251
10252 @menu
10253 * But-bugs::         Bugs really in other programs or elsewhere.
10254 * Known Bugs::       Bugs known to be in this version of @code{g77}.
10255 * Missing Features:: Features we already know we want to add later.
10256 * Disappointments::  Regrettable things we can't change.
10257 * Non-bugs::         Things we think are right, but some others disagree.
10258 * Warnings and Errors::  Which problems in your code get warnings,
10259                         and which get errors.
10260 @end menu
10261
10262 @node But-bugs
10263 @section Bugs Not In GNU Fortran
10264 @cindex but-bugs
10265
10266 These are bugs to which the maintainers often have to reply,
10267 ``but that isn't a bug in @code{g77}@dots{}''.
10268 Some of these already are fixed in new versions of other
10269 software; some still need to be fixed; some are problems
10270 with how @code{g77} is installed or is being used;
10271 some are the result of bad hardware that causes software
10272 to misbehave in sometimes bizarre ways;
10273 some just cannot be addressed at this time until more
10274 is known about the problem.
10275
10276 Please don't re-report these bugs to the @code{g77} maintainers---if
10277 you must remind someone how important it is to you that the problem
10278 be fixed, talk to the people responsible for the other products
10279 identified below, but preferably only after you've tried the
10280 latest versions of those products.
10281 The @code{g77} maintainers have their hands full working on
10282 just fixing and improving @code{g77}, without serving as a
10283 clearinghouse for all bugs that happen to affect @code{g77}
10284 users.
10285
10286 @xref{Collected Fortran Wisdom}, for information on behavior
10287 of Fortran programs, and the programs that compile them, that
10288 might be @emph{thought} to indicate bugs.
10289
10290 @menu
10291 * Signal 11 and Friends::  Strange behavior by any software.
10292 * Cannot Link Fortran Programs::  Unresolved references.
10293 * Large Common Blocks::    Problems on older GNU/Linux systems.
10294 * Debugger Problems::      When the debugger crashes.
10295 * NeXTStep Problems::      Misbehaving executables.
10296 * Stack Overflow::         More misbehaving executables.
10297 * Nothing Happens::        Less behaving executables.
10298 * Strange Behavior at Run Time::  Executables misbehaving due to
10299                             bugs in your program.
10300 * Floating-point Errors::  The results look wrong, but@dots{}.
10301 @end menu
10302
10303 @node Signal 11 and Friends
10304 @subsection Signal 11 and Friends
10305 @cindex signal 11
10306 @cindex hardware errors
10307
10308 A whole variety of strange behaviors can occur when the
10309 software, or the way you are using the software,
10310 stresses the hardware in a way that triggers hardware bugs.
10311 This might seem hard to believe, but it happens frequently
10312 enough that there exist documents explaining in detail
10313 what the various causes of the problems are, what
10314 typical symptoms look like, and so on.
10315
10316 Generally these problems are referred to in this document
10317 as ``signal 11'' crashes, because the Linux kernel, running
10318 on the most popular hardware (the Intel x86 line), often
10319 stresses the hardware more than other popular operating
10320 systems.
10321 When hardware problems do occur under GNU/Linux on x86
10322 systems, these often manifest themselves as ``signal 11''
10323 problems, as illustrated by the following diagnostic:
10324
10325 @smallexample
10326 sh# @kbd{g77 myprog.f}
10327 gcc: Internal compiler error: program f771 got fatal signal 11
10328 sh#
10329 @end smallexample
10330
10331 It is @emph{very} important to remember that the above
10332 message is @emph{not} the only one that indicates a
10333 hardware problem, nor does it always indicate a hardware
10334 problem.
10335
10336 In particular, on systems other than those running the Linux
10337 kernel, the message might appear somewhat or very different,
10338 as it will if the error manifests itself while running a
10339 program other than the @code{g77} compiler.
10340 For example,
10341 it will appear somewhat different when running your program,
10342 when running Emacs, and so on.
10343
10344 How to cope with such problems is well beyond the scope
10345 of this manual.
10346
10347 However, users of Linux-based systems (such as GNU/Linux)
10348 should review @uref{http://www.bitwizard.nl/sig11/}, a source
10349 of detailed information on diagnosing hardware problems,
10350 by recognizing their common symptoms.
10351
10352 Users of other operating systems and hardware might
10353 find this reference useful as well.
10354 If you know of similar material for another hardware/software
10355 combination, please let us know so we can consider including
10356 a reference to it in future versions of this manual.
10357
10358 @node Cannot Link Fortran Programs
10359 @subsection Cannot Link Fortran Programs
10360 @cindex unresolved reference (various)
10361 @cindex linking error for user code
10362 @cindex code, user
10363 @cindex @code{ld}, error linking user code
10364 @cindex @code{ld}, can't find strange names
10365 On some systems, perhaps just those with out-of-date (shared?)
10366 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
10367 programs (which should be done using @code{g77}).
10368
10369 If this happens to you, try appending @samp{-lc} to the command you
10370 use to link the program, e.g. @samp{g77 foo.f -lc}.
10371 @code{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
10372 but it cannot also specify @samp{-lc} because not all systems have a
10373 file named @file{libc.a}.
10374
10375 It is unclear at this point whether there are legitimately installed
10376 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
10377 by @code{g77}.
10378
10379 @cindex undefined reference (_main)
10380 @cindex linking error, user code
10381 @cindex @code{ld}, error linking user code
10382 @cindex code, user
10383 @cindex @code{ld}, can't find @samp{_main}
10384 If your program doesn't link due to unresolved references to names
10385 like @samp{_main}, make sure you're using the @code{g77} command to do the
10386 link, since this command ensures that the necessary libraries are
10387 loaded by specifying @samp{-lg2c -lm} when it invokes the @code{gcc}
10388 command to do the actual link.
10389 (Use the @samp{-v} option to discover
10390 more about what actually happens when you use the @code{g77} and @code{gcc}
10391 commands.)
10392
10393 Also, try specifying @samp{-lc} as the last item on the @code{g77}
10394 command line, in case that helps.
10395
10396 @node Large Common Blocks
10397 @subsection Large Common Blocks
10398 @cindex common blocks, large
10399 @cindex large common blocks
10400 @cindex linking, errors
10401 @cindex @code{ld}, errors
10402 @cindex errors, linker
10403 On some older GNU/Linux systems, programs with common blocks larger
10404 than 16MB cannot be linked without some kind of error
10405 message being produced.
10406
10407 This is a bug in older versions of @code{ld}, fixed in
10408 more recent versions of @code{binutils}, such as version 2.6.
10409
10410 @node Debugger Problems
10411 @subsection Debugger Problems
10412 @cindex @code{gdb}, support
10413 @cindex support, @code{gdb}
10414 There are some known problems when using @code{gdb} on code
10415 compiled by @code{g77}.
10416 Inadequate investigation as of the release of 0.5.16 results in not
10417 knowing which products are the culprit, but @file{gdb-4.14} definitely
10418 crashes when, for example, an attempt is made to print the contents
10419 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
10420 machines, plus some others.
10421 Attempts to access assumed-size arrays are
10422 also known to crash recent versions of @code{gdb}.
10423 (@code{gdb}'s Fortran support was done for a different compiler
10424 and isn't properly compatible with @code{g77}.)
10425
10426 @node NeXTStep Problems
10427 @subsection NeXTStep Problems
10428 @cindex NeXTStep problems
10429 @cindex bus error
10430 @cindex segmentation violation
10431 Developers of Fortran code on NeXTStep (all architectures) have to
10432 watch out for the following problem when writing programs with
10433 large, statically allocated (i.e. non-stack based) data structures
10434 (common blocks, saved arrays).
10435
10436 Due to the way the native loader (@file{/bin/ld}) lays out
10437 data structures in virtual memory, it is very easy to create an
10438 executable wherein the @samp{__DATA} segment overlaps (has addresses in
10439 common) with the @samp{UNIX STACK} segment.
10440
10441 This leads to all sorts of trouble, from the executable simply not
10442 executing, to bus errors.
10443 The NeXTStep command line tool @code{ebadexec} points to
10444 the problem as follows:
10445
10446 @smallexample
10447 % @kbd{/bin/ebadexec a.out}
10448 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
10449 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
10450 STACK segment (truncated address = 0x400000 rounded size =
10451 0x3c00000) of executable file: a.out
10452 @end smallexample
10453
10454 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
10455 stack segment.)
10456
10457 This can be cured by assigning the @samp{__DATA} segment
10458 (virtual) addresses beyond the stack segment.
10459 A conservative
10460 estimate for this is from address 6000000 (hexadecimal) onwards---this
10461 has always worked for me [Toon Moene]:
10462
10463 @smallexample
10464 % @kbd{g77 -segaddr __DATA 6000000 test.f}
10465 % @kbd{ebadexec a.out}
10466 ebadexec: file: a.out appears to be executable
10467 %
10468 @end smallexample
10469
10470 Browsing through @file{@value{path-g77}/Makefile.in},
10471 you will find that the @code{f771} program itself also has to be
10472 linked with these flags---it has large statically allocated
10473 data structures.
10474 (Version 0.5.18 reduces this somewhat, but probably
10475 not enough.)
10476
10477 (The above item was contributed by Toon Moene
10478 (@email{toon@@moene.indiv.nluug.nl}).)
10479
10480 @node Stack Overflow
10481 @subsection Stack Overflow
10482 @cindex stack, overflow
10483 @cindex segmentation violation
10484 @code{g77} code might fail at runtime (probably with a ``segmentation
10485 violation'') due to overflowing the stack.
10486 This happens most often on systems with an environment
10487 that provides substantially more heap space (for use
10488 when arbitrarily allocating and freeing memory) than stack
10489 space.
10490
10491 Often this can be cured by
10492 increasing or removing your shell's limit on stack usage, typically
10493 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
10494 @kbd{ulimit -s} (in @code{sh} and derivatives).
10495
10496 Increasing the allowed stack size might, however, require
10497 changing some operating system or system configuration parameters.
10498
10499 You might be able to work around the problem by compiling with the
10500 @samp{-fno-automatic} option to reduce stack usage, probably at the
10501 expense of speed.
10502
10503 @code{g77}, on most machines, puts many variables and arrays on the stack
10504 where possible, and can be configured (by changing
10505 @code{FFECOM_sizeMAXSTACKITEM} in @file{@value{path-g77}/com.c}) to force
10506 smaller-sized entities into static storage (saving
10507 on stack space) or permit larger-sized entities to be put on the
10508 stack (which can improve run-time performance, as it presents
10509 more opportunities for the GBE to optimize the generated code).
10510
10511 @emph{Note:} Putting more variables and arrays on the stack
10512 might cause problems due to system-dependent limits on stack size.
10513 Also, the value of @code{FFECOM_sizeMAXSTACKITEM} has no
10514 effect on automatic variables and arrays.
10515 @xref{But-bugs}, for more information.
10516 @emph{Note:} While @code{libg2c} places a limit on the range
10517 of Fortran file-unit numbers, the underlying library and operating
10518 system might impose different kinds of limits.
10519 For example, some systems limit the number of files simultaneously
10520 open by a running program.
10521 Information on how to increase these limits should be found
10522 in your system's documentation.
10523
10524 @cindex automatic arrays
10525 @cindex arrays, automatic
10526 However, if your program uses large automatic arrays
10527 (for example, has declarations like @samp{REAL A(N)} where
10528 @samp{A} is a local array and @samp{N} is a dummy or
10529 @code{COMMON} variable that can have a large value),
10530 neither use of @samp{-fno-automatic},
10531 nor changing the cut-off point for @code{g77} for using the stack,
10532 will solve the problem by changing the placement of these
10533 large arrays, as they are @emph{necessarily} automatic.
10534
10535 @code{g77} currently provides no means to specify that
10536 automatic arrays are to be allocated on the heap instead
10537 of the stack.
10538 So, other than increasing the stack size, your best bet is to
10539 change your source code to avoid large automatic arrays.
10540 Methods for doing this currently are outside the scope of
10541 this document.
10542
10543 (@emph{Note:} If your system puts stack and heap space in the
10544 same memory area, such that they are effectively combined, then
10545 a stack overflow probably indicates a program that is either
10546 simply too large for the system, or buggy.)
10547
10548 @node Nothing Happens
10549 @subsection Nothing Happens
10550 @cindex nothing happens
10551 @cindex naming programs
10552 @cindex @code{test} programs
10553 @cindex programs, @code{test}
10554 It is occasionally reported that a ``simple'' program,
10555 such as a ``Hello, World!'' program, does nothing when
10556 it is run, even though the compiler reported no errors,
10557 despite the program containing nothing other than a
10558 simple @code{PRINT} statement.
10559
10560 This most often happens because the program has been
10561 compiled and linked on a UNIX system and named @code{test},
10562 though other names can lead to similarly unexpected
10563 run-time behavior on various systems.
10564
10565 Essentially this problem boils down to giving
10566 your program a name that is already known to
10567 the shell you are using to identify some other program,
10568 which the shell continues to execute instead of your
10569 program when you invoke it via, for example:
10570
10571 @smallexample
10572 sh# @kbd{test}
10573 sh#
10574 @end smallexample
10575
10576 Under UNIX and many other system, a simple command name
10577 invokes a searching mechanism that might well not choose
10578 the program located in the current working directory if
10579 there is another alternative (such as the @code{test}
10580 command commonly installed on UNIX systems).
10581
10582 The reliable way to invoke a program you just linked in
10583 the current directory under UNIX is to specify it using
10584 an explicit pathname, as in:
10585
10586 @smallexample
10587 sh# @kbd{./test}
10588  Hello, World!
10589 sh#
10590 @end smallexample
10591
10592 Users who encounter this problem should take the time to
10593 read up on how their shell searches for commands, how to
10594 set their search path, and so on.
10595 The relevant UNIX commands to learn about include
10596 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
10597 @code{set} and @code{env}), @code{which}, and @code{find}.
10598
10599 @node Strange Behavior at Run Time
10600 @subsection Strange Behavior at Run Time
10601 @cindex segmentation violation
10602 @cindex bus error
10603 @cindex overwritten data
10604 @cindex data, overwritten
10605 @code{g77} code might fail at runtime with ``segmentation violation'',
10606 ``bus error'', or even something as subtle as a procedure call
10607 overwriting a variable or array element that it is not supposed
10608 to touch.
10609
10610 These can be symptoms of a wide variety of actual bugs that
10611 occurred earlier during the program's run, but manifested
10612 themselves as @emph{visible} problems some time later.
10613
10614 Overflowing the bounds of an array---usually by writing beyond
10615 the end of it---is one of two kinds of bug that often occurs
10616 in Fortran code.
10617 (Compile your code with the @samp{-fbounds-check} option
10618 to catch many of these kinds of errors at program run time.)
10619
10620 The other kind of bug is a mismatch between the actual arguments
10621 passed to a procedure and the dummy arguments as declared by that
10622 procedure.
10623
10624 Both of these kinds of bugs, and some others as well, can be
10625 difficult to track down, because the bug can change its behavior,
10626 or even appear to not occur, when using a debugger.
10627
10628 That is, these bugs can be quite sensitive to data, including
10629 data representing the placement of other data in memory (that is,
10630 pointers, such as the placement of stack frames in memory).
10631
10632 @code{g77} now offers the
10633 ability to catch and report some of these problems at compile, link, or
10634 run time, such as by generating code to detect references to
10635 beyond the bounds of most arrays (except assumed-size arrays),
10636 and checking for agreement between calling and called procedures.
10637 Future improvements are likely to be made in the procedure-mismatch area,
10638 at least.
10639
10640 In the meantime, finding and fixing the programming
10641 bugs that lead to these behaviors is, ultimately, the user's
10642 responsibility, as difficult as that task can sometimes be.
10643
10644 @cindex infinite spaces printed
10645 @cindex space, endless printing of
10646 @cindex libc, non-ANSI or non-default
10647 @cindex C library
10648 @cindex linking against non-standard library
10649 @cindex Solaris
10650 One runtime problem that has been observed might have a simple solution.
10651 If a formatted @code{WRITE} produces an endless stream of spaces, check
10652 that your program is linked against the correct version of the C library.
10653 The configuration process takes care to account for your
10654 system's normal @file{libc} not being ANSI-standard, which will
10655 otherwise cause this behaviour.
10656 If your system's default library is
10657 ANSI-standard and you subsequently link against a non-ANSI one, there
10658 might be problems such as this one.
10659
10660 Specifically, on Solaris2 systems,
10661 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
10662
10663 @node Floating-point Errors
10664 @subsection Floating-point Errors
10665 @cindex floating-point errors
10666 @cindex rounding errors
10667 @cindex inconsistent floating-point results
10668 @cindex results, inconsistent
10669 Some programs appear to produce inconsistent floating-point
10670 results compiled by @code{g77} versus by other compilers.
10671
10672 Often the reason for this behavior is the fact that floating-point
10673 values are represented on almost all Fortran systems by
10674 @emph{approximations}, and these approximations are inexact
10675 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
10676 0.7, 0.8, 0.9, 1.1, and so on.
10677 Most Fortran systems, including all current ports of @code{g77},
10678 use binary arithmetic to represent these approximations.
10679
10680 Therefore, the exact value of any floating-point approximation
10681 as manipulated by @code{g77}-compiled code is representable by
10682 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
10683 so on (just keep dividing by two) through the precision of the
10684 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
10685 @code{REAL(KIND=2)}), then multiplying the sum by a integral
10686 power of two (in Fortran, by @samp{2**N}) that typically is between
10687 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
10688 @code{REAL(KIND=2)}, then multiplying by -1 if the number
10689 is negative.
10690
10691 So, a value like 0.2 is exactly represented in decimal---since
10692 it is a fraction, @samp{2/10}, with a denominator that is compatible
10693 with the base of the number system (base 10).
10694 However, @samp{2/10} cannot be represented by any finite number
10695 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
10696 be exactly represented in binary notation.
10697
10698 (On the other hand, decimal notation can represent any binary
10699 number in a finite number of digits.
10700 Decimal notation cannot do so with ternary, or base-3,
10701 notation, which would represent floating-point numbers as
10702 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
10703 After all, no finite number of decimal digits can exactly
10704 represent @samp{1/3}.
10705 Fortunately, few systems use ternary notation.)
10706
10707 Moreover, differences in the way run-time I/O libraries convert
10708 between these approximations and the decimal representation often
10709 used by programmers and the programs they write can result in
10710 apparent differences between results that do not actually exist,
10711 or exist to such a small degree that they usually are not worth
10712 worrying about.
10713
10714 For example, consider the following program:
10715
10716 @smallexample
10717 PRINT *, 0.2
10718 END
10719 @end smallexample
10720
10721 When compiled by @code{g77}, the above program might output
10722 @samp{0.20000003}, while another compiler might produce a
10723 executable that outputs @samp{0.2}.
10724
10725 This particular difference is due to the fact that, currently,
10726 conversion of floating-point values by the @code{libg2c} library,
10727 used by @code{g77}, handles only double-precision values.
10728
10729 Since @samp{0.2} in the program is a single-precision value, it
10730 is converted to double precision (still in binary notation)
10731 before being converted back to decimal.
10732 The conversion to binary appends @emph{binary} zero digits to the
10733 original value---which, again, is an inexact approximation of
10734 0.2---resulting in an approximation that is much less exact
10735 than is connoted by the use of double precision.
10736
10737 (The appending of binary zero digits has essentially the same
10738 effect as taking a particular decimal approximation of
10739 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
10740 zeros to it, producing @samp{0.33333330000000000}.
10741 Treating the resulting decimal approximation as if it really
10742 had 18 or so digits of valid precision would make it seem
10743 a very poor approximation of @samp{1/3}.)
10744
10745 As a result of converting the single-precision approximation
10746 to double precision by appending binary zeros, the conversion
10747 of the resulting double-precision
10748 value to decimal produces what looks like an incorrect
10749 result, when in fact the result is @emph{inexact}, and
10750 is probably no less inaccurate or imprecise an approximation
10751 of 0.2 than is produced by other compilers that happen to output
10752 the converted value as ``exactly'' @samp{0.2}.
10753 (Some compilers behave in a way that can make them appear
10754 to retain more accuracy across a conversion of a single-precision
10755 constant to double precision.
10756 @xref{Context-Sensitive Constants}, to see why
10757 this practice is illusory and even dangerous.)
10758
10759 Note that a more exact approximation of the constant is
10760 computed when the program is changed to specify a
10761 double-precision constant:
10762
10763 @smallexample
10764 PRINT *, 0.2D0
10765 END
10766 @end smallexample
10767
10768 Future versions of @code{g77} and/or @code{libg2c} might convert
10769 single-precision values directly to decimal,
10770 instead of converting them to double precision first.
10771 This would tend to result in output that is more consistent
10772 with that produced by some other Fortran implementations.
10773
10774 A useful source of information on floating-point computation is David
10775 Goldberg, `What Every Computer Scientist Should Know About
10776 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
10777 5-48.
10778 An online version is available at
10779 @uref{http://docs.sun.com/},
10780 and there is a supplemented version, in PostScript form, at
10781 @uref{http://www.validgh.com/goldberg/paper.ps}.
10782
10783 Information related to the IEEE 754
10784 floating-point standard by a leading light can be found at
10785 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status/};
10786 see also slides from the short course referenced from
10787 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
10788 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
10789 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
10790 and library code for GNU/Linux x86 systems.
10791
10792 The supplement to the PostScript-formatted Goldberg document,
10793 referenced above, is available in HTML format.
10794 See `Differences Among IEEE 754 Implementations' by Doug Priest,
10795 available online at
10796 @uref{http://www.validgh.com/goldberg/addendum.html}.
10797 This document explores some of the issues surrounding computing
10798 of extended (80-bit) results on processors such as the x86,
10799 especially when those results are arbitrarily truncated
10800 to 32-bit or 64-bit values by the compiler
10801 as ``spills''.
10802
10803 @cindex spills of floating-point results
10804 @cindex 80-bit spills
10805 @cindex truncation, of floating-point values
10806 (@emph{Note:} @code{g77} specifically, and @code{gcc} generally,
10807 does arbitrarily truncate 80-bit results during spills
10808 as of this writing.
10809 It is not yet clear whether a future version of
10810 the GNU compiler suite will offer 80-bit spills
10811 as an option, or perhaps even as the default behavior.)
10812
10813 @c xref would be different between editions:
10814 The GNU C library provides routines for controlling the FPU, and other
10815 documentation about this.
10816
10817 @xref{Floating-point precision}, regarding IEEE 754 conformance.
10818
10819 @include bugs.texi
10820
10821 @node Missing Features
10822 @section Missing Features
10823
10824 This section lists features we know are missing from @code{g77},
10825 and which we want to add someday.
10826 (There is no priority implied in the ordering below.)
10827
10828 @menu
10829 GNU Fortran language:
10830 * Better Source Model::
10831 * Fortran 90 Support::
10832 * Intrinsics in PARAMETER Statements::
10833 * Arbitrary Concatenation::
10834 * SELECT CASE on CHARACTER Type::
10835 * RECURSIVE Keyword::
10836 * Popular Non-standard Types::
10837 * Full Support for Compiler Types::
10838 * Array Bounds Expressions::
10839 * POINTER Statements::
10840 * Sensible Non-standard Constructs::
10841 * READONLY Keyword::
10842 * FLUSH Statement::
10843 * Expressions in FORMAT Statements::
10844 * Explicit Assembler Code::
10845 * Q Edit Descriptor::
10846
10847 GNU Fortran dialects:
10848 * Old-style PARAMETER Statements::
10849 * TYPE and ACCEPT I/O Statements::
10850 * STRUCTURE UNION RECORD MAP::
10851 * OPEN CLOSE and INQUIRE Keywords::
10852 * ENCODE and DECODE::
10853 * AUTOMATIC Statement::
10854 * Suppressing Space Padding::
10855 * Fortran Preprocessor::
10856 * Bit Operations on Floating-point Data::
10857 * Really Ugly Character Assignments::
10858
10859 New facilities:
10860 * POSIX Standard::
10861 * Floating-point Exception Handling::
10862 * Nonportable Conversions::
10863 * Large Automatic Arrays::
10864 * Support for Threads::
10865 * Increasing Precision/Range::
10866 * Enabling Debug Lines::
10867
10868 Better diagnostics:
10869 * Better Warnings::
10870 * Gracefully Handle Sensible Bad Code::
10871 * Non-standard Conversions::
10872 * Non-standard Intrinsics::
10873 * Modifying DO Variable::
10874 * Better Pedantic Compilation::
10875 * Warn About Implicit Conversions::
10876 * Invalid Use of Hollerith Constant::
10877 * Dummy Array Without Dimensioning Dummy::
10878 * Invalid FORMAT Specifiers::
10879 * Ambiguous Dialects::
10880 * Unused Labels::
10881 * Informational Messages::
10882
10883 Run-time facilities:
10884 * Uninitialized Variables at Run Time::
10885 * Portable Unformatted Files::
10886 * Better List-directed I/O::
10887 * Default to Console I/O::
10888
10889 Debugging:
10890 * Labels Visible to Debugger::
10891 @end menu
10892
10893 @node Better Source Model
10894 @subsection Better Source Model
10895
10896 @code{g77} needs to provide, as the default source-line model,
10897 a ``pure visual'' mode, where
10898 the interpretation of a source program in this mode can be accurately
10899 determined by a user looking at a traditionally displayed rendition
10900 of the program (assuming the user knows whether the program is fixed
10901 or free form).
10902
10903 The design should assume the user cannot tell tabs from spaces
10904 and cannot see trailing spaces on lines, but has canonical tab stops
10905 and, for fixed-form source, has the ability to always know exactly
10906 where column 72 is (since the Fortran standard itself requires
10907 this for fixed-form source).
10908
10909 This would change the default treatment of fixed-form source
10910 to not treat lines with tabs as if they were infinitely long---instead,
10911 they would end at column 72 just as if the tabs were replaced
10912 by spaces in the canonical way.
10913
10914 As part of this, provide common alternate models (Digital, @code{f2c},
10915 and so on) via command-line options.
10916 This includes allowing arbitrarily long
10917 lines for free-form source as well as fixed-form source and providing
10918 various limits and diagnostics as appropriate.
10919
10920 @cindex sequence numbers
10921 @cindex columns 73 through 80
10922 Also, @code{g77} should offer, perhaps even default to, warnings
10923 when characters beyond the last valid column are anything other
10924 than spaces.
10925 This would mean code with ``sequence numbers'' in columns 73 through 80
10926 would be rejected, and there's a lot of that kind of code around,
10927 but one of the most frequent bugs encountered by new users is
10928 accidentally writing fixed-form source code into and beyond
10929 column 73.
10930 So, maybe the users of old code would be able to more easily handle
10931 having to specify, say, a @samp{-Wno-col73to80} option.
10932
10933 @node Fortran 90 Support
10934 @subsection Fortran 90 Support
10935 @cindex Fortran 90, support
10936 @cindex support, Fortran 90
10937
10938 @code{g77} does not support many of the features that
10939 distinguish Fortran 90 (and, now, Fortran 95) from
10940 ANSI FORTRAN 77.
10941
10942 Some Fortran 90 features are supported, because they
10943 make sense to offer even to die-hard users of F77.
10944 For example, many of them codify various ways F77 has
10945 been extended to meet users' needs during its tenure,
10946 so @code{g77} might as well offer them as the primary
10947 way to meet those same needs, even if it offers compatibility
10948 with one or more of the ways those needs were met
10949 by other F77 compilers in the industry.
10950
10951 Still, many important F90 features are not supported,
10952 because no attempt has been made to research each and
10953 every feature and assess its viability in @code{g77}.
10954 In the meantime, users who need those features must
10955 use Fortran 90 compilers anyway, and the best approach
10956 to adding some F90 features to GNU Fortran might well be
10957 to fund a comprehensive project to create GNU Fortran 95.
10958
10959 @node Intrinsics in PARAMETER Statements
10960 @subsection Intrinsics in @code{PARAMETER} Statements
10961 @cindex PARAMETER statement
10962 @cindex statements, PARAMETER
10963
10964 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
10965 This feature is considered to be absolutely vital, even though it
10966 is not standard-conforming, and is scheduled for version 0.6.
10967
10968 Related to this, @code{g77} doesn't allow non-integral
10969 exponentiation in @code{PARAMETER} statements, such as
10970 @samp{PARAMETER (R=2**.25)}.
10971 It is unlikely @code{g77} will ever support this feature,
10972 as doing it properly requires complete emulation of
10973 a target computer's floating-point facilities when
10974 building @code{g77} as a cross-compiler.
10975 But, if the @code{gcc} back end is enhanced to provide
10976 such a facility, @code{g77} will likely use that facility
10977 in implementing this feature soon afterwards.
10978
10979 @node Arbitrary Concatenation
10980 @subsection Arbitrary Concatenation
10981 @cindex concatenation
10982 @cindex CHARACTER*(*)
10983 @cindex run-time, dynamic allocation
10984
10985 @code{g77} doesn't support arbitrary operands for concatenation
10986 in contexts where run-time allocation is required.
10987 For example:
10988
10989 @smallexample
10990 SUBROUTINE X(A)
10991 CHARACTER*(*) A
10992 CALL FOO(A // 'suffix')
10993 @end smallexample
10994
10995 @node SELECT CASE on CHARACTER Type
10996 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
10997
10998 Character-type selector/cases for @code{SELECT CASE} currently
10999 are not supported.
11000
11001 @node RECURSIVE Keyword
11002 @subsection @code{RECURSIVE} Keyword
11003 @cindex RECURSIVE keyword
11004 @cindex keywords, RECURSIVE
11005 @cindex recursion, lack of
11006 @cindex lack of recursion
11007
11008 @code{g77} doesn't support the @code{RECURSIVE} keyword that
11009 F90 compilers do.
11010 Nor does it provide any means for compiling procedures
11011 designed to do recursion.
11012
11013 All recursive code can be rewritten to not use recursion,
11014 but the result is not pretty.
11015
11016 @node Increasing Precision/Range
11017 @subsection Increasing Precision/Range
11018 @cindex -r8
11019 @cindex -qrealsize=8
11020 @cindex -i8
11021 @cindex f2c
11022 @cindex increasing precision
11023 @cindex precision, increasing
11024 @cindex increasing range
11025 @cindex range, increasing
11026 @cindex Toolpack
11027 @cindex Netlib
11028
11029 Some compilers, such as @code{f2c}, have an option (@samp{-r8},
11030 @samp{-qrealsize=8} or
11031 similar) that provides automatic treatment of @code{REAL}
11032 entities such that they have twice the storage size, and
11033 a corresponding increase in the range and precision, of what
11034 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
11035 (This affects @code{COMPLEX} the same way.)
11036
11037 They also typically offer another option (@samp{-i8}) to increase
11038 @code{INTEGER} entities so they are twice as large
11039 (with roughly twice as much range).
11040
11041 (There are potential pitfalls in using these options.)
11042
11043 @code{g77} does not yet offer any option that performs these
11044 kinds of transformations.
11045 Part of the problem is the lack of detailed specifications regarding
11046 exactly how these options affect the interpretation of constants,
11047 intrinsics, and so on.
11048
11049 Until @code{g77} addresses this need, programmers could improve
11050 the portability of their code by modifying it to not require
11051 compile-time options to produce correct results.
11052 Some free tools are available which may help, specifically
11053 in Toolpack (which one would expect to be sound) and the @file{fortran}
11054 section of the Netlib repository.
11055
11056 Use of preprocessors can provide a fairly portable means
11057 to work around the lack of widely portable methods in the Fortran
11058 language itself (though increasing acceptance of Fortran 90 would
11059 alleviate this problem).
11060
11061 @node Popular Non-standard Types
11062 @subsection Popular Non-standard Types
11063 @cindex @code{INTEGER*2} support
11064 @cindex types, @code{INTEGER*2}
11065 @cindex @code{LOGICAL*1} support
11066 @cindex types, @code{LOGICAL*1}
11067
11068 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
11069 and similar.
11070 Version 0.6 will provide full support for this very
11071 popular set of features.
11072 In the meantime, version 0.5.18 provides rudimentary support
11073 for them.
11074
11075 @node Full Support for Compiler Types
11076 @subsection Full Support for Compiler Types
11077
11078 @cindex @code{REAL*16} support
11079 @cindex types, @code{REAL*16}
11080 @cindex @code{INTEGER*8} support
11081 @cindex types, @code{INTEGER*8}
11082 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
11083 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
11084 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
11085 This means providing intrinsic support, and maybe constant
11086 support (using F90 syntax) as well, and, for most
11087 machines will result in automatic support of @code{INTEGER*1},
11088 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
11089 and so on.
11090 This is scheduled for version 0.6.
11091
11092 @node Array Bounds Expressions
11093 @subsection Array Bounds Expressions
11094 @cindex array elements, in adjustable array bounds
11095 @cindex function references, in adjustable array bounds
11096 @cindex array bounds, adjustable
11097 @cindex @code{DIMENSION} statement
11098 @cindex statements, @code{DIMENSION}
11099
11100 @code{g77} doesn't support more general expressions to dimension
11101 arrays, such as array element references, function
11102 references, etc.
11103
11104 For example, @code{g77} currently does not accept the following:
11105
11106 @smallexample
11107 SUBROUTINE X(M, N)
11108 INTEGER N(10), M(N(2), N(1))
11109 @end smallexample
11110
11111 @node POINTER Statements
11112 @subsection POINTER Statements
11113 @cindex POINTER statement
11114 @cindex statements, POINTER
11115 @cindex Cray pointers
11116
11117 @code{g77} doesn't support pointers or allocatable objects
11118 (other than automatic arrays).
11119 This set of features is
11120 probably considered just behind intrinsics
11121 in @code{PARAMETER} statements on the list of large,
11122 important things to add to @code{g77}.
11123
11124 In the meantime, consider using the @code{INTEGER(KIND=7)}
11125 declaration to specify that a variable must be
11126 able to hold a pointer.
11127 This construct is not portable to other non-GNU compilers,
11128 but it is portable to all machines GNU Fortran supports
11129 when @code{g77} is used.
11130
11131 @xref{Functions and Subroutines}, for information on
11132 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
11133 constructs, which are useful for passing pointers to
11134 procedures written in languages other than Fortran.
11135
11136 @node Sensible Non-standard Constructs
11137 @subsection Sensible Non-standard Constructs
11138
11139 @code{g77} rejects things other compilers accept,
11140 like @samp{INTRINSIC SQRT,SQRT}.
11141 As time permits in the future, some of these things that are easy for
11142 humans to read and write and unlikely to be intended to mean something
11143 else will be accepted by @code{g77} (though @samp{-fpedantic} should
11144 trigger warnings about such non-standard constructs).
11145
11146 Until @code{g77} no longer gratuitously rejects sensible code,
11147 you might as well fix your code
11148 to be more standard-conforming and portable.
11149
11150 The kind of case that is important to except from the
11151 recommendation to change your code is one where following
11152 good coding rules would force you to write non-standard
11153 code that nevertheless has a clear meaning.
11154
11155 For example, when writing an @code{INCLUDE} file that
11156 defines a common block, it might be appropriate to
11157 include a @code{SAVE} statement for the common block
11158 (such as @samp{SAVE /CBLOCK/}), so that variables
11159 defined in the common block retain their values even
11160 when all procedures declaring the common block become
11161 inactive (return to their callers).
11162
11163 However, putting @code{SAVE} statements in an @code{INCLUDE}
11164 file would prevent otherwise standard-conforming code
11165 from also specifying the @code{SAVE} statement, by itself,
11166 to indicate that all local variables and arrays are to
11167 have the @code{SAVE} attribute.
11168
11169 For this reason, @code{g77} already has been changed to
11170 allow this combination, because although the general
11171 problem of gratuitously rejecting unambiguous and
11172 ``safe'' constructs still exists in @code{g77}, this
11173 particular construct was deemed useful enough that
11174 it was worth fixing @code{g77} for just this case.
11175
11176 So, while there is no need to change your code
11177 to avoid using this particular construct, there
11178 might be other, equally appropriate but non-standard
11179 constructs, that you shouldn't have to stop using
11180 just because @code{g77} (or any other compiler)
11181 gratuitously rejects it.
11182
11183 Until the general problem is solved, if you have
11184 any such construct you believe is worthwhile
11185 using (e.g. not just an arbitrary, redundant
11186 specification of an attribute), please submit a
11187 bug report with an explanation, so we can consider
11188 fixing @code{g77} just for cases like yours.
11189
11190 @node READONLY Keyword
11191 @subsection @code{READONLY} Keyword
11192 @cindex READONLY
11193
11194 Support for @code{READONLY}, in @code{OPEN} statements,
11195 requires @code{libg2c} support,
11196 to make sure that @samp{CLOSE(@dots{},STATUS='DELETE')}
11197 does not delete a file opened on a unit
11198 with the @code{READONLY} keyword,
11199 and perhaps to trigger a fatal diagnostic
11200 if a @code{WRITE} or @code{PRINT}
11201 to such a unit is attempted.
11202
11203 @emph{Note:} It is not sufficient for @code{g77} and @code{libg2c}
11204 (its version of @code{libf2c})
11205 to assume that @code{READONLY} does not need some kind of explicit support
11206 at run time,
11207 due to UNIX systems not (generally) needing it.
11208 @code{g77} is not just a UNIX-based compiler!
11209
11210 Further, mounting of non-UNIX filesystems on UNIX systems
11211 (such as via NFS)
11212 might require proper @code{READONLY} support.
11213
11214 @cindex SHARED
11215 (Similar issues might be involved with supporting the @code{SHARED}
11216 keyword.)
11217
11218 @node FLUSH Statement
11219 @subsection @code{FLUSH} Statement
11220
11221 @code{g77} could perhaps use a @code{FLUSH} statement that
11222 does what @samp{CALL FLUSH} does,
11223 but that supports @samp{*} as the unit designator (same unit as for
11224 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
11225 specifiers.
11226
11227 @node Expressions in FORMAT Statements
11228 @subsection Expressions in @code{FORMAT} Statements
11229 @cindex FORMAT statement
11230 @cindex statements, FORMAT
11231
11232 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
11233 Supporting this requires a significant redesign or replacement
11234 of @code{libg2c}.
11235
11236 However, @code{g77} does support
11237 this construct when the expression is constant
11238 (as of version 0.5.22).
11239 For example:
11240
11241 @smallexample
11242       PARAMETER (IWIDTH = 12)
11243 10    FORMAT (I<IWIDTH>)
11244 @end smallexample
11245
11246 Otherwise, at least for output (@code{PRINT} and
11247 @code{WRITE}), Fortran code making use of this feature can
11248 be rewritten to avoid it by constructing the @code{FORMAT}
11249 string in a @code{CHARACTER} variable or array, then
11250 using that variable or array in place of the @code{FORMAT}
11251 statement label to do the original @code{PRINT} or @code{WRITE}.
11252
11253 Many uses of this feature on input can be rewritten this way
11254 as well, but not all can.
11255 For example, this can be rewritten:
11256
11257 @smallexample
11258       READ 20, I
11259 20    FORMAT (I<J>)
11260 @end smallexample
11261
11262 However, this cannot, in general, be rewritten, especially
11263 when @code{ERR=} and @code{END=} constructs are employed:
11264
11265 @smallexample
11266       READ 30, J, I
11267 30    FORMAT (I<J>)
11268 @end smallexample
11269
11270 @node Explicit Assembler Code
11271 @subsection Explicit Assembler Code
11272
11273 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
11274 code to specify explicit assembler code.
11275
11276 @node Q Edit Descriptor
11277 @subsection Q Edit Descriptor
11278 @cindex FORMAT statement
11279 @cindex Q edit descriptor
11280 @cindex edit descriptor, Q
11281
11282 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
11283 (This is meant to get the number of characters remaining in an input record.)
11284 Supporting this requires a significant redesign or replacement
11285 of @code{libg2c}.
11286
11287 A workaround might be using internal I/O or the stream-based intrinsics.
11288 @xref{FGetC Intrinsic (subroutine)}.
11289
11290 @node Old-style PARAMETER Statements
11291 @subsection Old-style PARAMETER Statements
11292 @cindex PARAMETER statement
11293 @cindex statements, PARAMETER
11294
11295 @code{g77} doesn't accept @samp{PARAMETER I=1}.
11296 Supporting this obsolete form of
11297 the @code{PARAMETER} statement would not be particularly hard, as most of the
11298 parsing code is already in place and working.
11299
11300 Until time/money is
11301 spent implementing it, you might as well fix your code to use the
11302 standard form, @samp{PARAMETER (I=1)} (possibly needing
11303 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
11304 otherwise, in the obsolete form of @code{PARAMETER}, the
11305 type of the variable is set from the type of the constant being
11306 assigned to it).
11307
11308 @node TYPE and ACCEPT I/O Statements
11309 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
11310 @cindex TYPE statement
11311 @cindex statements, TYPE
11312 @cindex ACCEPT statement
11313 @cindex statements, ACCEPT
11314
11315 @code{g77} doesn't support the I/O statements @code{TYPE} and
11316 @code{ACCEPT}.
11317 These are common extensions that should be easy to support,
11318 but also are fairly easy to work around in user code.
11319
11320 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
11321 by @samp{PRINT fmt,list}.
11322 And, any @samp{ACCEPT fmt,list} statement can be
11323 replaced by @samp{READ fmt,list}.
11324
11325 @node STRUCTURE UNION RECORD MAP
11326 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
11327 @cindex STRUCTURE statement
11328 @cindex statements, STRUCTURE
11329 @cindex UNION statement
11330 @cindex statements, UNION
11331 @cindex RECORD statement
11332 @cindex statements, RECORD
11333 @cindex MAP statement
11334 @cindex statements, MAP
11335
11336 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
11337 @code{MAP}.
11338 This set of extensions is quite a bit
11339 lower on the list of large, important things to add to @code{g77}, partly
11340 because it requires a great deal of work either upgrading or
11341 replacing @code{libg2c}.
11342
11343 @node OPEN CLOSE and INQUIRE Keywords
11344 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
11345 @cindex disposition of files
11346 @cindex OPEN statement
11347 @cindex statements, OPEN
11348 @cindex CLOSE statement
11349 @cindex statements, CLOSE
11350 @cindex INQUIRE statement
11351 @cindex statements, INQUIRE
11352
11353 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
11354 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
11355 These extensions are easy to add to @code{g77} itself, but
11356 require much more work on @code{libg2c}.
11357
11358 @cindex FORM='PRINT'
11359 @cindex ANS carriage control
11360 @cindex carriage control
11361 @pindex asa
11362 @pindex fpr
11363 @code{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
11364 translate the traditional `carriage control' characters in column 1 of
11365 output to use backspaces, carriage returns and the like.  However
11366 programs exist to translate them in output files (or standard output).
11367 These are typically called either @code{fpr} or @code{asa}.  You can get
11368 a version of @code{asa} from
11369 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
11370 systems which will probably build easily on other systems.
11371 Alternatively, @code{fpr} is in BSD distributions in various archive
11372 sites.
11373
11374 @c (Can both programs can be used in a pipeline,
11375 @c with a named input file,
11376 @c and/or with a named output file???)
11377
11378 @node ENCODE and DECODE
11379 @subsection @code{ENCODE} and @code{DECODE}
11380 @cindex ENCODE statement
11381 @cindex statements, ENCODE
11382 @cindex DECODE statement
11383 @cindex statements, DECODE
11384
11385 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
11386
11387 These statements are best replaced by READ and WRITE statements
11388 involving internal files (CHARACTER variables and arrays).
11389
11390 For example, replace a code fragment like
11391
11392 @smallexample
11393       INTEGER*1 LINE(80)
11394 @dots{}
11395       DECODE (80, 9000, LINE) A, B, C
11396 @dots{}
11397 9000  FORMAT (1X, 3(F10.5))
11398 @end smallexample
11399
11400 @noindent
11401 with:
11402
11403 @smallexample
11404       CHARACTER*80 LINE
11405 @dots{}
11406       READ (UNIT=LINE, FMT=9000) A, B, C
11407 @dots{}
11408 9000  FORMAT (1X, 3(F10.5))
11409 @end smallexample
11410
11411 Similarly, replace a code fragment like
11412
11413 @smallexample
11414       INTEGER*1 LINE(80)
11415 @dots{}
11416       ENCODE (80, 9000, LINE) A, B, C
11417 @dots{}
11418 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11419 @end smallexample
11420
11421 @noindent
11422 with:
11423
11424 @smallexample
11425       CHARACTER*80 LINE
11426 @dots{}
11427       WRITE (UNIT=LINE, FMT=9000) A, B, C
11428 @dots{}
11429 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11430 @end smallexample
11431
11432 It is entirely possible that @code{ENCODE} and @code{DECODE} will
11433 be supported by a future version of @code{g77}.
11434
11435 @node AUTOMATIC Statement
11436 @subsection @code{AUTOMATIC} Statement
11437 @cindex @code{AUTOMATIC} statement
11438 @cindex statements, @code{AUTOMATIC}
11439 @cindex automatic variables
11440 @cindex variables, automatic
11441
11442 @code{g77} doesn't support the @code{AUTOMATIC} statement that
11443 @code{f2c} does.
11444
11445 @code{AUTOMATIC} would identify a variable or array
11446 as not being @code{SAVE}'d, which is normally the default,
11447 but which would be especially useful for code that, @emph{generally},
11448 needed to be compiled with the @samp{-fno-automatic} option.
11449
11450 @code{AUTOMATIC} also would serve as a hint to the compiler that placing
11451 the variable or array---even a very large array--on the stack is acceptable.
11452
11453 @code{AUTOMATIC} would not, by itself, designate the containing procedure
11454 as recursive.
11455
11456 @code{AUTOMATIC} should work syntactically like @code{SAVE},
11457 in that @code{AUTOMATIC} with no variables listed should apply to
11458 all pertinent variables and arrays
11459 (which would not include common blocks or their members).
11460
11461 Variables and arrays denoted as @code{AUTOMATIC}
11462 would not be permitted to be initialized via @code{DATA}
11463 or other specification of any initial values,
11464 requiring explicit initialization,
11465 such as via assignment statements.
11466
11467 @cindex UNSAVE
11468 @cindex STATIC
11469 Perhaps @code{UNSAVE} and @code{STATIC},
11470 as strict semantic opposites to @code{SAVE} and @code{AUTOMATIC},
11471 should be provided as well.
11472
11473 @node Suppressing Space Padding
11474 @subsection Suppressing Space Padding of Source Lines
11475
11476 @code{g77} should offer VXT-Fortran-style suppression of virtual
11477 spaces at the end of a source line
11478 if an appropriate command-line option is specified.
11479
11480 This affects cases where
11481 a character constant is continued onto the next line in a fixed-form
11482 source file, as in the following example:
11483
11484 @smallexample
11485 10    PRINT *,'HOW MANY
11486      1 SPACES?'
11487 @end smallexample
11488
11489 @noindent
11490 @code{g77}, and many other compilers, virtually extend
11491 the continued line through column 72 with spaces that become part
11492 of the character constant, but Digital Fortran normally didn't,
11493 leaving only one space between @samp{MANY} and @samp{SPACES?}
11494 in the output of the above statement.
11495
11496 Fairly recently, at least one version of Digital Fortran
11497 was enhanced to provide the other behavior when a
11498 command-line option is specified, apparently due to demand
11499 from readers of the USENET group @file{comp.lang.fortran}
11500 to offer conformance to this widespread practice in the
11501 industry.
11502 @code{g77} should return the favor by offering conformance
11503 to Digital's approach to handling the above example.
11504
11505 @node Fortran Preprocessor
11506 @subsection Fortran Preprocessor
11507
11508 @code{g77} should offer a preprocessor designed specifically
11509 for Fortran to replace @samp{cpp -traditional}.
11510 There are several out there worth evaluating, at least.
11511
11512 Such a preprocessor would recognize Hollerith constants,
11513 properly parse comments and character constants, and so on.
11514 It might also recognize, process, and thus preprocess
11515 files included via the @code{INCLUDE} directive.
11516
11517 @node Bit Operations on Floating-point Data
11518 @subsection Bit Operations on Floating-point Data
11519 @cindex @code{And} intrinsic
11520 @cindex intrinsics, @code{And}
11521 @cindex @code{Or} intrinsic
11522 @cindex intrinsics, @code{Or}
11523 @cindex @code{Shift} intrinsic
11524 @cindex intrinsics, @code{Shift}
11525
11526 @code{g77} does not allow @code{REAL} and other non-integral types for
11527 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
11528
11529 For example, this program is rejected by @code{g77}, because
11530 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
11531
11532 @smallexample
11533 DATA A/7.54/, B/9.112/
11534 PRINT *, IAND(A, B)
11535 END
11536 @end smallexample
11537
11538 @node Really Ugly Character Assignments
11539 @subsection Really Ugly Character Assignments
11540
11541 An option such as @samp{-fugly-char} should be provided
11542 to allow
11543
11544 @smallexample
11545 REAL*8 A1
11546 DATA A1 / '12345678' /
11547 @end smallexample
11548
11549 and:
11550
11551 @smallexample
11552 REAL*8 A1
11553 A1 = 'ABCDEFGH'
11554 @end smallexample
11555
11556 @node POSIX Standard
11557 @subsection @code{POSIX} Standard
11558
11559 @code{g77} should support the POSIX standard for Fortran.
11560
11561 @node Floating-point Exception Handling
11562 @subsection Floating-point Exception Handling
11563 @cindex floating-point, exceptions
11564 @cindex exceptions, floating-point
11565 @cindex FPE handling
11566 @cindex NaN values
11567
11568 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
11569 general control over whether or not floating-point exceptions are trapped or
11570 ignored.
11571 (Ignoring them typically results in NaN values being
11572 propagated in systems that conform to IEEE 754.)
11573 The behaviour is normally inherited from the system-dependent startup
11574 code, though some targets, such as the Alpha, have code generation
11575 options which change the behaviour.
11576
11577 Most systems provide some C-callable mechanism to change this; this can
11578 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
11579 For example, just compiling and linking the following C code with your
11580 program will turn on exception trapping for the ``common'' exceptions
11581 on a GNU system using glibc 2.2 or newer:
11582
11583 @smallexample
11584 #define _GNU_SOURCE 1
11585 #include <fenv.h>
11586 static void __attribute__ ((constructor))
11587 trapfpe ()
11588 @{
11589   /* Enable some exceptions.  At startup all exceptions are masked.  */
11590   
11591   feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
11592 @}
11593 @end smallexample
11594
11595 A convenient trick is to compile this something like:
11596 @smallexample
11597 gcc -o libtrapfpe.a trapfpe.c
11598 @end smallexample
11599 and then use it by adding @samp{-trapfpe} to the @code{g77} command line
11600 when linking.
11601
11602 @node Nonportable Conversions
11603 @subsection Nonportable Conversions
11604 @cindex nonportable conversions
11605 @cindex conversions, nonportable
11606
11607 @code{g77} doesn't accept some particularly nonportable,
11608 silent data-type conversions such as @code{LOGICAL}
11609 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
11610 is type @code{REAL}), that other compilers might
11611 quietly accept.
11612
11613 Some of these conversions are accepted by @code{g77}
11614 when the @samp{-fugly-logint} option is specified.
11615 Perhaps it should accept more or all of them.
11616
11617 @node Large Automatic Arrays
11618 @subsection Large Automatic Arrays
11619 @cindex automatic arrays
11620 @cindex arrays, automatic
11621
11622 Currently, automatic arrays always are allocated on the stack.
11623 For situations where the stack cannot be made large enough,
11624 @code{g77} should offer a compiler option that specifies
11625 allocation of automatic arrays in heap storage.
11626
11627 @node Support for Threads
11628 @subsection Support for Threads
11629 @cindex threads
11630 @cindex parallel processing
11631
11632 Neither the code produced by @code{g77} nor the @code{libg2c} library
11633 are thread-safe, nor does @code{g77} have support for parallel processing
11634 (other than the instruction-level parallelism available on some
11635 processors).
11636 A package such as PVM might help here.
11637
11638 @node Enabling Debug Lines
11639 @subsection Enabling Debug Lines
11640 @cindex debug line
11641 @cindex comment line, debug
11642
11643 An option such as @samp{-fdebug-lines} should be provided
11644 to turn fixed-form lines beginning with @samp{D}
11645 to be treated as if they began with a space,
11646 instead of as if they began with a @samp{C}
11647 (as comment lines).
11648
11649 @node Better Warnings
11650 @subsection Better Warnings
11651
11652 Because of how @code{g77} generates code via the back end,
11653 it doesn't always provide warnings the user wants.
11654 Consider:
11655
11656 @smallexample
11657 PROGRAM X
11658 PRINT *, A
11659 END
11660 @end smallexample
11661
11662 Currently, the above is not flagged as a case of
11663 using an uninitialized variable,
11664 because @code{g77} generates a run-time library call that looks,
11665 to the GBE, like it might actually @emph{modify} @samp{A} at run time.
11666 (And, in fact, depending on the previous run-time library call,
11667 it would!)
11668
11669 Fixing this requires one of the following:
11670
11671 @itemize @bullet
11672 @item
11673 Switch to new library, @code{libg77}, that provides
11674 a more ``clean'' interface,
11675 vis-a-vis input, output, and modified arguments,
11676 so the GBE can tell what's going on.
11677
11678 This would provide a pretty big performance improvement,
11679 at least theoretically, and, ultimately, in practice,
11680 for some types of code.
11681
11682 @item
11683 Have @code{g77} pass a pointer to a temporary
11684 containing a copy of @samp{A},
11685 instead of to @samp{A} itself.
11686 The GBE would then complain about the copy operation
11687 involving a potentially uninitialized variable.
11688
11689 This might also provide a performance boost for some code,
11690 because @samp{A} might then end up living in a register,
11691 which could help with inner loops.
11692
11693 @item
11694 Have @code{g77} use a GBE construct similar to @code{ADDR_EXPR}
11695 but with extra information on the fact that the
11696 item pointed to won't be modified
11697 (a la @code{const} in C).
11698
11699 Probably the best solution for now, but not quite trivial
11700 to implement in the general case.
11701 Worth considering after @code{g77} 0.6 is considered
11702 pretty solid.
11703 @end itemize
11704
11705 @node Gracefully Handle Sensible Bad Code
11706 @subsection Gracefully Handle Sensible Bad Code
11707
11708 @code{g77} generally should continue processing for
11709 warnings and recoverable (user) errors whenever possible---that
11710 is, it shouldn't gratuitously make bad or useless code.
11711
11712 For example:
11713
11714 @smallexample
11715 INTRINSIC ZABS
11716 CALL FOO(ZABS)
11717 END
11718 @end smallexample
11719
11720 @noindent
11721 When compiling the above with @samp{-ff2c-intrinsics-disable},
11722 @code{g77} should indeed complain about passing @code{ZABS},
11723 but it still should compile, instead of rejecting
11724 the entire @code{CALL} statement.
11725 (Some of this is related to improving
11726 the compiler internals to improve how statements are analyzed.)
11727
11728 @node Non-standard Conversions
11729 @subsection Non-standard Conversions
11730
11731 @samp{-Wconversion} and related should flag places where non-standard
11732 conversions are found.
11733 Perhaps much of this would be part of @samp{-Wugly*}.
11734
11735 @node Non-standard Intrinsics
11736 @subsection Non-standard Intrinsics
11737
11738 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
11739 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
11740 This would help find code that might fail silently when ported to another
11741 compiler.
11742
11743 @node Modifying DO Variable
11744 @subsection Modifying @code{DO} Variable
11745
11746 @code{g77} should warn about modifying @code{DO} variables
11747 via @code{EQUIVALENCE}.
11748 (The internal information gathered to produce this warning
11749 might also be useful in setting the
11750 internal ``doiter'' flag for a variable or even array
11751 reference within a loop, since that might produce faster code someday.)
11752
11753 For example, this code is invalid, so @code{g77} should warn about
11754 the invalid assignment to @samp{NOTHER}:
11755
11756 @smallexample
11757 EQUIVALENCE (I, NOTHER)
11758 DO I = 1, 100
11759    IF (I.EQ. 10) NOTHER = 20
11760 END DO
11761 @end smallexample
11762
11763 @node Better Pedantic Compilation
11764 @subsection Better Pedantic Compilation
11765
11766 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
11767 and use it only to generate
11768 warnings instead of rejecting constructs outright.
11769 Have it warn:
11770 if a variable that dimensions an array is not a dummy or placed
11771 explicitly in @code{COMMON} (F77 does not allow it to be
11772 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
11773 follow statement-function-definition statements; about all sorts of
11774 syntactic extensions.
11775
11776 @node Warn About Implicit Conversions
11777 @subsection Warn About Implicit Conversions
11778
11779 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
11780 to expect automatic, silent, and
11781 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
11782 constants to @code{REAL(KIND=2)} based on context.
11783
11784 For example, it would warn about cases like this:
11785
11786 @smallexample
11787 DOUBLE PRECISION FOO
11788 PARAMETER (TZPHI = 9.435784839284958)
11789 FOO = TZPHI * 3D0
11790 @end smallexample
11791
11792 @node Invalid Use of Hollerith Constant
11793 @subsection Invalid Use of Hollerith Constant
11794
11795 @code{g77} should disallow statements like @samp{RETURN 2HAB},
11796 which are invalid in both source forms
11797 (unlike @samp{RETURN (2HAB)},
11798 which probably still makes no sense but at least can
11799 be reliably parsed).
11800 Fixed-form processing rejects it, but not free-form, except
11801 in a way that is a bit difficult to understand.
11802
11803 @node Dummy Array Without Dimensioning Dummy
11804 @subsection Dummy Array Without Dimensioning Dummy
11805
11806 @code{g77} should complain when a list of dummy arguments containing an
11807 adjustable dummy array does
11808 not also contain every variable listed in the dimension list of the
11809 adjustable array.
11810
11811 Currently, @code{g77} does complain about a variable that
11812 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
11813 area, but this needs to be extended to catch cases where it doesn't appear in
11814 every dummy list that also lists any arrays it dimensions.
11815
11816 For example, @code{g77} should warn about the entry point @samp{ALT}
11817 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
11818 list of arguments:
11819
11820 @smallexample
11821 SUBROUTINE PRIMARY(ARRAY, ISIZE)
11822 REAL ARRAY(ISIZE)
11823 ENTRY ALT(ARRAY)
11824 @end smallexample
11825
11826 @node Invalid FORMAT Specifiers
11827 @subsection Invalid FORMAT Specifiers
11828
11829 @code{g77} should check @code{FORMAT} specifiers for validity
11830 as it does @code{FORMAT} statements.
11831
11832 For example, a diagnostic would be produced for:
11833
11834 @smallexample
11835 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
11836 @end smallexample
11837
11838 @node Ambiguous Dialects
11839 @subsection Ambiguous Dialects
11840
11841 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
11842 @samp{-Wvxt}, @samp{-Wf90}, and so on.
11843 These would warn about places in the user's source where ambiguities
11844 are found, helpful in resolving ambiguities in the program's
11845 dialect or dialects.
11846
11847 @node Unused Labels
11848 @subsection Unused Labels
11849
11850 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
11851
11852 @node Informational Messages
11853 @subsection Informational Messages
11854
11855 @code{g77} needs an option to suppress information messages (notes).
11856 @samp{-w} does this but also suppresses warnings.
11857 The default should be to suppress info messages.
11858
11859 Perhaps info messages should simply be eliminated.
11860
11861 @node Uninitialized Variables at Run Time
11862 @subsection Uninitialized Variables at Run Time
11863
11864 @code{g77} needs an option to initialize everything (not otherwise
11865 explicitly initialized) to ``weird''
11866 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
11867 largest-magnitude integers, would help track down references to
11868 some kinds of uninitialized variables at run time.
11869
11870 Note that use of the options @samp{-O -Wuninitialized} can catch
11871 many such bugs at compile time.
11872
11873 @node Portable Unformatted Files
11874 @subsection Portable Unformatted Files
11875
11876 @cindex unformatted files
11877 @cindex file formats
11878 @cindex binary data
11879 @cindex byte ordering
11880 @code{g77} has no facility for exchanging unformatted files with systems
11881 using different number formats---even differing only in endianness (byte
11882 order)---or written by other compilers.  Some compilers provide
11883 facilities at least for doing byte-swapping during unformatted I/O.
11884
11885 It is unrealistic to expect to cope with exchanging unformatted files
11886 with arbitrary other compiler runtimes, but the @code{g77} runtime
11887 should at least be able to read files written by @code{g77} on systems
11888 with different number formats, particularly if they differ only in byte
11889 order.
11890
11891 In case you do need to write a program to translate to or from
11892 @code{g77} (@code{libf2c}) unformatted files, they are written as
11893 follows:
11894 @table @asis
11895 @item Sequential
11896 Unformatted sequential records consist of
11897 @enumerate
11898 @item
11899 A number giving the length of the record contents;
11900 @item
11901 the length of record contents again (for backspace).
11902 @end enumerate
11903
11904 The record length is of C type
11905 @code{long}; this means that it is 8 bytes on 64-bit systems such as
11906 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
11907 Consequently such files cannot be exchanged between 64-bit and 32-bit
11908 systems, even with the same basic number format.
11909 @item Direct access
11910 Unformatted direct access files form a byte stream of length
11911 @var{records}*@var{recl} bytes, where @var{records} is the maximum
11912 record number (@code{REC=@var{records}}) written and @var{recl} is the
11913 record length in bytes specified in the @code{OPEN} statement
11914 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
11915 the relevant @code{WRITE} statement.  Dummy records with arbitrary
11916 contents appear in the file in place of records which haven't been
11917 written.
11918 @end table
11919
11920 Thus for exchanging a sequential or direct access unformatted file
11921 between big- and little-endian 32-bit systems using IEEE 754 floating
11922 point it would be sufficient to reverse the bytes in consecutive words
11923 in the file if, and @emph{only} if, only @code{REAL*4}, @code{COMPLEX},
11924 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
11925 @code{g77}.
11926
11927 If necessary, it is possible to do byte-oriented i/o with @code{g77}'s
11928 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
11929 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
11930 array or a set of scalars.
11931
11932 @cindex HDF
11933 @cindex PDB
11934 If you need to exchange binary data between arbitrary system and
11935 compiler variations, we recommend using a portable binary format with
11936 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
11937 or PACT's PDB@footnote{No, not @emph{that} one.}
11938 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
11939 say, CDF or XDR, HDF-like systems write in the native number formats and
11940 only incur overhead when they are read on a system with a different
11941 format.)  A future @code{g77} runtime library should use such
11942 techniques.
11943
11944 @node Better List-directed I/O
11945 @subsection Better List-directed I/O
11946
11947 Values output using list-directed I/O
11948 (@samp{PRINT *, R, D})
11949 should be written with a field width, precision, and so on
11950 appropriate for the type (precision) of each value.
11951
11952 (Currently, no distinction is made between single-precision
11953 and double-precision values
11954 by @code{libf2c}.)
11955
11956 It is likely this item will require the @code{libg77} project
11957 to be undertaken.
11958
11959 In the meantime, use of formatted I/O is recommended.
11960 While it might be of little consolation,
11961 @code{g77} does support @samp{FORMAT(F<WIDTH>.4)}, for example,
11962 as long as @samp{WIDTH} is defined as a named constant
11963 (via @code{PARAMETER}).
11964 That at least allows some compile-time specification
11965 of the precision of a data type,
11966 perhaps controlled by preprocessing directives.
11967
11968 @node Default to Console I/O
11969 @subsection Default to Console I/O
11970
11971 The default I/O units,
11972 specified by @samp{READ @var{fmt}},
11973 @samp{READ (UNIT=*)},
11974 @samp{WRITE (UNIT=*)}, and
11975 @samp{PRINT @var{fmt}},
11976 should not be units 5 (input) and 6 (output),
11977 but, rather, unit numbers not normally available
11978 for use in statements such as @code{OPEN} and @code{CLOSE}.
11979
11980 Changing this would allow a program to connect units 5 and 6
11981 to files via @code{OPEN},
11982 but still use @samp{READ (UNIT=*)} and @samp{PRINT}
11983 to do I/O to the ``console''.
11984
11985 This change probably requires the @code{libg77} project.
11986
11987 @node Labels Visible to Debugger
11988 @subsection Labels Visible to Debugger
11989
11990 @code{g77} should output debugging information for statements labels,
11991 for use by debuggers that know how to support them.
11992 Same with weirder things like construct names.
11993 It is not yet known if any debug formats or debuggers support these.
11994
11995 @node Disappointments
11996 @section Disappointments and Misunderstandings
11997
11998 These problems are perhaps regrettable, but we don't know any practical
11999 way around them for now.
12000
12001 @menu
12002 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
12003                                               external name @samp{foo_}.
12004 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
12005                                               and @samp{SUBROUTINE FOO}.
12006 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
12007 @end menu
12008
12009 @node Mangling of Names
12010 @subsection Mangling of Names in Source Code
12011 @cindex naming issues
12012 @cindex external names
12013 @cindex common blocks
12014 @cindex name space
12015 @cindex underscore
12016
12017 The current external-interface design, which includes naming of
12018 external procedures, COMMON blocks, and the library interface,
12019 has various usability problems, including things like adding
12020 underscores where not really necessary (and preventing easier
12021 inter-language operability) and yet not providing complete
12022 namespace freedom for user C code linked with Fortran apps (due
12023 to the naming of functions in the library, among other things).
12024
12025 Project GNU should at least get all this ``right'' for systems
12026 it fully controls, such as the Hurd, and provide defaults and
12027 options for compatibility with existing systems and interoperability
12028 with popular existing compilers.
12029
12030 @node Multiple Definitions of External Names
12031 @subsection Multiple Definitions of External Names
12032 @cindex block data
12033 @cindex BLOCK DATA statement
12034 @cindex statements, BLOCK DATA
12035 @cindex @code{COMMON} statement
12036 @cindex statements, @code{COMMON}
12037 @cindex naming conflicts
12038
12039 @code{g77} doesn't allow a common block and an external procedure or
12040 @code{BLOCK DATA} to have the same name.
12041 Some systems allow this, but @code{g77} does not,
12042 to be compatible with @code{f2c}.
12043
12044 @code{g77} could special-case the way it handles
12045 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
12046 particular area (necessarily, since @code{g77} offers an
12047 important feature here), but
12048 it is likely that such special-casing would be very annoying to people
12049 with programs that use @samp{EXTERNAL FOO}, with no other mention of
12050 @samp{FOO} in the same program unit, to refer to external procedures, since
12051 the result would be that @code{g77} would treat these references as requests to
12052 force-load BLOCK DATA program units.
12053
12054 In that case, if @code{g77} modified
12055 names of @code{BLOCK DATA} so they could have the same names as
12056 @code{COMMON}, users
12057 would find that their programs wouldn't link because the @samp{FOO} procedure
12058 didn't have its name translated the same way.
12059
12060 (Strictly speaking,
12061 @code{g77} could emit a null-but-externally-satisfying definition of
12062 @samp{FOO} with its name transformed as if it had been a
12063 @code{BLOCK DATA}, but that probably invites more trouble than it's
12064 worth.)
12065
12066 @node Limitation on Implicit Declarations
12067 @subsection Limitation on Implicit Declarations
12068 @cindex IMPLICIT CHARACTER*(*) statement
12069 @cindex statements, IMPLICIT CHARACTER*(*)
12070
12071 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
12072 This is not standard-conforming.
12073
12074 @node Non-bugs
12075 @section Certain Changes We Don't Want to Make
12076
12077 This section lists changes that people frequently request, but which
12078 we do not make because we think GNU Fortran is better without them.
12079
12080 @menu
12081 * Backslash in Constants::           Why @samp{'\\'} is a constant that
12082                                        is one, not two, characters long.
12083 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
12084                                        @samp{COMMON VAR}.
12085 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
12086 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
12087                                        single-precision constant,
12088                                        and might be interpreted as
12089                                        @samp{9.435785} or similar.
12090 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
12091 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
12092                                        not behave as expected.
12093 @end menu
12094
12095 @node Backslash in Constants
12096 @subsection Backslash in Constants
12097 @cindex backslash
12098 @cindex @code{f77} support
12099 @cindex support, @code{f77}
12100
12101 In the opinion of many experienced Fortran users,
12102 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
12103 as currently set by @code{g77}.
12104
12105 First of all, you can always specify
12106 @samp{-fno-backslash} to turn off this processing.
12107
12108 Despite not being within the spirit (though apparently within the
12109 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
12110 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
12111 default to, and apparently lots of code depends on this feature.
12112
12113 This is a particularly troubling issue.
12114 The use of a C construct in the midst of Fortran code
12115 is bad enough, worse when it makes existing Fortran
12116 programs stop working (as happens when programs written
12117 for non-UNIX systems are ported to UNIX systems with
12118 compilers that provide the @samp{-fbackslash} feature
12119 as the default---sometimes with no option to turn it off).
12120
12121 The author of GNU Fortran wished, for reasons of linguistic
12122 purity, to make @samp{-fno-backslash} the default for GNU
12123 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
12124 to specify @samp{-fbackslash} to get the UNIX behavior.
12125
12126 However, the realization that @code{g77} is intended as
12127 a replacement for @emph{UNIX} @code{f77}, caused the author
12128 to choose to make @code{g77} as compatible with
12129 @code{f77} as feasible, which meant making @samp{-fbackslash}
12130 the default.
12131
12132 The primary focus on compatibility is at the source-code
12133 level, and the question became ``What will users expect
12134 a replacement for @code{f77} to do, by default?''
12135 Although at least one UNIX @code{f77} does not provide
12136 @samp{-fbackslash} as a default, it appears that
12137 the majority of them do, which suggests that
12138 the majority of code that is compiled by UNIX @code{f77}
12139 compilers expects @samp{-fbackslash} to be the default.
12140
12141 It is probably the case that more code exists
12142 that would @emph{not} work with @samp{-fbackslash}
12143 in force than code that requires it be in force.
12144
12145 However, most of @emph{that} code is not being compiled
12146 with @code{f77},
12147 and when it is, new build procedures (shell scripts,
12148 makefiles, and so on) must be set up anyway so that
12149 they work under UNIX.
12150 That makes a much more natural and safe opportunity for
12151 non-UNIX users to adapt their build procedures for
12152 @code{g77}'s default of @samp{-fbackslash} than would
12153 exist for the majority of UNIX @code{f77} users who
12154 would have to modify existing, working build procedures
12155 to explicitly specify @samp{-fbackslash} if that was
12156 not the default.
12157
12158 One suggestion has been to configure the default for
12159 @samp{-fbackslash} (and perhaps other options as well)
12160 based on the configuration of @code{g77}.
12161
12162 This is technically quite straightforward, but will be avoided
12163 even in cases where not configuring defaults to be
12164 dependent on a particular configuration greatly inconveniences
12165 some users of legacy code.
12166
12167 Many users appreciate the GNU compilers because they provide an
12168 environment that is uniform across machines.
12169 These users would be
12170 inconvenienced if the compiler treated things like the
12171 format of the source code differently on certain machines.
12172
12173 Occasionally users write programs intended only for a particular machine
12174 type.
12175 On these occasions, the users would benefit if the GNU Fortran compiler
12176 were to support by default the same dialect as the other compilers on
12177 that machine.
12178 But such applications are rare.
12179 And users writing a
12180 program to run on more than one type of machine cannot possibly benefit
12181 from this kind of compatibility.
12182 (This is consistent with the design goals for @code{gcc}.
12183 To change them for @code{g77}, you must first change them
12184 for @code{gcc}.
12185 Do not ask the maintainers of @code{g77} to do this for you,
12186 or to disassociate @code{g77} from the widely understood, if
12187 not widely agreed-upon, goals for GNU compilers in general.)
12188
12189 This is why GNU Fortran does and will treat backslashes in the same
12190 fashion on all types of machines (by default).
12191 @xref{Direction of Language Development}, for more information on
12192 this overall philosophy guiding the development of the GNU Fortran
12193 language.
12194
12195 Of course, users strongly concerned about portability should indicate
12196 explicitly in their build procedures which options are expected
12197 by their source code, or write source code that has as few such
12198 expectations as possible.
12199
12200 For example, avoid writing code that depends on backslash (@samp{\})
12201 being interpreted either way in particular, such as by
12202 starting a program unit with:
12203
12204 @smallexample
12205 CHARACTER BACKSL
12206 PARAMETER (BACKSL = '\\')
12207 @end smallexample
12208
12209 @noindent
12210 Then, use concatenation of @samp{BACKSL} anyplace a backslash
12211 is desired.
12212 In this way, users can write programs which have the same meaning
12213 in many Fortran dialects.
12214
12215 (However, this technique does not work for Hollerith constants---which
12216 is just as well, since the only generally portable uses for Hollerith
12217 constants are in places where character constants can and should
12218 be used instead, for readability.)
12219
12220 @node Initializing Before Specifying
12221 @subsection Initializing Before Specifying
12222 @cindex initialization, statement placement
12223 @cindex placing initialization statements
12224
12225 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
12226 source code before @samp{COMMON VAR},
12227 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
12228 In general, @code{g77} requires initialization of a variable
12229 or array to be specified @emph{after} all other specifications
12230 of attributes (type, size, placement, and so on) of that variable
12231 or array are specified (though @emph{confirmation} of data type is
12232 permitted).
12233
12234 It is @emph{possible} @code{g77} will someday allow all of this,
12235 even though it is not allowed by the FORTRAN 77 standard.
12236
12237 Then again, maybe it is better to have
12238 @code{g77} always require placement of @code{DATA}
12239 so that it can possibly immediately write constants
12240 to the output file, thus saving time and space.
12241
12242 That is, @samp{DATA A/1000000*1/} should perhaps always
12243 be immediately writable to canonical assembler, unless it's already known
12244 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
12245 and to do this it cannot be followed by @samp{COMMON A}.
12246
12247 @node Context-Sensitive Intrinsicness
12248 @subsection Context-Sensitive Intrinsicness
12249 @cindex intrinsics, context-sensitive
12250 @cindex context-sensitive intrinsics
12251
12252 @code{g77} treats procedure references to @emph{possible} intrinsic
12253 names as always enabling their intrinsic nature, regardless of
12254 whether the @emph{form} of the reference is valid for that
12255 intrinsic.
12256
12257 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
12258 an invalid reference to the @code{SQRT} intrinsic function,
12259 because the reference is a subroutine invocation.
12260
12261 First, @code{g77} recognizes the statement @samp{CALL SQRT}
12262 as a reference to a @emph{procedure} named @samp{SQRT}, not
12263 to a @emph{variable} with that name (as it would for a statement
12264 such as @samp{V = SQRT}).
12265
12266 Next, @code{g77} establishes that, in the program unit being compiled,
12267 @code{SQRT} is an intrinsic---not a subroutine that
12268 happens to have the same name as an intrinsic (as would be
12269 the case if, for example, @samp{EXTERNAL SQRT} was present).
12270
12271 Finally, @code{g77} recognizes that the @emph{form} of the
12272 reference is invalid for that particular intrinsic.
12273 That is, it recognizes that it is invalid for an intrinsic
12274 @emph{function}, such as @code{SQRT}, to be invoked as
12275 a @emph{subroutine}.
12276
12277 At that point, @code{g77} issues a diagnostic.
12278
12279 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
12280 references an external subroutine of their own, not an
12281 intrinsic function.
12282
12283 However, @code{g77} knows about intrinsic
12284 subroutines, not just functions, and is able to support both having
12285 the same names, for example.
12286
12287 As a result of this, @code{g77} rejects calls
12288 to intrinsics that are not subroutines, and function invocations
12289 of intrinsics that are not functions, just as it (and most compilers)
12290 rejects invocations of intrinsics with the wrong number (or types)
12291 of arguments.
12292
12293 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
12294 a user-written subroutine named @samp{SQRT}.
12295
12296 @node Context-Sensitive Constants
12297 @subsection Context-Sensitive Constants
12298 @cindex constants, context-sensitive
12299 @cindex context-sensitive constants
12300
12301 @code{g77} does not use context to determine the types of
12302 constants or named constants (@code{PARAMETER}), except
12303 for (non-standard) typeless constants such as @samp{'123'O}.
12304
12305 For example, consider the following statement:
12306
12307 @smallexample
12308 PRINT *, 9.435784839284958 * 2D0
12309 @end smallexample
12310
12311 @noindent
12312 @code{g77} will interpret the (truncated) constant
12313 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
12314 constant, because the suffix @code{D0} is not specified.
12315
12316 As a result, the output of the above statement when
12317 compiled by @code{g77} will appear to have ``less precision''
12318 than when compiled by other compilers.
12319
12320 In these and other cases, some compilers detect the
12321 fact that a single-precision constant is used in
12322 a double-precision context and therefore interpret the
12323 single-precision constant as if it was @emph{explicitly}
12324 specified as a double-precision constant.
12325 (This has the effect of appending @emph{decimal}, not
12326 @emph{binary}, zeros to the fractional part of the
12327 number---producing different computational results.)
12328
12329 The reason this misfeature is dangerous is that a slight,
12330 apparently innocuous change to the source code can change
12331 the computational results.
12332 Consider:
12333
12334 @smallexample
12335 REAL ALMOST, CLOSE
12336 DOUBLE PRECISION FIVE
12337 PARAMETER (ALMOST = 5.000000000001)
12338 FIVE = 5
12339 CLOSE = 5.000000000001
12340 PRINT *, 5.000000000001 - FIVE
12341 PRINT *, ALMOST - FIVE
12342 PRINT *, CLOSE - FIVE
12343 END
12344 @end smallexample
12345
12346 @noindent
12347 Running the above program should
12348 result in the same value being
12349 printed three times.
12350 With @code{g77} as the compiler,
12351 it does.
12352
12353 However, compiled by many other compilers,
12354 running the above program would print
12355 two or three distinct values, because
12356 in two or three of the statements, the
12357 constant @samp{5.000000000001}, which
12358 on most systems is exactly equal to @samp{5.}
12359 when interpreted as a single-precision constant,
12360 is instead interpreted as a double-precision
12361 constant, preserving the represented
12362 precision.
12363 However, this ``clever'' promotion of
12364 type does not extend to variables or,
12365 in some compilers, to named constants.
12366
12367 Since programmers often are encouraged to replace manifest
12368 constants or permanently-assigned variables with named
12369 constants (@code{PARAMETER} in Fortran), and might need
12370 to replace some constants with variables having the same
12371 values for pertinent portions of code,
12372 it is important that compilers treat code so modified in the
12373 same way so that the results of such programs are the same.
12374 @code{g77} helps in this regard by treating constants just
12375 the same as variables in terms of determining their types
12376 in a context-independent way.
12377
12378 Still, there is a lot of existing Fortran code that has
12379 been written to depend on the way other compilers freely
12380 interpret constants' types based on context, so anything
12381 @code{g77} can do to help flag cases of this in such code
12382 could be very helpful.
12383
12384 @node Equivalence Versus Equality
12385 @subsection Equivalence Versus Equality
12386 @cindex .EQV., with integer operands
12387 @cindex comparing logical expressions
12388 @cindex logical expressions, comparing
12389
12390 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
12391 is not supported, except via @samp{-fugly-logint}, which is not
12392 recommended except for legacy code (where the behavior expected
12393 by the @emph{code} is assumed).
12394
12395 Legacy code should be changed, as resources permit, to use @code{.EQV.}
12396 and @code{.NEQV.} instead, as these are permitted by the various
12397 Fortran standards.
12398
12399 New code should never be written expecting @code{.EQ.} or @code{.NE.}
12400 to work if either of its operands is @code{LOGICAL}.
12401
12402 The problem with supporting this ``feature'' is that there is
12403 unlikely to be consensus on how it works, as illustrated by the
12404 following sample program:
12405
12406 @smallexample
12407 LOGICAL L,M,N
12408 DATA L,M,N /3*.FALSE./
12409 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
12410 END
12411 @end smallexample
12412
12413 The issue raised by the above sample program is: what is the
12414 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
12415 @code{LOGICAL} operands?
12416
12417 Some programmers will argue that it is the same as the precedence
12418 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
12419 operands.
12420 By this interpretation, the subexpression @samp{M.EQ.N} must be
12421 evaluated first in the above program, resulting in a program that,
12422 when run, does not execute the @code{PRINT} statement.
12423
12424 Other programmers will argue that the precedence is the same as
12425 the precedence for @code{.EQV.}, which is restricted by the standards
12426 to @code{LOGICAL} operands.
12427 By this interpretation, the subexpression @samp{L.AND.M} must be
12428 evaluated first, resulting in a program that @emph{does} execute
12429 the @code{PRINT} statement.
12430
12431 Assigning arbitrary semantic interpretations to syntactic expressions
12432 that might legitimately have more than one ``obvious'' interpretation
12433 is generally unwise.
12434
12435 The creators of the various Fortran standards have done a good job
12436 in this case, requiring a distinct set of operators (which have their
12437 own distinct precedence) to compare @code{LOGICAL} operands.
12438 This requirement results in expression syntax with more certain
12439 precedence (without requiring substantial context), making it easier
12440 for programmers to read existing code.
12441 @code{g77} will avoid muddying up elements of the Fortran language
12442 that were well-designed in the first place.
12443
12444 (Ask C programmers about the precedence of expressions such as
12445 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
12446 you, without knowing more context, whether the @samp{&} and @samp{-}
12447 operators are infix (binary) or unary!)
12448
12449 Most dangerous of all is the fact that,
12450 even assuming consensus on its meaning,
12451 an expression like @samp{L.AND.M.EQ.N},
12452 if it is the result of a typographical error,
12453 doesn't @emph{look} like it has such a typo.
12454 Even experienced Fortran programmers would not likely notice that
12455 @samp{L.AND.M.EQV.N} was, in fact, intended.
12456
12457 So, this is a prime example of a circumstance in which
12458 a quality compiler diagnoses the code,
12459 instead of leaving it up to someone debugging it
12460 to know to turn on special compiler options
12461 that might diagnose it.
12462
12463 @node Order of Side Effects
12464 @subsection Order of Side Effects
12465 @cindex side effects, order of evaluation
12466 @cindex order of evaluation, side effects
12467
12468 @code{g77} does not necessarily produce code that, when run, performs
12469 side effects (such as those performed by function invocations)
12470 in the same order as in some other compiler---or even in the same
12471 order as another version, port, or invocation (using different
12472 command-line options) of @code{g77}.
12473
12474 It is never safe to depend on the order of evaluation of side effects.
12475 For example, an expression like this may very well behave differently
12476 from one compiler to another:
12477
12478 @smallexample
12479 J = IFUNC() - IFUNC()
12480 @end smallexample
12481
12482 @noindent
12483 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
12484 order.
12485 Either invocation might happen first.
12486 If @samp{IFUNC} returns 5 the first time it is invoked, and
12487 returns 12 the second time, @samp{J} might end up with the
12488 value @samp{7}, or it might end up with @samp{-7}.
12489
12490 Generally, in Fortran, procedures with side-effects intended to
12491 be visible to the caller are best designed as @emph{subroutines},
12492 not functions.
12493 Examples of such side-effects include:
12494
12495 @itemize @bullet
12496 @item
12497 The generation of random numbers
12498 that are intended to influence return values.
12499
12500 @item
12501 Performing I/O
12502 (other than internal I/O to local variables).
12503
12504 @item
12505 Updating information in common blocks.
12506 @end itemize
12507
12508 An example of a side-effect that is not intended to be visible
12509 to the caller is a function that maintains a cache of recently
12510 calculated results, intended solely to speed repeated invocations
12511 of the function with identical arguments.
12512 Such a function can be safely used in expressions, because
12513 if the compiler optimizes away one or more calls to the
12514 function, operation of the program is unaffected (aside
12515 from being speeded up).
12516
12517 @node Warnings and Errors
12518 @section Warning Messages and Error Messages
12519
12520 @cindex error messages
12521 @cindex warnings vs errors
12522 @cindex messages, warning and error
12523 The GNU compiler can produce two kinds of diagnostics: errors and
12524 warnings.
12525 Each kind has a different purpose:
12526
12527 @itemize @w{}
12528 @item
12529 @emph{Errors} report problems that make it impossible to compile your
12530 program.
12531 GNU Fortran reports errors with the source file name, line
12532 number, and column within the line where the problem is apparent.
12533
12534 @item
12535 @emph{Warnings} report other unusual conditions in your code that
12536 @emph{might} indicate a problem, although compilation can (and does)
12537 proceed.
12538 Warning messages also report the source file name, line number,
12539 and column information,
12540 but include the text @samp{warning:} to distinguish them
12541 from error messages.
12542 @end itemize
12543
12544 Warnings might indicate danger points where you should check to make sure
12545 that your program really does what you intend; or the use of obsolete
12546 features; or the use of nonstandard features of GNU Fortran.
12547 Many warnings are issued only if you ask for them, with one of the
12548 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
12549 useful warnings).
12550
12551 @emph{Note:} Currently, the text of the line and a pointer to the column
12552 is printed in most @code{g77} diagnostics.
12553 Probably, as of version 0.6, @code{g77} will
12554 no longer print the text of the source line, instead printing
12555 the column number following the file name and line number in
12556 a form that GNU Emacs recognizes.
12557 This change is expected to speed up and reduce the memory usage
12558 of the @code{g77} compiler.
12559 @c
12560 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
12561 @c
12562 @c GNU Fortran always tries to compile your program if possible; it never
12563 @c gratuitously rejects a program whose meaning is clear merely because
12564 @c (for instance) it fails to conform to a standard.  In some cases,
12565 @c however, the Fortran standard specifies that certain extensions are
12566 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
12567 @c compiler.  The @samp{-pedantic} option tells GNU Fortran to issue warnings
12568 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
12569 @c This does not mean that @emph{all} non-ANSI constructs get warnings
12570 @c or errors.
12571
12572 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
12573 more detail on these and related command-line options.
12574
12575 @node Open Questions
12576 @chapter Open Questions
12577
12578 Please consider offering useful answers to these questions!
12579
12580 @itemize @bullet
12581 @item
12582 @code{LOC()} and other intrinsics are probably somewhat misclassified.
12583 Is the a need for more precise classification of intrinsics, and if so,
12584 what are the appropriate groupings?
12585 Is there a need to individually
12586 enable/disable/delete/hide intrinsics from the command line?
12587 @end itemize
12588
12589 @node Bugs
12590 @chapter Reporting Bugs
12591 @cindex bugs
12592 @cindex reporting bugs
12593
12594 Your bug reports play an essential role in making GNU Fortran reliable.
12595
12596 When you encounter a problem, the first thing to do is to see if it is
12597 already known.
12598 @xref{Trouble}.
12599 If it isn't known, then you should report the problem.
12600
12601 Reporting a bug might help you by bringing a solution to your problem, or
12602 it might not.
12603 (If it does not, look in the service directory; see
12604 @ref{Service}.)
12605 In any case, the principal function of a bug report is
12606 to help the entire community by making the next version of GNU Fortran work
12607 better.
12608 Bug reports are your contribution to the maintenance of GNU Fortran.
12609
12610 Since the maintainers are very overloaded, we cannot respond to every
12611 bug report.
12612 However, if the bug has not been fixed, we are likely to
12613 send you a patch and ask you to tell us whether it works.
12614
12615 In order for a bug report to serve its purpose, you must include the
12616 information that makes for fixing the bug.
12617
12618 @menu
12619 * Criteria: Bug Criteria.    Have you really found a bug?
12620 * Where: Bug Lists.          Where to send your bug report.
12621 * Reporting: Bug Reporting.  How to report a bug effectively.
12622 * Patches: Sending Patches.  How to send a patch for GNU Fortran.
12623 @end menu
12624
12625 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
12626 for information on problems we already know about.
12627
12628 @xref{Service,,How To Get Help with GNU Fortran},
12629 for information on where to ask for help.
12630
12631 @node Bug Criteria
12632 @section Have You Found a Bug?
12633 @cindex bug criteria
12634
12635 If you are not sure whether you have found a bug, here are some guidelines:
12636
12637 @itemize @bullet
12638 @cindex fatal signal
12639 @cindex core dump
12640 @item
12641 If the compiler gets a fatal signal, for any input whatever, that is a
12642 compiler bug.
12643 Reliable compilers never crash---they just remain obsolete.
12644
12645 @cindex invalid assembly code
12646 @cindex assembly code, invalid
12647 @item
12648 If the compiler produces invalid assembly code, for any input whatever,
12649 @c (except an @code{asm} statement),
12650 that is a compiler bug, unless the
12651 compiler reports errors (not just warnings) which would ordinarily
12652 prevent the assembler from being run.
12653
12654 @cindex undefined behavior
12655 @cindex undefined function value
12656 @item
12657 If the compiler produces valid assembly code that does not correctly
12658 execute the input source code, that is a compiler bug.
12659
12660 However, you must double-check to make sure, because you might have run
12661 into an incompatibility between GNU Fortran and traditional Fortran.
12662 @c (@pxref{Incompatibilities}).
12663 These incompatibilities might be considered
12664 bugs, but they are inescapable consequences of valuable features.
12665
12666 Or you might have a program whose behavior is undefined, which happened
12667 by chance to give the desired results with another Fortran compiler.
12668 It is best to check the relevant Fortran standard thoroughly if
12669 it is possible that the program indeed does something undefined.
12670
12671 After you have localized the error to a single source line, it should
12672 be easy to check for these things.
12673 If your program is correct and well defined, you have found
12674 a compiler bug.
12675
12676 It might help if, in your submission, you identified the specific
12677 language in the relevant Fortran standard that specifies the
12678 desired behavior, if it isn't likely to be obvious and agreed-upon
12679 by all Fortran users.
12680
12681 @item
12682 If the compiler produces an error message for valid input, that is a
12683 compiler bug.
12684
12685 @cindex invalid input
12686 @item
12687 If the compiler does not produce an error message for invalid input,
12688 that is a compiler bug.
12689 However, you should note that your idea of
12690 ``invalid input'' might be someone else's idea
12691 of ``an extension'' or ``support for traditional practice''.
12692
12693 @item
12694 If you are an experienced user of Fortran compilers, your suggestions
12695 for improvement of GNU Fortran are welcome in any case.
12696 @end itemize
12697
12698 Many, perhaps most, bug reports against @code{g77} turn out to
12699 be bugs in the user's code.
12700 While we find such bug reports educational, they sometimes take
12701 a considerable amount of time to track down or at least respond
12702 to---time we could be spending making @code{g77}, not some user's
12703 code, better.
12704
12705 Some steps you can take to verify that the bug is not certainly
12706 in the code you're compiling with @code{g77}:
12707
12708 @itemize @bullet
12709 @item
12710 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
12711 These options enable many useful warning; the @samp{-O} option
12712 enables flow analysis that enables the uninitialized-variable
12713 warning.
12714
12715 If you investigate the warnings and find evidence of possible bugs
12716 in your code, fix them first and retry @code{g77}.
12717
12718 @item
12719 Compile your code using the @code{g77} options @samp{-finit-local-zero},
12720 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
12721 combinations thereof.
12722
12723 If your code works with any of these combinations, that is not
12724 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
12725 by your code might simply be avoided, or have a different, more subtle
12726 effect, when different options are used---but it can be a
12727 strong indicator that your code is making unwarranted assumptions
12728 about the Fortran dialect and/or underlying machine it is
12729 being compiled and run on.
12730
12731 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
12732 for information on the @samp{-fno-automatic} and
12733 @samp{-finit-local-zero} options and how to convert
12734 their use into selective changes in your own code.
12735
12736 @item
12737 @pindex ftnchek
12738 Validate your code with @code{ftnchek} or a similar code-checking
12739 tool.
12740 @code{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
12741 or @uref{ftp://ftp.dsm.fordham.edu}.
12742
12743 @pindex make
12744 @cindex Makefile example
12745 Here are some sample @file{Makefile} rules using @code{ftnchek}
12746 ``project'' files to do cross-file checking and @code{sfmakedepend}
12747 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
12748 to maintain dependencies automatically.
12749 These assume the use of GNU @code{make}.
12750
12751 @smallexample
12752 # Dummy suffix for ftnchek targets:
12753 .SUFFIXES: .chek
12754 .PHONY: chekall
12755
12756 # How to compile .f files (for implicit rule):
12757 FC = g77
12758 # Assume `include' directory:
12759 FFLAGS = -Iinclude -g -O -Wall
12760
12761 # Flags for ftnchek:
12762 CHEK1 = -array=0 -include=includes -noarray
12763 CHEK2 = -nonovice -usage=1 -notruncation
12764 CHEKFLAGS = $(CHEK1) $(CHEK2)
12765
12766 # Run ftnchek with all the .prj files except the one corresponding
12767 # to the target's root:
12768 %.chek : %.f ; \
12769   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
12770     -noextern -library $<
12771
12772 # Derive a project file from a source file:
12773 %.prj : %.f ; \
12774   ftnchek $(CHEKFLAGS) -noextern -project -library $<
12775
12776 # The list of objects is assumed to be in variable OBJS.
12777 # Sources corresponding to the objects:
12778 SRCS = $(OBJS:%.o=%.f)
12779 # ftnchek project files:
12780 PRJS = $(OBJS:%.o=%.prj)
12781
12782 # Build the program
12783 prog: $(OBJS) ; \
12784   $(FC) -o $@ $(OBJS)
12785
12786 chekall: $(PRJS) ; \
12787   ftnchek $(CHEKFLAGS) $(PRJS)
12788
12789 prjs: $(PRJS)
12790
12791 # For Emacs M-x find-tag:
12792 TAGS: $(SRCS) ; \
12793   etags $(SRCS)
12794
12795 # Rebuild dependencies:
12796 depend: ; \
12797   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
12798 @end smallexample
12799
12800 @item
12801 Try your code out using other Fortran compilers, such as @code{f2c}.
12802 If it does not work on at least one other compiler (assuming the
12803 compiler supports the features the code needs), that is a strong
12804 indicator of a bug in the code.
12805
12806 However, even if your code works on many compilers @emph{except}
12807 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
12808 It might mean the bug is in your code, and that @code{g77} simply
12809 exposes it more readily than other compilers.
12810 @end itemize
12811
12812 @node Bug Lists
12813 @section Where to Report Bugs
12814 @cindex bug report mailing lists
12815 @kindex @value{email-bugs}
12816 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
12817
12818 Often people think of posting bug reports to a newsgroup instead of
12819 mailing them.
12820 This sometimes appears to work, but it has one problem which can be
12821 crucial: a newsgroup posting does not contain a mail path back to the
12822 sender.
12823 Thus, if maintainers need more information, they might be unable
12824 to reach you.  For this reason, you should always send bug reports by
12825 mail to the proper mailing list.
12826
12827 As a last resort, send bug reports on paper to:
12828
12829 @example
12830 GNU Compiler Bugs
12831 Free Software Foundation
12832 59 Temple Place - Suite 330
12833 Boston, MA 02111-1307, USA
12834 @end example
12835
12836 @node Bug Reporting
12837 @section How to Report Bugs
12838 @cindex compiler bugs, reporting
12839
12840 The fundamental principle of reporting bugs usefully is this:
12841 @strong{report all the facts}.
12842 If you are not sure whether to state a
12843 fact or leave it out, state it!
12844
12845 Often people omit facts because they think they know what causes the
12846 problem and they conclude that some details don't matter.
12847 Thus, you might
12848 assume that the name of the variable you use in an example does not matter.
12849 Well, probably it doesn't, but one cannot be sure.
12850 Perhaps the bug is a
12851 stray memory reference which happens to fetch from the location where that
12852 name is stored in memory; perhaps, if the name were different, the contents
12853 of that location would fool the compiler into doing the right thing despite
12854 the bug.
12855 Play it safe and give a specific, complete example.
12856 That is the
12857 easiest thing for you to do, and the most helpful.
12858
12859 Keep in mind that the purpose of a bug report is to enable someone to
12860 fix the bug if it is not known.
12861 It isn't very important what happens if
12862 the bug is already known.
12863 Therefore, always write your bug reports on
12864 the assumption that the bug is not known.
12865
12866 Sometimes people give a few sketchy facts and ask, ``Does this ring a
12867 bell?''
12868 This cannot help us fix a bug, so it is rarely helpful.
12869 We respond by asking for enough details to enable us to investigate.
12870 You might as well expedite matters by sending them to begin with.
12871 (Besides, there are enough bells ringing around here as it is.)
12872
12873 Try to make your bug report self-contained.
12874 If we have to ask you for
12875 more information, it is best if you include all the previous information
12876 in your response, as well as the information that was missing.
12877
12878 Please report each bug in a separate message.
12879 This makes it easier for
12880 us to track which bugs have been fixed and to forward your bugs reports
12881 to the appropriate maintainer.
12882
12883 Do not compress and encode any part of your bug report using programs
12884 such as @file{uuencode}.
12885 If you do so it will slow down the processing
12886 of your bug.
12887 If you must submit multiple large files, use @file{shar},
12888 which allows us to read your message without having to run any
12889 decompression programs.
12890
12891 (As a special exception for GNU Fortran bug-reporting, at least
12892 for now, if you are sending more than a few lines of code, if
12893 your program's source file format contains ``interesting'' things
12894 like trailing spaces or strange characters, or if you need to
12895 include binary data files, it is acceptable to put all the
12896 files together in a @code{tar} archive, and, whether you need to
12897 do that, it is acceptable to then compress the single file (@code{tar}
12898 archive or source file)
12899 using @code{gzip} and encode it via @code{uuencode}.
12900 Do not use any MIME stuff---the current maintainer can't decode this.
12901 Using @code{compress} instead of @code{gzip} is acceptable, assuming
12902 you have licensed the use of the patented algorithm in
12903 @code{compress} from Unisys.)
12904
12905 To enable someone to investigate the bug, you should include all these
12906 things:
12907
12908 @itemize @bullet
12909 @item
12910 The version of GNU Fortran.
12911 You can get this by running @code{g77} with the @samp{-v} option.
12912 (Ignore any error messages that might be displayed
12913 when the linker is run.)
12914
12915 Without this, we won't know whether there is any point in looking for
12916 the bug in the current version of GNU Fortran.
12917
12918 @item
12919 @cindex preprocessor
12920 @cindex cpp program
12921 @cindex programs, cpp
12922 @pindex cpp
12923 A complete input file that will reproduce the bug.
12924
12925 If your source file(s) require preprocessing
12926 (for example, their names have suffixes like
12927 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
12928 and the bug is in the compiler proper (@file{f771})
12929 or in a subsequent phase of processing,
12930 run your source file through the C preprocessor
12931 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
12932 Then, include the contents of @var{newfile} in the bug report.
12933 (When you do this, use the same preprocessor options---such as
12934 @samp{-I}, @samp{-D}, and @samp{-U}---that you used in actual
12935 compilation.)
12936
12937 A single statement is not enough of an example.
12938 In order to compile it,
12939 it must be embedded in a complete file of compiler input.
12940 The bug might depend on the details of how this is done.
12941
12942 Without a real example one can compile,
12943 all anyone can do about your bug report is wish you luck.
12944 It would be futile to try to guess how to provoke the bug.
12945 For example, bugs in register allocation and reloading
12946 can depend on every little detail of the source and include files
12947 that trigger them.
12948
12949 @item
12950 @cindex included files
12951 @cindex INCLUDE directive
12952 @cindex directive, INCLUDE
12953 @cindex #include directive
12954 @cindex directive, #include
12955 Note that you should include with your bug report any files
12956 included by the source file
12957 (via the @code{#include} or @code{INCLUDE} directive)
12958 that you send, and any files they include, and so on.
12959
12960 It is not necessary to replace
12961 the @code{#include} and @code{INCLUDE} directives
12962 with the actual files in the version of the source file that
12963 you send, but it might make submitting the bug report easier
12964 in the end.
12965 However, be sure to @emph{reproduce} the bug using the @emph{exact}
12966 version of the source material you submit, to avoid wild-goose
12967 chases.
12968
12969 @item
12970 The command arguments you gave GNU Fortran to compile that example
12971 and observe the bug.  For example, did you use @samp{-O}?  To guarantee
12972 you won't omit something important, list all the options.
12973
12974 If we were to try to guess the arguments, we would probably guess wrong
12975 and then we would not encounter the bug.
12976
12977 @item
12978 The type of machine you are using, and the operating system name and
12979 version number.
12980 (Much of this information is printed by @samp{g77 -v}---if you
12981 include that, send along any additional info you have that you
12982 don't see clearly represented in that output.)
12983
12984 @item
12985 The operands you gave to the @code{configure} command when you installed
12986 the compiler.
12987
12988 @item
12989 A complete list of any modifications you have made to the compiler
12990 source.  (We don't promise to investigate the bug unless it happens in
12991 an unmodified compiler.  But if you've made modifications and don't tell
12992 us, then you are sending us on a wild-goose chase.)
12993
12994 Be precise about these changes.  A description in English is not
12995 enough---send a context diff for them.
12996
12997 Adding files of your own (such as a machine description for a machine we
12998 don't support) is a modification of the compiler source.
12999
13000 @item
13001 Details of any other deviations from the standard procedure for installing
13002 GNU Fortran.
13003
13004 @item
13005 A description of what behavior you observe that you believe is
13006 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
13007 ``The assembler instruction at line 208 in the output is incorrect.''
13008
13009 Of course, if the bug is that the compiler gets a fatal signal, then one
13010 can't miss it.  But if the bug is incorrect output, the maintainer might
13011 not notice unless it is glaringly wrong.  None of us has time to study
13012 all the assembler code from a 50-line Fortran program just on the chance that
13013 one instruction might be wrong.  We need @emph{you} to do this part!
13014
13015 Even if the problem you experience is a fatal signal, you should still
13016 say so explicitly.  Suppose something strange is going on, such as, your
13017 copy of the compiler is out of synch, or you have encountered a bug in
13018 the C library on your system.  (This has happened!)  Your copy might
13019 crash and the copy here would not.  If you @i{said} to expect a crash,
13020 then when the compiler here fails to crash, we would know that the bug
13021 was not happening.  If you don't say to expect a crash, then we would
13022 not know whether the bug was happening.  We would not be able to draw
13023 any conclusion from our observations.
13024
13025 If the problem is a diagnostic when building GNU Fortran with some other
13026 compiler, say whether it is a warning or an error.
13027
13028 Often the observed symptom is incorrect output when your program is run.
13029 Sad to say, this is not enough information unless the program is short
13030 and simple.  None of us has time to study a large program to figure out
13031 how it would work if compiled correctly, much less which line of it was
13032 compiled wrong.  So you will have to do that.  Tell us which source line
13033 it is, and what incorrect result happens when that line is executed.  A
13034 person who understands the program can find this as easily as finding a
13035 bug in the program itself.
13036
13037 @item
13038 If you send examples of assembler code output from GNU Fortran,
13039 please use @samp{-g} when you make them.  The debugging information
13040 includes source line numbers which are essential for correlating the
13041 output with the input.
13042
13043 @item
13044 If you wish to mention something in the GNU Fortran source, refer to it by
13045 context, not by line number.
13046
13047 The line numbers in the development sources don't match those in your
13048 sources.  Your line numbers would convey no convenient information to the
13049 maintainers.
13050
13051 @item
13052 Additional information from a debugger might enable someone to find a
13053 problem on a machine which he does not have available.  However, you
13054 need to think when you collect this information if you want it to have
13055 any chance of being useful.
13056
13057 @cindex backtrace for bug reports
13058 For example, many people send just a backtrace, but that is never
13059 useful by itself.  A simple backtrace with arguments conveys little
13060 about GNU Fortran because the compiler is largely data-driven; the same
13061 functions are called over and over for different RTL insns, doing
13062 different things depending on the details of the insn.
13063
13064 Most of the arguments listed in the backtrace are useless because they
13065 are pointers to RTL list structure.  The numeric values of the
13066 pointers, which the debugger prints in the backtrace, have no
13067 significance whatever; all that matters is the contents of the objects
13068 they point to (and most of the contents are other such pointers).
13069
13070 In addition, most compiler passes consist of one or more loops that
13071 scan the RTL insn sequence.  The most vital piece of information about
13072 such a loop---which insn it has reached---is usually in a local variable,
13073 not in an argument.
13074
13075 @findex debug_rtx
13076 What you need to provide in addition to a backtrace are the values of
13077 the local variables for several stack frames up.  When a local
13078 variable or an argument is an RTX, first print its value and then use
13079 the GDB command @code{pr} to print the RTL expression that it points
13080 to.  (If GDB doesn't run on your machine, use your debugger to call
13081 the function @code{debug_rtx} with the RTX as an argument.)  In
13082 general, whenever a variable is a pointer, its value is no use
13083 without the data it points to.
13084 @end itemize
13085
13086 Here are some things that are not necessary:
13087
13088 @itemize @bullet
13089 @item
13090 A description of the envelope of the bug.
13091
13092 Often people who encounter a bug spend a lot of time investigating
13093 which changes to the input file will make the bug go away and which
13094 changes will not affect it.
13095
13096 This is often time consuming and not very useful, because the way we
13097 will find the bug is by running a single example under the debugger with
13098 breakpoints, not by pure deduction from a series of examples.  You might
13099 as well save your time for something else.
13100
13101 Of course, if you can find a simpler example to report @emph{instead} of
13102 the original one, that is a convenience.  Errors in the output will be
13103 easier to spot, running under the debugger will take less time, etc.
13104 Most GNU Fortran bugs involve just one function, so the most straightforward
13105 way to simplify an example is to delete all the function definitions
13106 except the one where the bug occurs.  Those earlier in the file may be
13107 replaced by external declarations if the crucial function depends on
13108 them.  (Exception: inline functions might affect compilation of functions
13109 defined later in the file.)
13110
13111 However, simplification is not vital; if you don't want to do this,
13112 report the bug anyway and send the entire test case you used.
13113
13114 @item
13115 In particular, some people insert conditionals @samp{#ifdef BUG} around
13116 a statement which, if removed, makes the bug not happen.  These are just
13117 clutter; we won't pay any attention to them anyway.  Besides, you should
13118 send us preprocessor output, and that can't have conditionals.
13119
13120 @item
13121 A patch for the bug.
13122
13123 A patch for the bug is useful if it is a good one.  But don't omit the
13124 necessary information, such as the test case, on the assumption that a
13125 patch is all we need.  We might see problems with your patch and decide
13126 to fix the problem another way, or we might not understand it at all.
13127
13128 Sometimes with a program as complicated as GNU Fortran it is very hard to
13129 construct an example that will make the program follow a certain path
13130 through the code.  If you don't send the example, we won't be able to
13131 construct one, so we won't be able to verify that the bug is fixed.
13132
13133 And if we can't understand what bug you are trying to fix, or why your
13134 patch should be an improvement, we won't install it.  A test case will
13135 help us to understand.
13136
13137 @xref{Sending Patches}, for guidelines on how to make it easy for us to
13138 understand and install your patches.
13139
13140 @item
13141 A guess about what the bug is or what it depends on.
13142
13143 Such guesses are usually wrong.  Even the maintainer can't guess right
13144 about such things without first using the debugger to find the facts.
13145
13146 @item
13147 A core dump file.
13148
13149 We have no way of examining a core dump for your type of machine
13150 unless we have an identical system---and if we do have one,
13151 we should be able to reproduce the crash ourselves.
13152 @end itemize
13153
13154 @node Sending Patches
13155 @section Sending Patches for GNU Fortran
13156
13157 If you would like to write bug fixes or improvements for the GNU Fortran
13158 compiler, that is very helpful.
13159 Send suggested fixes to the mailing list for patches,
13160 @email{@value{email-patch}}.
13161
13162 Please follow these guidelines so we can study your patches efficiently.
13163 If you don't follow these guidelines, your information might still be
13164 useful, but using it will take extra work.  Maintaining GNU Fortran is a lot
13165 of work in the best of circumstances, and we can't keep up unless you do
13166 your best to help.
13167
13168 @itemize @bullet
13169 @item
13170 Send an explanation with your changes of what problem they fix or what
13171 improvement they bring about.  For a bug fix, just include a copy of the
13172 bug report, and explain why the change fixes the bug.
13173
13174 (Referring to a bug report is not as good as including it, because then
13175 we will have to look it up, and we have probably already deleted it if
13176 we've already fixed the bug.)
13177
13178 @item
13179 Always include a proper bug report for the problem you think you have
13180 fixed.  We need to convince ourselves that the change is right before
13181 installing it.  Even if it is right, we might have trouble judging it if
13182 we don't have a way to reproduce the problem.
13183
13184 @item
13185 Include all the comments that are appropriate to help people reading the
13186 source in the future understand why this change was needed.
13187
13188 @item
13189 Don't mix together changes made for different reasons.
13190 Send them @emph{individually}.
13191
13192 If you make two changes for separate reasons, then we might not want to
13193 install them both.  We might want to install just one.  If you send them
13194 all jumbled together in a single set of diffs, we have to do extra work
13195 to disentangle them---to figure out which parts of the change serve
13196 which purpose.  If we don't have time for this, we might have to ignore
13197 your changes entirely.
13198
13199 If you send each change as soon as you have written it, with its own
13200 explanation, then the two changes never get tangled up, and we can
13201 consider each one properly without any extra work to disentangle them.
13202
13203 Ideally, each change you send should be impossible to subdivide into
13204 parts that we might want to consider separately, because each of its
13205 parts gets its motivation from the other parts.
13206
13207 @item
13208 Send each change as soon as that change is finished.  Sometimes people
13209 think they are helping us by accumulating many changes to send them all
13210 together.  As explained above, this is absolutely the worst thing you
13211 could do.
13212
13213 Since you should send each change separately, you might as well send it
13214 right away.  That gives us the option of installing it immediately if it
13215 is important.
13216
13217 @item
13218 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
13219 for us to install reliably.  More than that, they make it hard for us to
13220 study the diffs to decide whether we want to install them.  Unidiff
13221 format is better than contextless diffs, but not as easy to read as
13222 @samp{-c} format.
13223
13224 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
13225 function that each change occurs in.
13226 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
13227
13228 @item
13229 Write the change log entries for your changes.  We get lots of changes,
13230 and we don't have time to do all the change log writing ourselves.
13231
13232 Read the @file{ChangeLog} file to see what sorts of information to put
13233 in, and to learn the style that we use.  The purpose of the change log
13234 is to show people where to find what was changed.  So you need to be
13235 specific about what functions you changed; in large functions, it's
13236 often helpful to indicate where within the function the change was.
13237
13238 On the other hand, once you have shown people where to find the change,
13239 you need not explain its purpose.  Thus, if you add a new function, all
13240 you need to say about it is that it is new.  If you feel that the
13241 purpose needs explaining, it probably does---but the explanation will be
13242 much more useful if you put it in comments in the code.
13243
13244 If you would like your name to appear in the header line for who made
13245 the change, send us the header line.
13246
13247 @item
13248 When you write the fix, keep in mind that we can't install a change that
13249 would break other systems.
13250
13251 People often suggest fixing a problem by changing machine-independent
13252 files such as @file{toplev.c} to do something special that a particular
13253 system needs.  Sometimes it is totally obvious that such changes would
13254 break GNU Fortran for almost all users.  We can't possibly make a change like
13255 that.  At best it might tell us how to write another patch that would
13256 solve the problem acceptably.
13257
13258 Sometimes people send fixes that @emph{might} be an improvement in
13259 general---but it is hard to be sure of this.  It's hard to install
13260 such changes because we have to study them very carefully.  Of course,
13261 a good explanation of the reasoning by which you concluded the change
13262 was correct can help convince us.
13263
13264 The safest changes are changes to the configuration files for a
13265 particular machine.  These are safe because they can't create new bugs
13266 on other machines.
13267
13268 Please help us keep up with the workload by designing the patch in a
13269 form that is good to install.
13270 @end itemize
13271
13272 @node Service
13273 @chapter How To Get Help with GNU Fortran
13274
13275 If you need help installing, using or changing GNU Fortran, there are two
13276 ways to find it:
13277
13278 @itemize @bullet
13279 @item
13280 Look in the service directory for someone who might help you for a fee.
13281 The service directory is found in the file named @file{SERVICE} in the
13282 GNU CC distribution.
13283
13284 @item
13285 Send a message to @email{@value{email-help}}.
13286 @end itemize
13287
13288 @end ifset
13289 @ifset INTERNALS
13290 @node Adding Options
13291 @chapter Adding Options
13292 @cindex options, adding
13293 @cindex adding options
13294
13295 To add a new command-line option to @code{g77}, first decide
13296 what kind of option you wish to add.
13297 Search the @code{g77} and @code{gcc} documentation for one
13298 or more options that is most closely like the one you want to add
13299 (in terms of what kind of effect it has, and so on) to
13300 help clarify its nature.
13301
13302 @itemize @bullet
13303 @item
13304 @emph{Fortran options} are options that apply only
13305 when compiling Fortran programs.
13306 They are accepted by @code{g77} and @code{gcc}, but
13307 they apply only when compiling Fortran programs.
13308
13309 @item
13310 @emph{Compiler options} are options that apply
13311 when compiling most any kind of program.
13312 @end itemize
13313
13314 @emph{Fortran options} are listed in the file
13315 @file{@value{path-g77}/lang-options.h},
13316 which is used during the build of @code{gcc} to
13317 build a list of all options that are accepted by
13318 at least one language's compiler.
13319 This list goes into the @code{documented_lang_options} array
13320 in @file{gcc/toplev.c}, which uses this array to
13321 determine whether a particular option should be
13322 offered to the linked-in front end for processing
13323 by calling @code{lang_option_decode}, which, for
13324 @code{g77}, is in @file{@value{path-g77}/com.c} and just
13325 calls @code{ffe_decode_option}.
13326
13327 If the linked-in front end ``rejects'' a
13328 particular option passed to it, @file{toplev.c}
13329 just ignores the option, because @emph{some}
13330 language's compiler is willing to accept it.
13331
13332 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
13333 to work, even though Fortran compilation does
13334 not currently support the @samp{-fno-asm} option;
13335 even though the @code{f771} version of @code{lang_decode_option}
13336 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
13337 produce a diagnostic because some other language (C)
13338 does accept it.
13339
13340 This also means that commands like
13341 @samp{g77 -fno-asm foo.f} yield no diagnostics,
13342 despite the fact that no phase of the command was
13343 able to recognize and process @samp{-fno-asm}---perhaps
13344 a warning about this would be helpful if it were
13345 possible.
13346
13347 Code that processes Fortran options is found in
13348 @file{@value{path-g77}/top.c}, function @code{ffe_decode_option}.
13349 This code needs to check positive and negative forms
13350 of each option.
13351
13352 The defaults for Fortran options are set in their
13353 global definitions, also found in @file{@value{path-g77}/top.c}.
13354 Many of these defaults are actually macros defined
13355 in @file{@value{path-g77}/target.h}, since they might be
13356 machine-specific.
13357 However, since, in practice, GNU compilers
13358 should behave the same way on all configurations
13359 (especially when it comes to language constructs),
13360 the practice of setting defaults in @file{target.h}
13361 is likely to be deprecated and, ultimately, stopped
13362 in future versions of @code{g77}.
13363
13364 Accessor macros for Fortran options, used by code
13365 in the @code{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
13366
13367 @emph{Compiler options} are listed in @file{gcc/toplev.c}
13368 in the array @code{f_options}.
13369 An option not listed in @code{lang_options} is
13370 looked up in @code{f_options} and handled from there.
13371
13372 The defaults for compiler options are set in the
13373 global definitions for the corresponding variables,
13374 some of which are in @file{gcc/toplev.c}.
13375
13376 You can set different defaults for @emph{Fortran-oriented}
13377 or @emph{Fortran-reticent} compiler options by changing
13378 the source code of @code{g77} and rebuilding.
13379 How to do this depends on the version of @code{g77}:
13380
13381 @table @code
13382 @item G77 0.5.24 (EGCS 1.1)
13383 @itemx G77 0.5.25 (EGCS 1.2 - which became GCC 2.95)
13384 Change the @code{lang_init_options} routine in @file{gcc/gcc/f/com.c}.
13385
13386 (Note that these versions of @code{g77}
13387 perform internal consistency checking automatically
13388 when the @samp{-fversion} option is specified.)
13389
13390 @item G77 0.5.23
13391 @itemx G77 0.5.24 (EGCS 1.0)
13392 Change the way @code{f771} handles the @samp{-fset-g77-defaults}
13393 option, which is always provided as the first option when
13394 called by @code{g77} or @code{gcc}.
13395
13396 This code is in @code{ffe_decode_options} in @file{@value{path-g77}/top.c}.
13397 Have it change just the variables that you want to default
13398 to a different setting for Fortran compiles compared to
13399 compiles of other languages.
13400
13401 The @samp{-fset-g77-defaults} option is passed to @code{f771}
13402 automatically because of the specification information
13403 kept in @file{@value{path-g77}/lang-specs.h}.
13404 This file tells the @code{gcc} command how to recognize,
13405 in this case, Fortran source files (those to be preprocessed,
13406 and those that are not), and further, how to invoke the
13407 appropriate programs (including @code{f771}) to process
13408 those source files.
13409
13410 It is in @file{@value{path-g77}/lang-specs.h} that @samp{-fset-g77-defaults},
13411 @samp{-fversion}, and other options are passed, as appropriate,
13412 even when the user has not explicitly specified them.
13413 Other ``internal'' options such as @samp{-quiet} also
13414 are passed via this mechanism.
13415 @end table
13416
13417 @node Projects
13418 @chapter Projects
13419 @cindex projects
13420
13421 If you want to contribute to @code{g77} by doing research,
13422 design, specification, documentation, coding, or testing,
13423 the following information should give you some ideas.
13424 More relevant information might be available from
13425 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
13426
13427 @menu
13428 * Efficiency::               Make @code{g77} itself compile code faster.
13429 * Better Optimization::      Teach @code{g77} to generate faster code.
13430 * Simplify Porting::         Make @code{g77} easier to configure, build,
13431                              and install.
13432 * More Extensions::          Features many users won't know to ask for.
13433 * Machine Model::            @code{g77} should better leverage @code{gcc}.
13434 * Internals Documentation::  Make maintenance easier.
13435 * Internals Improvements::   Make internals more robust.
13436 * Better Diagnostics::       Make using @code{g77} on new code easier.
13437 @end menu
13438
13439 @node Efficiency
13440 @section Improve Efficiency
13441 @cindex efficiency
13442
13443 Don't bother doing any performance analysis until most of the
13444 following items are taken care of, because there's no question
13445 they represent serious space/time problems, although some of
13446 them show up only given certain kinds of (popular) input.
13447
13448 @itemize @bullet
13449 @item
13450 Improve @code{malloc} package and its uses to specify more info about
13451 memory pools and, where feasible, use obstacks to implement them.
13452
13453 @item
13454 Skip over uninitialized portions of aggregate areas (arrays,
13455 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
13456 This would reduce memory usage for large initialized aggregate
13457 areas, even ones with only one initialized element.
13458
13459 As of version 0.5.18, a portion of this item has already been
13460 accomplished.
13461
13462 @item
13463 Prescan the statement (in @file{sta.c}) so that the nature of the statement
13464 is determined as much as possible by looking entirely at its form,
13465 and not looking at any context (previous statements, including types
13466 of symbols).
13467 This would allow ripping out of the statement-confirmation,
13468 symbol retraction/confirmation, and diagnostic inhibition
13469 mechanisms.
13470 Plus, it would result in much-improved diagnostics.
13471 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
13472 is not a subroutine intrinsic, would result actual error instead of the
13473 unimplemented-statement catch-all.
13474
13475 @item
13476 Throughout @code{g77}, don't pass line/column pairs where
13477 a simple @code{ffewhere} type, which points to the error as much as is
13478 desired by the configuration, will do, and don't pass @code{ffelexToken} types
13479 where a simple @code{ffewhere} type will do.
13480 Then, allow new default
13481 configuration of @code{ffewhere} such that the source line text is not
13482 preserved, and leave it to things like Emacs' next-error function
13483 to point to them (now that @samp{next-error} supports column,
13484 or, perhaps, character-offset, numbers).
13485 The change in calling sequences should improve performance somewhat,
13486 as should not having to save source lines.
13487 (Whether this whole
13488 item will improve performance is questionable, but it should
13489 improve maintainability.)
13490
13491 @item
13492 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
13493 as regards the assembly output.
13494 Some of this might require improving
13495 the back end, but lots of improvement in space/time required in @code{g77}
13496 itself can be fairly easily obtained without touching the back end.
13497 Maybe type-conversion, where necessary, can be speeded up as well in
13498 cases like the one shown (converting the @samp{2} into @samp{2.}).
13499
13500 @item
13501 If analysis shows it to be worthwhile, optimize @file{lex.c}.
13502
13503 @item
13504 Consider redesigning @file{lex.c} to not need any feedback
13505 during tokenization, by keeping track of enough parse state on its
13506 own.
13507 @end itemize
13508
13509 @node Better Optimization
13510 @section Better Optimization
13511 @cindex optimization, better
13512 @cindex code generation, improving
13513
13514 Much of this work should be put off until after @code{g77} has
13515 all the features necessary for its widespread acceptance as a
13516 useful F77 compiler.
13517 However, perhaps this work can be done in parallel during
13518 the feature-adding work.
13519
13520 @itemize @bullet
13521 @item
13522 Do the equivalent of the trick of putting @samp{extern inline} in front
13523 of every function definition in @code{libg2c} and #include'ing the resulting
13524 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
13525 that are at all worth inlining.
13526 (Some of this has already been done, such as for integral exponentiation.)
13527
13528 @item
13529 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
13530 and it's clear that types line up
13531 and @samp{CHAR_VAR} is addressable or not a @code{VAR_DECL},
13532 make @samp{CHAR_VAR}, not a
13533 temporary, be the receiver for @samp{CHAR_FUNC}.
13534 (This is now done for @code{COMPLEX} variables.)
13535
13536 @item
13537 Design and implement Fortran-specific optimizations that don't
13538 really belong in the back end, or where the front end needs to
13539 give the back end more info than it currently does.
13540
13541 @item
13542 Design and implement a new run-time library interface, with the
13543 code going into @code{libgcc} so no special linking is required to
13544 link Fortran programs using standard language features.
13545 This library
13546 would speed up lots of things, from I/O (using precompiled formats,
13547 doing just one, or, at most, very few, calls for arrays or array sections,
13548 and so on) to general computing (array/section implementations of
13549 various intrinsics, implementation of commonly performed loops that
13550 aren't likely to be optimally compiled otherwise, etc.).
13551
13552 Among the important things the library would do are:
13553
13554 @itemize @bullet
13555 @item
13556 Be a one-stop-shop-type
13557 library, hence shareable and usable by all, in that what are now
13558 library-build-time options in @code{libg2c} would be moved at least to the
13559 @code{g77} compile phase, if not to finer grains (such as choosing how
13560 list-directed I/O formatting is done by default at @code{OPEN} time, for
13561 preconnected units via options or even statements in the main program
13562 unit, maybe even on a per-I/O basis with appropriate pragma-like
13563 devices).
13564 @end itemize
13565
13566 @item
13567 Probably requiring the new library design, change interface to
13568 normally have @code{COMPLEX} functions return their values in the way
13569 @code{gcc} would if they were declared @code{__complex__ float},
13570 rather than using
13571 the mechanism currently used by @code{CHARACTER} functions (whereby the
13572 functions are compiled as returning void and their first arg is
13573 a pointer to where to store the result).
13574 (Don't append underscores to
13575 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
13576 @code{gcc} rather than @code{f2c} calling conventions.)
13577
13578 @item
13579 Do something useful with @code{doiter} references where possible.
13580 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
13581 a @code{DO} loop that uses @samp{I} as the
13582 iteration variable, and the back end might find that info useful
13583 in determining whether it needs to read @samp{I} back into a register after
13584 the call.
13585 (It normally has to do that, unless it knows @samp{FOO} never
13586 modifies its passed-by-reference argument, which is rarely the case
13587 for Fortran-77 code.)
13588 @end itemize
13589
13590 @node Simplify Porting
13591 @section Simplify Porting
13592 @cindex porting, simplify
13593 @cindex simplify porting
13594
13595 Making @code{g77} easier to configure, port, build, and install, either
13596 as a single-system compiler or as a cross-compiler, would be
13597 very useful.
13598
13599 @itemize @bullet
13600 @item
13601 A new library (replacing @code{libg2c}) should improve portability as well as
13602 produce more optimal code.
13603 Further, @code{g77} and the new library should
13604 conspire to simplify naming of externals, such as by removing unnecessarily
13605 added underscores, and to reduce/eliminate the possibility of naming
13606 conflicts, while making debugger more straightforward.
13607
13608 Also, it should
13609 make multi-language applications more feasible, such as by providing
13610 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
13611 descriptors.
13612
13613 @item
13614 Possibly related to a new library, @code{g77} should produce the equivalent
13615 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
13616 main program unit, instead of compiling something that must be
13617 called by a library
13618 implementation of @code{main()}.
13619
13620 This would do many useful things such as
13621 provide more flexibility in terms of setting up exception handling,
13622 not requiring programmers to start their debugging sessions with
13623 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
13624
13625 @item
13626 The GBE needs to understand the difference between alignment
13627 requirements and desires.
13628 For example, on Intel x86 machines, @code{g77} currently imposes
13629 overly strict alignment requirements, due to the back end, but it
13630 would be useful for Fortran and C programmers to be able to override
13631 these @emph{recommendations} as long as they don't violate the actual
13632 processor @emph{requirements}.
13633 @end itemize
13634
13635 @node More Extensions
13636 @section More Extensions
13637 @cindex extensions, more
13638
13639 These extensions are not the sort of things users ask for ``by name'',
13640 but they might improve the usability of @code{g77}, and Fortran in
13641 general, in the long run.
13642 Some of these items really pertain to improving @code{g77} internals
13643 so that some popular extensions can be more easily supported.
13644
13645 @itemize @bullet
13646 @item
13647 Look through all the documentation on the GNU Fortran language,
13648 dialects, compiler, missing features, bugs, and so on.
13649 Many mentions of incomplete or missing features are
13650 sprinkled throughout.
13651 It is not worth repeating them here.
13652
13653 @item
13654 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
13655 named and unnamed.
13656 The idea is to provide a forward-looking, effective
13657 replacement for things like the old-style @code{PARAMETER} statement
13658 when people
13659 really need typelessness in a maintainable, portable, clearly documented
13660 way.
13661 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
13662 and whatever else might come along.
13663 (This is not really a call for polymorphism per se, just
13664 an ability to express limited, syntactic polymorphism.)
13665
13666 @item
13667 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
13668
13669 @item
13670 Support arbitrary file unit numbers, instead of limiting them
13671 to 0 through @samp{MXUNIT-1}.
13672 (This is a @code{libg2c} issue.)
13673
13674 @item
13675 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
13676 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
13677 later @code{UNIT=} in the first example is invalid.
13678 Make sure this is what users of this feature would expect.
13679
13680 @item
13681 Currently @code{g77} disallows @samp{READ(1'10)} since
13682 it is an obnoxious syntax, but
13683 supporting it might be pretty easy if needed.
13684 More details are needed, such
13685 as whether general expressions separated by an apostrophe are supported,
13686 or maybe the record number can be a general expression, and so on.
13687
13688 @item
13689 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
13690 fully.
13691 Currently there is no support at all
13692 for @code{%FILL} in @code{STRUCTURE} and related syntax,
13693 whereas the rest of the
13694 stuff has at least some parsing support.
13695 This requires either major
13696 changes to @code{libg2c} or its replacement.
13697
13698 @item
13699 F90 and @code{g77} probably disagree about label scoping relative to
13700 @code{INTERFACE} and @code{END INTERFACE}, and their contained
13701 procedure interface bodies (blocks?).
13702
13703 @item
13704 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
13705 since that was added after S8.112.
13706
13707 @item
13708 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
13709 with the final form of the standard (it was vague at S8.112).
13710
13711 @item
13712 It seems to be an ``open'' question whether a file, immediately after being
13713 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
13714 might be nice to offer an option of opening to ``undefined'' status, requiring
13715 an explicit absolute-positioning operation to be performed before any
13716 other (besides @code{CLOSE}) to assist in making applications port to systems
13717 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
13718 @end itemize
13719
13720 @node Machine Model
13721 @section Machine Model
13722
13723 This items pertain to generalizing @code{g77}'s view of
13724 the machine model to more fully accept whatever the GBE
13725 provides it via its configuration.
13726
13727 @itemize @bullet
13728 @item
13729 Switch to using @code{REAL_VALUE_TYPE} to represent floating-point constants
13730 exclusively so the target float format need not be required.
13731 This
13732 means changing the way @code{g77} handles initialization of aggregate areas
13733 having more than one type, such as @code{REAL} and @code{INTEGER},
13734 because currently
13735 it initializes them as if they were arrays of @code{char} and uses the
13736 bit patterns of the constants of the various types in them to determine
13737 what to stuff in elements of the arrays.
13738
13739 @item
13740 Rely more and more on back-end info and capabilities, especially in the
13741 area of constants (where having the @code{g77} front-end's IL just store
13742 the appropriate tree nodes containing constants might be best).
13743
13744 @item
13745 Suite of C and Fortran programs that a user/administrator can run on a
13746 machine to help determine the configuration for @code{g77} before building
13747 and help determine if the compiler works (especially with whatever
13748 libraries are installed) after building.
13749 @end itemize
13750
13751 @node Internals Documentation
13752 @section Internals Documentation
13753
13754 Better info on how @code{g77} works and how to port it is needed.
13755 Much of this should be done only after the redesign planned for
13756 0.6 is complete.
13757
13758 @xref{Front End}, which contains some information
13759 on @code{g77} internals.
13760
13761 @node Internals Improvements
13762 @section Internals Improvements
13763
13764 Some more items that would make @code{g77} more reliable
13765 and easier to maintain:
13766
13767 @itemize @bullet
13768 @item
13769 Generally make expression handling focus
13770 more on critical syntax stuff, leaving semantics to callers.
13771 For example,
13772 anything a caller can check, semantically, let it do so, rather
13773 than having @file{expr.c} do it.
13774 (Exceptions might include things like
13775 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
13776 it seems
13777 important to preserve the left-to-right-in-source order of production
13778 of diagnostics.)
13779
13780 @item
13781 Come up with better naming conventions for @samp{-D} to establish requirements
13782 to achieve desired implementation dialect via @file{proj.h}.
13783
13784 @item
13785 Clean up used tokens and @code{ffewhere}s in @code{ffeglobal_terminate_1}.
13786
13787 @item
13788 Replace @file{sta.c} @code{outpooldisp} mechanism with @code{malloc_pool_use}.
13789
13790 @item
13791 Check for @code{opANY} in more places in @file{com.c}, @file{std.c},
13792 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
13793 (after determining if there is indeed no real need for it).
13794
13795 @item
13796 Utility to read and check @file{bad.def} messages and their references in the
13797 code, to make sure calls are consistent with message templates.
13798
13799 @item
13800 Search and fix @samp{&ffe@dots{}} and similar so that
13801 @samp{ffe@dots{}ptr@dots{}} macros are
13802 available instead (a good argument for wishing this could have written all
13803 this stuff in C++, perhaps).
13804 On the other hand, it's questionable whether this sort of
13805 improvement is really necessary, given the availability of
13806 tools such as Emacs and Perl, which make finding any
13807 address-taking of structure members easy enough?
13808
13809 @item
13810 Some modules truly export the member names of their structures (and the
13811 structures themselves), maybe fix this, and fix other modules that just
13812 appear to as well (by appending @samp{_}, though it'd be ugly and probably
13813 not worth the time).
13814
13815 @item
13816 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
13817 in @file{proj.h}
13818 and use them throughout @code{g77} source code (especially in the definitions
13819 of access macros in @samp{.h} files) so they can be tailored
13820 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
13821
13822 @item
13823 Decorate throughout with @code{const} and other such stuff.
13824
13825 @item
13826 All F90 notational derivations in the source code are still based
13827 on the S8.112 version of the draft standard.
13828 Probably should update
13829 to the official standard, or put documentation of the rules as used
13830 in the code@dots{}uh@dots{}in the code.
13831
13832 @item
13833 Some @code{ffebld_new} calls (those outside of @file{ffeexpr.c} or
13834 inside but invoked via paths not involving @code{ffeexpr_lhs} or
13835 @code{ffeexpr_rhs}) might be creating things
13836 in improper pools, leading to such things staying around too long or
13837 (doubtful, but possible and dangerous) not long enough.
13838
13839 @item
13840 Some @code{ffebld_list_new} (or whatever) calls might not be matched by
13841 @code{ffebld_list_bottom} (or whatever) calls, which might someday matter.
13842 (It definitely is not a problem just yet.)
13843
13844 @item
13845 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
13846 due to alignment/mismatch or other problems---they end up without
13847 @code{ffestorag} objects, so maybe the backend (and other parts of the front
13848 end) can notice that and handle like an @code{opANY} (do what it wants, just
13849 don't complain or crash).
13850 Most of this seems to have been addressed
13851 by now, but a code review wouldn't hurt.
13852 @end itemize
13853
13854 @node Better Diagnostics
13855 @section Better Diagnostics
13856
13857 These are things users might not ask about, or that need to
13858 be looked into, before worrying about.
13859 Also here are items that involve reducing unnecessary diagnostic
13860 clutter.
13861
13862 @itemize @bullet
13863 @item
13864 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
13865 lengths, type classes, and so on),
13866 @code{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
13867 it specifies.
13868
13869 @item
13870 Speed up and improve error handling for data when repeat-count is
13871 specified.
13872 For example, don't output 20 unnecessary messages after the
13873 first necessary one for:
13874
13875 @smallexample
13876 INTEGER X(20)
13877 CONTINUE
13878 DATA (X(I), J= 1, 20) /20*5/
13879 END
13880 @end smallexample
13881
13882 @noindent
13883 (The @code{CONTINUE} statement ensures the @code{DATA} statement
13884 is processed in the context of executable, not specification,
13885 statements.)
13886 @end itemize
13887
13888 @include ffe.texi
13889
13890 @end ifset
13891
13892 @ifset USING
13893 @node Diagnostics
13894 @chapter Diagnostics
13895 @cindex diagnostics
13896
13897 Some diagnostics produced by @code{g77} require sufficient explanation
13898 that the explanations are given below, and the diagnostics themselves
13899 identify the appropriate explanation.
13900
13901 Identification uses the GNU Info format---specifically, the @code{info}
13902 command that displays the explanation is given within square
13903 brackets in the diagnostic.
13904 For example:
13905
13906 @smallexample
13907 foo.f:5: Invalid statement [info -f g77 M FOOEY]
13908 @end smallexample
13909
13910 More details about the above diagnostic is found in the @code{g77} Info
13911 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
13912 which is displayed by typing the UNIX command
13913 @samp{info -f g77 M FOOEY}.
13914
13915 Other Info readers, such as EMACS, may be just as easily used to display
13916 the pertinent node.
13917 In the above example, @samp{g77} is the Info document name,
13918 @samp{M} is the top-level menu item to select,
13919 and, in that node (named @samp{Diagnostics}, the name of
13920 this chapter, which is the very text you're reading now),
13921 @samp{FOOEY} is the menu item to select.
13922
13923 @iftex
13924 In this printed version of the @code{g77} manual, the above example
13925 points to a section, below, entitled @samp{FOOEY}---though, of course,
13926 as the above is just a sample, no such section exists.
13927 @end iftex
13928
13929 @menu
13930 * CMPAMBIG::    Ambiguous use of intrinsic.
13931 * EXPIMP::      Intrinsic used explicitly and implicitly.
13932 * INTGLOB::     Intrinsic also used as name of global.
13933 * LEX::         Various lexer messages
13934 * GLOBALS::     Disagreements about globals.
13935 * LINKFAIL::    When linking @code{f771} fails.
13936 * Y2KBAD::      Use of non-Y2K-compliant intrinsic.
13937 @end menu
13938
13939 @node CMPAMBIG
13940 @section @code{CMPAMBIG}
13941
13942 @noindent
13943 @smallexample
13944 Ambiguous use of intrinsic @var{intrinsic} @dots{}
13945 @end smallexample
13946
13947 The type of the argument to the invocation of the @var{intrinsic}
13948 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
13949 Typically, it is @code{COMPLEX(KIND=2)}, also known as
13950 @code{DOUBLE COMPLEX}.
13951
13952 The interpretation of this invocation depends on the particular
13953 dialect of Fortran for which the code was written.
13954 Some dialects convert the real part of the argument to
13955 @code{REAL(KIND=1)}, thus losing precision; other dialects,
13956 and Fortran 90, do no such conversion.
13957
13958 So, GNU Fortran rejects such invocations except under certain
13959 circumstances, to avoid making an incorrect assumption that results
13960 in generating the wrong code.
13961
13962 To determine the dialect of the program unit, perhaps even whether
13963 that particular invocation is properly coded, determine how the
13964 result of the intrinsic is used.
13965
13966 The result of @var{intrinsic} is expected (by the original programmer)
13967 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
13968
13969 @itemize @bullet
13970 @item
13971 It is passed as an argument to a procedure that explicitly or
13972 implicitly declares that argument @code{REAL(KIND=1)}.
13973
13974 For example,
13975 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
13976 statement specifying the dummy argument corresponding to an
13977 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
13978 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
13979 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
13980 of @code{REAL(KIND=2)}.
13981
13982 @item
13983 It is used in a context that would otherwise not include
13984 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
13985 invocation as @code{REAL(KIND=2)} would result in unnecessary
13986 promotions and (typically) more expensive operations on the
13987 wider type.
13988
13989 For example:
13990
13991 @smallexample
13992 DOUBLE COMPLEX Z
13993 @dots{}
13994 R(1) = T * REAL(Z)
13995 @end smallexample
13996
13997 The above example suggests the programmer expected the real part
13998 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
13999 multiplied by @samp{T} (presumed, along with @samp{R} above, to
14000 be type @code{REAL(KIND=1)}).
14001
14002 Otherwise, the conversion would have to be delayed until after
14003 the multiplication, requiring not only an extra conversion
14004 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
14005 expensive multiplication (a double-precision multiplication instead
14006 of a single-precision one).
14007 @end itemize
14008
14009 The result of @var{intrinsic} is expected (by the original programmer)
14010 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
14011
14012 @itemize @bullet
14013 @item
14014 It is passed as an argument to a procedure that explicitly or
14015 implicitly declares that argument @code{REAL(KIND=2)}.
14016
14017 For example, a procedure specifying a @code{DOUBLE PRECISION}
14018 dummy argument corresponding to an
14019 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14020 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14021 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
14022 of @code{REAL(KIND=1)}.
14023
14024 @item
14025 It is used in an expression context that includes
14026 other @code{REAL(KIND=2)} operands,
14027 or is assigned to a @code{REAL(KIND=2)} variable or array element.
14028
14029 For example:
14030
14031 @smallexample
14032 DOUBLE COMPLEX Z
14033 DOUBLE PRECISION R, T
14034 @dots{}
14035 R(1) = T * REAL(Z)
14036 @end smallexample
14037
14038 The above example suggests the programmer expected the real part
14039 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
14040 by the @code{REAL()} intrinsic.
14041
14042 Otherwise, the conversion would have to be immediately followed
14043 by a conversion back to @code{REAL(KIND=2)}, losing
14044 the original, full precision of the real part of @code{Z},
14045 before being multiplied by @samp{T}.
14046 @end itemize
14047
14048 Once you have determined whether a particular invocation of @var{intrinsic}
14049 expects the Fortran 90 interpretation, you can:
14050
14051 @itemize @bullet
14052 @item
14053 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
14054 @code{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
14055 is @code{AIMAG})
14056 if it expected the Fortran 90 interpretation.
14057
14058 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
14059 some other type, such as @code{COMPLEX*32}, you should use the
14060 appropriate intrinsic, such as the one to convert to @code{REAL*16}
14061 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
14062 @code{QIMAG()} in place of @code{DIMAG()}).
14063
14064 @item
14065 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
14066 otherwise.
14067 This converts to @code{REAL(KIND=1)} in all working
14068 Fortran compilers.
14069 @end itemize
14070
14071 If you don't want to change the code, and you are certain that all
14072 ambiguous invocations of @var{intrinsic} in the source file have
14073 the same expectation regarding interpretation, you can:
14074
14075 @itemize @bullet
14076 @item
14077 Compile with the @code{g77} option @samp{-ff90}, to enable the
14078 Fortran 90 interpretation.
14079
14080 @item
14081 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
14082 to enable the non-Fortran-90 interpretations.
14083 @end itemize
14084
14085 @xref{REAL() and AIMAG() of Complex}, for more information on this
14086 issue.
14087
14088 Note: If the above suggestions don't produce enough evidence
14089 as to whether a particular program expects the Fortran 90
14090 interpretation of this ambiguous invocation of @var{intrinsic},
14091 there is one more thing you can try.
14092
14093 If you have access to most or all the compilers used on the
14094 program to create successfully tested and deployed executables,
14095 read the documentation for, and @emph{also} test out, each compiler
14096 to determine how it treats the @var{intrinsic} intrinsic in
14097 this case.
14098 (If all the compilers don't agree on an interpretation, there
14099 might be lurking bugs in the deployed versions of the program.)
14100
14101 The following sample program might help:
14102
14103 @cindex JCB003 program
14104 @smallexample
14105       PROGRAM JCB003
14106 C
14107 C Written by James Craig Burley 1997-02-23.
14108 C
14109 C Determine how compilers handle non-standard REAL
14110 C and AIMAG on DOUBLE COMPLEX operands.
14111 C
14112       DOUBLE COMPLEX Z
14113       REAL R
14114       Z = (3.3D0, 4.4D0)
14115       R = Z
14116       CALL DUMDUM(Z, R)
14117       R = REAL(Z) - R
14118       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
14119       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
14120       R = 4.4D0
14121       CALL DUMDUM(Z, R)
14122       R = AIMAG(Z) - R
14123       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
14124       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
14125       END
14126 C
14127 C Just to make sure compiler doesn't use naive flow
14128 C analysis to optimize away careful work above,
14129 C which might invalidate results....
14130 C
14131       SUBROUTINE DUMDUM(Z, R)
14132       DOUBLE COMPLEX Z
14133       REAL R
14134       END
14135 @end smallexample
14136
14137 If the above program prints contradictory results on a
14138 particular compiler, run away!
14139
14140 @node EXPIMP
14141 @section @code{EXPIMP}
14142
14143 @noindent
14144 @smallexample
14145 Intrinsic @var{intrinsic} referenced @dots{}
14146 @end smallexample
14147
14148 The @var{intrinsic} is explicitly declared in one program
14149 unit in the source file and implicitly used as an intrinsic
14150 in another program unit in the same source file.
14151
14152 This diagnostic is designed to catch cases where a program
14153 might depend on using the name @var{intrinsic} as an intrinsic
14154 in one program unit and as a global name (such as the name
14155 of a subroutine or function) in another, but @code{g77} recognizes
14156 the name as an intrinsic in both cases.
14157
14158 After verifying that the program unit making implicit use
14159 of the intrinsic is indeed written expecting the intrinsic,
14160 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14161 program unit to prevent this warning.
14162
14163 This and related warnings are disabled by using
14164 the @samp{-Wno-globals} option when compiling.
14165
14166 Note that this warning is not issued for standard intrinsics.
14167 Standard intrinsics include those described in the FORTRAN 77
14168 standard and, if @samp{-ff90} is specified, those described
14169 in the Fortran 90 standard.
14170 Such intrinsics are not as likely to be confused with user
14171 procedures as intrinsics provided as extensions to the
14172 standard by @code{g77}.
14173
14174 @node INTGLOB
14175 @section @code{INTGLOB}
14176
14177 @noindent
14178 @smallexample
14179 Same name `@var{intrinsic}' given @dots{}
14180 @end smallexample
14181
14182 The name @var{intrinsic} is used for a global entity (a common
14183 block or a program unit) in one program unit and implicitly
14184 used as an intrinsic in another program unit.
14185
14186 This diagnostic is designed to catch cases where a program
14187 intends to use a name entirely as a global name, but @code{g77}
14188 recognizes the name as an intrinsic in the program unit that
14189 references the name, a situation that would likely produce
14190 incorrect code.
14191
14192 For example:
14193
14194 @smallexample
14195 INTEGER FUNCTION TIME()
14196 @dots{}
14197 END
14198 @dots{}
14199 PROGRAM SAMP
14200 INTEGER TIME
14201 PRINT *, 'Time is ', TIME()
14202 END
14203 @end smallexample
14204
14205 The above example defines a program unit named @samp{TIME}, but
14206 the reference to @samp{TIME} in the main program unit @samp{SAMP}
14207 is normally treated by @code{g77} as a reference to the intrinsic
14208 @code{TIME()} (unless a command-line option that prevents such
14209 treatment has been specified).
14210
14211 As a result, the program @samp{SAMP} will @emph{not}
14212 invoke the @samp{TIME} function in the same source file.
14213
14214 Since @code{g77} recognizes @code{libU77} procedures as
14215 intrinsics, and since some existing code uses the same names
14216 for its own procedures as used by some @code{libU77}
14217 procedures, this situation is expected to arise often enough
14218 to make this sort of warning worth issuing.
14219
14220 After verifying that the program unit making implicit use
14221 of the intrinsic is indeed written expecting the intrinsic,
14222 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14223 program unit to prevent this warning.
14224
14225 Or, if you believe the program unit is designed to invoke the
14226 program-defined procedure instead of the intrinsic (as
14227 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
14228 statement to the program unit that references the name to
14229 prevent this warning.
14230
14231 This and related warnings are disabled by using
14232 the @samp{-Wno-globals} option when compiling.
14233
14234 Note that this warning is not issued for standard intrinsics.
14235 Standard intrinsics include those described in the FORTRAN 77
14236 standard and, if @samp{-ff90} is specified, those described
14237 in the Fortran 90 standard.
14238 Such intrinsics are not as likely to be confused with user
14239 procedures as intrinsics provided as extensions to the
14240 standard by @code{g77}.
14241
14242 @node LEX
14243 @section @code{LEX}
14244
14245 @noindent
14246 @smallexample
14247 Unrecognized character @dots{}
14248 Invalid first character @dots{}
14249 Line too long @dots{}
14250 Non-numeric character @dots{}
14251 Continuation indicator @dots{}
14252 Label at @dots{} invalid with continuation line indicator @dots{}
14253 Character constant @dots{}
14254 Continuation line @dots{}
14255 Statement at @dots{} begins with invalid token
14256 @end smallexample
14257
14258 Although the diagnostics identify specific problems, they can
14259 be produced when general problems such as the following occur:
14260
14261 @itemize @bullet
14262 @item
14263 The source file contains something other than Fortran code.
14264
14265 If the code in the file does not look like many of the examples
14266 elsewhere in this document, it might not be Fortran code.
14267 (Note that Fortran code often is written in lower case letters,
14268 while the examples in this document use upper case letters,
14269 for stylistic reasons.)
14270
14271 For example, if the file contains lots of strange-looking
14272 characters, it might be APL source code; if it contains lots
14273 of parentheses, it might be Lisp source code; if it
14274 contains lots of bugs, it might be C++ source code.
14275
14276 @item
14277 The source file contains free-form Fortran code, but @samp{-ffree-form}
14278 was not specified on the command line to compile it.
14279
14280 Free form is a newer form for Fortran code.
14281 The older, classic form is called fixed form.
14282
14283 @cindex continuation character
14284 @cindex characters, continuation
14285 Fixed-form code is visually fairly distinctive, because
14286 numerical labels and comments are all that appear in
14287 the first five columns of a line, the sixth column is
14288 reserved to denote continuation lines,
14289 and actual statements start at or beyond column 7.
14290 Spaces generally are not significant, so if you
14291 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
14292 you are looking at fixed-form code.
14293 @cindex *
14294 @cindex asterisk
14295 Comment lines are indicated by the letter @samp{C} or the symbol
14296 @samp{*} in column 1.
14297 @cindex trailing comment
14298 @cindex comment
14299 @cindex characters, comment
14300 @cindex !
14301 @cindex exclamation point
14302 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
14303 which many compilers support.)
14304
14305 Free-form code is distinguished from fixed-form source
14306 primarily by the fact that statements may start anywhere.
14307 (If lots of statements start in columns 1 through 6,
14308 that's a strong indicator of free-form source.)
14309 Consecutive keywords must be separated by spaces, so
14310 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
14311 There are no comment lines per se, but @samp{!} starts a
14312 comment anywhere in a line (other than within a character or
14313 Hollerith constant).
14314
14315 @xref{Source Form}, for more information.
14316
14317 @item
14318 The source file is in fixed form and has been edited without
14319 sensitivity to the column requirements.
14320
14321 Statements in fixed-form code must be entirely contained within
14322 columns 7 through 72 on a given line.
14323 Starting them ``early'' is more likely to result in diagnostics
14324 than finishing them ``late'', though both kinds of errors are
14325 often caught at compile time.
14326
14327 For example, if the following code fragment is edited by following
14328 the commented instructions literally, the result, shown afterward,
14329 would produce a diagnostic when compiled:
14330
14331 @smallexample
14332 C On XYZZY systems, remove "C" on next line:
14333 C     CALL XYZZY_RESET
14334 @end smallexample
14335
14336 The result of editing the above line might be:
14337
14338 @smallexample
14339 C On XYZZY systems, remove "C" on next line:
14340      CALL XYZZY_RESET
14341 @end smallexample
14342
14343 However, that leaves the first @samp{C} in the @code{CALL}
14344 statement in column 6, making it a comment line, which is
14345 not really what the author intended, and which is likely
14346 to result in one of the above-listed diagnostics.
14347
14348 @emph{Replacing} the @samp{C} in column 1 with a space
14349 is the proper change to make, to ensure the @code{CALL}
14350 keyword starts in or after column 7.
14351
14352 Another common mistake like this is to forget that fixed-form
14353 source lines are significant through only column 72, and that,
14354 normally, any text beyond column 72 is ignored or is diagnosed
14355 at compile time.
14356
14357 @xref{Source Form}, for more information.
14358
14359 @item
14360 The source file requires preprocessing, and the preprocessing
14361 is not being specified at compile time.
14362
14363 A source file containing lines beginning with @code{#define},
14364 @code{#include}, @code{#if}, and so on is likely one that
14365 requires preprocessing.
14366
14367 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
14368 the file normally will be compiled @emph{without} preprocessing
14369 by @code{g77}.
14370
14371 Change the file's suffix from @samp{.f} to @samp{.F}
14372 (or, on systems with case-insensitive file names,
14373 to @samp{.fpp} or @samp{.FPP}),
14374 from @samp{.for} to @samp{.fpp},
14375 or from @samp{.FOR} to @samp{.FPP}.
14376 @code{g77} compiles files with such names @emph{with}
14377 preprocessing.
14378
14379 @pindex cpp
14380 @cindex preprocessor
14381 @cindex cpp program
14382 @cindex programs, cpp
14383 @cindex @samp{-x f77-cpp-input} option
14384 @cindex options, @samp{-x f77-cpp-input}
14385 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
14386 the language @samp{f77-cpp-input} for Fortran files that
14387 require preprocessing.
14388 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
14389
14390 @item
14391 The source file is preprocessed, and the results of preprocessing
14392 result in syntactic errors that are not necessarily obvious to
14393 someone examining the source file itself.
14394
14395 Examples of errors resulting from preprocessor macro expansion
14396 include exceeding the line-length limit, improperly starting,
14397 terminating, or incorporating the apostrophe or double-quote in
14398 a character constant, improperly forming a Hollerith constant,
14399 and so on.
14400
14401 @xref{Overall Options,,Options Controlling the Kind of Output},
14402 for suggestions about how to use, and not use, preprocessing
14403 for Fortran code.
14404 @end itemize
14405
14406 @node GLOBALS
14407 @section @code{GLOBALS}
14408
14409 @noindent
14410 @smallexample
14411 Global name @var{name} defined at @dots{} already defined@dots{}
14412 Global name @var{name} at @dots{} has different type@dots{}
14413 Too many arguments passed to @var{name} at @dots{}
14414 Too few arguments passed to @var{name} at @dots{}
14415 Argument #@var{n} of @var{name} is @dots{}
14416 @end smallexample
14417
14418 These messages all identify disagreements about the
14419 global procedure named @var{name} among different program units
14420 (usually including @var{name} itself).
14421
14422 Whether a particular disagreement is reported
14423 as a warning or an error
14424 can depend on the relative order
14425 of the disagreeing portions of the source file.
14426
14427 Disagreements between a procedure invocation
14428 and the @emph{subsequent} procedure itself
14429 are, usually, diagnosed as errors
14430 when the procedure itself @emph{precedes} the invocation.
14431 Other disagreements are diagnosed via warnings.
14432
14433 @cindex forward references
14434 @cindex in-line code
14435 @cindex compilation, in-line
14436 This distinction, between warnings and errors,
14437 is due primarily to the present tendency of the @code{gcc} back end
14438 to inline only those procedure invocations that are
14439 @emph{preceded} by the corresponding procedure definitions.
14440 If the @code{gcc} back end is changed
14441 to inline ``forward references'',
14442 in which invocations precede definitions,
14443 the @code{g77} front end will be changed
14444 to treat both orderings as errors, accordingly.
14445
14446 The sorts of disagreements that are diagnosed by @code{g77} include
14447 whether a procedure is a subroutine or function;
14448 if it is a function, the type of the return value of the procedure;
14449 the number of arguments the procedure accepts;
14450 and the type of each argument.
14451
14452 Disagreements regarding global names among program units
14453 in a Fortran program @emph{should} be fixed in the code itself.
14454 However, if that is not immediately practical,
14455 and the code has been working for some time,
14456 it is possible it will work
14457 when compiled with the @samp{-fno-globals} option.
14458
14459 The @samp{-fno-globals} option
14460 causes these diagnostics to all be warnings
14461 and disables all inlining of references to global procedures
14462 (to avoid subsequent compiler crashes and bad-code generation).
14463 Use of the @samp{-Wno-globals} option as well as @samp{-fno-globals}
14464 suppresses all of these diagnostics.
14465 (@samp{-Wno-globals} by itself disables only the warnings,
14466 not the errors.)
14467
14468 After using @samp{-fno-globals} to work around these problems,
14469 it is wise to stop using that option and address them by fixing
14470 the Fortran code, because such problems, while they might not
14471 actually result in bugs on some systems, indicate that the code
14472 is not as portable as it could be.
14473 In particular, the code might appear to work on a particular
14474 system, but have bugs that affect the reliability of the data
14475 without exhibiting any other outward manifestations of the bugs.
14476
14477 @node LINKFAIL
14478 @section @code{LINKFAIL}
14479
14480 @noindent
14481 On AIX 4.1, @code{g77} might not build with the native (non-GNU) tools
14482 due to a linker bug in coping with the @samp{-bbigtoc} option which
14483 leads to a @samp{Relocation overflow} error.  The GNU linker is not
14484 recommended on current AIX versions, though; it was developed under a
14485 now-unsupported version.  This bug is said to be fixed by `update PTF
14486 U455193 for APAR IX75823'.
14487
14488 Compiling with @samp{-mminimal-toc}
14489 might solve this problem, e.g.@: by adding
14490 @smallexample
14491 BOOT_CFLAGS='-mminimal-toc -O2 -g'
14492 @end smallexample
14493 to the @code{make bootstrap} command line.
14494
14495 @node Y2KBAD
14496 @section @code{Y2KBAD}
14497 @cindex Y2K compliance
14498 @cindex Year 2000 compliance
14499
14500 @noindent
14501 @smallexample
14502 Intrinsic `@var{name}', invoked at (^), known to be non-Y2K-compliant@dots{}
14503 @end smallexample
14504
14505 This diagnostic indicates that
14506 the specific intrinsic invoked by the name @var{name}
14507 is known to have an interface
14508 that is not Year-2000 (Y2K) compliant.
14509
14510 @xref{Year 2000 (Y2K) Problems}.
14511
14512 @end ifset
14513
14514 @node Index
14515 @unnumbered Index
14516
14517 @printindex cp
14518 @bye