* doc/cpp.texi, doc/cppinternals.texi, doc/gcc.texi: Move contents
[official-gcc.git] / gcc / f / g77.texi
blob5d3fb2f5db50712977b380255b72178730ab89c7
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename g77.info
5 @set last-update 2001-05-22
6 @set copyrights-g77 1995,1996,1997,1998,1999,2000,2001
8 @include root.texi
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
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
27 @c 6/27/96 FSF DO wants smallbook fmt for 1st bound edition. (from gcc.texi)
28 @c @smallbook
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
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
54 @syncodeindex fn cp
55 @syncodeindex vr cp
56 @c %**end of header
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.
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.)
68 @c @tex
69 @c \global\bindingoffset=0.75in
70 @c \global\normaloffset =0.75in
71 @c @end tex
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
94 Published by the Free Software Foundation
95 59 Temple Place - Suite 330
96 Boston, MA 02111-1307 USA
98 Copyright (C) @value{copyrights-g77} Free Software Foundation, Inc.
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'', the Front-Cover
105 texts being (a) (see below), and with the Back-Cover Texts being (b)
106 (see below).  A copy of the license is included in the section entitled
107 ``GNU Free Documentation License''.
109 (a) The FSF's Front-Cover Text is:
111      A GNU Manual
113 (b) The FSF's Back-Cover Text is:
115      You have freedom to copy and modify this GNU Manual, like GNU
116      software.  Copies published by the Free Software Foundation raise
117      funds for GNU development.
118 @end ifinfo
120 Contributed by James Craig Burley (@email{@value{email-burley}}).
121 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
122 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
124 @setchapternewpage odd
125 @c @finalout
126 @titlepage
127 @ifset INTERNALS
128 @ifset USING
129 @center @titlefont{Using and Porting GNU Fortran}
131 @end ifset
132 @end ifset
133 @ifclear INTERNALS
134 @title Using GNU Fortran
135 @end ifclear
136 @ifclear USING
137 @title Porting GNU Fortran
138 @end ifclear
139 @sp 2
140 @center James Craig Burley
141 @sp 3
142 @center Last updated @value{last-update}
143 @sp 1
144 @center for version @value{version-g77}
145 @page
146 @vskip 0pt plus 1filll
147 Copyright @copyright{} @value{copyrights-g77} Free Software Foundation, Inc.
148 @sp 2
149 For the @value{which-g77} Version*
150 @sp 1
151 Published by the Free Software Foundation @*
152 59 Temple Place - Suite 330@*
153 Boston, MA 02111-1307, USA@*
154 @c Last printed ??ber, 19??.@*
155 @c Printed copies are available for $? each.@*
156 @c ISBN ???
157 @sp 1
158 Permission is granted to copy, distribute and/or modify this document
159 under the terms of the GNU Free Documentation License, Version 1.1 or
160 any later version published by the Free Software Foundation; with the
161 Invariant Sections being ``GNU General Public License'', the Front-Cover
162 texts being (a) (see below), and with the Back-Cover Texts being (b)
163 (see below).  A copy of the license is included in the section entitled
164 ``GNU Free Documentation License''.
166 (a) The FSF's Front-Cover Text is:
168      A GNU Manual
170 (b) The FSF's Back-Cover Text is:
172      You have freedom to copy and modify this GNU Manual, like GNU
173      software.  Copies published by the Free Software Foundation raise
174      funds for GNU development.
175 @end titlepage
176 @summarycontents
177 @contents
178 @page
180 @ifinfo
182 @node Top, Copying,, (DIR)
183 @top Introduction
184 @cindex Introduction
186 @ifset INTERNALS
187 @ifset USING
188 This manual documents how to run, install and port @code{g77},
189 as well as its new features and incompatibilities,
190 and how to report bugs.
191 It corresponds to the @value{which-g77} version of @code{g77}.
192 @end ifset
193 @end ifset
195 @ifclear INTERNALS
196 This manual documents how to run and install @code{g77},
197 as well as its new features and incompatibilities, and how to report
198 bugs.
199 It corresponds to the @value{which-g77} version of @code{g77}.
200 @end ifclear
201 @ifclear USING
202 This manual documents how to port @code{g77},
203 as well as its new features and incompatibilities,
204 and how to report bugs.
205 It corresponds to the @value{which-g77} version of @code{g77}.
206 @end ifclear
208 @end ifinfo
210 @ifset DEVELOPMENT
211 @emph{Warning:} This document is still under development,
212 and might not accurately reflect the @code{g77} code base
213 of which it is a part.
214 Efforts are made to keep it somewhat up-to-date,
215 but they are particularly concentrated
216 on any version of this information
217 that is distributed as part of a @emph{released} @code{g77}.
219 In particular, while this document is intended to apply to
220 the @value{which-g77} version of @code{g77},
221 only an official @emph{release} of that version
222 is expected to contain documentation that is
223 most consistent with the @code{g77} product in that version.
224 @end ifset
226 @menu
227 * Copying::         GNU General Public License says
228                     how you can copy and share GNU Fortran.
229 * GNU Free Documentation License::
230                     How you can copy and share this manual.
231 * Contributors::    People who have contributed to GNU Fortran.
232 * Funding::         How to help assure continued work for free software.
233 * Funding GNU Fortran::  How to help assure continued work on GNU Fortran.
234 * Look and Feel::   Protect your freedom---fight ``look and feel''.
235 @ifset USING
236 * Getting Started:: Finding your way around this manual.
237 * What is GNU Fortran?::  How @code{g77} fits into the universe.
238 * G77 and GCC::     You can compile Fortran, C, or other programs.
239 * Invoking G77::    Command options supported by @code{g77}.
240 * News::            News about recent releases of @code{g77}.
241 * Changes::         User-visible changes to recent releases of @code{g77}.
242 * Language::        The GNU Fortran language.
243 * Compiler::        The GNU Fortran compiler.
244 * Other Dialects::  Dialects of Fortran supported by @code{g77}.
245 * Other Compilers:: Fortran compilers other than @code{g77}.
246 * Other Languages:: Languages other than Fortran.
247 * Installation::    How to configure, compile and install GNU 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
261 * M: Diagnostics.   Diagnostics produced by @code{g77}.
263 * Index::           Index of concepts and symbol names.
264 @end menu
265 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
267 @node Copying
268 @unnumbered GNU GENERAL PUBLIC LICENSE
269 @center Version 2, June 1991
271 @display
272 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
273 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
275 Everyone is permitted to copy and distribute verbatim copies
276 of this license document, but changing it is not allowed.
277 @end display
279 @unnumberedsec Preamble
281   The licenses for most software are designed to take away your
282 freedom to share and change it.  By contrast, the GNU General Public
283 License is intended to guarantee your freedom to share and change free
284 software---to make sure the software is free for all its users.  This
285 General Public License applies to most of the Free Software
286 Foundation's software and to any other program whose authors commit to
287 using it.  (Some other Free Software Foundation software is covered by
288 the GNU Library General Public License instead.)  You can apply it to
289 your programs, too.
291   When we speak of free software, we are referring to freedom, not
292 price.  Our General Public Licenses are designed to make sure that you
293 have the freedom to distribute copies of free software (and charge for
294 this service if you wish), that you receive source code or can get it
295 if you want it, that you can change the software or use pieces of it
296 in new free programs; and that you know you can do these things.
298   To protect your rights, we need to make restrictions that forbid
299 anyone to deny you these rights or to ask you to surrender the rights.
300 These restrictions translate to certain responsibilities for you if you
301 distribute copies of the software, or if you modify it.
303   For example, if you distribute copies of such a program, whether
304 gratis or for a fee, you must give the recipients all the rights that
305 you have.  You must make sure that they, too, receive or can get the
306 source code.  And you must show them these terms so they know their
307 rights.
309   We protect your rights with two steps: (1) copyright the software, and
310 (2) offer you this license which gives you legal permission to copy,
311 distribute and/or modify the software.
313   Also, for each author's protection and ours, we want to make certain
314 that everyone understands that there is no warranty for this free
315 software.  If the software is modified by someone else and passed on, we
316 want its recipients to know that what they have is not the original, so
317 that any problems introduced by others will not reflect on the original
318 authors' reputations.
320   Finally, any free program is threatened constantly by software
321 patents.  We wish to avoid the danger that redistributors of a free
322 program will individually obtain patent licenses, in effect making the
323 program proprietary.  To prevent this, we have made it clear that any
324 patent must be licensed for everyone's free use or not licensed at all.
326   The precise terms and conditions for copying, distribution and
327 modification follow.
329 @iftex
330 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
331 @end iftex
332 @ifinfo
333 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
334 @end ifinfo
336 @enumerate 0
337 @item
338 This License applies to any program or other work which contains
339 a notice placed by the copyright holder saying it may be distributed
340 under the terms of this General Public License.  The ``Program'', below,
341 refers to any such program or work, and a ``work based on the Program''
342 means either the Program or any derivative work under copyright law:
343 that is to say, a work containing the Program or a portion of it,
344 either verbatim or with modifications and/or translated into another
345 language.  (Hereinafter, translation is included without limitation in
346 the term ``modification''.)  Each licensee is addressed as ``you''.
348 Activities other than copying, distribution and modification are not
349 covered by this License; they are outside its scope.  The act of
350 running the Program is not restricted, and the output from the Program
351 is covered only if its contents constitute a work based on the
352 Program (independent of having been made by running the Program).
353 Whether that is true depends on what the Program does.
355 @item
356 You may copy and distribute verbatim copies of the Program's
357 source code as you receive it, in any medium, provided that you
358 conspicuously and appropriately publish on each copy an appropriate
359 copyright notice and disclaimer of warranty; keep intact all the
360 notices that refer to this License and to the absence of any warranty;
361 and give any other recipients of the Program a copy of this License
362 along with the Program.
364 You may charge a fee for the physical act of transferring a copy, and
365 you may at your option offer warranty protection in exchange for a fee.
367 @item
368 You may modify your copy or copies of the Program or any portion
369 of it, thus forming a work based on the Program, and copy and
370 distribute such modifications or work under the terms of Section 1
371 above, provided that you also meet all of these conditions:
373 @enumerate a
374 @item
375 You must cause the modified files to carry prominent notices
376 stating that you changed the files and the date of any change.
378 @item
379 You must cause any work that you distribute or publish, that in
380 whole or in part contains or is derived from the Program or any
381 part thereof, to be licensed as a whole at no charge to all third
382 parties under the terms of this License.
384 @item
385 If the modified program normally reads commands interactively
386 when run, you must cause it, when started running for such
387 interactive use in the most ordinary way, to print or display an
388 announcement including an appropriate copyright notice and a
389 notice that there is no warranty (or else, saying that you provide
390 a warranty) and that users may redistribute the program under
391 these conditions, and telling the user how to view a copy of this
392 License.  (Exception: if the Program itself is interactive but
393 does not normally print such an announcement, your work based on
394 the Program is not required to print an announcement.)
395 @end enumerate
397 These requirements apply to the modified work as a whole.  If
398 identifiable sections of that work are not derived from the Program,
399 and can be reasonably considered independent and separate works in
400 themselves, then this License, and its terms, do not apply to those
401 sections when you distribute them as separate works.  But when you
402 distribute the same sections as part of a whole which is a work based
403 on the Program, the distribution of the whole must be on the terms of
404 this License, whose permissions for other licensees extend to the
405 entire whole, and thus to each and every part regardless of who wrote it.
407 Thus, it is not the intent of this section to claim rights or contest
408 your rights to work written entirely by you; rather, the intent is to
409 exercise the right to control the distribution of derivative or
410 collective works based on the Program.
412 In addition, mere aggregation of another work not based on the Program
413 with the Program (or with a work based on the Program) on a volume of
414 a storage or distribution medium does not bring the other work under
415 the scope of this License.
417 @item
418 You may copy and distribute the Program (or a work based on it,
419 under Section 2) in object code or executable form under the terms of
420 Sections 1 and 2 above provided that you also do one of the following:
422 @enumerate a
423 @item
424 Accompany it with the complete corresponding machine-readable
425 source code, which must be distributed under the terms of Sections
426 1 and 2 above on a medium customarily used for software interchange; or,
428 @item
429 Accompany it with a written offer, valid for at least three
430 years, to give any third party, for a charge no more than your
431 cost of physically performing source distribution, a complete
432 machine-readable copy of the corresponding source code, to be
433 distributed under the terms of Sections 1 and 2 above on a medium
434 customarily used for software interchange; or,
436 @item
437 Accompany it with the information you received as to the offer
438 to distribute corresponding source code.  (This alternative is
439 allowed only for noncommercial distribution and only if you
440 received the program in object code or executable form with such
441 an offer, in accord with Subsection b above.)
442 @end enumerate
444 The source code for a work means the preferred form of the work for
445 making modifications to it.  For an executable work, complete source
446 code means all the source code for all modules it contains, plus any
447 associated interface definition files, plus the scripts used to
448 control compilation and installation of the executable.  However, as a
449 special exception, the source code distributed need not include
450 anything that is normally distributed (in either source or binary
451 form) with the major components (compiler, kernel, and so on) of the
452 operating system on which the executable runs, unless that component
453 itself accompanies the executable.
455 If distribution of executable or object code is made by offering
456 access to copy from a designated place, then offering equivalent
457 access to copy the source code from the same place counts as
458 distribution of the source code, even though third parties are not
459 compelled to copy the source along with the object code.
461 @item
462 You may not copy, modify, sublicense, or distribute the Program
463 except as expressly provided under this License.  Any attempt
464 otherwise to copy, modify, sublicense or distribute the Program is
465 void, and will automatically terminate your rights under this License.
466 However, parties who have received copies, or rights, from you under
467 this License will not have their licenses terminated so long as such
468 parties remain in full compliance.
470 @item
471 You are not required to accept this License, since you have not
472 signed it.  However, nothing else grants you permission to modify or
473 distribute the Program or its derivative works.  These actions are
474 prohibited by law if you do not accept this License.  Therefore, by
475 modifying or distributing the Program (or any work based on the
476 Program), you indicate your acceptance of this License to do so, and
477 all its terms and conditions for copying, distributing or modifying
478 the Program or works based on it.
480 @item
481 Each time you redistribute the Program (or any work based on the
482 Program), the recipient automatically receives a license from the
483 original licensor to copy, distribute or modify the Program subject to
484 these terms and conditions.  You may not impose any further
485 restrictions on the recipients' exercise of the rights granted herein.
486 You are not responsible for enforcing compliance by third parties to
487 this License.
489 @item
490 If, as a consequence of a court judgment or allegation of patent
491 infringement or for any other reason (not limited to patent issues),
492 conditions are imposed on you (whether by court order, agreement or
493 otherwise) that contradict the conditions of this License, they do not
494 excuse you from the conditions of this License.  If you cannot
495 distribute so as to satisfy simultaneously your obligations under this
496 License and any other pertinent obligations, then as a consequence you
497 may not distribute the Program at all.  For example, if a patent
498 license would not permit royalty-free redistribution of the Program by
499 all those who receive copies directly or indirectly through you, then
500 the only way you could satisfy both it and this License would be to
501 refrain entirely from distribution of the Program.
503 If any portion of this section is held invalid or unenforceable under
504 any particular circumstance, the balance of the section is intended to
505 apply and the section as a whole is intended to apply in other
506 circumstances.
508 It is not the purpose of this section to induce you to infringe any
509 patents or other property right claims or to contest validity of any
510 such claims; this section has the sole purpose of protecting the
511 integrity of the free software distribution system, which is
512 implemented by public license practices.  Many people have made
513 generous contributions to the wide range of software distributed
514 through that system in reliance on consistent application of that
515 system; it is up to the author/donor to decide if he or she is willing
516 to distribute software through any other system and a licensee cannot
517 impose that choice.
519 This section is intended to make thoroughly clear what is believed to
520 be a consequence of the rest of this License.
522 @item
523 If the distribution and/or use of the Program is restricted in
524 certain countries either by patents or by copyrighted interfaces, the
525 original copyright holder who places the Program under this License
526 may add an explicit geographical distribution limitation excluding
527 those countries, so that distribution is permitted only in or among
528 countries not thus excluded.  In such case, this License incorporates
529 the limitation as if written in the body of this License.
531 @item
532 The Free Software Foundation may publish revised and/or new versions
533 of the General Public License from time to time.  Such new versions will
534 be similar in spirit to the present version, but may differ in detail to
535 address new problems or concerns.
537 Each version is given a distinguishing version number.  If the Program
538 specifies a version number of this License which applies to it and ``any
539 later version'', you have the option of following the terms and conditions
540 either of that version or of any later version published by the Free
541 Software Foundation.  If the Program does not specify a version number of
542 this License, you may choose any version ever published by the Free Software
543 Foundation.
545 @item
546 If you wish to incorporate parts of the Program into other free
547 programs whose distribution conditions are different, write to the author
548 to ask for permission.  For software which is copyrighted by the Free
549 Software Foundation, write to the Free Software Foundation; we sometimes
550 make exceptions for this.  Our decision will be guided by the two goals
551 of preserving the free status of all derivatives of our free software and
552 of promoting the sharing and reuse of software generally.
554 @iftex
555 @heading NO WARRANTY
556 @end iftex
557 @ifinfo
558 @center NO WARRANTY
559 @end ifinfo
561 @item
562 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
563 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
564 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
565 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
566 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
567 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
568 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
569 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
570 REPAIR OR CORRECTION.
572 @item
573 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
574 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
575 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
576 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
577 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
578 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
579 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
580 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
581 POSSIBILITY OF SUCH DAMAGES.
582 @end enumerate
584 @iftex
585 @heading END OF TERMS AND CONDITIONS
586 @end iftex
587 @ifinfo
588 @center END OF TERMS AND CONDITIONS
589 @end ifinfo
591 @page
592 @unnumberedsec How to Apply These Terms to Your New Programs
594   If you develop a new program, and you want it to be of the greatest
595 possible use to the public, the best way to achieve this is to make it
596 free software which everyone can redistribute and change under these terms.
598   To do so, attach the following notices to the program.  It is safest
599 to attach them to the start of each source file to most effectively
600 convey the exclusion of warranty; and each file should have at least
601 the ``copyright'' line and a pointer to where the full notice is found.
603 @smallexample
604 @var{one line to give the program's name and a brief idea of what it does.}
605 Copyright (C) @var{year}  @var{name of author}
607 This program is free software; you can redistribute it and/or modify
608 it under the terms of the GNU General Public License as published by
609 the Free Software Foundation; either version 2 of the License, or
610 (at your option) any later version.
612 This program is distributed in the hope that it will be useful,
613 but WITHOUT ANY WARRANTY; without even the implied warranty of
614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
615 GNU General Public License for more details.
617 You should have received a copy of the GNU General Public License
618 along with this program; if not, write to the Free Software
619 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
620 @end smallexample
622 Also add information on how to contact you by electronic and paper mail.
624 If the program is interactive, make it output a short notice like this
625 when it starts in an interactive mode:
627 @smallexample
628 Gnomovision version 69, Copyright (C) @var{year} @var{name of author}
629 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
630 type `show w'.
631 This is free software, and you are welcome to redistribute it
632 under certain conditions; type `show c' for details.
633 @end smallexample
635 The hypothetical commands @samp{show w} and @samp{show c} should show
636 the appropriate parts of the General Public License.  Of course, the
637 commands you use may be called something other than @samp{show w} and
638 @samp{show c}; they could even be mouse-clicks or menu items---whatever
639 suits your program.
641 You should also get your employer (if you work as a programmer) or your
642 school, if any, to sign a ``copyright disclaimer'' for the program, if
643 necessary.  Here is a sample; alter the names:
645 @smallexample
646 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
647 `Gnomovision' (which makes passes at compilers) written by James Hacker.
649 @var{signature of Ty Coon}, 1 April 1989
650 Ty Coon, President of Vice
651 @end smallexample
653 This General Public License does not permit incorporating your program into
654 proprietary programs.  If your program is a subroutine library, you may
655 consider it more useful to permit linking proprietary applications with the
656 library.  If this is what you want to do, use the GNU Library General
657 Public License instead of this License.
659 @include fdl.texi
661 @node Contributors
662 @unnumbered Contributors to GNU Fortran
663 @cindex contributors
664 @cindex credits
666 In addition to James Craig Burley, who wrote the front end,
667 many people have helped create and improve GNU Fortran.
669 @itemize @bullet
670 @item
671 The packaging and compiler portions of GNU Fortran are based largely
672 on the GNU CC compiler.
673 @xref{Contributors,,Contributors to GNU CC,gcc,Using and Porting GNU CC},
674 for more information.
676 @item
677 The run-time library used by GNU Fortran is a repackaged version
678 of the @code{libf2c} library (combined from the @code{libF77} and
679 @code{libI77} libraries) provided as part of @code{f2c}, available for
680 free from @code{netlib} sites on the Internet.
682 @item
683 Cygnus Support and The Free Software Foundation contributed
684 significant money and/or equipment to Craig's efforts.
686 @item
687 The following individuals served as alpha testers prior to @code{g77}'s
688 public release.  This work consisted of testing, researching, sometimes
689 debugging, and occasionally providing small amounts of code and fixes
690 for @code{g77}, plus offering plenty of helpful advice to Craig:
692 @itemize @w{}
693 @item
694 Jonathan Corbet
695 @item
696 Dr.@: Mark Fernyhough
697 @item
698 Takafumi Hayashi (The University of Aizu)---@email{takafumi@@u-aizu.ac.jp}
699 @item
700 Kate Hedstrom
701 @item
702 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
703 @item
704 Dr.@: A. O. V. Le Blanc
705 @item
706 Dave Love
707 @item
708 Rick Lutowski
709 @item
710 Toon Moene
711 @item
712 Rick Niles
713 @item
714 Derk Reefman
715 @item
716 Wayne K. Schroll
717 @item
718 Bill Thorson
719 @item
720 Pedro A. M. Vazquez
721 @item
722 Ian Watson
723 @end itemize
725 @item
726 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
727 provided the patch to add rudimentary support
728 for @code{INTEGER*1}, @code{INTEGER*2}, and
729 @code{LOGICAL*1}.
730 This inspired Craig to add further support,
731 even though the resulting support
732 would still be incomplete, because version 0.6 is still
733 a ways off.
735 @item
736 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
737 and encouraged Craig to rewrite the documentation in texinfo
738 format by contributing a first pass at a translation of the
739 old @file{g77-0.5.16/f/DOC} file.
741 @item
742 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
743 some analysis of generated code as part of an overall project
744 to improve @code{g77} code generation to at least be as good
745 as @code{f2c} used in conjunction with @code{gcc}.
746 So far, this has resulted in the three, somewhat
747 experimental, options added by @code{g77} to the @code{gcc}
748 compiler and its back end.
750 (These, in turn, had made their way into the @code{egcs}
751 version of the compiler, and do not exist in @code{gcc}
752 version 2.8 or versions of @code{g77} based on that version
753 of @code{gcc}.)
755 @item
756 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
758 @item
759 Thanks to Mary Cortani and the staff at Craftwork Solutions
760 (@email{support@@craftwork.com}) for all of their support.
762 @item
763 Many other individuals have helped debug, test, and improve @code{g77}
764 over the past several years, and undoubtedly more people
765 will be doing so in the future.
766 If you have done so, and would like
767 to see your name listed in the above list, please ask!
768 The default is that people wish to remain anonymous.
769 @end itemize
771 @node Funding
772 @chapter Funding Free Software
774 If you want to have more free software a few years from now, it makes
775 sense for you to help encourage people to contribute funds for its
776 development.  The most effective approach known is to encourage
777 commercial redistributors to donate.
779 Users of free software systems can boost the pace of development by
780 encouraging for-a-fee distributors to donate part of their selling price
781 to free software developers---the Free Software Foundation, and others.
783 The way to convince distributors to do this is to demand it and expect
784 it from them.  So when you compare distributors, judge them partly by
785 how much they give to free software development.  Show distributors
786 they must compete to be the one who gives the most.
788 To make this approach work, you must insist on numbers that you can
789 compare, such as, ``We will donate ten dollars to the Frobnitz project
790 for each disk sold.''  Don't be satisfied with a vague promise, such as
791 ``A portion of the profits are donated,'' since it doesn't give a basis
792 for comparison.
794 Even a precise fraction ``of the profits from this disk'' is not very
795 meaningful, since creative accounting and unrelated business decisions
796 can greatly alter what fraction of the sales price counts as profit.
797 If the price you pay is $50, ten percent of the profit is probably
798 less than a dollar; it might be a few cents, or nothing at all.
800 Some redistributors do development work themselves.  This is useful too;
801 but to keep everyone honest, you need to inquire how much they do, and
802 what kind.  Some kinds of development make much more long-term
803 difference than others.  For example, maintaining a separate version of
804 a program contributes very little; maintaining the standard version of a
805 program for the whole community contributes much.  Easy new ports
806 contribute little, since someone else would surely do them; difficult
807 ports such as adding a new CPU to the GNU C compiler contribute more;
808 major new features or packages contribute the most.
810 By establishing the idea that supporting further development is ``the
811 proper thing to do'' when distributing free software for a fee, we can
812 assure a steady flow of resources into making more free software.
814 @display
815 Copyright (C) 1994 Free Software Foundation, Inc.
816 Verbatim copying and redistribution of this section is permitted
817 without royalty; alteration is not permitted.
818 @end display
820 @node Funding GNU Fortran
821 @chapter Funding GNU Fortran
822 @cindex funding improvements
823 @cindex improvements, funding
825 James Craig Burley (@email{@value{email-burley}}), the original author
826 of g77, stopped working on it in September 1999
827 (He has a web page at @uref{@value{www-burley}}.)
829 GNU Fortran is currently maintained by Toon Moene
830 (@email{toon@@moene.indiv.nluug.nl}), with the help of countless other
831 volunteers.
833 As with other GNU software, funding is important because it can pay for
834 needed equipment, personnel, and so on.
836 @cindex FSF, funding the
837 @cindex funding the FSF
838 The FSF provides information on the best way to fund ongoing
839 development of GNU software (such as GNU Fortran) in documents
840 such as the ``GNUS Bulletin''.
841 Email @email{gnu@@gnu.org} for information on funding the FSF.
843 Another important way to support work on GNU Fortran is to volunteer
844 to help out.
845 Work is needed on documentation, testing, porting
846 to various machines, and in some cases, coding (although major
847 changes planned for version 0.6 make it difficult to add manpower to this
848 area).
849 Email @email{@value{email-general}} to volunteer for this work.
851 @xref{Funding,,Funding Free Software}, for more information.
853 @node Look and Feel
854 @chapter Protect Your Freedom---Fight ``Look And Feel''
855 @c the above chapter heading overflows onto the next line. --mew 1/26/93
857 To preserve the ability to write free software, including replacements
858 for proprietary software, authors must be free to replicate the
859 user interface to which users of existing software have become
860 accustomed.
862 @xref{Look and Feel,,Protect Your Freedom---Fight ``Look And Feel'',
863 gcc,Using and Porting GNU CC}, for more information.
865 @node Getting Started
866 @chapter Getting Started
867 @cindex getting started
868 @cindex new users
869 @cindex newbies
870 @cindex beginners
872 If you don't need help getting started reading the portions
873 of this manual that are most important to you, you should skip
874 this portion of the manual.
876 If you are new to compilers, especially Fortran compilers, or
877 new to how compilers are structured under UNIX and UNIX-like
878 systems, you'll want to see @ref{What is GNU Fortran?}.
880 If you are new to GNU compilers, or have used only one GNU
881 compiler in the past and not had to delve into how it lets
882 you manage various versions and configurations of @code{gcc},
883 you should see @ref{G77 and GCC}.
885 Everyone except experienced @code{g77} users should
886 see @ref{Invoking G77}.
888 If you're acquainted with previous versions of @code{g77},
889 you should see @ref{News,,News About GNU Fortran}.
890 Further, if you've actually used previous versions of @code{g77},
891 especially if you've written or modified Fortran code to
892 be compiled by previous versions of @code{g77}, you
893 should see @ref{Changes}.
895 If you intend to write or otherwise compile code that is
896 not already strictly conforming ANSI FORTRAN 77---and this
897 is probably everyone---you should see @ref{Language}.
899 If you don't already have @code{g77} installed on your
900 system, you must see @ref{Installation}.
902 If you run into trouble getting Fortran code to compile,
903 link, run, or work properly, you might find answers
904 if you see @ref{Debugging and Interfacing},
905 see @ref{Collected Fortran Wisdom},
906 and see @ref{Trouble}.
907 You might also find that the problems you are encountering
908 are bugs in @code{g77}---see @ref{Bugs}, for information on
909 reporting them, after reading the other material.
911 If you need further help with @code{g77}, or with
912 freely redistributable software in general,
913 see @ref{Service}.
915 If you would like to help the @code{g77} project,
916 see @ref{Funding GNU Fortran}, for information on
917 helping financially, and see @ref{Projects}, for information
918 on helping in other ways.
920 If you're generally curious about the future of
921 @code{g77}, see @ref{Projects}.
922 If you're curious about its past,
923 see @ref{Contributors},
924 and see @ref{Funding GNU Fortran}.
926 To see a few of the questions maintainers of @code{g77} have,
927 and that you might be able to answer,
928 see @ref{Open Questions}.
930 @ifset USING
931 @node What is GNU Fortran?
932 @chapter What is GNU Fortran?
933 @cindex concepts, basic
934 @cindex basic concepts
936 GNU Fortran, or @code{g77}, is designed initially as a free replacement
937 for, or alternative to, the UNIX @code{f77} command.
938 (Similarly, @code{gcc} is designed as a replacement
939 for the UNIX @code{cc} command.)
941 @code{g77} also is designed to fit in well with the other
942 fine GNU compilers and tools.
944 Sometimes these design goals conflict---in such cases, resolution
945 often is made in favor of fitting in well with Project GNU.
946 These cases are usually identified in the appropriate
947 sections of this manual.
949 @cindex compilers
950 As compilers, @code{g77}, @code{gcc}, and @code{f77}
951 share the following characteristics:
953 @itemize @bullet
954 @cindex source code
955 @cindex file, source
956 @cindex code, source
957 @cindex source file
958 @item
959 They read a user's program, stored in a file and
960 containing instructions written in the appropriate
961 language (Fortran, C, and so on).
962 This file contains @dfn{source code}.
964 @cindex translation of user programs
965 @cindex machine code
966 @cindex code, machine
967 @cindex mistakes
968 @item
969 They translate the user's program into instructions
970 a computer can carry out more quickly than it takes
971 to translate the instructions in the first place.
972 These instructions are called @dfn{machine code}---code
973 designed to be efficiently translated and processed
974 by a machine such as a computer.
975 Humans usually aren't as good writing machine code
976 as they are at writing Fortran or C, because
977 it is easy to make tiny mistakes writing machine code.
978 When writing Fortran or C, it is easy
979 to make big mistakes.
981 @cindex debugger
982 @cindex bugs, finding
983 @cindex @code{gdb}, command
984 @cindex commands, @code{gdb}
985 @item
986 They provide information in the generated machine code
987 that can make it easier to find bugs in the program
988 (using a debugging tool, called a @dfn{debugger},
989 such as @code{gdb}).
991 @cindex libraries
992 @cindex linking
993 @cindex @code{ld} command
994 @cindex commands, @code{ld}
995 @item
996 They locate and gather machine code already generated
997 to perform actions requested by statements in
998 the user's program.
999 This machine code is organized
1000 into @dfn{libraries} and is located and gathered
1001 during the @dfn{link} phase of the compilation
1002 process.
1003 (Linking often is thought of as a separate
1004 step, because it can be directly invoked via the
1005 @code{ld} command.
1006 However, the @code{g77} and @code{gcc}
1007 commands, as with most compiler commands, automatically
1008 perform the linking step by calling on @code{ld}
1009 directly, unless asked to not do so by the user.)
1011 @cindex language, incorrect use of
1012 @cindex incorrect use of language
1013 @item
1014 They attempt to diagnose cases where the user's
1015 program contains incorrect usages of the language.
1016 The @dfn{diagnostics} produced by the compiler
1017 indicate the problem and the location in the user's
1018 source file where the problem was first noticed.
1019 The user can use this information to locate and
1020 fix the problem.
1021 @cindex diagnostics, incorrect
1022 @cindex incorrect diagnostics
1023 @cindex error messages, incorrect
1024 @cindex incorrect error messages
1025 (Sometimes an incorrect usage
1026 of the language leads to a situation where the
1027 compiler can no longer make any sense of what
1028 follows---while a human might be able to---and
1029 thus ends up complaining about many ``problems''
1030 it encounters that, in fact, stem from just one
1031 problem, usually the first one reported.)
1033 @cindex warnings
1034 @cindex questionable instructions
1035 @item
1036 They attempt to diagnose cases where the user's
1037 program contains a correct usage of the language,
1038 but instructs the computer to do something questionable.
1039 These diagnostics often are in the form of @dfn{warnings},
1040 instead of the @dfn{errors} that indicate incorrect
1041 usage of the language.
1042 @end itemize
1044 How these actions are performed is generally under the
1045 control of the user.
1046 Using command-line options, the user can specify
1047 how persnickety the compiler is to be regarding
1048 the program (whether to diagnose questionable usage
1049 of the language), how much time to spend making
1050 the generated machine code run faster, and so on.
1052 @cindex components of g77
1053 @cindex @code{g77}, components of
1054 @code{g77} consists of several components:
1056 @cindex @code{gcc}, command
1057 @cindex commands, @code{gcc}
1058 @itemize @bullet
1059 @item
1060 A modified version of the @code{gcc} command, which also might be
1061 installed as the system's @code{cc} command.
1062 (In many cases, @code{cc} refers to the
1063 system's ``native'' C compiler, which
1064 might be a non-GNU compiler, or an older version
1065 of @code{gcc} considered more stable or that is
1066 used to build the operating system kernel.)
1068 @cindex @code{g77}, command
1069 @cindex commands, @code{g77}
1070 @item
1071 The @code{g77} command itself, which also might be installed as the
1072 system's @code{f77} command.
1074 @cindex libg2c library
1075 @cindex libf2c library
1076 @cindex libraries, libf2c
1077 @cindex libraries, libg2c
1078 @cindex run-time, library
1079 @item
1080 The @code{libg2c} run-time library.
1081 This library contains the machine code needed to support
1082 capabilities of the Fortran language that are not directly
1083 provided by the machine code generated by the @code{g77}
1084 compilation phase.
1086 @code{libg2c} is just the unique name @code{g77} gives
1087 to its version of @code{libf2c} to distinguish it from
1088 any copy of @code{libf2c} installed from @code{f2c}
1089 (or versions of @code{g77} that built @code{libf2c} under
1090 that same name)
1091 on the system.
1093 The maintainer of @code{libf2c} currently is
1094 @email{dmg@@bell-labs.com}.
1096 @cindex @code{f771}, program
1097 @cindex programs, @code{f771}
1098 @cindex assembler
1099 @cindex @code{as} command
1100 @cindex commands, @code{as}
1101 @cindex assembly code
1102 @cindex code, assembly
1103 @item
1104 The compiler itself, internally named @code{f771}.
1106 Note that @code{f771} does not generate machine code directly---it
1107 generates @dfn{assembly code} that is a more readable form
1108 of machine code, leaving the conversion to actual machine code
1109 to an @dfn{assembler}, usually named @code{as}.
1110 @end itemize
1112 @code{gcc} is often thought of as ``the C compiler'' only,
1113 but it does more than that.
1114 Based on command-line options and the names given for files
1115 on the command line, @code{gcc} determines which actions to perform, including
1116 preprocessing, compiling (in a variety of possible languages), assembling,
1117 and linking.
1119 @cindex driver, gcc command as
1120 @cindex @code{gcc}, command as driver
1121 @cindex executable file
1122 @cindex files, executable
1123 @cindex cc1 program
1124 @cindex programs, cc1
1125 @cindex preprocessor
1126 @cindex cpp program
1127 @cindex programs, cpp
1128 For example, the command @samp{gcc foo.c} @dfn{drives} the file
1129 @file{foo.c} through the preprocessor @code{cpp}, then
1130 the C compiler (internally named
1131 @code{cc1}), then the assembler (usually @code{as}), then the linker
1132 (@code{ld}), producing an executable program named @file{a.out} (on
1133 UNIX systems).
1135 @cindex cc1plus program
1136 @cindex programs, cc1plus
1137 As another example, the command @samp{gcc foo.cc} would do much the same as
1138 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
1139 @code{gcc} would use the C++ compiler (named @code{cc1plus}).
1141 @cindex @code{f771}, program
1142 @cindex programs, @code{f771}
1143 In a GNU Fortran installation, @code{gcc} recognizes Fortran source
1144 files by name just like it does C and C++ source files.
1145 It knows to use the Fortran compiler named @code{f771}, instead of
1146 @code{cc1} or @code{cc1plus}, to compile Fortran files.
1148 @cindex @code{gcc}, not recognizing Fortran source
1149 @cindex unrecognized file format
1150 @cindex file format not recognized
1151 Non-Fortran-related operation of @code{gcc} is generally
1152 unaffected by installing the GNU Fortran version of @code{gcc}.
1153 However, without the installed version of @code{gcc} being the
1154 GNU Fortran version, @code{gcc} will not be able to compile
1155 and link Fortran programs---and since @code{g77} uses @code{gcc}
1156 to do most of the actual work, neither will @code{g77}!
1158 @cindex @code{g77}, command
1159 @cindex commands, @code{g77}
1160 The @code{g77} command is essentially just a front-end for
1161 the @code{gcc} command.
1162 Fortran users will normally use @code{g77} instead of @code{gcc},
1163 because @code{g77}
1164 knows how to specify the libraries needed to link with Fortran programs
1165 (@code{libg2c} and @code{lm}).
1166 @code{g77} can still compile and link programs and
1167 source files written in other languages, just like @code{gcc}.
1169 @cindex printing version information
1170 @cindex version information, printing
1171 The command @samp{g77 -v} is a quick
1172 way to display lots of version information for the various programs
1173 used to compile a typical preprocessed Fortran source file---this
1174 produces much more output than @samp{gcc -v} currently does.
1175 (If it produces an error message near the end of the output---diagnostics
1176 from the linker, usually @code{ld}---you might
1177 have an out-of-date @code{libf2c} that improperly handles
1178 complex arithmetic.)
1179 In the output of this command, the line beginning @samp{GNU Fortran Front
1180 End} identifies the version number of GNU Fortran; immediately
1181 preceding that line is a line identifying the version of @code{gcc}
1182 with which that version of @code{g77} was built.
1184 @cindex libf2c library
1185 @cindex libraries, libf2c
1186 The @code{libf2c} library is distributed with GNU Fortran for
1187 the convenience of its users, but is not part of GNU Fortran.
1188 It contains the procedures
1189 needed by Fortran programs while they are running.
1191 @cindex in-line code
1192 @cindex code, in-line
1193 For example, while code generated by @code{g77} is likely
1194 to do additions, subtractions, and multiplications @dfn{in line}---in
1195 the actual compiled code---it is not likely to do trigonometric
1196 functions this way.
1198 Instead, operations like trigonometric
1199 functions are compiled by the @code{f771} compiler
1200 (invoked by @code{g77} when compiling Fortran code) into machine
1201 code that, when run, calls on functions in @code{libg2c}, so
1202 @code{libg2c} must be linked with almost every useful program
1203 having any component compiled by GNU Fortran.
1204 (As mentioned above, the @code{g77} command takes
1205 care of all this for you.)
1207 The @code{f771} program represents most of what is unique to GNU Fortran.
1208 While much of the @code{libg2c} component comes from
1209 the @code{libf2c} component of @code{f2c},
1210 a free Fortran-to-C converter distributed by Bellcore (AT&T),
1211 plus @code{libU77}, provided by Dave Love,
1212 and the @code{g77} command is just a small front-end to @code{gcc},
1213 @code{f771} is a combination of two rather
1214 large chunks of code.
1216 @cindex GNU Back End (GBE)
1217 @cindex GBE
1218 @cindex @code{gcc}, back end
1219 @cindex back end, gcc
1220 @cindex code generator
1221 One chunk is the so-called @dfn{GNU Back End}, or GBE,
1222 which knows how to generate fast code for a wide variety of processors.
1223 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
1224 @code{cc1plus}, and @code{f771}, plus others.
1225 Often the GBE is referred to as the ``gcc back end'' or
1226 even just ``gcc''---in this manual, the term GBE is used
1227 whenever the distinction is important.
1229 @cindex GNU Fortran Front End (FFE)
1230 @cindex FFE
1231 @cindex @code{g77}, front end
1232 @cindex front end, @code{g77}
1233 The other chunk of @code{f771} is the
1234 majority of what is unique about GNU Fortran---the code that knows how
1235 to interpret Fortran programs to determine what they are intending to
1236 do, and then communicate that knowledge to the GBE for actual compilation
1237 of those programs.
1238 This chunk is called the @dfn{Fortran Front End} (FFE).
1239 The @code{cc1} and @code{cc1plus} programs have their own front ends,
1240 for the C and C++ languages, respectively.
1241 These fronts ends are responsible for diagnosing
1242 incorrect usage of their respective languages by the
1243 programs the process, and are responsible for most of
1244 the warnings about questionable constructs as well.
1245 (The GBE handles producing some warnings, like those
1246 concerning possible references to undefined variables.)
1248 Because so much is shared among the compilers for various languages,
1249 much of the behavior and many of the user-selectable options for these
1250 compilers are similar.
1251 For example, diagnostics (error messages and
1252 warnings) are similar in appearance; command-line
1253 options like @samp{-Wall} have generally similar effects; and the quality
1254 of generated code (in terms of speed and size) is roughly similar
1255 (since that work is done by the shared GBE).
1257 @node G77 and GCC
1258 @chapter Compile Fortran, C, or Other Programs
1259 @cindex compiling programs
1260 @cindex programs, compiling
1262 @cindex @code{gcc}, command
1263 @cindex commands, @code{gcc}
1264 A GNU Fortran installation includes a modified version of the @code{gcc}
1265 command.
1267 In a non-Fortran installation, @code{gcc} recognizes C, C++,
1268 and Objective-C source files.
1270 In a GNU Fortran installation, @code{gcc} also recognizes Fortran source
1271 files and accepts Fortran-specific command-line options, plus some
1272 command-line options that are designed to cater to Fortran users
1273 but apply to other languages as well.
1275 @xref{G++ and GCC,,Compile C; C++; or Objective-C,gcc,Using and Porting GNU CC},
1276 for information on the way different languages are handled
1277 by the GNU CC compiler (@code{gcc}).
1279 @cindex @code{g77}, command
1280 @cindex commands, @code{g77}
1281 Also provided as part of GNU Fortran is the @code{g77} command.
1282 The @code{g77} command is designed to make compiling and linking Fortran
1283 programs somewhat easier than when using the @code{gcc} command for
1284 these tasks.
1285 It does this by analyzing the command line somewhat and changing it
1286 appropriately before submitting it to the @code{gcc} command.
1288 @cindex -v option
1289 @cindex @code{g77} options, -v
1290 @cindex options, -v
1291 Use the @samp{-v} option with @code{g77}
1292 to see what is going on---the first line of output is the invocation
1293 of the @code{gcc} command.
1295 @node Invoking G77
1296 @chapter GNU Fortran Command Options
1297 @cindex GNU Fortran command options
1298 @cindex command options
1299 @cindex options, GNU Fortran command
1301 The @code{g77} command supports all the options supported by the
1302 @code{gcc} command.
1303 @xref{Invoking GCC,,GNU CC Command Options,gcc,Using and Porting GNU CC},
1304 for information
1305 on the non-Fortran-specific aspects of the @code{gcc} command (and,
1306 therefore, the @code{g77} command).
1308 @cindex options, negative forms
1309 @cindex negative forms of options
1310 All @code{gcc} and @code{g77} options
1311 are accepted both by @code{g77} and by @code{gcc}
1312 (as well as any other drivers built at the same time,
1313 such as @code{g++}),
1314 since adding @code{g77} to the @code{gcc} distribution
1315 enables acceptance of @code{g77}-specific options
1316 by all of the relevant drivers.
1318 In some cases, options have positive and negative forms;
1319 the negative form of @samp{-ffoo} would be @samp{-fno-foo}.
1320 This manual documents only one of these two forms, whichever
1321 one is not the default.
1323 @menu
1324 * Option Summary::      Brief list of all @code{g77} options,
1325                         without explanations.
1326 * Overall Options::     Controlling the kind of output:
1327                         an executable, object files, assembler files,
1328                         or preprocessed source.
1329 * Shorthand Options::   Options that are shorthand for other options.
1330 * Fortran Dialect Options::  Controlling the variant of Fortran language
1331                              compiled.
1332 * Warning Options::     How picky should the compiler be?
1333 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1334 * Optimize Options::    How much optimization?
1335 * Preprocessor Options:: Controlling header files and macro definitions.
1336                          Also, getting dependency information for Make.
1337 * Directory Options::   Where to find header files and libraries.
1338                         Where to find the compiler executable files.
1339 * Code Gen Options::    Specifying conventions for function calls, data layout
1340                         and register usage.
1341 * Environment Variables:: Env vars that affect GNU Fortran.
1342 @end menu
1344 @node Option Summary
1345 @section Option Summary
1347 Here is a summary of all the options specific to GNU Fortran, grouped
1348 by type.  Explanations are in the following sections.
1350 @table @emph
1351 @item Overall Options
1352 @xref{Overall Options,,Options Controlling the Kind of Output}.
1353 @smallexample
1354 -fversion  -fset-g77-defaults  -fno-silent
1355 @end smallexample
1357 @item Shorthand Options
1358 @xref{Shorthand Options}.
1359 @smallexample
1360 -ff66  -fno-f66  -ff77  -fno-f77  -fno-ugly
1361 @end smallexample
1363 @item Fortran Language Options
1364 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
1365 @smallexample
1366 -ffree-form  -fno-fixed-form  -ff90
1367 -fvxt  -fdollar-ok  -fno-backslash
1368 -fno-ugly-args  -fno-ugly-assign  -fno-ugly-assumed
1369 -fugly-comma  -fugly-complex  -fugly-init  -fugly-logint
1370 -fonetrip  -ftypeless-boz
1371 -fintrin-case-initcap  -fintrin-case-upper
1372 -fintrin-case-lower  -fintrin-case-any
1373 -fmatch-case-initcap  -fmatch-case-upper
1374 -fmatch-case-lower  -fmatch-case-any
1375 -fsource-case-upper -fsource-case-lower  -fsource-case-preserve
1376 -fsymbol-case-initcap  -fsymbol-case-upper
1377 -fsymbol-case-lower  -fsymbol-case-any
1378 -fcase-strict-upper  -fcase-strict-lower
1379 -fcase-initcap  -fcase-upper  -fcase-lower  -fcase-preserve
1380 -ff2c-intrinsics-delete  -ff2c-intrinsics-hide
1381 -ff2c-intrinsics-disable  -ff2c-intrinsics-enable
1382 -fbadu77-intrinsics-delete  -fbadu77-intrinsics-hide
1383 -fbadu77-intrinsics-disable  -fbadu77-intrinsics-enable
1384 -ff90-intrinsics-delete  -ff90-intrinsics-hide
1385 -ff90-intrinsics-disable  -ff90-intrinsics-enable
1386 -fgnu-intrinsics-delete  -fgnu-intrinsics-hide
1387 -fgnu-intrinsics-disable  -fgnu-intrinsics-enable
1388 -fmil-intrinsics-delete  -fmil-intrinsics-hide
1389 -fmil-intrinsics-disable  -fmil-intrinsics-enable
1390 -funix-intrinsics-delete  -funix-intrinsics-hide
1391 -funix-intrinsics-disable  -funix-intrinsics-enable
1392 -fvxt-intrinsics-delete  -fvxt-intrinsics-hide
1393 -fvxt-intrinsics-disable  -fvxt-intrinsics-enable
1394 -ffixed-line-length-@var{n}  -ffixed-line-length-none
1395 @end smallexample
1397 @item Warning Options
1398 @xref{Warning Options,,Options to Request or Suppress Warnings}.
1399 @smallexample
1400 -fsyntax-only  -pedantic  -pedantic-errors  -fpedantic
1401 -w  -Wno-globals  -Wimplicit -Wunused  -Wuninitialized
1402 -Wall  -Wsurprising
1403 -Werror  -W
1404 @end smallexample
1406 @item Debugging Options
1407 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
1408 @smallexample
1410 @end smallexample
1412 @item Optimization Options
1413 @xref{Optimize Options,,Options that Control Optimization}.
1414 @smallexample
1415 -malign-double
1416 -ffloat-store  -fforce-mem  -fforce-addr  -fno-inline
1417 -ffast-math  -fstrength-reduce  -frerun-cse-after-loop
1418 -funsafe-math-optimizations -fno-trapping-math
1419 -fexpensive-optimizations  -fdelayed-branch
1420 -fschedule-insns  -fschedule-insn2  -fcaller-saves
1421 -funroll-loops  -funroll-all-loops
1422 -fno-move-all-movables  -fno-reduce-all-givs
1423 -fno-rerun-loop-opt
1424 @end smallexample
1426 @item Directory Options
1427 @xref{Directory Options,,Options for Directory Search}.
1428 @smallexample
1429 -I@var{dir}  -I-
1430 @end smallexample
1432 @item Code Generation Options
1433 @xref{Code Gen Options,,Options for Code Generation Conventions}.
1434 @smallexample
1435 -fno-automatic  -finit-local-zero  -fno-f2c
1436 -ff2c-library  -fno-underscoring  -fno-ident
1437 -fpcc-struct-return  -freg-struct-return
1438 -fshort-double  -fno-common  -fpack-struct
1439 -fzeros  -fno-second-underscore
1440 -femulate-complex
1441 -falias-check  -fargument-alias
1442 -fargument-noalias  -fno-argument-noalias-global
1443 -fno-globals  -fflatten-arrays
1444 -fbounds-check  -ffortran-bounds-check
1445 @end smallexample
1446 @end table
1448 @menu
1449 * Overall Options::     Controlling the kind of output:
1450                         an executable, object files, assembler files,
1451                         or preprocessed source.
1452 * Shorthand Options::   Options that are shorthand for other options.
1453 * Fortran Dialect Options::  Controlling the variant of Fortran language
1454                              compiled.
1455 * Warning Options::     How picky should the compiler be?
1456 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1457 * Optimize Options::    How much optimization?
1458 * Preprocessor Options:: Controlling header files and macro definitions.
1459                          Also, getting dependency information for Make.
1460 * Directory Options::   Where to find header files and libraries.
1461                         Where to find the compiler executable files.
1462 * Code Gen Options::    Specifying conventions for function calls, data layout
1463                         and register usage.
1464 @end menu
1466 @node Overall Options
1467 @section Options Controlling the Kind of Output
1468 @cindex overall options
1469 @cindex options, overall
1471 Compilation can involve as many as four stages: preprocessing, code
1472 generation (often what is really meant by the term ``compilation''),
1473 assembly, and linking, always in that order.  The first three
1474 stages apply to an individual source file, and end by producing an
1475 object file; linking combines all the object files (those newly
1476 compiled, and those specified as input) into an executable file.
1478 @cindex file name suffix
1479 @cindex suffixes, file name
1480 @cindex file name extension
1481 @cindex extensions, file name
1482 @cindex file type
1483 @cindex types, file
1484 For any given input file, the file name suffix determines what kind of
1485 program is contained in the file---that is, the language in which the
1486 program is written is generally indicated by the suffix.
1487 Suffixes specific to GNU Fortran are listed below.
1488 @xref{Overall Options,,gcc,Using and Porting GNU CC}, for
1489 information on suffixes recognized by GNU CC.
1491 @table @code
1492 @cindex .f filename suffix
1493 @cindex .for filename suffix
1494 @cindex .FOR filename suffix
1495 @item @var{file}.f
1496 @item @var{file}.for
1497 @item @var{file}.FOR
1498 Fortran source code that should not be preprocessed.
1500 Such source code cannot contain any preprocessor directives, such
1501 as @code{#include}, @code{#define}, @code{#if}, and so on.
1503 You can force @samp{.f} files to be preprocessed by @code{cpp} by using
1504 @samp{-x f77-cpp-input}.
1505 @xref{LEX}.
1507 @cindex preprocessor
1508 @cindex C preprocessor
1509 @cindex cpp preprocessor
1510 @cindex Fortran preprocessor
1511 @cindex cpp program
1512 @cindex programs, cpp
1513 @cindex .F filename suffix
1514 @cindex .fpp filename suffix
1515 @cindex .FPP filename suffix
1516 @item @var{file}.F
1517 @item @var{file}.fpp
1518 @item @var{file}.FPP
1519 Fortran source code that must be preprocessed (by the C preprocessor
1520 @code{cpp}, which is part of GNU CC).
1522 Note that preprocessing is not extended to the contents of
1523 files included by the @code{INCLUDE} directive---the @code{#include}
1524 preprocessor directive must be used instead.
1526 @cindex Ratfor preprocessor
1527 @cindex programs, @code{ratfor}
1528 @cindex @samp{.r} filename suffix
1529 @cindex @code{ratfor}
1530 @item @var{file}.r
1531 Ratfor source code, which must be preprocessed by the @code{ratfor}
1532 command, which is available separately (as it is not yet part of the GNU
1533 Fortran distribution).
1534 One version in Fortran, adapted for use with @code{g77}, is at
1535 @uref{ftp://members.aol.com/n8tm/rat7.uue} (of uncertain copyright
1536 status).  Another, public domain version in C is at
1537 @uref{http://sepwww.stanford.edu/sep/prof/ratfor.shar.2}.
1538 @end table
1540 UNIX users typically use the @file{@var{file}.f} and @file{@var{file}.F}
1541 nomenclature.
1542 Users of other operating systems, especially those that cannot
1543 distinguish upper-case
1544 letters from lower-case letters in their file names, typically use
1545 the @file{@var{file}.for} and @file{@var{file}.fpp} nomenclature.
1547 @cindex #define
1548 @cindex #include
1549 @cindex #if
1550 Use of the preprocessor @code{cpp} allows use of C-like
1551 constructs such as @code{#define} and @code{#include}, but can
1552 lead to unexpected, even mistaken, results due to Fortran's source file
1553 format.
1554 It is recommended that use of the C preprocessor
1555 be limited to @code{#include} and, in
1556 conjunction with @code{#define}, only @code{#if} and related directives,
1557 thus avoiding in-line macro expansion entirely.
1558 This recommendation applies especially
1559 when using the traditional fixed source form.
1560 With free source form,
1561 fewer unexpected transformations are likely to happen, but use of
1562 constructs such as Hollerith and character constants can nevertheless
1563 present problems, especially when these are continued across multiple
1564 source lines.
1565 These problems result, primarily, from differences between the way
1566 such constants are interpreted by the C preprocessor and by a Fortran
1567 compiler.
1569 Another example of a problem that results from using the C preprocessor
1570 is that a Fortran comment line that happens to contain any
1571 characters ``interesting'' to the C preprocessor,
1572 such as a backslash at the end of the line,
1573 is not recognized by the preprocessor as a comment line,
1574 so instead of being passed through ``raw'',
1575 the line is edited according to the rules for the preprocessor.
1576 For example, the backslash at the end of the line is removed,
1577 along with the subsequent newline, resulting in the next
1578 line being effectively commented out---unfortunate if that
1579 line is a non-comment line of important code!
1581 @emph{Note:} The @samp{-traditional} and @samp{-undef} flags are supplied
1582 to @code{cpp} by default, to help avoid unpleasant surprises.
1583 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
1584 gcc,Using and Porting GNU CC}.
1585 This means that ANSI C preprocessor features (such as the @samp{#}
1586 operator) aren't available, and only variables in the C reserved
1587 namespace (generally, names with a leading underscore) are liable to
1588 substitution by C predefines.
1589 Thus, if you want to do system-specific
1590 tests, use, for example, @samp{#ifdef __linux__} rather than @samp{#ifdef linux}.
1591 Use the @samp{-v} option to see exactly how the preprocessor is invoked.
1593 @cindex /*
1594 Unfortunately, the @samp{-traditional} flag will not avoid an error from
1595 anything that @code{cpp} sees as an unterminated C comment, such as:
1596 @smallexample
1597 C Some Fortran compilers accept /* as starting
1598 C an inline comment.
1599 @end smallexample
1600 @xref{Trailing Comment}.
1602 The following options that affect overall processing are recognized
1603 by the @code{g77} and @code{gcc} commands in a GNU Fortran installation:
1605 @table @code
1606 @cindex -fversion option
1607 @cindex options, -fversion
1608 @cindex printing version information
1609 @cindex version information, printing
1610 @cindex consistency checks
1611 @cindex internal consistency checks
1612 @cindex checks, of internal consistency
1613 @item -fversion
1614 Ensure that the @code{g77}-specific version of the compiler phase is reported,
1615 if run,
1616 and, starting in @code{egcs} version 1.1,
1617 that internal consistency checks in the @file{f771} program are run.
1619 This option is supplied automatically when @samp{-v} or @samp{--verbose}
1620 is specified as a command-line option for @code{g77} or @code{gcc}
1621 and when the resulting commands compile Fortran source files.
1623 @cindex -fset-g77-defaults option
1624 @cindex options, -fset-g77-defaults
1625 @item -fset-g77-defaults
1626 @emph{Version info:}
1627 This option was obsolete as of @code{egcs}
1628 version 1.1.
1629 The effect is instead achieved
1630 by the @code{lang_init_options} routine
1631 in @file{gcc/gcc/f/com.c}.
1633 @cindex consistency checks
1634 @cindex internal consistency checks
1635 @cindex checks, of internal consistency
1636 Set up whatever @code{gcc} options are to apply to Fortran
1637 compilations, and avoid running internal consistency checks
1638 that might take some time.
1640 This option is supplied automatically when compiling Fortran code
1641 via the @code{g77} or @code{gcc} command.
1642 The description of this option is provided so that users seeing
1643 it in the output of, say, @samp{g77 -v} understand why it is
1644 there.
1646 @cindex modifying g77
1647 @cindex code, modifying
1648 Also, developers who run @code{f771} directly might want to specify it
1649 by hand to get the same defaults as they would running @code{f771}
1650 via @code{g77} or @code{gcc}.
1651 However, such developers should, after linking a new @code{f771}
1652 executable, invoke it without this option once,
1653 e.g. via @kbd{./f771 -quiet < /dev/null},
1654 to ensure that they have not introduced any
1655 internal inconsistencies (such as in the table of
1656 intrinsics) before proceeding---@code{g77} will crash
1657 with a diagnostic if it detects an inconsistency.
1659 @cindex -fno-silent option
1660 @cindex options, -fno-silent
1661 @cindex f2c compatibility
1662 @cindex compatibility, f2c
1663 @cindex status, compilation
1664 @cindex compilation, status
1665 @cindex reporting compilation status
1666 @cindex printing compilation status
1667 @item -fno-silent
1668 Print (to @code{stderr}) the names of the program units as
1669 they are compiled, in a form similar to that used by popular
1670 UNIX @code{f77} implementations and @code{f2c}.
1671 @end table
1673 @xref{Overall Options,,Options Controlling the Kind of Output,
1674 gcc,Using and Porting GNU CC}, for information
1675 on more options that control the overall operation of the @code{gcc} command
1676 (and, by extension, the @code{g77} command).
1678 @node Shorthand Options
1679 @section Shorthand Options
1680 @cindex shorthand options
1681 @cindex options, shorthand
1682 @cindex macro options
1683 @cindex options, macro
1685 The following options serve as ``shorthand''
1686 for other options accepted by the compiler:
1688 @table @code
1689 @cindex -fugly option
1690 @cindex options, -fugly
1691 @item -fugly
1692 @cindex ugly features
1693 @cindex features, ugly
1694 @emph{Note:} This option is no longer supported.
1695 The information, below, is provided to aid
1696 in the conversion of old scripts.
1698 Specify that certain ``ugly'' constructs are to be quietly accepted.
1699 Same as:
1701 @smallexample
1702 -fugly-args -fugly-assign -fugly-assumed
1703 -fugly-comma -fugly-complex -fugly-init
1704 -fugly-logint
1705 @end smallexample
1707 These constructs are considered inappropriate to use in new
1708 or well-maintained portable Fortran code, but widely used
1709 in old code.
1710 @xref{Distensions}, for more information.
1712 @cindex -fno-ugly option
1713 @cindex options, -fno-ugly
1714 @item -fno-ugly
1715 @cindex ugly features
1716 @cindex features, ugly
1717 Specify that all ``ugly'' constructs are to be noisily rejected.
1718 Same as:
1720 @smallexample
1721 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1722 -fno-ugly-comma -fno-ugly-complex -fno-ugly-init
1723 -fno-ugly-logint
1724 @end smallexample
1726 @xref{Distensions}, for more information.
1728 @cindex -ff66 option
1729 @cindex options, -ff66
1730 @item -ff66
1731 @cindex FORTRAN 66
1732 @cindex compatibility, FORTRAN 66
1733 Specify that the program is written in idiomatic FORTRAN 66.
1734 Same as @samp{-fonetrip -fugly-assumed}.
1736 The @samp{-fno-f66} option is the inverse of @samp{-ff66}.
1737 As such, it is the same as @samp{-fno-onetrip -fno-ugly-assumed}.
1739 The meaning of this option is likely to be refined as future
1740 versions of @code{g77} provide more compatibility with other
1741 existing and obsolete Fortran implementations.
1743 @cindex -ff77 option
1744 @cindex options, -ff77
1745 @item -ff77
1746 @cindex UNIX f77
1747 @cindex f2c compatibility
1748 @cindex compatibility, f2c
1749 @cindex f77 compatibility
1750 @cindex compatibility, f77
1751 Specify that the program is written in idiomatic UNIX FORTRAN 77
1752 and/or the dialect accepted by the @code{f2c} product.
1753 Same as @samp{-fbackslash -fno-typeless-boz}.
1755 The meaning of this option is likely to be refined as future
1756 versions of @code{g77} provide more compatibility with other
1757 existing and obsolete Fortran implementations.
1759 @cindex -fno-f77 option
1760 @cindex options, -fno-f77
1761 @item -fno-f77
1762 @cindex UNIX f77
1763 The @samp{-fno-f77} option is @emph{not} the inverse
1764 of @samp{-ff77}.
1765 It specifies that the program is not written in idiomatic UNIX
1766 FORTRAN 77 or @code{f2c}, but in a more widely portable dialect.
1767 @samp{-fno-f77} is the same as @samp{-fno-backslash}.
1769 The meaning of this option is likely to be refined as future
1770 versions of @code{g77} provide more compatibility with other
1771 existing and obsolete Fortran implementations.
1772 @end table
1774 @node Fortran Dialect Options
1775 @section Options Controlling Fortran Dialect
1776 @cindex dialect options
1777 @cindex language, dialect options
1778 @cindex options, dialect
1780 The following options control the dialect of Fortran
1781 that the compiler accepts:
1783 @table @code
1784 @cindex -ffree-form option
1785 @cindex options, -ffree-form
1786 @cindex -fno-fixed-form option
1787 @cindex options, -fno-fixed-form
1788 @cindex source file format
1789 @cindex free form
1790 @cindex fixed form
1791 @cindex Fortran 90, features
1792 @item -ffree-form
1793 @item -fno-fixed-form
1794 Specify that the source file is written in free form
1795 (introduced in Fortran 90) instead of the more-traditional fixed form.
1797 @cindex -ff90 option
1798 @cindex options, -ff90
1799 @cindex Fortran 90, features
1800 @item -ff90
1801 Allow certain Fortran-90 constructs.
1803 This option controls whether certain
1804 Fortran 90 constructs are recognized.
1805 (Other Fortran 90 constructs
1806 might or might not be recognized depending on other options such as
1807 @samp{-fvxt}, @samp{-ff90-intrinsics-enable}, and the
1808 current level of support for Fortran 90.)
1810 @xref{Fortran 90}, for more information.
1812 @cindex -fvxt option
1813 @cindex options, -fvxt
1814 @item -fvxt
1815 @cindex Fortran 90, features
1816 @cindex VXT extensions
1817 Specify the treatment of certain constructs that have different
1818 meanings depending on whether the code is written in
1819 GNU Fortran (based on FORTRAN 77 and akin to Fortran 90)
1820 or VXT Fortran (more like VAX FORTRAN).
1822 The default is @samp{-fno-vxt}.
1823 @samp{-fvxt} specifies that the VXT Fortran interpretations
1824 for those constructs are to be chosen.
1826 @xref{VXT Fortran}, for more information.
1828 @cindex -fdollar-ok option
1829 @cindex options, -fdollar-ok
1830 @item -fdollar-ok
1831 @cindex dollar sign
1832 @cindex symbol names
1833 @cindex character set
1834 Allow @samp{$} as a valid character in a symbol name.
1836 @cindex -fno-backslash option
1837 @cindex options, -fno-backslash
1838 @item -fno-backslash
1839 @cindex backslash
1840 @cindex character constants
1841 @cindex Hollerith constants
1842 Specify that @samp{\} is not to be specially interpreted in character
1843 and Hollerith constants a la C and many UNIX Fortran compilers.
1845 For example, with @samp{-fbackslash} in effect, @samp{A\nB} specifies
1846 three characters, with the second one being newline.
1847 With @samp{-fno-backslash}, it specifies four characters,
1848 @samp{A}, @samp{\}, @samp{n}, and @samp{B}.
1850 Note that @code{g77} implements a fairly general form of backslash
1851 processing that is incompatible with the narrower forms supported
1852 by some other compilers.
1853 For example, @samp{'A\003B'} is a three-character string in @code{g77},
1854 whereas other compilers that support backslash might not support
1855 the three-octal-digit form, and thus treat that string as longer
1856 than three characters.
1858 @xref{Backslash in Constants}, for
1859 information on why @samp{-fbackslash} is the default
1860 instead of @samp{-fno-backslash}.
1862 @cindex -fno-ugly-args option
1863 @cindex options, -fno-ugly-args
1864 @item -fno-ugly-args
1865 Disallow passing Hollerith and typeless constants as actual
1866 arguments (for example, @samp{CALL FOO(4HABCD)}).
1868 @xref{Ugly Implicit Argument Conversion}, for more information.
1870 @cindex -fugly-assign option
1871 @cindex options, -fugly-assign
1872 @item -fugly-assign
1873 Use the same storage for a given variable regardless of
1874 whether it is used to hold an assigned-statement label
1875 (as in @samp{ASSIGN 10 TO I}) or used to hold numeric data
1876 (as in @samp{I = 3}).
1878 @xref{Ugly Assigned Labels}, for more information.
1880 @cindex -fugly-assumed option
1881 @cindex options, -fugly-assumed
1882 @item -fugly-assumed
1883 Assume any dummy array with a final dimension specified as @samp{1}
1884 is really an assumed-size array, as if @samp{*} had been specified
1885 for the final dimension instead of @samp{1}.
1887 For example, @samp{DIMENSION X(1)} is treated as if it
1888 had read @samp{DIMENSION X(*)}.
1890 @xref{Ugly Assumed-Size Arrays}, for more information.
1892 @cindex -fugly-comma option
1893 @cindex options, -fugly-comma
1894 @item -fugly-comma
1895 In an external-procedure invocation,
1896 treat a trailing comma in the argument list
1897 as specification of a trailing null argument,
1898 and treat an empty argument list
1899 as specification of a single null argument.
1901 For example, @samp{CALL FOO(,)} is treated as
1902 @samp{CALL FOO(%VAL(0), %VAL(0))}.
1903 That is, @emph{two} null arguments are specified
1904 by the procedure call when @samp{-fugly-comma} is in force.
1905 And @samp{F = FUNC()} is treated as @samp{F = FUNC(%VAL(0))}.
1907 The default behavior, @samp{-fno-ugly-comma}, is to ignore
1908 a single trailing comma in an argument list.
1909 So, by default, @samp{CALL FOO(X,)} is treated
1910 exactly the same as @samp{CALL FOO(X)}.
1912 @xref{Ugly Null Arguments}, for more information.
1914 @cindex -fugly-complex option
1915 @cindex options, -fugly-complex
1916 @item -fugly-complex
1917 Do not complain about @samp{REAL(@var{expr})} or
1918 @samp{AIMAG(@var{expr})} when @var{expr} is a @code{COMPLEX}
1919 type other than @code{COMPLEX(KIND=1)}---usually
1920 this is used to permit @code{COMPLEX(KIND=2)}
1921 (@code{DOUBLE COMPLEX}) operands.
1923 The @samp{-ff90} option controls the interpretation
1924 of this construct.
1926 @xref{Ugly Complex Part Extraction}, for more information.
1928 @cindex -fno-ugly-init option
1929 @cindex options, -fno-ugly-init
1930 @item -fno-ugly-init
1931 Disallow use of Hollerith and typeless constants as initial
1932 values (in @code{PARAMETER} and @code{DATA} statements), and
1933 use of character constants to
1934 initialize numeric types and vice versa.
1936 For example, @samp{DATA I/'F'/, CHRVAR/65/, J/4HABCD/} is disallowed by
1937 @samp{-fno-ugly-init}.
1939 @xref{Ugly Conversion of Initializers}, for more information.
1941 @cindex -fugly-logint option
1942 @cindex options, -fugly-logint
1943 @item -fugly-logint
1944 Treat @code{INTEGER} and @code{LOGICAL} variables and
1945 expressions as potential stand-ins for each other.
1947 For example, automatic conversion between @code{INTEGER} and
1948 @code{LOGICAL} is enabled, for many contexts, via this option.
1950 @xref{Ugly Integer Conversions}, for more information.
1952 @cindex -fonetrip option
1953 @cindex options, -fonetrip
1954 @item -fonetrip
1955 @cindex FORTRAN 66
1956 @cindex @code{DO} loops, one-trip
1957 @cindex one-trip @code{DO} loops
1958 @cindex @code{DO} loops, zero-trip
1959 @cindex zero-trip @code{DO} loops
1960 @cindex compatibility, FORTRAN 66
1961 Executable iterative @code{DO} loops are to be executed at
1962 least once each time they are reached.
1964 ANSI FORTRAN 77 and more recent versions of the Fortran standard
1965 specify that the body of an iterative @code{DO} loop is not executed
1966 if the number of iterations calculated from the parameters of the
1967 loop is less than 1.
1968 (For example, @samp{DO 10 I = 1, 0}.)
1969 Such a loop is called a @dfn{zero-trip loop}.
1971 Prior to ANSI FORTRAN 77, many compilers implemented @code{DO} loops
1972 such that the body of a loop would be executed at least once, even
1973 if the iteration count was zero.
1974 Fortran code written assuming this behavior is said to require
1975 @dfn{one-trip loops}.
1976 For example, some code written to the FORTRAN 66 standard
1977 expects this behavior from its @code{DO} loops, although that
1978 standard did not specify this behavior.
1980 The @samp{-fonetrip} option specifies that the source file(s) being
1981 compiled require one-trip loops.
1983 This option affects only those loops specified by the (iterative) @code{DO}
1984 statement and by implied-@code{DO} lists in I/O statements.
1985 Loops specified by implied-@code{DO} lists in @code{DATA} and
1986 specification (non-executable) statements are not affected.
1988 @cindex -ftypeless-boz option
1989 @cindex options, -ftypeless-boz
1990 @cindex prefix-radix constants
1991 @cindex constants, prefix-radix
1992 @cindex constants, types
1993 @cindex types, constants
1994 @item -ftypeless-boz
1995 Specifies that prefix-radix non-decimal constants, such as
1996 @samp{Z'ABCD'}, are typeless instead of @code{INTEGER(KIND=1)}.
1998 You can test for yourself whether a particular compiler treats
1999 the prefix form as @code{INTEGER(KIND=1)} or typeless by running the
2000 following program:
2002 @smallexample
2003 EQUIVALENCE (I, R)
2004 R = Z'ABCD1234'
2005 J = Z'ABCD1234'
2006 IF (J .EQ. I) PRINT *, 'Prefix form is TYPELESS'
2007 IF (J .NE. I) PRINT *, 'Prefix form is INTEGER'
2009 @end smallexample
2011 Reports indicate that many compilers process this form as
2012 @code{INTEGER(KIND=1)}, though a few as typeless, and at least one
2013 based on a command-line option specifying some kind of
2014 compatibility.
2016 @cindex -fintrin-case-initcap option
2017 @cindex options, -fintrin-case-initcap
2018 @item -fintrin-case-initcap
2019 @cindex -fintrin-case-upper option
2020 @cindex options, -fintrin-case-upper
2021 @item -fintrin-case-upper
2022 @cindex -fintrin-case-lower option
2023 @cindex options, -fintrin-case-lower
2024 @item -fintrin-case-lower
2025 @cindex -fintrin-case-any option
2026 @cindex options, -fintrin-case-any
2027 @item -fintrin-case-any
2028 Specify expected case for intrinsic names.
2029 @samp{-fintrin-case-lower} is the default.
2031 @cindex -fmatch-case-initcap option
2032 @cindex options, -fmatch-case-initcap
2033 @item -fmatch-case-initcap
2034 @cindex -fmatch-case-upper option
2035 @cindex options, -fmatch-case-upper
2036 @item -fmatch-case-upper
2037 @cindex -fmatch-case-lower option
2038 @cindex options, -fmatch-case-lower
2039 @item -fmatch-case-lower
2040 @cindex -fmatch-case-any option
2041 @cindex options, -fmatch-case-any
2042 @item -fmatch-case-any
2043 Specify expected case for keywords.
2044 @samp{-fmatch-case-lower} is the default.
2046 @cindex -fsource-case-upper option
2047 @cindex options, -fsource-case-upper
2048 @item -fsource-case-upper
2049 @cindex -fsource-case-lower option
2050 @cindex options, -fsource-case-lower
2051 @item -fsource-case-lower
2052 @cindex -fsource-case-preserve option
2053 @cindex options, -fsource-case-preserve
2054 @item -fsource-case-preserve
2055 Specify whether source text other than character and Hollerith constants
2056 is to be translated to uppercase, to lowercase, or preserved as is.
2057 @samp{-fsource-case-lower} is the default.
2059 @cindex -fsymbol-case-initcap option
2060 @cindex options, -fsymbol-case-initcap
2061 @item -fsymbol-case-initcap
2062 @cindex -fsymbol-case-upper option
2063 @cindex options, -fsymbol-case-upper
2064 @item -fsymbol-case-upper
2065 @cindex -fsymbol-case-lower option
2066 @cindex options, -fsymbol-case-lower
2067 @item -fsymbol-case-lower
2068 @cindex -fsymbol-case-any option
2069 @cindex options, -fsymbol-case-any
2070 @item -fsymbol-case-any
2071 Specify valid cases for user-defined symbol names.
2072 @samp{-fsymbol-case-any} is the default.
2074 @cindex -fcase-strict-upper option
2075 @cindex options, -fcase-strict-upper
2076 @item -fcase-strict-upper
2077 Same as @samp{-fintrin-case-upper -fmatch-case-upper -fsource-case-preserve
2078 -fsymbol-case-upper}.
2079 (Requires all pertinent source to be in uppercase.)
2081 @cindex -fcase-strict-lower option
2082 @cindex options, -fcase-strict-lower
2083 @item -fcase-strict-lower
2084 Same as @samp{-fintrin-case-lower -fmatch-case-lower -fsource-case-preserve
2085 -fsymbol-case-lower}.
2086 (Requires all pertinent source to be in lowercase.)
2088 @cindex -fcase-initcap option
2089 @cindex options, -fcase-initcap
2090 @item -fcase-initcap
2091 Same as @samp{-fintrin-case-initcap -fmatch-case-initcap -fsource-case-preserve
2092 -fsymbol-case-initcap}.
2093 (Requires all pertinent source to be in initial capitals,
2094 as in @samp{Print *,SqRt(Value)}.)
2096 @cindex -fcase-upper option
2097 @cindex options, -fcase-upper
2098 @item -fcase-upper
2099 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-upper
2100 -fsymbol-case-any}.
2101 (Maps all pertinent source to uppercase.)
2103 @cindex -fcase-lower option
2104 @cindex options, -fcase-lower
2105 @item -fcase-lower
2106 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-lower
2107 -fsymbol-case-any}.
2108 (Maps all pertinent source to lowercase.)
2110 @cindex -fcase-preserve option
2111 @cindex options, -fcase-preserve
2112 @item -fcase-preserve
2113 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-preserve
2114 -fsymbol-case-any}.
2115 (Preserves all case in user-defined symbols,
2116 while allowing any-case matching of intrinsics and keywords.
2117 For example, @samp{call Foo(i,I)} would pass two @emph{different}
2118 variables named @samp{i} and @samp{I} to a procedure named @samp{Foo}.)
2120 @cindex -fbadu77-intrinsics-delete option
2121 @cindex options, -fbadu77-intrinsics-delete
2122 @item -fbadu77-intrinsics-delete
2123 @cindex -fbadu77-intrinsics-hide option
2124 @cindex options, -fbadu77-intrinsics-hide
2125 @item -fbadu77-intrinsics-hide
2126 @cindex -fbadu77-intrinsics-disable option
2127 @cindex options, -fbadu77-intrinsics-disable
2128 @item -fbadu77-intrinsics-disable
2129 @cindex -fbadu77-intrinsics-enable option
2130 @cindex options, -fbadu77-intrinsics-enable
2131 @item -fbadu77-intrinsics-enable
2132 @cindex @code{badu77} intrinsics
2133 @cindex intrinsics, @code{badu77}
2134 Specify status of UNIX intrinsics having inappropriate forms.
2135 @samp{-fbadu77-intrinsics-enable} is the default.
2136 @xref{Intrinsic Groups}.
2138 @cindex -ff2c-intrinsics-delete option
2139 @cindex options, -ff2c-intrinsics-delete
2140 @item -ff2c-intrinsics-delete
2141 @cindex -ff2c-intrinsics-hide option
2142 @cindex options, -ff2c-intrinsics-hide
2143 @item -ff2c-intrinsics-hide
2144 @cindex -ff2c-intrinsics-disable option
2145 @cindex options, -ff2c-intrinsics-disable
2146 @item -ff2c-intrinsics-disable
2147 @cindex -ff2c-intrinsics-enable option
2148 @cindex options, -ff2c-intrinsics-enable
2149 @item -ff2c-intrinsics-enable
2150 @cindex @code{f2c} intrinsics
2151 @cindex intrinsics, @code{f2c}
2152 Specify status of f2c-specific intrinsics.
2153 @samp{-ff2c-intrinsics-enable} is the default.
2154 @xref{Intrinsic Groups}.
2156 @cindex -ff90-intrinsics-delete option
2157 @cindex options, -ff90-intrinsics-delete
2158 @item -ff90-intrinsics-delete
2159 @cindex -ff90-intrinsics-hide option
2160 @cindex options, -ff90-intrinsics-hide
2161 @item -ff90-intrinsics-hide
2162 @cindex -ff90-intrinsics-disable option
2163 @cindex options, -ff90-intrinsics-disable
2164 @item -ff90-intrinsics-disable
2165 @cindex -ff90-intrinsics-enable option
2166 @cindex options, -ff90-intrinsics-enable
2167 @item -ff90-intrinsics-enable
2168 @cindex Fortran 90, intrinsics
2169 @cindex intrinsics, Fortran 90
2170 Specify status of F90-specific intrinsics.
2171 @samp{-ff90-intrinsics-enable} is the default.
2172 @xref{Intrinsic Groups}.
2174 @cindex -fgnu-intrinsics-delete option
2175 @cindex options, -fgnu-intrinsics-delete
2176 @item -fgnu-intrinsics-delete
2177 @cindex -fgnu-intrinsics-hide option
2178 @cindex options, -fgnu-intrinsics-hide
2179 @item -fgnu-intrinsics-hide
2180 @cindex -fgnu-intrinsics-disable option
2181 @cindex options, -fgnu-intrinsics-disable
2182 @item -fgnu-intrinsics-disable
2183 @cindex -fgnu-intrinsics-enable option
2184 @cindex options, -fgnu-intrinsics-enable
2185 @item -fgnu-intrinsics-enable
2186 @cindex Digital Fortran features
2187 @cindex @code{COMPLEX} intrinsics
2188 @cindex intrinsics, @code{COMPLEX}
2189 Specify status of Digital's COMPLEX-related intrinsics.
2190 @samp{-fgnu-intrinsics-enable} is the default.
2191 @xref{Intrinsic Groups}.
2193 @cindex -fmil-intrinsics-delete option
2194 @cindex options, -fmil-intrinsics-delete
2195 @item -fmil-intrinsics-delete
2196 @cindex -fmil-intrinsics-hide option
2197 @cindex options, -fmil-intrinsics-hide
2198 @item -fmil-intrinsics-hide
2199 @cindex -fmil-intrinsics-disable option
2200 @cindex options, -fmil-intrinsics-disable
2201 @item -fmil-intrinsics-disable
2202 @cindex -fmil-intrinsics-enable option
2203 @cindex options, -fmil-intrinsics-enable
2204 @item -fmil-intrinsics-enable
2205 @cindex MIL-STD 1753
2206 @cindex intrinsics, MIL-STD 1753
2207 Specify status of MIL-STD-1753-specific intrinsics.
2208 @samp{-fmil-intrinsics-enable} is the default.
2209 @xref{Intrinsic Groups}.
2211 @cindex -funix-intrinsics-delete option
2212 @cindex options, -funix-intrinsics-delete
2213 @item -funix-intrinsics-delete
2214 @cindex -funix-intrinsics-hide option
2215 @cindex options, -funix-intrinsics-hide
2216 @item -funix-intrinsics-hide
2217 @cindex -funix-intrinsics-disable option
2218 @cindex options, -funix-intrinsics-disable
2219 @item -funix-intrinsics-disable
2220 @cindex -funix-intrinsics-enable option
2221 @cindex options, -funix-intrinsics-enable
2222 @item -funix-intrinsics-enable
2223 @cindex UNIX intrinsics
2224 @cindex intrinsics, UNIX
2225 Specify status of UNIX intrinsics.
2226 @samp{-funix-intrinsics-enable} is the default.
2227 @xref{Intrinsic Groups}.
2229 @cindex -fvxt-intrinsics-delete option
2230 @cindex options, -fvxt-intrinsics-delete
2231 @item -fvxt-intrinsics-delete
2232 @cindex -fvxt-intrinsics-hide option
2233 @cindex options, -fvxt-intrinsics-hide
2234 @item -fvxt-intrinsics-hide
2235 @cindex -fvxt-intrinsics-disable option
2236 @cindex options, -fvxt-intrinsics-disable
2237 @item -fvxt-intrinsics-disable
2238 @cindex -fvxt-intrinsics-enable option
2239 @cindex options, -fvxt-intrinsics-enable
2240 @item -fvxt-intrinsics-enable
2241 @cindex VXT intrinsics
2242 @cindex intrinsics, VXT
2243 Specify status of VXT intrinsics.
2244 @samp{-fvxt-intrinsics-enable} is the default.
2245 @xref{Intrinsic Groups}.
2247 @cindex -ffixed-line-length-@var{n} option
2248 @cindex options, -ffixed-line-length-@var{n}
2249 @item -ffixed-line-length-@var{n}
2250 @cindex source file format
2251 @cindex lines, length
2252 @cindex length of source lines
2253 @cindex fixed form
2254 @cindex limits, lengths of source lines
2255 Set column after which characters are ignored in typical fixed-form
2256 lines in the source file, and through which spaces are assumed (as
2257 if padded to that length) after the ends of short fixed-form lines.
2259 @cindex card image
2260 @cindex extended-source option
2261 Popular values for @var{n} include 72 (the
2262 standard and the default), 80 (card image), and 132 (corresponds
2263 to ``extended-source'' options in some popular compilers).
2264 @var{n} may be @samp{none}, meaning that the entire line is meaningful
2265 and that continued character constants never have implicit spaces appended
2266 to them to fill out the line.
2267 @samp{-ffixed-line-length-0} means the same thing as
2268 @samp{-ffixed-line-length-none}.
2270 @xref{Source Form}, for more information.
2271 @end table
2273 @node Warning Options
2274 @section Options to Request or Suppress Warnings
2275 @cindex options, warnings
2276 @cindex warnings, suppressing
2277 @cindex messages, warning
2278 @cindex suppressing warnings
2280 Warnings are diagnostic messages that report constructions which
2281 are not inherently erroneous but which are risky or suggest there
2282 might have been an error.
2284 You can request many specific warnings with options beginning @samp{-W},
2285 for example @samp{-Wimplicit} to request warnings on implicit
2286 declarations.  Each of these specific warning options also has a
2287 negative form beginning @samp{-Wno-} to turn off warnings;
2288 for example, @samp{-Wno-implicit}.  This manual lists only one of the
2289 two forms, whichever is not the default.
2291 These options control the amount and kinds of warnings produced by GNU
2292 Fortran:
2294 @table @code
2295 @cindex syntax checking
2296 @cindex -fsyntax-only option
2297 @cindex options, -fsyntax-only
2298 @item -fsyntax-only
2299 Check the code for syntax errors, but don't do anything beyond that.
2301 @cindex -pedantic option
2302 @cindex options, -pedantic
2303 @item -pedantic
2304 Issue warnings for uses of extensions to ANSI FORTRAN 77.
2305 @samp{-pedantic} also applies to C-language constructs where they
2306 occur in GNU Fortran source files, such as use of @samp{\e} in a
2307 character constant within a directive like @samp{#include}.
2309 Valid ANSI FORTRAN 77 programs should compile properly with or without
2310 this option.
2311 However, without this option, certain GNU extensions and traditional
2312 Fortran features are supported as well.
2313 With this option, many of them are rejected.
2315 Some users try to use @samp{-pedantic} to check programs for strict ANSI
2316 conformance.
2317 They soon find that it does not do quite what they want---it finds some
2318 non-ANSI practices, but not all.
2319 However, improvements to @code{g77} in this area are welcome.
2321 @cindex -pedantic-errors option
2322 @cindex options, -pedantic-errors
2323 @item -pedantic-errors
2324 Like @samp{-pedantic}, except that errors are produced rather than
2325 warnings.
2327 @cindex -fpedantic option
2328 @cindex options, -fpedantic
2329 @item -fpedantic
2330 Like @samp{-pedantic}, but applies only to Fortran constructs.
2332 @cindex -w option
2333 @cindex options, -w
2334 @item -w
2335 Inhibit all warning messages.
2337 @cindex -Wno-globals option
2338 @cindex options, -Wno-globals
2339 @item -Wno-globals
2340 @cindex global names, warning
2341 @cindex warnings, global names
2342 Inhibit warnings about use of a name as both a global name
2343 (a subroutine, function, or block data program unit, or a
2344 common block) and implicitly as the name of an intrinsic
2345 in a source file.
2347 Also inhibit warnings about inconsistent invocations and/or
2348 definitions of global procedures (function and subroutines).
2349 Such inconsistencies include different numbers of arguments
2350 and different types of arguments.
2352 @cindex -Wimplicit option
2353 @cindex options, -Wimplicit
2354 @item -Wimplicit
2355 @cindex implicit declaration, warning
2356 @cindex warnings, implicit declaration
2357 @cindex -u option
2358 @cindex /WARNINGS=DECLARATIONS switch
2359 @cindex IMPLICIT NONE, similar effect
2360 @cindex effecting IMPLICIT NONE
2361 Warn whenever a variable, array, or function is implicitly
2362 declared.
2363 Has an effect similar to using the @code{IMPLICIT NONE} statement
2364 in every program unit.
2365 (Some Fortran compilers provide this feature by an option
2366 named @samp{-u} or @samp{/WARNINGS=DECLARATIONS}.)
2368 @cindex -Wunused option
2369 @cindex options, -Wunused
2370 @item -Wunused
2371 @cindex unused variables
2372 @cindex variables, unused
2373 Warn whenever a variable is unused aside from its declaration.
2375 @cindex -Wuninitialized option
2376 @cindex options, -Wuninitialized
2377 @item -Wuninitialized
2378 @cindex uninitialized variables
2379 @cindex variables, uninitialized
2380 Warn whenever an automatic variable is used without first being initialized.
2382 These warnings are possible only in optimizing compilation,
2383 because they require data-flow information that is computed only
2384 when optimizing.  If you don't specify @samp{-O}, you simply won't
2385 get these warnings.
2387 These warnings occur only for variables that are candidates for
2388 register allocation.  Therefore, they do not occur for a variable
2389 @c that is declared @code{VOLATILE}, or
2390 whose address is taken, or whose size
2391 is other than 1, 2, 4 or 8 bytes.  Also, they do not occur for
2392 arrays, even when they are in registers.
2394 Note that there might be no warning about a variable that is used only
2395 to compute a value that itself is never used, because such
2396 computations may be deleted by data-flow analysis before the warnings
2397 are printed.
2399 These warnings are made optional because GNU Fortran is not smart
2400 enough to see all the reasons why the code might be correct
2401 despite appearing to have an error.  Here is one example of how
2402 this can happen:
2404 @example
2405 SUBROUTINE DISPAT(J)
2406 IF (J.EQ.1) I=1
2407 IF (J.EQ.2) I=4
2408 IF (J.EQ.3) I=5
2409 CALL FOO(I)
2411 @end example
2413 @noindent
2414 If the value of @code{J} is always 1, 2 or 3, then @code{I} is
2415 always initialized, but GNU Fortran doesn't know this.  Here is
2416 another common case:
2418 @example
2419 SUBROUTINE MAYBE(FLAG)
2420 LOGICAL FLAG
2421 IF (FLAG) VALUE = 9.4
2422 @dots{}
2423 IF (FLAG) PRINT *, VALUE
2425 @end example
2427 @noindent
2428 This has no bug because @code{VALUE} is used only if it is set.
2430 @cindex -Wall option
2431 @cindex options, -Wall
2432 @item -Wall
2433 @cindex all warnings
2434 @cindex warnings, all
2435 The @samp{-Wunused} and @samp{-Wuninitialized} options combined.
2436 These are all the
2437 options which pertain to usage that we recommend avoiding and that we
2438 believe is easy to avoid.
2439 (As more warnings are added to @code{g77}, some might
2440 be added to the list enabled by @samp{-Wall}.)
2441 @end table
2443 The remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}
2444 because they warn about constructions that we consider reasonable to
2445 use, on occasion, in clean programs.
2447 @table @code
2448 @c @item -W
2449 @c Print extra warning messages for these events:
2451 @c @itemize @bullet
2452 @c @item
2453 @c If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused
2454 @c arguments.
2456 @c @end itemize
2458 @cindex -Wsurprising option
2459 @cindex options, -Wsurprising
2460 @item -Wsurprising
2461 Warn about ``suspicious'' constructs that are interpreted
2462 by the compiler in a way that might well be surprising to
2463 someone reading the code.
2464 These differences can result in subtle, compiler-dependent
2465 (even machine-dependent) behavioral differences.
2466 The constructs warned about include:
2468 @itemize @bullet
2469 @item
2470 Expressions having two arithmetic operators in a row, such
2471 as @samp{X*-Y}.
2472 Such a construct is nonstandard, and can produce
2473 unexpected results in more complicated situations such
2474 as @samp{X**-Y*Z}.
2475 @code{g77}, along with many other compilers, interprets
2476 this example differently than many programmers, and a few
2477 other compilers.
2478 Specifically, @code{g77} interprets @samp{X**-Y*Z} as
2479 @samp{(X**(-Y))*Z}, while others might think it should
2480 be interpreted as @samp{X**(-(Y*Z))}.
2482 A revealing example is the constant expression @samp{2**-2*1.},
2483 which @code{g77} evaluates to .25, while others might evaluate
2484 it to 0., the difference resulting from the way precedence affects
2485 type promotion.
2487 (The @samp{-fpedantic} option also warns about expressions
2488 having two arithmetic operators in a row.)
2490 @item
2491 Expressions with a unary minus followed by an operand and then
2492 a binary operator other than plus or minus.
2493 For example, @samp{-2**2} produces a warning, because
2494 the precedence is @samp{-(2**2)}, yielding -4, not
2495 @samp{(-2)**2}, which yields 4, and which might represent
2496 what a programmer expects.
2498 An example of an expression producing different results
2499 in a surprising way is @samp{-I*S}, where @var{I} holds
2500 the value @samp{-2147483648} and @var{S} holds @samp{0.5}.
2501 On many systems, negating @var{I} results in the same
2502 value, not a positive number, because it is already the
2503 lower bound of what an @code{INTEGER(KIND=1)} variable can hold.
2504 So, the expression evaluates to a positive number, while
2505 the ``expected'' interpretation, @samp{(-I)*S}, would
2506 evaluate to a negative number.
2508 Even cases such as @samp{-I*J} produce warnings,
2509 even though, in most configurations and situations,
2510 there is no computational difference between the
2511 results of the two interpretations---the purpose
2512 of this warning is to warn about differing interpretations
2513 and encourage a better style of coding, not to identify
2514 only those places where bugs might exist in the user's
2515 code.
2517 @cindex DO statement
2518 @cindex statements, DO
2519 @item
2520 @code{DO} loops with @code{DO} variables that are not
2521 of integral type---that is, using @code{REAL}
2522 variables as loop control variables.
2523 Although such loops can be written to work in the
2524 ``obvious'' way, the way @code{g77} is required by the
2525 Fortran standard to interpret such code is likely to
2526 be quite different from the way many programmers expect.
2527 (This is true of all @code{DO} loops, but the differences
2528 are pronounced for non-integral loop control variables.)
2530 @xref{Loops}, for more information.
2531 @end itemize
2533 @cindex -Werror option
2534 @cindex options, -Werror
2535 @item -Werror
2536 Make all warnings into errors.
2538 @cindex -W option
2539 @cindex options, -W
2540 @item -W
2541 @cindex extra warnings
2542 @cindex warnings, extra
2543 Turns on ``extra warnings'' and, if optimization is specified
2544 via @samp{-O}, the @samp{-Wuninitialized} option.
2545 (This might change in future versions of @code{g77}.)
2547 ``Extra warnings'' are issued for:
2549 @itemize @bullet
2550 @item
2551 @cindex unused parameters
2552 @cindex parameters, unused
2553 @cindex unused arguments
2554 @cindex arguments, unused
2555 @cindex unused dummies
2556 @cindex dummies, unused
2557 Unused parameters to a procedure (when @samp{-Wunused} also is
2558 specified).
2560 @item
2561 @cindex overflow
2562 Overflows involving floating-point constants (not available
2563 for certain configurations).
2564 @end itemize
2565 @end table
2567 @xref{Warning Options,,Options to Request or Suppress Warnings,
2568 gcc,Using and Porting GNU CC}, for information on more options offered
2569 by the GBE shared by @code{g77}, @code{gcc}, and other GNU compilers.
2571 Some of these have no effect when compiling programs written in Fortran:
2573 @table @code
2574 @cindex -Wcomment option
2575 @cindex options, -Wcomment
2576 @item -Wcomment
2577 @cindex -Wformat option
2578 @cindex options, -Wformat
2579 @item -Wformat
2580 @cindex -Wparentheses option
2581 @cindex options, -Wparentheses
2582 @item -Wparentheses
2583 @cindex -Wswitch option
2584 @cindex options, -Wswitch
2585 @item -Wswitch
2586 @cindex -Wtraditional option
2587 @cindex options, -Wtraditional
2588 @item -Wtraditional
2589 @cindex -Wshadow option
2590 @cindex options, -Wshadow
2591 @item -Wshadow
2592 @cindex -Wid-clash-@var{len} option
2593 @cindex options, -Wid-clash-@var{len}
2594 @item -Wid-clash-@var{len}
2595 @cindex -Wlarger-than-@var{len} option
2596 @cindex options, -Wlarger-than-@var{len}
2597 @item -Wlarger-than-@var{len}
2598 @cindex -Wconversion option
2599 @cindex options, -Wconversion
2600 @item -Wconversion
2601 @cindex -Waggregate-return option
2602 @cindex options, -Waggregate-return
2603 @item -Waggregate-return
2604 @cindex -Wredundant-decls option
2605 @cindex options, -Wredundant-decls
2606 @item -Wredundant-decls
2607 @cindex unsupported warnings
2608 @cindex warnings, unsupported
2609 These options all could have some relevant meaning for
2610 GNU Fortran programs, but are not yet supported.
2611 @end table
2613 @node Debugging Options
2614 @section Options for Debugging Your Program or GNU Fortran
2615 @cindex options, debugging
2616 @cindex debugging information options
2618 GNU Fortran has various special options that are used for debugging
2619 either your program or @code{g77}.
2621 @table @code
2622 @cindex -g option
2623 @cindex options, -g
2624 @item -g
2625 Produce debugging information in the operating system's native format
2626 (stabs, COFF, XCOFF, or DWARF).  GDB can work with this debugging
2627 information.
2628 @end table
2630 @xref{Debugging Options,,Options for Debugging Your Program or GNU CC,
2631 gcc,Using and Porting GNU CC}, for more information on debugging options.
2633 @node Optimize Options
2634 @section Options That Control Optimization
2635 @cindex optimize options
2636 @cindex options, optimization
2638 Most Fortran users will want to use no optimization when
2639 developing and testing programs, and use @samp{-O} or @samp{-O2} when
2640 compiling programs for late-cycle testing and for production use.
2641 However, note that certain diagnostics---such as for uninitialized
2642 variables---depend on the flow analysis done by @samp{-O}, i.e.@: you
2643 must use @samp{-O} or @samp{-O2} to get such diagnostics.
2645 The following flags have particular applicability when
2646 compiling Fortran programs:
2648 @table @code
2649 @cindex -malign-double option
2650 @cindex options, -malign-double
2651 @item -malign-double
2652 (Intel x86 architecture only.)
2654 Noticeably improves performance of @code{g77} programs making
2655 heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data
2656 on some systems.
2657 In particular, systems using Pentium, Pentium Pro, 586, and
2658 686 implementations
2659 of the i386 architecture execute programs faster when
2660 @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data are
2661 aligned on 64-bit boundaries
2662 in memory.
2664 This option can, at least, make benchmark results more consistent
2665 across various system configurations, versions of the program,
2666 and data sets.
2668 @emph{Note:} The warning in the @code{gcc} documentation about
2669 this option does not apply, generally speaking, to Fortran
2670 code compiled by @code{g77}.
2672 @xref{Aligned Data}, for more information on alignment issues.
2674 @emph{Also also note:} The negative form of @samp{-malign-double}
2675 is @samp{-mno-align-double}, not @samp{-benign-double}.
2677 @cindex -ffloat-store option
2678 @cindex options, -ffloat-store
2679 @item -ffloat-store
2680 @cindex IEEE 754 conformance
2681 @cindex conformance, IEEE 754
2682 @cindex floating-point, precision
2683 Might help a Fortran program that depends on exact IEEE conformance on
2684 some machines, but might slow down a program that doesn't.
2686 This option is effective when the floating-point unit is set to work in
2687 IEEE 854 `extended precision'---as it typically is on x86 and m68k GNU
2688 systems---rather than IEEE 754 double precision.  @samp{-ffloat-store}
2689 tries to remove the extra precision by spilling data from floating-point
2690 registers into memory and this typically involves a big performance
2691 hit.  However, it doesn't affect intermediate results, so that it is
2692 only partially effective.  `Excess precision' is avoided in code like:
2693 @smallexample
2694 a = b + c
2695 d = a * e
2696 @end smallexample
2697 but not in code like:
2698 @smallexample
2699       d = (b + c) * e
2700 @end smallexample
2702 For another, potentially better, way of controlling the precision,
2703 see @ref{Floating-point precision}.
2705 @cindex -fforce-mem option
2706 @cindex options, -fforce-mem
2707 @item -fforce-mem
2708 @cindex -fforce-addr option
2709 @cindex options, -fforce-addr
2710 @item -fforce-addr
2711 @cindex loops, speeding up
2712 @cindex speed, of loops
2713 Might improve optimization of loops.
2715 @cindex -fno-inline option
2716 @cindex options, -fno-inline
2717 @item -fno-inline
2718 @cindex in-line code
2719 @cindex compilation, in-line
2720 @c DL: Only relevant for -O3?
2721 Don't compile statement functions inline.
2722 Might reduce the size of a program unit---which might be at
2723 expense of some speed (though it should compile faster).
2724 Note that if you are not optimizing, no functions can be expanded inline.
2726 @cindex -ffast-math option
2727 @cindex options, -ffast-math
2728 @item -ffast-math
2729 @cindex IEEE 754 conformance
2730 @cindex conformance, IEEE 754
2731 Might allow some programs designed to not be too dependent
2732 on IEEE behavior for floating-point to run faster, or die trying.
2733 Sets @samp{-funsafe-math-optimizations}, and
2734 @samp{-fno-trapping-math}.
2736 @cindex -funsafe-math-optimizations option
2737 @cindex options, -funsafe-math-optimizations
2738 @item -funsafe-math-optimizations
2739 Allow optimizations that may be give incorrect results
2740 for certain IEEE inputs.
2742 @cindex -fno-trapping-math option
2743 @cindex options, -fno-trapping-math
2744 @item -fno-trapping-math
2745 Allow the compiler to assume that floating-point arithmetic
2746 will not generate traps on any inputs.  This is useful, for
2747 example, when running a program using IEEE "non-stop"
2748 floating-point arithmetic.
2750 @cindex -fstrength-reduce option
2751 @cindex options, -fstrength-reduce
2752 @item -fstrength-reduce
2753 @cindex loops, speeding up
2754 @cindex speed, of loops
2755 @c DL: normally defaulted?
2756 Might make some loops run faster.
2758 @cindex -frerun-cse-after-loop option
2759 @cindex options, -frerun-cse-after-loop
2760 @item -frerun-cse-after-loop
2761 @cindex -fexpensive-optimizations option
2762 @cindex options, -fexpensive-optimizations
2763 @c DL: This is -O2?
2764 @item -fexpensive-optimizations
2765 @cindex -fdelayed-branch option
2766 @cindex options, -fdelayed-branch
2767 @item -fdelayed-branch
2768 @cindex -fschedule-insns option
2769 @cindex options, -fschedule-insns
2770 @item -fschedule-insns
2771 @cindex -fschedule-insns2 option
2772 @cindex options, -fschedule-insns2
2773 @item -fschedule-insns2
2774 @cindex -fcaller-saves option
2775 @cindex options, -fcaller-saves
2776 @item -fcaller-saves
2777 Might improve performance on some code.
2779 @cindex -funroll-loops option
2780 @cindex options, -funroll-loops
2781 @item -funroll-loops
2782 @cindex loops, unrolling
2783 @cindex unrolling loops
2784 @cindex loops, optimizing
2785 @cindex indexed (iterative) @code{DO}
2786 @cindex iterative @code{DO}
2787 @c DL: fixme: Craig doesn't like `indexed' but f95 doesn't seem to
2788 @c provide a suitable term
2789 @c CB: I've decided on `iterative', for the time being, and changed
2790 @c my previous, rather bizarre, use of `imperative' to that
2791 @c (though `precomputed-trip' would be a more precise adjective)
2792 Typically improves performance on code using iterative @code{DO} loops by
2793 unrolling them and is probably generally appropriate for Fortran, though
2794 it is not turned on at any optimization level.
2795 Note that outer loop unrolling isn't done specifically; decisions about
2796 whether to unroll a loop are made on the basis of its instruction count.
2798 @c DL: Fixme: This should obviously go somewhere else...
2799 Also, no `loop discovery'@footnote{@dfn{loop discovery} refers to the
2800 process by which a compiler, or indeed any reader of a program,
2801 determines which portions of the program are more likely to be executed
2802 repeatedly as it is being run.  Such discovery typically is done early
2803 when compiling using optimization techniques, so the ``discovered''
2804 loops get more attention---and more run-time resources, such as
2805 registers---from the compiler.  It is easy to ``discover'' loops that are
2806 constructed out of looping constructs in the language
2807 (such as Fortran's @code{DO}).  For some programs, ``discovering'' loops
2808 constructed out of lower-level constructs (such as @code{IF} and
2809 @code{GOTO}) can lead to generation of more optimal code
2810 than otherwise.} is done, so only loops written with @code{DO}
2811 benefit from loop optimizations, including---but not limited
2812 to---unrolling.  Loops written with @code{IF} and @code{GOTO} are not
2813 currently recognized as such.  This option unrolls only iterative
2814 @code{DO} loops, not @code{DO WHILE} loops.
2816 @cindex -funroll-all-loops option
2817 @cindex options, -funroll-all-loops
2818 @cindex DO WHILE
2819 @item -funroll-all-loops
2820 @c DL: Check my understanding of -funroll-all-loops v. -funroll-loops is correct.
2821 Probably improves performance on code using @code{DO WHILE} loops by
2822 unrolling them in addition to iterative @code{DO} loops.  In the absence
2823 of @code{DO WHILE}, this option is equivalent to @samp{-funroll-loops}
2824 but possibly slower.
2826 @item -fno-move-all-movables
2827 @cindex -fno-move-all-movables option
2828 @cindex options, -fno-move-all-movables
2829 @item -fno-reduce-all-givs
2830 @cindex -fno-reduce-all-givs option
2831 @cindex options, -fno-reduce-all-givs
2832 @item -fno-rerun-loop-opt
2833 @cindex -fno-rerun-loop-opt option
2834 @cindex options, -fno-rerun-loop-opt
2835 @emph{Version info:}
2836 These options are not supported by
2837 versions of @code{g77} based on @code{gcc} version 2.8.
2839 Each of these might improve performance on some code.
2841 Analysis of Fortran code optimization and the resulting
2842 optimizations triggered by the above options were
2843 contributed by Toon Moene (@email{toon@@moene.indiv.nluug.nl}).
2845 These three options are intended to be removed someday, once
2846 they have helped determine the efficacy of various
2847 approaches to improving the performance of Fortran code.
2849 Please let us know how use of these options affects
2850 the performance of your production code.
2851 We're particularly interested in code that runs faster
2852 when these options are @emph{disabled}, and in
2853 non-Fortran code that benefits when they are
2854 @emph{enabled} via the above @code{gcc} command-line options.
2855 @end table
2857 @xref{Optimize Options,,Options That Control Optimization,
2858 gcc,Using and Porting GNU CC}, for more information on options
2859 to optimize the generated machine code.
2861 @node Preprocessor Options
2862 @section Options Controlling the Preprocessor
2863 @cindex preprocessor options
2864 @cindex options, preprocessor
2865 @cindex cpp program
2866 @cindex programs, cpp
2868 These options control the C preprocessor, which is run on each C source
2869 file before actual compilation.
2871 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
2872 gcc,Using and Porting GNU CC}, for information on C preprocessor options.
2874 @cindex INCLUDE directive
2875 @cindex directive, INCLUDE
2876 Some of these options also affect how @code{g77} processes the
2877 @code{INCLUDE} directive.
2878 Since this directive is processed even when preprocessing
2879 is not requested, it is not described in this section.
2880 @xref{Directory Options,,Options for Directory Search}, for
2881 information on how @code{g77} processes the @code{INCLUDE} directive.
2883 However, the @code{INCLUDE} directive does not apply
2884 preprocessing to the contents of the included file itself.
2886 Therefore, any file that contains preprocessor directives
2887 (such as @code{#include}, @code{#define}, and @code{#if})
2888 must be included via the @code{#include} directive, not
2889 via the @code{INCLUDE} directive.
2890 Therefore, any file containing preprocessor directives,
2891 if included, is necessarily included by a file that itself
2892 contains preprocessor directives.
2894 @node Directory Options
2895 @section Options for Directory Search
2896 @cindex directory, options
2897 @cindex options, directory search
2898 @cindex search path
2900 These options affect how the @code{cpp} preprocessor searches
2901 for files specified via the @code{#include} directive.
2902 Therefore, when compiling Fortran programs, they are meaningful
2903 when the preprocessor is used.
2905 @cindex INCLUDE directive
2906 @cindex directive, INCLUDE
2907 Some of these options also affect how @code{g77} searches
2908 for files specified via the @code{INCLUDE} directive,
2909 although files included by that directive are not,
2910 themselves, preprocessed.
2911 These options are:
2913 @table @code
2914 @cindex -I- option
2915 @cindex options, -I-
2916 @item -I-
2917 @cindex -Idir option
2918 @cindex options, -Idir
2919 @item -I@var{dir}
2920 @cindex directory, search paths for inclusion
2921 @cindex inclusion, directory search paths for
2922 @cindex search paths, for included files
2923 @cindex paths, search
2924 These affect interpretation of the @code{INCLUDE} directive
2925 (as well as of the @code{#include} directive of the @code{cpp}
2926 preprocessor).
2928 Note that @samp{-I@var{dir}} must be specified @emph{without} any
2929 spaces between @samp{-I} and the directory name---that is,
2930 @samp{-Ifoo/bar} is valid, but @samp{-I foo/bar}
2931 is rejected by the @code{g77} compiler (though the preprocessor supports
2932 the latter form).
2933 @c this is due to toplev.c's inflexible option processing
2934 Also note that the general behavior of @samp{-I} and
2935 @code{INCLUDE} is pretty much the same as of @samp{-I} with
2936 @code{#include} in the @code{cpp} preprocessor, with regard to
2937 looking for @file{header.gcc} files and other such things.
2939 @xref{Directory Options,,Options for Directory Search,
2940 gcc,Using and Porting GNU CC}, for information on the @samp{-I} option.
2941 @end table
2943 @node Code Gen Options
2944 @section Options for Code Generation Conventions
2945 @cindex code generation, conventions
2946 @cindex options, code generation
2947 @cindex run-time, options
2949 These machine-independent options control the interface conventions
2950 used in code generation.
2952 Most of them have both positive and negative forms; the negative form
2953 of @samp{-ffoo} would be @samp{-fno-foo}.  In the table below, only
2954 one of the forms is listed---the one which is not the default.  You
2955 can figure out the other form by either removing @samp{no-} or adding
2958 @table @code
2959 @cindex -fno-automatic option
2960 @cindex options, -fno-automatic
2961 @item -fno-automatic
2962 @cindex SAVE statement
2963 @cindex statements, SAVE
2964 Treat each program unit as if the @code{SAVE} statement was specified
2965 for every local variable and array referenced in it.
2966 Does not affect common blocks.
2967 (Some Fortran compilers provide this option under
2968 the name @samp{-static}.)
2970 @cindex -finit-local-zero option
2971 @cindex options, -finit-local-zero
2972 @item -finit-local-zero
2973 @cindex DATA statement
2974 @cindex statements, DATA
2975 @cindex initialization, of local variables
2976 @cindex variables, initialization of
2977 @cindex uninitialized variables
2978 @cindex variables, uninitialized
2979 Specify that variables and arrays that are local to a program unit
2980 (not in a common block and not passed as an argument) are to be initialized
2981 to binary zeros.
2983 Since there is a run-time penalty for initialization of variables
2984 that are not given the @code{SAVE} attribute, it might be a
2985 good idea to also use @samp{-fno-automatic} with @samp{-finit-local-zero}.
2987 @cindex -fno-f2c option
2988 @cindex options, -fno-f2c
2989 @item -fno-f2c
2990 @cindex @code{f2c} compatibility
2991 @cindex compatibility, @code{f2c}
2992 Do not generate code designed to be compatible with code generated
2993 by @code{f2c}; use the GNU calling conventions instead.
2995 The @code{f2c} calling conventions require functions that return
2996 type @code{REAL(KIND=1)} to actually return the C type @code{double},
2997 and functions that return type @code{COMPLEX} to return the
2998 values via an extra argument in the calling sequence that points
2999 to where to store the return value.
3000 Under the GNU calling conventions, such functions simply return
3001 their results as they would in GNU C---@code{REAL(KIND=1)} functions
3002 return the C type @code{float}, and @code{COMPLEX} functions
3003 return the GNU C type @code{complex} (or its @code{struct}
3004 equivalent).
3006 This does not affect the generation of code that interfaces with the
3007 @code{libg2c} library.
3009 However, because the @code{libg2c} library uses @code{f2c}
3010 calling conventions, @code{g77} rejects attempts to pass
3011 intrinsics implemented by routines in this library as actual
3012 arguments when @samp{-fno-f2c} is used, to avoid bugs when
3013 they are actually called by code expecting the GNU calling
3014 conventions to work.
3016 For example, @samp{INTRINSIC ABS;CALL FOO(ABS)} is
3017 rejected when @samp{-fno-f2c} is in force.
3018 (Future versions of the @code{g77} run-time library might
3019 offer routines that provide GNU-callable versions of the
3020 routines that implement the @code{f2c}-callable intrinsics
3021 that may be passed as actual arguments, so that
3022 valid programs need not be rejected when @samp{-fno-f2c}
3023 is used.)
3025 @strong{Caution:} If @samp{-fno-f2c} is used when compiling any
3026 source file used in a program, it must be used when compiling
3027 @emph{all} Fortran source files used in that program.
3029 @c seems kinda dumb to tell people about an option they can't use -- jcb
3030 @c then again, we want users building future-compatible libraries with it.
3031 @cindex -ff2c-library option
3032 @cindex options, -ff2c-library
3033 @item -ff2c-library
3034 Specify that use of @code{libg2c} (or the original @code{libf2c})
3035 is required.
3036 This is the default for the current version of @code{g77}.
3038 Currently it is not
3039 valid to specify @samp{-fno-f2c-library}.
3040 This option is provided so users can specify it in shell
3041 scripts that build programs and libraries that require the
3042 @code{libf2c} library, even when being compiled by future
3043 versions of @code{g77} that might otherwise default to
3044 generating code for an incompatible library.
3046 @cindex -fno-underscoring option
3047 @cindex options, -fno-underscoring
3048 @item -fno-underscoring
3049 @cindex underscore
3050 @cindex symbol names, underscores
3051 @cindex transforming symbol names
3052 @cindex symbol names, transforming
3053 Do not transform names of entities specified in the Fortran
3054 source file by appending underscores to them.
3056 With @samp{-funderscoring} in effect, @code{g77} appends two underscores
3057 to names with underscores and one underscore to external names with
3058 no underscores.  (@code{g77} also appends two underscores to internal
3059 names with underscores to avoid naming collisions with external names.
3060 The @samp{-fno-second-underscore} option disables appending of the
3061 second underscore in all cases.)
3063 This is done to ensure compatibility with code produced by many
3064 UNIX Fortran compilers, including @code{f2c}, which perform the
3065 same transformations.
3067 Use of @samp{-fno-underscoring} is not recommended unless you are
3068 experimenting with issues such as integration of (GNU) Fortran into
3069 existing system environments (vis-a-vis existing libraries, tools, and
3070 so on).
3072 For example, with @samp{-funderscoring}, and assuming other defaults like
3073 @samp{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
3074 external functions while @samp{my_var} and @samp{lvar} are local variables,
3075 a statement like
3077 @smallexample
3078 I = J() + MAX_COUNT (MY_VAR, LVAR)
3079 @end smallexample
3081 @noindent
3082 is implemented as something akin to:
3084 @smallexample
3085 i = j_() + max_count__(&my_var__, &lvar);
3086 @end smallexample
3088 With @samp{-fno-underscoring}, the same statement is implemented as:
3090 @smallexample
3091 i = j() + max_count(&my_var, &lvar);
3092 @end smallexample
3094 Use of @samp{-fno-underscoring} allows direct specification of
3095 user-defined names while debugging and when interfacing @code{g77}-compiled
3096 code with other languages.
3098 Note that just because the names match does @emph{not} mean that the
3099 interface implemented by @code{g77} for an external name matches the
3100 interface implemented by some other language for that same name.
3101 That is, getting code produced by @code{g77} to link to code produced
3102 by some other compiler using this or any other method can be only a
3103 small part of the overall solution---getting the code generated by
3104 both compilers to agree on issues other than naming can require
3105 significant effort, and, unlike naming disagreements, linkers normally
3106 cannot detect disagreements in these other areas.
3108 Also, note that with @samp{-fno-underscoring}, the lack of appended
3109 underscores introduces the very real possibility that a user-defined
3110 external name will conflict with a name in a system library, which
3111 could make finding unresolved-reference bugs quite difficult in some
3112 cases---they might occur at program run time, and show up only as
3113 buggy behavior at run time.
3115 In future versions of @code{g77}, we hope to improve naming and linking
3116 issues so that debugging always involves using the names as they appear
3117 in the source, even if the names as seen by the linker are mangled to
3118 prevent accidental linking between procedures with incompatible
3119 interfaces.
3121 @cindex -fno-second-underscore option
3122 @cindex options, -fno-second-underscore
3123 @item -fno-second-underscore
3124 @cindex underscore
3125 @cindex symbol names, underscores
3126 @cindex transforming symbol names
3127 @cindex symbol names, transforming
3128 Do not append a second underscore to names of entities specified
3129 in the Fortran source file.
3131 This option has no effect if @samp{-fno-underscoring} is
3132 in effect.
3134 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
3135 is implemented as a reference to the link-time external symbol
3136 @samp{max_count_}, instead of @samp{max_count__}.
3138 @cindex -fno-ident option
3139 @cindex options, -fno-ident
3140 @item -fno-ident
3141 Ignore the @samp{#ident} directive.
3143 @cindex -fzeros option
3144 @cindex options, -fzeros
3145 @item -fzeros
3146 Treat initial values of zero as if they were any other value.
3148 As of version 0.5.18, @code{g77} normally treats @code{DATA} and
3149 other statements that are used to specify initial values of zero
3150 for variables and arrays as if no values were actually specified,
3151 in the sense that no diagnostics regarding multiple initializations
3152 are produced.
3154 This is done to speed up compiling of programs that initialize
3155 large arrays to zeros.
3157 Use @samp{-fzeros} to revert to the simpler, slower behavior
3158 that can catch multiple initializations by keeping track of
3159 all initializations, zero or otherwise.
3161 @emph{Caution:} Future versions of @code{g77} might disregard this option
3162 (and its negative form, the default) or interpret it somewhat
3163 differently.
3164 The interpretation changes will affect only non-standard
3165 programs; standard-conforming programs should not be affected.
3167 @cindex -femulate-complex option
3168 @cindex options, -femulate-complex
3169 @item -femulate-complex
3170 Implement @code{COMPLEX} arithmetic via emulation,
3171 instead of using the facilities of
3172 the @code{gcc} back end that provide direct support of
3173 @code{complex} arithmetic.
3175 (@code{gcc} had some bugs in its back-end support
3176 for @code{complex} arithmetic, due primarily to the support not being
3177 completed as of version 2.8.1 and @code{egcs} 1.1.2.)
3179 Use @samp{-femulate-complex} if you suspect code-generation bugs,
3180 or experience compiler crashes,
3181 that might result from @code{g77} using the @code{COMPLEX} support
3182 in the @code{gcc} back end.
3183 If using that option fixes the bugs or crashes you are seeing,
3184 that indicates a likely @code{g77} bugs
3185 (though, all compiler crashes are considered bugs),
3186 so, please report it.
3187 (Note that the known bugs, now believed fixed, produced compiler crashes
3188 rather than causing the generation of incorrect code.)
3190 Use of this option should not affect how Fortran code compiled
3191 by @code{g77} works in terms of its interfaces to other code,
3192 e.g. that compiled by @code{f2c}.
3194 @emph{Caution:} Future versions of @code{g77} might ignore both forms
3195 of this option.
3197 @cindex -falias-check option
3198 @cindex options, -falias-check
3199 @cindex -fargument-alias option
3200 @cindex options, -fargument-alias
3201 @cindex -fargument-noalias option
3202 @cindex options, -fargument-noalias
3203 @cindex -fno-argument-noalias-global option
3204 @cindex options, -fno-argument-noalias-global
3205 @item -falias-check
3206 @item -fargument-alias
3207 @item -fargument-noalias
3208 @item -fno-argument-noalias-global
3209 @emph{Version info:}
3210 These options are not supported by
3211 versions of @code{g77} based on @code{gcc} version 2.8.
3213 These options specify to what degree aliasing
3214 (overlap)
3215 is permitted between
3216 arguments (passed as pointers) and @code{COMMON} (external, or
3217 public) storage.
3219 The default for Fortran code, as mandated by the FORTRAN 77 and
3220 Fortran 90 standards, is @samp{-fargument-noalias-global}.
3221 The default for code written in the C language family is
3222 @samp{-fargument-alias}.
3224 Note that, on some systems, compiling with @samp{-fforce-addr} in
3225 effect can produce more optimal code when the default aliasing
3226 options are in effect (and when optimization is enabled).
3228 @xref{Aliasing Assumed To Work}, for detailed information on the implications
3229 of compiling Fortran code that depends on the ability to alias dummy
3230 arguments.
3232 @cindex -fno-globals option
3233 @cindex options, -fno-globals
3234 @item -fno-globals
3235 @cindex global names, warning
3236 @cindex warnings, global names
3237 @cindex in-line code
3238 @cindex compilation, in-line
3239 Disable diagnostics about inter-procedural
3240 analysis problems, such as disagreements about the
3241 type of a function or a procedure's argument,
3242 that might cause a compiler crash when attempting
3243 to inline a reference to a procedure within a
3244 program unit.
3245 (The diagnostics themselves are still produced, but
3246 as warnings, unless @samp{-Wno-globals} is specified,
3247 in which case no relevant diagnostics are produced.)
3249 Further, this option disables such inlining, to
3250 avoid compiler crashes resulting from incorrect
3251 code that would otherwise be diagnosed.
3253 As such, this option might be quite useful when
3254 compiling existing, ``working'' code that happens
3255 to have a few bugs that do not generally show themselves,
3256 but which @code{g77} diagnoses.
3258 Use of this option therefore has the effect of
3259 instructing @code{g77} to behave more like it did
3260 up through version 0.5.19.1, when it paid little or
3261 no attention to disagreements between program units
3262 about a procedure's type and argument information,
3263 and when it performed no inlining of procedures
3264 (except statement functions).
3266 Without this option, @code{g77} defaults to performing
3267 the potentially inlining procedures as it started doing
3268 in version 0.5.20, but as of version 0.5.21, it also
3269 diagnoses disagreements that might cause such inlining
3270 to crash the compiler as (fatal) errors,
3271 and warns about similar disagreements
3272 that are currently believed to not
3273 likely to result in the compiler later crashing
3274 or producing incorrect code.
3276 @cindex -fflatten-arrays option
3277 @item -fflatten-arrays
3278 @cindex array performance
3279 @cindex arrays, flattening
3280 Use back end's C-like constructs
3281 (pointer plus offset)
3282 instead of its @code{ARRAY_REF} construct
3283 to handle all array references.
3285 @emph{Note:} This option is not supported.
3286 It is intended for use only by @code{g77} developers,
3287 to evaluate code-generation issues.
3288 It might be removed at any time.
3290 @cindex -fbounds-check option
3291 @cindex -ffortran-bounds-check option
3292 @item -fbounds-check
3293 @itemx -ffortran-bounds-check
3294 @cindex bounds checking
3295 @cindex range checking
3296 @cindex array bounds checking
3297 @cindex subscript checking
3298 @cindex substring checking
3299 @cindex checking subscripts
3300 @cindex checking substrings
3301 Enable generation of run-time checks for array subscripts
3302 and substring start and end points
3303 against the (locally) declared minimum and maximum values.
3305 The current implementation uses the @code{libf2c}
3306 library routine @code{s_rnge} to print the diagnostic.
3308 However, whereas @code{f2c} generates a single check per
3309 reference for a multi-dimensional array, of the computed
3310 offset against the valid offset range (0 through the size of the array),
3311 @code{g77} generates a single check per @emph{subscript} expression.
3312 This catches some cases of potential bugs that @code{f2c} does not,
3313 such as references to below the beginning of an assumed-size array.
3315 @code{g77} also generates checks for @code{CHARACTER} substring references,
3316 something @code{f2c} currently does not do.
3318 Use the new @samp{-ffortran-bounds-check} option
3319 to specify bounds-checking for only the Fortran code you are compiling,
3320 not necessarily for code written in other languages.
3322 @emph{Note:} To provide more detailed information on the offending subscript,
3323 @code{g77} provides the @code{libg2c} run-time library routine @code{s_rnge}
3324 with somewhat differently-formatted information.
3325 Here's a sample diagnostic:
3327 @smallexample
3328 Subscript out of range on file line 4, procedure rnge.f/bf.
3329 Attempt to access the -6-th element of variable b[subscript-2-of-2].
3330 Aborted
3331 @end smallexample
3333 The above message indicates that the offending source line is
3334 line 4 of the file @file{rnge.f},
3335 within the program unit (or statement function) named @samp{bf}.
3336 The offended array is named @samp{b}.
3337 The offended array dimension is the second for a two-dimensional array,
3338 and the offending, computed subscript expression was @samp{-6}.
3340 For a @code{CHARACTER} substring reference, the second line has
3341 this appearance:
3343 @smallexample
3344 Attempt to access the 11-th element of variable a[start-substring].
3345 @end smallexample
3347 This indicates that the offended @code{CHARACTER} variable or array
3348 is named @samp{a},
3349 the offended substring position is the starting (leftmost) position,
3350 and the offending substring expression is @samp{11}.
3352 (Though the verbage of @code{s_rnge} is not ideal
3353 for the purpose of the @code{g77} compiler,
3354 the above information should provide adequate diagnostic abilities
3355 to it users.)
3356 @end table
3358 @xref{Code Gen Options,,Options for Code Generation Conventions,
3359 gcc,Using and Porting GNU CC}, for information on more options
3360 offered by the GBE
3361 shared by @code{g77}, @code{gcc}, and other GNU compilers.
3363 Some of these do @emph{not} work when compiling programs written in Fortran:
3365 @table @code
3366 @cindex -fpcc-struct-return option
3367 @cindex options, -fpcc-struct-return
3368 @item -fpcc-struct-return
3369 @cindex -freg-struct-return option
3370 @cindex options, -freg-struct-return
3371 @item -freg-struct-return
3372 You should not use these except strictly the same way as you
3373 used them to build the version of @code{libg2c} with which
3374 you will be linking all code compiled by @code{g77} with the
3375 same option.
3377 @cindex -fshort-double option
3378 @cindex options, -fshort-double
3379 @item -fshort-double
3380 This probably either has no effect on Fortran programs, or
3381 makes them act loopy.
3383 @cindex -fno-common option
3384 @cindex options, -fno-common
3385 @item -fno-common
3386 Do not use this when compiling Fortran programs,
3387 or there will be Trouble.
3389 @cindex -fpack-struct option
3390 @cindex options, -fpack-struct
3391 @item -fpack-struct
3392 This probably will break any calls to the @code{libg2c} library,
3393 at the very least, even if it is built with the same option.
3394 @end table
3396 @node Environment Variables
3397 @section Environment Variables Affecting GNU Fortran
3398 @cindex environment variables
3400 GNU Fortran currently does not make use of any environment
3401 variables to control its operation above and beyond those
3402 that affect the operation of @code{gcc}.
3404 @xref{Environment Variables,,Environment Variables Affecting GNU CC,
3405 gcc,Using and Porting GNU CC}, for information on environment
3406 variables.
3408 @include news.texi
3410 @set USERVISONLY
3411 @include news.texi
3412 @clear USERVISONLY
3414 @node Language
3415 @chapter The GNU Fortran Language
3417 @cindex standard, ANSI FORTRAN 77
3418 @cindex ANSI FORTRAN 77 standard
3419 @cindex reference works
3420 GNU Fortran supports a variety of extensions to, and dialects
3421 of, the Fortran language.
3422 Its primary base is the ANSI FORTRAN 77 standard, currently available on
3423 the network at
3424 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
3425 or as monolithic text at
3426 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
3427 It offers some extensions that are popular among users
3428 of UNIX @code{f77} and @code{f2c} compilers, some that
3429 are popular among users of other compilers (such as Digital
3430 products), some that are popular among users of the
3431 newer Fortran 90 standard, and some that are introduced
3432 by GNU Fortran.
3434 @cindex textbooks
3435 (If you need a text on Fortran,
3436 a few freely available electronic references have pointers from
3437 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
3438 net project', @cite{User Notes on Fortran Programming} at
3439 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
3440 material might not apply specifically to @code{g77}.)
3442 Part of what defines a particular implementation of a Fortran
3443 system, such as @code{g77}, is the particular characteristics
3444 of how it supports types, constants, and so on.
3445 Much of this is left up to the implementation by the various
3446 Fortran standards and accepted practice in the industry.
3448 The GNU Fortran @emph{language} is described below.
3449 Much of the material is organized along the same lines
3450 as the ANSI FORTRAN 77 standard itself.
3452 @xref{Other Dialects}, for information on features @code{g77} supports
3453 that are not part of the GNU Fortran language.
3455 @emph{Note}: This portion of the documentation definitely needs a lot
3456 of work!
3458 @menu
3459 Relationship to the ANSI FORTRAN 77 standard:
3460 * Direction of Language Development::  Where GNU Fortran is headed.
3461 * Standard Support::  Degree of support for the standard.
3463 Extensions to the ANSI FORTRAN 77 standard:
3464 * Conformance::
3465 * Notation Used::
3466 * Terms and Concepts::
3467 * Characters Lines Sequence::
3468 * Data Types and Constants::
3469 * Expressions::
3470 * Specification Statements::
3471 * Control Statements::
3472 * Functions and Subroutines::
3473 * Scope and Classes of Names::
3474 * I/O::
3475 * Fortran 90 Features::
3476 @end menu
3478 @node Direction of Language Development
3479 @section Direction of Language Development
3480 @cindex direction of language development
3481 @cindex features, language
3482 @cindex language, features
3484 The purpose of the following description of the GNU Fortran
3485 language is to promote wide portability of GNU Fortran programs.
3487 GNU Fortran is an evolving language, due to the
3488 fact that @code{g77} itself is in beta test.
3489 Some current features of the language might later
3490 be redefined as dialects of Fortran supported by @code{g77}
3491 when better ways to express these features are added to @code{g77},
3492 for example.
3493 Such features would still be supported by
3494 @code{g77}, but would be available only when
3495 one or more command-line options were used.
3497 The GNU Fortran @emph{language} is distinct from the
3498 GNU Fortran @emph{compilation system} (@code{g77}).
3500 For example, @code{g77} supports various dialects of
3501 Fortran---in a sense, these are languages other than
3502 GNU Fortran---though its primary
3503 purpose is to support the GNU Fortran language, which also is
3504 described in its documentation and by its implementation.
3506 On the other hand, non-GNU compilers might offer
3507 support for the GNU Fortran language, and are encouraged
3508 to do so.
3510 Currently, the GNU Fortran language is a fairly fuzzy object.
3511 It represents something of a cross between what @code{g77} accepts
3512 when compiling using the prevailing defaults and what this
3513 document describes as being part of the language.
3515 Future versions of @code{g77} are expected to clarify the
3516 definition of the language in the documentation.
3517 Often, this will mean adding new features to the language, in the form
3518 of both new documentation and new support in @code{g77}.
3519 However, it might occasionally mean removing a feature
3520 from the language itself to ``dialect'' status.
3521 In such a case, the documentation would be adjusted
3522 to reflect the change, and @code{g77} itself would likely be changed
3523 to require one or more command-line options to continue supporting
3524 the feature.
3526 The development of the GNU Fortran language is intended to strike
3527 a balance between:
3529 @itemize @bullet
3530 @item
3531 Serving as a mostly-upwards-compatible language from the
3532 de facto UNIX Fortran dialect as supported by @code{f77}.
3534 @item
3535 Offering new, well-designed language features.
3536 Attributes of such features include
3537 not making existing code any harder to read
3538 (for those who might be unaware that the new
3539 features are not in use) and
3540 not making state-of-the-art
3541 compilers take longer to issue diagnostics,
3542 among others.
3544 @item
3545 Supporting existing, well-written code without gratuitously
3546 rejecting non-standard constructs, regardless of the origin
3547 of the code (its dialect).
3549 @item
3550 Offering default behavior and command-line options to reduce
3551 and, where reasonable, eliminate the need for programmers to make
3552 any modifications to code that already works in existing
3553 production environments.
3555 @item
3556 Diagnosing constructs that have different meanings in different
3557 systems, languages, and dialects, while offering clear,
3558 less ambiguous ways to express each of the different meanings
3559 so programmers can change their code appropriately.
3560 @end itemize
3562 One of the biggest practical challenges for the developers of the
3563 GNU Fortran language is meeting the sometimes contradictory demands
3564 of the above items.
3566 For example, a feature might be widely used in one popular environment,
3567 but the exact same code that utilizes that feature might not work
3568 as expected---perhaps it might mean something entirely different---in
3569 another popular environment.
3571 Traditionally, Fortran compilers---even portable ones---have solved this
3572 problem by simply offering the appropriate feature to users of
3573 the respective systems.
3574 This approach treats users of various Fortran systems and dialects
3575 as remote ``islands'', or camps, of programmers, and assume that these
3576 camps rarely come into contact with each other (or,
3577 especially, with each other's code).
3579 Project GNU takes a radically different approach to software and language
3580 design, in that it assumes that users of GNU software do not necessarily
3581 care what kind of underlying system they are using, regardless
3582 of whether they are using software (at the user-interface
3583 level) or writing it (for example, writing Fortran or C code).
3585 As such, GNU users rarely need consider just what kind of underlying
3586 hardware (or, in many cases, operating system) they are using at any
3587 particular time.
3588 They can use and write software designed for a general-purpose,
3589 widely portable, heterogenous environment---the GNU environment.
3591 In line with this philosophy, GNU Fortran must evolve into a product
3592 that is widely ported and portable not only in the sense that it can
3593 be successfully built, installed, and run by users, but in the larger
3594 sense that its users can use it in the same way, and expect largely the
3595 same behaviors from it, regardless of the kind of system they are using
3596 at any particular time.
3598 This approach constrains the solutions @code{g77} can use to resolve
3599 conflicts between various camps of Fortran users.
3600 If these two camps disagree about what a particular construct should
3601 mean, @code{g77} cannot simply be changed to treat that particular construct as
3602 having one meaning without comment (such as a warning), lest the users
3603 expecting it to have the other meaning are unpleasantly surprised that
3604 their code misbehaves when executed.
3606 The use of the ASCII backslash character in character constants is
3607 an excellent (and still somewhat unresolved) example of this kind of
3608 controversy.
3609 @xref{Backslash in Constants}.
3610 Other examples are likely to arise in the future, as @code{g77} developers
3611 strive to improve its ability to accept an ever-wider variety of existing
3612 Fortran code without requiring significant modifications to said code.
3614 Development of GNU Fortran is further constrained by the desire
3615 to avoid requiring programmers to change their code.
3616 This is important because it allows programmers, administrators,
3617 and others to more faithfully evaluate and validate @code{g77}
3618 (as an overall product and as new versions are distributed)
3619 without having to support multiple versions of their programs
3620 so that they continue to work the same way on their existing
3621 systems (non-GNU perhaps, but possibly also earlier versions
3622 of @code{g77}).
3624 @node Standard Support
3625 @section ANSI FORTRAN 77 Standard Support
3626 @cindex ANSI FORTRAN 77 support
3627 @cindex standard, support for
3628 @cindex support, FORTRAN 77
3629 @cindex compatibility, FORTRAN 77
3630 @cindex FORTRAN 77 compatibility
3632 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
3633 In summary, the only ANSI FORTRAN 77 features @code{g77} doesn't
3634 support are those that are probably rarely used in actual code,
3635 some of which are explicitly disallowed by the Fortran 90 standard.
3637 @menu
3638 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
3639 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
3640 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
3641 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
3642 @end menu
3644 @node No Passing External Assumed-length
3645 @subsection No Passing External Assumed-length
3647 @code{g77} disallows passing of an external procedure
3648 as an actual argument if the procedure's
3649 type is declared @code{CHARACTER*(*)}.  For example:
3651 @example
3652 CHARACTER*(*) CFUNC
3653 EXTERNAL CFUNC
3654 CALL FOO(CFUNC)
3656 @end example
3658 @noindent
3659 It isn't clear whether the standard considers this conforming.
3661 @node No Passing Dummy Assumed-length
3662 @subsection No Passing Dummy Assumed-length
3664 @code{g77} disallows passing of a dummy procedure
3665 as an actual argument if the procedure's
3666 type is declared @code{CHARACTER*(*)}.
3668 @example
3669 SUBROUTINE BAR(CFUNC)
3670 CHARACTER*(*) CFUNC
3671 EXTERNAL CFUNC
3672 CALL FOO(CFUNC)
3674 @end example
3676 @noindent
3677 It isn't clear whether the standard considers this conforming.
3679 @node No Pathological Implied-DO
3680 @subsection No Pathological Implied-DO
3682 The @code{DO} variable for an implied-@code{DO} construct in a
3683 @code{DATA} statement may not be used as the @code{DO} variable
3684 for an outer implied-@code{DO} construct.  For example, this
3685 fragment is disallowed by @code{g77}:
3687 @smallexample
3688 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
3689 @end smallexample
3691 @noindent
3692 This also is disallowed by Fortran 90, as it offers no additional
3693 capabilities and would have a variety of possible meanings.
3695 Note that it is @emph{very} unlikely that any production Fortran code
3696 tries to use this unsupported construct.
3698 @node No Useless Implied-DO
3699 @subsection No Useless Implied-DO
3701 An array element initializer in an implied-@code{DO} construct in a
3702 @code{DATA} statement must contain at least one reference to the @code{DO}
3703 variables of each outer implied-@code{DO} construct.  For example,
3704 this fragment is disallowed by @code{g77}:
3706 @smallexample
3707 DATA (A, I= 1, 1) /1./
3708 @end smallexample
3710 @noindent
3711 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
3712 requirements offer no additional capabilities.
3713 However, @code{g77} doesn't necessarily diagnose all cases
3714 where this requirement is not met.
3716 Note that it is @emph{very} unlikely that any production Fortran code
3717 tries to use this unsupported construct.
3719 @node Conformance
3720 @section Conformance
3722 (The following information augments or overrides the information in
3723 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3724 language.
3725 Chapter 1 of that document otherwise serves as the basis
3726 for the relevant aspects of GNU Fortran.)
3728 The definition of the GNU Fortran language is akin to that of
3729 the ANSI FORTRAN 77 language in that it does not generally require
3730 conforming implementations to diagnose cases where programs do
3731 not conform to the language.
3733 However, @code{g77} as a compiler is being developed in a way that
3734 is intended to enable it to diagnose such cases in an easy-to-understand
3735 manner.
3737 A program that conforms to the GNU Fortran language should, when
3738 compiled, linked, and executed using a properly installed @code{g77}
3739 system, perform as described by the GNU Fortran language definition.
3740 Reasons for different behavior include, among others:
3742 @itemize @bullet
3743 @item
3744 Use of resources (memory---heap, stack, and so on; disk space; CPU
3745 time; etc.) exceeds those of the system.
3747 @item
3748 Range and/or precision of calculations required by the program
3749 exceeds that of the system.
3751 @item
3752 Excessive reliance on behaviors that are system-dependent
3753 (non-portable Fortran code).
3755 @item
3756 Bugs in the program.
3758 @item
3759 Bug in @code{g77}.
3761 @item
3762 Bugs in the system.
3763 @end itemize
3765 Despite these ``loopholes'', the availability of a clear specification
3766 of the language of programs submitted to @code{g77}, as this document
3767 is intended to provide, is considered an important aspect of providing
3768 a robust, clean, predictable Fortran implementation.
3770 The definition of the GNU Fortran language, while having no special
3771 legal status, can therefore be viewed as a sort of contract, or agreement.
3772 This agreement says, in essence, ``if you write a program in this language,
3773 and run it in an environment (such as a @code{g77} system) that supports
3774 this language, the program should behave in a largely predictable way''.
3776 @node Notation Used
3777 @section Notation Used in This Chapter
3779 (The following information augments or overrides the information in
3780 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3781 language.
3782 Chapter 1 of that document otherwise serves as the basis
3783 for the relevant aspects of GNU Fortran.)
3785 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
3786 and ``must not'' and ``may not'' denote prohibition.
3787 Terms such as ``might'', ``should'', and ``can'' generally add little or
3788 nothing in the way of weight to the GNU Fortran language itself,
3789 but are used to explain or illustrate the language.
3791 For example:
3793 @display
3794 ``The @code{FROBNITZ} statement must precede all executable
3795 statements in a program unit, and may not specify any dummy
3796 arguments.  It may specify local or common variables and arrays.
3797 Its use should be limited to portions of the program designed to
3798 be non-portable and system-specific, because it might cause the
3799 containing program unit to behave quite differently on different
3800 systems.''
3801 @end display
3803 Insofar as the GNU Fortran language is specified,
3804 the requirements and permissions denoted by the above sample statement
3805 are limited to the placement of the statement and the kinds of
3806 things it may specify.
3807 The rest of the statement---the content regarding non-portable portions
3808 of the program and the differing behavior of program units containing
3809 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
3810 language itself.
3811 That content offers advice and warnings about the @code{FROBNITZ}
3812 statement.
3814 @emph{Remember:} The GNU Fortran language definition specifies
3815 both what constitutes a valid GNU Fortran program and how,
3816 given such a program, a valid GNU Fortran implementation is
3817 to interpret that program.
3819 It is @emph{not} incumbent upon a valid GNU Fortran implementation
3820 to behave in any particular way, any consistent way, or any
3821 predictable way when it is asked to interpret input that is
3822 @emph{not} a valid GNU Fortran program.
3824 Such input is said to have @dfn{undefined} behavior when
3825 interpreted by a valid GNU Fortran implementation, though
3826 an implementation may choose to specify behaviors for some
3827 cases of inputs that are not valid GNU Fortran programs.
3829 Other notation used herein is that of the GNU texinfo format,
3830 which is used to generate printed hardcopy, on-line hypertext
3831 (Info), and on-line HTML versions, all from a single source
3832 document.
3833 This notation is used as follows:
3835 @itemize @bullet
3836 @item
3837 Keywords defined by the GNU Fortran language are shown
3838 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
3839 @code{BLOCK DATA}.
3841 Note that, in practice, many Fortran programs are written
3842 in lowercase---uppercase is used in this manual as a
3843 means to readily distinguish keywords and sample Fortran-related
3844 text from the prose in this document.
3846 @item
3847 Portions of actual sample program, input, or output text
3848 look like this: @samp{Actual program text}.
3850 Generally, uppercase is used for all Fortran-specific and
3851 Fortran-related text, though this does not always include
3852 literal text within Fortran code.
3854 For example: @samp{PRINT *, 'My name is Bob'}.
3856 @item
3857 A metasyntactic variable---that is, a name used in this document
3858 to serve as a placeholder for whatever text is used by the
3859 user or programmer---appears as shown in the following example:
3861 ``The @code{INTEGER @var{ivar}} statement specifies that
3862 @var{ivar} is a variable or array of type @code{INTEGER}.''
3864 In the above example, any valid text may be substituted for
3865 the metasyntactic variable @var{ivar} to make the statement
3866 apply to a specific instance, as long as the same text is
3867 substituted for @emph{both} occurrences of @var{ivar}.
3869 @item
3870 Ellipses (``@dots{}'') are used to indicate further text that
3871 is either unimportant or expanded upon further, elsewhere.
3873 @item
3874 Names of data types are in the style of Fortran 90, in most
3875 cases.
3877 @xref{Kind Notation}, for information on the relationship
3878 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
3879 and the more traditional, less portably concise nomenclature
3880 (such as @code{INTEGER*4}).
3881 @end itemize
3883 @node Terms and Concepts
3884 @section Fortran Terms and Concepts
3886 (The following information augments or overrides the information in
3887 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3888 language.
3889 Chapter 2 of that document otherwise serves as the basis
3890 for the relevant aspects of GNU Fortran.)
3892 @menu
3893 * Syntactic Items::
3894 * Statements Comments Lines::
3895 * Scope of Names and Labels::
3896 @end menu
3898 @node Syntactic Items
3899 @subsection Syntactic Items
3901 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
3903 @cindex limits, lengths of names
3904 In GNU Fortran, a symbolic name is at least one character long,
3905 and has no arbitrary upper limit on length.
3906 However, names of entities requiring external linkage (such as
3907 external functions, external subroutines, and @code{COMMON} areas)
3908 might be restricted to some arbitrary length by the system.
3909 Such a restriction is no more constrained than that of one
3910 through six characters.
3912 Underscores (@samp{_}) are accepted in symbol names after the first
3913 character (which must be a letter).
3915 @node Statements Comments Lines
3916 @subsection Statements, Comments, and Lines
3918 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
3920 @cindex trailing comment
3921 @cindex comment
3922 @cindex characters, comment
3923 @cindex !
3924 @cindex exclamation point
3925 @cindex continuation character
3926 @cindex characters, continuation
3927 Use of an exclamation point (@samp{!}) to begin a
3928 trailing comment (a comment that extends to the end of the same
3929 source line) is permitted under the following conditions:
3931 @itemize @bullet
3932 @item
3933 The exclamation point does not appear in column 6.
3934 Otherwise, it is treated as an indicator of a continuation
3935 line.
3937 @item
3938 The exclamation point appears outside a character or Hollerith
3939 constant.
3940 Otherwise, the exclamation point is considered part of the
3941 constant.
3943 @item
3944 The exclamation point appears to the left of any other possible
3945 trailing comment.
3946 That is, a trailing comment may contain exclamation points
3947 in their commentary text.
3948 @end itemize
3950 @cindex ;
3951 @cindex semicolon
3952 @cindex statements, separated by semicolon
3953 Use of a semicolon (@samp{;}) as a statement separator
3954 is permitted under the following conditions:
3956 @itemize @bullet
3957 @item
3958 The semicolon appears outside a character or Hollerith
3959 constant.
3960 Otherwise, the semicolon is considered part of the
3961 constant.
3963 @item
3964 The semicolon appears to the left of a trailing comment.
3965 Otherwise, the semicolon is considered part of that
3966 comment.
3968 @item
3969 Neither a logical @code{IF} statement nor a non-construct
3970 @code{WHERE} statement (a Fortran 90 feature) may be
3971 followed (in the same, possibly continued, line) by
3972 a semicolon used as a statement separator.
3974 This restriction avoids the confusion
3975 that can result when reading a line such as:
3977 @smallexample
3978 IF (VALIDP) CALL FOO; CALL BAR
3979 @end smallexample
3981 @noindent
3982 Some readers might think the @samp{CALL BAR} is executed
3983 only if @samp{VALIDP} is @code{.TRUE.}, while others might
3984 assume its execution is unconditional.
3986 (At present, @code{g77} does not diagnose code that
3987 violates this restriction.)
3988 @end itemize
3990 @node Scope of Names and Labels
3991 @subsection Scope of Symbolic Names and Statement Labels
3992 @cindex scope
3994 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
3996 Included in the list of entities that have a scope of a
3997 program unit are construct names (a Fortran 90 feature).
3998 @xref{Construct Names}, for more information.
4000 @node Characters Lines Sequence
4001 @section Characters, Lines, and Execution Sequence
4003 (The following information augments or overrides the information in
4004 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4005 language.
4006 Chapter 3 of that document otherwise serves as the basis
4007 for the relevant aspects of GNU Fortran.)
4009 @menu
4010 * Character Set::
4011 * Lines::
4012 * Continuation Line::
4013 * Statements::
4014 * Statement Labels::
4015 * Order::
4016 * INCLUDE::
4017 * Cpp-style directives::
4018 @end menu
4020 @node Character Set
4021 @subsection GNU Fortran Character Set
4022 @cindex characters
4024 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
4026 Letters include uppercase letters (the twenty-six characters
4027 of the English alphabet) and lowercase letters (their lowercase
4028 equivalent).
4029 Generally, lowercase letters may be used in place of uppercase
4030 letters, though in character and Hollerith constants, they
4031 are distinct.
4033 Special characters include:
4035 @itemize @bullet
4036 @item
4037 @cindex ;
4038 @cindex semicolon
4039 Semicolon (@samp{;})
4041 @item
4042 @cindex !
4043 @cindex exclamation point
4044 Exclamation point (@samp{!})
4046 @item
4047 @cindex "
4048 @cindex double quote
4049 Double quote (@samp{"})
4051 @item
4052 @cindex \
4053 @cindex backslash
4054 Backslash (@samp{\})
4056 @item
4057 @cindex ?
4058 @cindex question mark
4059 Question mark (@samp{?})
4061 @item
4062 @cindex #
4063 @cindex hash mark
4064 @cindex pound sign
4065 Hash mark (@samp{#})
4067 @item
4068 @cindex &
4069 @cindex ampersand
4070 Ampersand (@samp{&})
4072 @item
4073 @cindex %
4074 @cindex percent sign
4075 Percent sign (@samp{%})
4077 @item
4078 @cindex _
4079 @cindex underscore
4080 Underscore (@samp{_})
4082 @item
4083 @cindex <
4084 @cindex open angle
4085 @cindex left angle
4086 @cindex open bracket
4087 @cindex left bracket
4088 Open angle (@samp{<})
4090 @item
4091 @cindex >
4092 @cindex close angle
4093 @cindex right angle
4094 @cindex close bracket
4095 @cindex right bracket
4096 Close angle (@samp{>})
4098 @item
4099 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
4100 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
4101 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
4102 and @samp{:})
4103 @end itemize
4105 @cindex blank
4106 @cindex space
4107 @cindex SPC
4108 Note that this document refers to @key{SPC} as @dfn{space},
4109 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
4111 @node Lines
4112 @subsection Lines
4113 @cindex lines
4114 @cindex source file format
4115 @cindex source format
4116 @cindex file, source
4117 @cindex source code
4118 @cindex code, source
4119 @cindex fixed form
4120 @cindex free form
4122 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
4124 The way a Fortran compiler views source files depends entirely on the
4125 implementation choices made for the compiler, since those choices
4126 are explicitly left to the implementation by the published Fortran
4127 standards.
4129 The GNU Fortran language mandates a view applicable to UNIX-like
4130 text files---files that are made up of an arbitrary number of lines,
4131 each with an arbitrary number of characters (sometimes called stream-based
4132 files).
4134 This view does not apply to types of files that are specified as
4135 having a particular number of characters on every single line (sometimes
4136 referred to as record-based files).
4138 Because a ``line in a program unit is a sequence of 72 characters'',
4139 to quote X3.9-1978, the GNU Fortran language specifies that a
4140 stream-based text file is translated to GNU Fortran lines as follows:
4142 @itemize @bullet
4143 @item
4144 A newline in the file is the character that represents the end of
4145 a line of text to the underlying system.
4146 For example, on ASCII-based systems, a newline is the @key{NL}
4147 character, which has ASCII value 10 (decimal).
4149 @item
4150 Each newline in the file serves to end the line of text that precedes
4151 it (and that does not contain a newline).
4153 @item
4154 The end-of-file marker (@code{EOF}) also serves to end the line
4155 of text that precedes it (and that does not contain a newline).
4157 @item
4158 @cindex blank
4159 @cindex space
4160 @cindex SPC
4161 Any line of text that is shorter than 72 characters is padded to that length
4162 with spaces (called ``blanks'' in the standard).
4164 @item
4165 Any line of text that is longer than 72 characters is truncated to that
4166 length, but the truncated remainder must consist entirely of spaces.
4168 @item
4169 Characters other than newline and the GNU Fortran character set
4170 are invalid.
4171 @end itemize
4173 For the purposes of the remainder of this description of the GNU
4174 Fortran language, the translation described above has already
4175 taken place, unless otherwise specified.
4177 The result of the above translation is that the source file appears,
4178 in terms of the remainder of this description of the GNU Fortran language,
4179 as if it had an arbitrary
4180 number of 72-character lines, each character being among the GNU Fortran
4181 character set.
4183 For example, if the source file itself has two newlines in a row,
4184 the second newline becomes, after the above translation, a single
4185 line containing 72 spaces.
4187 @node Continuation Line
4188 @subsection Continuation Line
4189 @cindex continuation line, number of
4190 @cindex lines, continuation
4191 @cindex number of continuation lines
4192 @cindex limits, continuation lines
4194 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
4196 A continuation line is any line that both
4198 @itemize @bullet
4199 @item
4200 Contains a continuation character, and
4202 @item
4203 Contains only spaces in columns 1 through 5
4204 @end itemize
4206 A continuation character is any character of the GNU Fortran character set
4207 other than space (@key{SPC}) or zero (@samp{0})
4208 in column 6, or a digit (@samp{0} through @samp{9}) in column
4209 7 through 72 of a line that has only spaces to the left of that
4210 digit.
4212 The continuation character is ignored as far as the content of
4213 the statement is concerned.
4215 The GNU Fortran language places no limit on the number of
4216 continuation lines in a statement.
4217 In practice, the limit depends on a variety of factors, such as
4218 available memory, statement content, and so on, but no
4219 GNU Fortran system may impose an arbitrary limit.
4221 @node Statements
4222 @subsection Statements
4224 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
4226 Statements may be written using an arbitrary number of continuation
4227 lines.
4229 Statements may be separated using the semicolon (@samp{;}), except
4230 that the logical @code{IF} and non-construct @code{WHERE} statements
4231 may not be separated from subsequent statements using only a semicolon
4232 as statement separator.
4234 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
4235 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
4236 statement.
4237 These alternatives may be written as normal statements---they are not
4238 subject to the restrictions of the @code{END} statement.
4240 However, no statement other than @code{END} may have an initial line
4241 that appears to be an @code{END} statement---even @code{END PROGRAM},
4242 for example, must not be written as:
4244 @example
4245       END
4246      &PROGRAM
4247 @end example
4249 @node Statement Labels
4250 @subsection Statement Labels
4252 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
4254 A statement separated from its predecessor via a semicolon may be
4255 labeled as follows:
4257 @itemize @bullet
4258 @item
4259 The semicolon is followed by the label for the statement,
4260 which in turn follows the label.
4262 @item
4263 The label must be no more than five digits in length.
4265 @item
4266 The first digit of the label for the statement is not
4267 the first non-space character on a line.
4268 Otherwise, that character is treated as a continuation
4269 character.
4270 @end itemize
4272 A statement may have only one label defined for it.
4274 @node Order
4275 @subsection Order of Statements and Lines
4277 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
4279 Generally, @code{DATA} statements may precede executable statements.
4280 However, specification statements pertaining to any entities
4281 initialized by a @code{DATA} statement must precede that @code{DATA}
4282 statement.
4283 For example,
4284 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
4285 @samp{INTEGER J} is permitted.
4287 The last line of a program unit may be an @code{END} statement,
4288 or may be:
4290 @itemize @bullet
4291 @item
4292 An @code{END PROGRAM} statement, if the program unit is a main program.
4294 @item
4295 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
4297 @item
4298 An @code{END FUNCTION} statement, if the program unit is a function.
4300 @item
4301 An @code{END BLOCK DATA} statement, if the program unit is a block data.
4302 @end itemize
4304 @node INCLUDE
4305 @subsection Including Source Text
4306 @cindex INCLUDE directive
4308 Additional source text may be included in the processing of
4309 the source file via the @code{INCLUDE} directive:
4311 @example
4312 INCLUDE @var{filename}
4313 @end example
4315 @noindent
4316 The source text to be included is identified by @var{filename},
4317 which is a literal GNU Fortran character constant.
4318 The meaning and interpretation of @var{filename} depends on the
4319 implementation, but typically is a filename.
4321 (@code{g77} treats it as a filename that it searches for
4322 in the current directory and/or directories specified
4323 via the @samp{-I} command-line option.)
4325 The effect of the @code{INCLUDE} directive is as if the
4326 included text directly replaced the directive in the source
4327 file prior to interpretation of the program.
4328 Included text may itself use @code{INCLUDE}.
4329 The depth of nested @code{INCLUDE} references depends on
4330 the implementation, but typically is a positive integer.
4332 This virtual replacement treats the statements and @code{INCLUDE}
4333 directives in the included text as syntactically distinct from
4334 those in the including text.
4336 Therefore, the first non-comment line of the included text
4337 must not be a continuation line.
4338 The included text must therefore have, after the non-comment
4339 lines, either an initial line (statement), an @code{INCLUDE}
4340 directive, or nothing (the end of the included text).
4342 Similarly, the including text may end the @code{INCLUDE}
4343 directive with a semicolon or the end of the line, but it
4344 cannot follow an @code{INCLUDE} directive at the end of its
4345 line with a continuation line.
4346 Thus, the last statement in an included text may not be
4347 continued.
4349 Any statements between two @code{INCLUDE} directives on the
4350 same line are treated as if they appeared in between the
4351 respective included texts.
4352 For example:
4354 @smallexample
4355 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
4356 @end smallexample
4358 @noindent
4359 If the text included by @samp{INCLUDE 'A'} constitutes
4360 a @samp{PRINT *, 'A'} statement and the text included by
4361 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
4362 then the output of the above sample program would be
4364 @example
4368 @end example
4370 @noindent
4371 (with suitable allowances for how an implementation defines
4372 its handling of output).
4374 Included text must not include itself directly or indirectly,
4375 regardless of whether the @var{filename} used to reference
4376 the text is the same.
4378 Note that @code{INCLUDE} is @emph{not} a statement.
4379 As such, it is neither a non-executable or executable
4380 statement.
4381 However, if the text it includes constitutes one or more
4382 executable statements, then the placement of @code{INCLUDE}
4383 is subject to effectively the same restrictions as those
4384 on executable statements.
4386 An @code{INCLUDE} directive may be continued across multiple
4387 lines as if it were a statement.
4388 This permits long names to be used for @var{filename}.
4390 @node Cpp-style directives
4391 @subsection Cpp-style directives
4392 @cindex #
4393 @cindex preprocessor
4395 @code{cpp} output-style @code{#} directives
4396 (@pxref{C Preprocessor Output,,, cpp, The C Preprocessor})
4397 are recognized by the compiler even
4398 when the preprocessor isn't run on the input (as it is when compiling
4399 @samp{.F} files).  (Note the distinction between these @code{cpp}
4400 @code{#} @emph{output} directives and @code{#line} @emph{input}
4401 directives.)
4403 @node Data Types and Constants
4404 @section Data Types and Constants
4406 (The following information augments or overrides the information in
4407 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4408 language.
4409 Chapter 4 of that document otherwise serves as the basis
4410 for the relevant aspects of GNU Fortran.)
4412 To more concisely express the appropriate types for
4413 entities, this document uses the more concise
4414 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
4415 instead of the more traditional, but less portably concise,
4416 byte-size-based nomenclature such as @code{INTEGER*4},
4417 wherever reasonable.
4419 When referring to generic types---in contexts where the
4420 specific precision and range of a type are not important---this
4421 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
4422 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
4424 In some cases, the context requires specification of a
4425 particular type.
4426 This document uses the @samp{KIND=} notation to accomplish
4427 this throughout, sometimes supplying the more traditional
4428 notation for clarification, though the traditional notation
4429 might not work the same way on all GNU Fortran implementations.
4431 Use of @samp{KIND=} makes this document more concise because
4432 @code{g77} is able to define values for @samp{KIND=} that
4433 have the same meanings on all systems, due to the way the
4434 Fortran 90 standard specifies these values are to be used.
4436 (In particular, that standard permits an implementation to
4437 arbitrarily assign nonnegative values.
4438 There are four distinct sets of assignments: one to the @code{CHARACTER}
4439 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
4440 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
4441 Implementations are free to assign these values in any order,
4442 leave gaps in the ordering of assignments, and assign more than
4443 one value to a representation.)
4445 This makes @samp{KIND=} values superior to the values used
4446 in non-standard statements such as @samp{INTEGER*4}, because
4447 the meanings of the values in those statements vary from machine
4448 to machine, compiler to compiler, even operating system to
4449 operating system.
4451 However, use of @samp{KIND=} is @emph{not} generally recommended
4452 when writing portable code (unless, for example, the code is
4453 going to be compiled only via @code{g77}, which is a widely
4454 ported compiler).
4455 GNU Fortran does not yet have adequate language constructs to
4456 permit use of @samp{KIND=} in a fashion that would make the
4457 code portable to Fortran 90 implementations; and, this construct
4458 is known to @emph{not} be accepted by many popular FORTRAN 77
4459 implementations, so it cannot be used in code that is to be ported
4460 to those.
4462 The distinction here is that this document is able to use
4463 specific values for @samp{KIND=} to concisely document the
4464 types of various operations and operands.
4466 A Fortran program should use the FORTRAN 77 designations for the
4467 appropriate GNU Fortran types---such as @code{INTEGER} for
4468 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
4469 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
4470 where no such designations exist, make use of appropriate
4471 techniques (preprocessor macros, parameters, and so on)
4472 to specify the types in a fashion that may be easily adjusted
4473 to suit each particular implementation to which the program
4474 is ported.
4475 (These types generally won't need to be adjusted for ports of
4476 @code{g77}.)
4478 Further details regarding GNU Fortran data types and constants
4479 are provided below.
4481 @menu
4482 * Types::
4483 * Constants::
4484 * Integer Type::
4485 * Character Type::
4486 @end menu
4488 @node Types
4489 @subsection Data Types
4491 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
4493 GNU Fortran supports these types:
4495 @enumerate
4496 @item
4497 Integer (generic type @code{INTEGER})
4499 @item
4500 Real (generic type @code{REAL})
4502 @item
4503 Double precision
4505 @item
4506 Complex (generic type @code{COMPLEX})
4508 @item
4509 Logical (generic type @code{LOGICAL})
4511 @item
4512 Character (generic type @code{CHARACTER})
4514 @item
4515 Double Complex
4516 @end enumerate
4518 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
4520 The generic types shown above are referred to in this document
4521 using only their generic type names.
4522 Such references usually indicate that any specific type (kind)
4523 of that generic type is valid.
4525 For example, a context described in this document as accepting
4526 the @code{COMPLEX} type also is likely to accept the
4527 @code{DOUBLE COMPLEX} type.
4529 The GNU Fortran language supports three ways to specify
4530 a specific kind of a generic type.
4532 @menu
4533 * Double Notation::  As in @code{DOUBLE COMPLEX}.
4534 * Star Notation::    As in @code{INTEGER*4}.
4535 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
4536 @end menu
4538 @node Double Notation
4539 @subsubsection Double Notation
4541 The GNU Fortran language supports two uses of the keyword
4542 @code{DOUBLE} to specify a specific kind of type:
4544 @itemize @bullet
4545 @item
4546 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
4548 @item
4549 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
4550 @end itemize
4552 Use one of the above forms where a type name is valid.
4554 While use of this notation is popular, it doesn't scale
4555 well in a language or dialect rich in intrinsic types,
4556 as is the case for the GNU Fortran language (especially
4557 planned future versions of it).
4559 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
4560 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
4561 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
4562 often are substituted for these, respectively, even though they
4563 do not always have the same meanings on all systems.
4564 (And, the fact that @samp{DOUBLE REAL} does not exist as such
4565 is an inconsistency.)
4567 Therefore, this document uses ``double notation'' only on occasion
4568 for the benefit of those readers who are accustomed to it.
4570 @node Star Notation
4571 @subsubsection Star Notation
4572 @cindex *@var{n} notation
4574 The following notation specifies the storage size for a type:
4576 @smallexample
4577 @var{generic-type}*@var{n}
4578 @end smallexample
4580 @noindent
4581 @var{generic-type} must be a generic type---one of
4582 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4583 or @code{CHARACTER}.
4584 @var{n} must be one or more digits comprising a decimal
4585 integer number greater than zero.
4587 Use the above form where a type name is valid.
4589 The @samp{*@var{n}} notation specifies that the amount of storage
4590 occupied by variables and array elements of that type is @var{n}
4591 times the storage occupied by a @code{CHARACTER*1} variable.
4593 This notation might indicate a different degree of precision and/or
4594 range for such variables and array elements, and the functions that
4595 return values of types using this notation.
4596 It does not limit the precision or range of values of that type
4597 in any particular way---use explicit code to do that.
4599 Further, the GNU Fortran language requires no particular values
4600 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
4601 notation.
4602 @code{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
4603 on all systems, for example,
4604 but not all implementations are required to do so, and @code{g77}
4605 is known to not support @code{REAL*1} on most (or all) systems.
4607 As a result, except for @var{generic-type} of @code{CHARACTER},
4608 uses of this notation should be limited to isolated
4609 portions of a program that are intended to handle system-specific
4610 tasks and are expected to be non-portable.
4612 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
4613 only @code{CHARACTER}, where it signifies not only the amount
4614 of storage occupied, but the number of characters in entities
4615 of that type.
4616 However, almost all Fortran compilers have supported this
4617 notation for generic types, though with a variety of meanings
4618 for @var{n}.)
4620 Specifications of types using the @samp{*@var{n}} notation
4621 always are interpreted as specifications of the appropriate
4622 types described in this document using the @samp{KIND=@var{n}}
4623 notation, described below.
4625 While use of this notation is popular, it doesn't serve well
4626 in the context of a widely portable dialect of Fortran, such as
4627 the GNU Fortran language.
4629 For example, even on one particular machine, two or more popular
4630 Fortran compilers might well disagree on the size of a type
4631 declared @code{INTEGER*2} or @code{REAL*16}.
4632 Certainly there
4633 is known to be disagreement over such things among Fortran
4634 compilers on @emph{different} systems.
4636 Further, this notation offers no elegant way to specify sizes
4637 that are not even multiples of the ``byte size'' typically
4638 designated by @code{INTEGER*1}.
4639 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
4640 certainly be possible, but would perhaps be stretching the original
4641 intent of this notation beyond the breaking point in terms
4642 of widespread readability of documentation and code making use
4643 of it.
4645 Therefore, this document uses ``star notation'' only on occasion
4646 for the benefit of those readers who are accustomed to it.
4648 @node Kind Notation
4649 @subsubsection Kind Notation
4650 @cindex KIND= notation
4652 The following notation specifies the kind-type selector of a type:
4654 @smallexample
4655 @var{generic-type}(KIND=@var{n})
4656 @end smallexample
4658 @noindent
4659 Use the above form where a type name is valid.
4661 @var{generic-type} must be a generic type---one of
4662 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4663 or @code{CHARACTER}.
4664 @var{n} must be an integer initialization expression that
4665 is a positive, nonzero value.
4667 Programmers are discouraged from writing these values directly
4668 into their code.
4669 Future versions of the GNU Fortran language will offer
4670 facilities that will make the writing of code portable
4671 to @code{g77} @emph{and} Fortran 90 implementations simpler.
4673 However, writing code that ports to existing FORTRAN 77
4674 implementations depends on avoiding the @samp{KIND=} construct.
4676 The @samp{KIND=} construct is thus useful in the context
4677 of GNU Fortran for two reasons:
4679 @itemize @bullet
4680 @item
4681 It provides a means to specify a type in a fashion that
4682 is portable across all GNU Fortran implementations (though
4683 not other FORTRAN 77 and Fortran 90 implementations).
4685 @item
4686 It provides a sort of Rosetta stone for this document to use
4687 to concisely describe the types of various operations and
4688 operands.
4689 @end itemize
4691 The values of @var{n} in the GNU Fortran language are
4692 assigned using a scheme that:
4694 @itemize @bullet
4695 @item
4696 Attempts to maximize the ability of readers
4697 of this document to quickly familiarize themselves
4698 with assignments for popular types
4700 @item
4701 Provides a unique value for each specific desired
4702 meaning
4704 @item
4705 Provides a means to automatically assign new values so
4706 they have a ``natural'' relationship to existing values,
4707 if appropriate, or, if no such relationship exists, will
4708 not interfere with future values assigned on the basis
4709 of such relationships
4711 @item
4712 Avoids using values that are similar to values used
4713 in the existing, popular @samp{*@var{n}} notation,
4714 to prevent readers from expecting that these implied
4715 correspondences work on all GNU Fortran implementations
4716 @end itemize
4718 The assignment system accomplishes this by assigning
4719 to each ``fundamental meaning'' of a specific type a
4720 unique prime number.
4721 Combinations of fundamental meanings---for example, a type
4722 that is two times the size of some other type---are assigned
4723 values of @var{n} that are the products of the values for
4724 those fundamental meanings.
4726 A prime value of @var{n} is never given more than one fundamental
4727 meaning, to avoid situations where some code or system
4728 cannot reasonably provide those meanings in the form of a
4729 single type.
4731 The values of @var{n} assigned so far are:
4733 @table @code
4734 @item KIND=0
4735 This value is reserved for future use.
4737 The planned future use is for this value to designate,
4738 explicitly, context-sensitive kind-type selection.
4739 For example, the expression @samp{1D0 * 0.1_0} would
4740 be equivalent to @samp{1D0 * 0.1D0}.
4742 @item KIND=1
4743 This corresponds to the default types for
4744 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
4745 and @code{CHARACTER}, as appropriate.
4747 These are the ``default'' types described in the Fortran 90 standard,
4748 though that standard does not assign any particular @samp{KIND=}
4749 value to these types.
4751 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
4752 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
4754 @item KIND=2
4755 This corresponds to types that occupy twice as much
4756 storage as the default types.
4757 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
4758 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
4760 These are the ``double precision'' types described in the Fortran 90
4761 standard,
4762 though that standard does not assign any particular @samp{KIND=}
4763 value to these types.
4765 @var{n} of 4 thus corresponds to types that occupy four times
4766 as much storage as the default types, @var{n} of 8 to types that
4767 occupy eight times as much storage, and so on.
4769 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
4770 are not necessarily supported by every GNU Fortran implementation.
4772 @item KIND=3
4773 This corresponds to types that occupy as much
4774 storage as the default @code{CHARACTER} type,
4775 which is the same effective type as @code{CHARACTER(KIND=1)}
4776 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
4778 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
4780 @var{n} of 6 thus corresponds to types that occupy twice as
4781 much storage as the @var{n}=3 types, @var{n} of 12 to types
4782 that occupy four times as much storage, and so on.
4784 These are not necessarily supported by every GNU Fortran
4785 implementation.
4787 @item KIND=5
4788 This corresponds to types that occupy half the
4789 storage as the default (@var{n}=1) types.
4791 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
4793 @var{n} of 25 thus corresponds to types that occupy one-quarter
4794 as much storage as the default types.
4796 These are not necessarily supported by every GNU Fortran
4797 implementation.
4799 @item KIND=7
4800 @cindex pointers
4801 This is valid only as @code{INTEGER(KIND=7)} and
4802 denotes the @code{INTEGER} type that has the smallest
4803 storage size that holds a pointer on the system.
4805 A pointer representable by this type is capable of uniquely
4806 addressing a @code{CHARACTER*1} variable, array, array element,
4807 or substring.
4809 (Typically this is equivalent to @code{INTEGER*4} or,
4810 on 64-bit systems, @code{INTEGER*8}.
4811 In a compatible C implementation, it typically would
4812 be the same size and semantics of the C type @code{void *}.)
4813 @end table
4815 Note that these are @emph{proposed} correspondences and might change
4816 in future versions of @code{g77}---avoid writing code depending
4817 on them while @code{g77}, and therefore the GNU Fortran language
4818 it defines, is in beta testing.
4820 Values not specified in the above list are reserved to
4821 future versions of the GNU Fortran language.
4823 Implementation-dependent meanings will be assigned new,
4824 unique prime numbers so as to not interfere with other
4825 implementation-dependent meanings, and offer the possibility
4826 of increasing the portability of code depending on such
4827 types by offering support for them in other GNU Fortran
4828 implementations.
4830 Other meanings that might be given unique values are:
4832 @itemize @bullet
4833 @item
4834 Types that make use of only half their storage size for
4835 representing precision and range.
4837 For example, some compilers offer options that cause
4838 @code{INTEGER} types to occupy the amount of storage
4839 that would be needed for @code{INTEGER(KIND=2)} types, but the
4840 range remains that of @code{INTEGER(KIND=1)}.
4842 @item
4843 The IEEE single floating-point type.
4845 @item
4846 Types with a specific bit pattern (endianness), such as the
4847 little-endian form of @code{INTEGER(KIND=1)}.
4848 These could permit, conceptually, use of portable code and
4849 implementations on data files written by existing systems.
4850 @end itemize
4852 Future @emph{prime} numbers should be given meanings in as incremental
4853 a fashion as possible, to allow for flexibility and
4854 expressiveness in combining types.
4856 For example, instead of defining a prime number for little-endian
4857 IEEE doubles, one prime number might be assigned the meaning
4858 ``little-endian'', another the meaning ``IEEE double'', and the
4859 value of @var{n} for a little-endian IEEE double would thus
4860 naturally be the product of those two respective assigned values.
4861 (It could even be reasonable to have IEEE values result from the
4862 products of prime values denoting exponent and fraction sizes
4863 and meanings, hidden bit usage, availability and representations
4864 of special values such as subnormals, infinities, and Not-A-Numbers
4865 (NaNs), and so on.)
4867 This assignment mechanism, while not inherently required for
4868 future versions of the GNU Fortran language, is worth using
4869 because it could ease management of the ``space'' of supported
4870 types much easier in the long run.
4872 The above approach suggests a mechanism for specifying inheritance
4873 of intrinsic (built-in) types for an entire, widely portable
4874 product line.
4875 It is certainly reasonable that, unlike programmers of other languages
4876 offering inheritance mechanisms that employ verbose names for classes
4877 and subclasses, along with graphical browsers to elucidate the
4878 relationships, Fortran programmers would employ
4879 a mechanism that works by multiplying prime numbers together
4880 and finding the prime factors of such products.
4882 Most of the advantages for the above scheme have been explained
4883 above.
4884 One disadvantage is that it could lead to the defining,
4885 by the GNU Fortran language, of some fairly large prime numbers.
4886 This could lead to the GNU Fortran language being declared
4887 ``munitions'' by the United States Department of Defense.
4889 @node Constants
4890 @subsection Constants
4891 @cindex constants
4892 @cindex types, constants
4894 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
4896 A @dfn{typeless constant} has one of the following forms:
4898 @smallexample
4899 '@var{binary-digits}'B
4900 '@var{octal-digits}'O
4901 '@var{hexadecimal-digits}'Z
4902 '@var{hexadecimal-digits}'X
4903 @end smallexample
4905 @noindent
4906 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
4907 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
4908 and @samp{0123456789ABCDEFabcdef}, respectively.
4909 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
4910 is 11, and so on.)
4912 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
4913 treated as typeless.  @xref{Fortran Dialect Options,, Options
4914 Controlling Fortran Dialect}, for information on the
4915 @samp{-ftypeless-boz} option.
4917 Typeless constants have values that depend on the context in which
4918 they are used.
4920 All other constants, called @dfn{typed constants}, are interpreted---converted
4921 to internal form---according to their inherent type.
4922 Thus, context is @emph{never} a determining factor for the type, and hence
4923 the interpretation, of a typed constant.
4924 (All constants in the ANSI FORTRAN 77 language are typed constants.)
4926 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
4927 Fortran (called default INTEGER in Fortran 90),
4928 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
4929 additional precision specified is lost, and even when used in a
4930 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
4931 and @samp{1D0} is always type @code{REAL(KIND=2)}.
4933 @node Integer Type
4934 @subsection Integer Type
4936 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
4938 An integer constant also may have one of the following forms:
4940 @smallexample
4941 B'@var{binary-digits}'
4942 O'@var{octal-digits}'
4943 Z'@var{hexadecimal-digits}'
4944 X'@var{hexadecimal-digits}'
4945 @end smallexample
4947 @noindent
4948 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
4949 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
4950 and @samp{0123456789ABCDEFabcdef}, respectively.
4951 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
4952 is 11, and so on.)
4954 @node Character Type
4955 @subsection Character Type
4957 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
4959 @cindex double quoted character constants
4960 A character constant may be delimited by a pair of double quotes
4961 (@samp{"}) instead of apostrophes.
4962 In this case, an apostrophe within the constant represents
4963 a single apostrophe, while a double quote is represented in
4964 the source text of the constant by two consecutive double
4965 quotes with no intervening spaces.
4967 @cindex zero-length CHARACTER
4968 @cindex null CHARACTER strings
4969 @cindex empty CHARACTER strings
4970 @cindex strings, empty
4971 @cindex CHARACTER, null
4972 A character constant may be empty (have a length of zero).
4974 A character constant may include a substring specification,
4975 The value of such a constant is the value of the substring---for
4976 example, the value of @samp{'hello'(3:5)} is the same
4977 as the value of @samp{'llo'}.
4979 @node Expressions
4980 @section Expressions
4982 (The following information augments or overrides the information in
4983 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4984 language.
4985 Chapter 6 of that document otherwise serves as the basis
4986 for the relevant aspects of GNU Fortran.)
4988 @menu
4989 * %LOC()::
4990 @end menu
4992 @node %LOC()
4993 @subsection The @code{%LOC()} Construct
4994 @cindex %LOC() construct
4996 @example
4997 %LOC(@var{arg})
4998 @end example
5000 The @code{%LOC()} construct is an expression
5001 that yields the value of the location of its argument,
5002 @var{arg}, in memory.
5003 The size of the type of the expression depends on the system---typically,
5004 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
5005 though it is actually type @code{INTEGER(KIND=7)}.
5007 The argument to @code{%LOC()} must be suitable as the
5008 left-hand side of an assignment statement.
5009 That is, it may not be a general expression involving
5010 operators such as addition, subtraction, and so on,
5011 nor may it be a constant.
5013 Use of @code{%LOC()} is recommended only for code that
5014 is accessing facilities outside of GNU Fortran, such as
5015 operating system or windowing facilities.
5016 It is best to constrain such uses to isolated portions of
5017 a program---portions that deal specifically and exclusively
5018 with low-level, system-dependent facilities.
5019 Such portions might well provide a portable interface for
5020 use by the program as a whole, but are themselves not
5021 portable, and should be thoroughly tested each time they
5022 are rebuilt using a new compiler or version of a compiler.
5024 Do not depend on @code{%LOC()} returning a pointer that
5025 can be safely used to @emph{define} (change) the argument.
5026 While this might work in some circumstances, it is hard
5027 to predict whether it will continue to work when a program
5028 (that works using this unsafe behavior)
5029 is recompiled using different command-line options or
5030 a different version of @code{g77}.
5032 Generally, @code{%LOC()} is safe when used as an argument
5033 to a procedure that makes use of the value of the corresponding
5034 dummy argument only during its activation, and only when
5035 such use is restricted to referencing (reading) the value
5036 of the argument to @code{%LOC()}.
5038 @emph{Implementation Note:} Currently, @code{g77} passes
5039 arguments (those not passed using a construct such as @code{%VAL()})
5040 by reference or descriptor, depending on the type of
5041 the actual argument.
5042 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
5043 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
5044 in fact might compile to identical code.
5046 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
5047 ``pass, by value, the address of @samp{I} in memory''.
5048 While @samp{CALL FOO(I)} might use that same approach in a
5049 particular version of @code{g77}, another version or compiler
5050 might choose a different implementation, such as copy-in/copy-out,
5051 to effect the desired behavior---and which will therefore not
5052 necessarily compile to the same code as would
5053 @samp{CALL FOO(%VAL(%LOC(I)))}
5054 using the same version or compiler.
5056 @xref{Debugging and Interfacing}, for detailed information on
5057 how this particular version of @code{g77} implements various
5058 constructs.
5060 @node Specification Statements
5061 @section Specification Statements
5063 (The following information augments or overrides the information in
5064 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5065 language.
5066 Chapter 8 of that document otherwise serves as the basis
5067 for the relevant aspects of GNU Fortran.)
5069 @menu
5070 * NAMELIST::
5071 * DOUBLE COMPLEX::
5072 @end menu
5074 @node NAMELIST
5075 @subsection @code{NAMELIST} Statement
5076 @cindex NAMELIST statement
5077 @cindex statements, NAMELIST
5079 The @code{NAMELIST} statement, and related I/O constructs, are
5080 supported by the GNU Fortran language in essentially the same
5081 way as they are by @code{f2c}.
5083 This follows Fortran 90 with the restriction that on @code{NAMELIST}
5084 input, subscripts must have the form
5085 @smallexample
5086 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
5087 @end smallexample
5088 i.e.@:
5089 @smallexample
5090 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
5091 @end smallexample
5092 is allowed, but not, say,
5093 @smallexample
5094 &xx x(:3,8::2)=1,2,3,4,5,6/
5095 @end smallexample
5097 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
5098 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
5099 @smallexample
5100 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
5101 @end smallexample
5102 could be used instead of the example above.
5104 @node DOUBLE COMPLEX
5105 @subsection @code{DOUBLE COMPLEX} Statement
5106 @cindex DOUBLE COMPLEX
5108 @code{DOUBLE COMPLEX} is a type-statement (and type) that
5109 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
5111 @node Control Statements
5112 @section Control Statements
5114 (The following information augments or overrides the information in
5115 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5116 language.
5117 Chapter 11 of that document otherwise serves as the basis
5118 for the relevant aspects of GNU Fortran.)
5120 @menu
5121 * DO WHILE::
5122 * END DO::
5123 * Construct Names::
5124 * CYCLE and EXIT::
5125 @end menu
5127 @node DO WHILE
5128 @subsection DO WHILE
5129 @cindex DO WHILE
5130 @cindex DO
5131 @cindex MIL-STD 1753
5133 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
5134 Fortran 90 standards, is provided by the GNU Fortran language.
5135 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
5136 also supported.
5138 @node END DO
5139 @subsection END DO
5140 @cindex END DO
5141 @cindex MIL-STD 1753
5143 The @code{END DO} statement is provided by the GNU Fortran language.
5145 This statement is used in one of two ways:
5147 @itemize @bullet
5148 @item
5149 The Fortran 90 meaning, in which it specifies the termination
5150 point of a single @code{DO} loop started with a @code{DO} statement
5151 that specifies no termination label.
5153 @item
5154 The MIL-STD 1753 meaning, in which it specifies the termination
5155 point of one or more @code{DO} loops, all of which start with a
5156 @code{DO} statement that specify the label defined for the
5157 @code{END DO} statement.
5159 This kind of @code{END DO} statement is merely a synonym for
5160 @code{CONTINUE}, except it is permitted only when the statement
5161 is labeled and a target of one or more labeled @code{DO} loops.
5163 It is expected that this use of @code{END DO} will be removed from
5164 the GNU Fortran language in the future, though it is likely that
5165 it will long be supported by @code{g77} as a dialect form.
5166 @end itemize
5168 @node Construct Names
5169 @subsection Construct Names
5170 @cindex construct names
5172 The GNU Fortran language supports construct names as defined
5173 by the Fortran 90 standard.
5174 These names are local to the program unit and are defined
5175 as follows:
5177 @smallexample
5178 @var{construct-name}: @var{block-statement}
5179 @end smallexample
5181 @noindent
5182 Here, @var{construct-name} is the construct name itself;
5183 its definition is connoted by the single colon (@samp{:}); and
5184 @var{block-statement} is an @code{IF}, @code{DO},
5185 or @code{SELECT CASE} statement that begins a block.
5187 A block that is given a construct name must also specify the
5188 same construct name in its termination statement:
5190 @example
5191 END @var{block} @var{construct-name}
5192 @end example
5194 @noindent
5195 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
5196 as appropriate.
5198 @node CYCLE and EXIT
5199 @subsection The @code{CYCLE} and @code{EXIT} Statements
5201 @cindex CYCLE statement
5202 @cindex EXIT statement
5203 @cindex statements, CYCLE
5204 @cindex statements, EXIT
5205 The @code{CYCLE} and @code{EXIT} statements specify that
5206 the remaining statements in the current iteration of a
5207 particular active (enclosing) @code{DO} loop are to be skipped.
5209 @code{CYCLE} specifies that these statements are skipped,
5210 but the @code{END DO} statement that marks the end of the
5211 @code{DO} loop be executed---that is, the next iteration,
5212 if any, is to be started.
5213 If the statement marking the end of the @code{DO} loop is
5214 not @code{END DO}---in other words, if the loop is not
5215 a block @code{DO}---the @code{CYCLE} statement does not
5216 execute that statement, but does start the next iteration (if any).
5218 @code{EXIT} specifies that the loop specified by the
5219 @code{DO} construct is terminated.
5221 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
5222 is the innermost enclosing @code{DO} loop when the following
5223 forms are used:
5225 @example
5226 CYCLE
5227 EXIT
5228 @end example
5230 Otherwise, the following forms specify the construct name
5231 of the pertinent @code{DO} loop:
5233 @example
5234 CYCLE @var{construct-name}
5235 EXIT @var{construct-name}
5236 @end example
5238 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
5239 statements.
5240 However, they cannot be easily thought of as @code{GO TO} statements
5241 in obscure cases involving FORTRAN 77 loops.
5242 For example:
5244 @smallexample
5245       DO 10 I = 1, 5
5246       DO 10 J = 1, 5
5247          IF (J .EQ. 5) EXIT
5248       DO 10 K = 1, 5
5249          IF (K .EQ. 3) CYCLE
5250 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
5251 20    CONTINUE
5252 @end smallexample
5254 @noindent
5255 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
5256 above are equivalent to a @code{GO TO} statement to either label
5257 @samp{10} or @samp{20}.
5259 To understand the effect of @code{CYCLE} and @code{EXIT} in the
5260 above fragment, it is helpful to first translate it to its equivalent
5261 using only block @code{DO} loops:
5263 @smallexample
5264       DO I = 1, 5
5265          DO J = 1, 5
5266             IF (J .EQ. 5) EXIT
5267             DO K = 1, 5
5268                IF (K .EQ. 3) CYCLE
5269 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
5270             END DO
5271          END DO
5272       END DO
5273 20    CONTINUE
5274 @end smallexample
5276 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
5277 to @code{GO TO} so they may be more easily understood by programmers
5278 accustomed to FORTRAN coding:
5280 @smallexample
5281       DO I = 1, 5
5282          DO J = 1, 5
5283             IF (J .EQ. 5) GOTO 18
5284             DO K = 1, 5
5285                IF (K .EQ. 3) GO TO 12
5286 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
5287 12          END DO
5288          END DO
5289 18    END DO
5290 20    CONTINUE
5291 @end smallexample
5293 @noindent
5294 Thus, the @code{CYCLE} statement in the innermost loop skips over
5295 the @code{PRINT} statement as it begins the next iteration of the
5296 loop, while the @code{EXIT} statement in the middle loop ends that
5297 loop but @emph{not} the outermost loop.
5299 @node Functions and Subroutines
5300 @section Functions and Subroutines
5302 (The following information augments or overrides the information in
5303 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5304 language.
5305 Chapter 15 of that document otherwise serves as the basis
5306 for the relevant aspects of GNU Fortran.)
5308 @menu
5309 * %VAL()::
5310 * %REF()::
5311 * %DESCR()::
5312 * Generics and Specifics::
5313 * REAL() and AIMAG() of Complex::
5314 * CMPLX() of DOUBLE PRECISION::
5315 * MIL-STD 1753::
5316 * f77/f2c Intrinsics::
5317 * Table of Intrinsic Functions::
5318 @end menu
5320 @node %VAL()
5321 @subsection The @code{%VAL()} Construct
5322 @cindex %VAL() construct
5324 @example
5325 %VAL(@var{arg})
5326 @end example
5328 The @code{%VAL()} construct specifies that an argument,
5329 @var{arg}, is to be passed by value, instead of by reference
5330 or descriptor.
5332 @code{%VAL()} is restricted to actual arguments in
5333 invocations of external procedures.
5335 Use of @code{%VAL()} is recommended only for code that
5336 is accessing facilities outside of GNU Fortran, such as
5337 operating system or windowing facilities.
5338 It is best to constrain such uses to isolated portions of
5339 a program---portions the deal specifically and exclusively
5340 with low-level, system-dependent facilities.
5341 Such portions might well provide a portable interface for
5342 use by the program as a whole, but are themselves not
5343 portable, and should be thoroughly tested each time they
5344 are rebuilt using a new compiler or version of a compiler.
5346 @emph{Implementation Note:} Currently, @code{g77} passes
5347 all arguments either by reference or by descriptor.
5349 Thus, use of @code{%VAL()} tends to be restricted to cases
5350 where the called procedure is written in a language other
5351 than Fortran that supports call-by-value semantics.
5352 (C is an example of such a language.)
5354 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
5355 for detailed information on
5356 how this particular version of @code{g77} passes arguments
5357 to procedures.
5359 @node %REF()
5360 @subsection The @code{%REF()} Construct
5361 @cindex %REF() construct
5363 @example
5364 %REF(@var{arg})
5365 @end example
5367 The @code{%REF()} construct specifies that an argument,
5368 @var{arg}, is to be passed by reference, instead of by
5369 value or descriptor.
5371 @code{%REF()} is restricted to actual arguments in
5372 invocations of external procedures.
5374 Use of @code{%REF()} is recommended only for code that
5375 is accessing facilities outside of GNU Fortran, such as
5376 operating system or windowing facilities.
5377 It is best to constrain such uses to isolated portions of
5378 a program---portions the deal specifically and exclusively
5379 with low-level, system-dependent facilities.
5380 Such portions might well provide a portable interface for
5381 use by the program as a whole, but are themselves not
5382 portable, and should be thoroughly tested each time they
5383 are rebuilt using a new compiler or version of a compiler.
5385 Do not depend on @code{%REF()} supplying a pointer to the
5386 procedure being invoked.
5387 While that is a likely implementation choice, other
5388 implementation choices are available that preserve Fortran
5389 pass-by-reference semantics without passing a pointer to
5390 the argument, @var{arg}.
5391 (For example, a copy-in/copy-out implementation.)
5393 @emph{Implementation Note:} Currently, @code{g77} passes
5394 all arguments
5395 (other than variables and arrays of type @code{CHARACTER})
5396 by reference.
5397 Future versions of, or dialects supported by, @code{g77} might
5398 not pass @code{CHARACTER} functions by reference.
5400 Thus, use of @code{%REF()} tends to be restricted to cases
5401 where @var{arg} is type @code{CHARACTER} but the called
5402 procedure accesses it via a means other than the method
5403 used for Fortran @code{CHARACTER} arguments.
5405 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5406 how this particular version of @code{g77} passes arguments
5407 to procedures.
5409 @node %DESCR()
5410 @subsection The @code{%DESCR()} Construct
5411 @cindex %DESCR() construct
5413 @example
5414 %DESCR(@var{arg})
5415 @end example
5417 The @code{%DESCR()} construct specifies that an argument,
5418 @var{arg}, is to be passed by descriptor, instead of by
5419 value or reference.
5421 @code{%DESCR()} is restricted to actual arguments in
5422 invocations of external procedures.
5424 Use of @code{%DESCR()} is recommended only for code that
5425 is accessing facilities outside of GNU Fortran, such as
5426 operating system or windowing facilities.
5427 It is best to constrain such uses to isolated portions of
5428 a program---portions the deal specifically and exclusively
5429 with low-level, system-dependent facilities.
5430 Such portions might well provide a portable interface for
5431 use by the program as a whole, but are themselves not
5432 portable, and should be thoroughly tested each time they
5433 are rebuilt using a new compiler or version of a compiler.
5435 Do not depend on @code{%DESCR()} supplying a pointer
5436 and/or a length passed by value
5437 to the procedure being invoked.
5438 While that is a likely implementation choice, other
5439 implementation choices are available that preserve the
5440 pass-by-reference semantics without passing a pointer to
5441 the argument, @var{arg}.
5442 (For example, a copy-in/copy-out implementation.)
5443 And, future versions of @code{g77} might change the
5444 way descriptors are implemented, such as passing a
5445 single argument pointing to a record containing the
5446 pointer/length information instead of passing that same
5447 information via two arguments as it currently does.
5449 @emph{Implementation Note:} Currently, @code{g77} passes
5450 all variables and arrays of type @code{CHARACTER}
5451 by descriptor.
5452 Future versions of, or dialects supported by, @code{g77} might
5453 pass @code{CHARACTER} functions by descriptor as well.
5455 Thus, use of @code{%DESCR()} tends to be restricted to cases
5456 where @var{arg} is not type @code{CHARACTER} but the called
5457 procedure accesses it via a means similar to the method
5458 used for Fortran @code{CHARACTER} arguments.
5460 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5461 how this particular version of @code{g77} passes arguments
5462 to procedures.
5464 @node Generics and Specifics
5465 @subsection Generics and Specifics
5466 @cindex generic intrinsics
5467 @cindex intrinsics, generic
5469 The ANSI FORTRAN 77 language defines generic and specific
5470 intrinsics.
5471 In short, the distinctions are:
5473 @itemize @bullet
5474 @item
5475 @emph{Specific} intrinsics have
5476 specific types for their arguments and a specific return
5477 type.
5479 @item
5480 @emph{Generic} intrinsics are treated,
5481 on a case-by-case basis in the program's source code,
5482 as one of several possible specific intrinsics.
5484 Typically, a generic intrinsic has a return type that
5485 is determined by the type of one or more of its arguments.
5486 @end itemize
5488 The GNU Fortran language generalizes these concepts somewhat,
5489 especially by providing intrinsic subroutines and generic
5490 intrinsics that are treated as either a specific intrinsic subroutine
5491 or a specific intrinsic function (e.g. @code{SECOND}).
5493 However, GNU Fortran avoids generalizing this concept to
5494 the point where existing code would be accepted as meaning
5495 something possibly different than what was intended.
5497 For example, @code{ABS} is a generic intrinsic, so all working
5498 code written using @code{ABS} of an @code{INTEGER} argument
5499 expects an @code{INTEGER} return value.
5500 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
5501 argument returns an @code{INTEGER*2} return value.
5503 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
5504 an @code{INTEGER(KIND=1)} argument.
5505 Code that passes something other than an @code{INTEGER(KIND=1)}
5506 argument to @code{IABS} is not valid GNU Fortran code, because
5507 it is not clear what the author intended.
5509 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
5510 is not defined by the GNU Fortran language, because the programmer
5511 might have used that construct to mean any of the following, subtly
5512 different, things:
5514 @itemize @bullet
5515 @item
5516 Convert @samp{J} to @code{INTEGER(KIND=1)} first
5517 (as if @samp{IABS(INT(J))} had been written).
5519 @item
5520 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
5521 (as if @samp{INT(ABS(J))} had been written).
5523 @item
5524 No conversion (as if @samp{ABS(J)} had been written).
5525 @end itemize
5527 The distinctions matter especially when types and values wider than
5528 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
5529 operations performing more ``arithmetic'' than absolute-value, are involved.
5531 The following sample program is not a valid GNU Fortran program, but
5532 might be accepted by other compilers.
5533 If so, the output is likely to be revealing in terms of how a given
5534 compiler treats intrinsics (that normally are specific) when they
5535 are given arguments that do not conform to their stated requirements:
5537 @cindex JCB002 program
5538 @smallexample
5539       PROGRAM JCB002
5540 C Version 1:
5541 C Modified 1999-02-15 (Burley) to delete my email address.
5542 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
5543 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
5545 C Version 0:
5546 C Written by James Craig Burley 1997-02-20.
5548 C Purpose:
5549 C Determine how compilers handle non-standard IDIM
5550 C on INTEGER*2 operands, which presumably can be
5551 C extrapolated into understanding how the compiler
5552 C generally treats specific intrinsics that are passed
5553 C arguments not of the correct types.
5555 C If your compiler implements INTEGER*2 and INTEGER
5556 C as the same type, change all INTEGER*2 below to
5557 C INTEGER*1.
5559       INTEGER*2 I0, I4
5560       INTEGER I1, I2, I3
5561       INTEGER*2 ISMALL, ILARGE
5562       INTEGER*2 ITOOLG, ITWO
5563       INTEGER*2 ITMP
5564       LOGICAL L2, L3, L4
5566 C Find smallest INTEGER*2 number.
5568       ISMALL=0
5569  10   I0 = ISMALL-1
5570       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
5571       ISMALL = I0
5572       GOTO 10
5573  20   CONTINUE
5575 C Find largest INTEGER*2 number.
5577       ILARGE=0
5578  30   I0 = ILARGE+1
5579       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
5580       ILARGE = I0
5581       GOTO 30
5582  40   CONTINUE
5584 C Multiplying by two adds stress to the situation.
5586       ITWO = 2
5588 C Need a number that, added to -2, is too wide to fit in I*2.
5590       ITOOLG = ISMALL
5592 C Use IDIM the straightforward way.
5594       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
5596 C Calculate result for first interpretation.
5598       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
5600 C Calculate result for second interpretation.
5602       ITMP = ILARGE - ISMALL
5603       I3 = (INT (ITMP)) * ITWO + ITOOLG
5605 C Calculate result for third interpretation.
5607       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
5609 C Print results.
5611       PRINT *, 'ILARGE=', ILARGE
5612       PRINT *, 'ITWO=', ITWO
5613       PRINT *, 'ITOOLG=', ITOOLG
5614       PRINT *, 'ISMALL=', ISMALL
5615       PRINT *, 'I1=', I1
5616       PRINT *, 'I2=', I2
5617       PRINT *, 'I3=', I3
5618       PRINT *, 'I4=', I4
5619       PRINT *
5620       L2 = (I1 .EQ. I2)
5621       L3 = (I1 .EQ. I3)
5622       L4 = (I1 .EQ. I4)
5623       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
5624          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
5625          STOP
5626       END IF
5627       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
5628          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
5629          STOP
5630       END IF
5631       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
5632          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
5633          STOP
5634       END IF
5635       PRINT *, 'Results need careful analysis.'
5636       END
5637 @end smallexample
5639 No future version of the GNU Fortran language
5640 will likely permit specific intrinsic invocations with wrong-typed
5641 arguments (such as @code{IDIM} in the above example), since
5642 it has been determined that disagreements exist among
5643 many production compilers on the interpretation of
5644 such invocations.
5645 These disagreements strongly suggest that Fortran programmers,
5646 and certainly existing Fortran programs, disagree about the
5647 meaning of such invocations.
5649 The first version of @code{JCB002} didn't accommodate some compilers'
5650 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
5651 @code{INTEGER*2}.
5652 In such a case, these compilers apparently convert both
5653 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
5654 instead of doing an @code{INTEGER*2} subtraction on the
5655 original values in @samp{I1} and @samp{I2}.
5657 However, the results of the careful analyses done on the outputs
5658 of programs compiled by these various compilers show that they
5659 all implement either @samp{Interp 1} or @samp{Interp 2} above.
5661 Specifically, it is believed that the new version of @code{JCB002}
5662 above will confirm that:
5664 @itemize @bullet
5665 @item
5666 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
5667 @code{f77} compilers all implement @samp{Interp 1}.
5669 @item
5670 IRIX 5.3 @code{f77} compiler implements @samp{Interp 2}.
5672 @item
5673 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
5674 and IRIX 6.1 @code{f77} compilers all implement @samp{Interp 3}.
5675 @end itemize
5677 If you get different results than the above for the stated
5678 compilers, or have results for other compilers that might be
5679 worth adding to the above list, please let us know the details
5680 (compiler product, version, machine, results, and so on).
5682 @node REAL() and AIMAG() of Complex
5683 @subsection @code{REAL()} and @code{AIMAG()} of Complex
5684 @cindex @code{Real} intrinsic
5685 @cindex intrinsics, @code{Real}
5686 @cindex @code{AImag} intrinsic
5687 @cindex intrinsics, @code{AImag}
5689 The GNU Fortran language disallows @code{REAL(@var{expr})}
5690 and @code{AIMAG(@var{expr})},
5691 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
5692 except when they are used in the following way:
5694 @example
5695 REAL(REAL(@var{expr}))
5696 REAL(AIMAG(@var{expr}))
5697 @end example
5699 @noindent
5700 The above forms explicitly specify that the desired effect
5701 is to convert the real or imaginary part of @var{expr}, which might
5702 be some @code{REAL} type other than @code{REAL(KIND=1)},
5703 to type @code{REAL(KIND=1)},
5704 and have that serve as the value of the expression.
5706 The GNU Fortran language offers clearly named intrinsics to extract the
5707 real and imaginary parts of a complex entity without any
5708 conversion:
5710 @example
5711 REALPART(@var{expr})
5712 IMAGPART(@var{expr})
5713 @end example
5715 To express the above using typical extended FORTRAN 77,
5716 use the following constructs
5717 (when @var{expr} is @code{COMPLEX(KIND=2)}):
5719 @example
5720 DBLE(@var{expr})
5721 DIMAG(@var{expr})
5722 @end example
5724 The FORTRAN 77 language offers no way
5725 to explicitly specify the real and imaginary parts of a complex expression of
5726 arbitrary type, apparently as a result of requiring support for
5727 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
5728 The concepts of converting an expression to type @code{REAL(KIND=1)} and
5729 of extracting the real part of a complex expression were
5730 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
5731 they happened to have the exact same effect in that language
5732 (due to having only one @code{COMPLEX} type).
5734 @emph{Note:} When @samp{-ff90} is in effect,
5735 @code{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
5736 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
5737 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
5738 treated as @samp{REAL(REALPART(@var{expr}))}.
5740 @xref{Ugly Complex Part Extraction}, for more information.
5742 @node CMPLX() of DOUBLE PRECISION
5743 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
5744 @cindex @code{Cmplx} intrinsic
5745 @cindex intrinsics, @code{Cmplx}
5747 In accordance with Fortran 90 and at least some (perhaps all)
5748 other compilers, the GNU Fortran language defines @code{CMPLX()}
5749 as always returning a result that is type @code{COMPLEX(KIND=1)}.
5751 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
5752 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
5754 @example
5755 CMPLX(SNGL(D1), SNGL(D2))
5756 @end example
5758 (It was necessary for Fortran 90 to specify this behavior
5759 for @code{DOUBLE PRECISION} arguments, since that is
5760 the behavior mandated by FORTRAN 77.)
5762 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
5763 which is provided by some FORTRAN 77 compilers to construct
5764 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
5765 operands.
5766 However, this solution does not scale well when more @code{COMPLEX} types
5767 (having various precisions and ranges) are offered by Fortran implementations.
5769 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
5770 an extra argument used to specify the desired kind of complex
5771 result.
5772 However, this solution is somewhat awkward to use, and
5773 @code{g77} currently does not support it.
5775 The GNU Fortran language provides a simple way to build a complex
5776 value out of two numbers, with the precise type of the value
5777 determined by the types of the two numbers (via the usual
5778 type-promotion mechanism):
5780 @example
5781 COMPLEX(@var{real}, @var{imag})
5782 @end example
5784 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
5785 performs no conversion other than to put them together to form a
5786 complex result of the same (complex version of real) type.
5788 @xref{Complex Intrinsic}, for more information.
5790 @node MIL-STD 1753
5791 @subsection MIL-STD 1753 Support
5792 @cindex MIL-STD 1753
5794 The GNU Fortran language includes the MIL-STD 1753 intrinsics
5795 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
5796 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
5797 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
5799 @node f77/f2c Intrinsics
5800 @subsection @code{f77}/@code{f2c} Intrinsics
5802 The bit-manipulation intrinsics supported by traditional
5803 @code{f77} and by @code{f2c} are available in the GNU Fortran language.
5804 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
5805 and @code{XOR}.
5807 Also supported are the intrinsics @code{CDABS},
5808 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
5809 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
5810 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
5811 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
5812 and @code{ZSQRT}.
5814 @node Table of Intrinsic Functions
5815 @subsection Table of Intrinsic Functions
5816 @cindex intrinsics, table of
5817 @cindex table of intrinsics
5819 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
5821 The GNU Fortran language adds various functions, subroutines, types,
5822 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
5823 The complete set of intrinsics supported by the GNU Fortran language
5824 is described below.
5826 Note that a name is not treated as that of an intrinsic if it is
5827 specified in an @code{EXTERNAL} statement in the same program unit;
5828 if a command-line option is used to disable the groups to which
5829 the intrinsic belongs; or if the intrinsic is not named in an
5830 @code{INTRINSIC} statement and a command-line option is used to
5831 hide the groups to which the intrinsic belongs.
5833 So, it is recommended that any reference in a program unit to
5834 an intrinsic procedure that is not a standard FORTRAN 77
5835 intrinsic be accompanied by an appropriate @code{INTRINSIC}
5836 statement in that program unit.
5837 This sort of defensive programming makes it more
5838 likely that an implementation will issue a diagnostic rather
5839 than generate incorrect code for such a reference.
5841 The terminology used below is based on that of the Fortran 90
5842 standard, so that the text may be more concise and accurate:
5844 @itemize @bullet
5845 @item
5846 @code{OPTIONAL} means the argument may be omitted.
5848 @item
5849 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
5850 (generally named @samp{A}) may be specified.
5852 @item
5853 @samp{scalar} means the argument must not be an array (must
5854 be a variable or array element, or perhaps a constant if expressions
5855 are permitted).
5857 @item
5858 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
5860 @item
5861 @code{INTENT(IN)} means the argument must be an expression
5862 (such as a constant or a variable that is defined upon invocation
5863 of the intrinsic).
5865 @item
5866 @code{INTENT(OUT)} means the argument must be definable by the
5867 invocation of the intrinsic (that is, must not be a constant nor
5868 an expression involving operators other than array reference and
5869 substring reference).
5871 @item
5872 @code{INTENT(INOUT)} means the argument must be defined prior to,
5873 and definable by, invocation of the intrinsic (a combination of
5874 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
5876 @item
5877 @xref{Kind Notation}, for an explanation of @code{KIND}.
5878 @end itemize
5880 @ifinfo
5881 (Note that the empty lines appearing in the menu below
5882 are not intentional---they result from a bug in the
5883 GNU @code{makeinfo} program@dots{}a program that, if it
5884 did not exist, would leave this document in far worse shape!)
5885 @end ifinfo
5887 @c The actual documentation for intrinsics comes from
5888 @c intdoc.texi, which in turn is automatically generated
5889 @c from the internal g77 tables in intrin.def _and_ the
5890 @c largely hand-written text in intdoc.h.  So, if you want
5891 @c to change or add to existing documentation on intrinsics,
5892 @c you probably want to edit intdoc.h.
5894 @set familyF77
5895 @set familyGNU
5896 @set familyASC
5897 @set familyMIL
5898 @set familyF90
5899 @clear familyVXT
5900 @clear familyFVZ
5901 @set familyF2C
5902 @set familyF2U
5903 @clear familyBADU77
5904 @include intdoc.texi
5906 @node Scope and Classes of Names
5907 @section Scope and Classes of Symbolic Names
5908 @cindex symbol names, scope and classes
5909 @cindex scope
5911 (The following information augments or overrides the information in
5912 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5913 language.
5914 Chapter 18 of that document otherwise serves as the basis
5915 for the relevant aspects of GNU Fortran.)
5917 @menu
5918 * Underscores in Symbol Names::
5919 @end menu
5921 @node Underscores in Symbol Names
5922 @subsection Underscores in Symbol Names
5923 @cindex underscore
5925 Underscores (@samp{_}) are accepted in symbol names after the first
5926 character (which must be a letter).
5928 @node I/O
5929 @section I/O
5931 @cindex dollar sign
5932 A dollar sign at the end of an output format specification suppresses
5933 the newline at the end of the output.
5935 @cindex <> edit descriptor
5936 @cindex edit descriptor, <>
5937 Edit descriptors in @code{FORMAT} statements may contain compile-time
5938 @code{INTEGER} constant expressions in angle brackets, such as
5939 @smallexample
5940 10    FORMAT (I<WIDTH>)
5941 @end smallexample
5943 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
5945 These Fortran 90 features are supported:
5946 @itemize @bullet
5947 @item
5948 @cindex FORMAT descriptors
5949 @cindex Z edit descriptor
5950 @cindex edit descriptor, Z
5951 @cindex O edit descriptor
5952 @cindex edit descriptor, O
5953 The @code{O} and @code{Z} edit descriptors are supported for I/O of
5954 integers in octal and hexadecimal formats, respectively.
5955 @item
5956 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
5957 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
5958 specifier is supported.
5959 @end itemize
5961 @node Fortran 90 Features
5962 @section Fortran 90 Features
5963 @cindex Fortran 90
5964 @cindex extensions, from Fortran 90
5966 For convenience this section collects a list (probably incomplete) of
5967 the Fortran 90 features supported by the GNU Fortran language, even if
5968 they are documented elsewhere.
5969 @xref{Characters Lines Sequence,,@asis{Characters, Lines, and Execution Sequence}},
5970 for information on additional fixed source form lexical issues.
5971 @cindex @samp{-ffree-form}
5972 Further, the free source form is supported through the
5973 @samp{-ffree-form} option.
5974 @cindex @samp{-ff90}
5975 Other Fortran 90 features can be turned on by the @samp{-ff90} option;
5976 see @ref{Fortran 90}.
5977 For information on the Fortran 90 intrinsics available,
5978 see @ref{Table of Intrinsic Functions}.
5980 @table @asis
5981 @item Automatic arrays in procedures
5982 @item Character assignments
5983 @cindex character assignments
5984 In character assignments, the variable being assigned may occur on the
5985 right hand side of the assignment.
5986 @item Character strings
5987 @cindex double quoted character constants
5988 Strings may have zero length and substrings of character constants are
5989 permitted.  Character constants may be enclosed in double quotes
5990 (@code{"}) as well as single quotes.  @xref{Character Type}.
5991 @item Construct names
5992 (Symbolic tags on blocks.)  @xref{Construct Names}.
5993 @item @code{CYCLE} and @code{EXIT}
5994 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
5995 @item @code{DOUBLE COMPLEX}
5996 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement}.
5997 @item @code{DO WHILE}
5998 @xref{DO WHILE}.
5999 @item @code{END} decoration
6000 @xref{Statements}.
6001 @item @code{END DO}
6002 @xref{END DO}.
6003 @item @code{KIND}
6004 @item @code{IMPLICIT NONE}
6005 @item @code{INCLUDE} statements
6006 @xref{INCLUDE}.
6007 @item List-directed and namelist I/O on internal files
6008 @item Binary, octal and hexadecimal constants
6009 These are supported more generally than required by Fortran 90.
6010 @xref{Integer Type}.
6011 @item @samp{O} and @samp{Z} edit descriptors
6012 @item @code{NAMELIST}
6013 @xref{NAMELIST}.
6014 @item @code{OPEN} specifiers
6015 @code{STATUS='REPLACE'} is supported.
6016 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6017 @code{STATUS='SCRATCH'} is supplied.
6018 @item @code{FORMAT} edit descriptors
6019 @cindex FORMAT descriptors
6020 @cindex Z edit descriptor
6021 @cindex edit descriptor, Z
6022 The @code{Z} edit descriptor is supported.
6023 @item Relational operators
6024 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
6025 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
6026 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
6027 @item @code{SELECT CASE}
6028 Not fully implemented.
6029 @xref{SELECT CASE on CHARACTER Type,, @code{SELECT CASE} on @code{CHARACTER} Type}.
6030 @item Specification statements
6031 A limited subset of the Fortran 90 syntax and semantics for variable
6032 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
6033 (@code{KIND} is of limited usefulness in the absence of the
6034 @code{KIND}-related intrinsics, since these intrinsics permit writing
6035 more widely portable code.)  An example of supported @code{KIND} usage
6037 @smallexample
6038 INTEGER (KIND=1) :: FOO=1, BAR=2
6039 CHARACTER (LEN=3) FOO
6040 @end smallexample
6041 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
6042 @end table
6044 @node Other Dialects
6045 @chapter Other Dialects
6047 GNU Fortran supports a variety of features that are not
6048 considered part of the GNU Fortran language itself, but
6049 are representative of various dialects of Fortran that
6050 @code{g77} supports in whole or in part.
6052 Any of the features listed below might be disallowed by
6053 @code{g77} unless some command-line option is specified.
6054 Currently, some of the features are accepted using the
6055 default invocation of @code{g77}, but that might change
6056 in the future.
6058 @emph{Note: This portion of the documentation definitely needs a lot
6059 of work!}
6061 @menu
6062 * Source Form::       Details of fixed-form and free-form source.
6063 * Trailing Comment::  Use of @samp{/*} to start a comment.
6064 * Debug Line::        Use of @samp{D} in column 1.
6065 * Dollar Signs::      Use of @samp{$} in symbolic names.
6066 * Case Sensitivity::  Uppercase and lowercase in source files.
6067 * VXT Fortran::       @dots{}versus the GNU Fortran language.
6068 * Fortran 90::        @dots{}versus the GNU Fortran language.
6069 * Pedantic Compilation::  Enforcing the standard.
6070 * Distensions::       Misfeatures supported by GNU Fortran.
6071 @end menu
6073 @node Source Form
6074 @section Source Form
6075 @cindex source file format
6076 @cindex source format
6077 @cindex file, source
6078 @cindex source code
6079 @cindex code, source
6080 @cindex fixed form
6081 @cindex free form
6083 GNU Fortran accepts programs written in either fixed form or
6084 free form.
6086 Fixed form
6087 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
6088 allowing tabs) and Fortran 90's fixed form.
6090 Free form corresponds to
6091 Fortran 90's free form (though possibly not entirely up-to-date, and
6092 without complaining about some things that for which Fortran 90 requires
6093 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
6095 The way a Fortran compiler views source files depends entirely on the
6096 implementation choices made for the compiler, since those choices
6097 are explicitly left to the implementation by the published Fortran
6098 standards.
6099 GNU Fortran currently tries to be somewhat like a few popular compilers
6100 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
6101 definition along with more
6102 flexibility offered by command-line options is likely to be offered
6103 in version 0.6.
6105 This section describes how @code{g77} interprets source lines.
6107 @menu
6108 * Carriage Returns::  Carriage returns ignored.
6109 * Tabs::              Tabs converted to spaces.
6110 * Short Lines::       Short lines padded with spaces (fixed-form only).
6111 * Long Lines::        Long lines truncated.
6112 * Ampersands::        Special Continuation Lines.
6113 @end menu
6115 @node Carriage Returns
6116 @subsection Carriage Returns
6117 @cindex carriage returns
6119 Carriage returns (@samp{\r}) in source lines are ignored.
6120 This is somewhat different from @code{f2c}, which seems to treat them as
6121 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
6122 inside such constants.
6124 @node Tabs
6125 @subsection Tabs
6126 @cindex tab character
6127 @cindex horizontal tab
6129 A source line with a @key{TAB} character anywhere in it is treated as
6130 entirely significant---however long it is---instead of ending in
6131 column 72 (for fixed-form source) or 132 (for free-form source).
6132 This also is different from @code{f2c}, which encodes tabs as
6133 @samp{\t} (the ASCII @key{TAB} character) inside character
6134 and Hollerith constants, but nevertheless seems to treat the column
6135 position as if it had been affected by the canonical tab positioning.
6137 @code{g77} effectively
6138 translates tabs to the appropriate number of spaces (a la the default
6139 for the UNIX @code{expand} command) before doing any other processing, other
6140 than (currently) noting whether a tab was found on a line and using this
6141 information to decide how to interpret the length of the line and continued
6142 constants.
6144 Note that this default behavior probably will change for version 0.6,
6145 when it will presumably be available via a command-line option.
6146 The default as of version 0.6 is planned to be a ``pure visual''
6147 model, where tabs are immediately
6148 converted to spaces and otherwise have no effect, so the way a typical
6149 user sees source lines produces a consistent result no matter how the
6150 spacing in those source lines is actually implemented via tabs, spaces,
6151 and trailing tabs/spaces before newline.
6152 Command-line options are likely to be added to specify whether all or
6153 just-tabbed lines are to be extended to 132 or full input-line length,
6154 and perhaps even an option will be added to specify the truncated-line
6155 behavior to which some Digital compilers default (and which affects
6156 the way continued character/Hollerith constants are interpreted).
6158 @node Short Lines
6159 @subsection Short Lines
6160 @cindex short source lines
6161 @cindex space, padding with
6162 @cindex source lines, short
6163 @cindex lines, short
6165 Source lines shorter than the applicable fixed-form length are treated as
6166 if they were padded with spaces to that length.
6167 (None of this is relevant to source files written in free form.)
6169 This affects only
6170 continued character and Hollerith constants, and is a different
6171 interpretation than provided by some other popular compilers
6172 (although a bit more consistent with the traditional punched-card
6173 basis of Fortran and the way the Fortran standard expressed fixed
6174 source form).
6176 @code{g77} might someday offer an option to warn about cases where differences
6177 might be seen as a result of this treatment, and perhaps an option to
6178 specify the alternate behavior as well.
6180 Note that this padding cannot apply to lines that are effectively of
6181 infinite length---such lines are specified using command-line options
6182 like @samp{-ffixed-line-length-none}, for example.
6184 @node Long Lines
6185 @subsection Long Lines
6186 @cindex long source lines
6187 @cindex truncation, of long lines
6188 @cindex lines, long
6189 @cindex source lines, long
6191 Source lines longer than the applicable length are truncated to that
6192 length.
6193 Currently, @code{g77} does not warn if the truncated characters are
6194 not spaces, to accommodate existing code written for systems that
6195 treated truncated text as commentary (especially in columns 73 through 80).
6197 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
6198 for information on the @samp{-ffixed-line-length-@var{n}} option,
6199 which can be used to set the line length applicable to fixed-form
6200 source files.
6202 @node Ampersands
6203 @subsection Ampersand Continuation Line
6204 @cindex ampersand continuation line
6205 @cindex continuation line, ampersand
6207 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
6208 continuation line, imitating the behavior of @code{f2c}.
6210 @node Trailing Comment
6211 @section Trailing Comment
6213 @cindex trailing comment
6214 @cindex comment
6215 @cindex characters, comment
6216 @cindex /*
6217 @cindex !
6218 @cindex exclamation point
6219 @code{g77} supports use of @samp{/*} to start a trailing
6220 comment.
6221 In the GNU Fortran language, @samp{!} is used for this purpose.
6223 @samp{/*} is not in the GNU Fortran language
6224 because the use of @samp{/*} in a program might
6225 suggest to some readers that a block, not trailing, comment is
6226 started (and thus ended by @samp{*/}, not end of line),
6227 since that is the meaning of @samp{/*} in C.
6229 Also, such readers might think they can use @samp{//} to start
6230 a trailing comment as an alternative to @samp{/*}, but
6231 @samp{//} already denotes concatenation, and such a ``comment''
6232 might actually result in a program that compiles without
6233 error (though it would likely behave incorrectly).
6235 @node Debug Line
6236 @section Debug Line
6237 @cindex debug line
6238 @cindex comment line, debug
6240 Use of @samp{D} or @samp{d} as the first character (column 1) of
6241 a source line denotes a debug line.
6243 In turn, a debug line is treated as either a comment line
6244 or a normal line, depending on whether debug lines are enabled.
6246 When treated as a comment line, a line beginning with @samp{D} or
6247 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
6248 When treated as a normal line, such a line is treated as if
6249 the first character was @key{SPC} (space).
6251 (Currently, @code{g77} provides no means for treating debug
6252 lines as normal lines.)
6254 @node Dollar Signs
6255 @section Dollar Signs in Symbol Names
6256 @cindex dollar sign
6257 @cindex $
6259 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
6260 when the @samp{-fdollar-ok} option is specified.
6262 @node Case Sensitivity
6263 @section Case Sensitivity
6264 @cindex case sensitivity
6265 @cindex source file format
6266 @cindex code, source
6267 @cindex source code
6268 @cindex uppercase letters
6269 @cindex lowercase letters
6270 @cindex letters, uppercase
6271 @cindex letters, lowercase
6273 GNU Fortran offers the programmer way too much flexibility in deciding
6274 how source files are to be treated vis-a-vis uppercase and lowercase
6275 characters.
6276 There are 66 useful settings that affect case sensitivity, plus 10
6277 settings that are nearly useless, with the remaining 116 settings
6278 being either redundant or useless.
6280 None of these settings have any effect on the contents of comments
6281 (the text after a @samp{c} or @samp{C} in Column 1, for example)
6282 or of character or Hollerith constants.
6283 Note that things like the @samp{E} in the statement
6284 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
6285 are considered built-in keywords, and so are affected by
6286 these settings.
6288 Low-level switches are identified in this section as follows:
6290 @itemize @w{}
6291 @item A
6292 Source Case Conversion:
6294 @itemize @w{}
6295 @item 0
6296 Preserve (see Note 1)
6297 @item 1
6298 Convert to Upper Case
6299 @item 2
6300 Convert to Lower Case
6301 @end itemize
6303 @item B
6304 Built-in Keyword Matching:
6306 @itemize @w{}
6307 @item 0
6308 Match Any Case (per-character basis)
6309 @item 1
6310 Match Upper Case Only
6311 @item 2
6312 Match Lower Case Only
6313 @item 3
6314 Match InitialCaps Only (see tables for spellings)
6315 @end itemize
6317 @item C
6318 Built-in Intrinsic Matching:
6320 @itemize @w{}
6321 @item 0
6322 Match Any Case (per-character basis)
6323 @item 1
6324 Match Upper Case Only
6325 @item 2
6326 Match Lower Case Only
6327 @item 3
6328 Match InitialCaps Only (see tables for spellings)
6329 @end itemize
6331 @item D
6332 User-defined Symbol Possibilities (warnings only):
6334 @itemize @w{}
6335 @item 0
6336 Allow Any Case (per-character basis)
6337 @item 1
6338 Allow Upper Case Only
6339 @item 2
6340 Allow Lower Case Only
6341 @item 3
6342 Allow InitialCaps Only (see Note 2)
6343 @end itemize
6344 @end itemize
6346 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
6347 consistent with these source switches---in the sense that input will be
6348 expected to meet the same requirements as source code in terms
6349 of matching symbol names and keywords (for the exponent letters).
6351 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
6352 which uppercases @code{NAMELIST} input and symbol names for matching.
6353 This means not only that @code{NAMELIST} output currently shows symbol
6354 (and keyword) names in uppercase even if lower-case source
6355 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
6356 adequately supported when source case preservation (option A0)
6357 is selected.
6359 If A0 is selected, a warning message will be
6360 output for each @code{NAMELIST} statement to this effect.
6361 The behavior
6362 of the program is undefined at run time if two or more symbol names
6363 appear in a given @code{NAMELIST} such that the names are identical
6364 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
6365 For complete and total elegance, perhaps there should be a warning
6366 when option A2 is selected, since the output of NAMELIST is currently
6367 in uppercase but will someday be lowercase (when a @code{libg77} is written),
6368 but that seems to be overkill for a product in beta test.
6370 Note 2: Rules for InitialCaps names are:
6372 @itemize @minus
6373 @item
6374 Must be a single uppercase letter, @strong{or}
6375 @item
6376 Must start with an uppercase letter and contain at least one
6377 lowercase letter.
6378 @end itemize
6380 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
6381 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
6382 not.
6383 Note that most, but not all, built-in names meet these
6384 requirements---the exceptions are some of the two-letter format
6385 specifiers, such as @code{BN} and @code{BZ}.
6387 Here are the names of the corresponding command-line options:
6389 @smallexample
6390 A0: -fsource-case-preserve
6391 A1: -fsource-case-upper
6392 A2: -fsource-case-lower
6394 B0: -fmatch-case-any
6395 B1: -fmatch-case-upper
6396 B2: -fmatch-case-lower
6397 B3: -fmatch-case-initcap
6399 C0: -fintrin-case-any
6400 C1: -fintrin-case-upper
6401 C2: -fintrin-case-lower
6402 C3: -fintrin-case-initcap
6404 D0: -fsymbol-case-any
6405 D1: -fsymbol-case-upper
6406 D2: -fsymbol-case-lower
6407 D3: -fsymbol-case-initcap
6408 @end smallexample
6410 Useful combinations of the above settings, along with abbreviated
6411 option names that set some of these combinations all at once:
6413 @smallexample
6414  1: A0--  B0---  C0---  D0---    -fcase-preserve
6415  2: A0--  B0---  C0---  D-1--
6416  3: A0--  B0---  C0---  D--2-
6417  4: A0--  B0---  C0---  D---3
6418  5: A0--  B0---  C-1--  D0---
6419  6: A0--  B0---  C-1--  D-1--
6420  7: A0--  B0---  C-1--  D--2-
6421  8: A0--  B0---  C-1--  D---3
6422  9: A0--  B0---  C--2-  D0---
6423 10: A0--  B0---  C--2-  D-1--
6424 11: A0--  B0---  C--2-  D--2-
6425 12: A0--  B0---  C--2-  D---3
6426 13: A0--  B0---  C---3  D0---
6427 14: A0--  B0---  C---3  D-1--
6428 15: A0--  B0---  C---3  D--2-
6429 16: A0--  B0---  C---3  D---3
6430 17: A0--  B-1--  C0---  D0---
6431 18: A0--  B-1--  C0---  D-1--
6432 19: A0--  B-1--  C0---  D--2-
6433 20: A0--  B-1--  C0---  D---3
6434 21: A0--  B-1--  C-1--  D0---
6435 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
6436 23: A0--  B-1--  C-1--  D--2-
6437 24: A0--  B-1--  C-1--  D---3
6438 25: A0--  B-1--  C--2-  D0---
6439 26: A0--  B-1--  C--2-  D-1--
6440 27: A0--  B-1--  C--2-  D--2-
6441 28: A0--  B-1--  C--2-  D---3
6442 29: A0--  B-1--  C---3  D0---
6443 30: A0--  B-1--  C---3  D-1--
6444 31: A0--  B-1--  C---3  D--2-
6445 32: A0--  B-1--  C---3  D---3
6446 33: A0--  B--2-  C0---  D0---
6447 34: A0--  B--2-  C0---  D-1--
6448 35: A0--  B--2-  C0---  D--2-
6449 36: A0--  B--2-  C0---  D---3
6450 37: A0--  B--2-  C-1--  D0---
6451 38: A0--  B--2-  C-1--  D-1--
6452 39: A0--  B--2-  C-1--  D--2-
6453 40: A0--  B--2-  C-1--  D---3
6454 41: A0--  B--2-  C--2-  D0---
6455 42: A0--  B--2-  C--2-  D-1--
6456 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
6457 44: A0--  B--2-  C--2-  D---3
6458 45: A0--  B--2-  C---3  D0---
6459 46: A0--  B--2-  C---3  D-1--
6460 47: A0--  B--2-  C---3  D--2-
6461 48: A0--  B--2-  C---3  D---3
6462 49: A0--  B---3  C0---  D0---
6463 50: A0--  B---3  C0---  D-1--
6464 51: A0--  B---3  C0---  D--2-
6465 52: A0--  B---3  C0---  D---3
6466 53: A0--  B---3  C-1--  D0---
6467 54: A0--  B---3  C-1--  D-1--
6468 55: A0--  B---3  C-1--  D--2-
6469 56: A0--  B---3  C-1--  D---3
6470 57: A0--  B---3  C--2-  D0---
6471 58: A0--  B---3  C--2-  D-1--
6472 59: A0--  B---3  C--2-  D--2-
6473 60: A0--  B---3  C--2-  D---3
6474 61: A0--  B---3  C---3  D0---
6475 62: A0--  B---3  C---3  D-1--
6476 63: A0--  B---3  C---3  D--2-
6477 64: A0--  B---3  C---3  D---3    -fcase-initcap
6478 65: A-1-  B01--  C01--  D01--    -fcase-upper
6479 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
6480 @end smallexample
6482 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
6483 (except comments, character constants, and Hollerith strings) must
6484 be entered in uppercase.
6485 Use @samp{-fcase-strict-upper} to specify this
6486 combination.
6488 Number 43 is like Number 22 except all input must be lowercase.  Use
6489 @samp{-fcase-strict-lower} to specify this combination.
6491 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
6492 non-UNIX machines whereby all the source is translated to uppercase.
6493 Use @samp{-fcase-upper} to specify this combination.
6495 Number 66 is the ``canonical'' UNIX model whereby all the source is
6496 translated to lowercase.
6497 Use @samp{-fcase-lower} to specify this combination.
6499 There are a few nearly useless combinations:
6501 @smallexample
6502 67: A-1-  B01--  C01--  D--2-
6503 68: A-1-  B01--  C01--  D---3
6504 69: A-1-  B01--  C--23  D01--
6505 70: A-1-  B01--  C--23  D--2-
6506 71: A-1-  B01--  C--23  D---3
6507 72: A--2  B01--  C0-2-  D-1--
6508 73: A--2  B01--  C0-2-  D---3
6509 74: A--2  B01--  C-1-3  D0-2-
6510 75: A--2  B01--  C-1-3  D-1--
6511 76: A--2  B01--  C-1-3  D---3
6512 @end smallexample
6514 The above allow some programs to be compiled but with restrictions that
6515 make most useful programs impossible: Numbers 67 and 72 warn about
6516 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
6517 Numbers
6518 68 and 73 warn about any user-defined symbol names longer than one
6519 character that don't have at least one non-alphabetic character after
6520 the first;
6521 Numbers 69 and 74 disallow any references to intrinsics;
6522 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
6523 67+69, 68+69, 72+74, and 73+74, respectively.
6525 All redundant combinations are shown in the above tables anyplace
6526 where more than one setting is shown for a low-level switch.
6527 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
6528 The ``proper'' setting in such a case is the one that copies the setting
6529 of switch A---any other setting might slightly reduce the speed of
6530 the compiler, though possibly to an unmeasurable extent.
6532 All remaining combinations are useless in that they prevent successful
6533 compilation of non-null source files (source files with something other
6534 than comments).
6536 @node VXT Fortran
6537 @section VXT Fortran
6539 @cindex VXT extensions
6540 @cindex extensions, VXT
6541 @code{g77} supports certain constructs that
6542 have different meanings in VXT Fortran than they
6543 do in the GNU Fortran language.
6545 Generally, this manual uses the invented term VXT Fortran to refer
6546 VAX FORTRAN (circa v4).
6547 That compiler offered many popular features, though not necessarily
6548 those that are specific to the VAX processor architecture,
6549 the VMS operating system,
6550 or Digital Equipment Corporation's Fortran product line.
6551 (VAX and VMS probably are trademarks of Digital Equipment
6552 Corporation.)
6554 An extension offered by a Digital Fortran product that also is
6555 offered by several other Fortran products for different kinds of
6556 systems is probably going to be considered for inclusion in @code{g77}
6557 someday, and is considered a VXT Fortran feature.
6559 The @samp{-fvxt} option generally specifies that, where
6560 the meaning of a construct is ambiguous (means one thing
6561 in GNU Fortran and another in VXT Fortran), the VXT Fortran
6562 meaning is to be assumed.
6564 @menu
6565 * Double Quote Meaning::  @samp{"2000} as octal constant.
6566 * Exclamation Point::     @samp{!} in column 6.
6567 @end menu
6569 @node Double Quote Meaning
6570 @subsection Meaning of Double Quote
6571 @cindex double quotes
6572 @cindex character constants
6573 @cindex constants, character
6574 @cindex octal constants
6575 @cindex constants, octal
6577 @code{g77} treats double-quote (@samp{"})
6578 as beginning an octal constant of @code{INTEGER(KIND=1)} type
6579 when the @samp{-fvxt} option is specified.
6580 The form of this octal constant is
6582 @example
6583 "@var{octal-digits}
6584 @end example
6586 @noindent
6587 where @var{octal-digits} is a nonempty string of characters in
6588 the set @samp{01234567}.
6590 For example, the @samp{-fvxt} option permits this:
6592 @example
6593 PRINT *, "20
6595 @end example
6597 @noindent
6598 The above program would print the value @samp{16}.
6600 @xref{Integer Type}, for information on the preferred construct
6601 for integer constants specified using GNU Fortran's octal notation.
6603 (In the GNU Fortran language, the double-quote character (@samp{"})
6604 delimits a character constant just as does apostrophe (@samp{'}).
6605 There is no way to allow
6606 both constructs in the general case, since statements like
6607 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
6609 @node Exclamation Point
6610 @subsection Meaning of Exclamation Point in Column 6
6611 @cindex !
6612 @cindex exclamation point
6613 @cindex continuation character
6614 @cindex characters, continuation
6615 @cindex comment character
6616 @cindex characters, comment
6618 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
6619 a fixed-form source file
6620 as a continuation character rather than
6621 as the beginning of a comment
6622 (as it does in any other column)
6623 when the @samp{-fvxt} option is specified.
6625 The following program, when run, prints a message indicating
6626 whether it is interpreted according to GNU Fortran (and Fortran 90)
6627 rules or VXT Fortran rules:
6629 @smallexample
6630 C234567  (This line begins in column 1.)
6631       I = 0
6632      !1
6633       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
6634       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
6635       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
6636       END
6637 @end smallexample
6639 (In the GNU Fortran and Fortran 90 languages, exclamation point is
6640 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
6641 marks a line as a continuation line when it appears in column 6.)
6643 @node Fortran 90
6644 @section Fortran 90
6645 @cindex compatibility, Fortran 90
6646 @cindex Fortran 90, compatibility
6648 The GNU Fortran language includes a number of features that are
6649 part of Fortran 90, even when the @samp{-ff90} option is not specified.
6650 The features enabled by @samp{-ff90} are intended to be those that,
6651 when @samp{-ff90} is not specified, would have another
6652 meaning to @code{g77}---usually meaning something invalid in the
6653 GNU Fortran language.
6655 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
6656 to gratuitously reject Fortran 90 constructs.
6657 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
6658 to do that, although its implementation is certainly incomplete at
6659 this point.
6661 When @samp{-ff90} is specified:
6663 @itemize @bullet
6664 @item
6665 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
6666 where @var{expr} is @code{COMPLEX} type,
6667 is the same type as the real part of @var{expr}.
6669 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
6670 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
6671 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
6672 @end itemize
6674 @node Pedantic Compilation
6675 @section Pedantic Compilation
6676 @cindex pedantic compilation
6677 @cindex compilation, pedantic
6679 The @samp{-fpedantic} command-line option specifies that @code{g77}
6680 is to warn about code that is not standard-conforming.
6681 This is useful for finding
6682 some extensions @code{g77} accepts that other compilers might not accept.
6683 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
6684 always imply @samp{-fpedantic}.)
6686 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
6687 for conforming code.
6688 With @samp{-ff90} in force, Fortran 90 is used.
6690 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
6691 and @samp{-fno-f90} are in force are:
6693 @itemize @bullet
6694 @item
6695 Automatic arrays, as in
6697 @example
6698 SUBROUTINE X(N)
6699 REAL A(N)
6700 @dots{}
6701 @end example
6703 @noindent
6704 where @samp{A} is not listed in any @code{ENTRY} statement,
6705 and thus is not a dummy argument.
6707 @item
6708 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
6710 These commas are disallowed by FORTRAN 77, but, while strictly
6711 superfluous, are syntactically elegant,
6712 especially given that commas are required in statements such
6713 as @samp{READ 99, I} and @samp{PRINT *, J}.
6714 Many compilers permit the superfluous commas for this reason.
6716 @item
6717 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
6719 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
6720 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
6722 An example of an implicit use is the expression @samp{C*D},
6723 where @samp{C} is @code{COMPLEX(KIND=1)}
6724 and @samp{D} is @code{DOUBLE PRECISION}.
6725 This expression is prohibited by ANSI FORTRAN 77
6726 because the rules of promotion would suggest that it
6727 produce a @code{DOUBLE COMPLEX} result---a type not
6728 provided for by that standard.
6730 @item
6731 Automatic conversion of numeric
6732 expressions to @code{INTEGER(KIND=1)} in contexts such as:
6734 @itemize @minus
6735 @item
6736 Array-reference indexes.
6737 @item
6738 Alternate-return values.
6739 @item
6740 Computed @code{GOTO}.
6741 @item
6742 @code{FORMAT} run-time expressions (not yet supported).
6743 @item
6744 Dimension lists in specification statements.
6745 @item
6746 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
6747 @item
6748 Sizes of @code{CHARACTER} entities in specification statements.
6749 @item
6750 Kind types in specification entities (a Fortran 90 feature).
6751 @item
6752 Initial, terminal, and incrementation parameters for implied-@code{DO}
6753 constructs in @code{DATA} statements.
6754 @end itemize
6756 @item
6757 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
6758 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
6759 expressions are disallowed anyway).
6761 @item
6762 Zero-size array dimensions, as in:
6764 @example
6765 INTEGER I(10,20,4:2)
6766 @end example
6768 @item
6769 Zero-length @code{CHARACTER} entities, as in:
6771 @example
6772 PRINT *, ''
6773 @end example
6775 @item
6776 Substring operators applied to character constants and named
6777 constants, as in:
6779 @example
6780 PRINT *, 'hello'(3:5)
6781 @end example
6783 @item
6784 Null arguments passed to statement function, as in:
6786 @example
6787 PRINT *, FOO(,3)
6788 @end example
6790 @item
6791 Disagreement among program units regarding whether a given @code{COMMON}
6792 area is @code{SAVE}d (for targets where program units in a single source
6793 file are ``glued'' together as they typically are for UNIX development
6794 environments).
6796 @item
6797 Disagreement among program units regarding the size of a
6798 named @code{COMMON} block.
6800 @item
6801 Specification statements following first @code{DATA} statement.
6803 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
6804 but not @samp{INTEGER I}.
6805 The @samp{-fpedantic} option disallows both of these.)
6807 @item
6808 Semicolon as statement separator, as in:
6810 @example
6811 CALL FOO; CALL BAR
6812 @end example
6814 @c @item
6815 @c Comma before list of I/O items in @code{WRITE}
6816 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
6817 @c statements, as with @code{READ} (as explained above).
6819 @item
6820 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
6822 @item
6823 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
6824 versa.
6826 @item
6827 Expressions having two arithmetic operators in a row, such
6828 as @samp{X*-Y}.
6829 @end itemize
6831 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
6832 following constructs result in diagnostics:
6834 @itemize @bullet
6835 @item
6836 Use of semicolon as a statement separator on a line
6837 that has an @code{INCLUDE} directive.
6838 @end itemize
6840 @node Distensions
6841 @section Distensions
6842 @cindex distensions
6843 @cindex ugly features
6844 @cindex features, ugly
6846 The @samp{-fugly-*} command-line options determine whether certain
6847 features supported by VAX FORTRAN and other such compilers, but considered
6848 too ugly to be in code that can be changed to use safer and/or more
6849 portable constructs, are accepted.
6850 These are humorously referred to as ``distensions'',
6851 extensions that just plain look ugly in the harsh light of day.
6853 @menu
6854 * Ugly Implicit Argument Conversion::  Disabled via @samp{-fno-ugly-args}.
6855 * Ugly Assumed-Size Arrays::           Enabled via @samp{-fugly-assumed}.
6856 * Ugly Null Arguments::                Enabled via @samp{-fugly-comma}.
6857 * Ugly Complex Part Extraction::       Enabled via @samp{-fugly-complex}.
6858 * Ugly Conversion of Initializers::    Disabled via @samp{-fno-ugly-init}.
6859 * Ugly Integer Conversions::           Enabled via @samp{-fugly-logint}.
6860 * Ugly Assigned Labels::               Enabled via @samp{-fugly-assign}.
6861 @end menu
6863 @node Ugly Implicit Argument Conversion
6864 @subsection Implicit Argument Conversion
6865 @cindex Hollerith constants
6866 @cindex constants, Hollerith
6868 The @samp{-fno-ugly-args} option disables
6869 passing typeless and Hollerith constants as actual arguments
6870 in procedure invocations.
6871 For example:
6873 @example
6874 CALL FOO(4HABCD)
6875 CALL BAR('123'O)
6876 @end example
6878 @noindent
6879 These constructs can be too easily used to create non-portable
6880 code, but are not considered as ``ugly'' as others.
6881 Further, they are widely used in existing Fortran source code
6882 in ways that often are quite portable.
6883 Therefore, they are enabled by default.
6885 @node Ugly Assumed-Size Arrays
6886 @subsection Ugly Assumed-Size Arrays
6887 @cindex arrays, assumed-size
6888 @cindex assumed-size arrays
6889 @cindex DIMENSION X(1)
6891 The @samp{-fugly-assumed} option enables
6892 the treatment of any array with a final dimension specified as @samp{1}
6893 as an assumed-size array, as if @samp{*} had been specified
6894 instead.
6896 For example, @samp{DIMENSION X(1)} is treated as if it
6897 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
6898 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
6899 or @code{ENTRY} statement in the same program unit.
6901 Use an explicit lower bound to avoid this interpretation.
6902 For example, @samp{DIMENSION X(1:1)} is never treated as if
6903 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
6904 Nor is @samp{DIMENSION X(2-1)} affected by this option,
6905 since that kind of expression is unlikely to have been
6906 intended to designate an assumed-size array.
6908 This option is used to prevent warnings being issued about apparent
6909 out-of-bounds reference such as @samp{X(2) = 99}.
6911 It also prevents the array from being used in contexts that
6912 disallow assumed-size arrays, such as @samp{PRINT *,X}.
6913 In such cases, a diagnostic is generated and the source file is
6914 not compiled.
6916 The construct affected by this option is used only in old code
6917 that pre-exists the widespread acceptance of adjustable and assumed-size
6918 arrays in the Fortran community.
6920 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
6921 treated if @samp{X} is listed as a dummy argument only
6922 @emph{after} the @code{DIMENSION} statement (presumably in
6923 an @code{ENTRY} statement).
6924 For example, @samp{-fugly-assumed} has no effect on the
6925 following program unit:
6927 @example
6928 SUBROUTINE X
6929 REAL A(1)
6930 RETURN
6931 ENTRY Y(A)
6932 PRINT *, A
6934 @end example
6936 @node Ugly Complex Part Extraction
6937 @subsection Ugly Complex Part Extraction
6938 @cindex complex values
6939 @cindex real part
6940 @cindex imaginary part
6942 The @samp{-fugly-complex} option enables
6943 use of the @code{REAL()} and @code{AIMAG()}
6944 intrinsics with arguments that are
6945 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
6947 With @samp{-ff90} in effect, these intrinsics return
6948 the unconverted real and imaginary parts (respectively)
6949 of their argument.
6951 With @samp{-fno-f90} in effect, these intrinsics convert
6952 the real and imaginary parts to @code{REAL(KIND=1)}, and return
6953 the result of that conversion.
6955 Due to this ambiguity, the GNU Fortran language defines
6956 these constructs as invalid, except in the specific
6957 case where they are entirely and solely passed as an
6958 argument to an invocation of the @code{REAL()} intrinsic.
6959 For example,
6961 @example
6962 REAL(REAL(Z))
6963 @end example
6965 @noindent
6966 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
6967 and @samp{-fno-ugly-complex} is in effect, because the
6968 meaning is clear.
6970 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
6971 is specified, in which case the appropriate interpretation is
6972 chosen and no diagnostic is issued.
6974 @xref{CMPAMBIG}, for information on how to cope with existing
6975 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
6976 with @code{COMPLEX(KIND=2)} arguments.
6978 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
6979 intrinsic, used to extract the real part of a complex expression
6980 without conversion.
6981 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
6982 intrinsic, used to extract the imaginary part of a complex expression
6983 without conversion.
6985 @node Ugly Null Arguments
6986 @subsection Ugly Null Arguments
6987 @cindex trailing comma
6988 @cindex comma, trailing
6989 @cindex characters, comma
6990 @cindex null arguments
6991 @cindex arguments, null
6993 The @samp{-fugly-comma} option enables use of a single trailing comma
6994 to mean ``pass an extra trailing null argument''
6995 in a list of actual arguments to an external procedure,
6996 and use of an empty list of arguments to such a procedure
6997 to mean ``pass a single null argument''.
6999 @cindex omitting arguments
7000 @cindex arguments, omitting
7001 (Null arguments often are used in some procedure-calling
7002 schemes to indicate omitted arguments.)
7004 For example, @samp{CALL FOO(,)} means ``pass
7005 two null arguments'', rather than ``pass one null argument''.
7006 Also, @samp{CALL BAR()} means ``pass one null argument''.
7008 This construct is considered ``ugly'' because it does not
7009 provide an elegant way to pass a single null argument
7010 that is syntactically distinct from passing no arguments.
7011 That is, this construct changes the meaning of code that
7012 makes no use of the construct.
7014 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
7015 and @samp{I = JFUNC()} pass a single null argument, instead
7016 of passing no arguments as required by the Fortran 77 and
7017 90 standards.
7019 @emph{Note:} Many systems gracefully allow the case
7020 where a procedure call passes one extra argument that the
7021 called procedure does not expect.
7023 So, in practice, there might be no difference in
7024 the behavior of a program that does @samp{CALL FOO()}
7025 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
7026 in force as compared to its behavior when compiled
7027 with the default, @samp{-fno-ugly-comma}, in force,
7028 assuming @samp{FOO} and @samp{JFUNC} do not expect any
7029 arguments to be passed.
7031 @node Ugly Conversion of Initializers
7032 @subsection Ugly Conversion of Initializers
7034 The constructs disabled by @samp{-fno-ugly-init} are:
7036 @itemize @bullet
7037 @cindex Hollerith constants
7038 @cindex constants, Hollerith
7039 @item
7040 Use of Hollerith and typeless constants in contexts where they set
7041 initial (compile-time) values for variables, arrays, and named
7042 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
7043 type-declaration statements specifying initial values.
7045 Here are some sample initializations that are disabled by the
7046 @samp{-fno-ugly-init} option:
7048 @example
7049 PARAMETER (VAL='9A304FFE'X)
7050 REAL*8 STRING/8HOUTPUT00/
7051 DATA VAR/4HABCD/
7052 @end example
7054 @cindex character constants
7055 @cindex constants, character
7056 @item
7057 In the same contexts as above, use of character constants to initialize
7058 numeric items and vice versa (one constant per item).
7060 Here are more sample initializations that are disabled by the
7061 @samp{-fno-ugly-init} option:
7063 @example
7064 INTEGER IA
7065 CHARACTER BELL
7066 PARAMETER (IA = 'A')
7067 PARAMETER (BELL = 7)
7068 @end example
7070 @item
7071 Use of Hollerith and typeless constants on the right-hand side
7072 of assignment statements to numeric types, and in other
7073 contexts (such as passing arguments in invocations of
7074 intrinsic procedures and statement functions) that
7075 are treated as assignments to known types (the dummy
7076 arguments, in these cases).
7078 Here are sample statements that are disabled by the
7079 @samp{-fno-ugly-init} option:
7081 @example
7082 IVAR = 4HABCD
7083 PRINT *, IMAX0(2HAB, 2HBA)
7084 @end example
7085 @end itemize
7087 The above constructs, when used,
7088 can tend to result in non-portable code.
7089 But, they are widely used in existing Fortran code in ways
7090 that often are quite portable.
7091 Therefore, they are enabled by default.
7093 @node Ugly Integer Conversions
7094 @subsection Ugly Integer Conversions
7096 The constructs enabled via @samp{-fugly-logint} are:
7098 @itemize @bullet
7099 @item
7100 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
7101 dictated by
7102 context (typically implies nonportable dependencies on how a
7103 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
7105 @item
7106 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
7107 statements.
7108 @end itemize
7110 The above constructs are disabled by default because use
7111 of them tends to lead to non-portable code.
7112 Even existing Fortran code that uses that often turns out
7113 to be non-portable, if not outright buggy.
7115 Some of this is due to differences among implementations as
7116 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
7117 @code{INTEGER} values---Fortran code that assumes a particular
7118 coding is likely to use one of the above constructs, and is
7119 also likely to not work correctly on implementations using
7120 different encodings.
7122 @xref{Equivalence Versus Equality}, for more information.
7124 @node Ugly Assigned Labels
7125 @subsection Ugly Assigned Labels
7126 @cindex ASSIGN statement
7127 @cindex statements, ASSIGN
7128 @cindex assigned labels
7129 @cindex pointers
7131 The @samp{-fugly-assign} option forces @code{g77} to use the
7132 same storage for assigned labels as it would for a normal
7133 assignment to the same variable.
7135 For example, consider the following code fragment:
7137 @example
7138 I = 3
7139 ASSIGN 10 TO I
7140 @end example
7142 @noindent
7143 Normally, for portability and improved diagnostics, @code{g77}
7144 reserves distinct storage for a ``sibling'' of @samp{I}, used
7145 only for @code{ASSIGN} statements to that variable (along with
7146 the corresponding assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O
7147 statements that reference the variable).
7149 However, some code (that violates the ANSI FORTRAN 77 standard)
7150 attempts to copy assigned labels among variables involved with
7151 @code{ASSIGN} statements, as in:
7153 @example
7154 ASSIGN 10 TO I
7155 ISTATE(5) = I
7156 @dots{}
7157 J = ISTATE(ICUR)
7158 GOTO J
7159 @end example
7161 @noindent
7162 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
7163 is specified on the command-line, ensuring that the value of @code{I}
7164 referenced in the second line is whatever value @code{g77} uses
7165 to designate statement label @samp{10}, so the value may be
7166 copied into the @samp{ISTATE} array, later retrieved into a
7167 variable of the appropriate type (@samp{J}), and used as the target of
7168 an assigned-@code{GOTO} statement.
7170 @emph{Note:} To avoid subtle program bugs,
7171 when @samp{-fugly-assign} is specified,
7172 @code{g77} requires the type of variables
7173 specified in assigned-label contexts
7174 @emph{must} be the same type returned by @code{%LOC()}.
7175 On many systems, this type is effectively the same
7176 as @code{INTEGER(KIND=1)}, while, on others, it is
7177 effectively the same as @code{INTEGER(KIND=2)}.
7179 Do @emph{not} depend on @code{g77} actually writing valid pointers
7180 to these variables, however.
7181 While @code{g77} currently chooses that implementation, it might
7182 be changed in the future.
7184 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
7185 for implementation details on assigned-statement labels.
7187 @node Compiler
7188 @chapter The GNU Fortran Compiler
7190 The GNU Fortran compiler, @code{g77}, supports programs written
7191 in the GNU Fortran language and in some other dialects of Fortran.
7193 Some aspects of how @code{g77} works are universal regardless
7194 of dialect, and yet are not properly part of the GNU Fortran
7195 language itself.
7196 These are described below.
7198 @emph{Note: This portion of the documentation definitely needs a lot
7199 of work!}
7201 @menu
7202 * Compiler Limits::
7203 * Run-time Environment Limits::
7204 * Compiler Types::
7205 * Compiler Constants::
7206 * Compiler Intrinsics::
7207 @end menu
7209 @node Compiler Limits
7210 @section Compiler Limits
7211 @cindex limits, compiler
7212 @cindex compiler limits
7214 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
7215 on lengths of identifiers, number of continuation lines, number of external
7216 symbols in a program, and so on.
7218 @cindex options, -Nl
7219 @cindex -Nl option
7220 @cindex options, -Nx
7221 @cindex -Nx option
7222 @cindex limits, continuation lines
7223 @cindex limits, lengths of names
7224 For example, some other Fortran compiler have an option
7225 (such as @samp{-Nl@var{x}}) to increase the limit on the
7226 number of continuation lines.
7227 Also, some Fortran compilation systems have an option
7228 (such as @samp{-Nx@var{x}}) to increase the limit on the
7229 number of external symbols.
7231 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
7232 no equivalent options, since they do not impose arbitrary
7233 limits in these areas.
7235 @cindex rank, maximum
7236 @cindex maximum rank
7237 @cindex number of dimensions, maximum
7238 @cindex maximum number of dimensions
7239 @cindex limits, rank
7240 @cindex limits, array dimensions
7241 @code{g77} does currently limit the number of dimensions in an array
7242 to the same degree as do the Fortran standards---seven (7).
7243 This restriction might be lifted in a future version.
7245 @node Run-time Environment Limits
7246 @section Run-time Environment Limits
7247 @cindex limits, run-time library
7248 @cindex wraparound
7250 As a portable Fortran implementation,
7251 @code{g77} offers its users direct access to,
7252 and otherwise depends upon,
7253 the underlying facilities of the system
7254 used to build @code{g77},
7255 the system on which @code{g77} itself is used to compile programs,
7256 and the system on which the @code{g77}-compiled program is actually run.
7257 (For most users, the three systems are of the same
7258 type---combination of operating environment and hardware---often
7259 the same physical system.)
7261 The run-time environment for a particular system
7262 inevitably imposes some limits on a program's use
7263 of various system facilities.
7264 These limits vary from system to system.
7266 Even when such limits might be well beyond the
7267 possibility of being encountered on a particular system,
7268 the @code{g77} run-time environment
7269 has certain built-in limits,
7270 usually, but not always, stemming from intrinsics
7271 with inherently limited interfaces.
7273 Currently, the @code{g77} run-time environment
7274 does not generally offer a less-limiting environment
7275 by augmenting the underlying system's own environment.
7277 Therefore, code written in the GNU Fortran language,
7278 while syntactically and semantically portable,
7279 might nevertheless make non-portable assumptions
7280 about the run-time environment---assumptions that
7281 prove to be false for some particular environments.
7283 The GNU Fortran language,
7284 the @code{g77} compiler and run-time environment,
7285 and the @code{g77} documentation
7286 do not yet offer comprehensive portable work-arounds for such limits,
7287 though programmers should be able to
7288 find their own in specific instances.
7290 Not all of the limitations are described in this document.
7291 Some of the known limitations include:
7293 @menu
7294 * Timer Wraparounds::
7295 * Year 2000 (Y2K) Problems::
7296 * Array Size::
7297 * Character-variable Length::
7298 * Year 10000 (Y10K) Problems::
7299 @end menu
7301 @node Timer Wraparounds
7302 @subsection Timer Wraparounds
7304 Intrinsics that return values computed from system timers,
7305 whether elapsed (wall-clock) timers,
7306 process CPU timers,
7307 or other kinds of timers,
7308 are prone to experiencing wrap-around errors
7309 (or returning wrapped-around values from successive calls)
7310 due to insufficient ranges
7311 offered by the underlying system's timers.
7313 @cindex negative time
7314 @cindex short time
7315 @cindex long time
7316 Some of the symptoms of such behaviors include
7317 apparently negative time being computed for a duration,
7318 an extremely short amount of time being computed for a long duration,
7319 and an extremely long amount of time being computed for a short duration.
7321 See the following for intrinsics
7322 known to have potential problems in these areas
7323 on at least some systems:
7324 @ref{CPU_Time Intrinsic},
7325 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
7326 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
7327 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
7328 @ref{Secnds Intrinsic},
7329 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
7330 @ref{System_Clock Intrinsic},
7331 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
7332 @ref{Time8 Intrinsic}.
7334 @node Year 2000 (Y2K) Problems
7335 @subsection Year 2000 (Y2K) Problems
7336 @cindex Y2K compliance
7337 @cindex Year 2000 compliance
7339 While the @code{g77} compiler itself is believed to
7340 be Year-2000 (Y2K) compliant,
7341 some intrinsics are not,
7342 and, potentially, some underlying systems are not,
7343 perhaps rendering some Y2K-compliant intrinsics
7344 non-compliant when used on those particular systems.
7346 Fortran code that uses non-Y2K-compliant intrinsics
7347 (listed below)
7348 is, itself, almost certainly not compliant,
7349 and should be modified to use Y2K-compliant intrinsics instead.
7351 Fortran code that uses no non-Y2K-compliant intrinsics,
7352 but which currently is running on a non-Y2K-compliant system,
7353 can be made more Y2K compliant by compiling and
7354 linking it for use on a new Y2K-compliant system,
7355 such as a new version of an old, non-Y2K-compliant, system.
7357 Currently, information on Y2K and related issues
7358 is being maintained at
7359 @uref{http://www.gnu.org/software/year2000-list.html}.
7361 See the following for intrinsics
7362 known to have potential problems in these areas
7363 on at least some systems:
7364 @ref{Date Intrinsic},
7365 @ref{IDate Intrinsic (VXT)}.
7367 @cindex y2kbuggy
7368 @cindex date_y2kbuggy_0
7369 @cindex vxtidate_y2kbuggy_0
7370 @cindex G77_date_y2kbuggy_0
7371 @cindex G77_vxtidate_y2kbuggy_0
7372 The @code{libg2c} library
7373 shipped with any @code{g77} that warns
7374 about invocation of a non-Y2K-compliant intrinsic
7375 has renamed the @code{EXTERNAL} procedure names
7376 of those intrinsics.
7377 This is done so that
7378 the @code{libg2c} implementations of these intrinsics
7379 cannot be directly linked to
7380 as @code{EXTERNAL} names
7381 (which normally would avoid the non-Y2K-intrinsic warning).
7383 The renamed forms of the @code{EXTERNAL} names
7384 of these renamed procedures
7385 may be linked to
7386 by appending the string @samp{_y2kbug}
7387 to the name of the procedure
7388 in the source code.
7389 For example:
7391 @smallexample
7392 CHARACTER*20 STR
7393 INTEGER YY, MM, DD
7394 EXTERNAL DATE_Y2KBUG, VXTIDATE_Y2KBUG
7395 CALL DATE_Y2KBUG (STR)
7396 CALL VXTIDATE_Y2KBUG (MM, DD, YY)
7397 @end smallexample
7399 (Note that the @code{EXTERNAL} statement
7400 is not actually required,
7401 since the modified names are not recognized as intrinsics
7402 by the current version of @code{g77}.
7403 But it is shown in this specific case,
7404 for purposes of illustration.)
7406 The renaming of @code{EXTERNAL} procedure names of these intrinsics
7407 causes unresolved references at link time.
7408 For example, @samp{EXTERNAL DATE; CALL DATE(STR)}
7409 is normally compiled by @code{g77}
7410 as, in C, @samp{date_(&str, 20);}.
7411 This, in turn, links to the @code{date_} procedure
7412 in the @code{libE77} portion of @code{libg2c},
7413 which purposely calls a nonexistent procedure
7414 named @code{G77_date_y2kbuggy_0}.
7415 The resulting link-time error is designed, via this name,
7416 to encourage the programmer to look up the
7417 index entries to this portion of the @code{g77} documentation.
7419 Generally, we recommend that the @code{EXTERNAL} method
7420 of invoking procedures in @code{libg2c}
7421 @emph{not} be used.
7422 When used, some of the correctness checking
7423 normally performed by @code{g77}
7424 is skipped.
7426 In particular, it is probably better to use the
7427 @code{INTRINSIC} method of invoking
7428 non-Y2K-compliant procedures,
7429 so anyone compiling the code
7430 can quickly notice the potential Y2K problems
7431 (via the warnings printing by @code{g77})
7432 without having to even look at the code itself.
7434 If there are problems linking @code{libg2c}
7435 to code compiled by @code{g77}
7436 that involve the string @samp{y2kbug},
7437 and these are not explained above,
7438 that probably indicates
7439 that a version of @code{libg2c}
7440 older than @code{g77}
7441 is being linked to,
7442 or that the new library is being linked
7443 to code compiled by an older version of @code{g77}.
7445 That's because, as of the version that warns about
7446 non-Y2K-compliant intrinsic invocation,
7447 @code{g77} references the @code{libg2c} implementations
7448 of those intrinsics
7449 using new names, containing the string @samp{y2kbug}.
7451 So, linking newly-compiled code
7452 (invoking one of the intrinsics in question)
7453 to an old library
7454 might yield an unresolved reference
7455 to @code{G77_date_y2kbug_0}.
7456 (The old library calls it @code{G77_date_0}.)
7458 Similarly, linking previously-compiled code
7459 to a new library
7460 might yield an unresolved reference
7461 to @code{G77_vxtidate_0}.
7462 (The new library calls it @code{G77_vxtidate_y2kbug_0}.)
7464 The proper fix for the above problems
7465 is to obtain the latest release of @code{g77}
7466 and related products
7467 (including @code{libg2c})
7468 and install them on all systems,
7469 then recompile, relink, and install
7470 (as appropriate)
7471 all existing Fortran programs.
7473 (Normally, this sort of renaming is steadfastly avoided.
7474 In this case, however, it seems more important to highlight
7475 potential Y2K problems
7476 than to ease the transition
7477 of potentially non-Y2K-compliant code
7478 to new versions of @code{g77} and @code{libg2c}.)
7480 @node Array Size
7481 @subsection Array Size
7482 @cindex limits, array size
7483 @cindex array size
7485 Currently, @code{g77} uses the default @code{INTEGER} type
7486 for array indexes,
7487 which limits the sizes of single-dimension arrays
7488 on systems offering a larger address space
7489 than can be addressed by that type.
7490 (That @code{g77} puts all arrays in memory
7491 could be considered another limitation---it
7492 could use large temporary files---but that decision
7493 is left to the programmer as an implementation choice
7494 by most Fortran implementations.)
7496 @c ??? Investigate this, to offer a more clear statement
7497 @c than the following paragraphs do.  -- burley 1999-02-17
7498 It is not yet clear whether this limitation
7499 never, sometimes, or always applies to the
7500 sizes of multiple-dimension arrays as a whole.
7502 For example, on a system with 64-bit addresses
7503 and 32-bit default @code{INTEGER},
7504 an array with a size greater than can be addressed
7505 by a 32-bit offset
7506 can be declared using multiple dimensions.
7507 Such an array is therefore larger
7508 than a single-dimension array can be,
7509 on the same system.
7511 @cindex limits, multi-dimension arrays
7512 @cindex multi-dimension arrays
7513 @cindex arrays, dimensioning
7514 Whether large multiple-dimension arrays are reliably supported
7515 depends mostly on the @code{gcc} back end (code generator)
7516 used by @code{g77}, and has not yet been fully investigated.
7518 @node Character-variable Length
7519 @subsection Character-variable Length
7520 @cindex limits, on character-variable length
7521 @cindex character-variable length
7523 Currently, @code{g77} uses the default @code{INTEGER} type
7524 for the lengths of @code{CHARACTER} variables
7525 and array elements.
7527 This means that, for example,
7528 a system with a 64-bit address space
7529 and a 32-bit default @code{INTEGER} type
7530 does not, under @code{g77},
7531 support a @code{CHARACTER*@var{n}} declaration
7532 where @var{n} is greater than 2147483647.
7534 @node Year 10000 (Y10K) Problems
7535 @subsection Year 10000 (Y10K) Problems
7536 @cindex Y10K compliance
7537 @cindex Year 10000 compliance
7539 Most intrinsics returning, or computing values based on,
7540 date information are prone to Year-10000 (Y10K) problems,
7541 due to supporting only 4 digits for the year.
7543 See the following for examples:
7544 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
7545 @ref{IDate Intrinsic (UNIX)},
7546 @ref{Time Intrinsic (VXT)},
7547 @ref{Date_and_Time Intrinsic}.
7549 @node Compiler Types
7550 @section Compiler Types
7551 @cindex types, of data
7552 @cindex data types
7554 Fortran implementations have a fair amount of freedom given them by the
7555 standard as far as how much storage space is used and how much precision
7556 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
7557 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
7558 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
7559 Further, many compilers offer so-called @samp{*@var{n}} notation, but
7560 the interpretation of @var{n} varies across compilers and target architectures.
7562 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
7563 and @code{REAL(KIND=1)}
7564 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
7565 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
7566 Further, it requires that @code{COMPLEX(KIND=1)}
7567 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
7568 storage-associated (such as via @code{EQUIVALENCE})
7569 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
7570 corresponds to the real element and @samp{R(2)} to the imaginary
7571 element of the @code{COMPLEX(KIND=1)} variable.
7573 (Few requirements as to precision or ranges of any of these are
7574 placed on the implementation, nor is the relationship of storage sizes of
7575 these types to the @code{CHARACTER} type specified, by the standard.)
7577 @code{g77} follows the above requirements, warning when compiling
7578 a program requires placement of items in memory that contradict the
7579 requirements of the target architecture.
7580 (For example, a program can require placement of a @code{REAL(KIND=2)}
7581 on a boundary that is not an even multiple of its size, but still an
7582 even multiple of the size of a @code{REAL(KIND=1)} variable.
7583 On some target architectures, using the canonical
7584 mapping of Fortran types to underlying architectural types, such
7585 placement is prohibited by the machine definition or
7586 the Application Binary Interface (ABI) in force for
7587 the configuration defined for building @code{gcc} and @code{g77}.
7588 @code{g77} warns about such
7589 situations when it encounters them.)
7591 @code{g77} follows consistent rules for configuring the mapping between Fortran
7592 types, including the @samp{*@var{n}} notation, and the underlying architectural
7593 types as accessed by a similarly-configured applicable version of the
7594 @code{gcc} compiler.
7595 These rules offer a widely portable, consistent Fortran/C
7596 environment, although they might well conflict with the expectations of
7597 users of Fortran compilers designed and written for particular
7598 architectures.
7600 These rules are based on the configuration that is in force for the
7601 version of @code{gcc} built in the same release as @code{g77} (and
7602 which was therefore used to build both the @code{g77} compiler
7603 components and the @code{libg2c} run-time library):
7605 @table @code
7606 @cindex REAL(KIND=1) type
7607 @cindex types, REAL(KIND=1)
7608 @item REAL(KIND=1)
7609 Same as @code{float} type.
7611 @cindex REAL(KIND=2) type
7612 @cindex types, REAL(KIND=2)
7613 @item REAL(KIND=2)
7614 Same as whatever floating-point type that is twice the size
7615 of a @code{float}---usually, this is a @code{double}.
7617 @cindex INTEGER(KIND=1) type
7618 @cindex types, INTEGER(KIND=1)
7619 @item INTEGER(KIND=1)
7620 Same as an integral type that is occupies the same amount
7621 of memory storage as @code{float}---usually, this is either
7622 an @code{int} or a @code{long int}.
7624 @cindex LOGICAL(KIND=1) type
7625 @cindex types, LOGICAL(KIND=1)
7626 @item LOGICAL(KIND=1)
7627 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
7629 @cindex INTEGER(KIND=2) type
7630 @cindex types, INTEGER(KIND=2)
7631 @item INTEGER(KIND=2)
7632 Twice the size, and usually nearly twice the range,
7633 as @code{INTEGER(KIND=1)}---usually, this is either
7634 a @code{long int} or a @code{long long int}.
7636 @cindex LOGICAL(KIND=2) type
7637 @cindex types, LOGICAL(KIND=2)
7638 @item LOGICAL(KIND=2)
7639 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
7641 @cindex INTEGER(KIND=3) type
7642 @cindex types, INTEGER(KIND=3)
7643 @item INTEGER(KIND=3)
7644 Same @code{gcc} type as signed @code{char}.
7646 @cindex LOGICAL(KIND=3) type
7647 @cindex types, LOGICAL(KIND=3)
7648 @item LOGICAL(KIND=3)
7649 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
7651 @cindex INTEGER(KIND=6) type
7652 @cindex types, INTEGER(KIND=6)
7653 @item INTEGER(KIND=6)
7654 Twice the size, and usually nearly twice the range,
7655 as @code{INTEGER(KIND=3)}---usually, this is
7656 a @code{short}.
7658 @cindex LOGICAL(KIND=6) type
7659 @cindex types, LOGICAL(KIND=6)
7660 @item LOGICAL(KIND=6)
7661 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
7663 @cindex COMPLEX(KIND=1) type
7664 @cindex types, COMPLEX(KIND=1)
7665 @item COMPLEX(KIND=1)
7666 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
7667 one for the imaginary part).
7669 @cindex COMPLEX(KIND=2) type
7670 @cindex types, COMPLEX(KIND=2)
7671 @item COMPLEX(KIND=2)
7672 Two @code{REAL(KIND=2)} scalars.
7674 @cindex *@var{n} notation
7675 @item @var{numeric-type}*@var{n}
7676 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
7677 Same as whatever @code{gcc} type occupies @var{n} times the storage
7678 space of a @code{gcc} @code{char} item.
7680 @cindex DOUBLE PRECISION type
7681 @cindex types, DOUBLE PRECISION
7682 @item DOUBLE PRECISION
7683 Same as @code{REAL(KIND=2)}.
7685 @cindex DOUBLE COMPLEX type
7686 @cindex types, DOUBLE COMPLEX
7687 @item DOUBLE COMPLEX
7688 Same as @code{COMPLEX(KIND=2)}.
7689 @end table
7691 Note that the above are proposed correspondences and might change
7692 in future versions of @code{g77}---avoid writing code depending
7693 on them.
7695 Other types supported by @code{g77}
7696 are derived from gcc types such as @code{char}, @code{short},
7697 @code{int}, @code{long int}, @code{long long int}, @code{long double},
7698 and so on.
7699 That is, whatever types @code{gcc} already supports, @code{g77} supports
7700 now or probably will support in a future version.
7701 The rules for the @samp{@var{numeric-type}*@var{n}} notation
7702 apply to these types,
7703 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
7704 assigned in a way that encourages clarity, consistency, and portability.
7706 @node Compiler Constants
7707 @section Compiler Constants
7708 @cindex constants
7709 @cindex types, constants
7711 @code{g77} strictly assigns types to @emph{all} constants not
7712 documented as ``typeless'' (typeless constants including @samp{'1'Z},
7713 for example).
7714 Many other Fortran compilers attempt to assign types to typed constants
7715 based on their context.
7716 This results in hard-to-find bugs, nonportable
7717 code, and is not in the spirit (though it strictly follows the letter)
7718 of the 77 and 90 standards.
7720 @code{g77} might offer, in a future release, explicit constructs by
7721 which a wider variety of typeless constants may be specified, and/or
7722 user-requested warnings indicating places where @code{g77} might differ
7723 from how other compilers assign types to constants.
7725 @xref{Context-Sensitive Constants}, for more information on this issue.
7727 @node Compiler Intrinsics
7728 @section Compiler Intrinsics
7730 @code{g77} offers an ever-widening set of intrinsics.
7731 Currently these all are procedures (functions and subroutines).
7733 Some of these intrinsics are unimplemented, but their names reserved
7734 to reduce future problems with existing code as they are implemented.
7735 Others are implemented as part of the GNU Fortran language, while
7736 yet others are provided for compatibility with other dialects of
7737 Fortran but are not part of the GNU Fortran language.
7739 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
7740 a facility that is simply an extension of the intrinsic groups provided
7741 by the GNU Fortran language.
7743 @menu
7744 * Intrinsic Groups::  How intrinsics are grouped for easy management.
7745 * Other Intrinsics::  Intrinsics other than those in the GNU
7746                        Fortran language.
7747 @end menu
7749 @node Intrinsic Groups
7750 @subsection Intrinsic Groups
7751 @cindex groups of intrinsics
7752 @cindex intrinsics, groups
7754 A given specific intrinsic belongs in one or more groups.
7755 Each group is deleted, disabled, hidden, or enabled
7756 by default or a command-line option.
7757 The meaning of each term follows.
7759 @table @b
7760 @cindex deleted intrinsics
7761 @cindex intrinsics, deleted
7762 @item Deleted
7763 No intrinsics are recognized as belonging to that group.
7765 @cindex disabled intrinsics
7766 @cindex intrinsics, disabled
7767 @item Disabled
7768 Intrinsics are recognized as belonging to the group, but
7769 references to them (other than via the @code{INTRINSIC} statement)
7770 are disallowed through that group.
7772 @cindex hidden intrinsics
7773 @cindex intrinsics, hidden
7774 @item Hidden
7775 Intrinsics in that group are recognized and enabled (if implemented)
7776 @emph{only} if the first mention of the actual name of an intrinsic
7777 in a program unit is in an @code{INTRINSIC} statement.
7779 @cindex enabled intrinsics
7780 @cindex intrinsics, enabled
7781 @item Enabled
7782 Intrinsics in that group are recognized and enabled (if implemented).
7783 @end table
7785 The distinction between deleting and disabling a group is illustrated
7786 by the following example.
7787 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
7788 If group @samp{FGR} is deleted, the following program unit will
7789 successfully compile, because @samp{FOO()} will be seen as a
7790 reference to an external function named @samp{FOO}:
7792 @example
7793 PRINT *, FOO()
7795 @end example
7797 @noindent
7798 If group @samp{FGR} is disabled, compiling the above program will produce
7799 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
7800 or, if properly invoked, it is not enabled.
7801 To change the above program so it references an external function @samp{FOO}
7802 instead of the disabled @samp{FOO} intrinsic,
7803 add the following line to the top:
7805 @example
7806 EXTERNAL FOO
7807 @end example
7809 @noindent
7810 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
7811 that group do not exist at all, whereas disabling it tells @code{g77} to
7812 recognize them as (disabled) intrinsics in intrinsic-like contexts.
7814 Hiding a group is like enabling it, but the intrinsic must be first
7815 named in an @code{INTRINSIC} statement to be considered a reference to the
7816 intrinsic rather than to an external procedure.
7817 This might be the ``safest'' way to treat a new group of intrinsics
7818 when compiling old
7819 code, because it allows the old code to be generally written as if
7820 those new intrinsics never existed, but to be changed to use them
7821 by inserting @code{INTRINSIC} statements in the appropriate places.
7822 However, it should be the goal of development to use @code{EXTERNAL}
7823 for all names of external procedures that might be intrinsic names.
7825 If an intrinsic is in more than one group, it is enabled if any of its
7826 containing groups are enabled; if not so enabled, it is hidden if
7827 any of its containing groups are hidden; if not so hidden, it is disabled
7828 if any of its containing groups are disabled; if not so disabled, it is
7829 deleted.
7830 This extra complication is necessary because some intrinsics,
7831 such as @code{IBITS}, belong to more than one group, and hence should be
7832 enabled if any of the groups to which they belong are enabled, and so
7835 The groups are:
7837 @cindex intrinsics, groups of
7838 @cindex groups of intrinsics
7839 @table @code
7840 @cindex @code{badu77} intrinsics group
7841 @item badu77
7842 UNIX intrinsics having inappropriate forms (usually functions that
7843 have intended side effects).
7845 @cindex @code{gnu} intrinsics group
7846 @item gnu
7847 Intrinsics the GNU Fortran language supports that are extensions to
7848 the Fortran standards (77 and 90).
7850 @cindex @code{f2c} intrinsics group
7851 @item f2c
7852 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
7854 @cindex @code{f90} intrinsics group
7855 @item f90
7856 Fortran 90 intrinsics.
7858 @cindex @code{mil} intrinsics group
7859 @item mil
7860 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
7862 @cindex @code{mil} intrinsics group
7863 @item unix
7864 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
7866 @cindex @code{mil} intrinsics group
7867 @item vxt
7868 VAX/VMS FORTRAN (current as of v4) intrinsics.
7869 @end table
7871 @node Other Intrinsics
7872 @subsection Other Intrinsics
7873 @cindex intrinsics, others
7874 @cindex other intrinsics
7876 @code{g77} supports intrinsics other than those in the GNU Fortran
7877 language proper.
7878 This set of intrinsics is described below.
7880 @ifinfo
7881 (Note that the empty lines appearing in the menu below
7882 are not intentional---they result from a bug in the
7883 @code{makeinfo} program.)
7884 @end ifinfo
7886 @c The actual documentation for intrinsics comes from
7887 @c intdoc.texi, which in turn is automatically generated
7888 @c from the internal g77 tables in intrin.def _and_ the
7889 @c largely hand-written text in intdoc.h.  So, if you want
7890 @c to change or add to existing documentation on intrinsics,
7891 @c you probably want to edit intdoc.h.
7893 @clear familyF77
7894 @clear familyGNU
7895 @clear familyASC
7896 @clear familyMIL
7897 @clear familyF90
7898 @set familyVXT
7899 @set familyFVZ
7900 @clear familyF2C
7901 @clear familyF2U
7902 @set familyBADU77
7903 @include intdoc.texi
7905 @node Other Compilers
7906 @chapter Other Compilers
7908 An individual Fortran source file can be compiled to
7909 an object (@file{*.o}) file instead of to the final
7910 program executable.
7911 This allows several portions of a program to be compiled
7912 at different times and linked together whenever a new
7913 version of the program is needed.
7914 However, it introduces the issue of @dfn{object compatibility}
7915 across the various object files (and libraries, or @file{*.a}
7916 files) that are linked together to produce any particular
7917 executable file.
7919 Object compatibility is an issue when combining, in one
7920 program, Fortran code compiled by more than one compiler
7921 (or more than one configuration of a compiler).
7922 If the compilers
7923 disagree on how to transform the names of procedures, there
7924 will normally be errors when linking such programs.
7925 Worse, if the compilers agree on naming, but disagree on issues
7926 like how to pass parameters, return arguments, and lay out
7927 @code{COMMON} areas, the earliest detected errors might be the
7928 incorrect results produced by the program (and that assumes
7929 these errors are detected, which is not always the case).
7931 Normally, @code{g77} generates code that is
7932 object-compatible with code generated by a version of
7933 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
7934 to be generally compatible with @code{g77} as built by @code{gcc}.
7935 (Normally, @code{f2c} will, by default, conform to the appropriate
7936 configuration, but it is possible that older or perhaps even newer
7937 versions of @code{f2c}, or versions having certain configuration changes
7938 to @code{f2c} internals, will produce object files that are
7939 incompatible with @code{g77}.)
7941 For example, a Fortran string subroutine
7942 argument will become two arguments on the C side: a @code{char *}
7943 and an @code{int} length.
7945 Much of this compatibility results from the fact that
7946 @code{g77} uses the same run-time library,
7947 @code{libf2c}, used by @code{f2c},
7948 though @code{g77} gives its version the name @code{libg2c}
7949 so as to avoid conflicts when linking,
7950 installing them in the same directories,
7951 and so on.
7953 Other compilers might or might not generate code that
7954 is object-compatible with @code{libg2c} and current @code{g77},
7955 and some might offer such compatibility only when explicitly
7956 selected via a command-line option to the compiler.
7958 @emph{Note: This portion of the documentation definitely needs a lot
7959 of work!}
7961 @menu
7962 * Dropping f2c Compatibility::  When speed is more important.
7963 * Compilers Other Than f2c::    Interoperation with code from other compilers.
7964 @end menu
7966 @node Dropping f2c Compatibility
7967 @section Dropping @code{f2c} Compatibility
7969 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
7970 some cases, faster code, by not needing to allow to the possibility
7971 of linking with code compiled by @code{f2c}.
7973 For example, this affects how @code{REAL(KIND=1)},
7974 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
7975 With @samp{-fno-f2c}, they are
7976 compiled as returning the appropriate @code{gcc} type
7977 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
7978 in many configurations).
7980 With @samp{-ff2c} in force, they
7981 are compiled differently (with perhaps slower run-time performance)
7982 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
7983 C as an intermediate language---@code{REAL(KIND=1)} functions
7984 return C's @code{double} type, while @code{COMPLEX} functions return
7985 @code{void} and use an extra argument pointing to a place for the functions to
7986 return their values.
7988 It is possible that, in some cases, leaving @samp{-ff2c} in force
7989 might produce faster code than using @samp{-fno-f2c}.
7990 Feel free to experiment, but remember to experiment with changing the way
7991 @emph{entire programs and their Fortran libraries are compiled} at
7992 a time, since this sort of experimentation affects the interface
7993 of code generated for a Fortran source file---that is, it affects
7994 object compatibility.
7996 Note that @code{f2c} compatibility is a fairly static target to achieve,
7997 though not necessarily perfectly so, since, like @code{g77}, it is
7998 still being improved.
7999 However, specifying @samp{-fno-f2c} causes @code{g77}
8000 to generate code that will probably be incompatible with code
8001 generated by future versions of @code{g77} when the same option
8002 is in force.
8003 You should make sure you are always able to recompile complete
8004 programs from source code when upgrading to new versions of @code{g77}
8005 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
8007 Therefore, if you are using @code{g77} to compile libraries and other
8008 object files for possible future use and you don't want to require
8009 recompilation for future use with subsequent versions of @code{g77},
8010 you might want to stick with @code{f2c} compatibility for now, and
8011 carefully watch for any announcements about changes to the
8012 @code{f2c}/@code{libf2c} interface that might affect existing programs
8013 (thus requiring recompilation).
8015 It is probable that a future version of @code{g77} will not,
8016 by default, generate object files compatible with @code{f2c},
8017 and that version probably would no longer use @code{libf2c}.
8018 If you expect to depend on this compatibility in the
8019 long term, use the options @samp{-ff2c -ff2c-library} when compiling
8020 all of the applicable code.
8021 This should cause future versions of @code{g77} either to produce
8022 compatible code (at the expense of the availability of some features and
8023 performance), or at the very least, to produce diagnostics.
8025 (The library @code{g77} produces will no longer be named @file{libg2c}
8026 when it is no longer generally compatible with @file{libf2c}.
8027 It will likely be referred to, and, if installed as a distinct
8028 library, named @code{libg77}, or some other as-yet-unused name.)
8030 @node Compilers Other Than f2c
8031 @section Compilers Other Than @code{f2c}
8033 On systems with Fortran compilers other than @code{f2c} and @code{g77},
8034 code compiled by @code{g77} is not expected to work
8035 well with code compiled by the native compiler.
8036 (This is true for @code{f2c}-compiled objects as well.)
8037 Libraries compiled with the native compiler probably will have
8038 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
8040 Reasons for such incompatibilities include:
8042 @itemize @bullet
8043 @item
8044 There might be differences in the way names of Fortran procedures
8045 are translated for use in the system's object-file format.
8046 For example, the statement @samp{CALL FOO} might be compiled
8047 by @code{g77} to call a procedure the linker @code{ld} sees
8048 given the name @samp{_foo_}, while the apparently corresponding
8049 statement @samp{SUBROUTINE FOO} might be compiled by the
8050 native compiler to define the linker-visible name @samp{_foo},
8051 or @samp{_FOO_}, and so on.
8053 @item
8054 There might be subtle type mismatches which cause subroutine arguments
8055 and function return values to get corrupted.
8057 This is why simply getting @code{g77} to
8058 transform procedure names the same way a native
8059 compiler does is not usually a good idea---unless
8060 some effort has been made to ensure that, aside
8061 from the way the two compilers transform procedure
8062 names, everything else about the way they generate
8063 code for procedure interfaces is identical.
8065 @item
8066 Native compilers
8067 use libraries of private I/O routines which will not be available
8068 at link time unless you have the native compiler---and you would
8069 have to explicitly ask for them.
8071 For example, on the Sun you
8072 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
8073 command.
8074 @end itemize
8076 @node Other Languages
8077 @chapter Other Languages
8079 @emph{Note: This portion of the documentation definitely needs a lot
8080 of work!}
8082 @menu
8083 * Interoperating with C and C++::
8084 @end menu
8086 @node Interoperating with C and C++
8087 @section Tools and advice for interoperating with C and C++
8089 @cindex C, linking with
8090 @cindex C++, linking with
8091 @cindex linking with C
8092 The following discussion assumes that you are running @code{g77} in @code{f2c}
8093 compatibility mode, i.e.@: not using @samp{-fno-f2c}.
8094 It provides some
8095 advice about quick and simple techniques for linking Fortran and C (or
8096 C++), the most common requirement.
8097 For the full story consult the
8098 description of code generation.
8099 @xref{Debugging and Interfacing}.
8101 When linking Fortran and C, it's usually best to use @code{g77} to do
8102 the linking so that the correct libraries are included (including the
8103 maths one).
8104 If you're linking with C++ you will want to add
8105 @samp{-lstdc++}, @samp{-lg++} or whatever.
8106 If you need to use another
8107 driver program (or @code{ld} directly),
8108 you can find out what linkage
8109 options @code{g77} passes by running @samp{g77 -v}.
8111 @menu
8112 * C Interfacing Tools::
8113 * C Access to Type Information::
8114 * f2c Skeletons and Prototypes::
8115 * C++ Considerations::
8116 * Startup Code::
8117 @end menu
8119 @node C Interfacing Tools
8120 @subsection C Interfacing Tools
8121 @pindex f2c
8122 @cindex cfortran.h
8123 @cindex Netlib
8124 Even if you don't actually use it as a compiler, @code{f2c} from
8125 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
8126 interfacing (linking) Fortran and C@.
8127 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
8129 To use @code{f2c} for this purpose you only need retrieve and
8130 build the @file{src} directory from the distribution, consult the
8131 @file{README} instructions there for machine-specifics, and install the
8132 @code{f2c} program on your path.
8134 Something else that might be useful is @samp{cfortran.h} from
8135 @uref{ftp://zebra.desy.de/cfortran}.
8136 This is a fairly general tool which
8137 can be used to generate interfaces for calling in both directions
8138 between Fortran and C@.
8139 It can be used in @code{f2c} mode with
8140 @code{g77}---consult its documentation for details.
8142 @node C Access to Type Information
8143 @subsection Accessing Type Information in C
8145 @cindex types, Fortran/C
8146 Generally, C code written to link with
8147 @code{g77} code---calling and/or being
8148 called from Fortran---should @samp{#include <g2c.h>} to define the C
8149 versions of the Fortran types.
8150 Don't assume Fortran @code{INTEGER} types
8151 correspond to C @code{int}s, for instance; instead, declare them as
8152 @code{integer}, a type defined by @file{g2c.h}.
8153 @file{g2c.h} is installed where @code{gcc} will find it by
8154 default, assuming you use a copy of @code{gcc} compatible with
8155 @code{g77}, probably built at the same time as @code{g77}.
8157 @node f2c Skeletons and Prototypes
8158 @subsection Generating Skeletons and Prototypes with @code{f2c}
8160 @pindex f2c
8161 @cindex -fno-second-underscore
8162 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@: to
8163 interface with an existing library---is to write a file (named, for
8164 example, @file{fred.f}) of dummy Fortran
8165 skeletons comprising just the declaration of the routine(s) and dummy
8166 arguments plus @code{END} statements.
8167 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
8168 into which you can edit
8169 useful code, confident the calling sequence is correct, at least.
8170 (There are some errors otherwise commonly made in generating C
8171 interfaces with @code{f2c} conventions,
8172 such as not using @code{doublereal}
8173 as the return type of a @code{REAL} @code{FUNCTION}.)
8175 @pindex ftnchek
8176 @code{f2c} also can help with calling Fortran from C, using its
8177 @samp{-P} option to generate C prototypes appropriate for calling the
8178 Fortran.@footnote{The files generated like this can also be used for
8179 inter-unit consistency checking of dummy and actual arguments, although
8180 the @code{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
8181 or @uref{ftp://ftp.dsm.fordham.edu} is
8182 probably better for this purpose.}
8183 If the Fortran code containing any
8184 routines to be called from C is in file @file{joe.f}, use the command
8185 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
8186 prototype information.
8187 @code{#include} this in the C which has to call
8188 the Fortran routines to make sure you get it right.
8190 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
8191 between the way Fortran (including compilers like @code{g77}) and
8192 C handle arrays.
8194 @node C++ Considerations
8195 @subsection C++ Considerations
8197 @cindex C++
8198 @code{f2c} can be used to generate suitable code for compilation with a
8199 C++ system using the @samp{-C++} option.
8200 The important thing about linking @code{g77}-compiled
8201 code with C++ is that the prototypes for the @code{g77}
8202 routines must specify C linkage to avoid name mangling.
8203 So, use an @samp{extern "C"} declaration.
8204 @code{f2c}'s @samp{-C++} option will take care
8205 of this when generating skeletons or prototype files as above, and also
8206 avoid clashes with C++ reserved words in addition to those in C@.
8208 @node Startup Code
8209 @subsection Startup Code
8211 @cindex startup code
8212 @cindex run-time, initialization
8213 @cindex initialization, run-time
8214 Unlike with some runtime systems,
8215 it shouldn't be necessary
8216 (unless there are bugs)
8217 to use a Fortran main program unit to ensure the
8218 runtime---specifically the I/O system---is initialized.
8220 However, to use the @code{g77} intrinsics @code{GETARG} and @code{IARGC},
8221 either the @code{main} routine from the @file{libg2c} library must be used,
8222 or the @code{f_setarg} routine
8223 (new as of @code{egcs} version 1.1 and @code{g77} version 0.5.23)
8224 must be called with the appropriate @code{argc} and @code{argv} arguments
8225 prior to the program calling @code{GETARG} or @code{IARGC}.
8227 To provide more flexibility for mixed-language programming
8228 involving @code{g77} while allowing for shared libraries,
8229 as of @code{egcs} version 1.1 and @code{g77} version 0.5.23,
8230 @code{g77}'s @code{main} routine in @code{libg2c}
8231 does the following, in order:
8233 @enumerate
8234 @item
8235 Calls @code{f_setarg}
8236 with the incoming @code{argc} and @code{argv} arguments,
8237 in the same order as for @code{main} itself.
8239 This sets up the command-line environment
8240 for @code{GETARG} and @code{IARGC}.
8242 @item
8243 Calls @code{f_setsig} (with no arguments).
8245 This sets up the signaling and exception environment.
8247 @item
8248 Calls @code{f_init} (with no arguments).
8250 This initializes the I/O environment,
8251 though that should not be necessary,
8252 as all I/O functions in @code{libf2c}
8253 are believed to call @code{f_init} automatically,
8254 if necessary.
8256 (A future version of @code{g77} might skip this explicit step,
8257 to speed up normal exit of a program.)
8259 @item
8260 Arranges for @code{f_exit} to be called (with no arguments)
8261 when the program exits.
8263 This ensures that the I/O environment is properly shut down
8264 before the program exits normally.
8265 Otherwise, output buffers might not be fully flushed,
8266 scratch files might not be deleted, and so on.
8268 The simple way @code{main} does this is
8269 to call @code{f_exit} itself after calling
8270 @code{MAIN__} (in the next step).
8272 However, this does not catch the cases where the program
8273 might call @code{exit} directly,
8274 instead of using the @code{EXIT} intrinsic
8275 (implemented as @code{exit_} in @code{libf2c}).
8277 So, @code{main} attempts to use
8278 the operating environment's @code{onexit} or @code{atexit}
8279 facility, if available,
8280 to cause @code{f_exit} to be called automatically
8281 upon any invocation of @code{exit}.
8283 @item
8284 Calls @code{MAIN__} (with no arguments).
8286 This starts executing the Fortran main program unit for
8287 the application.
8288 (Both @code{g77} and @code{f2c} currently compile a main
8289 program unit so that its global name is @code{MAIN__}.)
8291 @item
8292 If no @code{onexit} or @code{atexit} is provided by the system,
8293 calls @code{f_exit}.
8295 @item
8296 Calls @code{exit} with a zero argument,
8297 to signal a successful program termination.
8299 @item
8300 Returns a zero value to the caller,
8301 to signal a successful program termination,
8302 in case @code{exit} doesn't exit on the system.
8303 @end enumerate
8305 All of the above names are C @code{extern} names,
8306 i.e.@: not mangled.
8308 When using the @code{main} procedure provided by @code{g77}
8309 without a Fortran main program unit,
8310 you need to provide @code{MAIN__}
8311 as the entry point for your C code.
8312 (Make sure you link the object file that defines that
8313 entry point with the rest of your program.)
8315 To provide your own @code{main} procedure
8316 in place of @code{g77}'s,
8317 make sure you specify the object file defining that procedure
8318 @emph{before} @samp{-lg2c} on the @code{g77} command line.
8319 Since the @samp{-lg2c} option is implicitly provided,
8320 this is usually straightforward.
8321 (Use the @samp{--verbose} option to see how and where
8322 @code{g77} implicitly adds @samp{-lg2c} in a command line
8323 that will link the program.
8324 Feel free to specify @samp{-lg2c} explicitly,
8325 as appropriate.)
8327 However, when providing your own @code{main},
8328 make sure you perform the appropriate tasks in the
8329 appropriate order.
8330 For example, if your @code{main} does not call @code{f_setarg},
8331 make sure the rest of your application does not call
8332 @code{GETARG} or @code{IARGC}.
8334 And, if your @code{main} fails to ensure that @code{f_exit}
8335 is called upon program exit,
8336 some files might end up incompletely written,
8337 some scratch files might be left lying around,
8338 and some existing files being written might be left
8339 with old data not properly truncated at the end.
8341 Note that, generally, the @code{g77} operating environment
8342 does not depend on a procedure named @code{MAIN__} actually
8343 being called prior to any other @code{g77}-compiled code.
8344 That is, @code{MAIN__} does not, itself,
8345 set up any important operating-environment characteristics
8346 upon which other code might depend.
8347 This might change in future versions of @code{g77},
8348 with appropriate notification in the release notes.
8350 For more information, consult the source code for the above routines.
8351 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
8352 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
8354 Also, the file @file{@value{path-g77}/com.c} contains the code @code{g77}
8355 uses to open-code (inline) references to @code{IARGC}.
8357 @include g77install.texi
8359 @node Debugging and Interfacing
8360 @chapter Debugging and Interfacing
8361 @cindex debugging
8362 @cindex interfacing
8363 @cindex calling C routines
8364 @cindex C routines calling Fortran
8365 @cindex f2c compatibility
8367 GNU Fortran currently generates code that is object-compatible with
8368 the @code{f2c} converter.
8369 Also, it avoids limitations in the current GBE, such as the
8370 inability to generate a procedure with
8371 multiple entry points, by generating code that is structured
8372 differently (in terms of procedure names, scopes, arguments, and
8373 so on) than might be expected.
8375 As a result, writing code in other languages that calls on, is
8376 called by, or shares in-memory data with @code{g77}-compiled code generally
8377 requires some understanding of the way @code{g77} compiles code for
8378 various constructs.
8380 Similarly, using a debugger to debug @code{g77}-compiled
8381 code, even if that debugger supports native Fortran debugging, generally
8382 requires this sort of information.
8384 This section describes some of the basic information on how
8385 @code{g77} compiles code for constructs involving interfaces to other
8386 languages and to debuggers.
8388 @emph{Caution:} Much or all of this information pertains to only the current
8389 release of @code{g77}, sometimes even to using certain compiler options
8390 with @code{g77} (such as @samp{-fno-f2c}).
8391 Do not write code that depends on this
8392 information without clearly marking said code as nonportable and
8393 subject to review for every new release of @code{g77}.
8394 This information
8395 is provided primarily to make debugging of code generated by this
8396 particular release of @code{g77} easier for the user, and partly to make
8397 writing (generally nonportable) interface code easier.
8398 Both of these
8399 activities require tracking changes in new version of @code{g77} as they
8400 are installed, because new versions can change the behaviors
8401 described in this section.
8403 @menu
8404 * Main Program Unit::  How @code{g77} compiles a main program unit.
8405 * Procedures::         How @code{g77} constructs parameter lists
8406                        for procedures.
8407 * Functions::          Functions returning floating-point or character data.
8408 * Names::              Naming of user-defined variables, procedures, etc.
8409 * Common Blocks::      Accessing common variables while debugging.
8410 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
8411 * Complex Variables::  How @code{g77} performs complex arithmetic.
8412 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
8413 * Adjustable Arrays::  Special consideration for adjustable arrays.
8414 * Alternate Entry Points::  How @code{g77} implements alternate @code{ENTRY}.
8415 * Alternate Returns::  How @code{g77} handles alternate returns.
8416 * Assigned Statement Labels::  How @code{g77} handles @code{ASSIGN}.
8417 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
8418 @end menu
8420 @node Main Program Unit
8421 @section Main Program Unit (PROGRAM)
8422 @cindex PROGRAM statement
8423 @cindex statements, PROGRAM
8425 When @code{g77} compiles a main program unit, it gives it the public
8426 procedure name @code{MAIN__}.
8427 The @code{libg2c} library has the actual @code{main()} procedure
8428 as is typical of C-based environments, and
8429 it is this procedure that performs some initial start-up
8430 activity and then calls @code{MAIN__}.
8432 Generally, @code{g77} and @code{libg2c} are designed so that you need not
8433 include a main program unit written in Fortran in your program---it
8434 can be written in C or some other language.
8435 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
8436 includes a bug fix for @code{libg2c} that solved a problem with using the
8437 @code{OPEN} statement as the first Fortran I/O activity in a program
8438 without a Fortran main program unit.
8440 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
8441 your main program unit---that is, if you intend to compile a @code{main()}
8442 procedure using some other language---you should carefully
8443 examine the code for @code{main()} in @code{libg2c}, found in the source
8444 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
8445 might need to be done by your @code{main()} in order to provide the
8446 Fortran environment your Fortran code is expecting.
8448 @cindex @code{IArgC} intrinsic
8449 @cindex intrinsics, @code{IArgC}
8450 @cindex @code{GetArg} intrinsic
8451 @cindex intrinsics, @code{GetArg}
8452 For example, @code{libg2c}'s @code{main()} sets up the information used by
8453 the @code{IARGC} and @code{GETARG} intrinsics.
8454 Bypassing @code{libg2c}'s @code{main()}
8455 without providing a substitute for this activity would mean
8456 that invoking @code{IARGC} and @code{GETARG} would produce undefined
8457 results.
8459 @cindex debugging
8460 @cindex main program unit, debugging
8461 @cindex main()
8462 @cindex MAIN__()
8463 @cindex .gdbinit
8464 When debugging, one implication of the fact that @code{main()}, which
8465 is the place where the debugged program ``starts'' from the
8466 debugger's point of view, is in @code{libg2c} is that you won't be
8467 starting your Fortran program at a point you recognize as your
8468 Fortran code.
8470 The standard way to get around this problem is to set a break
8471 point (a one-time, or temporary, break point will do) at
8472 the entrance to @code{MAIN__}, and then run the program.
8473 A convenient way to do so is to add the @code{gdb} command
8475 @example
8476 tbreak MAIN__
8477 @end example
8479 @noindent
8480 to the file @file{.gdbinit} in the directory in which you're debugging
8481 (using @code{gdb}).
8483 After doing this, the debugger will see the current execution
8484 point of the program as at the beginning of the main program
8485 unit of your program.
8487 Of course, if you really want to set a break point at some
8488 other place in your program and just start the program
8489 running, without first breaking at @code{MAIN__},
8490 that should work fine.
8492 @node Procedures
8493 @section Procedures (SUBROUTINE and FUNCTION)
8494 @cindex procedures
8495 @cindex SUBROUTINE statement
8496 @cindex statements, SUBROUTINE
8497 @cindex FUNCTION statement
8498 @cindex statements, FUNCTION
8499 @cindex signature of procedures
8501 Currently, @code{g77} passes arguments via reference---specifically,
8502 by passing a pointer to the location in memory of a variable, array,
8503 array element, a temporary location that holds the result of evaluating an
8504 expression, or a temporary or permanent location that holds the value
8505 of a constant.
8507 Procedures that accept @code{CHARACTER} arguments are implemented by
8508 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
8510 The first argument occupies the expected position in the
8511 argument list and has the user-specified name.
8512 This argument
8513 is a pointer to an array of characters, passed by the caller.
8515 The second argument is appended to the end of the user-specified
8516 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
8517 is the user-specified name.
8518 This argument is of the C type @code{ftnlen}
8519 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
8520 is the number of characters the caller has allocated in the
8521 array pointed to by the first argument.
8523 A procedure will ignore the length argument if @samp{X} is not declared
8524 @code{CHARACTER*(*)}, because for other declarations, it knows the
8525 length.
8526 Not all callers necessarily ``know'' this, however, which
8527 is why they all pass the extra argument.
8529 The contents of the @code{CHARACTER} argument are specified by the
8530 address passed in the first argument (named after it).
8531 The procedure can read or write these contents as appropriate.
8533 When more than one @code{CHARACTER} argument is present in the argument
8534 list, the length arguments are appended in the order
8535 the original arguments appear.
8536 So @samp{CALL FOO('HI','THERE')} is implemented in
8537 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
8538 does not provide the trailing null bytes on the constant
8539 strings (@code{f2c} does provide them, but they are unnecessary in
8540 a Fortran environment, and you should not expect them to be
8541 there).
8543 Note that the above information applies to @code{CHARACTER} variables and
8544 arrays @strong{only}.
8545 It does @strong{not} apply to external @code{CHARACTER}
8546 functions or to intrinsic @code{CHARACTER} functions.
8547 That is, no second length argument is passed to @samp{FOO} in this case:
8549 @example
8550 CHARACTER X
8551 EXTERNAL X
8552 CALL FOO(X)
8553 @end example
8555 @noindent
8556 Nor does @samp{FOO} expect such an argument in this case:
8558 @example
8559 SUBROUTINE FOO(X)
8560 CHARACTER X
8561 EXTERNAL X
8562 @end example
8564 Because of this implementation detail, if a program has a bug
8565 such that there is disagreement as to whether an argument is
8566 a procedure, and the type of the argument is @code{CHARACTER}, subtle
8567 symptoms might appear.
8569 @node Functions
8570 @section Functions (FUNCTION and RETURN)
8571 @cindex functions
8572 @cindex FUNCTION statement
8573 @cindex statements, FUNCTION
8574 @cindex RETURN statement
8575 @cindex statements, RETURN
8576 @cindex return type of functions
8578 @code{g77} handles in a special way functions that return the following
8579 types:
8581 @itemize @bullet
8582 @item
8583 @code{CHARACTER}
8584 @item
8585 @code{COMPLEX}
8586 @item
8587 @code{REAL(KIND=1)}
8588 @end itemize
8590 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
8591 returning @code{void})
8592 with two arguments prepended: @samp{__g77_result}, which the caller passes
8593 as a pointer to a @code{char} array expected to hold the return value,
8594 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
8595 specifying the length of the return value as declared in the calling
8596 program.
8597 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
8598 to determine the size of the array that @samp{__g77_result} points to;
8599 otherwise, it ignores that argument.
8601 For @code{COMPLEX}, when @samp{-ff2c} is in
8602 force, @code{g77} implements
8603 a subroutine with one argument prepended: @samp{__g77_result}, which the
8604 caller passes as a pointer to a variable of the type of the function.
8605 The called function writes the return value into this variable instead
8606 of returning it as a function value.
8607 When @samp{-fno-f2c} is in force,
8608 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
8609 @samp{__complex__ float} or @samp{__complex__ double} function
8610 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
8611 returning the result of the function in the same way as @code{gcc} would.
8613 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
8614 a function that actually returns @code{REAL(KIND=2)} (typically
8615 C's @code{double} type).
8616 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
8617 functions return @code{float}.
8619 @node Names
8620 @section Names
8621 @cindex symbol names
8622 @cindex transforming symbol names
8624 Fortran permits each implementation to decide how to represent
8625 names as far as how they're seen in other contexts, such as debuggers
8626 and when interfacing to other languages, and especially as far
8627 as how casing is handled.
8629 External names---names of entities that are public, or ``accessible'',
8630 to all modules in a program---normally have an underscore (@samp{_})
8631 appended by @code{g77},
8632 to generate code that is compatible with @code{f2c}.
8633 External names include names of Fortran things like common blocks,
8634 external procedures (subroutines and functions, but not including
8635 statement functions, which are internal procedures), and entry point
8636 names.
8638 However, use of the @samp{-fno-underscoring} option
8639 disables this kind of transformation of external names (though inhibiting
8640 the transformation certainly improves the chances of colliding with
8641 incompatible externals written in other languages---but that
8642 might be intentional.
8644 @cindex -fno-underscoring option
8645 @cindex options, -fno-underscoring
8646 @cindex -fno-second-underscore option
8647 @cindex options, -fno-underscoring
8648 When @samp{-funderscoring} is in force, any name (external or local)
8649 that already has at least one underscore in it is
8650 implemented by @code{g77} by appending two underscores.
8651 (This second underscore can be disabled via the
8652 @samp{-fno-second-underscore} option.)
8653 External names are changed this way for @code{f2c} compatibility.
8654 Local names are changed this way to avoid collisions with external names
8655 that are different in the source code---@code{f2c} does the same thing, but
8656 there's no compatibility issue there except for user expectations while
8657 debugging.
8659 For example:
8661 @example
8662 Max_Cost = 0
8663 @end example
8665 @cindex debugging
8666 @noindent
8667 Here, a user would, in the debugger, refer to this variable using the
8668 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
8669 as described below).
8670 (We hope to improve @code{g77} in this regard in the future---don't
8671 write scripts depending on this behavior!
8672 Also, consider experimenting with the @samp{-fno-underscoring}
8673 option to try out debugging without having to massage names by
8674 hand like this.)
8676 @code{g77} provides a number of command-line options that allow the user
8677 to control how case mapping is handled for source files.
8678 The default is the traditional UNIX model for Fortran compilers---names
8679 are mapped to lower case.
8680 Other command-line options can be specified to map names to upper
8681 case, or to leave them exactly as written in the source file.
8683 For example:
8685 @example
8686 Foo = 9.436
8687 @end example
8689 @noindent
8690 Here, it is normally the case that the variable assigned will be named
8691 @samp{foo}.
8692 This would be the name to enter when using a debugger to
8693 access the variable.
8695 However, depending on the command-line options specified, the
8696 name implemented by @code{g77} might instead be @samp{FOO} or even
8697 @samp{Foo}, thus affecting how debugging is done.
8699 Also:
8701 @example
8702 Call Foo
8703 @end example
8705 @noindent
8706 This would normally call a procedure that, if it were in a separate C program,
8707 be defined starting with the line:
8709 @example
8710 void foo_()
8711 @end example
8713 @noindent
8714 However, @code{g77} command-line options could be used to change the casing
8715 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
8716 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
8717 could be used to inhibit the appending of the underscore to the name.
8719 @node Common Blocks
8720 @section Common Blocks (COMMON)
8721 @cindex common blocks
8722 @cindex @code{COMMON} statement
8723 @cindex statements, @code{COMMON}
8725 @code{g77} names and lays out @code{COMMON} areas
8726 the same way @code{f2c} does,
8727 for compatibility with @code{f2c}.
8729 @node Local Equivalence Areas
8730 @section Local Equivalence Areas (EQUIVALENCE)
8731 @cindex equivalence areas
8732 @cindex local equivalence areas
8733 @cindex EQUIVALENCE statement
8734 @cindex statements, EQUIVALENCE
8736 @code{g77} treats storage-associated areas involving a @code{COMMON}
8737 block as explained in the section on common blocks.
8739 A local @code{EQUIVALENCE} area is a collection of variables and arrays
8740 connected to each other in any way via @code{EQUIVALENCE}, none of which are
8741 listed in a @code{COMMON} statement.
8743 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
8744 for @var{x} using a different method when more than one name was
8745 in the list of names of entities placed at the beginning of the
8746 array.
8747 Though the documentation specified that the first name listed in
8748 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
8749 in fact chose the name using a method that was so complicated,
8750 it seemed easier to change it to an alphabetical sort than to describe the
8751 previous method in the documentation.)
8753 @node Complex Variables
8754 @section Complex Variables (COMPLEX)
8755 @cindex complex variables
8756 @cindex imaginary part
8757 @cindex COMPLEX statement
8758 @cindex statements, COMPLEX
8760 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
8761 (and related intrinsics, constants, functions, and so on)
8762 in a manner that
8763 makes direct debugging involving these types in Fortran
8764 language mode difficult.
8766 Essentially, @code{g77} implements these types using an
8767 internal construct similar to C's @code{struct}, at least
8768 as seen by the @code{gcc} back end.
8770 Currently, the back end, when outputting debugging info with
8771 the compiled code for the assembler to digest, does not detect
8772 these @code{struct} types as being substitutes for Fortran
8773 complex.
8774 As a result, the Fortran language modes of debuggers such as
8775 @code{gdb} see these types as C @code{struct} types, which
8776 they might or might not support.
8778 Until this is fixed, switch to C language mode to work with
8779 entities of @code{COMPLEX} type and then switch back to Fortran language
8780 mode afterward.
8781 (In @code{gdb}, this is accomplished via @samp{set lang c} and
8782 either @samp{set lang fortran} or @samp{set lang auto}.)
8784 @node Arrays
8785 @section Arrays (DIMENSION)
8786 @cindex DIMENSION statement
8787 @cindex statements, DIMENSION
8788 @cindex array ordering
8789 @cindex ordering, array
8790 @cindex column-major ordering
8791 @cindex row-major ordering
8792 @cindex arrays
8794 Fortran uses ``column-major ordering'' in its arrays.
8795 This differs from other languages, such as C, which use ``row-major ordering''.
8796 The difference is that, with Fortran, array elements adjacent to
8797 each other in memory differ in the @emph{first} subscript instead of
8798 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
8799 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
8801 This consideration
8802 affects not only interfacing with and debugging Fortran code,
8803 it can greatly affect how code is designed and written, especially
8804 when code speed and size is a concern.
8806 Fortran also differs from C, a popular language for interfacing and
8807 to support directly in debuggers, in the way arrays are treated.
8808 In C, arrays are single-dimensional and have interesting relationships
8809 to pointers, neither of which is true for Fortran.
8810 As a result, dealing with Fortran arrays from within
8811 an environment limited to C concepts can be challenging.
8813 For example, accessing the array element @samp{A(5,10,20)} is easy enough
8814 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
8815 are needed.
8816 First, C would treat the A array as a single-dimension array.
8817 Second, C does not understand low bounds for arrays as does Fortran.
8818 Third, C assumes a low bound of zero (0), while Fortran defaults to a
8819 low bound of one (1) and can supports an arbitrary low bound.
8820 Therefore, calculations must be done
8821 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
8822 calculations require knowing the dimensions of @samp{A}.
8824 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
8825 @samp{A(5,10,20)} would be:
8827 @example
8828   (5-2)
8829 + (10-1)*(11-2+1)
8830 + (20-0)*(11-2+1)*(21-1+1)
8831 = 4293
8832 @end example
8834 @noindent
8835 So the C equivalent in this case would be @samp{a[4293]}.
8837 When using a debugger directly on Fortran code, the C equivalent
8838 might not work, because some debuggers cannot understand the notion
8839 of low bounds other than zero.  However, unlike @code{f2c}, @code{g77}
8840 does inform the GBE that a multi-dimensional array (like @samp{A}
8841 in the above example) is really multi-dimensional, rather than a
8842 single-dimensional array, so at least the dimensionality of the array
8843 is preserved.
8845 Debuggers that understand Fortran should have no trouble with
8846 non-zero low bounds, but for non-Fortran debuggers, especially
8847 C debuggers, the above example might have a C equivalent of
8848 @samp{a[4305]}.
8849 This calculation is arrived at by eliminating the subtraction
8850 of the lower bound in the first parenthesized expression on each
8851 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
8852 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
8853 Actually, the implication of
8854 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
8855 but that @samp{a[20][10][5]} produces the equivalent of
8856 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
8858 Come to think of it, perhaps
8859 the behavior is due to the debugger internally compensating for
8860 the lower bounds by offsetting the base address of @samp{a}, leaving
8861 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
8862 its first element as identified by subscripts equal to the
8863 corresponding lower bounds).
8865 You know, maybe nobody really needs to use arrays.
8867 @node Adjustable Arrays
8868 @section Adjustable Arrays (DIMENSION)
8869 @cindex arrays, adjustable
8870 @cindex adjustable arrays
8871 @cindex arrays, automatic
8872 @cindex automatic arrays
8873 @cindex DIMENSION statement
8874 @cindex statements, DIMENSION
8875 @cindex dimensioning arrays
8876 @cindex arrays, dimensioning
8878 Adjustable and automatic arrays in Fortran require the implementation
8879 (in this
8880 case, the @code{g77} compiler) to ``memorize'' the expressions that
8881 dimension the arrays each time the procedure is invoked.
8882 This is so that subsequent changes to variables used in those
8883 expressions, made during execution of the procedure, do not
8884 have any effect on the dimensions of those arrays.
8886 For example:
8888 @example
8889 REAL ARRAY(5)
8890 DATA ARRAY/5*2/
8891 CALL X(ARRAY, 5)
8893 SUBROUTINE X(A, N)
8894 DIMENSION A(N)
8895 N = 20
8896 PRINT *, N, A
8898 @end example
8900 @noindent
8901 Here, the implementation should, when running the program, print something
8902 like:
8904 @example
8905 20   2.  2.  2.  2.  2.
8906 @end example
8908 @noindent
8909 Note that this shows that while the value of @samp{N} was successfully
8910 changed, the size of the @samp{A} array remained at 5 elements.
8912 To support this, @code{g77} generates code that executes before any user
8913 code (and before the internally generated computed @code{GOTO} to handle
8914 alternate entry points, as described below) that evaluates each
8915 (nonconstant) expression in the list of subscripts for an
8916 array, and saves the result of each such evaluation to be used when
8917 determining the size of the array (instead of re-evaluating the
8918 expressions).
8920 So, in the above example, when @samp{X} is first invoked, code is
8921 executed that copies the value of @samp{N} to a temporary.
8922 And that same temporary serves as the actual high bound for the single
8923 dimension of the @samp{A} array (the low bound being the constant 1).
8924 Since the user program cannot (legitimately) change the value
8925 of the temporary during execution of the procedure, the size
8926 of the array remains constant during each invocation.
8928 For alternate entry points, the code @code{g77} generates takes into
8929 account the possibility that a dummy adjustable array is not actually
8930 passed to the actual entry point being invoked at that time.
8931 In that case, the public procedure implementing the entry point
8932 passes to the master private procedure implementing all the
8933 code for the entry points a @code{NULL} pointer where a pointer to that
8934 adjustable array would be expected.
8935 The @code{g77}-generated code
8936 doesn't attempt to evaluate any of the expressions in the subscripts
8937 for an array if the pointer to that array is @code{NULL} at run time in
8938 such cases.
8939 (Don't depend on this particular implementation
8940 by writing code that purposely passes @code{NULL} pointers where the
8941 callee expects adjustable arrays, even if you know the callee
8942 won't reference the arrays---nor should you pass @code{NULL} pointers
8943 for any dummy arguments used in calculating the bounds of such
8944 arrays or leave undefined any values used for that purpose in
8945 COMMON---because the way @code{g77} implements these things might
8946 change in the future!)
8948 @node Alternate Entry Points
8949 @section Alternate Entry Points (ENTRY)
8950 @cindex alternate entry points
8951 @cindex entry points
8952 @cindex ENTRY statement
8953 @cindex statements, ENTRY
8955 The GBE does not understand the general concept of
8956 alternate entry points as Fortran provides via the ENTRY statement.
8957 @code{g77} gets around this by using an approach to compiling procedures
8958 having at least one @code{ENTRY} statement that is almost identical to the
8959 approach used by @code{f2c}.
8960 (An alternate approach could be used that
8961 would probably generate faster, but larger, code that would also
8962 be a bit easier to debug.)
8964 Information on how @code{g77} implements @code{ENTRY} is provided for those
8965 trying to debug such code.
8966 The choice of implementation seems
8967 unlikely to affect code (compiled in other languages) that interfaces
8968 to such code.
8970 @code{g77} compiles exactly one public procedure for the primary entry
8971 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
8972 That is, in terms of the public interface, there is no difference
8973 between
8975 @example
8976 SUBROUTINE X
8978 SUBROUTINE Y
8980 @end example
8982 @noindent
8983 and:
8985 @example
8986 SUBROUTINE X
8987 ENTRY Y
8989 @end example
8991 The difference between the above two cases lies in the code compiled
8992 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
8993 for the second case, an extra internal procedure is compiled.
8995 For every Fortran procedure with at least one @code{ENTRY}
8996 statement, @code{g77} compiles an extra procedure
8997 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
8998 the name of the primary entry point (which, in the above case,
8999 using the standard compiler options, would be @samp{x_} in C).
9001 This extra procedure is compiled as a private procedure---that is,
9002 a procedure not accessible by name to separately compiled modules.
9003 It contains all the code in the program unit, including the code
9004 for the primary entry point plus for every entry point.
9005 (The code for each public procedure is quite short, and explained later.)
9007 The extra procedure has some other interesting characteristics.
9009 The argument list for this procedure is invented by @code{g77}.
9010 It contains
9011 a single integer argument named @samp{__g77_which_entrypoint},
9012 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
9013 entry point index---0 for the primary entry point, 1 for the
9014 first entry point (the first @code{ENTRY} statement encountered), 2 for
9015 the second entry point, and so on.
9017 It also contains, for functions returning @code{CHARACTER} and
9018 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
9019 and for functions returning different types among the
9020 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
9021 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
9022 is expected at run time to contain a pointer to where to store
9023 the result of the entry point.
9024 For @code{CHARACTER} functions, this
9025 storage area is an array of the appropriate number of characters;
9026 for @code{COMPLEX} functions, it is the appropriate area for the return
9027 type; for multiple-return-type functions, it is a union of all the supported return
9028 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
9029 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
9030 is not supported by @code{g77}).
9032 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
9033 by yet another argument named @samp{__g77_length} that, at run time,
9034 specifies the caller's expected length of the returned value.
9035 Note that only @code{CHARACTER*(*)} functions and entry points actually
9036 make use of this argument, even though it is always passed by
9037 all callers of public @code{CHARACTER} functions (since the caller does not
9038 generally know whether such a function is @code{CHARACTER*(*)} or whether
9039 there are any other callers that don't have that information).
9041 The rest of the argument list is the union of all the arguments
9042 specified for all the entry points (in their usual forms, e.g.
9043 @code{CHARACTER} arguments have extra length arguments, all appended at
9044 the end of this list).
9045 This is considered the ``master list'' of
9046 arguments.
9048 The code for this procedure has, before the code for the first
9049 executable statement, code much like that for the following Fortran
9050 statement:
9052 @smallexample
9053        GOTO (100000,100001,100002), __g77_which_entrypoint
9054 100000 @dots{}code for primary entry point@dots{}
9055 100001 @dots{}code immediately following first ENTRY statement@dots{}
9056 100002 @dots{}code immediately following second ENTRY statement@dots{}
9057 @end smallexample
9059 @noindent
9060 (Note that invalid Fortran statement labels and variable names
9061 are used in the above example to highlight the fact that it
9062 represents code generated by the @code{g77} internals, not code to be
9063 written by the user.)
9065 It is this code that, when the procedure is called, picks which
9066 entry point to start executing.
9068 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
9069 example), those procedures are fairly simple.
9070 Their interfaces
9071 are just like they would be if they were self-contained procedures
9072 (without @code{ENTRY}), of course, since that is what the callers
9073 expect.
9074 Their code consists of simply calling the private
9075 procedure, described above, with the appropriate extra arguments
9076 (the entry point index, and perhaps a pointer to a multiple-type-
9077 return variable, local to the public procedure, that contains
9078 all the supported returnable non-character types).
9079 For arguments
9080 that are not listed for a given entry point that are listed for
9081 other entry points, and therefore that are in the ``master list''
9082 for the private procedure, null pointers (in C, the @code{NULL} macro)
9083 are passed.
9084 Also, for entry points that are part of a multiple-type-
9085 returning function, code is compiled after the call of the private
9086 procedure to extract from the multi-type union the appropriate result,
9087 depending on the type of the entry point in question, returning
9088 that result to the original caller.
9090 When debugging a procedure containing alternate entry points, you
9091 can either set a break point on the public procedure itself (e.g.
9092 a break point on @samp{X} or @samp{Y}) or on the private procedure that
9093 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
9094 If you do the former, you should use the debugger's command to
9095 ``step into'' the called procedure to get to the actual code; with
9096 the latter approach, the break point leaves you right at the
9097 actual code, skipping over the public entry point and its call
9098 to the private procedure (unless you have set a break point there
9099 as well, of course).
9101 Further, the list of dummy arguments that is visible when the
9102 private procedure is active is going to be the expanded version
9103 of the list for whichever particular entry point is active,
9104 as explained above, and the way in which return values are
9105 handled might well be different from how they would be handled
9106 for an equivalent single-entry function.
9108 @node Alternate Returns
9109 @section Alternate Returns (SUBROUTINE and RETURN)
9110 @cindex subroutines
9111 @cindex alternate returns
9112 @cindex SUBROUTINE statement
9113 @cindex statements, SUBROUTINE
9114 @cindex RETURN statement
9115 @cindex statements, RETURN
9117 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
9118 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
9119 the C @code{int} type.
9120 The actual alternate-return arguments are omitted from the calling sequence.
9121 Instead, the caller uses
9122 the return value to do a rough equivalent of the Fortran
9123 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
9124 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
9125 function), and the callee just returns whatever integer
9126 is specified in the @code{RETURN} statement for the subroutine
9127 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
9128 by @samp{RETURN}
9129 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
9131 @node Assigned Statement Labels
9132 @section Assigned Statement Labels (ASSIGN and GOTO)
9133 @cindex assigned statement labels
9134 @cindex statement labels, assigned
9135 @cindex ASSIGN statement
9136 @cindex statements, ASSIGN
9137 @cindex GOTO statement
9138 @cindex statements, GOTO
9140 For portability to machines where a pointer (such as to a label,
9141 which is how @code{g77} implements @code{ASSIGN} and its relatives,
9142 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
9143 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
9144 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
9145 than it does the numerical value in that variable, unless the
9146 variable is wide enough (can hold enough bits).
9148 In particular, while @code{g77} implements
9150 @example
9151 I = 10
9152 @end example
9154 @noindent
9155 as, in C notation, @samp{i = 10;}, it implements
9157 @example
9158 ASSIGN 10 TO I
9159 @end example
9161 @noindent
9162 as, in GNU's extended C notation (for the label syntax),
9163 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
9164 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
9165 actually generate the name @samp{L10} or any other name like that,
9166 since debuggers cannot access labels anyway).
9168 While this currently means that an @code{ASSIGN} statement does not
9169 overwrite the numeric contents of its target variable, @emph{do not}
9170 write any code depending on this feature.
9171 @code{g77} has already changed this implementation across
9172 versions and might do so in the future.
9173 This information is provided only to make debugging Fortran programs
9174 compiled with the current version of @code{g77} somewhat easier.
9175 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
9176 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
9177 means @code{g77} has decided it can store the pointer to the label directly
9178 into @samp{I} itself.
9180 @xref{Ugly Assigned Labels}, for information on a command-line option
9181 to force @code{g77} to use the same storage for both normal and
9182 assigned-label uses of a variable.
9184 @node Run-time Library Errors
9185 @section Run-time Library Errors
9186 @cindex IOSTAT=
9187 @cindex error values
9188 @cindex error messages
9189 @cindex messages, run-time
9190 @cindex I/O, errors
9192 The @code{libg2c} library currently has the following table to relate
9193 error code numbers, returned in @code{IOSTAT=} variables, to messages.
9194 This information should, in future versions of this document, be
9195 expanded upon to include detailed descriptions of each message.
9197 In line with good coding practices, any of the numbers in the
9198 list below should @emph{not} be directly written into Fortran
9199 code you write.
9200 Instead, make a separate @code{INCLUDE} file that defines
9201 @code{PARAMETER} names for them, and use those in your code,
9202 so you can more easily change the actual numbers in the future.
9204 The information below is culled from the definition
9205 of @code{F_err} in @file{f/runtime/libI77/err.c} in the
9206 @code{g77} source tree.
9208 @smallexample
9209 100: "error in format"
9210 101: "illegal unit number"
9211 102: "formatted io not allowed"
9212 103: "unformatted io not allowed"
9213 104: "direct io not allowed"
9214 105: "sequential io not allowed"
9215 106: "can't backspace file"
9216 107: "null file name"
9217 108: "can't stat file"
9218 109: "unit not connected"
9219 110: "off end of record"
9220 111: "truncation failed in endfile"
9221 112: "incomprehensible list input"
9222 113: "out of free space"
9223 114: "unit not connected"
9224 115: "read unexpected character"
9225 116: "bad logical input field"
9226 117: "bad variable type"
9227 118: "bad namelist name"
9228 119: "variable not in namelist"
9229 120: "no end record"
9230 121: "variable count incorrect"
9231 122: "subscript for scalar variable"
9232 123: "invalid array section"
9233 124: "substring out of bounds"
9234 125: "subscript out of bounds"
9235 126: "can't read file"
9236 127: "can't write file"
9237 128: "'new' file exists"
9238 129: "can't append to file"
9239 130: "non-positive record number"
9240 131: "I/O started while already doing I/O"
9241 @end smallexample
9243 @node Collected Fortran Wisdom
9244 @chapter Collected Fortran Wisdom
9245 @cindex wisdom
9246 @cindex legacy code
9247 @cindex code, legacy
9248 @cindex writing code
9249 @cindex code, writing
9251 Most users of @code{g77} can be divided into two camps:
9253 @itemize @bullet
9254 @item
9255 Those writing new Fortran code to be compiled by @code{g77}.
9257 @item
9258 Those using @code{g77} to compile existing, ``legacy'' code.
9259 @end itemize
9261 Users writing new code generally understand most of the necessary
9262 aspects of Fortran to write ``mainstream'' code, but often need
9263 help deciding how to handle problems, such as the construction
9264 of libraries containing @code{BLOCK DATA}.
9266 Users dealing with ``legacy'' code sometimes don't have much
9267 experience with Fortran, but believe that the code they're compiling
9268 already works when compiled by other compilers (and might
9269 not understand why, as is sometimes the case, it doesn't work
9270 when compiled by @code{g77}).
9272 The following information is designed to help users do a better job
9273 coping with existing, ``legacy'' Fortran code, and with writing
9274 new code as well.
9276 @menu
9277 * Advantages Over f2c::        If @code{f2c} is so great, why @code{g77}?
9278 * Block Data and Libraries::   How @code{g77} solves a common problem.
9279 * Loops::                      Fortran @code{DO} loops surprise many people.
9280 * Working Programs::           Getting programs to work should be done first.
9281 * Overly Convenient Options::  Temptations to avoid, habits to not form.
9282 * Faster Programs::            Everybody wants these, but at what cost?
9283 @end menu
9285 @node Advantages Over f2c
9286 @section Advantages Over f2c
9288 Without @code{f2c}, @code{g77} would have taken much longer to
9289 do and probably not been as good for quite a while.
9290 Sometimes people who notice how much @code{g77} depends on, and
9291 documents encouragement to use, @code{f2c} ask why @code{g77}
9292 was created if @code{f2c} already existed.
9294 This section gives some basic answers to these questions, though it
9295 is not intended to be comprehensive.
9297 @menu
9298 * Language Extensions::  Features used by Fortran code.
9299 * Diagnostic Abilities:: Abilities to spot problems early.
9300 * Compiler Options::     Features helpful to accommodate legacy code, etc.
9301 * Compiler Speed::       Speed of the compilation process.
9302 * Program Speed::        Speed of the generated, optimized code.
9303 * Ease of Debugging::    Debugging ease-of-use at the source level.
9304 * Character and Hollerith Constants::  A byte saved is a byte earned.
9305 @end menu
9307 @node Language Extensions
9308 @subsection Language Extensions
9310 @code{g77} offers several extensions to FORTRAN 77 language that @code{f2c}
9311 doesn't:
9313 @itemize @bullet
9314 @item
9315 Automatic arrays
9317 @item
9318 @code{CYCLE} and @code{EXIT}
9320 @item
9321 Construct names
9323 @item
9324 @code{SELECT CASE}
9326 @item
9327 @code{KIND=} and @code{LEN=} notation
9329 @item
9330 Semicolon as statement separator
9332 @item
9333 Constant expressions in @code{FORMAT} statements
9334 (such as @samp{FORMAT(I<J>)},
9335 where @samp{J} is a @code{PARAMETER} named constant)
9337 @item
9338 @code{MvBits} intrinsic
9340 @item
9341 @code{libU77} (Unix-compatibility) library,
9342 with routines known to compiler as intrinsics
9343 (so they work even when compiler options are used
9344 to change the interfaces used by Fortran routines)
9345 @end itemize
9347 @code{g77} also implements iterative @code{DO} loops
9348 so that they work even in the presence of certain ``extreme'' inputs,
9349 unlike @code{f2c}.
9350 @xref{Loops}.
9352 However, @code{f2c} offers a few that @code{g77} doesn't, such as:
9354 @itemize @bullet
9355 @item
9356 Intrinsics in @code{PARAMETER} statements
9358 @item
9359 Array bounds expressions (such as @samp{REAL M(N(2))})
9361 @item
9362 @code{AUTOMATIC} statement
9363 @end itemize
9365 It is expected that @code{g77} will offer some or all of these missing
9366 features at some time in the future.
9368 @node Diagnostic Abilities
9369 @subsection Diagnostic Abilities
9371 @code{g77} offers better diagnosis of problems in @code{FORMAT} statements.
9372 @code{f2c} doesn't, for example, emit any diagnostic for
9373 @samp{FORMAT(XZFAJG10324)},
9374 leaving that to be diagnosed, at run time, by
9375 the @code{libf2c} run-time library.
9377 @node Compiler Options
9378 @subsection Compiler Options
9380 @code{g77} offers compiler options that @code{f2c} doesn't,
9381 most of which are designed to more easily accommodate
9382 legacy code:
9384 @itemize @bullet
9385 @item
9386 Two that control the automatic appending of extra
9387 underscores to external names
9389 @item
9390 One that allows dollar signs (@samp{$}) in symbol names
9392 @item
9393 A variety that control acceptance of various
9394 ``ugly'' constructs
9396 @item
9397 Several that specify acceptable use of upper and lower case
9398 in the source code
9400 @item
9401 Many that enable, disable, delete, or hide
9402 groups of intrinsics
9404 @item
9405 One to specify the length of fixed-form source lines
9406 (normally 72)
9408 @item
9409 One to specify the the source code is written in
9410 Fortran-90-style free-form
9411 @end itemize
9413 However, @code{f2c} offers a few that @code{g77} doesn't,
9414 like an option to have @code{REAL} default to @code{REAL*8}.
9415 It is expected that @code{g77} will offer all of the
9416 missing options pertinent to being a Fortran compiler
9417 at some time in the future.
9419 @node Compiler Speed
9420 @subsection Compiler Speed
9422 Saving the steps of writing and then rereading C code is a big reason
9423 why @code{g77} should be able to compile code much faster than using
9424 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
9426 However, due to @code{g77}'s youth, lots of self-checking is still being
9427 performed.
9428 As a result, this improvement is as yet unrealized
9429 (though the potential seems to be there for quite a big speedup
9430 in the future).
9431 It is possible that, as of version 0.5.18, @code{g77}
9432 is noticeably faster compiling many Fortran source files than using
9433 @code{f2c} in conjunction with @code{gcc}.
9435 @node Program Speed
9436 @subsection Program Speed
9438 @code{g77} has the potential to better optimize code than @code{f2c},
9439 even when @code{gcc} is used to compile the output of @code{f2c},
9440 because @code{f2c} must necessarily
9441 translate Fortran into a somewhat lower-level language (C) that cannot
9442 preserve all the information that is potentially useful for optimization,
9443 while @code{g77} can gather, preserve, and transmit that information directly
9444 to the GBE.
9446 For example, @code{g77} implements @code{ASSIGN} and assigned
9447 @code{GOTO} using direct assignment of pointers to labels and direct
9448 jumps to labels, whereas @code{f2c} maps the assigned labels to
9449 integer values and then uses a C @code{switch} statement to encode
9450 the assigned @code{GOTO} statements.
9452 However, as is typical, theory and reality don't quite match, at least
9453 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
9454 can generate code that is faster than @code{g77}.
9456 Version 0.5.18 of @code{g77} offered default
9457 settings and options, via patches to the @code{gcc}
9458 back end, that allow for better program speed, though
9459 some of these improvements also affected the performance
9460 of programs translated by @code{f2c} and then compiled
9461 by @code{g77}'s version of @code{gcc}.
9463 Version 0.5.20 of @code{g77} offers further performance
9464 improvements, at least one of which (alias analysis) is
9465 not generally applicable to @code{f2c} (though @code{f2c}
9466 could presumably be changed to also take advantage of
9467 this new capability of the @code{gcc} back end, assuming
9468 this is made available in an upcoming release of @code{gcc}).
9470 @node Ease of Debugging
9471 @subsection Ease of Debugging
9473 Because @code{g77} compiles directly to assembler code like @code{gcc},
9474 instead of translating to an intermediate language (C) as does @code{f2c},
9475 support for debugging can be better for @code{g77} than @code{f2c}.
9477 However, although @code{g77} might be somewhat more ``native'' in terms of
9478 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
9479 of things ``not quite right''.
9480 Many of the important ones should be resolved in the near future.
9482 For example, @code{g77} doesn't have to worry about reserved names
9483 like @code{f2c} does.
9484 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
9485 translate this to something @emph{other} than
9486 @samp{for = while;}, because C reserves those words.
9488 However, @code{g77} does still uses things like an extra level of indirection
9489 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
9490 yet support multiple entry points.
9492 Another example is that, given
9494 @smallexample
9495 COMMON A, B
9496 EQUIVALENCE (B, C)
9497 @end smallexample
9499 @noindent
9500 the @code{g77} user should be able to access the variables directly, by name,
9501 without having to traverse C-like structures and unions, while @code{f2c}
9502 is unlikely to ever offer this ability (due to limitations in the
9503 C language).
9505 However, due to apparent bugs in the back end, @code{g77} currently doesn't
9506 take advantage of this facility at all---it doesn't emit any debugging
9507 information for @code{COMMON} and @code{EQUIVALENCE} areas,
9508 other than information
9509 on the array of @code{char} it creates (and, in the case
9510 of local @code{EQUIVALENCE}, names) for each such area.
9512 Yet another example is arrays.
9513 @code{g77} represents them to the debugger
9514 using the same ``dimensionality'' as in the source code, while @code{f2c}
9515 must necessarily convert them all to one-dimensional arrays to fit
9516 into the confines of the C language.
9517 However, the level of support
9518 offered by debuggers for interactive Fortran-style access to arrays
9519 as compiled by @code{g77} can vary widely.
9520 In some cases, it can actually
9521 be an advantage that @code{f2c} converts everything to widely supported
9522 C semantics.
9524 In fairness, @code{g77} could do many of the things @code{f2c} does
9525 to get things working at least as well as @code{f2c}---for now,
9526 the developers prefer making @code{g77} work the
9527 way they think it is supposed to, and finding help improving the
9528 other products (the back end of @code{gcc}; @code{gdb}; and so on)
9529 to get things working properly.
9531 @node Character and Hollerith Constants
9532 @subsection Character and Hollerith Constants
9533 @cindex character constants
9534 @cindex constants, character
9535 @cindex Hollerith constants
9536 @cindex constants, Hollerith
9537 @cindex trailing null byte
9538 @cindex null byte, trailing
9539 @cindex zero byte, trailing
9541 To avoid the extensive hassle that would be needed to avoid this,
9542 @code{f2c} uses C character constants to encode character and Hollerith
9543 constants.
9544 That means a constant like @samp{'HELLO'} is translated to
9545 @samp{"hello"} in C, which further means that an extra null byte is
9546 present at the end of the constant.
9547 This null byte is superfluous.
9549 @code{g77} does not generate such null bytes.
9550 This represents significant
9551 savings of resources, such as on systems where @file{/dev/null} or
9552 @file{/dev/zero} represent bottlenecks in the systems' performance,
9553 because @code{g77} simply asks for fewer zeros from the operating
9554 system than @code{f2c}.
9555 (Avoiding spurious use of zero bytes, each byte typically have
9556 eight zero bits, also reduces the liabilities in case
9557 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
9559 @node Block Data and Libraries
9560 @section Block Data and Libraries
9561 @cindex block data and libraries
9562 @cindex BLOCK DATA statement
9563 @cindex statements, BLOCK DATA
9564 @cindex libraries, containing BLOCK DATA
9565 @cindex f2c compatibility
9566 @cindex compatibility, f2c
9568 To ensure that block data program units are linked, especially a concern
9569 when they are put into libraries, give each one a name (as in
9570 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
9571 statement in every program unit that uses any common block
9572 initialized by the corresponding @code{BLOCK DATA}.
9573 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
9574 @code{SUBROUTINE},
9575 that is, it generates an actual procedure having the appropriate name.
9576 The procedure does nothing but return immediately if it happens to be
9577 called.
9578 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
9579 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
9580 in the program and ensures that by generating a
9581 reference to it so the linker will make sure it is present.
9582 (Specifically, @code{g77} outputs in the data section a static pointer to the
9583 external name @samp{FOO}.)
9585 The implementation @code{g77} currently uses to make this work is
9586 one of the few things not compatible with @code{f2c} as currently
9587 shipped.
9588 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
9589 issue a warning that @samp{FOO} is not otherwise referenced,
9590 and, for @samp{BLOCK DATA FOO},
9591 @code{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
9592 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
9593 this particular case.
9594 If you use @code{f2c} to compile @samp{BLOCK DATA FOO},
9595 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
9596 will result in an unresolved reference when linked.
9597 If you do the
9598 opposite, then @samp{FOO} might not be linked in under various
9599 circumstances (such as when @samp{FOO} is in a library, or you're
9600 using a ``clever'' linker---so clever, it produces a broken program
9601 with little or no warning by omitting initializations of global data
9602 because they are contained in unreferenced procedures).
9604 The changes you make to your code to make @code{g77} handle this situation,
9605 however, appear to be a widely portable way to handle it.
9606 That is, many systems permit it (as they should, since the
9607 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
9608 is a block data program unit), and of the ones
9609 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
9610 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
9611 program units.
9613 Here is the recommended approach to modifying a program containing
9614 a program unit such as the following:
9616 @smallexample
9617 BLOCK DATA FOO
9618 COMMON /VARS/ X, Y, Z
9619 DATA X, Y, Z / 3., 4., 5. /
9621 @end smallexample
9623 @noindent
9624 If the above program unit might be placed in a library module, then
9625 ensure that every program unit in every program that references that
9626 particular @code{COMMON} area uses the @code{EXTERNAL} statement
9627 to force the area to be initialized.
9629 For example, change a program unit that starts with
9631 @smallexample
9632 INTEGER FUNCTION CURX()
9633 COMMON /VARS/ X, Y, Z
9634 CURX = X
9636 @end smallexample
9638 @noindent
9639 so that it uses the @code{EXTERNAL} statement, as in:
9641 @smallexample
9642 INTEGER FUNCTION CURX()
9643 COMMON /VARS/ X, Y, Z
9644 EXTERNAL FOO
9645 CURX = X
9647 @end smallexample
9649 @noindent
9650 That way, @samp{CURX} is compiled by @code{g77} (and many other
9651 compilers) so that the linker knows it must include @samp{FOO},
9652 the @code{BLOCK DATA} program unit that sets the initial values
9653 for the variables in @samp{VAR}, in the executable program.
9655 @node Loops
9656 @section Loops
9657 @cindex DO statement
9658 @cindex statements, DO
9659 @cindex trips, number of
9660 @cindex number of trips
9662 The meaning of a @code{DO} loop in Fortran is precisely specified
9663 in the Fortran standard@dots{}and is quite different from what
9664 many programmers might expect.
9666 In particular, Fortran iterative @code{DO} loops are implemented as if
9667 the number of trips through the loop is calculated @emph{before}
9668 the loop is entered.
9670 The number of trips for a loop is calculated from the @var{start},
9671 @var{end}, and @var{increment} values specified in a statement such as:
9673 @smallexample
9674 DO @var{iter} = @var{start}, @var{end}, @var{increment}
9675 @end smallexample
9677 @noindent
9678 The trip count is evaluated using a fairly simple formula
9679 based on the three values following the @samp{=} in the
9680 statement, and it is that trip count that is effectively
9681 decremented during each iteration of the loop.
9682 If, at the beginning of an iteration of the loop, the
9683 trip count is zero or negative, the loop terminates.
9684 The per-loop-iteration modifications to @var{iter} are not
9685 related to determining whether to terminate the loop.
9687 There are two important things to remember about the trip
9688 count:
9690 @itemize @bullet
9691 @item
9692 It can be @emph{negative}, in which case it is
9693 treated as if it was zero---meaning the loop is
9694 not executed at all.
9696 @item
9697 The type used to @emph{calculate} the trip count
9698 is the same type as @var{iter}, but the final
9699 calculation, and thus the type of the trip
9700 count itself, always is @code{INTEGER(KIND=1)}.
9701 @end itemize
9703 These two items mean that there are loops that cannot
9704 be written in straightforward fashion using the Fortran @code{DO}.
9706 For example, on a system with the canonical 32-bit two's-complement
9707 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
9709 @smallexample
9710 DO I = -2000000000, 2000000000
9711 @end smallexample
9713 @noindent
9714 Although the @var{start} and @var{end} values are well within
9715 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
9716 The expected trip count is 40000000001, which is outside
9717 the range of @code{INTEGER(KIND=1)} on many systems.
9719 Instead, the above loop should be constructed this way:
9721 @smallexample
9722 I = -2000000000
9724   IF (I .GT. 2000000000) EXIT
9725   @dots{}
9726   I = I + 1
9727 END DO
9728 @end smallexample
9730 @noindent
9731 The simple @code{DO} construct and the @code{EXIT} statement
9732 (used to leave the innermost loop)
9733 are F90 features that @code{g77} supports.
9735 Some Fortran compilers have buggy implementations of @code{DO},
9736 in that they don't follow the standard.
9737 They implement @code{DO} as a straightforward translation
9738 to what, in C, would be a @code{for} statement.
9739 Instead of creating a temporary variable to hold the trip count
9740 as calculated at run time, these compilers
9741 use the iteration variable @var{iter} to control
9742 whether the loop continues at each iteration.
9744 The bug in such an implementation shows up when the
9745 trip count is within the range of the type of @var{iter},
9746 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
9747 exceeds that range.  For example:
9749 @smallexample
9750 DO I = 2147483600, 2147483647
9751 @end smallexample
9753 @noindent
9754 A loop started by the above statement will work as implemented
9755 by @code{g77}, but the use, by some compilers, of a
9756 more C-like implementation akin to
9758 @smallexample
9759 for (i = 2147483600; i <= 2147483647; ++i)
9760 @end smallexample
9762 @noindent
9763 produces a loop that does not terminate, because @samp{i}
9764 can never be greater than 2147483647, since incrementing it
9765 beyond that value overflows @samp{i}, setting it to -2147483648.
9766 This is a large, negative number that still is less than 2147483647.
9768 Another example of unexpected behavior of @code{DO} involves
9769 using a nonintegral iteration variable @var{iter}, that is,
9770 a @code{REAL} variable.
9771 Consider the following program:
9773 @smallexample
9774       DATA BEGIN, END, STEP /.1, .31, .007/
9775       DO 10 R = BEGIN, END, STEP
9776          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
9777          PRINT *,R
9778 10    CONTINUE
9779       PRINT *,'LAST = ',R
9780       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
9781       END
9782 @end smallexample
9784 @noindent
9785 A C-like view of @code{DO} would hold that the two ``exclamatory''
9786 @code{PRINT} statements are never executed.
9787 However, this is the output of running the above program
9788 as compiled by @code{g77} on a GNU/Linux ix86 system:
9790 @smallexample
9791  .100000001
9792  .107000001
9793  .114
9794  .120999999
9795  @dots{}
9796  .289000005
9797  .296000004
9798  .303000003
9799 LAST =   .310000002
9800  .310000002 .LE.   .310000002!!
9801 @end smallexample
9803 Note that one of the two checks in the program turned up
9804 an apparent violation of the programmer's expectation---yet,
9805 the loop is correctly implemented by @code{g77}, in that
9806 it has 30 iterations.
9807 This trip count of 30 is correct when evaluated using
9808 the floating-point representations for the @var{begin},
9809 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
9810 ix86 are used.
9811 On other systems, an apparently more accurate trip count
9812 of 31 might result, but, nevertheless, @code{g77} is
9813 faithfully following the Fortran standard, and the result
9814 is not what the author of the sample program above
9815 apparently expected.
9816 (Such other systems might, for different values in the @code{DATA}
9817 statement, violate the other programmer's expectation,
9818 for example.)
9820 Due to this combination of imprecise representation
9821 of floating-point values and the often-misunderstood
9822 interpretation of @code{DO} by standard-conforming
9823 compilers such as @code{g77}, use of @code{DO} loops
9824 with @code{REAL} iteration
9825 variables is not recommended.
9826 Such use can be caught by specifying @samp{-Wsurprising}.
9827 @xref{Warning Options}, for more information on this
9828 option.
9830 @node Working Programs
9831 @section Working Programs
9833 Getting Fortran programs to work in the first place can be
9834 quite a challenge---even when the programs already work on
9835 other systems, or when using other compilers.
9837 @code{g77} offers some facilities that might be useful for
9838 tracking down bugs in such programs.
9840 @menu
9841 * Not My Type::
9842 * Variables Assumed To Be Zero::
9843 * Variables Assumed To Be Saved::
9844 * Unwanted Variables::
9845 * Unused Arguments::
9846 * Surprising Interpretations of Code::
9847 * Aliasing Assumed To Work::
9848 * Output Assumed To Flush::
9849 * Large File Unit Numbers::
9850 * Floating-point precision::
9851 * Inconsistent Calling Sequences::
9852 @end menu
9854 @node Not My Type
9855 @subsection Not My Type
9856 @cindex mistyped variables
9857 @cindex variables, mistyped
9858 @cindex mistyped functions
9859 @cindex functions, mistyped
9860 @cindex implicit typing
9862 A fruitful source of bugs in Fortran source code is use, or
9863 mis-use, of Fortran's implicit-typing feature, whereby the
9864 type of a variable, array, or function is determined by the
9865 first character of its name.
9867 Simple cases of this include statements like @samp{LOGX=9.227},
9868 without a statement such as @samp{REAL LOGX}.
9869 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
9870 type, with the result of the assignment being that it is given
9871 the value @samp{9}.
9873 More involved cases include a function that is defined starting
9874 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
9875 Any caller of this function that does not also declare @samp{IPS}
9876 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
9877 is likely to assume it returns
9878 @code{INTEGER}, or some other type, leading to invalid results
9879 or even program crashes.
9881 The @samp{-Wimplicit} option might catch failures to
9882 properly specify the types of
9883 variables, arrays, and functions in the code.
9885 However, in code that makes heavy use of Fortran's
9886 implicit-typing facility, this option might produce so
9887 many warnings about cases that are working, it would be
9888 hard to find the one or two that represent bugs.
9889 This is why so many experienced Fortran programmers strongly
9890 recommend widespread use of the @code{IMPLICIT NONE} statement,
9891 despite it not being standard FORTRAN 77, to completely turn
9892 off implicit typing.
9893 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
9894 FORTRAN 77 compilers.)
9896 Note that @samp{-Wimplicit} catches only implicit typing of
9897 @emph{names}.
9898 It does not catch implicit typing of expressions such
9899 as @samp{X**(2/3)}.
9900 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
9901 is equivalent to @samp{X**0}, due to the way Fortran expressions
9902 are given types and then evaluated.
9903 (In this particular case, the programmer probably wanted
9904 @samp{X**(2./3.)}.)
9906 @node Variables Assumed To Be Zero
9907 @subsection Variables Assumed To Be Zero
9908 @cindex zero-initialized variables
9909 @cindex variables, assumed to be zero
9910 @cindex uninitialized variables
9912 Many Fortran programs were developed on systems that provided
9913 automatic initialization of all, or some, variables and arrays
9914 to zero.
9915 As a result, many of these programs depend, sometimes
9916 inadvertently, on this behavior, though to do so violates
9917 the Fortran standards.
9919 You can ask @code{g77} for this behavior by specifying the
9920 @samp{-finit-local-zero} option when compiling Fortran code.
9921 (You might want to specify @samp{-fno-automatic} as well,
9922 to avoid code-size inflation for non-optimized compilations.)
9924 Note that a program that works better when compiled with the
9925 @samp{-finit-local-zero} option
9926 is almost certainly depending on a particular system's,
9927 or compiler's, tendency to initialize some variables to zero.
9928 It might be worthwhile finding such cases and fixing them,
9929 using techniques such as compiling with the @samp{-O -Wuninitialized}
9930 options using @code{g77}.
9932 @node Variables Assumed To Be Saved
9933 @subsection Variables Assumed To Be Saved
9934 @cindex variables, retaining values across calls
9935 @cindex saved variables
9936 @cindex static variables
9938 Many Fortran programs were developed on systems that
9939 saved the values of all, or some, variables and arrays
9940 across procedure calls.
9941 As a result, many of these programs depend, sometimes
9942 inadvertently, on being able to assign a value to a
9943 variable, perform a @code{RETURN} to a calling procedure,
9944 and, upon subsequent invocation, reference the previously
9945 assigned variable to obtain the value.
9947 They expect this despite not using the @code{SAVE} statement
9948 to specify that the value in a variable is expected to survive
9949 procedure returns and calls.
9950 Depending on variables and arrays to retain values across
9951 procedure calls without using @code{SAVE} to require it violates
9952 the Fortran standards.
9954 You can ask @code{g77} to assume @code{SAVE} is specified for all
9955 relevant (local) variables and arrays by using the
9956 @samp{-fno-automatic} option.
9958 Note that a program that works better when compiled with the
9959 @samp{-fno-automatic} option
9960 is almost certainly depending on not having to use
9961 the @code{SAVE} statement as required by the Fortran standard.
9962 It might be worthwhile finding such cases and fixing them,
9963 using techniques such as compiling with the @samp{-O -Wuninitialized}
9964 options using @code{g77}.
9966 @node Unwanted Variables
9967 @subsection Unwanted Variables
9969 The @samp{-Wunused} option can find bugs involving
9970 implicit typing, sometimes
9971 more easily than using @samp{-Wimplicit} in code that makes
9972 heavy use of implicit typing.
9973 An unused variable or array might indicate that the
9974 spelling for its declaration is different from that of
9975 its intended uses.
9977 Other than cases involving typos, unused variables rarely
9978 indicate actual bugs in a program.
9979 However, investigating such cases thoroughly has, on occasion,
9980 led to the discovery of code that had not been completely
9981 written---where the programmer wrote declarations as needed
9982 for the whole algorithm, wrote some or even most of the code
9983 for that algorithm, then got distracted and forgot that the
9984 job was not complete.
9986 @node Unused Arguments
9987 @subsection Unused Arguments
9988 @cindex unused arguments
9989 @cindex arguments, unused
9991 As with unused variables, It is possible that unused arguments
9992 to a procedure might indicate a bug.
9993 Compile with @samp{-W -Wunused} option to catch cases of
9994 unused arguments.
9996 Note that @samp{-W} also enables warnings regarding overflow
9997 of floating-point constants under certain circumstances.
9999 @node Surprising Interpretations of Code
10000 @subsection Surprising Interpretations of Code
10002 The @samp{-Wsurprising} option can help find bugs involving
10003 expression evaluation or in
10004 the way @code{DO} loops with non-integral iteration variables
10005 are handled.
10006 Cases found by this option might indicate a difference of
10007 interpretation between the author of the code involved, and
10008 a standard-conforming compiler such as @code{g77}.
10009 Such a difference might produce actual bugs.
10011 In any case, changing the code to explicitly do what the
10012 programmer might have expected it to do, so @code{g77} and
10013 other compilers are more likely to follow the programmer's
10014 expectations, might be worthwhile, especially if such changes
10015 make the program work better.
10017 @node Aliasing Assumed To Work
10018 @subsection Aliasing Assumed To Work
10019 @cindex -falias-check option
10020 @cindex options, -falias-check
10021 @cindex -fargument-alias option
10022 @cindex options, -fargument-alias
10023 @cindex -fargument-noalias option
10024 @cindex options, -fargument-noalias
10025 @cindex -fno-argument-noalias-global option
10026 @cindex options, -fno-argument-noalias-global
10027 @cindex aliasing
10028 @cindex anti-aliasing
10029 @cindex overlapping arguments
10030 @cindex overlays
10031 @cindex association, storage
10032 @cindex storage association
10033 @cindex scheduling of reads and writes
10034 @cindex reads and writes, scheduling
10036 The @samp{-falias-check}, @samp{-fargument-alias},
10037 @samp{-fargument-noalias},
10038 and @samp{-fno-argument-noalias-global} options,
10039 introduced in version 0.5.20 and
10040 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
10041 were withdrawn as of @code{g77} version 0.5.23
10042 due to their not being supported by @code{gcc} version 2.8.
10044 These options control the assumptions regarding aliasing
10045 (overlapping) of writes and reads to main memory (core) made
10046 by the @code{gcc} back end.
10048 The information below still is useful, but applies to
10049 only those versions of @code{g77} that support the
10050 alias analysis implied by support for these options.
10052 These options are effective only when compiling with @samp{-O}
10053 (specifying any level other than @samp{-O0})
10054 or with @samp{-falias-check}.
10056 The default for Fortran code is @samp{-fargument-noalias-global}.
10057 (The default for C code and code written in other C-based languages
10058 is @samp{-fargument-alias}.
10059 These defaults apply regardless of whether you use @code{g77} or
10060 @code{gcc} to compile your code.)
10062 Note that, on some systems, compiling with @samp{-fforce-addr} in
10063 effect can produce more optimal code when the default aliasing
10064 options are in effect (and when optimization is enabled).
10066 If your program is not working when compiled with optimization,
10067 it is possible it is violating the Fortran standards (77 and 90)
10068 by relying on the ability to ``safely'' modify variables and
10069 arrays that are aliased, via procedure calls, to other variables
10070 and arrays, without using @code{EQUIVALENCE} to explicitly
10071 set up this kind of aliasing.
10073 (The FORTRAN 77 standard's prohibition of this sort of
10074 overlap, generally referred to therein as ``storage
10075 assocation'', appears in Sections 15.9.3.6.
10076 This prohibition allows implementations, such as @code{g77},
10077 to, for example, implement the passing of procedures and
10078 even values in @code{COMMON} via copy operations into local,
10079 perhaps more efficiently accessed temporaries at entry to a
10080 procedure, and, where appropriate, via copy operations back
10081 out to their original locations in memory at exit from that
10082 procedure, without having to take into consideration the
10083 order in which the local copies are updated by the code,
10084 among other things.)
10086 To test this hypothesis, try compiling your program with
10087 the @samp{-fargument-alias} option, which causes the
10088 compiler to revert to assumptions essentially the same as
10089 made by versions of @code{g77} prior to 0.5.20.
10091 If the program works using this option, that strongly suggests
10092 that the bug is in your program.
10093 Finding and fixing the bug(s) should result in a program that
10094 is more standard-conforming and that can be compiled by @code{g77}
10095 in a way that results in a faster executable.
10097 (You might want to try compiling with @samp{-fargument-noalias},
10098 a kind of half-way point, to see if the problem is limited to
10099 aliasing between dummy arguments and @code{COMMON} variables---this
10100 option assumes that such aliasing is not done, while still allowing
10101 aliasing among dummy arguments.)
10103 An example of aliasing that is invalid according to the standards
10104 is shown in the following program, which might @emph{not} produce
10105 the expected results when executed:
10107 @smallexample
10108 I = 1
10109 CALL FOO(I, I)
10110 PRINT *, I
10113 SUBROUTINE FOO(J, K)
10114 J = J + K
10115 K = J * K
10116 PRINT *, J, K
10118 @end smallexample
10120 The above program attempts to use the temporary aliasing of the
10121 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
10122 pathological behavior---the simultaneous changing of the values
10123 of @emph{both} @samp{J} and @samp{K} when either one of them
10124 is written.
10126 The programmer likely expects the program to print these values:
10128 @example
10129 2  4
10131 @end example
10133 However, since the program is not standard-conforming, an
10134 implementation's behavior when running it is undefined, because
10135 subroutine @samp{FOO} modifies at least one of the arguments,
10136 and they are aliased with each other.
10137 (Even if one of the assignment statements was deleted, the
10138 program would still violate these rules.
10139 This kind of on-the-fly aliasing is permitted by the standard
10140 only when none of the aliased items are defined, or written,
10141 while the aliasing is in effect.)
10143 As a practical example, an optimizing compiler might schedule
10144 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
10145 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
10146 resulting in the following output:
10148 @example
10149 2  2
10151 @end example
10153 Essentially, compilers are promised (by the standard and, therefore,
10154 by programmers who write code they claim to be standard-conforming)
10155 that if they cannot detect aliasing via static analysis of a single
10156 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
10157 such aliasing exists.
10158 In such cases, compilers are free to assume that an assignment to
10159 one variable will not change the value of another variable, allowing
10160 it to avoid generating code to re-read the value of the other
10161 variable, to re-schedule reads and writes, and so on, to produce
10162 a faster executable.
10164 The same promise holds true for arrays (as seen by the called
10165 procedure)---an element of one dummy array cannot be aliased
10166 with, or overlap, any element of another dummy array or be
10167 in a @code{COMMON} area known to the procedure.
10169 (These restrictions apply only when the procedure defines, or
10170 writes to, one of the aliased variables or arrays.)
10172 Unfortunately, there is no way to find @emph{all} possible cases of
10173 violations of the prohibitions against aliasing in Fortran code.
10174 Static analysis is certainly imperfect, as is run-time analysis,
10175 since neither can catch all violations.
10176 (Static analysis can catch all likely violations, and some that
10177 might never actually happen, while run-time analysis can catch
10178 only those violations that actually happen during a particular run.
10179 Neither approach can cope with programs mixing Fortran code with
10180 routines written in other languages, however.)
10182 Currently, @code{g77} provides neither static nor run-time facilities
10183 to detect any cases of this problem, although other products might.
10184 Run-time facilities are more likely to be offered by future
10185 versions of @code{g77}, though patches improving @code{g77} so that
10186 it provides either form of detection are welcome.
10188 @node Output Assumed To Flush
10189 @subsection Output Assumed To Flush
10190 @cindex ALWAYS_FLUSH
10191 @cindex synchronous write errors
10192 @cindex disk full
10193 @cindex flushing output
10194 @cindex fflush()
10195 @cindex I/O, flushing
10196 @cindex output, flushing
10197 @cindex writes, flushing
10198 @cindex NFS
10199 @cindex network file system
10201 For several versions prior to 0.5.20, @code{g77} configured its
10202 version of the @code{libf2c} run-time library so that one of
10203 its configuration macros, @code{ALWAYS_FLUSH}, was defined.
10205 This was done as a result of a belief that many programs expected
10206 output to be flushed to the operating system (under UNIX, via
10207 the @code{fflush()} library call) with the result that errors,
10208 such as disk full, would be immediately flagged via the
10209 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
10211 Because of the adverse effects this approach had on the performance
10212 of many programs, @code{g77} no longer configures @code{libf2c}
10213 (now named @code{libg2c} in its @code{g77} incarnation)
10214 to always flush output.
10216 If your program depends on this behavior, either insert the
10217 appropriate @samp{CALL FLUSH} statements, or modify the sources
10218 to the @code{libg2c}, rebuild and reinstall @code{g77}, and
10219 relink your programs with the modified library.
10221 (Ideally, @code{libg2c} would offer the choice at run-time, so
10222 that a compile-time option to @code{g77} or @code{f2c} could
10223 result in generating the appropriate calls to flushing or
10224 non-flushing library routines.)
10226 @xref{Always Flush Output}, for information on how to modify
10227 the @code{g77} source tree so that a version of @code{libg2c}
10228 can be built and installed with the @code{ALWAYS_FLUSH} macro defined.
10230 @node Large File Unit Numbers
10231 @subsection Large File Unit Numbers
10232 @cindex MXUNIT
10233 @cindex unit numbers
10234 @cindex maximum unit number
10235 @cindex illegal unit number
10236 @cindex increasing maximum unit number
10238 If your program crashes at run time with a message including
10239 the text @samp{illegal unit number}, that probably is
10240 a message from the run-time library, @code{libg2c}.
10242 The message means that your program has attempted to use a
10243 file unit number that is out of the range accepted by
10244 @code{libg2c}.
10245 Normally, this range is 0 through 99, and the high end
10246 of the range is controlled by a @code{libg2c} source-file
10247 macro named @code{MXUNIT}.
10249 If you can easily change your program to use unit numbers
10250 in the range 0 through 99, you should do so.
10252 Otherwise, see @ref{Larger File Unit Numbers}, for information on how
10253 to change @code{MXUNIT} in @code{libg2c} so you can build and
10254 install a new version of @code{libg2c} that supports the larger
10255 unit numbers you need.
10257 @emph{Note:} While @code{libg2c} places a limit on the range
10258 of Fortran file-unit numbers, the underlying library and operating
10259 system might impose different kinds of limits.
10260 For example, some systems limit the number of files simultaneously
10261 open by a running program.
10262 Information on how to increase these limits should be found
10263 in your system's documentation.
10265 @node Floating-point precision
10266 @subsection Floating-point precision
10268 @cindex IEEE 754 conformance
10269 @cindex conformance, IEEE 754
10270 @cindex floating-point, precision
10271 @cindex ix86 floating-point
10272 @cindex x86 floating-point
10273 If your program depends on exact IEEE 754 floating-point handling it may
10274 help on some systems---specifically x86 or m68k hardware---to use
10275 the @samp{-ffloat-store} option or to reset the precision flag on the
10276 floating-point unit.
10277 @xref{Optimize Options}.
10279 However, it might be better simply to put the FPU into double precision
10280 mode and not take the performance hit of @samp{-ffloat-store}.  On x86
10281 and m68k GNU systems you can do this with a technique similar to that
10282 for turning on floating-point exceptions
10283 (@pxref{Floating-point Exception Handling}).
10284 The control word could be set to double precision by some code like this
10285 one:
10286 @smallexample
10287 #include <fpu_control.h>
10289   fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
10290   _FPU_SETCW(cw);
10292 @end smallexample
10293 (It is not clear whether this has any effect on the operation of the GNU
10294 maths library, but we have no evidence of it causing trouble.)
10296 Some targets (such as the Alpha) may need special options for full IEEE
10297 conformance.
10298 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and Porting GNU CC}.
10300 @node Inconsistent Calling Sequences
10301 @subsection Inconsistent Calling Sequences
10303 @pindex ftnchek
10304 @cindex floating-point, errors
10305 @cindex ix86 FPU stack
10306 @cindex x86 FPU stack
10307 Code containing inconsistent calling sequences in the same file is
10308 normally rejected---see @ref{GLOBALS}.
10309 (Use, say, @code{ftnchek} to ensure
10310 consistency across source files.
10311 @xref{f2c Skeletons and Prototypes,,
10312 Generating Skeletons and Prototypes with @code{f2c}}.)
10314 Mysterious errors, which may appear to be code generation problems, can
10315 appear specifically on the x86 architecture with some such
10316 inconsistencies.  On x86 hardware, floating-point return values of
10317 functions are placed on the floating-point unit's register stack, not
10318 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
10319 @code{FUNCTION} as some other sort of procedure, or vice versa,
10320 scrambles the floating-point stack.  This may break unrelated code
10321 executed later.  Similarly if, say, external C routines are written
10322 incorrectly.
10324 @node Overly Convenient Options
10325 @section Overly Convenient Command-line Options
10326 @cindex overly convenient options
10327 @cindex options, overly convenient
10329 These options should be used only as a quick-and-dirty way to determine
10330 how well your program will run under different compilation models
10331 without having to change the source.
10332 Some are more problematic
10333 than others, depending on how portable and maintainable you want the
10334 program to be (and, of course, whether you are allowed to change it
10335 at all is crucial).
10337 You should not continue to use these command-line options to compile
10338 a given program, but rather should make changes to the source code:
10340 @table @code
10341 @cindex -finit-local-zero option
10342 @cindex options, -finit-local-zero
10343 @item -finit-local-zero
10344 (This option specifies that any uninitialized local variables
10345 and arrays have default initialization to binary zeros.)
10347 Many other compilers do this automatically, which means lots of
10348 Fortran code developed with those compilers depends on it.
10350 It is safer (and probably
10351 would produce a faster program) to find the variables and arrays that
10352 need such initialization and provide it explicitly via @code{DATA}, so that
10353 @samp{-finit-local-zero} is not needed.
10355 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
10356 find likely candidates, but
10357 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
10358 or this technique won't work.
10360 @cindex -fno-automatic option
10361 @cindex options, -fno-automatic
10362 @item -fno-automatic
10363 (This option specifies that all local variables and arrays
10364 are to be treated as if they were named in @code{SAVE} statements.)
10366 Many other compilers do this automatically, which means lots of
10367 Fortran code developed with those compilers depends on it.
10369 The effect of this is that all non-automatic variables and arrays
10370 are made static, that is, not placed on the stack or in heap storage.
10371 This might cause a buggy program to appear to work better.
10372 If so, rather than relying on this command-line option (and hoping all
10373 compilers provide the equivalent one), add @code{SAVE}
10374 statements to some or all program unit sources, as appropriate.
10375 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
10376 to find likely candidates, but
10377 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
10378 or this technique won't work.
10380 The default is @samp{-fautomatic}, which tells @code{g77} to try
10381 and put variables and arrays on the stack (or in fast registers)
10382 where possible and reasonable.
10383 This tends to make programs faster.
10385 @cindex automatic arrays
10386 @cindex arrays, automatic
10387 @emph{Note:} Automatic variables and arrays are not affected
10388 by this option.
10389 These are variables and arrays that are @emph{necessarily} automatic,
10390 either due to explicit statements, or due to the way they are
10391 declared.
10392 Examples include local variables and arrays not given the
10393 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
10394 and local arrays declared with non-constant bounds (automatic
10395 arrays).
10396 Currently, @code{g77} supports only automatic arrays, not
10397 @code{RECURSIVE} procedures or other means of explicitly
10398 specifying that variables or arrays are automatic.
10400 @cindex -f@var{group}-intrinsics-hide option
10401 @cindex options, -f@var{group}-intrinsics-hide
10402 @item -f@var{group}-intrinsics-hide
10403 Change the source code to use @code{EXTERNAL} for any external procedure
10404 that might be the name of an intrinsic.
10405 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
10406 @end table
10408 @node Faster Programs
10409 @section Faster Programs
10410 @cindex speed, of programs
10411 @cindex programs, speeding up
10413 Aside from the usual @code{gcc} options, such as @samp{-O},
10414 @samp{-ffast-math}, and so on, consider trying some of the
10415 following approaches to speed up your program (once you get
10416 it working).
10418 @menu
10419 * Aligned Data::
10420 * Prefer Automatic Uninitialized Variables::
10421 * Avoid f2c Compatibility::
10422 * Use Submodel Options::
10423 @end menu
10425 @node Aligned Data
10426 @subsection Aligned Data
10427 @cindex alignment
10428 @cindex data, aligned
10429 @cindex stack, aligned
10430 @cindex aligned data
10431 @cindex aligned stack
10432 @cindex Pentium optimizations
10433 @cindex optimization, for Pentium
10435 On some systems, such as those with Pentium Pro CPUs, programs
10436 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
10437 might run much slower
10438 than possible due to the compiler not aligning these 64-bit
10439 values to 64-bit boundaries in memory.
10440 (The effect also is present, though
10441 to a lesser extent, on the 586 (Pentium) architecture.)
10443 The Intel x86 architecture generally ensures that these programs will
10444 work on all its implementations,
10445 but particular implementations (such as Pentium Pro)
10446 perform better with more strict alignment.
10447 (Such behavior isn't unique to the Intel x86 architecture.)
10448 Other architectures might @emph{demand} 64-bit alignment
10449 of 64-bit data.
10451 There are a variety of approaches to use to address this problem:
10453 @itemize @bullet
10454 @item
10455 @cindex @code{COMMON} layout
10456 @cindex layout of @code{COMMON} blocks
10457 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
10458 that the variables and arrays with the widest alignment
10459 guidelines come first.
10461 For example, on most systems, this would mean placing
10462 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
10463 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
10464 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
10465 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
10466 and @code{INTEGER(KIND=3)} entities.
10468 The reason to use such placement is it makes it more likely
10469 that your data will be aligned properly, without requiring
10470 you to do detailed analysis of each aggregate (@code{COMMON}
10471 and @code{EQUIVALENCE}) area.
10473 Specifically, on systems where the above guidelines are
10474 appropriate, placing @code{CHARACTER} entities before
10475 @code{REAL(KIND=2)} entities can work just as well,
10476 but only if the number of bytes occupied by the @code{CHARACTER}
10477 entities is divisible by the recommended alignment for
10478 @code{REAL(KIND=2)}.
10480 By ordering the placement of entities in aggregate
10481 areas according to the simple guidelines above, you
10482 avoid having to carefully count the number of bytes
10483 occupied by each entity to determine whether the
10484 actual alignment of each subsequent entity meets the
10485 alignment guidelines for the type of that entity.
10487 If you don't ensure correct alignment of @code{COMMON} elements, the
10488 compiler may be forced by some systems to violate the Fortran semantics by
10489 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
10490 If the unfortunate practice is employed of overlaying different types of
10491 data in the @code{COMMON} block, the different variants
10492 of this block may become misaligned with respect to each other.
10493 Even if your platform doesn't require strict alignment,
10494 @code{COMMON} should be laid out as above for portability.
10495 (Unfortunately the FORTRAN 77 standard didn't anticipate this
10496 possible requirement, which is compiler-independent on a given platform.)
10498 @item
10499 @cindex -malign-double option
10500 @cindex options, -malign-double
10501 Use the (x86-specific) @samp{-malign-double} option when compiling
10502 programs for the Pentium and Pentium Pro architectures (called 586
10503 and 686 in the @code{gcc} configuration subsystem).
10504 The warning about this in the @code{gcc} manual isn't
10505 generally relevant to Fortran,
10506 but using it will force @code{COMMON} to be padded if necessary to align
10507 @code{DOUBLE PRECISION} data.
10509 When @code{DOUBLE PRECISION} data is forcibly aligned
10510 in @code{COMMON} by @code{g77} due to specifying @samp{-malign-double},
10511 @code{g77} issues a warning about the need to
10512 insert padding.
10514 In this case, each and every program unit that uses
10515 the same @code{COMMON} area
10516 must specify the same layout of variables and their types
10517 for that area
10518 and be compiled with @samp{-malign-double} as well.
10519 @code{g77} will issue warnings in each case,
10520 but as long as every program unit using that area
10521 is compiled with the same warnings,
10522 the resulting object files should work when linked together
10523 unless the program makes additional assumptions about
10524 @code{COMMON} area layouts that are outside the scope
10525 of the FORTRAN 77 standard,
10526 or uses @code{EQUIVALENCE} or different layouts
10527 in ways that assume no padding is ever inserted by the compiler.
10529 @item
10530 Ensure that @file{crt0.o} or @file{crt1.o}
10531 on your system guarantees a 64-bit
10532 aligned stack for @code{main()}.
10533 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
10534 but we don't know of any other x86 setups where it will be right.
10535 Read your system's documentation to determine if
10536 it is appropriate to upgrade to a more recent version
10537 to obtain the optimal alignment.
10538 @end itemize
10540 Progress is being made on making this work
10541 ``out of the box'' on future versions of @code{g77},
10542 @code{gcc}, and some of the relevant operating systems
10543 (such as GNU/Linux).
10545 @cindex alignment testing
10546 @cindex testing alignment
10547 A package that tests the degree to which a Fortran compiler
10548 (such as @code{g77})
10549 aligns 64-bit floating-point variables and arrays
10550 is available at @uref{ftp://alpha.gnu.org/gnu/g77/align/}.
10552 @node Prefer Automatic Uninitialized Variables
10553 @subsection Prefer Automatic Uninitialized Variables
10555 If you're using @samp{-fno-automatic} already, you probably
10556 should change your code to allow compilation with @samp{-fautomatic}
10557 (the default), to allow the program to run faster.
10559 Similarly, you should be able to use @samp{-fno-init-local-zero}
10560 (the default) instead of @samp{-finit-local-zero}.
10561 This is because it is rare that every variable affected by these
10562 options in a given program actually needs to
10563 be so affected.
10565 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
10566 every local non-automatic variable and array, affects even things like
10567 @code{DO} iteration
10568 variables, which rarely need to be @code{SAVE}d, and this often reduces
10569 run-time performances.
10570 Similarly, @samp{-fno-init-local-zero} forces such
10571 variables to be initialized to zero---when @code{SAVE}d (such as when
10572 @samp{-fno-automatic}), this by itself generally affects only
10573 startup time for a program, but when not @code{SAVE}d,
10574 it can slow down the procedure every time it is called.
10576 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10577 for information on the @samp{-fno-automatic} and
10578 @samp{-finit-local-zero} options and how to convert
10579 their use into selective changes in your own code.
10581 @node Avoid f2c Compatibility
10582 @subsection Avoid f2c Compatibility
10583 @cindex -fno-f2c option
10584 @cindex options, -fno-f2c
10585 @cindex @code{f2c} compatibility
10586 @cindex compatibility, @code{f2c}
10588 If you aren't linking with any code compiled using
10589 @code{f2c}, try using the @samp{-fno-f2c} option when
10590 compiling @emph{all} the code in your program.
10591 (Note that @code{libf2c} is @emph{not} an example of code
10592 that is compiled using @code{f2c}---it is compiled by a C
10593 compiler, typically @code{gcc}.)
10595 @node Use Submodel Options
10596 @subsection Use Submodel Options
10597 @cindex submodels
10599 Using an appropriate @samp{-m} option to generate specific code for your
10600 CPU may be worthwhile, though it may mean the executable won't run on
10601 other versions of the CPU that don't support the same instruction set.
10602 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
10603 Porting GNU CC}.  For instance on an x86 system the compiler might have
10604 been built---as shown by @samp{g77 -v}---for the target
10605 @samp{i386-pc-linux-gnu}, i.e.@: an @samp{i386} CPU@.  In that case to
10606 generate code best optimized for a Pentium you could use the option
10607 @samp{-march=pentium}.
10609 For recent CPUs that don't have explicit support in the released version
10610 of @code{gcc}, it @emph{might} still be possible to get improvements
10611 with certain @samp{-m} options.
10613 @samp{-fomit-frame-pointer} can help performance on x86 systems and
10614 others.  It will, however, inhibit debugging on the systems on which it
10615 is not turned on anyway by @samp{-O}.
10617 @node Trouble
10618 @chapter Known Causes of Trouble with GNU Fortran
10619 @cindex bugs, known
10620 @cindex installation trouble
10621 @cindex known causes of trouble
10623 This section describes known problems that affect users of GNU Fortran.
10624 Most of these are not GNU Fortran bugs per se---if they were, we would
10625 fix them.
10626 But the result for a user might be like the result of a bug.
10628 Some of these problems are due to bugs in other software, some are
10629 missing features that are too much work to add, and some are places
10630 where people's opinions differ as to what is best.
10632 Information on bugs that show up when configuring, porting, building,
10633 or installing @code{g77} is not provided here.
10634 @xref{Problems Installing}.
10636 To find out about major bugs discovered in the current release and
10637 possible workarounds for them, see
10638 @uref{ftp://alpha.gnu.org/g77.plan}.
10640 (Note that some of this portion of the manual is lifted
10641 directly from the @code{gcc} manual, with minor modifications
10642 to tailor it to users of @code{g77}.
10643 Anytime a bug seems to have more to do with the @code{gcc}
10644 portion of @code{g77}, see
10645 @ref{Trouble,,Known Causes of Trouble with GNU CC,
10646 gcc,Using and Porting GNU CC}.)
10648 @menu
10649 * But-bugs::         Bugs really in other programs or elsewhere.
10650 * Known Bugs::       Bugs known to be in this version of @code{g77}.
10651 * Missing Features:: Features we already know we want to add later.
10652 * Disappointments::  Regrettable things we can't change.
10653 * Non-bugs::         Things we think are right, but some others disagree.
10654 * Warnings and Errors::  Which problems in your code get warnings,
10655                         and which get errors.
10656 @end menu
10658 @node But-bugs
10659 @section Bugs Not In GNU Fortran
10660 @cindex but-bugs
10662 These are bugs to which the maintainers often have to reply,
10663 ``but that isn't a bug in @code{g77}@dots{}''.
10664 Some of these already are fixed in new versions of other
10665 software; some still need to be fixed; some are problems
10666 with how @code{g77} is installed or is being used;
10667 some are the result of bad hardware that causes software
10668 to misbehave in sometimes bizarre ways;
10669 some just cannot be addressed at this time until more
10670 is known about the problem.
10672 Please don't re-report these bugs to the @code{g77} maintainers---if
10673 you must remind someone how important it is to you that the problem
10674 be fixed, talk to the people responsible for the other products
10675 identified below, but preferably only after you've tried the
10676 latest versions of those products.
10677 The @code{g77} maintainers have their hands full working on
10678 just fixing and improving @code{g77}, without serving as a
10679 clearinghouse for all bugs that happen to affect @code{g77}
10680 users.
10682 @xref{Collected Fortran Wisdom}, for information on behavior
10683 of Fortran programs, and the programs that compile them, that
10684 might be @emph{thought} to indicate bugs.
10686 @menu
10687 * Signal 11 and Friends::  Strange behavior by any software.
10688 * Cannot Link Fortran Programs::  Unresolved references.
10689 * Large Common Blocks::    Problems on older GNU/Linux systems.
10690 * Debugger Problems::      When the debugger crashes.
10691 * NeXTStep Problems::      Misbehaving executables.
10692 * Stack Overflow::         More misbehaving executables.
10693 * Nothing Happens::        Less behaving executables.
10694 * Strange Behavior at Run Time::  Executables misbehaving due to
10695                             bugs in your program.
10696 * Floating-point Errors::  The results look wrong, but@dots{}.
10697 @end menu
10699 @node Signal 11 and Friends
10700 @subsection Signal 11 and Friends
10701 @cindex signal 11
10702 @cindex hardware errors
10704 A whole variety of strange behaviors can occur when the
10705 software, or the way you are using the software,
10706 stresses the hardware in a way that triggers hardware bugs.
10707 This might seem hard to believe, but it happens frequently
10708 enough that there exist documents explaining in detail
10709 what the various causes of the problems are, what
10710 typical symptoms look like, and so on.
10712 Generally these problems are referred to in this document
10713 as ``signal 11'' crashes, because the Linux kernel, running
10714 on the most popular hardware (the Intel x86 line), often
10715 stresses the hardware more than other popular operating
10716 systems.
10717 When hardware problems do occur under GNU/Linux on x86
10718 systems, these often manifest themselves as ``signal 11''
10719 problems, as illustrated by the following diagnostic:
10721 @smallexample
10722 sh# @kbd{g77 myprog.f}
10723 gcc: Internal compiler error: program f771 got fatal signal 11
10725 @end smallexample
10727 It is @emph{very} important to remember that the above
10728 message is @emph{not} the only one that indicates a
10729 hardware problem, nor does it always indicate a hardware
10730 problem.
10732 In particular, on systems other than those running the Linux
10733 kernel, the message might appear somewhat or very different,
10734 as it will if the error manifests itself while running a
10735 program other than the @code{g77} compiler.
10736 For example,
10737 it will appear somewhat different when running your program,
10738 when running Emacs, and so on.
10740 How to cope with such problems is well beyond the scope
10741 of this manual.
10743 However, users of Linux-based systems (such as GNU/Linux)
10744 should review @uref{http://www.bitwizard.nl/sig11/}, a source
10745 of detailed information on diagnosing hardware problems,
10746 by recognizing their common symptoms.
10748 Users of other operating systems and hardware might
10749 find this reference useful as well.
10750 If you know of similar material for another hardware/software
10751 combination, please let us know so we can consider including
10752 a reference to it in future versions of this manual.
10754 @node Cannot Link Fortran Programs
10755 @subsection Cannot Link Fortran Programs
10756 @cindex unresolved reference (various)
10757 @cindex linking error for user code
10758 @cindex code, user
10759 @cindex @code{ld}, error linking user code
10760 @cindex @code{ld}, can't find strange names
10761 On some systems, perhaps just those with out-of-date (shared?)
10762 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
10763 programs (which should be done using @code{g77}).
10765 If this happens to you, try appending @samp{-lc} to the command you
10766 use to link the program, e.g. @samp{g77 foo.f -lc}.
10767 @code{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
10768 but it cannot also specify @samp{-lc} because not all systems have a
10769 file named @file{libc.a}.
10771 It is unclear at this point whether there are legitimately installed
10772 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
10773 by @code{g77}.
10775 @cindex undefined reference (_main)
10776 @cindex linking error, user code
10777 @cindex @code{ld}, error linking user code
10778 @cindex code, user
10779 @cindex @code{ld}, can't find @samp{_main}
10780 If your program doesn't link due to unresolved references to names
10781 like @samp{_main}, make sure you're using the @code{g77} command to do the
10782 link, since this command ensures that the necessary libraries are
10783 loaded by specifying @samp{-lg2c -lm} when it invokes the @code{gcc}
10784 command to do the actual link.
10785 (Use the @samp{-v} option to discover
10786 more about what actually happens when you use the @code{g77} and @code{gcc}
10787 commands.)
10789 Also, try specifying @samp{-lc} as the last item on the @code{g77}
10790 command line, in case that helps.
10792 @node Large Common Blocks
10793 @subsection Large Common Blocks
10794 @cindex common blocks, large
10795 @cindex large common blocks
10796 @cindex linking, errors
10797 @cindex @code{ld}, errors
10798 @cindex errors, linker
10799 On some older GNU/Linux systems, programs with common blocks larger
10800 than 16MB cannot be linked without some kind of error
10801 message being produced.
10803 This is a bug in older versions of @code{ld}, fixed in
10804 more recent versions of @code{binutils}, such as version 2.6.
10806 @node Debugger Problems
10807 @subsection Debugger Problems
10808 @cindex @code{gdb}, support
10809 @cindex support, @code{gdb}
10810 There are some known problems when using @code{gdb} on code
10811 compiled by @code{g77}.
10812 Inadequate investigation as of the release of 0.5.16 results in not
10813 knowing which products are the culprit, but @file{gdb-4.14} definitely
10814 crashes when, for example, an attempt is made to print the contents
10815 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
10816 machines, plus some others.
10817 Attempts to access assumed-size arrays are
10818 also known to crash recent versions of @code{gdb}.
10819 (@code{gdb}'s Fortran support was done for a different compiler
10820 and isn't properly compatible with @code{g77}.)
10822 @node NeXTStep Problems
10823 @subsection NeXTStep Problems
10824 @cindex NeXTStep problems
10825 @cindex bus error
10826 @cindex segmentation violation
10827 Developers of Fortran code on NeXTStep (all architectures) have to
10828 watch out for the following problem when writing programs with
10829 large, statically allocated (i.e. non-stack based) data structures
10830 (common blocks, saved arrays).
10832 Due to the way the native loader (@file{/bin/ld}) lays out
10833 data structures in virtual memory, it is very easy to create an
10834 executable wherein the @samp{__DATA} segment overlaps (has addresses in
10835 common) with the @samp{UNIX STACK} segment.
10837 This leads to all sorts of trouble, from the executable simply not
10838 executing, to bus errors.
10839 The NeXTStep command line tool @code{ebadexec} points to
10840 the problem as follows:
10842 @smallexample
10843 % @kbd{/bin/ebadexec a.out}
10844 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
10845 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
10846 STACK segment (truncated address = 0x400000 rounded size =
10847 0x3c00000) of executable file: a.out
10848 @end smallexample
10850 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
10851 stack segment.)
10853 This can be cured by assigning the @samp{__DATA} segment
10854 (virtual) addresses beyond the stack segment.
10855 A conservative
10856 estimate for this is from address 6000000 (hexadecimal) onwards---this
10857 has always worked for me [Toon Moene]:
10859 @smallexample
10860 % @kbd{g77 -segaddr __DATA 6000000 test.f}
10861 % @kbd{ebadexec a.out}
10862 ebadexec: file: a.out appears to be executable
10864 @end smallexample
10866 Browsing through @file{@value{path-g77}/Makefile.in},
10867 you will find that the @code{f771} program itself also has to be
10868 linked with these flags---it has large statically allocated
10869 data structures.
10870 (Version 0.5.18 reduces this somewhat, but probably
10871 not enough.)
10873 (The above item was contributed by Toon Moene
10874 (@email{toon@@moene.indiv.nluug.nl}).)
10876 @node Stack Overflow
10877 @subsection Stack Overflow
10878 @cindex stack, overflow
10879 @cindex segmentation violation
10880 @code{g77} code might fail at runtime (probably with a ``segmentation
10881 violation'') due to overflowing the stack.
10882 This happens most often on systems with an environment
10883 that provides substantially more heap space (for use
10884 when arbitrarily allocating and freeing memory) than stack
10885 space.
10887 Often this can be cured by
10888 increasing or removing your shell's limit on stack usage, typically
10889 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
10890 @kbd{ulimit -s} (in @code{sh} and derivatives).
10892 Increasing the allowed stack size might, however, require
10893 changing some operating system or system configuration parameters.
10895 You might be able to work around the problem by compiling with the
10896 @samp{-fno-automatic} option to reduce stack usage, probably at the
10897 expense of speed.
10899 @xref{Maximum Stackable Size}, for information on patching
10900 @code{g77} to use different criteria for placing local
10901 non-automatic variables and arrays on the stack.
10903 @cindex automatic arrays
10904 @cindex arrays, automatic
10905 However, if your program uses large automatic arrays
10906 (for example, has declarations like @samp{REAL A(N)} where
10907 @samp{A} is a local array and @samp{N} is a dummy or
10908 @code{COMMON} variable that can have a large value),
10909 neither use of @samp{-fno-automatic},
10910 nor changing the cut-off point for @code{g77} for using the stack,
10911 will solve the problem by changing the placement of these
10912 large arrays, as they are @emph{necessarily} automatic.
10914 @code{g77} currently provides no means to specify that
10915 automatic arrays are to be allocated on the heap instead
10916 of the stack.
10917 So, other than increasing the stack size, your best bet is to
10918 change your source code to avoid large automatic arrays.
10919 Methods for doing this currently are outside the scope of
10920 this document.
10922 (@emph{Note:} If your system puts stack and heap space in the
10923 same memory area, such that they are effectively combined, then
10924 a stack overflow probably indicates a program that is either
10925 simply too large for the system, or buggy.)
10927 @node Nothing Happens
10928 @subsection Nothing Happens
10929 @cindex nothing happens
10930 @cindex naming programs
10931 @cindex @code{test} programs
10932 @cindex programs, @code{test}
10933 It is occasionally reported that a ``simple'' program,
10934 such as a ``Hello, World!'' program, does nothing when
10935 it is run, even though the compiler reported no errors,
10936 despite the program containing nothing other than a
10937 simple @code{PRINT} statement.
10939 This most often happens because the program has been
10940 compiled and linked on a UNIX system and named @code{test},
10941 though other names can lead to similarly unexpected
10942 run-time behavior on various systems.
10944 Essentially this problem boils down to giving
10945 your program a name that is already known to
10946 the shell you are using to identify some other program,
10947 which the shell continues to execute instead of your
10948 program when you invoke it via, for example:
10950 @smallexample
10951 sh# @kbd{test}
10953 @end smallexample
10955 Under UNIX and many other system, a simple command name
10956 invokes a searching mechanism that might well not choose
10957 the program located in the current working directory if
10958 there is another alternative (such as the @code{test}
10959 command commonly installed on UNIX systems).
10961 The reliable way to invoke a program you just linked in
10962 the current directory under UNIX is to specify it using
10963 an explicit pathname, as in:
10965 @smallexample
10966 sh# @kbd{./test}
10967  Hello, World!
10969 @end smallexample
10971 Users who encounter this problem should take the time to
10972 read up on how their shell searches for commands, how to
10973 set their search path, and so on.
10974 The relevant UNIX commands to learn about include
10975 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
10976 @code{set} and @code{env}), @code{which}, and @code{find}.
10978 @node Strange Behavior at Run Time
10979 @subsection Strange Behavior at Run Time
10980 @cindex segmentation violation
10981 @cindex bus error
10982 @cindex overwritten data
10983 @cindex data, overwritten
10984 @code{g77} code might fail at runtime with ``segmentation violation'',
10985 ``bus error'', or even something as subtle as a procedure call
10986 overwriting a variable or array element that it is not supposed
10987 to touch.
10989 These can be symptoms of a wide variety of actual bugs that
10990 occurred earlier during the program's run, but manifested
10991 themselves as @emph{visible} problems some time later.
10993 Overflowing the bounds of an array---usually by writing beyond
10994 the end of it---is one of two kinds of bug that often occurs
10995 in Fortran code.
10996 (Compile your code with the @samp{-fbounds-check} option
10997 to catch many of these kinds of errors at program run time.)
10999 The other kind of bug is a mismatch between the actual arguments
11000 passed to a procedure and the dummy arguments as declared by that
11001 procedure.
11003 Both of these kinds of bugs, and some others as well, can be
11004 difficult to track down, because the bug can change its behavior,
11005 or even appear to not occur, when using a debugger.
11007 That is, these bugs can be quite sensitive to data, including
11008 data representing the placement of other data in memory (that is,
11009 pointers, such as the placement of stack frames in memory).
11011 @code{g77} now offers the
11012 ability to catch and report some of these problems at compile, link, or
11013 run time, such as by generating code to detect references to
11014 beyond the bounds of most arrays (except assumed-size arrays),
11015 and checking for agreement between calling and called procedures.
11016 Future improvements are likely to be made in the procedure-mismatch area,
11017 at least.
11019 In the meantime, finding and fixing the programming
11020 bugs that lead to these behaviors is, ultimately, the user's
11021 responsibility, as difficult as that task can sometimes be.
11023 @cindex infinite spaces printed
11024 @cindex space, endless printing of
11025 @cindex libc, non-ANSI or non-default
11026 @cindex C library
11027 @cindex linking against non-standard library
11028 @cindex Solaris
11029 One runtime problem that has been observed might have a simple solution.
11030 If a formatted @code{WRITE} produces an endless stream of spaces, check
11031 that your program is linked against the correct version of the C library.
11032 The configuration process takes care to account for your
11033 system's normal @file{libc} not being ANSI-standard, which will
11034 otherwise cause this behaviour.
11035 If your system's default library is
11036 ANSI-standard and you subsequently link against a non-ANSI one, there
11037 might be problems such as this one.
11039 Specifically, on Solaris2 systems,
11040 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
11042 @node Floating-point Errors
11043 @subsection Floating-point Errors
11044 @cindex floating-point errors
11045 @cindex rounding errors
11046 @cindex inconsistent floating-point results
11047 @cindex results, inconsistent
11048 Some programs appear to produce inconsistent floating-point
11049 results compiled by @code{g77} versus by other compilers.
11051 Often the reason for this behavior is the fact that floating-point
11052 values are represented on almost all Fortran systems by
11053 @emph{approximations}, and these approximations are inexact
11054 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
11055 0.7, 0.8, 0.9, 1.1, and so on.
11056 Most Fortran systems, including all current ports of @code{g77},
11057 use binary arithmetic to represent these approximations.
11059 Therefore, the exact value of any floating-point approximation
11060 as manipulated by @code{g77}-compiled code is representable by
11061 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
11062 so on (just keep dividing by two) through the precision of the
11063 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
11064 @code{REAL(KIND=2)}), then multiplying the sum by a integral
11065 power of two (in Fortran, by @samp{2**N}) that typically is between
11066 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
11067 @code{REAL(KIND=2)}, then multiplying by -1 if the number
11068 is negative.
11070 So, a value like 0.2 is exactly represented in decimal---since
11071 it is a fraction, @samp{2/10}, with a denominator that is compatible
11072 with the base of the number system (base 10).
11073 However, @samp{2/10} cannot be represented by any finite number
11074 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
11075 be exactly represented in binary notation.
11077 (On the other hand, decimal notation can represent any binary
11078 number in a finite number of digits.
11079 Decimal notation cannot do so with ternary, or base-3,
11080 notation, which would represent floating-point numbers as
11081 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
11082 After all, no finite number of decimal digits can exactly
11083 represent @samp{1/3}.
11084 Fortunately, few systems use ternary notation.)
11086 Moreover, differences in the way run-time I/O libraries convert
11087 between these approximations and the decimal representation often
11088 used by programmers and the programs they write can result in
11089 apparent differences between results that do not actually exist,
11090 or exist to such a small degree that they usually are not worth
11091 worrying about.
11093 For example, consider the following program:
11095 @smallexample
11096 PRINT *, 0.2
11098 @end smallexample
11100 When compiled by @code{g77}, the above program might output
11101 @samp{0.20000003}, while another compiler might produce a
11102 executable that outputs @samp{0.2}.
11104 This particular difference is due to the fact that, currently,
11105 conversion of floating-point values by the @code{libg2c} library,
11106 used by @code{g77}, handles only double-precision values.
11108 Since @samp{0.2} in the program is a single-precision value, it
11109 is converted to double precision (still in binary notation)
11110 before being converted back to decimal.
11111 The conversion to binary appends @emph{binary} zero digits to the
11112 original value---which, again, is an inexact approximation of
11113 0.2---resulting in an approximation that is much less exact
11114 than is connoted by the use of double precision.
11116 (The appending of binary zero digits has essentially the same
11117 effect as taking a particular decimal approximation of
11118 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
11119 zeros to it, producing @samp{0.33333330000000000}.
11120 Treating the resulting decimal approximation as if it really
11121 had 18 or so digits of valid precision would make it seem
11122 a very poor approximation of @samp{1/3}.)
11124 As a result of converting the single-precision approximation
11125 to double precision by appending binary zeros, the conversion
11126 of the resulting double-precision
11127 value to decimal produces what looks like an incorrect
11128 result, when in fact the result is @emph{inexact}, and
11129 is probably no less inaccurate or imprecise an approximation
11130 of 0.2 than is produced by other compilers that happen to output
11131 the converted value as ``exactly'' @samp{0.2}.
11132 (Some compilers behave in a way that can make them appear
11133 to retain more accuracy across a conversion of a single-precision
11134 constant to double precision.
11135 @xref{Context-Sensitive Constants}, to see why
11136 this practice is illusory and even dangerous.)
11138 Note that a more exact approximation of the constant is
11139 computed when the program is changed to specify a
11140 double-precision constant:
11142 @smallexample
11143 PRINT *, 0.2D0
11145 @end smallexample
11147 Future versions of @code{g77} and/or @code{libg2c} might convert
11148 single-precision values directly to decimal,
11149 instead of converting them to double precision first.
11150 This would tend to result in output that is more consistent
11151 with that produced by some other Fortran implementations.
11153 A useful source of information on floating-point computation is David
11154 Goldberg, `What Every Computer Scientist Should Know About
11155 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
11156 5-48.
11157 An online version is available at
11158 @uref{http://docs.sun.com/},
11159 and there is a supplemented version, in PostScript form, at
11160 @uref{http://www.validgh.com/goldberg/paper.ps}.
11162 Information related to the IEEE 754
11163 floating-point standard by a leading light can be found at
11164 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status/};
11165 see also slides from the short course referenced from
11166 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
11167 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
11168 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
11169 and library code for GNU/Linux x86 systems.
11171 The supplement to the PostScript-formatted Goldberg document,
11172 referenced above, is available in HTML format.
11173 See `Differences Among IEEE 754 Implementations' by Doug Priest,
11174 available online at
11175 @uref{http://www.validgh.com/goldberg/addendum.html}.
11176 This document explores some of the issues surrounding computing
11177 of extended (80-bit) results on processors such as the x86,
11178 especially when those results are arbitrarily truncated
11179 to 32-bit or 64-bit values by the compiler
11180 as ``spills''.
11182 @cindex spills of floating-point results
11183 @cindex 80-bit spills
11184 @cindex truncation, of floating-point values
11185 (@emph{Note:} @code{g77} specifically, and @code{gcc} generally,
11186 does arbitrarily truncate 80-bit results during spills
11187 as of this writing.
11188 It is not yet clear whether a future version of
11189 the GNU compiler suite will offer 80-bit spills
11190 as an option, or perhaps even as the default behavior.)
11192 @c xref would be different between editions:
11193 The GNU C library provides routines for controlling the FPU, and other
11194 documentation about this.
11196 @xref{Floating-point precision}, regarding IEEE 754 conformance.
11198 @include bugs.texi
11200 @node Missing Features
11201 @section Missing Features
11203 This section lists features we know are missing from @code{g77},
11204 and which we want to add someday.
11205 (There is no priority implied in the ordering below.)
11207 @menu
11208 GNU Fortran language:
11209 * Better Source Model::
11210 * Fortran 90 Support::
11211 * Intrinsics in PARAMETER Statements::
11212 * Arbitrary Concatenation::
11213 * SELECT CASE on CHARACTER Type::
11214 * RECURSIVE Keyword::
11215 * Popular Non-standard Types::
11216 * Full Support for Compiler Types::
11217 * Array Bounds Expressions::
11218 * POINTER Statements::
11219 * Sensible Non-standard Constructs::
11220 * READONLY Keyword::
11221 * FLUSH Statement::
11222 * Expressions in FORMAT Statements::
11223 * Explicit Assembler Code::
11224 * Q Edit Descriptor::
11226 GNU Fortran dialects:
11227 * Old-style PARAMETER Statements::
11228 * TYPE and ACCEPT I/O Statements::
11229 * STRUCTURE UNION RECORD MAP::
11230 * OPEN CLOSE and INQUIRE Keywords::
11231 * ENCODE and DECODE::
11232 * AUTOMATIC Statement::
11233 * Suppressing Space Padding::
11234 * Fortran Preprocessor::
11235 * Bit Operations on Floating-point Data::
11236 * Really Ugly Character Assignments::
11238 New facilities:
11239 * POSIX Standard::
11240 * Floating-point Exception Handling::
11241 * Nonportable Conversions::
11242 * Large Automatic Arrays::
11243 * Support for Threads::
11244 * Increasing Precision/Range::
11245 * Enabling Debug Lines::
11247 Better diagnostics:
11248 * Better Warnings::
11249 * Gracefully Handle Sensible Bad Code::
11250 * Non-standard Conversions::
11251 * Non-standard Intrinsics::
11252 * Modifying DO Variable::
11253 * Better Pedantic Compilation::
11254 * Warn About Implicit Conversions::
11255 * Invalid Use of Hollerith Constant::
11256 * Dummy Array Without Dimensioning Dummy::
11257 * Invalid FORMAT Specifiers::
11258 * Ambiguous Dialects::
11259 * Unused Labels::
11260 * Informational Messages::
11262 Run-time facilities:
11263 * Uninitialized Variables at Run Time::
11264 * Portable Unformatted Files::
11265 * Better List-directed I/O::
11266 * Default to Console I/O::
11268 Debugging:
11269 * Labels Visible to Debugger::
11270 @end menu
11272 @node Better Source Model
11273 @subsection Better Source Model
11275 @code{g77} needs to provide, as the default source-line model,
11276 a ``pure visual'' mode, where
11277 the interpretation of a source program in this mode can be accurately
11278 determined by a user looking at a traditionally displayed rendition
11279 of the program (assuming the user knows whether the program is fixed
11280 or free form).
11282 The design should assume the user cannot tell tabs from spaces
11283 and cannot see trailing spaces on lines, but has canonical tab stops
11284 and, for fixed-form source, has the ability to always know exactly
11285 where column 72 is (since the Fortran standard itself requires
11286 this for fixed-form source).
11288 This would change the default treatment of fixed-form source
11289 to not treat lines with tabs as if they were infinitely long---instead,
11290 they would end at column 72 just as if the tabs were replaced
11291 by spaces in the canonical way.
11293 As part of this, provide common alternate models (Digital, @code{f2c},
11294 and so on) via command-line options.
11295 This includes allowing arbitrarily long
11296 lines for free-form source as well as fixed-form source and providing
11297 various limits and diagnostics as appropriate.
11299 @cindex sequence numbers
11300 @cindex columns 73 through 80
11301 Also, @code{g77} should offer, perhaps even default to, warnings
11302 when characters beyond the last valid column are anything other
11303 than spaces.
11304 This would mean code with ``sequence numbers'' in columns 73 through 80
11305 would be rejected, and there's a lot of that kind of code around,
11306 but one of the most frequent bugs encountered by new users is
11307 accidentally writing fixed-form source code into and beyond
11308 column 73.
11309 So, maybe the users of old code would be able to more easily handle
11310 having to specify, say, a @samp{-Wno-col73to80} option.
11312 @node Fortran 90 Support
11313 @subsection Fortran 90 Support
11314 @cindex Fortran 90, support
11315 @cindex support, Fortran 90
11317 @code{g77} does not support many of the features that
11318 distinguish Fortran 90 (and, now, Fortran 95) from
11319 ANSI FORTRAN 77.
11321 Some Fortran 90 features are supported, because they
11322 make sense to offer even to die-hard users of F77.
11323 For example, many of them codify various ways F77 has
11324 been extended to meet users' needs during its tenure,
11325 so @code{g77} might as well offer them as the primary
11326 way to meet those same needs, even if it offers compatibility
11327 with one or more of the ways those needs were met
11328 by other F77 compilers in the industry.
11330 Still, many important F90 features are not supported,
11331 because no attempt has been made to research each and
11332 every feature and assess its viability in @code{g77}.
11333 In the meantime, users who need those features must
11334 use Fortran 90 compilers anyway, and the best approach
11335 to adding some F90 features to GNU Fortran might well be
11336 to fund a comprehensive project to create GNU Fortran 95.
11338 @node Intrinsics in PARAMETER Statements
11339 @subsection Intrinsics in @code{PARAMETER} Statements
11340 @cindex PARAMETER statement
11341 @cindex statements, PARAMETER
11343 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
11344 This feature is considered to be absolutely vital, even though it
11345 is not standard-conforming, and is scheduled for version 0.6.
11347 Related to this, @code{g77} doesn't allow non-integral
11348 exponentiation in @code{PARAMETER} statements, such as
11349 @samp{PARAMETER (R=2**.25)}.
11350 It is unlikely @code{g77} will ever support this feature,
11351 as doing it properly requires complete emulation of
11352 a target computer's floating-point facilities when
11353 building @code{g77} as a cross-compiler.
11354 But, if the @code{gcc} back end is enhanced to provide
11355 such a facility, @code{g77} will likely use that facility
11356 in implementing this feature soon afterwards.
11358 @node Arbitrary Concatenation
11359 @subsection Arbitrary Concatenation
11360 @cindex concatenation
11361 @cindex CHARACTER*(*)
11362 @cindex run-time, dynamic allocation
11364 @code{g77} doesn't support arbitrary operands for concatenation
11365 in contexts where run-time allocation is required.
11366 For example:
11368 @smallexample
11369 SUBROUTINE X(A)
11370 CHARACTER*(*) A
11371 CALL FOO(A // 'suffix')
11372 @end smallexample
11374 @node SELECT CASE on CHARACTER Type
11375 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
11377 Character-type selector/cases for @code{SELECT CASE} currently
11378 are not supported.
11380 @node RECURSIVE Keyword
11381 @subsection @code{RECURSIVE} Keyword
11382 @cindex RECURSIVE keyword
11383 @cindex keywords, RECURSIVE
11384 @cindex recursion, lack of
11385 @cindex lack of recursion
11387 @code{g77} doesn't support the @code{RECURSIVE} keyword that
11388 F90 compilers do.
11389 Nor does it provide any means for compiling procedures
11390 designed to do recursion.
11392 All recursive code can be rewritten to not use recursion,
11393 but the result is not pretty.
11395 @node Increasing Precision/Range
11396 @subsection Increasing Precision/Range
11397 @cindex -r8
11398 @cindex -qrealsize=8
11399 @cindex -i8
11400 @cindex f2c
11401 @cindex increasing precision
11402 @cindex precision, increasing
11403 @cindex increasing range
11404 @cindex range, increasing
11405 @cindex Toolpack
11406 @cindex Netlib
11408 Some compilers, such as @code{f2c}, have an option (@samp{-r8},
11409 @samp{-qrealsize=8} or
11410 similar) that provides automatic treatment of @code{REAL}
11411 entities such that they have twice the storage size, and
11412 a corresponding increase in the range and precision, of what
11413 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
11414 (This affects @code{COMPLEX} the same way.)
11416 They also typically offer another option (@samp{-i8}) to increase
11417 @code{INTEGER} entities so they are twice as large
11418 (with roughly twice as much range).
11420 (There are potential pitfalls in using these options.)
11422 @code{g77} does not yet offer any option that performs these
11423 kinds of transformations.
11424 Part of the problem is the lack of detailed specifications regarding
11425 exactly how these options affect the interpretation of constants,
11426 intrinsics, and so on.
11428 Until @code{g77} addresses this need, programmers could improve
11429 the portability of their code by modifying it to not require
11430 compile-time options to produce correct results.
11431 Some free tools are available which may help, specifically
11432 in Toolpack (which one would expect to be sound) and the @file{fortran}
11433 section of the Netlib repository.
11435 Use of preprocessors can provide a fairly portable means
11436 to work around the lack of widely portable methods in the Fortran
11437 language itself (though increasing acceptance of Fortran 90 would
11438 alleviate this problem).
11440 @node Popular Non-standard Types
11441 @subsection Popular Non-standard Types
11442 @cindex @code{INTEGER*2} support
11443 @cindex types, @code{INTEGER*2}
11444 @cindex @code{LOGICAL*1} support
11445 @cindex types, @code{LOGICAL*1}
11447 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
11448 and similar.
11449 Version 0.6 will provide full support for this very
11450 popular set of features.
11451 In the meantime, version 0.5.18 provides rudimentary support
11452 for them.
11454 @node Full Support for Compiler Types
11455 @subsection Full Support for Compiler Types
11457 @cindex @code{REAL*16} support
11458 @cindex types, @code{REAL*16}
11459 @cindex @code{INTEGER*8} support
11460 @cindex types, @code{INTEGER*8}
11461 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
11462 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
11463 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
11464 This means providing intrinsic support, and maybe constant
11465 support (using F90 syntax) as well, and, for most
11466 machines will result in automatic support of @code{INTEGER*1},
11467 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
11468 and so on.
11469 This is scheduled for version 0.6.
11471 @node Array Bounds Expressions
11472 @subsection Array Bounds Expressions
11473 @cindex array elements, in adjustable array bounds
11474 @cindex function references, in adjustable array bounds
11475 @cindex array bounds, adjustable
11476 @cindex @code{DIMENSION} statement
11477 @cindex statements, @code{DIMENSION}
11479 @code{g77} doesn't support more general expressions to dimension
11480 arrays, such as array element references, function
11481 references, etc.
11483 For example, @code{g77} currently does not accept the following:
11485 @smallexample
11486 SUBROUTINE X(M, N)
11487 INTEGER N(10), M(N(2), N(1))
11488 @end smallexample
11490 @node POINTER Statements
11491 @subsection POINTER Statements
11492 @cindex POINTER statement
11493 @cindex statements, POINTER
11494 @cindex Cray pointers
11496 @code{g77} doesn't support pointers or allocatable objects
11497 (other than automatic arrays).
11498 This set of features is
11499 probably considered just behind intrinsics
11500 in @code{PARAMETER} statements on the list of large,
11501 important things to add to @code{g77}.
11503 In the meantime, consider using the @code{INTEGER(KIND=7)}
11504 declaration to specify that a variable must be
11505 able to hold a pointer.
11506 This construct is not portable to other non-GNU compilers,
11507 but it is portable to all machines GNU Fortran supports
11508 when @code{g77} is used.
11510 @xref{Functions and Subroutines}, for information on
11511 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
11512 constructs, which are useful for passing pointers to
11513 procedures written in languages other than Fortran.
11515 @node Sensible Non-standard Constructs
11516 @subsection Sensible Non-standard Constructs
11518 @code{g77} rejects things other compilers accept,
11519 like @samp{INTRINSIC SQRT,SQRT}.
11520 As time permits in the future, some of these things that are easy for
11521 humans to read and write and unlikely to be intended to mean something
11522 else will be accepted by @code{g77} (though @samp{-fpedantic} should
11523 trigger warnings about such non-standard constructs).
11525 Until @code{g77} no longer gratuitously rejects sensible code,
11526 you might as well fix your code
11527 to be more standard-conforming and portable.
11529 The kind of case that is important to except from the
11530 recommendation to change your code is one where following
11531 good coding rules would force you to write non-standard
11532 code that nevertheless has a clear meaning.
11534 For example, when writing an @code{INCLUDE} file that
11535 defines a common block, it might be appropriate to
11536 include a @code{SAVE} statement for the common block
11537 (such as @samp{SAVE /CBLOCK/}), so that variables
11538 defined in the common block retain their values even
11539 when all procedures declaring the common block become
11540 inactive (return to their callers).
11542 However, putting @code{SAVE} statements in an @code{INCLUDE}
11543 file would prevent otherwise standard-conforming code
11544 from also specifying the @code{SAVE} statement, by itself,
11545 to indicate that all local variables and arrays are to
11546 have the @code{SAVE} attribute.
11548 For this reason, @code{g77} already has been changed to
11549 allow this combination, because although the general
11550 problem of gratuitously rejecting unambiguous and
11551 ``safe'' constructs still exists in @code{g77}, this
11552 particular construct was deemed useful enough that
11553 it was worth fixing @code{g77} for just this case.
11555 So, while there is no need to change your code
11556 to avoid using this particular construct, there
11557 might be other, equally appropriate but non-standard
11558 constructs, that you shouldn't have to stop using
11559 just because @code{g77} (or any other compiler)
11560 gratuitously rejects it.
11562 Until the general problem is solved, if you have
11563 any such construct you believe is worthwhile
11564 using (e.g. not just an arbitrary, redundant
11565 specification of an attribute), please submit a
11566 bug report with an explanation, so we can consider
11567 fixing @code{g77} just for cases like yours.
11569 @node READONLY Keyword
11570 @subsection @code{READONLY} Keyword
11571 @cindex READONLY
11573 Support for @code{READONLY}, in @code{OPEN} statements,
11574 requires @code{libg2c} support,
11575 to make sure that @samp{CLOSE(@dots{},STATUS='DELETE')}
11576 does not delete a file opened on a unit
11577 with the @code{READONLY} keyword,
11578 and perhaps to trigger a fatal diagnostic
11579 if a @code{WRITE} or @code{PRINT}
11580 to such a unit is attempted.
11582 @emph{Note:} It is not sufficient for @code{g77} and @code{libg2c}
11583 (its version of @code{libf2c})
11584 to assume that @code{READONLY} does not need some kind of explicit support
11585 at run time,
11586 due to UNIX systems not (generally) needing it.
11587 @code{g77} is not just a UNIX-based compiler!
11589 Further, mounting of non-UNIX filesystems on UNIX systems
11590 (such as via NFS)
11591 might require proper @code{READONLY} support.
11593 @cindex SHARED
11594 (Similar issues might be involved with supporting the @code{SHARED}
11595 keyword.)
11597 @node FLUSH Statement
11598 @subsection @code{FLUSH} Statement
11600 @code{g77} could perhaps use a @code{FLUSH} statement that
11601 does what @samp{CALL FLUSH} does,
11602 but that supports @samp{*} as the unit designator (same unit as for
11603 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
11604 specifiers.
11606 @node Expressions in FORMAT Statements
11607 @subsection Expressions in @code{FORMAT} Statements
11608 @cindex FORMAT statement
11609 @cindex statements, FORMAT
11611 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
11612 Supporting this requires a significant redesign or replacement
11613 of @code{libg2c}.
11615 However, @code{g77} does support
11616 this construct when the expression is constant
11617 (as of version 0.5.22).
11618 For example:
11620 @smallexample
11621       PARAMETER (IWIDTH = 12)
11622 10    FORMAT (I<IWIDTH>)
11623 @end smallexample
11625 Otherwise, at least for output (@code{PRINT} and
11626 @code{WRITE}), Fortran code making use of this feature can
11627 be rewritten to avoid it by constructing the @code{FORMAT}
11628 string in a @code{CHARACTER} variable or array, then
11629 using that variable or array in place of the @code{FORMAT}
11630 statement label to do the original @code{PRINT} or @code{WRITE}.
11632 Many uses of this feature on input can be rewritten this way
11633 as well, but not all can.
11634 For example, this can be rewritten:
11636 @smallexample
11637       READ 20, I
11638 20    FORMAT (I<J>)
11639 @end smallexample
11641 However, this cannot, in general, be rewritten, especially
11642 when @code{ERR=} and @code{END=} constructs are employed:
11644 @smallexample
11645       READ 30, J, I
11646 30    FORMAT (I<J>)
11647 @end smallexample
11649 @node Explicit Assembler Code
11650 @subsection Explicit Assembler Code
11652 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
11653 code to specify explicit assembler code.
11655 @node Q Edit Descriptor
11656 @subsection Q Edit Descriptor
11657 @cindex FORMAT statement
11658 @cindex Q edit descriptor
11659 @cindex edit descriptor, Q
11661 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
11662 (This is meant to get the number of characters remaining in an input record.)
11663 Supporting this requires a significant redesign or replacement
11664 of @code{libg2c}.
11666 A workaround might be using internal I/O or the stream-based intrinsics.
11667 @xref{FGetC Intrinsic (subroutine)}.
11669 @node Old-style PARAMETER Statements
11670 @subsection Old-style PARAMETER Statements
11671 @cindex PARAMETER statement
11672 @cindex statements, PARAMETER
11674 @code{g77} doesn't accept @samp{PARAMETER I=1}.
11675 Supporting this obsolete form of
11676 the @code{PARAMETER} statement would not be particularly hard, as most of the
11677 parsing code is already in place and working.
11679 Until time/money is
11680 spent implementing it, you might as well fix your code to use the
11681 standard form, @samp{PARAMETER (I=1)} (possibly needing
11682 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
11683 otherwise, in the obsolete form of @code{PARAMETER}, the
11684 type of the variable is set from the type of the constant being
11685 assigned to it).
11687 @node TYPE and ACCEPT I/O Statements
11688 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
11689 @cindex TYPE statement
11690 @cindex statements, TYPE
11691 @cindex ACCEPT statement
11692 @cindex statements, ACCEPT
11694 @code{g77} doesn't support the I/O statements @code{TYPE} and
11695 @code{ACCEPT}.
11696 These are common extensions that should be easy to support,
11697 but also are fairly easy to work around in user code.
11699 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
11700 by @samp{PRINT fmt,list}.
11701 And, any @samp{ACCEPT fmt,list} statement can be
11702 replaced by @samp{READ fmt,list}.
11704 @node STRUCTURE UNION RECORD MAP
11705 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
11706 @cindex STRUCTURE statement
11707 @cindex statements, STRUCTURE
11708 @cindex UNION statement
11709 @cindex statements, UNION
11710 @cindex RECORD statement
11711 @cindex statements, RECORD
11712 @cindex MAP statement
11713 @cindex statements, MAP
11715 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
11716 @code{MAP}.
11717 This set of extensions is quite a bit
11718 lower on the list of large, important things to add to @code{g77}, partly
11719 because it requires a great deal of work either upgrading or
11720 replacing @code{libg2c}.
11722 @node OPEN CLOSE and INQUIRE Keywords
11723 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
11724 @cindex disposition of files
11725 @cindex OPEN statement
11726 @cindex statements, OPEN
11727 @cindex CLOSE statement
11728 @cindex statements, CLOSE
11729 @cindex INQUIRE statement
11730 @cindex statements, INQUIRE
11732 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
11733 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
11734 These extensions are easy to add to @code{g77} itself, but
11735 require much more work on @code{libg2c}.
11737 @cindex FORM='PRINT'
11738 @cindex ANS carriage control
11739 @cindex carriage control
11740 @pindex asa
11741 @pindex fpr
11742 @code{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
11743 translate the traditional `carriage control' characters in column 1 of
11744 output to use backspaces, carriage returns and the like.  However
11745 programs exist to translate them in output files (or standard output).
11746 These are typically called either @code{fpr} or @code{asa}.  You can get
11747 a version of @code{asa} from
11748 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
11749 systems which will probably build easily on other systems.
11750 Alternatively, @code{fpr} is in BSD distributions in various archive
11751 sites.
11753 @c (Can both programs can be used in a pipeline,
11754 @c with a named input file,
11755 @c and/or with a named output file???)
11757 @node ENCODE and DECODE
11758 @subsection @code{ENCODE} and @code{DECODE}
11759 @cindex ENCODE statement
11760 @cindex statements, ENCODE
11761 @cindex DECODE statement
11762 @cindex statements, DECODE
11764 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
11766 These statements are best replaced by READ and WRITE statements
11767 involving internal files (CHARACTER variables and arrays).
11769 For example, replace a code fragment like
11771 @smallexample
11772       INTEGER*1 LINE(80)
11773 @dots{}
11774       DECODE (80, 9000, LINE) A, B, C
11775 @dots{}
11776 9000  FORMAT (1X, 3(F10.5))
11777 @end smallexample
11779 @noindent
11780 with:
11782 @smallexample
11783       CHARACTER*80 LINE
11784 @dots{}
11785       READ (UNIT=LINE, FMT=9000) A, B, C
11786 @dots{}
11787 9000  FORMAT (1X, 3(F10.5))
11788 @end smallexample
11790 Similarly, replace a code fragment like
11792 @smallexample
11793       INTEGER*1 LINE(80)
11794 @dots{}
11795       ENCODE (80, 9000, LINE) A, B, C
11796 @dots{}
11797 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11798 @end smallexample
11800 @noindent
11801 with:
11803 @smallexample
11804       CHARACTER*80 LINE
11805 @dots{}
11806       WRITE (UNIT=LINE, FMT=9000) A, B, C
11807 @dots{}
11808 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11809 @end smallexample
11811 It is entirely possible that @code{ENCODE} and @code{DECODE} will
11812 be supported by a future version of @code{g77}.
11814 @node AUTOMATIC Statement
11815 @subsection @code{AUTOMATIC} Statement
11816 @cindex @code{AUTOMATIC} statement
11817 @cindex statements, @code{AUTOMATIC}
11818 @cindex automatic variables
11819 @cindex variables, automatic
11821 @code{g77} doesn't support the @code{AUTOMATIC} statement that
11822 @code{f2c} does.
11824 @code{AUTOMATIC} would identify a variable or array
11825 as not being @code{SAVE}'d, which is normally the default,
11826 but which would be especially useful for code that, @emph{generally},
11827 needed to be compiled with the @samp{-fno-automatic} option.
11829 @code{AUTOMATIC} also would serve as a hint to the compiler that placing
11830 the variable or array---even a very large array--on the stack is acceptable.
11832 @code{AUTOMATIC} would not, by itself, designate the containing procedure
11833 as recursive.
11835 @code{AUTOMATIC} should work syntactically like @code{SAVE},
11836 in that @code{AUTOMATIC} with no variables listed should apply to
11837 all pertinent variables and arrays
11838 (which would not include common blocks or their members).
11840 Variables and arrays denoted as @code{AUTOMATIC}
11841 would not be permitted to be initialized via @code{DATA}
11842 or other specification of any initial values,
11843 requiring explicit initialization,
11844 such as via assignment statements.
11846 @cindex UNSAVE
11847 @cindex STATIC
11848 Perhaps @code{UNSAVE} and @code{STATIC},
11849 as strict semantic opposites to @code{SAVE} and @code{AUTOMATIC},
11850 should be provided as well.
11852 @node Suppressing Space Padding
11853 @subsection Suppressing Space Padding of Source Lines
11855 @code{g77} should offer VXT-Fortran-style suppression of virtual
11856 spaces at the end of a source line
11857 if an appropriate command-line option is specified.
11859 This affects cases where
11860 a character constant is continued onto the next line in a fixed-form
11861 source file, as in the following example:
11863 @smallexample
11864 10    PRINT *,'HOW MANY
11865      1 SPACES?'
11866 @end smallexample
11868 @noindent
11869 @code{g77}, and many other compilers, virtually extend
11870 the continued line through column 72 with spaces that become part
11871 of the character constant, but Digital Fortran normally didn't,
11872 leaving only one space between @samp{MANY} and @samp{SPACES?}
11873 in the output of the above statement.
11875 Fairly recently, at least one version of Digital Fortran
11876 was enhanced to provide the other behavior when a
11877 command-line option is specified, apparently due to demand
11878 from readers of the USENET group @file{comp.lang.fortran}
11879 to offer conformance to this widespread practice in the
11880 industry.
11881 @code{g77} should return the favor by offering conformance
11882 to Digital's approach to handling the above example.
11884 @node Fortran Preprocessor
11885 @subsection Fortran Preprocessor
11887 @code{g77} should offer a preprocessor designed specifically
11888 for Fortran to replace @samp{cpp -traditional}.
11889 There are several out there worth evaluating, at least.
11891 Such a preprocessor would recognize Hollerith constants,
11892 properly parse comments and character constants, and so on.
11893 It might also recognize, process, and thus preprocess
11894 files included via the @code{INCLUDE} directive.
11896 @node Bit Operations on Floating-point Data
11897 @subsection Bit Operations on Floating-point Data
11898 @cindex @code{And} intrinsic
11899 @cindex intrinsics, @code{And}
11900 @cindex @code{Or} intrinsic
11901 @cindex intrinsics, @code{Or}
11902 @cindex @code{Shift} intrinsic
11903 @cindex intrinsics, @code{Shift}
11905 @code{g77} does not allow @code{REAL} and other non-integral types for
11906 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
11908 For example, this program is rejected by @code{g77}, because
11909 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
11911 @smallexample
11912 DATA A/7.54/, B/9.112/
11913 PRINT *, IAND(A, B)
11915 @end smallexample
11917 @node Really Ugly Character Assignments
11918 @subsection Really Ugly Character Assignments
11920 An option such as @samp{-fugly-char} should be provided
11921 to allow
11923 @smallexample
11924 REAL*8 A1
11925 DATA A1 / '12345678' /
11926 @end smallexample
11928 and:
11930 @smallexample
11931 REAL*8 A1
11932 A1 = 'ABCDEFGH'
11933 @end smallexample
11935 @node POSIX Standard
11936 @subsection @code{POSIX} Standard
11938 @code{g77} should support the POSIX standard for Fortran.
11940 @node Floating-point Exception Handling
11941 @subsection Floating-point Exception Handling
11942 @cindex floating-point, exceptions
11943 @cindex exceptions, floating-point
11944 @cindex FPE handling
11945 @cindex NaN values
11947 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
11948 general control over whether or not floating-point exceptions are trapped or
11949 ignored.
11950 (Ignoring them typically results in NaN values being
11951 propagated in systems that conform to IEEE 754.)
11952 The behaviour is normally inherited from the system-dependent startup
11953 code, though some targets, such as the Alpha, have code generation
11954 options which change the behaviour.
11956 Most systems provide some C-callable mechanism to change this; this can
11957 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
11958 For example, just compiling and linking the following C code with your
11959 program will turn on exception trapping for the ``common'' exceptions
11960 on a GNU system using glibc 2.2 or newer:
11962 @smallexample
11963 #define _GNU_SOURCE 1
11964 #include <fenv.h>
11965 static void __attribute__ ((constructor))
11966 trapfpe ()
11968   /* Enable some exceptions.  At startup all exceptions are masked.  */
11969   
11970   feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
11972 @end smallexample
11974 A convenient trick is to compile this something like:
11975 @smallexample
11976 gcc -o libtrapfpe.a trapfpe.c
11977 @end smallexample
11978 and then use it by adding @samp{-trapfpe} to the @code{g77} command line
11979 when linking.
11981 @node Nonportable Conversions
11982 @subsection Nonportable Conversions
11983 @cindex nonportable conversions
11984 @cindex conversions, nonportable
11986 @code{g77} doesn't accept some particularly nonportable,
11987 silent data-type conversions such as @code{LOGICAL}
11988 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
11989 is type @code{REAL}), that other compilers might
11990 quietly accept.
11992 Some of these conversions are accepted by @code{g77}
11993 when the @samp{-fugly-logint} option is specified.
11994 Perhaps it should accept more or all of them.
11996 @node Large Automatic Arrays
11997 @subsection Large Automatic Arrays
11998 @cindex automatic arrays
11999 @cindex arrays, automatic
12001 Currently, automatic arrays always are allocated on the stack.
12002 For situations where the stack cannot be made large enough,
12003 @code{g77} should offer a compiler option that specifies
12004 allocation of automatic arrays in heap storage.
12006 @node Support for Threads
12007 @subsection Support for Threads
12008 @cindex threads
12009 @cindex parallel processing
12011 Neither the code produced by @code{g77} nor the @code{libg2c} library
12012 are thread-safe, nor does @code{g77} have support for parallel processing
12013 (other than the instruction-level parallelism available on some
12014 processors).
12015 A package such as PVM might help here.
12017 @node Enabling Debug Lines
12018 @subsection Enabling Debug Lines
12019 @cindex debug line
12020 @cindex comment line, debug
12022 An option such as @samp{-fdebug-lines} should be provided
12023 to turn fixed-form lines beginning with @samp{D}
12024 to be treated as if they began with a space,
12025 instead of as if they began with a @samp{C}
12026 (as comment lines).
12028 @node Better Warnings
12029 @subsection Better Warnings
12031 Because of how @code{g77} generates code via the back end,
12032 it doesn't always provide warnings the user wants.
12033 Consider:
12035 @smallexample
12036 PROGRAM X
12037 PRINT *, A
12039 @end smallexample
12041 Currently, the above is not flagged as a case of
12042 using an uninitialized variable,
12043 because @code{g77} generates a run-time library call that looks,
12044 to the GBE, like it might actually @emph{modify} @samp{A} at run time.
12045 (And, in fact, depending on the previous run-time library call,
12046 it would!)
12048 Fixing this requires one of the following:
12050 @itemize @bullet
12051 @item
12052 Switch to new library, @code{libg77}, that provides
12053 a more ``clean'' interface,
12054 vis-a-vis input, output, and modified arguments,
12055 so the GBE can tell what's going on.
12057 This would provide a pretty big performance improvement,
12058 at least theoretically, and, ultimately, in practice,
12059 for some types of code.
12061 @item
12062 Have @code{g77} pass a pointer to a temporary
12063 containing a copy of @samp{A},
12064 instead of to @samp{A} itself.
12065 The GBE would then complain about the copy operation
12066 involving a potentially uninitialized variable.
12068 This might also provide a performance boost for some code,
12069 because @samp{A} might then end up living in a register,
12070 which could help with inner loops.
12072 @item
12073 Have @code{g77} use a GBE construct similar to @code{ADDR_EXPR}
12074 but with extra information on the fact that the
12075 item pointed to won't be modified
12076 (a la @code{const} in C).
12078 Probably the best solution for now, but not quite trivial
12079 to implement in the general case.
12080 Worth considering after @code{g77} 0.6 is considered
12081 pretty solid.
12082 @end itemize
12084 @node Gracefully Handle Sensible Bad Code
12085 @subsection Gracefully Handle Sensible Bad Code
12087 @code{g77} generally should continue processing for
12088 warnings and recoverable (user) errors whenever possible---that
12089 is, it shouldn't gratuitously make bad or useless code.
12091 For example:
12093 @smallexample
12094 INTRINSIC ZABS
12095 CALL FOO(ZABS)
12097 @end smallexample
12099 @noindent
12100 When compiling the above with @samp{-ff2c-intrinsics-disable},
12101 @code{g77} should indeed complain about passing @code{ZABS},
12102 but it still should compile, instead of rejecting
12103 the entire @code{CALL} statement.
12104 (Some of this is related to improving
12105 the compiler internals to improve how statements are analyzed.)
12107 @node Non-standard Conversions
12108 @subsection Non-standard Conversions
12110 @samp{-Wconversion} and related should flag places where non-standard
12111 conversions are found.
12112 Perhaps much of this would be part of @samp{-Wugly*}.
12114 @node Non-standard Intrinsics
12115 @subsection Non-standard Intrinsics
12117 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
12118 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
12119 This would help find code that might fail silently when ported to another
12120 compiler.
12122 @node Modifying DO Variable
12123 @subsection Modifying @code{DO} Variable
12125 @code{g77} should warn about modifying @code{DO} variables
12126 via @code{EQUIVALENCE}.
12127 (The internal information gathered to produce this warning
12128 might also be useful in setting the
12129 internal ``doiter'' flag for a variable or even array
12130 reference within a loop, since that might produce faster code someday.)
12132 For example, this code is invalid, so @code{g77} should warn about
12133 the invalid assignment to @samp{NOTHER}:
12135 @smallexample
12136 EQUIVALENCE (I, NOTHER)
12137 DO I = 1, 100
12138    IF (I.EQ. 10) NOTHER = 20
12139 END DO
12140 @end smallexample
12142 @node Better Pedantic Compilation
12143 @subsection Better Pedantic Compilation
12145 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
12146 and use it only to generate
12147 warnings instead of rejecting constructs outright.
12148 Have it warn:
12149 if a variable that dimensions an array is not a dummy or placed
12150 explicitly in @code{COMMON} (F77 does not allow it to be
12151 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
12152 follow statement-function-definition statements; about all sorts of
12153 syntactic extensions.
12155 @node Warn About Implicit Conversions
12156 @subsection Warn About Implicit Conversions
12158 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
12159 to expect automatic, silent, and
12160 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
12161 constants to @code{REAL(KIND=2)} based on context.
12163 For example, it would warn about cases like this:
12165 @smallexample
12166 DOUBLE PRECISION FOO
12167 PARAMETER (TZPHI = 9.435784839284958)
12168 FOO = TZPHI * 3D0
12169 @end smallexample
12171 @node Invalid Use of Hollerith Constant
12172 @subsection Invalid Use of Hollerith Constant
12174 @code{g77} should disallow statements like @samp{RETURN 2HAB},
12175 which are invalid in both source forms
12176 (unlike @samp{RETURN (2HAB)},
12177 which probably still makes no sense but at least can
12178 be reliably parsed).
12179 Fixed-form processing rejects it, but not free-form, except
12180 in a way that is a bit difficult to understand.
12182 @node Dummy Array Without Dimensioning Dummy
12183 @subsection Dummy Array Without Dimensioning Dummy
12185 @code{g77} should complain when a list of dummy arguments containing an
12186 adjustable dummy array does
12187 not also contain every variable listed in the dimension list of the
12188 adjustable array.
12190 Currently, @code{g77} does complain about a variable that
12191 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
12192 area, but this needs to be extended to catch cases where it doesn't appear in
12193 every dummy list that also lists any arrays it dimensions.
12195 For example, @code{g77} should warn about the entry point @samp{ALT}
12196 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
12197 list of arguments:
12199 @smallexample
12200 SUBROUTINE PRIMARY(ARRAY, ISIZE)
12201 REAL ARRAY(ISIZE)
12202 ENTRY ALT(ARRAY)
12203 @end smallexample
12205 @node Invalid FORMAT Specifiers
12206 @subsection Invalid FORMAT Specifiers
12208 @code{g77} should check @code{FORMAT} specifiers for validity
12209 as it does @code{FORMAT} statements.
12211 For example, a diagnostic would be produced for:
12213 @smallexample
12214 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
12215 @end smallexample
12217 @node Ambiguous Dialects
12218 @subsection Ambiguous Dialects
12220 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
12221 @samp{-Wvxt}, @samp{-Wf90}, and so on.
12222 These would warn about places in the user's source where ambiguities
12223 are found, helpful in resolving ambiguities in the program's
12224 dialect or dialects.
12226 @node Unused Labels
12227 @subsection Unused Labels
12229 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
12231 @node Informational Messages
12232 @subsection Informational Messages
12234 @code{g77} needs an option to suppress information messages (notes).
12235 @samp{-w} does this but also suppresses warnings.
12236 The default should be to suppress info messages.
12238 Perhaps info messages should simply be eliminated.
12240 @node Uninitialized Variables at Run Time
12241 @subsection Uninitialized Variables at Run Time
12243 @code{g77} needs an option to initialize everything (not otherwise
12244 explicitly initialized) to ``weird''
12245 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
12246 largest-magnitude integers, would help track down references to
12247 some kinds of uninitialized variables at run time.
12249 Note that use of the options @samp{-O -Wuninitialized} can catch
12250 many such bugs at compile time.
12252 @node Portable Unformatted Files
12253 @subsection Portable Unformatted Files
12255 @cindex unformatted files
12256 @cindex file formats
12257 @cindex binary data
12258 @cindex byte ordering
12259 @code{g77} has no facility for exchanging unformatted files with systems
12260 using different number formats---even differing only in endianness (byte
12261 order)---or written by other compilers.  Some compilers provide
12262 facilities at least for doing byte-swapping during unformatted I/O.
12264 It is unrealistic to expect to cope with exchanging unformatted files
12265 with arbitrary other compiler runtimes, but the @code{g77} runtime
12266 should at least be able to read files written by @code{g77} on systems
12267 with different number formats, particularly if they differ only in byte
12268 order.
12270 In case you do need to write a program to translate to or from
12271 @code{g77} (@code{libf2c}) unformatted files, they are written as
12272 follows:
12273 @table @asis
12274 @item Sequential
12275 Unformatted sequential records consist of
12276 @enumerate
12277 @item
12278 A number giving the length of the record contents;
12279 @item
12280 the length of record contents again (for backspace).
12281 @end enumerate
12283 The record length is of C type
12284 @code{long}; this means that it is 8 bytes on 64-bit systems such as
12285 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
12286 Consequently such files cannot be exchanged between 64-bit and 32-bit
12287 systems, even with the same basic number format.
12288 @item Direct access
12289 Unformatted direct access files form a byte stream of length
12290 @var{records}*@var{recl} bytes, where @var{records} is the maximum
12291 record number (@code{REC=@var{records}}) written and @var{recl} is the
12292 record length in bytes specified in the @code{OPEN} statement
12293 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
12294 the relevant @code{WRITE} statement.  Dummy records with arbitrary
12295 contents appear in the file in place of records which haven't been
12296 written.
12297 @end table
12299 Thus for exchanging a sequential or direct access unformatted file
12300 between big- and little-endian 32-bit systems using IEEE 754 floating
12301 point it would be sufficient to reverse the bytes in consecutive words
12302 in the file if, and @emph{only} if, only @code{REAL*4}, @code{COMPLEX},
12303 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
12304 @code{g77}.
12306 If necessary, it is possible to do byte-oriented i/o with @code{g77}'s
12307 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
12308 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
12309 array or a set of scalars.
12311 @cindex HDF
12312 @cindex PDB
12313 If you need to exchange binary data between arbitrary system and
12314 compiler variations, we recommend using a portable binary format with
12315 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
12316 or PACT's PDB@footnote{No, not @emph{that} one.}
12317 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
12318 say, CDF or XDR, HDF-like systems write in the native number formats and
12319 only incur overhead when they are read on a system with a different
12320 format.)  A future @code{g77} runtime library should use such
12321 techniques.
12323 @node Better List-directed I/O
12324 @subsection Better List-directed I/O
12326 Values output using list-directed I/O
12327 (@samp{PRINT *, R, D})
12328 should be written with a field width, precision, and so on
12329 appropriate for the type (precision) of each value.
12331 (Currently, no distinction is made between single-precision
12332 and double-precision values
12333 by @code{libf2c}.)
12335 It is likely this item will require the @code{libg77} project
12336 to be undertaken.
12338 In the meantime, use of formatted I/O is recommended.
12339 While it might be of little consolation,
12340 @code{g77} does support @samp{FORMAT(F<WIDTH>.4)}, for example,
12341 as long as @samp{WIDTH} is defined as a named constant
12342 (via @code{PARAMETER}).
12343 That at least allows some compile-time specification
12344 of the precision of a data type,
12345 perhaps controlled by preprocessing directives.
12347 @node Default to Console I/O
12348 @subsection Default to Console I/O
12350 The default I/O units,
12351 specified by @samp{READ @var{fmt}},
12352 @samp{READ (UNIT=*)},
12353 @samp{WRITE (UNIT=*)}, and
12354 @samp{PRINT @var{fmt}},
12355 should not be units 5 (input) and 6 (output),
12356 but, rather, unit numbers not normally available
12357 for use in statements such as @code{OPEN} and @code{CLOSE}.
12359 Changing this would allow a program to connect units 5 and 6
12360 to files via @code{OPEN},
12361 but still use @samp{READ (UNIT=*)} and @samp{PRINT}
12362 to do I/O to the ``console''.
12364 This change probably requires the @code{libg77} project.
12366 @node Labels Visible to Debugger
12367 @subsection Labels Visible to Debugger
12369 @code{g77} should output debugging information for statements labels,
12370 for use by debuggers that know how to support them.
12371 Same with weirder things like construct names.
12372 It is not yet known if any debug formats or debuggers support these.
12374 @node Disappointments
12375 @section Disappointments and Misunderstandings
12377 These problems are perhaps regrettable, but we don't know any practical
12378 way around them for now.
12380 @menu
12381 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
12382                                               external name @samp{foo_}.
12383 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
12384                                               and @samp{SUBROUTINE FOO}.
12385 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
12386 @end menu
12388 @node Mangling of Names
12389 @subsection Mangling of Names in Source Code
12390 @cindex naming issues
12391 @cindex external names
12392 @cindex common blocks
12393 @cindex name space
12394 @cindex underscore
12396 The current external-interface design, which includes naming of
12397 external procedures, COMMON blocks, and the library interface,
12398 has various usability problems, including things like adding
12399 underscores where not really necessary (and preventing easier
12400 inter-language operability) and yet not providing complete
12401 namespace freedom for user C code linked with Fortran apps (due
12402 to the naming of functions in the library, among other things).
12404 Project GNU should at least get all this ``right'' for systems
12405 it fully controls, such as the Hurd, and provide defaults and
12406 options for compatibility with existing systems and interoperability
12407 with popular existing compilers.
12409 @node Multiple Definitions of External Names
12410 @subsection Multiple Definitions of External Names
12411 @cindex block data
12412 @cindex BLOCK DATA statement
12413 @cindex statements, BLOCK DATA
12414 @cindex @code{COMMON} statement
12415 @cindex statements, @code{COMMON}
12416 @cindex naming conflicts
12418 @code{g77} doesn't allow a common block and an external procedure or
12419 @code{BLOCK DATA} to have the same name.
12420 Some systems allow this, but @code{g77} does not,
12421 to be compatible with @code{f2c}.
12423 @code{g77} could special-case the way it handles
12424 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
12425 particular area (necessarily, since @code{g77} offers an
12426 important feature here), but
12427 it is likely that such special-casing would be very annoying to people
12428 with programs that use @samp{EXTERNAL FOO}, with no other mention of
12429 @samp{FOO} in the same program unit, to refer to external procedures, since
12430 the result would be that @code{g77} would treat these references as requests to
12431 force-load BLOCK DATA program units.
12433 In that case, if @code{g77} modified
12434 names of @code{BLOCK DATA} so they could have the same names as
12435 @code{COMMON}, users
12436 would find that their programs wouldn't link because the @samp{FOO} procedure
12437 didn't have its name translated the same way.
12439 (Strictly speaking,
12440 @code{g77} could emit a null-but-externally-satisfying definition of
12441 @samp{FOO} with its name transformed as if it had been a
12442 @code{BLOCK DATA}, but that probably invites more trouble than it's
12443 worth.)
12445 @node Limitation on Implicit Declarations
12446 @subsection Limitation on Implicit Declarations
12447 @cindex IMPLICIT CHARACTER*(*) statement
12448 @cindex statements, IMPLICIT CHARACTER*(*)
12450 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
12451 This is not standard-conforming.
12453 @node Non-bugs
12454 @section Certain Changes We Don't Want to Make
12456 This section lists changes that people frequently request, but which
12457 we do not make because we think GNU Fortran is better without them.
12459 @menu
12460 * Backslash in Constants::           Why @samp{'\\'} is a constant that
12461                                        is one, not two, characters long.
12462 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
12463                                        @samp{COMMON VAR}.
12464 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
12465 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
12466                                        single-precision constant,
12467                                        and might be interpreted as
12468                                        @samp{9.435785} or similar.
12469 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
12470 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
12471                                        not behave as expected.
12472 @end menu
12474 @node Backslash in Constants
12475 @subsection Backslash in Constants
12476 @cindex backslash
12477 @cindex @code{f77} support
12478 @cindex support, @code{f77}
12480 In the opinion of many experienced Fortran users,
12481 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
12482 as currently set by @code{g77}.
12484 First of all, you can always specify
12485 @samp{-fno-backslash} to turn off this processing.
12487 Despite not being within the spirit (though apparently within the
12488 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
12489 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
12490 default to, and apparently lots of code depends on this feature.
12492 This is a particularly troubling issue.
12493 The use of a C construct in the midst of Fortran code
12494 is bad enough, worse when it makes existing Fortran
12495 programs stop working (as happens when programs written
12496 for non-UNIX systems are ported to UNIX systems with
12497 compilers that provide the @samp{-fbackslash} feature
12498 as the default---sometimes with no option to turn it off).
12500 The author of GNU Fortran wished, for reasons of linguistic
12501 purity, to make @samp{-fno-backslash} the default for GNU
12502 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
12503 to specify @samp{-fbackslash} to get the UNIX behavior.
12505 However, the realization that @code{g77} is intended as
12506 a replacement for @emph{UNIX} @code{f77}, caused the author
12507 to choose to make @code{g77} as compatible with
12508 @code{f77} as feasible, which meant making @samp{-fbackslash}
12509 the default.
12511 The primary focus on compatibility is at the source-code
12512 level, and the question became ``What will users expect
12513 a replacement for @code{f77} to do, by default?''
12514 Although at least one UNIX @code{f77} does not provide
12515 @samp{-fbackslash} as a default, it appears that
12516 the majority of them do, which suggests that
12517 the majority of code that is compiled by UNIX @code{f77}
12518 compilers expects @samp{-fbackslash} to be the default.
12520 It is probably the case that more code exists
12521 that would @emph{not} work with @samp{-fbackslash}
12522 in force than code that requires it be in force.
12524 However, most of @emph{that} code is not being compiled
12525 with @code{f77},
12526 and when it is, new build procedures (shell scripts,
12527 makefiles, and so on) must be set up anyway so that
12528 they work under UNIX.
12529 That makes a much more natural and safe opportunity for
12530 non-UNIX users to adapt their build procedures for
12531 @code{g77}'s default of @samp{-fbackslash} than would
12532 exist for the majority of UNIX @code{f77} users who
12533 would have to modify existing, working build procedures
12534 to explicitly specify @samp{-fbackslash} if that was
12535 not the default.
12537 One suggestion has been to configure the default for
12538 @samp{-fbackslash} (and perhaps other options as well)
12539 based on the configuration of @code{g77}.
12541 This is technically quite straightforward, but will be avoided
12542 even in cases where not configuring defaults to be
12543 dependent on a particular configuration greatly inconveniences
12544 some users of legacy code.
12546 Many users appreciate the GNU compilers because they provide an
12547 environment that is uniform across machines.
12548 These users would be
12549 inconvenienced if the compiler treated things like the
12550 format of the source code differently on certain machines.
12552 Occasionally users write programs intended only for a particular machine
12553 type.
12554 On these occasions, the users would benefit if the GNU Fortran compiler
12555 were to support by default the same dialect as the other compilers on
12556 that machine.
12557 But such applications are rare.
12558 And users writing a
12559 program to run on more than one type of machine cannot possibly benefit
12560 from this kind of compatibility.
12561 (This is consistent with the design goals for @code{gcc}.
12562 To change them for @code{g77}, you must first change them
12563 for @code{gcc}.
12564 Do not ask the maintainers of @code{g77} to do this for you,
12565 or to disassociate @code{g77} from the widely understood, if
12566 not widely agreed-upon, goals for GNU compilers in general.)
12568 This is why GNU Fortran does and will treat backslashes in the same
12569 fashion on all types of machines (by default).
12570 @xref{Direction of Language Development}, for more information on
12571 this overall philosophy guiding the development of the GNU Fortran
12572 language.
12574 Of course, users strongly concerned about portability should indicate
12575 explicitly in their build procedures which options are expected
12576 by their source code, or write source code that has as few such
12577 expectations as possible.
12579 For example, avoid writing code that depends on backslash (@samp{\})
12580 being interpreted either way in particular, such as by
12581 starting a program unit with:
12583 @smallexample
12584 CHARACTER BACKSL
12585 PARAMETER (BACKSL = '\\')
12586 @end smallexample
12588 @noindent
12589 Then, use concatenation of @samp{BACKSL} anyplace a backslash
12590 is desired.
12591 In this way, users can write programs which have the same meaning
12592 in many Fortran dialects.
12594 (However, this technique does not work for Hollerith constants---which
12595 is just as well, since the only generally portable uses for Hollerith
12596 constants are in places where character constants can and should
12597 be used instead, for readability.)
12599 @node Initializing Before Specifying
12600 @subsection Initializing Before Specifying
12601 @cindex initialization, statement placement
12602 @cindex placing initialization statements
12604 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
12605 source code before @samp{COMMON VAR},
12606 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
12607 In general, @code{g77} requires initialization of a variable
12608 or array to be specified @emph{after} all other specifications
12609 of attributes (type, size, placement, and so on) of that variable
12610 or array are specified (though @emph{confirmation} of data type is
12611 permitted).
12613 It is @emph{possible} @code{g77} will someday allow all of this,
12614 even though it is not allowed by the FORTRAN 77 standard.
12616 Then again, maybe it is better to have
12617 @code{g77} always require placement of @code{DATA}
12618 so that it can possibly immediately write constants
12619 to the output file, thus saving time and space.
12621 That is, @samp{DATA A/1000000*1/} should perhaps always
12622 be immediately writable to canonical assembler, unless it's already known
12623 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
12624 and to do this it cannot be followed by @samp{COMMON A}.
12626 @node Context-Sensitive Intrinsicness
12627 @subsection Context-Sensitive Intrinsicness
12628 @cindex intrinsics, context-sensitive
12629 @cindex context-sensitive intrinsics
12631 @code{g77} treats procedure references to @emph{possible} intrinsic
12632 names as always enabling their intrinsic nature, regardless of
12633 whether the @emph{form} of the reference is valid for that
12634 intrinsic.
12636 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
12637 an invalid reference to the @code{SQRT} intrinsic function,
12638 because the reference is a subroutine invocation.
12640 First, @code{g77} recognizes the statement @samp{CALL SQRT}
12641 as a reference to a @emph{procedure} named @samp{SQRT}, not
12642 to a @emph{variable} with that name (as it would for a statement
12643 such as @samp{V = SQRT}).
12645 Next, @code{g77} establishes that, in the program unit being compiled,
12646 @code{SQRT} is an intrinsic---not a subroutine that
12647 happens to have the same name as an intrinsic (as would be
12648 the case if, for example, @samp{EXTERNAL SQRT} was present).
12650 Finally, @code{g77} recognizes that the @emph{form} of the
12651 reference is invalid for that particular intrinsic.
12652 That is, it recognizes that it is invalid for an intrinsic
12653 @emph{function}, such as @code{SQRT}, to be invoked as
12654 a @emph{subroutine}.
12656 At that point, @code{g77} issues a diagnostic.
12658 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
12659 references an external subroutine of their own, not an
12660 intrinsic function.
12662 However, @code{g77} knows about intrinsic
12663 subroutines, not just functions, and is able to support both having
12664 the same names, for example.
12666 As a result of this, @code{g77} rejects calls
12667 to intrinsics that are not subroutines, and function invocations
12668 of intrinsics that are not functions, just as it (and most compilers)
12669 rejects invocations of intrinsics with the wrong number (or types)
12670 of arguments.
12672 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
12673 a user-written subroutine named @samp{SQRT}.
12675 @node Context-Sensitive Constants
12676 @subsection Context-Sensitive Constants
12677 @cindex constants, context-sensitive
12678 @cindex context-sensitive constants
12680 @code{g77} does not use context to determine the types of
12681 constants or named constants (@code{PARAMETER}), except
12682 for (non-standard) typeless constants such as @samp{'123'O}.
12684 For example, consider the following statement:
12686 @smallexample
12687 PRINT *, 9.435784839284958 * 2D0
12688 @end smallexample
12690 @noindent
12691 @code{g77} will interpret the (truncated) constant
12692 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
12693 constant, because the suffix @code{D0} is not specified.
12695 As a result, the output of the above statement when
12696 compiled by @code{g77} will appear to have ``less precision''
12697 than when compiled by other compilers.
12699 In these and other cases, some compilers detect the
12700 fact that a single-precision constant is used in
12701 a double-precision context and therefore interpret the
12702 single-precision constant as if it was @emph{explicitly}
12703 specified as a double-precision constant.
12704 (This has the effect of appending @emph{decimal}, not
12705 @emph{binary}, zeros to the fractional part of the
12706 number---producing different computational results.)
12708 The reason this misfeature is dangerous is that a slight,
12709 apparently innocuous change to the source code can change
12710 the computational results.
12711 Consider:
12713 @smallexample
12714 REAL ALMOST, CLOSE
12715 DOUBLE PRECISION FIVE
12716 PARAMETER (ALMOST = 5.000000000001)
12717 FIVE = 5
12718 CLOSE = 5.000000000001
12719 PRINT *, 5.000000000001 - FIVE
12720 PRINT *, ALMOST - FIVE
12721 PRINT *, CLOSE - FIVE
12723 @end smallexample
12725 @noindent
12726 Running the above program should
12727 result in the same value being
12728 printed three times.
12729 With @code{g77} as the compiler,
12730 it does.
12732 However, compiled by many other compilers,
12733 running the above program would print
12734 two or three distinct values, because
12735 in two or three of the statements, the
12736 constant @samp{5.000000000001}, which
12737 on most systems is exactly equal to @samp{5.}
12738 when interpreted as a single-precision constant,
12739 is instead interpreted as a double-precision
12740 constant, preserving the represented
12741 precision.
12742 However, this ``clever'' promotion of
12743 type does not extend to variables or,
12744 in some compilers, to named constants.
12746 Since programmers often are encouraged to replace manifest
12747 constants or permanently-assigned variables with named
12748 constants (@code{PARAMETER} in Fortran), and might need
12749 to replace some constants with variables having the same
12750 values for pertinent portions of code,
12751 it is important that compilers treat code so modified in the
12752 same way so that the results of such programs are the same.
12753 @code{g77} helps in this regard by treating constants just
12754 the same as variables in terms of determining their types
12755 in a context-independent way.
12757 Still, there is a lot of existing Fortran code that has
12758 been written to depend on the way other compilers freely
12759 interpret constants' types based on context, so anything
12760 @code{g77} can do to help flag cases of this in such code
12761 could be very helpful.
12763 @node Equivalence Versus Equality
12764 @subsection Equivalence Versus Equality
12765 @cindex .EQV., with integer operands
12766 @cindex comparing logical expressions
12767 @cindex logical expressions, comparing
12769 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
12770 is not supported, except via @samp{-fugly-logint}, which is not
12771 recommended except for legacy code (where the behavior expected
12772 by the @emph{code} is assumed).
12774 Legacy code should be changed, as resources permit, to use @code{.EQV.}
12775 and @code{.NEQV.} instead, as these are permitted by the various
12776 Fortran standards.
12778 New code should never be written expecting @code{.EQ.} or @code{.NE.}
12779 to work if either of its operands is @code{LOGICAL}.
12781 The problem with supporting this ``feature'' is that there is
12782 unlikely to be consensus on how it works, as illustrated by the
12783 following sample program:
12785 @smallexample
12786 LOGICAL L,M,N
12787 DATA L,M,N /3*.FALSE./
12788 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
12790 @end smallexample
12792 The issue raised by the above sample program is: what is the
12793 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
12794 @code{LOGICAL} operands?
12796 Some programmers will argue that it is the same as the precedence
12797 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
12798 operands.
12799 By this interpretation, the subexpression @samp{M.EQ.N} must be
12800 evaluated first in the above program, resulting in a program that,
12801 when run, does not execute the @code{PRINT} statement.
12803 Other programmers will argue that the precedence is the same as
12804 the precedence for @code{.EQV.}, which is restricted by the standards
12805 to @code{LOGICAL} operands.
12806 By this interpretation, the subexpression @samp{L.AND.M} must be
12807 evaluated first, resulting in a program that @emph{does} execute
12808 the @code{PRINT} statement.
12810 Assigning arbitrary semantic interpretations to syntactic expressions
12811 that might legitimately have more than one ``obvious'' interpretation
12812 is generally unwise.
12814 The creators of the various Fortran standards have done a good job
12815 in this case, requiring a distinct set of operators (which have their
12816 own distinct precedence) to compare @code{LOGICAL} operands.
12817 This requirement results in expression syntax with more certain
12818 precedence (without requiring substantial context), making it easier
12819 for programmers to read existing code.
12820 @code{g77} will avoid muddying up elements of the Fortran language
12821 that were well-designed in the first place.
12823 (Ask C programmers about the precedence of expressions such as
12824 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
12825 you, without knowing more context, whether the @samp{&} and @samp{-}
12826 operators are infix (binary) or unary!)
12828 Most dangerous of all is the fact that,
12829 even assuming consensus on its meaning,
12830 an expression like @samp{L.AND.M.EQ.N},
12831 if it is the result of a typographical error,
12832 doesn't @emph{look} like it has such a typo.
12833 Even experienced Fortran programmers would not likely notice that
12834 @samp{L.AND.M.EQV.N} was, in fact, intended.
12836 So, this is a prime example of a circumstance in which
12837 a quality compiler diagnoses the code,
12838 instead of leaving it up to someone debugging it
12839 to know to turn on special compiler options
12840 that might diagnose it.
12842 @node Order of Side Effects
12843 @subsection Order of Side Effects
12844 @cindex side effects, order of evaluation
12845 @cindex order of evaluation, side effects
12847 @code{g77} does not necessarily produce code that, when run, performs
12848 side effects (such as those performed by function invocations)
12849 in the same order as in some other compiler---or even in the same
12850 order as another version, port, or invocation (using different
12851 command-line options) of @code{g77}.
12853 It is never safe to depend on the order of evaluation of side effects.
12854 For example, an expression like this may very well behave differently
12855 from one compiler to another:
12857 @smallexample
12858 J = IFUNC() - IFUNC()
12859 @end smallexample
12861 @noindent
12862 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
12863 order.
12864 Either invocation might happen first.
12865 If @samp{IFUNC} returns 5 the first time it is invoked, and
12866 returns 12 the second time, @samp{J} might end up with the
12867 value @samp{7}, or it might end up with @samp{-7}.
12869 Generally, in Fortran, procedures with side-effects intended to
12870 be visible to the caller are best designed as @emph{subroutines},
12871 not functions.
12872 Examples of such side-effects include:
12874 @itemize @bullet
12875 @item
12876 The generation of random numbers
12877 that are intended to influence return values.
12879 @item
12880 Performing I/O
12881 (other than internal I/O to local variables).
12883 @item
12884 Updating information in common blocks.
12885 @end itemize
12887 An example of a side-effect that is not intended to be visible
12888 to the caller is a function that maintains a cache of recently
12889 calculated results, intended solely to speed repeated invocations
12890 of the function with identical arguments.
12891 Such a function can be safely used in expressions, because
12892 if the compiler optimizes away one or more calls to the
12893 function, operation of the program is unaffected (aside
12894 from being speeded up).
12896 @node Warnings and Errors
12897 @section Warning Messages and Error Messages
12899 @cindex error messages
12900 @cindex warnings vs errors
12901 @cindex messages, warning and error
12902 The GNU compiler can produce two kinds of diagnostics: errors and
12903 warnings.
12904 Each kind has a different purpose:
12906 @itemize @w{}
12907 @item
12908 @emph{Errors} report problems that make it impossible to compile your
12909 program.
12910 GNU Fortran reports errors with the source file name, line
12911 number, and column within the line where the problem is apparent.
12913 @item
12914 @emph{Warnings} report other unusual conditions in your code that
12915 @emph{might} indicate a problem, although compilation can (and does)
12916 proceed.
12917 Warning messages also report the source file name, line number,
12918 and column information,
12919 but include the text @samp{warning:} to distinguish them
12920 from error messages.
12921 @end itemize
12923 Warnings might indicate danger points where you should check to make sure
12924 that your program really does what you intend; or the use of obsolete
12925 features; or the use of nonstandard features of GNU Fortran.
12926 Many warnings are issued only if you ask for them, with one of the
12927 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
12928 useful warnings).
12930 @emph{Note:} Currently, the text of the line and a pointer to the column
12931 is printed in most @code{g77} diagnostics.
12932 Probably, as of version 0.6, @code{g77} will
12933 no longer print the text of the source line, instead printing
12934 the column number following the file name and line number in
12935 a form that GNU Emacs recognizes.
12936 This change is expected to speed up and reduce the memory usage
12937 of the @code{g77} compiler.
12939 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
12941 @c GNU Fortran always tries to compile your program if possible; it never
12942 @c gratuitously rejects a program whose meaning is clear merely because
12943 @c (for instance) it fails to conform to a standard.  In some cases,
12944 @c however, the Fortran standard specifies that certain extensions are
12945 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
12946 @c compiler.  The @samp{-pedantic} option tells GNU Fortran to issue warnings
12947 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
12948 @c This does not mean that @emph{all} non-ANSI constructs get warnings
12949 @c or errors.
12951 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
12952 more detail on these and related command-line options.
12954 @node Open Questions
12955 @chapter Open Questions
12957 Please consider offering useful answers to these questions!
12959 @itemize @bullet
12960 @item
12961 @code{LOC()} and other intrinsics are probably somewhat misclassified.
12962 Is the a need for more precise classification of intrinsics, and if so,
12963 what are the appropriate groupings?
12964 Is there a need to individually
12965 enable/disable/delete/hide intrinsics from the command line?
12966 @end itemize
12968 @node Bugs
12969 @chapter Reporting Bugs
12970 @cindex bugs
12971 @cindex reporting bugs
12973 Your bug reports play an essential role in making GNU Fortran reliable.
12975 When you encounter a problem, the first thing to do is to see if it is
12976 already known.
12977 @xref{Trouble}.
12978 If it isn't known, then you should report the problem.
12980 Reporting a bug might help you by bringing a solution to your problem, or
12981 it might not.
12982 (If it does not, look in the service directory; see
12983 @ref{Service}.)
12984 In any case, the principal function of a bug report is
12985 to help the entire community by making the next version of GNU Fortran work
12986 better.
12987 Bug reports are your contribution to the maintenance of GNU Fortran.
12989 Since the maintainers are very overloaded, we cannot respond to every
12990 bug report.
12991 However, if the bug has not been fixed, we are likely to
12992 send you a patch and ask you to tell us whether it works.
12994 In order for a bug report to serve its purpose, you must include the
12995 information that makes for fixing the bug.
12997 @menu
12998 * Criteria: Bug Criteria.    Have you really found a bug?
12999 * Where: Bug Lists.          Where to send your bug report.
13000 * Reporting: Bug Reporting.  How to report a bug effectively.
13001 * Patches: Sending Patches.  How to send a patch for GNU Fortran.
13002 @end menu
13004 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
13005 for information on problems we already know about.
13007 @xref{Service,,How To Get Help with GNU Fortran},
13008 for information on where to ask for help.
13010 @node Bug Criteria
13011 @section Have You Found a Bug?
13012 @cindex bug criteria
13014 If you are not sure whether you have found a bug, here are some guidelines:
13016 @itemize @bullet
13017 @cindex fatal signal
13018 @cindex core dump
13019 @item
13020 If the compiler gets a fatal signal, for any input whatever, that is a
13021 compiler bug.
13022 Reliable compilers never crash---they just remain obsolete.
13024 @cindex invalid assembly code
13025 @cindex assembly code, invalid
13026 @item
13027 If the compiler produces invalid assembly code, for any input whatever,
13028 @c (except an @code{asm} statement),
13029 that is a compiler bug, unless the
13030 compiler reports errors (not just warnings) which would ordinarily
13031 prevent the assembler from being run.
13033 @cindex undefined behavior
13034 @cindex undefined function value
13035 @item
13036 If the compiler produces valid assembly code that does not correctly
13037 execute the input source code, that is a compiler bug.
13039 However, you must double-check to make sure, because you might have run
13040 into an incompatibility between GNU Fortran and traditional Fortran.
13041 @c (@pxref{Incompatibilities}).
13042 These incompatibilities might be considered
13043 bugs, but they are inescapable consequences of valuable features.
13045 Or you might have a program whose behavior is undefined, which happened
13046 by chance to give the desired results with another Fortran compiler.
13047 It is best to check the relevant Fortran standard thoroughly if
13048 it is possible that the program indeed does something undefined.
13050 After you have localized the error to a single source line, it should
13051 be easy to check for these things.
13052 If your program is correct and well defined, you have found
13053 a compiler bug.
13055 It might help if, in your submission, you identified the specific
13056 language in the relevant Fortran standard that specifies the
13057 desired behavior, if it isn't likely to be obvious and agreed-upon
13058 by all Fortran users.
13060 @item
13061 If the compiler produces an error message for valid input, that is a
13062 compiler bug.
13064 @cindex invalid input
13065 @item
13066 If the compiler does not produce an error message for invalid input,
13067 that is a compiler bug.
13068 However, you should note that your idea of
13069 ``invalid input'' might be someone else's idea
13070 of ``an extension'' or ``support for traditional practice''.
13072 @item
13073 If you are an experienced user of Fortran compilers, your suggestions
13074 for improvement of GNU Fortran are welcome in any case.
13075 @end itemize
13077 Many, perhaps most, bug reports against @code{g77} turn out to
13078 be bugs in the user's code.
13079 While we find such bug reports educational, they sometimes take
13080 a considerable amount of time to track down or at least respond
13081 to---time we could be spending making @code{g77}, not some user's
13082 code, better.
13084 Some steps you can take to verify that the bug is not certainly
13085 in the code you're compiling with @code{g77}:
13087 @itemize @bullet
13088 @item
13089 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
13090 These options enable many useful warning; the @samp{-O} option
13091 enables flow analysis that enables the uninitialized-variable
13092 warning.
13094 If you investigate the warnings and find evidence of possible bugs
13095 in your code, fix them first and retry @code{g77}.
13097 @item
13098 Compile your code using the @code{g77} options @samp{-finit-local-zero},
13099 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
13100 combinations thereof.
13102 If your code works with any of these combinations, that is not
13103 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
13104 by your code might simply be avoided, or have a different, more subtle
13105 effect, when different options are used---but it can be a
13106 strong indicator that your code is making unwarranted assumptions
13107 about the Fortran dialect and/or underlying machine it is
13108 being compiled and run on.
13110 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
13111 for information on the @samp{-fno-automatic} and
13112 @samp{-finit-local-zero} options and how to convert
13113 their use into selective changes in your own code.
13115 @item
13116 @pindex ftnchek
13117 Validate your code with @code{ftnchek} or a similar code-checking
13118 tool.
13119 @code{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
13120 or @uref{ftp://ftp.dsm.fordham.edu}.
13122 @pindex make
13123 @cindex Makefile example
13124 Here are some sample @file{Makefile} rules using @code{ftnchek}
13125 ``project'' files to do cross-file checking and @code{sfmakedepend}
13126 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
13127 to maintain dependencies automatically.
13128 These assume the use of GNU @code{make}.
13130 @smallexample
13131 # Dummy suffix for ftnchek targets:
13132 .SUFFIXES: .chek
13133 .PHONY: chekall
13135 # How to compile .f files (for implicit rule):
13136 FC = g77
13137 # Assume `include' directory:
13138 FFLAGS = -Iinclude -g -O -Wall
13140 # Flags for ftnchek:
13141 CHEK1 = -array=0 -include=includes -noarray
13142 CHEK2 = -nonovice -usage=1 -notruncation
13143 CHEKFLAGS = $(CHEK1) $(CHEK2)
13145 # Run ftnchek with all the .prj files except the one corresponding
13146 # to the target's root:
13147 %.chek : %.f ; \
13148   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
13149     -noextern -library $<
13151 # Derive a project file from a source file:
13152 %.prj : %.f ; \
13153   ftnchek $(CHEKFLAGS) -noextern -project -library $<
13155 # The list of objects is assumed to be in variable OBJS.
13156 # Sources corresponding to the objects:
13157 SRCS = $(OBJS:%.o=%.f)
13158 # ftnchek project files:
13159 PRJS = $(OBJS:%.o=%.prj)
13161 # Build the program
13162 prog: $(OBJS) ; \
13163   $(FC) -o $@ $(OBJS)
13165 chekall: $(PRJS) ; \
13166   ftnchek $(CHEKFLAGS) $(PRJS)
13168 prjs: $(PRJS)
13170 # For Emacs M-x find-tag:
13171 TAGS: $(SRCS) ; \
13172   etags $(SRCS)
13174 # Rebuild dependencies:
13175 depend: ; \
13176   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
13177 @end smallexample
13179 @item
13180 Try your code out using other Fortran compilers, such as @code{f2c}.
13181 If it does not work on at least one other compiler (assuming the
13182 compiler supports the features the code needs), that is a strong
13183 indicator of a bug in the code.
13185 However, even if your code works on many compilers @emph{except}
13186 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
13187 It might mean the bug is in your code, and that @code{g77} simply
13188 exposes it more readily than other compilers.
13189 @end itemize
13191 @node Bug Lists
13192 @section Where to Report Bugs
13193 @cindex bug report mailing lists
13194 @kindex @value{email-bugs}
13195 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
13197 Often people think of posting bug reports to a newsgroup instead of
13198 mailing them.
13199 This sometimes appears to work, but it has one problem which can be
13200 crucial: a newsgroup posting does not contain a mail path back to the
13201 sender.
13202 Thus, if maintainers need more information, they might be unable
13203 to reach you.  For this reason, you should always send bug reports by
13204 mail to the proper mailing list.
13206 As a last resort, send bug reports on paper to:
13208 @example
13209 GNU Compiler Bugs
13210 Free Software Foundation
13211 59 Temple Place - Suite 330
13212 Boston, MA 02111-1307, USA
13213 @end example
13215 @node Bug Reporting
13216 @section How to Report Bugs
13217 @cindex compiler bugs, reporting
13219 The fundamental principle of reporting bugs usefully is this:
13220 @strong{report all the facts}.
13221 If you are not sure whether to state a
13222 fact or leave it out, state it!
13224 Often people omit facts because they think they know what causes the
13225 problem and they conclude that some details don't matter.
13226 Thus, you might
13227 assume that the name of the variable you use in an example does not matter.
13228 Well, probably it doesn't, but one cannot be sure.
13229 Perhaps the bug is a
13230 stray memory reference which happens to fetch from the location where that
13231 name is stored in memory; perhaps, if the name were different, the contents
13232 of that location would fool the compiler into doing the right thing despite
13233 the bug.
13234 Play it safe and give a specific, complete example.
13235 That is the
13236 easiest thing for you to do, and the most helpful.
13238 Keep in mind that the purpose of a bug report is to enable someone to
13239 fix the bug if it is not known.
13240 It isn't very important what happens if
13241 the bug is already known.
13242 Therefore, always write your bug reports on
13243 the assumption that the bug is not known.
13245 Sometimes people give a few sketchy facts and ask, ``Does this ring a
13246 bell?''
13247 This cannot help us fix a bug, so it is rarely helpful.
13248 We respond by asking for enough details to enable us to investigate.
13249 You might as well expedite matters by sending them to begin with.
13250 (Besides, there are enough bells ringing around here as it is.)
13252 Try to make your bug report self-contained.
13253 If we have to ask you for
13254 more information, it is best if you include all the previous information
13255 in your response, as well as the information that was missing.
13257 Please report each bug in a separate message.
13258 This makes it easier for
13259 us to track which bugs have been fixed and to forward your bugs reports
13260 to the appropriate maintainer.
13262 Do not compress and encode any part of your bug report using programs
13263 such as @file{uuencode}.
13264 If you do so it will slow down the processing
13265 of your bug.
13266 If you must submit multiple large files, use @file{shar},
13267 which allows us to read your message without having to run any
13268 decompression programs.
13270 (As a special exception for GNU Fortran bug-reporting, at least
13271 for now, if you are sending more than a few lines of code, if
13272 your program's source file format contains ``interesting'' things
13273 like trailing spaces or strange characters, or if you need to
13274 include binary data files, it is acceptable to put all the
13275 files together in a @code{tar} archive, and, whether you need to
13276 do that, it is acceptable to then compress the single file (@code{tar}
13277 archive or source file)
13278 using @code{gzip} and encode it via @code{uuencode}.
13279 Do not use any MIME stuff---the current maintainer can't decode this.
13280 Using @code{compress} instead of @code{gzip} is acceptable, assuming
13281 you have licensed the use of the patented algorithm in
13282 @code{compress} from Unisys.)
13284 To enable someone to investigate the bug, you should include all these
13285 things:
13287 @itemize @bullet
13288 @item
13289 The version of GNU Fortran.
13290 You can get this by running @code{g77} with the @samp{-v} option.
13291 (Ignore any error messages that might be displayed
13292 when the linker is run.)
13294 Without this, we won't know whether there is any point in looking for
13295 the bug in the current version of GNU Fortran.
13297 @item
13298 @cindex preprocessor
13299 @cindex cpp program
13300 @cindex programs, cpp
13301 @pindex cpp
13302 A complete input file that will reproduce the bug.
13304 If your source file(s) require preprocessing
13305 (for example, their names have suffixes like
13306 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
13307 and the bug is in the compiler proper (@file{f771})
13308 or in a subsequent phase of processing,
13309 run your source file through the C preprocessor
13310 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
13311 Then, include the contents of @var{newfile} in the bug report.
13312 (When you do this, use the same preprocessor options---such as
13313 @samp{-I}, @samp{-D}, and @samp{-U}---that you used in actual
13314 compilation.)
13316 A single statement is not enough of an example.
13317 In order to compile it,
13318 it must be embedded in a complete file of compiler input.
13319 The bug might depend on the details of how this is done.
13321 Without a real example one can compile,
13322 all anyone can do about your bug report is wish you luck.
13323 It would be futile to try to guess how to provoke the bug.
13324 For example, bugs in register allocation and reloading
13325 can depend on every little detail of the source and include files
13326 that trigger them.
13328 @item
13329 @cindex included files
13330 @cindex INCLUDE directive
13331 @cindex directive, INCLUDE
13332 @cindex #include directive
13333 @cindex directive, #include
13334 Note that you should include with your bug report any files
13335 included by the source file
13336 (via the @code{#include} or @code{INCLUDE} directive)
13337 that you send, and any files they include, and so on.
13339 It is not necessary to replace
13340 the @code{#include} and @code{INCLUDE} directives
13341 with the actual files in the version of the source file that
13342 you send, but it might make submitting the bug report easier
13343 in the end.
13344 However, be sure to @emph{reproduce} the bug using the @emph{exact}
13345 version of the source material you submit, to avoid wild-goose
13346 chases.
13348 @item
13349 The command arguments you gave GNU Fortran to compile that example
13350 and observe the bug.  For example, did you use @samp{-O}?  To guarantee
13351 you won't omit something important, list all the options.
13353 If we were to try to guess the arguments, we would probably guess wrong
13354 and then we would not encounter the bug.
13356 @item
13357 The type of machine you are using, and the operating system name and
13358 version number.
13359 (Much of this information is printed by @samp{g77 -v}---if you
13360 include that, send along any additional info you have that you
13361 don't see clearly represented in that output.)
13363 @item
13364 The operands you gave to the @code{configure} command when you installed
13365 the compiler.
13367 @item
13368 A complete list of any modifications you have made to the compiler
13369 source.  (We don't promise to investigate the bug unless it happens in
13370 an unmodified compiler.  But if you've made modifications and don't tell
13371 us, then you are sending us on a wild-goose chase.)
13373 Be precise about these changes.  A description in English is not
13374 enough---send a context diff for them.
13376 Adding files of your own (such as a machine description for a machine we
13377 don't support) is a modification of the compiler source.
13379 @item
13380 Details of any other deviations from the standard procedure for installing
13381 GNU Fortran.
13383 @item
13384 A description of what behavior you observe that you believe is
13385 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
13386 ``The assembler instruction at line 208 in the output is incorrect.''
13388 Of course, if the bug is that the compiler gets a fatal signal, then one
13389 can't miss it.  But if the bug is incorrect output, the maintainer might
13390 not notice unless it is glaringly wrong.  None of us has time to study
13391 all the assembler code from a 50-line Fortran program just on the chance that
13392 one instruction might be wrong.  We need @emph{you} to do this part!
13394 Even if the problem you experience is a fatal signal, you should still
13395 say so explicitly.  Suppose something strange is going on, such as, your
13396 copy of the compiler is out of synch, or you have encountered a bug in
13397 the C library on your system.  (This has happened!)  Your copy might
13398 crash and the copy here would not.  If you @i{said} to expect a crash,
13399 then when the compiler here fails to crash, we would know that the bug
13400 was not happening.  If you don't say to expect a crash, then we would
13401 not know whether the bug was happening.  We would not be able to draw
13402 any conclusion from our observations.
13404 If the problem is a diagnostic when building GNU Fortran with some other
13405 compiler, say whether it is a warning or an error.
13407 Often the observed symptom is incorrect output when your program is run.
13408 Sad to say, this is not enough information unless the program is short
13409 and simple.  None of us has time to study a large program to figure out
13410 how it would work if compiled correctly, much less which line of it was
13411 compiled wrong.  So you will have to do that.  Tell us which source line
13412 it is, and what incorrect result happens when that line is executed.  A
13413 person who understands the program can find this as easily as finding a
13414 bug in the program itself.
13416 @item
13417 If you send examples of assembler code output from GNU Fortran,
13418 please use @samp{-g} when you make them.  The debugging information
13419 includes source line numbers which are essential for correlating the
13420 output with the input.
13422 @item
13423 If you wish to mention something in the GNU Fortran source, refer to it by
13424 context, not by line number.
13426 The line numbers in the development sources don't match those in your
13427 sources.  Your line numbers would convey no convenient information to the
13428 maintainers.
13430 @item
13431 Additional information from a debugger might enable someone to find a
13432 problem on a machine which he does not have available.  However, you
13433 need to think when you collect this information if you want it to have
13434 any chance of being useful.
13436 @cindex backtrace for bug reports
13437 For example, many people send just a backtrace, but that is never
13438 useful by itself.  A simple backtrace with arguments conveys little
13439 about GNU Fortran because the compiler is largely data-driven; the same
13440 functions are called over and over for different RTL insns, doing
13441 different things depending on the details of the insn.
13443 Most of the arguments listed in the backtrace are useless because they
13444 are pointers to RTL list structure.  The numeric values of the
13445 pointers, which the debugger prints in the backtrace, have no
13446 significance whatever; all that matters is the contents of the objects
13447 they point to (and most of the contents are other such pointers).
13449 In addition, most compiler passes consist of one or more loops that
13450 scan the RTL insn sequence.  The most vital piece of information about
13451 such a loop---which insn it has reached---is usually in a local variable,
13452 not in an argument.
13454 @findex debug_rtx
13455 What you need to provide in addition to a backtrace are the values of
13456 the local variables for several stack frames up.  When a local
13457 variable or an argument is an RTX, first print its value and then use
13458 the GDB command @code{pr} to print the RTL expression that it points
13459 to.  (If GDB doesn't run on your machine, use your debugger to call
13460 the function @code{debug_rtx} with the RTX as an argument.)  In
13461 general, whenever a variable is a pointer, its value is no use
13462 without the data it points to.
13463 @end itemize
13465 Here are some things that are not necessary:
13467 @itemize @bullet
13468 @item
13469 A description of the envelope of the bug.
13471 Often people who encounter a bug spend a lot of time investigating
13472 which changes to the input file will make the bug go away and which
13473 changes will not affect it.
13475 This is often time consuming and not very useful, because the way we
13476 will find the bug is by running a single example under the debugger with
13477 breakpoints, not by pure deduction from a series of examples.  You might
13478 as well save your time for something else.
13480 Of course, if you can find a simpler example to report @emph{instead} of
13481 the original one, that is a convenience.  Errors in the output will be
13482 easier to spot, running under the debugger will take less time, etc.
13483 Most GNU Fortran bugs involve just one function, so the most straightforward
13484 way to simplify an example is to delete all the function definitions
13485 except the one where the bug occurs.  Those earlier in the file may be
13486 replaced by external declarations if the crucial function depends on
13487 them.  (Exception: inline functions might affect compilation of functions
13488 defined later in the file.)
13490 However, simplification is not vital; if you don't want to do this,
13491 report the bug anyway and send the entire test case you used.
13493 @item
13494 In particular, some people insert conditionals @samp{#ifdef BUG} around
13495 a statement which, if removed, makes the bug not happen.  These are just
13496 clutter; we won't pay any attention to them anyway.  Besides, you should
13497 send us preprocessor output, and that can't have conditionals.
13499 @item
13500 A patch for the bug.
13502 A patch for the bug is useful if it is a good one.  But don't omit the
13503 necessary information, such as the test case, on the assumption that a
13504 patch is all we need.  We might see problems with your patch and decide
13505 to fix the problem another way, or we might not understand it at all.
13507 Sometimes with a program as complicated as GNU Fortran it is very hard to
13508 construct an example that will make the program follow a certain path
13509 through the code.  If you don't send the example, we won't be able to
13510 construct one, so we won't be able to verify that the bug is fixed.
13512 And if we can't understand what bug you are trying to fix, or why your
13513 patch should be an improvement, we won't install it.  A test case will
13514 help us to understand.
13516 @xref{Sending Patches}, for guidelines on how to make it easy for us to
13517 understand and install your patches.
13519 @item
13520 A guess about what the bug is or what it depends on.
13522 Such guesses are usually wrong.  Even the maintainer can't guess right
13523 about such things without first using the debugger to find the facts.
13525 @item
13526 A core dump file.
13528 We have no way of examining a core dump for your type of machine
13529 unless we have an identical system---and if we do have one,
13530 we should be able to reproduce the crash ourselves.
13531 @end itemize
13533 @node Sending Patches
13534 @section Sending Patches for GNU Fortran
13536 If you would like to write bug fixes or improvements for the GNU Fortran
13537 compiler, that is very helpful.
13538 Send suggested fixes to the bug report
13539 mailing list, @email{@value{email-bugs}}.
13541 Please follow these guidelines so we can study your patches efficiently.
13542 If you don't follow these guidelines, your information might still be
13543 useful, but using it will take extra work.  Maintaining GNU Fortran is a lot
13544 of work in the best of circumstances, and we can't keep up unless you do
13545 your best to help.
13547 @itemize @bullet
13548 @item
13549 Send an explanation with your changes of what problem they fix or what
13550 improvement they bring about.  For a bug fix, just include a copy of the
13551 bug report, and explain why the change fixes the bug.
13553 (Referring to a bug report is not as good as including it, because then
13554 we will have to look it up, and we have probably already deleted it if
13555 we've already fixed the bug.)
13557 @item
13558 Always include a proper bug report for the problem you think you have
13559 fixed.  We need to convince ourselves that the change is right before
13560 installing it.  Even if it is right, we might have trouble judging it if
13561 we don't have a way to reproduce the problem.
13563 @item
13564 Include all the comments that are appropriate to help people reading the
13565 source in the future understand why this change was needed.
13567 @item
13568 Don't mix together changes made for different reasons.
13569 Send them @emph{individually}.
13571 If you make two changes for separate reasons, then we might not want to
13572 install them both.  We might want to install just one.  If you send them
13573 all jumbled together in a single set of diffs, we have to do extra work
13574 to disentangle them---to figure out which parts of the change serve
13575 which purpose.  If we don't have time for this, we might have to ignore
13576 your changes entirely.
13578 If you send each change as soon as you have written it, with its own
13579 explanation, then the two changes never get tangled up, and we can
13580 consider each one properly without any extra work to disentangle them.
13582 Ideally, each change you send should be impossible to subdivide into
13583 parts that we might want to consider separately, because each of its
13584 parts gets its motivation from the other parts.
13586 @item
13587 Send each change as soon as that change is finished.  Sometimes people
13588 think they are helping us by accumulating many changes to send them all
13589 together.  As explained above, this is absolutely the worst thing you
13590 could do.
13592 Since you should send each change separately, you might as well send it
13593 right away.  That gives us the option of installing it immediately if it
13594 is important.
13596 @item
13597 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
13598 for us to install reliably.  More than that, they make it hard for us to
13599 study the diffs to decide whether we want to install them.  Unidiff
13600 format is better than contextless diffs, but not as easy to read as
13601 @samp{-c} format.
13603 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
13604 function that each change occurs in.
13605 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
13607 @item
13608 Write the change log entries for your changes.  We get lots of changes,
13609 and we don't have time to do all the change log writing ourselves.
13611 Read the @file{ChangeLog} file to see what sorts of information to put
13612 in, and to learn the style that we use.  The purpose of the change log
13613 is to show people where to find what was changed.  So you need to be
13614 specific about what functions you changed; in large functions, it's
13615 often helpful to indicate where within the function the change was.
13617 On the other hand, once you have shown people where to find the change,
13618 you need not explain its purpose.  Thus, if you add a new function, all
13619 you need to say about it is that it is new.  If you feel that the
13620 purpose needs explaining, it probably does---but the explanation will be
13621 much more useful if you put it in comments in the code.
13623 If you would like your name to appear in the header line for who made
13624 the change, send us the header line.
13626 @item
13627 When you write the fix, keep in mind that we can't install a change that
13628 would break other systems.
13630 People often suggest fixing a problem by changing machine-independent
13631 files such as @file{toplev.c} to do something special that a particular
13632 system needs.  Sometimes it is totally obvious that such changes would
13633 break GNU Fortran for almost all users.  We can't possibly make a change like
13634 that.  At best it might tell us how to write another patch that would
13635 solve the problem acceptably.
13637 Sometimes people send fixes that @emph{might} be an improvement in
13638 general---but it is hard to be sure of this.  It's hard to install
13639 such changes because we have to study them very carefully.  Of course,
13640 a good explanation of the reasoning by which you concluded the change
13641 was correct can help convince us.
13643 The safest changes are changes to the configuration files for a
13644 particular machine.  These are safe because they can't create new bugs
13645 on other machines.
13647 Please help us keep up with the workload by designing the patch in a
13648 form that is good to install.
13649 @end itemize
13651 @node Service
13652 @chapter How To Get Help with GNU Fortran
13654 If you need help installing, using or changing GNU Fortran, there are two
13655 ways to find it:
13657 @itemize @bullet
13658 @item
13659 Look in the service directory for someone who might help you for a fee.
13660 The service directory is found in the file named @file{SERVICE} in the
13661 GNU CC distribution.
13663 @item
13664 Send a message to @email{@value{email-general}}.
13665 @end itemize
13667 @end ifset
13668 @ifset INTERNALS
13669 @node Adding Options
13670 @chapter Adding Options
13671 @cindex options, adding
13672 @cindex adding options
13674 To add a new command-line option to @code{g77}, first decide
13675 what kind of option you wish to add.
13676 Search the @code{g77} and @code{gcc} documentation for one
13677 or more options that is most closely like the one you want to add
13678 (in terms of what kind of effect it has, and so on) to
13679 help clarify its nature.
13681 @itemize @bullet
13682 @item
13683 @emph{Fortran options} are options that apply only
13684 when compiling Fortran programs.
13685 They are accepted by @code{g77} and @code{gcc}, but
13686 they apply only when compiling Fortran programs.
13688 @item
13689 @emph{Compiler options} are options that apply
13690 when compiling most any kind of program.
13691 @end itemize
13693 @emph{Fortran options} are listed in the file
13694 @file{@value{path-g77}/lang-options.h},
13695 which is used during the build of @code{gcc} to
13696 build a list of all options that are accepted by
13697 at least one language's compiler.
13698 This list goes into the @code{documented_lang_options} array
13699 in @file{gcc/toplev.c}, which uses this array to
13700 determine whether a particular option should be
13701 offered to the linked-in front end for processing
13702 by calling @code{lang_option_decode}, which, for
13703 @code{g77}, is in @file{@value{path-g77}/com.c} and just
13704 calls @code{ffe_decode_option}.
13706 If the linked-in front end ``rejects'' a
13707 particular option passed to it, @file{toplev.c}
13708 just ignores the option, because @emph{some}
13709 language's compiler is willing to accept it.
13711 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
13712 to work, even though Fortran compilation does
13713 not currently support the @samp{-fno-asm} option;
13714 even though the @code{f771} version of @code{lang_decode_option}
13715 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
13716 produce a diagnostic because some other language (C)
13717 does accept it.
13719 This also means that commands like
13720 @samp{g77 -fno-asm foo.f} yield no diagnostics,
13721 despite the fact that no phase of the command was
13722 able to recognize and process @samp{-fno-asm}---perhaps
13723 a warning about this would be helpful if it were
13724 possible.
13726 Code that processes Fortran options is found in
13727 @file{@value{path-g77}/top.c}, function @code{ffe_decode_option}.
13728 This code needs to check positive and negative forms
13729 of each option.
13731 The defaults for Fortran options are set in their
13732 global definitions, also found in @file{@value{path-g77}/top.c}.
13733 Many of these defaults are actually macros defined
13734 in @file{@value{path-g77}/target.h}, since they might be
13735 machine-specific.
13736 However, since, in practice, GNU compilers
13737 should behave the same way on all configurations
13738 (especially when it comes to language constructs),
13739 the practice of setting defaults in @file{target.h}
13740 is likely to be deprecated and, ultimately, stopped
13741 in future versions of @code{g77}.
13743 Accessor macros for Fortran options, used by code
13744 in the @code{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
13746 @emph{Compiler options} are listed in @file{gcc/toplev.c}
13747 in the array @code{f_options}.
13748 An option not listed in @code{lang_options} is
13749 looked up in @code{f_options} and handled from there.
13751 The defaults for compiler options are set in the
13752 global definitions for the corresponding variables,
13753 some of which are in @file{gcc/toplev.c}.
13755 You can set different defaults for @emph{Fortran-oriented}
13756 or @emph{Fortran-reticent} compiler options by changing
13757 the source code of @code{g77} and rebuilding.
13758 How to do this depends on the version of @code{g77}:
13760 @table @code
13761 @item G77 0.5.24 (EGCS 1.1)
13762 @itemx G77 0.5.25 (EGCS 1.2 - which became GCC 2.95)
13763 Change the @code{lang_init_options} routine in @file{gcc/gcc/f/com.c}.
13765 (Note that these versions of @code{g77}
13766 perform internal consistency checking automatically
13767 when the @samp{-fversion} option is specified.)
13769 @item G77 0.5.23
13770 @itemx G77 0.5.24 (EGCS 1.0)
13771 Change the way @code{f771} handles the @samp{-fset-g77-defaults}
13772 option, which is always provided as the first option when
13773 called by @code{g77} or @code{gcc}.
13775 This code is in @code{ffe_decode_options} in @file{@value{path-g77}/top.c}.
13776 Have it change just the variables that you want to default
13777 to a different setting for Fortran compiles compared to
13778 compiles of other languages.
13780 The @samp{-fset-g77-defaults} option is passed to @code{f771}
13781 automatically because of the specification information
13782 kept in @file{@value{path-g77}/lang-specs.h}.
13783 This file tells the @code{gcc} command how to recognize,
13784 in this case, Fortran source files (those to be preprocessed,
13785 and those that are not), and further, how to invoke the
13786 appropriate programs (including @code{f771}) to process
13787 those source files.
13789 It is in @file{@value{path-g77}/lang-specs.h} that @samp{-fset-g77-defaults},
13790 @samp{-fversion}, and other options are passed, as appropriate,
13791 even when the user has not explicitly specified them.
13792 Other ``internal'' options such as @samp{-quiet} also
13793 are passed via this mechanism.
13794 @end table
13796 @node Projects
13797 @chapter Projects
13798 @cindex projects
13800 If you want to contribute to @code{g77} by doing research,
13801 design, specification, documentation, coding, or testing,
13802 the following information should give you some ideas.
13803 More relevant information might be available from
13804 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
13806 @menu
13807 * Efficiency::               Make @code{g77} itself compile code faster.
13808 * Better Optimization::      Teach @code{g77} to generate faster code.
13809 * Simplify Porting::         Make @code{g77} easier to configure, build,
13810                              and install.
13811 * More Extensions::          Features many users won't know to ask for.
13812 * Machine Model::            @code{g77} should better leverage @code{gcc}.
13813 * Internals Documentation::  Make maintenance easier.
13814 * Internals Improvements::   Make internals more robust.
13815 * Better Diagnostics::       Make using @code{g77} on new code easier.
13816 @end menu
13818 @node Efficiency
13819 @section Improve Efficiency
13820 @cindex efficiency
13822 Don't bother doing any performance analysis until most of the
13823 following items are taken care of, because there's no question
13824 they represent serious space/time problems, although some of
13825 them show up only given certain kinds of (popular) input.
13827 @itemize @bullet
13828 @item
13829 Improve @code{malloc} package and its uses to specify more info about
13830 memory pools and, where feasible, use obstacks to implement them.
13832 @item
13833 Skip over uninitialized portions of aggregate areas (arrays,
13834 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
13835 This would reduce memory usage for large initialized aggregate
13836 areas, even ones with only one initialized element.
13838 As of version 0.5.18, a portion of this item has already been
13839 accomplished.
13841 @item
13842 Prescan the statement (in @file{sta.c}) so that the nature of the statement
13843 is determined as much as possible by looking entirely at its form,
13844 and not looking at any context (previous statements, including types
13845 of symbols).
13846 This would allow ripping out of the statement-confirmation,
13847 symbol retraction/confirmation, and diagnostic inhibition
13848 mechanisms.
13849 Plus, it would result in much-improved diagnostics.
13850 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
13851 is not a subroutine intrinsic, would result actual error instead of the
13852 unimplemented-statement catch-all.
13854 @item
13855 Throughout @code{g77}, don't pass line/column pairs where
13856 a simple @code{ffewhere} type, which points to the error as much as is
13857 desired by the configuration, will do, and don't pass @code{ffelexToken} types
13858 where a simple @code{ffewhere} type will do.
13859 Then, allow new default
13860 configuration of @code{ffewhere} such that the source line text is not
13861 preserved, and leave it to things like Emacs' next-error function
13862 to point to them (now that @samp{next-error} supports column,
13863 or, perhaps, character-offset, numbers).
13864 The change in calling sequences should improve performance somewhat,
13865 as should not having to save source lines.
13866 (Whether this whole
13867 item will improve performance is questionable, but it should
13868 improve maintainability.)
13870 @item
13871 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
13872 as regards the assembly output.
13873 Some of this might require improving
13874 the back end, but lots of improvement in space/time required in @code{g77}
13875 itself can be fairly easily obtained without touching the back end.
13876 Maybe type-conversion, where necessary, can be speeded up as well in
13877 cases like the one shown (converting the @samp{2} into @samp{2.}).
13879 @item
13880 If analysis shows it to be worthwhile, optimize @file{lex.c}.
13882 @item
13883 Consider redesigning @file{lex.c} to not need any feedback
13884 during tokenization, by keeping track of enough parse state on its
13885 own.
13886 @end itemize
13888 @node Better Optimization
13889 @section Better Optimization
13890 @cindex optimization, better
13891 @cindex code generation, improving
13893 Much of this work should be put off until after @code{g77} has
13894 all the features necessary for its widespread acceptance as a
13895 useful F77 compiler.
13896 However, perhaps this work can be done in parallel during
13897 the feature-adding work.
13899 @itemize @bullet
13900 @item
13901 Do the equivalent of the trick of putting @samp{extern inline} in front
13902 of every function definition in @code{libg2c} and #include'ing the resulting
13903 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
13904 that are at all worth inlining.
13905 (Some of this has already been done, such as for integral exponentiation.)
13907 @item
13908 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
13909 and it's clear that types line up
13910 and @samp{CHAR_VAR} is addressable or not a @code{VAR_DECL},
13911 make @samp{CHAR_VAR}, not a
13912 temporary, be the receiver for @samp{CHAR_FUNC}.
13913 (This is now done for @code{COMPLEX} variables.)
13915 @item
13916 Design and implement Fortran-specific optimizations that don't
13917 really belong in the back end, or where the front end needs to
13918 give the back end more info than it currently does.
13920 @item
13921 Design and implement a new run-time library interface, with the
13922 code going into @code{libgcc} so no special linking is required to
13923 link Fortran programs using standard language features.
13924 This library
13925 would speed up lots of things, from I/O (using precompiled formats,
13926 doing just one, or, at most, very few, calls for arrays or array sections,
13927 and so on) to general computing (array/section implementations of
13928 various intrinsics, implementation of commonly performed loops that
13929 aren't likely to be optimally compiled otherwise, etc.).
13931 Among the important things the library would do are:
13933 @itemize @bullet
13934 @item
13935 Be a one-stop-shop-type
13936 library, hence shareable and usable by all, in that what are now
13937 library-build-time options in @code{libg2c} would be moved at least to the
13938 @code{g77} compile phase, if not to finer grains (such as choosing how
13939 list-directed I/O formatting is done by default at @code{OPEN} time, for
13940 preconnected units via options or even statements in the main program
13941 unit, maybe even on a per-I/O basis with appropriate pragma-like
13942 devices).
13943 @end itemize
13945 @item
13946 Probably requiring the new library design, change interface to
13947 normally have @code{COMPLEX} functions return their values in the way
13948 @code{gcc} would if they were declared @code{__complex__ float},
13949 rather than using
13950 the mechanism currently used by @code{CHARACTER} functions (whereby the
13951 functions are compiled as returning void and their first arg is
13952 a pointer to where to store the result).
13953 (Don't append underscores to
13954 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
13955 @code{gcc} rather than @code{f2c} calling conventions.)
13957 @item
13958 Do something useful with @code{doiter} references where possible.
13959 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
13960 a @code{DO} loop that uses @samp{I} as the
13961 iteration variable, and the back end might find that info useful
13962 in determining whether it needs to read @samp{I} back into a register after
13963 the call.
13964 (It normally has to do that, unless it knows @samp{FOO} never
13965 modifies its passed-by-reference argument, which is rarely the case
13966 for Fortran-77 code.)
13967 @end itemize
13969 @node Simplify Porting
13970 @section Simplify Porting
13971 @cindex porting, simplify
13972 @cindex simplify porting
13974 Making @code{g77} easier to configure, port, build, and install, either
13975 as a single-system compiler or as a cross-compiler, would be
13976 very useful.
13978 @itemize @bullet
13979 @item
13980 A new library (replacing @code{libg2c}) should improve portability as well as
13981 produce more optimal code.
13982 Further, @code{g77} and the new library should
13983 conspire to simplify naming of externals, such as by removing unnecessarily
13984 added underscores, and to reduce/eliminate the possibility of naming
13985 conflicts, while making debugger more straightforward.
13987 Also, it should
13988 make multi-language applications more feasible, such as by providing
13989 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
13990 descriptors.
13992 @item
13993 Possibly related to a new library, @code{g77} should produce the equivalent
13994 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
13995 main program unit, instead of compiling something that must be
13996 called by a library
13997 implementation of @code{main()}.
13999 This would do many useful things such as
14000 provide more flexibility in terms of setting up exception handling,
14001 not requiring programmers to start their debugging sessions with
14002 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
14004 @item
14005 The GBE needs to understand the difference between alignment
14006 requirements and desires.
14007 For example, on Intel x86 machines, @code{g77} currently imposes
14008 overly strict alignment requirements, due to the back end, but it
14009 would be useful for Fortran and C programmers to be able to override
14010 these @emph{recommendations} as long as they don't violate the actual
14011 processor @emph{requirements}.
14012 @end itemize
14014 @node More Extensions
14015 @section More Extensions
14016 @cindex extensions, more
14018 These extensions are not the sort of things users ask for ``by name'',
14019 but they might improve the usability of @code{g77}, and Fortran in
14020 general, in the long run.
14021 Some of these items really pertain to improving @code{g77} internals
14022 so that some popular extensions can be more easily supported.
14024 @itemize @bullet
14025 @item
14026 Look through all the documentation on the GNU Fortran language,
14027 dialects, compiler, missing features, bugs, and so on.
14028 Many mentions of incomplete or missing features are
14029 sprinkled throughout.
14030 It is not worth repeating them here.
14032 @item
14033 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
14034 named and unnamed.
14035 The idea is to provide a forward-looking, effective
14036 replacement for things like the old-style @code{PARAMETER} statement
14037 when people
14038 really need typelessness in a maintainable, portable, clearly documented
14039 way.
14040 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
14041 and whatever else might come along.
14042 (This is not really a call for polymorphism per se, just
14043 an ability to express limited, syntactic polymorphism.)
14045 @item
14046 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
14048 @item
14049 Support arbitrary file unit numbers, instead of limiting them
14050 to 0 through @samp{MXUNIT-1}.
14051 (This is a @code{libg2c} issue.)
14053 @item
14054 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
14055 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
14056 later @code{UNIT=} in the first example is invalid.
14057 Make sure this is what users of this feature would expect.
14059 @item
14060 Currently @code{g77} disallows @samp{READ(1'10)} since
14061 it is an obnoxious syntax, but
14062 supporting it might be pretty easy if needed.
14063 More details are needed, such
14064 as whether general expressions separated by an apostrophe are supported,
14065 or maybe the record number can be a general expression, and so on.
14067 @item
14068 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
14069 fully.
14070 Currently there is no support at all
14071 for @code{%FILL} in @code{STRUCTURE} and related syntax,
14072 whereas the rest of the
14073 stuff has at least some parsing support.
14074 This requires either major
14075 changes to @code{libg2c} or its replacement.
14077 @item
14078 F90 and @code{g77} probably disagree about label scoping relative to
14079 @code{INTERFACE} and @code{END INTERFACE}, and their contained
14080 procedure interface bodies (blocks?).
14082 @item
14083 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
14084 since that was added after S8.112.
14086 @item
14087 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
14088 with the final form of the standard (it was vague at S8.112).
14090 @item
14091 It seems to be an ``open'' question whether a file, immediately after being
14092 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
14093 might be nice to offer an option of opening to ``undefined'' status, requiring
14094 an explicit absolute-positioning operation to be performed before any
14095 other (besides @code{CLOSE}) to assist in making applications port to systems
14096 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
14097 @end itemize
14099 @node Machine Model
14100 @section Machine Model
14102 This items pertain to generalizing @code{g77}'s view of
14103 the machine model to more fully accept whatever the GBE
14104 provides it via its configuration.
14106 @itemize @bullet
14107 @item
14108 Switch to using @code{REAL_VALUE_TYPE} to represent floating-point constants
14109 exclusively so the target float format need not be required.
14110 This
14111 means changing the way @code{g77} handles initialization of aggregate areas
14112 having more than one type, such as @code{REAL} and @code{INTEGER},
14113 because currently
14114 it initializes them as if they were arrays of @code{char} and uses the
14115 bit patterns of the constants of the various types in them to determine
14116 what to stuff in elements of the arrays.
14118 @item
14119 Rely more and more on back-end info and capabilities, especially in the
14120 area of constants (where having the @code{g77} front-end's IL just store
14121 the appropriate tree nodes containing constants might be best).
14123 @item
14124 Suite of C and Fortran programs that a user/administrator can run on a
14125 machine to help determine the configuration for @code{g77} before building
14126 and help determine if the compiler works (especially with whatever
14127 libraries are installed) after building.
14128 @end itemize
14130 @node Internals Documentation
14131 @section Internals Documentation
14133 Better info on how @code{g77} works and how to port it is needed.
14134 Much of this should be done only after the redesign planned for
14135 0.6 is complete.
14137 @xref{Front End}, which contains some information
14138 on @code{g77} internals.
14140 @node Internals Improvements
14141 @section Internals Improvements
14143 Some more items that would make @code{g77} more reliable
14144 and easier to maintain:
14146 @itemize @bullet
14147 @item
14148 Generally make expression handling focus
14149 more on critical syntax stuff, leaving semantics to callers.
14150 For example,
14151 anything a caller can check, semantically, let it do so, rather
14152 than having @file{expr.c} do it.
14153 (Exceptions might include things like
14154 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
14155 it seems
14156 important to preserve the left-to-right-in-source order of production
14157 of diagnostics.)
14159 @item
14160 Come up with better naming conventions for @samp{-D} to establish requirements
14161 to achieve desired implementation dialect via @file{proj.h}.
14163 @item
14164 Clean up used tokens and @code{ffewhere}s in @code{ffeglobal_terminate_1}.
14166 @item
14167 Replace @file{sta.c} @code{outpooldisp} mechanism with @code{malloc_pool_use}.
14169 @item
14170 Check for @code{opANY} in more places in @file{com.c}, @file{std.c},
14171 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
14172 (after determining if there is indeed no real need for it).
14174 @item
14175 Utility to read and check @file{bad.def} messages and their references in the
14176 code, to make sure calls are consistent with message templates.
14178 @item
14179 Search and fix @samp{&ffe@dots{}} and similar so that
14180 @samp{ffe@dots{}ptr@dots{}} macros are
14181 available instead (a good argument for wishing this could have written all
14182 this stuff in C++, perhaps).
14183 On the other hand, it's questionable whether this sort of
14184 improvement is really necessary, given the availability of
14185 tools such as Emacs and Perl, which make finding any
14186 address-taking of structure members easy enough?
14188 @item
14189 Some modules truly export the member names of their structures (and the
14190 structures themselves), maybe fix this, and fix other modules that just
14191 appear to as well (by appending @samp{_}, though it'd be ugly and probably
14192 not worth the time).
14194 @item
14195 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
14196 in @file{proj.h}
14197 and use them throughout @code{g77} source code (especially in the definitions
14198 of access macros in @samp{.h} files) so they can be tailored
14199 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
14201 @item
14202 Decorate throughout with @code{const} and other such stuff.
14204 @item
14205 All F90 notational derivations in the source code are still based
14206 on the S8.112 version of the draft standard.
14207 Probably should update
14208 to the official standard, or put documentation of the rules as used
14209 in the code@dots{}uh@dots{}in the code.
14211 @item
14212 Some @code{ffebld_new} calls (those outside of @file{ffeexpr.c} or
14213 inside but invoked via paths not involving @code{ffeexpr_lhs} or
14214 @code{ffeexpr_rhs}) might be creating things
14215 in improper pools, leading to such things staying around too long or
14216 (doubtful, but possible and dangerous) not long enough.
14218 @item
14219 Some @code{ffebld_list_new} (or whatever) calls might not be matched by
14220 @code{ffebld_list_bottom} (or whatever) calls, which might someday matter.
14221 (It definitely is not a problem just yet.)
14223 @item
14224 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
14225 due to alignment/mismatch or other problems---they end up without
14226 @code{ffestorag} objects, so maybe the backend (and other parts of the front
14227 end) can notice that and handle like an @code{opANY} (do what it wants, just
14228 don't complain or crash).
14229 Most of this seems to have been addressed
14230 by now, but a code review wouldn't hurt.
14231 @end itemize
14233 @node Better Diagnostics
14234 @section Better Diagnostics
14236 These are things users might not ask about, or that need to
14237 be looked into, before worrying about.
14238 Also here are items that involve reducing unnecessary diagnostic
14239 clutter.
14241 @itemize @bullet
14242 @item
14243 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
14244 lengths, type classes, and so on),
14245 @code{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
14246 it specifies.
14248 @item
14249 Speed up and improve error handling for data when repeat-count is
14250 specified.
14251 For example, don't output 20 unnecessary messages after the
14252 first necessary one for:
14254 @smallexample
14255 INTEGER X(20)
14256 CONTINUE
14257 DATA (X(I), J= 1, 20) /20*5/
14259 @end smallexample
14261 @noindent
14262 (The @code{CONTINUE} statement ensures the @code{DATA} statement
14263 is processed in the context of executable, not specification,
14264 statements.)
14265 @end itemize
14267 @include ffe.texi
14269 @end ifset
14271 @ifset USING
14272 @node Diagnostics
14273 @chapter Diagnostics
14274 @cindex diagnostics
14276 Some diagnostics produced by @code{g77} require sufficient explanation
14277 that the explanations are given below, and the diagnostics themselves
14278 identify the appropriate explanation.
14280 Identification uses the GNU Info format---specifically, the @code{info}
14281 command that displays the explanation is given within square
14282 brackets in the diagnostic.
14283 For example:
14285 @smallexample
14286 foo.f:5: Invalid statement [info -f g77 M FOOEY]
14287 @end smallexample
14289 More details about the above diagnostic is found in the @code{g77} Info
14290 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
14291 which is displayed by typing the UNIX command
14292 @samp{info -f g77 M FOOEY}.
14294 Other Info readers, such as EMACS, may be just as easily used to display
14295 the pertinent node.
14296 In the above example, @samp{g77} is the Info document name,
14297 @samp{M} is the top-level menu item to select,
14298 and, in that node (named @samp{Diagnostics}, the name of
14299 this chapter, which is the very text you're reading now),
14300 @samp{FOOEY} is the menu item to select.
14302 @iftex
14303 In this printed version of the @code{g77} manual, the above example
14304 points to a section, below, entitled @samp{FOOEY}---though, of course,
14305 as the above is just a sample, no such section exists.
14306 @end iftex
14308 @menu
14309 * CMPAMBIG::    Ambiguous use of intrinsic.
14310 * EXPIMP::      Intrinsic used explicitly and implicitly.
14311 * INTGLOB::     Intrinsic also used as name of global.
14312 * LEX::         Various lexer messages
14313 * GLOBALS::     Disagreements about globals.
14314 * LINKFAIL::    When linking @code{f771} fails.
14315 * Y2KBAD::      Use of non-Y2K-compliant intrinsic.
14316 @end menu
14318 @node CMPAMBIG
14319 @section @code{CMPAMBIG}
14321 @noindent
14322 @smallexample
14323 Ambiguous use of intrinsic @var{intrinsic} @dots{}
14324 @end smallexample
14326 The type of the argument to the invocation of the @var{intrinsic}
14327 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
14328 Typically, it is @code{COMPLEX(KIND=2)}, also known as
14329 @code{DOUBLE COMPLEX}.
14331 The interpretation of this invocation depends on the particular
14332 dialect of Fortran for which the code was written.
14333 Some dialects convert the real part of the argument to
14334 @code{REAL(KIND=1)}, thus losing precision; other dialects,
14335 and Fortran 90, do no such conversion.
14337 So, GNU Fortran rejects such invocations except under certain
14338 circumstances, to avoid making an incorrect assumption that results
14339 in generating the wrong code.
14341 To determine the dialect of the program unit, perhaps even whether
14342 that particular invocation is properly coded, determine how the
14343 result of the intrinsic is used.
14345 The result of @var{intrinsic} is expected (by the original programmer)
14346 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
14348 @itemize @bullet
14349 @item
14350 It is passed as an argument to a procedure that explicitly or
14351 implicitly declares that argument @code{REAL(KIND=1)}.
14353 For example,
14354 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
14355 statement specifying the dummy argument corresponding to an
14356 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14357 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14358 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
14359 of @code{REAL(KIND=2)}.
14361 @item
14362 It is used in a context that would otherwise not include
14363 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
14364 invocation as @code{REAL(KIND=2)} would result in unnecessary
14365 promotions and (typically) more expensive operations on the
14366 wider type.
14368 For example:
14370 @smallexample
14371 DOUBLE COMPLEX Z
14372 @dots{}
14373 R(1) = T * REAL(Z)
14374 @end smallexample
14376 The above example suggests the programmer expected the real part
14377 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
14378 multiplied by @samp{T} (presumed, along with @samp{R} above, to
14379 be type @code{REAL(KIND=1)}).
14381 Otherwise, the conversion would have to be delayed until after
14382 the multiplication, requiring not only an extra conversion
14383 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
14384 expensive multiplication (a double-precision multiplication instead
14385 of a single-precision one).
14386 @end itemize
14388 The result of @var{intrinsic} is expected (by the original programmer)
14389 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
14391 @itemize @bullet
14392 @item
14393 It is passed as an argument to a procedure that explicitly or
14394 implicitly declares that argument @code{REAL(KIND=2)}.
14396 For example, a procedure specifying a @code{DOUBLE PRECISION}
14397 dummy argument corresponding to an
14398 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14399 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14400 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
14401 of @code{REAL(KIND=1)}.
14403 @item
14404 It is used in an expression context that includes
14405 other @code{REAL(KIND=2)} operands,
14406 or is assigned to a @code{REAL(KIND=2)} variable or array element.
14408 For example:
14410 @smallexample
14411 DOUBLE COMPLEX Z
14412 DOUBLE PRECISION R, T
14413 @dots{}
14414 R(1) = T * REAL(Z)
14415 @end smallexample
14417 The above example suggests the programmer expected the real part
14418 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
14419 by the @code{REAL()} intrinsic.
14421 Otherwise, the conversion would have to be immediately followed
14422 by a conversion back to @code{REAL(KIND=2)}, losing
14423 the original, full precision of the real part of @code{Z},
14424 before being multiplied by @samp{T}.
14425 @end itemize
14427 Once you have determined whether a particular invocation of @var{intrinsic}
14428 expects the Fortran 90 interpretation, you can:
14430 @itemize @bullet
14431 @item
14432 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
14433 @code{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
14434 is @code{AIMAG})
14435 if it expected the Fortran 90 interpretation.
14437 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
14438 some other type, such as @code{COMPLEX*32}, you should use the
14439 appropriate intrinsic, such as the one to convert to @code{REAL*16}
14440 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
14441 @code{QIMAG()} in place of @code{DIMAG()}).
14443 @item
14444 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
14445 otherwise.
14446 This converts to @code{REAL(KIND=1)} in all working
14447 Fortran compilers.
14448 @end itemize
14450 If you don't want to change the code, and you are certain that all
14451 ambiguous invocations of @var{intrinsic} in the source file have
14452 the same expectation regarding interpretation, you can:
14454 @itemize @bullet
14455 @item
14456 Compile with the @code{g77} option @samp{-ff90}, to enable the
14457 Fortran 90 interpretation.
14459 @item
14460 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
14461 to enable the non-Fortran-90 interpretations.
14462 @end itemize
14464 @xref{REAL() and AIMAG() of Complex}, for more information on this
14465 issue.
14467 Note: If the above suggestions don't produce enough evidence
14468 as to whether a particular program expects the Fortran 90
14469 interpretation of this ambiguous invocation of @var{intrinsic},
14470 there is one more thing you can try.
14472 If you have access to most or all the compilers used on the
14473 program to create successfully tested and deployed executables,
14474 read the documentation for, and @emph{also} test out, each compiler
14475 to determine how it treats the @var{intrinsic} intrinsic in
14476 this case.
14477 (If all the compilers don't agree on an interpretation, there
14478 might be lurking bugs in the deployed versions of the program.)
14480 The following sample program might help:
14482 @cindex JCB003 program
14483 @smallexample
14484       PROGRAM JCB003
14486 C Written by James Craig Burley 1997-02-23.
14488 C Determine how compilers handle non-standard REAL
14489 C and AIMAG on DOUBLE COMPLEX operands.
14491       DOUBLE COMPLEX Z
14492       REAL R
14493       Z = (3.3D0, 4.4D0)
14494       R = Z
14495       CALL DUMDUM(Z, R)
14496       R = REAL(Z) - R
14497       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
14498       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
14499       R = 4.4D0
14500       CALL DUMDUM(Z, R)
14501       R = AIMAG(Z) - R
14502       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
14503       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
14504       END
14506 C Just to make sure compiler doesn't use naive flow
14507 C analysis to optimize away careful work above,
14508 C which might invalidate results....
14510       SUBROUTINE DUMDUM(Z, R)
14511       DOUBLE COMPLEX Z
14512       REAL R
14513       END
14514 @end smallexample
14516 If the above program prints contradictory results on a
14517 particular compiler, run away!
14519 @node EXPIMP
14520 @section @code{EXPIMP}
14522 @noindent
14523 @smallexample
14524 Intrinsic @var{intrinsic} referenced @dots{}
14525 @end smallexample
14527 The @var{intrinsic} is explicitly declared in one program
14528 unit in the source file and implicitly used as an intrinsic
14529 in another program unit in the same source file.
14531 This diagnostic is designed to catch cases where a program
14532 might depend on using the name @var{intrinsic} as an intrinsic
14533 in one program unit and as a global name (such as the name
14534 of a subroutine or function) in another, but @code{g77} recognizes
14535 the name as an intrinsic in both cases.
14537 After verifying that the program unit making implicit use
14538 of the intrinsic is indeed written expecting the intrinsic,
14539 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14540 program unit to prevent this warning.
14542 This and related warnings are disabled by using
14543 the @samp{-Wno-globals} option when compiling.
14545 Note that this warning is not issued for standard intrinsics.
14546 Standard intrinsics include those described in the FORTRAN 77
14547 standard and, if @samp{-ff90} is specified, those described
14548 in the Fortran 90 standard.
14549 Such intrinsics are not as likely to be confused with user
14550 procedures as intrinsics provided as extensions to the
14551 standard by @code{g77}.
14553 @node INTGLOB
14554 @section @code{INTGLOB}
14556 @noindent
14557 @smallexample
14558 Same name `@var{intrinsic}' given @dots{}
14559 @end smallexample
14561 The name @var{intrinsic} is used for a global entity (a common
14562 block or a program unit) in one program unit and implicitly
14563 used as an intrinsic in another program unit.
14565 This diagnostic is designed to catch cases where a program
14566 intends to use a name entirely as a global name, but @code{g77}
14567 recognizes the name as an intrinsic in the program unit that
14568 references the name, a situation that would likely produce
14569 incorrect code.
14571 For example:
14573 @smallexample
14574 INTEGER FUNCTION TIME()
14575 @dots{}
14577 @dots{}
14578 PROGRAM SAMP
14579 INTEGER TIME
14580 PRINT *, 'Time is ', TIME()
14582 @end smallexample
14584 The above example defines a program unit named @samp{TIME}, but
14585 the reference to @samp{TIME} in the main program unit @samp{SAMP}
14586 is normally treated by @code{g77} as a reference to the intrinsic
14587 @code{TIME()} (unless a command-line option that prevents such
14588 treatment has been specified).
14590 As a result, the program @samp{SAMP} will @emph{not}
14591 invoke the @samp{TIME} function in the same source file.
14593 Since @code{g77} recognizes @code{libU77} procedures as
14594 intrinsics, and since some existing code uses the same names
14595 for its own procedures as used by some @code{libU77}
14596 procedures, this situation is expected to arise often enough
14597 to make this sort of warning worth issuing.
14599 After verifying that the program unit making implicit use
14600 of the intrinsic is indeed written expecting the intrinsic,
14601 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14602 program unit to prevent this warning.
14604 Or, if you believe the program unit is designed to invoke the
14605 program-defined procedure instead of the intrinsic (as
14606 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
14607 statement to the program unit that references the name to
14608 prevent this warning.
14610 This and related warnings are disabled by using
14611 the @samp{-Wno-globals} option when compiling.
14613 Note that this warning is not issued for standard intrinsics.
14614 Standard intrinsics include those described in the FORTRAN 77
14615 standard and, if @samp{-ff90} is specified, those described
14616 in the Fortran 90 standard.
14617 Such intrinsics are not as likely to be confused with user
14618 procedures as intrinsics provided as extensions to the
14619 standard by @code{g77}.
14621 @node LEX
14622 @section @code{LEX}
14624 @noindent
14625 @smallexample
14626 Unrecognized character @dots{}
14627 Invalid first character @dots{}
14628 Line too long @dots{}
14629 Non-numeric character @dots{}
14630 Continuation indicator @dots{}
14631 Label at @dots{} invalid with continuation line indicator @dots{}
14632 Character constant @dots{}
14633 Continuation line @dots{}
14634 Statement at @dots{} begins with invalid token
14635 @end smallexample
14637 Although the diagnostics identify specific problems, they can
14638 be produced when general problems such as the following occur:
14640 @itemize @bullet
14641 @item
14642 The source file contains something other than Fortran code.
14644 If the code in the file does not look like many of the examples
14645 elsewhere in this document, it might not be Fortran code.
14646 (Note that Fortran code often is written in lower case letters,
14647 while the examples in this document use upper case letters,
14648 for stylistic reasons.)
14650 For example, if the file contains lots of strange-looking
14651 characters, it might be APL source code; if it contains lots
14652 of parentheses, it might be Lisp source code; if it
14653 contains lots of bugs, it might be C++ source code.
14655 @item
14656 The source file contains free-form Fortran code, but @samp{-ffree-form}
14657 was not specified on the command line to compile it.
14659 Free form is a newer form for Fortran code.
14660 The older, classic form is called fixed form.
14662 @cindex continuation character
14663 @cindex characters, continuation
14664 Fixed-form code is visually fairly distinctive, because
14665 numerical labels and comments are all that appear in
14666 the first five columns of a line, the sixth column is
14667 reserved to denote continuation lines,
14668 and actual statements start at or beyond column 7.
14669 Spaces generally are not significant, so if you
14670 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
14671 you are looking at fixed-form code.
14672 @cindex *
14673 @cindex asterisk
14674 Comment lines are indicated by the letter @samp{C} or the symbol
14675 @samp{*} in column 1.
14676 @cindex trailing comment
14677 @cindex comment
14678 @cindex characters, comment
14679 @cindex !
14680 @cindex exclamation point
14681 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
14682 which many compilers support.)
14684 Free-form code is distinguished from fixed-form source
14685 primarily by the fact that statements may start anywhere.
14686 (If lots of statements start in columns 1 through 6,
14687 that's a strong indicator of free-form source.)
14688 Consecutive keywords must be separated by spaces, so
14689 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
14690 There are no comment lines per se, but @samp{!} starts a
14691 comment anywhere in a line (other than within a character or
14692 Hollerith constant).
14694 @xref{Source Form}, for more information.
14696 @item
14697 The source file is in fixed form and has been edited without
14698 sensitivity to the column requirements.
14700 Statements in fixed-form code must be entirely contained within
14701 columns 7 through 72 on a given line.
14702 Starting them ``early'' is more likely to result in diagnostics
14703 than finishing them ``late'', though both kinds of errors are
14704 often caught at compile time.
14706 For example, if the following code fragment is edited by following
14707 the commented instructions literally, the result, shown afterward,
14708 would produce a diagnostic when compiled:
14710 @smallexample
14711 C On XYZZY systems, remove "C" on next line:
14712 C     CALL XYZZY_RESET
14713 @end smallexample
14715 The result of editing the above line might be:
14717 @smallexample
14718 C On XYZZY systems, remove "C" on next line:
14719      CALL XYZZY_RESET
14720 @end smallexample
14722 However, that leaves the first @samp{C} in the @code{CALL}
14723 statement in column 6, making it a comment line, which is
14724 not really what the author intended, and which is likely
14725 to result in one of the above-listed diagnostics.
14727 @emph{Replacing} the @samp{C} in column 1 with a space
14728 is the proper change to make, to ensure the @code{CALL}
14729 keyword starts in or after column 7.
14731 Another common mistake like this is to forget that fixed-form
14732 source lines are significant through only column 72, and that,
14733 normally, any text beyond column 72 is ignored or is diagnosed
14734 at compile time.
14736 @xref{Source Form}, for more information.
14738 @item
14739 The source file requires preprocessing, and the preprocessing
14740 is not being specified at compile time.
14742 A source file containing lines beginning with @code{#define},
14743 @code{#include}, @code{#if}, and so on is likely one that
14744 requires preprocessing.
14746 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
14747 the file normally will be compiled @emph{without} preprocessing
14748 by @code{g77}.
14750 Change the file's suffix from @samp{.f} to @samp{.F}
14751 (or, on systems with case-insensitive file names,
14752 to @samp{.fpp} or @samp{.FPP}),
14753 from @samp{.for} to @samp{.fpp},
14754 or from @samp{.FOR} to @samp{.FPP}.
14755 @code{g77} compiles files with such names @emph{with}
14756 preprocessing.
14758 @pindex cpp
14759 @cindex preprocessor
14760 @cindex cpp program
14761 @cindex programs, cpp
14762 @cindex @samp{-x f77-cpp-input} option
14763 @cindex options, @samp{-x f77-cpp-input}
14764 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
14765 the language @samp{f77-cpp-input} for Fortran files that
14766 require preprocessing.
14767 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
14769 @item
14770 The source file is preprocessed, and the results of preprocessing
14771 result in syntactic errors that are not necessarily obvious to
14772 someone examining the source file itself.
14774 Examples of errors resulting from preprocessor macro expansion
14775 include exceeding the line-length limit, improperly starting,
14776 terminating, or incorporating the apostrophe or double-quote in
14777 a character constant, improperly forming a Hollerith constant,
14778 and so on.
14780 @xref{Overall Options,,Options Controlling the Kind of Output},
14781 for suggestions about how to use, and not use, preprocessing
14782 for Fortran code.
14783 @end itemize
14785 @node GLOBALS
14786 @section @code{GLOBALS}
14788 @noindent
14789 @smallexample
14790 Global name @var{name} defined at @dots{} already defined@dots{}
14791 Global name @var{name} at @dots{} has different type@dots{}
14792 Too many arguments passed to @var{name} at @dots{}
14793 Too few arguments passed to @var{name} at @dots{}
14794 Argument #@var{n} of @var{name} is @dots{}
14795 @end smallexample
14797 These messages all identify disagreements about the
14798 global procedure named @var{name} among different program units
14799 (usually including @var{name} itself).
14801 Whether a particular disagreement is reported
14802 as a warning or an error
14803 can depend on the relative order
14804 of the disagreeing portions of the source file.
14806 Disagreements between a procedure invocation
14807 and the @emph{subsequent} procedure itself
14808 are, usually, diagnosed as errors
14809 when the procedure itself @emph{precedes} the invocation.
14810 Other disagreements are diagnosed via warnings.
14812 @cindex forward references
14813 @cindex in-line code
14814 @cindex compilation, in-line
14815 This distinction, between warnings and errors,
14816 is due primarily to the present tendency of the @code{gcc} back end
14817 to inline only those procedure invocations that are
14818 @emph{preceded} by the corresponding procedure definitions.
14819 If the @code{gcc} back end is changed
14820 to inline ``forward references'',
14821 in which invocations precede definitions,
14822 the @code{g77} front end will be changed
14823 to treat both orderings as errors, accordingly.
14825 The sorts of disagreements that are diagnosed by @code{g77} include
14826 whether a procedure is a subroutine or function;
14827 if it is a function, the type of the return value of the procedure;
14828 the number of arguments the procedure accepts;
14829 and the type of each argument.
14831 Disagreements regarding global names among program units
14832 in a Fortran program @emph{should} be fixed in the code itself.
14833 However, if that is not immediately practical,
14834 and the code has been working for some time,
14835 it is possible it will work
14836 when compiled with the @samp{-fno-globals} option.
14838 The @samp{-fno-globals} option
14839 causes these diagnostics to all be warnings
14840 and disables all inlining of references to global procedures
14841 (to avoid subsequent compiler crashes and bad-code generation).
14842 Use of the @samp{-Wno-globals} option as well as @samp{-fno-globals}
14843 suppresses all of these diagnostics.
14844 (@samp{-Wno-globals} by itself disables only the warnings,
14845 not the errors.)
14847 After using @samp{-fno-globals} to work around these problems,
14848 it is wise to stop using that option and address them by fixing
14849 the Fortran code, because such problems, while they might not
14850 actually result in bugs on some systems, indicate that the code
14851 is not as portable as it could be.
14852 In particular, the code might appear to work on a particular
14853 system, but have bugs that affect the reliability of the data
14854 without exhibiting any other outward manifestations of the bugs.
14856 @node LINKFAIL
14857 @section @code{LINKFAIL}
14859 @noindent
14860 @smallexample
14861 If the above command failed due to an unresolved reference
14862 to strtoul, _strtoul, bsearch, _bsearch, or similar, see
14863 [info -f g77 M LINKFAIL] (a node in the g77 documentation)
14864 for information on what causes this, how to work around
14865 the problem by editing $@{srcdir@}/proj.c, and what else to do.
14866 @end smallexample
14868 @xref{Missing strtoul or bsearch}, for more information on
14869 this problem,
14870 which occurs only in releases of @code{g77}
14871 based on @code{gcc}.
14872 (It did not occur in @code{egcs}.)
14874 On AIX 4.1, @code{g77} might not build with the native (non-GNU) tools
14875 due to a linker bug in coping with the @samp{-bbigtoc} option which
14876 leads to a @samp{Relocation overflow} error.  The GNU linker is not
14877 recommended on current AIX versions, though; it was developed under a
14878 now-unsupported version.  This bug is said to be fixed by `update PTF
14879 U455193 for APAR IX75823'.
14881 Compiling with @samp{-mminimal-toc}
14882 might solve this problem, e.g.@: by adding
14883 @smallexample
14884 BOOT_CFLAGS='-mminimal-toc -O2 -g'
14885 @end smallexample
14886 to the @code{make bootstrap} command line.
14888 @node Y2KBAD
14889 @section @code{Y2KBAD}
14890 @cindex Y2K compliance
14891 @cindex Year 2000 compliance
14893 @noindent
14894 @smallexample
14895 Intrinsic `@var{name}', invoked at (^), known to be non-Y2K-compliant@dots{}
14896 @end smallexample
14898 This diagnostic indicates that
14899 the specific intrinsic invoked by the name @var{name}
14900 is known to have an interface
14901 that is not Year-2000 (Y2K) compliant.
14903 @xref{Year 2000 (Y2K) Problems}.
14905 @end ifset
14907 @node Index
14908 @unnumbered Index
14910 @printindex cp
14911 @bye