d2f3d995c0e3fe2631f9c2bd9e2c9abaadb885ec
[gcc.git] / gcc / f / g77.texi
1 \input texinfo @c -*-texinfo-*-
2 @c fix @set inside @example:
3 @tex
4 \gdef\set{\begingroup\catcode` =10 \parsearg\setxxx}
5 \gdef\setyyy#1 #2\endsetyyy{%
6 \def\temp{#2}%
7 \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty
8 \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted.
9 \fi
10 \endgroup
11 }
12 @end tex
13
14 @c %**start of header
15 @setfilename g77.info
16 @c @setfilename useg77.info
17 @c @setfilename portg77.info
18 @c To produce the full manual, use the "g77.info" setfilename, and
19 @c make sure the following do NOT begin with '@c' (and the @clear lines DO)
20 @set INTERNALS
21 @set USING
22 @c To produce a user-only manual, use the "useg77.info" setfilename, and
23 @c make sure the following does NOT begin with '@c':
24 @c @clear INTERNALS
25 @c To produce a porter-only manual, use the "portg77.info" setfilename,
26 @c and make sure the following does NOT begin with '@c':
27 @c @clear USING
28
29 @c (For FSF printing, turn on smallbook; that is all that is needed.)
30
31 @c smallbook
32
33 @ifset INTERNALS
34 @ifset USING
35 @settitle Using and Porting GNU Fortran
36 @end ifset
37 @end ifset
38 @c seems reasonable to assume at least one of INTERNALS or USING is set...
39 @ifclear INTERNALS
40 @settitle Using GNU Fortran
41 @end ifclear
42 @ifclear USING
43 @settitle Porting GNU Fortran
44 @end ifclear
45 @c then again, have some fun
46 @ifclear INTERNALS
47 @ifclear USING
48 @settitle Doing Squat with GNU Fortran
49 @end ifclear
50 @end ifclear
51
52 @syncodeindex fn cp
53 @syncodeindex vr cp
54 @c %**end of header
55 @setchapternewpage odd
56
57 @ifinfo
58 This file explains how to use the GNU Fortran system.
59
60 Published by the Free Software Foundation
61 59 Temple Place - Suite 330
62 Boston, MA 02111-1307 USA
63
64 Copyright (C) 1995-1997 Free Software Foundation, Inc.
65
66 Permission is granted to make and distribute verbatim copies of
67 this manual provided the copyright notice and this permission notice
68 are preserved on all copies.
69
70 @ignore
71 Permission is granted to process this file through Tex and print the
72 results, provided the printed document carries copying permission
73 notice identical to this one except for the removal of this paragraph
74 (this paragraph not being relevant to the printed manual).
75
76 @end ignore
77 Permission is granted to copy and distribute modified versions of this
78 manual under the conditions for verbatim copying, provided also that the
79 sections entitled ``GNU General Public License,'' ``Funding for Free
80 Software,'' and ``Protect Your Freedom---Fight `Look And Feel'@w{}'' are
81 included exactly as in the original, and provided that the entire
82 resulting derived work is distributed under the terms of a permission
83 notice identical to this one.
84
85 Permission is granted to copy and distribute translations of this manual
86 into another language, under the above conditions for modified versions,
87 except that the sections entitled ``GNU General Public License,''
88 ``Funding for Free Software,'' and ``Protect Your Freedom---Fight `Look
89 And Feel'@w{}'', and this permission notice, may be included in
90 translations approved by the Free Software Foundation instead of in the
91 original English.
92 @end ifinfo
93
94 Contributed by James Craig Burley (@email{burley@@gnu.org}).
95 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
96 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
97
98 @finalout
99 @titlepage
100 @comment The title is printed in a large font.
101 @center @titlefont{Using GNU Fortran}
102 @sp 2
103 @center James Craig Burley
104 @sp 3
105 @center Last updated 1997-09-09
106 @sp 1
107 @c The version number appears some more times in this file.
108
109 @center for version 0.5.21
110 @page
111 @vskip 0pt plus 1filll
112 Copyright @copyright{} 1995-1997 Free Software Foundation, Inc.
113 @sp 2
114 For GNU Fortran Version 0.5.21*
115 @sp 1
116 Published by the Free Software Foundation @*
117 59 Temple Place - Suite 330@*
118 Boston, MA 02111-1307, USA@*
119 @c Last printed ??ber, 19??.@*
120 @c Printed copies are available for $? each.@*
121 @c ISBN ???
122 @sp 1
123 Permission is granted to make and distribute verbatim copies of
124 this manual provided the copyright notice and this permission notice
125 are preserved on all copies.
126
127 Permission is granted to copy and distribute modified versions of this
128 manual under the conditions for verbatim copying, provided also that the
129 sections entitled ``GNU General Public License,'' ``Funding for Free
130 Software,'' and ``Protect Your Freedom---Fight `Look And Feel'@w{}'' are
131 included exactly as in the original, and provided that the entire
132 resulting derived work is distributed under the terms of a permission
133 notice identical to this one.
134
135 Permission is granted to copy and distribute translations of this manual
136 into another language, under the above conditions for modified versions,
137 except that the sections entitled ``GNU General Public License,''
138 ``Funding for Free Software,'' and ``Protect Your Freedom---Fight `Look
139 And Feel'@w{}'', and this permission notice, may be included in
140 translations approved by the Free Software Foundation instead of in the
141 original English.
142 @end titlepage
143 @page
144
145 @ifinfo
146
147 @dircategory Fortran Programming
148 @direntry
149 * g77: (g77). The GNU Fortran compilation system.
150 @end direntry
151 @node Top, Copying,, (DIR)
152 @top Introduction
153 @cindex Introduction
154
155 @ifset INTERNALS
156 @ifset USING
157 This manual documents how to run, install and port the GNU Fortran
158 compiler, as well as its new features and incompatibilities, and how to
159 report bugs. It corresponds to GNU Fortran version 0.5.21.
160 @end ifset
161 @end ifset
162
163 @ifclear INTERNALS
164 This manual documents how to run and install the GNU Fortran compiler,
165 as well as its new features and incompatibilities, and how to report
166 bugs. It corresponds to GNU Fortran version 0.5.21.
167 @end ifclear
168 @ifclear USING
169 This manual documents how to port the GNU Fortran compiler,
170 as well as its new features and incompatibilities, and how to report
171 bugs. It corresponds to GNU Fortran version 0.5.21.
172 @end ifclear
173
174 @end ifinfo
175 @menu
176 * Copying:: GNU General Public License says
177 how you can copy and share GNU Fortran.
178 * Contributors:: People who have contributed to GNU Fortran.
179 * Funding:: How to help assure continued work for free software.
180 * Funding GNU Fortran:: How to help assure continued work on GNU Fortran.
181 * Look and Feel:: Protect your freedom---fight ``look and feel''.
182 @ifset USING
183 * Getting Started:: Finding your way around this manual.
184 * What is GNU Fortran?:: How @code{g77} fits into the universe.
185 * G77 and GCC:: You can compile Fortran, C, or other programs.
186 * Invoking G77:: Command options supported by @code{g77}.
187 * News:: News about recent releases of @code{g77}.
188 * Changes:: User-visible changes to recent releases of @code{g77}.
189 * Language:: The GNU Fortran language.
190 * Compiler:: The GNU Fortran compiler.
191 * Other Dialects:: Dialects of Fortran supported by @code{g77}.
192 * Other Compilers:: Fortran compilers other than @code{g77}.
193 * Other Languages:: Languages other than Fortran.
194 * Installation:: How to configure, compile and install GNU Fortran.
195 * Debugging and Interfacing:: How @code{g77} generates code.
196 * Collected Fortran Wisdom:: How to avoid Trouble.
197 * Trouble:: If you have trouble with GNU Fortran.
198 * Open Questions:: Things we'd like to know.
199 * Bugs:: How, why, and where to report bugs.
200 * Service:: How to find suppliers of support for GNU Fortran.
201 @end ifset
202 @ifset INTERNALS
203 * Adding Options:: Guidance on teaching @code{g77} about new options.
204 * Projects:: Projects for @code{g77} internals hackers.
205 @end ifset
206
207 * M: Diagnostics. Diagnostics produced by @code{g77}.
208
209 * Index:: Index of concepts and symbol names.
210 @end menu
211 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
212
213 @node Copying
214 @unnumbered GNU GENERAL PUBLIC LICENSE
215 @center Version 2, June 1991
216
217 @display
218 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
219 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
220
221 Everyone is permitted to copy and distribute verbatim copies
222 of this license document, but changing it is not allowed.
223 @end display
224
225 @unnumberedsec Preamble
226
227 The licenses for most software are designed to take away your
228 freedom to share and change it. By contrast, the GNU General Public
229 License is intended to guarantee your freedom to share and change free
230 software---to make sure the software is free for all its users. This
231 General Public License applies to most of the Free Software
232 Foundation's software and to any other program whose authors commit to
233 using it. (Some other Free Software Foundation software is covered by
234 the GNU Library General Public License instead.) You can apply it to
235 your programs, too.
236
237 When we speak of free software, we are referring to freedom, not
238 price. Our General Public Licenses are designed to make sure that you
239 have the freedom to distribute copies of free software (and charge for
240 this service if you wish), that you receive source code or can get it
241 if you want it, that you can change the software or use pieces of it
242 in new free programs; and that you know you can do these things.
243
244 To protect your rights, we need to make restrictions that forbid
245 anyone to deny you these rights or to ask you to surrender the rights.
246 These restrictions translate to certain responsibilities for you if you
247 distribute copies of the software, or if you modify it.
248
249 For example, if you distribute copies of such a program, whether
250 gratis or for a fee, you must give the recipients all the rights that
251 you have. You must make sure that they, too, receive or can get the
252 source code. And you must show them these terms so they know their
253 rights.
254
255 We protect your rights with two steps: (1) copyright the software, and
256 (2) offer you this license which gives you legal permission to copy,
257 distribute and/or modify the software.
258
259 Also, for each author's protection and ours, we want to make certain
260 that everyone understands that there is no warranty for this free
261 software. If the software is modified by someone else and passed on, we
262 want its recipients to know that what they have is not the original, so
263 that any problems introduced by others will not reflect on the original
264 authors' reputations.
265
266 Finally, any free program is threatened constantly by software
267 patents. We wish to avoid the danger that redistributors of a free
268 program will individually obtain patent licenses, in effect making the
269 program proprietary. To prevent this, we have made it clear that any
270 patent must be licensed for everyone's free use or not licensed at all.
271
272 The precise terms and conditions for copying, distribution and
273 modification follow.
274
275 @iftex
276 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
277 @end iftex
278 @ifinfo
279 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
280 @end ifinfo
281
282 @enumerate 0
283 @item
284 This License applies to any program or other work which contains
285 a notice placed by the copyright holder saying it may be distributed
286 under the terms of this General Public License. The ``Program'', below,
287 refers to any such program or work, and a ``work based on the Program''
288 means either the Program or any derivative work under copyright law:
289 that is to say, a work containing the Program or a portion of it,
290 either verbatim or with modifications and/or translated into another
291 language. (Hereinafter, translation is included without limitation in
292 the term ``modification''.) Each licensee is addressed as ``you''.
293
294 Activities other than copying, distribution and modification are not
295 covered by this License; they are outside its scope. The act of
296 running the Program is not restricted, and the output from the Program
297 is covered only if its contents constitute a work based on the
298 Program (independent of having been made by running the Program).
299 Whether that is true depends on what the Program does.
300
301 @item
302 You may copy and distribute verbatim copies of the Program's
303 source code as you receive it, in any medium, provided that you
304 conspicuously and appropriately publish on each copy an appropriate
305 copyright notice and disclaimer of warranty; keep intact all the
306 notices that refer to this License and to the absence of any warranty;
307 and give any other recipients of the Program a copy of this License
308 along with the Program.
309
310 You may charge a fee for the physical act of transferring a copy, and
311 you may at your option offer warranty protection in exchange for a fee.
312
313 @item
314 You may modify your copy or copies of the Program or any portion
315 of it, thus forming a work based on the Program, and copy and
316 distribute such modifications or work under the terms of Section 1
317 above, provided that you also meet all of these conditions:
318
319 @enumerate a
320 @item
321 You must cause the modified files to carry prominent notices
322 stating that you changed the files and the date of any change.
323
324 @item
325 You must cause any work that you distribute or publish, that in
326 whole or in part contains or is derived from the Program or any
327 part thereof, to be licensed as a whole at no charge to all third
328 parties under the terms of this License.
329
330 @item
331 If the modified program normally reads commands interactively
332 when run, you must cause it, when started running for such
333 interactive use in the most ordinary way, to print or display an
334 announcement including an appropriate copyright notice and a
335 notice that there is no warranty (or else, saying that you provide
336 a warranty) and that users may redistribute the program under
337 these conditions, and telling the user how to view a copy of this
338 License. (Exception: if the Program itself is interactive but
339 does not normally print such an announcement, your work based on
340 the Program is not required to print an announcement.)
341 @end enumerate
342
343 These requirements apply to the modified work as a whole. If
344 identifiable sections of that work are not derived from the Program,
345 and can be reasonably considered independent and separate works in
346 themselves, then this License, and its terms, do not apply to those
347 sections when you distribute them as separate works. But when you
348 distribute the same sections as part of a whole which is a work based
349 on the Program, the distribution of the whole must be on the terms of
350 this License, whose permissions for other licensees extend to the
351 entire whole, and thus to each and every part regardless of who wrote it.
352
353 Thus, it is not the intent of this section to claim rights or contest
354 your rights to work written entirely by you; rather, the intent is to
355 exercise the right to control the distribution of derivative or
356 collective works based on the Program.
357
358 In addition, mere aggregation of another work not based on the Program
359 with the Program (or with a work based on the Program) on a volume of
360 a storage or distribution medium does not bring the other work under
361 the scope of this License.
362
363 @item
364 You may copy and distribute the Program (or a work based on it,
365 under Section 2) in object code or executable form under the terms of
366 Sections 1 and 2 above provided that you also do one of the following:
367
368 @enumerate a
369 @item
370 Accompany it with the complete corresponding machine-readable
371 source code, which must be distributed under the terms of Sections
372 1 and 2 above on a medium customarily used for software interchange; or,
373
374 @item
375 Accompany it with a written offer, valid for at least three
376 years, to give any third party, for a charge no more than your
377 cost of physically performing source distribution, a complete
378 machine-readable copy of the corresponding source code, to be
379 distributed under the terms of Sections 1 and 2 above on a medium
380 customarily used for software interchange; or,
381
382 @item
383 Accompany it with the information you received as to the offer
384 to distribute corresponding source code. (This alternative is
385 allowed only for noncommercial distribution and only if you
386 received the program in object code or executable form with such
387 an offer, in accord with Subsection b above.)
388 @end enumerate
389
390 The source code for a work means the preferred form of the work for
391 making modifications to it. For an executable work, complete source
392 code means all the source code for all modules it contains, plus any
393 associated interface definition files, plus the scripts used to
394 control compilation and installation of the executable. However, as a
395 special exception, the source code distributed need not include
396 anything that is normally distributed (in either source or binary
397 form) with the major components (compiler, kernel, and so on) of the
398 operating system on which the executable runs, unless that component
399 itself accompanies the executable.
400
401 If distribution of executable or object code is made by offering
402 access to copy from a designated place, then offering equivalent
403 access to copy the source code from the same place counts as
404 distribution of the source code, even though third parties are not
405 compelled to copy the source along with the object code.
406
407 @item
408 You may not copy, modify, sublicense, or distribute the Program
409 except as expressly provided under this License. Any attempt
410 otherwise to copy, modify, sublicense or distribute the Program is
411 void, and will automatically terminate your rights under this License.
412 However, parties who have received copies, or rights, from you under
413 this License will not have their licenses terminated so long as such
414 parties remain in full compliance.
415
416 @item
417 You are not required to accept this License, since you have not
418 signed it. However, nothing else grants you permission to modify or
419 distribute the Program or its derivative works. These actions are
420 prohibited by law if you do not accept this License. Therefore, by
421 modifying or distributing the Program (or any work based on the
422 Program), you indicate your acceptance of this License to do so, and
423 all its terms and conditions for copying, distributing or modifying
424 the Program or works based on it.
425
426 @item
427 Each time you redistribute the Program (or any work based on the
428 Program), the recipient automatically receives a license from the
429 original licensor to copy, distribute or modify the Program subject to
430 these terms and conditions. You may not impose any further
431 restrictions on the recipients' exercise of the rights granted herein.
432 You are not responsible for enforcing compliance by third parties to
433 this License.
434
435 @item
436 If, as a consequence of a court judgment or allegation of patent
437 infringement or for any other reason (not limited to patent issues),
438 conditions are imposed on you (whether by court order, agreement or
439 otherwise) that contradict the conditions of this License, they do not
440 excuse you from the conditions of this License. If you cannot
441 distribute so as to satisfy simultaneously your obligations under this
442 License and any other pertinent obligations, then as a consequence you
443 may not distribute the Program at all. For example, if a patent
444 license would not permit royalty-free redistribution of the Program by
445 all those who receive copies directly or indirectly through you, then
446 the only way you could satisfy both it and this License would be to
447 refrain entirely from distribution of the Program.
448
449 If any portion of this section is held invalid or unenforceable under
450 any particular circumstance, the balance of the section is intended to
451 apply and the section as a whole is intended to apply in other
452 circumstances.
453
454 It is not the purpose of this section to induce you to infringe any
455 patents or other property right claims or to contest validity of any
456 such claims; this section has the sole purpose of protecting the
457 integrity of the free software distribution system, which is
458 implemented by public license practices. Many people have made
459 generous contributions to the wide range of software distributed
460 through that system in reliance on consistent application of that
461 system; it is up to the author/donor to decide if he or she is willing
462 to distribute software through any other system and a licensee cannot
463 impose that choice.
464
465 This section is intended to make thoroughly clear what is believed to
466 be a consequence of the rest of this License.
467
468 @item
469 If the distribution and/or use of the Program is restricted in
470 certain countries either by patents or by copyrighted interfaces, the
471 original copyright holder who places the Program under this License
472 may add an explicit geographical distribution limitation excluding
473 those countries, so that distribution is permitted only in or among
474 countries not thus excluded. In such case, this License incorporates
475 the limitation as if written in the body of this License.
476
477 @item
478 The Free Software Foundation may publish revised and/or new versions
479 of the General Public License from time to time. Such new versions will
480 be similar in spirit to the present version, but may differ in detail to
481 address new problems or concerns.
482
483 Each version is given a distinguishing version number. If the Program
484 specifies a version number of this License which applies to it and ``any
485 later version'', you have the option of following the terms and conditions
486 either of that version or of any later version published by the Free
487 Software Foundation. If the Program does not specify a version number of
488 this License, you may choose any version ever published by the Free Software
489 Foundation.
490
491 @item
492 If you wish to incorporate parts of the Program into other free
493 programs whose distribution conditions are different, write to the author
494 to ask for permission. For software which is copyrighted by the Free
495 Software Foundation, write to the Free Software Foundation; we sometimes
496 make exceptions for this. Our decision will be guided by the two goals
497 of preserving the free status of all derivatives of our free software and
498 of promoting the sharing and reuse of software generally.
499
500 @iftex
501 @heading NO WARRANTY
502 @end iftex
503 @ifinfo
504 @center NO WARRANTY
505 @end ifinfo
506
507 @item
508 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
509 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
510 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
511 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
512 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
513 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
514 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
515 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
516 REPAIR OR CORRECTION.
517
518 @item
519 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
520 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
521 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
522 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
523 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
524 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
525 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
526 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
527 POSSIBILITY OF SUCH DAMAGES.
528 @end enumerate
529
530 @iftex
531 @heading END OF TERMS AND CONDITIONS
532 @end iftex
533 @ifinfo
534 @center END OF TERMS AND CONDITIONS
535 @end ifinfo
536
537 @page
538 @unnumberedsec How to Apply These Terms to Your New Programs
539
540 If you develop a new program, and you want it to be of the greatest
541 possible use to the public, the best way to achieve this is to make it
542 free software which everyone can redistribute and change under these terms.
543
544 To do so, attach the following notices to the program. It is safest
545 to attach them to the start of each source file to most effectively
546 convey the exclusion of warranty; and each file should have at least
547 the ``copyright'' line and a pointer to where the full notice is found.
548
549 @smallexample
550 @var{one line to give the program's name and a brief idea of what it does.}
551 Copyright (C) 19@var{yy} @var{name of author}
552
553 This program is free software; you can redistribute it and/or modify
554 it under the terms of the GNU General Public License as published by
555 the Free Software Foundation; either version 2 of the License, or
556 (at your option) any later version.
557
558 This program is distributed in the hope that it will be useful,
559 but WITHOUT ANY WARRANTY; without even the implied warranty of
560 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
561 GNU General Public License for more details.
562
563 You should have received a copy of the GNU General Public License
564 along with this program; if not, write to the Free Software
565 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
566 @end smallexample
567
568 Also add information on how to contact you by electronic and paper mail.
569
570 If the program is interactive, make it output a short notice like this
571 when it starts in an interactive mode:
572
573 @smallexample
574 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
575 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
576 type `show w'.
577 This is free software, and you are welcome to redistribute it
578 under certain conditions; type `show c' for details.
579 @end smallexample
580
581 The hypothetical commands @samp{show w} and @samp{show c} should show
582 the appropriate parts of the General Public License. Of course, the
583 commands you use may be called something other than @samp{show w} and
584 @samp{show c}; they could even be mouse-clicks or menu items---whatever
585 suits your program.
586
587 You should also get your employer (if you work as a programmer) or your
588 school, if any, to sign a ``copyright disclaimer'' for the program, if
589 necessary. Here is a sample; alter the names:
590
591 @smallexample
592 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
593 `Gnomovision' (which makes passes at compilers) written by James Hacker.
594
595 @var{signature of Ty Coon}, 1 April 1989
596 Ty Coon, President of Vice
597 @end smallexample
598
599 This General Public License does not permit incorporating your program into
600 proprietary programs. If your program is a subroutine library, you may
601 consider it more useful to permit linking proprietary applications with the
602 library. If this is what you want to do, use the GNU Library General
603 Public License instead of this License.
604
605 @node Contributors
606 @unnumbered Contributors to GNU Fortran
607 @cindex contributors
608 @cindex credits
609
610 In addition to James Craig Burley, who wrote the front end,
611 many people have helped create and improve GNU Fortran.
612
613 @itemize @bullet
614 @item
615 The packaging and compiler portions of GNU Fortran are based largely
616 on the GNU CC compiler.
617 @xref{Contributors,,Contributors to GNU CC,gcc,Using and Porting GNU CC},
618 for more information.
619
620 @item
621 The run-time library used by GNU Fortran is a repackaged version
622 of the @code{libf2c} library (combined from the @code{libF77} and
623 @code{libI77} libraries) provided as part of @code{f2c}, available for
624 free from @code{netlib} sites on the Internet.
625
626 @item
627 Cygnus Support and The Free Software Foundation contributed
628 significant money and/or equipment to Craig's efforts.
629
630 @item
631 The following individuals served as alpha testers prior to @code{g77}'s
632 public release. This work consisted of testing, researching, sometimes
633 debugging, and occasionally providing small amounts of code and fixes
634 for @code{g77}, plus offering plenty of helpful advice to Craig:
635
636 @itemize @w{}
637 @item
638 Jonathan Corbet
639 @item
640 Dr.@: Mark Fernyhough
641 @item
642 Takafumi Hayashi (The University of AIzu)---@email{takafumi@@u-aizu.ac.jp}
643 @item
644 Kate Hedstrom
645 @item
646 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
647 @item
648 Dr.@: A. O. V. Le Blanc
649 @item
650 Dave Love
651 @item
652 Rick Lutowski
653 @item
654 Toon Moene
655 @item
656 Rick Niles
657 @item
658 Derk Reefman
659 @item
660 Wayne K. Schroll
661 @item
662 Bill Thorson
663 @item
664 Pedro A. M. Vazquez
665 @item
666 Ian Watson
667 @end itemize
668
669 @item
670 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
671 provided the patch to add rudimentary support
672 for @code{INTEGER*1}, @code{INTEGER*2}, and
673 @code{LOGICAL*1}.
674 This inspired Craig to add further support,
675 even though the resulting support
676 would still be incomplete, because version 0.6 is still
677 a ways off.
678
679 @item
680 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
681 and encouraged Craig to rewrite the documentation in texinfo
682 format by contributing a first pass at a translation of the
683 old @file{g77-0.5.16/f/DOC} file.
684
685 @item
686 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
687 some analysis of generated code as part of an overall project
688 to improve @code{g77} code generation to at least be as good
689 as @code{f2c} used in conjunction with @code{gcc}.
690 So far, this has resulted in the three, somewhat
691 experimental, options added by @code{g77} to the @code{gcc}
692 compiler and its back end.
693
694 @item
695 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
696
697 @item
698 Thanks to Mary Cortani and the staff at Craftwork Solutions
699 (@email{support@@craftwork.com}) for all of their support.
700
701 @item
702 Many other individuals have helped debug, test, and improve @code{g77}
703 over the past several years, and undoubtedly more people
704 will be doing so in the future.
705 If you have done so, and would like
706 to see your name listed in the above list, please ask!
707 The default is that people wish to remain anonymous.
708 @end itemize
709
710 @node Funding
711 @chapter Funding Free Software
712
713 If you want to have more free software a few years from now, it makes
714 sense for you to help encourage people to contribute funds for its
715 development. The most effective approach known is to encourage
716 commercial redistributors to donate.
717
718 Users of free software systems can boost the pace of development by
719 encouraging for-a-fee distributors to donate part of their selling price
720 to free software developers---the Free Software Foundation, and others.
721
722 The way to convince distributors to do this is to demand it and expect
723 it from them. So when you compare distributors, judge them partly by
724 how much they give to free software development. Show distributors
725 they must compete to be the one who gives the most.
726
727 To make this approach work, you must insist on numbers that you can
728 compare, such as, ``We will donate ten dollars to the Frobnitz project
729 for each disk sold.'' Don't be satisfied with a vague promise, such as
730 ``A portion of the profits are donated,'' since it doesn't give a basis
731 for comparison.
732
733 Even a precise fraction ``of the profits from this disk'' is not very
734 meaningful, since creative accounting and unrelated business decisions
735 can greatly alter what fraction of the sales price counts as profit.
736 If the price you pay is $50, ten percent of the profit is probably
737 less than a dollar; it might be a few cents, or nothing at all.
738
739 Some redistributors do development work themselves. This is useful too;
740 but to keep everyone honest, you need to inquire how much they do, and
741 what kind. Some kinds of development make much more long-term
742 difference than others. For example, maintaining a separate version of
743 a program contributes very little; maintaining the standard version of a
744 program for the whole community contributes much. Easy new ports
745 contribute little, since someone else would surely do them; difficult
746 ports such as adding a new CPU to the GNU C compiler contribute more;
747 major new features or packages contribute the most.
748
749 By establishing the idea that supporting further development is ``the
750 proper thing to do'' when distributing free software for a fee, we can
751 assure a steady flow of resources into making more free software.
752
753 @display
754 Copyright (C) 1994 Free Software Foundation, Inc.
755 Verbatim copying and redistribution of this section is permitted
756 without royalty; alteration is not permitted.
757 @end display
758
759 @node Funding GNU Fortran
760 @chapter Funding GNU Fortran
761 @cindex funding improvements
762 @cindex improvements, funding
763
764 Work on GNU Fortran is still being done mostly by its author,
765 James Craig Burley (@email{burley@@gnu.org}), who is a volunteer
766 for, not an employee of, the Free Software Foundation (FSF).
767 As with other GNU software, funding is important because it can pay for
768 needed equipment, personnel, and so on.
769
770 @cindex FSF, funding the
771 @cindex funding the FSF
772 The FSF provides information on the best way to fund ongoing
773 development of GNU software (such as GNU Fortran) in documents
774 such as the ``GNUS Bulletin''.
775 Email @email{gnu@@gnu.org} for information on funding the FSF.
776
777 To fund specific GNU Fortran work in particular, the FSF might
778 provide a means for that, but the FSF does not provide direct funding
779 to the author of GNU Fortran to continue his work. The FSF has
780 employee salary restrictions that can be incompatible with the
781 financial needs of some volunteers, who therefore choose to
782 remain volunteers and thus be able to be free to do contract work
783 and otherwise make their own schedules for doing GNU work.
784
785 Still, funding the FSF at least indirectly benefits work
786 on specific projects like GNU Fortran because it ensures the
787 continuing operation of the FSF offices, their workstations, their
788 network connections, and so on, which are invaluable to volunteers.
789 (Similarly, hiring Cygnus Support can help a project like GNU
790 Fortran---Cygnus has been a long-time donor of equipment usage to the author
791 of GNU Fortran, and this too has been invaluable---@xref{Contributors}.)
792
793 Currently, the only way to directly fund the author of GNU Fortran
794 in his work on that project is to hire him for the work you want
795 him to do, or donate money to him.
796 Several people have done this
797 already, with the result that he has not needed to immediately find
798 contract work on a few occasions.
799 If more people did this, he
800 would be able to plan on not doing contract work for many months and
801 could thus devote that time to work on projects (such as the planned
802 changes for 0.6) that require longer timeframes to complete.
803 For the latest information on the status of the author, do
804 @kbd{finger -l burley@@gnu.org} on a UNIX system
805 (or any system with a command like UNIX @code{finger}).
806
807 Another important way to support work on GNU Fortran is to volunteer
808 to help out.
809 Work is needed on documentation, testing, porting
810 to various machines, and in some cases, coding (although major
811 changes planned for version 0.6 make it difficult to add manpower to this
812 area).
813 Email @email{egcs@@cygnus.com} to volunteer for this work.
814
815 @xref{Funding,,Funding Free Software}, for more information.
816
817 @node Look and Feel
818 @chapter Protect Your Freedom---Fight ``Look And Feel''
819 @c the above chapter heading overflows onto the next line. --mew 1/26/93
820
821 To preserve the ability to write free software, including replacements
822 for proprietary software, authors must be free to replicate the
823 user interface to which users of existing software have become
824 accustomed.
825
826 @xref{Look and Feel,,Protect Your Freedom---Fight ``Look And Feel'',
827 gcc,Using and Porting GNU CC}, for more information.
828
829 @node Getting Started
830 @chapter Getting Started
831 @cindex getting started
832 @cindex new users
833 @cindex newbies
834 @cindex beginners
835
836 If you don't need help getting started reading the portions
837 of this manual that are most important to you, you should skip
838 this portion of the manual.
839
840 If you are new to compilers, especially Fortran compilers, or
841 new to how compilers are structured under UNIX and UNIX-like
842 systems, you'll want to see @ref{What is GNU Fortran?}.
843
844 If you are new to GNU compilers, or have used only one GNU
845 compiler in the past and not had to delve into how it lets
846 you manage various versions and configurations of @code{gcc},
847 you should see @ref{G77 and GCC}.
848
849 Everyone except experienced @code{g77} users should
850 see @ref{Invoking G77}.
851
852 If you're acquainted with previous versions of @code{g77},
853 you should see @ref{News}.
854 Further, if you've actually used previous versions of @code{g77},
855 especially if you've written or modified Fortran code to
856 be compiled by previous versions of @code{g77}, you
857 should see @ref{Changes}.
858
859 If you intend to write or otherwise compile code that is
860 not already strictly conforming ANSI FORTRAN 77---and this
861 is probably everyone---you should see @ref{Language}.
862
863 If you don't already have @code{g77} installed on your
864 system, you must see @ref{Installation}.
865
866 If you run into trouble getting Fortran code to compile,
867 link, run, or work properly, you might find answers
868 if you see @ref{Debugging and Interfacing},
869 see @ref{Collected Fortran Wisdom},
870 and see @ref{Trouble}.
871 You might also find that the problems you are encountering
872 are bugs in @code{g77}---see @ref{Bugs}, for information on
873 reporting them, after reading the other material.
874
875 If you need further help with @code{g77}, or with
876 freely redistributable software in general,
877 see @ref{Service}.
878
879 If you would like to help the @code{g77} project,
880 see @ref{Funding GNU Fortran}, for information on
881 helping financially, and see @ref{Projects}, for information
882 on helping in other ways.
883
884 If you're generally curious about the future of
885 @code{g77}, see @ref{Projects}.
886 If you're curious about its past,
887 see @ref{Contributors},
888 and see @ref{Funding GNU Fortran}.
889
890 To see a few of the questions maintainers of @code{g77} have,
891 and that you might be able to answer,
892 see @ref{Open Questions}.
893
894 @ifset USING
895 @node What is GNU Fortran?
896 @chapter What is GNU Fortran?
897 @cindex concepts, basic
898 @cindex basic concepts
899
900 GNU Fortran, or @code{g77}, is designed initially as a free replacement
901 for, or alternative to, the UNIX @code{f77} command.
902 (Similarly, @code{gcc} is designed as a replacement
903 for the UNIX @code{cc} command.)
904
905 @code{g77} also is designed to fit in well with the other
906 fine GNU compilers and tools.
907
908 Sometimes these design goals conflict---in such cases, resolution
909 often is made in favor of fitting in well with Project GNU.
910 These cases are usually identified in the appropriate
911 sections of this manual.
912
913 @cindex compilers
914 As compilers, @code{g77}, @code{gcc}, and @code{f77}
915 share the following characteristics:
916
917 @itemize @bullet
918 @cindex source code
919 @cindex file, source
920 @cindex code, source
921 @cindex source file
922 @item
923 They read a user's program, stored in a file and
924 containing instructions written in the appropriate
925 language (Fortran, C, and so on).
926 This file contains @dfn{source code}.
927
928 @cindex translation of user programs
929 @cindex machine code
930 @cindex code, machine
931 @cindex mistakes
932 @item
933 They translate the user's program into instructions
934 a computer can carry out more quickly than it takes
935 to translate the instructions in the first place.
936 These instructions are called @dfn{machine code}---code
937 designed to be efficiently translated and processed
938 by a machine such as a computer.
939 Humans usually aren't as good writing machine code
940 as they are at writing Fortran or C, because
941 it is easy to make tiny mistakes writing machine code.
942 When writing Fortran or C, it is easy
943 to make big mistakes.
944
945 @cindex debugger
946 @cindex bugs, finding
947 @cindex gdb command
948 @cindex commands, gdb
949 @item
950 They provide information in the generated machine code
951 that can make it easier to find bugs in the program
952 (using a debugging tool, called a @dfn{debugger},
953 such as @code{gdb}).
954
955 @cindex libraries
956 @cindex linking
957 @cindex ld command
958 @cindex commands, ld
959 @item
960 They locate and gather machine code already generated
961 to perform actions requested by statements in
962 the user's program.
963 This machine code is organized
964 into @dfn{libraries} and is located and gathered
965 during the @dfn{link} phase of the compilation
966 process.
967 (Linking often is thought of as a separate
968 step, because it can be directly invoked via the
969 @code{ld} command.
970 However, the @code{g77} and @code{gcc}
971 commands, as with most compiler commands, automatically
972 perform the linking step by calling on @code{ld}
973 directly, unless asked to not do so by the user.)
974
975 @cindex language, incorrect use of
976 @cindex incorrect use of language
977 @item
978 They attempt to diagnose cases where the user's
979 program contains incorrect usages of the language.
980 The @dfn{diagnostics} produced by the compiler
981 indicate the problem and the location in the user's
982 source file where the problem was first noticed.
983 The user can use this information to locate and
984 fix the problem.
985 @cindex diagnostics, incorrect
986 @cindex incorrect diagnostics
987 @cindex error messages, incorrect
988 @cindex incorrect error messages
989 (Sometimes an incorrect usage
990 of the language leads to a situation where the
991 compiler can no longer make any sense of what
992 follows---while a human might be able to---and
993 thus ends up complaining about many ``problems''
994 it encounters that, in fact, stem from just one
995 problem, usually the first one reported.)
996
997 @cindex warnings
998 @cindex questionable instructions
999 @item
1000 They attempt to diagnose cases where the user's
1001 program contains a correct usage of the language,
1002 but instructs the computer to do something questionable.
1003 These diagnostics often are in the form of @dfn{warnings},
1004 instead of the @dfn{errors} that indicate incorrect
1005 usage of the language.
1006 @end itemize
1007
1008 How these actions are performed is generally under the
1009 control of the user.
1010 Using command-line options, the user can specify
1011 how persnickety the compiler is to be regarding
1012 the program (whether to diagnose questionable usage
1013 of the language), how much time to spend making
1014 the generated machine code run faster, and so on.
1015
1016 @cindex components of g77
1017 @cindex g77, components of
1018 @code{g77} consists of several components:
1019
1020 @cindex gcc command
1021 @cindex commands, gcc
1022 @itemize @bullet
1023 @item
1024 A modified version of the @code{gcc} command, which also might be
1025 installed as the system's @code{cc} command.
1026 (In many cases, @code{cc} refers to the
1027 system's ``native'' C compiler, which
1028 might be a non-GNU compiler, or an older version
1029 of @code{gcc} considered more stable or that is
1030 used to build the operating system kernel.)
1031
1032 @cindex g77 command
1033 @cindex commands, g77
1034 @item
1035 The @code{g77} command itself, which also might be installed as the
1036 system's @code{f77} command.
1037
1038 @cindex libf2c library
1039 @cindex libraries, libf2c
1040 @cindex run-time library
1041 @item
1042 The @code{libf2c} run-time library.
1043 This library contains the machine code needed to support
1044 capabilities of the Fortran language that are not directly
1045 provided by the machine code generated by the @code{g77}
1046 compilation phase.
1047
1048 @cindex f771 program
1049 @cindex programs, f771
1050 @cindex assembler
1051 @cindex as command
1052 @cindex commands, as
1053 @cindex assembly code
1054 @cindex code, assembly
1055 @item
1056 The compiler itself, internally named @code{f771}.
1057
1058 Note that @code{f771} does not generate machine code directly---it
1059 generates @dfn{assembly code} that is a more readable form
1060 of machine code, leaving the conversion to actual machine code
1061 to an @dfn{assembler}, usually named @code{as}.
1062 @end itemize
1063
1064 @code{gcc} is often thought of as ``the C compiler'' only,
1065 but it does more than that.
1066 Based on command-line options and the names given for files
1067 on the command line, @code{gcc} determines which actions to perform, including
1068 preprocessing, compiling (in a variety of possible languages), assembling,
1069 and linking.
1070
1071 @cindex driver, gcc command as
1072 @cindex gcc command as driver
1073 @cindex executable file
1074 @cindex files, executable
1075 @cindex cc1 program
1076 @cindex programs, cc1
1077 @cindex preprocessor
1078 @cindex cpp program
1079 @cindex programs, cpp
1080 For example, the command @samp{gcc foo.c} @dfn{drives} the file
1081 @file{foo.c} through the preprocessor @code{cpp}, then
1082 the C compiler (internally named
1083 @code{cc1}), then the assembler (usually @code{as}), then the linker
1084 (@code{ld}), producing an executable program named @file{a.out} (on
1085 UNIX systems).
1086
1087 @cindex cc1plus program
1088 @cindex programs, cc1plus
1089 As another example, the command @samp{gcc foo.cc} would do much the same as
1090 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
1091 @code{gcc} would use the C++ compiler (named @code{cc1plus}).
1092
1093 @cindex f771 program
1094 @cindex programs, f771
1095 In a GNU Fortran installation, @code{gcc} recognizes Fortran source
1096 files by name just like it does C and C++ source files.
1097 It knows to use the Fortran compiler named @code{f771}, instead of
1098 @code{cc1} or @code{cc1plus}, to compile Fortran files.
1099
1100 @cindex gcc not recognizing Fortran source
1101 @cindex unrecognized file format
1102 @cindex file format not recognized
1103 Non-Fortran-related operation of @code{gcc} is generally
1104 unaffected by installing the GNU Fortran version of @code{gcc}.
1105 However, without the installed version of @code{gcc} being the
1106 GNU Fortran version, @code{gcc} will not be able to compile
1107 and link Fortran programs---and since @code{g77} uses @code{gcc}
1108 to do most of the actual work, neither will @code{g77}!
1109
1110 @cindex g77 command
1111 @cindex commands, g77
1112 The @code{g77} command is essentially just a front-end for
1113 the @code{gcc} command.
1114 Fortran users will normally use @code{g77} instead of @code{gcc},
1115 because @code{g77}
1116 knows how to specify the libraries needed to link with Fortran programs
1117 (@code{libf2c} and @code{lm}).
1118 @code{g77} can still compile and link programs and
1119 source files written in other languages, just like @code{gcc}.
1120
1121 @cindex printing version information
1122 @cindex version information, printing
1123 The command @samp{g77 -v} is a quick
1124 way to display lots of version information for the various programs
1125 used to compile a typical preprocessed Fortran source file---this
1126 produces much more output than @samp{gcc -v} currently does.
1127 (If it produces an error message near the end of the output---diagnostics
1128 from the linker, usually @code{ld}---you might
1129 have an out-of-date @code{libf2c} that improperly handles
1130 complex arithmetic.)@
1131 In the output of this command, the line beginning @samp{GNU Fortran Front
1132 End} identifies the version number of GNU Fortran; immediately
1133 preceding that line is a line identifying the version of @code{gcc}
1134 with which that version of @code{g77} was built.
1135
1136 @cindex libf2c library
1137 @cindex libraries, libf2c
1138 The @code{libf2c} library is distributed with GNU Fortran for
1139 the convenience of its users, but is not part of GNU Fortran.
1140 It contains the procedures
1141 needed by Fortran programs while they are running.
1142
1143 @cindex in-line code
1144 @cindex code, in-line
1145 For example, while code generated by @code{g77} is likely
1146 to do additions, subtractions, and multiplications @dfn{in line}---in
1147 the actual compiled code---it is not likely to do trigonometric
1148 functions this way.
1149
1150 Instead, operations like trigonometric
1151 functions are compiled by the @code{f771} compiler
1152 (invoked by @code{g77} when compiling Fortran code) into machine
1153 code that, when run, calls on functions in @code{libf2c}, so
1154 @code{libf2c} must be linked with almost every useful program
1155 having any component compiled by GNU Fortran.
1156 (As mentioned above, the @code{g77} command takes
1157 care of all this for you.)
1158
1159 The @code{f771} program represents most of what is unique to GNU Fortran.
1160 While much of the @code{libf2c} component is really part of @code{f2c},
1161 a free Fortran-to-C converter distributed by Bellcore (AT&T),
1162 plus @code{libU77}, provided by Dave Love,
1163 and the @code{g77} command is just a small front-end to @code{gcc},
1164 @code{f771} is a combination of two rather
1165 large chunks of code.
1166
1167 @cindex GNU Back End (GBE)
1168 @cindex GBE
1169 @cindex gcc back end
1170 @cindex back end, gcc
1171 @cindex code generator
1172 One chunk is the so-called @dfn{GNU Back End}, or GBE,
1173 which knows how to generate fast code for a wide variety of processors.
1174 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
1175 @code{cc1plus}, and @code{f771}, plus others.
1176 Often the GBE is referred to as the ``gcc back end'' or
1177 even just ``gcc''---in this manual, the term GBE is used
1178 whenever the distinction is important.
1179
1180 @cindex GNU Fortran Front End (FFE)
1181 @cindex FFE
1182 @cindex g77 front end
1183 @cindex front end, g77
1184 The other chunk of @code{f771} is the
1185 majority of what is unique about GNU Fortran---the code that knows how
1186 to interpret Fortran programs to determine what they are intending to
1187 do, and then communicate that knowledge to the GBE for actual compilation
1188 of those programs.
1189 This chunk is called the @dfn{Fortran Front End} (FFE).
1190 The @code{cc1} and @code{cc1plus} programs have their own front ends,
1191 for the C and C++ languages, respectively.
1192 These fronts ends are responsible for diagnosing
1193 incorrect usage of their respective languages by the
1194 programs the process, and are responsible for most of
1195 the warnings about questionable constructs as well.
1196 (The GBE handles producing some warnings, like those
1197 concerning possible references to undefined variables.)
1198
1199 Because so much is shared among the compilers for various languages,
1200 much of the behavior and many of the user-selectable options for these
1201 compilers are similar.
1202 For example, diagnostics (error messages and
1203 warnings) are similar in appearance; command-line
1204 options like @samp{-Wall} have generally similar effects; and the quality
1205 of generated code (in terms of speed and size) is roughly similar
1206 (since that work is done by the shared GBE).
1207
1208 @node G77 and GCC
1209 @chapter Compile Fortran, C, or Other Programs
1210 @cindex compiling programs
1211 @cindex programs, compiling
1212
1213 @cindex gcc command
1214 @cindex commands, gcc
1215 A GNU Fortran installation includes a modified version of the @code{gcc}
1216 command.
1217
1218 In a non-Fortran installation, @code{gcc} recognizes C, C++,
1219 and Objective-C source files.
1220
1221 In a GNU Fortran installation, @code{gcc} also recognizes Fortran source
1222 files and accepts Fortran-specific command-line options, plus some
1223 command-line options that are designed to cater to Fortran users
1224 but apply to other languages as well.
1225
1226 @xref{G++ and GCC,,Compile C; C++; or Objective-C,gcc,Using and Porting GNU CC},
1227 for information on the way different languages are handled
1228 by the GNU CC compiler (@code{gcc}).
1229
1230 @cindex g77 command
1231 @cindex commands, g77
1232 Also provided as part of GNU Fortran is the @code{g77} command.
1233 The @code{g77} command is designed to make compiling and linking Fortran
1234 programs somewhat easier than when using the @code{gcc} command for
1235 these tasks.
1236 It does this by analyzing the command line somewhat and changing it
1237 appropriately before submitting it to the @code{gcc} command.
1238
1239 @cindex -v option
1240 @cindex g77 options, -v
1241 @cindex options, -v
1242 @cindex -@w{}-driver option
1243 @cindex g77 options, -@w{}-driver
1244 @cindex options, -@w{}-driver
1245 Use the @samp{-v} option with @code{g77}
1246 to see what is going on---the first line of output is the invocation
1247 of the @code{gcc} command.
1248 Use @samp{--driver=true} to disable actual invocation
1249 of @code{gcc} (this works because @samp{true} is the name of a
1250 UNIX command that simply returns success status).
1251
1252 @node Invoking G77
1253 @chapter GNU Fortran Command Options
1254 @cindex GNU Fortran command options
1255 @cindex command options
1256 @cindex options, GNU Fortran command
1257
1258 The @code{g77} command supports all the options supported by the
1259 @code{gcc} command.
1260 @xref{Invoking GCC,,GNU CC Command Options,gcc,Using and Porting GNU CC},
1261 for information
1262 on the non-Fortran-specific aspects of the @code{gcc} command (and,
1263 therefore, the @code{g77} command).
1264
1265 The @code{g77} command supports one option not supported by
1266 the @code{gcc} command:
1267
1268 @table @code
1269 @cindex -@w{}-driver option
1270 @cindex g77 options, -@w{}-driver
1271 @cindex options, -@w{}-driver
1272 @item --driver=@var{command}
1273 Specifies that @var{command}, rather than @code{gcc}, is to
1274 be invoked by @code{g77} to do its job.
1275 For example, within the @code{gcc} build directory after
1276 building GNU Fortran (but without having to install it),
1277 @kbd{./g77 --driver=./xgcc foo.f -B./}.
1278 @end table
1279
1280 @cindex options, negative forms
1281 @cindex negative forms of options
1282 All other options are supported both by @code{g77} and by @code{gcc} as
1283 modified (and reinstalled) by the @code{g77} distribution.
1284 In some cases, options have positive and negative forms;
1285 the negative form of @samp{-ffoo} would be @samp{-fno-foo}.
1286 This manual documents only one of these two forms, whichever
1287 one is not the default.
1288
1289 @menu
1290 * Option Summary:: Brief list of all @code{g77} options,
1291 without explanations.
1292 * Overall Options:: Controlling the kind of output:
1293 an executable, object files, assembler files,
1294 or preprocessed source.
1295 * Shorthand Options:: Options that are shorthand for other options.
1296 * Fortran Dialect Options:: Controlling the variant of Fortran language
1297 compiled.
1298 * Warning Options:: How picky should the compiler be?
1299 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
1300 * Optimize Options:: How much optimization?
1301 * Preprocessor Options:: Controlling header files and macro definitions.
1302 Also, getting dependency information for Make.
1303 * Directory Options:: Where to find header files and libraries.
1304 Where to find the compiler executable files.
1305 * Code Gen Options:: Specifying conventions for function calls, data layout
1306 and register usage.
1307 * Environment Variables:: Env vars that affect GNU Fortran.
1308 @end menu
1309
1310 @node Option Summary
1311 @section Option Summary
1312
1313 Here is a summary of all the options specific to GNU Fortran, grouped
1314 by type. Explanations are in the following sections.
1315
1316 @table @emph
1317 @item Overall Options
1318 @xref{Overall Options,,Options Controlling the Kind of Output}.
1319 @smallexample
1320 --driver -fversion -fset-g77-defaults -fno-silent
1321 @end smallexample
1322
1323 @item Shorthand Options
1324 @xref{Shorthand Options}.
1325 @smallexample
1326 -ff66 -fno-f66 -ff77 -fno-f77 -fugly -fno-ugly
1327 @end smallexample
1328
1329 @item Fortran Language Options
1330 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
1331 @smallexample
1332 -ffree-form -fno-fixed-form -ff90
1333 -fvxt -fdollar-ok -fno-backslash
1334 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1335 -fugly-comma -fugly-complex -fugly-init -fugly-logint
1336 -fonetrip -ftypeless-boz
1337 -fintrin-case-initcap -fintrin-case-upper
1338 -fintrin-case-lower -fintrin-case-any
1339 -fmatch-case-initcap -fmatch-case-upper
1340 -fmatch-case-lower -fmatch-case-any
1341 -fsource-case-upper -fsource-case-lower -fsource-case-preserve
1342 -fsymbol-case-initcap -fsymbol-case-upper
1343 -fsymbol-case-lower -fsymbol-case-any
1344 -fcase-strict-upper -fcase-strict-lower
1345 -fcase-initcap -fcase-upper -fcase-lower -fcase-preserve
1346 -ff2c-intrinsics-delete -ff2c-intrinsics-hide
1347 -ff2c-intrinsics-disable -ff2c-intrinsics-enable
1348 -ff90-intrinsics-delete -ff90-intrinsics-hide
1349 -ff90-intrinsics-disable -ff90-intrinsics-enable
1350 -fgnu-intrinsics-delete -fgnu-intrinsics-hide
1351 -fgnu-intrinsics-disable -fgnu-intrinsics-enable
1352 -fmil-intrinsics-delete -fmil-intrinsics-hide
1353 -fmil-intrinsics-disable -fmil-intrinsics-enable
1354 -funix-intrinsics-delete -funix-intrinsics-hide
1355 -funix-intrinsics-disable -funix-intrinsics-enable
1356 -fvxt-intrinsics-delete -fvxt-intrinsics-hide
1357 -fvxt-intrinsics-disable -fvxt-intrinsics-enable
1358 -ffixed-line-length-@var{n} -ffixed-line-length-none
1359 @end smallexample
1360
1361 @item Warning Options
1362 @xref{Warning Options,,Options to Request or Suppress Warnings}.
1363 @smallexample
1364 -fsyntax-only -pedantic -pedantic-errors -fpedantic
1365 -w -Wno-globals -Wimplicit -Wunused -Wuninitialized
1366 -Wall -Wsurprising
1367 -Werror -W
1368 @end smallexample
1369
1370 @item Debugging Options
1371 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
1372 @smallexample
1373 -g
1374 @end smallexample
1375
1376 @item Optimization Options
1377 @xref{Optimize Options,,Options that Control Optimization}.
1378 @smallexample
1379 -malign-double
1380 -ffloat-store -fforce-mem -fforce-addr -fno-inline
1381 -ffast-math -fstrength-reduce -frerun-cse-after-loop
1382 -fexpensive-optimizations -fdelayed-branch
1383 -fschedule-insns -fschedule-insn2 -fcaller-saves
1384 -funroll-loops -funroll-all-loops
1385 -fno-move-all-movables -fno-reduce-all-givs
1386 -fno-rerun-loop-opt
1387 @end smallexample
1388
1389 @item Directory Options
1390 @xref{Directory Options,,Options for Directory Search}.
1391 @smallexample
1392 -I@var{dir} -I-
1393 @end smallexample
1394
1395 @item Code Generation Options
1396 @xref{Code Gen Options,,Options for Code Generation Conventions}.
1397 @smallexample
1398 -fno-automatic -finit-local-zero -fno-f2c
1399 -ff2c-library -fno-underscoring -fno-ident
1400 -fpcc-struct-return -freg-struct-return
1401 -fshort-double -fno-common -fpack-struct
1402 -fzeros -fno-second-underscore
1403 -fdebug-kludge -fno-emulate-complex
1404 -falias-check -fargument-alias
1405 -fargument-noalias -fno-argument-noalias-global
1406 -fno-globals
1407 @end smallexample
1408 @end table
1409
1410 @menu
1411 * Overall Options:: Controlling the kind of output:
1412 an executable, object files, assembler files,
1413 or preprocessed source.
1414 * Shorthand Options:: Options that are shorthand for other options.
1415 * Fortran Dialect Options:: Controlling the variant of Fortran language
1416 compiled.
1417 * Warning Options:: How picky should the compiler be?
1418 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
1419 * Optimize Options:: How much optimization?
1420 * Preprocessor Options:: Controlling header files and macro definitions.
1421 Also, getting dependency information for Make.
1422 * Directory Options:: Where to find header files and libraries.
1423 Where to find the compiler executable files.
1424 * Code Gen Options:: Specifying conventions for function calls, data layout
1425 and register usage.
1426 @end menu
1427
1428 @node Overall Options
1429 @section Options Controlling the Kind of Output
1430 @cindex overall options
1431 @cindex options, overall
1432
1433 Compilation can involve as many as four stages: preprocessing, code
1434 generation (often what is really meant by the term ``compilation''),
1435 assembly, and linking, always in that order. The first three
1436 stages apply to an individual source file, and end by producing an
1437 object file; linking combines all the object files (those newly
1438 compiled, and those specified as input) into an executable file.
1439
1440 @cindex file name suffix
1441 @cindex suffixes, file name
1442 @cindex file name extension
1443 @cindex extensions, file name
1444 @cindex file type
1445 @cindex types, file
1446 For any given input file, the file name suffix determines what kind of
1447 program is contained in the file---that is, the language in which the
1448 program is written is generally indicated by the suffix.
1449 Suffixes specific to GNU Fortran are listed below.
1450 @xref{Overall Options,,gcc,Using and Porting GNU CC}, for
1451 information on suffixes recognized by GNU CC.
1452
1453 @table @code
1454 @item @var{file}.f
1455 @item @var{file}.for
1456 Fortran source code that should not be preprocessed.
1457
1458 Such source code cannot contain any preprocessor directives, such
1459 as @code{#include}, @code{#define}, @code{#if}, and so on.
1460
1461 @cindex preprocessor
1462 @cindex C preprocessor
1463 @cindex cpp preprocessor
1464 @cindex Fortran preprocessor
1465 @cindex cpp program
1466 @cindex programs, cpp
1467 @cindex .F filename suffix
1468 @cindex .fpp filename suffix
1469 @item @var{file}.F
1470 @item @var{file}.fpp
1471 Fortran source code that must be preprocessed (by the C preprocessor
1472 @code{cpp}, which is part of GNU CC).
1473
1474 Note that preprocessing is not extended to the contents of
1475 files included by the @code{INCLUDE} directive---the @code{#include}
1476 preprocessor directive must be used instead.
1477
1478 @cindex Ratfor preprocessor
1479 @cindex programs, ratfor
1480 @cindex .r filename suffix
1481 @item @var{file}.r
1482 Ratfor source code, which must be preprocessed by the @code{ratfor}
1483 command, which is available separately (as it is not yet part of
1484 the GNU Fortran distribution).
1485 @end table
1486
1487 UNIX users typically use the @file{@var{file}.f} and @file{@var{file}.F}
1488 nomenclature.
1489 Users of other operating systems, especially those that cannot
1490 distinguish upper-case
1491 letters from lower-case letters in their file names, typically use
1492 the @file{@var{file}.for} and @file{@var{file}.fpp} nomenclature.
1493
1494 @cindex #define
1495 @cindex #include
1496 @cindex #if
1497 Use of the preprocessor @code{cpp} allows use of C-like
1498 constructs such as @code{#define} and @code{#include}, but can
1499 lead to unexpected, even mistaken, results due to Fortran's source file
1500 format.
1501 It is recommended that use of the C preprocessor
1502 be limited to @code{#include} and, in
1503 conjunction with @code{#define}, only @code{#if} and related directives,
1504 thus avoiding in-line macro expansion entirely.
1505 This recommendation applies especially
1506 when using the traditional fixed source form.
1507 With free source form,
1508 fewer unexpected transformations are likely to happen, but use of
1509 constructs such as Hollerith and character constants can nevertheless
1510 present problems, especially when these are continued across multiple
1511 source lines.
1512 These problems result, primarily, from differences between the way
1513 such constants are interpreted by the C preprocessor and by a Fortran
1514 compiler.
1515
1516 Another example of a problem that results from using the C preprocessor
1517 is that a Fortran comment line that happens to contain any
1518 characters ``interesting'' to the C preprocessor,
1519 such as a backslash at the end of the line,
1520 is not recognized by the preprocessor as a comment line,
1521 so instead of being passed through ``raw'',
1522 the line is edited according to the rules for the preprocessor.
1523 For example, the backslash at the end of the line is removed,
1524 along with the subsequent newline, resulting in the next
1525 line being effectively commented out---unfortunate if that
1526 line is a non-comment line of important code!
1527
1528 @emph{Note:} The @samp{-traditional} and @samp{-undef} flags are supplied
1529 to @code{cpp} by default, to avoid unpleasant surprises.
1530 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
1531 gcc,Using and Porting GNU CC}.
1532 This means that ANSI C preprocessor features (such as the @samp{#}
1533 operator) aren't available, and only variables in the C reserved
1534 namespace (generally, names with a leading underscore) are liable to
1535 substitution by C predefines.
1536 Thus, if you want to do system-specific
1537 tests, use, for example, @samp{#ifdef __linux__} rather than @samp{#ifdef linux}.
1538 Use the @samp{-v} option to see exactly how the preprocessor is invoked.
1539
1540 The following options that affect overall processing are recognized
1541 by the @code{g77} and @code{gcc} commands in a GNU Fortran installation:
1542
1543 @table @code
1544 @item --driver=@var{command}
1545 This works when invoking only the @code{g77} command, not
1546 when invoking the @code{gcc} command.
1547 @xref{Invoking G77,,GNU Fortran Command Options}, for
1548 information on this option.
1549
1550 @cindex -fversion option
1551 @cindex options, -fversion
1552 @cindex printing version information
1553 @cindex version information, printing
1554 @item -fversion
1555 Ensure that the @code{g77}-specific version of the compiler phase is reported,
1556 if run.
1557 (This is supplied automatically when @samp{-v} or @samp{--verbose}
1558 is specified as a command-line option for @code{g77} or @code{gcc}
1559 and when the resulting commands compile Fortran source files.)
1560
1561 @cindex -fset-g77-defaults option
1562 @cindex options, -fset-g77-defaults
1563 @item -fset-g77-defaults
1564 Set up whatever @code{gcc} options are to apply to Fortran
1565 compilations, and avoid running internal consistency checks
1566 that might take some time.
1567
1568 As of version 0.5.20, this is equivalent to @samp{-fmove-all-movables
1569 -freduce-all-givs -frerun-loop-opt -fargument-noalias-global}.
1570
1571 This option is supplied automatically when compiling Fortran code
1572 via the @code{g77} or @code{gcc} command.
1573 The description of this option is provided so that users seeing
1574 it in the output of, say, @samp{g77 -v} understand why it is
1575 there.
1576
1577 @cindex modifying g77
1578 @cindex code, modifying
1579 Also, developers who run @code{f771} directly might want to specify it
1580 by hand to get the same defaults as they would running @code{f771}
1581 via @code{g77} or @code{gcc}.
1582 However, such developers should, after linking a new @code{f771}
1583 executable, invoke it without this option once,
1584 e.g. via @kbd{./f771 -quiet < /dev/null},
1585 to ensure that they have not introduced any
1586 internal inconsistencies (such as in the table of
1587 intrinsics) before proceeding---@code{g77} will crash
1588 with a diagnostic if it detects an inconsistency.
1589
1590 @cindex -fno-silent option
1591 @cindex options, -fno-silent
1592 @cindex @code{f2c} compatibility
1593 @cindex compatibility, @code{f2c}
1594 @cindex status, compilation
1595 @cindex compilation status
1596 @cindex reporting compilation status
1597 @cindex printing compilation status
1598 @item -fno-silent
1599 Print (to @code{stderr}) the names of the program units as
1600 they are compiled, in a form similar to that used by popular
1601 UNIX @code{f77} implementations and @code{f2c}.
1602 @end table
1603
1604 @xref{Overall Options,,Options Controlling the Kind of Output,
1605 gcc,Using and Porting GNU CC}, for information
1606 on more options that control the overall operation of the @code{gcc} command
1607 (and, by extension, the @code{g77} command).
1608
1609 @node Shorthand Options
1610 @section Shorthand Options
1611 @cindex shorthand options
1612 @cindex options, shorthand
1613 @cindex macro options
1614 @cindex options, macro
1615
1616 The following options serve as ``shorthand''
1617 for other options accepted by the compiler:
1618
1619 @table @code
1620 @cindex -fugly option
1621 @cindex options, -fugly
1622 @item -fugly
1623 @cindex ugly features
1624 @cindex features, ugly
1625 Specify that certain ``ugly'' constructs are to be quietly accepted.
1626 Same as:
1627
1628 @smallexample
1629 -fugly-args -fugly-assign -fugly-assumed
1630 -fugly-comma -fugly-complex -fugly-init
1631 -fugly-logint
1632 @end smallexample
1633
1634 These constructs are considered inappropriate to use in new
1635 or well-maintained portable Fortran code, but widely used
1636 in old code.
1637 @xref{Distensions}, for more information.
1638
1639 @emph{Note:} The @samp{-fugly} option is likely to
1640 be removed in a future version.
1641 Implicitly enabling all the @samp{-fugly-*} options
1642 is unlikely to be feasible, or sensible, in the future,
1643 so users should learn to specify only those
1644 @samp{-fugly-*} options they really need for a
1645 particular source file.
1646
1647 @cindex -fno-ugly option
1648 @cindex options, -fno-ugly
1649 @item -fno-ugly
1650 @cindex ugly features
1651 @cindex features, ugly
1652 Specify that all ``ugly'' constructs are to be noisily rejected.
1653 Same as:
1654
1655 @smallexample
1656 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1657 -fno-ugly-comma -fno-ugly-complex -fno-ugly-init
1658 -fno-ugly-logint
1659 @end smallexample
1660
1661 @xref{Distensions}, for more information.
1662
1663 @cindex -ff66 option
1664 @cindex options, -ff66
1665 @item -ff66
1666 @cindex FORTRAN 66
1667 @cindex compatibility, FORTRAN 66
1668 Specify that the program is written in idiomatic FORTRAN 66.
1669 Same as @samp{-fonetrip -fugly-assumed}.
1670
1671 The @samp{-fno-f66} option is the inverse of @samp{-ff66}.
1672 As such, it is the same as @samp{-fno-onetrip -fno-ugly-assumed}.
1673
1674 The meaning of this option is likely to be refined as future
1675 versions of @code{g77} provide more compatibility with other
1676 existing and obsolete Fortran implementations.
1677
1678 @cindex -ff77 option
1679 @cindex options, -ff77
1680 @item -ff77
1681 @cindex UNIX f77
1682 @cindex @code{f2c} compatibility
1683 @cindex compatibility, @code{f2c}
1684 @cindex @code{f77} compatibility
1685 @cindex compatibility, @code{f77}
1686 Specify that the program is written in idiomatic UNIX FORTRAN 77
1687 and/or the dialect accepted by the @code{f2c} product.
1688 Same as @samp{-fbackslash -fno-typeless-boz}.
1689
1690 The meaning of this option is likely to be refined as future
1691 versions of @code{g77} provide more compatibility with other
1692 existing and obsolete Fortran implementations.
1693
1694 @cindex -fno-f77 option
1695 @cindex options, -fno-f77
1696 @item -fno-f77
1697 @cindex UNIX f77
1698 The @samp{-fno-f77} option is @emph{not} the inverse
1699 of @samp{-ff77}.
1700 It specifies that the program is not written in idiomatic UNIX
1701 FORTRAN 77 or @code{f2c}, but in a more widely portable dialect.
1702 @samp{-fno-f77} is the same as @samp{-fno-backslash}.
1703
1704 The meaning of this option is likely to be refined as future
1705 versions of @code{g77} provide more compatibility with other
1706 existing and obsolete Fortran implementations.
1707 @end table
1708
1709 @node Fortran Dialect Options
1710 @section Options Controlling Fortran Dialect
1711 @cindex dialect options
1712 @cindex language dialect options
1713 @cindex options, dialect
1714
1715 The following options control the dialect of Fortran
1716 that the compiler accepts:
1717
1718 @table @code
1719 @cindex -ffree-form option
1720 @cindex options, -ffree-form
1721 @cindex -fno-fixed-form option
1722 @cindex options, -fno-fixed-form
1723 @cindex source file form
1724 @cindex free form
1725 @cindex fixed form
1726 @cindex Fortran 90 features
1727 @item -ffree-form
1728 @item -fno-fixed-form
1729 Specify that the source file is written in free form
1730 (introduced in Fortran 90) instead of the more-traditional fixed form.
1731
1732 @cindex -ff90 option
1733 @cindex options, -ff90
1734 @cindex Fortran 90 features
1735 @item -ff90
1736 Allow certain Fortran-90 constructs.
1737
1738 This option controls whether certain
1739 Fortran 90 constructs are recognized.
1740 (Other Fortran 90 constructs
1741 might or might not be recognized depending on other options such as
1742 @samp{-fvxt}, @samp{-ff90-intrinsics-enable}, and the
1743 current level of support for Fortran 90.)
1744
1745 @xref{Fortran 90}, for more information.
1746
1747 @cindex -fvxt option
1748 @cindex options, -fvxt
1749 @item -fvxt
1750 @cindex Fortran 90 features
1751 @cindex VXT features
1752 Specify the treatment of certain constructs that have different
1753 meanings depending on whether the code is written in
1754 GNU Fortran (based on FORTRAN 77 and akin to Fortran 90)
1755 or VXT Fortran (more like VAX FORTRAN).
1756
1757 The default is @samp{-fno-vxt}.
1758 @samp{-fvxt} specifies that the VXT Fortran interpretations
1759 for those constructs are to be chosen.
1760
1761 @xref{VXT Fortran}, for more information.
1762
1763 @cindex -fdollar-ok option
1764 @cindex options, -fdollar-ok
1765 @item -fdollar-ok
1766 @cindex dollar sign
1767 @cindex symbol names
1768 @cindex character set
1769 Allow @samp{$} as a valid character in a symbol name.
1770
1771 @cindex -fno-backslash option
1772 @cindex options, -fno-backslash
1773 @item -fno-backslash
1774 @cindex backslash
1775 @cindex character constants
1776 @cindex Hollerith constants
1777 Specify that @samp{\} is not to be specially interpreted in character
1778 and Hollerith constants a la C and many UNIX Fortran compilers.
1779
1780 For example, with @samp{-fbackslash} in effect, @samp{A\nB} specifies
1781 three characters, with the second one being newline.
1782 With @samp{-fno-backslash}, it specifies four characters,
1783 @samp{A}, @samp{\}, @samp{n}, and @samp{B}.
1784
1785 Note that @code{g77} implements a fairly general form of backslash
1786 processing that is incompatible with the narrower forms supported
1787 by some other compilers.
1788 For example, @samp{'A\003B'} is a three-character string in @code{g77},
1789 whereas other compilers that support backslash might not support
1790 the three-octal-digit form, and thus treat that string as longer
1791 than three characters.
1792
1793 @xref{Backslash in Constants}, for
1794 information on why @samp{-fbackslash} is the default
1795 instead of @samp{-fno-backslash}.
1796
1797 @cindex -fno-ugly-args option
1798 @cindex options, -fno-ugly-args
1799 @item -fno-ugly-args
1800 Disallow passing Hollerith and typeless constants as actual
1801 arguments (for example, @samp{CALL FOO(4HABCD)}).
1802
1803 @xref{Ugly Implicit Argument Conversion}, for more information.
1804
1805 @cindex -fugly-assign option
1806 @cindex options, -fugly-assign
1807 @item -fugly-assign
1808 Use the same storage for a given variable regardless of
1809 whether it is used to hold an assigned-statement label
1810 (as in @samp{ASSIGN 10 TO I}) or used to hold numeric data
1811 (as in @samp{I = 3}).
1812
1813 @xref{Ugly Assigned Labels}, for more information.
1814
1815 @cindex -fugly-assumed option
1816 @cindex options, -fugly-assumed
1817 @item -fugly-assumed
1818 Assume any dummy array with a final dimension specified as @samp{1}
1819 is really an assumed-size array, as if @samp{*} had been specified
1820 for the final dimension instead of @samp{1}.
1821
1822 For example, @samp{DIMENSION X(1)} is treated as if it
1823 had read @samp{DIMENSION X(*)}.
1824
1825 @xref{Ugly Assumed-Size Arrays}, for more information.
1826
1827 @cindex -fugly-comma option
1828 @cindex options, -fugly-comma
1829 @item -fugly-comma
1830 Treat a trailing comma in an argument list as specification
1831 of a trailing null argument, and treat an empty argument
1832 list as specification of a single null argument.
1833
1834 For example, @samp{CALL FOO(,)} is treated as
1835 @samp{CALL FOO(%VAL(0), %VAL(0))}.
1836 That is, @emph{two} null arguments are specified
1837 by the procedure call when @samp{-fugly-comma} is in force.
1838 And @samp{F = FUNC()} is treated as @samp{F = FUNC(%VAL(0))}.
1839
1840 The default behavior, @samp{-fno-ugly-comma}, is to ignore
1841 a single trailing comma in an argument list.
1842
1843 @xref{Ugly Null Arguments}, for more information.
1844
1845 @cindex -fugly-complex option
1846 @cindex options, -fugly-complex
1847 @item -fugly-complex
1848 Do not complain about @samp{REAL(@var{expr})} or
1849 @samp{AIMAG(@var{expr})} when @var{expr} is a @code{COMPLEX}
1850 type other than @code{COMPLEX(KIND=1)}---usually
1851 this is used to permit @code{COMPLEX(KIND=2)}
1852 (@code{DOUBLE COMPLEX}) operands.
1853
1854 The @samp{-ff90} option controls the interpretation
1855 of this construct.
1856
1857 @xref{Ugly Complex Part Extraction}, for more information.
1858
1859 @cindex -fno-ugly-init option
1860 @cindex options, -fno-ugly-init
1861 @item -fno-ugly-init
1862 Disallow use of Hollerith and typeless constants as initial
1863 values (in @code{PARAMETER} and @code{DATA} statements), and
1864 use of character constants to
1865 initialize numeric types and vice versa.
1866
1867 For example, @samp{DATA I/'F'/, CHRVAR/65/, J/4HABCD/} is disallowed by
1868 @samp{-fno-ugly-init}.
1869
1870 @xref{Ugly Conversion of Initializers}, for more information.
1871
1872 @cindex -fugly-logint option
1873 @cindex options, -fugly-logint
1874 @item -fugly-logint
1875 Treat @code{INTEGER} and @code{LOGICAL} variables and
1876 expressions as potential stand-ins for each other.
1877
1878 For example, automatic conversion between @code{INTEGER} and
1879 @code{LOGICAL} is enabled, for many contexts, via this option.
1880
1881 @xref{Ugly Integer Conversions}, for more information.
1882
1883 @cindex -fonetrip option
1884 @cindex options, -fonetrip
1885 @item -fonetrip
1886 @cindex FORTRAN 66
1887 @cindex DO loops, one-trip
1888 @cindex one-trip DO loops
1889 @cindex compatibility, FORTRAN 66
1890 Imperative executable @code{DO} loops are to be executed at
1891 least once each time they are reached.
1892
1893 ANSI FORTRAN 77 and more recent versions of the Fortran standard
1894 specify that the body of an imperative @code{DO} loop is not executed
1895 if the number of iterations calculated from the parameters of the
1896 loop is less than 1.
1897 (For example, @samp{DO 10 I = 1, 0}.)@
1898 Such a loop is called a @dfn{zero-trip loop}.
1899
1900 Prior to ANSI FORTRAN 77, many compilers implemented @code{DO} loops
1901 such that the body of a loop would be executed at least once, even
1902 if the iteration count was zero.
1903 Fortran code written assuming this behavior is said to require
1904 @dfn{one-trip loops}.
1905 For example, some code written to the FORTRAN 66 standard
1906 expects this behavior from its @code{DO} loops, although that
1907 standard did not specify this behavior.
1908
1909 The @samp{-fonetrip} option specifies that the source file(s) being
1910 compiled require one-trip loops.
1911
1912 This option affects only those loops specified by the (imperative) @code{DO}
1913 statement and by implied-@code{DO} lists in I/O statements.
1914 Loops specified by implied-@code{DO} lists in @code{DATA} and
1915 specification (non-executable) statements are not affected.
1916
1917 @cindex -ftypeless-boz option
1918 @cindex options, -ftypeless-boz
1919 @cindex prefix-radix constants
1920 @cindex constants, prefix-radix
1921 @cindex constants, types
1922 @cindex types, constants
1923 @item -ftypeless-boz
1924 Specifies that prefix-radix non-decimal constants, such as
1925 @samp{Z'ABCD'}, are typeless instead of @code{INTEGER(KIND=1)}.
1926
1927 You can test for yourself whether a particular compiler treats
1928 the prefix form as @code{INTEGER(KIND=1)} or typeless by running the
1929 following program:
1930
1931 @smallexample
1932 EQUIVALENCE (I, R)
1933 R = Z'ABCD1234'
1934 J = Z'ABCD1234'
1935 IF (J .EQ. I) PRINT *, 'Prefix form is TYPELESS'
1936 IF (J .NE. I) PRINT *, 'Prefix form is INTEGER'
1937 END
1938 @end smallexample
1939
1940 Reports indicate that many compilers process this form as
1941 @code{INTEGER(KIND=1)}, though a few as typeless, and at least one
1942 based on a command-line option specifying some kind of
1943 compatibility.
1944
1945 @cindex -fintrin-case-initcap option
1946 @cindex options, -fintrin-case-initcap
1947 @item -fintrin-case-initcap
1948 @cindex -fintrin-case-upper option
1949 @cindex options, -fintrin-case-upper
1950 @item -fintrin-case-upper
1951 @cindex -fintrin-case-lower option
1952 @cindex options, -fintrin-case-lower
1953 @item -fintrin-case-lower
1954 @cindex -fintrin-case-any option
1955 @cindex options, -fintrin-case-any
1956 @item -fintrin-case-any
1957 Specify expected case for intrinsic names.
1958 @samp{-fintrin-case-lower} is the default.
1959
1960 @cindex -fmatch-case-initcap option
1961 @cindex options, -fmatch-case-initcap
1962 @item -fmatch-case-initcap
1963 @cindex -fmatch-case-upper option
1964 @cindex options, -fmatch-case-upper
1965 @item -fmatch-case-upper
1966 @cindex -fmatch-case-lower option
1967 @cindex options, -fmatch-case-lower
1968 @item -fmatch-case-lower
1969 @cindex -fmatch-case-any option
1970 @cindex options, -fmatch-case-any
1971 @item -fmatch-case-any
1972 Specify expected case for keywords.
1973 @samp{-fmatch-case-lower} is the default.
1974
1975 @cindex -fsource-case-upper option
1976 @cindex options, -fsource-case-upper
1977 @item -fsource-case-upper
1978 @cindex -fsource-case-lower option
1979 @cindex options, -fsource-case-lower
1980 @item -fsource-case-lower
1981 @cindex -fsource-case-preserve option
1982 @cindex options, -fsource-case-preserve
1983 @item -fsource-case-preserve
1984 Specify whether source text other than character and Hollerith constants
1985 is to be translated to uppercase, to lowercase, or preserved as is.
1986 @samp{-fsource-case-lower} is the default.
1987
1988 @cindex -fsymbol-case-initcap option
1989 @cindex options, -fsymbol-case-initcap
1990 @item -fsymbol-case-initcap
1991 @cindex -fsymbol-case-upper option
1992 @cindex options, -fsymbol-case-upper
1993 @item -fsymbol-case-upper
1994 @cindex -fsymbol-case-lower option
1995 @cindex options, -fsymbol-case-lower
1996 @item -fsymbol-case-lower
1997 @cindex -fsymbol-case-any option
1998 @cindex options, -fsymbol-case-any
1999 @item -fsymbol-case-any
2000 Specify valid cases for user-defined symbol names.
2001 @samp{-fsymbol-case-any} is the default.
2002
2003 @cindex -fcase-strict-upper option
2004 @cindex options, -fcase-strict-upper
2005 @item -fcase-strict-upper
2006 Same as @samp{-fintrin-case-upper -fmatch-case-upper -fsource-case-preserve
2007 -fsymbol-case-upper}.
2008 (Requires all pertinent source to be in uppercase.)
2009
2010 @cindex -fcase-strict-lower option
2011 @cindex options, -fcase-strict-lower
2012 @item -fcase-strict-lower
2013 Same as @samp{-fintrin-case-lower -fmatch-case-lower -fsource-case-preserve
2014 -fsymbol-case-lower}.
2015 (Requires all pertinent source to be in lowercase.)
2016
2017 @cindex -fcase-initcap option
2018 @cindex options, -fcase-initcap
2019 @item -fcase-initcap
2020 Same as @samp{-fintrin-case-initcap -fmatch-case-initcap -fsource-case-preserve
2021 -fsymbol-case-initcap}.
2022 (Requires all pertinent source to be in initial capitals,
2023 as in @samp{Print *,SqRt(Value)}.)
2024
2025 @cindex -fcase-upper option
2026 @cindex options, -fcase-upper
2027 @item -fcase-upper
2028 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-upper
2029 -fsymbol-case-any}.
2030 (Maps all pertinent source to uppercase.)
2031
2032 @cindex -fcase-lower option
2033 @cindex options, -fcase-lower
2034 @item -fcase-lower
2035 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-lower
2036 -fsymbol-case-any}.
2037 (Maps all pertinent source to lowercase.)
2038
2039 @cindex -fcase-preserve option
2040 @cindex options, -fcase-preserve
2041 @item -fcase-preserve
2042 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-preserve
2043 -fsymbol-case-any}.
2044 (Preserves all case in user-defined symbols,
2045 while allowing any-case matching of intrinsics and keywords.
2046 For example, @samp{call Foo(i,I)} would pass two @emph{different}
2047 variables named @samp{i} and @samp{I} to a procedure named @samp{Foo}.)
2048
2049 @cindex -ff2c-intrinsics-delete option
2050 @cindex options, -ff2c-intrinsics-delete
2051 @item -ff2c-intrinsics-delete
2052 @cindex -ff2c-intrinsics-hide option
2053 @cindex options, -ff2c-intrinsics-hide
2054 @item -ff2c-intrinsics-hide
2055 @cindex -ff2c-intrinsics-disable option
2056 @cindex options, -ff2c-intrinsics-disable
2057 @item -ff2c-intrinsics-disable
2058 @cindex -ff2c-intrinsics-enable option
2059 @cindex options, -ff2c-intrinsics-enable
2060 @item -ff2c-intrinsics-enable
2061 @cindex f2c intrinsics
2062 @cindex intrinsics, f2c
2063 Specify status of f2c-specific intrinsics.
2064 @samp{-ff2c-intrinsics-enable} is the default.
2065
2066 @cindex -ff90-intrinsics-delete option
2067 @cindex options, -ff90-intrinsics-delete
2068 @item -ff90-intrinsics-delete
2069 @cindex -ff90-intrinsics-hide option
2070 @cindex options, -ff90-intrinsics-hide
2071 @item -ff90-intrinsics-hide
2072 @cindex -ff90-intrinsics-disable option
2073 @cindex options, -ff90-intrinsics-disable
2074 @item -ff90-intrinsics-disable
2075 @cindex -ff90-intrinsics-enable option
2076 @cindex options, -ff90-intrinsics-enable
2077 @item -ff90-intrinsics-enable
2078 @cindex Fortran 90 intrinsics
2079 @cindex intrinsics, Fortran 90
2080 Specify status of F90-specific intrinsics.
2081 @samp{-ff90-intrinsics-enable} is the default.
2082
2083 @cindex -fgnu-intrinsics-delete option
2084 @cindex options, -fgnu-intrinsics-delete
2085 @item -fgnu-intrinsics-delete
2086 @cindex -fgnu-intrinsics-hide option
2087 @cindex options, -fgnu-intrinsics-hide
2088 @item -fgnu-intrinsics-hide
2089 @cindex -fgnu-intrinsics-disable option
2090 @cindex options, -fgnu-intrinsics-disable
2091 @item -fgnu-intrinsics-disable
2092 @cindex -fgnu-intrinsics-enable option
2093 @cindex options, -fgnu-intrinsics-enable
2094 @item -fgnu-intrinsics-enable
2095 @cindex Digital Fortran features
2096 @cindex COMPLEX intrinsics
2097 @cindex intrinsics, COMPLEX
2098 Specify status of Digital's COMPLEX-related intrinsics.
2099 @samp{-fgnu-intrinsics-enable} is the default.
2100
2101 @cindex -fmil-intrinsics-delete option
2102 @cindex options, -fmil-intrinsics-delete
2103 @item -fmil-intrinsics-delete
2104 @cindex -fmil-intrinsics-hide option
2105 @cindex options, -fmil-intrinsics-hide
2106 @item -fmil-intrinsics-hide
2107 @cindex -fmil-intrinsics-disable option
2108 @cindex options, -fmil-intrinsics-disable
2109 @item -fmil-intrinsics-disable
2110 @cindex -fmil-intrinsics-enable option
2111 @cindex options, -fmil-intrinsics-enable
2112 @item -fmil-intrinsics-enable
2113 @cindex MIL-STD 1753
2114 @cindex intrinsics, MIL-STD 1753
2115 Specify status of MIL-STD-1753-specific intrinsics.
2116 @samp{-fmil-intrinsics-enable} is the default.
2117
2118 @cindex -funix-intrinsics-delete option
2119 @cindex options, -funix-intrinsics-delete
2120 @item -funix-intrinsics-delete
2121 @cindex -funix-intrinsics-hide option
2122 @cindex options, -funix-intrinsics-hide
2123 @item -funix-intrinsics-hide
2124 @cindex -funix-intrinsics-disable option
2125 @cindex options, -funix-intrinsics-disable
2126 @item -funix-intrinsics-disable
2127 @cindex -funix-intrinsics-enable option
2128 @cindex options, -funix-intrinsics-enable
2129 @item -funix-intrinsics-enable
2130 @cindex UNIX intrinsics
2131 @cindex intrinsics, UNIX
2132 Specify status of UNIX intrinsics.
2133 @samp{-funix-intrinsics-enable} is the default.
2134
2135 @cindex -fvxt-intrinsics-delete option
2136 @cindex options, -fvxt-intrinsics-delete
2137 @item -fvxt-intrinsics-delete
2138 @cindex -fvxt-intrinsics-hide option
2139 @cindex options, -fvxt-intrinsics-hide
2140 @item -fvxt-intrinsics-hide
2141 @cindex -fvxt-intrinsics-disable option
2142 @cindex options, -fvxt-intrinsics-disable
2143 @item -fvxt-intrinsics-disable
2144 @cindex -fvxt-intrinsics-enable option
2145 @cindex options, -fvxt-intrinsics-enable
2146 @item -fvxt-intrinsics-enable
2147 @cindex VXT intrinsics
2148 @cindex intrinsics, VXT
2149 Specify status of VXT intrinsics.
2150 @samp{-fvxt-intrinsics-enable} is the default.
2151
2152 @cindex -ffixed-line-length-@var{n} option
2153 @cindex options, -ffixed-line-length-@var{n}
2154 @item -ffixed-line-length-@var{n}
2155 @cindex source file format
2156 @cindex line length
2157 @cindex length of source lines
2158 @cindex fixed-form line length
2159 Set column after which characters are ignored in typical fixed-form
2160 lines in the source file, and through which spaces are assumed (as
2161 if padded to that length) after the ends of short fixed-form lines.
2162
2163 @cindex card image
2164 @cindex extended-source option
2165 Popular values for @var{n} include 72 (the
2166 standard and the default), 80 (card image), and 132 (corresponds
2167 to ``extended-source'' options in some popular compilers).
2168 @var{n} may be @samp{none}, meaning that the entire line is meaningful
2169 and that continued character constants never have implicit spaces appended
2170 to them to fill out the line.
2171 @samp{-ffixed-line-length-0} means the same thing as
2172 @samp{-ffixed-line-length-none}.
2173
2174 @xref{Source Form}, for more information.
2175 @end table
2176
2177 @node Warning Options
2178 @section Options to Request or Suppress Warnings
2179 @cindex options to control warnings
2180 @cindex warning messages
2181 @cindex messages, warning
2182 @cindex suppressing warnings
2183
2184 Warnings are diagnostic messages that report constructions which
2185 are not inherently erroneous but which are risky or suggest there
2186 might have been an error.
2187
2188 You can request many specific warnings with options beginning @samp{-W},
2189 for example @samp{-Wimplicit} to request warnings on implicit
2190 declarations. Each of these specific warning options also has a
2191 negative form beginning @samp{-Wno-} to turn off warnings;
2192 for example, @samp{-Wno-implicit}. This manual lists only one of the
2193 two forms, whichever is not the default.
2194
2195 These options control the amount and kinds of warnings produced by GNU
2196 Fortran:
2197
2198 @table @code
2199 @cindex syntax checking
2200 @cindex -fsyntax-only option
2201 @cindex options, -fsyntax-only
2202 @item -fsyntax-only
2203 Check the code for syntax errors, but don't do anything beyond that.
2204
2205 @cindex -pedantic option
2206 @cindex options, -pedantic
2207 @item -pedantic
2208 Issue warnings for uses of extensions to ANSI FORTRAN 77.
2209 @samp{-pedantic} also applies to C-language constructs where they
2210 occur in GNU Fortran source files, such as use of @samp{\e} in a
2211 character constant within a directive like @samp{#include}.
2212
2213 Valid ANSI FORTRAN 77 programs should compile properly with or without
2214 this option.
2215 However, without this option, certain GNU extensions and traditional
2216 Fortran features are supported as well.
2217 With this option, many of them are rejected.
2218
2219 Some users try to use @samp{-pedantic} to check programs for strict ANSI
2220 conformance.
2221 They soon find that it does not do quite what they want---it finds some
2222 non-ANSI practices, but not all.
2223 However, improvements to @code{g77} in this area are welcome.
2224
2225 @cindex -pedantic-errors option
2226 @cindex options, -pedantic-errors
2227 @item -pedantic-errors
2228 Like @samp{-pedantic}, except that errors are produced rather than
2229 warnings.
2230
2231 @cindex -fpedantic option
2232 @cindex options, -fpedantic
2233 @item -fpedantic
2234 Like @samp{-pedantic}, but applies only to Fortran constructs.
2235
2236 @cindex -w option
2237 @cindex options, -w
2238 @item -w
2239 Inhibit all warning messages.
2240
2241 @cindex -Wno-globals option
2242 @cindex options, -Wno-globals
2243 @item -Wno-globals
2244 @cindex global names, warning
2245 @cindex warnings, global names
2246 Inhibit warnings about use of a name as both a global name
2247 (a subroutine, function, or block data program unit, or a
2248 common block) and implicitly as the name of an intrinsic
2249 in a source file.
2250
2251 Also inhibit warnings about inconsistent invocations and/or
2252 definitions of global procedures (function and subroutines).
2253 Such inconsistencies include different numbers of arguments
2254 and different types of arguments.
2255
2256 @cindex -Wimplicit option
2257 @cindex options, -Wimplicit
2258 @item -Wimplicit
2259 @cindex implicit declaration, warning
2260 @cindex warnings, implicit declaration
2261 @cindex -u option
2262 @cindex /WARNINGS=DECLARATIONS switch
2263 @cindex IMPLICIT NONE, similar effect
2264 @cindex effecting IMPLICIT NONE
2265 Warn whenever a variable, array, or function is implicitly
2266 declared.
2267 Has an effect similar to using the @code{IMPLICIT NONE} statement
2268 in every program unit.
2269 (Some Fortran compilers provide this feature by an option
2270 named @samp{-u} or @samp{/WARNINGS=DECLARATIONS}.)
2271
2272 @cindex -Wunused option
2273 @cindex options, -Wunused
2274 @item -Wunused
2275 @cindex unused variables
2276 @cindex variables, unused
2277 Warn whenever a variable is unused aside from its declaration.
2278
2279 @cindex -Wuninitialized option
2280 @cindex options, -Wuninitialized
2281 @item -Wuninitialized
2282 @cindex uninitialized variables
2283 @cindex variables, uninitialized
2284 Warn whenever an automatic variable is used without first being initialized.
2285
2286 These warnings are possible only in optimizing compilation,
2287 because they require data-flow information that is computed only
2288 when optimizing. If you don't specify @samp{-O}, you simply won't
2289 get these warnings.
2290
2291 These warnings occur only for variables that are candidates for
2292 register allocation. Therefore, they do not occur for a variable
2293 @c that is declared @code{VOLATILE}, or
2294 whose address is taken, or whose size
2295 is other than 1, 2, 4 or 8 bytes. Also, they do not occur for
2296 arrays, even when they are in registers.
2297
2298 Note that there might be no warning about a variable that is used only
2299 to compute a value that itself is never used, because such
2300 computations may be deleted by data-flow analysis before the warnings
2301 are printed.
2302
2303 These warnings are made optional because GNU Fortran is not smart
2304 enough to see all the reasons why the code might be correct
2305 despite appearing to have an error. Here is one example of how
2306 this can happen:
2307
2308 @example
2309 SUBROUTINE DISPAT(J)
2310 IF (J.EQ.1) I=1
2311 IF (J.EQ.2) I=4
2312 IF (J.EQ.3) I=5
2313 CALL FOO(I)
2314 END
2315 @end example
2316
2317 @noindent
2318 If the value of @code{J} is always 1, 2 or 3, then @code{I} is
2319 always initialized, but GNU Fortran doesn't know this. Here is
2320 another common case:
2321
2322 @example
2323 SUBROUTINE MAYBE(FLAG)
2324 LOGICAL FLAG
2325 IF (FLAG) VALUE = 9.4
2326 @dots{}
2327 IF (FLAG) PRINT *, VALUE
2328 END
2329 @end example
2330
2331 @noindent
2332 This has no bug because @code{VALUE} is used only if it is set.
2333
2334 @cindex -Wall option
2335 @cindex options, -Wall
2336 @item -Wall
2337 @cindex all warnings
2338 @cindex warnings, all
2339 The @samp{-Wunused} and @samp{-Wuninitialized} options combined.
2340 These are all the
2341 options which pertain to usage that we recommend avoiding and that we
2342 believe is easy to avoid.
2343 (As more warnings are added to @code{g77}, some might
2344 be added to the list enabled by @samp{-Wall}.)
2345 @end table
2346
2347 The remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}
2348 because they warn about constructions that we consider reasonable to
2349 use, on occasion, in clean programs.
2350
2351 @table @code
2352 @c @item -W
2353 @c Print extra warning messages for these events:
2354 @c
2355 @c @itemize @bullet
2356 @c @item
2357 @c If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused
2358 @c arguments.
2359 @c
2360 @c @end itemize
2361 @c
2362 @cindex -Wsurprising option
2363 @cindex options, -Wsurprising
2364 @item -Wsurprising
2365 Warn about ``suspicious'' constructs that are interpreted
2366 by the compiler in a way that might well be surprising to
2367 someone reading the code.
2368 These differences can result in subtle, compiler-dependent
2369 (even machine-dependent) behavioral differences.
2370 The constructs warned about include:
2371
2372 @itemize @bullet
2373 @item
2374 Expressions having two arithmetic operators in a row, such
2375 as @samp{X*-Y}.
2376 Such a construct is nonstandard, and can produce
2377 unexpected results in more complicated situations such
2378 as @samp{X**-Y*Z}.
2379 @code{g77}, along with many other compilers, interprets
2380 this example differently than many programmers, and a few
2381 other compilers.
2382 Specifically, @code{g77} interprets @samp{X**-Y*Z} as
2383 @samp{(X**(-Y))*Z}, while others might think it should
2384 be interpreted as @samp{X**(-(Y*Z))}.
2385
2386 A revealing example is the constant expression @samp{2**-2*1.},
2387 which @code{g77} evaluates to .25, while others might evaluate
2388 it to 0., the difference resulting from the way precedence affects
2389 type promotion.
2390
2391 (The @samp{-fpedantic} option also warns about expressions
2392 having two arithmetic operators in a row.)
2393
2394 @item
2395 Expressions with a unary minus followed by an operand and then
2396 a binary operator other than plus or minus.
2397 For example, @samp{-2**2} produces a warning, because
2398 the precedence is @samp{-(2**2)}, yielding -4, not
2399 @samp{(-2)**2}, which yields 4, and which might represent
2400 what a programmer expects.
2401
2402 An example of an expression producing different results
2403 in a surprising way is @samp{-I*S}, where @var{I} holds
2404 the value @samp{-2147483648} and @var{S} holds @samp{0.5}.
2405 On many systems, negating @var{I} results in the same
2406 value, not a positive number, because it is already the
2407 lower bound of what an @code{INTEGER(KIND=1)} variable can hold.
2408 So, the expression evaluates to a positive number, while
2409 the ``expected'' interpretation, @samp{(-I)*S}, would
2410 evaluate to a negative number.
2411
2412 Even cases such as @samp{-I*J} produce warnings,
2413 even though, in most configurations and situations,
2414 there is no computational difference between the
2415 results of the two interpretations---the purpose
2416 of this warning is to warn about differing interpretations
2417 and encourage a better style of coding, not to identify
2418 only those places where bugs might exist in the user's
2419 code.
2420
2421 @cindex DO statement
2422 @cindex statements, DO
2423 @item
2424 @code{DO} loops with @code{DO} variables that are not
2425 of integral type---that is, using @code{REAL}
2426 variables as loop control variables.
2427 Although such loops can be written to work in the
2428 ``obvious'' way, the way @code{g77} is required by the
2429 Fortran standard to interpret such code is likely to
2430 be quite different from the way many programmers expect.
2431 (This is true of all @code{DO} loops, but the differences
2432 are pronounced for non-integral loop control variables.)
2433
2434 @xref{Loops}, for more information.
2435 @end itemize
2436
2437 @cindex -Werror option
2438 @cindex options, -Werror
2439 @item -Werror
2440 Make all warnings into errors.
2441
2442 @cindex -W option
2443 @cindex options, -W
2444 @item -W
2445 @cindex extra warnings
2446 @cindex warnings, extra
2447 Turns on ``extra warnings'' and, if optimization is specified
2448 via @samp{-O}, the @samp{-Wuninitialized} option.
2449 (This might change in future versions of @code{g77}.)
2450
2451 ``Extra warnings'' are issued for:
2452
2453 @itemize @bullet
2454 @item
2455 @cindex unused parameters
2456 @cindex parameters, unused
2457 @cindex unused arguments
2458 @cindex arguments, unused
2459 @cindex unused dummies
2460 @cindex dummies, unused
2461 Unused parameters to a procedure (when @samp{-Wunused} also is
2462 specified).
2463
2464 @item
2465 @cindex overflow
2466 Overflows involving floating-point constants (not available
2467 for certain configurations).
2468 @end itemize
2469 @end table
2470
2471 @xref{Warning Options,,Options to Request or Suppress Warnings,
2472 gcc,Using and Porting GNU CC}, for information on more options offered
2473 by the GBE shared by @code{g77}, @code{gcc}, and other GNU compilers.
2474
2475 Some of these have no effect when compiling programs written in Fortran:
2476
2477 @table @code
2478 @cindex -Wcomment option
2479 @cindex options, -Wcomment
2480 @item -Wcomment
2481 @cindex -Wformat option
2482 @cindex options, -Wformat
2483 @item -Wformat
2484 @cindex -Wparentheses option
2485 @cindex options, -Wparentheses
2486 @item -Wparentheses
2487 @cindex -Wswitch option
2488 @cindex options, -Wswitch
2489 @item -Wswitch
2490 @cindex -Wtraditional option
2491 @cindex options, -Wtraditional
2492 @item -Wtraditional
2493 @cindex -Wshadow option
2494 @cindex options, -Wshadow
2495 @item -Wshadow
2496 @cindex -Wid-clash-@var{len} option
2497 @cindex options, -Wid-clash-@var{len}
2498 @item -Wid-clash-@var{len}
2499 @cindex -Wlarger-than-@var{len} option
2500 @cindex options, -Wlarger-than-@var{len}
2501 @item -Wlarger-than-@var{len}
2502 @cindex -Wconversion option
2503 @cindex options, -Wconversion
2504 @item -Wconversion
2505 @cindex -Waggregate-return option
2506 @cindex options, -Waggregate-return
2507 @item -Waggregate-return
2508 @cindex -Wredundant-decls option
2509 @cindex options, -Wredundant-decls
2510 @item -Wredundant-decls
2511 @cindex unsupported warnings
2512 @cindex warnings, unsupported
2513 These options all could have some relevant meaning for
2514 GNU Fortran programs, but are not yet supported.
2515 @end table
2516
2517 @node Debugging Options
2518 @section Options for Debugging Your Program or GNU Fortran
2519 @cindex options, debugging
2520 @cindex debugging information options
2521
2522 GNU Fortran has various special options that are used for debugging
2523 either your program or @code{g77}.
2524
2525 @table @code
2526 @cindex -g option
2527 @cindex options, -g
2528 @item -g
2529 Produce debugging information in the operating system's native format
2530 (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging
2531 information.
2532
2533 @cindex common blocks
2534 @cindex equivalence areas
2535 @cindex missing debug features
2536 Support for this option in Fortran programs is incomplete.
2537 In particular, names of variables and arrays in common blocks
2538 or that are storage-associated via @code{EQUIVALENCE} are
2539 unavailable to the debugger.
2540
2541 However, version 0.5.19 of @code{g77} does provide this information
2542 in a rudimentary way, as controlled by the
2543 @samp{-fdebug-kludge} option.
2544
2545 @xref{Code Gen Options,,Options for Code Generation Conventions},
2546 for more information.
2547 @end table
2548
2549 @xref{Debugging Options,,Options for Debugging Your Program or GNU CC,
2550 gcc,Using and Porting GNU CC}, for more information on debugging options.
2551
2552 @node Optimize Options
2553 @section Options That Control Optimization
2554 @cindex optimize options
2555 @cindex options, optimization
2556
2557 Most Fortran users will want to use no optimization when
2558 developing and testing programs, and use @samp{-O} or @samp{-O2} when
2559 compiling programs for late-cycle testing and for production use.
2560
2561 The following flags have particular applicability when
2562 compiling Fortran programs:
2563
2564 @table @code
2565 @cindex -malign-double option
2566 @cindex options, -malign-double
2567 @item -malign-double
2568 (Intel 386 architecture only.)
2569
2570 Noticeably improves performance of @code{g77} programs making
2571 heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data
2572 on some systems.
2573 In particular, systems using Pentium, Pentium Pro, 586, and
2574 686 implementations
2575 of the i386 architecture execute programs faster when
2576 @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data are
2577 aligned on 64-bit boundaries
2578 in memory.
2579
2580 This option can, at least, make benchmark results more consistent
2581 across various system configurations, versions of the program,
2582 and data sets.
2583
2584 @emph{Note:} The warning in the @code{gcc} documentation about
2585 this option does not apply, generally speaking, to Fortran
2586 code compiled by @code{g77}.
2587
2588 @emph{Also note:} @code{g77} fixes a @code{gcc} backend bug to allow
2589 @samp{-malign-double} to work generally, not just with
2590 statically-allocated data.
2591
2592 @emph{Also also note:} The negative form of @samp{-malign-double}
2593 is @samp{-mno-align-double}, not @samp{-benign-double}.
2594
2595 @cindex -ffloat-store option
2596 @cindex options, -ffloat-store
2597 @item -ffloat-store
2598 @cindex IEEE conformance
2599 @cindex conformance, IEEE
2600 Might help a Fortran program that depends on exact IEEE conformance
2601 on some machines, but might slow down a program that doesn't.
2602
2603 @cindex -fforce-mem option
2604 @cindex options, -fforce-mem
2605 @item -fforce-mem
2606 @cindex -fforce-addr option
2607 @cindex options, -fforce-addr
2608 @item -fforce-addr
2609 @cindex loops, speeding up
2610 @cindex speeding up loops
2611 Might improve optimization of loops.
2612
2613 @cindex -fno-inline option
2614 @cindex options, -fno-inline
2615 @item -fno-inline
2616 @cindex in-line compilation
2617 @cindex compilation, in-line
2618 Don't compile statement functions inline.
2619 Might reduce the size of a program unit---which might be at
2620 expense of some speed (though it should compile faster).
2621 Note that if you are not optimizing, no functions can be expanded inline.
2622
2623 @cindex -ffast-math option
2624 @cindex options, -ffast-math
2625 @item -ffast-math
2626 @cindex IEEE conformance
2627 @cindex conformance, IEEE
2628 Might allow some programs designed to not be too dependent
2629 on IEEE behavior for floating-point to run faster, or die trying.
2630
2631 @cindex -fstrength-reduce option
2632 @cindex options, -fstrength-reduce
2633 @item -fstrength-reduce
2634 @cindex loops, speeding up
2635 @cindex speeding up loops
2636 Might make some loops run faster.
2637
2638 @cindex -frerun-cse-after-loop option
2639 @cindex options, -frerun-cse-after-loop
2640 @item -frerun-cse-after-loop
2641 @cindex -fexpensive-optimizations option
2642 @cindex options, -fexpensive-optimizations
2643 @item -fexpensive-optimizations
2644 @cindex -fdelayed-branch option
2645 @cindex options, -fdelayed-branch
2646 @item -fdelayed-branch
2647 @cindex -fschedule-insns option
2648 @cindex options, -fschedule-insns
2649 @item -fschedule-insns
2650 @cindex -fschedule-insns2 option
2651 @cindex options, -fschedule-insns2
2652 @item -fschedule-insns2
2653 @cindex -fcaller-saves option
2654 @cindex options, -fcaller-saves
2655 @item -fcaller-saves
2656 Might improve performance on some code.
2657
2658 @cindex -funroll-loops option
2659 @cindex options, -funroll-loops
2660 @item -funroll-loops
2661 @cindex loops, unrolling
2662 @cindex unrolling loops
2663 Definitely improves performance on some code.
2664
2665 @cindex -funroll-all-loops option
2666 @cindex options, -funroll-all-loops
2667 @item -funroll-all-loops
2668 Definitely improves performance on some code.
2669
2670 @item -fno-move-all-movables
2671 @cindex -fno-move-all-movables option
2672 @cindex options, -fno-move-all-movables
2673 @item -fno-reduce-all-givs
2674 @cindex -fno-reduce-all-givs option
2675 @cindex options, -fno-reduce-all-givs
2676 @item -fno-rerun-loop-opt
2677 @cindex -fno-rerun-loop-opt option
2678 @cindex options, -fno-rerun-loop-opt
2679 Each of these might improve performance on some code.
2680
2681 Analysis of Fortran code optimization and the resulting
2682 optimizations triggered by the above options were
2683 contributed by Toon Moene (@email{toon@@moene.indiv.nluug.nl}).
2684
2685 These three options are intended to be removed someday, once
2686 they have helped determine the efficacy of various
2687 approaches to improving the performance of Fortran code.
2688
2689 Please let us know how use of these options affects
2690 the performance of your production code.
2691 We're particularly interested in code that runs faster
2692 when these options are @emph{disabled}, and in
2693 non-Fortran code that benefits when they are
2694 @emph{enabled} via the above @code{gcc} command-line options.
2695 @end table
2696
2697 @xref{Optimize Options,,Options That Control Optimization,
2698 gcc,Using and Porting GNU CC}, for more information on options
2699 to optimize the generated machine code.
2700
2701 @node Preprocessor Options
2702 @section Options Controlling the Preprocessor
2703 @cindex preprocessor options
2704 @cindex options, preprocessor
2705 @cindex cpp program
2706 @cindex programs, cpp
2707
2708 These options control the C preprocessor, which is run on each C source
2709 file before actual compilation.
2710
2711 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
2712 gcc,Using and Porting GNU CC}, for information on C preprocessor options.
2713
2714 @cindex INCLUDE directive
2715 @cindex directive, INCLUDE
2716 Some of these options also affect how @code{g77} processes the
2717 @code{INCLUDE} directive.
2718 Since this directive is processed even when preprocessing
2719 is not requested, it is not described in this section.
2720 @xref{Directory Options,,Options for Directory Search}, for
2721 information on how @code{g77} processes the @code{INCLUDE} directive.
2722
2723 However, the @code{INCLUDE} directive does not apply
2724 preprocessing to the contents of the included file itself.
2725
2726 Therefore, any file that contains preprocessor directives
2727 (such as @code{#include}, @code{#define}, and @code{#if})
2728 must be included via the @code{#include} directive, not
2729 via the @code{INCLUDE} directive.
2730 Therefore, any file containing preprocessor directives,
2731 if included, is necessarily included by a file that itself
2732 contains preprocessor directives.
2733
2734 @node Directory Options
2735 @section Options for Directory Search
2736 @cindex directory options
2737 @cindex options, directory search
2738 @cindex search path
2739
2740 These options affect how the @code{cpp} preprocessor searches
2741 for files specified via the @code{#include} directive.
2742 Therefore, when compiling Fortran programs, they are meaningful
2743 when the preproecssor is used.
2744
2745 @cindex INCLUDE directive
2746 @cindex directive, INCLUDE
2747 Some of these options also affect how @code{g77} searches
2748 for files specified via the @code{INCLUDE} directive,
2749 although files included by that directive are not,
2750 themselves, preprocessed.
2751 These options are:
2752
2753 @table @code
2754 @cindex -I- option
2755 @cindex options, -I-
2756 @item -I-
2757 @cindex -Idir option
2758 @cindex options, -Idir
2759 @item -I@var{dir}
2760 @cindex directory search paths for inclusion
2761 @cindex inclusion, directory search paths for
2762 @cindex searching for included files
2763 These affect interpretation of the @code{INCLUDE} directive
2764 (as well as of the @code{#include} directive of the @code{cpp}
2765 preprocessor).
2766
2767 Note that @samp{-I@var{dir}} must be specified @emph{without} any
2768 spaces between @samp{-I} and the directory name---that is,
2769 @samp{-Ifoo/bar} is valid, but @samp{-I foo/bar}
2770 is rejected by the @code{g77} compiler (though the preprocessor supports
2771 the latter form).
2772 @c this is due to toplev.c's inflexible option processing
2773 Also note that the general behavior of @samp{-I} and
2774 @code{INCLUDE} is pretty much the same as of @samp{-I} with
2775 @code{#include} in the @code{cpp} preprocessor, with regard to
2776 looking for @file{header.gcc} files and other such things.
2777
2778 @xref{Directory Options,,Options for Directory Search,
2779 gcc,Using and Porting GNU CC}, for information on the @samp{-I} option.
2780 @end table
2781
2782 @node Code Gen Options
2783 @section Options for Code Generation Conventions
2784 @cindex code generation conventions
2785 @cindex options, code generation
2786 @cindex run-time options
2787
2788 These machine-independent options control the interface conventions
2789 used in code generation.
2790
2791 Most of them have both positive and negative forms; the negative form
2792 of @samp{-ffoo} would be @samp{-fno-foo}. In the table below, only
2793 one of the forms is listed---the one which is not the default. You
2794 can figure out the other form by either removing @samp{no-} or adding
2795 it.
2796
2797 @table @code
2798 @cindex -fno-automatic option
2799 @cindex options, -fno-automatic
2800 @item -fno-automatic
2801 @cindex SAVE statement
2802 @cindex statements, SAVE
2803 Treat each program unit as if the @code{SAVE} statement was specified
2804 for every local variable and array referenced in it.
2805 Does not affect common blocks.
2806 (Some Fortran compilers provide this option under
2807 the name @samp{-static}.)
2808
2809 @cindex -finit-local-zero option
2810 @cindex options, -finit-local-zero
2811 @item -finit-local-zero
2812 @cindex DATA statement
2813 @cindex statements, DATA
2814 @cindex initialization of local variables
2815 @cindex variables, initialization of
2816 @cindex uninitialized variables
2817 @cindex variables, uninitialized
2818 Specify that variables and arrays that are local to a program unit
2819 (not in a common block and not passed as an argument) are to be initialized
2820 to binary zeros.
2821
2822 Since there is a run-time penalty for initialization of variables
2823 that are not given the @code{SAVE} attribute, it might be a
2824 good idea to also use @samp{-fno-automatic} with @samp{-finit-local-zero}.
2825
2826 @cindex -fno-f2c option
2827 @cindex options, -fno-f2c
2828 @item -fno-f2c
2829 @cindex @code{f2c} compatibility
2830 @cindex compatibility, @code{f2c}
2831 Do not generate code designed to be compatible with code generated
2832 by @code{f2c}; use the GNU calling conventions instead.
2833
2834 The @code{f2c} calling conventions require functions that return
2835 type @code{REAL(KIND=1)} to actually return the C type @code{double},
2836 and functions that return type @code{COMPLEX} to return the
2837 values via an extra argument in the calling sequence that points
2838 to where to store the return value.
2839 Under the GNU calling conventions, such functions simply return
2840 their results as they would in GNU C---@code{REAL(KIND=1)} functions
2841 return the C type @code{float}, and @code{COMPLEX} functions
2842 return the GNU C type @code{complex} (or its @code{struct}
2843 equivalent).
2844
2845 This does not affect the generation of code that interfaces with the
2846 @code{libf2c} library.
2847
2848 However, because the @code{libf2c} library uses @code{f2c}
2849 calling conventions, @code{g77} rejects attempts to pass
2850 intrinsics implemented by routines in this library as actual
2851 arguments when @samp{-fno-f2c} is used, to avoid bugs when
2852 they are actually called by code expecting the GNU calling
2853 conventions to work.
2854
2855 For example, @samp{INTRINSIC ABS;CALL FOO(ABS)} is
2856 rejected when @samp{-fno-f2c} is in force.
2857 (Future versions of the @code{g77} run-time library might
2858 offer routines that provide GNU-callable versions of the
2859 routines that implement the @code{f2c}-callable intrinsics
2860 that may be passed as actual arguments, so that
2861 valid programs need not be rejected when @samp{-fno-f2c}
2862 is used.)
2863
2864 @strong{Caution:} If @samp{-fno-f2c} is used when compiling any
2865 source file used in a program, it must be used when compiling
2866 @emph{all} Fortran source files used in that program.
2867
2868 @c seems kinda dumb to tell people about an option they can't use -- jcb
2869 @c then again, we want users building future-compatible libraries with it.
2870 @cindex -ff2c-library option
2871 @cindex options, -ff2c-library
2872 @item -ff2c-library
2873 Specify that use of @code{libf2c} is required.
2874 This is the default for the current version of @code{g77}.
2875
2876 Currently it is not
2877 valid to specify @samp{-fno-f2c-library}.
2878 This option is provided so users can specify it in shell
2879 scripts that build programs and libraries that require the
2880 @code{libf2c} library, even when being compiled by future
2881 versions of @code{g77} that might otherwise default to
2882 generating code for an incompatible library.
2883
2884 @cindex -fno-underscoring option
2885 @cindex options, -fno-underscoring
2886 @item -fno-underscoring
2887 @cindex underscores
2888 @cindex symbol names, underscores
2889 @cindex transforming symbol names
2890 @cindex symbol names, transforming
2891 Do not transform names of entities specified in the Fortran
2892 source file by appending underscores to them.
2893
2894 With @samp{-funderscoring} in effect, @code{g77} appends two underscores
2895 to names with underscores and one underscore to external names with
2896 no underscores. (@code{g77} also appends two underscores to internal
2897 names with underscores to avoid naming collisions with external names.
2898 The @samp{-fno-second-underscore} option disables appending of the
2899 second underscore in all cases.)
2900
2901 This is done to ensure compatibility with code produced by many
2902 UNIX Fortran compilers, including @code{f2c}, which perform the
2903 same transformations.
2904
2905 Use of @samp{-fno-underscoring} is not recommended unless you are
2906 experimenting with issues such as integration of (GNU) Fortran into
2907 existing system environments (vis-a-vis existing libraries, tools, and
2908 so on).
2909
2910 For example, with @samp{-funderscoring}, and assuming other defaults like
2911 @samp{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
2912 external functions while @samp{my_var} and @samp{lvar} are local variables,
2913 a statement like
2914
2915 @smallexample
2916 I = J() + MAX_COUNT (MY_VAR, LVAR)
2917 @end smallexample
2918
2919 @noindent
2920 is implemented as something akin to:
2921
2922 @smallexample
2923 i = j_() + max_count__(&my_var__, &lvar);
2924 @end smallexample
2925
2926 With @samp{-fno-underscoring}, the same statement is implemented as:
2927
2928 @smallexample
2929 i = j() + max_count(&my_var, &lvar);
2930 @end smallexample
2931
2932 Use of @samp{-fno-underscoring} allows direct specification of
2933 user-defined names while debugging and when interfacing @code{g77}-compiled
2934 code with other languages.
2935
2936 Note that just because the names match does @emph{not} mean that the
2937 interface implemented by @code{g77} for an external name matches the
2938 interface implemented by some other language for that same name.
2939 That is, getting code produced by @code{g77} to link to code produced
2940 by some other compiler using this or any other method can be only a
2941 small part of the overall solution---getting the code generated by
2942 both compilers to agree on issues other than naming can require
2943 significant effort, and, unlike naming disagreements, linkers normally
2944 cannot detect disagreements in these other areas.
2945
2946 Also, note that with @samp{-fno-underscoring}, the lack of appended
2947 underscores introduces the very real possibility that a user-defined
2948 external name will conflict with a name in a system library, which
2949 could make finding unresolved-reference bugs quite difficult in some
2950 cases---they might occur at program run time, and show up only as
2951 buggy behavior at run time.
2952
2953 In future versions of @code{g77}, we hope to improve naming and linking
2954 issues so that debugging always involves using the names as they appear
2955 in the source, even if the names as seen by the linker are mangled to
2956 prevent accidental linking between procedures with incompatible
2957 interfaces.
2958
2959 @cindex -fno-second-underscore option
2960 @cindex options, -fno-second-underscore
2961 @item -fno-second-underscore
2962 @cindex underscores
2963 @cindex symbol names, underscores
2964 @cindex transforming symbol names
2965 @cindex symbol names, transforming
2966 Do not append a second underscore to names of entities specified
2967 in the Fortran source file.
2968
2969 This option has no effect if @samp{-fno-underscoring} is
2970 in effect.
2971
2972 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
2973 is implemented as a reference to the link-time external symbol
2974 @samp{max_count_}, instead of @samp{max_count__}.
2975
2976 @cindex -fno-ident option
2977 @cindex options, -fno-ident
2978 @item -fno-ident
2979 Ignore the @samp{#ident} directive.
2980
2981 @cindex -fzeros option
2982 @cindex options, -fzeros
2983 @item -fzeros
2984 Treat initial values of zero as if they were any other value.
2985
2986 As of version 0.5.18, @code{g77} normally treats @code{DATA} and
2987 other statements that are used to specify initial values of zero
2988 for variables and arrays as if no values were actually specified,
2989 in the sense that no diagnostics regarding multiple initializations
2990 are produced.
2991
2992 This is done to speed up compiling of programs that initialize
2993 large arrays to zeros.
2994
2995 Use @samp{-fzeros} to revert to the simpler, slower behavior
2996 that can catch multiple initializations by keeping track of
2997 all initializations, zero or otherwise.
2998
2999 @emph{Caution:} Future versions of @code{g77} might disregard this option
3000 (and its negative form, the default) or interpret it somewhat
3001 differently.
3002 The interpretation changes will affect only non-standard
3003 programs; standard-conforming programs should not be affected.
3004
3005 @cindex -fdebug-kludge option
3006 @cindex options, -fdebug-kludge
3007 @item -fdebug-kludge
3008 Emit information on @code{COMMON} and @code{EQUIVALENCE} members
3009 that might help users of debuggers work around lack of proper debugging
3010 information on such members.
3011
3012 As of version 0.5.19, @code{g77} offers this option to emit
3013 information on members of aggregate areas to help users while debugging.
3014 This information consists of establishing the type and contents of each
3015 such member so that, when a debugger is asked to print the contents,
3016 the printed information provides rudimentary debugging information.
3017 This information identifies the name of the aggregate area (either the
3018 @code{COMMON} block name, or the @code{g77}-assigned name for the
3019 @code{EQUIVALENCE} name) and the offset, in bytes, of the member from
3020 the beginning of the area.
3021
3022 Using @code{gdb}, this information is not coherently displayed in the Fortran
3023 language mode, so temporarily switching to the C language mode to display the
3024 information is suggested.
3025 Use @samp{set language c} and @samp{set language fortran} to accomplish this.
3026
3027 For example:
3028
3029 @smallexample
3030 COMMON /X/A,B
3031 EQUIVALENCE (C,D)
3032 CHARACTER XX*50
3033 EQUIVALENCE (I,XX(20:20))
3034 END
3035
3036 GDB is free software and you are welcome to distribute copies of it
3037 under certain conditions; type "show copying" to see the conditions.
3038 There is absolutely no warranty for GDB; type "show warranty" for details.
3039 GDB 4.16 (lm-gnits-dwim), Copyright 1996 Free Software Foundation, Inc...
3040 (gdb) b MAIN__
3041 Breakpoint 1 at 0t1200000201120112: file cd.f, line 5.
3042 (gdb) r
3043 Starting program: /home/user/a.out
3044
3045 Breakpoint 1, MAIN__ () at cd.f:5
3046 Current language: auto; currently fortran
3047 (gdb) set language c
3048 Warning: the current language does not match this frame.
3049 (gdb) p a
3050 $2 = "At (COMMON) `x_' plus 0 bytes"
3051 (gdb) p b
3052 $3 = "At (COMMON) `x_' plus 4 bytes"
3053 (gdb) p c
3054 $4 = "At (EQUIVALENCE) `__g77_equiv_c' plus 0 bytes"
3055 (gdb) p d
3056 $5 = "At (EQUIVALENCE) `__g77_equiv_c' plus 0 bytes"
3057 (gdb) p i
3058 $6 = "At (EQUIVALENCE) `__g77_equiv_xx' plus 20 bytes"
3059 (gdb) p xx
3060 $7 = "At (EQUIVALENCE) `__g77_equiv_xx' plus 1 bytes"
3061 (gdb) set language fortran
3062 (gdb)
3063 @end smallexample
3064
3065 @noindent
3066 Use @samp{-fdebug-kludge} to generate this information,
3067 which might make some programs noticeably larger.
3068
3069 @emph{Caution:} Future versions of @code{g77} might disregard this option
3070 (and its negative form).
3071 Current plans call for this to happen when published versions of @code{g77}
3072 and @code{gdb} exist that provide proper access to debugging information on
3073 @code{COMMON} and @code{EQUIVALENCE} members.
3074
3075 @cindex -fno-emulate-complex option
3076 @cindex options, -fno-emulate-complex
3077 @item -fno-emulate-complex
3078 Implement @code{COMPLEX} arithmetic using the facilities in
3079 the @code{gcc} back end that provide direct support of
3080 @code{complex} arithmetic, instead of emulating the arithmetic.
3081
3082 @code{gcc} has some known problems in its back-end support
3083 for @code{complex} arithmetic, due primarily to the support not being
3084 completed as of version 2.7.2.2.
3085 Other front ends for the @code{gcc} back end avoid this problem
3086 by emulating @code{complex} arithmetic at a higher level, so the
3087 back end sees arithmetic on the real and imaginary components.
3088 To make @code{g77} more portable to systems where @code{complex}
3089 support in the @code{gcc} back end is particularly troublesome,
3090 @code{g77} now defaults to performing the same kinds of emulations
3091 done by these other front ends.
3092
3093 Use @samp{-fno-emulate-complex} to try the @code{complex} support
3094 in the @code{gcc} back end, in case it works and produces faster
3095 programs.
3096 So far, all the known bugs seem to involve compile-time crashes,
3097 rather than the generation of incorrect code.
3098
3099 Use of this option should not affect how Fortran code compiled
3100 by @code{g77} works in terms of its interfaces to other code,
3101 e.g. that compiled by @code{f2c}.
3102
3103 @emph{Caution:} Future versions of @code{g77} are likely to change
3104 the default for this option to
3105 @samp{-fno-emulate-complex}, and perhaps someday ignore both forms
3106 of this option.
3107
3108 Also, it is possible that use of the @samp{-fno-emulate-complex} option
3109 could result in incorrect code being silently produced by @code{g77}.
3110 But, this is generally true of compilers anyway, so, as usual, test
3111 the programs you compile before assuming they are working.
3112
3113 @cindex -falias-check option
3114 @cindex options, -falias-check
3115 @cindex -fargument-alias option
3116 @cindex options, -fargument-alias
3117 @cindex -fargument-noalias option
3118 @cindex options, -fargument-noalias
3119 @cindex -fno-argument-noalias-global option
3120 @cindex options, -fno-argument-noalias-global
3121 @item -falias-check
3122 @item -fargument-alias
3123 @item -fargument-noalias
3124 @item -fno-argument-noalias-global
3125 These options specify to what degree aliasing
3126 (overlap)
3127 is permitted between
3128 arguments (passed as pointers) and @code{COMMON} (external, or
3129 public) storage.
3130
3131 The default for Fortran code, as mandated by the FORTRAN 77 and
3132 Fortran 90 standards, is @samp{-fargument-noalias-global}.
3133 The default for code written in the C language family is
3134 @samp{-fargument-alias}.
3135
3136 Note that, on some systems, compiling with @samp{-fforce-addr} in
3137 effect can produce more optimal code when the default aliasing
3138 options are in effect (and when optimization is enabled).
3139
3140 @xref{Aliasing Assumed To Work}, for detailed information on the implications
3141 of compiling Fortran code that depends on the ability to alias dummy
3142 arguments.
3143
3144 @cindex -fno-globals option
3145 @cindex options, -fno-globals
3146 @item -fno-globals
3147 @cindex global names, warning
3148 @cindex warnings, global names
3149 Disable diagnostics about inter-procedural
3150 analysis problems, such as disagreements about the
3151 type of a function or a procedure's argument,
3152 that might cause a compiler crash when attempting
3153 to inline a reference to a procedure within a
3154 program unit.
3155 (The diagnostics themselves are still produced, but
3156 as warnings, unless @samp{-Wno-globals} is specified,
3157 in which case no relevant diagnostics are produced.)
3158
3159 Further, this option disables such inlining, to
3160 avoid compiler crashes resulting from incorrect
3161 code that would otherwise be diagnosed.
3162
3163 As such, this option might be quite useful when
3164 compiling existing, ``working'' code that happens
3165 to have a few bugs that do not generally show
3166 themselves, but @code{g77} exposes via a
3167 diagnostic.
3168
3169 Use of this option therefore has the effect of
3170 instructing @code{g77} to behave more like it did
3171 up through version 0.5.19.1, when it paid little or
3172 no attention to disagreements between program units
3173 about a procedure's type and argument information,
3174 and when it performed no inlining of procedures
3175 (except statement functions).
3176
3177 Without this option, @code{g77} defaults to performing
3178 the potentially inlining procedures as it started doing
3179 in version 0.5.20, but as of version 0.5.21, it also
3180 diagnoses disagreements that might cause such inlining
3181 to crash the compiler.
3182 @end table
3183
3184 @xref{Code Gen Options,,Options for Code Generation Conventions,
3185 gcc,Using and Porting GNU CC}, for information on more options
3186 offered by the GBE
3187 shared by @code{g77}, @code{gcc}, and other GNU compilers.
3188
3189 Some of these do @emph{not} work when compiling programs written in Fortran:
3190
3191 @table @code
3192 @cindex -fpcc-struct-return option
3193 @cindex options, -fpcc-struct-return
3194 @item -fpcc-struct-return
3195 @cindex -freg-struct-return option
3196 @cindex options, -freg-struct-return
3197 @item -freg-struct-return
3198 You should not use these except strictly the same way as you
3199 used them to build the version of @code{libf2c} with which
3200 you will be linking all code compiled by @code{g77} with the
3201 same option.
3202
3203 @cindex -fshort-double option
3204 @cindex options, -fshort-double
3205 @item -fshort-double
3206 This probably either has no effect on Fortran programs, or
3207 makes them act loopy.
3208
3209 @cindex -fno-common option
3210 @cindex options, -fno-common
3211 @item -fno-common
3212 Do not use this when compiling Fortran programs,
3213 or there will be Trouble.
3214
3215 @cindex -fpack-struct option
3216 @cindex options, -fpack-struct
3217 @item -fpack-struct
3218 This probably will break any calls to the @code{libf2c} library,
3219 at the very least, even if it is built with the same option.
3220 @end table
3221
3222 @node Environment Variables
3223 @section Environment Variables Affecting GNU Fortran
3224 @cindex environment variables
3225
3226 GNU Fortran currently does not make use of any environment
3227 variables to control its operation above and beyond those
3228 that affect the operation of @code{gcc}.
3229
3230 @xref{Environment Variables,,Environment Variables Affecting GNU CC,
3231 gcc,Using and Porting GNU CC}, for information on environment
3232 variables.
3233
3234 @include news.texi
3235
3236 @node Changes
3237 @chapter User-visible Changes
3238 @cindex versions, recent
3239 @cindex recent versions
3240 @cindex changes, user-visible
3241 @cindex user-visible changes
3242
3243 This section describes changes to @code{g77} that are visible
3244 to the programmers who actually write and maintain Fortran
3245 code they compile with @code{g77}.
3246 Information on changes to installation procedures,
3247 changes to the documentation, and bug fixes is
3248 not provided here, unless it is likely to affect how
3249 users use @code{g77}.
3250 @xref{News,,News About GNU Fortran}, for information on
3251 such changes to @code{g77}.
3252
3253 To find out about existing bugs and ongoing plans for GNU
3254 Fortran, retrieve @code{ftp://alpha.gnu.org/g77.plan}
3255 or, if you cannot do that, email
3256 @email{fortran@@gnu.org} asking for a recent copy of the
3257 GNU Fortran @file{.plan} file.
3258
3259 @heading In 0.5.21:
3260 @itemize @bullet
3261 @item
3262 When the @samp{-W} option is specified, @code{gcc}, @code{g77},
3263 and other GNU compilers that incorporate the @code{gcc}
3264 back end as modified by @code{g77}, issue
3265 a warning about integer division by constant zero.
3266
3267 @item
3268 New option @samp{-Wno-globals} disables warnings
3269 about ``suspicious'' use of a name both as a global
3270 name and as the implicit name of an intrinsic, and
3271 warnings about disagreements over the number or natures of
3272 arguments passed to global procedures, or the
3273 natures of the procedures themselves.
3274
3275 The default is to issue such warnings, which are
3276 new as of this version of @code{g77}.
3277
3278 @item
3279 New option @samp{-fno-globals} disables diagnostics
3280 about potentially fatal disagreements
3281 analysis problems, such as disagreements over the
3282 number or natures of arguments passed to global
3283 procedures, or the natures of those procedures themselves.
3284
3285 The default is to issue such diagnostics and flag
3286 the compilation as unsuccessful.
3287 With this option, the diagnostics are issued as
3288 warnings, or, if @samp{-Wno-globals} is specified,
3289 are not issued at all.
3290
3291 This option also disables inlining of global procedures,
3292 to avoid compiler crashes resulting from coding errors
3293 that these diagnostics normally would identify.
3294
3295 @item
3296 Fix @code{libU77} routines that accept file names
3297 to strip trailing spaces from them, for consistency
3298 with other implementations.
3299
3300 @item
3301 Fix @code{SIGNAL} intrinsic so it accepts an
3302 optional third @samp{Status} argument.
3303
3304 @item
3305 Make many changes to @code{libU77} intrinsics to
3306 support existing code more directly.
3307
3308 Such changes include allowing both subroutine and
3309 function forms of many routines, changing @code{MCLOCK()}
3310 and @code{TIME()} to return @code{INTEGER(KIND=1)} values,
3311 introducing @code{MCLOCK8()} and @code{TIME8()} to
3312 return @code{INTEGER(KIND=2)} values,
3313 and placing functions that are intended to perform
3314 side effects in a new intrinsic group, @code{badu77}.
3315
3316 @item
3317 Add options @samp{-fbadu77-intrinsics-delete},
3318 @samp{-fbadu77-intrinsics-hide}, and so on.
3319
3320 @item
3321 Add @code{INT2} and @code{INT8} intrinsics.
3322
3323 @item
3324 Add @code{CPU_TIME} intrinsic.
3325
3326 @item
3327 @code{CTIME} intrinsic now accepts any @code{INTEGER}
3328 argument, not just @code{INTEGER(KIND=2)}.
3329 @end itemize
3330
3331 @heading In 0.5.20:
3332 @itemize @bullet
3333 @item
3334 The @samp{-fno-typeless-boz} option is now the default.
3335
3336 This option specifies that non-decimal-radix
3337 constants using the prefixed-radix form (such as @samp{Z'1234'})
3338 are to be interpreted as @code{INTEGER(KIND=1)} constants.
3339 Specify @samp{-ftypeless-boz} to cause such
3340 constants to be interpreted as typeless.
3341
3342 (Version 0.5.19 introduced @samp{-fno-typeless-boz} and
3343 its inverse.)
3344
3345 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
3346 for information on the @samp{-ftypeless-boz} option.
3347
3348 @item
3349 Options @samp{-ff90-intrinsics-enable} and
3350 @samp{-fvxt-intrinsics-enable} now are the
3351 defaults.
3352
3353 Some programs might use names that clash with
3354 intrinsic names defined (and now enabled) by these
3355 options or by the new @code{libU77} intrinsics.
3356 Users of such programs might need to compile them
3357 differently (using, for example, @samp{-ff90-intrinsics-disable})
3358 or, better yet, insert appropriate @code{EXTERNAL}
3359 statements specifying that these names are not intended
3360 to be names of intrinsics.
3361
3362 @item
3363 The @samp{ALWAYS_FLUSH} macro is no longer defined when
3364 building @code{libf2c}, which should result in improved
3365 I/O performance, especially over NFS.
3366
3367 @emph{Note:} If you have code that depends on the behavior
3368 of @code{libf2c} when built with @samp{ALWAYS_FLUSH} defined,
3369 you will have to modify @code{libf2c} accordingly before
3370 building it from this and future versions of @code{g77}.
3371
3372 @xref{Output Assumed To Flush}, for more information.
3373
3374 @item
3375 Dave Love's implementation of @code{libU77} has been
3376 added to the version of @code{libf2c} distributed with
3377 and built by @code{g77}.
3378 @code{g77} now knows about the routines in this library
3379 as intrinsics.
3380
3381 @item
3382 New option @samp{-fvxt} specifies that the
3383 source file is written in VXT Fortran, instead of GNU Fortran.
3384
3385 @xref{VXT Fortran}, for more information on the constructs
3386 recognized when the @samp{-fvxt} option is specified.
3387
3388 @item
3389 The @samp{-fvxt-not-f90} option has been deleted,
3390 along with its inverse, @samp{-ff90-not-vxt}.
3391
3392 If you used one of these deleted options, you should
3393 re-read the pertinent documentation to determine which
3394 options, if any, are appropriate for compiling your
3395 code with this version of @code{g77}.
3396
3397 @xref{Other Dialects}, for more information.
3398
3399 @item
3400 The @samp{-fugly} option now issues a warning, as it
3401 likely will be removed in a future version.
3402
3403 (Enabling all the @samp{-fugly-*} options is unlikely
3404 to be feasible, or sensible, in the future,
3405 so users should learn to specify only those
3406 @samp{-fugly-*} options they really need for a
3407 particular source file.)
3408
3409 @item
3410 The @samp{-fugly-assumed} option, introduced in
3411 version 0.5.19, has been changed to
3412 better accommodate old and new code.
3413 @xref{Ugly Assumed-Size Arrays}, for more information.
3414
3415 @item
3416 Related to supporting Alpha (AXP) machines, the @code{LOC()}
3417 intrinsic and @code{%LOC()} construct now return
3418 values of @code{INTEGER(KIND=0)} type,
3419 as defined by the GNU Fortran language.
3420
3421 This type is wide enough
3422 (holds the same number of bits)
3423 as the character-pointer type on the machine.
3424
3425 On most systems, this won't make a noticable difference,
3426 whereas on Alphas and other systems with 64-bit pointers,
3427 the @code{INTEGER(KIND=0)} type is equivalent to @code{INTEGER(KIND=2)}
3428 (often referred to as @code{INTEGER*8})
3429 instead of the more common @code{INTEGER(KIND=1)}
3430 (often referred to as @code{INTEGER*4}).
3431
3432 @item
3433 Emulate @code{COMPLEX} arithmetic in the @code{g77} front
3434 end, to avoid bugs in @code{complex} support in the
3435 @code{gcc} back end.
3436 New option @samp{-fno-emulate-complex}
3437 causes @code{g77} to revert the 0.5.19 behavior.
3438
3439 @item
3440 Dummy arguments are no longer assumed to potentially alias
3441 (overlap)
3442 other dummy arguments or @code{COMMON} areas when any of
3443 these are defined (assigned to) by Fortran code.
3444
3445 This can result in faster and/or smaller programs when
3446 compiling with optimization enabled, though on some
3447 systems this effect is observed only when @samp{-fforce-addr}
3448 also is specified.
3449
3450 New options @samp{-falias-check}, @samp{-fargument-alias},
3451 @samp{-fargument-noalias},
3452 and @samp{-fno-argument-noalias-global} control the
3453 way @code{g77} handles potential aliasing.
3454
3455 @xref{Aliasing Assumed To Work}, for detailed information on why the
3456 new defaults might result in some programs no longer working the way they
3457 did when compiled by previous versions of @code{g77}.
3458
3459 @item
3460 New option @samp{-fugly-assign} specifies that the
3461 same memory locations are to be used to hold the
3462 values assigned by both statements @samp{I = 3} and
3463 @samp{ASSIGN 10 TO I}, for example.
3464 (Normally, @code{g77} uses a separate memory location
3465 to hold assigned statement labels.)
3466
3467 @xref{Ugly Assigned Labels}, for more information.
3468
3469 @item
3470 @code{FORMAT} and @code{ENTRY} statements now are allowed to
3471 precede @code{IMPLICIT NONE} statements.
3472
3473 @item
3474 Enable full support of @code{INTEGER(KIND=2)}
3475 (often referred to as @code{INTEGER*8})
3476 available in
3477 @code{libf2c} and @file{f2c.h} so that @code{f2c} users
3478 may make full use of its features via the @code{g77}
3479 version of @file{f2c.h} and the @code{INTEGER(KIND=2)}
3480 support routines in the @code{g77} version of @code{libf2c}.
3481
3482 @item
3483 Improve @code{g77} driver and @code{libf2c} so that @samp{g77 -v}
3484 yields version information on the library.
3485
3486 @item
3487 The @code{SNGL} and @code{FLOAT} intrinsics now are
3488 specific intrinsics, instead of synonyms for the
3489 generic intrinsic @code{REAL}.
3490
3491 @item
3492 New intrinsics have been added.
3493 These are @code{REALPART}, @code{IMAGPART},
3494 @code{COMPLEX},
3495 @code{LONG}, and @code{SHORT}.
3496
3497 @item
3498 A new group of intrinsics, @samp{gnu}, has been added
3499 to contain the new @code{REALPART}, @code{IMAGPART},
3500 and @code{COMPLEX} intrinsics.
3501 An old group, @samp{dcp}, has been removed.
3502 @end itemize
3503
3504 @heading In 0.5.19:
3505
3506 @itemize @bullet
3507 @item
3508 A temporary kludge option provides bare-bones information on
3509 @code{COMMON} and @code{EQUIVALENCE} members at debug time.
3510 @xref{Code Gen Options,,Options for Code Generation Conventions},
3511 for information on the @samp{-fdebug-kludge} option.
3512
3513 @item
3514 New @samp{-fonetrip} option specifies FORTRAN-66-style
3515 one-trip @code{DO} loops.
3516
3517 @item
3518 New @samp{-fno-silent} option causes names of program units
3519 to be printed as they are compiled, in a fashion similar to
3520 UNIX @code{f77} and @code{f2c}.
3521
3522 @item
3523 New @samp{-fugly-assumed} option specifies that arrays
3524 dimensioned via @samp{DIMENSION X(1)}, for example, are to be
3525 treated as assumed-size.
3526
3527 @item
3528 New @samp{-fno-typeless-boz} option specifies that non-decimal-radix
3529 constants using the prefixed-radix form (such as @samp{Z'1234'})
3530 are to be interpreted as @code{INTEGER(KIND=1)} constants.
3531
3532 @item
3533 New @samp{-ff66} option is a ``shorthand'' option that specifies
3534 behaviors considered appropriate for FORTRAN 66 programs.
3535
3536 @item
3537 New @samp{-ff77} option is a ``shorthand'' option that specifies
3538 behaviors considered appropriate for UNIX @code{f77} programs.
3539
3540 @item
3541 New @samp{-fugly-comma} and @samp{-fugly-logint} options provided
3542 to perform some of what @samp{-fugly} used to do.
3543 @samp{-fugly} and @samp{-fno-ugly} are now ``shorthand'' options,
3544 in that they do nothing more than enable (or disable) other
3545 @samp{-fugly-*} options.
3546
3547 @item
3548 Change code generation for list-directed I/O so it allows
3549 for new versions of @code{libf2c} that might return non-zero
3550 status codes for some operations previously assumed to always
3551 return zero.
3552
3553 This change not only affects how @code{IOSTAT=} variables
3554 are set by list-directed I/O, it also affects whether
3555 @code{END=} and @code{ERR=} labels are reached by these
3556 operations.
3557
3558 @item
3559 Add intrinsic support for new @code{FTELL} and @code{FSEEK}
3560 procedures in @code{libf2c}.
3561
3562 @item
3563 Add options @samp{--help} and @samp{--version} to the
3564 @code{g77} command, to conform to GNU coding guidelines.
3565 Also add printing of @code{g77} version number when
3566 the @samp{--verbose} (@samp{-v}) option is used.
3567 @end itemize
3568
3569 @heading In 0.5.18:
3570
3571 @itemize @bullet
3572 @item
3573 The @code{BYTE} and @code{WORD} statements now are supported,
3574 to a limited extent.
3575
3576 @item
3577 @code{INTEGER*1}, @code{INTEGER*2}, @code{INTEGER*8},
3578 and their @code{LOGICAL}
3579 equivalents, now are supported to a limited extent.
3580 Among the missing elements are complete intrinsic and constant
3581 support.
3582
3583 @item
3584 Support automatic arrays in procedures.
3585 For example, @samp{REAL A(N)}, where @samp{A} is
3586 not a dummy argument, specifies that @samp{A} is
3587 an automatic array.
3588 The size of @samp{A} is calculated from the value
3589 of @samp{N} each time the procedure is called,
3590 that amount of space is allocated, and that space
3591 is freed when the procedure returns to its caller.
3592
3593 @item
3594 Add @samp{-fno-zeros} option, enabled by default,
3595 to reduce compile-time CPU and memory usage for
3596 code that provides initial zero values for variables
3597 and arrays.
3598
3599 @item
3600 Introduce three new options that apply to all compilations
3601 by @code{g77}-aware GNU compilers---@samp{-fmove-all-movables},
3602 @samp{-freduce-all-givs}, and @samp{-frerun-loop-opt}---which
3603 can improve the run-time performance of some programs.
3604
3605 @item
3606 Replace much of the existing documentation with a single
3607 Info document.
3608
3609 @item
3610 New option @samp{-fno-second-underscore}.
3611 @end itemize
3612
3613 @heading In 0.5.17:
3614
3615 @itemize @bullet
3616 @item
3617 The @code{ERF()} and @code{ERFC()} intrinsics now are generic
3618 intrinsics, mapping to @code{ERF}/@code{DERF} and
3619 @code{ERFC}/@code{DERFC}, respectively.
3620 @emph{Note:} Use @samp{INTRINSIC ERF,ERFC} in any code that
3621 might reference these as generic intrinsics, to
3622 improve the likelihood of diagnostics (instead of subtle run-time
3623 bugs) when using compilers that don't support these as intrinsics.
3624
3625 @item
3626 New option @samp{-Wsurprising}.
3627
3628 @item
3629 DO loops with non-@code{INTEGER} variables now diagnosed only when
3630 @samp{-Wsurprising} specified.
3631 Previously, this was diagnosed @emph{unless} @samp{-fpedantic} or
3632 @samp{-fugly} was specified.
3633 @end itemize
3634
3635 @heading In 0.5.16:
3636
3637 @itemize @bullet
3638 @item
3639 @code{libf2c} changed to output a leading zero (0) digit for floating-point
3640 values output via list-directed and formatted output (to bring @code{g77}
3641 more into line with many existing Fortran implementations---the
3642 ANSI FORTRAN 77 standard leaves this choice to the implementation).
3643
3644 @item
3645 @code{libf2c} no longer built with debugging information
3646 intact, making it much smaller.
3647
3648 @item
3649 Automatic installation of the @code{g77} command now works.
3650
3651 @item
3652 Diagnostic messages now more informative, a la @code{gcc},
3653 including messages like @samp{In function `foo':} and @samp{In file
3654 included from...:}.
3655
3656 @item
3657 New group of intrinsics called @samp{unix}, including @code{ABORT},
3658 @code{DERF}, @code{DERFC}, @code{ERF}, @code{ERFC}, @code{EXIT},
3659 @code{FLUSH}, @code{GETARG}, @code{GETENV}, @code{SIGNAL}, and
3660 @code{SYSTEM}.
3661
3662 @item
3663 @samp{-funix-intrinsics-@{delete,hide,disable,enable@}}
3664 options added.
3665
3666 @item
3667 @samp{-fno-underscoring} option added.
3668
3669 @item
3670 @samp{--driver} option added to the @code{g77} command.
3671
3672 @item
3673 Support for the @code{gcc} options @samp{-fident} and @samp{-fno-ident}
3674 added.
3675
3676 @item
3677 @samp{g77 -v} returns much more version info, making the submission
3678 of better bug reports easily.
3679
3680 @item
3681 Many improvements to the @code{g77} command to better fulfill its role as
3682 a front-end to the @code{gcc} driver.
3683 For example, @code{g77} now
3684 recognizes @samp{--verbose} as a verbose way of specifying @samp{-v}.
3685
3686 @item
3687 Compiling preprocessed (@file{*.F} and @file{*.fpp}) files now
3688 results in better diagnostics and debugging information, as the
3689 source-location info now is passed all the
3690 way through the compilation process instead of being lost.
3691 @end itemize
3692
3693 @node Language
3694 @chapter The GNU Fortran Language
3695
3696 @cindex standard, ANSI FORTRAN 77
3697 @cindex ANSI FORTRAN 77 standard
3698 @cindex reference works
3699 GNU Fortran supports a variety of extensions to, and dialects
3700 of, the Fortran language.
3701 Its primary base is the ANSI FORTRAN 77 standard, currently available on
3702 the network at @code{http://kumo.swcp.com/fortran/F77_std/f77_std.html}
3703 or in @code{ftp://ftp.ast.cam.ac.uk/pub/michael/}.
3704 It offers some extensions that are popular among users
3705 of UNIX @code{f77} and @code{f2c} compilers, some that
3706 are popular among users of other compilers (such as Digital
3707 products), some that are popular among users of the
3708 newer Fortran 90 standard, and some that are introduced
3709 by GNU Fortran.
3710
3711 @cindex textbooks
3712 (If you need a text on Fortran,
3713 a few freely available electronic references have pointers from
3714 @code{http://www.fortran.com/fortran/Books/}.)
3715
3716 Part of what defines a particular implementation of a Fortran
3717 system, such as @code{g77}, is the particular characteristics
3718 of how it supports types, constants, and so on.
3719 Much of this is left up to the implementation by the various
3720 Fortran standards and accepted practice in the industry.
3721
3722 The GNU Fortran @emph{language} is described below.
3723 Much of the material is organized along the same lines
3724 as the ANSI FORTRAN 77 standard itself.
3725
3726 @xref{Other Dialects}, for information on features @code{g77} supports
3727 that are not part of the GNU Fortran language.
3728
3729 @emph{Note}: This portion of the documentation definitely needs a lot
3730 of work!
3731
3732 @menu
3733 Relationship to the ANSI FORTRAN 77 standard:
3734 * Direction of Language Development:: Where GNU Fortran is headed.
3735 * Standard Support:: Degree of support for the standard.
3736
3737 Extensions to the ANSI FORTRAN 77 standard:
3738 * Conformance::
3739 * Notation Used::
3740 * Terms and Concepts::
3741 * Characters Lines Sequence::
3742 * Data Types and Constants::
3743 * Expressions::
3744 * Specification Statements::
3745 * Control Statements::
3746 * Functions and Subroutines::
3747 * Scope and Classes of Names::
3748 @end menu
3749
3750 @node Direction of Language Development
3751 @section Direction of Language Development
3752 @cindex direction of language development
3753 @cindex features, language
3754 @cindex language features
3755
3756 The purpose of the following description of the GNU Fortran
3757 language is to promote wide portability of GNU Fortran programs.
3758
3759 GNU Fortran is an evolving language, due to the
3760 fact that @code{g77} itself is in beta test.
3761 Some current features of the language might later
3762 be redefined as dialects of Fortran supported by @code{g77}
3763 when better ways to express these features are added to @code{g77},
3764 for example.
3765 Such features would still be supported by
3766 @code{g77}, but would be available only when
3767 one or more command-line options were used.
3768
3769 The GNU Fortran @emph{language} is distinct from the
3770 GNU Fortran @emph{compilation system} (@code{g77}).
3771
3772 For example, @code{g77} supports various dialects of
3773 Fortran---in a sense, these are languages other than
3774 GNU Fortran---though its primary
3775 purpose is to support the GNU Fortran language, which also is
3776 described in its documentation and by its implementation.
3777
3778 On the other hand, non-GNU compilers might offer
3779 support for the GNU Fortran language, and are encouraged
3780 to do so.
3781
3782 Currently, the GNU Fortran language is a fairly fuzzy object.
3783 It represents something of a cross between what @code{g77} accepts
3784 when compiling using the prevailing defaults and what this
3785 document describes as being part of the language.
3786
3787 Future versions of @code{g77} are expected to clarify the
3788 definition of the language in the documentation.
3789 Often, this will mean adding new features to the language, in the form
3790 of both new documentation and new support in @code{g77}.
3791 However, it might occasionally mean removing a feature
3792 from the language itself to ``dialect'' status.
3793 In such a case, the documentation would be adjusted
3794 to reflect the change, and @code{g77} itself would likely be changed
3795 to require one or more command-line options to continue supporting
3796 the feature.
3797
3798 The development of the GNU Fortran language is intended to strike
3799 a balance between:
3800
3801 @itemize @bullet
3802 @item
3803 Serving as a mostly-upwards-compatible language from the
3804 de facto UNIX Fortran dialect as supported by @code{f77}.
3805
3806 @item
3807 Offering new, well-designed language features.
3808 Attributes of such features include
3809 not making existing code any harder to read
3810 (for those who might be unaware that the new
3811 features are not in use) and
3812 not making state-of-the-art
3813 compilers take longer to issue diagnostics,
3814 among others.
3815
3816 @item
3817 Supporting existing, well-written code without gratuitously
3818 rejecting non-standard constructs, regardless of the origin
3819 of the code (its dialect).
3820
3821 @item
3822 Offering default behavior and command-line options to reduce
3823 and, where reasonable, eliminate the need for programmers to make
3824 any modifications to code that already works in existing
3825 production environments.
3826
3827 @item
3828 Diagnosing constructs that have different meanings in different
3829 systems, languages, and dialects, while offering clear,
3830 less ambiguous ways to express each of the different meanings
3831 so programmers can change their code appropriately.
3832 @end itemize
3833
3834 One of the biggest practical challenges for the developers of the
3835 GNU Fortran language is meeting the sometimes contradictory demands
3836 of the above items.
3837
3838 For example, a feature might be widely used in one popular environment,
3839 but the exact same code that utilizes that feature might not work
3840 as expected---perhaps it might mean something entirely different---in
3841 another popular environment.
3842
3843 Traditionally, Fortran compilers---even portable ones---have solved this
3844 problem by simply offering the appropriate feature to users of
3845 the respective systems.
3846 This approach treats users of various Fortran systems and dialects
3847 as remote ``islands'', or camps, of programmers, and assume that these
3848 camps rarely come into contact with each other (or,
3849 especially, with each other's code).
3850
3851 Project GNU takes a radically different approach to software and language
3852 design, in that it assumes that users of GNU software do not necessarily
3853 care what kind of underlying system they are using, regardless
3854 of whether they are using software (at the user-interface
3855 level) or writing it (for example, writing Fortran or C code).
3856
3857 As such, GNU users rarely need consider just what kind of underlying
3858 hardware (or, in many cases, operating system) they are using at any
3859 particular time.
3860 They can use and write software designed for a general-purpose,
3861 widely portable, heteregenous environment---the GNU environment.
3862
3863 In line with this philosophy, GNU Fortran must evolve into a product
3864 that is widely ported and portable not only in the sense that it can
3865 be successfully built, installed, and run by users, but in the larger
3866 sense that its users can use it in the same way, and expect largely the
3867 same behaviors from it, regardless of the kind of system they are using
3868 at any particular time.
3869
3870 This approach constrains the solutions @code{g77} can use to resolve
3871 conflicts between various camps of Fortran users.
3872 If these two camps disagree about what a particular construct should
3873 mean, @code{g77} cannot simply be changed to treat that particular construct as
3874 having one meaning without comment (such as a warning), lest the users
3875 expecting it to have the other meaning are unpleasantly surprised that
3876 their code misbehaves when executed.
3877
3878 The use of the ASCII backslash character in character constants is
3879 an excellent (and still somewhat unresolved) example of this kind of
3880 controversy.
3881 @xref{Backslash in Constants}.
3882 Other examples are likely to arise in the future, as @code{g77} developers
3883 strive to improve its ability to accept an ever-wider variety of existing
3884 Fortran code without requiring significant modifications to said code.
3885
3886 Development of GNU Fortran is further constrained by the desire
3887 to avoid requiring programmers to change their code.
3888 This is important because it allows programmers, administrators,
3889 and others to more faithfully evaluate and validate @code{g77}
3890 (as an overall product and as new versions are distributed)
3891 without having to support multiple versions of their programs
3892 so that they continue to work the same way on their existing
3893 systems (non-GNU perhaps, but possibly also earlier versions
3894 of @code{g77}).
3895
3896 @node Standard Support
3897 @section ANSI FORTRAN 77 Standard Support
3898 @cindex ANSI FORTRAN 77 support
3899 @cindex standard support
3900 @cindex support for ANSI FORTRAN 77
3901 @cindex compatibility, FORTRAN 77
3902 @cindex FORTRAN 77 compatibility
3903
3904 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
3905 In summary, the only ANSI FORTRAN 77 features @code{g77} doesn't
3906 support are those that are probably rarely used in actual code,
3907 some of which are explicitly disallowed by the Fortran 90 standard.
3908
3909 @menu
3910 * No Passing External Assumed-length:: CHAR*(*) CFUNC restriction.
3911 * No Passing Dummy Assumed-length:: CHAR*(*) CFUNC restriction.
3912 * No Pathological Implied-DO:: No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
3913 * No Useless Implied-DO:: No @samp{(A, I=1, 1)}.
3914 @end menu
3915
3916 @node No Passing External Assumed-length
3917 @subsection No Passing External Assumed-length
3918
3919 @code{g77} disallows passing of an external procedure
3920 as an actual argument if the procedure's
3921 type is declared @code{CHARACTER*(*)}. For example:
3922
3923 @example
3924 CHARACTER*(*) CFUNC
3925 EXTERNAL CFUNC
3926 CALL FOO(CFUNC)
3927 END
3928 @end example
3929
3930 @noindent
3931 It isn't clear whether the standard considers this conforming.
3932
3933 @node No Passing Dummy Assumed-length
3934 @subsection No Passing Dummy Assumed-length
3935
3936 @code{g77} disallows passing of a dummy procedure
3937 as an actual argument if the procedure's
3938 type is declared @code{CHARACTER*(*)}.
3939
3940 @example
3941 SUBROUTINE BAR(CFUNC)
3942 CHARACTER*(*) CFUNC
3943 EXTERNAL CFUNC
3944 CALL FOO(CFUNC)
3945 END
3946 @end example
3947
3948 @noindent
3949 It isn't clear whether the standard considers this conforming.
3950
3951 @node No Pathological Implied-DO
3952 @subsection No Pathological Implied-DO
3953
3954 The @code{DO} variable for an implied-@code{DO} construct in a
3955 @code{DATA} statement may not be used as the @code{DO} variable
3956 for an outer implied-@code{DO} construct. For example, this
3957 fragment is disallowed by @code{g77}:
3958
3959 @smallexample
3960 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
3961 @end smallexample
3962
3963 @noindent
3964 This also is disallowed by Fortran 90, as it offers no additional
3965 capabilities and would have a variety of possible meanings.
3966
3967 Note that it is @emph{very} unlikely that any production Fortran code
3968 tries to use this unsupported construct.
3969
3970 @node No Useless Implied-DO
3971 @subsection No Useless Implied-DO
3972
3973 An array element initializer in an implied-@code{DO} construct in a
3974 @code{DATA} statement must contain at least one reference to the @code{DO}
3975 variables of each outer implied-@code{DO} construct. For example,
3976 this fragment is disallowed by @code{g77}:
3977
3978 @smallexample
3979 DATA (A, I= 1, 1) /1./
3980 @end smallexample
3981
3982 @noindent
3983 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
3984 requirements offer no additional capabilities.
3985 However, @code{g77} doesn't necessarily diagnose all cases
3986 where this requirement is not met.
3987
3988 Note that it is @emph{very} unlikely that any production Fortran code
3989 tries to use this unsupported construct.
3990
3991 @node Conformance
3992 @section Conformance
3993
3994 (The following information augments or overrides the information in
3995 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3996 language.
3997 Chapter 1 of that document otherwise serves as the basis
3998 for the relevant aspects of GNU Fortran.)
3999
4000 The definition of the GNU Fortran language is akin to that of
4001 the ANSI FORTRAN 77 language in that it does not generally require
4002 conforming implementations to diagnose cases where programs do
4003 not conform to the language.
4004
4005 However, @code{g77} as a compiler is being developed in a way that
4006 is intended to enable it to diagnose such cases in an easy-to-understand
4007 manner.
4008
4009 A program that conforms to the GNU Fortran language should, when
4010 compiled, linked, and executed using a properly installed @code{g77}
4011 system, perform as described by the GNU Fortran language definition.
4012 Reasons for different behavior include, among others:
4013
4014 @itemize @bullet
4015 @item
4016 Use of resources (memory---heap, stack, and so on; disk space; CPU
4017 time; etc.) exceeds those of the system.
4018
4019 @item
4020 Range and/or precision of calculations required by the program
4021 exceeds that of the system.
4022
4023 @item
4024 Excessive reliance on behaviors that are system-dependent
4025 (non-portable Fortran code).
4026
4027 @item
4028 Bugs in the program.
4029
4030 @item
4031 Bug in @code{g77}.
4032
4033 @item
4034 Bugs in the system.
4035 @end itemize
4036
4037 Despite these ``loopholes'', the availability of a clear specification
4038 of the language of programs submitted to @code{g77}, as this document
4039 is intended to provide, is considered an important aspect of providing
4040 a robust, clean, predictable Fortran implementation.
4041
4042 The definition of the GNU Fortran language, while having no special
4043 legal status, can therefore be viewed as a sort of contract, or agreement.
4044 This agreement says, in essence, ``if you write a program in this language,
4045 and run it in an environment (such as a @code{g77} system) that supports
4046 this language, the program should behave in a largely predictable way''.
4047
4048 @node Notation Used
4049 @section Notation Used in This Chapter
4050
4051 (The following information augments or overrides the information in
4052 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4053 language.
4054 Chapter 1 of that document otherwise serves as the basis
4055 for the relevant aspects of GNU Fortran.)
4056
4057 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
4058 and ``must not'' and ``may not'' denote prohibition.
4059 Terms such as ``might'', ``should'', and ``can'' generally add little or
4060 nothing in the way of weight to the GNU Fortran language itself,
4061 but are used to explain or illustrate the language.
4062
4063 For example:
4064
4065 @display
4066 ``The @code{FROBNITZ} statement must precede all executable
4067 statements in a program unit, and may not specify any dummy
4068 arguments. It may specify local or common variables and arrays.
4069 Its use should be limited to portions of the program designed to
4070 be non-portable and system-specific, because it might cause the
4071 containing program unit to behave quite differently on different
4072 systems.''
4073 @end display
4074
4075 Insofar as the GNU Fortran language is specified,
4076 the requirements and permissions denoted by the above sample statement
4077 are limited to the placement of the statement and the kinds of
4078 things it may specify.
4079 The rest of the statement---the content regarding non-portable portions
4080 of the program and the differing behavior of program units containing
4081 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
4082 language itself.
4083 That content offers advice and warnings about the @code{FROBNITZ}
4084 statement.
4085
4086 @emph{Remember:} The GNU Fortran language definition specifies
4087 both what constitutes a valid GNU Fortran program and how,
4088 given such a program, a valid GNU Fortran implementation is
4089 to interpret that program.
4090
4091 It is @emph{not} incumbent upon a valid GNU Fortran implementation
4092 to behave in any particular way, any consistent way, or any
4093 predictable way when it is asked to interpret input that is
4094 @emph{not} a valid GNU Fortran program.
4095
4096 Such input is said to have @dfn{undefined} behavior when
4097 interpreted by a valid GNU Fortran implementation, though
4098 an implementation may choose to specify behaviors for some
4099 cases of inputs that are not valid GNU Fortran programs.
4100
4101 Other notation used herein is that of the GNU texinfo format,
4102 which is used to generate printed hardcopy, on-line hypertext
4103 (Info), and on-line HTML versions, all from a single source
4104 document.
4105 This notation is used as follows:
4106
4107 @itemize @bullet
4108 @item
4109 Keywords defined by the GNU Fortran language are shown
4110 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
4111 @code{BLOCK DATA}.
4112
4113 Note that, in practice, many Fortran programs are written
4114 in lowercase---uppercase is used in this manual as a
4115 means to readily distinguish keywords and sample Fortran-related
4116 text from the prose in this document.
4117
4118 @item
4119 Portions of actual sample program, input, or output text
4120 look like this: @samp{Actual program text}.
4121
4122 Generally, uppercase is used for all Fortran-specific and
4123 Fortran-related text, though this does not always include
4124 literal text within Fortran code.
4125
4126 For example: @samp{PRINT *, 'My name is Bob'}.
4127
4128 @item
4129 A metasyntactic variable---that is, a name used in this document
4130 to serve as a placeholder for whatever text is used by the
4131 user or programmer--appears as shown in the following example:
4132
4133 ``The @code{INTEGER @var{ivar}} statement specifies that
4134 @var{ivar} is a variable or array of type @code{INTEGER}.''
4135
4136 In the above example, any valid text may be substituted for
4137 the metasyntactic variable @var{ivar} to make the statement
4138 apply to a specific instance, as long as the same text is
4139 substituted for @emph{both} occurrences of @var{ivar}.
4140
4141 @item
4142 Ellipses (``@dots{}'') are used to indicate further text that
4143 is either unimportant or expanded upon further, elsewhere.
4144
4145 @item
4146 Names of data types are in the style of Fortran 90, in most
4147 cases.
4148
4149 @xref{Kind Notation}, for information on the relationship
4150 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
4151 and the more traditional, less portably concise nomenclature
4152 (such as @code{INTEGER*4}).
4153 @end itemize
4154
4155 @node Terms and Concepts
4156 @section Fortran Terms and Concepts
4157
4158 (The following information augments or overrides the information in
4159 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4160 language.
4161 Chapter 2 of that document otherwise serves as the basis
4162 for the relevant aspects of GNU Fortran.)
4163
4164 @menu
4165 * Syntactic Items::
4166 * Statements Comments Lines::
4167 * Scope of Names and Labels::
4168 @end menu
4169
4170 @node Syntactic Items
4171 @subsection Syntactic Items
4172
4173 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
4174
4175 In GNU Fortran, a symbolic name is at least one character long,
4176 and has no arbitrary upper limit on length.
4177 However, names of entities requiring external linkage (such as
4178 external functions, external subroutines, and @code{COMMON} areas)
4179 might be restricted to some arbitrary length by the system.
4180 Such a restriction is no more constrained than that of one
4181 through six characters.
4182
4183 Underscores (@samp{_}) are accepted in symbol names after the first
4184 character (which must be a letter).
4185
4186 @node Statements Comments Lines
4187 @subsection Statements, Comments, and Lines
4188
4189 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
4190
4191 @cindex comments, trailing
4192 @cindex trailing comments
4193 Use of an exclamation point (@samp{!}) to begin a
4194 trailing comment (a comment that extends to the end of the same
4195 source line) is permitted under the following conditions:
4196
4197 @itemize @bullet
4198 @item
4199 The exclamation point does not appear in column 6.
4200 Otherwise, it is treated as an indicator of a continuation
4201 line.
4202
4203 @item
4204 The exclamation point appears outside a character or hollerith
4205 constant.
4206 Otherwise, the exclamation point is considered part of the
4207 constant.
4208
4209 @item
4210 The exclamation point appears to the left of any other possible
4211 trailing comment.
4212 That is, a trailing comment may contain exclamation points
4213 in their commentary text.
4214 @end itemize
4215
4216 @cindex semicolons
4217 @cindex statements, separated by semicolon
4218 Use of a semicolon (@samp{;}) as a statement separator
4219 is permitted under the following conditions:
4220
4221 @itemize @bullet
4222 @item
4223 The semicolon appears outside a character or hollerith
4224 constant.
4225 Otherwise, the semicolon is considered part of the
4226 constant.
4227
4228 @item
4229 The semicolon appears to the left of a trailing comment.
4230 Otherwise, the semicolon is considered part of that
4231 comment.
4232
4233 @item
4234 Neither a logical @code{IF} statement nor a non-construct
4235 @code{WHERE} statement (a Fortran 90 feature) may be
4236 followed (in the same, possibly continued, line) by
4237 a semicolon used as a statement separator.
4238
4239 This restriction avoids the confusion
4240 that can result when reading a line such as:
4241
4242 @smallexample
4243 IF (VALIDP) CALL FOO; CALL BAR
4244 @end smallexample
4245
4246 @noindent
4247 Some readers might think the @samp{CALL BAR} is executed
4248 only if @samp{VALIDP} is @code{.TRUE.}, while others might
4249 assume its execution is unconditional.
4250
4251 (At present, @code{g77} does not diagnose code that
4252 violates this restriction.)
4253 @end itemize
4254
4255 @node Scope of Names and Labels
4256 @subsection Scope of Symbolic Names and Statement Labels
4257 @cindex scope
4258
4259 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
4260
4261 Included in the list of entities that have a scope of a
4262 program unit are construct names (a Fortran 90 feature).
4263 @xref{Construct Names}, for more information.
4264
4265 @node Characters Lines Sequence
4266 @section Characters, Lines, and Execution Sequence
4267
4268 (The following information augments or overrides the information in
4269 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4270 language.
4271 Chapter 3 of that document otherwise serves as the basis
4272 for the relevant aspects of GNU Fortran.)
4273
4274 @menu
4275 * Character Set::
4276 * Lines::
4277 * Continuation Line::
4278 * Statements::
4279 * Statement Labels::
4280 * Order::
4281 * INCLUDE::
4282 @end menu
4283
4284 @node Character Set
4285 @subsection GNU Fortran Character Set
4286 @cindex characters
4287
4288 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
4289
4290 Letters include uppercase letters (the twenty-six characters
4291 of the English alphabet) and lowercase letters (their lowercase
4292 equivalent).
4293 Generally, lowercase letters may be used in place of uppercase
4294 letters, though in character and hollerith constants, they
4295 are distinct.
4296
4297 Special characters include:
4298
4299 @itemize @bullet
4300 @item
4301 Semicolon (@samp{;})
4302
4303 @item
4304 Exclamation point (@samp{!})
4305
4306 @item
4307 Double quote (@samp{"})
4308
4309 @item
4310 Backslash (@samp{\})
4311
4312 @item
4313 Question mark (@samp{?})
4314
4315 @item
4316 Hash mark (@samp{#})
4317
4318 @item
4319 Ampersand (@samp{&})
4320
4321 @item
4322 Percent sign (@samp{%})
4323
4324 @item
4325 Underscore (@samp{_})
4326
4327 @item
4328 Open angle (@samp{<})
4329
4330 @item
4331 Close angle (@samp{>})
4332
4333 @item
4334 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
4335 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
4336 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
4337 and @samp{:})
4338 @end itemize
4339
4340 @cindex blanks (spaces)
4341 Note that this document refers to @key{SPC} as @dfn{space},
4342 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
4343
4344 @node Lines
4345 @subsection Lines
4346 @cindex lines
4347 @cindex source file format
4348 @cindex source form
4349 @cindex files, source
4350 @cindex source code
4351 @cindex code, source
4352 @cindex fixed form
4353 @cindex free form
4354
4355 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
4356
4357 The way a Fortran compiler views source files depends entirely on the
4358 implementation choices made for the compiler, since those choices
4359 are explicitly left to the implementation by the published Fortran
4360 standards.
4361
4362 The GNU Fortran language mandates a view applicable to UNIX-like
4363 text files---files that are made up of an arbitrary number of lines,
4364 each with an arbitrary number of characters (sometimes called stream-based
4365 files).
4366
4367 This view does not apply to types of files that are specified as
4368 having a particular number of characters on every single line (sometimes
4369 referred to as record-based files).
4370
4371 Because a ``line in a program unit is a sequence of 72 characters'',
4372 to quote X3.9-1978, the GNU Fortran language specifies that a
4373 stream-based text file is translated to GNU Fortran lines as follows:
4374
4375 @itemize @bullet
4376 @item
4377 A newline in the file is the character that represents the end of
4378 a line of text to the underlying system.
4379 For example, on ASCII-based systems, a newline is the @key{NL}
4380 character, which has ASCII value 12 (decimal).
4381
4382 @item
4383 Each newline in the file serves to end the line of text that precedes
4384 it (and that does not contain a newline).
4385
4386 @item
4387 The end-of-file marker (@code{EOF}) also serves to end the line
4388 of text that precedes it (and that does not contain a newline).
4389
4390 @item
4391 @cindex blanks (spaces)
4392 Any line of text that is shorter than 72 characters is padded to that length
4393 with spaces (called ``blanks'' in the standard).
4394
4395 @item
4396 Any line of text that is longer than 72 characters is truncated to that
4397 length, but the truncated remainder must consist entirely of spaces.
4398
4399 @item
4400 Characters other than newline and the GNU Fortran character set
4401 are invalid.
4402 @end itemize
4403
4404 For the purposes of the remainder of this description of the GNU
4405 Fortran language, the translation described above has already
4406 taken place, unless otherwise specified.
4407
4408 The result of the above translation is that the source file appears,
4409 in terms of the remainder of this description of the GNU Fortran language,
4410 as if it had an arbitrary
4411 number of 72-character lines, each character being among the GNU Fortran
4412 character set.
4413
4414 For example, if the source file itself has two newlines in a row,
4415 the second newline becomes, after the above translation, a single
4416 line containing 72 spaces.
4417
4418 @node Continuation Line
4419 @subsection Continuation Line
4420 @cindex continuation lines, number of
4421 @cindex lines, continuation
4422 @cindex number of continuation lines
4423 @cindex limits on continuation lines
4424
4425 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
4426
4427 A continuation line is any line that both
4428
4429 @itemize @bullet
4430 @item
4431 Contains a continuation character, and
4432
4433 @item
4434 Contains only spaces in columns 1 through 5
4435 @end itemize
4436
4437 A continuation character is any character of the GNU Fortran character set
4438 other than space (@key{SPC}) or zero (@samp{0})
4439 in column 6, or a digit (@samp{0} through @samp{9}) in column
4440 7 through 72 of a line that has only spaces to the left of that
4441 digit.
4442
4443 The continuation character is ignored as far as the content of
4444 the statement is concerned.
4445
4446 The GNU Fortran language places no limit on the number of
4447 continuation lines in a statement.
4448 In practice, the limit depends on a variety of factors, such as
4449 available memory, statement content, and so on, but no
4450 GNU Fortran system may impose an arbitrary limit.
4451
4452 @node Statements
4453 @subsection Statements
4454
4455 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
4456
4457 Statements may be written using an arbitrary number of continuation
4458 lines.
4459
4460 Statements may be separated using the semicolon (@samp{;}), except
4461 that the logical @code{IF} and non-construct @code{WHERE} statements
4462 may not be separated from subsequent statements using only a semicolon
4463 as statement separator.
4464
4465 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
4466 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
4467 statement.
4468 These alternatives may be written as normal statements---they are not
4469 subject to the restrictions of the @code{END} statement.
4470
4471 However, no statement other than @code{END} may have an initial line
4472 that appears to be an @code{END} statement---even @code{END PROGRAM},
4473 for example, must not be written as:
4474
4475 @example
4476 END
4477 &PROGRAM
4478 @end example
4479
4480 @node Statement Labels
4481 @subsection Statement Labels
4482
4483 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
4484
4485 A statement separated from its predecessor via a semicolon may be
4486 labeled as follows:
4487
4488 @itemize @bullet
4489 @item
4490 The semicolon is followed by the label for the statement,
4491 which in turn follows the label.
4492
4493 @item
4494 The label must be no more than five digits in length.
4495
4496 @item
4497 The first digit of the label for the statement is not
4498 the first non-space character on a line.
4499 Otherwise, that character is treated as a continuation
4500 character.
4501 @end itemize
4502
4503 A statement may have only one label defined for it.
4504
4505 @node Order
4506 @subsection Order of Statements and Lines
4507
4508 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
4509
4510 Generally, @code{DATA} statements may precede executable statements.
4511 However, specification statements pertaining to any entities
4512 initialized by a @code{DATA} statement must precede that @code{DATA}
4513 statement.
4514 For example,
4515 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
4516 @samp{INTEGER J} is permitted.
4517
4518 The last line of a program unit may be an @code{END} statement,
4519 or may be:
4520
4521 @itemize @bullet
4522 @item
4523 An @code{END PROGRAM} statement, if the program unit is a main program.
4524
4525 @item
4526 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
4527
4528 @item
4529 An @code{END FUNCTION} statement, if the program unit is a function.
4530
4531 @item
4532 An @code{END BLOCK DATA} statement, if the program unit is a block data.
4533 @end itemize
4534
4535 @node INCLUDE
4536 @subsection Including Source Text
4537 @cindex INCLUDE
4538
4539 Additional source text may be included in the processing of
4540 the source file via the @code{INCLUDE} directive:
4541
4542 @example
4543 INCLUDE @var{filename}
4544 @end example
4545
4546 @noindent
4547 The source text to be included is identified by @var{filename},
4548 which is a literal GNU Fortran character constant.
4549 The meaning and interpretation of @var{filename} depends on the
4550 implementation, but typically is a filename.
4551
4552 (@code{g77} treats it as a filename that it searches for
4553 in the current directory and/or directories specified
4554 via the @samp{-I} command-line option.)
4555
4556 The effect of the @code{INCLUDE} directive is as if the
4557 included text directly replaced the directive in the source
4558 file prior to interpretation of the program.
4559 Included text may itself use @code{INCLUDE}.
4560 The depth of nested @code{INCLUDE} references depends on
4561 the implementation, but typically is a positive integer.
4562
4563 This virtual replacement treats the statements and @code{INCLUDE}
4564 directives in the included text as syntactically distinct from
4565 those in the including text.
4566
4567 Therefore, the first non-comment line of the included text
4568 must not be a continuation line.
4569 The included text must therefore have, after the non-comment
4570 lines, either an initial line (statement), an @code{INCLUDE}
4571 directive, or nothing (the end of the included text).
4572
4573 Similarly, the including text may end the @code{INCLUDE}
4574 directive with a semicolon or the end of the line, but it
4575 cannot follow an @code{INCLUDE} directive at the end of its
4576 line with a continuation line.
4577 Thus, the last statement in an included text may not be
4578 continued.
4579
4580 Any statements between two @code{INCLUDE} directives on the
4581 same line are treated as if they appeared in between the
4582 respective included texts.
4583 For example:
4584
4585 @smallexample
4586 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
4587 @end smallexample
4588
4589 @noindent
4590 If the text included by @samp{INCLUDE 'A'} constitutes
4591 a @samp{PRINT *, 'A'} statement and the text included by
4592 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
4593 then the output of the above sample program would be
4594
4595 @example
4596 A
4597 B
4598 C
4599 @end example
4600
4601 @noindent
4602 (with suitable allowances for how an implementation defines
4603 its handling of output).
4604
4605 Included text must not include itself directly or indirectly,
4606 regardless of whether the @var{filename} used to reference
4607 the text is the same.
4608
4609 Note that @code{INCLUDE} is @emph{not} a statement.
4610 As such, it is neither a non-executable or executable
4611 statement.
4612 However, if the text it includes constitutes one or more
4613 executable statements, then the placement of @code{INCLUDE}
4614 is subject to effectively the same restrictions as those
4615 on executable statements.
4616
4617 An @code{INCLUDE} directive may be continued across multiple
4618 lines as if it were a statement.
4619 This permits long names to be used for @var{filename}.
4620
4621 @node Data Types and Constants
4622 @section Data Types and Constants
4623
4624 (The following information augments or overrides the information in
4625 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4626 language.
4627 Chapter 4 of that document otherwise serves as the basis
4628 for the relevant aspects of GNU Fortran.)
4629
4630 To more concisely express the appropriate types for
4631 entities, this document uses the more concise
4632 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
4633 instead of the more traditional, but less portably concise,
4634 byte-size-based nomenclature such as @code{INTEGER*4},
4635 wherever reasonable.
4636
4637 When referring to generic types---in contexts where the
4638 specific precision and range of a type are not important---this
4639 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
4640 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
4641
4642 In some cases, the context requires specification of a
4643 particular type.
4644 This document uses the @samp{KIND=} notation to accomplish
4645 this throughout, sometimes supplying the more traditional
4646 notation for clarification, though the traditional notation
4647 might not work the same way on all GNU Fortran implementations.
4648
4649 Use of @samp{KIND=} makes this document more concise because
4650 @code{g77} is able to define values for @samp{KIND=} that
4651 have the same meanings on all systems, due to the way the
4652 Fortran 90 standard specifies these values are to be used.
4653
4654 (In particular, that standard permits an implementation to
4655 arbitrarily assign nonnegative values.
4656 There are four distinct sets of assignments: one to the @code{CHARACTER}
4657 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
4658 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
4659 Implementations are free to assign these values in any order,
4660 leave gaps in the ordering of assignments, and assign more than
4661 one value to a representation.)
4662
4663 This makes @samp{KIND=} values superior to the values used
4664 in non-standard statements such as @samp{INTEGER*4}, because
4665 the meanings of the values in those statements vary from machine
4666 to machine, compiler to compiler, even operating system to
4667 operating system.
4668
4669 However, use of @samp{KIND=} is @emph{not} generally recommended
4670 when writing portable code (unless, for example, the code is
4671 going to be compiled only via @code{g77}, which is a widely
4672 ported compiler).
4673 GNU Fortran does not yet have adequate language constructs to
4674 permit use of @samp{KIND=} in a fashion that would make the
4675 code portable to Fortran 90 implementations; and, this construct
4676 is known to @emph{not} be accepted by many popular FORTRAN 77
4677 implementations, so it cannot be used in code that is to be ported
4678 to those.
4679
4680 The distinction here is that this document is able to use
4681 specific values for @samp{KIND=} to concisely document the
4682 types of various operations and operands.
4683
4684 A Fortran program should use the FORTRAN 77 designations for the
4685 appropriate GNU Fortran types---such as @code{INTEGER} for
4686 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
4687 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
4688 where no such designations exist, make use of appropriate
4689 techniques (preprocessor macros, parameters, and so on)
4690 to specify the types in a fashion that may be easily adjusted
4691 to suit each particular implementation to which the program
4692 is ported.
4693 (These types generally won't need to be adjusted for ports of
4694 @code{g77}.)
4695
4696 Further details regarding GNU Fortran data types and constants
4697 are provided below.
4698
4699 @menu
4700 * Types::
4701 * Constants::
4702 * Integer Type::
4703 * Character Type::
4704 @end menu
4705
4706 @node Types
4707 @subsection Data Types
4708
4709 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
4710
4711 GNU Fortran supports these types:
4712
4713 @enumerate
4714 @item
4715 Integer (generic type @code{INTEGER})
4716
4717 @item
4718 Real (generic type @code{REAL})
4719
4720 @item
4721 Double precision
4722
4723 @item
4724 Complex (generic type @code{COMPLEX})
4725
4726 @item
4727 Logical (generic type @code{LOGICAL})
4728
4729 @item
4730 Character (generic type @code{CHARACTER})
4731
4732 @item
4733 Double Complex
4734 @end enumerate
4735
4736 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
4737
4738 The generic types shown above are referred to in this document
4739 using only their generic type names.
4740 Such references usually indicate that any specific type (kind)
4741 of that generic type is valid.
4742
4743 For example, a context described in this document as accepting
4744 the @code{COMPLEX} type also is likely to accept the
4745 @code{DOUBLE COMPLEX} type.
4746
4747 The GNU Fortran language supports three ways to specify
4748 a specific kind of a generic type.
4749
4750 @menu
4751 * Double Notation:: As in @code{DOUBLE COMPLEX}.
4752 * Star Notation:: As in @code{INTEGER*4}.
4753 * Kind Notation:: As in @code{INTEGER(KIND=1)}.
4754 @end menu
4755
4756 @node Double Notation
4757 @subsubsection Double Notation
4758
4759 The GNU Fortran language supports two uses of the keyword
4760 @code{DOUBLE} to specify a specific kind of type:
4761
4762 @itemize @bullet
4763 @item
4764 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
4765
4766 @item
4767 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
4768 @end itemize
4769
4770 Use one of the above forms where a type name is valid.
4771
4772 While use of this notation is popular, it doesn't scale
4773 well in a language or dialect rich in intrinsic types,
4774 as is the case for the GNU Fortran language (especially
4775 planned future versions of it).
4776
4777 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
4778 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
4779 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
4780 often are substituted for these, respectively, even though they
4781 do not always have the same meanings on all systems.
4782 (And, the fact that @samp{DOUBLE REAL} does not exist as such
4783 is an inconsistency.)
4784
4785 Therefore, this document uses ``double notation'' only on occasion
4786 for the benefit of those readers who are accustomed to it.
4787
4788 @node Star Notation
4789 @subsubsection Star Notation
4790 @cindex *@var{n} notation
4791
4792 The following notation specifies the storage size for a type:
4793
4794 @smallexample
4795 @var{generic-type}*@var{n}
4796 @end smallexample
4797
4798 @noindent
4799 @var{generic-type} must be a generic type---one of
4800 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4801 or @code{CHARACTER}.
4802 @var{n} must be one or more digits comprising a decimal
4803 integer number greater than zero.
4804
4805 Use the above form where a type name is valid.
4806
4807 The @samp{*@var{n}} notation specifies that the amount of storage
4808 occupied by variables and array elements of that type is @var{n}
4809 times the storage occupied by a @code{CHARACTER*1} variable.
4810
4811 This notation might indicate a different degree of precision and/or
4812 range for such variables and array elements, and the functions that
4813 return values of types using this notation.
4814 It does not limit the precision or range of values of that type
4815 in any particular way---use explicit code to do that.
4816
4817 Further, the GNU Fortran language requires no particular values
4818 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
4819 notation.
4820 @code{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
4821 on all systems, for example,
4822 but not all implementations are required to do so, and @code{g77}
4823 is known to not support @code{REAL*1} on most (or all) systems.
4824
4825 As a result, except for @var{generic-type} of @code{CHARACTER},
4826 uses of this notation should be limited to isolated
4827 portions of a program that are intended to handle system-specific
4828 tasks and are expected to be non-portable.
4829
4830 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
4831 only @code{CHARACTER}, where it signifies not only the amount
4832 of storage occupied, but the number of characters in entities
4833 of that type.
4834 However, almost all Fortran compilers have supported this
4835 notation for generic types, though with a variety of meanings
4836 for @var{n}.)
4837
4838 Specifications of types using the @samp{*@var{n}} notation
4839 always are interpreted as specifications of the appropriate
4840 types described in this document using the @samp{KIND=@var{n}}
4841 notation, described below.
4842
4843 While use of this notation is popular, it doesn't serve well
4844 in the context of a widely portable dialect of Fortran, such as
4845 the GNU Fortran language.
4846
4847 For example, even on one particular machine, two or more popular
4848 Fortran compilers might well disagree on the size of a type
4849 declared @code{INTEGER*2} or @code{REAL*16}.
4850 Certainly there
4851 is known to be disagreement over such things among Fortran
4852 compilers on @emph{different} systems.
4853
4854 Further, this notation offers no elegant way to specify sizes
4855 that are not even multiples of the ``byte size'' typically
4856 designated by @code{INTEGER*1}.
4857 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
4858 certainly be possible, but would perhaps be stretching the original
4859 intent of this notation beyond the breaking point in terms
4860 of widespread readability of documentation and code making use
4861 of it.
4862
4863 Therefore, this document uses ``star notation'' only on occasion
4864 for the benefit of those readers who are accustomed to it.
4865
4866 @node Kind Notation
4867 @subsubsection Kind Notation
4868 @cindex KIND= notation
4869
4870 The following notation specifies the kind-type selector of a type:
4871
4872 @smallexample
4873 @var{generic-type}(KIND=@var{n})
4874 @end smallexample
4875
4876 @noindent
4877 Use the above form where a type name is valid.
4878
4879 @var{generic-type} must be a generic type---one of
4880 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4881 or @code{CHARACTER}.
4882 @var{n} must be an integer initialization expression that
4883 is a positive, nonzero value.
4884
4885 Programmers are discouraged from writing these values directly
4886 into their code.
4887 Future versions of the GNU Fortran language will offer
4888 facilities that will make the writing of code portable
4889 to @code{g77} @emph{and} Fortran 90 implementations simpler.
4890
4891 However, writing code that ports to existing FORTRAN 77
4892 implementations depends on avoiding the @samp{KIND=} construct.
4893
4894 The @samp{KIND=} construct is thus useful in the context
4895 of GNU Fortran for two reasons:
4896
4897 @itemize @bullet
4898 @item
4899 It provides a means to specify a type in a fashion that
4900 is portable across all GNU Fortran implementations (though
4901 not other FORTRAN 77 and Fortran 90 implementations).
4902
4903 @item
4904 It provides a sort of Rosetta stone for this document to use
4905 to concisely describe the types of various operations and
4906 operands.
4907 @end itemize
4908
4909 The values of @var{n} in the GNU Fortran language are
4910 assigned using a scheme that:
4911
4912 @itemize @bullet
4913 @item
4914 Attempts to maximize the ability of readers
4915 of this document to quickly familiarize themselves
4916 with assignments for popular types
4917
4918 @item
4919 Provides a unique value for each specific desired
4920 meaning
4921
4922 @item
4923 Provides a means to automatically assign new values so
4924 they have a ``natural'' relationship to existing values,
4925 if appropriate, or, if no such relationship exists, will
4926 not interfere with future values assigned on the basis
4927 of such relationships
4928
4929 @item
4930 Avoids using values that are similar to values used
4931 in the existing, popular @samp{*@var{n}} notation,
4932 to prevent readers from expecting that these implied
4933 correspondences work on all GNU Fortran implementations
4934 @end itemize
4935
4936 The assignment system accomplishes this by assigning
4937 to each ``fundamental meaning'' of a specific type a
4938 unique prime number.
4939 Combinations of fundamental meanings---for example, a type
4940 that is two times the size of some other type---are assigned
4941 values of @var{n} that are the products of the values for
4942 those fundamental meanings.
4943
4944 A prime value of @var{n} is never given more than one fundamental
4945 meaning, to avoid situations where some code or system
4946 cannot reasonably provide those meanings in the form of a
4947 single type.
4948
4949 The values of @var{n} assigned so far are:
4950
4951 @table @code
4952 @item KIND=0
4953 This value is reserved for future use.
4954
4955 The planned future use is for this value to designate,
4956 explicitly, context-sensitive kind-type selection.
4957 For example, the expression @samp{1D0 * 0.1_0} would
4958 be equivalent to @samp{1D0 * 0.1D0}.
4959
4960 @item KIND=1
4961 This corresponds to the default types for
4962 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
4963 and @code{CHARACTER}, as appropriate.
4964
4965 These are the ``default'' types described in the Fortran 90 standard,
4966 though that standard does not assign any particular @samp{KIND=}
4967 value to these types.
4968
4969 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
4970 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
4971
4972 @item KIND=2
4973 This corresponds to types that occupy twice as much
4974 storage as the default types.
4975 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
4976 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
4977
4978 These are the ``double precision'' types described in the Fortran 90
4979 standard,
4980 though that standard does not assign any particular @samp{KIND=}
4981 value to these types.
4982
4983 @var{n} of 4 thus corresponds to types that occupy four times
4984 as much storage as the default types, @var{n} of 8 to types that
4985 occupy eight times as much storage, and so on.
4986
4987 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
4988 are not necessarily supported by every GNU Fortran implementation.
4989
4990 @item KIND=3
4991 This corresponds to types that occupy as much
4992 storage as the default @code{CHARACTER} type,
4993 which is the same effective type as @code{CHARACTER(KIND=1)}
4994 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
4995
4996 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
4997
4998 @var{n} of 6 thus corresponds to types that occupy twice as
4999 much storage as the @var{n}=3 types, @var{n} of 12 to types
5000 that occupy four times as much storage, and so on.
5001
5002 These are not necessarily supported by every GNU Fortran
5003 implementation.
5004
5005 @item KIND=5
5006 This corresponds to types that occupy half the
5007 storage as the default (@var{n}=1) types.
5008
5009 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
5010
5011 @var{n} of 25 thus corresponds to types that occupy one-quarter
5012 as much storage as the default types.
5013
5014 These are not necessarily supported by every GNU Fortran
5015 implementation.
5016
5017 @item KIND=7
5018 @cindex pointers
5019 This is valid only as @code{INTEGER(KIND=7)} and
5020 denotes the @code{INTEGER} type that has the smallest
5021 storage size that holds a pointer on the system.
5022
5023 A pointer representable by this type is capable of uniquely
5024 addressing a @code{CHARACTER*1} variable, array, array element,
5025 or substring.
5026
5027 (Typically this is equivalent to @code{INTEGER*4} or,
5028 on 64-bit systems, @code{INTEGER*8}.
5029 In a compatible C implementation, it typically would
5030 be the same size and semantics of the C type @code{void *}.)
5031 @end table
5032
5033 Note that these are @emph{proposed} correspondences and might change
5034 in future versions of @code{g77}---avoid writing code depending
5035 on them while @code{g77}, and therefore the GNU Fortran language
5036 it defines, is in beta testing.
5037
5038 Values not specified in the above list are reserved to
5039 future versions of the GNU Fortran language.
5040
5041 Implementation-dependent meanings will be assigned new,
5042 unique prime numbers so as to not interfere with other
5043 implementation-dependent meanings, and offer the possibility
5044 of increasing the portability of code depending on such
5045 types by offering support for them in other GNU Fortran
5046 implementations.
5047
5048 Other meanings that might be given unique values are:
5049
5050 @itemize @bullet
5051 @item
5052 Types that make use of only half their storage size for
5053 representing precision and range.
5054
5055 For example, some compilers offer options that cause
5056 @code{INTEGER} types to occupy the amount of storage
5057 that would be needed for @code{INTEGER(KIND=2)} types, but the
5058 range remains that of @code{INTEGER(KIND=1)}.
5059
5060 @item
5061 The IEEE single floating-point type.
5062
5063 @item
5064 Types with a specific bit pattern (endianness), such as the
5065 little-endian form of @code{INTEGER(KIND=1)}.
5066 These could permit, conceptually, use of portable code and
5067 implementations on data files written by existing systems.
5068 @end itemize
5069
5070 Future @emph{prime} numbers should be given meanings in as incremental
5071 a fashion as possible, to allow for flexibility and
5072 expressiveness in combining types.
5073
5074 For example, instead of defining a prime number for little-endian
5075 IEEE doubles, one prime number might be assigned the meaning
5076 ``little-endian'', another the meaning ``IEEE double'', and the
5077 value of @var{n} for a little-endian IEEE double would thus
5078 naturally be the product of those two respective assigned values.
5079 (It could even be reasonable to have IEEE values result from the
5080 products of prime values denoting exponent and fraction sizes
5081 and meanings, hidden bit usage, availability and representations
5082 of special values such as subnormals, infinities, and Not-A-Numbers
5083 (NaNs), and so on.)
5084
5085 This assignment mechanism, while not inherently required for
5086 future versions of the GNU Fortran language, is worth using
5087 because it could ease management of the ``space'' of supported
5088 types much easier in the long run.
5089
5090 The above approach suggests a mechanism for specifying inheritance
5091 of intrinsic (built-in) types for an entire, widely portable
5092 product line.
5093 It is certainly reasonable that, unlike programmers of other languages
5094 offering inheritance mechanisms that employ verbose names for classes
5095 and subclasses, along with graphical browsers to elucidate the
5096 relationships, Fortran programmers would employ
5097 a mechanism that works by multiplying prime numbers together
5098 and finding the prime factors of such products.
5099
5100 Most of the advantages for the above scheme have been explained
5101 above.
5102 One disadvantage is that it could lead to the defining,
5103 by the GNU Fortran language, of some fairly large prime numbers.
5104 This could lead to the GNU Fortran language being declared
5105 ``munitions'' by the United States Department of Defense.
5106
5107 @node Constants
5108 @subsection Constants
5109 @cindex constants
5110 @cindex types, constants
5111
5112 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
5113
5114 A @dfn{typeless constant} has one of the following forms:
5115
5116 @smallexample
5117 '@var{binary-digits}'B
5118 '@var{octal-digits}'O
5119 '@var{hexadecimal-digits}'Z
5120 '@var{hexadecimal-digits}'X
5121 @end smallexample
5122
5123 @noindent
5124 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
5125 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
5126 and @samp{0123456789ABCDEFabcdef}, respectively.
5127 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
5128 is 11, and so on.)
5129
5130 Typeless constants have values that depend on the context in which
5131 they are used.
5132
5133 All other constants, called @dfn{typed constants}, are interpreted---converted
5134 to internal form---according to their inherent type.
5135 Thus, context is @emph{never} a determining factor for the type, and hence
5136 the interpretation, of a typed constant.
5137 (All constants in the ANSI FORTRAN 77 language are typed constants.)
5138
5139 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
5140 Fortran (called default INTEGER in Fortran 90),
5141 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
5142 additional precision specified is lost, and even when used in a
5143 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
5144 and @samp{1D0} is always type @code{REAL(KIND=2)}.
5145
5146 @node Integer Type
5147 @subsection Integer Type
5148
5149 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
5150
5151 An integer constant also may have one of the following forms:
5152
5153 @smallexample
5154 B'@var{binary-digits}'
5155 O'@var{octal-digits}'
5156 Z'@var{hexadecimal-digits}'
5157 X'@var{hexadecimal-digits}'
5158 @end smallexample
5159
5160 @noindent
5161 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
5162 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
5163 and @samp{0123456789ABCDEFabcdef}, respectively.
5164 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
5165 is 11, and so on.)
5166
5167 @node Character Type
5168 @subsection Character Type
5169
5170 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
5171
5172 A character constant may be delimited by a pair of double quotes
5173 (@samp{"}) instead of apostrophes.
5174 In this case, an apostrophe within the constant represents
5175 a single apostrophe, while a double quote is represented in
5176 the source text of the constant by two consecutive double
5177 quotes with no intervening spaces.
5178
5179 @cindex zero-length CHARACTER
5180 @cindex null CHARACTER strings
5181 @cindex empty CHARACTER strings
5182 @cindex strings, empty
5183 @cindex CHARACTER, null
5184 A character constant may be empty (have a length of zero).
5185
5186 A character constant may include a substring specification,
5187 The value of such a constant is the value of the substring---for
5188 example, the value of @samp{'hello'(3:5)} is the same
5189 as the value of @samp{'llo'}.
5190
5191 @node Expressions
5192 @section Expressions
5193
5194 (The following information augments or overrides the information in
5195 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5196 language.
5197 Chapter 6 of that document otherwise serves as the basis
5198 for the relevant aspects of GNU Fortran.)
5199
5200 @menu
5201 * %LOC()::
5202 @end menu
5203
5204 @node %LOC()
5205 @subsection The @code{%LOC()} Construct
5206 @cindex %LOC() construct
5207
5208 @example
5209 %LOC(@var{arg})
5210 @end example
5211
5212 The @code{%LOC()} construct is an expression
5213 that yields the value of the location of its argument,
5214 @var{arg}, in memory.
5215 The size of the type of the expression depends on the system---typically,
5216 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
5217 though it is actually type @code{INTEGER(KIND=7)}.
5218
5219 The argument to @code{%LOC()} must be suitable as the
5220 left-hand side of an assignment statement.
5221 That is, it may not be a general expression involving
5222 operators such as addition, subtraction, and so on,
5223 nor may it be a constant.
5224
5225 Use of @code{%LOC()} is recommended only for code that
5226 is accessing facilities outside of GNU Fortran, such as
5227 operating system or windowing facilities.
5228 It is best to constrain such uses to isolated portions of
5229 a program---portions that deal specifically and exclusively
5230 with low-level, system-dependent facilities.
5231 Such portions might well provide a portable interface for
5232 use by the program as a whole, but are themselves not
5233 portable, and should be thoroughly tested each time they
5234 are rebuilt using a new compiler or version of a compiler.
5235
5236 Do not depend on @code{%LOC()} returning a pointer that
5237 can be safely used to @emph{define} (change) the argument.
5238 While this might work in some circumstances, it is hard
5239 to predict whether it will continue to work when a program
5240 (that works using this unsafe behavior)
5241 is recompiled using different command-line options or
5242 a different version of @code{g77}.
5243
5244 Generally, @code{%LOC()} is safe when used as an argument
5245 to a procedure that makes use of the value of the corresponding
5246 dummy argument only during its activation, and only when
5247 such use is restricted to referencing (reading) the value
5248 of the argument to @code{%LOC()}.
5249
5250 @emph{Implementation Note:} Currently, @code{g77} passes
5251 arguments (those not passed using a construct such as @code{%VAL()})
5252 by reference or descriptor, depending on the type of
5253 the actual argument.
5254 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
5255 seem to mean the same thing as @samp{CALL FOO(%LOC(I))}, and
5256 in fact might compile to identical code.
5257
5258 However, @samp{CALL FOO(%LOC(I))} emphatically means ``pass the
5259 address of @samp{I} in memory''.
5260 While @samp{CALL FOO(I)} might use that same approach in a
5261 particular version of @code{g77}, another version or compiler
5262 might choose a different implementation, such as copy-in/copy-out,
5263 to effect the desired behavior---and which will therefore not
5264 necessarily compile to the same code as would @samp{CALL FOO(%LOC(I))}
5265 using the same version or compiler.
5266
5267 @xref{Debugging and Interfacing}, for detailed information on
5268 how this particular version of @code{g77} implements various
5269 constructs.
5270
5271 @node Specification Statements
5272 @section Specification Statements
5273
5274 (The following information augments or overrides the information in
5275 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5276 language.
5277 Chapter 8 of that document otherwise serves as the basis
5278 for the relevant aspects of GNU Fortran.)
5279
5280 @menu
5281 * NAMELIST::
5282 * DOUBLE COMPLEX::
5283 @end menu
5284
5285 @node NAMELIST
5286 @subsection @code{NAMELIST} Statement
5287 @cindex NAMELIST statement
5288 @cindex statements, NAMELIST
5289
5290 The @code{NAMELIST} statement, and related I/O constructs, are
5291 supported by the GNU Fortran language in essentially the same
5292 way as they are by @code{f2c}.
5293
5294 @node DOUBLE COMPLEX
5295 @subsection @code{DOUBLE COMPLEX} Statement
5296 @cindex DOUBLE COMPLEX
5297
5298 @code{DOUBLE COMPLEX} is a type-statement (and type) that
5299 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
5300
5301 @node Control Statements
5302 @section Control Statements
5303
5304 (The following information augments or overrides the information in
5305 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5306 language.
5307 Chapter 11 of that document otherwise serves as the basis
5308 for the relevant aspects of GNU Fortran.)
5309
5310 @menu
5311 * DO WHILE::
5312 * END DO::
5313 * Construct Names::
5314 * CYCLE and EXIT::
5315 @end menu
5316
5317 @node DO WHILE
5318 @subsection DO WHILE
5319 @cindex DO WHILE
5320 @cindex MIL-STD 1753
5321
5322 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
5323 Fortran 90 standards, is provided by the GNU Fortran language.
5324
5325 @node END DO
5326 @subsection END DO
5327 @cindex END DO
5328 @cindex MIL-STD 1753
5329
5330 The @code{END DO} statement is provided by the GNU Fortran language.
5331
5332 This statement is used in one of two ways:
5333
5334 @itemize @bullet
5335 @item
5336 The Fortran 90 meaning, in which it specifies the termination
5337 point of a single @code{DO} loop started with a @code{DO} statement
5338 that specifies no termination label.
5339
5340 @item
5341 The MIL-STD 1753 meaning, in which it specifies the termination
5342 point of one or more @code{DO} loops, all of which start with a
5343 @code{DO} statement that specify the label defined for the
5344 @code{END DO} statement.
5345
5346 This kind of @code{END DO} statement is merely a synonym for
5347 @code{CONTINUE}, except it is permitted only when the statement
5348 is labeled and a target of one or more labeled @code{DO} loops.
5349
5350 It is expected that this use of @code{END DO} will be removed from
5351 the GNU Fortran language in the future, though it is likely that
5352 it will long be supported by @code{g77} as a dialect form.
5353 @end itemize
5354
5355 @node Construct Names
5356 @subsection Construct Names
5357 @cindex construct names
5358
5359 The GNU Fortran language supports construct names as defined
5360 by the Fortran 90 standard.
5361 These names are local to the program unit and are defined
5362 as follows:
5363
5364 @smallexample
5365 @var{construct-name}: @var{block-statement}
5366 @end smallexample
5367
5368 @noindent
5369 Here, @var{construct-name} is the construct name itself;
5370 its definition is connoted by the single colon (@samp{:}); and
5371 @var{block-statement} is an @code{IF}, @code{DO},
5372 or @code{SELECT CASE} statement that begins a block.
5373
5374 A block that is given a construct name must also specify the
5375 same construct name in its termination statement:
5376
5377 @example
5378 END @var{block} @var{construct-name}
5379 @end example
5380
5381 @noindent
5382 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
5383 as appropriate.
5384
5385 @node CYCLE and EXIT
5386 @subsection The @code{CYCLE} and @code{EXIT} Statements
5387
5388 The @code{CYCLE} and @code{EXIT} statements specify that
5389 the remaining statements in the current iteration of a
5390 particular active (enclosing) @code{DO} loop are to be skipped.
5391
5392 @code{CYCLE} specifies that these statements are skipped,
5393 but the @code{END DO} statement that marks the end of the
5394 @code{DO} loop be executed---that is, the next iteration,
5395 if any, is to be started.
5396 If the statement marking the end of the @code{DO} loop is
5397 not @code{END DO}---in other words, if the loop is not
5398 a block @code{DO}---the @code{CYCLE} statement does not
5399 execute that statement, but does start the next iteration (if any).
5400
5401 @code{EXIT} specifies that the loop specified by the
5402 @code{DO} construct is terminated.
5403
5404 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
5405 is the innermost enclosing @code{DO} loop when the following
5406 forms are used:
5407
5408 @example
5409 CYCLE
5410 EXIT
5411 @end example
5412
5413 Otherwise, the following forms specify the construct name
5414 of the pertinent @code{DO} loop:
5415
5416 @example
5417 CYCLE @var{construct-name}
5418 EXIT @var{construct-name}
5419 @end example
5420
5421 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
5422 statements.
5423 However, they cannot be easily thought of as @code{GO TO} statements
5424 in obscure cases involving FORTRAN 77 loops.
5425 For example:
5426
5427 @smallexample
5428 DO 10 I = 1, 5
5429 DO 10 J = 1, 5
5430 IF (J .EQ. 5) EXIT
5431 DO 10 K = 1, 5
5432 IF (K .EQ. 3) CYCLE
5433 10 PRINT *, 'I=', I, ' J=', J, ' K=', K
5434 20 CONTINUE
5435 @end smallexample
5436
5437 @noindent
5438 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
5439 above are equivalent to a @code{GO TO} statement to either label
5440 @samp{10} or @samp{20}.
5441
5442 To understand the effect of @code{CYCLE} and @code{EXIT} in the
5443 above fragment, it is helpful to first translate it to its equivalent
5444 using only block @code{DO} loops:
5445
5446 @smallexample
5447 DO I = 1, 5
5448 DO J = 1, 5
5449 IF (J .EQ. 5) EXIT
5450 DO K = 1, 5
5451 IF (K .EQ. 3) CYCLE
5452 10 PRINT *, 'I=', I, ' J=', J, ' K=', K
5453 END DO
5454 END DO
5455 END DO
5456 20 CONTINUE
5457 @end smallexample
5458
5459 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
5460 to @code{GO TO} so they may be more easily understood by programmers
5461 accustomed to FORTRAN coding:
5462
5463 @smallexample
5464 DO I = 1, 5
5465 DO J = 1, 5
5466 IF (J .EQ. 5) GOTO 18
5467 DO K = 1, 5
5468 IF (K .EQ. 3) GO TO 12
5469 10 PRINT *, 'I=', I, ' J=', J, ' K=', K
5470 12 END DO
5471 END DO
5472 18 END DO
5473 20 CONTINUE
5474 @end smallexample
5475
5476 @noindent
5477 Thus, the @code{CYCLE} statement in the innermost loop skips over
5478 the @code{PRINT} statement as it begins the next iteration of the
5479 loop, while the @code{EXIT} statement in the middle loop ends that
5480 loop but @emph{not} the outermost loop.
5481
5482 @node Functions and Subroutines
5483 @section Functions and Subroutines
5484
5485 (The following information augments or overrides the information in
5486 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5487 language.
5488 Chapter 15 of that document otherwise serves as the basis
5489 for the relevant aspects of GNU Fortran.)
5490
5491 @menu
5492 * %VAL()::
5493 * %REF()::
5494 * %DESCR()::
5495 * Generics and Specifics::
5496 * REAL() and AIMAG() of Complex::
5497 * CMPLX() of DOUBLE PRECISION::
5498 * MIL-STD 1753::
5499 * f77/f2c Intrinsics::
5500 * Table of Intrinsic Functions::
5501 @end menu
5502
5503 @node %VAL()
5504 @subsection The @code{%VAL()} Construct
5505 @cindex %VAL() construct
5506
5507 @example
5508 %VAL(@var{arg})
5509 @end example
5510
5511 The @code{%VAL()} construct specifies that an argument,
5512 @var{arg}, is to be passed by value, instead of by reference
5513 or descriptor.
5514
5515 @code{%VAL()} is restricted to actual arguments in
5516 invocations of external procedures.
5517
5518 Use of @code{%VAL()} is recommended only for code that
5519 is accessing facilities outside of GNU Fortran, such as
5520 operating system or windowing facilities.
5521 It is best to constrain such uses to isolated portions of
5522 a program---portions the deal specifically and exclusively
5523 with low-level, system-dependent facilities.
5524 Such portions might well provide a portable interface for
5525 use by the program as a whole, but are themselves not
5526 portable, and should be thoroughly tested each time they
5527 are rebuilt using a new compiler or version of a compiler.
5528
5529 @emph{Implementation Note:} Currently, @code{g77} passes
5530 all arguments either by reference or by descriptor.
5531
5532 Thus, use of @code{%VAL()} tends to be restricted to cases
5533 where the called procedure is written in a language other
5534 than Fortran that supports call-by-value semantics.
5535 (C is an example of such a language.)
5536
5537 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
5538 for detailed information on
5539 how this particular version of @code{g77} passes arguments
5540 to procedures.
5541
5542 @node %REF()
5543 @subsection The @code{%REF()} Construct
5544 @cindex %REF() construct
5545
5546 @example
5547 %REF(@var{arg})
5548 @end example
5549
5550 The @code{%REF()} construct specifies that an argument,
5551 @var{arg}, is to be passed by reference, instead of by
5552 value or descriptor.
5553
5554 @code{%REF()} is restricted to actual arguments in
5555 invocations of external procedures.
5556
5557 Use of @code{%REF()} is recommended only for code that
5558 is accessing facilities outside of GNU Fortran, such as
5559 operating system or windowing facilities.
5560 It is best to constrain such uses to isolated portions of
5561 a program---portions the deal specifically and exclusively
5562 with low-level, system-dependent facilities.
5563 Such portions might well provide a portable interface for
5564 use by the program as a whole, but are themselves not
5565 portable, and should be thoroughly tested each time they
5566 are rebuilt using a new compiler or version of a compiler.
5567
5568 Do not depend on @code{%REF()} supplying a pointer to the
5569 procedure being invoked.
5570 While that is a likely implementation choice, other
5571 implementation choices are available that preserve Fortran
5572 pass-by-reference semantics without passing a pointer to
5573 the argument, @var{arg}.
5574 (For example, a copy-in/copy-out implementation.)
5575
5576 @emph{Implementation Note:} Currently, @code{g77} passes
5577 all arguments
5578 (other than variables and arrays of type @code{CHARACTER})
5579 by reference.
5580 Future versions of, or dialects supported by, @code{g77} might
5581 not pass @code{CHARACTER} functions by reference.
5582
5583 Thus, use of @code{%REF()} tends to be restricted to cases
5584 where @var{arg} is type @code{CHARACTER} but the called
5585 procedure accesses it via a means other than the method
5586 used for Fortran @code{CHARACTER} arguments.
5587
5588 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5589 how this particular version of @code{g77} passes arguments
5590 to procedures.
5591
5592 @node %DESCR()
5593 @subsection The @code{%DESCR()} Construct
5594 @cindex %DESCR() construct
5595
5596 @example
5597 %DESCR(@var{arg})
5598 @end example
5599
5600 The @code{%DESCR()} construct specifies that an argument,
5601 @var{arg}, is to be passed by descriptor, instead of by
5602 value or reference.
5603
5604 @code{%DESCR()} is restricted to actual arguments in
5605 invocations of external procedures.
5606
5607 Use of @code{%DESCR()} is recommended only for code that
5608 is accessing facilities outside of GNU Fortran, such as
5609 operating system or windowing facilities.
5610 It is best to constrain such uses to isolated portions of
5611 a program---portions the deal specifically and exclusively
5612 with low-level, system-dependent facilities.
5613 Such portions might well provide a portable interface for
5614 use by the program as a whole, but are themselves not
5615 portable, and should be thoroughly tested each time they
5616 are rebuilt using a new compiler or version of a compiler.
5617
5618 Do not depend on @code{%DESCR()} supplying a pointer
5619 and/or a length passed by value
5620 to the procedure being invoked.
5621 While that is a likely implementation choice, other
5622 implementation choices are available that preserve the
5623 pass-by-reference semantics without passing a pointer to
5624 the argument, @var{arg}.
5625 (For example, a copy-in/copy-out implementation.)@
5626 And, future versions of @code{g77} might change the
5627 way descriptors are implemented, such as passing a
5628 single argument pointing to a record containing the
5629 pointer/length information instead of passing that same
5630 information via two arguments as it currently does.
5631
5632 @emph{Implementation Note:} Currently, @code{g77} passes
5633 all variables and arrays of type @code{CHARACTER}
5634 by descriptor.
5635 Future versions of, or dialects supported by, @code{g77} might
5636 pass @code{CHARACTER} functions by descriptor as well.
5637
5638 Thus, use of @code{%DESCR()} tends to be restricted to cases
5639 where @var{arg} is not type @code{CHARACTER} but the called
5640 procedure accesses it via a means similar to the method
5641 used for Fortran @code{CHARACTER} arguments.
5642
5643 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5644 how this particular version of @code{g77} passes arguments
5645 to procedures.
5646
5647 @node Generics and Specifics
5648 @subsection Generics and Specifics
5649 @cindex generic intrinsics
5650 @cindex intrinsics, generic
5651
5652 The ANSI FORTRAN 77 language defines generic and specific
5653 intrinsics.
5654 In short, the distinctions are:
5655
5656 @itemize @bullet
5657 @item
5658 @emph{Specific} intrinsics have
5659 specific types for their arguments and a specific return
5660 type.
5661
5662 @item
5663 @emph{Generic} intrinsics are treated,
5664 on a case-by-case basis in the program's source code,
5665 as one of several possible specific intrinsics.
5666
5667 Typically, a generic intrinsic has a return type that
5668 is determined by the type of one or more of its arguments.
5669 @end itemize
5670
5671 The GNU Fortran language generalizes these concepts somewhat,
5672 especially by providing intrinsic subroutines and generic
5673 intrinsics that are treated as either a specific intrinsic subroutine
5674 or a specific intrinsic function (e.g. @code{SECOND}).
5675
5676 However, GNU Fortran avoids generalizing this concept to
5677 the point where existing code would be accepted as meaning
5678 something possibly different than what was intended.
5679
5680 For example, @code{ABS} is a generic intrinsic, so all working
5681 code written using @code{ABS} of an @code{INTEGER} argument
5682 expects an @code{INTEGER} return value.
5683 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
5684 argument returns an @code{INTEGER*2} return value.
5685
5686 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
5687 an @code{INTEGER(KIND=1)} argument.
5688 Code that passes something other than an @code{INTEGER(KIND=1)}
5689 argument to @code{IABS} is not valid GNU Fortran code, because
5690 it is not clear what the author intended.
5691
5692 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
5693 is not defined by the GNU Fortran language, because the programmer
5694 might have used that construct to mean any of the following, subtly
5695 different, things:
5696
5697 @itemize @bullet
5698 @item
5699 Convert @samp{J} to @code{INTEGER(KIND=1)} first
5700 (as if @samp{IABS(INT(J))} had been written).
5701
5702 @item
5703 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
5704 (as if @samp{INT(ABS(J))} had been written).
5705
5706 @item
5707 No conversion (as if @samp{ABS(J)} had been written).
5708 @end itemize
5709
5710 The distinctions matter especially when types and values wider than
5711 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
5712 operations performing more ``arithmetic'' than absolute-value, are involved.
5713
5714 The following sample program is not a valid GNU Fortran program, but
5715 might be accepted by other compilers.
5716 If so, the output is likely to be revealing in terms of how a given
5717 compiler treats intrinsics (that normally are specific) when they
5718 are given arguments that do not conform to their stated requirements:
5719
5720 @cindex JCB002 program
5721 @smallexample
5722 PROGRAM JCB002
5723 C Version 1:
5724 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
5725 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
5726 C
5727 C Version 0:
5728 C Written by James Craig Burley 1997-02-20.
5729 C Contact via Internet email: burley@@gnu.ai.mit.edu
5730 C
5731 C Purpose:
5732 C Determine how compilers handle non-standard IDIM
5733 C on INTEGER*2 operands, which presumably can be
5734 C extrapolated into understanding how the compiler
5735 C generally treats specific intrinsics that are passed
5736 C arguments not of the correct types.
5737 C
5738 C If your compiler implements INTEGER*2 and INTEGER
5739 C as the same type, change all INTEGER*2 below to
5740 C INTEGER*1.
5741 C
5742 INTEGER*2 I0, I4
5743 INTEGER I1, I2, I3
5744 INTEGER*2 ISMALL, ILARGE
5745 INTEGER*2 ITOOLG, ITWO
5746 INTEGER*2 ITMP
5747 LOGICAL L2, L3, L4
5748 C
5749 C Find smallest INTEGER*2 number.
5750 C
5751 ISMALL=0
5752 10 I0 = ISMALL-1
5753 IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
5754 ISMALL = I0
5755 GOTO 10
5756 20 CONTINUE
5757 C
5758 C Find largest INTEGER*2 number.
5759 C
5760 ILARGE=0
5761 30 I0 = ILARGE+1
5762 IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
5763 ILARGE = I0
5764 GOTO 30
5765 40 CONTINUE
5766 C
5767 C Multiplying by two adds stress to the situation.
5768 C
5769 ITWO = 2
5770 C
5771 C Need a number that, added to -2, is too wide to fit in I*2.
5772 C
5773 ITOOLG = ISMALL
5774 C
5775 C Use IDIM the straightforward way.
5776 C
5777 I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
5778 C
5779 C Calculate result for first interpretation.
5780 C
5781 I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
5782 C
5783 C Calculate result for second interpretation.
5784 C
5785 ITMP = ILARGE - ISMALL
5786 I3 = (INT (ITMP)) * ITWO + ITOOLG
5787 C
5788 C Calculate result for third interpretation.
5789 C
5790 I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
5791 C
5792 C Print results.
5793 C
5794 PRINT *, 'ILARGE=', ILARGE
5795 PRINT *, 'ITWO=', ITWO
5796 PRINT *, 'ITOOLG=', ITOOLG
5797 PRINT *, 'ISMALL=', ISMALL
5798 PRINT *, 'I1=', I1
5799 PRINT *, 'I2=', I2
5800 PRINT *, 'I3=', I3
5801 PRINT *, 'I4=', I4
5802 PRINT *
5803 L2 = (I1 .EQ. I2)
5804 L3 = (I1 .EQ. I3)
5805 L4 = (I1 .EQ. I4)
5806 IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
5807 PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
5808 STOP
5809 END IF
5810 IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
5811 PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
5812 STOP
5813 END IF
5814 IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
5815 PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
5816 STOP
5817 END IF
5818 PRINT *, 'Results need careful analysis.'
5819 END
5820 @end smallexample
5821
5822 No future version of the GNU Fortran language
5823 will likely permit specific intrinsic invocations with wrong-typed
5824 arguments (such as @code{IDIM} in the above example), since
5825 it has been determined that disagreements exist among
5826 many production compilers on the interpretation of
5827 such invocations.
5828 These disagreements strongly suggest that Fortran programmers,
5829 and certainly existing Fortran programs, disagree about the
5830 meaning of such invocations.
5831
5832 The first version of @samp{JCB002} didn't accommodate some compilers'
5833 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
5834 @code{INTEGER*2}.
5835 In such a case, these compilers apparently convert both
5836 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
5837 instead of doing an @code{INTEGER*2} subtraction on the
5838 original values in @samp{I1} and @samp{I2}.
5839
5840 However, the results of the careful analyses done on the outputs
5841 of programs compiled by these various compilers show that they
5842 all implement either @samp{Interp 1} or @samp{Interp 2} above.
5843
5844 Specifically, it is believed that the new version of @samp{JCB002}
5845 above will confirm that:
5846
5847 @itemize @bullet
5848 @item
5849 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
5850 @code{f77} compilers all implement @samp{Interp 1}.
5851
5852 @item
5853 IRIX 5.3 @code{f77} compiler implements @samp{Interp 2}.
5854
5855 @item
5856 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
5857 and IRIX 6.1 @code{f77} compilers all implement @samp{Interp 3}.
5858 @end itemize
5859
5860 If you get different results than the above for the stated
5861 compilers, or have results for other compilers that might be
5862 worth adding to the above list, please let us know the details
5863 (compiler product, version, machine, results, and so on).
5864
5865 @node REAL() and AIMAG() of Complex
5866 @subsection @code{REAL()} and @code{AIMAG()} of Complex
5867 @cindex REAL intrinsic
5868 @cindex intrinsics, REAL
5869 @cindex AIMAG intrinsic
5870 @cindex intrinsics, AIMAG
5871
5872 The GNU Fortran language disallows @code{REAL(@var{expr})}
5873 and @code{AIMAG(@var{expr})},
5874 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
5875 except when they are used in the following way:
5876
5877 @example
5878 REAL(REAL(@var{expr}))
5879 REAL(AIMAG(@var{expr}))
5880 @end example
5881
5882 @noindent
5883 The above forms explicitly specify that the desired effect
5884 is to convert the real or imaginary part of @var{expr}, which might
5885 be some @code{REAL} type other than @code{REAL(KIND=1)},
5886 to type @code{REAL(KIND=1)},
5887 and have that serve as the value of the expression.
5888
5889 The GNU Fortran language offers clearly named intrinsics to extract the
5890 real and imaginary parts of a complex entity without any
5891 conversion:
5892
5893 @example
5894 REALPART(@var{expr})
5895 IMAGPART(@var{expr})
5896 @end example
5897
5898 To express the above using typical extended FORTRAN 77,
5899 use the following constructs
5900 (when @var{expr} is @code{COMPLEX(KIND=2)}):
5901
5902 @example
5903 DBLE(@var{expr})
5904 DIMAG(@var{expr})
5905 @end example
5906
5907 The FORTRAN 77 language offers no way
5908 to explicitly specify the real and imaginary parts of a complex expression of
5909 arbitrary type, apparently as a result of requiring support for
5910 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
5911 The concepts of converting an expression to type @code{REAL(KIND=1)} and
5912 of extracting the real part of a complex expression were
5913 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
5914 they happened to have the exact same effect in that language
5915 (due to having only one @code{COMPLEX} type).
5916
5917 @emph{Note:} When @samp{-ff90} is in effect,
5918 @code{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
5919 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
5920 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
5921 treated as @samp{REAL(REALPART(@var{expr}))}.
5922
5923 @xref{Ugly Complex Part Extraction}, for more information.
5924
5925 @node CMPLX() of DOUBLE PRECISION
5926 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
5927 @cindex CMPLX intrinsic
5928 @cindex intrinsics, CMPLX
5929
5930 In accordance with Fortran 90 and at least some (perhaps all)
5931 other compilers, the GNU Fortran language defines @code{CMPLX()}
5932 as always returning a result that is type @code{COMPLEX(KIND=1)}.
5933
5934 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
5935 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
5936
5937 @example
5938 CMPLX(SNGL(D1), SNGL(D2))
5939 @end example
5940
5941 (It was necessary for Fortran 90 to specify this behavior
5942 for @code{DOUBLE PRECISION} arguments, since that is
5943 the behavior mandated by FORTRAN 77.)
5944
5945 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
5946 which is provided by some FORTRAN 77 compilers to construct
5947 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
5948 operands.
5949 However, this solution does not scale well when more @code{COMPLEX} types
5950 (having various precisions and ranges) are offered by Fortran implementations.
5951
5952 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
5953 an extra argument used to specify the desired kind of complex
5954 result.
5955 However, this solution is somewhat awkward to use, and
5956 @code{g77} currently does not support it.
5957
5958 The GNU Fortran language provides a simple way to build a complex
5959 value out of two numbers, with the precise type of the value
5960 determined by the types of the two numbers (via the usual
5961 type-promotion mechanism):
5962
5963 @example
5964 COMPLEX(@var{real}, @var{imag})
5965 @end example
5966
5967 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
5968 performs no conversion other than to put them together to form a
5969 complex result of the same (complex version of real) type.
5970
5971 @xref{Complex Intrinsic}, for more information.
5972
5973 @node MIL-STD 1753
5974 @subsection MIL-STD 1753 Support
5975 @cindex MIL-STD 1753
5976
5977 The GNU Fortran language includes the MIL-STD 1753 intrinsics
5978 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
5979 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
5980 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
5981
5982 @node f77/f2c Intrinsics
5983 @subsection @code{f77}/@code{f2c} Intrinsics
5984
5985 The bit-manipulation intrinsics supported by traditional
5986 @code{f77} and by @code{f2c} are available in the GNU Fortran language.
5987 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
5988 and @code{XOR}.
5989
5990 Also supported are the intrinsics @code{CDABS},
5991 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
5992 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
5993 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
5994 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
5995 and @code{ZSQRT}.
5996
5997 @node Table of Intrinsic Functions
5998 @subsection Table of Intrinsic Functions
5999 @cindex intrinsics, table of
6000 @cindex table of intrinsics
6001
6002 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
6003
6004 The GNU Fortran language adds various functions, subroutines, types,
6005 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
6006 The complete set of intrinsics supported by the GNU Fortran language
6007 is described below.
6008
6009 Note that a name is not treated as that of an intrinsic if it is
6010 specified in an @code{EXTERNAL} statement in the same program unit;
6011 if a command-line option is used to disable the groups to which
6012 the intrinsic belongs; or if the intrinsic is not named in an
6013 @code{INTRINSIC} statement and a command-line option is used to
6014 hide the groups to which the intrinsic belongs.
6015
6016 So, it is recommended that any reference in a program unit to
6017 an intrinsic procedure that is not a standard FORTRAN 77
6018 intrinsic be accompanied by an appropriate @code{INTRINSIC}
6019 statement in that program unit.
6020 This sort of defensive programming makes it more
6021 likely that an implementation will issue a diagnostic rather
6022 than generate incorrect code for such a reference.
6023
6024 The terminology used below is based on that of the Fortran 90
6025 standard, so that the text may be more concise and accurate:
6026
6027 @itemize @bullet
6028 @item
6029 @code{OPTIONAL} means the argument may be omitted.
6030
6031 @item
6032 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
6033 (generally named @samp{A}) may be specified.
6034
6035 @item
6036 @samp{scalar} means the argument must not be an array (must
6037 be a variable or array element, or perhaps a constant if expressions
6038 are permitted).
6039
6040 @item
6041 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
6042
6043 @item
6044 @code{INTENT(IN)} means the argument must be an expression
6045 (such as a constant or a variable that is defined upon invocation
6046 of the intrinsic).
6047
6048 @item
6049 @code{INTENT(OUT)} means the argument must be definable by the
6050 invocation of the intrinsic (that is, must not be a constant nor
6051 an expression involving operators other than array reference and
6052 substring reference).
6053
6054 @item
6055 @code{INTENT(INOUT)} means the argument must be defined prior to,
6056 and definable by, invocation of the intrinsic (a combination of
6057 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
6058
6059 @item
6060 @xref{Kind Notation} for explanation of @code{KIND}.
6061 @end itemize
6062
6063 @ifinfo
6064 (Note that the empty lines appearing in the menu below
6065 are not intentional---they result from a bug in the
6066 GNU @code{makeinfo} program@dots{}a program that, if it
6067 did not exist, would leave this document in far worse shape!)
6068 @end ifinfo
6069
6070 @c The actual documentation for intrinsics comes from
6071 @c intdoc.texi, which in turn is automatically generated
6072 @c from the internal g77 tables in intrin.def _and_ the
6073 @c largely hand-written text in intdoc.h. So, if you want
6074 @c to change or add to existing documentation on intrinsics,
6075 @c you probably want to edit intdoc.h.
6076 @c
6077 @set familyF77
6078 @set familyGNU
6079 @set familyASC
6080 @set familyMIL
6081 @set familyF90
6082 @clear familyVXT
6083 @clear familyFVZ
6084 @set familyF2C
6085 @set familyF2U
6086 @clear familyBADU77
6087 @include intdoc.texi
6088
6089 @node Scope and Classes of Names
6090 @section Scope and Classes of Symbolic Names
6091 @cindex symbolic names
6092 @cindex scope
6093
6094 (The following information augments or overrides the information in
6095 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
6096 language.
6097 Chapter 18 of that document otherwise serves as the basis
6098 for the relevant aspects of GNU Fortran.)
6099
6100 @menu
6101 * Underscores in Symbol Names::
6102 @end menu
6103
6104 @node Underscores in Symbol Names
6105 @subsection Underscores in Symbol Names
6106 @cindex underscores
6107
6108 Underscores (@samp{_}) are accepted in symbol names after the first
6109 character (which must be a letter).
6110
6111 @node Other Dialects
6112 @chapter Other Dialects
6113
6114 GNU Fortran supports a variety of features that are not
6115 considered part of the GNU Fortran language itself, but
6116 are representative of various dialects of Fortran that
6117 @code{g77} supports in whole or in part.
6118
6119 Any of the features listed below might be disallowed by
6120 @code{g77} unless some command-line option is specified.
6121 Currently, some of the features are accepted using the
6122 default invocation of @code{g77}, but that might change
6123 in the future.
6124
6125 @emph{Note: This portion of the documentation definitely needs a lot
6126 of work!}
6127
6128 @menu
6129 * Source Form:: Details of fixed-form and free-form source.
6130 * Trailing Comment:: Use of @samp{/*} to start a comment.
6131 * Debug Line:: Use of @samp{D} in column 1.
6132 * Dollar Signs:: Use of @samp{$} in symbolic names.
6133 * Case Sensitivity:: Uppercase and lowercase in source files.
6134 * VXT Fortran:: @dots{}versus the GNU Fortran language.
6135 * Fortran 90:: @dots{}versus the GNU Fortran language.
6136 * Pedantic Compilation:: Enforcing the standard.
6137 * Distensions:: Misfeatures supported by GNU Fortran.
6138 @end menu
6139
6140 @node Source Form
6141 @section Source Form
6142 @cindex source file format
6143 @cindex source form
6144 @cindex files, source
6145 @cindex source code
6146 @cindex code, source
6147 @cindex fixed form
6148 @cindex free form
6149
6150 GNU Fortran accepts programs written in either fixed form or
6151 free form.
6152
6153 Fixed form
6154 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
6155 allowing tabs) and Fortran 90's fixed form.
6156
6157 Free form corresponds to
6158 Fortran 90's free form (though possibly not entirely up-to-date, and
6159 without complaining about some things that for which Fortran 90 requires
6160 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
6161
6162 The way a Fortran compiler views source files depends entirely on the
6163 implementation choices made for the compiler, since those choices
6164 are explicitly left to the implementation by the published Fortran
6165 standards.
6166 GNU Fortran currently tries to be somewhat like a few popular compilers
6167 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
6168 definition along with more
6169 flexibility offered by command-line options is likely to be offered
6170 in version 0.6.
6171
6172 This section describes how @code{g77} interprets source lines.
6173
6174 @menu
6175 * Carriage Returns:: Carriage returns ignored.
6176 * Tabs:: Tabs converted to spaces.
6177 * Short Lines:: Short lines padded with spaces (fixed-form only).
6178 * Long Lines:: Long lines truncated.
6179 * Ampersands:: Special Continuation Lines.
6180 @end menu
6181
6182 @node Carriage Returns
6183 @subsection Carriage Returns
6184 @cindex carriage returns
6185
6186 Carriage returns (@samp{\r}) in source lines are ignored.
6187 This is somewhat different from @code{f2c}, which seems to treat them as
6188 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
6189 inside such constants.
6190
6191 @node Tabs
6192 @subsection Tabs
6193 @cindex tab characters
6194
6195 A source line with a @key{TAB} character anywhere in it is treated as
6196 entirely significant---however long it is---instead of ending in
6197 column 72 (for fixed-form source) or 132 (for free-form source).
6198 This also is different from @code{f2c}, which encodes tabs as
6199 @samp{\t} (the ASCII @key{TAB} character) inside character
6200 and Hollerith constants, but nevertheless seems to treat the column
6201 position as if it had been affected by the canonical tab positioning.
6202
6203 @code{g77} effectively
6204 translates tabs to the appropriate number of spaces (a la the default
6205 for the UNIX @code{expand} command) before doing any other processing, other
6206 than (currently) noting whether a tab was found on a line and using this
6207 information to decide how to interpret the length of the line and continued
6208 constants.
6209
6210 Note that this default behavior probably will change for version 0.6,
6211 when it will presumably be available via a command-line option.
6212 The default as of version 0.6 is planned to be a ``pure visual''
6213 model, where tabs are immediately
6214 converted to spaces and otherwise have no effect, so the way a typical
6215 user sees source lines produces a consistent result no matter how the
6216 spacing in those source lines is actually implemented via tabs, spaces,
6217 and trailing tabs/spaces before newline.
6218 Command-line options are likely to be added to specify whether all or
6219 just-tabbed lines are to be extended to 132 or full input-line length,
6220 and perhaps even an option will be added to specify the truncated-line
6221 behavior to which some Digital compilers default (and which affects
6222 the way continued character/Hollerith constants are interpreted).
6223
6224 @node Short Lines
6225 @subsection Short Lines
6226 @cindex short source lines
6227 @cindex space-padding
6228 @cindex spaces
6229 @cindex source lines, short
6230 @cindex lines, short
6231
6232 Source lines shorter than the applicable fixed-form length are treated as
6233 if they were padded with spaces to that length.
6234 (None of this is relevant to source files written in free form.)
6235
6236 This affects only
6237 continued character and Hollerith constants, and is a different
6238 interpretation than provided by some other popular compilers
6239 (although a bit more consistent with the traditional punched-card
6240 basis of Fortran and the way the Fortran standard expressed fixed
6241 source form).
6242
6243 @code{g77} might someday offer an option to warn about cases where differences
6244 might be seen as a result of this treatment, and perhaps an option to
6245 specify the alternate behavior as well.
6246
6247 Note that this padding cannot apply to lines that are effectively of
6248 infinite length---such lines are specified using command-line options
6249 like @samp{-ffixed-line-length-none}, for example.
6250
6251 @node Long Lines
6252 @subsection Long Lines
6253 @cindex long source lines
6254 @cindex truncation
6255 @cindex lines, long
6256 @cindex source lines, long
6257
6258 Source lines longer than the applicable length are truncated to that
6259 length.
6260 Currently, @code{g77} does not warn if the truncated characters are
6261 not spaces, to accommodate existing code written for systems that
6262 treated truncated text as commentary (especially in columns 73 through 80).
6263
6264 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
6265 for information on the @samp{-ffixed-line-length-@var{n}} option,
6266 which can be used to set the line length applicable to fixed-form
6267 source files.
6268
6269 @node Ampersands
6270 @subsection Ampersand Continuation Line
6271 @cindex ampersand continuation line
6272 @cindex continuation line, ampersand
6273
6274 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
6275 continuation line, imitating the behavior of @code{f2c}.
6276
6277 @node Trailing Comment
6278 @section Trailing Comment
6279
6280 @code{g77} supports use of @samp{/*} to start a trailing
6281 comment.
6282 In the GNU Fortran language, @samp{!} is used for this purpose.
6283
6284 @samp{/*} is not in the GNU Fortran language
6285 because the use of @samp{/*} in a program might
6286 suggest to some readers that a block, not trailing, comment is
6287 started (and thus ended by @samp{*/}, not end of line),
6288 since that is the meaning of @samp{/*} in C.
6289
6290 Also, such readers might think they can use @samp{//} to start
6291 a trailing comment as an alternative to @samp{/*}, but
6292 @samp{//} already denotes concatenation, and such a ``comment''
6293 might actually result in a program that compiles without
6294 error (though it would likely behave incorrectly).
6295
6296 @node Debug Line
6297 @section Debug Line
6298 @cindex debug line
6299
6300 Use of @samp{D} or @samp{d} as the first character (column 1) of
6301 a source line denotes a debug line.
6302
6303 In turn, a debug line is treated as either a comment line
6304 or a normal line, depending on whether debug lines are enabled.
6305
6306 When treated as a comment line, a line beginning with @samp{D} or
6307 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
6308 When treated as a normal line, such a line is treated as if
6309 the first character was @key{SPC} (space).
6310
6311 (Currently, @code{g77} provides no means for treating debug
6312 lines as normal lines.)
6313
6314 @node Dollar Signs
6315 @section Dollar Signs in Symbol Names
6316 @cindex dollar sign
6317 @cindex $
6318
6319 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
6320 when the @samp{-fdollar-ok} option is specified.
6321
6322 @node Case Sensitivity
6323 @section Case Sensitivity
6324 @cindex case sensitivity
6325 @cindex source file format
6326 @cindex code, source
6327 @cindex source code
6328 @cindex uppercase letters
6329 @cindex lowercase letters
6330 @cindex letters, uppercase
6331 @cindex letters, lowercase
6332
6333 GNU Fortran offers the programmer way too much flexibility in deciding
6334 how source files are to be treated vis-a-vis uppercase and lowercase
6335 characters.
6336 There are 66 useful settings that affect case sensitivity, plus 10
6337 settings that are nearly useless, with the remaining 116 settings
6338 being either redundant or useless.
6339
6340 None of these settings have any effect on the contents of comments
6341 (the text after a @samp{c} or @samp{C} in Column 1, for example)
6342 or of character or Hollerith constants.
6343 Note that things like the @samp{E} in the statement
6344 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
6345 are considered built-in keywords, and so are affected by
6346 these settings.
6347
6348 Low-level switches are identified in this section as follows:
6349
6350 @itemize @w{}
6351 @item A
6352 Source Case Conversion:
6353
6354 @itemize @w{}
6355 @item 0
6356 Preserve (see Note 1)
6357 @item 1
6358 Convert to Upper Case
6359 @item 2
6360 Convert to Lower Case
6361 @end itemize
6362
6363 @item B
6364 Built-in Keyword Matching:
6365
6366 @itemize @w{}
6367 @item 0
6368 Match Any Case (per-character basis)
6369 @item 1
6370 Match Upper Case Only
6371 @item 2
6372 Match Lower Case Only
6373 @item 3
6374 Match InitialCaps Only (see tables for spellings)
6375 @end itemize
6376
6377 @item C
6378 Built-in Intrinsic Matching:
6379
6380 @itemize @w{}
6381 @item 0
6382 Match Any Case (per-character basis)
6383 @item 1
6384 Match Upper Case Only
6385 @item 2
6386 Match Lower Case Only
6387 @item 3
6388 Match InitialCaps Only (see tables for spellings)
6389 @end itemize
6390
6391 @item D
6392 User-defined Symbol Possibilities (warnings only):
6393
6394 @itemize @w{}
6395 @item 0
6396 Allow Any Case (per-character basis)
6397 @item 1
6398 Allow Upper Case Only
6399 @item 2
6400 Allow Lower Case Only
6401 @item 3
6402 Allow InitialCaps Only (see Note 2)
6403 @end itemize
6404 @end itemize
6405
6406 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
6407 consistent with these source switches---in the sense that input will be
6408 expected to meet the same requirements as source code in terms
6409 of matching symbol names and keywords (for the exponent letters).
6410
6411 Currently, however, @code{NAMELIST} is supported by @code{libf2c},
6412 which uppercases @code{NAMELIST} input and symbol names for matching.
6413 This means not only that @code{NAMELIST} output currently shows symbol
6414 (and keyword) names in uppercase even if lower-case source
6415 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
6416 adequately supported when source case preservation (option A0)
6417 is selected.
6418
6419 If A0 is selected, a warning message will be
6420 output for each @code{NAMELIST} statement to this effect.
6421 The behavior
6422 of the program is undefined at run time if two or more symbol names
6423 appear in a given @code{NAMELIST} such that the names are identical
6424 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
6425 For complete and total elegance, perhaps there should be a warning
6426 when option A2 is selected, since the output of NAMELIST is currently
6427 in uppercase but will someday be lowercase (when a @code{libg77} is written),
6428 but that seems to be overkill for a product in beta test.
6429
6430 Note 2: Rules for InitialCaps names are:
6431
6432 @itemize --
6433 @item
6434 Must be a single uppercase letter, @strong{or}
6435 @item
6436 Must start with an uppercase letter and contain at least one
6437 lowercase letter.
6438 @end itemize
6439
6440 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
6441 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
6442 not.
6443 Note that most, but not all, built-in names meet these
6444 requirements---the exceptions are some of the two-letter format
6445 specifiers, such as @samp{BN} and @samp{BZ}.
6446
6447 Here are the names of the corresponding command-line options:
6448
6449 @smallexample
6450 A0: -fsource-case-preserve
6451 A1: -fsource-case-upper
6452 A2: -fsource-case-lower
6453
6454 B0: -fmatch-case-any
6455 B1: -fmatch-case-upper
6456 B2: -fmatch-case-lower
6457 B3: -fmatch-case-initcap
6458
6459 C0: -fintrin-case-any
6460 C1: -fintrin-case-upper
6461 C2: -fintrin-case-lower
6462 C3: -fintrin-case-initcap
6463
6464 D0: -fsymbol-case-any
6465 D1: -fsymbol-case-upper
6466 D2: -fsymbol-case-lower
6467 D3: -fsymbol-case-initcap
6468 @end smallexample
6469
6470 Useful combinations of the above settings, along with abbreviated
6471 option names that set some of these combinations all at once:
6472
6473 @smallexample
6474 1: A0-- B0--- C0--- D0--- -fcase-preserve
6475 2: A0-- B0--- C0--- D-1--
6476 3: A0-- B0--- C0--- D--2-
6477 4: A0-- B0--- C0--- D---3
6478 5: A0-- B0--- C-1-- D0---
6479 6: A0-- B0--- C-1-- D-1--
6480 7: A0-- B0--- C-1-- D--2-
6481 8: A0-- B0--- C-1-- D---3
6482 9: A0-- B0--- C--2- D0---
6483 10: A0-- B0--- C--2- D-1--
6484 11: A0-- B0--- C--2- D--2-
6485 12: A0-- B0--- C--2- D---3
6486 13: A0-- B0--- C---3 D0---
6487 14: A0-- B0--- C---3 D-1--
6488 15: A0-- B0--- C---3 D--2-
6489 16: A0-- B0--- C---3 D---3
6490 17: A0-- B-1-- C0--- D0---
6491 18: A0-- B-1-- C0--- D-1--
6492 19: A0-- B-1-- C0--- D--2-
6493 20: A0-- B-1-- C0--- D---3
6494 21: A0-- B-1-- C-1-- D0---
6495 22: A0-- B-1-- C-1-- D-1-- -fcase-strict-upper
6496 23: A0-- B-1-- C-1-- D--2-
6497 24: A0-- B-1-- C-1-- D---3
6498 25: A0-- B-1-- C--2- D0---
6499 26: A0-- B-1-- C--2- D-1--
6500 27: A0-- B-1-- C--2- D--2-
6501 28: A0-- B-1-- C--2- D---3
6502 29: A0-- B-1-- C---3 D0---
6503 30: A0-- B-1-- C---3 D-1--
6504 31: A0-- B-1-- C---3 D--2-
6505 32: A0-- B-1-- C---3 D---3
6506 33: A0-- B--2- C0--- D0---
6507 34: A0-- B--2- C0--- D-1--
6508 35: A0-- B--2- C0--- D--2-
6509 36: A0-- B--2- C0--- D---3
6510 37: A0-- B--2- C-1-- D0---
6511 38: A0-- B--2- C-1-- D-1--
6512 39: A0-- B--2- C-1-- D--2-
6513 40: A0-- B--2- C-1-- D---3
6514 41: A0-- B--2- C--2- D0---
6515 42: A0-- B--2- C--2- D-1--
6516 43: A0-- B--2- C--2- D--2- -fcase-strict-lower
6517 44: A0-- B--2- C--2- D---3
6518 45: A0-- B--2- C---3 D0---
6519 46: A0-- B--2- C---3 D-1--
6520 47: A0-- B--2- C---3 D--2-
6521 48: A0-- B--2- C---3 D---3
6522 49: A0-- B---3 C0--- D0---
6523 50: A0-- B---3 C0--- D-1--
6524 51: A0-- B---3 C0--- D--2-
6525 52: A0-- B---3 C0--- D---3
6526 53: A0-- B---3 C-1-- D0---
6527 54: A0-- B---3 C-1-- D-1--
6528 55: A0-- B---3 C-1-- D--2-
6529 56: A0-- B---3 C-1-- D---3
6530 57: A0-- B---3 C--2- D0---
6531 58: A0-- B---3 C--2- D-1--
6532 59: A0-- B---3 C--2- D--2-
6533 60: A0-- B---3 C--2- D---3
6534 61: A0-- B---3 C---3 D0---
6535 62: A0-- B---3 C---3 D-1--
6536 63: A0-- B---3 C---3 D--2-
6537 64: A0-- B---3 C---3 D---3 -fcase-initcap
6538 65: A-1- B01-- C01-- D01-- -fcase-upper
6539 66: A--2 B0-2- C0-2- D0-2- -fcase-lower
6540 @end smallexample
6541
6542 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
6543 (except comments, character constants, and Hollerith strings) must
6544 be entered in uppercase.
6545 Use @samp{-fcase-strict-upper} to specify this
6546 combination.
6547
6548 Number 43 is like Number 22 except all input must be lowercase. Use
6549 @samp{-fcase-strict-lower} to specify this combination.
6550
6551 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
6552 non-UNIX machines whereby all the source is translated to uppercase.
6553 Use @samp{-fcase-upper} to specify this combination.
6554
6555 Number 66 is the ``canonical'' UNIX model whereby all the source is
6556 translated to lowercase.
6557 Use @samp{-fcase-lower} to specify this combination.
6558
6559 There are a few nearly useless combinations:
6560
6561 @smallexample
6562 67: A-1- B01-- C01-- D--2-
6563 68: A-1- B01-- C01-- D---3
6564 69: A-1- B01-- C--23 D01--
6565 70: A-1- B01-- C--23 D--2-
6566 71: A-1- B01-- C--23 D---3
6567 72: A--2 B01-- C0-2- D-1--
6568 73: A--2 B01-- C0-2- D---3
6569 74: A--2 B01-- C-1-3 D0-2-
6570 75: A--2 B01-- C-1-3 D-1--
6571 76: A--2 B01-- C-1-3 D---3
6572 @end smallexample
6573
6574 The above allow some programs to be compiled but with restrictions that
6575 make most useful programs impossible: Numbers 67 and 72 warn about
6576 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
6577 Numbers
6578 68 and 73 warn about any user-defined symbol names longer than one
6579 character that don't have at least one non-alphabetic character after
6580 the first;
6581 Numbers 69 and 74 disallow any references to intrinsics;
6582 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
6583 67+69, 68+69, 72+74, and 73+74, respectively.
6584
6585 All redundant combinations are shown in the above tables anyplace
6586 where more than one setting is shown for a low-level switch.
6587 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
6588 The ``proper'' setting in such a case is the one that copies the setting
6589 of switch A---any other setting might slightly reduce the speed of
6590 the compiler, though possibly to an unmeasurable extent.
6591
6592 All remaining combinations are useless in that they prevent successful
6593 compilation of non-null source files (source files with something other
6594 than comments).
6595
6596 @node VXT Fortran
6597 @section VXT Fortran
6598
6599 @cindex VXT extensions
6600 @cindex extensions, VXT
6601 @code{g77} supports certain constructs that
6602 have different meanings in VXT Fortran than they
6603 do in the GNU Fortran language.
6604
6605 Generally, this manual uses the invented term VXT Fortran to refer
6606 VAX FORTRAN (circa v4).
6607 That compiler offered many popular features, though not necessarily
6608 those that are specific to the VAX processor architecture,
6609 the VMS operating system,
6610 or Digital Equipment Corporation's Fortran product line.
6611 (VAX and VMS probably are trademarks of Digital Equipment
6612 Corporation.)
6613
6614 An extension offered by a Digital Fortran product that also is
6615 offered by several other Fortran products for different kinds of
6616 systems is probably going to be considered for inclusion in @code{g77}
6617 someday, and is considered a VXT Fortran feature.
6618
6619 The @samp{-fvxt} option generally specifies that, where
6620 the meaning of a construct is ambiguous (means one thing
6621 in GNU Fortran and another in VXT Fortran), the VXT Fortran
6622 meaning is to be assumed.
6623
6624 @menu
6625 * Double Quote Meaning:: @samp{"2000} as octal constant.
6626 * Exclamation Point:: @samp{!} in column 6.
6627 @end menu
6628
6629 @node Double Quote Meaning
6630 @subsection Meaning of Double Quote
6631 @cindex double quotes
6632 @cindex character constants
6633 @cindex constants, character
6634 @cindex octal constants
6635 @cindex constants, octal
6636
6637 @code{g77} treats double-quote (@samp{"})
6638 as beginning an octal constant of @code{INTEGER(KIND=1)} type
6639 when the @code{-fvxt} option is specified.
6640 The form of this octal constant is
6641
6642 @example
6643 "@var{octal-digits}
6644 @end example
6645
6646 @noindent
6647 where @var{octal-digits} is a nonempty string of characters in
6648 the set @samp{01234567}.
6649
6650 For example, the @code{-fvxt} option permits this:
6651
6652 @example
6653 PRINT *, "20
6654 END
6655 @end example
6656
6657 @noindent
6658 The above program would print the value @samp{16}.
6659
6660 @xref{Integer Type}, for information on the preferred construct
6661 for integer constants specified using GNU Fortran's octal notation.
6662
6663 (In the GNU Fortran language, the double-quote character (@samp{"})
6664 delimits a character constant just as does apostrophe (@samp{'}).
6665 There is no way to allow
6666 both constructs in the general case, since statements like
6667 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
6668
6669 @node Exclamation Point
6670 @subsection Meaning of Exclamation Point in Column 6
6671 @cindex exclamation points
6672 @cindex continuation character
6673 @cindex characters, continuation
6674 @cindex comment character
6675 @cindex characters, comment
6676
6677 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
6678 a fixed-form source file
6679 as a continuation character rather than
6680 as the beginning of a comment
6681 (as it does in any other column)
6682 when the @code{-fvxt} option is specified.
6683
6684 The following program, when run, prints a message indicating
6685 whether it is interpreted according to GNU Fortran (and Fortran 90)
6686 rules or VXT Fortran rules:
6687
6688 @smallexample
6689 C234567 (This line begins in column 1.)
6690 I = 0
6691 !1
6692 IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
6693 IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
6694 IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
6695 END
6696 @end smallexample
6697
6698 (In the GNU Fortran and Fortran 90 languages, exclamation point is
6699 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
6700 marks a line as a continuation line when it appears in column 6.)
6701
6702 @node Fortran 90
6703 @section Fortran 90
6704 @cindex compatibility, Fortran 90
6705 @cindex Fortran 90 compatibility
6706
6707 The GNU Fortran language includes a number of features that are
6708 part of Fortran 90, even when the @samp{-ff90} option is not specified.
6709 The features enabled by @samp{-ff90} are intended to be those that,
6710 when @samp{-ff90} is not specified, would have another
6711 meaning to @code{g77}---usually meaning something invalid in the
6712 GNU Fortran language.
6713
6714 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
6715 to gratuitously reject Fortran 90 constructs.
6716 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
6717 to do that, although its implementation is certainly incomplete at
6718 this point.
6719
6720 When @samp{-ff90} is specified:
6721
6722 @itemize @bullet
6723 @item
6724 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
6725 where @var{expr} is @code{COMPLEX} type,
6726 is the same type as the real part of @var{expr}.
6727
6728 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
6729 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
6730 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
6731 @end itemize
6732
6733 @node Pedantic Compilation
6734 @section Pedantic Compilation
6735 @cindex pedantic compilation
6736 @cindex compilation, pedantic
6737
6738 The @samp{-fpedantic} command-line option specifies that @code{g77}
6739 is to warn about code that is not standard-conforming.
6740 This is useful for finding
6741 some extensions @code{g77} accepts that other compilers might not accept.
6742 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
6743 always imply @samp{-fpedantic}.)
6744
6745 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
6746 for conforming code.
6747 With @samp{-ff90} in force, Fortran 90 is used.
6748
6749 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
6750 and @samp{-fno-f90} are in force are:
6751
6752 @itemize @bullet
6753 @item
6754 Automatic arrays, as in
6755
6756 @example
6757 SUBROUTINE X(N)
6758 REAL A(N)
6759 @dots{}
6760 @end example
6761
6762 @noindent
6763 where @samp{A} is not listed in any @code{ENTRY} statement,
6764 and thus is not a dummy argument.
6765
6766 @item
6767 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
6768
6769 These commas are disallowed by FORTRAN 77, but, while strictly
6770 superfluous, are syntactically elegant,
6771 especially given that commas are required in statements such
6772 as @samp{READ 99, I} and @samp{PRINT *, J}.
6773 Many compilers permit the superfluous commas for this reason.
6774
6775 @item
6776 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
6777
6778 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
6779 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
6780
6781 An example of an implicit use is the expression @samp{C*D},
6782 where @samp{C} is @code{COMPLEX(KIND=1)}
6783 and @samp{D} is @code{DOUBLE PRECISION}.
6784 This expression is prohibited by ANSI FORTRAN 77
6785 because the rules of promotion would suggest that it
6786 produce a @code{DOUBLE COMPLEX} result---a type not
6787 provided for by that standard.
6788
6789 @item
6790 Automatic conversion of numeric
6791 expressions to @code{INTEGER(KIND=1)} in contexts such as:
6792
6793 @itemize --
6794 @item
6795 Array-reference indexes.
6796 @item
6797 Alternate-return values.
6798 @item
6799 Computed @code{GOTO}.
6800 @item
6801 @code{FORMAT} run-time expressions (not yet supported).
6802 @item
6803 Dimension lists in specification statements.
6804 @item
6805 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
6806 @item
6807 Sizes of @code{CHARACTER} entities in specification statements.
6808 @item
6809 Kind types in specification entities (a Fortran 90 feature).
6810 @item
6811 Initial, terminal, and incrementation parameters for implied-@code{DO}
6812 constructs in @code{DATA} statements.
6813 @end itemize
6814
6815 @item
6816 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
6817 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
6818 expressions are disallowed anyway).
6819
6820 @item
6821 Zero-size array dimensions, as in:
6822
6823 @example
6824 INTEGER I(10,20,4:2)
6825 @end example
6826
6827 @item
6828 Zero-length @code{CHARACTER} entities, as in:
6829
6830 @example
6831 PRINT *, ''
6832 @end example
6833
6834 @item
6835 Substring operators applied to character constants and named
6836 constants, as in:
6837
6838 @example
6839 PRINT *, 'hello'(3:5)
6840 @end example
6841
6842 @item
6843 Null arguments passed to statement function, as in:
6844
6845 @example
6846 PRINT *, FOO(,3)
6847 @end example
6848
6849 @item
6850 Disagreement among program units regarding whether a given @code{COMMON}
6851 area is @code{SAVE}d (for targets where program units in a single source
6852 file are ``glued'' together as they typically are for UNIX development
6853 environments).
6854
6855 @item
6856 Disagreement among program units regarding the size of a
6857 named @code{COMMON} block.
6858
6859 @item
6860 Specification statements following first @code{DATA} statement.
6861
6862 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
6863 but not @samp{INTEGER I}.
6864 The @samp{-fpedantic} option disallows both of these.)
6865
6866 @item
6867 Semicolon as statement separator, as in:
6868
6869 @example
6870 CALL FOO; CALL BAR
6871 @end example
6872 @c
6873 @c @item
6874 @c Comma before list of I/O items in @code{WRITE}
6875 @c @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
6876 @c statements, as with @code{READ} (as explained above).
6877
6878 @item
6879 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
6880
6881 @item
6882 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
6883 versa.
6884
6885 @item
6886 Expressions having two arithmetic operators in a row, such
6887 as @samp{X*-Y}.
6888 @end itemize
6889
6890 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
6891 following constructs result in diagnostics:
6892
6893 @itemize @bullet
6894 @item
6895 Use of semicolon as a statement separator on a line
6896 that has an @code{INCLUDE} directive.
6897 @end itemize
6898
6899 @node Distensions
6900 @section Distensions
6901 @cindex distensions
6902 @cindex ugly features
6903 @cindex features, ugly
6904
6905 The @samp{-fugly-*} command-line options determine whether certain
6906 features supported by VAX FORTRAN and other such compilers, but considered
6907 too ugly to be in code that can be changed to use safer and/or more
6908 portable constructs, are accepted.
6909 These are humorously referred to as ``distensions'',
6910 extensions that just plain look ugly in the harsh light of day.
6911
6912 @emph{Note:} The @samp{-fugly} option, which currently serves
6913 as shorthand to enable all of the distensions below, is likely to
6914 be removed in a future version of @code{g77}.
6915 That's because it's likely new distensions will be added that
6916 conflict with existing ones in terms of assigning meaning to
6917 a given chunk of code.
6918 (Also, it's pretty clear that users should not use @samp{-fugly}
6919 as shorthand when the next release of @code{g77} might add a
6920 distension to that that causes their existing code, when recompiled,
6921 to behave differently---perhaps even fail to compile or run
6922 correctly.)
6923
6924 @menu
6925 * Ugly Implicit Argument Conversion:: Disabled via @samp{-fno-ugly-args}.
6926 * Ugly Assumed-Size Arrays:: Enabled via @samp{-fugly-assumed}.
6927 * Ugly Null Arguments:: Enabled via @samp{-fugly-comma}.
6928 * Ugly Complex Part Extraction:: Enabled via @samp{-fugly-complex}.
6929 * Ugly Conversion of Initializers:: Disabled via @samp{-fno-ugly-init}.
6930 * Ugly Integer Conversions:: Enabled via @samp{-fugly-logint}.
6931 * Ugly Assigned Labels:: Enabled via @samp{-fugly-assign}.
6932 @end menu
6933
6934 @node Ugly Implicit Argument Conversion
6935 @subsection Implicit Argument Conversion
6936 @cindex Hollerith constants
6937 @cindex constants, Hollerith
6938
6939 The @samp{-fno-ugly-args} option disables
6940 passing typeless and Hollerith constants as actual arguments
6941 in procedure invocations.
6942 For example:
6943
6944 @example
6945 CALL FOO(4HABCD)
6946 CALL BAR('123'O)
6947 @end example
6948
6949 @noindent
6950 These constructs can be too easily used to create non-portable
6951 code, but are not considered as ``ugly'' as others.
6952 Further, they are widely used in existing Fortran source code
6953 in ways that often are quite portable.
6954 Therefore, they are enabled by default.
6955
6956 @node Ugly Assumed-Size Arrays
6957 @subsection Ugly Assumed-Size Arrays
6958 @cindex arrays, assumed-size
6959 @cindex assumed-size arrays
6960 @cindex DIMENSION X(1)
6961
6962 The @samp{-fugly-assumed} option enables
6963 the treatment of any array with a final dimension specified as @samp{1}
6964 as an assumed-size array, as if @samp{*} had been specified
6965 instead.
6966
6967 For example, @samp{DIMENSION X(1)} is treated as if it
6968 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
6969 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
6970 or @code{ENTRY} statement in the same program unit.
6971
6972 Use an explicit lower bound to avoid this interpretation.
6973 For example, @samp{DIMENSION X(1:1)} is never treated as if
6974 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
6975 Nor is @samp{DIMENSION X(2-1)} affected by this option,
6976 since that kind of expression is unlikely to have been
6977 intended to designate an assumed-size array.
6978
6979 This option is used to prevent warnings being issued about apparent
6980 out-of-bounds reference such as @samp{X(2) = 99}.
6981
6982 It also prevents the array from being used in contexts that
6983 disallow assumed-size arrays, such as @samp{PRINT *,X}.
6984 In such cases, a diagnostic is generated and the source file is
6985 not compiled.
6986
6987 The construct affected by this option is used only in old code
6988 that pre-exists the widespread acceptance of adjustable and assumed-size
6989 arrays in the Fortran community.
6990
6991 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
6992 treated if @samp{X} is listed as a dummy argument only
6993 @emph{after} the @code{DIMENSION} statement (presumably in
6994 an @code{ENTRY} statement).
6995 For example, @samp{-fugly-assumed} has no effect on the
6996 following program unit:
6997
6998 @example
6999 SUBROUTINE X
7000 REAL A(1)
7001 RETURN
7002 ENTRY Y(A)
7003 PRINT *, A
7004 END
7005 @end example
7006
7007 @node Ugly Complex Part Extraction
7008 @subsection Ugly Complex Part Extraction
7009 @cindex complex values
7010 @cindex real part
7011 @cindex imaginary part
7012
7013 The @samp{-fugly-complex} option enables
7014 use of the @code{REAL()} and @code{AIMAG()}
7015 intrinsics with arguments that are
7016 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
7017
7018 With @samp{-ff90} in effect, these intrinsics return
7019 the unconverted real and imaginary parts (respectively)
7020 of their argument.
7021
7022 With @samp{-fno-f90} in effect, these intrinsics convert
7023 the real and imaginary parts to @code{REAL(KIND=1)}, and return
7024 the result of that conversion.
7025
7026 Due to this ambiguity, the GNU Fortran language defines
7027 these constructs as invalid, except in the specific
7028 case where they are entirely and solely passed as an
7029 argument to an invocation of the @code{REAL()} intrinsic.
7030 For example,
7031
7032 @example
7033 REAL(REAL(Z))
7034 @end example
7035
7036 @noindent
7037 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
7038 and @samp{-fno-ugly-complex} is in effect, because the
7039 meaning is clear.
7040
7041 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
7042 is specified, in which case the appropriate interpretation is
7043 chosen and no diagnostic is issued.
7044
7045 @xref{CMPAMBIG}, for information on how to cope with existing
7046 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
7047 with @code{COMPLEX(KIND=2)} arguments.
7048
7049 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
7050 intrinsic, used to extract the real part of a complex expression
7051 without conversion.
7052 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
7053 intrinsic, used to extract the imaginary part of a complex expression
7054 without conversion.
7055
7056 @node Ugly Null Arguments
7057 @subsection Ugly Null Arguments
7058 @cindex trailing commas
7059 @cindex commas, trailing
7060 @cindex null arguments
7061 @cindex arguments, null
7062
7063 The @samp{-fugly-comma} option enables
7064 use of a single trailing comma to mean ``pass an extra trailing null
7065 argument'' in a list of actual arguments to a procedure other than a
7066 statement function, and use of an empty list of arguments to
7067 mean ``pass a single null argument''.
7068
7069 @cindex omitting arguments
7070 @cindex arguments, omitting
7071 (Null arguments often are used in some procedure-calling
7072 schemes to indicate omitted arguments.)
7073
7074 For example, @samp{CALL FOO(,)} means ``pass
7075 two null arguments'', rather than ``pass one null argument''.
7076 Also, @samp{CALL BAR()} means ``pass one null argument''.
7077
7078 This construct is considered ``ugly'' because it does not
7079 provide an elegant way to pass a single null argument
7080 that is syntactically distinct from passing no arguments.
7081 That is, this construct changes the meaning of code that
7082 makes no use of the construct.
7083
7084 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
7085 and @samp{I = JFUNC()} pass a single null argument, instead
7086 of passing no arguments as required by the Fortran 77 and
7087 90 standards.
7088
7089 @emph{Note:} Many systems gracefully allow the case
7090 where a procedure call passes one extra argument that the
7091 called procedure does not expect.
7092
7093 So, in practice, there might be no difference in
7094 the behavior of a program that does @samp{CALL FOO()}
7095 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
7096 in force as compared to its behavior when compiled
7097 with the default, @samp{-fno-ugly-comma}, in force,
7098 assuming @samp{FOO} and @samp{JFUNC} do not expect any
7099 arguments to be passed.
7100
7101 @node Ugly Conversion of Initializers
7102 @subsection Ugly Conversion of Initializers
7103
7104 The constructs disabled by @samp{-fno-ugly-init} are:
7105
7106 @itemize @bullet
7107 @cindex Hollerith constants
7108 @cindex constants, Hollerith
7109 @item
7110 Use of Hollerith and typeless constants in contexts where they set
7111 initial (compile-time) values for variables, arrays, and named
7112 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
7113 type-declaration statements specifying initial values.
7114
7115 Here are some sample initializations that are disabled by the
7116 @samp{-fno-ugly-init} option:
7117
7118 @example
7119 PARAMETER (VAL='9A304FFE'X)
7120 REAL*8 STRING/8HOUTPUT00/
7121 DATA VAR/4HABCD/
7122 @end example
7123
7124 @cindex character constants
7125 @cindex constants, character
7126 @item
7127 In the same contexts as above, use of character constants to initialize
7128 numeric items and vice versa (one constant per item).
7129
7130 Here are more sample initializations that are disabled by the
7131 @samp{-fno-ugly-init} option:
7132
7133 @example
7134 INTEGER IA
7135 CHARACTER BELL
7136 PARAMETER (IA = 'A')
7137 PARAMETER (BELL = 7)
7138 @end example
7139
7140 @item
7141 Use of Hollerith and typeless constants on the right-hand side
7142 of assignment statements to numeric types, and in other
7143 contexts (such as passing arguments in invocations of
7144 intrinsic procedures and statement functions) that
7145 are treated as assignments to known types (the dummy
7146 arguments, in these cases).
7147
7148 Here are sample statements that are disabled by the
7149 @samp{-fno-ugly-init} option:
7150
7151 @example
7152 IVAR = 4HABCD
7153 PRINT *, IMAX0(2HAB, 2HBA)
7154 @end example
7155 @end itemize
7156
7157 The above constructs, when used,
7158 can tend to result in non-portable code.
7159 But, they are widely used in existing Fortran code in ways
7160 that often are quite portable.
7161 Therefore, they are enabled by default.
7162
7163 @node Ugly Integer Conversions
7164 @subsection Ugly Integer Conversions
7165
7166 The constructs enabled via @samp{-fugly-logint} are:
7167
7168 @itemize @bullet
7169 @item
7170 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
7171 dictated by
7172 context (typically implies nonportable dependencies on how a
7173 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
7174
7175 @item
7176 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
7177 statements.
7178 @end itemize
7179
7180 The above constructs are disabled by default because use
7181 of them tends to lead to non-portable code.
7182 Even existing Fortran code that uses that often turns out
7183 to be non-portable, if not outright buggy.
7184
7185 Some of this is due to differences among implementations as
7186 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
7187 @code{INTEGER} values---Fortran code that assumes a particular
7188 coding is likely to use one of the above constructs, and is
7189 also likely to not work correctly on implementations using
7190 different encodings.
7191
7192 @xref{Equivalence Versus Equality}, for more information.
7193
7194 @node Ugly Assigned Labels
7195 @subsection Ugly Assigned Labels
7196 @cindex ASSIGN statement
7197 @cindex statements, ASSIGN
7198 @cindex assigned labels
7199 @cindex pointers
7200
7201 The @samp{-fugly-assign} option forces @code{g77} to use the
7202 same storage for assigned labels as it would for a normal
7203 assignment to the same variable.
7204
7205 For example, consider the following code fragment:
7206
7207 @example
7208 I = 3
7209 ASSIGN 10 TO I
7210 @end example
7211
7212 @noindent
7213 Normally, for portability and improved diagnostics, @code{g77}
7214 reserves distinct storage for a ``sibling'' of @samp{I}, used
7215 only for @code{ASSIGN} statements to that variable (along with
7216 the corresponding assigned-@code{GOTO} and assigned-@samp{FORMAT}-I/O
7217 statements that reference the variable).
7218
7219 However, some code (that violates the ANSI FORTRAN 77 standard)
7220 attempts to copy assigned labels among variables involved with
7221 @code{ASSIGN} statements, as in:
7222
7223 @example
7224 ASSIGN 10 TO I
7225 ISTATE(5) = I
7226 @dots{}
7227 J = ISTATE(ICUR)
7228 GOTO J
7229 @end example
7230
7231 @noindent
7232 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
7233 is specified on the command-line, ensuring that the value of @code{I}
7234 referenced in the second line is whatever value @code{g77} uses
7235 to designate statement label @samp{10}, so the value may be
7236 copied into the @samp{ISTATE} array, later retrieved into a
7237 variable of the appropriate type (@samp{J}), and used as the target of
7238 an assigned-@code{GOTO} statement.
7239
7240 @emph{Note:} To avoid subtle program bugs,
7241 when @samp{-fugly-assign} is specified,
7242 @code{g77} requires the type of variables
7243 specified in assigned-label contexts
7244 @emph{must} be the same type returned by @code{%LOC()}.
7245 On many systems, this type is effectively the same
7246 as @code{INTEGER(KIND=1)}, while, on others, it is
7247 effectively the same as @code{INTEGER(KIND=2)}.
7248
7249 Do @emph{not} depend on @code{g77} actually writing valid pointers
7250 to these variables, however.
7251 While @code{g77} currently chooses that implementation, it might
7252 be changed in the future.
7253
7254 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
7255 for implementation details on assigned-statement labels.
7256
7257 @node Compiler
7258 @chapter The GNU Fortran Compiler
7259
7260 The GNU Fortran compiler, @code{g77}, supports programs written
7261 in the GNU Fortran language and in some other dialects of Fortran.
7262
7263 Some aspects of how @code{g77} works are universal regardless
7264 of dialect, and yet are not properly part of the GNU Fortran
7265 language itself.
7266 These are described below.
7267
7268 @emph{Note: This portion of the documentation definitely needs a lot
7269 of work!}
7270
7271 @menu
7272 * Compiler Limits::
7273 * Compiler Types::
7274 * Compiler Constants::
7275 * Compiler Intrinsics::
7276 @end menu
7277
7278 @node Compiler Limits
7279 @section Compiler Limits
7280 @cindex limits, compiler
7281 @cindex compiler limits
7282
7283 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
7284 on lengths of identifiers, number of continuation lines, number of external
7285 symbols in a program, and so on.
7286
7287 @cindex options, -Nl
7288 @cindex -Nl option
7289 @cindex options, -Nx
7290 @cindex -Nx option
7291 For example, some other Fortran compiler have an option
7292 (such as @samp{-Nl@var{x}}) to increase the limit on the
7293 number of continuation lines.
7294 Also, some Fortran compilation systems have an option
7295 (such as @samp{-Nx@var{x}}) to increase the limit on the
7296 number of external symbols.
7297
7298 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
7299 no equivalent options, since they do not impose arbitrary
7300 limits in these areas.
7301
7302 @cindex rank, maximum
7303 @cindex maximum rank
7304 @cindex number of dimensions, maximum
7305 @cindex maximum number of dimensions
7306 @code{g77} does currently limit the number of dimensions in an array
7307 to the same degree as do the Fortran standards---seven (7).
7308 This restriction might well be lifted in a future version.
7309
7310 @node Compiler Types
7311 @section Compiler Types
7312 @cindex types, of data
7313 @cindex data types
7314
7315 Fortran implementations have a fair amount of freedom given them by the
7316 standard as far as how much storage space is used and how much precision
7317 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
7318 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
7319 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
7320 Further, many compilers offer so-called @samp{*@var{n}} notation, but
7321 the interpretation of @var{n} varies across compilers and target architectures.
7322
7323 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
7324 and @code{REAL(KIND=1)}
7325 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
7326 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
7327 Further, it requires that @code{COMPLEX(KIND=1)}
7328 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
7329 storage-associated (such as via @code{EQUIVALENCE})
7330 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
7331 corresponds to the real element and @samp{R(2)} to the imaginary
7332 element of the @code{COMPLEX(KIND=1)} variable.
7333
7334 (Few requirements as to precision or ranges of any of these are
7335 placed on the implementation, nor is the relationship of storage sizes of
7336 these types to the @code{CHARACTER} type specified, by the standard.)
7337
7338 @code{g77} follows the above requirements, warning when compiling
7339 a program requires placement of items in memory that contradict the
7340 requirements of the target architecture.
7341 (For example, a program can require placement of a @code{REAL(KIND=2)}
7342 on a boundary that is not an even multiple of its size, but still an
7343 even multiple of the size of a @code{REAL(KIND=1)} variable.
7344 On some target architectures, using the canonical
7345 mapping of Fortran types to underlying architectural types, such
7346 placement is prohibited by the machine definition or
7347 the Application Binary Interface (ABI) in force for
7348 the configuration defined for building @code{gcc} and @code{g77}.
7349 @code{g77} warns about such
7350 situations when it encounters them.)
7351
7352 @code{g77} follows consistent rules for configuring the mapping between Fortran
7353 types, including the @samp{*@var{n}} notation, and the underlying architectural
7354 types as accessed by a similarly-configured applicable version of the
7355 @code{gcc} compiler.
7356 These rules offer a widely portable, consistent Fortran/C
7357 environment, although they might well conflict with the expectations of
7358 users of Fortran compilers designed and written for particular
7359 architectures.
7360
7361 These rules are based on the configuration that is in force for the
7362 version of @code{gcc} built in the same release as @code{g77} (and
7363 which was therefore used to build both the @code{g77} compiler
7364 components and the @code{libf2c} run-time library):
7365
7366 @table @code
7367 @cindex REAL(KIND=1) type
7368 @cindex types, REAL(KIND=1)
7369 @item REAL(KIND=1)
7370 Same as @code{float} type.
7371
7372 @cindex REAL(KIND=2) type
7373 @cindex types, REAL(KIND=2)
7374 @item REAL(KIND=2)
7375 Same as whatever floating-point type that is twice the size
7376 of a @code{float}---usually, this is a @code{double}.
7377
7378 @cindex INTEGER(KIND=1) type
7379 @cindex types, INTEGER(KIND=1)
7380 @item INTEGER(KIND=1)
7381 Same as an integral type that is occupies the same amount
7382 of memory storage as @code{float}---usually, this is either
7383 an @code{int} or a @code{long int}.
7384
7385 @cindex LOGICAL(KIND=1) type
7386 @cindex types, LOGICAL(KIND=1)
7387 @item LOGICAL(KIND=1)
7388 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
7389
7390 @cindex INTEGER(KIND=2) type
7391 @cindex types, INTEGER(KIND=2)
7392 @item INTEGER(KIND=2)
7393 Twice the size, and usually nearly twice the range,
7394 as @code{INTEGER(KIND=1)}---usually, this is either
7395 a @code{long int} or a @code{long long int}.
7396
7397 @cindex LOGICAL(KIND=2) type
7398 @cindex types, LOGICAL(KIND=2)
7399 @item LOGICAL(KIND=2)
7400 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
7401
7402 @cindex INTEGER(KIND=3) type
7403 @cindex types, INTEGER(KIND=3)
7404 @item INTEGER(KIND=3)
7405 Same @code{gcc} type as signed @code{char}.
7406
7407 @cindex LOGICAL(KIND=3) type
7408 @cindex types, LOGICAL(KIND=3)
7409 @item LOGICAL(KIND=3)
7410 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
7411
7412 @cindex INTEGER(KIND=6) type
7413 @cindex types, INTEGER(KIND=6)
7414 @item INTEGER(KIND=6)
7415 Twice the size, and usually nearly twice the range,
7416 as @code{INTEGER(KIND=3)}---usually, this is
7417 a @code{short}.
7418
7419 @cindex LOGICAL(KIND=6) type
7420 @cindex types, LOGICAL(KIND=6)
7421 @item LOGICAL(KIND=6)
7422 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
7423
7424 @cindex COMPLEX(KIND=1) type
7425 @cindex types, COMPLEX(KIND=1)
7426 @item COMPLEX(KIND=1)
7427 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
7428 one for the imaginary part).
7429
7430 @cindex COMPLEX(KIND=2) type
7431 @cindex types, COMPLEX(KIND=2)
7432 @item COMPLEX(KIND=2)
7433 Two @code{REAL(KIND=2)} scalars.
7434
7435 @cindex *@var{n} notation
7436 @item @var{numeric-type}*@var{n}
7437 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)@
7438 Same as whatever @code{gcc} type occupies @var{n} times the storage
7439 space of a @code{gcc} @code{char} item.
7440
7441 @cindex DOUBLE PRECISION type
7442 @cindex types, DOUBLE PRECISION
7443 @item DOUBLE PRECISION
7444 Same as @code{REAL(KIND=2)}.
7445
7446 @cindex DOUBLE COMPLEX type
7447 @cindex types, DOUBLE COMPLEX
7448 @item DOUBLE COMPLEX
7449 Same as @code{COMPLEX(KIND=2)}.
7450 @end table
7451
7452 Note that the above are proposed correspondences and might change
7453 in future versions of @code{g77}---avoid writing code depending
7454 on them.
7455
7456 Other types supported by @code{g77}
7457 are derived from gcc types such as @code{char}, @code{short},
7458 @code{int}, @code{long int}, @code{long long int}, @code{long double},
7459 and so on.
7460 That is, whatever types @code{gcc} already supports, @code{g77} supports
7461 now or probably will support in a future version.
7462 The rules for the @samp{@var{numeric-type}*@var{n}} notation
7463 apply to these types,
7464 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
7465 assigned in a way that encourages clarity, consistency, and portability.
7466
7467 @node Compiler Constants
7468 @section Compiler Constants
7469 @cindex constants
7470 @cindex types, constants
7471
7472 @code{g77} strictly assigns types to @emph{all} constants not
7473 documented as ``typeless'' (typeless constants including @samp{'1'Z},
7474 for example).
7475 Many other Fortran compilers attempt to assign types to typed constants
7476 based on their context.
7477 This results in hard-to-find bugs, nonportable
7478 code, and is not in the spirit (though it strictly follows the letter)
7479 of the 77 and 90 standards.
7480
7481 @code{g77} might offer, in a future release, explicit constructs by
7482 which a wider variety of typeless constants may be specified, and/or
7483 user-requested warnings indicating places where @code{g77} might differ
7484 from how other compilers assign types to constants.
7485
7486 @xref{Context-Sensitive Constants}, for more information on this issue.
7487
7488 @node Compiler Intrinsics
7489 @section Compiler Intrinsics
7490
7491 @code{g77} offers an ever-widening set of intrinsics.
7492 Currently these all are procedures (functions and subroutines).
7493
7494 Some of these intrinsics are unimplemented, but their names reserved
7495 to reduce future problems with existing code as they are implemented.
7496 Others are implemented as part of the GNU Fortran language, while
7497 yet others are provided for compatibility with other dialects of
7498 Fortran but are not part of the GNU Fortran language.
7499
7500 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
7501 a facility that is simply an extension of the intrinsic groups provided
7502 by the GNU Fortran language.
7503
7504 @menu
7505 * Intrinsic Groups:: How intrinsics are grouped for easy management.
7506 * Other Intrinsics:: Intrinsics other than those in the GNU
7507 Fortran language.
7508 @end menu
7509
7510 @node Intrinsic Groups
7511 @subsection Intrinsic Groups
7512 @cindex groups of intrinsics
7513 @cindex intrinsics, groups
7514
7515 A given specific intrinsic belongs in one or more groups.
7516 Each group is deleted, disabled, hidden, or enabled
7517 by default or a command-line option.
7518 The meaning of each term follows.
7519
7520 @table @b
7521 @cindex deleted intrinsics
7522 @cindex intrinsics, deleted
7523 @item Deleted
7524 No intrinsics are recognized as belonging to that group.
7525
7526 @cindex disabled intrinsics
7527 @cindex intrinsics, disabled
7528 @item Disabled
7529 Intrinsics are recognized as belonging to the group, but
7530 references to them (other than via the @code{INTRINSIC} statement)
7531 are disallowed through that group.
7532
7533 @cindex hidden intrinsics
7534 @cindex intrinsics, hidden
7535 @item Hidden
7536 Intrinsics in that group are recognized and enabled (if implemented)
7537 @emph{only} if the first mention of the actual name of an intrinsic
7538 in a program unit is in an @code{INTRINSIC} statement.
7539
7540 @cindex enabled intrinsics
7541 @cindex intrinsics, enabled
7542 @item Enabled
7543 Intrinsics in that group are recognized and enabled (if implemented).
7544 @end table
7545
7546 The distinction between deleting and disabling a group is illustrated
7547 by the following example.
7548 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
7549 If group @samp{FGR} is deleted, the following program unit will
7550 successfully compile, because @samp{FOO()} will be seen as a
7551 reference to an external function named @samp{FOO}:
7552
7553 @example
7554 PRINT *, FOO()
7555 END
7556 @end example
7557
7558 @noindent
7559 If group @samp{FGR} is disabled, compiling the above program will produce
7560 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
7561 or, if properly invoked, it is not enabled.
7562 To change the above program so it references an external function @samp{FOO}
7563 instead of the disabled @samp{FOO} intrinsic,
7564 add the following line to the top:
7565
7566 @example
7567 EXTERNAL FOO
7568 @end example
7569
7570 @noindent
7571 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
7572 that group do not exist at all, whereas disabling it tells @code{g77} to
7573 recognize them as (disabled) intrinsics in intrinsic-like contexts.
7574
7575 Hiding a group is like enabling it, but the intrinsic must be first
7576 named in an @code{INTRINSIC} statement to be considered a reference to the
7577 intrinsic rather than to an external procedure.
7578 This might be the ``safest'' way to treat a new group of intrinsics
7579 when compiling old
7580 code, because it allows the old code to be generally written as if
7581 those new intrinsics never existed, but to be changed to use them
7582 by inserting @code{INTRINSIC} statements in the appropriate places.
7583 However, it should be the goal of development to use @code{EXTERNAL}
7584 for all names of external procedures that might be intrinsic names.
7585
7586 If an intrinsic is in more than one group, it is enabled if any of its
7587 containing groups are enabled; if not so enabled, it is hidden if
7588 any of its containing groups are hidden; if not so hidden, it is disabled
7589 if any of its containing groups are disabled; if not so disabled, it is
7590 deleted.
7591 This extra complication is necessary because some intrinsics,
7592 such as @code{IBITS}, belong to more than one group, and hence should be
7593 enabled if any of the groups to which they belong are enabled, and so
7594 on.
7595
7596 The groups are:
7597
7598 @cindex intrinsics, groups of
7599 @cindex groups of intrinsics
7600 @table @code
7601 @item badu77
7602 UNIX intrinsics having inappropriate forms (usually functions that
7603 have intended side effects).
7604
7605 @item gnu
7606 Intrinsics the GNU Fortran language supports that are extensions to
7607 the Fortran standards (77 and 90).
7608
7609 @item f2c
7610 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
7611
7612 @item f90
7613 Fortran 90 intrinsics.
7614
7615 @item mil
7616 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
7617
7618 @item unix
7619 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
7620
7621 @item vxt
7622 VAX/VMS FORTRAN (current as of v4) intrinsics.
7623 @end table
7624
7625 @node Other Intrinsics
7626 @subsection Other Intrinsics
7627 @cindex intrinsics, others
7628 @cindex other intrinsics
7629
7630 @code{g77} supports intrinsics other than those in the GNU Fortran
7631 language proper.
7632 This set of intrinsics is described below.
7633
7634 @ifinfo
7635 (Note that the empty lines appearing in the menu below
7636 are not intentional---they result from a bug in the
7637 @code{makeinfo} program.)
7638 @end ifinfo
7639
7640 @c The actual documentation for intrinsics comes from
7641 @c intdoc.texi, which in turn is automatically generated
7642 @c from the internal g77 tables in intrin.def _and_ the
7643 @c largely hand-written text in intdoc.h. So, if you want
7644 @c to change or add to existing documentation on intrinsics,
7645 @c you probably want to edit intdoc.h.
7646 @c
7647 @clear familyF77
7648 @clear familyGNU
7649 @clear familyASC
7650 @clear familyMIL
7651 @clear familyF90
7652 @set familyVXT
7653 @set familyFVZ
7654 @clear familyF2C
7655 @clear familyF2U
7656 @set familyBADU77
7657 @include intdoc.texi
7658
7659 @node Other Compilers
7660 @chapter Other Compilers
7661
7662 An individual Fortran source file can be compiled to
7663 an object (@file{*.o}) file instead of to the final
7664 program executable.
7665 This allows several portions of a program to be compiled
7666 at different times and linked together whenever a new
7667 version of the program is needed.
7668 However, it introduces the issue of @dfn{object compatibility}
7669 across the various object files (and libraries, or @file{*.a}
7670 files) that are linked together to produce any particular
7671 executable file.
7672
7673 Object compatibility is an issue when combining, in one
7674 program, Fortran code compiled by more than one compiler
7675 (or more than one configuration of a compiler).
7676 If the compilers
7677 disagree on how to transform the names of procedures, there
7678 will normally be errors when linking such programs.
7679 Worse, if the compilers agree on naming, but disagree on issues
7680 like how to pass parameters, return arguments, and lay out
7681 @code{COMMON} areas, the earliest detected errors might be the
7682 incorrect results produced by the program (and that assumes
7683 these errors are detected, which is not always the case).
7684
7685 Normally, @code{g77} generates code that is
7686 object-compatible with code generated by a version of
7687 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
7688 to be generally compatible with @code{g77} as built by @code{gcc}.
7689 (Normally, @code{f2c} will, by default, conform to the appropriate
7690 configuration, but it is possible that older or perhaps even newer
7691 versions of @code{f2c}, or versions having certain configuration changes
7692 to @code{f2c} internals, will produce object files that are
7693 incompatible with @code{g77}.)
7694
7695 For example, a Fortran string subroutine
7696 argument will become two arguments on the C side: a @code{char *}
7697 and an @code{int} length.
7698
7699 Much of this compatibility results from the fact that
7700 @code{g77} uses the same run-time library, @code{libf2c}, used by
7701 @code{f2c}.
7702
7703 Other compilers might or might not generate code that
7704 is object-compatible with @code{libf2c} and current @code{g77},
7705 and some might offer such compatibility only when explicitly
7706 selected via a command-line option to the compiler.
7707
7708 @emph{Note: This portion of the documentation definitely needs a lot
7709 of work!}
7710
7711 @menu
7712 * Dropping f2c Compatibility:: When speed is more important.
7713 * Compilers Other Than f2c:: Interoperation with code from other compilers.
7714 @end menu
7715
7716 @node Dropping f2c Compatibility
7717 @section Dropping @code{f2c} Compatibility
7718
7719 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
7720 some cases, faster code, by not needing to allow to the possibility
7721 of linking with code compiled by @code{f2c}.
7722
7723 For example, this affects how @code{REAL(KIND=1)},
7724 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
7725 With @samp{-fno-f2c}, they are
7726 compiled as returning the appropriate @code{gcc} type
7727 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
7728 in many configurations).
7729
7730 With @samp{-ff2c} in force, they
7731 are compiled differently (with perhaps slower run-time performance)
7732 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
7733 C as an intermediate language---@code{REAL(KIND=1)} functions
7734 return C's @code{double} type, while @code{COMPLEX} functions return
7735 @code{void} and use an extra argument pointing to a place for the functions to
7736 return their values.
7737
7738 It is possible that, in some cases, leaving @samp{-ff2c} in force
7739 might produce faster code than using @samp{-fno-f2c}.
7740 Feel free to experiment, but remember to experiment with changing the way
7741 @emph{entire programs and their Fortran libraries are compiled} at
7742 a time, since this sort of experimentation affects the interface
7743 of code generated for a Fortran source file---that is, it affects
7744 object compatibility.
7745
7746 Note that @code{f2c} compatibility is a fairly static target to achieve,
7747 though not necessarily perfectly so, since, like @code{g77}, it is
7748 still being improved.
7749 However, specifying @samp{-fno-f2c} causes @code{g77}
7750 to generate code that will probably be incompatible with code
7751 generated by future versions of @code{g77} when the same option
7752 is in force.
7753 You should make sure you are always able to recompile complete
7754 programs from source code when upgrading to new versions of @code{g77}
7755 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
7756
7757 Therefore, if you are using @code{g77} to compile libraries and other
7758 object files for possible future use and you don't want to require
7759 recompilation for future use with subsequent versions of @code{g77},
7760 you might want to stick with @code{f2c} compatibility for now, and
7761 carefully watch for any announcements about changes to the
7762 @code{f2c}/@code{libf2c} interface that might affect existing programs
7763 (thus requiring recompilation).
7764
7765 It is probable that a future version of @code{g77} will not,
7766 by default, generate object files compatible with @code{f2c},
7767 and that version probably would no longer use @code{libf2c}.
7768 If you expect to depend on this compatibility in the
7769 long term, use the options @samp{-ff2c -ff2c-library} when compiling
7770 all of the applicable code.
7771 This should cause future versions of @code{g77} either to produce
7772 compatible code (at the expense of the availability of some features and
7773 performance), or at the very least, to produce diagnostics.
7774
7775 @node Compilers Other Than f2c
7776 @section Compilers Other Than @code{f2c}
7777
7778 On systems with Fortran compilers other than @code{f2c} and @code{g77},
7779 code compiled by @code{g77} is not expected to work
7780 well with code compiled by the native compiler.
7781 (This is true for @code{f2c}-compiled objects as well.)@
7782 Libraries compiled with the native compiler probably will have
7783 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
7784
7785 Reasons for such incompatibilities include:
7786
7787 @itemize @bullet
7788 @item
7789 There might be differences in the way names of Fortran procedures
7790 are translated for use in the system's object-file format.
7791 For example, the statement @samp{CALL FOO} might be compiled
7792 by @code{g77} to call a procedure the linker @code{ld} sees
7793 given the name @samp{_foo_}, while the apparently corresponding
7794 statement @samp{SUBROUTINE FOO} might be compiled by the
7795 native compiler to define the linker-visible name @samp{_foo},
7796 or @samp{_FOO_}, and so on.
7797
7798 @item
7799 There might be subtle type mismatches which cause subroutine arguments
7800 and function return values to get corrupted.
7801
7802 This is why simply getting @code{g77} to
7803 transform procedure names the same way a native
7804 compiler does is not usually a good idea---unless
7805 some effort has been made to ensure that, aside
7806 from the way the two compilers transform procedure
7807 names, everything else about the way they generate
7808 code for procedure interfaces is identical.
7809
7810 @item
7811 Native compilers
7812 use libraries of private I/O routines which will not be available
7813 at link time unless you have the native compiler---and you would
7814 have to explicitly ask for them.
7815
7816 For example, on the Sun you
7817 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
7818 command.
7819 @end itemize
7820
7821 @node Other Languages
7822 @chapter Other Languages
7823
7824 @emph{Note: This portion of the documentation definitely needs a lot
7825 of work!}
7826
7827 @menu
7828 * Interoperating with C and C++::
7829 @end menu
7830
7831 @node Interoperating with C and C++
7832 @section Tools and advice for interoperating with C and C++
7833
7834 @cindex C, linking with
7835 @cindex C++, linking with
7836 @cindex linking with C
7837 The following discussion assumes that you are running @code{g77} in @code{f2c}
7838 compatibility mode, i.e.@ not using @samp{-fno-f2c}.
7839 It provides some
7840 advice about quick and simple techniques for linking Fortran and C (or
7841 C++), the most common requirement.
7842 For the full story consult the
7843 description of code generation.
7844 @xref{Debugging and Interfacing}.
7845
7846 When linking Fortran and C, it's usually best to use @code{g77} to do
7847 the linking so that the correct libraries are included (including the
7848 maths one).
7849 If you're linking with C++ you will want to add
7850 @samp{-lstdc++}, @samp{-lg++} or whatever.
7851 If you need to use another
7852 driver program (or @code{ld} directly),
7853 you can find out what linkage
7854 options @code{g77} passes by running @samp{g77 -v}.
7855
7856 @menu
7857 * C Interfacing Tools::
7858 * C Access to Type Information::
7859 * f2c Skeletons and Prototypes::
7860 * C++ Considerations::
7861 * Startup Code::
7862 @end menu
7863
7864 @node C Interfacing Tools
7865 @subsection C Interfacing Tools
7866 @pindex f2c
7867 @cindex cfortran.h
7868 @cindex Netlib
7869 Even if you don't actually use it as a compiler, @samp{f2c} from
7870 @code{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
7871 interfacing (linking) Fortran and C@.
7872 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
7873
7874 To use @code{f2c} for this purpose you only need retrieve and
7875 build the @file{src} directory from the distribution, consult the
7876 @file{README} instructions there for machine-specifics, and install the
7877 @code{f2c} program on your path.
7878
7879 Something else that might be useful is @samp{cfortran.h} from
7880 @code{ftp://zebra/desy.de/cfortran}.
7881 This is a fairly general tool which
7882 can be used to generate interfaces for calling in both directions
7883 between Fortran and C@.
7884 It can be used in @code{f2c} mode with
7885 @code{g77}---consult its documentation for details.
7886
7887 @node C Access to Type Information
7888 @subsection Accessing Type Information in C
7889
7890 @cindex types, Fortran/C
7891 Generally, C code written to link with
7892 @code{g77} code---calling and/or being
7893 called from Fortran---should @samp{#include <f2c.h>} to define the C
7894 versions of the Fortran types.
7895 Don't assume Fortran @code{INTEGER} types
7896 correspond to C @samp{int}s, for instance; instead, declare them as
7897 @code{integer}, a type defined by @file{f2c.h}.
7898 @file{f2c.h} is installed where @code{gcc} will find it by
7899 default, assuming you use a copy of @code{gcc} compatible with
7900 @code{g77}, probably built at the same time as @code{g77}.
7901
7902 @node f2c Skeletons and Prototypes
7903 @subsection Generating Skeletons and Prototypes with @code{f2c}
7904
7905 @pindex f2c
7906 @cindex -fno-second-underscore
7907 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@ to
7908 interface with an existing library---is to write a file (named, for
7909 example, @file{fred.f}) of dummy Fortran
7910 skeletons comprising just the declaration of the routine(s) and dummy
7911 arguments plus @samp{END} statements.
7912 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
7913 into which you can edit
7914 useful code, confident the calling sequence is correct, at least.
7915 (There are some errors otherwise commonly made in generating C
7916 interfaces with f2c conventions, such as not using @code{doublereal} as
7917 the return type of a @code{REAL} @code{FUNCTION}.)
7918
7919 @pindex ftnchek
7920 @code{f2c} also can help with calling Fortran from C, using its
7921 @samp{-P} option to generate C prototypes appropriate for calling the
7922 Fortran.@footnote{The files generated like this can also be used for
7923 inter-unit consistency checking of dummy and actual arguments, although
7924 the @samp{ftnchek} tool from @code{ftp://ftp.netlib.org/fortran}
7925 or @code{ftp://ftp.dsm.fordham.edu} is
7926 probably better for this purpose.}
7927 If the Fortran code containing any
7928 routines to be called from C is in file @file{joe.f}, use the command
7929 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
7930 prototype information.
7931 @code{#include} this in the C which has to call
7932 the Fortran routines to make sure you get it right.
7933
7934 @xref{Arrays,,Arrays (DIMENSION}, for information on the differences
7935 between the way Fortran (including compilers like @code{g77}) and
7936 C handle arrays.
7937
7938 @node C++ Considerations
7939 @subsection C++ Considerations
7940
7941 @cindex C++
7942 @code{f2c} can be used to generate suitable code for compilation with a
7943 C++ system using the @samp{-C++} option.
7944 The important thing about linking @code{g77}-compiled
7945 code with C++ is that the prototypes for the @code{g77}
7946 routines must specify C linkage to avoid name mangling.
7947 So, use an @samp{extern "C"} declaration.
7948 @code{f2c}'s @samp{-C++} option will take care
7949 of this when generating skeletons or prototype files as above, and also
7950 avoid clashes with C++ reserved words in addition to those in C@.
7951
7952 @node Startup Code
7953 @subsection Startup Code
7954
7955 @cindex startup code
7956 @cindex runtime initialization
7957 @cindex initialization, runtime
7958 Unlike with some runtime systems, it shouldn't be necessary (unless there are
7959 bugs) to use a Fortran main program to ensure the
7960 runtime---specifically the i/o system---is initialized.
7961 However, to use
7962 the @code{g77} intrinsics @code{GETARG()} and @code{IARGC()} the
7963 @code{main()} routine from the @file{libf2c} library must be used, either
7964 explicitly or implicitly by using a Fortran main program.
7965 This
7966 @code{main()} program calls @code{MAIN__()} (where the names are C-type
7967 @code{extern} names, i.e.@ not mangled).
7968 You need to provide this
7969 nullary procedure as the entry point for your C code if using
7970 @file{libf2c}'s @code{main}.
7971 In some cases it might be necessary to
7972 provide a dummy version of this to avoid linkers complaining about
7973 failure to resolve @code{MAIN__()} if linking against @file{libf2c} and
7974 not using @code{main()} from it.
7975
7976 @include g77install.texi
7977
7978 @node Debugging and Interfacing
7979 @chapter Debugging and Interfacing
7980 @cindex debugging
7981 @cindex interfacing
7982 @cindex calling C routines
7983 @cindex C routines calling Fortran
7984 @cindex f2c compatibility
7985
7986 GNU Fortran currently generates code that is object-compatible with
7987 the @code{f2c} converter.
7988 Also, it avoids limitations in the current GBE, such as the
7989 inability to generate a procedure with
7990 multiple entry points, by generating code that is structured
7991 differently (in terms of procedure names, scopes, arguments, and
7992 so on) than might be expected.
7993
7994 As a result, writing code in other languages that calls on, is
7995 called by, or shares in-memory data with @code{g77}-compiled code generally
7996 requires some understanding of the way @code{g77} compiles code for
7997 various constructs.
7998
7999 Similarly, using a debugger to debug @code{g77}-compiled
8000 code, even if that debugger supports native Fortran debugging, generally
8001 requires this sort of information.
8002
8003 This section describes some of the basic information on how
8004 @code{g77} compiles code for constructs involving interfaces to other
8005 languages and to debuggers.
8006
8007 @emph{Caution:} Much or all of this information pertains to only the current
8008 release of @code{g77}, sometimes even to using certain compiler options
8009 with @code{g77} (such as @samp{-fno-f2c}).
8010 Do not write code that depends on this
8011 information without clearly marking said code as nonportable and
8012 subject to review for every new release of @code{g77}.
8013 This information
8014 is provided primarily to make debugging of code generated by this
8015 particular release of @code{g77} easier for the user, and partly to make
8016 writing (generally nonportable) interface code easier.
8017 Both of these
8018 activities require tracking changes in new version of @code{g77} as they
8019 are installed, because new versions can change the behaviors
8020 described in this section.
8021
8022 @menu
8023 * Main Program Unit:: How @code{g77} compiles a main program unit.
8024 * Procedures:: How @code{g77} constructs parameter lists
8025 for procedures.
8026 * Functions:: Functions returning floating-point or character data.
8027 * Names:: Naming of user-defined variables, procedures, etc.
8028 * Common Blocks:: Accessing common variables while debugging.
8029 * Local Equivalence Areas:: Accessing @code{EQUIVALENCE} while debugging.
8030 * Complex Variables:: How @code{g77} performs complex arithmetic.
8031 * Arrays:: Dealing with (possibly multi-dimensional) arrays.
8032 * Adjustable Arrays:: Special consideration for adjustable arrays.
8033 * Alternate Entry Points:: How @code{g77} implements alternate @code{ENTRY}.
8034 * Alternate Returns:: How @code{g77} handles alternate returns.
8035 * Assigned Statement Labels:: How @code{g77} handles @code{ASSIGN}.
8036 * Run-time Library Errors:: Meanings of some @code{IOSTAT=} values.
8037 @end menu
8038
8039 @node Main Program Unit
8040 @section Main Program Unit (PROGRAM)
8041 @cindex PROGRAM statement
8042 @cindex statements, PROGRAM
8043
8044 When @code{g77} compiles a main program unit, it gives it the public
8045 procedure name @samp{MAIN__}.
8046 The @code{libf2c} library has the actual @code{main()} procedure
8047 as is typical of C-based environments, and
8048 it is this procedure that performs some initial start-up
8049 activity and then calls @samp{MAIN__}.
8050
8051 Generally, @code{g77} and @code{libf2c} are designed so that you need not
8052 include a main program unit written in Fortran in your program---it
8053 can be written in C or some other language.
8054 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
8055 includes a bug fix for @code{libf2c} that solved a problem with using the
8056 @code{OPEN} statement as the first Fortran I/O activity in a program
8057 without a Fortran main program unit.
8058
8059 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
8060 your main program unit---that is, if you intend to compile a @code{main()}
8061 procedure using some other language---you should carefully
8062 examine the code for @code{main()} in @code{libf2c}, found in the source
8063 file @file{gcc/f/runtime/libF77/main.c}, to see what kinds of things
8064 might need to be done by your @code{main()} in order to provide the
8065 Fortran environment your Fortran code is expecting.
8066
8067 @cindex IARGC() intrinsic
8068 @cindex intrinsics, IARGC()
8069 @cindex GETARG() intrinsic
8070 @cindex intrinsics, GETARG()
8071 For example, @code{libf2c}'s @code{main()} sets up the information used by
8072 the @code{IARGC} and @code{GETARG} intrinsics.
8073 Bypassing @code{libf2c}'s @code{main()}
8074 without providing a substitute for this activity would mean
8075 that invoking @code{IARGC} and @code{GETARG} would produce undefined
8076 results.
8077
8078 @cindex debugging
8079 @cindex main program unit, debugging
8080 @cindex main()
8081 @cindex MAIN__()
8082 @cindex .gdbinit
8083 When debugging, one implication of the fact that @code{main()}, which
8084 is the place where the debugged program ``starts'' from the
8085 debugger's point of view, is in @code{libf2c} is that you won't be
8086 starting your Fortran program at a point you recognize as your
8087 Fortran code.
8088
8089 The standard way to get around this problem is to set a break
8090 point (a one-time, or temporary, break point will do) at
8091 the entrance to @samp{MAIN__}, and then run the program.
8092 A convenient way to do so is to add the @code{gdb} command
8093
8094 @example
8095 tbreak MAIN__
8096 @end example
8097
8098 @noindent
8099 to the file @file{.gdbinit} in the directory in which you're debugging
8100 (using @code{gdb}).
8101
8102 After doing this, the debugger will see the current execution
8103 point of the program as at the beginning of the main program
8104 unit of your program.
8105
8106 Of course, if you really want to set a break point at some
8107 other place in your program and just start the program
8108 running, without first breaking at @samp{MAIN__},
8109 that should work fine.
8110
8111 @node Procedures
8112 @section Procedures (SUBROUTINE and FUNCTION)
8113 @cindex procedures
8114 @cindex SUBROUTINE statement
8115 @cindex statements, SUBROUTINE
8116 @cindex FUNCTION statement
8117 @cindex statements, FUNCTION
8118 @cindex signature of procedures
8119
8120 Currently, @code{g77} passes arguments via reference---specifically,
8121 by passing a pointer to the location in memory of a variable, array,
8122 array element, a temporary location that holds the result of evaluating an
8123 expression, or a temporary or permanent location that holds the value
8124 of a constant.
8125
8126 Procedures that accept @code{CHARACTER} arguments are implemented by
8127 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
8128
8129 The first argument occupies the expected position in the
8130 argument list and has the user-specified name.
8131 This argument
8132 is a pointer to an array of characters, passed by the caller.
8133
8134 The second argument is appended to the end of the user-specified
8135 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
8136 is the user-specified name.
8137 This argument is of the C type @code{ftnlen}
8138 (see @file{gcc/f/runtime/f2c.h.in} for information on that type) and
8139 is the number of characters the caller has allocated in the
8140 array pointed to by the first argument.
8141
8142 A procedure will ignore the length argument if @samp{X} is not declared
8143 @code{CHARACTER*(*)}, because for other declarations, it knows the
8144 length.
8145 Not all callers necessarily ``know'' this, however, which
8146 is why they all pass the extra argument.
8147
8148 The contents of the @code{CHARACTER} argument are specified by the
8149 address passed in the first argument (named after it).
8150 The procedure can read or write these contents as appropriate.
8151
8152 When more than one @code{CHARACTER} argument is present in the argument
8153 list, the length arguments are appended in the order
8154 the original arguments appear.
8155 So @samp{CALL FOO('HI','THERE')} is implemented in
8156 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
8157 does not provide the trailing null bytes on the constant
8158 strings (@code{f2c} does provide them, but they are unnecessary in
8159 a Fortran environment, and you should not expect them to be
8160 there).
8161
8162 Note that the above information applies to @code{CHARACTER} variables and
8163 arrays @strong{only}.
8164 It does @strong{not} apply to external @code{CHARACTER}
8165 functions or to intrinsic @code{CHARACTER} functions.
8166 That is, no second length argument is passed to @samp{FOO} in this case:
8167
8168 @example
8169 CHARACTER X
8170 EXTERNAL X
8171 CALL FOO(X)
8172 @end example
8173
8174 @noindent
8175 Nor does @samp{FOO} expect such an argument in this case:
8176
8177 @example
8178 SUBROUTINE FOO(X)
8179 CHARACTER X
8180 EXTERNAL X
8181 @end example
8182
8183 Because of this implementation detail, if a program has a bug
8184 such that there is disagreement as to whether an argument is
8185 a procedure, and the type of the argument is @code{CHARACTER}, subtle
8186 symptoms might appear.
8187
8188 @node Functions
8189 @section Functions (FUNCTION and RETURN)
8190 @cindex functions
8191 @cindex FUNCTION statement
8192 @cindex statements, FUNCTION
8193 @cindex RETURN statement
8194 @cindex statements, RETURN
8195 @cindex return type of functions
8196
8197 @code{g77} handles in a special way functions that return the following
8198 types:
8199
8200 @itemize @bullet
8201 @item
8202 @code{CHARACTER}
8203 @item
8204 @code{COMPLEX}
8205 @item
8206 @code{REAL(KIND=1)}
8207 @end itemize
8208
8209 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
8210 returning @code{void})
8211 with two arguments prepended: @samp{__g77_result}, which the caller passes
8212 as a pointer to a @code{char} array expected to hold the return value,
8213 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
8214 specifying the length of the return value as declared in the calling
8215 program.
8216 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
8217 to determine the size of the array that @samp{__g77_result} points to;
8218 otherwise, it ignores that argument.
8219
8220 For @code{COMPLEX}, when @samp{-ff2c} is in
8221 force, @code{g77} implements
8222 a subroutine with one argument prepended: @samp{__g77_result}, which the
8223 caller passes as a pointer to a variable of the type of the function.
8224 The called function writes the return value into this variable instead
8225 of returning it as a function value.
8226 When @samp{-fno-f2c} is in force,
8227 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
8228 @samp{__complex__ float} or @samp{__complex__ double} function
8229 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
8230 returning the result of the function in the same way as @code{gcc} would.
8231
8232 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
8233 a function that actually returns @code{REAL(KIND=2)} (typically
8234 C's @code{double} type).
8235 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
8236 functions return @code{float}.
8237
8238 @node Names
8239 @section Names
8240 @cindex symbol names
8241 @cindex transformation of symbol names
8242
8243 Fortran permits each implementation to decide how to represent
8244 names as far as how they're seen in other contexts, such as debuggers
8245 and when interfacing to other languages, and especially as far
8246 as how casing is handled.
8247
8248 External names---names of entities that are public, or ``accessible'',
8249 to all modules in a program---normally have an underscore (@samp{_})
8250 appended by @code{g77}, to generate code that is compatible with f2c.
8251 External names include names of Fortran things like common blocks,
8252 external procedures (subroutines and functions, but not including
8253 statement functions, which are internal procedures), and entry point
8254 names.
8255
8256 However, use of the @samp{-fno-underscoring} option
8257 disables this kind of transformation of external names (though inhibiting
8258 the transformation certainly improves the chances of colliding with
8259 incompatible externals written in other languages---but that
8260 might be intentional.
8261
8262 @cindex -fno-underscoring option
8263 @cindex options, -fno-underscoring
8264 @cindex -fno-second-underscore option
8265 @cindex options, -fno-underscoring
8266 When @samp{-funderscoring} is in force, any name (external or local)
8267 that already has at least one underscore in it is
8268 implemented by @code{g77} by appending two underscores.
8269 (This second underscore can be disabled via the
8270 @samp{-fno-second-underscore} option.)@
8271 External names are changed this way for @code{f2c} compatibility.
8272 Local names are changed this way to avoid collisions with external names
8273 that are different in the source code---@code{f2c} does the same thing, but
8274 there's no compatibility issue there except for user expectations while
8275 debugging.
8276
8277 For example:
8278
8279 @example
8280 Max_Cost = 0
8281 @end example
8282
8283 @cindex debugging
8284 @noindent
8285 Here, a user would, in the debugger, refer to this variable using the
8286 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
8287 as described below).
8288 (We hope to improve @code{g77} in this regard in the future---don't
8289 write scripts depending on this behavior!
8290 Also, consider experimenting with the @samp{-fno-underscoring}
8291 option to try out debugging without having to massage names by
8292 hand like this.)
8293
8294 @code{g77} provides a number of command-line options that allow the user
8295 to control how case mapping is handled for source files.
8296 The default is the traditional UNIX model for Fortran compilers---names
8297 are mapped to lower case.
8298 Other command-line options can be specified to map names to upper
8299 case, or to leave them exactly as written in the source file.
8300
8301 For example:
8302
8303 @example
8304 Foo = 9.436
8305 @end example
8306
8307 @noindent
8308 Here, it is normally the case that the variable assigned will be named
8309 @samp{foo}.
8310 This would be the name to enter when using a debugger to
8311 access the variable.
8312
8313 However, depending on the command-line options specified, the
8314 name implemented by @code{g77} might instead be @samp{FOO} or even
8315 @samp{Foo}, thus affecting how debugging is done.
8316
8317 Also:
8318
8319 @example
8320 Call Foo
8321 @end example
8322
8323 @noindent
8324 This would normally call a procedure that, if it were in a separate C program,
8325 be defined starting with the line:
8326
8327 @example
8328 void foo_()
8329 @end example
8330
8331 @noindent
8332 However, @code{g77} command-line options could be used to change the casing
8333 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
8334 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
8335 could be used to inhibit the appending of the underscore to the name.
8336
8337 @node Common Blocks
8338 @section Common Blocks (COMMON)
8339 @cindex common blocks
8340 @cindex COMMON statement
8341 @cindex statements, COMMON
8342
8343 @code{g77} names and lays out @code{COMMON} areas the same way f2c does,
8344 for compatibility with f2c.
8345
8346 Currently, @code{g77} does not emit ``true'' debugging information for
8347 members of a @code{COMMON} area, due to an apparent bug in the GBE.
8348
8349 (As of Version 0.5.19, @code{g77} emits debugging information for such
8350 members in the form of a constant string specifying the base name of
8351 the aggregate area and the offset of the member in bytes from the start
8352 of the area.
8353 Use the @samp{-fdebug-kludge} option to enable this behavior.
8354 In @code{gdb}, use @samp{set language c} before printing the value
8355 of the member, then @samp{set language fortran} to restore the default
8356 language, since @code{gdb} doesn't provide a way to print a readable
8357 version of a character string in Fortran language mode.
8358
8359 This kludge will be removed in a future version of @code{g77} that,
8360 in conjunction with a contemporary version of @code{gdb},
8361 properly supports Fortran-language debugging, including access
8362 to members of @code{COMMON} areas.)
8363
8364 @xref{Code Gen Options,,Options for Code Generation Conventions},
8365 for information on the @samp{-fdebug-kludge} option.
8366
8367 Moreover, @code{g77} currently implements a @code{COMMON} area such that its
8368 type is an array of the C @code{char} data type.
8369
8370 So, when debugging, you must know the offset into a @code{COMMON} area
8371 for a particular item in that area, and you have to take into
8372 account the appropriate multiplier for the respective sizes
8373 of the types (as declared in your code) for the items preceding
8374 the item in question as compared to the size of the @code{char} type.
8375
8376 For example, using default implicit typing, the statement
8377
8378 @example
8379 COMMON I(15), R(20), T
8380 @end example
8381
8382 @noindent
8383 results in a public 144-byte @code{char} array named @samp{_BLNK__}
8384 with @samp{I} placed at @samp{_BLNK__[0]}, @samp{R} at @samp{_BLNK__[60]},
8385 and @samp{T} at @samp{_BLNK__[140]}.
8386 (This is assuming that the target machine for
8387 the compilation has 4-byte @code{INTEGER(KIND=1)} and @code{REAL(KIND=1)}
8388 types.)
8389
8390 @node Local Equivalence Areas
8391 @section Local Equivalence Areas (EQUIVALENCE)
8392 @cindex equivalence areas
8393 @cindex local equivalence areas
8394 @cindex EQUIVALENCE statement
8395 @cindex statements, EQUIVALENCE
8396
8397 @code{g77} treats storage-associated areas involving a @code{COMMON}
8398 block as explained in the section on common blocks.
8399
8400 A local @code{EQUIVALENCE} area is a collection of variables and arrays
8401 connected to each other in any way via @code{EQUIVALENCE}, none of which are
8402 listed in a @code{COMMON} statement.
8403
8404 Currently, @code{g77} does not emit ``true'' debugging information for
8405 members in a local @code{EQUIVALENCE} area, due to an apparent bug in the GBE.
8406
8407 (As of Version 0.5.19, @code{g77} does emit debugging information for such
8408 members in the form of a constant string specifying the base name of
8409 the aggregate area and the offset of the member in bytes from the start
8410 of the area.
8411 Use the @samp{-fdebug-kludge} option to enable this behavior.
8412 In @code{gdb}, use @samp{set language c} before printing the value
8413 of the member, then @samp{set language fortran} to restore the default
8414 language, since @code{gdb} doesn't provide a way to print a readable
8415 version of a character string in Fortran language mode.
8416
8417 This kludge will be removed in a future version of @code{g77} that,
8418 in conjunction with a contemporary version of @code{gdb},
8419 properly supports Fortran-language debugging, including access
8420 to members of @code{EQUIVALENCE} areas.)
8421
8422 @xref{Code Gen Options,,Options for Code Generation Conventions},
8423 for information on the @samp{-fdebug-kludge} option.
8424
8425 Moreover, @code{g77} implements a local @code{EQUIVALENCE} area such that its
8426 type is an array of the C @code{char} data type.
8427
8428 The name @code{g77} gives this array of @code{char} type is @samp{__g77_equiv_@var{x}},
8429 where @var{x} is the name of the item that is placed at the beginning (offset 0)
8430 of this array.
8431 If more than one such item is placed at the beginning, @var{x} is
8432 the name that sorts to the top in an alphabetical sort of the list of
8433 such items.
8434
8435 When debugging, you must therefore access members of @code{EQUIVALENCE}
8436 areas by specifying the appropriate @samp{__g77_equiv_@var{x}}
8437 array section with the appropriate offset.
8438 See the explanation of debugging @code{COMMON} blocks
8439 for info applicable to debugging local @code{EQUIVALENCE} areas.
8440
8441 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
8442 for @var{x} using a different method when more than one name was
8443 in the list of names of entities placed at the beginning of the
8444 array.
8445 Though the documentation specified that the first name listed in
8446 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
8447 in fact chose the name using a method that was so complicated,
8448 it seemed easier to change it to an alphabetical sort than to describe the
8449 previous method in the documentation.)
8450
8451 @node Complex Variables
8452 @section Complex Variables (COMPLEX)
8453 @cindex complex variables
8454 @cindex imaginary part of complex
8455 @cindex COMPLEX statement
8456 @cindex statements, COMPLEX
8457
8458 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
8459 (and related intrinsics, constants, functions, and so on)
8460 in a manner that
8461 makes direct debugging involving these types in Fortran
8462 language mode difficult.
8463
8464 Essentially, @code{g77} implements these types using an
8465 internal construct similar to C's @code{struct}, at least
8466 as seen by the @code{gcc} back end.
8467
8468 Currently, the back end, when outputting debugging info with
8469 the compiled code for the assembler to digest, does not detect
8470 these @code{struct} types as being substitutes for Fortran
8471 complex.
8472 As a result, the Fortran language modes of debuggers such as
8473 @code{gdb} see these types as C @code{struct} types, which
8474 they might or might not support.
8475
8476 Until this is fixed, switch to C language mode to work with
8477 entities of @code{COMPLEX} type and then switch back to Fortran language
8478 mode afterward.
8479 (In @code{gdb}, this is accomplished via @samp{set lang c} and
8480 either @samp{set lang fortran} or @samp{set lang auto}.)
8481
8482 @emph{Note:} Compiling with the @samp{-fno-emulate-complex} option
8483 avoids the debugging problem, but is known to cause other problems
8484 like compiler crashes and generation of incorrect code, so it is
8485 not recommended.
8486
8487 @node Arrays
8488 @section Arrays (DIMENSION)
8489 @cindex DIMENSION statement
8490 @cindex statements, DIMENSION
8491 @cindex array ordering
8492 @cindex ordering, array
8493 @cindex column-major ordering
8494 @cindex row-major ordering
8495 @cindex arrays
8496
8497 Fortran uses ``column-major ordering'' in its arrays.
8498 This differs from other languages, such as C, which use ``row-major ordering''.
8499 The difference is that, with Fortran, array elements adjacent to
8500 each other in memory differ in the @emph{first} subscript instead of
8501 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
8502 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
8503
8504 This consideration
8505 affects not only interfacing with and debugging Fortran code,
8506 it can greatly affect how code is designed and written, especially
8507 when code speed and size is a concern.
8508
8509 Fortran also differs from C, a popular language for interfacing and
8510 to support directly in debuggers, in the way arrays are treated.
8511 In C, arrays are single-dimensional and have interesting relationships
8512 to pointers, neither of which is true for Fortran.
8513 As a result, dealing with Fortran arrays from within
8514 an environment limited to C concepts can be challenging.
8515
8516 For example, accessing the array element @samp{A(5,10,20)} is easy enough
8517 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
8518 are needed.
8519 First, C would treat the A array as a single-dimension array.
8520 Second, C does not understand low bounds for arrays as does Fortran.
8521 Third, C assumes a low bound of zero (0), while Fortran defaults to a
8522 low bound of one (1) and can supports an arbitrary low bound.
8523 Therefore, calculations must be done
8524 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
8525 calculations require knowing the dimensions of @samp{A}.
8526
8527 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
8528 @samp{A(5,10,20)} would be:
8529
8530 @example
8531 (5-2)
8532 + (10-1)*(11-2+1)
8533 + (20-0)*(11-2+1)*(21-1+1)
8534 = 4293
8535 @end example
8536
8537 @noindent
8538 So the C equivalent in this case would be @samp{a[4293]}.
8539
8540 When using a debugger directly on Fortran code, the C equivalent
8541 might not work, because some debuggers cannot understand the notion
8542 of low bounds other than zero. However, unlike @code{f2c}, @code{g77}
8543 does inform the GBE that a multi-dimensional array (like @samp{A}
8544 in the above example) is really multi-dimensional, rather than a
8545 single-dimensional array, so at least the dimensionality of the array
8546 is preserved.
8547
8548 Debuggers that understand Fortran should have no trouble with
8549 non-zero low bounds, but for non-Fortran debuggers, especially
8550 C debuggers, the above example might have a C equivalent of
8551 @samp{a[4305]}.
8552 This calculation is arrived at by eliminating the subtraction
8553 of the lower bound in the first parenthesized expression on each
8554 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
8555 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
8556 Actually, the implication of
8557 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
8558 but that @samp{a[20][10][5]} produces the equivalent of
8559 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
8560
8561 Come to think of it, perhaps
8562 the behavior is due to the debugger internally compensating for
8563 the lower bounds by offsetting the base address of @samp{a}, leaving
8564 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
8565 its first element as identified by subscripts equal to the
8566 corresponding lower bounds).
8567
8568 You know, maybe nobody really needs to use arrays.
8569
8570 @node Adjustable Arrays
8571 @section Adjustable Arrays (DIMENSION)
8572 @cindex arrays, adjustable
8573 @cindex adjustable arrays
8574 @cindex arrays, automatic
8575 @cindex automatic arrays
8576 @cindex DIMENSION statement
8577 @cindex statements, DIMENSION
8578 @cindex dimensioning arrays
8579 @cindex arrays, dimensioning
8580
8581 Adjustable and automatic arrays in Fortran require the implementation
8582 (in this
8583 case, the @code{g77} compiler) to ``memorize'' the expressions that
8584 dimension the arrays each time the procedure is invoked.
8585 This is so that subsequent changes to variables used in those
8586 expressions, made during execution of the procedure, do not
8587 have any effect on the dimensions of those arrays.
8588
8589 For example:
8590
8591 @example
8592 REAL ARRAY(5)
8593 DATA ARRAY/5*2/
8594 CALL X(ARRAY, 5)
8595 END
8596 SUBROUTINE X(A, N)
8597 DIMENSION A(N)
8598 N = 20
8599 PRINT *, N, A
8600 END
8601 @end example
8602
8603 @noindent
8604 Here, the implementation should, when running the program, print something
8605 like:
8606
8607 @example
8608 20 2. 2. 2. 2. 2.
8609 @end example
8610
8611 @noindent
8612 Note that this shows that while the value of @samp{N} was successfully
8613 changed, the size of the @samp{A} array remained at 5 elements.
8614
8615 To support this, @code{g77} generates code that executes before any user
8616 code (and before the internally generated computed @code{GOTO} to handle
8617 alternate entry points, as described below) that evaluates each
8618 (nonconstant) expression in the list of subscripts for an
8619 array, and saves the result of each such evaluation to be used when
8620 determining the size of the array (instead of re-evaluating the
8621 expressions).
8622
8623 So, in the above example, when @samp{X} is first invoked, code is
8624 executed that copies the value of @samp{N} to a temporary.
8625 And that same temporary serves as the actual high bound for the single
8626 dimension of the @samp{A} array (the low bound being the constant 1).
8627 Since the user program cannot (legitimately) change the value
8628 of the temporary during execution of the procedure, the size
8629 of the array remains constant during each invocation.
8630
8631 For alternate entry points, the code @code{g77} generates takes into
8632 account the possibility that a dummy adjustable array is not actually
8633 passed to the actual entry point being invoked at that time.
8634 In that case, the public procedure implementing the entry point
8635 passes to the master private procedure implementing all the
8636 code for the entry points a @code{NULL} pointer where a pointer to that
8637 adjustable array would be expected.
8638 The @code{g77}-generated code
8639 doesn't attempt to evaluate any of the expressions in the subscripts
8640 for an array if the pointer to that array is @code{NULL} at run time in
8641 such cases.
8642 (Don't depend on this particular implementation
8643 by writing code that purposely passes @code{NULL} pointers where the
8644 callee expects adjustable arrays, even if you know the callee
8645 won't reference the arrays---nor should you pass @code{NULL} pointers
8646 for any dummy arguments used in calculating the bounds of such
8647 arrays or leave undefined any values used for that purpose in
8648 COMMON---because the way @code{g77} implements these things might
8649 change in the future!)
8650
8651 @node Alternate Entry Points
8652 @section Alternate Entry Points (ENTRY)
8653 @cindex alternate entry points
8654 @cindex entry points
8655 @cindex ENTRY statement
8656 @cindex statements, ENTRY
8657
8658 The GBE does not understand the general concept of
8659 alternate entry points as Fortran provides via the ENTRY statement.
8660 @code{g77} gets around this by using an approach to compiling procedures
8661 having at least one @code{ENTRY} statement that is almost identical to the
8662 approach used by @code{f2c}.
8663 (An alternate approach could be used that
8664 would probably generate faster, but larger, code that would also
8665 be a bit easier to debug.)
8666
8667 Information on how @code{g77} implements @code{ENTRY} is provided for those
8668 trying to debug such code.
8669 The choice of implementation seems
8670 unlikely to affect code (compiled in other languages) that interfaces
8671 to such code.
8672
8673 @code{g77} compiles exactly one public procedure for the primary entry
8674 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
8675 That is, in terms of the public interface, there is no difference
8676 between
8677
8678 @example
8679 SUBROUTINE X
8680 END
8681 SUBROUTINE Y
8682 END
8683 @end example
8684
8685 @noindent
8686 and:
8687
8688 @example
8689 SUBROUTINE X
8690 ENTRY Y
8691 END
8692 @end example
8693
8694 The difference between the above two cases lies in the code compiled
8695 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
8696 for the second case, an extra internal procedure is compiled.
8697
8698 For every Fortran procedure with at least one @code{ENTRY}
8699 statement, @code{g77} compiles an extra procedure
8700 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
8701 the name of the primary entry point (which, in the above case,
8702 using the standard compiler options, would be @samp{x_} in C).
8703
8704 This extra procedure is compiled as a private procedure---that is,
8705 a procedure not accessible by name to separately compiled modules.
8706 It contains all the code in the program unit, including the code
8707 for the primary entry point plus for every entry point.
8708 (The code for each public procedure is quite short, and explained later.)
8709
8710 The extra procedure has some other interesting characteristics.
8711
8712 The argument list for this procedure is invented by @code{g77}.
8713 It contains
8714 a single integer argument named @samp{__g77_which_entrypoint},
8715 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
8716 entry point index---0 for the primary entry point, 1 for the
8717 first entry point (the first @code{ENTRY} statement encountered), 2 for
8718 the second entry point, and so on.
8719
8720 It also contains, for functions returning @code{CHARACTER} and
8721 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
8722 and for functions returning different types among the
8723 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
8724 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
8725 is expected at run time to contain a pointer to where to store
8726 the result of the entry point.
8727 For @code{CHARACTER} functions, this
8728 storage area is an array of the appropriate number of characters;
8729 for @code{COMPLEX} functions, it is the appropriate area for the return
8730 type; for multiple-return-type functions, it is a union of all the supported return
8731 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
8732 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
8733 is not supported by @code{g77}).
8734
8735 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
8736 by yet another argument named @samp{__g77_length} that, at run time,
8737 specifies the caller's expected length of the returned value.
8738 Note that only @code{CHARACTER*(*)} functions and entry points actually
8739 make use of this argument, even though it is always passed by
8740 all callers of public @code{CHARACTER} functions (since the caller does not
8741 generally know whether such a function is @code{CHARACTER*(*)} or whether
8742 there are any other callers that don't have that information).
8743
8744 The rest of the argument list is the union of all the arguments
8745 specified for all the entry points (in their usual forms, e.g.
8746 @code{CHARACTER} arguments have extra length arguments, all appended at
8747 the end of this list).
8748 This is considered the ``master list'' of
8749 arguments.
8750
8751 The code for this procedure has, before the code for the first
8752 executable statement, code much like that for the following Fortran
8753 statement:
8754
8755 @smallexample
8756 GOTO (100000,100001,100002), __g77_which_entrypoint
8757 100000 @dots{}code for primary entry point@dots{}
8758 100001 @dots{}code immediately following first ENTRY statement@dots{}
8759 100002 @dots{}code immediately following second ENTRY statement@dots{}
8760 @end smallexample
8761
8762 @noindent
8763 (Note that invalid Fortran statement labels and variable names
8764 are used in the above example to highlight the fact that it
8765 represents code generated by the @code{g77} internals, not code to be
8766 written by the user.)
8767
8768 It is this code that, when the procedure is called, picks which
8769 entry point to start executing.
8770
8771 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
8772 example), those procedures are fairly simple.
8773 Their interfaces
8774 are just like they would be if they were self-contained procedures
8775 (without @code{ENTRY}), of course, since that is what the callers
8776 expect.
8777 Their code consists of simply calling the private
8778 procedure, described above, with the appropriate extra arguments
8779 (the entry point index, and perhaps a pointer to a multiple-type-
8780 return variable, local to the public procedure, that contains
8781 all the supported returnable non-character types).
8782 For arguments
8783 that are not listed for a given entry point that are listed for
8784 other entry points, and therefore that are in the ``master list''
8785 for the private procedure, null pointers (in C, the @code{NULL} macro)
8786 are passed.
8787 Also, for entry points that are part of a multiple-type-
8788 returning function, code is compiled after the call of the private
8789 procedure to extract from the multi-type union the appropriate result,
8790 depending on the type of the entry point in question, returning
8791 that result to the original caller.
8792
8793 When debugging a procedure containing alternate entry points, you
8794 can either set a break point on the public procedure itself (e.g.
8795 a break point on @samp{X} or @samp{Y}) or on the private procedure that
8796 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
8797 If you do the former, you should use the debugger's command to
8798 ``step into'' the called procedure to get to the actual code; with
8799 the latter approach, the break point leaves you right at the
8800 actual code, skipping over the public entry point and its call
8801 to the private procedure (unless you have set a break point there
8802 as well, of course).
8803
8804 Further, the list of dummy arguments that is visible when the
8805 private procedure is active is going to be the expanded version
8806 of the list for whichever particular entry point is active,
8807 as explained above, and the way in which return values are
8808 handled might well be different from how they would be handled
8809 for an equivalent single-entry function.
8810
8811 @node Alternate Returns
8812 @section Alternate Returns (SUBROUTINE and RETURN)
8813 @cindex subroutines
8814 @cindex alternate returns
8815 @cindex SUBROUTINE statement
8816 @cindex statements, SUBROUTINE
8817 @cindex RETURN statement
8818 @cindex statements, RETURN
8819
8820 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
8821 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
8822 the C @code{int} type.
8823 The actual alternate-return arguments are omitted from the calling sequence.
8824 Instead, the caller uses
8825 the return value to do a rough equivalent of the Fortran
8826 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
8827 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
8828 function), and the callee just returns whatever integer
8829 is specified in the @code{RETURN} statement for the subroutine
8830 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
8831 by @samp{RETURN}
8832 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
8833
8834 @node Assigned Statement Labels
8835 @section Assigned Statement Labels (ASSIGN and GOTO)
8836 @cindex assigned statement labels
8837 @cindex statement labels, assigned
8838 @cindex ASSIGN statement
8839 @cindex statements, ASSIGN
8840 @cindex GOTO statement
8841 @cindex statements, GOTO
8842
8843 For portability to machines where a pointer (such as to a label,
8844 which is how @code{g77} implements @code{ASSIGN} and its relatives,
8845 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
8846 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
8847 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
8848 than it does the numerical value in that variable, unless the
8849 variable is wide enough (can hold enough bits).
8850
8851 In particular, while @code{g77} implements
8852
8853 @example
8854 I = 10
8855 @end example
8856
8857 @noindent
8858 as, in C notation, @samp{i = 10;}, it implements
8859
8860 @example
8861 ASSIGN 10 TO I
8862 @end example
8863
8864 @noindent
8865 as, in GNU's extended C notation (for the label syntax),
8866 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
8867 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
8868 actually generate the name @samp{L10} or any other name like that,
8869 since debuggers cannot access labels anyway).
8870
8871 While this currently means that an @code{ASSIGN} statement does not
8872 overwrite the numeric contents of its target variable, @emph{do not}
8873 write any code depending on this feature.
8874 @code{g77} has already changed this implementation across
8875 versions and might do so in the future.
8876 This information is provided only to make debugging Fortran programs
8877 compiled with the current version of @code{g77} somewhat easier.
8878 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
8879 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
8880 means @code{g77} has decided it can store the pointer to the label directly
8881 into @samp{I} itself.
8882
8883 @xref{Ugly Assigned Labels}, for information on a command-line option
8884 to force @code{g77} to use the same storage for both normal and
8885 assigned-label uses of a variable.
8886
8887 @node Run-time Library Errors
8888 @section Run-time Library Errors
8889 @cindex IOSTAT=
8890 @cindex error values
8891 @cindex error messages
8892 @cindex messages, run-time
8893 @cindex I/O, errors
8894
8895 The @code{libf2c} library currently has the following table to relate
8896 error code numbers, returned in @code{IOSTAT=} variables, to messages.
8897 This information should, in future versions of this document, be
8898 expanded upon to include detailed descriptions of each message.
8899
8900 In line with good coding practices, any of the numbers in the
8901 list below should @emph{not} be directly written into Fortran
8902 code you write.
8903 Instead, make a separate @code{INCLUDE} file that defines
8904 @code{PARAMETER} names for them, and use those in your code,
8905 so you can more easily change the actual numbers in the future.
8906
8907 The information below is culled from the definition
8908 of @samp{F_err} in @file{f/runtime/libI77/err.c} in the
8909 @code{g77} source tree.
8910
8911 @smallexample
8912 100: "error in format"
8913 101: "illegal unit number"
8914 102: "formatted io not allowed"
8915 103: "unformatted io not allowed"
8916 104: "direct io not allowed"
8917 105: "sequential io not allowed"
8918 106: "can't backspace file"
8919 107: "null file name"
8920 108: "can't stat file"
8921 109: "unit not connected"
8922 110: "off end of record"
8923 111: "truncation failed in endfile"
8924 112: "incomprehensible list input"
8925 113: "out of free space"
8926 114: "unit not connected"
8927 115: "read unexpected character"
8928 116: "bad logical input field"
8929 117: "bad variable type"
8930 118: "bad namelist name"
8931 119: "variable not in namelist"
8932 120: "no end record"
8933 121: "variable count incorrect"
8934 122: "subscript for scalar variable"
8935 123: "invalid array section"
8936 124: "substring out of bounds"
8937 125: "subscript out of bounds"
8938 126: "can't read file"
8939 127: "can't write file"
8940 128: "'new' file exists"
8941 129: "can't append to file"
8942 130: "non-positive record number"
8943 131: "I/O started while already doing I/O"
8944 @end smallexample
8945
8946 @node Collected Fortran Wisdom
8947 @chapter Collected Fortran Wisdom
8948 @cindex wisdom
8949 @cindex legacy code
8950 @cindex code, legacy
8951 @cindex writing code
8952 @cindex code, writing
8953
8954 Most users of @code{g77} can be divided into two camps:
8955
8956 @itemize @bullet
8957 @item
8958 Those writing new Fortran code to be compiled by @code{g77}.
8959
8960 @item
8961 Those using @code{g77} to compile existing, ``legacy'' code.
8962 @end itemize
8963
8964 Users writing new code generally understand most of the necessary
8965 aspects of Fortran to write ``mainstream'' code, but often need
8966 help deciding how to handle problems, such as the construction
8967 of libraries containing @code{BLOCK DATA}.
8968
8969 Users dealing with ``legacy'' code sometimes don't have much
8970 experience with Fortran, but believe that the code they're compiling
8971 already works when compiled by other compilers (and might
8972 not understand why, as is sometimes the case, it doesn't work
8973 when compiled by @code{g77}).
8974
8975 The following information is designed to help users do a better job
8976 coping with existing, ``legacy'' Fortran code, and with writing
8977 new code as well.
8978
8979 @menu
8980 * Advantages Over f2c:: If @code{f2c} is so great, why @code{g77}?
8981 * Block Data and Libraries:: How @code{g77} solves a common problem.
8982 * Loops:: Fortran @code{DO} loops surprise many people.
8983 * Working Programs:: Getting programs to work should be done first.
8984 * Overly Convenient Options:: Temptations to avoid, habits to not form.
8985 * Faster Programs:: Everybody wants these, but at what cost?
8986 @end menu
8987
8988 @node Advantages Over f2c
8989 @section Advantages Over f2c
8990
8991 Without @code{f2c}, @code{g77} would have taken much longer to
8992 do and probably not been as good for quite a while.
8993 Sometimes people who notice how much @code{g77} depends on, and
8994 documents encouragement to use, @code{f2c} ask why @code{g77}
8995 was created if @code{f2c} already existed.
8996
8997 This section gives some basic answers to these questions, though it
8998 is not intended to be comprehensive.
8999
9000 @menu
9001 * Language Extensions:: Features used by Fortran code.
9002 * Compiler Options:: Features helpful during development.
9003 * Compiler Speed:: Speed of the compilation process.
9004 * Program Speed:: Speed of the generated, optimized code.
9005 * Ease of Debugging:: Debugging ease-of-use at the source level.
9006 * Character and Hollerith Constants:: A byte saved is a byte earned.
9007 @end menu
9008
9009 @node Language Extensions
9010 @subsection Language Extensions
9011
9012 @code{g77} offers several extensions to the Fortran language that @code{f2c}
9013 doesn't.
9014
9015 However, @code{f2c} offers a few that @code{g77} doesn't, like
9016 fairly complete support for @code{INTEGER*2}.
9017 It is expected that @code{g77} will offer some or all of these missing
9018 features at some time in the future.
9019 (Version 0.5.18 of @code{g77} offers some rudimentary support for some
9020 of these features.)
9021
9022 @node Compiler Options
9023 @subsection Compiler Options
9024
9025 @code{g77} offers a whole bunch of compiler options that @code{f2c} doesn't.
9026
9027 However, @code{f2c} offers a few that @code{g77} doesn't, like an
9028 option to generate code to check array subscripts at run time.
9029 It is expected that @code{g77} will offer some or all of these
9030 missing options at some time in the future.
9031
9032 @node Compiler Speed
9033 @subsection Compiler Speed
9034
9035 Saving the steps of writing and then rereading C code is a big reason
9036 why @code{g77} should be able to compile code much faster than using
9037 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
9038
9039 However, due to @code{g77}'s youth, lots of self-checking is still being
9040 performed.
9041 As a result, this improvement is as yet unrealized
9042 (though the potential seems to be there for quite a big speedup
9043 in the future).
9044 It is possible that, as of version 0.5.18, @code{g77}
9045 is noticeably faster compiling many Fortran source files than using
9046 @code{f2c} in conjunction with @code{gcc}.
9047
9048 @node Program Speed
9049 @subsection Program Speed
9050
9051 @code{g77} has the potential to better optimize code than @code{f2c},
9052 even when @code{gcc} is used to compile the output of @code{f2c},
9053 because @code{f2c} must necessarily
9054 translate Fortran into a somewhat lower-level language (C) that cannot
9055 preserve all the information that is potentially useful for optimization,
9056 while @code{g77} can gather, preserve, and transmit that information directly
9057 to the GBE.
9058
9059 For example, @code{g77} implements @code{ASSIGN} and assigned
9060 @code{GOTO} using direct assignment of pointers to labels and direct
9061 jumps to labels, whereas @code{f2c} maps the assigned labels to
9062 integer values and then uses a C @code{switch} statement to encode
9063 the assigned @code{GOTO} statements.
9064
9065 However, as is typical, theory and reality don't quite match, at least
9066 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
9067 can generate code that is faster than @code{g77}.
9068
9069 Version 0.5.18 of @code{g77} offered default
9070 settings and options, via patches to the @code{gcc}
9071 back end, that allow for better program speed, though
9072 some of these improvements also affected the performance
9073 of programs translated by @code{f2c} and then compiled
9074 by @code{g77}'s version of @code{gcc}.
9075
9076 Version 0.5.20 of @code{g77} offers further performance
9077 improvements, at least one of which (alias analysis) is
9078 not generally applicable to @code{f2c} (though @code{f2c}
9079 could presumably be changed to also take advantage of
9080 this new capability of the @code{gcc} back end, assuming
9081 this is made available in an upcoming release of @code{gcc}).
9082
9083 @node Ease of Debugging
9084 @subsection Ease of Debugging
9085
9086 Because @code{g77} compiles directly to assembler code like @code{gcc},
9087 instead of translating to an intermediate language (C) as does @code{f2c},
9088 support for debugging can be better for @code{g77} than @code{f2c}.
9089
9090 However, although @code{g77} might be somewhat more ``native'' in terms of
9091 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
9092 of things ``not quite right''.
9093 Many of the important ones should be resolved in the near future.
9094
9095 For example, @code{g77} doesn't have to worry about reserved names
9096 like @code{f2c} does.
9097 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
9098 translate this to something @emph{other} than
9099 @samp{for = while;}, because C reserves those words.
9100
9101 However, @code{g77} does still uses things like an extra level of indirection
9102 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
9103 yet support multiple entry points.
9104
9105 Another example is that, given
9106
9107 @smallexample
9108 COMMON A, B
9109 EQUIVALENCE (B, C)
9110 @end smallexample
9111
9112 @noindent
9113 the @code{g77} user should be able to access the variables directly, by name,
9114 without having to traverse C-like structures and unions, while @code{f2c}
9115 is unlikely to ever offer this ability (due to limitations in the
9116 C language).
9117
9118 However, due to apparent bugs in the back end, @code{g77} currently doesn't
9119 take advantage of this facility at all---it doesn't emit any debugging
9120 information for @code{COMMON} and @code{EQUIVALENCE} areas,
9121 other than information
9122 on the array of @code{char} it creates (and, in the case
9123 of local @code{EQUIVALENCE}, names) for each such area.
9124
9125 Yet another example is arrays.
9126 @code{g77} represents them to the debugger
9127 using the same ``dimensionality'' as in the source code, while @code{f2c}
9128 must necessarily convert them all to one-dimensional arrays to fit
9129 into the confines of the C language.
9130 However, the level of support
9131 offered by debuggers for interactive Fortran-style access to arrays
9132 as compiled by @code{g77} can vary widely.
9133 In some cases, it can actually
9134 be an advantage that @code{f2c} converts everything to widely supported
9135 C semantics.
9136
9137 In fairness, @code{g77} could do many of the things @code{f2c} does
9138 to get things working at least as well as @code{f2c}---for now,
9139 the developers prefer making @code{g77} work the
9140 way they think it is supposed to, and finding help improving the
9141 other products (the back end of @code{gcc}; @code{gdb}; and so on)
9142 to get things working properly.
9143
9144 @node Character and Hollerith Constants
9145 @subsection Character and Hollerith Constants
9146 @cindex character constants
9147 @cindex constants, character
9148 @cindex Hollerith constants
9149 @cindex constants, Hollerith
9150 @cindex trailing null byte
9151 @cindex null byte, trailing
9152 @cindex zero byte, trailing
9153
9154 To avoid the extensive hassle that would be needed to avoid this,
9155 @code{f2c} uses C character constants to encode character and Hollerith
9156 constants.
9157 That means a constant like @samp{'HELLO'} is translated to
9158 @samp{"hello"} in C, which further means that an extra null byte is
9159 present at the end of the constant.
9160 This null byte is superfluous.
9161
9162 @code{g77} does not generate such null bytes.
9163 This represents significant
9164 savings of resources, such as on systems where @file{/dev/null} or
9165 @file{/dev/zero} represent bottlenecks in the systems' performance,
9166 because @code{g77} simply asks for fewer zeros from the operating
9167 system than @code{f2c}.
9168
9169 @node Block Data and Libraries
9170 @section Block Data and Libraries
9171 @cindex block data and libraries
9172 @cindex BLOCK DATA statement
9173 @cindex statements, BLOCK DATA
9174 @cindex libraries, containing BLOCK DATA
9175 @cindex @code{f2c} compatibility
9176 @cindex compatibility, @code{f2c}
9177
9178 To ensure that block data program units are linked, especially a concern
9179 when they are put into libraries, give each one a name (as in
9180 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
9181 statement in every program unit that uses any common block
9182 initialized by the corresponding @code{BLOCK DATA}.
9183 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
9184 @code{SUBROUTINE},
9185 that is, it generates an actual procedure having the appropriate name.
9186 The procedure does nothing but return immediately if it happens to be
9187 called.
9188 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
9189 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
9190 in the program and ensures that by generating a
9191 reference to it so the linker will make sure it is present.
9192 (Specifically, @code{g77} outputs in the data section a static pointer to the
9193 external name @samp{FOO}.)
9194
9195 The implementation @code{g77} currently uses to make this work is
9196 one of the few things not compatible with @code{f2c} as currently
9197 shipped.
9198 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
9199 issue a warning that @samp{FOO} is not otherwise referenced, and for
9200 @samp{BLOCK DATA FOO}, f2c doesn't generate a dummy procedure with the
9201 name @samp{FOO}.
9202 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
9203 this particular case.
9204 If you use f2c to compile @samp{BLOCK DATA FOO},
9205 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
9206 will result in an unresolved reference when linked.
9207 If you do the
9208 opposite, then @samp{FOO} might not be linked in under various
9209 circumstances (such as when @samp{FOO} is in a library, or you're
9210 using a ``clever'' linker---so clever, it produces a broken program
9211 with little or no warning by omitting initializations of global data
9212 because they are contained in unreferenced procedures).
9213
9214 The changes you make to your code to make @code{g77} handle this situation,
9215 however, appear to be a widely portable way to handle it.
9216 That is, many systems permit it (as they should, since the
9217 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
9218 is a block data program unit), and of the ones
9219 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
9220 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
9221 program units.
9222
9223 Here is the recommended approach to modifying a program containing
9224 a program unit such as the following:
9225
9226 @smallexample
9227 BLOCK DATA FOO
9228 COMMON /VARS/ X, Y, Z
9229 DATA X, Y, Z / 3., 4., 5. /
9230 END
9231 @end smallexample
9232
9233 @noindent
9234 If the above program unit might be placed in a library module, then
9235 ensure that every program unit in every program that references that
9236 particular @code{COMMON} area uses the @code{EXTERNAL} statement
9237 to force the area to be initialized.
9238
9239 For example, change a program unit that starts with
9240
9241 @smallexample
9242 INTEGER FUNCTION CURX()
9243 COMMON /VARS/ X, Y, Z
9244 CURX = X
9245 END
9246 @end smallexample
9247
9248 @noindent
9249 so that it uses the @code{EXTERNAL} statement, as in:
9250
9251 @smallexample
9252 INTEGER FUNCTION CURX()
9253 COMMON /VARS/ X, Y, Z
9254 EXTERNAL FOO
9255 CURX = X
9256 END
9257 @end smallexample
9258
9259 @noindent
9260 That way, @samp{CURX} is compiled by @code{g77} (and many other
9261 compilers) so that the linker knows it must include @samp{FOO},
9262 the @code{BLOCK DATA} program unit that sets the initial values
9263 for the variables in @samp{VAR}, in the executable program.
9264
9265 @node Loops
9266 @section Loops
9267 @cindex DO statement
9268 @cindex statements, DO
9269 @cindex trips, number of
9270 @cindex number of trips
9271
9272 The meaning of a @code{DO} loop in Fortran is precisely specified
9273 in the Fortran standard@dots{}and is quite different from what
9274 many programmers might expect.
9275
9276 In particular, Fortran @code{DO} loops are implemented as if
9277 the number of trips through the loop is calculated @emph{before}
9278 the loop is entered.
9279
9280 The number of trips for a loop is calculated from the @var{start},
9281 @var{end}, and @var{increment} values specified in a statement such as:
9282
9283 @smallexample
9284 DO @var{iter} = @var{start}, @var{end}, @var{increment}
9285 @end smallexample
9286
9287 @noindent
9288 The trip count is evaluated using a fairly simple formula
9289 based on the three values following the @samp{=} in the
9290 statement, and it is that trip count that is effectively
9291 decremented during each iteration of the loop.
9292 If, at the beginning of an iteration of the loop, the
9293 trip count is zero or negative, the loop terminates.
9294 The per-loop-iteration modifications to @var{iter} are not
9295 related to determining whether to terminate the loop.
9296
9297 There are two important things to remember about the trip
9298 count:
9299
9300 @itemize @bullet
9301 @item
9302 It can be @emph{negative}, in which case it is
9303 treated as if it was zero---meaning the loop is
9304 not executed at all.
9305
9306 @item
9307 The type used to @emph{calculate} the trip count
9308 is the same type as @var{iter}, but the final
9309 calculation, and thus the type of the trip
9310 count itself, always is @code{INTEGER(KIND=1)}.
9311 @end itemize
9312
9313 These two items mean that there are loops that cannot
9314 be written in straightforward fashion using the Fortran @code{DO}.
9315
9316 For example, on a system with the canonical 32-bit two's-complement
9317 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
9318
9319 @smallexample
9320 DO I = -2000000000, 2000000000
9321 @end smallexample
9322
9323 @noindent
9324 Although the @var{start} and @var{end} values are well within
9325 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
9326 The expected trip count is 40000000001, which is outside
9327 the range of @code{INTEGER(KIND=1)} on many systems.
9328
9329 Instead, the above loop should be constructed this way:
9330
9331 @smallexample
9332 I = -2000000000
9333 DO
9334 IF (I .GT. 2000000000) EXIT
9335 @dots{}
9336 I = I + 1
9337 END DO
9338 @end smallexample
9339
9340 @noindent
9341 The simple @code{DO} construct and the @code{EXIT} statement
9342 (used to leave the innermost loop)
9343 are F90 features that @code{g77} supports.
9344
9345 Some Fortran compilers have buggy implementations of @code{DO},
9346 in that they don't follow the standard.
9347 They implement @code{DO} as a straightforward translation
9348 to what, in C, would be a @code{for} statement.
9349 Instead of creating a temporary variable to hold the trip count
9350 as calculated at run time, these compilers
9351 use the iteration variable @var{iter} to control
9352 whether the loop continues at each iteration.
9353
9354 The bug in such an implementation shows up when the
9355 trip count is within the range of the type of @var{iter},
9356 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
9357 exceeds that range. For example:
9358
9359 @smallexample
9360 DO I = 2147483600, 2147483647
9361 @end smallexample
9362
9363 @noindent
9364 A loop started by the above statement will work as implemented
9365 by @code{g77}, but the use, by some compilers, of a
9366 more C-like implementation akin to
9367
9368 @smallexample
9369 for (i = 2147483600; i <= 2147483647; ++i)
9370 @end smallexample
9371
9372 @noindent
9373 produces a loop that does not terminate, because @samp{i}
9374 can never be greater than 2147483647, since incrementing it
9375 beyond that value overflows @samp{i}, setting it to -2147483648.
9376 This is a large, negative number that still is less than 2147483647.
9377
9378 Another example of unexpected behavior of @code{DO} involves
9379 using a nonintegral iteration variable @var{iter}, that is,
9380 a @code{REAL} variable.
9381 Consider the following program:
9382
9383 @smallexample
9384 DATA BEGIN, END, STEP /.1, .31, .007/
9385 DO 10 R = BEGIN, END, STEP
9386 IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
9387 PRINT *,R
9388 10 CONTINUE
9389 PRINT *,'LAST = ',R
9390 IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
9391 END
9392 @end smallexample
9393
9394 @noindent
9395 A C-like view of @code{DO} would hold that the two ``exclamatory''
9396 @code{PRINT} statements are never executed.
9397 However, this is the output of running the above program
9398 as compiled by @code{g77} on a GNU/Linux ix86 system:
9399
9400 @smallexample
9401 .100000001
9402 .107000001
9403 .114
9404 .120999999
9405 @dots{}
9406 .289000005
9407 .296000004
9408 .303000003
9409 LAST = .310000002
9410 .310000002 .LE. .310000002!!
9411 @end smallexample
9412
9413 Note that one of the two checks in the program turned up
9414 an apparent violation of the programmer's expectation---yet,
9415 the loop is correctly implemented by @code{g77}, in that
9416 it has 30 iterations.
9417 This trip count of 30 is correct when evaluated using
9418 the floating-point representations for the @var{begin},
9419 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
9420 ix86 are used.
9421 On other systems, an apparently more accurate trip count
9422 of 31 might result, but, nevertheless, @code{g77} is
9423 faithfully following the Fortran standard, and the result
9424 is not what the author of the sample program above
9425 apparently expected.
9426 (Such other systems might, for different values in the @code{DATA}
9427 statement, violate the other programmer's expectation,
9428 for example.)
9429
9430 Due to this combination of imprecise representation
9431 of floating-point values and the often-misunderstood
9432 interpretation of @code{DO} by standard-conforming
9433 compilers such as @code{g77}, use of @code{DO} loops
9434 with @code{REAL} iteration
9435 variables is not recommended.
9436 Such use can be caught by specifying @samp{-Wsurprising}.
9437 @xref{Warning Options}, for more information on this
9438 option.
9439
9440 @node Working Programs
9441 @section Working Programs
9442
9443 Getting Fortran programs to work in the first place can be
9444 quite a challenge---even when the programs already work on
9445 other systems, or when using other compilers.
9446
9447 @code{g77} offers some facilities that might be useful for
9448 tracking down bugs in such programs.
9449
9450 @menu
9451 * Not My Type::
9452 * Variables Assumed To Be Zero::
9453 * Variables Assumed To Be Saved::
9454 * Unwanted Variables::
9455 * Unused Arguments::
9456 * Surprising Interpretations of Code::
9457 * Aliasing Assumed To Work::
9458 * Output Assumed To Flush::
9459 * Large File Unit Numbers::
9460 @end menu
9461
9462 @node Not My Type
9463 @subsection Not My Type
9464 @cindex mistyped variables
9465 @cindex variables, mistyped
9466 @cindex mistyped functions
9467 @cindex functions, mistyped
9468 @cindex implicit typing
9469
9470 A fruitful source of bugs in Fortran source code is use, or
9471 mis-use, of Fortran's implicit-typing feature, whereby the
9472 type of a variable, array, or function is determined by the
9473 first character of its name.
9474
9475 Simple cases of this include statements like @samp{LOGX=9.227},
9476 without a statement such as @samp{REAL LOGX}.
9477 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
9478 type, with the result of the assignment being that it is given
9479 the value @samp{9}.
9480
9481 More involved cases include a function that is defined starting
9482 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
9483 Any caller of this function that does not also declare @samp{IPS}
9484 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
9485 is likely to assume it returns
9486 @code{INTEGER}, or some other type, leading to invalid results
9487 or even program crashes.
9488
9489 The @samp{-Wimplicit} option might catch failures to
9490 properly specify the types of
9491 variables, arrays, and functions in the code.
9492
9493 However, in code that makes heavy use of Fortran's
9494 implicit-typing facility, this option might produce so
9495 many warnings about cases that are working, it would be
9496 hard to find the one or two that represent bugs.
9497 This is why so many experienced Fortran programmers strongly
9498 recommend widespread use of the @code{IMPLICIT NONE} statement,
9499 despite it not being standard FORTRAN 77, to completely turn
9500 off implicit typing.
9501 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
9502 FORTRAN 77 compilers.)
9503
9504 Note that @samp{-Wimplicit} catches only implicit typing of
9505 @emph{names}.
9506 It does not catch implicit typing of expressions such
9507 as @samp{X**(2/3)}.
9508 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
9509 is equivalent to @samp{X**0}, due to the way Fortran expressions
9510 are given types and then evaluated.
9511 (In this particular case, the programmer probably wanted
9512 @samp{X**(2./3.)}.)
9513
9514 @node Variables Assumed To Be Zero
9515 @subsection Variables Assumed To Be Zero
9516 @cindex zero-initialized variables
9517 @cindex variables assumed to be zero
9518 @cindex uninitialized variables
9519
9520 Many Fortran programs were developed on systems that provided
9521 automatic initialization of all, or some, variables and arrays
9522 to zero.
9523 As a result, many of these programs depend, sometimes
9524 inadvertently, on this behavior, though to do so violates
9525 the Fortran standards.
9526
9527 You can ask @code{g77} for this behavior by specifying the
9528 @samp{-finit-local-zero} option when compiling Fortran code.
9529 (You might want to specify @samp{-fno-automatic} as well,
9530 to avoid code-size inflation for non-optimized compilations.)
9531
9532 Note that a program that works better when compiled with the
9533 @samp{-finit-local-zero} option
9534 is almost certainly depending on a particular system's,
9535 or compiler's, tendency to initialize some variables to zero.
9536 It might be worthwhile finding such cases and fixing them,
9537 using techniques such as compiling with the @samp{-O -Wuninitialized}
9538 options using @code{g77}.
9539
9540 @node Variables Assumed To Be Saved
9541 @subsection Variables Assumed To Be Saved
9542 @cindex variables retaining values across calls
9543 @cindex saved variables
9544 @cindex static variables
9545
9546 Many Fortran programs were developed on systems that
9547 saved the values of all, or some, variables and arrays
9548 across procedure calls.
9549 As a result, many of these programs depend, sometimes
9550 inadvertently, on being able to assign a value to a
9551 variable, perform a @code{RETURN} to a calling procedure,
9552 and, upon subsequent invocation, reference the previously
9553 assigned variable to obtain the value.
9554
9555 They expect this despite not using the @code{SAVE} statement
9556 to specify that the value in a variable is expected to survive
9557 procedure returns and calls.
9558 Depending on variables and arrays to retain values across
9559 procedure calls without using @code{SAVE} to require it violates
9560 the Fortran standards.
9561
9562 You can ask @code{g77} to assume @code{SAVE} is specified for all
9563 relevant (local) variables and arrays by using the
9564 @samp{-fno-automatic} option.
9565
9566 Note that a program that works better when compiled with the
9567 @samp{-fno-automatic} option
9568 is almost certainly depending on not having to use
9569 the @code{SAVE} statement as required by the Fortran standard.
9570 It might be worthwhile finding such cases and fixing them,
9571 using techniques such as compiling with the @samp{-O -Wuninitialized}
9572 options using @code{g77}.
9573
9574 @node Unwanted Variables
9575 @subsection Unwanted Variables
9576
9577 The @samp{-Wunused} option can find bugs involving
9578 implicit typing, sometimes
9579 more easily than using @samp{-Wimplicit} in code that makes
9580 heavy use of implicit typing.
9581 An unused variable or array might indicate that the
9582 spelling for its declaration is different from that of
9583 its intended uses.
9584
9585 Other than cases involving typos, unused variables rarely
9586 indicate actual bugs in a program.
9587 However, investigating such cases thoroughly has, on occasion,
9588 led to the discovery of code that had not been completely
9589 written---where the programmer wrote declarations as needed
9590 for the whole algorithm, wrote some or even most of the code
9591 for that algorithm, then got distracted and forgot that the
9592 job was not complete.
9593
9594 @node Unused Arguments
9595 @subsection Unused Arguments
9596 @cindex unused arguments
9597 @cindex arguments, unused
9598
9599 As with unused variables, It is possible that unused arguments
9600 to a procedure might indicate a bug.
9601 Compile with @samp{-W -Wunused} option to catch cases of
9602 unused arguments.
9603
9604 Note that @samp{-W} also enables warnings regarding overflow
9605 of floating-point constants under certain circumstances.
9606
9607 @node Surprising Interpretations of Code
9608 @subsection Surprising Interpretations of Code
9609
9610 The @samp{-Wsuprising} option can help find bugs involving
9611 expression evaluation or in
9612 the way @code{DO} loops with non-integral iteration variables
9613 are handled.
9614 Cases found by this option might indicate a difference of
9615 interpretation between the author of the code involved, and
9616 a standard-conforming compiler such as @code{g77}.
9617 Such a difference might produce actual bugs.
9618
9619 In any case, changing the code to explicitly do what the
9620 programmer might have expected it to do, so @code{g77} and
9621 other compilers are more likely to follow the programmer's
9622 expectations, might be worthwhile, especially if such changes
9623 make the program work better.
9624
9625 @node Aliasing Assumed To Work
9626 @subsection Aliasing Assumed To Work
9627 @cindex -falias-check option
9628 @cindex options, -falias-check
9629 @cindex -fargument-alias option
9630 @cindex options, -fargument-alias
9631 @cindex -fargument-noalias option
9632 @cindex options, -fargument-noalias
9633 @cindex -fno-argument-noalias-global option
9634 @cindex options, -fno-argument-noalias-global
9635 @cindex aliasing
9636 @cindex anti-aliasing
9637 @cindex overlapping arguments
9638 @cindex overlays
9639 @cindex association, storage
9640 @cindex storage association
9641 @cindex scheduling of reads and writes
9642 @cindex reads and writes, scheduling
9643
9644 The @samp{-falias-check}, @samp{-fargument-alias},
9645 @samp{-fargument-noalias},
9646 and @samp{-fno-argument-noalias-global} options,
9647 introduced in version 0.5.20 and
9648 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
9649 control the assumptions regarding aliasing
9650 (overlapping)
9651 of writes and reads to main memory (core) made
9652 by the @code{gcc} back end.
9653
9654 They are effective only when compiling with @samp{-O} (specifying
9655 any level other than @samp{-O0}) or with @samp{-falias-check}.
9656
9657 The default for Fortran code is @samp{-fargument-noalias-global}.
9658 (The default for C code and code written in other C-based languages
9659 is @samp{-fargument-alias}.
9660 These defaults apply regardless of whether you use @code{g77} or
9661 @code{gcc} to compile your code.)
9662
9663 Note that, on some systems, compiling with @samp{-fforce-addr} in
9664 effect can produce more optimal code when the default aliasing
9665 options are in effect (and when optimization is enabled).
9666
9667 If your program is not working when compiled with optimization,
9668 it is possible it is violating the Fortran standards (77 and 90)
9669 by relying on the ability to ``safely'' modify variables and
9670 arrays that are aliased, via procedure calls, to other variables
9671 and arrays, without using @code{EQUIVALENCE} to explicitly
9672 set up this kind of aliasing.
9673
9674 (The FORTRAN 77 standard's prohibition of this sort of
9675 overlap, generally referred to therein as ``storage
9676 assocation'', appears in Sections 15.9.3.6.
9677 This prohibition allows implementations, such as @code{g77},
9678 to, for example, implement the passing of procedures and
9679 even values in @code{COMMON} via copy operations into local,
9680 perhaps more efficiently accessed temporaries at entry to a
9681 procedure, and, where appropriate, via copy operations back
9682 out to their original locations in memory at exit from that
9683 procedure, without having to take into consideration the
9684 order in which the local copies are updated by the code,
9685 among other things.)
9686
9687 To test this hypothesis, try compiling your program with
9688 the @samp{-fargument-alias} option, which causes the
9689 compiler to revert to assumptions essentially the same as
9690 made by versions of @code{g77} prior to 0.5.20.
9691
9692 If the program works using this option, that strongly suggests
9693 that the bug is in your program.
9694 Finding and fixing the bug(s) should result in a program that
9695 is more standard-conforming and that can be compiled by @code{g77}
9696 in a way that results in a faster executable.
9697
9698 (You might want to try compiling with @samp{-fargument-noalias},
9699 a kind of half-way point, to see if the problem is limited to
9700 aliasing between dummy arguments and @code{COMMON} variables---this
9701 option assumes that such aliasing is not done, while still allowing
9702 aliasing among dummy arguments.)
9703
9704 An example of aliasing that is invalid according to the standards
9705 is shown in the following program, which might @emph{not} produce
9706 the expected results when executed:
9707
9708 @smallexample
9709 I = 1
9710 CALL FOO(I, I)
9711 PRINT *, I
9712 END
9713
9714 SUBROUTINE FOO(J, K)
9715 J = J + K
9716 K = J * K
9717 PRINT *, J, K
9718 END
9719 @end smallexample
9720
9721 The above program attempts to use the temporary aliasing of the
9722 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
9723 pathological behavior---the simultaneous changing of the values
9724 of @emph{both} @samp{J} and @samp{K} when either one of them
9725 is written.
9726
9727 The programmer likely expects the program to print these values:
9728
9729 @example
9730 2 4
9731 4
9732 @end example
9733
9734 However, since the program is not standard-conforming, an
9735 implementation's behavior when running it is undefined, because
9736 subroutine @samp{FOO} modifies at least one of the arguments,
9737 and they are aliased with each other.
9738 (Even if one of the assignment statements was deleted, the
9739 program would still violate these rules.
9740 This kind of on-the-fly aliasing is permitted by the standard
9741 only when none of the aliased items are defined, or written,
9742 while the aliasing is in effect.)
9743
9744 As a practical example, an optimizing compiler might schedule
9745 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
9746 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
9747 resulting in the following output:
9748
9749 @example
9750 2 2
9751 2
9752 @end example
9753
9754 Essentially, compilers are promised (by the standard and, therefore,
9755 by programmers who write code they claim to be standard-conforming)
9756 that if they cannot detect aliasing via static analysis of a single
9757 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
9758 such aliasing exists.
9759 In such cases, compilers are free to assume that an assignment to
9760 one variable will not change the value of another variable, allowing
9761 it to avoid generating code to re-read the value of the other
9762 variable, to re-schedule reads and writes, and so on, to produce
9763 a faster executable.
9764
9765 The same promise holds true for arrays (as seen by the called
9766 procedure)---an element of one dummy array cannot be aliased
9767 with, or overlap, any element of another dummy array or be
9768 in a @code{COMMON} area known to the procedure.
9769
9770 (These restrictions apply only when the procedure defines, or
9771 writes to, one of the aliased variables or arrays.)
9772
9773 Unfortunately, there is no way to find @emph{all} possible cases of
9774 violations of the prohibitions against aliasing in Fortran code.
9775 Static analysis is certainly imperfect, as is run-time analysis,
9776 since neither can catch all violations.
9777 (Static analysis can catch all likely violations, and some that
9778 might never actually happen, while run-time analysis can catch
9779 only those violations that actually happen during a particular
9780 run.
9781 Neither approach can cope with programs mixing Fortran code with
9782 routines written in other languages, however.)
9783
9784 Currently, @code{g77} provides neither static nor run-time facilities
9785 to detect any cases of this problem, although other products might.
9786 Run-time facilities are more likely to be offered by future
9787 versions of @code{g77}, though patches improving @code{g77} so that
9788 it provides either form of detection are welcome.
9789
9790 @node Output Assumed To Flush
9791 @subsection Output Assumed To Flush
9792 @cindex ALWAYS_FLUSH
9793 @cindex synchronous write errors
9794 @cindex disk full
9795 @cindex flushing output
9796 @cindex fflush()
9797 @cindex I/O, flushing
9798 @cindex output, flushing
9799 @cindex writes, flushing
9800 @cindex NFS
9801 @cindex network file system
9802
9803 For several versions prior to 0.5.20, @code{g77} configured its
9804 version of the @code{libf2c} run-time library so that one of
9805 its configuration macros, @samp{ALWAYS_FLUSH}, was defined.
9806
9807 This was done as a result of a belief that many programs expected
9808 output to be flushed to the operating system (under UNIX, via
9809 the @code{fflush()} library call) with the result that errors,
9810 such as disk full, would be immediately flagged via the
9811 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
9812
9813 Because of the adverse effects this approach had on the performance
9814 of many programs, @code{g77} no longer configures @code{libf2c}
9815 to always flush output.
9816
9817 If your program depends on this behavior, either insert the
9818 appropriate @samp{CALL FLUSH} statements, or modify the sources
9819 to the @code{libf2c}, rebuild and reinstall @code{g77}, and
9820 relink your programs with the modified library.
9821
9822 (Ideally, @code{libf2c} would offer the choice at run-time, so
9823 that a compile-time option to @code{g77} or @code{f2c} could
9824 result in generating the appropriate calls to flushing or
9825 non-flushing library routines.)
9826
9827 @xref{Always Flush Output}, for information on how to modify
9828 the @code{g77} source tree so that a version of @code{libf2c}
9829 can be built and installed with the @samp{ALWAYS_FLUSH} macro defined.
9830
9831 @node Large File Unit Numbers
9832 @subsection Large File Unit Numbers
9833 @cindex MXUNIT
9834 @cindex unit numbers
9835 @cindex maximum unit number
9836 @cindex illegal unit number
9837 @cindex increasing maximum unit number
9838
9839 If your program crashes at run time with a message including
9840 the text @samp{illegal unit number}, that probably is
9841 a message from the run-time library, @code{libf2c}, used, and
9842 distributed with, @code{g77}.
9843
9844 The message means that your program has attempted to use a
9845 file unit number that is out of the range accepted by
9846 @code{libf2c}.
9847 Normally, this range is 0 through 99, and the high end
9848 of the range is controlled by a @code{libf2c} source-file
9849 macro named @samp{MXUNIT}.
9850
9851 If you can easily change your program to use unit numbers
9852 in the range 0 through 99, you should do so.
9853
9854 Otherwise, see @ref{Larger File Unit Numbers}, for information on how
9855 to change @samp{MXUNIT} in @code{libf2c} so you can build and
9856 install a new version of @code{libf2c} that supports the larger
9857 unit numbers you need.
9858
9859 @emph{Note:} While @code{libf2c} places a limit on the range
9860 of Fortran file-unit numbers, the underlying library and operating
9861 system might impose different kinds of limits.
9862 For example, some systems limit the number of files simultaneously
9863 open by a running program.
9864 Information on how to increase these limits should be found
9865 in your system's documentation.
9866
9867 @node Overly Convenient Options
9868 @section Overly Convenient Command-line Options
9869 @cindex overly convenient options
9870 @cindex options, overly convenient
9871
9872 These options should be used only as a quick-and-dirty way to determine
9873 how well your program will run under different compilation models
9874 without having to change the source.
9875 Some are more problematic
9876 than others, depending on how portable and maintainable you want the
9877 program to be (and, of course, whether you are allowed to change it
9878 at all is crucial).
9879
9880 You should not continue to use these command-line options to compile
9881 a given program, but rather should make changes to the source code:
9882
9883 @table @code
9884 @cindex -finit-local-zero option
9885 @cindex options, -finit-local-zero
9886 @item -finit-local-zero
9887 (This option specifies that any uninitialized local variables
9888 and arrays have default initialization to binary zeros.)
9889
9890 Many other compilers do this automatically, which means lots of
9891 Fortran code developed with those compilers depends on it.
9892
9893 It is safer (and probably
9894 would produce a faster program) to find the variables and arrays that
9895 need such initialization and provide it explicitly via @code{DATA}, so that
9896 @samp{-finit-local-zero} is not needed.
9897
9898 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
9899 find likely candidates, but
9900 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
9901 or this technique won't work.
9902
9903 @cindex -fno-automatic option
9904 @cindex options, -fno-automatic
9905 @item -fno-automatic
9906 (This option specifies that all local variables and arrays
9907 are to be treated as if they were named in @code{SAVE} statements.)
9908
9909 Many other compilers do this automatically, which means lots of
9910 Fortran code developed with those compilers depends on it.
9911
9912 The effect of this is that all non-automatic variables and arrays
9913 are made static, that is, not placed on the stack or in heap storage.
9914 This might cause a buggy program to appear to work better.
9915 If so, rather than relying on this command-line option (and hoping all
9916 compilers provide the equivalent one), add @code{SAVE}
9917 statements to some or all program unit sources, as appropriate.
9918 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
9919 to find likely candidates, but
9920 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
9921 or this technique won't work.
9922
9923 The default is @samp{-fautomatic}, which tells @code{g77} to try
9924 and put variables and arrays on the stack (or in fast registers)
9925 where possible and reasonable.
9926 This tends to make programs faster.
9927
9928 @cindex automatic arrays
9929 @cindex arrays, automatic
9930 @emph{Note:} Automatic variables and arrays are not affected
9931 by this option.
9932 These are variables and arrays that are @emph{necessarily} automatic,
9933 either due to explicit statements, or due to the way they are
9934 declared.
9935 Examples include local variables and arrays not given the
9936 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
9937 and local arrays declared with non-constant bounds (automatic
9938 arrays).
9939 Currently, @code{g77} supports only automatic arrays, not
9940 @code{RECURSIVE} procedures or other means of explicitly
9941 specifying that variables or arrays are automatic.
9942
9943 @cindex -fugly option
9944 @cindex options, -fugly
9945 @item -fugly
9946 Fix the source code so that @samp{-fno-ugly} will work.
9947 Note that, for many programs, it is difficult to practically
9948 avoid using the features enabled via @samp{-fugly-init}, and these
9949 features pose the lowest risk of writing nonportable code, among the
9950 various ``ugly'' features.
9951
9952 @cindex -f@var{group}-intrinsics-hide option
9953 @cindex options, -f@var{group}-intrinsics-hide
9954 @item -f@var{group}-intrinsics-hide
9955 Change the source code to use @code{EXTERNAL} for any external procedure
9956 that might be the name of an intrinsic.
9957 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
9958 @end table
9959
9960 @node Faster Programs
9961 @section Faster Programs
9962 @cindex speeding up programs
9963 @cindex programs, speeding up
9964
9965 Aside from the usual @code{gcc} options, such as @samp{-O},
9966 @samp{-ffast-math}, and so on, consider trying some of the
9967 following approaches to speed up your program (once you get
9968 it working).
9969
9970 @menu
9971 * Aligned Data::
9972 * Prefer Automatic Uninitialized Variables::
9973 * Avoid f2c Compatibility::
9974 * Use Submodel Options::
9975 @end menu
9976
9977 @node Aligned Data
9978 @subsection Aligned Data
9979 @cindex data, aligned
9980 @cindex stack, aligned
9981 @cindex aligned data
9982 @cindex aligned stack
9983 @cindex Pentium optimizations
9984 @cindex optimizations, Pentium
9985
9986 On some systems, such as those with Pentium Pro CPUs, programs
9987 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
9988 might run much slower
9989 than possible due to the compiler not aligning these 64-bit
9990 values to 64-bit boundaries in memory.
9991 (The effect also is present, though
9992 to a lesser extent, on the 586 (Pentium) architecture.)
9993
9994 The Intel x86 architecture generally ensures that these programs will
9995 work on all its implementations,
9996 but particular implementations (such as Pentium Pro)
9997 perform better with more strict alignment.
9998 (Such behavior isn't unique to the Intel x86 architecture.)
9999 Other architectures might @emph{demand} 64-bit alignment
10000 of 64-bit data.
10001
10002 There are a variety of approaches to use to address this problem:
10003
10004 @itemize @bullet
10005 @item
10006 @cindex COMMON, layout
10007 @cindex layout of common blocks
10008 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
10009 that the variables and arrays with the widest alignment
10010 guidelines come first.
10011
10012 For example, on most systems, this would mean placing
10013 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
10014 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
10015 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
10016 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
10017 and @code{INTEGER(KIND=3)} entities.
10018
10019 The reason to use such placement is it makes it more likely
10020 that your data will be aligned properly, without requiring
10021 you to do detailed analysis of each aggregate (@code{COMMON}
10022 and @code{EQUIVALENCE}) area.
10023
10024 Specifically, on systems where the above guidelines are
10025 appropriate, placing @code{CHARACTER} entities before
10026 @code{REAL(KIND=2)} entities can work just as well,
10027 but only if the number of bytes occupied by the @code{CHARACTER}
10028 entities is divisible by the recommended alignment for
10029 @code{REAL(KIND=2)}.
10030
10031 By ordering the placement of entities in aggregate
10032 areas according to the simple guidelines above, you
10033 avoid having to carefully count the number of bytes
10034 occupied by each entity to determine whether the
10035 actual alignment of each subsequent entity meets the
10036 alignment guidelines for the type of that entity.
10037
10038 If you don't ensure correct alignment of @code{COMMON} elements, the
10039 compiler may be forced by some systems to violate the Fortran semantics by
10040 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
10041 If the unfortunate practice is employed of overlaying different types of
10042 data in the @code{COMMON} block, the different variants
10043 of this block may become misaligned with respect to each other.
10044 Even if your platform doesn't require strict alignment,
10045 @code{COMMON} should be laid out as above for portability.
10046 (Unfortunately the FORTRAN 77 standard didn't anticipate this
10047 possible requirement, which is compiler-independent on a given platform.)
10048
10049 @item
10050 @cindex -malign-double option
10051 @cindex options, -malign-double
10052 Use the (x86-specific) @samp{-malign-double} option when compiling
10053 programs for the Pentium and Pentium Pro architectures (called 586
10054 and 686 in the @code{gcc} configuration subsystem).
10055 The warning about this in the @code{gcc} manual isn't
10056 generally relevant to Fortran,
10057 but using it will force @code{COMMON} to be padded if necessary to align
10058 @code{DOUBLE PRECISION} data.
10059
10060 @item
10061 Ensure that @file{crt0.o} or @file{crt1.o}
10062 on your system guarantees a 64-bit
10063 aligned stack for @code{main()}.
10064 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
10065 but we don't know of any other x86 setups where it will be right.
10066 Read your system's documentation to determine if
10067 it is appropriate to upgrade to a more recent version
10068 to obtain the optimal alignment.
10069 @end itemize
10070
10071 Progress is being made on making this work
10072 ``out of the box'' on future versions of @code{g77},
10073 @code{gcc}, and some of the relevant operating systems
10074 (such as GNU/Linux).
10075
10076 @node Prefer Automatic Uninitialized Variables
10077 @subsection Prefer Automatic Uninitialized Variables
10078
10079 If you're using @samp{-fno-automatic} already, you probably
10080 should change your code to allow compilation with @samp{-fautomatic}
10081 (the default), to allow the program to run faster.
10082
10083 Similarly, you should be able to use @samp{-fno-init-local-zero}
10084 (the default) instead of @samp{-finit-local-zero}.
10085 This is because it is rare that every variable affected by these
10086 options in a given program actually needs to
10087 be so affected.
10088
10089 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
10090 every local non-automatic variable and array, affects even things like
10091 @code{DO} iteration
10092 variables, which rarely need to be @code{SAVE}d, and this often reduces
10093 run-time performances.
10094 Similarly, @samp{-fno-init-local-zero} forces such
10095 variables to be initialized to zero---when @code{SAVE}d (such as when
10096 @samp{-fno-automatic}), this by itself generally affects only
10097 startup time for a program, but when not @code{SAVE}d,
10098 it can slow down the procedure every time it is called.
10099
10100 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10101 for information on the @samp{-fno-automatic} and
10102 @samp{-finit-local-zero} options and how to convert
10103 their use into selective changes in your own code.
10104
10105 @node Avoid f2c Compatibility
10106 @subsection Avoid f2c Compatibility
10107 @cindex -fno-f2c option
10108 @cindex options, -fno-f2c
10109 @cindex @code{f2c} compatibility
10110 @cindex compatibility, @code{f2c}
10111
10112 If you aren't linking with any code compiled using
10113 @code{f2c}, try using the @samp{-fno-f2c} option when
10114 compiling @emph{all} the code in your program.
10115 (Note that @code{libf2c} is @emph{not} an example of code
10116 that is compiled using @code{f2c}---it is compiled by a C
10117 compiler, typically @code{gcc}.)
10118
10119 @node Use Submodel Options
10120 @subsection Use Submodel Options
10121 @cindex Pentium optimizations
10122 @cindex optimizations, Pentium
10123 @cindex 586/686 CPUs
10124 @cindex submodels
10125
10126 Using an appropriate @samp{-m} option to generate specific code for your
10127 CPU may be worthwhile, though it may mean the executable won't run on
10128 other versions of the CPU that don't support the same instruction set.
10129 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
10130 Porting GNU CC}.
10131
10132 For recent CPUs that don't have explicit support in
10133 the released version of @code{gcc}, it may still be possible to get
10134 improvements.
10135 For instance, the flags recommended for 586/686
10136 (Pentium(Pro)) chips for building the Linux kernel are:
10137
10138 @smallexample
10139 -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2
10140 -fomit-frame-pointer
10141 @end smallexample
10142
10143 @noindent @samp{-fomit-frame-pointer} will, however, inhibit debugging
10144 on x86 systems.
10145
10146 @node Trouble
10147 @chapter Known Causes of Trouble with GNU Fortran
10148 @cindex bugs, known
10149 @cindex installation trouble
10150 @cindex known causes of trouble
10151
10152 This section describes known problems that affect users of GNU Fortran.
10153 Most of these are not GNU Fortran bugs per se---if they were, we would
10154 fix them.
10155 But the result for a user might be like the result of a bug.
10156
10157 Some of these problems are due to bugs in other software, some are
10158 missing features that are too much work to add, and some are places
10159 where people's opinions differ as to what is best.
10160
10161 Information on bugs that show up when configuring, porting, building,
10162 or installing @code{g77} is not provided here.
10163 @xref{Problems Installing}.
10164
10165 To find out about major bugs discovered in the current release and
10166 possible workarounds for them, retrieve
10167 @code{ftp://alpha.gnu.org/g77.plan}.
10168
10169 (Note that some of this portion of the manual is lifted
10170 directly from the @code{gcc} manual, with minor modifications
10171 to tailor it to users of @code{g77}.
10172 Anytime a bug seems to have more to do with the @code{gcc}
10173 portion of @code{g77},
10174 @xref{Trouble,,Known Causes of Trouble with GNU CC,
10175 gcc,Using and Porting GNU CC}.)
10176
10177 @menu
10178 * But-bugs:: Bugs really in other programs or elsewhere.
10179 * Actual Bugs:: Bugs and misfeatures we will fix later.
10180 * Missing Features:: Features we already know we want to add later.
10181 * Disappointments:: Regrettable things we can't change.
10182 * Non-bugs:: Things we think are right, but some others disagree.
10183 * Warnings and Errors:: Which problems in your code get warnings,
10184 and which get errors.
10185 @end menu
10186
10187 @node But-bugs
10188 @section Bugs Not In GNU Fortran
10189 @cindex but-bugs
10190
10191 These are bugs to which the maintainers often have to reply,
10192 ``but that isn't a bug in @code{g77}@dots{}''.
10193 Some of these already are fixed in new versions of other
10194 software; some still need to be fixed; some are problems
10195 with how @code{g77} is installed or is being used;
10196 some are the result of bad hardware that causes software
10197 to misbehave in sometimes bizarre ways;
10198 some just cannot be addressed at this time until more
10199 is known about the problem.
10200
10201 Please don't re-report these bugs to the @code{g77} maintainers---if
10202 you must remind someone how important it is to you that the problem
10203 be fixed, talk to the people responsible for the other products
10204 identified below, but preferably only after you've tried the
10205 latest versions of those products.
10206 The @code{g77} maintainers have their hands full working on
10207 just fixing and improving @code{g77}, without serving as a
10208 clearinghouse for all bugs that happen to affect @code{g77}
10209 users.
10210
10211 @xref{Collected Fortran Wisdom}, for information on behavior
10212 of Fortran programs, and the programs that compile them, that
10213 might be @emph{thought} to indicate bugs.
10214
10215 @menu
10216 * Signal 11 and Friends:: Strange behavior by any software.
10217 * Cannot Link Fortran Programs:: Unresolved references.
10218 * Large Common Blocks:: Problems on older GNU/Linux systems.
10219 * Debugger Problems:: When the debugger crashes.
10220 * NeXTStep Problems:: Misbehaving executables.
10221 * Stack Overflow:: More misbehaving executables.
10222 * Nothing Happens:: Less behaving executables.
10223 * Strange Behavior at Run Time:: Executables misbehaving due to
10224 bugs in your program.
10225 * Floating-point Errors:: The results look wrong, but@dots{}.
10226 @end menu
10227
10228 @node Signal 11 and Friends
10229 @subsection Signal 11 and Friends
10230 @cindex signal 11
10231 @cindex hardware errors
10232
10233 A whole variety of strange behaviors can occur when the
10234 software, or the way you are using the software,
10235 stresses the hardware in a way that triggers hardware bugs.
10236 This might seem hard to believe, but it happens frequently
10237 enough that there exist documents explaining in detail
10238 what the various causes of the problems are, what
10239 typical symptoms look like, and so on.
10240
10241 Generally these problems are referred to in this document
10242 as ``signal 11'' crashes, because the Linux kernel, running
10243 on the most popular hardware (the Intel x86 line), often
10244 stresses the hardware more than other popular operating
10245 systems.
10246 When hardware problems do occur under GNU/Linux on x86
10247 systems, these often manifest themselves as ``signal 11''
10248 problems, as illustrated by the following diagnostic:
10249
10250 @smallexample
10251 sh# @kbd{g77 myprog.f}
10252 gcc: Internal compiler error: program f771 got fatal signal 11
10253 sh#
10254 @end smallexample
10255
10256 It is @emph{very} important to remember that the above
10257 message is @emph{not} the only one that indicates a
10258 hardware problem, nor does it always indicate a hardware
10259 problem.
10260
10261 In particular, on systems other than those running the Linux
10262 kernel, the message might appear somewhat or very different,
10263 as it will if the error manifests itself while running a
10264 program other than the @code{g77} compiler.
10265 For example,
10266 it will appear somewhat different when running your program,
10267 when running Emacs, and so on.
10268
10269 How to cope with such problems is well beyond the scope
10270 of this manual.
10271
10272 However, users of Linux-based systems (such as GNU/Linux)
10273 should review @code{http://www.bitwizard.nl/sig11}, a source
10274 of detailed information on diagnosing hardware problems,
10275 by recognizing their common symptoms.
10276
10277 Users of other operating systems and hardware might
10278 find this reference useful as well.
10279 If you know of similar material for another hardware/software
10280 combination, please let us know so we can consider including
10281 a reference to it in future versions of this manual.
10282
10283 @node Cannot Link Fortran Programs
10284 @subsection Cannot Link Fortran Programs
10285 @cindex unresolved reference (various)
10286 @cindex linking error for user code
10287 @cindex code, user
10288 @cindex ld error for user code
10289 @cindex ld can't find strange names
10290 On some systems, perhaps just those with out-of-date (shared?)
10291 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
10292 programs (which should be done using @code{g77}).
10293
10294 If this happens to you, try appending @samp{-lc} to the command you
10295 use to link the program, e.g. @samp{g77 foo.f -lc}.
10296 @code{g77} already specifies @samp{-lf2c -lm} when it calls the linker,
10297 but it cannot also specify @samp{-lc} because not all systems have a
10298 file named @file{libc.a}.
10299
10300 It is unclear at this point whether there are legitimately installed
10301 systems where @samp{-lf2c -lm} is insufficient to resolve code produced
10302 by @code{g77}.
10303
10304 @cindex undefined reference (_main)
10305 @cindex linking error for user code
10306 @cindex ld error for user code
10307 @cindex code, user
10308 @cindex ld can't find _main
10309 If your program doesn't link due to unresolved references to names
10310 like @samp{_main}, make sure you're using the @code{g77} command to do the
10311 link, since this command ensures that the necessary libraries are
10312 loaded by specifying @samp{-lf2c -lm} when it invokes the @code{gcc}
10313 command to do the actual link.
10314 (Use the @samp{-v} option to discover
10315 more about what actually happens when you use the @code{g77} and @code{gcc}
10316 commands.)
10317
10318 Also, try specifying @samp{-lc} as the last item on the @code{g77}
10319 command line, in case that helps.
10320
10321 @node Large Common Blocks
10322 @subsection Large Common Blocks
10323 @cindex common blocks, large
10324 @cindex large common blocks
10325 @cindex linker errors
10326 @cindex ld errors
10327 @cindex errors, linker
10328 On some older GNU/Linux systems, programs with common blocks larger
10329 than 16MB cannot be linked without some kind of error
10330 message being produced.
10331
10332 This is a bug in older versions of @code{ld}, fixed in
10333 more recent versions of @code{binutils}, such as version 2.6.
10334
10335 @node Debugger Problems
10336 @subsection Debugger Problems
10337 @cindex @code{gdb} support
10338 @cindex support, @code{gdb}
10339 There are some known problems when using @code{gdb} on code
10340 compiled by @code{g77}.
10341 Inadequate investigation as of the release of 0.5.16 results in not
10342 knowing which products are the culprit, but @file{gdb-4.14} definitely
10343 crashes when, for example, an attempt is made to print the contents
10344 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux machines, plus
10345 some others.
10346
10347 @node NeXTStep Problems
10348 @subsection NeXTStep Problems
10349 @cindex NeXTStep problems
10350 @cindex bus error
10351 @cindex segmentation violation
10352 Developers of Fortran code on NeXTStep (all architectures) have to
10353 watch out for the following problem when writing programs with
10354 large, statically allocated (i.e. non-stack based) data structures
10355 (common blocks, saved arrays).
10356
10357 Due to the way the native loader (@file{/bin/ld}) lays out
10358 data structures in virtual memory, it is very easy to create an
10359 executable wherein the @samp{__DATA} segment overlaps (has addresses in
10360 common) with the @samp{UNIX STACK} segment.
10361
10362 This leads to all sorts of trouble, from the executable simply not
10363 executing, to bus errors.
10364 The NeXTStep command line tool @code{ebadexec} points to
10365 the problem as follows:
10366
10367 @smallexample
10368 % @kbd{/bin/ebadexec a.out}
10369 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
10370 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
10371 STACK segment (truncated address = 0x400000 rounded size =
10372 0x3c00000) of executable file: a.out
10373 @end smallexample
10374
10375 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
10376 stack segment.)
10377
10378 This can be cured by assigning the @samp{__DATA} segment
10379 (virtual) addresses beyond the stack segment.
10380 A conservative
10381 estimate for this is from address 6000000 (hexadecimal) onwards---this
10382 has always worked for me [Toon Moene]:
10383
10384 @smallexample
10385 % @kbd{g77 -segaddr __DATA 6000000 test.f}
10386 % @kbd{ebadexec a.out}
10387 ebadexec: file: a.out appears to be executable
10388 %
10389 @end smallexample
10390
10391 Browsing through @file{gcc/f/Makefile.in},
10392 you will find that the @code{f771} program itself also has to be
10393 linked with these flags---it has large statically allocated
10394 data structures.
10395 (Version 0.5.18 reduces this somewhat, but probably
10396 not enough.)
10397
10398 (The above item was contributed by Toon Moene
10399 (@email{toon@@moene.indiv.nluug.nl}).)
10400
10401 @node Stack Overflow
10402 @subsection Stack Overflow
10403 @cindex stack overflow
10404 @cindex segmentation violation
10405 @code{g77} code might fail at runtime (probably with a ``segmentation
10406 violation'') due to overflowing the stack.
10407 This happens most often on systems with an environment
10408 that provides substantially more heap space (for use
10409 when arbitrarily allocating and freeing memory) than stack
10410 space.
10411
10412 Often this can be cured by
10413 increasing or removing your shell's limit on stack usage, typically
10414 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
10415 @kbd{ulimit -s} (in @code{sh} and derivatives).
10416
10417 Increasing the allowed stack size might, however, require
10418 changing some operating system or system configuration parameters.
10419
10420 You might be able to work around the problem by compiling with the
10421 @samp{-fno-automatic} option to reduce stack usage, probably at the
10422 expense of speed.
10423
10424 @xref{Maximum Stackable Size}, for information on patching
10425 @code{g77} to use different criteria for placing local
10426 non-automatic variables and arrays on the stack.
10427
10428 @cindex automatic arrays
10429 @cindex arrays, automatic
10430 However, if your program uses large automatic arrays
10431 (for example, has declarations like @samp{REAL A(N)} where
10432 @samp{A} is a local array and @samp{N} is a dummy or
10433 @code{COMMON} variable that can have a large value),
10434 neither use of @samp{-fno-automatic},
10435 nor changing the cut-off point for @code{g77} for using the stack,
10436 will solve the problem by changing the placement of these
10437 large arrays, as they are @emph{necessarily} automatic.
10438
10439 @code{g77} currently provides no means to specify that
10440 automatic arrays are to be allocated on the heap instead
10441 of the stack.
10442 So, other than increasing the stack size, your best bet is to
10443 change your source code to avoid large automatic arrays.
10444 Methods for doing this currently are outside the scope of
10445 this document.
10446
10447 (@emph{Note:} If your system puts stack and heap space in the
10448 same memory area, such that they are effectively combined, then
10449 a stack overflow probably indicates a program that is either
10450 simply too large for the system, or buggy.)
10451
10452 @node Nothing Happens
10453 @subsection Nothing Happens
10454 @cindex nothing happens
10455 @cindex naming programs @samp{test}
10456 @cindex @samp{test} programs
10457 @cindex programs named @samp{test}
10458 It is occasionally reported that a ``simple'' program,
10459 such as a ``Hello, World!'' program, does nothing when
10460 it is run, even though the compiler reported no errors,
10461 despite the program containing nothing other than a
10462 simple @code{PRINT} statement.
10463
10464 This most often happens because the program has been
10465 compiled and linked on a UNIX system and named @samp{test},
10466 though other names can lead to similarly unexpected
10467 run-time behavior on various systems.
10468
10469 Essentially this problem boils down to giving
10470 your program a name that is already known to
10471 the shell you are using to identify some other program,
10472 which the shell continues to execute instead of your
10473 program when you invoke it via, for example:
10474
10475 @smallexample
10476 sh# @kbd{test}
10477 sh#
10478 @end smallexample
10479
10480 Under UNIX and many other system, a simple command name
10481 invokes a searching mechanism that might well not choose
10482 the program located in the current working directory if
10483 there is another alternative (such as the @code{test}
10484 command commonly installed on UNIX systems).
10485
10486 The reliable way to invoke a program you just linked in
10487 the current directory under UNIX is to specify it using
10488 an explicit pathname, as in:
10489
10490 @smallexample
10491 sh# @kbd{./test}
10492 Hello, World!
10493 sh#
10494 @end smallexample
10495
10496 Users who encounter this problem should take the time to
10497 read up on how their shell searches for commands, how to
10498 set their search path, and so on.
10499 The relevant UNIX commands to learn about include
10500 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
10501 @code{set} and @code{env}), @code{which}, and @code{find}.
10502
10503 @node Strange Behavior at Run Time
10504 @subsection Strange Behavior at Run Time
10505 @cindex segmentation violation
10506 @cindex bus error
10507 @cindex overwritten data
10508 @cindex data, overwritten
10509 @code{g77} code might fail at runtime with ``segmentation violation'',
10510 ``bus error'', or even something as subtle as a procedure call
10511 overwriting a variable or array element that it is not supposed
10512 to touch.
10513
10514 These can be symptoms of a wide variety of actual bugs that
10515 occurred earlier during the program's run, but manifested
10516 themselves as @emph{visible} problems some time later.
10517
10518 Overflowing the bounds of an array---usually by writing beyond
10519 the end of it---is one of two kinds of bug that often occurs
10520 in Fortran code.
10521
10522 The other kind of bug is a mismatch between the actual arguments
10523 passed to a procedure and the dummy arguments as declared by that
10524 procedure.
10525
10526 Both of these kinds of bugs, and some others as well, can be
10527 difficult to track down, because the bug can change its behavior,
10528 or even appear to not occur, when using a debugger.
10529
10530 That is, these bugs can be quite sensitive to data, including
10531 data representing the placement of other data in memory (that is,
10532 pointers, such as the placement of stack frames in memory).
10533
10534 Plans call for improving @code{g77} so that it can offer the
10535 ability to catch and report some of these problems at compile, link, or
10536 run time, such as by generating code to detect references to
10537 beyond the bounds of an array, or checking for agreement between
10538 calling and called procedures.
10539
10540 In the meantime, finding and fixing the programming
10541 bugs that lead to these behaviors is, ultimately, the user's
10542 responsibility, as difficult as that task can sometimes be.
10543
10544 @cindex `infinite spaces' printed
10545 @cindex spaces, endless printing of
10546 @cindex libc, non-ANSI or non-default
10547 @cindex C library
10548 @cindex linking against non-standard library
10549 @cindex Solaris
10550 One runtime problem that has been observed might have a simple solution.
10551 If a formatted @code{WRITE} produces an endless stream of spaces, check
10552 that your program is linked against the correct version of the C library.
10553 The configuration process takes care to account for your
10554 system's normal @file{libc} not being ANSI-standard, which will
10555 otherwise cause this behaviour.
10556 If your system's default library is
10557 ANSI-standard and you subsequently link against a non-ANSI one, there
10558 might be problems such as this one.
10559
10560 Specifically, on Solaris2 systems,
10561 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
10562
10563 @node Floating-point Errors
10564 @subsection Floating-point Errors
10565 @cindex floating-point errors
10566 @cindex rounding errors
10567 @cindex inconsistent floating-point results
10568 @cindex results, inconsistent
10569 Some programs appear to produce inconsistent floating-point
10570 results compiled by @code{g77} versus by other compilers.
10571
10572 Often the reason for this behavior is the fact that floating-point
10573 values are represented on almost all Fortran systems by
10574 @emph{approximations}, and these approximations are inexact
10575 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
10576 0.7, 0.8, 0.9, 1.1, and so on.
10577 Most Fortran systems, including all current ports of @code{g77},
10578 use binary arithmetic to represent these approximations.
10579
10580 Therefore, the exact value of any floating-point approximation
10581 as manipulated by @code{g77}-compiled code is representable by
10582 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
10583 so on (just keep dividing by two) through the precision of the
10584 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
10585 @code{REAL(KIND=2)}), then multiplying the sum by a integral
10586 power of two (in Fortran, by @samp{2**N}) that typically is between
10587 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
10588 @code{REAL(KIND=2)}, then multiplying by -1 if the number
10589 is negative.
10590
10591 So, a value like 0.2 is exactly represented in decimal---since
10592 it is a fraction, @samp{2/10}, with a denomenator that is compatible
10593 with the base of the number system (base 10).
10594 However, @samp{2/10} cannot be represented by any finite number
10595 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
10596 be exactly represented in binary notation.
10597
10598 (On the other hand, decimal notation can represent any binary
10599 number in a finite number of digits.
10600 Decimal notation cannot do so with ternary, or base-3,
10601 notation, which would represent floating-point numbers as
10602 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
10603 After all, no finite number of decimal digits can exactly
10604 represent @samp{1/3}.
10605 Fortunately, few systems use ternary notation.)
10606
10607 Moreover, differences in the way run-time I/O libraries convert
10608 between these approximations and the decimal representation often
10609 used by programmers and the programs they write can result in
10610 apparent differences between results that do not actually exist,
10611 or exist to such a small degree that they usually are not worth
10612 worrying about.
10613
10614 For example, consider the following program:
10615
10616 @smallexample
10617 PRINT *, 0.2
10618 END
10619 @end smallexample
10620
10621 When compiled by @code{g77}, the above program might output
10622 @samp{0.20000003}, while another compiler might produce a
10623 executable that outputs @samp{0.2}.
10624
10625 This particular difference is due to the fact that, currently,
10626 conversion of floating-point values by the @code{libf2c} library,
10627 used by @code{g77}, handles only double-precision values.
10628
10629 Since @samp{0.2} in the program is a single-precision value, it
10630 is converted to double precision (still in binary notation)
10631 before being converted back to decimal.
10632 The conversion to binary appends _binary_ zero digits to the
10633 original value---which, again, is an inexact approximation of
10634 0.2---resulting in an approximation that is much less exact
10635 than is connoted by the use of double precision.
10636
10637 (The appending of binary zero digits has essentially the same
10638 effect as taking a particular decimal approximation of
10639 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
10640 zeros to it, producing @samp{0.33333330000000000}.
10641 Treating the resulting decimal approximation as if it really
10642 had 18 or so digits of valid precision would make it seem
10643 a very poor approximation of @samp{1/3}.)
10644
10645 As a result of converting the single-precision approximation
10646 to double precision by appending binary zeros, the conversion
10647 of the resulting double-precision
10648 value to decimal produces what looks like an incorrect
10649 result, when in fact the result is @emph{inexact}, and
10650 is probably no less inaccurate or imprecise an approximation
10651 of 0.2 than is produced by other compilers that happen to output
10652 the converted value as ``exactly'' @samp{0.2}.
10653 (Some compilers behave in a way that can make them appear
10654 to retain more accuracy across a conversion of a single-precision
10655 constant to double precision.
10656 @xref{Context-Sensitive Constants}, to see why
10657 this practice is illusory and even dangerous.)
10658
10659 Note that a more exact approximation of the constant is
10660 computed when the program is changed to specify a
10661 double-precision constant:
10662
10663 @smallexample
10664 PRINT *, 0.2D0
10665 END
10666 @end smallexample
10667
10668 Future versions of @code{g77} and/or @code{libf2c} might convert
10669 single-precision values directly to decimal,
10670 instead of converting them to double precision first.
10671 This would tend to result in output that is more consistent
10672 with that produced by some other Fortran implementations.
10673
10674 @include bugs.texi
10675
10676 @node Missing Features
10677 @section Missing Features
10678
10679 This section lists features we know are missing from @code{g77},
10680 and which we want to add someday.
10681 (There is no priority implied in the ordering below.)
10682
10683 @menu
10684 GNU Fortran language:
10685 * Better Source Model::
10686 * Fortran 90 Support::
10687 * Intrinsics in PARAMETER Statements::
10688 * SELECT CASE on CHARACTER Type::
10689 * RECURSIVE Keyword::
10690 * Popular Non-standard Types::
10691 * Full Support for Compiler Types::
10692 * Array Bounds Expressions::
10693 * POINTER Statements::
10694 * Sensible Non-standard Constructs::
10695 * FLUSH Statement::
10696 * Expressions in FORMAT Statements::
10697 * Explicit Assembler Code::
10698 * Q Edit Descriptor::
10699
10700 GNU Fortran dialects:
10701 * Old-style PARAMETER Statements::
10702 * TYPE and ACCEPT I/O Statements::
10703 * STRUCTURE UNION RECORD MAP::
10704 * OPEN CLOSE and INQUIRE Keywords::
10705 * ENCODE and DECODE::
10706 * Suppressing Space Padding::
10707 * Fortran Preprocessor::
10708 * Bit Operations on Floating-point Data::
10709
10710 New facilities:
10711 * POSIX Standard::
10712 * Floating-point Exception Handling::
10713 * Nonportable Conversions::
10714 * Large Automatic Arrays::
10715 * Support for Threads::
10716 * Increasing Precision/Range::
10717
10718 Better diagnostics:
10719 * Gracefully Handle Sensible Bad Code::
10720 * Non-standard Conversions::
10721 * Non-standard Intrinsics::
10722 * Modifying DO Variable::
10723 * Better Pedantic Compilation::
10724 * Warn About Implicit Conversions::
10725 * Invalid Use of Hollerith Constant::
10726 * Dummy Array Without Dimensioning Dummy::
10727 * Invalid FORMAT Specifiers::
10728 * Ambiguous Dialects::
10729 * Unused Labels::
10730 * Informational Messages::
10731
10732 Run-time facilities:
10733 * Uninitialized Variables at Run Time::
10734 * Bounds Checking at Run Time::
10735
10736 Debugging:
10737 * Labels Visible to Debugger::
10738 @end menu
10739
10740 @node Better Source Model
10741 @subsection Better Source Model
10742
10743 @code{g77} needs to provide, as the default source-line model,
10744 a ``pure visual'' mode, where
10745 the interpretation of a source program in this mode can be accurately
10746 determined by a user looking at a traditionally displayed rendition
10747 of the program (assuming the user knows whether the program is fixed
10748 or free form).
10749
10750 The design should assume the user cannot tell tabs from spaces
10751 and cannot see trailing spaces on lines, but has canonical tab stops
10752 and, for fixed-form source, has the ability to always know exactly
10753 where column 72 is (since the Fortran standard itself requires
10754 this for fixed-form source).
10755
10756 This would change the default treatment of fixed-form source
10757 to not treat lines with tabs as if they were infinitely long---instead,
10758 they would end at column 72 just as if the tabs were replaced
10759 by spaces in the canonical way.
10760
10761 As part of this, provide common alternate models (Digital, @code{f2c},
10762 and so on) via command-line options.
10763 This includes allowing arbitrarily long
10764 lines for free-form source as well as fixed-form source and providing
10765 various limits and diagnostics as appropriate.
10766
10767 @cindex sequence numbers
10768 @cindex columns 73 through 80
10769 Also, @code{g77} should offer, perhaps even default to, warnings
10770 when characters beyond the last valid column are anything other
10771 than spaces.
10772 This would mean code with ``sequence numbers'' in columns 73 through 80
10773 would be rejected, and there's a lot of that kind of code around,
10774 but one of the most frequent bugs encountered by new users is
10775 accidentally writing fixed-form source code into and beyond
10776 column 73.
10777 So, maybe the users of old code would be able to more easily handle
10778 having to specify, say, a @code{-Wno-col73to80} option.
10779
10780 @node Fortran 90 Support
10781 @subsection Fortran 90 Support
10782 @cindex Fortran 90 support
10783 @cindex support, Fortran 90
10784
10785 @code{g77} does not support many of the features that
10786 distinguish Fortran 90 (and, now, Fortran 95) from
10787 ANSI FORTRAN 77.
10788
10789 Some Fortran 90 features are supported, because they
10790 make sense to offer even to die-hard users of F77.
10791 For example, many of them codify various ways F77 has
10792 been extended to meet users' needs during its tenure,
10793 so @code{g77} might as well offer them as the primary
10794 way to meet those same needs, even if it offers compatibility
10795 with one or more of the ways those needs were met
10796 by other F77 compilers in the industry.
10797
10798 Still, many important F90 features are not supported,
10799 because no attempt has been made to research each and
10800 every feature and assess its viability in @code{g77}.
10801 In the meantime, users who need those features must
10802 use Fortran 90 compilers anyway, and the best approach
10803 to adding some F90 features to GNU Fortran might well be
10804 to fund a comprehensive project to create GNU Fortran 95.
10805
10806 @node Intrinsics in PARAMETER Statements
10807 @subsection Intrinsics in @code{PARAMETER} Statements
10808 @cindex PARAMETER statement
10809 @cindex statements, PARAMETER
10810
10811 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
10812 This feature is considered to be absolutely vital, even though it
10813 is not standard-conforming, and is scheduled for version 0.6.
10814
10815 Related to this, @code{g77} doesn't allow non-integral
10816 exponentiation in @code{PARAMETER} statements, such as
10817 @samp{PARAMETER (R=2**.25)}.
10818 It is unlikely @code{g77} will ever support this feature,
10819 as doing it properly requires complete emulation of
10820 a target computer's floating-point facilities when
10821 building @code{g77} as a cross-compiler.
10822 But, if the @code{gcc} back end is enhanced to provide
10823 such a facility, @code{g77} will likely use that facility
10824 in implementing this feature soon afterwards.
10825
10826 @node SELECT CASE on CHARACTER Type
10827 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
10828
10829 Character-type selector/cases for @code{SELECT CASE} currently
10830 are not supported.
10831
10832 @node RECURSIVE Keyword
10833 @subsection @code{RECURSIVE} Keyword
10834 @cindex RECURSIVE keyword
10835 @cindex keywords, RECURSIVE
10836 @cindex recursion, lack of
10837 @cindex lack of recursion
10838
10839 @code{g77} doesn't support the @code{RECURSIVE} keyword that
10840 F90 compilers do.
10841 Nor does it provide any means for compiling procedures
10842 designed to do recursion.
10843
10844 All recursive code can be rewritten to not use recursion,
10845 but the result is not pretty.
10846
10847 @node Increasing Precision/Range
10848 @subsection Increasing Precision/Range
10849 @cindex -r8
10850 @cindex -i8
10851 @cindex f2c
10852 @cindex increasing precision
10853 @cindex precision, increasing
10854 @cindex increasing range
10855 @cindex range, increasing
10856 @cindex Toolpack
10857 @cindex Netlib
10858
10859 Some compilers, such as @code{f2c}, have an option (@samp{-r8} or
10860 similar) that provides automatic treatment of @code{REAL}
10861 entities such that they have twice the storage size, and
10862 a corresponding increase in the range and precision, of what
10863 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
10864 (This affects @code{COMPLEX} the same way.)
10865
10866 They also typically offer another option (@samp{-i8}) to increase
10867 @code{INTEGER} entities so they are twice as large
10868 (with roughly twice as much range).
10869
10870 (There are potential pitfalls in using these options.)
10871
10872 @code{g77} does not yet offer any option that performs these
10873 kinds of transformations.
10874 Part of the problem is the lack of detailed specifications regarding
10875 exactly how these options affect the interpretation of constants,
10876 intrinsics, and so on.
10877
10878 Until @code{g77} addresses this need, programmers could improve
10879 the portability of their code by modifying it to not require
10880 compile-time options to produce correct results.
10881 Some free tools are available which may help, specifically
10882 in Toolpack (which one would expect to be sound) and the @file{fortran}
10883 section of the Netlib repository.
10884
10885 Use of preprocessors can provide a fairly portable means
10886 to work around the lack of widely portable methods in the Fortran
10887 language itself (though increasing acceptance of Fortran 90 would
10888 alleviate this problem).
10889
10890 @node Popular Non-standard Types
10891 @subsection Popular Non-standard Types
10892 @cindex INTEGER*2 support
10893 @cindex LOGICAL*1 support
10894
10895 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
10896 and similar.
10897 Version 0.6 will provide full support for this very
10898 popular set of features.
10899 In the meantime, version 0.5.18 provides rudimentary support
10900 for them.
10901
10902 @node Full Support for Compiler Types
10903 @subsection Full Support for Compiler Types
10904
10905 @cindex REAL*16 support
10906 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
10907 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
10908 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
10909 This means providing intrinsic support, and maybe constant
10910 support (using F90 syntax) as well, and, for most
10911 machines will result in automatic support of @code{INTEGER*1},
10912 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
10913 and so on.
10914 This is scheduled for version 0.6.
10915
10916 @node Array Bounds Expressions
10917 @subsection Array Bounds Expressions
10918 @cindex array elements, in adjustable array bounds
10919 @cindex function references, in adjustable array bounds
10920 @cindex array bounds, adjustable
10921 @cindex DIMENSION statement
10922 @cindex statements, DIMENSION
10923
10924 @code{g77} doesn't support more general expressions to dimension
10925 arrays, such as array element references, function
10926 references, etc.
10927
10928 For example, @code{g77} currently does not accept the following:
10929
10930 @smallexample
10931 SUBROUTINE X(M, N)
10932 INTEGER N(10), M(N(2), N(1))
10933 @end smallexample
10934
10935 @node POINTER Statements
10936 @subsection POINTER Statements
10937 @cindex POINTER statement
10938 @cindex statements, POINTER
10939 @cindex Cray pointers
10940
10941 @code{g77} doesn't support pointers or allocatable objects
10942 (other than automatic arrays).
10943 This set of features is
10944 probably considered just behind intrinsics
10945 in @code{PARAMETER} statements on the list of large,
10946 important things to add to @code{g77}.
10947
10948 In the meantime, consider using the @code{INTEGER(KIND=7)}
10949 declaration to specify that a variable must be
10950 able to hold a pointer.
10951 This construct is not portable to other non-GNU compilers,
10952 but it is portable to all machines GNU Fortran supports
10953 when @code{g77} is used.
10954
10955 @xref{Functions and Subroutines}, for information on
10956 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
10957 constructs, which are useful for passing pointers to
10958 procedures written in languages other than Fortran.
10959
10960 @node Sensible Non-standard Constructs
10961 @subsection Sensible Non-standard Constructs
10962
10963 @code{g77} rejects things other compilers accept,
10964 like @samp{INTRINSIC SQRT,SQRT}.
10965 As time permits in the future, some of these things that are easy for
10966 humans to read and write and unlikely to be intended to mean something
10967 else will be accepted by @code{g77} (though @samp{-fpedantic} should
10968 trigger warnings about such non-standard constructs).
10969
10970 Until @code{g77} no longer gratuitously rejects sensible code,
10971 you might as well fix your code
10972 to be more standard-conforming and portable.
10973
10974 The kind of case that is important to except from the
10975 recommendation to change your code is one where following
10976 good coding rules would force you to write non-standard
10977 code that nevertheless has a clear meaning.
10978
10979 For example, when writing an @code{INCLUDE} file that
10980 defines a common block, it might be appropriate to
10981 include a @code{SAVE} statement for the common block
10982 (such as @samp{SAVE /CBLOCK/}), so that variables
10983 defined in the common block retain their values even
10984 when all procedures declaring the common block become
10985 inactive (return to their callers).
10986
10987 However, putting @code{SAVE} statements in an @code{INCLUDE}
10988 file would prevent otherwise standard-conforming code
10989 from also specifying the @code{SAVE} statement, by itself,
10990 to indicate that all local variables and arrays are to
10991 have the @code{SAVE} attribute.
10992
10993 For this reason, @code{g77} already has been changed to
10994 allow this combination, because although the general
10995 problem of gratuitously rejecting unambiguous and
10996 ``safe'' constructs still exists in @code{g77}, this
10997 particular construct was deemed useful enough that
10998 it was worth fixing @code{g77} for just this case.
10999
11000 So, while there is no need to change your code
11001 to avoid using this particular construct, there
11002 might be other, equally appropriate but non-standard
11003 constructs, that you shouldn't have to stop using
11004 just because @code{g77} (or any other compiler)
11005 gratuitously rejects it.
11006
11007 Until the general problem is solved, if you have
11008 any such construct you believe is worthwhile
11009 using (e.g. not just an arbitrary, redundant
11010 specification of an attribute), please submit a
11011 bug report with an explanation, so we can consider
11012 fixing @code{g77} just for cases like yours.
11013
11014 @node FLUSH Statement
11015 @subsection @code{FLUSH} Statement
11016
11017 @code{g77} could perhaps use a @code{FLUSH} statement that
11018 does what @samp{CALL FLUSH} does,
11019 but that supports @samp{*} as the unit designator (same unit as for
11020 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
11021 specifiers.
11022
11023 @node Expressions in FORMAT Statements
11024 @subsection Expressions in @code{FORMAT} Statements
11025 @cindex FORMAT statement
11026 @cindex statements, FORMAT
11027
11028 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
11029 Supporting this requires a significant redesign or replacement
11030 of @code{libf2c}.
11031
11032 However, a future version of @code{g77} might support
11033 this construct when the expression is constant. For
11034 example:
11035
11036 @smallexample
11037 PARAMETER (IWIDTH = 12)
11038 10 FORMAT (I<IWIDTH>)
11039 @end smallexample
11040
11041 In the meantime, at least for output (@code{PRINT} and
11042 @code{WRITE}), Fortran code making use of this feature can
11043 be rewritten to avoid it by constructing the @code{FORMAT}
11044 string in a @code{CHARACTER} variable or array, then
11045 using that variable or array in place of the @code{FORMAT}
11046 statement label to do the original @code{PRINT} or @code{WRITE}.
11047
11048 Many uses of this feature on input can be rewritten this way
11049 as well, but not all can.
11050 For example, this can be rewritten:
11051
11052 @smallexample
11053 READ 20, I
11054 20 FORMAT (I<J>)
11055 @end smallexample
11056
11057 However, this cannot, in general, be rewritten, especially
11058 when @code{ERR=} and @code{END=} constructs are employed:
11059
11060 @smallexample
11061 READ 30, J, I
11062 30 FORMAT (I<J>)
11063 @end smallexample
11064
11065 @node Explicit Assembler Code
11066 @subsection Explicit Assembler Code
11067
11068 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
11069 code to specify explicit assembler code.
11070
11071 @node Q Edit Descriptor
11072 @subsection Q Edit Descriptor
11073 @cindex FORMAT statement
11074 @cindex Q edit descriptor
11075
11076 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
11077 (This is meant to get the number of characters remaining in an input record.)
11078 Supporting this requires a significant redesign or replacement
11079 of @code{libf2c}.
11080
11081 A workaround might be using internal I/O or the stream-based intrinsics.
11082 @xref{FGetC Intrinsic (subroutine)}.
11083
11084 @node Old-style PARAMETER Statements
11085 @subsection Old-style PARAMETER Statements
11086 @cindex PARAMETER statement
11087 @cindex statements, PARAMETER
11088
11089 @code{g77} doesn't accept @samp{PARAMETER I=1}.
11090 Supporting this obsolete form of
11091 the @code{PARAMETER} statement would not be particularly hard, as most of the
11092 parsing code is already in place and working.
11093
11094 Until time/money is
11095 spent implementing it, you might as well fix your code to use the
11096 standard form, @samp{PARAMETER (I=1)} (possibly needing
11097 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
11098 otherwise, in the obsolete form of @code{PARAMETER}, the
11099 type of the variable is set from the type of the constant being
11100 assigned to it).
11101
11102 @node TYPE and ACCEPT I/O Statements
11103 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
11104 @cindex TYPE statement
11105 @cindex statements, TYPE
11106 @cindex ACCEPT statement
11107 @cindex statements, ACCEPT
11108
11109 @code{g77} doesn't support the I/O statements @code{TYPE} and
11110 @code{ACCEPT}.
11111 These are common extensions that should be easy to support,
11112 but also are fairly easy to work around in user code.
11113
11114 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
11115 by @samp{PRINT fmt,list}.
11116 And, any @samp{ACCEPT fmt,list} statement can be
11117 replaced by @samp{READ fmt,list}.
11118
11119 @node STRUCTURE UNION RECORD MAP
11120 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
11121 @cindex STRUCTURE statement
11122 @cindex statements, STRUCTURE
11123 @cindex UNION statement
11124 @cindex statements, UNION
11125 @cindex RECORD statement
11126 @cindex statements, RECORD
11127 @cindex MAP statement
11128 @cindex statements, MAP
11129
11130 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
11131 @code{MAP}.
11132 This set of extensions is quite a bit
11133 lower on the list of large, important things to add to @code{g77}, partly
11134 because it requires a great deal of work either upgrading or
11135 replacing @code{libf2c}.
11136
11137 @node OPEN CLOSE and INQUIRE Keywords
11138 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
11139 @cindex disposition of files
11140 @cindex OPEN statement
11141 @cindex statements, OPEN
11142 @cindex CLOSE statement
11143 @cindex statements, CLOSE
11144 @cindex INQUIRE statement
11145 @cindex statements, INQUIRE
11146
11147 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
11148 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
11149 These extensions are easy to add to @code{g77} itself, but
11150 require much more work on @code{libf2c}.
11151
11152 @node ENCODE and DECODE
11153 @subsection @code{ENCODE} and @code{DECODE}
11154 @cindex ENCODE statement
11155 @cindex statements, ENCODE
11156 @cindex DECODE statement
11157 @cindex statements, DECODE
11158
11159 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
11160
11161 These statements are best replaced by READ and WRITE statements
11162 involving internal files (CHARACTER variables and arrays).
11163
11164 For example, replace a code fragment like
11165
11166 @smallexample
11167 INTEGER*1 LINE(80)
11168 @dots{}
11169 DECODE (80, 9000, LINE) A, B, C
11170 @dots{}
11171 9000 FORMAT (1X, 3(F10.5))
11172 @end smallexample
11173
11174 @noindent
11175 with:
11176
11177 @smallexample
11178 CHARACTER*80 LINE
11179 @dots{}
11180 READ (UNIT=LINE, FMT=9000) A, B, C
11181 @dots{}
11182 9000 FORMAT (1X, 3(F10.5))
11183 @end smallexample
11184
11185 Similarly, replace a code fragment like
11186
11187 @smallexample
11188 INTEGER*1 LINE(80)
11189 @dots{}
11190 ENCODE (80, 9000, LINE) A, B, C
11191 @dots{}
11192 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11193 @end smallexample
11194
11195 @noindent
11196 with:
11197
11198 @smallexample
11199 CHARACTER*80 LINE
11200 @dots{}
11201 WRITE (UNIT=LINE, FMT=9000) A, B, C
11202 @dots{}
11203 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11204 @end smallexample
11205
11206 It is entirely possible that @code{ENCODE} and @code{DECODE} will
11207 be supported by a future version of @code{g77}.
11208
11209 @node Suppressing Space Padding
11210 @subsection Suppressing Space Padding of Source Lines
11211
11212 @code{g77} should offer VXT-Fortran-style suppression of virtual
11213 spaces at the end of a source line
11214 if an appropriate command-line option is specified.
11215
11216 This affects cases where
11217 a character constant is continued onto the next line in a fixed-form
11218 source file, as in the following example:
11219
11220 @smallexample
11221 10 PRINT *,'HOW MANY
11222 1 SPACES?'
11223 @end smallexample
11224
11225 @noindent
11226 @code{g77}, and many other compilers, virtually extend
11227 the continued line through column 72 with spaces that become part
11228 of the character constant, but Digital Fortran normally didn't,
11229 leaving only one space between @samp{MANY} and @samp{SPACES?}
11230 in the output of the above statement.
11231
11232 Fairly recently, at least one version of Digital Fortran
11233 was enhanced to provide the other behavior when a
11234 command-line option is specified, apparently due to demand
11235 from readers of the USENET group @file{comp.lang.fortran}
11236 to offer conformance to this widespread practice in the
11237 industry.
11238 @code{g77} should return the favor by offering conformance
11239 to Digital's approach to handling the above example.
11240
11241 @node Fortran Preprocessor
11242 @subsection Fortran Preprocessor
11243
11244 @code{g77} should offer a preprocessor designed specifically
11245 for Fortran to replace @samp{cpp -traditional}.
11246 There are several out there worth evaluating, at least.
11247
11248 Such a preprocessor would recognize Hollerith constants,
11249 properly parse comments and character constants, and so on.
11250 It might also recognize, process, and thus preprocess
11251 files included via the @code{INCLUDE} directive.
11252
11253 @node Bit Operations on Floating-point Data
11254 @subsection Bit Operations on Floating-point Data
11255 @cindex AND intrinsic
11256 @cindex intrinsics, AND
11257 @cindex OR intrinsic
11258 @cindex intrinsics, OR
11259 @cindex SHIFT intrinsic
11260 @cindex intrinsics, SHIFT
11261
11262 @code{g77} does not allow @code{REAL} and other non-integral types for
11263 arguments to intrinsics like @code{AND}, @code{OR}, and @code{SHIFT}.
11264
11265 For example, this program is rejected by @code{g77}, because
11266 the intrinsic @code{IAND} does not accept @code{REAL} arguments:
11267
11268 @smallexample
11269 DATA A/7.54/, B/9.112/
11270 PRINT *, IAND(A, B)
11271 END
11272 @end smallexample
11273
11274 @node POSIX Standard
11275 @subsection @code{POSIX} Standard
11276
11277 @code{g77} should support the POSIX standard for Fortran.
11278
11279 @node Floating-point Exception Handling
11280 @subsection Floating-point Exception Handling
11281 @cindex floating point exceptions
11282 @cindex exceptions, floating point
11283 @cindex FPE handling
11284 @cindex NaN values
11285
11286 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
11287 control over whether or not floating-point exceptions are trapped or
11288 ignored.
11289 (Ignoring them typically results in NaN values being
11290 propagated in systems that conform to IEEE 754.)@
11291 The behaviour is inherited from the system-dependent startup code.
11292
11293 Most systems provide some C-callable mechanism to change this; this can
11294 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
11295 For example, just compiling and linking the following C code with your
11296 program will turn on exception trapping for the ``common'' exceptions
11297 on an x86-based GNU system:
11298
11299 @smallexample
11300 #include <fpu_control.h>
11301 void __attribute__ ((constructor))
11302 trapfpe () @{
11303 (void) __setfpucw (_FPU_DEFAULT &
11304 ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM));
11305 @}
11306 @end smallexample
11307
11308 @node Nonportable Conversions
11309 @subsection Nonportable Conversions
11310 @cindex nonportable conversions
11311 @cindex conversions, nonportable
11312
11313 @code{g77} doesn't accept some particularly nonportable,
11314 silent data-type conversions such as @code{LOGICAL}
11315 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
11316 is type @code{REAL}), that other compilers might
11317 quietly accept.
11318
11319 Some of these conversions are accepted by @code{g77}
11320 when the @samp{-fugly} option is specified.
11321 Perhaps it should accept more or all of them.
11322
11323 @node Large Automatic Arrays
11324 @subsection Large Automatic Arrays
11325 @cindex automatic arrays
11326 @cindex arrays, automatic
11327
11328 Currently, automatic arrays always are allocated on the stack.
11329 For situations where the stack cannot be made large enough,
11330 @code{g77} should offer a compiler option that specifies
11331 allocation of automatic arrays in heap storage.
11332
11333 @node Support for Threads
11334 @subsection Support for Threads
11335 @cindex threads
11336 @cindex parallel processing
11337
11338 Neither the code produced by @code{g77} nor the @code{libf2c} library
11339 are thread-safe, nor does @code{g77} have support for parallel processing
11340 (other than the instruction-level parallelism available on some
11341 processors).
11342 A package such as PVM might help here.
11343
11344 @node Gracefully Handle Sensible Bad Code
11345 @subsection Gracefully Handle Sensible Bad Code
11346
11347 @code{g77} generally should continue processing for
11348 warnings and recoverable (user) errors whenever possible---that
11349 is, it shouldn't gratuitously make bad or useless code.
11350
11351 For example:
11352
11353 @smallexample
11354 INTRINSIC ZABS
11355 CALL FOO(ZABS)
11356 END
11357 @end smallexample
11358
11359 @noindent
11360 When compiling the above with @samp{-ff2c-intrinsics-disable},
11361 @code{g77} should indeed complain about passing @code{ZABS},
11362 but it still should compile, instead of rejecting
11363 the entire @code{CALL} statement.
11364 (Some of this is related to improving
11365 the compiler internals to improve how statements are analyzed.)
11366
11367 @node Non-standard Conversions
11368 @subsection Non-standard Conversions
11369
11370 @samp{-Wconversion} and related should flag places where non-standard
11371 conversions are found.
11372 Perhaps much of this would be part of @samp{-Wugly*}.
11373
11374 @node Non-standard Intrinsics
11375 @subsection Non-standard Intrinsics
11376
11377 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
11378 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
11379 This would help find code that might fail silently when ported to another
11380 compiler.
11381
11382 @node Modifying DO Variable
11383 @subsection Modifying @code{DO} Variable
11384
11385 @code{g77} should warn about modifying @code{DO} variables
11386 via @code{EQUIVALENCE}.
11387 (The internal information gathered to produce this warning
11388 might also be useful in setting the
11389 internal ``doiter'' flag for a variable or even array
11390 reference within a loop, since that might produce faster code someday.)
11391
11392 For example, this code is invalid, so @code{g77} should warn about
11393 the invalid assignment to @samp{NOTHER}:
11394
11395 @smallexample
11396 EQUIVALENCE (I, NOTHER)
11397 DO I = 1, 100
11398 IF (I.EQ. 10) NOTHER = 20
11399 END DO
11400 @end smallexample
11401
11402 @node Better Pedantic Compilation
11403 @subsection Better Pedantic Compilation
11404
11405 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
11406 and use it only to generate
11407 warnings instead of rejecting constructs outright.
11408 Have it warn:
11409 if a variable that dimensions an array is not a dummy or placed
11410 explicitly in @code{COMMON} (F77 does not allow it to be
11411 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
11412 follow statement-function-definition statements; about all sorts of
11413 syntactic extensions.
11414
11415 @node Warn About Implicit Conversions
11416 @subsection Warn About Implicit Conversions
11417
11418 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
11419 to expect automatic, silent, and
11420 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
11421 constants to @code{REAL(KIND=2)} based on context.
11422
11423 For example, it would warn about cases like this:
11424
11425 @smallexample
11426 DOUBLE PRECISION FOO
11427 PARAMETER (TZPHI = 9.435784839284958)
11428 FOO = TZPHI * 3D0
11429 @end smallexample
11430
11431 @node Invalid Use of Hollerith Constant
11432 @subsection Invalid Use of Hollerith Constant
11433
11434 @code{g77} should disallow statements like @samp{RETURN 2HAB},
11435 which are invalid in both source forms
11436 (unlike @samp{RETURN (2HAB)},
11437 which probably still makes no sense but at least can
11438 be reliably parsed).
11439 Fixed-form processing rejects it, but not free-form, except
11440 in a way that is a bit difficult to understand.
11441
11442 @node Dummy Array Without Dimensioning Dummy
11443 @subsection Dummy Array Without Dimensioning Dummy
11444
11445 @code{g77} should complain when a list of dummy arguments containing an
11446 adjustable dummy array does
11447 not also contain every variable listed in the dimension list of the
11448 adjustable array.
11449
11450 Currently, @code{g77} does complain about a variable that
11451 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
11452 area, but this needs to be extended to catch cases where it doesn't appear in
11453 every dummy list that also lists any arrays it dimensions.
11454
11455 For example, @code{g77} should warn about the entry point @samp{ALT}
11456 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
11457 list of arguments:
11458
11459 @smallexample
11460 SUBROUTINE PRIMARY(ARRAY, ISIZE)
11461 REAL ARRAY(ISIZE)
11462 ENTRY ALT(ARRAY)
11463 @end smallexample
11464
11465 @node Invalid FORMAT Specifiers
11466 @subsection Invalid FORMAT Specifiers
11467
11468 @code{g77} should check @code{FORMAT} specifiers for validity
11469 as it does @code{FORMAT} statements.
11470
11471 For example, a diagnostic would be produced for:
11472
11473 @smallexample
11474 PRINT 'HI THERE!' !User meant PRINT *, 'HI THERE!'
11475 @end smallexample
11476
11477 @node Ambiguous Dialects
11478 @subsection Ambiguous Dialects
11479
11480 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
11481 @samp{-Wvxt}, @samp{-Wf90}, and so on.
11482 These would warn about places in the user's source where ambiguities
11483 are found, helpful in resolving ambiguities in the program's
11484 dialect or dialects.
11485
11486 @node Unused Labels
11487 @subsection Unused Labels
11488
11489 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
11490
11491 @node Informational Messages
11492 @subsection Informational Messages
11493
11494 @code{g77} needs an option to suppress information messages (notes).
11495 @samp{-w} does this but also suppresses warnings.
11496 The default should be to suppress info messages.
11497
11498 Perhaps info messages should simply be eliminated.
11499
11500 @node Uninitialized Variables at Run Time
11501 @subsection Uninitialized Variables at Run Time
11502
11503 @code{g77} needs an option to initialize everything (not otherwise
11504 explicitly initialized) to ``weird''
11505 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
11506 largest-magnitude integers, would help track down references to
11507 some kinds of uninitialized variables at run time.
11508
11509 Note that use of the options @samp{-O -Wuninitialized} can catch
11510 many such bugs at compile time.
11511
11512 @node Bounds Checking at Run Time
11513 @subsection Bounds Checking at Run Time
11514
11515 @code{g77} should offer run-time bounds-checking of array/subscript references
11516 in a fashion similar to @code{f2c}.
11517
11518 Note that @code{g77} already warns about references to out-of-bounds
11519 elements of arrays when it detects these at compile time.
11520
11521 @node Labels Visible to Debugger
11522 @subsection Labels Visible to Debugger
11523
11524 @code{g77} should output debugging information for statements labels,
11525 for use by debuggers that know how to support them.
11526 Same with weirder things like construct names.
11527 It is not yet known if any debug formats or debuggers support these.
11528
11529 @node Disappointments
11530 @section Disappointments and Misunderstandings
11531
11532 These problems are perhaps regrettable, but we don't know any practical
11533 way around them for now.
11534
11535 @menu
11536 * Mangling of Names:: @samp{SUBROUTINE FOO} is given
11537 external name @samp{foo_}.
11538 * Multiple Definitions of External Names:: No doing both @samp{COMMON /FOO/}
11539 and @samp{SUBROUTINE FOO}.
11540 * Limitation on Implicit Declarations:: No @samp{IMPLICIT CHARACTER*(*)}.
11541 @end menu
11542
11543 @node Mangling of Names
11544 @subsection Mangling of Names in Source Code
11545 @cindex naming issues
11546 @cindex external names
11547 @cindex common blocks
11548 @cindex name space
11549 @cindex underscores
11550
11551 The current external-interface design, which includes naming of
11552 external procedures, COMMON blocks, and the library interface,
11553 has various usability problems, including things like adding
11554 underscores where not really necessary (and preventing easier
11555 inter-language operability) and yet not providing complete
11556 namespace freedom for user C code linked with Fortran apps (due
11557 to the naming of functions in the library, among other things).
11558
11559 Project GNU should at least get all this ``right'' for systems
11560 it fully controls, such as the Hurd, and provide defaults and
11561 options for compatibility with existing systems and interoperability
11562 with popular existing compilers.
11563
11564 @node Multiple Definitions of External Names
11565 @subsection Multiple Definitions of External Names
11566 @cindex block data
11567 @cindex BLOCK DATA statement
11568 @cindex statements, BLOCK DATA
11569 @cindex COMMON statement
11570 @cindex statements, COMMON
11571 @cindex naming conflicts
11572
11573 @code{g77} doesn't allow a common block and an external procedure or
11574 @code{BLOCK DATA} to have the same name.
11575 Some systems allow this, but @code{g77} does not,
11576 to be compatible with @code{f2c}.
11577
11578 @code{g77} could special-case the way it handles
11579 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
11580 particular area (necessarily, since @code{g77} offers an
11581 important feature here), but
11582 it is likely that such special-casing would be very annoying to people
11583 with programs that use @samp{EXTERNAL FOO}, with no other mention of
11584 @samp{FOO} in the same program unit, to refer to external procedures, since
11585 the result would be that @code{g77} would treat these references as requests to
11586 force-load BLOCK DATA program units.
11587
11588 In that case, if @code{g77} modified
11589 names of @code{BLOCK DATA} so they could have the same names as
11590 @code{COMMON}, users
11591 would find that their programs wouldn't link because the @samp{FOO} procedure
11592 didn't have its name translated the same way.
11593
11594 (Strictly speaking,
11595 @code{g77} could emit a null-but-externally-satisfying definition of
11596 @samp{FOO} with its name transformed as if it had been a
11597 @code{BLOCK DATA}, but that probably invites more trouble than it's
11598 worth.)
11599
11600 @node Limitation on Implicit Declarations
11601 @subsection Limitation on Implicit Declarations
11602 @cindex IMPLICIT CHARACTER*(*) statement
11603 @cindex statements, IMPLICIT CHARACTER*(*)
11604
11605 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
11606 This is not standard-conforming.
11607
11608 @node Non-bugs
11609 @section Certain Changes We Don't Want to Make
11610
11611 This section lists changes that people frequently request, but which
11612 we do not make because we think GNU Fortran is better without them.
11613
11614 @menu
11615 * Backslash in Constants:: Why @samp{'\\'} is a constant that
11616 is one, not two, characters long.
11617 * Initializing Before Specifying:: Why @samp{DATA VAR/1/} can't precede
11618 @samp{COMMON VAR}.
11619 * Context-Sensitive Intrinsicness:: Why @samp{CALL SQRT} won't work.
11620 * Context-Sensitive Constants:: Why @samp{9.435784839284958} is a
11621 single-precision constant,
11622 and might be interpreted as
11623 @samp{9.435785} or similar.
11624 * Equivalence Versus Equality:: Why @samp{.TRUE. .EQ. .TRUE.} won't work.
11625 * Order of Side Effects:: Why @samp{J = IFUNC() - IFUNC()} might
11626 not behave as expected.
11627 @end menu
11628
11629 @node Backslash in Constants
11630 @subsection Backslash in Constants
11631 @cindex backslash
11632 @cindex f77 support
11633 @cindex support, f77
11634
11635 In the opinion of many experienced Fortran users,
11636 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
11637 as currently set by @code{g77}.
11638
11639 First of all, you can always specify
11640 @samp{-fno-backslash} to turn off this processing.
11641
11642 Despite not being within the spirit (though apparently within the
11643 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
11644 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
11645 default to, and apparently lots of code depends on this feature.
11646
11647 This is a particularly troubling issue.
11648 The use of a C construct in the midst of Fortran code
11649 is bad enough, worse when it makes existing Fortran
11650 programs stop working (as happens when programs written
11651 for non-UNIX systems are ported to UNIX systems with
11652 compilers that provide the @samp{-fbackslash} feature
11653 as the default---sometimes with no option to turn it off).
11654
11655 The author of GNU Fortran wished, for reasons of linguistic
11656 purity, to make @samp{-fno-backslash} the default for GNU
11657 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
11658 to specify @samp{-fbackslash} to get the UNIX behavior.
11659
11660 However, the realization that @code{g77} is intended as
11661 a replacement for @emph{UNIX} @code{f77}, caused the author
11662 to choose to make @code{g77} as compatible with
11663 @code{f77} as feasible, which meant making @samp{-fbackslash}
11664 the default.
11665
11666 The primary focus on compatibility is at the source-code
11667 level, and the question became ``What will users expect
11668 a replacement for @code{f77} to do, by default?''
11669 Although at least one UNIX @code{f77} does not provide
11670 @samp{-fbackslash} as a default, it appears that
11671 the majority of them do, which suggests that
11672 the majority of code that is compiled by UNIX @code{f77}
11673 compilers expects @samp{-fbackslash} to be the default.
11674
11675 It is probably the case that more code exists
11676 that would @emph{not} work with @samp{-fbackslash}
11677 in force than code that requires it be in force.
11678
11679 However, most of @emph{that} code is not being compiled
11680 with @code{f77},
11681 and when it is, new build procedures (shell scripts,
11682 makefiles, and so on) must be set up anyway so that
11683 they work under UNIX.
11684 That makes a much more natural and safe opportunity for
11685 non-UNIX users to adapt their build procedures for
11686 @code{g77}'s default of @samp{-fbackslash} than would
11687 exist for the majority of UNIX @code{f77} users who
11688 would have to modify existing, working build procedures
11689 to explicitly specify @samp{-fbackslash} if that was
11690 not the default.
11691
11692 One suggestion has been to configure the default for
11693 @samp{-fbackslash} (and perhaps other options as well)
11694 based on the configuration of @code{g77}.
11695
11696 This is technically quite straightforward, but will be avoided
11697 even in cases where not configuring defaults to be
11698 dependent on a particular configuration greatly inconveniences
11699 some users of legacy code.
11700
11701 Many users appreciate the GNU compilers because they provide an
11702 environment that is uniform across machines.
11703 These users would be
11704 inconvenienced if the compiler treated things like the
11705 format of the source code differently on certain machines.
11706
11707 Occasionally users write programs intended only for a particular machine
11708 type.
11709 On these occasions, the users would benefit if the GNU Fortran compiler
11710 were to support by default the same dialect as the other compilers on
11711 that machine.
11712 But such applications are rare.
11713 And users writing a
11714 program to run on more than one type of machine cannot possibly benefit
11715 from this kind of compatibility.
11716 (This is consistent with the design goals for @code{gcc}.
11717 To change them for @code{g77}, you must first change them
11718 for @code{gcc}.
11719 Do not ask the maintainers of @code{g77} to do this for you,
11720 or to disassociate @code{g77} from the widely understood, if
11721 not widely agreed-upon, goals for GNU compilers in general.)
11722
11723 This is why GNU Fortran does and will treat backslashes in the same
11724 fashion on all types of machines (by default).
11725 @xref{Direction of Language Development}, for more information on
11726 this overall philosophy guiding the development of the GNU Fortran
11727 language.
11728
11729 Of course, users strongly concerned about portability should indicate
11730 explicitly in their build procedures which options are expected
11731 by their source code, or write source code that has as few such
11732 expectations as possible.
11733
11734 For example, avoid writing code that depends on backslash (@samp{\})
11735 being interpreted either way in particular, such as by
11736 starting a program unit with:
11737
11738 @smallexample
11739 CHARACTER BACKSL
11740 PARAMETER (BACKSL = '\\')
11741 @end smallexample
11742
11743 @noindent
11744 Then, use concatenation of @samp{BACKSL} anyplace a backslash
11745 is desired.
11746 In this way, users can write programs which have the same meaning
11747 in many Fortran dialects.
11748
11749 (However, this technique does not work for Hollerith constants---which
11750 is just as well, since the only generally portable uses for Hollerith
11751 constants are in places where character constants can and should
11752 be used instead, for readability.)
11753
11754 @node Initializing Before Specifying
11755 @subsection Initializing Before Specifying
11756 @cindex initialization, statement placement
11757 @cindex placing initialization statements
11758
11759 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
11760 source code before @samp{COMMON VAR},
11761 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
11762 In general, @code{g77} requires initialization of a variable
11763 or array to be specified @emph{after} all other specifications
11764 of attributes (type, size, placement, and so on) of that variable
11765 or array are specified (though @emph{confirmation} of data type is
11766 permitted).
11767
11768 It is @emph{possible} @code{g77} will someday allow all of this,
11769 even though it is not allowed by the FORTRAN 77 standard.
11770
11771 Then again, maybe it is better to have
11772 @code{g77} always require placement of @code{DATA}
11773 so that it can possibly immediately write constants
11774 to the output file, thus saving time and space.
11775
11776 That is, @samp{DATA A/1000000*1/} should perhaps always
11777 be immediately writable to canonical assembler, unless it's already known
11778 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
11779 and to do this it cannot be followed by @samp{COMMON A}.
11780
11781 @node Context-Sensitive Intrinsicness
11782 @subsection Context-Sensitive Intrinsicness
11783 @cindex intrinsics, context-sensitive
11784 @cindex context-sensitive intrinsics
11785
11786 @code{g77} treats procedure references to @emph{possible} intrinsic
11787 names as always enabling their intrinsic nature, regardless of
11788 whether the @emph{form} of the reference is valid for that
11789 intrinsic.
11790
11791 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
11792 an invalid reference to the @code{SQRT} intrinsic function,
11793 because the reference is a subroutine invocation.
11794
11795 First, @code{g77} recognizes the statement @samp{CALL SQRT}
11796 as a reference to a @emph{procedure} named @samp{SQRT}, not
11797 to a @emph{variable} with that name (as it would for a statement
11798 such as @samp{V = SQRT}).
11799
11800 Next, @code{g77} establishes that, in the program unit being compiled,
11801 @code{SQRT} is an intrinsic---not a subroutine that
11802 happens to have the same name as an intrinsic (as would be
11803 the case if, for example, @samp{EXTERNAL SQRT} was present).
11804
11805 Finally, @code{g77} recognizes that the @emph{form} of the
11806 reference is invalid for that particular intrinsic.
11807 That is, it recognizes that it is invalid for an intrinsic
11808 @emph{function}, such as @code{SQRT}, to be invoked as
11809 a @emph{subroutine}.
11810
11811 At that point, @code{g77} issues a diagnostic.
11812
11813 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
11814 references an external subroutine of their own, not an
11815 intrinsic function.
11816
11817 However, @code{g77} knows about intrinsic
11818 subroutines, not just functions, and is able to support both having
11819 the same names, for example.
11820
11821 As a result of this, @code{g77} rejects calls
11822 to intrinsics that are not subroutines, and function invocations
11823 of intrinsics that are not functions, just as it (and most compilers)
11824 rejects invocations of intrinsics with the wrong number (or types)
11825 of arguments.
11826
11827 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
11828 a user-written subroutine named @samp{SQRT}.
11829
11830 @node Context-Sensitive Constants
11831 @subsection Context-Sensitive Constants
11832 @cindex constants, context-sensitive
11833 @cindex context-sensitive constants
11834
11835 @code{g77} does not use context to determine the types of
11836 constants or named constants (@code{PARAMETER}), except
11837 for (non-standard) typeless constants such as @samp{'123'O}.
11838
11839 For example, consider the following statement:
11840
11841 @smallexample
11842 PRINT *, 9.435784839284958 * 2D0
11843 @end smallexample
11844
11845 @noindent
11846 @code{g77} will interpret the (truncated) constant
11847 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
11848 constant, because the suffix @code{D0} is not specified.
11849
11850 As a result, the output of the above statement when
11851 compiled by @code{g77} will appear to have ``less precision''
11852 than when compiled by other compilers.
11853
11854 In these and other cases, some compilers detect the
11855 fact that a single-precision constant is used in
11856 a double-precision context and therefore interpret the
11857 single-precision constant as if it was @emph{explicitly}
11858 specified as a double-precision constant.
11859 (This has the effect of appending @emph{decimal}, not
11860 @emph{binary}, zeros to the fractional part of the
11861 number---producing different computational results.)
11862
11863 The reason this misfeature is dangerous is that a slight,
11864 apparently innocuous change to the source code can change
11865 the computational results. Consider:
11866
11867 @smallexample
11868 REAL ALMOST, CLOSE
11869 DOUBLE PRECISION FIVE
11870 PARAMETER (ALMOST = 5.000000000001)
11871 FIVE = 5
11872 CLOSE = 5.000000000001
11873 PRINT *, 5.000000000001 - FIVE
11874 PRINT *, ALMOST - FIVE
11875 PRINT *, CLOSE - FIVE
11876 END
11877 @end smallexample
11878
11879 @noindent
11880 Running the above program should
11881 result in the same value being
11882 printed three times.
11883 With @code{g77} as the compiler,
11884 it does.
11885
11886 However, compiled by many other compilers,
11887 running the above program would print
11888 two or three distinct values, because
11889 in two or three of the statements, the
11890 constant @samp{5.000000000001}, which
11891 on most systems is exactly equal to @samp{5.}
11892 when interpreted as a single-precision constant,
11893 is instead interpreted as a double-precision
11894 constant, preserving the represented
11895 precision.
11896 However, this ``clever'' promotion of
11897 type does not extend to variables or,
11898 in some compilers, to named constants.
11899
11900 Since programmers often are encouraged to replace manifest
11901 constants or permanently-assigned variables with named
11902 constants (@code{PARAMETER} in Fortran), and might need
11903 to replace some constants with variables having the same
11904 values for pertinent portions of code,
11905 it is important that compilers treat code so modified in the
11906 same way so that the results of such programs are the same.
11907 @code{g77} helps in this regard by treating constants just
11908 the same as variables in terms of determining their types
11909 in a context-independent way.
11910
11911 Still, there is a lot of existing Fortran code that has
11912 been written to depend on the way other compilers freely
11913 interpret constants' types based on context, so anything
11914 @code{g77} can do to help flag cases of this in such code
11915 could be very helpful.
11916
11917 @node Equivalence Versus Equality
11918 @subsection Equivalence Versus Equality
11919 @cindex .EQV., with integer operands
11920 @cindex comparing logical expressions
11921 @cindex logical expressions, comparing
11922
11923 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
11924 is not supported, except via @samp{-fugly}, which is not
11925 recommended except for legacy code (where the behavior expected
11926 by the @emph{code} is assumed).
11927
11928 Legacy code should be changed, as resources permit, to use @code{.EQV.}
11929 and @code{.NEQV.} instead, as these are permitted by the various
11930 Fortran standards.
11931
11932 New code should never be written expecting @code{.EQ.} or @code{.NE.}
11933 to work if either of its operands is @code{LOGICAL}.
11934
11935 The problem with supporting this ``feature'' is that there is
11936 unlikely to be consensus on how it works, as illustrated by the
11937 following sample program:
11938
11939 @smallexample
11940 LOGICAL L,M,N
11941 DATA L,M,N /3*.FALSE./
11942 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
11943 END
11944 @end smallexample
11945
11946 The issue raised by the above sample program is: what is the
11947 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
11948 @code{LOGICAL} operands?
11949
11950 Some programmers will argue that it is the same as the precedence
11951 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
11952 operands.
11953 By this interpretation, the subexpression @samp{M.EQ.N} must be
11954 evaluated first in the above program, resulting in a program that,
11955 when run, does not execute the @code{PRINT} statement.
11956
11957 Other programmers will argue that the precedence is the same as
11958 the precedence for @code{.EQV.}, which is restricted by the standards
11959 to @code{LOGICAL} operands.
11960 By this interpretation, the subexpression @samp{L.AND.M} must be
11961 evaluated first, resulting in a program that @emph{does} execute
11962 the @code{PRINT} statement.
11963
11964 Assigning arbitrary semantic interpretations to syntactic expressions
11965 that might legitimately have more than one ``obvious'' interpretation
11966 is generally unwise.
11967
11968 The creators of the various Fortran standards have done a good job
11969 in this case, requiring a distinct set of operators (which have their
11970 own distinct precedence) to compare @code{LOGICAL} operands.
11971 This requirement results in expression syntax with more certain
11972 precedence (without requiring substantial context), making it easier
11973 for programmers to read existing code.
11974 @code{g77} will avoid muddying up elements of the Fortran language
11975 that were well-designed in the first place.
11976
11977 (Ask C programmers about the precedence of expressions such as
11978 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
11979 you, without knowing more context, whether the @samp{&} and @samp{-}
11980 operators are infix (binary) or unary!)
11981
11982 @node Order of Side Effects
11983 @subsection Order of Side Effects
11984 @cindex side effects, order of evaluation
11985 @cindex order of evaluation, side effects
11986
11987 @code{g77} does not necessarily produce code that, when run, performs
11988 side effects (such as those performed by function invocations)
11989 in the same order as in some other compiler---or even in the same
11990 order as another version, port, or invocation (using different
11991 command-line options) of @code{g77}.
11992
11993 It is never safe to depend on the order of evaluation of side effects.
11994 For example, an expression like this may very well behave differently
11995 from one compiler to another:
11996
11997 @smallexample
11998 J = IFUNC() - IFUNC()
11999 @end smallexample
12000
12001 @noindent
12002 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
12003 order.
12004 Either invocation might happen first.
12005 If @samp{IFUNC} returns 5 the first time it is invoked, and
12006 returns 12 the second time, @samp{J} might end up with the
12007 value @samp{7}, or it might end up with @samp{-7}.
12008
12009 Generally, in Fortran, procedures with side-effects intended to
12010 be visible to the caller are best designed as @emph{subroutines},
12011 not functions.
12012 Examples of such side-effects include:
12013
12014 @itemize @bullet
12015 @item
12016 The generation of random numbers
12017 that are intended to influence return values.
12018
12019 @item
12020 Performing I/O
12021 (other than internal I/O to local variables).
12022
12023 @item
12024 Updating information in common blocks.
12025 @end itemize
12026
12027 An example of a side-effect that is not intended to be visible
12028 to the caller is a function that maintains a cache of recently
12029 calculated results, intended solely to speed repeated invocations
12030 of the function with identical arguments.
12031 Such a function can be safely used in expressions, because
12032 if the compiler optimizes away one or more calls to the
12033 function, operation of the program is unaffected (aside
12034 from being speeded up).
12035
12036 @node Warnings and Errors
12037 @section Warning Messages and Error Messages
12038
12039 @cindex error messages
12040 @cindex warnings vs errors
12041 @cindex messages, warning and error
12042 The GNU compiler can produce two kinds of diagnostics: errors and
12043 warnings.
12044 Each kind has a different purpose:
12045
12046 @itemize @w{}
12047 @item
12048 @emph{Errors} report problems that make it impossible to compile your
12049 program.
12050 GNU Fortran reports errors with the source file name, line
12051 number, and column within the line where the problem is apparent.
12052
12053 @item
12054 @emph{Warnings} report other unusual conditions in your code that
12055 @emph{might} indicate a problem, although compilation can (and does)
12056 proceed.
12057 Warning messages also report the source file name, line number,
12058 and column information,
12059 but include the text @samp{warning:} to distinguish them
12060 from error messages.
12061 @end itemize
12062
12063 Warnings might indicate danger points where you should check to make sure
12064 that your program really does what you intend; or the use of obsolete
12065 features; or the use of nonstandard features of GNU Fortran.
12066 Many warnings are issued only if you ask for them, with one of the
12067 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
12068 useful warnings).
12069
12070 @emph{Note:} Currently, the text of the line and a pointer to the column
12071 is printed in most @code{g77} diagnostics.
12072 Probably, as of version 0.6, @code{g77} will
12073 no longer print the text of the source line, instead printing
12074 the column number following the file name and line number in
12075 a form that GNU Emacs recognizes.
12076 This change is expected to speed up and reduce the memory usage
12077 of the @code{g77} compiler.
12078 @c
12079 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later. --burley
12080 @c
12081 @c GNU Fortran always tries to compile your program if possible; it never
12082 @c gratuitously rejects a program whose meaning is clear merely because
12083 @c (for instance) it fails to conform to a standard. In some cases,
12084 @c however, the Fortran standard specifies that certain extensions are
12085 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
12086 @c compiler. The @samp{-pedantic} option tells GNU Fortran to issue warnings
12087 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
12088 @c This does not mean that @emph{all} non-ANSI constructs get warnings
12089 @c or errors.
12090
12091 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
12092 more detail on these and related command-line options.
12093
12094 @node Open Questions
12095 @chapter Open Questions
12096
12097 Please consider offering useful answers to these questions!
12098
12099 @itemize @bullet
12100 @item
12101 How do system administrators and users manage multiple incompatible
12102 Fortran compilers on their systems?
12103 How can @code{g77} contribute to this, or at least avoiding
12104 intefering with it?
12105
12106 Currently, @code{g77} provides rudimentary ways to choose whether to
12107 overwrite portions of other Fortran compilation systems
12108 (such as the @code{f77} command and the @code{libf2c} library).
12109 Is this sufficient?
12110 What happens when users choose not to overwrite these---does
12111 @code{g77} work properly in all such installations, picking
12112 up its own versions, or does it pick up the existing ``alien''
12113 versions it didn't overwrite with its own, possibly leading
12114 to subtle bugs?
12115
12116 @item
12117 @code{LOC()} and other intrinsics are probably somewhat misclassified.
12118 Is the a need for more precise classification of intrinsics, and if so,
12119 what are the appropriate groupings?
12120 Is there a need to individually
12121 enable/disable/delete/hide intrinsics from the command line?
12122 @end itemize
12123
12124 @node Bugs
12125 @chapter Reporting Bugs
12126 @cindex bugs
12127 @cindex reporting bugs
12128
12129 Your bug reports play an essential role in making GNU Fortran reliable.
12130
12131 When you encounter a problem, the first thing to do is to see if it is
12132 already known.
12133 @xref{Trouble}.
12134 If it isn't known, then you should report the problem.
12135
12136 Reporting a bug might help you by bringing a solution to your problem, or
12137 it might not.
12138 (If it does not, look in the service directory; see
12139 @ref{Service}.)@
12140 In any case, the principal function of a bug report is
12141 to help the entire community by making the next version of GNU Fortran work
12142 better.
12143 Bug reports are your contribution to the maintenance of GNU Fortran.
12144
12145 Since the maintainers are very overloaded, we cannot respond to every
12146 bug report.
12147 However, if the bug has not been fixed, we are likely to
12148 send you a patch and ask you to tell us whether it works.
12149
12150 In order for a bug report to serve its purpose, you must include the
12151 information that makes for fixing the bug.
12152
12153 @menu
12154 * Criteria: Bug Criteria. Have you really found a bug?
12155 * Where: Bug Lists. Where to send your bug report.
12156 * Reporting: Bug Reporting. How to report a bug effectively.
12157 * Patches: Sending Patches. How to send a patch for GNU Fortran.
12158 @end menu
12159
12160 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
12161 for information on problems we already know about.
12162
12163 @xref{Service,,How To Get Help with GNU Fortran},
12164 for information on where to ask for help.
12165
12166 @node Bug Criteria
12167 @section Have You Found a Bug?
12168 @cindex bug criteria
12169
12170 If you are not sure whether you have found a bug, here are some guidelines:
12171
12172 @itemize @bullet
12173 @cindex fatal signal
12174 @cindex core dump
12175 @item
12176 If the compiler gets a fatal signal, for any input whatever, that is a
12177 compiler bug.
12178 Reliable compilers never crash---they just remain obsolete.
12179
12180 @cindex invalid assembly code
12181 @cindex assembly code, invalid
12182 @item
12183 If the compiler produces invalid assembly code, for any input whatever,
12184 @c (except an @code{asm} statement),
12185 that is a compiler bug, unless the
12186 compiler reports errors (not just warnings) which would ordinarily
12187 prevent the assembler from being run.
12188
12189 @cindex undefined behavior
12190 @cindex undefined function value
12191 @item
12192 If the compiler produces valid assembly code that does not correctly
12193 execute the input source code, that is a compiler bug.
12194
12195 However, you must double-check to make sure, because you might have run
12196 into an incompatibility between GNU Fortran and traditional Fortran.
12197 @c (@pxref{Incompatibilities}).
12198 These incompatibilities might be considered
12199 bugs, but they are inescapable consequences of valuable features.
12200
12201 Or you might have a program whose behavior is undefined, which happened
12202 by chance to give the desired results with another Fortran compiler.
12203 It is best to check the relevant Fortran standard thoroughly if
12204 it is possible that the program indeed does something undefined.
12205
12206 After you have localized the error to a single source line, it should
12207 be easy to check for these things.
12208 If your program is correct and well defined, you have found
12209 a compiler bug.
12210
12211 It might help if, in your submission, you identified the specific
12212 language in the relevant Fortran standard that specifies the
12213 desired behavior, if it isn't likely to be obvious and agreed-upon
12214 by all Fortran users.
12215
12216 @item
12217 If the compiler produces an error message for valid input, that is a
12218 compiler bug.
12219
12220 @cindex invalid input
12221 @item
12222 If the compiler does not produce an error message for invalid input,
12223 that is a compiler bug.
12224 However, you should note that your idea of
12225 ``invalid input'' might be someone else's idea
12226 of ``an extension'' or ``support for traditional practice''.
12227
12228 @item
12229 If you are an experienced user of Fortran compilers, your suggestions
12230 for improvement of GNU Fortran are welcome in any case.
12231 @end itemize
12232
12233 Many, perhaps most, bug reports against @code{g77} turn out to
12234 be bugs in the user's code.
12235 While we find such bug reports educational, they sometimes take
12236 a considerable amount of time to track down or at least respond
12237 to---time we could be spending making @code{g77}, not some user's
12238 code, better.
12239
12240 Some steps you can take to verify that the bug is not certainly
12241 in the code you're compiling with @code{g77}:
12242
12243 @itemize @bullet
12244 @item
12245 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
12246 These options enable many useful warning; the @samp{-O} option
12247 enables flow analysis that enables the uninitialized-variable
12248 warning.
12249
12250 If you investigate the warnings and find evidence of possible bugs
12251 in your code, fix them first and retry @code{g77}.
12252
12253 @item
12254 Compile your code using the @code{g77} options @samp{-finit-local-zero},
12255 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
12256 combinations thereof.
12257
12258 If your code works with any of these combinations, that is not
12259 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
12260 by your code might simply be avoided, or have a different, more subtle
12261 effect, when different options are used---but it can be a
12262 strong indicator that your code is making unawarranted assumptions
12263 about the Fortran dialect and/or underlying machine it is
12264 being compiled and run on.
12265
12266 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
12267 for information on the @samp{-fno-automatic} and
12268 @samp{-finit-local-zero} options and how to convert
12269 their use into selective changes in your own code.
12270
12271 @item
12272 @pindex ftncheck
12273 Validate your code with @code{ftnchek} or a similar code-checking
12274 tool.
12275 @code{ftncheck} can be found at @code{ftp://ftp.netlib.org/fortran}
12276 or @code{ftp://ftp.dsm.fordham.edu}.
12277
12278 @item
12279 Try your code out using other Fortran compilers, such as @code{f2c}.
12280 If it does not work on at least one other compiler (assuming the
12281 compiler supports the features the code needs), that is a strong
12282 indicator of a bug in the code.
12283
12284 However, even if your code works on many compilers @emph{except}
12285 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
12286 It might mean the bug is in your code, and that @code{g77} simply
12287 exposes it more readily than other compilers.
12288 @end itemize
12289
12290 @node Bug Lists
12291 @section Where to Report Bugs
12292 @cindex bug report mailing lists
12293 @kindex egcs-bugs@@cygnus.com
12294 Send bug reports for GNU Fortran to @email{egcs-bugs@@cygnus.com}.
12295
12296 Often people think of posting bug reports to a newsgroup instead of
12297 mailing them.
12298 This sometimes appears to work, but it has one problem which can be
12299 crucial: a newsgroup posting does not contain a mail path back to the
12300 sender.
12301 Thus, if maintainers need more information, they might be unable
12302 to reach you. For this reason, you should always send bug reports by
12303 mail to the proper mailing list.
12304
12305 As a last resort, send bug reports on paper to:
12306
12307 @example
12308 GNU Compiler Bugs
12309 Free Software Foundation
12310 59 Temple Place - Suite 330
12311 Boston, MA 02111-1307, USA
12312 @end example
12313
12314 @node Bug Reporting
12315 @section How to Report Bugs
12316 @cindex compiler bugs, reporting
12317
12318 The fundamental principle of reporting bugs usefully is this:
12319 @strong{report all the facts}.
12320 If you are not sure whether to state a
12321 fact or leave it out, state it!
12322
12323 Often people omit facts because they think they know what causes the
12324 problem and they conclude that some details don't matter.
12325 Thus, you might
12326 assume that the name of the variable you use in an example does not matter.
12327 Well, probably it doesn't, but one cannot be sure.
12328 Perhaps the bug is a
12329 stray memory reference which happens to fetch from the location where that
12330 name is stored in memory; perhaps, if the name were different, the contents
12331 of that location would fool the compiler into doing the right thing despite
12332 the bug.
12333 Play it safe and give a specific, complete example.
12334 That is the
12335 easiest thing for you to do, and the most helpful.
12336
12337 Keep in mind that the purpose of a bug report is to enable someone to
12338 fix the bug if it is not known.
12339 It isn't very important what happens if
12340 the bug is already known.
12341 Therefore, always write your bug reports on
12342 the assumption that the bug is not known.
12343
12344 Sometimes people give a few sketchy facts and ask, ``Does this ring a
12345 bell?''
12346 This cannot help us fix a bug, so it is rarely helpful.
12347 We respond by asking for enough details to enable us to investigate.
12348 You might as well expedite matters by sending them to begin with.
12349 (Besides, there are enough bells ringing around here as it is.)
12350
12351 Try to make your bug report self-contained.
12352 If we have to ask you for
12353 more information, it is best if you include all the previous information
12354 in your response, as well as the information that was missing.
12355
12356 Please report each bug in a separate message.
12357 This makes it easier for
12358 us to track which bugs have been fixed and to forward your bugs reports
12359 to the appropriate maintainer.
12360
12361 Do not compress and encode any part of your bug report using programs
12362 such as @file{uuencode}.
12363 If you do so it will slow down the processing
12364 of your bug.
12365 If you must submit multiple large files, use @file{shar},
12366 which allows us to read your message without having to run any
12367 decompression programs.
12368
12369 (As a special exception for GNU Fortran bug-reporting, at least
12370 for now, if you are sending more than a few lines of code, if
12371 your program's source file format contains ``interesting'' things
12372 like trailing spaces or strange characters, or if you need to
12373 include binary data files, it is acceptable to put all the
12374 files together in a @code{tar} archive, and, whether you need to
12375 do that, it is acceptable to then compress the single file (@code{tar}
12376 archive or source file)
12377 using @code{gzip} and encode it via @code{uuencode}.
12378 Do not use any MIME stuff---the current maintainer can't decode this.
12379 Using @code{compress} instead of @code{gzip} is acceptable, assuming
12380 you have licensed the use of the patented algorithm in
12381 @code{compress} from Unisys.)
12382
12383 To enable someone to investigate the bug, you should include all these
12384 things:
12385
12386 @itemize @bullet
12387 @item
12388 The version of GNU Fortran.
12389 You can get this by running @code{g77} with the @samp{-v} option.
12390 (Ignore any error messages that might be displayed
12391 when the linker is run.)
12392
12393 Without this, we won't know whether there is any point in looking for
12394 the bug in the current version of GNU Fortran.
12395
12396 @item
12397 @cindex preprocessor
12398 @cindex cpp program
12399 @cindex programs, cpp
12400 A complete input file that will reproduce the bug.
12401 If the bug is in the compiler proper (@file{f771}) and
12402 you are using the C preprocessor, run your
12403 source file through the C preprocessor by doing @samp{g77 -E
12404 @var{sourcefile} > @var{outfile}}, then include the contents of
12405 @var{outfile} in the bug report. (When you do this, use the same
12406 @samp{-I}, @samp{-D} or @samp{-U} options that you used in actual
12407 compilation.)
12408
12409 A single statement is not enough of an example.
12410 In order to compile it,
12411 it must be embedded in a complete file of compiler input; and the bug
12412 might depend on the details of how this is done.
12413
12414 Without a real example one can compile, all anyone can do about your bug
12415 report is wish you luck. It would be futile to try to guess how to
12416 provoke the bug. For example, bugs in register allocation and reloading
12417 frequently depend on every little detail of the function they happen in.
12418
12419 @item
12420 @cindex included files
12421 @cindex INCLUDE directive
12422 @cindex directive, INCLUDE
12423 @cindex #include directive
12424 @cindex directive, #include
12425 Note that you should include with your bug report any files
12426 included by the source file
12427 (via the @code{#include} or @code{INCLUDE} directive)
12428 that you send, and any files they include, and so on.
12429
12430 It is not necessary to replace
12431 the @code{#include} and @code{INCLUDE} directives
12432 with the actual files in the version of the source file that
12433 you send, but it might make submitting the bug report easier
12434 in the end.
12435 However, be sure to @emph{reproduce} the bug using the @emph{exact}
12436 version of the source material you submit, to avoid wild-goose
12437 chases.
12438
12439 @item
12440 The command arguments you gave GNU Fortran to compile that example
12441 and observe the bug. For example, did you use @samp{-O}? To guarantee
12442 you won't omit something important, list all the options.
12443
12444 If we were to try to guess the arguments, we would probably guess wrong
12445 and then we would not encounter the bug.
12446
12447 @item
12448 The type of machine you are using, and the operating system name and
12449 version number.
12450 (Much of this information is printed by @samp{g77 -v}---if you
12451 include that, send along any additional info you have that you
12452 don't see clearly represented in that output.)
12453
12454 @item
12455 The operands you gave to the @code{configure} command when you installed
12456 the compiler.
12457
12458 @item
12459 A complete list of any modifications you have made to the compiler
12460 source. (We don't promise to investigate the bug unless it happens in
12461 an unmodified compiler. But if you've made modifications and don't tell
12462 us, then you are sending us on a wild-goose chase.)
12463
12464 Be precise about these changes. A description in English is not
12465 enough---send a context diff for them.
12466
12467 Adding files of your own (such as a machine description for a machine we
12468 don't support) is a modification of the compiler source.
12469
12470 @item
12471 Details of any other deviations from the standard procedure for installing
12472 GNU Fortran.
12473
12474 @item
12475 A description of what behavior you observe that you believe is
12476 incorrect. For example, ``The compiler gets a fatal signal,'' or,
12477 ``The assembler instruction at line 208 in the output is incorrect.''
12478
12479 Of course, if the bug is that the compiler gets a fatal signal, then one
12480 can't miss it. But if the bug is incorrect output, the maintainer might
12481 not notice unless it is glaringly wrong. None of us has time to study
12482 all the assembler code from a 50-line Fortran program just on the chance that
12483 one instruction might be wrong. We need @emph{you} to do this part!
12484
12485 Even if the problem you experience is a fatal signal, you should still
12486 say so explicitly. Suppose something strange is going on, such as, your
12487 copy of the compiler is out of synch, or you have encountered a bug in
12488 the C library on your system. (This has happened!) Your copy might
12489 crash and the copy here would not. If you @i{said} to expect a crash,
12490 then when the compiler here fails to crash, we would know that the bug
12491 was not happening. If you don't say to expect a crash, then we would
12492 not know whether the bug was happening. We would not be able to draw
12493 any conclusion from our observations.
12494
12495 If the problem is a diagnostic when building GNU Fortran with some other
12496 compiler, say whether it is a warning or an error.
12497
12498 Often the observed symptom is incorrect output when your program is run.
12499 Sad to say, this is not enough information unless the program is short
12500 and simple. None of us has time to study a large program to figure out
12501 how it would work if compiled correctly, much less which line of it was
12502 compiled wrong. So you will have to do that. Tell us which source line
12503 it is, and what incorrect result happens when that line is executed. A
12504 person who understands the program can find this as easily as finding a
12505 bug in the program itself.
12506
12507 @item
12508 If you send examples of assembler code output from GNU Fortran,
12509 please use @samp{-g} when you make them. The debugging information
12510 includes source line numbers which are essential for correlating the
12511 output with the input.
12512
12513 @item
12514 If you wish to mention something in the GNU Fortran source, refer to it by
12515 context, not by line number.
12516
12517 The line numbers in the development sources don't match those in your
12518 sources. Your line numbers would convey no convenient information to the
12519 maintainers.
12520
12521 @item
12522 Additional information from a debugger might enable someone to find a
12523 problem on a machine which he does not have available. However, you
12524 need to think when you collect this information if you want it to have
12525 any chance of being useful.
12526
12527 @cindex backtrace for bug reports
12528 For example, many people send just a backtrace, but that is never
12529 useful by itself. A simple backtrace with arguments conveys little
12530 about GNU Fortran because the compiler is largely data-driven; the same
12531 functions are called over and over for different RTL insns, doing
12532 different things depending on the details of the insn.
12533
12534 Most of the arguments listed in the backtrace are useless because they
12535 are pointers to RTL list structure. The numeric values of the
12536 pointers, which the debugger prints in the backtrace, have no
12537 significance whatever; all that matters is the contents of the objects
12538 they point to (and most of the contents are other such pointers).
12539
12540 In addition, most compiler passes consist of one or more loops that
12541 scan the RTL insn sequence. The most vital piece of information about
12542 such a loop---which insn it has reached---is usually in a local variable,
12543 not in an argument.
12544
12545 @findex debug_rtx
12546 What you need to provide in addition to a backtrace are the values of
12547 the local variables for several stack frames up. When a local
12548 variable or an argument is an RTX, first print its value and then use
12549 the GDB command @code{pr} to print the RTL expression that it points
12550 to. (If GDB doesn't run on your machine, use your debugger to call
12551 the function @code{debug_rtx} with the RTX as an argument.) In
12552 general, whenever a variable is a pointer, its value is no use
12553 without the data it points to.
12554 @end itemize
12555
12556 Here are some things that are not necessary:
12557
12558 @itemize @bullet
12559 @item
12560 A description of the envelope of the bug.
12561
12562 Often people who encounter a bug spend a lot of time investigating
12563 which changes to the input file will make the bug go away and which
12564 changes will not affect it.
12565
12566 This is often time consuming and not very useful, because the way we
12567 will find the bug is by running a single example under the debugger with
12568 breakpoints, not by pure deduction from a series of examples. You might
12569 as well save your time for something else.
12570
12571 Of course, if you can find a simpler example to report @emph{instead} of
12572 the original one, that is a convenience. Errors in the output will be
12573 easier to spot, running under the debugger will take less time, etc.
12574 Most GNU Fortran bugs involve just one function, so the most straightforward
12575 way to simplify an example is to delete all the function definitions
12576 except the one where the bug occurs. Those earlier in the file may be
12577 replaced by external declarations if the crucial function depends on
12578 them. (Exception: inline functions might affect compilation of functions
12579 defined later in the file.)
12580
12581 However, simplification is not vital; if you don't want to do this,
12582 report the bug anyway and send the entire test case you used.
12583
12584 @item
12585 In particular, some people insert conditionals @samp{#ifdef BUG} around
12586 a statement which, if removed, makes the bug not happen. These are just
12587 clutter; we won't pay any attention to them anyway. Besides, you should
12588 send us preprocessor output, and that can't have conditionals.
12589
12590 @item
12591 A patch for the bug.
12592
12593 A patch for the bug is useful if it is a good one. But don't omit the
12594 necessary information, such as the test case, on the assumption that a
12595 patch is all we need. We might see problems with your patch and decide
12596 to fix the problem another way, or we might not understand it at all.
12597
12598 Sometimes with a program as complicated as GNU Fortran it is very hard to
12599 construct an example that will make the program follow a certain path
12600 through the code. If you don't send the example, we won't be able to
12601 construct one, so we won't be able to verify that the bug is fixed.
12602
12603 And if we can't understand what bug you are trying to fix, or why your
12604 patch should be an improvement, we won't install it. A test case will
12605 help us to understand.
12606
12607 @xref{Sending Patches}, for guidelines on how to make it easy for us to
12608 understand and install your patches.
12609
12610 @item
12611 A guess about what the bug is or what it depends on.
12612
12613 Such guesses are usually wrong. Even the maintainer can't guess right
12614 about such things without first using the debugger to find the facts.
12615
12616 @item
12617 A core dump file.
12618
12619 We have no way of examining a core dump for your type of machine
12620 unless we have an identical system---and if we do have one,
12621 we should be able to reproduce the crash ourselves.
12622 @end itemize
12623
12624 @node Sending Patches
12625 @section Sending Patches for GNU Fortran
12626
12627 If you would like to write bug fixes or improvements for the GNU Fortran
12628 compiler, that is very helpful.
12629 Send suggested fixes to the bug report
12630 mailing list, @email{egcs-bugs@@cygnus.com}.
12631
12632 Please follow these guidelines so we can study your patches efficiently.
12633 If you don't follow these guidelines, your information might still be
12634 useful, but using it will take extra work. Maintaining GNU Fortran is a lot
12635 of work in the best of circumstances, and we can't keep up unless you do
12636 your best to help.
12637
12638 @itemize @bullet
12639 @item
12640 Send an explanation with your changes of what problem they fix or what
12641 improvement they bring about. For a bug fix, just include a copy of the
12642 bug report, and explain why the change fixes the bug.
12643
12644 (Referring to a bug report is not as good as including it, because then
12645 we will have to look it up, and we have probably already deleted it if
12646 we've already fixed the bug.)
12647
12648 @item
12649 Always include a proper bug report for the problem you think you have
12650 fixed. We need to convince ourselves that the change is right before
12651 installing it. Even if it is right, we might have trouble judging it if
12652 we don't have a way to reproduce the problem.
12653
12654 @item
12655 Include all the comments that are appropriate to help people reading the
12656 source in the future understand why this change was needed.
12657
12658 @item
12659 Don't mix together changes made for different reasons.
12660 Send them @emph{individually}.
12661
12662 If you make two changes for separate reasons, then we might not want to
12663 install them both. We might want to install just one. If you send them
12664 all jumbled together in a single set of diffs, we have to do extra work
12665 to disentangle them---to figure out which parts of the change serve
12666 which purpose. If we don't have time for this, we might have to ignore
12667 your changes entirely.
12668
12669 If you send each change as soon as you have written it, with its own
12670 explanation, then the two changes never get tangled up, and we can
12671 consider each one properly without any extra work to disentangle them.
12672
12673 Ideally, each change you send should be impossible to subdivide into
12674 parts that we might want to consider separately, because each of its
12675 parts gets its motivation from the other parts.
12676
12677 @item
12678 Send each change as soon as that change is finished. Sometimes people
12679 think they are helping us by accumulating many changes to send them all
12680 together. As explained above, this is absolutely the worst thing you
12681 could do.
12682
12683 Since you should send each change separately, you might as well send it
12684 right away. That gives us the option of installing it immediately if it
12685 is important.
12686
12687 @item
12688 Use @samp{diff -c} to make your diffs. Diffs without context are hard
12689 for us to install reliably. More than that, they make it hard for us to
12690 study the diffs to decide whether we want to install them. Unidiff
12691 format is better than contextless diffs, but not as easy to read as
12692 @samp{-c} format.
12693
12694 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
12695 function that each change occurs in.
12696 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
12697
12698 @item
12699 Write the change log entries for your changes. We get lots of changes,
12700 and we don't have time to do all the change log writing ourselves.
12701
12702 Read the @file{ChangeLog} file to see what sorts of information to put
12703 in, and to learn the style that we use. The purpose of the change log
12704 is to show people where to find what was changed. So you need to be
12705 specific about what functions you changed; in large functions, it's
12706 often helpful to indicate where within the function the change was.
12707
12708 On the other hand, once you have shown people where to find the change,
12709 you need not explain its purpose. Thus, if you add a new function, all
12710 you need to say about it is that it is new. If you feel that the
12711 purpose needs explaining, it probably does---but the explanation will be
12712 much more useful if you put it in comments in the code.
12713
12714 If you would like your name to appear in the header line for who made
12715 the change, send us the header line.
12716
12717 @item
12718 When you write the fix, keep in mind that we can't install a change that
12719 would break other systems.
12720
12721 People often suggest fixing a problem by changing machine-independent
12722 files such as @file{toplev.c} to do something special that a particular
12723 system needs. Sometimes it is totally obvious that such changes would
12724 break GNU Fortran for almost all users. We can't possibly make a change like
12725 that. At best it might tell us how to write another patch that would
12726 solve the problem acceptably.
12727
12728 Sometimes people send fixes that @emph{might} be an improvement in
12729 general---but it is hard to be sure of this. It's hard to install
12730 such changes because we have to study them very carefully. Of course,
12731 a good explanation of the reasoning by which you concluded the change
12732 was correct can help convince us.
12733
12734 The safest changes are changes to the configuration files for a
12735 particular machine. These are safe because they can't create new bugs
12736 on other machines.
12737
12738 Please help us keep up with the workload by designing the patch in a
12739 form that is good to install.
12740 @end itemize
12741
12742 @node Service
12743 @chapter How To Get Help with GNU Fortran
12744
12745 If you need help installing, using or changing GNU Fortran, there are two
12746 ways to find it:
12747
12748 @itemize @bullet
12749 @item
12750 Look in the service directory for someone who might help you for a fee.
12751 The service directory is found in the file named @file{SERVICE} in the
12752 GNU CC distribution.
12753
12754 @item
12755 Send a message to @email{egcs@@cygnus.com}.
12756 @end itemize
12757
12758 @end ifset
12759 @ifset INTERNALS
12760 @node Adding Options
12761 @chapter Adding Options
12762 @cindex options, adding
12763 @cindex adding options
12764
12765 To add a new command-line option to @code{g77}, first decide
12766 what kind of option you wish to add.
12767 Search the @code{g77} and @code{gcc} documentation for one
12768 or more options that is most closely like the one you want to add
12769 (in terms of what kind of effect it has, and so on) to
12770 help clarify its nature.
12771
12772 @itemize @bullet
12773 @item
12774 @emph{Fortran options} are options that apply only
12775 when compiling Fortran programs.
12776 They are accepted by @code{g77} and @code{gcc}, but
12777 they apply only when compiling Fortran programs.
12778
12779 @item
12780 @emph{Compiler options} are options that apply
12781 when compiling most any kind of program.
12782 @end itemize
12783
12784 @emph{Fortran options} are listed in the file
12785 @file{gcc/f/lang-options.h},
12786 which is used during the build of @code{gcc} to
12787 build a list of all options that are accepted by
12788 at least one language's compiler.
12789 This list goes into the @samp{lang_options} array
12790 in @file{gcc/toplev.c}, which uses this array to
12791 determine whether a particular option should be
12792 offered to the linked-in front end for processing
12793 by calling @samp{lang_option_decode}, which, for
12794 @code{g77}, is in @file{gcc/f/com.c} and just
12795 calls @samp{ffe_decode_option}.
12796
12797 If the linked-in front end ``rejects'' a
12798 particular option passed to it, @file{toplev.c}
12799 just ignores the option, because @emph{some}
12800 language's compiler is willing to accept it.
12801
12802 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
12803 to work, even though Fortran compilation does
12804 not currently support the @samp{-fno-asm} option;
12805 even though the @code{f771} version of @samp{lang_decode_option}
12806 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
12807 produce a diagnostic because some other language (C)
12808 does accept it.
12809
12810 This also means that commands like
12811 @samp{g77 -fno-asm foo.f} yield no diagnostics,
12812 despite the fact that no phase of the command was
12813 able to recognize and process @samp{-fno-asm}---perhaps
12814 a warning about this would be helpful if it were
12815 possible.
12816
12817 Code that processes Fortran options is found in
12818 @file{gcc/f/top.c}, function @samp{ffe_decode_option}.
12819 This code needs to check positive and negative forms
12820 of each option.
12821
12822 The defaults for Fortran options are set in their
12823 global definitions, also found in @file{gcc/f/top.c}.
12824 Many of these defaults are actually macros defined
12825 in @file{gcc/f/target.h}, since they might be
12826 machine-specific.
12827 However, since, in practice, GNU compilers
12828 should behave the same way on all configurations
12829 (especially when it comes to language constructs),
12830 the practice of setting defaults in @file{target.h}
12831 is likely to be deprecated and, ultimately, stopped
12832 in future versions of @code{g77}.
12833
12834 Accessor macros for Fortran options, used by code
12835 in the @code{g77} FFE, are defined in @file{gcc/f/top.h}.
12836
12837 @emph{Compiler options} are listed in @file{gcc/toplev.c}
12838 in the array @samp{f_options}.
12839 An option not listed in @samp{lang_options} is
12840 looked up in @samp{f_options} and handled from there.
12841
12842 The defaults for compiler options are set in the
12843 global definitions for the corresponding variables,
12844 some of which are in @file{gcc/toplev.c}.
12845
12846 You can set different defaults for @emph{Fortran-oriented}
12847 or @emph{Fortran-reticent} compiler options by changing
12848 the way @code{f771} handles the @samp{-fset-g77-defaults}
12849 option, which is always provided as the first option when
12850 called by @code{g77} or @code{gcc}.
12851
12852 This code is in @samp{ffe_decode_options} in @file{gcc/f/top.c}.
12853 Have it change just the variables that you want to default
12854 to a different setting for Fortran compiles compared to
12855 compiles of other languages.
12856
12857 The @samp{-fset-g77-defaults} option is passed to @code{f771}
12858 automatically because of the specification information
12859 kept in @file{gcc/f/lang-specs.h}.
12860 This file tells the @code{gcc} command how to recognize,
12861 in this case, Fortran source files (those to be preprocessed,
12862 and those that are not), and further, how to invoke the
12863 appropriate programs (including @code{f771}) to process
12864 those source files.
12865
12866 It is in @file{gcc/f/lang-specs.h} that @samp{-fset-g77-defaults},
12867 @samp{-fversion}, and other options are passed, as appropriate,
12868 even when the user has not explicitly specified them.
12869 Other ``internal'' options such as @samp{-quiet} also
12870 are passed via this mechanism.
12871
12872 @node Projects
12873 @chapter Projects
12874 @cindex projects
12875
12876 If you want to contribute to @code{g77} by doing research,
12877 design, specification, documentation, coding, or testing,
12878 the following information should give you some ideas.
12879
12880 @menu
12881 * Efficiency:: Make @code{g77} itself compile code faster.
12882 * Better Optimization:: Teach @code{g77} to generate faster code.
12883 * Simplify Porting:: Make @code{g77} easier to configure, build,
12884 and install.
12885 * More Extensions:: Features many users won't know to ask for.
12886 * Machine Model:: @code{g77} should better leverage @code{gcc}.
12887 * Internals Documentation:: Make maintenance easier.
12888 * Internals Improvements:: Make internals more robust.
12889 * Better Diagnostics:: Make using @code{g77} on new code easier.
12890 @end menu
12891
12892 @node Efficiency
12893 @section Improve Efficiency
12894 @cindex efficiency
12895
12896 Don't bother doing any performance analysis until most of the
12897 following items are taken care of, because there's no question
12898 they represent serious space/time problems, although some of
12899 them show up only given certain kinds of (popular) input.
12900
12901 @itemize @bullet
12902 @item
12903 Improve @samp{malloc} package and its uses to specify more info about
12904 memory pools and, where feasible, use obstacks to implement them.
12905
12906 @item
12907 Skip over uninitialized portions of aggregate areas (arrays,
12908 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
12909 This would reduce memory usage for large initialized aggregate
12910 areas, even ones with only one initialized element.
12911
12912 As of version 0.5.18, a portion of this item has already been
12913 accomplished.
12914
12915 @item
12916 Prescan the statement (in @file{sta.c}) so that the nature of the statement
12917 is determined as much as possible by looking entirely at its form,
12918 and not looking at any context (previous statements, including types
12919 of symbols).
12920 This would allow ripping out of the statement-confirmation,
12921 symbol retraction/confirmation, and diagnostic inhibition
12922 mechanisms.
12923 Plus, it would result in much-improved diagnostics.
12924 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
12925 is not a subroutine intrinsic, would result actual error instead of the
12926 unimplemented-statement catch-all.
12927
12928 @item
12929 Throughout @code{g77}, don't pass line/column pairs where
12930 a simple @samp{ffewhere} type, which points to the error as much as is
12931 desired by the configuration, will do, and don't pass @samp{ffelexToken} types
12932 where a simple @samp{ffewhere} type will do.
12933 Then, allow new default
12934 configuration of @samp{ffewhere} such that the source line text is not
12935 preserved, and leave it to things like Emacs' next-error function
12936 to point to them (now that @samp{next-error} supports column,
12937 or, perhaps, character-offset, numbers).
12938 The change in calling sequences should improve performance somewhat,
12939 as should not having to save source lines.
12940 (Whether this whole
12941 item will improve performance is questionable, but it should
12942 improve maintainability.)
12943
12944 @item
12945 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
12946 as regards the assembly output.
12947 Some of this might require improving
12948 the back end, but lots of improvement in space/time required in @code{g77}
12949 itself can be fairly easily obtained without touching the back end.
12950 Maybe type-conversion, where necessary, can be speeded up as well in
12951 cases like the one shown (converting the @samp{2} into @samp{2.}).
12952
12953 @item
12954 If analysis shows it to be worthwhile, optimize @file{lex.c}.
12955
12956 @item
12957 Consider redesigning @file{lex.c} to not need any feedback
12958 during tokenization, by keeping track of enough parse state on its
12959 own.
12960 @end itemize
12961
12962 @node Better Optimization
12963 @section Better Optimization
12964 @cindex optimization, better
12965 @cindex code generation, improving
12966
12967 Much of this work should be put off until after @code{g77} has
12968 all the features necessary for its widespread acceptance as a
12969 useful F77 compiler.
12970 However, perhaps this work can be done in parallel during
12971 the feature-adding work.
12972
12973 @itemize @bullet
12974 @item
12975 Do the equivalent of the trick of putting @samp{extern inline} in front
12976 of every function definition in @code{libf2c} and #include'ing the resulting
12977 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
12978 that are at all worth inlining.
12979 (Some of this has already been done, such as for integral exponentiation.)
12980
12981 @item
12982 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
12983 and it's clear that types line up
12984 and @samp{CHAR_VAR} is addressable or not a @samp{VAR_DECL},
12985 make @samp{CHAR_VAR}, not a
12986 temporary, be the receiver for @samp{CHAR_FUNC}.
12987 (This is now done for @code{COMPLEX} variables.)
12988
12989 @item
12990 Design and implement Fortran-specific optimizations that don't
12991 really belong in the back end, or where the front end needs to
12992 give the back end more info than it currently does.
12993
12994 @item
12995 Design and implement a new run-time library interface, with the
12996 code going into @code{libgcc} so no special linking is required to
12997 link Fortran programs using standard language features.
12998 This library
12999 would speed up lots of things, from I/O (using precompiled formats,
13000 doing just one, or, at most, very few, calls for arrays or array sections,
13001 and so on) to general computing (array/section implementations of
13002 various intrinsics, implementation of commonly performed loops that
13003 aren't likely to be optimally compiled otherwise, etc.).
13004
13005 Among the important things the library would do are:
13006
13007 @itemize @bullet
13008 @item
13009 Be a one-stop-shop-type
13010 library, hence shareable and usable by all, in that what are now
13011 library-build-time options in @code{libf2c} would be moved at least to the
13012 @code{g77} compile phase, if not to finer grains (such as choosing how
13013 list-directed I/O formatting is done by default at @code{OPEN} time, for
13014 preconnected units via options or even statements in the main program
13015 unit, maybe even on a per-I/O basis with appropriate pragma-like
13016 devices).
13017 @end itemize
13018
13019 @item
13020 Probably requiring the new library design, change interface to
13021 normally have @code{COMPLEX} functions return their values in the way
13022 @code{gcc} would if they were declared @code{__complex__ float},
13023 rather than using
13024 the mechanism currently used by @code{CHARACTER} functions (whereby the
13025 functions are compiled as returning void and their first arg is
13026 a pointer to where to store the result).
13027 (Don't append underscores to
13028 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
13029 @code{gcc} rather than @code{f2c} calling conventions.)
13030
13031 @item
13032 Do something useful with @samp{doiter} references where possible.
13033 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
13034 a @code{DO} loop that uses @samp{I} as the
13035 iteration variable, and the back end might find that info useful
13036 in determining whether it needs to read @samp{I} back into a register after
13037 the call.
13038 (It normally has to do that, unless it knows @samp{FOO} never
13039 modifies its passed-by-reference argument, which is rarely the case
13040 for Fortran-77 code.)
13041 @end itemize
13042
13043 @node Simplify Porting
13044 @section Simplify Porting
13045 @cindex porting, simplify
13046 @cindex simplify porting
13047
13048 Making @code{g77} easier to configure, port, build, and install, either
13049 as a single-system compiler or as a cross-compiler, would be
13050 very useful.
13051
13052 @itemize @bullet
13053 @item
13054 A new library (replacing @code{libf2c}) should improve portability as well as
13055 produce more optimal code.
13056 Further, @code{g77} and the new library should
13057 conspire to simplify naming of externals, such as by removing unnecessarily
13058 added underscores, and to reduce/eliminate the possibility of naming
13059 conflicts, while making debugger more straightforward.
13060
13061 Also, it should
13062 make multi-language applications more feasible, such as by providing
13063 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
13064 descriptors.
13065
13066 @item
13067 Possibly related to a new library, @code{g77} should produce the equivalent
13068 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
13069 main program unit, instead of compiling something that must be
13070 called by a library
13071 implementation of @code{main()}.
13072
13073 This would do many useful things such as
13074 provide more flexibility in terms of setting up exception handling,
13075 not requiring programmers to start their debugging sessions with
13076 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
13077
13078 @item
13079 The GBE needs to understand the difference between alignment
13080 requirements and desires.
13081 For example, on Intel x86 machines, @code{g77} currently imposes
13082 overly strict alignment requirements, due to the back end, but it
13083 would be useful for Fortran and C programmers to be able to override
13084 these @emph{recommendations} as long as they don't violate the actual
13085 processor @emph{requirements}.
13086 @end itemize
13087
13088 @node More Extensions
13089 @section More Extensions
13090 @cindex extensions, more
13091
13092 These extensions are not the sort of things users ask for ``by name'',
13093 but they might improve the usability of @code{g77}, and Fortran in
13094 general, in the long run.
13095 Some of these items really pertain to improving @code{g77} internals
13096 so that some popular extensions can be more easily supported.
13097
13098 @itemize @bullet
13099 @item
13100 Look through all the documentation on the GNU Fortran language,
13101 dialects, compiler, missing features, bugs, and so on.
13102 Many mentions of incomplete or missing features are
13103 sprinkled throughout.
13104 It is not worth repeating them here.
13105
13106 @item
13107 @cindex concatenation
13108 @cindex CHARACTER*(*)
13109 Support arbitrary operands for concatenation, even in contexts where
13110 run-time allocation is required.
13111
13112 @item
13113 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
13114 named and unnamed.
13115 The idea is to provide a forward-looking, effective
13116 replacement for things like the old-style @code{PARAMETER} statement
13117 when people
13118 really need typelessness in a maintainable, portable, clearly documented
13119 way.
13120 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
13121 and whatever else might come along.
13122 (This is not really a call for polymorphism per se, just
13123 an ability to express limited, syntactic polymorphism.)
13124
13125 @item
13126 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
13127
13128 @item
13129 Support arbitrary file unit numbers, instead of limiting them
13130 to 0 through @samp{MXUNIT-1}.
13131 (This is a @code{libf2c} issue.)
13132
13133 @item
13134 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
13135 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
13136 later @code{UNIT=} in the first example is invalid.
13137 Make sure this is what users of this feature would expect.
13138
13139 @item
13140 Currently @code{g77} disallows @samp{READ(1'10)} since
13141 it is an obnoxious syntax, but
13142 supporting it might be pretty easy if needed.
13143 More details are needed, such
13144 as whether general expressions separated by an apostrophe are supported,
13145 or maybe the record number can be a general expression, and so on.
13146
13147 @item
13148 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
13149 fully.
13150 Currently there is no support at all
13151 for @code{%FILL} in @code{STRUCTURE} and related syntax,
13152 whereas the rest of the
13153 stuff has at least some parsing support.
13154 This requires either major
13155 changes to @code{libf2c} or its replacement.
13156
13157 @item
13158 F90 and @code{g77} probably disagree about label scoping relative to
13159 @code{INTERFACE} and @code{END INTERFACE}, and their contained
13160 procedure interface bodies (blocks?).
13161
13162 @item
13163 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
13164 since that was added after S8.112.
13165
13166 @item
13167 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
13168 with the final form of the standard (it was vague at S8.112).
13169
13170 @item
13171 It seems to be an ``open'' question whether a file, immediately after being
13172 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
13173 might be nice to offer an option of opening to ``undefined'' status, requiring
13174 an explicit absolute-positioning operation to be performed before any
13175 other (besides @code{CLOSE}) to assist in making applications port to systems
13176 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
13177 @end itemize
13178
13179 @node Machine Model
13180 @section Machine Model
13181
13182 This items pertain to generalizing @code{g77}'s view of
13183 the machine model to more fully accept whatever the GBE
13184 provides it via its configuration.
13185
13186 @itemize @bullet
13187 @item
13188 Switch to using @samp{REAL_VALUE_TYPE} to represent floating-point constants
13189 exclusively so the target float format need not be required.
13190 This
13191 means changing the way @code{g77} handles initialization of aggregate areas
13192 having more than one type, such as @code{REAL} and @code{INTEGER},
13193 because currently
13194 it initializes them as if they were arrays of @code{char} and uses the
13195 bit patterns of the constants of the various types in them to determine
13196 what to stuff in elements of the arrays.
13197
13198 @item
13199 Rely more and more on back-end info and capabilities, especially in the
13200 area of constants (where having the @code{g77} front-end's IL just store
13201 the appropriate tree nodes containing constants might be best).
13202
13203 @item
13204 Suite of C and Fortran programs that a user/administrator can run on a
13205 machine to help determine the configuration for @code{g77} before building
13206 and help determine if the compiler works (especially with whatever
13207 libraries are installed) after building.
13208 @end itemize
13209
13210 @node Internals Documentation
13211 @section Internals Documentation
13212
13213 Better info on how @code{g77} works and how to port it is needed.
13214 Much of this should be done only after the redesign planned for
13215 0.6 is complete.
13216
13217 @node Internals Improvements
13218 @section Internals Improvements
13219
13220 Some more items that would make @code{g77} more reliable
13221 and easier to maintain:
13222
13223 @itemize @bullet
13224 @item
13225 Generally make expression handling focus
13226 more on critical syntax stuff, leaving semantics to callers.
13227 For example,
13228 anything a caller can check, semantically, let it do so, rather
13229 than having @file{expr.c} do it.
13230 (Exceptions might include things like
13231 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
13232 it seems
13233 important to preserve the left-to-right-in-source order of production
13234 of diagnostics.)
13235
13236 @item
13237 Come up with better naming conventions for @samp{-D} to establish requirements
13238 to achieve desired implementation dialect via @file{proj.h}.
13239
13240 @item
13241 Clean up used tokens and @samp{ffewhere}s in @samp{ffeglobal_terminate_1}.
13242
13243 @item
13244 Replace @file{sta.c} @samp{outpooldisp} mechanism with @samp{malloc_pool_use}.
13245
13246 @item
13247 Check for @samp{opANY} in more places in @file{com.c}, @file{std.c},
13248 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
13249 (after determining if there is indeed no real need for it).
13250
13251 @item
13252 Utility to read and check @file{bad.def} messages and their references in the
13253 code, to make sure calls are consistent with message templates.
13254
13255 @item
13256 Search and fix @samp{&ffe@dots{}} and similar so that
13257 @samp{ffe@dots{}ptr@dots{}} macros are
13258 available instead (a good argument for wishing this could have written all
13259 this stuff in C++, perhaps).
13260 On the other hand, it's questionable whether this sort of
13261 improvement is really necessary, given the availability of
13262 tools such as Emacs and Perl, which make finding any
13263 address-taking of structure members easy enough?
13264
13265 @item
13266 Some modules truly export the member names of their structures (and the
13267 structures themselves), maybe fix this, and fix other modules that just
13268 appear to as well (by appending @samp{_}, though it'd be ugly and probably
13269 not worth the time).
13270
13271 @item
13272 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
13273 in @file{proj.h}
13274 and use them throughout @code{g77} source code (especially in the definitions
13275 of access macros in @samp{.h} files) so they can be tailored
13276 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
13277
13278 @item
13279 Decorate throughout with @code{const} and other such stuff.
13280
13281 @item
13282 All F90 notational derivations in the source code are still based
13283 on the S8.112 version of the draft standard.
13284 Probably should update
13285 to the official standard, or put documentation of the rules as used
13286 in the code@dots{}uh@dots{}in the code.
13287
13288 @item
13289 Some @samp{ffebld_new} calls (those outside of @file{ffeexpr.c} or
13290 inside but invoked via paths not involving @samp{ffeexpr_lhs} or
13291 @samp{ffeexpr_rhs}) might be creating things
13292 in improper pools, leading to such things staying around too long or
13293 (doubtful, but possible and dangerous) not long enough.
13294
13295 @item
13296 Some @samp{ffebld_list_new} (or whatever) calls might not be matched by
13297 @samp{ffebld_list_bottom} (or whatever) calls, which might someday matter.
13298 (It definitely is not a problem just yet.)
13299
13300 @item
13301 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
13302 due to alignment/mismatch or other problems---they end up without
13303 @samp{ffestorag} objects, so maybe the backend (and other parts of the front
13304 end) can notice that and handle like an @samp{opANY} (do what it wants, just
13305 don't complain or crash).
13306 Most of this seems to have been addressed
13307 by now, but a code review wouldn't hurt.
13308 @end itemize
13309
13310 @node Better Diagnostics
13311 @section Better Diagnostics
13312
13313 These are things users might not ask about, or that need to
13314 be looked into, before worrying about.
13315 Also here are items that involve reducing unnecessary diagnostic
13316 clutter.
13317
13318 @itemize @bullet
13319 @item
13320 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
13321 lengths, type classes, and so on),
13322 @samp{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
13323 it specifies.
13324
13325 @item
13326 Speed up and improve error handling for data when repeat-count is
13327 specified.
13328 For example, don't output 20 unnecessary messages after the
13329 first necessary one for:
13330
13331 @smallexample
13332 INTEGER X(20)
13333 CONTINUE
13334 DATA (X(I), J= 1, 20) /20*5/
13335 END
13336 @end smallexample
13337
13338 @noindent
13339 (The @code{CONTINUE} statement ensures the @code{DATA} statement
13340 is processed in the context of executable, not specification,
13341 statements.)
13342 @end itemize
13343 @end ifset
13344
13345 @ifset USING
13346 @node Diagnostics
13347 @chapter Diagnostics
13348 @cindex diagnostics
13349
13350 Some diagnostics produced by @code{g77} require sufficient explanation
13351 that the explanations are given below, and the diagnostics themselves
13352 identify the appropriate explanation.
13353
13354 Identification uses the GNU Info format---specifically, the @code{info}
13355 command that displays the explanation is given in within square
13356 brackets in the diagnostic.
13357 For example:
13358
13359 @smallexample
13360 foo.f:5: Invalid statement [info -f g77 M FOOEY]
13361 @end smallexample
13362
13363 More details about the above diagnostic is found in the @code{g77} Info
13364 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
13365 which is displayed by typing the UNIX command
13366 @samp{info -f g77 M FOOEY}.
13367
13368 Other Info readers, such as EMACS, may be just as easily used to display
13369 the pertinent node.
13370 In the above example, @samp{g77} is the Info document name,
13371 @samp{M} is the top-level menu item to select,
13372 and, in that node (named @samp{Diagnostics}, the name of
13373 this chapter, which is the very text you're reading now),
13374 @samp{FOOEY} is the menu item to select.
13375
13376 @iftex
13377 In this printed version of the @code{g77} manual, the above example
13378 points to a section, below, entitled @samp{FOOEY}---though, of course,
13379 as the above is just a sample, no such section exists.
13380 @end iftex
13381
13382 @menu
13383 * CMPAMBIG:: Ambiguous use of intrinsic.
13384 * EXPIMP:: Intrinsic used explicitly and implicitly.
13385 * INTGLOB:: Intrinsic also used as name of global.
13386 * LEX:: Various lexer messages
13387 * GLOBALS:: Disagreements about globals.
13388 @end menu
13389
13390 @node CMPAMBIG
13391 @section @code{CMPAMBIG}
13392
13393 @noindent
13394 @smallexample
13395 Ambiguous use of intrinsic @var{intrinsic} @dots{}
13396 @end smallexample
13397
13398 The type of the argument to the invocation of the @var{intrinsic}
13399 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
13400 Typically, it is @code{COMPLEX(KIND=2)}, also known as
13401 @code{DOUBLE COMPLEX}.
13402
13403 The interpretation of this invocation depends on the particular
13404 dialect of Fortran for which the code was written.
13405 Some dialects convert the real part of the argument to
13406 @code{REAL(KIND=1)}, thus losing precision; other dialects,
13407 and Fortran 90, do no such conversion.
13408
13409 So, GNU Fortran rejects such invocations except under certain
13410 circumstances, to avoid making an incorrect assumption that results
13411 in generating the wrong code.
13412
13413 To determine the dialect of the program unit, perhaps even whether
13414 that particular invocation is properly coded, determine how the
13415 result of the intrinsic is used.
13416
13417 The result of @var{intrinsic} is expected (by the original programmer)
13418 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
13419
13420 @itemize @bullet
13421 @item
13422 It is passed as an argument to a procedure that explicitly or
13423 implicitly declares that argument @code{REAL(KIND=1)}.
13424
13425 For example,
13426 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
13427 statement specifying the dummy argument corresponding to an
13428 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
13429 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
13430 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
13431 of @code{REAL(KIND=2)}.
13432
13433 @item
13434 It is used in a context that would otherwise not include
13435 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
13436 invocation as @code{REAL(KIND=2)} would result in unnecessary
13437 promotions and (typically) more expensive operations on the
13438 wider type.
13439
13440 For example:
13441
13442 @smallexample
13443 DOUBLE COMPLEX Z
13444 @dots{}
13445 R(1) = T * REAL(Z)
13446 @end smallexample
13447
13448 The above example suggests the programmer expected the real part
13449 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
13450 multiplied by @samp{T} (presumed, along with @samp{R} above, to
13451 be type @code{REAL(KIND=1)}).
13452
13453 Otherwise, the conversion would have to be delayed until after
13454 the multiplication, requiring not only an extra conversion
13455 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
13456 expensive multiplication (a double-precision multiplication instead
13457 of a single-precision one).
13458 @end itemize
13459
13460 The result of @var{intrinsic} is expected (by the original programmer)
13461 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
13462
13463 @itemize @bullet
13464 @item
13465 It is passed as an argument to a procedure that explicitly or
13466 implicitly declares that argument @code{REAL(KIND=2)}.
13467
13468 For example, a procedure specifying a @code{DOUBLE PRECISION}
13469 dummy argument corresponding to an
13470 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
13471 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
13472 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
13473 of @code{REAL(KIND=1)}.
13474
13475 @item
13476 It is used in an expression context that includes
13477 other @code{REAL(KIND=2)} operands,
13478 or is assigned to a @code{REAL(KIND=2)} variable or array element.
13479
13480 For example:
13481
13482 @smallexample
13483 DOUBLE COMPLEX Z
13484 DOUBLE PRECISION R, T
13485 @dots{}
13486 R(1) = T * REAL(Z)
13487 @end smallexample
13488
13489 The above example suggests the programmer expected the real part
13490 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
13491 by the @code{REAL()} intrinsic.
13492
13493 Otherwise, the conversion would have to be immediately followed
13494 by a conversion back to @code{REAL(KIND=2)}, losing
13495 the original, full precision of the real part of @code{Z},
13496 before being multiplied by @samp{T}.
13497 @end itemize
13498
13499 Once you have determined whether a particular invocation of @var{intrinsic}
13500 expects the Fortran 90 interpretation, you can:
13501
13502 @itemize @bullet
13503 @item
13504 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
13505 @samp{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
13506 is @samp{AIMAG})
13507 if it expected the Fortran 90 interpretation.
13508
13509 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
13510 some other type, such as @code{COMPLEX*32}, you should use the
13511 appropriate intrinsic, such as the one to convert to @code{REAL*16}
13512 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
13513 @code{QIMAG()} in place of @code{DIMAG()}).
13514
13515 @item
13516 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
13517 otherwise.
13518 This converts to @code{REAL(KIND=1)} in all working
13519 Fortran compilers.
13520 @end itemize
13521
13522 If you don't want to change the code, and you are certain that all
13523 ambiguous invocations of @var{intrinsic} in the source file have
13524 the same expectation regarding interpretation, you can:
13525
13526 @itemize @bullet
13527 @item
13528 Compile with the @code{g77} option @samp{-ff90}, to enable the
13529 Fortran 90 interpretation.
13530
13531 @item
13532 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
13533 to enable the non-Fortran-90 interpretations.
13534 @end itemize
13535
13536 @xref{REAL() and AIMAG() of Complex}, for more information on this
13537 issue.
13538
13539 Note: If the above suggestions don't produce enough evidence
13540 as to whether a particular program expects the Fortran 90
13541 interpretation of this ambiguous invocation of @var{intrinsic},
13542 there is one more thing you can try.
13543
13544 If you have access to most or all the compilers used on the
13545 program to create successfully tested and deployed executables,
13546 read the documentation for, and @emph{also} test out, each compiler
13547 to determine how it treats the @var{intrinsic} intrinsic in
13548 this case.
13549 (If all the compilers don't agree on an interpretation, there
13550 might be lurking bugs in the deployed versions of the program.)
13551
13552 The following sample program might help:
13553
13554 @cindex JCB003 program
13555 @smallexample
13556 PROGRAM JCB003
13557 C
13558 C Written by James Craig Burley 1997-02-23.
13559 C Contact via Internet email: burley@@gnu.ai.mit.edu
13560 C
13561 C Determine how compilers handle non-standard REAL
13562 C and AIMAG on DOUBLE COMPLEX operands.
13563 C
13564 DOUBLE COMPLEX Z
13565 REAL R
13566 Z = (3.3D0, 4.4D0)
13567 R = Z
13568 CALL DUMDUM(Z, R)
13569 R = REAL(Z) - R
13570 IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
13571 IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
13572 R = 4.4D0
13573 CALL DUMDUM(Z, R)
13574 R = AIMAG(Z) - R
13575 IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
13576 IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
13577 END
13578 C
13579 C Just to make sure compiler doesn't use naive flow
13580 C analysis to optimize away careful work above,
13581 C which might invalidate results....
13582 C
13583 SUBROUTINE DUMDUM(Z, R)
13584 DOUBLE COMPLEX Z
13585 REAL R
13586 END
13587 @end smallexample
13588
13589 If the above program prints contradictory results on a
13590 particular compiler, run away!
13591
13592 @node EXPIMP
13593 @section @code{EXPIMP}
13594
13595 @noindent
13596 @smallexample
13597 Intrinsic @var{intrinsic} referenced @dots{}
13598 @end smallexample
13599
13600 The @var{intrinsic} is explicitly declared in one program
13601 unit in the source file and implicitly used as an intrinsic
13602 in another program unit in the same source file.
13603
13604 This diagnostic is designed to catch cases where a program
13605 might depend on using the name @var{intrinsic} as an intrinsic
13606 in one program unit and as a global name (such as the name
13607 of a subroutine or function) in another, but @code{g77} recognizes
13608 the name as an intrinsic in both cases.
13609
13610 After verifying that the program unit making implicit use
13611 of the intrinsic is indeed written expecting the intrinsic,
13612 add an @samp{INTRINSIC @var{intrinsic}} statement to that
13613 program unit to prevent this warning.
13614
13615 This and related warnings are disabled by using
13616 the @samp{-Wno-globals} option when compiling.
13617
13618 Note that this warning is not issued for standard intrinsics.
13619 Standard intrinsics include those described in the FORTRAN 77
13620 standard and, if @samp{-ff90} is specified, those described
13621 in the Fortran 90 standard.
13622 Such intrinsics are not as likely to be confused with user
13623 procedures as intrinsics provided as extensions to the
13624 standard by @code{g77}.
13625
13626 @node INTGLOB
13627 @section @code{INTGLOB}
13628
13629 @noindent
13630 @smallexample
13631 Same name `@var{intrinsic}' given @dots{}
13632 @end smallexample
13633
13634 The name @var{intrinsic} is used for a global entity (a common
13635 block or a program unit) in one program unit and implicitly
13636 used as an intrinsic in another program unit.
13637
13638 This diagnostic is designed to catch cases where a program
13639 intends to use a name entirely as a global name, but @code{g77}
13640 recognizes the name as an intrinsic in the program unit that
13641 references the name, a situation that would likely produce
13642 incorrect code.
13643
13644 For example:
13645
13646 @smallexample
13647 INTEGER FUNCTION TIME()
13648 @dots{}
13649 END
13650 @dots{}
13651 PROGRAM SAMP
13652 INTEGER TIME
13653 PRINT *, 'Time is ', TIME()
13654 END
13655 @end smallexample
13656
13657 The above example defines a program unit named @samp{TIME}, but
13658 the reference to @samp{TIME} in the main program unit @samp{SAMP}
13659 is normally treated by @code{g77} as a reference to the intrinsic
13660 @code{TIME()} (unless a command-line option that prevents such
13661 treatment has been specified).
13662
13663 As a result, the program @samp{SAMP} will @emph{not}
13664 invoke the @samp{TIME} function in the same source file.
13665
13666 Since @code{g77} recognizes @code{libU77} procedures as
13667 intrinsics, and since some existing code uses the same names
13668 for its own procedures as used by some @code{libU77}
13669 procedures, this situation is expected to arise often enough
13670 to make this sort of warning worth issuing.
13671
13672 After verifying that the program unit making implicit use
13673 of the intrinsic is indeed written expecting the intrinsic,
13674 add an @samp{INTRINSIC @var{intrinsic}} statement to that
13675 program unit to prevent this warning.
13676
13677 Or, if you believe the program unit is designed to invoke the
13678 program-defined procedure instead of the intrinsic (as
13679 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
13680 statement to the program unit that references the name to
13681 prevent this warning.
13682
13683 This and related warnings are disabled by using
13684 the @samp{-Wno-globals} option when compiling.
13685
13686 Note that this warning is not issued for standard intrinsics.
13687 Standard intrinsics include those described in the FORTRAN 77
13688 standard and, if @samp{-ff90} is specified, those described
13689 in the Fortran 90 standard.
13690 Such intrinsics are not as likely to be confused with user
13691 procedures as intrinsics provided as extensions to the
13692 standard by @code{g77}.
13693
13694 @node LEX
13695 @section @code{LEX}
13696
13697 @noindent
13698 @smallexample
13699 Unrecognized character @dots{}
13700 Invalid first character @dots{}
13701 Line too long @dots{}
13702 Non-numeric character @dots{}
13703 Continuation indicator @dots{}
13704 Label at @dots{} invalid with continuation line indicator @dots{}
13705 Character constant @dots{}
13706 Continuation line @dots{}
13707 Statement at @dots{} begins with invalid token
13708 @end smallexample
13709
13710 Although the diagnostics identify specific problems, they can
13711 be produced when general problems such as the following occur:
13712
13713 @itemize @bullet
13714 @item
13715 The source file contains something other than Fortran code.
13716
13717 If the code in the file does not look like many of the examples
13718 elsewhere in this document, it might not be Fortran code.
13719 (Note that Fortran code often is written in lower case letters,
13720 while the examples in this document use upper case letters,
13721 for stylistic reasons.)
13722
13723 For example, if the file contains lots of strange-looking
13724 characters, it might be APL source code; if it contains lots
13725 of parentheses, it might be Lisp source code; if it
13726 contains lots of bugs, it might be C++ source code.
13727
13728 @item
13729 The source file contains free-form Fortran code, but @samp{-ffree-form}
13730 was not specified on the command line to compile it.
13731
13732 Free form is a newer form for Fortran code.
13733 The older, classic form is called fixed form.
13734
13735 Fixed-form code is visually fairly distinctive, because
13736 numerical labels and comments are all that appear in
13737 the first five columns of a line, the sixth column is
13738 reserved to denote continuation lines,
13739 and actual statements start at or beyond column 7.
13740 Spaces generally are not significant, so if you
13741 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
13742 you are looking at fixed-form code.
13743 Comment lines are indicated by the letter @samp{C} or the symbol
13744 @samp{*} in column 1.
13745 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
13746 which many compilers support.)
13747
13748 Free-form code is distinguished from fixed-form source
13749 primarily by the fact that statements may start anywhere.
13750 (If lots of statements start in columns 1 through 6,
13751 that's a strong indicator of free-form source.)
13752 Consecutive keywords must be separated by spaces, so
13753 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
13754 There are no comment lines per se, but @samp{!} starts a
13755 comment anywhere in a line (other than within a character or
13756 hollerith constant).
13757
13758 @xref{Source Form}, for more information.
13759
13760 @item
13761 The source file is in fixed form and has been edited without
13762 sensitivity to the column requirements.
13763
13764 Statements in fixed-form code must be entirely contained within
13765 columns 7 through 72 on a given line.
13766 Starting them ``early'' is more likely to result in diagnostics
13767 than finishing them ``late'', though both kinds of errors are
13768 often caught at compile time.
13769
13770 For example, if the following code fragment is edited by following
13771 the commented instructions literally, the result, shown afterward,
13772 would produce a diagnostic when compiled:
13773
13774 @smallexample
13775 C On XYZZY systems, remove "C" on next line:
13776 C CALL XYZZY_RESET
13777 @end smallexample
13778
13779 The result of editing the above line might be:
13780
13781 @smallexample
13782 C On XYZZY systems, remove "C" on next line:
13783 CALL XYZZY_RESET
13784 @end smallexample
13785
13786 However, that leaves the first @samp{C} in the @samp{CALL}
13787 statement in column 6, making it a comment line, which is
13788 not really what the author intended, and which is likely
13789 to result in one of the above-listed diagnostics.
13790
13791 @emph{Replacing} the @samp{C} in column 1 with a space
13792 is the proper change to make, to ensure the @samp{CALL}
13793 keyword starts in or after column 7.
13794
13795 Another common mistake like this is to forget that fixed-form
13796 source lines are significant through only column 72, and that,
13797 normally, any text beyond column 72 is ignored or is diagnosed
13798 at compile time.
13799
13800 @xref{Source Form}, for more information.
13801
13802 @item
13803 The source file requires preprocessing, and the preprocessing
13804 is not being specified at compile time.
13805
13806 A source file containing lines beginning with @code{#define},
13807 @code{#include}, @code{#if}, and so on is likely one that
13808 requires preprocessing.
13809
13810 If the file's suffix is @samp{.f} or @samp{.for}, the file
13811 will normally be compiled @emph{without} preprocessing by @code{g77}.
13812
13813 Change the file's suffix from @samp{.f} to @samp{.F} (or, on
13814 systems with case-insensitive file names, to @samp{.fpp}) or
13815 from @samp{.for} to @samp{.fpp}.
13816 @code{g77} compiles files with such names @emph{with}
13817 preprocessing.
13818
13819 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
13820 the language @samp{f77-cpp-input} for Fortran files that
13821 require preprocessing.
13822 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
13823
13824 @item
13825 The source file is preprocessed, and the results of preprocessing
13826 result in syntactic errors that are not necessarily obvious to
13827 someone examining the source file itself.
13828
13829 Examples of errors resulting from preprocessor macro expansion
13830 include exceeding the line-length limit, improperly starting,
13831 terminating, or incorporating the apostrophe or double-quote in
13832 a character constant, improperly forming a hollerith constant,
13833 and so on.
13834
13835 @xref{Overall Options,,Options Controlling the Kind of Output},
13836 for suggestions about how to use, and not use, preprocessing
13837 for Fortran code.
13838 @end itemize
13839
13840 @node GLOBALS
13841 @section @code{GLOBALS}
13842
13843 @noindent
13844 @smallexample
13845 Global name @var{name} defined at @dots{} already defined@dots{}
13846 Global name @var{name} at @dots{} has different type@dots{}
13847 Too many arguments passed to @var{name} at @dots{}
13848 Too few arguments passed to @var{name} at @dots{}
13849 Argument #@var{n} of @var{name} is @dots{}
13850 @end smallexample
13851
13852 These messages all identify disagreements about the
13853 global procedure named @var{name} among different program
13854 units (usually including @var{name} itself).
13855
13856 These disagreements, if not diagnosed, could result in a
13857 compiler crash if the compiler attempted to inline a reference
13858 to @var{name} within a calling program unit that disagreed
13859 with the @var{name} program unit regarding whether the
13860 procedure is a subroutine or function, the type of the
13861 return value of the procedure (if it is a function), the
13862 number of arguments the procedure accepts, or the type
13863 of each argument.
13864
13865 Such disagreements @emph{should} be fixed in the Fortran
13866 code itself.
13867 However, if that is not immediately practical, and the code
13868 has been working for some time, it is possible it will work
13869 when compiled by @code{g77} with the @samp{-fno-globals} option.
13870
13871 The @samp{-fno-globals} option disables these diagnostics, and
13872 also disables all inlining of references to global procedures
13873 to avoid compiler crashes.
13874 The diagnostics are actually produced, but as warnings, unless
13875 the @samp{-Wno-globals} option also is specified.
13876
13877 After using @samp{-fno-globals} to work around these problems,
13878 it is wise to stop using that option and address them by fixing
13879 the Fortran code, because such problems, while they might not
13880 actually result in bugs on some systems, indicate that the code
13881 is not as portable as it could be.
13882 In particular, the code might appear to work on a particular
13883 system, but have bugs that affect the reliability of the data
13884 without exhibiting any other outward manifestations of the bugs.
13885
13886 @end ifset
13887
13888 @node Index
13889 @unnumbered Index
13890
13891 @printindex cp
13892 @summarycontents
13893 @contents
13894 @bye