OSDN Git Service

doc changes from Dave Love left over
[pf3gnuchains/gcc-fork.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
17 @set last-up-date 1999-03-03
18 @set version-g77 0.5.24
19 @set email-general egcs@@egcs.cygnus.com
20 @set email-bugs egcs-bugs@@egcs.cygnus.com
21 @set email-burley craig@@jcb-sc.com
22 @set path-g77 egcs/gcc/f
23 @set path-libf2c egcs/libf2c
24
25 @c @setfilename useg77.info
26 @c @setfilename portg77.info
27 @c To produce the full manual, use the "g77.info" setfilename, and
28 @c make sure the following do NOT begin with '@c' (and the @clear lines DO)
29 @set INTERNALS
30 @set USING
31 @c To produce a user-only manual, use the "useg77.info" setfilename, and
32 @c make sure the following does NOT begin with '@c':
33 @c @clear INTERNALS
34 @c To produce a porter-only manual, use the "portg77.info" setfilename,
35 @c and make sure the following does NOT begin with '@c':
36 @c @clear USING
37
38 @c (For FSF printing, turn on smallbook; that is all that is needed.)
39
40 @c smallbook
41
42 @ifset INTERNALS
43 @ifset USING
44 @settitle Using and Porting GNU Fortran
45 @end ifset
46 @end ifset
47 @c seems reasonable to assume at least one of INTERNALS or USING is set...
48 @ifclear INTERNALS
49 @settitle Using GNU Fortran
50 @end ifclear
51 @ifclear USING
52 @settitle Porting GNU Fortran
53 @end ifclear
54 @c then again, have some fun
55 @ifclear INTERNALS
56 @ifclear USING
57 @settitle Doing Squat with GNU Fortran
58 @end ifclear
59 @end ifclear
60
61 @syncodeindex fn cp
62 @syncodeindex vr cp
63 @c %**end of header
64 @setchapternewpage odd
65
66 @ifinfo
67 This file explains how to use the GNU Fortran system.
68
69 Published by the Free Software Foundation
70 59 Temple Place - Suite 330
71 Boston, MA 02111-1307 USA
72
73 Copyright (C) 1995-1997 Free Software Foundation, Inc.
74
75 Permission is granted to make and distribute verbatim copies of
76 this manual provided the copyright notice and this permission notice
77 are preserved on all copies.
78
79 @ignore
80 Permission is granted to process this file through Tex and print the
81 results, provided the printed document carries copying permission
82 notice identical to this one except for the removal of this paragraph
83 (this paragraph not being relevant to the printed manual).
84
85 @end ignore
86 Permission is granted to copy and distribute modified versions of this
87 manual under the conditions for verbatim copying, provided also that the
88 sections entitled ``GNU General Public License,'' ``Funding for Free
89 Software,'' and ``Protect Your Freedom---Fight `Look And Feel'@w{}'' are
90 included exactly as in the original, and provided that the entire
91 resulting derived work is distributed under the terms of a permission
92 notice identical to this one.
93
94 Permission is granted to copy and distribute translations of this manual
95 into another language, under the above conditions for modified versions,
96 except that the sections entitled ``GNU General Public License,''
97 ``Funding for Free Software,'' and ``Protect Your Freedom---Fight `Look
98 And Feel'@w{}'', and this permission notice, may be included in
99 translations approved by the Free Software Foundation instead of in the
100 original English.
101 @end ifinfo
102
103 Contributed by James Craig Burley (@email{@value{email-burley}}).
104 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
105 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
106
107 @finalout
108 @titlepage
109 @comment The title is printed in a large font.
110 @center @titlefont{Using GNU Fortran}
111 @sp 2
112 @center James Craig Burley
113 @sp 3
114 @center Last updated @value{last-up-date}
115 @sp 1
116 @c The version number appears some more times in this file.
117
118 @center for version @value{version-g77}
119 @page
120 @vskip 0pt plus 1filll
121 Copyright @copyright{} 1995-1999 Free Software Foundation, Inc.
122 @sp 2
123 For GNU Fortran Version @value{version-g77}*
124 @sp 1
125 Published by the Free Software Foundation @*
126 59 Temple Place - Suite 330@*
127 Boston, MA 02111-1307, USA@*
128 @c Last printed ??ber, 19??.@*
129 @c Printed copies are available for $? each.@*
130 @c ISBN ???
131 @sp 1
132 Permission is granted to make and distribute verbatim copies of
133 this manual provided the copyright notice and this permission notice
134 are preserved on all copies.
135
136 Permission is granted to copy and distribute modified versions of this
137 manual under the conditions for verbatim copying, provided also that the
138 sections entitled ``GNU General Public License,'' ``Funding for Free
139 Software,'' and ``Protect Your Freedom---Fight `Look And Feel'@w{}'' are
140 included exactly as in the original, and provided that the entire
141 resulting derived work is distributed under the terms of a permission
142 notice identical to this one.
143
144 Permission is granted to copy and distribute translations of this manual
145 into another language, under the above conditions for modified versions,
146 except that the sections entitled ``GNU General Public License,''
147 ``Funding for Free Software,'' and ``Protect Your Freedom---Fight `Look
148 And Feel'@w{}'', and this permission notice, may be included in
149 translations approved by the Free Software Foundation instead of in the
150 original English.
151 @end titlepage
152 @page
153
154 @ifinfo
155
156 @dircategory Programming
157 @direntry
158 * g77: (g77).                  The GNU Fortran compiler.
159 @end direntry
160 @node Top, Copying,, (DIR)
161 @top Introduction
162 @cindex Introduction
163
164 @ifset INTERNALS
165 @ifset USING
166 This manual documents how to run, install and port the GNU Fortran
167 compiler, as well as its new features and incompatibilities, and how to
168 report bugs.  It corresponds to GNU Fortran version @value{version-g77}.
169 @end ifset
170 @end ifset
171
172 @ifclear INTERNALS
173 This manual documents how to run and install the GNU Fortran compiler,
174 as well as its new features and incompatibilities, and how to report
175 bugs.  It corresponds to GNU Fortran version @value{version-g77}.
176 @end ifclear
177 @ifclear USING
178 This manual documents how to port the GNU Fortran compiler,
179 as well as its new features and incompatibilities, and how to report
180 bugs.  It corresponds to GNU Fortran version @value{version-g77}.
181 @end ifclear
182
183 @end ifinfo
184 @menu
185 * Copying::         GNU General Public License says
186                     how you can copy and share GNU Fortran.
187 * Contributors::    People who have contributed to GNU Fortran.
188 * Funding::         How to help assure continued work for free software.
189 * Funding GNU Fortran::  How to help assure continued work on GNU Fortran.
190 * Look and Feel::   Protect your freedom---fight ``look and feel''.
191 @ifset USING
192 * Getting Started:: Finding your way around this manual.
193 * What is GNU Fortran?::  How @code{g77} fits into the universe.
194 * G77 and GCC::     You can compile Fortran, C, or other programs.
195 * Invoking G77::    Command options supported by @code{g77}.
196 * News::            News about recent releases of @code{g77}.
197 * Changes::         User-visible changes to recent releases of @code{g77}.
198 * Language::        The GNU Fortran language.
199 * Compiler::        The GNU Fortran compiler.
200 * Other Dialects::  Dialects of Fortran supported by @code{g77}.
201 * Other Compilers:: Fortran compilers other than @code{g77}.
202 * Other Languages:: Languages other than Fortran.
203 * Installation::    How to configure, compile and install GNU Fortran.
204 * Debugging and Interfacing::  How @code{g77} generates code.
205 * Collected Fortran Wisdom::  How to avoid Trouble.
206 * Trouble::         If you have trouble with GNU Fortran.
207 * Open Questions::  Things we'd like to know.
208 * Bugs::            How, why, and where to report bugs.
209 * Service::         How to find suppliers of support for GNU Fortran.
210 @end ifset
211 @ifset INTERNALS
212 * Adding Options::  Guidance on teaching @code{g77} about new options.
213 * Projects::        Projects for @code{g77} internals hackers.
214 @end ifset
215
216 * M: Diagnostics.   Diagnostics produced by @code{g77}.
217
218 * Index::           Index of concepts and symbol names.
219 @end menu
220 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
221
222 @node Copying
223 @unnumbered GNU GENERAL PUBLIC LICENSE
224 @center Version 2, June 1991
225
226 @display
227 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
228 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
229
230 Everyone is permitted to copy and distribute verbatim copies
231 of this license document, but changing it is not allowed.
232 @end display
233
234 @unnumberedsec Preamble
235
236   The licenses for most software are designed to take away your
237 freedom to share and change it.  By contrast, the GNU General Public
238 License is intended to guarantee your freedom to share and change free
239 software---to make sure the software is free for all its users.  This
240 General Public License applies to most of the Free Software
241 Foundation's software and to any other program whose authors commit to
242 using it.  (Some other Free Software Foundation software is covered by
243 the GNU Library General Public License instead.)  You can apply it to
244 your programs, too.
245
246   When we speak of free software, we are referring to freedom, not
247 price.  Our General Public Licenses are designed to make sure that you
248 have the freedom to distribute copies of free software (and charge for
249 this service if you wish), that you receive source code or can get it
250 if you want it, that you can change the software or use pieces of it
251 in new free programs; and that you know you can do these things.
252
253   To protect your rights, we need to make restrictions that forbid
254 anyone to deny you these rights or to ask you to surrender the rights.
255 These restrictions translate to certain responsibilities for you if you
256 distribute copies of the software, or if you modify it.
257
258   For example, if you distribute copies of such a program, whether
259 gratis or for a fee, you must give the recipients all the rights that
260 you have.  You must make sure that they, too, receive or can get the
261 source code.  And you must show them these terms so they know their
262 rights.
263
264   We protect your rights with two steps: (1) copyright the software, and
265 (2) offer you this license which gives you legal permission to copy,
266 distribute and/or modify the software.
267
268   Also, for each author's protection and ours, we want to make certain
269 that everyone understands that there is no warranty for this free
270 software.  If the software is modified by someone else and passed on, we
271 want its recipients to know that what they have is not the original, so
272 that any problems introduced by others will not reflect on the original
273 authors' reputations.
274
275   Finally, any free program is threatened constantly by software
276 patents.  We wish to avoid the danger that redistributors of a free
277 program will individually obtain patent licenses, in effect making the
278 program proprietary.  To prevent this, we have made it clear that any
279 patent must be licensed for everyone's free use or not licensed at all.
280
281   The precise terms and conditions for copying, distribution and
282 modification follow.
283
284 @iftex
285 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
286 @end iftex
287 @ifinfo
288 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
289 @end ifinfo
290
291 @enumerate 0
292 @item
293 This License applies to any program or other work which contains
294 a notice placed by the copyright holder saying it may be distributed
295 under the terms of this General Public License.  The ``Program'', below,
296 refers to any such program or work, and a ``work based on the Program''
297 means either the Program or any derivative work under copyright law:
298 that is to say, a work containing the Program or a portion of it,
299 either verbatim or with modifications and/or translated into another
300 language.  (Hereinafter, translation is included without limitation in
301 the term ``modification''.)  Each licensee is addressed as ``you''.
302
303 Activities other than copying, distribution and modification are not
304 covered by this License; they are outside its scope.  The act of
305 running the Program is not restricted, and the output from the Program
306 is covered only if its contents constitute a work based on the
307 Program (independent of having been made by running the Program).
308 Whether that is true depends on what the Program does.
309
310 @item
311 You may copy and distribute verbatim copies of the Program's
312 source code as you receive it, in any medium, provided that you
313 conspicuously and appropriately publish on each copy an appropriate
314 copyright notice and disclaimer of warranty; keep intact all the
315 notices that refer to this License and to the absence of any warranty;
316 and give any other recipients of the Program a copy of this License
317 along with the Program.
318
319 You may charge a fee for the physical act of transferring a copy, and
320 you may at your option offer warranty protection in exchange for a fee.
321
322 @item
323 You may modify your copy or copies of the Program or any portion
324 of it, thus forming a work based on the Program, and copy and
325 distribute such modifications or work under the terms of Section 1
326 above, provided that you also meet all of these conditions:
327
328 @enumerate a
329 @item
330 You must cause the modified files to carry prominent notices
331 stating that you changed the files and the date of any change.
332
333 @item
334 You must cause any work that you distribute or publish, that in
335 whole or in part contains or is derived from the Program or any
336 part thereof, to be licensed as a whole at no charge to all third
337 parties under the terms of this License.
338
339 @item
340 If the modified program normally reads commands interactively
341 when run, you must cause it, when started running for such
342 interactive use in the most ordinary way, to print or display an
343 announcement including an appropriate copyright notice and a
344 notice that there is no warranty (or else, saying that you provide
345 a warranty) and that users may redistribute the program under
346 these conditions, and telling the user how to view a copy of this
347 License.  (Exception: if the Program itself is interactive but
348 does not normally print such an announcement, your work based on
349 the Program is not required to print an announcement.)
350 @end enumerate
351
352 These requirements apply to the modified work as a whole.  If
353 identifiable sections of that work are not derived from the Program,
354 and can be reasonably considered independent and separate works in
355 themselves, then this License, and its terms, do not apply to those
356 sections when you distribute them as separate works.  But when you
357 distribute the same sections as part of a whole which is a work based
358 on the Program, the distribution of the whole must be on the terms of
359 this License, whose permissions for other licensees extend to the
360 entire whole, and thus to each and every part regardless of who wrote it.
361
362 Thus, it is not the intent of this section to claim rights or contest
363 your rights to work written entirely by you; rather, the intent is to
364 exercise the right to control the distribution of derivative or
365 collective works based on the Program.
366
367 In addition, mere aggregation of another work not based on the Program
368 with the Program (or with a work based on the Program) on a volume of
369 a storage or distribution medium does not bring the other work under
370 the scope of this License.
371
372 @item
373 You may copy and distribute the Program (or a work based on it,
374 under Section 2) in object code or executable form under the terms of
375 Sections 1 and 2 above provided that you also do one of the following:
376
377 @enumerate a
378 @item
379 Accompany it with the complete corresponding machine-readable
380 source code, which must be distributed under the terms of Sections
381 1 and 2 above on a medium customarily used for software interchange; or,
382
383 @item
384 Accompany it with a written offer, valid for at least three
385 years, to give any third party, for a charge no more than your
386 cost of physically performing source distribution, a complete
387 machine-readable copy of the corresponding source code, to be
388 distributed under the terms of Sections 1 and 2 above on a medium
389 customarily used for software interchange; or,
390
391 @item
392 Accompany it with the information you received as to the offer
393 to distribute corresponding source code.  (This alternative is
394 allowed only for noncommercial distribution and only if you
395 received the program in object code or executable form with such
396 an offer, in accord with Subsection b above.)
397 @end enumerate
398
399 The source code for a work means the preferred form of the work for
400 making modifications to it.  For an executable work, complete source
401 code means all the source code for all modules it contains, plus any
402 associated interface definition files, plus the scripts used to
403 control compilation and installation of the executable.  However, as a
404 special exception, the source code distributed need not include
405 anything that is normally distributed (in either source or binary
406 form) with the major components (compiler, kernel, and so on) of the
407 operating system on which the executable runs, unless that component
408 itself accompanies the executable.
409
410 If distribution of executable or object code is made by offering
411 access to copy from a designated place, then offering equivalent
412 access to copy the source code from the same place counts as
413 distribution of the source code, even though third parties are not
414 compelled to copy the source along with the object code.
415
416 @item
417 You may not copy, modify, sublicense, or distribute the Program
418 except as expressly provided under this License.  Any attempt
419 otherwise to copy, modify, sublicense or distribute the Program is
420 void, and will automatically terminate your rights under this License.
421 However, parties who have received copies, or rights, from you under
422 this License will not have their licenses terminated so long as such
423 parties remain in full compliance.
424
425 @item
426 You are not required to accept this License, since you have not
427 signed it.  However, nothing else grants you permission to modify or
428 distribute the Program or its derivative works.  These actions are
429 prohibited by law if you do not accept this License.  Therefore, by
430 modifying or distributing the Program (or any work based on the
431 Program), you indicate your acceptance of this License to do so, and
432 all its terms and conditions for copying, distributing or modifying
433 the Program or works based on it.
434
435 @item
436 Each time you redistribute the Program (or any work based on the
437 Program), the recipient automatically receives a license from the
438 original licensor to copy, distribute or modify the Program subject to
439 these terms and conditions.  You may not impose any further
440 restrictions on the recipients' exercise of the rights granted herein.
441 You are not responsible for enforcing compliance by third parties to
442 this License.
443
444 @item
445 If, as a consequence of a court judgment or allegation of patent
446 infringement or for any other reason (not limited to patent issues),
447 conditions are imposed on you (whether by court order, agreement or
448 otherwise) that contradict the conditions of this License, they do not
449 excuse you from the conditions of this License.  If you cannot
450 distribute so as to satisfy simultaneously your obligations under this
451 License and any other pertinent obligations, then as a consequence you
452 may not distribute the Program at all.  For example, if a patent
453 license would not permit royalty-free redistribution of the Program by
454 all those who receive copies directly or indirectly through you, then
455 the only way you could satisfy both it and this License would be to
456 refrain entirely from distribution of the Program.
457
458 If any portion of this section is held invalid or unenforceable under
459 any particular circumstance, the balance of the section is intended to
460 apply and the section as a whole is intended to apply in other
461 circumstances.
462
463 It is not the purpose of this section to induce you to infringe any
464 patents or other property right claims or to contest validity of any
465 such claims; this section has the sole purpose of protecting the
466 integrity of the free software distribution system, which is
467 implemented by public license practices.  Many people have made
468 generous contributions to the wide range of software distributed
469 through that system in reliance on consistent application of that
470 system; it is up to the author/donor to decide if he or she is willing
471 to distribute software through any other system and a licensee cannot
472 impose that choice.
473
474 This section is intended to make thoroughly clear what is believed to
475 be a consequence of the rest of this License.
476
477 @item
478 If the distribution and/or use of the Program is restricted in
479 certain countries either by patents or by copyrighted interfaces, the
480 original copyright holder who places the Program under this License
481 may add an explicit geographical distribution limitation excluding
482 those countries, so that distribution is permitted only in or among
483 countries not thus excluded.  In such case, this License incorporates
484 the limitation as if written in the body of this License.
485
486 @item
487 The Free Software Foundation may publish revised and/or new versions
488 of the General Public License from time to time.  Such new versions will
489 be similar in spirit to the present version, but may differ in detail to
490 address new problems or concerns.
491
492 Each version is given a distinguishing version number.  If the Program
493 specifies a version number of this License which applies to it and ``any
494 later version'', you have the option of following the terms and conditions
495 either of that version or of any later version published by the Free
496 Software Foundation.  If the Program does not specify a version number of
497 this License, you may choose any version ever published by the Free Software
498 Foundation.
499
500 @item
501 If you wish to incorporate parts of the Program into other free
502 programs whose distribution conditions are different, write to the author
503 to ask for permission.  For software which is copyrighted by the Free
504 Software Foundation, write to the Free Software Foundation; we sometimes
505 make exceptions for this.  Our decision will be guided by the two goals
506 of preserving the free status of all derivatives of our free software and
507 of promoting the sharing and reuse of software generally.
508
509 @iftex
510 @heading NO WARRANTY
511 @end iftex
512 @ifinfo
513 @center NO WARRANTY
514 @end ifinfo
515
516 @item
517 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
518 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
519 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
520 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
521 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
522 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
523 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
524 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
525 REPAIR OR CORRECTION.
526
527 @item
528 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
529 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
530 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
531 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
532 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
533 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
534 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
535 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
536 POSSIBILITY OF SUCH DAMAGES.
537 @end enumerate
538
539 @iftex
540 @heading END OF TERMS AND CONDITIONS
541 @end iftex
542 @ifinfo
543 @center END OF TERMS AND CONDITIONS
544 @end ifinfo
545
546 @page
547 @unnumberedsec How to Apply These Terms to Your New Programs
548
549   If you develop a new program, and you want it to be of the greatest
550 possible use to the public, the best way to achieve this is to make it
551 free software which everyone can redistribute and change under these terms.
552
553   To do so, attach the following notices to the program.  It is safest
554 to attach them to the start of each source file to most effectively
555 convey the exclusion of warranty; and each file should have at least
556 the ``copyright'' line and a pointer to where the full notice is found.
557
558 @smallexample
559 @var{one line to give the program's name and a brief idea of what it does.}
560 Copyright (C) 19@var{yy}  @var{name of author}
561
562 This program is free software; you can redistribute it and/or modify
563 it under the terms of the GNU General Public License as published by
564 the Free Software Foundation; either version 2 of the License, or
565 (at your option) any later version.
566
567 This program is distributed in the hope that it will be useful,
568 but WITHOUT ANY WARRANTY; without even the implied warranty of
569 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
570 GNU General Public License for more details.
571
572 You should have received a copy of the GNU General Public License
573 along with this program; if not, write to the Free Software
574 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
575 @end smallexample
576
577 Also add information on how to contact you by electronic and paper mail.
578
579 If the program is interactive, make it output a short notice like this
580 when it starts in an interactive mode:
581
582 @smallexample
583 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
584 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
585 type `show w'.
586 This is free software, and you are welcome to redistribute it
587 under certain conditions; type `show c' for details.
588 @end smallexample
589
590 The hypothetical commands @samp{show w} and @samp{show c} should show
591 the appropriate parts of the General Public License.  Of course, the
592 commands you use may be called something other than @samp{show w} and
593 @samp{show c}; they could even be mouse-clicks or menu items---whatever
594 suits your program.
595
596 You should also get your employer (if you work as a programmer) or your
597 school, if any, to sign a ``copyright disclaimer'' for the program, if
598 necessary.  Here is a sample; alter the names:
599
600 @smallexample
601 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
602 `Gnomovision' (which makes passes at compilers) written by James Hacker.
603
604 @var{signature of Ty Coon}, 1 April 1989
605 Ty Coon, President of Vice
606 @end smallexample
607
608 This General Public License does not permit incorporating your program into
609 proprietary programs.  If your program is a subroutine library, you may
610 consider it more useful to permit linking proprietary applications with the
611 library.  If this is what you want to do, use the GNU Library General
612 Public License instead of this License.
613
614 @node Contributors
615 @unnumbered Contributors to GNU Fortran
616 @cindex contributors
617 @cindex credits
618
619 In addition to James Craig Burley, who wrote the front end,
620 many people have helped create and improve GNU Fortran.
621
622 @itemize @bullet
623 @item
624 The packaging and compiler portions of GNU Fortran are based largely
625 on the GNU CC compiler.
626 @xref{Contributors,,Contributors to GNU CC,gcc,Using and Porting GNU CC},
627 for more information.
628
629 @item
630 The run-time library used by GNU Fortran is a repackaged version
631 of the @code{libf2c} library (combined from the @code{libF77} and
632 @code{libI77} libraries) provided as part of @code{f2c}, available for
633 free from @code{netlib} sites on the Internet.
634
635 @item
636 Cygnus Support and The Free Software Foundation contributed
637 significant money and/or equipment to Craig's efforts.
638
639 @item
640 The following individuals served as alpha testers prior to @code{g77}'s
641 public release.  This work consisted of testing, researching, sometimes
642 debugging, and occasionally providing small amounts of code and fixes
643 for @code{g77}, plus offering plenty of helpful advice to Craig:
644
645 @itemize @w{}
646 @item
647 Jonathan Corbet
648 @item
649 Dr.@: Mark Fernyhough
650 @item
651 Takafumi Hayashi (The University of Aizu)---@email{takafumi@@u-aizu.ac.jp}
652 @item
653 Kate Hedstrom
654 @item
655 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
656 @item
657 Dr.@: A. O. V. Le Blanc
658 @item
659 Dave Love
660 @item
661 Rick Lutowski
662 @item
663 Toon Moene
664 @item
665 Rick Niles
666 @item
667 Derk Reefman
668 @item
669 Wayne K. Schroll
670 @item
671 Bill Thorson
672 @item
673 Pedro A. M. Vazquez
674 @item
675 Ian Watson
676 @end itemize
677
678 @item
679 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
680 provided the patch to add rudimentary support
681 for @code{INTEGER*1}, @code{INTEGER*2}, and
682 @code{LOGICAL*1}.
683 This inspired Craig to add further support,
684 even though the resulting support
685 would still be incomplete, because version 0.6 is still
686 a ways off.
687
688 @item
689 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
690 and encouraged Craig to rewrite the documentation in texinfo
691 format by contributing a first pass at a translation of the
692 old @file{g77-0.5.16/f/DOC} file.
693
694 @item
695 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
696 some analysis of generated code as part of an overall project
697 to improve @code{g77} code generation to at least be as good
698 as @code{f2c} used in conjunction with @code{gcc}.
699 So far, this has resulted in the three, somewhat
700 experimental, options added by @code{g77} to the @code{gcc}
701 compiler and its back end.
702
703 (These, in turn, have made their way into the @code{egcs}
704 version of the compiler, and do not exist in @code{gcc}
705 version 2.8 or versions of @code{g77} based on that version
706 of @code{gcc}.)
707
708 @item
709 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
710
711 @item
712 Thanks to Mary Cortani and the staff at Craftwork Solutions
713 (@email{support@@craftwork.com}) for all of their support.
714
715 @item
716 Many other individuals have helped debug, test, and improve @code{g77}
717 over the past several years, and undoubtedly more people
718 will be doing so in the future.
719 If you have done so, and would like
720 to see your name listed in the above list, please ask!
721 The default is that people wish to remain anonymous.
722 @end itemize
723
724 @node Funding
725 @chapter Funding Free Software
726
727 If you want to have more free software a few years from now, it makes
728 sense for you to help encourage people to contribute funds for its
729 development.  The most effective approach known is to encourage
730 commercial redistributors to donate.
731
732 Users of free software systems can boost the pace of development by
733 encouraging for-a-fee distributors to donate part of their selling price
734 to free software developers---the Free Software Foundation, and others.
735
736 The way to convince distributors to do this is to demand it and expect
737 it from them.  So when you compare distributors, judge them partly by
738 how much they give to free software development.  Show distributors
739 they must compete to be the one who gives the most.
740
741 To make this approach work, you must insist on numbers that you can
742 compare, such as, ``We will donate ten dollars to the Frobnitz project
743 for each disk sold.''  Don't be satisfied with a vague promise, such as
744 ``A portion of the profits are donated,'' since it doesn't give a basis
745 for comparison.
746
747 Even a precise fraction ``of the profits from this disk'' is not very
748 meaningful, since creative accounting and unrelated business decisions
749 can greatly alter what fraction of the sales price counts as profit.
750 If the price you pay is $50, ten percent of the profit is probably
751 less than a dollar; it might be a few cents, or nothing at all.
752
753 Some redistributors do development work themselves.  This is useful too;
754 but to keep everyone honest, you need to inquire how much they do, and
755 what kind.  Some kinds of development make much more long-term
756 difference than others.  For example, maintaining a separate version of
757 a program contributes very little; maintaining the standard version of a
758 program for the whole community contributes much.  Easy new ports
759 contribute little, since someone else would surely do them; difficult
760 ports such as adding a new CPU to the GNU C compiler contribute more;
761 major new features or packages contribute the most.
762
763 By establishing the idea that supporting further development is ``the
764 proper thing to do'' when distributing free software for a fee, we can
765 assure a steady flow of resources into making more free software.
766
767 @display
768 Copyright (C) 1994 Free Software Foundation, Inc.
769 Verbatim copying and redistribution of this section is permitted
770 without royalty; alteration is not permitted.
771 @end display
772
773 @node Funding GNU Fortran
774 @chapter Funding GNU Fortran
775 @cindex funding improvements
776 @cindex improvements, funding
777
778 Work on GNU Fortran is still being done mostly by its author,
779 James Craig Burley (@email{@value{email-burley}}), who is a volunteer
780 for, not an employee of, the Free Software Foundation (FSF).
781 As with other GNU software, funding is important because it can pay for
782 needed equipment, personnel, and so on.
783
784 @cindex FSF, funding the
785 @cindex funding the FSF
786 The FSF provides information on the best way to fund ongoing
787 development of GNU software (such as GNU Fortran) in documents
788 such as the ``GNUS Bulletin''.
789 Email @email{gnu@@gnu.org} for information on funding the FSF.
790
791 To fund specific GNU Fortran work in particular, the FSF might
792 provide a means for that, but the FSF does not provide direct funding
793 to the author of GNU Fortran to continue his work.  The FSF has
794 employee salary restrictions that can be incompatible with the
795 financial needs of some volunteers, who therefore choose to
796 remain volunteers and thus be able to be free to do contract work
797 and otherwise make their own schedules for doing GNU work.
798
799 Still, funding the FSF at least indirectly benefits work
800 on specific projects like GNU Fortran because it ensures the
801 continuing operation of the FSF offices, their workstations, their
802 network connections, and so on, which are invaluable to volunteers.
803 (Similarly, hiring Cygnus Support can help a project like GNU
804 Fortran---Cygnus has been a long-time donor of equipment usage to the author
805 of GNU Fortran, and this too has been invaluable---@xref{Contributors}.)
806
807 Currently, the only way to directly fund the author of GNU Fortran
808 in his work on that project is to hire him for the work you want
809 him to do, or donate money to him.
810 Several people have done this
811 already, with the result that he has not needed to immediately find
812 contract work on a few occasions.
813 If more people did this, he
814 would be able to plan on not doing contract work for many months and
815 could thus devote that time to work on projects (such as the planned
816 changes for 0.6) that require longer timeframes to complete.
817 For the latest information on the status of the author, do
818 @kbd{finger -l burley@@gnu.org} on a UNIX system
819 (or any system with a command like UNIX @code{finger}).
820
821 Another important way to support work on GNU Fortran is to volunteer
822 to help out.
823 Work is needed on documentation, testing, porting
824 to various machines, and in some cases, coding (although major
825 changes planned for version 0.6 make it difficult to add manpower to this
826 area).
827 Email @email{@value{email-general}} to volunteer for this work.
828
829 @xref{Funding,,Funding Free Software}, for more information.
830
831 @node Look and Feel
832 @chapter Protect Your Freedom---Fight ``Look And Feel''
833 @c the above chapter heading overflows onto the next line. --mew 1/26/93
834
835 To preserve the ability to write free software, including replacements
836 for proprietary software, authors must be free to replicate the
837 user interface to which users of existing software have become
838 accustomed.
839
840 @xref{Look and Feel,,Protect Your Freedom---Fight ``Look And Feel'',
841 gcc,Using and Porting GNU CC}, for more information.
842
843 @node Getting Started
844 @chapter Getting Started
845 @cindex getting started
846 @cindex new users
847 @cindex newbies
848 @cindex beginners
849
850 If you don't need help getting started reading the portions
851 of this manual that are most important to you, you should skip
852 this portion of the manual.
853
854 If you are new to compilers, especially Fortran compilers, or
855 new to how compilers are structured under UNIX and UNIX-like
856 systems, you'll want to see @ref{What is GNU Fortran?}.
857
858 If you are new to GNU compilers, or have used only one GNU
859 compiler in the past and not had to delve into how it lets
860 you manage various versions and configurations of @code{gcc},
861 you should see @ref{G77 and GCC}.
862
863 Everyone except experienced @code{g77} users should
864 see @ref{Invoking G77}.
865
866 If you're acquainted with previous versions of @code{g77},
867 you should see @ref{News,,News About GNU Fortran}.
868 Further, if you've actually used previous versions of @code{g77},
869 especially if you've written or modified Fortran code to
870 be compiled by previous versions of @code{g77}, you
871 should see @ref{Changes}.
872
873 If you intend to write or otherwise compile code that is
874 not already strictly conforming ANSI FORTRAN 77---and this
875 is probably everyone---you should see @ref{Language}.
876
877 If you don't already have @code{g77} installed on your
878 system, you must see @ref{Installation}.
879
880 If you run into trouble getting Fortran code to compile,
881 link, run, or work properly, you might find answers
882 if you see @ref{Debugging and Interfacing},
883 see @ref{Collected Fortran Wisdom},
884 and see @ref{Trouble}.
885 You might also find that the problems you are encountering
886 are bugs in @code{g77}---see @ref{Bugs}, for information on
887 reporting them, after reading the other material.
888
889 If you need further help with @code{g77}, or with
890 freely redistributable software in general,
891 see @ref{Service}.
892
893 If you would like to help the @code{g77} project,
894 see @ref{Funding GNU Fortran}, for information on
895 helping financially, and see @ref{Projects}, for information
896 on helping in other ways.
897
898 If you're generally curious about the future of
899 @code{g77}, see @ref{Projects}.
900 If you're curious about its past,
901 see @ref{Contributors},
902 and see @ref{Funding GNU Fortran}.
903
904 To see a few of the questions maintainers of @code{g77} have,
905 and that you might be able to answer,
906 see @ref{Open Questions}.
907
908 @ifset USING
909 @node What is GNU Fortran?
910 @chapter What is GNU Fortran?
911 @cindex concepts, basic
912 @cindex basic concepts
913
914 GNU Fortran, or @code{g77}, is designed initially as a free replacement
915 for, or alternative to, the UNIX @code{f77} command.
916 (Similarly, @code{gcc} is designed as a replacement
917 for the UNIX @code{cc} command.)
918
919 @code{g77} also is designed to fit in well with the other
920 fine GNU compilers and tools.
921
922 Sometimes these design goals conflict---in such cases, resolution
923 often is made in favor of fitting in well with Project GNU.
924 These cases are usually identified in the appropriate
925 sections of this manual.
926
927 @cindex compilers
928 As compilers, @code{g77}, @code{gcc}, and @code{f77}
929 share the following characteristics:
930
931 @itemize @bullet
932 @cindex source code
933 @cindex file, source
934 @cindex code, source
935 @cindex source file
936 @item
937 They read a user's program, stored in a file and
938 containing instructions written in the appropriate
939 language (Fortran, C, and so on).
940 This file contains @dfn{source code}.
941
942 @cindex translation of user programs
943 @cindex machine code
944 @cindex code, machine
945 @cindex mistakes
946 @item
947 They translate the user's program into instructions
948 a computer can carry out more quickly than it takes
949 to translate the instructions in the first place.
950 These instructions are called @dfn{machine code}---code
951 designed to be efficiently translated and processed
952 by a machine such as a computer.
953 Humans usually aren't as good writing machine code
954 as they are at writing Fortran or C, because
955 it is easy to make tiny mistakes writing machine code.
956 When writing Fortran or C, it is easy
957 to make big mistakes.
958
959 @cindex debugger
960 @cindex bugs, finding
961 @cindex @code{gdb}, command
962 @cindex commands, @code{gdb}
963 @item
964 They provide information in the generated machine code
965 that can make it easier to find bugs in the program
966 (using a debugging tool, called a @dfn{debugger},
967 such as @code{gdb}).
968
969 @cindex libraries
970 @cindex linking
971 @cindex @code{ld} command
972 @cindex commands, @code{ld}
973 @item
974 They locate and gather machine code already generated
975 to perform actions requested by statements in
976 the user's program.
977 This machine code is organized
978 into @dfn{libraries} and is located and gathered
979 during the @dfn{link} phase of the compilation
980 process.
981 (Linking often is thought of as a separate
982 step, because it can be directly invoked via the
983 @code{ld} command.
984 However, the @code{g77} and @code{gcc}
985 commands, as with most compiler commands, automatically
986 perform the linking step by calling on @code{ld}
987 directly, unless asked to not do so by the user.)
988
989 @cindex language, incorrect use of
990 @cindex incorrect use of language
991 @item
992 They attempt to diagnose cases where the user's
993 program contains incorrect usages of the language.
994 The @dfn{diagnostics} produced by the compiler
995 indicate the problem and the location in the user's
996 source file where the problem was first noticed.
997 The user can use this information to locate and
998 fix the problem.
999 @cindex diagnostics, incorrect
1000 @cindex incorrect diagnostics
1001 @cindex error messages, incorrect
1002 @cindex incorrect error messages
1003 (Sometimes an incorrect usage
1004 of the language leads to a situation where the
1005 compiler can no longer make any sense of what
1006 follows---while a human might be able to---and
1007 thus ends up complaining about many ``problems''
1008 it encounters that, in fact, stem from just one
1009 problem, usually the first one reported.)
1010
1011 @cindex warnings
1012 @cindex questionable instructions
1013 @item
1014 They attempt to diagnose cases where the user's
1015 program contains a correct usage of the language,
1016 but instructs the computer to do something questionable.
1017 These diagnostics often are in the form of @dfn{warnings},
1018 instead of the @dfn{errors} that indicate incorrect
1019 usage of the language.
1020 @end itemize
1021
1022 How these actions are performed is generally under the
1023 control of the user.
1024 Using command-line options, the user can specify
1025 how persnickety the compiler is to be regarding
1026 the program (whether to diagnose questionable usage
1027 of the language), how much time to spend making
1028 the generated machine code run faster, and so on.
1029
1030 @cindex components of g77
1031 @cindex @code{g77}, components of
1032 @code{g77} consists of several components:
1033
1034 @cindex @code{gcc}, command
1035 @cindex commands, @code{gcc}
1036 @itemize @bullet
1037 @item
1038 A modified version of the @code{gcc} command, which also might be
1039 installed as the system's @code{cc} command.
1040 (In many cases, @code{cc} refers to the
1041 system's ``native'' C compiler, which
1042 might be a non-GNU compiler, or an older version
1043 of @code{gcc} considered more stable or that is
1044 used to build the operating system kernel.)
1045
1046 @cindex @code{g77}, command
1047 @cindex commands, @code{g77}
1048 @item
1049 The @code{g77} command itself, which also might be installed as the
1050 system's @code{f77} command.
1051
1052 @cindex libg2c library
1053 @cindex libf2c library
1054 @cindex libraries, libf2c
1055 @cindex libraries, libg2c
1056 @cindex run-time, library
1057 @item
1058 The @code{libg2c} run-time library.
1059 This library contains the machine code needed to support
1060 capabilities of the Fortran language that are not directly
1061 provided by the machine code generated by the @code{g77}
1062 compilation phase.
1063
1064 @code{libg2c} is just the unique name @code{g77} gives
1065 to its version of @code{libf2c} to distinguish it from
1066 any copy of @code{libf2c} installed from @code{f2c}
1067 (or versions of @code{g77} that built @code{libf2c} under
1068 that same name)
1069 on the system.
1070
1071 The maintainer of @code{libf2c} currently is
1072 @email{dmg@@bell-labs.com}.
1073
1074 @cindex @code{f771}, program
1075 @cindex programs, @code{f771}
1076 @cindex assembler
1077 @cindex @code{as} command
1078 @cindex commands, @code{as}
1079 @cindex assembly code
1080 @cindex code, assembly
1081 @item
1082 The compiler itself, internally named @code{f771}.
1083
1084 Note that @code{f771} does not generate machine code directly---it
1085 generates @dfn{assembly code} that is a more readable form
1086 of machine code, leaving the conversion to actual machine code
1087 to an @dfn{assembler}, usually named @code{as}.
1088 @end itemize
1089
1090 @code{gcc} is often thought of as ``the C compiler'' only,
1091 but it does more than that.
1092 Based on command-line options and the names given for files
1093 on the command line, @code{gcc} determines which actions to perform, including
1094 preprocessing, compiling (in a variety of possible languages), assembling,
1095 and linking.
1096
1097 @cindex driver, gcc command as
1098 @cindex @code{gcc}, command as driver
1099 @cindex executable file
1100 @cindex files, executable
1101 @cindex cc1 program
1102 @cindex programs, cc1
1103 @cindex preprocessor
1104 @cindex cpp program
1105 @cindex programs, cpp
1106 For example, the command @samp{gcc foo.c} @dfn{drives} the file
1107 @file{foo.c} through the preprocessor @code{cpp}, then
1108 the C compiler (internally named
1109 @code{cc1}), then the assembler (usually @code{as}), then the linker
1110 (@code{ld}), producing an executable program named @file{a.out} (on
1111 UNIX systems).
1112
1113 @cindex cc1plus program
1114 @cindex programs, cc1plus
1115 As another example, the command @samp{gcc foo.cc} would do much the same as
1116 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
1117 @code{gcc} would use the C++ compiler (named @code{cc1plus}).
1118
1119 @cindex @code{f771}, program
1120 @cindex programs, @code{f771}
1121 In a GNU Fortran installation, @code{gcc} recognizes Fortran source
1122 files by name just like it does C and C++ source files.
1123 It knows to use the Fortran compiler named @code{f771}, instead of
1124 @code{cc1} or @code{cc1plus}, to compile Fortran files.
1125
1126 @cindex @code{gcc}, not recognizing Fortran source
1127 @cindex unrecognized file format
1128 @cindex file format not recognized
1129 Non-Fortran-related operation of @code{gcc} is generally
1130 unaffected by installing the GNU Fortran version of @code{gcc}.
1131 However, without the installed version of @code{gcc} being the
1132 GNU Fortran version, @code{gcc} will not be able to compile
1133 and link Fortran programs---and since @code{g77} uses @code{gcc}
1134 to do most of the actual work, neither will @code{g77}!
1135
1136 @cindex @code{g77}, command
1137 @cindex commands, @code{g77}
1138 The @code{g77} command is essentially just a front-end for
1139 the @code{gcc} command.
1140 Fortran users will normally use @code{g77} instead of @code{gcc},
1141 because @code{g77}
1142 knows how to specify the libraries needed to link with Fortran programs
1143 (@code{libg2c} and @code{lm}).
1144 @code{g77} can still compile and link programs and
1145 source files written in other languages, just like @code{gcc}.
1146
1147 @cindex printing version information
1148 @cindex version information, printing
1149 The command @samp{g77 -v} is a quick
1150 way to display lots of version information for the various programs
1151 used to compile a typical preprocessed Fortran source file---this
1152 produces much more output than @samp{gcc -v} currently does.
1153 (If it produces an error message near the end of the output---diagnostics
1154 from the linker, usually @code{ld}---you might
1155 have an out-of-date @code{libf2c} that improperly handles
1156 complex arithmetic.)
1157 In the output of this command, the line beginning @samp{GNU Fortran Front
1158 End} identifies the version number of GNU Fortran; immediately
1159 preceding that line is a line identifying the version of @code{gcc}
1160 with which that version of @code{g77} was built.
1161
1162 @cindex libf2c library
1163 @cindex libraries, libf2c
1164 The @code{libf2c} library is distributed with GNU Fortran for
1165 the convenience of its users, but is not part of GNU Fortran.
1166 It contains the procedures
1167 needed by Fortran programs while they are running.
1168
1169 @cindex in-line code
1170 @cindex code, in-line
1171 For example, while code generated by @code{g77} is likely
1172 to do additions, subtractions, and multiplications @dfn{in line}---in
1173 the actual compiled code---it is not likely to do trigonometric
1174 functions this way.
1175
1176 Instead, operations like trigonometric
1177 functions are compiled by the @code{f771} compiler
1178 (invoked by @code{g77} when compiling Fortran code) into machine
1179 code that, when run, calls on functions in @code{libg2c}, so
1180 @code{libg2c} must be linked with almost every useful program
1181 having any component compiled by GNU Fortran.
1182 (As mentioned above, the @code{g77} command takes
1183 care of all this for you.)
1184
1185 The @code{f771} program represents most of what is unique to GNU Fortran.
1186 While much of the @code{libg2c} component comes from
1187 the @code{libf2c} component of @code{f2c},
1188 a free Fortran-to-C converter distributed by Bellcore (AT&T),
1189 plus @code{libU77}, provided by Dave Love,
1190 and the @code{g77} command is just a small front-end to @code{gcc},
1191 @code{f771} is a combination of two rather
1192 large chunks of code.
1193
1194 @cindex GNU Back End (GBE)
1195 @cindex GBE
1196 @cindex @code{gcc}, back end
1197 @cindex back end, gcc
1198 @cindex code generator
1199 One chunk is the so-called @dfn{GNU Back End}, or GBE,
1200 which knows how to generate fast code for a wide variety of processors.
1201 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
1202 @code{cc1plus}, and @code{f771}, plus others.
1203 Often the GBE is referred to as the ``gcc back end'' or
1204 even just ``gcc''---in this manual, the term GBE is used
1205 whenever the distinction is important.
1206
1207 @cindex GNU Fortran Front End (FFE)
1208 @cindex FFE
1209 @cindex @code{g77}, front end
1210 @cindex front end, g77
1211 The other chunk of @code{f771} is the
1212 majority of what is unique about GNU Fortran---the code that knows how
1213 to interpret Fortran programs to determine what they are intending to
1214 do, and then communicate that knowledge to the GBE for actual compilation
1215 of those programs.
1216 This chunk is called the @dfn{Fortran Front End} (FFE).
1217 The @code{cc1} and @code{cc1plus} programs have their own front ends,
1218 for the C and C++ languages, respectively.
1219 These fronts ends are responsible for diagnosing
1220 incorrect usage of their respective languages by the
1221 programs the process, and are responsible for most of
1222 the warnings about questionable constructs as well.
1223 (The GBE handles producing some warnings, like those
1224 concerning possible references to undefined variables.)
1225
1226 Because so much is shared among the compilers for various languages,
1227 much of the behavior and many of the user-selectable options for these
1228 compilers are similar.
1229 For example, diagnostics (error messages and
1230 warnings) are similar in appearance; command-line
1231 options like @samp{-Wall} have generally similar effects; and the quality
1232 of generated code (in terms of speed and size) is roughly similar
1233 (since that work is done by the shared GBE).
1234
1235 @node G77 and GCC
1236 @chapter Compile Fortran, C, or Other Programs
1237 @cindex compiling programs
1238 @cindex programs, compiling
1239
1240 @cindex @code{gcc}, command
1241 @cindex commands, @code{gcc}
1242 A GNU Fortran installation includes a modified version of the @code{gcc}
1243 command.
1244
1245 In a non-Fortran installation, @code{gcc} recognizes C, C++,
1246 and Objective-C source files.
1247
1248 In a GNU Fortran installation, @code{gcc} also recognizes Fortran source
1249 files and accepts Fortran-specific command-line options, plus some
1250 command-line options that are designed to cater to Fortran users
1251 but apply to other languages as well.
1252
1253 @xref{G++ and GCC,,Compile C; C++; or Objective-C,gcc,Using and Porting GNU CC},
1254 for information on the way different languages are handled
1255 by the GNU CC compiler (@code{gcc}).
1256
1257 @cindex @code{g77}, command
1258 @cindex commands, @code{g77}
1259 Also provided as part of GNU Fortran is the @code{g77} command.
1260 The @code{g77} command is designed to make compiling and linking Fortran
1261 programs somewhat easier than when using the @code{gcc} command for
1262 these tasks.
1263 It does this by analyzing the command line somewhat and changing it
1264 appropriately before submitting it to the @code{gcc} command.
1265
1266 @cindex -v option
1267 @cindex @code{g77} options, -v
1268 @cindex options, -v
1269 Use the @samp{-v} option with @code{g77}
1270 to see what is going on---the first line of output is the invocation
1271 of the @code{gcc} command.
1272
1273 @node Invoking G77
1274 @chapter GNU Fortran Command Options
1275 @cindex GNU Fortran command options
1276 @cindex command options
1277 @cindex options, GNU Fortran command
1278
1279 The @code{g77} command supports all the options supported by the
1280 @code{gcc} command.
1281 @xref{Invoking GCC,,GNU CC Command Options,gcc,Using and Porting GNU CC},
1282 for information
1283 on the non-Fortran-specific aspects of the @code{gcc} command (and,
1284 therefore, the @code{g77} command).
1285
1286 @cindex options, negative forms
1287 @cindex negative forms of options
1288 All @code{gcc} and @code{g77} options
1289 are accepted both by @code{g77} and by @code{gcc}
1290 (as well as any other drivers built at the same time,
1291 such as @code{g++}),
1292 since adding @code{g77} to the @code{gcc} distribution
1293 enables acceptance of @code{g77}-specific options
1294 by all of the relevant drivers.
1295
1296 In some cases, options have positive and negative forms;
1297 the negative form of @samp{-ffoo} would be @samp{-fno-foo}.
1298 This manual documents only one of these two forms, whichever
1299 one is not the default.
1300
1301 @menu
1302 * Option Summary::      Brief list of all @code{g77} options,
1303                         without explanations.
1304 * Overall Options::     Controlling the kind of output:
1305                         an executable, object files, assembler files,
1306                         or preprocessed source.
1307 * Shorthand Options::   Options that are shorthand for other options.
1308 * Fortran Dialect Options::  Controlling the variant of Fortran language
1309                              compiled.
1310 * Warning Options::     How picky should the compiler be?
1311 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1312 * Optimize Options::    How much optimization?
1313 * Preprocessor Options:: Controlling header files and macro definitions.
1314                          Also, getting dependency information for Make.
1315 * Directory Options::   Where to find header files and libraries.
1316                         Where to find the compiler executable files.
1317 * Code Gen Options::    Specifying conventions for function calls, data layout
1318                         and register usage.
1319 * Environment Variables:: Env vars that affect GNU Fortran.
1320 @end menu
1321
1322 @node Option Summary
1323 @section Option Summary
1324
1325 Here is a summary of all the options specific to GNU Fortran, grouped
1326 by type.  Explanations are in the following sections.
1327
1328 @table @emph
1329 @item Overall Options
1330 @xref{Overall Options,,Options Controlling the Kind of Output}.
1331 @smallexample
1332 -fversion  -fset-g77-defaults  -fno-silent
1333 @end smallexample
1334
1335 @item Shorthand Options
1336 @xref{Shorthand Options}.
1337 @smallexample
1338 -ff66  -fno-f66  -ff77  -fno-f77  -fugly  -fno-ugly
1339 @end smallexample
1340
1341 @item Fortran Language Options
1342 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
1343 @smallexample
1344 -ffree-form  -fno-fixed-form  -ff90
1345 -fvxt  -fdollar-ok  -fno-backslash
1346 -fno-ugly-args  -fno-ugly-assign  -fno-ugly-assumed
1347 -fugly-comma  -fugly-complex  -fugly-init  -fugly-logint
1348 -fonetrip  -ftypeless-boz
1349 -fintrin-case-initcap  -fintrin-case-upper
1350 -fintrin-case-lower  -fintrin-case-any
1351 -fmatch-case-initcap  -fmatch-case-upper
1352 -fmatch-case-lower  -fmatch-case-any
1353 -fsource-case-upper -fsource-case-lower  -fsource-case-preserve
1354 -fsymbol-case-initcap  -fsymbol-case-upper
1355 -fsymbol-case-lower  -fsymbol-case-any
1356 -fcase-strict-upper  -fcase-strict-lower
1357 -fcase-initcap  -fcase-upper  -fcase-lower  -fcase-preserve
1358 -ff2c-intrinsics-delete  -ff2c-intrinsics-hide
1359 -ff2c-intrinsics-disable  -ff2c-intrinsics-enable
1360 -fbadu77-intrinsics-delete  -fbadu77-intrinsics-hide
1361 -fbadu77-intrinsics-disable  -fbadu77-intrinsics-enable
1362 -ff90-intrinsics-delete  -ff90-intrinsics-hide
1363 -ff90-intrinsics-disable  -ff90-intrinsics-enable
1364 -fgnu-intrinsics-delete  -fgnu-intrinsics-hide
1365 -fgnu-intrinsics-disable  -fgnu-intrinsics-enable
1366 -fmil-intrinsics-delete  -fmil-intrinsics-hide
1367 -fmil-intrinsics-disable  -fmil-intrinsics-enable
1368 -funix-intrinsics-delete  -funix-intrinsics-hide
1369 -funix-intrinsics-disable  -funix-intrinsics-enable
1370 -fvxt-intrinsics-delete  -fvxt-intrinsics-hide
1371 -fvxt-intrinsics-disable  -fvxt-intrinsics-enable
1372 -ffixed-line-length-@var{n}  -ffixed-line-length-none
1373 @end smallexample
1374
1375 @item Warning Options
1376 @xref{Warning Options,,Options to Request or Suppress Warnings}.
1377 @smallexample
1378 -fsyntax-only  -pedantic  -pedantic-errors  -fpedantic
1379 -w  -Wno-globals  -Wimplicit -Wunused  -Wuninitialized
1380 -Wall  -Wsurprising
1381 -Werror  -W
1382 @end smallexample
1383
1384 @item Debugging Options
1385 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
1386 @smallexample
1387 -g
1388 @end smallexample
1389
1390 @item Optimization Options
1391 @xref{Optimize Options,,Options that Control Optimization}.
1392 @smallexample
1393 -malign-double
1394 -ffloat-store  -fforce-mem  -fforce-addr  -fno-inline
1395 -ffast-math  -fstrength-reduce  -frerun-cse-after-loop
1396 -fexpensive-optimizations  -fdelayed-branch
1397 -fschedule-insns  -fschedule-insn2  -fcaller-saves
1398 -funroll-loops  -funroll-all-loops
1399 -fno-move-all-movables  -fno-reduce-all-givs
1400 -fno-rerun-loop-opt
1401 @end smallexample
1402
1403 @item Directory Options
1404 @xref{Directory Options,,Options for Directory Search}.
1405 @smallexample
1406 -I@var{dir}  -I-
1407 @end smallexample
1408
1409 @item Code Generation Options
1410 @xref{Code Gen Options,,Options for Code Generation Conventions}.
1411 @smallexample
1412 -fno-automatic  -finit-local-zero  -fno-f2c
1413 -ff2c-library  -fno-underscoring  -fno-ident
1414 -fpcc-struct-return  -freg-struct-return
1415 -fshort-double  -fno-common  -fpack-struct
1416 -fzeros  -fno-second-underscore
1417 -fdebug-kludge  -fno-emulate-complex
1418 -falias-check  -fargument-alias
1419 -fargument-noalias  -fno-argument-noalias-global
1420 -fno-globals
1421 @end smallexample
1422 @end table
1423
1424 @menu
1425 * Overall Options::     Controlling the kind of output:
1426                         an executable, object files, assembler files,
1427                         or preprocessed source.
1428 * Shorthand Options::   Options that are shorthand for other options.
1429 * Fortran Dialect Options::  Controlling the variant of Fortran language
1430                              compiled.
1431 * Warning Options::     How picky should the compiler be?
1432 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1433 * Optimize Options::    How much optimization?
1434 * Preprocessor Options:: Controlling header files and macro definitions.
1435                          Also, getting dependency information for Make.
1436 * Directory Options::   Where to find header files and libraries.
1437                         Where to find the compiler executable files.
1438 * Code Gen Options::    Specifying conventions for function calls, data layout
1439                         and register usage.
1440 @end menu
1441
1442 @node Overall Options
1443 @section Options Controlling the Kind of Output
1444 @cindex overall options
1445 @cindex options, overall
1446
1447 Compilation can involve as many as four stages: preprocessing, code
1448 generation (often what is really meant by the term ``compilation''),
1449 assembly, and linking, always in that order.  The first three
1450 stages apply to an individual source file, and end by producing an
1451 object file; linking combines all the object files (those newly
1452 compiled, and those specified as input) into an executable file.
1453
1454 @cindex file name suffix
1455 @cindex suffixes, file name
1456 @cindex file name extension
1457 @cindex extensions, file name
1458 @cindex file type
1459 @cindex types, file
1460 For any given input file, the file name suffix determines what kind of
1461 program is contained in the file---that is, the language in which the
1462 program is written is generally indicated by the suffix.
1463 Suffixes specific to GNU Fortran are listed below.
1464 @xref{Overall Options,,gcc,Using and Porting GNU CC}, for
1465 information on suffixes recognized by GNU CC.
1466
1467 @table @code
1468 @cindex .f filename suffix
1469 @cindex .for filename suffix
1470 @cindex .FOR filename suffix
1471 @item @var{file}.f
1472 @item @var{file}.for
1473 @item @var{file}.FOR
1474 Fortran source code that should not be preprocessed.
1475
1476 Such source code cannot contain any preprocessor directives, such
1477 as @code{#include}, @code{#define}, @code{#if}, and so on.
1478
1479 You can force @samp{.f} files to be preprocessed by @samp{cpp} by using
1480 @samp{-x f77-cpp-input}, @ref{LEX}.
1481
1482 @cindex preprocessor
1483 @cindex C preprocessor
1484 @cindex cpp preprocessor
1485 @cindex Fortran preprocessor
1486 @cindex cpp program
1487 @cindex programs, cpp
1488 @cindex .F filename suffix
1489 @cindex .fpp filename suffix
1490 @cindex .FPP filename suffix
1491 @item @var{file}.F
1492 @item @var{file}.fpp
1493 @item @var{file}.FPP
1494 Fortran source code that must be preprocessed (by the C preprocessor
1495 @code{cpp}, which is part of GNU CC).
1496
1497 Note that preprocessing is not extended to the contents of
1498 files included by the @code{INCLUDE} directive---the @code{#include}
1499 preprocessor directive must be used instead.
1500
1501 @cindex Ratfor preprocessor
1502 @cindex programs, @code{ratfor}
1503 @cindex @samp{.r} filename suffix
1504 @cindex @code{ratfor}
1505 @item @var{file}.r
1506 Ratfor source code, which must be preprocessed by the @code{ratfor}
1507 command, which is available separately (as it is not yet part of the GNU
1508 Fortran distribution).
1509 One version in Fortran, adapted for use with @code{g77}, is at
1510 @uref{ftp://members.aol.com/n8tm/rat7.uue} (of uncertain copyright
1511 status).  Another, public domain version in C is at
1512 @uref{http://sepwww.stanford.edu/sep/prof/ratfor.shar.2}.
1513 @end table
1514
1515 UNIX users typically use the @file{@var{file}.f} and @file{@var{file}.F}
1516 nomenclature.
1517 Users of other operating systems, especially those that cannot
1518 distinguish upper-case
1519 letters from lower-case letters in their file names, typically use
1520 the @file{@var{file}.for} and @file{@var{file}.fpp} nomenclature.
1521
1522 @cindex #define
1523 @cindex #include
1524 @cindex #if
1525 Use of the preprocessor @code{cpp} allows use of C-like
1526 constructs such as @code{#define} and @code{#include}, but can
1527 lead to unexpected, even mistaken, results due to Fortran's source file
1528 format.
1529 It is recommended that use of the C preprocessor
1530 be limited to @code{#include} and, in
1531 conjunction with @code{#define}, only @code{#if} and related directives,
1532 thus avoiding in-line macro expansion entirely.
1533 This recommendation applies especially
1534 when using the traditional fixed source form.
1535 With free source form,
1536 fewer unexpected transformations are likely to happen, but use of
1537 constructs such as Hollerith and character constants can nevertheless
1538 present problems, especially when these are continued across multiple
1539 source lines.
1540 These problems result, primarily, from differences between the way
1541 such constants are interpreted by the C preprocessor and by a Fortran
1542 compiler.
1543
1544 Another example of a problem that results from using the C preprocessor
1545 is that a Fortran comment line that happens to contain any
1546 characters ``interesting'' to the C preprocessor,
1547 such as a backslash at the end of the line,
1548 is not recognized by the preprocessor as a comment line,
1549 so instead of being passed through ``raw'',
1550 the line is edited according to the rules for the preprocessor.
1551 For example, the backslash at the end of the line is removed,
1552 along with the subsequent newline, resulting in the next
1553 line being effectively commented out---unfortunate if that
1554 line is a non-comment line of important code!
1555
1556 @emph{Note:} The @samp{-traditional} and @samp{-undef} flags are supplied
1557 to @code{cpp} by default, to help avoid unpleasant surprises.
1558 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
1559 gcc,Using and Porting GNU CC}.
1560 This means that ANSI C preprocessor features (such as the @samp{#}
1561 operator) aren't available, and only variables in the C reserved
1562 namespace (generally, names with a leading underscore) are liable to
1563 substitution by C predefines.
1564 Thus, if you want to do system-specific
1565 tests, use, for example, @samp{#ifdef __linux__} rather than @samp{#ifdef linux}.
1566 Use the @samp{-v} option to see exactly how the preprocessor is invoked.
1567
1568 @cindex /*
1569 Unfortunately, the @samp{-traditional} flag will not avoid an error from
1570 anything that @code{cpp} sees as an unterminated C comment, such as:
1571 @smallexample
1572 C Some Fortran compilers accept /* as starting
1573 C an inline comment.
1574 @end smallexample
1575 @xref{Trailing Comment}.
1576
1577 The following options that affect overall processing are recognized
1578 by the @code{g77} and @code{gcc} commands in a GNU Fortran installation:
1579
1580 @table @code
1581 @cindex -fversion option
1582 @cindex options, -fversion
1583 @cindex printing version information
1584 @cindex version information, printing
1585 @item -fversion
1586 Ensure that the @code{g77}-specific version of the compiler phase is reported,
1587 if run.
1588 (This is supplied automatically when @samp{-v} or @samp{--verbose}
1589 is specified as a command-line option for @code{g77} or @code{gcc}
1590 and when the resulting commands compile Fortran source files.)
1591
1592 @cindex -fset-g77-defaults option
1593 @cindex options, -fset-g77-defaults
1594 @item -fset-g77-defaults
1595 @emph{Version info:}
1596 This option is obsolete in @code{egcs}
1597 as of version 1.1.
1598
1599 Set up whatever @code{gcc} options are to apply to Fortran
1600 compilations, and avoid running internal consistency checks
1601 that might take some time.
1602
1603 This option is supplied automatically when compiling Fortran code
1604 via the @code{g77} or @code{gcc} command.
1605 The description of this option is provided so that users seeing
1606 it in the output of, say, @samp{g77 -v} understand why it is
1607 there.
1608
1609 @cindex modifying g77
1610 @cindex code, modifying
1611 Also, developers who run @code{f771} directly might want to specify it
1612 by hand to get the same defaults as they would running @code{f771}
1613 via @code{g77} or @code{gcc}.
1614 However, such developers should, after linking a new @code{f771}
1615 executable, invoke it without this option once,
1616 e.g. via @kbd{./f771 -quiet < /dev/null},
1617 to ensure that they have not introduced any
1618 internal inconsistencies (such as in the table of
1619 intrinsics) before proceeding---@code{g77} will crash
1620 with a diagnostic if it detects an inconsistency.
1621
1622 @cindex -fno-silent option
1623 @cindex options, -fno-silent
1624 @cindex f2c compatibility
1625 @cindex compatibility, f2c
1626 @cindex status, compilation
1627 @cindex compilation, status
1628 @cindex reporting compilation status
1629 @cindex printing compilation status
1630 @item -fno-silent
1631 Print (to @code{stderr}) the names of the program units as
1632 they are compiled, in a form similar to that used by popular
1633 UNIX @code{f77} implementations and @code{f2c}.
1634 @end table
1635
1636 @xref{Overall Options,,Options Controlling the Kind of Output,
1637 gcc,Using and Porting GNU CC}, for information
1638 on more options that control the overall operation of the @code{gcc} command
1639 (and, by extension, the @code{g77} command).
1640
1641 @node Shorthand Options
1642 @section Shorthand Options
1643 @cindex shorthand options
1644 @cindex options, shorthand
1645 @cindex macro options
1646 @cindex options, macro
1647
1648 The following options serve as ``shorthand''
1649 for other options accepted by the compiler:
1650
1651 @table @code
1652 @cindex -fugly option
1653 @cindex options, -fugly
1654 @item -fugly
1655 @cindex ugly features
1656 @cindex features, ugly
1657 Specify that certain ``ugly'' constructs are to be quietly accepted.
1658 Same as:
1659
1660 @smallexample
1661 -fugly-args -fugly-assign -fugly-assumed
1662 -fugly-comma -fugly-complex -fugly-init
1663 -fugly-logint
1664 @end smallexample
1665
1666 These constructs are considered inappropriate to use in new
1667 or well-maintained portable Fortran code, but widely used
1668 in old code.
1669 @xref{Distensions}, for more information.
1670
1671 @emph{Note:} The @samp{-fugly} option is likely to
1672 be removed in a future version.
1673 Implicitly enabling all the @samp{-fugly-*} options
1674 is unlikely to be feasible, or sensible, in the future,
1675 so users should learn to specify only those
1676 @samp{-fugly-*} options they really need for a
1677 particular source file.
1678
1679 @cindex -fno-ugly option
1680 @cindex options, -fno-ugly
1681 @item -fno-ugly
1682 @cindex ugly features
1683 @cindex features, ugly
1684 Specify that all ``ugly'' constructs are to be noisily rejected.
1685 Same as:
1686
1687 @smallexample
1688 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1689 -fno-ugly-comma -fno-ugly-complex -fno-ugly-init
1690 -fno-ugly-logint
1691 @end smallexample
1692
1693 @xref{Distensions}, for more information.
1694
1695 @cindex -ff66 option
1696 @cindex options, -ff66
1697 @item -ff66
1698 @cindex FORTRAN 66
1699 @cindex compatibility, FORTRAN 66
1700 Specify that the program is written in idiomatic FORTRAN 66.
1701 Same as @samp{-fonetrip -fugly-assumed}.
1702
1703 The @samp{-fno-f66} option is the inverse of @samp{-ff66}.
1704 As such, it is the same as @samp{-fno-onetrip -fno-ugly-assumed}.
1705
1706 The meaning of this option is likely to be refined as future
1707 versions of @code{g77} provide more compatibility with other
1708 existing and obsolete Fortran implementations.
1709
1710 @cindex -ff77 option
1711 @cindex options, -ff77
1712 @item -ff77
1713 @cindex UNIX f77
1714 @cindex f2c compatibility
1715 @cindex compatibility, f2c
1716 @cindex f77 compatibility
1717 @cindex compatibility, f77
1718 Specify that the program is written in idiomatic UNIX FORTRAN 77
1719 and/or the dialect accepted by the @code{f2c} product.
1720 Same as @samp{-fbackslash -fno-typeless-boz}.
1721
1722 The meaning of this option is likely to be refined as future
1723 versions of @code{g77} provide more compatibility with other
1724 existing and obsolete Fortran implementations.
1725
1726 @cindex -fno-f77 option
1727 @cindex options, -fno-f77
1728 @item -fno-f77
1729 @cindex UNIX f77
1730 The @samp{-fno-f77} option is @emph{not} the inverse
1731 of @samp{-ff77}.
1732 It specifies that the program is not written in idiomatic UNIX
1733 FORTRAN 77 or @code{f2c}, but in a more widely portable dialect.
1734 @samp{-fno-f77} is the same as @samp{-fno-backslash}.
1735
1736 The meaning of this option is likely to be refined as future
1737 versions of @code{g77} provide more compatibility with other
1738 existing and obsolete Fortran implementations.
1739 @end table
1740
1741 @node Fortran Dialect Options
1742 @section Options Controlling Fortran Dialect
1743 @cindex dialect options
1744 @cindex language, dialect options
1745 @cindex options, dialect
1746
1747 The following options control the dialect of Fortran
1748 that the compiler accepts:
1749
1750 @table @code
1751 @cindex -ffree-form option
1752 @cindex options, -ffree-form
1753 @cindex -fno-fixed-form option
1754 @cindex options, -fno-fixed-form
1755 @cindex source file format
1756 @cindex free form
1757 @cindex fixed form
1758 @cindex Fortran 90, features
1759 @item -ffree-form
1760 @item -fno-fixed-form
1761 Specify that the source file is written in free form
1762 (introduced in Fortran 90) instead of the more-traditional fixed form.
1763
1764 @cindex -ff90 option
1765 @cindex options, -ff90
1766 @cindex Fortran 90, features
1767 @item -ff90
1768 Allow certain Fortran-90 constructs.
1769
1770 This option controls whether certain
1771 Fortran 90 constructs are recognized.
1772 (Other Fortran 90 constructs
1773 might or might not be recognized depending on other options such as
1774 @samp{-fvxt}, @samp{-ff90-intrinsics-enable}, and the
1775 current level of support for Fortran 90.)
1776
1777 @xref{Fortran 90}, for more information.
1778
1779 @cindex -fvxt option
1780 @cindex options, -fvxt
1781 @item -fvxt
1782 @cindex Fortran 90, features
1783 @cindex VXT extensions
1784 Specify the treatment of certain constructs that have different
1785 meanings depending on whether the code is written in
1786 GNU Fortran (based on FORTRAN 77 and akin to Fortran 90)
1787 or VXT Fortran (more like VAX FORTRAN).
1788
1789 The default is @samp{-fno-vxt}.
1790 @samp{-fvxt} specifies that the VXT Fortran interpretations
1791 for those constructs are to be chosen.
1792
1793 @xref{VXT Fortran}, for more information.
1794
1795 @cindex -fdollar-ok option
1796 @cindex options, -fdollar-ok
1797 @item -fdollar-ok
1798 @cindex dollar sign
1799 @cindex symbol names
1800 @cindex character set
1801 Allow @samp{$} as a valid character in a symbol name.
1802
1803 @cindex -fno-backslash option
1804 @cindex options, -fno-backslash
1805 @item -fno-backslash
1806 @cindex backslash
1807 @cindex character constants
1808 @cindex Hollerith constants
1809 Specify that @samp{\} is not to be specially interpreted in character
1810 and Hollerith constants a la C and many UNIX Fortran compilers.
1811
1812 For example, with @samp{-fbackslash} in effect, @samp{A\nB} specifies
1813 three characters, with the second one being newline.
1814 With @samp{-fno-backslash}, it specifies four characters,
1815 @samp{A}, @samp{\}, @samp{n}, and @samp{B}.
1816
1817 Note that @code{g77} implements a fairly general form of backslash
1818 processing that is incompatible with the narrower forms supported
1819 by some other compilers.
1820 For example, @samp{'A\003B'} is a three-character string in @code{g77},
1821 whereas other compilers that support backslash might not support
1822 the three-octal-digit form, and thus treat that string as longer
1823 than three characters.
1824
1825 @xref{Backslash in Constants}, for
1826 information on why @samp{-fbackslash} is the default
1827 instead of @samp{-fno-backslash}.
1828
1829 @cindex -fno-ugly-args option
1830 @cindex options, -fno-ugly-args
1831 @item -fno-ugly-args
1832 Disallow passing Hollerith and typeless constants as actual
1833 arguments (for example, @samp{CALL FOO(4HABCD)}).
1834
1835 @xref{Ugly Implicit Argument Conversion}, for more information.
1836
1837 @cindex -fugly-assign option
1838 @cindex options, -fugly-assign
1839 @item -fugly-assign
1840 Use the same storage for a given variable regardless of
1841 whether it is used to hold an assigned-statement label
1842 (as in @samp{ASSIGN 10 TO I}) or used to hold numeric data
1843 (as in @samp{I = 3}).
1844
1845 @xref{Ugly Assigned Labels}, for more information.
1846
1847 @cindex -fugly-assumed option
1848 @cindex options, -fugly-assumed
1849 @item -fugly-assumed
1850 Assume any dummy array with a final dimension specified as @samp{1}
1851 is really an assumed-size array, as if @samp{*} had been specified
1852 for the final dimension instead of @samp{1}.
1853
1854 For example, @samp{DIMENSION X(1)} is treated as if it
1855 had read @samp{DIMENSION X(*)}.
1856
1857 @xref{Ugly Assumed-Size Arrays}, for more information.
1858
1859 @cindex -fugly-comma option
1860 @cindex options, -fugly-comma
1861 @item -fugly-comma
1862 In an external-procedure invocation,
1863 treat a trailing comma in the argument list
1864 as specification of a trailing null argument,
1865 and treat an empty argument list
1866 as specification of a single null argument.
1867
1868 For example, @samp{CALL FOO(,)} is treated as
1869 @samp{CALL FOO(%VAL(0), %VAL(0))}.
1870 That is, @emph{two} null arguments are specified
1871 by the procedure call when @samp{-fugly-comma} is in force.
1872 And @samp{F = FUNC()} is treated as @samp{F = FUNC(%VAL(0))}.
1873
1874 The default behavior, @samp{-fno-ugly-comma}, is to ignore
1875 a single trailing comma in an argument list.
1876 So, by default, @samp{CALL FOO(X,)} is treated
1877 exactly the same as @samp{CALL FOO(X)}.
1878
1879 @xref{Ugly Null Arguments}, for more information.
1880
1881 @cindex -fugly-complex option
1882 @cindex options, -fugly-complex
1883 @item -fugly-complex
1884 Do not complain about @samp{REAL(@var{expr})} or
1885 @samp{AIMAG(@var{expr})} when @var{expr} is a @code{COMPLEX}
1886 type other than @code{COMPLEX(KIND=1)}---usually
1887 this is used to permit @code{COMPLEX(KIND=2)}
1888 (@code{DOUBLE COMPLEX}) operands.
1889
1890 The @samp{-ff90} option controls the interpretation
1891 of this construct.
1892
1893 @xref{Ugly Complex Part Extraction}, for more information.
1894
1895 @cindex -fno-ugly-init option
1896 @cindex options, -fno-ugly-init
1897 @item -fno-ugly-init
1898 Disallow use of Hollerith and typeless constants as initial
1899 values (in @code{PARAMETER} and @code{DATA} statements), and
1900 use of character constants to
1901 initialize numeric types and vice versa.
1902
1903 For example, @samp{DATA I/'F'/, CHRVAR/65/, J/4HABCD/} is disallowed by
1904 @samp{-fno-ugly-init}.
1905
1906 @xref{Ugly Conversion of Initializers}, for more information.
1907
1908 @cindex -fugly-logint option
1909 @cindex options, -fugly-logint
1910 @item -fugly-logint
1911 Treat @code{INTEGER} and @code{LOGICAL} variables and
1912 expressions as potential stand-ins for each other.
1913
1914 For example, automatic conversion between @code{INTEGER} and
1915 @code{LOGICAL} is enabled, for many contexts, via this option.
1916
1917 @xref{Ugly Integer Conversions}, for more information.
1918
1919 @cindex -fonetrip option
1920 @cindex options, -fonetrip
1921 @item -fonetrip
1922 @cindex FORTRAN 66
1923 @cindex @code{DO} loops, one-trip
1924 @cindex one-trip @code{DO} loops
1925 @cindex @code{DO} loops, zero-trip
1926 @cindex zero-trip @code{DO} loops
1927 @cindex compatibility, FORTRAN 66
1928 Executable iterative @code{DO} loops are to be executed at
1929 least once each time they are reached.
1930
1931 ANSI FORTRAN 77 and more recent versions of the Fortran standard
1932 specify that the body of an iterative @code{DO} loop is not executed
1933 if the number of iterations calculated from the parameters of the
1934 loop is less than 1.
1935 (For example, @samp{DO 10 I = 1, 0}.)
1936 Such a loop is called a @dfn{zero-trip loop}.
1937
1938 Prior to ANSI FORTRAN 77, many compilers implemented @code{DO} loops
1939 such that the body of a loop would be executed at least once, even
1940 if the iteration count was zero.
1941 Fortran code written assuming this behavior is said to require
1942 @dfn{one-trip loops}.
1943 For example, some code written to the FORTRAN 66 standard
1944 expects this behavior from its @code{DO} loops, although that
1945 standard did not specify this behavior.
1946
1947 The @samp{-fonetrip} option specifies that the source file(s) being
1948 compiled require one-trip loops.
1949
1950 This option affects only those loops specified by the (iterative) @code{DO}
1951 statement and by implied-@code{DO} lists in I/O statements.
1952 Loops specified by implied-@code{DO} lists in @code{DATA} and
1953 specification (non-executable) statements are not affected.
1954
1955 @cindex -ftypeless-boz option
1956 @cindex options, -ftypeless-boz
1957 @cindex prefix-radix constants
1958 @cindex constants, prefix-radix
1959 @cindex constants, types
1960 @cindex types, constants
1961 @item -ftypeless-boz
1962 Specifies that prefix-radix non-decimal constants, such as
1963 @samp{Z'ABCD'}, are typeless instead of @code{INTEGER(KIND=1)}.
1964
1965 You can test for yourself whether a particular compiler treats
1966 the prefix form as @code{INTEGER(KIND=1)} or typeless by running the
1967 following program:
1968
1969 @smallexample
1970 EQUIVALENCE (I, R)
1971 R = Z'ABCD1234'
1972 J = Z'ABCD1234'
1973 IF (J .EQ. I) PRINT *, 'Prefix form is TYPELESS'
1974 IF (J .NE. I) PRINT *, 'Prefix form is INTEGER'
1975 END
1976 @end smallexample
1977
1978 Reports indicate that many compilers process this form as
1979 @code{INTEGER(KIND=1)}, though a few as typeless, and at least one
1980 based on a command-line option specifying some kind of
1981 compatibility.
1982
1983 @cindex -fintrin-case-initcap option
1984 @cindex options, -fintrin-case-initcap
1985 @item -fintrin-case-initcap
1986 @cindex -fintrin-case-upper option
1987 @cindex options, -fintrin-case-upper
1988 @item -fintrin-case-upper
1989 @cindex -fintrin-case-lower option
1990 @cindex options, -fintrin-case-lower
1991 @item -fintrin-case-lower
1992 @cindex -fintrin-case-any option
1993 @cindex options, -fintrin-case-any
1994 @item -fintrin-case-any
1995 Specify expected case for intrinsic names.
1996 @samp{-fintrin-case-lower} is the default.
1997
1998 @cindex -fmatch-case-initcap option
1999 @cindex options, -fmatch-case-initcap
2000 @item -fmatch-case-initcap
2001 @cindex -fmatch-case-upper option
2002 @cindex options, -fmatch-case-upper
2003 @item -fmatch-case-upper
2004 @cindex -fmatch-case-lower option
2005 @cindex options, -fmatch-case-lower
2006 @item -fmatch-case-lower
2007 @cindex -fmatch-case-any option
2008 @cindex options, -fmatch-case-any
2009 @item -fmatch-case-any
2010 Specify expected case for keywords.
2011 @samp{-fmatch-case-lower} is the default.
2012
2013 @cindex -fsource-case-upper option
2014 @cindex options, -fsource-case-upper
2015 @item -fsource-case-upper
2016 @cindex -fsource-case-lower option
2017 @cindex options, -fsource-case-lower
2018 @item -fsource-case-lower
2019 @cindex -fsource-case-preserve option
2020 @cindex options, -fsource-case-preserve
2021 @item -fsource-case-preserve
2022 Specify whether source text other than character and Hollerith constants
2023 is to be translated to uppercase, to lowercase, or preserved as is.
2024 @samp{-fsource-case-lower} is the default.
2025
2026 @cindex -fsymbol-case-initcap option
2027 @cindex options, -fsymbol-case-initcap
2028 @item -fsymbol-case-initcap
2029 @cindex -fsymbol-case-upper option
2030 @cindex options, -fsymbol-case-upper
2031 @item -fsymbol-case-upper
2032 @cindex -fsymbol-case-lower option
2033 @cindex options, -fsymbol-case-lower
2034 @item -fsymbol-case-lower
2035 @cindex -fsymbol-case-any option
2036 @cindex options, -fsymbol-case-any
2037 @item -fsymbol-case-any
2038 Specify valid cases for user-defined symbol names.
2039 @samp{-fsymbol-case-any} is the default.
2040
2041 @cindex -fcase-strict-upper option
2042 @cindex options, -fcase-strict-upper
2043 @item -fcase-strict-upper
2044 Same as @samp{-fintrin-case-upper -fmatch-case-upper -fsource-case-preserve
2045 -fsymbol-case-upper}.
2046 (Requires all pertinent source to be in uppercase.)
2047
2048 @cindex -fcase-strict-lower option
2049 @cindex options, -fcase-strict-lower
2050 @item -fcase-strict-lower
2051 Same as @samp{-fintrin-case-lower -fmatch-case-lower -fsource-case-preserve
2052 -fsymbol-case-lower}.
2053 (Requires all pertinent source to be in lowercase.)
2054
2055 @cindex -fcase-initcap option
2056 @cindex options, -fcase-initcap
2057 @item -fcase-initcap
2058 Same as @samp{-fintrin-case-initcap -fmatch-case-initcap -fsource-case-preserve
2059 -fsymbol-case-initcap}.
2060 (Requires all pertinent source to be in initial capitals,
2061 as in @samp{Print *,SqRt(Value)}.)
2062
2063 @cindex -fcase-upper option
2064 @cindex options, -fcase-upper
2065 @item -fcase-upper
2066 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-upper
2067 -fsymbol-case-any}.
2068 (Maps all pertinent source to uppercase.)
2069
2070 @cindex -fcase-lower option
2071 @cindex options, -fcase-lower
2072 @item -fcase-lower
2073 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-lower
2074 -fsymbol-case-any}.
2075 (Maps all pertinent source to lowercase.)
2076
2077 @cindex -fcase-preserve option
2078 @cindex options, -fcase-preserve
2079 @item -fcase-preserve
2080 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-preserve
2081 -fsymbol-case-any}.
2082 (Preserves all case in user-defined symbols,
2083 while allowing any-case matching of intrinsics and keywords.
2084 For example, @samp{call Foo(i,I)} would pass two @emph{different}
2085 variables named @samp{i} and @samp{I} to a procedure named @samp{Foo}.)
2086
2087 @cindex -fbadu77-intrinsics-delete option
2088 @cindex options, -fbadu77-intrinsics-delete
2089 @item -fbadu77-intrinsics-delete
2090 @cindex -fbadu77-intrinsics-hide option
2091 @cindex options, -fbadu77-intrinsics-hide
2092 @item -fbadu77-intrinsics-hide
2093 @cindex -fbadu77-intrinsics-disable option
2094 @cindex options, -fbadu77-intrinsics-disable
2095 @item -fbadu77-intrinsics-disable
2096 @cindex -fbadu77-intrinsics-enable option
2097 @cindex options, -fbadu77-intrinsics-enable
2098 @item -fbadu77-intrinsics-enable
2099 @cindex @code{badu77} intrinsics
2100 @cindex intrinsics, @code{badu77}
2101 Specify status of UNIX intrinsics having inappropriate forms.
2102 @samp{-fbadu77-intrinsics-enable} is the default.
2103 @xref{Intrinsic Groups}.
2104
2105 @cindex -ff2c-intrinsics-delete option
2106 @cindex options, -ff2c-intrinsics-delete
2107 @item -ff2c-intrinsics-delete
2108 @cindex -ff2c-intrinsics-hide option
2109 @cindex options, -ff2c-intrinsics-hide
2110 @item -ff2c-intrinsics-hide
2111 @cindex -ff2c-intrinsics-disable option
2112 @cindex options, -ff2c-intrinsics-disable
2113 @item -ff2c-intrinsics-disable
2114 @cindex -ff2c-intrinsics-enable option
2115 @cindex options, -ff2c-intrinsics-enable
2116 @item -ff2c-intrinsics-enable
2117 @cindex @code{f2c} intrinsics
2118 @cindex intrinsics, @code{f2c}
2119 Specify status of f2c-specific intrinsics.
2120 @samp{-ff2c-intrinsics-enable} is the default.
2121 @xref{Intrinsic Groups}.
2122
2123 @cindex -ff90-intrinsics-delete option
2124 @cindex options, -ff90-intrinsics-delete
2125 @item -ff90-intrinsics-delete
2126 @cindex -ff90-intrinsics-hide option
2127 @cindex options, -ff90-intrinsics-hide
2128 @item -ff90-intrinsics-hide
2129 @cindex -ff90-intrinsics-disable option
2130 @cindex options, -ff90-intrinsics-disable
2131 @item -ff90-intrinsics-disable
2132 @cindex -ff90-intrinsics-enable option
2133 @cindex options, -ff90-intrinsics-enable
2134 @item -ff90-intrinsics-enable
2135 @cindex Fortran 90, intrinsics
2136 @cindex intrinsics, Fortran 90
2137 Specify status of F90-specific intrinsics.
2138 @samp{-ff90-intrinsics-enable} is the default.
2139 @xref{Intrinsic Groups}.
2140
2141 @cindex -fgnu-intrinsics-delete option
2142 @cindex options, -fgnu-intrinsics-delete
2143 @item -fgnu-intrinsics-delete
2144 @cindex -fgnu-intrinsics-hide option
2145 @cindex options, -fgnu-intrinsics-hide
2146 @item -fgnu-intrinsics-hide
2147 @cindex -fgnu-intrinsics-disable option
2148 @cindex options, -fgnu-intrinsics-disable
2149 @item -fgnu-intrinsics-disable
2150 @cindex -fgnu-intrinsics-enable option
2151 @cindex options, -fgnu-intrinsics-enable
2152 @item -fgnu-intrinsics-enable
2153 @cindex Digital Fortran features
2154 @cindex @code{COMPLEX} intrinsics
2155 @cindex intrinsics, @code{COMPLEX}
2156 Specify status of Digital's COMPLEX-related intrinsics.
2157 @samp{-fgnu-intrinsics-enable} is the default.
2158 @xref{Intrinsic Groups}.
2159
2160 @cindex -fmil-intrinsics-delete option
2161 @cindex options, -fmil-intrinsics-delete
2162 @item -fmil-intrinsics-delete
2163 @cindex -fmil-intrinsics-hide option
2164 @cindex options, -fmil-intrinsics-hide
2165 @item -fmil-intrinsics-hide
2166 @cindex -fmil-intrinsics-disable option
2167 @cindex options, -fmil-intrinsics-disable
2168 @item -fmil-intrinsics-disable
2169 @cindex -fmil-intrinsics-enable option
2170 @cindex options, -fmil-intrinsics-enable
2171 @item -fmil-intrinsics-enable
2172 @cindex MIL-STD 1753
2173 @cindex intrinsics, MIL-STD 1753
2174 Specify status of MIL-STD-1753-specific intrinsics.
2175 @samp{-fmil-intrinsics-enable} is the default.
2176 @xref{Intrinsic Groups}.
2177
2178 @cindex -funix-intrinsics-delete option
2179 @cindex options, -funix-intrinsics-delete
2180 @item -funix-intrinsics-delete
2181 @cindex -funix-intrinsics-hide option
2182 @cindex options, -funix-intrinsics-hide
2183 @item -funix-intrinsics-hide
2184 @cindex -funix-intrinsics-disable option
2185 @cindex options, -funix-intrinsics-disable
2186 @item -funix-intrinsics-disable
2187 @cindex -funix-intrinsics-enable option
2188 @cindex options, -funix-intrinsics-enable
2189 @item -funix-intrinsics-enable
2190 @cindex UNIX intrinsics
2191 @cindex intrinsics, UNIX
2192 Specify status of UNIX intrinsics.
2193 @samp{-funix-intrinsics-enable} is the default.
2194 @xref{Intrinsic Groups}.
2195
2196 @cindex -fvxt-intrinsics-delete option
2197 @cindex options, -fvxt-intrinsics-delete
2198 @item -fvxt-intrinsics-delete
2199 @cindex -fvxt-intrinsics-hide option
2200 @cindex options, -fvxt-intrinsics-hide
2201 @item -fvxt-intrinsics-hide
2202 @cindex -fvxt-intrinsics-disable option
2203 @cindex options, -fvxt-intrinsics-disable
2204 @item -fvxt-intrinsics-disable
2205 @cindex -fvxt-intrinsics-enable option
2206 @cindex options, -fvxt-intrinsics-enable
2207 @item -fvxt-intrinsics-enable
2208 @cindex VXT intrinsics
2209 @cindex intrinsics, VXT
2210 Specify status of VXT intrinsics.
2211 @samp{-fvxt-intrinsics-enable} is the default.
2212 @xref{Intrinsic Groups}.
2213
2214 @cindex -ffixed-line-length-@var{n} option
2215 @cindex options, -ffixed-line-length-@var{n}
2216 @item -ffixed-line-length-@var{n}
2217 @cindex source file format
2218 @cindex lines, length
2219 @cindex length of source lines
2220 @cindex fixed form
2221 @cindex limits, lengths of source lines
2222 Set column after which characters are ignored in typical fixed-form
2223 lines in the source file, and through which spaces are assumed (as
2224 if padded to that length) after the ends of short fixed-form lines.
2225
2226 @cindex card image
2227 @cindex extended-source option
2228 Popular values for @var{n} include 72 (the
2229 standard and the default), 80 (card image), and 132 (corresponds
2230 to ``extended-source'' options in some popular compilers).
2231 @var{n} may be @samp{none}, meaning that the entire line is meaningful
2232 and that continued character constants never have implicit spaces appended
2233 to them to fill out the line.
2234 @samp{-ffixed-line-length-0} means the same thing as
2235 @samp{-ffixed-line-length-none}.
2236
2237 @xref{Source Form}, for more information.
2238 @end table
2239
2240 @node Warning Options
2241 @section Options to Request or Suppress Warnings
2242 @cindex options, warnings
2243 @cindex warnings, suppressing
2244 @cindex messages, warning
2245 @cindex suppressing warnings
2246
2247 Warnings are diagnostic messages that report constructions which
2248 are not inherently erroneous but which are risky or suggest there
2249 might have been an error.
2250
2251 You can request many specific warnings with options beginning @samp{-W},
2252 for example @samp{-Wimplicit} to request warnings on implicit
2253 declarations.  Each of these specific warning options also has a
2254 negative form beginning @samp{-Wno-} to turn off warnings;
2255 for example, @samp{-Wno-implicit}.  This manual lists only one of the
2256 two forms, whichever is not the default.
2257
2258 These options control the amount and kinds of warnings produced by GNU
2259 Fortran:
2260
2261 @table @code
2262 @cindex syntax checking
2263 @cindex -fsyntax-only option
2264 @cindex options, -fsyntax-only
2265 @item -fsyntax-only
2266 Check the code for syntax errors, but don't do anything beyond that.
2267
2268 @cindex -pedantic option
2269 @cindex options, -pedantic
2270 @item -pedantic
2271 Issue warnings for uses of extensions to ANSI FORTRAN 77.
2272 @samp{-pedantic} also applies to C-language constructs where they
2273 occur in GNU Fortran source files, such as use of @samp{\e} in a
2274 character constant within a directive like @samp{#include}.
2275
2276 Valid ANSI FORTRAN 77 programs should compile properly with or without
2277 this option.
2278 However, without this option, certain GNU extensions and traditional
2279 Fortran features are supported as well.
2280 With this option, many of them are rejected.
2281
2282 Some users try to use @samp{-pedantic} to check programs for strict ANSI
2283 conformance.
2284 They soon find that it does not do quite what they want---it finds some
2285 non-ANSI practices, but not all.
2286 However, improvements to @code{g77} in this area are welcome.
2287
2288 @cindex -pedantic-errors option
2289 @cindex options, -pedantic-errors
2290 @item -pedantic-errors
2291 Like @samp{-pedantic}, except that errors are produced rather than
2292 warnings.
2293
2294 @cindex -fpedantic option
2295 @cindex options, -fpedantic
2296 @item -fpedantic
2297 Like @samp{-pedantic}, but applies only to Fortran constructs.
2298
2299 @cindex -w option
2300 @cindex options, -w
2301 @item -w
2302 Inhibit all warning messages.
2303
2304 @cindex -Wno-globals option
2305 @cindex options, -Wno-globals
2306 @item -Wno-globals
2307 @cindex global names, warning
2308 @cindex warnings, global names
2309 Inhibit warnings about use of a name as both a global name
2310 (a subroutine, function, or block data program unit, or a
2311 common block) and implicitly as the name of an intrinsic
2312 in a source file.
2313
2314 Also inhibit warnings about inconsistent invocations and/or
2315 definitions of global procedures (function and subroutines).
2316 Such inconsistencies include different numbers of arguments
2317 and different types of arguments.
2318
2319 @cindex -Wimplicit option
2320 @cindex options, -Wimplicit
2321 @item -Wimplicit
2322 @cindex implicit declaration, warning
2323 @cindex warnings, implicit declaration
2324 @cindex -u option
2325 @cindex /WARNINGS=DECLARATIONS switch
2326 @cindex IMPLICIT NONE, similar effect
2327 @cindex effecting IMPLICIT NONE
2328 Warn whenever a variable, array, or function is implicitly
2329 declared.
2330 Has an effect similar to using the @code{IMPLICIT NONE} statement
2331 in every program unit.
2332 (Some Fortran compilers provide this feature by an option
2333 named @samp{-u} or @samp{/WARNINGS=DECLARATIONS}.)
2334
2335 @cindex -Wunused option
2336 @cindex options, -Wunused
2337 @item -Wunused
2338 @cindex unused variables
2339 @cindex variables, unused
2340 Warn whenever a variable is unused aside from its declaration.
2341
2342 @cindex -Wuninitialized option
2343 @cindex options, -Wuninitialized
2344 @item -Wuninitialized
2345 @cindex uninitialized variables
2346 @cindex variables, uninitialized
2347 Warn whenever an automatic variable is used without first being initialized.
2348
2349 These warnings are possible only in optimizing compilation,
2350 because they require data-flow information that is computed only
2351 when optimizing.  If you don't specify @samp{-O}, you simply won't
2352 get these warnings.
2353
2354 These warnings occur only for variables that are candidates for
2355 register allocation.  Therefore, they do not occur for a variable
2356 @c that is declared @code{VOLATILE}, or
2357 whose address is taken, or whose size
2358 is other than 1, 2, 4 or 8 bytes.  Also, they do not occur for
2359 arrays, even when they are in registers.
2360
2361 Note that there might be no warning about a variable that is used only
2362 to compute a value that itself is never used, because such
2363 computations may be deleted by data-flow analysis before the warnings
2364 are printed.
2365
2366 These warnings are made optional because GNU Fortran is not smart
2367 enough to see all the reasons why the code might be correct
2368 despite appearing to have an error.  Here is one example of how
2369 this can happen:
2370
2371 @example
2372 SUBROUTINE DISPAT(J)
2373 IF (J.EQ.1) I=1
2374 IF (J.EQ.2) I=4
2375 IF (J.EQ.3) I=5
2376 CALL FOO(I)
2377 END
2378 @end example
2379
2380 @noindent
2381 If the value of @code{J} is always 1, 2 or 3, then @code{I} is
2382 always initialized, but GNU Fortran doesn't know this.  Here is
2383 another common case:
2384
2385 @example
2386 SUBROUTINE MAYBE(FLAG)
2387 LOGICAL FLAG
2388 IF (FLAG) VALUE = 9.4
2389 @dots{}
2390 IF (FLAG) PRINT *, VALUE
2391 END
2392 @end example
2393
2394 @noindent
2395 This has no bug because @code{VALUE} is used only if it is set.
2396
2397 @cindex -Wall option
2398 @cindex options, -Wall
2399 @item -Wall
2400 @cindex all warnings
2401 @cindex warnings, all
2402 The @samp{-Wunused} and @samp{-Wuninitialized} options combined.
2403 These are all the
2404 options which pertain to usage that we recommend avoiding and that we
2405 believe is easy to avoid.
2406 (As more warnings are added to @code{g77}, some might
2407 be added to the list enabled by @samp{-Wall}.)
2408 @end table
2409
2410 The remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}
2411 because they warn about constructions that we consider reasonable to
2412 use, on occasion, in clean programs.
2413
2414 @table @code
2415 @c @item -W
2416 @c Print extra warning messages for these events:
2417 @c
2418 @c @itemize @bullet
2419 @c @item
2420 @c If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused
2421 @c arguments.
2422 @c
2423 @c @end itemize
2424 @c
2425 @cindex -Wsurprising option
2426 @cindex options, -Wsurprising
2427 @item -Wsurprising
2428 Warn about ``suspicious'' constructs that are interpreted
2429 by the compiler in a way that might well be surprising to
2430 someone reading the code.
2431 These differences can result in subtle, compiler-dependent
2432 (even machine-dependent) behavioral differences.
2433 The constructs warned about include:
2434
2435 @itemize @bullet
2436 @item
2437 Expressions having two arithmetic operators in a row, such
2438 as @samp{X*-Y}.
2439 Such a construct is nonstandard, and can produce
2440 unexpected results in more complicated situations such
2441 as @samp{X**-Y*Z}.
2442 @code{g77}, along with many other compilers, interprets
2443 this example differently than many programmers, and a few
2444 other compilers.
2445 Specifically, @code{g77} interprets @samp{X**-Y*Z} as
2446 @samp{(X**(-Y))*Z}, while others might think it should
2447 be interpreted as @samp{X**(-(Y*Z))}.
2448
2449 A revealing example is the constant expression @samp{2**-2*1.},
2450 which @code{g77} evaluates to .25, while others might evaluate
2451 it to 0., the difference resulting from the way precedence affects
2452 type promotion.
2453
2454 (The @samp{-fpedantic} option also warns about expressions
2455 having two arithmetic operators in a row.)
2456
2457 @item
2458 Expressions with a unary minus followed by an operand and then
2459 a binary operator other than plus or minus.
2460 For example, @samp{-2**2} produces a warning, because
2461 the precedence is @samp{-(2**2)}, yielding -4, not
2462 @samp{(-2)**2}, which yields 4, and which might represent
2463 what a programmer expects.
2464
2465 An example of an expression producing different results
2466 in a surprising way is @samp{-I*S}, where @var{I} holds
2467 the value @samp{-2147483648} and @var{S} holds @samp{0.5}.
2468 On many systems, negating @var{I} results in the same
2469 value, not a positive number, because it is already the
2470 lower bound of what an @code{INTEGER(KIND=1)} variable can hold.
2471 So, the expression evaluates to a positive number, while
2472 the ``expected'' interpretation, @samp{(-I)*S}, would
2473 evaluate to a negative number.
2474
2475 Even cases such as @samp{-I*J} produce warnings,
2476 even though, in most configurations and situations,
2477 there is no computational difference between the
2478 results of the two interpretations---the purpose
2479 of this warning is to warn about differing interpretations
2480 and encourage a better style of coding, not to identify
2481 only those places where bugs might exist in the user's
2482 code.
2483
2484 @cindex DO statement
2485 @cindex statements, DO
2486 @item
2487 @code{DO} loops with @code{DO} variables that are not
2488 of integral type---that is, using @code{REAL}
2489 variables as loop control variables.
2490 Although such loops can be written to work in the
2491 ``obvious'' way, the way @code{g77} is required by the
2492 Fortran standard to interpret such code is likely to
2493 be quite different from the way many programmers expect.
2494 (This is true of all @code{DO} loops, but the differences
2495 are pronounced for non-integral loop control variables.)
2496
2497 @xref{Loops}, for more information.
2498 @end itemize
2499
2500 @cindex -Werror option
2501 @cindex options, -Werror
2502 @item -Werror
2503 Make all warnings into errors.
2504
2505 @cindex -W option
2506 @cindex options, -W
2507 @item -W
2508 @cindex extra warnings
2509 @cindex warnings, extra
2510 Turns on ``extra warnings'' and, if optimization is specified
2511 via @samp{-O}, the @samp{-Wuninitialized} option.
2512 (This might change in future versions of @code{g77}.)
2513
2514 ``Extra warnings'' are issued for:
2515
2516 @itemize @bullet
2517 @item
2518 @cindex unused parameters
2519 @cindex parameters, unused
2520 @cindex unused arguments
2521 @cindex arguments, unused
2522 @cindex unused dummies
2523 @cindex dummies, unused
2524 Unused parameters to a procedure (when @samp{-Wunused} also is
2525 specified).
2526
2527 @item
2528 @cindex overflow
2529 Overflows involving floating-point constants (not available
2530 for certain configurations).
2531 @end itemize
2532 @end table
2533
2534 @xref{Warning Options,,Options to Request or Suppress Warnings,
2535 gcc,Using and Porting GNU CC}, for information on more options offered
2536 by the GBE shared by @code{g77}, @code{gcc}, and other GNU compilers.
2537
2538 Some of these have no effect when compiling programs written in Fortran:
2539
2540 @table @code
2541 @cindex -Wcomment option
2542 @cindex options, -Wcomment
2543 @item -Wcomment
2544 @cindex -Wformat option
2545 @cindex options, -Wformat
2546 @item -Wformat
2547 @cindex -Wparentheses option
2548 @cindex options, -Wparentheses
2549 @item -Wparentheses
2550 @cindex -Wswitch option
2551 @cindex options, -Wswitch
2552 @item -Wswitch
2553 @cindex -Wtraditional option
2554 @cindex options, -Wtraditional
2555 @item -Wtraditional
2556 @cindex -Wshadow option
2557 @cindex options, -Wshadow
2558 @item -Wshadow
2559 @cindex -Wid-clash-@var{len} option
2560 @cindex options, -Wid-clash-@var{len}
2561 @item -Wid-clash-@var{len}
2562 @cindex -Wlarger-than-@var{len} option
2563 @cindex options, -Wlarger-than-@var{len}
2564 @item -Wlarger-than-@var{len}
2565 @cindex -Wconversion option
2566 @cindex options, -Wconversion
2567 @item -Wconversion
2568 @cindex -Waggregate-return option
2569 @cindex options, -Waggregate-return
2570 @item -Waggregate-return
2571 @cindex -Wredundant-decls option
2572 @cindex options, -Wredundant-decls
2573 @item -Wredundant-decls
2574 @cindex unsupported warnings
2575 @cindex warnings, unsupported
2576 These options all could have some relevant meaning for
2577 GNU Fortran programs, but are not yet supported.
2578 @end table
2579
2580 @node Debugging Options
2581 @section Options for Debugging Your Program or GNU Fortran
2582 @cindex options, debugging
2583 @cindex debugging information options
2584
2585 GNU Fortran has various special options that are used for debugging
2586 either your program or @code{g77}.
2587
2588 @table @code
2589 @cindex -g option
2590 @cindex options, -g
2591 @item -g
2592 Produce debugging information in the operating system's native format
2593 (stabs, COFF, XCOFF, or DWARF).  GDB can work with this debugging
2594 information.
2595
2596 @cindex common blocks
2597 @cindex equivalence areas
2598 @cindex missing debug features
2599 Support for this option in Fortran programs is incomplete.
2600 In particular, names of variables and arrays in common blocks
2601 or that are storage-associated via @code{EQUIVALENCE} are
2602 unavailable to the debugger.
2603
2604 However, version 0.5.19 of @code{g77} does provide this information
2605 in a rudimentary way, as controlled by the
2606 @samp{-fdebug-kludge} option.
2607
2608 @xref{Code Gen Options,,Options for Code Generation Conventions},
2609 for more information.
2610 @end table
2611
2612 @xref{Debugging Options,,Options for Debugging Your Program or GNU CC,
2613 gcc,Using and Porting GNU CC}, for more information on debugging options.
2614
2615 @node Optimize Options
2616 @section Options That Control Optimization
2617 @cindex optimize options
2618 @cindex options, optimization
2619
2620 Most Fortran users will want to use no optimization when
2621 developing and testing programs, and use @samp{-O} or @samp{-O2} when
2622 compiling programs for late-cycle testing and for production use.
2623 However, note that certain diagnostics---such as for uninitialized
2624 variables---depend on the flow analysis done by @samp{-O}, i.e.@: you
2625 must use @samp{-O} or @samp{-O2} to get such diagnostics.
2626
2627 The following flags have particular applicability when
2628 compiling Fortran programs:
2629
2630 @table @code
2631 @cindex -malign-double option
2632 @cindex options, -malign-double
2633 @item -malign-double
2634 (Intel x86 architecture only.)
2635
2636 Noticeably improves performance of @code{g77} programs making
2637 heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data
2638 on some systems.
2639 In particular, systems using Pentium, Pentium Pro, 586, and
2640 686 implementations
2641 of the i386 architecture execute programs faster when
2642 @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data are
2643 aligned on 64-bit boundaries
2644 in memory.
2645
2646 This option can, at least, make benchmark results more consistent
2647 across various system configurations, versions of the program,
2648 and data sets.
2649
2650 @emph{Note:} The warning in the @code{gcc} documentation about
2651 this option does not apply, generally speaking, to Fortran
2652 code compiled by @code{g77}.
2653
2654 @emph{Also note:} @samp{-malign-double} applies only to
2655 statically-allocated data.
2656 Double-precision data on the stack can still
2657 cause problems due to misalignment.
2658 @xref{Aligned Data}.
2659
2660 @emph{Also also note:} The negative form of @samp{-malign-double}
2661 is @samp{-mno-align-double}, not @samp{-benign-double}.
2662
2663 @cindex -ffloat-store option
2664 @cindex options, -ffloat-store
2665 @item -ffloat-store
2666 @cindex IEEE 754 conformance
2667 @cindex conformance, IEEE 754
2668 @cindex floating-point, precision
2669 Might help a Fortran program that depends on exact IEEE conformance on
2670 some machines, but might slow down a program that doesn't.
2671
2672 This option is effective when the floating-point unit is set to work in
2673 IEEE 854 `extended precision'---as it typically is on x86 and m68k GNU
2674 systems---rather than IEEE 754 double precision.  @code{-ffloat-store}
2675 tries to remove the extra precision by spilling data from floating-point
2676 registers into memory and this typically involves a big performance
2677 hit.  However, it doesn't affect intermediate results, so that it is
2678 only partially effective.  `Excess precision' is avoided in code like:
2679 @smallexample
2680 a = b + c
2681 d = a * e
2682 @end smallexample
2683 but not in code like:
2684 @smallexample
2685       d = (b + c) * e
2686 @end smallexample
2687
2688 For another, potentially better, way of controlling the precision
2689 @ref{Floating-point precision}.
2690
2691 @cindex -fforce-mem option
2692 @cindex options, -fforce-mem
2693 @item -fforce-mem
2694 @cindex -fforce-addr option
2695 @cindex options, -fforce-addr
2696 @item -fforce-addr
2697 @cindex loops, speeding up
2698 @cindex speed, of loops
2699 Might improve optimization of loops.
2700
2701 @cindex -fno-inline option
2702 @cindex options, -fno-inline
2703 @item -fno-inline
2704 @cindex in-line code
2705 @cindex compilation, in-line
2706 @c DL: Only relevant for -O3?
2707 Don't compile statement functions inline.
2708 Might reduce the size of a program unit---which might be at
2709 expense of some speed (though it should compile faster).
2710 Note that if you are not optimizing, no functions can be expanded inline.
2711
2712 @cindex -ffast-math option
2713 @cindex options, -ffast-math
2714 @item -ffast-math
2715 @cindex IEEE 754 conformance
2716 @cindex conformance, IEEE 754
2717 Might allow some programs designed to not be too dependent
2718 on IEEE behavior for floating-point to run faster, or die trying.
2719
2720 @cindex -fstrength-reduce option
2721 @cindex options, -fstrength-reduce
2722 @item -fstrength-reduce
2723 @cindex loops, speeding up
2724 @cindex speed, of loops
2725 @c DL: normally defaulted?
2726 Might make some loops run faster.
2727
2728 @cindex -frerun-cse-after-loop option
2729 @cindex options, -frerun-cse-after-loop
2730 @item -frerun-cse-after-loop
2731 @cindex -fexpensive-optimizations option
2732 @cindex options, -fexpensive-optimizations
2733 @c DL: This is -O2?
2734 @item -fexpensive-optimizations
2735 @cindex -fdelayed-branch option
2736 @cindex options, -fdelayed-branch
2737 @item -fdelayed-branch
2738 @cindex -fschedule-insns option
2739 @cindex options, -fschedule-insns
2740 @item -fschedule-insns
2741 @cindex -fschedule-insns2 option
2742 @cindex options, -fschedule-insns2
2743 @item -fschedule-insns2
2744 @cindex -fcaller-saves option
2745 @cindex options, -fcaller-saves
2746 @item -fcaller-saves
2747 Might improve performance on some code.
2748
2749 @cindex -funroll-loops option
2750 @cindex options, -funroll-loops
2751 @item -funroll-loops
2752 @cindex loops, unrolling
2753 @cindex unrolling loops
2754 @cindex loops, optimizing
2755 @cindex indexed (iterative) @code{DO}
2756 @cindex iterative @code{DO}
2757 @c DL: fixme: Craig doesn't like `indexed' but f95 doesn't seem to
2758 @c provide a suitable term
2759 @c CB: I've decided on `iterative', for the time being, and changed
2760 @c my previous, rather bizarre, use of `imperative' to that
2761 @c (though `precomputed-trip' would be a more precise adjective)
2762 Typically improves performance on code using iterative @code{DO} loops by
2763 unrolling them and is probably generally appropriate for Fortran, though
2764 it is not turned on at any optimization level.
2765 Note that outer loop unrolling isn't done specifically; decisions about
2766 whether to unroll a loop are made on the basis of its instruction count.
2767
2768 @c DL: Fixme: This should obviously go somewhere else...
2769 Also, no `loop discovery'@footnote{@dfn{loop discovery} refers to the
2770 process by which a compiler, or indeed any reader of a program,
2771 determines which portions of the program are more likely to be executed
2772 repeatedly as it is being run.  Such discovery typically is done early
2773 when compiling using optimization techniques, so the ``discovered''
2774 loops get more attention---and more run-time resources, such as
2775 registers---from the compiler.  It is easy to ``discover'' loops that are
2776 constructed out of looping constructs in the language
2777 (such as Fortran's @code{DO}).  For some programs, ``discovering'' loops
2778 constructed out of lower-level constructs (such as @code{IF} and
2779 @code{GOTO}) can lead to generation of more optimal code
2780 than otherwise.} is done, so only loops written with @code{DO}
2781 benefit from loop optimizations, including---but not limited
2782 to---unrolling.  Loops written with @code{IF} and @code{GOTO} are not
2783 currently recognized as such.  This option unrolls only iterative
2784 @code{DO} loops, not @code{DO WHILE} loops.
2785
2786 @cindex -funroll-all-loops option
2787 @cindex options, -funroll-all-loops
2788 @cindex DO WHILE
2789 @item -funroll-all-loops
2790 @c DL: Check my understanding of -funroll-all-loops v. -funroll-loops is correct.
2791 Probably improves performance on code using @code{DO WHILE} loops by
2792 unrolling them in addition to iterative @code{DO} loops.  In the absence
2793 of @code{DO WHILE}, this option is equivalent to @code{-funroll-loops}
2794 but possibly slower.
2795
2796 @item -fno-move-all-movables
2797 @cindex -fno-move-all-movables option
2798 @cindex options, -fno-move-all-movables
2799 @item -fno-reduce-all-givs
2800 @cindex -fno-reduce-all-givs option
2801 @cindex options, -fno-reduce-all-givs
2802 @item -fno-rerun-loop-opt
2803 @cindex -fno-rerun-loop-opt option
2804 @cindex options, -fno-rerun-loop-opt
2805 @emph{Version info:}
2806 These options are not supported by
2807 versions of @code{g77} based on @code{gcc} version 2.8.
2808
2809 Each of these might improve performance on some code.
2810
2811 Analysis of Fortran code optimization and the resulting
2812 optimizations triggered by the above options were
2813 contributed by Toon Moene (@email{toon@@moene.indiv.nluug.nl}).
2814
2815 These three options are intended to be removed someday, once
2816 they have helped determine the efficacy of various
2817 approaches to improving the performance of Fortran code.
2818
2819 Please let us know how use of these options affects
2820 the performance of your production code.
2821 We're particularly interested in code that runs faster
2822 when these options are @emph{disabled}, and in
2823 non-Fortran code that benefits when they are
2824 @emph{enabled} via the above @code{gcc} command-line options.
2825 @end table
2826
2827 @xref{Optimize Options,,Options That Control Optimization,
2828 gcc,Using and Porting GNU CC}, for more information on options
2829 to optimize the generated machine code.
2830
2831 @node Preprocessor Options
2832 @section Options Controlling the Preprocessor
2833 @cindex preprocessor options
2834 @cindex options, preprocessor
2835 @cindex cpp program
2836 @cindex programs, cpp
2837
2838 These options control the C preprocessor, which is run on each C source
2839 file before actual compilation.
2840
2841 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
2842 gcc,Using and Porting GNU CC}, for information on C preprocessor options.
2843
2844 @cindex INCLUDE directive
2845 @cindex directive, INCLUDE
2846 Some of these options also affect how @code{g77} processes the
2847 @code{INCLUDE} directive.
2848 Since this directive is processed even when preprocessing
2849 is not requested, it is not described in this section.
2850 @xref{Directory Options,,Options for Directory Search}, for
2851 information on how @code{g77} processes the @code{INCLUDE} directive.
2852
2853 However, the @code{INCLUDE} directive does not apply
2854 preprocessing to the contents of the included file itself.
2855
2856 Therefore, any file that contains preprocessor directives
2857 (such as @code{#include}, @code{#define}, and @code{#if})
2858 must be included via the @code{#include} directive, not
2859 via the @code{INCLUDE} directive.
2860 Therefore, any file containing preprocessor directives,
2861 if included, is necessarily included by a file that itself
2862 contains preprocessor directives.
2863
2864 @node Directory Options
2865 @section Options for Directory Search
2866 @cindex directory, options
2867 @cindex options, directory search
2868 @cindex search path
2869
2870 These options affect how the @code{cpp} preprocessor searches
2871 for files specified via the @code{#include} directive.
2872 Therefore, when compiling Fortran programs, they are meaningful
2873 when the preprocessor is used.
2874
2875 @cindex INCLUDE directive
2876 @cindex directive, INCLUDE
2877 Some of these options also affect how @code{g77} searches
2878 for files specified via the @code{INCLUDE} directive,
2879 although files included by that directive are not,
2880 themselves, preprocessed.
2881 These options are:
2882
2883 @table @code
2884 @cindex -I- option
2885 @cindex options, -I-
2886 @item -I-
2887 @cindex -Idir option
2888 @cindex options, -Idir
2889 @item -I@var{dir}
2890 @cindex directory, search paths for inclusion
2891 @cindex inclusion, directory search paths for
2892 @cindex search paths, for included files
2893 @cindex paths, search
2894 These affect interpretation of the @code{INCLUDE} directive
2895 (as well as of the @code{#include} directive of the @code{cpp}
2896 preprocessor).
2897
2898 Note that @samp{-I@var{dir}} must be specified @emph{without} any
2899 spaces between @samp{-I} and the directory name---that is,
2900 @samp{-Ifoo/bar} is valid, but @samp{-I foo/bar}
2901 is rejected by the @code{g77} compiler (though the preprocessor supports
2902 the latter form).
2903 @c this is due to toplev.c's inflexible option processing
2904 Also note that the general behavior of @samp{-I} and
2905 @code{INCLUDE} is pretty much the same as of @samp{-I} with
2906 @code{#include} in the @code{cpp} preprocessor, with regard to
2907 looking for @file{header.gcc} files and other such things.
2908
2909 @xref{Directory Options,,Options for Directory Search,
2910 gcc,Using and Porting GNU CC}, for information on the @samp{-I} option.
2911 @end table
2912
2913 @node Code Gen Options
2914 @section Options for Code Generation Conventions
2915 @cindex code generation, conventions
2916 @cindex options, code generation
2917 @cindex run-time, options
2918
2919 These machine-independent options control the interface conventions
2920 used in code generation.
2921
2922 Most of them have both positive and negative forms; the negative form
2923 of @samp{-ffoo} would be @samp{-fno-foo}.  In the table below, only
2924 one of the forms is listed---the one which is not the default.  You
2925 can figure out the other form by either removing @samp{no-} or adding
2926 it.
2927
2928 @table @code
2929 @cindex -fno-automatic option
2930 @cindex options, -fno-automatic
2931 @item -fno-automatic
2932 @cindex SAVE statement
2933 @cindex statements, SAVE
2934 Treat each program unit as if the @code{SAVE} statement was specified
2935 for every local variable and array referenced in it.
2936 Does not affect common blocks.
2937 (Some Fortran compilers provide this option under
2938 the name @samp{-static}.)
2939
2940 @cindex -finit-local-zero option
2941 @cindex options, -finit-local-zero
2942 @item -finit-local-zero
2943 @cindex DATA statement
2944 @cindex statements, DATA
2945 @cindex initialization, of local variables
2946 @cindex variables, initialization of
2947 @cindex uninitialized variables
2948 @cindex variables, uninitialized
2949 Specify that variables and arrays that are local to a program unit
2950 (not in a common block and not passed as an argument) are to be initialized
2951 to binary zeros.
2952
2953 Since there is a run-time penalty for initialization of variables
2954 that are not given the @code{SAVE} attribute, it might be a
2955 good idea to also use @samp{-fno-automatic} with @samp{-finit-local-zero}.
2956
2957 @cindex -fno-f2c option
2958 @cindex options, -fno-f2c
2959 @item -fno-f2c
2960 @cindex @code{f2c} compatibility
2961 @cindex compatibility, @code{f2c}
2962 Do not generate code designed to be compatible with code generated
2963 by @code{f2c}; use the GNU calling conventions instead.
2964
2965 The @code{f2c} calling conventions require functions that return
2966 type @code{REAL(KIND=1)} to actually return the C type @code{double},
2967 and functions that return type @code{COMPLEX} to return the
2968 values via an extra argument in the calling sequence that points
2969 to where to store the return value.
2970 Under the GNU calling conventions, such functions simply return
2971 their results as they would in GNU C---@code{REAL(KIND=1)} functions
2972 return the C type @code{float}, and @code{COMPLEX} functions
2973 return the GNU C type @code{complex} (or its @code{struct}
2974 equivalent).
2975
2976 This does not affect the generation of code that interfaces with the
2977 @code{libg2c} library.
2978
2979 However, because the @code{libg2c} library uses @code{f2c}
2980 calling conventions, @code{g77} rejects attempts to pass
2981 intrinsics implemented by routines in this library as actual
2982 arguments when @samp{-fno-f2c} is used, to avoid bugs when
2983 they are actually called by code expecting the GNU calling
2984 conventions to work.
2985
2986 For example, @samp{INTRINSIC ABS;CALL FOO(ABS)} is
2987 rejected when @samp{-fno-f2c} is in force.
2988 (Future versions of the @code{g77} run-time library might
2989 offer routines that provide GNU-callable versions of the
2990 routines that implement the @code{f2c}-callable intrinsics
2991 that may be passed as actual arguments, so that
2992 valid programs need not be rejected when @samp{-fno-f2c}
2993 is used.)
2994
2995 @strong{Caution:} If @samp{-fno-f2c} is used when compiling any
2996 source file used in a program, it must be used when compiling
2997 @emph{all} Fortran source files used in that program.
2998
2999 @c seems kinda dumb to tell people about an option they can't use -- jcb
3000 @c then again, we want users building future-compatible libraries with it.
3001 @cindex -ff2c-library option
3002 @cindex options, -ff2c-library
3003 @item -ff2c-library
3004 Specify that use of @code{libg2c} (or the original @code{libf2c})
3005 is required.
3006 This is the default for the current version of @code{g77}.
3007
3008 Currently it is not
3009 valid to specify @samp{-fno-f2c-library}.
3010 This option is provided so users can specify it in shell
3011 scripts that build programs and libraries that require the
3012 @code{libf2c} library, even when being compiled by future
3013 versions of @code{g77} that might otherwise default to
3014 generating code for an incompatible library.
3015
3016 @cindex -fno-underscoring option
3017 @cindex options, -fno-underscoring
3018 @item -fno-underscoring
3019 @cindex underscore
3020 @cindex symbol names, underscores
3021 @cindex transforming symbol names
3022 @cindex symbol names, transforming
3023 Do not transform names of entities specified in the Fortran
3024 source file by appending underscores to them.
3025
3026 With @samp{-funderscoring} in effect, @code{g77} appends two underscores
3027 to names with underscores and one underscore to external names with
3028 no underscores.  (@code{g77} also appends two underscores to internal
3029 names with underscores to avoid naming collisions with external names.
3030 The @samp{-fno-second-underscore} option disables appending of the
3031 second underscore in all cases.)
3032
3033 This is done to ensure compatibility with code produced by many
3034 UNIX Fortran compilers, including @code{f2c}, which perform the
3035 same transformations.
3036
3037 Use of @samp{-fno-underscoring} is not recommended unless you are
3038 experimenting with issues such as integration of (GNU) Fortran into
3039 existing system environments (vis-a-vis existing libraries, tools, and
3040 so on).
3041
3042 For example, with @samp{-funderscoring}, and assuming other defaults like
3043 @samp{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
3044 external functions while @samp{my_var} and @samp{lvar} are local variables,
3045 a statement like
3046
3047 @smallexample
3048 I = J() + MAX_COUNT (MY_VAR, LVAR)
3049 @end smallexample
3050
3051 @noindent
3052 is implemented as something akin to:
3053
3054 @smallexample
3055 i = j_() + max_count__(&my_var__, &lvar);
3056 @end smallexample
3057
3058 With @samp{-fno-underscoring}, the same statement is implemented as:
3059
3060 @smallexample
3061 i = j() + max_count(&my_var, &lvar);
3062 @end smallexample
3063
3064 Use of @samp{-fno-underscoring} allows direct specification of
3065 user-defined names while debugging and when interfacing @code{g77}-compiled
3066 code with other languages.
3067
3068 Note that just because the names match does @emph{not} mean that the
3069 interface implemented by @code{g77} for an external name matches the
3070 interface implemented by some other language for that same name.
3071 That is, getting code produced by @code{g77} to link to code produced
3072 by some other compiler using this or any other method can be only a
3073 small part of the overall solution---getting the code generated by
3074 both compilers to agree on issues other than naming can require
3075 significant effort, and, unlike naming disagreements, linkers normally
3076 cannot detect disagreements in these other areas.
3077
3078 Also, note that with @samp{-fno-underscoring}, the lack of appended
3079 underscores introduces the very real possibility that a user-defined
3080 external name will conflict with a name in a system library, which
3081 could make finding unresolved-reference bugs quite difficult in some
3082 cases---they might occur at program run time, and show up only as
3083 buggy behavior at run time.
3084
3085 In future versions of @code{g77}, we hope to improve naming and linking
3086 issues so that debugging always involves using the names as they appear
3087 in the source, even if the names as seen by the linker are mangled to
3088 prevent accidental linking between procedures with incompatible
3089 interfaces.
3090
3091 @cindex -fno-second-underscore option
3092 @cindex options, -fno-second-underscore
3093 @item -fno-second-underscore
3094 @cindex underscore
3095 @cindex symbol names, underscores
3096 @cindex transforming symbol names
3097 @cindex symbol names, transforming
3098 Do not append a second underscore to names of entities specified
3099 in the Fortran source file.
3100
3101 This option has no effect if @samp{-fno-underscoring} is
3102 in effect.
3103
3104 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
3105 is implemented as a reference to the link-time external symbol
3106 @samp{max_count_}, instead of @samp{max_count__}.
3107
3108 @cindex -fno-ident option
3109 @cindex options, -fno-ident
3110 @item -fno-ident
3111 Ignore the @samp{#ident} directive.
3112
3113 @cindex -fzeros option
3114 @cindex options, -fzeros
3115 @item -fzeros
3116 Treat initial values of zero as if they were any other value.
3117
3118 As of version 0.5.18, @code{g77} normally treats @code{DATA} and
3119 other statements that are used to specify initial values of zero
3120 for variables and arrays as if no values were actually specified,
3121 in the sense that no diagnostics regarding multiple initializations
3122 are produced.
3123
3124 This is done to speed up compiling of programs that initialize
3125 large arrays to zeros.
3126
3127 Use @samp{-fzeros} to revert to the simpler, slower behavior
3128 that can catch multiple initializations by keeping track of
3129 all initializations, zero or otherwise.
3130
3131 @emph{Caution:} Future versions of @code{g77} might disregard this option
3132 (and its negative form, the default) or interpret it somewhat
3133 differently.
3134 The interpretation changes will affect only non-standard
3135 programs; standard-conforming programs should not be affected.
3136
3137 @cindex -fdebug-kludge option
3138 @cindex options, -fdebug-kludge
3139 @item -fdebug-kludge
3140 Emit information on @code{COMMON} and @code{EQUIVALENCE} members
3141 that might help users of debuggers work around lack of proper debugging
3142 information on such members.
3143
3144 As of version 0.5.19, @code{g77} offers this option to emit
3145 information on members of aggregate areas to help users while debugging.
3146 This information consists of establishing the type and contents of each
3147 such member so that, when a debugger is asked to print the contents,
3148 the printed information provides rudimentary debugging information.
3149 This information identifies the name of the aggregate area (either the
3150 @code{COMMON} block name, or the @code{g77}-assigned name for the
3151 @code{EQUIVALENCE} name) and the offset, in bytes, of the member from
3152 the beginning of the area.
3153
3154 Using @code{gdb}, this information is not coherently displayed in the Fortran
3155 language mode, so temporarily switching to the C language mode to display the
3156 information is suggested.
3157 Use @samp{set language c} and @samp{set language fortran} to accomplish this.
3158
3159 For example:
3160
3161 @smallexample
3162       COMMON /X/A,B
3163       EQUIVALENCE (C,D)
3164       CHARACTER XX*50
3165       EQUIVALENCE (I,XX(20:20))
3166       END
3167
3168 GDB is free software and you are welcome to distribute copies of it
3169  under certain conditions; type "show copying" to see the conditions.
3170 There is absolutely no warranty for GDB; type "show warranty" for details.
3171 GDB 4.16 (lm-gnits-dwim), Copyright 1996 Free Software Foundation, Inc...
3172 (gdb) b MAIN__
3173 Breakpoint 1 at 0t1200000201120112: file cd.f, line 5.
3174 (gdb) r
3175 Starting program: /home/user/a.out
3176
3177 Breakpoint 1, MAIN__ () at cd.f:5
3178 Current language:  auto; currently fortran
3179 (gdb) set language c
3180 Warning: the current language does not match this frame.
3181 (gdb) p a
3182 $2 = "At (COMMON) `x_' plus 0 bytes"
3183 (gdb) p b
3184 $3 = "At (COMMON) `x_' plus 4 bytes"
3185 (gdb) p c
3186 $4 = "At (EQUIVALENCE) `__g77_equiv_c' plus 0 bytes"
3187 (gdb) p d
3188 $5 = "At (EQUIVALENCE) `__g77_equiv_c' plus 0 bytes"
3189 (gdb) p i
3190 $6 = "At (EQUIVALENCE) `__g77_equiv_xx' plus 20 bytes"
3191 (gdb) p xx
3192 $7 = "At (EQUIVALENCE) `__g77_equiv_xx' plus 1 bytes"
3193 (gdb) set language fortran
3194 (gdb)
3195 @end smallexample
3196
3197 @noindent
3198 Use @samp{-fdebug-kludge} to generate this information,
3199 which might make some programs noticeably larger.
3200
3201 @emph{Caution:} Future versions of @code{g77} might disregard this option
3202 (and its negative form).
3203 Current plans call for this to happen when published versions of @code{g77}
3204 and @code{gdb} exist that provide proper access to debugging information on
3205 @code{COMMON} and @code{EQUIVALENCE} members.
3206
3207 @cindex -fno-emulate-complex option
3208 @cindex options, -fno-emulate-complex
3209 @item -fno-emulate-complex
3210 Implement @code{COMPLEX} arithmetic using the facilities in
3211 the @code{gcc} back end that provide direct support of
3212 @code{complex} arithmetic, instead of emulating the arithmetic.
3213
3214 @code{gcc} has some known problems in its back-end support
3215 for @code{complex} arithmetic, due primarily to the support not being
3216 completed as of version 2.7.2.2.
3217 Other front ends for the @code{gcc} back end avoid this problem
3218 by emulating @code{complex} arithmetic at a higher level, so the
3219 back end sees arithmetic on the real and imaginary components.
3220 To make @code{g77} more portable to systems where @code{complex}
3221 support in the @code{gcc} back end is particularly troublesome,
3222 @code{g77} now defaults to performing the same kinds of emulations
3223 done by these other front ends.
3224
3225 Use @samp{-fno-emulate-complex} to try the @code{complex} support
3226 in the @code{gcc} back end, in case it works and produces faster
3227 programs.
3228 So far, all the known bugs seem to involve compile-time crashes,
3229 rather than the generation of incorrect code.
3230
3231 Use of this option should not affect how Fortran code compiled
3232 by @code{g77} works in terms of its interfaces to other code,
3233 e.g. that compiled by @code{f2c}.
3234
3235 @emph{Caution:} Future versions of @code{g77} are likely to change
3236 the default for this option to
3237 @samp{-fno-emulate-complex}, and perhaps someday ignore both forms
3238 of this option.
3239
3240 Also, it is possible that use of the @samp{-fno-emulate-complex} option
3241 could result in incorrect code being silently produced by @code{g77}.
3242 But, this is generally true of compilers anyway, so, as usual, test
3243 the programs you compile before assuming they are working.
3244
3245 @cindex -falias-check option
3246 @cindex options, -falias-check
3247 @cindex -fargument-alias option
3248 @cindex options, -fargument-alias
3249 @cindex -fargument-noalias option
3250 @cindex options, -fargument-noalias
3251 @cindex -fno-argument-noalias-global option
3252 @cindex options, -fno-argument-noalias-global
3253 @item -falias-check
3254 @item -fargument-alias
3255 @item -fargument-noalias
3256 @item -fno-argument-noalias-global
3257 @emph{Version info:}
3258 These options are not supported by
3259 versions of @code{g77} based on @code{gcc} version 2.8.
3260
3261 These options specify to what degree aliasing
3262 (overlap)
3263 is permitted between
3264 arguments (passed as pointers) and @code{COMMON} (external, or
3265 public) storage.
3266
3267 The default for Fortran code, as mandated by the FORTRAN 77 and
3268 Fortran 90 standards, is @samp{-fargument-noalias-global}.
3269 The default for code written in the C language family is
3270 @samp{-fargument-alias}.
3271
3272 Note that, on some systems, compiling with @samp{-fforce-addr} in
3273 effect can produce more optimal code when the default aliasing
3274 options are in effect (and when optimization is enabled).
3275
3276 @xref{Aliasing Assumed To Work}, for detailed information on the implications
3277 of compiling Fortran code that depends on the ability to alias dummy
3278 arguments.
3279
3280 @cindex -fno-globals option
3281 @cindex options, -fno-globals
3282 @item -fno-globals
3283 @cindex global names, warning
3284 @cindex warnings, global names
3285 @cindex in-line code
3286 @cindex compilation, in-line
3287 Disable diagnostics about inter-procedural
3288 analysis problems, such as disagreements about the
3289 type of a function or a procedure's argument,
3290 that might cause a compiler crash when attempting
3291 to inline a reference to a procedure within a
3292 program unit.
3293 (The diagnostics themselves are still produced, but
3294 as warnings, unless @samp{-Wno-globals} is specified,
3295 in which case no relevant diagnostics are produced.)
3296
3297 Further, this option disables such inlining, to
3298 avoid compiler crashes resulting from incorrect
3299 code that would otherwise be diagnosed.
3300
3301 As such, this option might be quite useful when
3302 compiling existing, ``working'' code that happens
3303 to have a few bugs that do not generally show themselves,
3304 but which @code{g77} diagnoses.
3305
3306 Use of this option therefore has the effect of
3307 instructing @code{g77} to behave more like it did
3308 up through version 0.5.19.1, when it paid little or
3309 no attention to disagreements between program units
3310 about a procedure's type and argument information,
3311 and when it performed no inlining of procedures
3312 (except statement functions).
3313
3314 Without this option, @code{g77} defaults to performing
3315 the potentially inlining procedures as it started doing
3316 in version 0.5.20, but as of version 0.5.21, it also
3317 diagnoses disagreements that might cause such inlining
3318 to crash the compiler as (fatal) errors,
3319 and warns about similar disagreements
3320 that are currently believed to not
3321 likely to result in the compiler later crashing
3322 or producing incorrect code.
3323 @end table
3324
3325 @xref{Code Gen Options,,Options for Code Generation Conventions,
3326 gcc,Using and Porting GNU CC}, for information on more options
3327 offered by the GBE
3328 shared by @code{g77}, @code{gcc}, and other GNU compilers.
3329
3330 Some of these do @emph{not} work when compiling programs written in Fortran:
3331
3332 @table @code
3333 @cindex -fpcc-struct-return option
3334 @cindex options, -fpcc-struct-return
3335 @item -fpcc-struct-return
3336 @cindex -freg-struct-return option
3337 @cindex options, -freg-struct-return
3338 @item -freg-struct-return
3339 You should not use these except strictly the same way as you
3340 used them to build the version of @code{libg2c} with which
3341 you will be linking all code compiled by @code{g77} with the
3342 same option.
3343
3344 @cindex -fshort-double option
3345 @cindex options, -fshort-double
3346 @item -fshort-double
3347 This probably either has no effect on Fortran programs, or
3348 makes them act loopy.
3349
3350 @cindex -fno-common option
3351 @cindex options, -fno-common
3352 @item -fno-common
3353 Do not use this when compiling Fortran programs,
3354 or there will be Trouble.
3355
3356 @cindex -fpack-struct option
3357 @cindex options, -fpack-struct
3358 @item -fpack-struct
3359 This probably will break any calls to the @code{libg2c} library,
3360 at the very least, even if it is built with the same option.
3361 @end table
3362
3363 @node Environment Variables
3364 @section Environment Variables Affecting GNU Fortran
3365 @cindex environment variables
3366
3367 GNU Fortran currently does not make use of any environment
3368 variables to control its operation above and beyond those
3369 that affect the operation of @code{gcc}.
3370
3371 @xref{Environment Variables,,Environment Variables Affecting GNU CC,
3372 gcc,Using and Porting GNU CC}, for information on environment
3373 variables.
3374
3375 @include news.texi
3376
3377 @node Changes
3378 @chapter User-visible Changes
3379 @cindex versions, recent
3380 @cindex recent versions
3381 @cindex changes, user-visible
3382 @cindex user-visible changes
3383
3384 This section describes changes to @code{g77} that are visible
3385 to the programmers who actually write and maintain Fortran
3386 code they compile with @code{g77}.
3387 Information on changes to installation procedures,
3388 changes to the documentation, and bug fixes is
3389 not provided here, unless it is likely to affect how
3390 users use @code{g77}.
3391 @xref{News,,News About GNU Fortran}, for information on
3392 such changes to @code{g77}.
3393
3394 To find out about existing bugs and ongoing plans for GNU
3395 Fortran, retrieve @uref{ftp://alpha.gnu.org/g77.plan}
3396 or, if you cannot do that, email
3397 @email{fortran@@gnu.org} asking for a recent copy of the
3398 GNU Fortran @file{.plan} file.
3399
3400 @heading In @code{egcs 1.2}:
3401 @itemize @bullet
3402 @item
3403 Source file names with the suffixes @samp{.FOR} and @samp{.FPP}
3404 now are recognized by @code{g77}
3405 as if they ended in @samp{.for} and @samp{.fpp}, respectively.
3406 @end itemize
3407
3408 @heading In @code{egcs} 1.1 (versus 0.5.24):
3409 @itemize @bullet
3410 @cindex alignment
3411 @cindex double-precision performance
3412 @cindex -malign-double
3413 @item
3414 Align static double-precision variables and arrays
3415 on Intel x86 targets
3416 regardless of whether @samp{-malign-double} is specified.
3417
3418 Generally, this affects only local variables and arrays
3419 having the @code{SAVE} attribute
3420 or given initial values via @code{DATA}.
3421 @end itemize
3422
3423 @heading In @code{egcs} 1.1 (versus @code{egcs} 1.0.3):
3424 @itemize @bullet
3425 @item
3426 Support @samp{FORMAT(I<@var{expr}>)} when @var{expr} is a
3427 compile-time constant @code{INTEGER} expression.
3428
3429 @item
3430 Fix @code{g77} @samp{-g} option so procedures that
3431 use @samp{ENTRY} can be stepped through, line by line,
3432 in @code{gdb}.
3433
3434 @item
3435 Allow any @code{REAL} argument to intrinsics
3436 @code{Second} and @code{CPU_Time}.
3437
3438 @item
3439 Use @code{tempnam}, if available, to open scratch files
3440 (as in @samp{OPEN(STATUS='SCRATCH')})
3441 so that the @code{TMPDIR} environment variable,
3442 if present, is used.
3443
3444 @item
3445 @code{g77}'s version of @code{libf2c} separates out
3446 the setting of global state
3447 (such as command-line arguments and signal handling)
3448 from @file{main.o} into distinct, new library
3449 archive members.
3450
3451 This should make it easier to write portable applications
3452 that have their own (non-Fortran) @code{main()} routine
3453 properly set up the @code{libf2c} environment, even
3454 when @code{libf2c} (now @code{libg2c}) is a shared library.
3455
3456 @item
3457 The @code{g77} command now expects the run-time library
3458 to be named @code{libg2c.a} instead of @code{libf2c.a},
3459 to ensure that a version other than the one built and
3460 installed as part of the same @code{g77} version is picked up.
3461
3462 @item
3463 Some diagnostics have been changed from warnings to errors,
3464 to prevent inadvertent use of the resulting, probably buggy,
3465 programs.
3466 These mostly include diagnostics about use of unsupported features
3467 in the @code{OPEN}, @code{INQUIRE}, @code{READ}, and
3468 @code{WRITE} statements,
3469 and about truncations of various sorts of constants.
3470 @end itemize
3471
3472 @heading In 0.5.24 and @code{egcs} 1.1 (versus 0.5.23):
3473 @itemize @bullet
3474 @item
3475 @code{g77} now treats @samp{%LOC(@var{expr})} and
3476 @samp{LOC(@var{expr})} as ``ordinary'' expressions
3477 when they are used as arguments in procedure calls.
3478 This change applies only to global (filewide) analysis,
3479 making it consistent with
3480 how @code{g77} actually generates code
3481 for these cases.
3482
3483 Previously, @code{g77} treated these expressions
3484 as denoting special ``pointer'' arguments
3485 for the purposes of filewide analysis.
3486
3487 @item
3488 The @code{g77} driver now ensures that @samp{-lg2c}
3489 is specified in the link phase prior to any
3490 occurrence of @samp{-lm}.
3491 This prevents accidentally linking to a routine
3492 in the SunOS4 @samp{-lm} library
3493 when the generated code wants to link to the one
3494 in @code{libf2c} (@code{libg2c}).
3495
3496 @item
3497 @code{g77} emits more debugging information when
3498 @samp{-g} is used.
3499
3500 This new information allows, for example,
3501 @kbd{which __g77_length_a} to be used in @code{gdb}
3502 to determine the type of the phantom length argument
3503 supplied with @samp{CHARACTER} variables.
3504
3505 This information pertains to internally-generated
3506 type, variable, and other information,
3507 not to the longstanding deficiencies vis-a-vis
3508 @samp{COMMON} and @samp{EQUIVALENCE}.
3509
3510 @item
3511 The F90 @samp{Date_and_Time} intrinsic now is
3512 supported.
3513
3514 @item
3515 The F90 @samp{System_Clock} intrinsic allows
3516 the optional arguments (except for the @samp{Count}
3517 argument) to be omitted.
3518 @end itemize
3519
3520 @heading In 0.5.23:
3521 @itemize @bullet
3522 @item
3523 This release contains several regressions against
3524 version 0.5.22 of @code{g77}, due to using the
3525 ``vanilla'' @code{gcc} back end instead of patching
3526 it to fix a few bugs and improve performance in a
3527 few cases.
3528
3529 @xref{Actual Bugs,,Actual Bugs We Haven't Fixed Yet},
3530 available in plain-text format in @code{gcc/f/BUGS},
3531 for information on the known bugs in this version,
3532 including the regressions.
3533
3534 Features that have been dropped from this version
3535 of @code{g77} due to their being implemented
3536 via @code{g77}-specific patches to the @code{gcc}
3537 back end in previous releases include:
3538
3539 @itemize --
3540 @item
3541 Support for @code{__restrict__} keyword,
3542 the options @samp{-fargument-alias}, @samp{-fargument-noalias},
3543 and @samp{-fargument-noalias-global},
3544 and the corresponding alias-analysis code.
3545
3546 (@code{egcs} has the alias-analysis
3547 code, but not the @code{__restrict__} keyword.
3548 @code{egcs} @code{g77} users benefit from the alias-analysis
3549 code despite the lack of the @code{__restrict__} keyword,
3550 which is a C-language construct.)
3551
3552 @item
3553 Support for the GNU compiler options
3554 @samp{-fmove-all-movables},
3555 @samp{-freduce-all-givs},
3556 and @samp{-frerun-loop-opt}.
3557
3558 (@code{egcs} supports these options.
3559 @code{g77} users of @code{egcs} benefit from them even if
3560 they are not explicitly specified,
3561 because the defaults are optimized for @code{g77} users.)
3562
3563 @item
3564 Support for the @samp{-W} option warning about
3565 integer division by zero.
3566
3567 @item
3568 The Intel x86-specific option @samp{-malign-double}
3569 applying to stack-allocated data
3570 as well as statically-allocate data.
3571 @end itemize
3572
3573 @item
3574 Support @code{gcc} version 2.8,
3575 and remove support for prior versions of @code{gcc}.
3576
3577 @cindex -@w{}-driver option
3578 @cindex @code{g77} options, -@w{}-driver
3579 @cindex options, -@w{}-driver
3580 @item
3581 Remove support for the @samp{--driver} option,
3582 as @code{g77} now does all the driving,
3583 just like @code{gcc}.
3584
3585 @item
3586 The @code{g77} command now expects the run-time library
3587 to be named @code{libg2c.a} instead of @code{libf2c.a},
3588 to ensure that a version other than the one built and
3589 installed as part of the same @code{g77} version is picked up.
3590
3591 @item
3592 @code{g77}'s version of @code{libf2c} separates out
3593 the setting of global state
3594 (such as command-line arguments and signal handling)
3595 from @file{main.o} into distinct, new library
3596 archive members.
3597
3598 This should make it easier to write portable applications
3599 that have their own (non-Fortran) @code{main()} routine
3600 properly set up the @code{libf2c} environment, even
3601 when @code{libf2c} (now @code{libg2c}) is a shared library.
3602
3603 @item
3604 Some diagnostics have been changed from warnings to errors,
3605 to prevent inadvertent use of the resulting, probably buggy,
3606 programs.
3607 These mostly include diagnostics about use of unsupported features
3608 in the @code{OPEN}, @code{INQUIRE}, @code{READ}, and
3609 @code{WRITE} statements,
3610 and about truncations of various sorts of constants.
3611 @end itemize
3612
3613 @heading In 0.5.22:
3614 @itemize @bullet
3615 @item
3616 Fix @code{Signal} intrinsic so it offers portable
3617 support for 64-bit systems (such as Digital Alphas
3618 running GNU/Linux).
3619
3620 @item
3621 Support @samp{FORMAT(I<@var{expr}>)} when @var{expr} is a
3622 compile-time constant @code{INTEGER} expression.
3623
3624 @item
3625 Fix @code{g77} @samp{-g} option so procedures that
3626 use @samp{ENTRY} can be stepped through, line by line,
3627 in @code{gdb}.
3628
3629 @item
3630 Allow any @code{REAL} argument to intrinsics
3631 @code{Second} and @code{CPU_Time}.
3632
3633 @item
3634 Allow any numeric argument to intrinsics
3635 @code{Int2} and @code{Int8}.
3636
3637 @item
3638 Use @code{tempnam}, if available, to open scratch files
3639 (as in @samp{OPEN(STATUS='SCRATCH')})
3640 so that the @code{TMPDIR} environment variable,
3641 if present, is used.
3642
3643 @item
3644 Rename the @code{gcc} keyword @code{restrict} to
3645 @code{__restrict__}, to avoid rejecting valid, existing,
3646 C programs.
3647 Support for @code{restrict} is now more like support
3648 for @code{complex}.
3649
3650 @item
3651 Fix @samp{-fugly-comma} to affect invocations of
3652 only external procedures.
3653 Restore rejection of gratuitous trailing omitted
3654 arguments to intrinsics, as in @samp{I=MAX(3,4,,)}.
3655
3656 @item
3657 Fix compiler so it accepts @samp{-fgnu-intrinsics-*} and
3658 @samp{-fbadu77-intrinsics-*} options.
3659 @end itemize
3660
3661 @heading In @code{egcs} 1.0.2 (versus @code{egcs} 1.0.1):
3662 @itemize @bullet
3663 @item
3664 Fix compiler so it accepts @samp{-fgnu-intrinsics-*} and
3665 @samp{-fbadu77-intrinsics-*} options.
3666 @end itemize
3667
3668 @heading In @code{egcs} 1.0 (versus 0.5.21):
3669 @itemize @bullet
3670 @item
3671 Version 1.0 of @code{egcs}
3672 contains several regressions against
3673 version 0.5.21 of @code{g77},
3674 due to using the
3675 ``vanilla'' @code{gcc} back end instead of patching
3676 it to fix a few bugs and improve performance in a
3677 few cases.
3678
3679 @xref{Actual Bugs,,Actual Bugs We Haven't Fixed Yet},
3680 available in plain-text format in @code{gcc/f/BUGS},
3681 for information on the known bugs in this version,
3682 including the regressions.
3683
3684 Features that have been dropped from this version
3685 of @code{g77} due to their being implemented
3686 via @code{g77}-specific patches to the @code{gcc}
3687 back end in previous releases include:
3688
3689 @itemize --
3690 @item
3691 Support for the C-language @code{restrict} keyword.
3692
3693 @item
3694 Support for the @samp{-W} option warning about
3695 integer division by zero.
3696
3697 @item
3698 The Intel x86-specific option @samp{-malign-double}
3699 applying to stack-allocated data
3700 as well as statically-allocate data.
3701 @end itemize
3702
3703 @cindex -@w{}-driver option
3704 @cindex @code{g77} options, -@w{}-driver
3705 @cindex options, -@w{}-driver
3706 @item
3707 Remove support for the @samp{--driver} option,
3708 as @code{g77} now does all the driving,
3709 just like @code{gcc}.
3710
3711 @item
3712 Allow any numeric argument to intrinsics
3713 @code{Int2} and @code{Int8}.
3714 @end itemize
3715
3716 @heading In 0.5.21:
3717 @itemize @bullet
3718 @item
3719 When the @samp{-W} option is specified, @code{gcc}, @code{g77},
3720 and other GNU compilers that incorporate the @code{gcc}
3721 back end as modified by @code{g77}, issue
3722 a warning about integer division by constant zero.
3723
3724 @item
3725 New option @samp{-Wno-globals} disables warnings
3726 about ``suspicious'' use of a name both as a global
3727 name and as the implicit name of an intrinsic, and
3728 warnings about disagreements over the number or natures of
3729 arguments passed to global procedures, or the
3730 natures of the procedures themselves.
3731
3732 The default is to issue such warnings, which are
3733 new as of this version of @code{g77}.
3734
3735 @item
3736 New option @samp{-fno-globals} disables diagnostics
3737 about potentially fatal disagreements
3738 analysis problems, such as disagreements over the
3739 number or natures of arguments passed to global
3740 procedures, or the natures of those procedures themselves.
3741
3742 The default is to issue such diagnostics and flag
3743 the compilation as unsuccessful.
3744 With this option, the diagnostics are issued as
3745 warnings, or, if @samp{-Wno-globals} is specified,
3746 are not issued at all.
3747
3748 This option also disables inlining of global procedures,
3749 to avoid compiler crashes resulting from coding errors
3750 that these diagnostics normally would identify.
3751
3752 @item
3753 Fix @code{libU77} routines that accept file and other names
3754 to strip trailing blanks from them, for consistency
3755 with other implementations.
3756 Blanks may be forcibly appended to such names by
3757 appending a single null character (@samp{CHAR(0)})
3758 to the significant trailing blanks.
3759
3760 @item
3761 Fix @code{CHMOD} intrinsic to work with file names
3762 that have embedded blanks, commas, and so on.
3763
3764 @item
3765 Fix @code{SIGNAL} intrinsic so it accepts an
3766 optional third @samp{Status} argument.
3767
3768 @item
3769 Make many changes to @code{libU77} intrinsics to
3770 support existing code more directly.
3771
3772 Such changes include allowing both subroutine and
3773 function forms of many routines, changing @code{MCLOCK()}
3774 and @code{TIME()} to return @code{INTEGER(KIND=1)} values,
3775 introducing @code{MCLOCK8()} and @code{TIME8()} to
3776 return @code{INTEGER(KIND=2)} values,
3777 and placing functions that are intended to perform
3778 side effects in a new intrinsic group, @code{badu77}.
3779
3780 @item
3781 Add options @samp{-fbadu77-intrinsics-delete},
3782 @samp{-fbadu77-intrinsics-hide}, and so on.
3783
3784 @item
3785 Add @code{INT2} and @code{INT8} intrinsics.
3786
3787 @item
3788 Add @code{CPU_TIME} intrinsic.
3789
3790 @item
3791 Add @code{ALARM} intrinsic.
3792
3793 @item
3794 @code{CTIME} intrinsic now accepts any @code{INTEGER}
3795 argument, not just @code{INTEGER(KIND=2)}.
3796
3797 @item
3798 @code{g77} driver now prints version information (such as produced
3799 by @kbd{g77 -v}) to @code{stderr} instead of @code{stdout}.
3800
3801 @item
3802 The @samp{.r} suffix now designates a Ratfor source file,
3803 to be preprocessed via the @code{ratfor} command, available
3804 separately.
3805 @end itemize
3806
3807 @heading In 0.5.20:
3808 @itemize @bullet
3809 @item
3810 The @samp{-fno-typeless-boz} option is now the default.
3811
3812 This option specifies that non-decimal-radix
3813 constants using the prefixed-radix form (such as @samp{Z'1234'})
3814 are to be interpreted as @code{INTEGER(KIND=1)} constants.
3815 Specify @samp{-ftypeless-boz} to cause such
3816 constants to be interpreted as typeless.
3817
3818 (Version 0.5.19 introduced @samp{-fno-typeless-boz} and
3819 its inverse.)
3820
3821 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
3822 for information on the @samp{-ftypeless-boz} option.
3823
3824 @item
3825 Options @samp{-ff90-intrinsics-enable} and
3826 @samp{-fvxt-intrinsics-enable} now are the
3827 defaults.
3828
3829 Some programs might use names that clash with
3830 intrinsic names defined (and now enabled) by these
3831 options or by the new @code{libU77} intrinsics.
3832 Users of such programs might need to compile them
3833 differently (using, for example, @samp{-ff90-intrinsics-disable})
3834 or, better yet, insert appropriate @code{EXTERNAL}
3835 statements specifying that these names are not intended
3836 to be names of intrinsics.
3837
3838 @item
3839 The @samp{ALWAYS_FLUSH} macro is no longer defined when
3840 building @code{libf2c}, which should result in improved
3841 I/O performance, especially over NFS.
3842
3843 @emph{Note:} If you have code that depends on the behavior
3844 of @code{libf2c} when built with @samp{ALWAYS_FLUSH} defined,
3845 you will have to modify @code{libf2c} accordingly before
3846 building it from this and future versions of @code{g77}.
3847
3848 @xref{Output Assumed To Flush}, for more information.
3849
3850 @item
3851 Dave Love's implementation of @code{libU77} has been
3852 added to the version of @code{libf2c} distributed with
3853 and built as part of @code{g77}.
3854 @code{g77} now knows about the routines in this library
3855 as intrinsics.
3856
3857 @item
3858 New option @samp{-fvxt} specifies that the
3859 source file is written in VXT Fortran, instead of GNU Fortran.
3860
3861 @xref{VXT Fortran}, for more information on the constructs
3862 recognized when the @samp{-fvxt} option is specified.
3863
3864 @item
3865 The @samp{-fvxt-not-f90} option has been deleted,
3866 along with its inverse, @samp{-ff90-not-vxt}.
3867
3868 If you used one of these deleted options, you should
3869 re-read the pertinent documentation to determine which
3870 options, if any, are appropriate for compiling your
3871 code with this version of @code{g77}.
3872
3873 @xref{Other Dialects}, for more information.
3874
3875 @item
3876 The @samp{-fugly} option now issues a warning, as it
3877 likely will be removed in a future version.
3878
3879 (Enabling all the @samp{-fugly-*} options is unlikely
3880 to be feasible, or sensible, in the future,
3881 so users should learn to specify only those
3882 @samp{-fugly-*} options they really need for a
3883 particular source file.)
3884
3885 @item
3886 The @samp{-fugly-assumed} option, introduced in
3887 version 0.5.19, has been changed to
3888 better accommodate old and new code.
3889 @xref{Ugly Assumed-Size Arrays}, for more information.
3890
3891 @item
3892 Related to supporting Alpha (AXP) machines, the @code{LOC()}
3893 intrinsic and @code{%LOC()} construct now return
3894 values of @code{INTEGER(KIND=0)} type,
3895 as defined by the GNU Fortran language.
3896
3897 This type is wide enough
3898 (holds the same number of bits)
3899 as the character-pointer type on the machine.
3900
3901 On most machines, this won't make a difference,
3902 whereas, on Alphas and other systems with 64-bit pointers,
3903 the @code{INTEGER(KIND=0)} type is equivalent to @code{INTEGER(KIND=2)}
3904 (often referred to as @code{INTEGER*8})
3905 instead of the more common @code{INTEGER(KIND=1)}
3906 (often referred to as @code{INTEGER*4}).
3907
3908 @item
3909 Emulate @code{COMPLEX} arithmetic in the @code{g77} front
3910 end, to avoid bugs in @code{complex} support in the
3911 @code{gcc} back end.
3912 New option @samp{-fno-emulate-complex}
3913 causes @code{g77} to revert the 0.5.19 behavior.
3914
3915 @item
3916 Dummy arguments are no longer assumed to potentially alias
3917 (overlap)
3918 other dummy arguments or @code{COMMON} areas when any of
3919 these are defined (assigned to) by Fortran code.
3920
3921 This can result in faster and/or smaller programs when
3922 compiling with optimization enabled, though on some
3923 systems this effect is observed only when @samp{-fforce-addr}
3924 also is specified.
3925
3926 New options @samp{-falias-check}, @samp{-fargument-alias},
3927 @samp{-fargument-noalias},
3928 and @samp{-fno-argument-noalias-global} control the
3929 way @code{g77} handles potential aliasing.
3930
3931 @xref{Aliasing Assumed To Work}, for detailed information on why the
3932 new defaults might result in some programs no longer working the way they
3933 did when compiled by previous versions of @code{g77}.
3934
3935 @item
3936 New option @samp{-fugly-assign} specifies that the
3937 same memory locations are to be used to hold the
3938 values assigned by both statements @samp{I = 3} and
3939 @samp{ASSIGN 10 TO I}, for example.
3940 (Normally, @code{g77} uses a separate memory location
3941 to hold assigned statement labels.)
3942
3943 @xref{Ugly Assigned Labels}, for more information.
3944
3945 @item
3946 @code{FORMAT} and @code{ENTRY} statements now are allowed to
3947 precede @code{IMPLICIT NONE} statements.
3948
3949 @item
3950 Enable full support of @code{INTEGER(KIND=2)}
3951 (often referred to as @code{INTEGER*8})
3952 available in
3953 @code{libf2c} and @file{f2c.h} so that @code{f2c} users
3954 may make full use of its features via the @code{g77}
3955 version of @file{f2c.h} and the @code{INTEGER(KIND=2)}
3956 support routines in the @code{g77} version of @code{libf2c}.
3957
3958 @item
3959 Improve @code{g77} driver and @code{libf2c} so that @samp{g77 -v}
3960 yields version information on the library.
3961
3962 @item
3963 The @code{SNGL} and @code{FLOAT} intrinsics now are
3964 specific intrinsics, instead of synonyms for the
3965 generic intrinsic @code{REAL}.
3966
3967 @item
3968 New intrinsics have been added.
3969 These are @code{REALPART}, @code{IMAGPART},
3970 @code{COMPLEX},
3971 @code{LONG}, and @code{SHORT}.
3972
3973 @item
3974 A new group of intrinsics, @samp{gnu}, has been added
3975 to contain the new @code{REALPART}, @code{IMAGPART},
3976 and @code{COMPLEX} intrinsics.
3977 An old group, @samp{dcp}, has been removed.
3978
3979 @item
3980 Complain about industry-wide ambiguous references
3981 @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
3982 where @var{expr} is @code{DOUBLE COMPLEX} (or any
3983 complex type other than @code{COMPLEX}), unless
3984 @samp{-ff90} option specifies Fortran 90 interpretation
3985 or new @samp{-fugly-complex} option, in conjunction with
3986 @samp{-fnot-f90}, specifies @code{f2c} interpretation.
3987 @end itemize
3988
3989 @heading In 0.5.19:
3990
3991 @itemize @bullet
3992 @item
3993 A temporary kludge option provides bare-bones information on
3994 @code{COMMON} and @code{EQUIVALENCE} members at debug time.
3995 @xref{Code Gen Options,,Options for Code Generation Conventions},
3996 for information on the @samp{-fdebug-kludge} option.
3997
3998 @item
3999 New @samp{-fonetrip} option specifies FORTRAN-66-style
4000 one-trip @code{DO} loops.
4001
4002 @item
4003 New @samp{-fno-silent} option causes names of program units
4004 to be printed as they are compiled, in a fashion similar to
4005 UNIX @code{f77} and @code{f2c}.
4006
4007 @item
4008 New @samp{-fugly-assumed} option specifies that arrays
4009 dimensioned via @samp{DIMENSION X(1)}, for example, are to be
4010 treated as assumed-size.
4011
4012 @item
4013 New @samp{-fno-typeless-boz} option specifies that non-decimal-radix
4014 constants using the prefixed-radix form (such as @samp{Z'1234'})
4015 are to be interpreted as @code{INTEGER(KIND=1)} constants.
4016
4017 @item
4018 New @samp{-ff66} option is a ``shorthand'' option that specifies
4019 behaviors considered appropriate for FORTRAN 66 programs.
4020
4021 @item
4022 New @samp{-ff77} option is a ``shorthand'' option that specifies
4023 behaviors considered appropriate for UNIX @code{f77} programs.
4024
4025 @item
4026 New @samp{-fugly-comma} and @samp{-fugly-logint} options provided
4027 to perform some of what @samp{-fugly} used to do.
4028 @samp{-fugly} and @samp{-fno-ugly} are now ``shorthand'' options,
4029 in that they do nothing more than enable (or disable) other
4030 @samp{-fugly-*} options.
4031
4032 @item
4033 Change code generation for list-directed I/O so it allows
4034 for new versions of @code{libf2c} that might return non-zero
4035 status codes for some operations previously assumed to always
4036 return zero.
4037
4038 This change not only affects how @code{IOSTAT=} variables
4039 are set by list-directed I/O, it also affects whether
4040 @code{END=} and @code{ERR=} labels are reached by these
4041 operations.
4042
4043 @item
4044 Add intrinsic support for new @code{FTELL} and @code{FSEEK}
4045 procedures in @code{libf2c}.
4046
4047 @item
4048 Add options @samp{--help} and @samp{--version} to the
4049 @code{g77} command, to conform to GNU coding guidelines.
4050 Also add printing of @code{g77} version number when
4051 the @samp{--verbose} (@samp{-v}) option is used.
4052 @end itemize
4053
4054 @heading In 0.5.18:
4055
4056 @itemize @bullet
4057 @item
4058 The @code{BYTE} and @code{WORD} statements now are supported,
4059 to a limited extent.
4060
4061 @item
4062 @code{INTEGER*1}, @code{INTEGER*2}, @code{INTEGER*8},
4063 and their @code{LOGICAL}
4064 equivalents, now are supported to a limited extent.
4065 Among the missing elements are complete intrinsic and constant
4066 support.
4067
4068 @item
4069 Support automatic arrays in procedures.
4070 For example, @samp{REAL A(N)}, where @samp{A} is
4071 not a dummy argument, specifies that @samp{A} is
4072 an automatic array.
4073 The size of @samp{A} is calculated from the value
4074 of @samp{N} each time the procedure is called,
4075 that amount of space is allocated, and that space
4076 is freed when the procedure returns to its caller.
4077
4078 @item
4079 Add @samp{-fno-zeros} option, enabled by default,
4080 to reduce compile-time CPU and memory usage for
4081 code that provides initial zero values for variables
4082 and arrays.
4083
4084 @item
4085 Introduce three new options that apply to all compilations
4086 by @code{g77}-aware GNU compilers---@samp{-fmove-all-movables},
4087 @samp{-freduce-all-givs}, and @samp{-frerun-loop-opt}---which
4088 can improve the run-time performance of some programs.
4089
4090 @item
4091 Replace much of the existing documentation with a single
4092 Info document.
4093
4094 @item
4095 New option @samp{-fno-second-underscore}.
4096 @end itemize
4097
4098 @heading In 0.5.17:
4099
4100 @itemize @bullet
4101 @item
4102 The @code{ERF()} and @code{ERFC()} intrinsics now are generic
4103 intrinsics, mapping to @code{ERF}/@code{DERF} and
4104 @code{ERFC}/@code{DERFC}, respectively.
4105 @emph{Note:} Use @samp{INTRINSIC ERF,ERFC} in any code that
4106 might reference these as generic intrinsics, to
4107 improve the likelihood of diagnostics (instead of subtle run-time
4108 bugs) when using compilers that don't support these as intrinsics.
4109
4110 @item
4111 New option @samp{-Wsurprising}.
4112
4113 @item
4114 DO loops with non-@code{INTEGER} variables now diagnosed only when
4115 @samp{-Wsurprising} specified.
4116 Previously, this was diagnosed @emph{unless} @samp{-fpedantic} or
4117 @samp{-fugly} was specified.
4118 @end itemize
4119
4120 @heading In 0.5.16:
4121
4122 @itemize @bullet
4123 @item
4124 @code{libf2c} changed to output a leading zero (0) digit for floating-point
4125 values output via list-directed and formatted output (to bring @code{g77}
4126 more into line with many existing Fortran implementations---the
4127 ANSI FORTRAN 77 standard leaves this choice to the implementation).
4128
4129 @item
4130 @code{libf2c} no longer built with debugging information
4131 intact, making it much smaller.
4132
4133 @item
4134 Automatic installation of the @code{g77} command now works.
4135
4136 @item
4137 Diagnostic messages now more informative, a la @code{gcc},
4138 including messages like @samp{In function `foo':} and @samp{In file
4139 included from...:}.
4140
4141 @item
4142 New group of intrinsics called @samp{unix}, including @code{ABORT},
4143 @code{DERF}, @code{DERFC}, @code{ERF}, @code{ERFC}, @code{EXIT},
4144 @code{FLUSH}, @code{GETARG}, @code{GETENV}, @code{SIGNAL}, and
4145 @code{SYSTEM}.
4146
4147 @item
4148 @samp{-funix-intrinsics-@{delete,hide,disable,enable@}}
4149 options added.
4150
4151 @item
4152 @samp{-fno-underscoring} option added.
4153
4154 @item
4155 @samp{--driver} option added to the @code{g77} command.
4156
4157 @item
4158 Support for the @code{gcc} options @samp{-fident} and @samp{-fno-ident}
4159 added.
4160
4161 @item
4162 @samp{g77 -v} returns much more version info, making the submission
4163 of better bug reports easily.
4164
4165 @item
4166 Many improvements to the @code{g77} command to better fulfill its role as
4167 a front-end to the @code{gcc} driver.
4168 For example, @code{g77} now
4169 recognizes @samp{--verbose} as a verbose way of specifying @samp{-v}.
4170
4171 @item
4172 Compiling preprocessed (@file{*.F} and @file{*.fpp}) files now
4173 results in better diagnostics and debugging information, as the
4174 source-location info now is passed all the
4175 way through the compilation process instead of being lost.
4176 @end itemize
4177
4178 @node Language
4179 @chapter The GNU Fortran Language
4180
4181 @cindex standard, ANSI FORTRAN 77
4182 @cindex ANSI FORTRAN 77 standard
4183 @cindex reference works
4184 GNU Fortran supports a variety of extensions to, and dialects
4185 of, the Fortran language.
4186 Its primary base is the ANSI FORTRAN 77 standard, currently available on
4187 the network at
4188 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
4189 or as monolithic text at
4190 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
4191 It offers some extensions that are popular among users
4192 of UNIX @code{f77} and @code{f2c} compilers, some that
4193 are popular among users of other compilers (such as Digital
4194 products), some that are popular among users of the
4195 newer Fortran 90 standard, and some that are introduced
4196 by GNU Fortran.
4197
4198 @cindex textbooks
4199 (If you need a text on Fortran,
4200 a few freely available electronic references have pointers from
4201 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
4202 net project', @cite{User Notes on Fortran Programming} at
4203 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
4204 material might not apply specifically to @code{g77}.)
4205
4206 Part of what defines a particular implementation of a Fortran
4207 system, such as @code{g77}, is the particular characteristics
4208 of how it supports types, constants, and so on.
4209 Much of this is left up to the implementation by the various
4210 Fortran standards and accepted practice in the industry.
4211
4212 The GNU Fortran @emph{language} is described below.
4213 Much of the material is organized along the same lines
4214 as the ANSI FORTRAN 77 standard itself.
4215
4216 @xref{Other Dialects}, for information on features @code{g77} supports
4217 that are not part of the GNU Fortran language.
4218
4219 @emph{Note}: This portion of the documentation definitely needs a lot
4220 of work!
4221
4222 @menu
4223 Relationship to the ANSI FORTRAN 77 standard:
4224 * Direction of Language Development::  Where GNU Fortran is headed.
4225 * Standard Support::  Degree of support for the standard.
4226
4227 Extensions to the ANSI FORTRAN 77 standard:
4228 * Conformance::
4229 * Notation Used::
4230 * Terms and Concepts::
4231 * Characters Lines Sequence::
4232 * Data Types and Constants::
4233 * Expressions::
4234 * Specification Statements::
4235 * Control Statements::
4236 * Functions and Subroutines::
4237 * Scope and Classes of Names::
4238 * I/O::
4239 * Fortran 90 Features::
4240 @end menu
4241
4242 @node Direction of Language Development
4243 @section Direction of Language Development
4244 @cindex direction of language development
4245 @cindex features, language
4246 @cindex language, features
4247
4248 The purpose of the following description of the GNU Fortran
4249 language is to promote wide portability of GNU Fortran programs.
4250
4251 GNU Fortran is an evolving language, due to the
4252 fact that @code{g77} itself is in beta test.
4253 Some current features of the language might later
4254 be redefined as dialects of Fortran supported by @code{g77}
4255 when better ways to express these features are added to @code{g77},
4256 for example.
4257 Such features would still be supported by
4258 @code{g77}, but would be available only when
4259 one or more command-line options were used.
4260
4261 The GNU Fortran @emph{language} is distinct from the
4262 GNU Fortran @emph{compilation system} (@code{g77}).
4263
4264 For example, @code{g77} supports various dialects of
4265 Fortran---in a sense, these are languages other than
4266 GNU Fortran---though its primary
4267 purpose is to support the GNU Fortran language, which also is
4268 described in its documentation and by its implementation.
4269
4270 On the other hand, non-GNU compilers might offer
4271 support for the GNU Fortran language, and are encouraged
4272 to do so.
4273
4274 Currently, the GNU Fortran language is a fairly fuzzy object.
4275 It represents something of a cross between what @code{g77} accepts
4276 when compiling using the prevailing defaults and what this
4277 document describes as being part of the language.
4278
4279 Future versions of @code{g77} are expected to clarify the
4280 definition of the language in the documentation.
4281 Often, this will mean adding new features to the language, in the form
4282 of both new documentation and new support in @code{g77}.
4283 However, it might occasionally mean removing a feature
4284 from the language itself to ``dialect'' status.
4285 In such a case, the documentation would be adjusted
4286 to reflect the change, and @code{g77} itself would likely be changed
4287 to require one or more command-line options to continue supporting
4288 the feature.
4289
4290 The development of the GNU Fortran language is intended to strike
4291 a balance between:
4292
4293 @itemize @bullet
4294 @item
4295 Serving as a mostly-upwards-compatible language from the
4296 de facto UNIX Fortran dialect as supported by @code{f77}.
4297
4298 @item
4299 Offering new, well-designed language features.
4300 Attributes of such features include
4301 not making existing code any harder to read
4302 (for those who might be unaware that the new
4303 features are not in use) and
4304 not making state-of-the-art
4305 compilers take longer to issue diagnostics,
4306 among others.
4307
4308 @item
4309 Supporting existing, well-written code without gratuitously
4310 rejecting non-standard constructs, regardless of the origin
4311 of the code (its dialect).
4312
4313 @item
4314 Offering default behavior and command-line options to reduce
4315 and, where reasonable, eliminate the need for programmers to make
4316 any modifications to code that already works in existing
4317 production environments.
4318
4319 @item
4320 Diagnosing constructs that have different meanings in different
4321 systems, languages, and dialects, while offering clear,
4322 less ambiguous ways to express each of the different meanings
4323 so programmers can change their code appropriately.
4324 @end itemize
4325
4326 One of the biggest practical challenges for the developers of the
4327 GNU Fortran language is meeting the sometimes contradictory demands
4328 of the above items.
4329
4330 For example, a feature might be widely used in one popular environment,
4331 but the exact same code that utilizes that feature might not work
4332 as expected---perhaps it might mean something entirely different---in
4333 another popular environment.
4334
4335 Traditionally, Fortran compilers---even portable ones---have solved this
4336 problem by simply offering the appropriate feature to users of
4337 the respective systems.
4338 This approach treats users of various Fortran systems and dialects
4339 as remote ``islands'', or camps, of programmers, and assume that these
4340 camps rarely come into contact with each other (or,
4341 especially, with each other's code).
4342
4343 Project GNU takes a radically different approach to software and language
4344 design, in that it assumes that users of GNU software do not necessarily
4345 care what kind of underlying system they are using, regardless
4346 of whether they are using software (at the user-interface
4347 level) or writing it (for example, writing Fortran or C code).
4348
4349 As such, GNU users rarely need consider just what kind of underlying
4350 hardware (or, in many cases, operating system) they are using at any
4351 particular time.
4352 They can use and write software designed for a general-purpose,
4353 widely portable, heterogenous environment---the GNU environment.
4354
4355 In line with this philosophy, GNU Fortran must evolve into a product
4356 that is widely ported and portable not only in the sense that it can
4357 be successfully built, installed, and run by users, but in the larger
4358 sense that its users can use it in the same way, and expect largely the
4359 same behaviors from it, regardless of the kind of system they are using
4360 at any particular time.
4361
4362 This approach constrains the solutions @code{g77} can use to resolve
4363 conflicts between various camps of Fortran users.
4364 If these two camps disagree about what a particular construct should
4365 mean, @code{g77} cannot simply be changed to treat that particular construct as
4366 having one meaning without comment (such as a warning), lest the users
4367 expecting it to have the other meaning are unpleasantly surprised that
4368 their code misbehaves when executed.
4369
4370 The use of the ASCII backslash character in character constants is
4371 an excellent (and still somewhat unresolved) example of this kind of
4372 controversy.
4373 @xref{Backslash in Constants}.
4374 Other examples are likely to arise in the future, as @code{g77} developers
4375 strive to improve its ability to accept an ever-wider variety of existing
4376 Fortran code without requiring significant modifications to said code.
4377
4378 Development of GNU Fortran is further constrained by the desire
4379 to avoid requiring programmers to change their code.
4380 This is important because it allows programmers, administrators,
4381 and others to more faithfully evaluate and validate @code{g77}
4382 (as an overall product and as new versions are distributed)
4383 without having to support multiple versions of their programs
4384 so that they continue to work the same way on their existing
4385 systems (non-GNU perhaps, but possibly also earlier versions
4386 of @code{g77}).
4387
4388 @node Standard Support
4389 @section ANSI FORTRAN 77 Standard Support
4390 @cindex ANSI FORTRAN 77 support
4391 @cindex standard, support for
4392 @cindex support, FORTRAN 77
4393 @cindex compatibility, FORTRAN 77
4394 @cindex FORTRAN 77 compatibility
4395
4396 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
4397 In summary, the only ANSI FORTRAN 77 features @code{g77} doesn't
4398 support are those that are probably rarely used in actual code,
4399 some of which are explicitly disallowed by the Fortran 90 standard.
4400
4401 @menu
4402 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
4403 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
4404 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
4405 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
4406 @end menu
4407
4408 @node No Passing External Assumed-length
4409 @subsection No Passing External Assumed-length
4410
4411 @code{g77} disallows passing of an external procedure
4412 as an actual argument if the procedure's
4413 type is declared @code{CHARACTER*(*)}.  For example:
4414
4415 @example
4416 CHARACTER*(*) CFUNC
4417 EXTERNAL CFUNC
4418 CALL FOO(CFUNC)
4419 END
4420 @end example
4421
4422 @noindent
4423 It isn't clear whether the standard considers this conforming.
4424
4425 @node No Passing Dummy Assumed-length
4426 @subsection No Passing Dummy Assumed-length
4427
4428 @code{g77} disallows passing of a dummy procedure
4429 as an actual argument if the procedure's
4430 type is declared @code{CHARACTER*(*)}.
4431
4432 @example
4433 SUBROUTINE BAR(CFUNC)
4434 CHARACTER*(*) CFUNC
4435 EXTERNAL CFUNC
4436 CALL FOO(CFUNC)
4437 END
4438 @end example
4439
4440 @noindent
4441 It isn't clear whether the standard considers this conforming.
4442
4443 @node No Pathological Implied-DO
4444 @subsection No Pathological Implied-DO
4445
4446 The @code{DO} variable for an implied-@code{DO} construct in a
4447 @code{DATA} statement may not be used as the @code{DO} variable
4448 for an outer implied-@code{DO} construct.  For example, this
4449 fragment is disallowed by @code{g77}:
4450
4451 @smallexample
4452 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
4453 @end smallexample
4454
4455 @noindent
4456 This also is disallowed by Fortran 90, as it offers no additional
4457 capabilities and would have a variety of possible meanings.
4458
4459 Note that it is @emph{very} unlikely that any production Fortran code
4460 tries to use this unsupported construct.
4461
4462 @node No Useless Implied-DO
4463 @subsection No Useless Implied-DO
4464
4465 An array element initializer in an implied-@code{DO} construct in a
4466 @code{DATA} statement must contain at least one reference to the @code{DO}
4467 variables of each outer implied-@code{DO} construct.  For example,
4468 this fragment is disallowed by @code{g77}:
4469
4470 @smallexample
4471 DATA (A, I= 1, 1) /1./
4472 @end smallexample
4473
4474 @noindent
4475 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
4476 requirements offer no additional capabilities.
4477 However, @code{g77} doesn't necessarily diagnose all cases
4478 where this requirement is not met.
4479
4480 Note that it is @emph{very} unlikely that any production Fortran code
4481 tries to use this unsupported construct.
4482
4483 @node Conformance
4484 @section Conformance
4485
4486 (The following information augments or overrides the information in
4487 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4488 language.
4489 Chapter 1 of that document otherwise serves as the basis
4490 for the relevant aspects of GNU Fortran.)
4491
4492 The definition of the GNU Fortran language is akin to that of
4493 the ANSI FORTRAN 77 language in that it does not generally require
4494 conforming implementations to diagnose cases where programs do
4495 not conform to the language.
4496
4497 However, @code{g77} as a compiler is being developed in a way that
4498 is intended to enable it to diagnose such cases in an easy-to-understand
4499 manner.
4500
4501 A program that conforms to the GNU Fortran language should, when
4502 compiled, linked, and executed using a properly installed @code{g77}
4503 system, perform as described by the GNU Fortran language definition.
4504 Reasons for different behavior include, among others:
4505
4506 @itemize @bullet
4507 @item
4508 Use of resources (memory---heap, stack, and so on; disk space; CPU
4509 time; etc.) exceeds those of the system.
4510
4511 @item
4512 Range and/or precision of calculations required by the program
4513 exceeds that of the system.
4514
4515 @item
4516 Excessive reliance on behaviors that are system-dependent
4517 (non-portable Fortran code).
4518
4519 @item
4520 Bugs in the program.
4521
4522 @item
4523 Bug in @code{g77}.
4524
4525 @item
4526 Bugs in the system.
4527 @end itemize
4528
4529 Despite these ``loopholes'', the availability of a clear specification
4530 of the language of programs submitted to @code{g77}, as this document
4531 is intended to provide, is considered an important aspect of providing
4532 a robust, clean, predictable Fortran implementation.
4533
4534 The definition of the GNU Fortran language, while having no special
4535 legal status, can therefore be viewed as a sort of contract, or agreement.
4536 This agreement says, in essence, ``if you write a program in this language,
4537 and run it in an environment (such as a @code{g77} system) that supports
4538 this language, the program should behave in a largely predictable way''.
4539
4540 @node Notation Used
4541 @section Notation Used in This Chapter
4542
4543 (The following information augments or overrides the information in
4544 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4545 language.
4546 Chapter 1 of that document otherwise serves as the basis
4547 for the relevant aspects of GNU Fortran.)
4548
4549 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
4550 and ``must not'' and ``may not'' denote prohibition.
4551 Terms such as ``might'', ``should'', and ``can'' generally add little or
4552 nothing in the way of weight to the GNU Fortran language itself,
4553 but are used to explain or illustrate the language.
4554
4555 For example:
4556
4557 @display
4558 ``The @code{FROBNITZ} statement must precede all executable
4559 statements in a program unit, and may not specify any dummy
4560 arguments.  It may specify local or common variables and arrays.
4561 Its use should be limited to portions of the program designed to
4562 be non-portable and system-specific, because it might cause the
4563 containing program unit to behave quite differently on different
4564 systems.''
4565 @end display
4566
4567 Insofar as the GNU Fortran language is specified,
4568 the requirements and permissions denoted by the above sample statement
4569 are limited to the placement of the statement and the kinds of
4570 things it may specify.
4571 The rest of the statement---the content regarding non-portable portions
4572 of the program and the differing behavior of program units containing
4573 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
4574 language itself.
4575 That content offers advice and warnings about the @code{FROBNITZ}
4576 statement.
4577
4578 @emph{Remember:} The GNU Fortran language definition specifies
4579 both what constitutes a valid GNU Fortran program and how,
4580 given such a program, a valid GNU Fortran implementation is
4581 to interpret that program.
4582
4583 It is @emph{not} incumbent upon a valid GNU Fortran implementation
4584 to behave in any particular way, any consistent way, or any
4585 predictable way when it is asked to interpret input that is
4586 @emph{not} a valid GNU Fortran program.
4587
4588 Such input is said to have @dfn{undefined} behavior when
4589 interpreted by a valid GNU Fortran implementation, though
4590 an implementation may choose to specify behaviors for some
4591 cases of inputs that are not valid GNU Fortran programs.
4592
4593 Other notation used herein is that of the GNU texinfo format,
4594 which is used to generate printed hardcopy, on-line hypertext
4595 (Info), and on-line HTML versions, all from a single source
4596 document.
4597 This notation is used as follows:
4598
4599 @itemize @bullet
4600 @item
4601 Keywords defined by the GNU Fortran language are shown
4602 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
4603 @code{BLOCK DATA}.
4604
4605 Note that, in practice, many Fortran programs are written
4606 in lowercase---uppercase is used in this manual as a
4607 means to readily distinguish keywords and sample Fortran-related
4608 text from the prose in this document.
4609
4610 @item
4611 Portions of actual sample program, input, or output text
4612 look like this: @samp{Actual program text}.
4613
4614 Generally, uppercase is used for all Fortran-specific and
4615 Fortran-related text, though this does not always include
4616 literal text within Fortran code.
4617
4618 For example: @samp{PRINT *, 'My name is Bob'}.
4619
4620 @item
4621 A metasyntactic variable---that is, a name used in this document
4622 to serve as a placeholder for whatever text is used by the
4623 user or programmer--appears as shown in the following example:
4624
4625 ``The @code{INTEGER @var{ivar}} statement specifies that
4626 @var{ivar} is a variable or array of type @code{INTEGER}.''
4627
4628 In the above example, any valid text may be substituted for
4629 the metasyntactic variable @var{ivar} to make the statement
4630 apply to a specific instance, as long as the same text is
4631 substituted for @emph{both} occurrences of @var{ivar}.
4632
4633 @item
4634 Ellipses (``@dots{}'') are used to indicate further text that
4635 is either unimportant or expanded upon further, elsewhere.
4636
4637 @item
4638 Names of data types are in the style of Fortran 90, in most
4639 cases.
4640
4641 @xref{Kind Notation}, for information on the relationship
4642 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
4643 and the more traditional, less portably concise nomenclature
4644 (such as @code{INTEGER*4}).
4645 @end itemize
4646
4647 @node Terms and Concepts
4648 @section Fortran Terms and Concepts
4649
4650 (The following information augments or overrides the information in
4651 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4652 language.
4653 Chapter 2 of that document otherwise serves as the basis
4654 for the relevant aspects of GNU Fortran.)
4655
4656 @menu
4657 * Syntactic Items::
4658 * Statements Comments Lines::
4659 * Scope of Names and Labels::
4660 @end menu
4661
4662 @node Syntactic Items
4663 @subsection Syntactic Items
4664
4665 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
4666
4667 @cindex limits, lengths of names
4668 In GNU Fortran, a symbolic name is at least one character long,
4669 and has no arbitrary upper limit on length.
4670 However, names of entities requiring external linkage (such as
4671 external functions, external subroutines, and @code{COMMON} areas)
4672 might be restricted to some arbitrary length by the system.
4673 Such a restriction is no more constrained than that of one
4674 through six characters.
4675
4676 Underscores (@samp{_}) are accepted in symbol names after the first
4677 character (which must be a letter).
4678
4679 @node Statements Comments Lines
4680 @subsection Statements, Comments, and Lines
4681
4682 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
4683
4684 @cindex trailing comment
4685 @cindex comment
4686 @cindex characters, comment
4687 @cindex !
4688 @cindex exclamation point
4689 @cindex continuation character
4690 @cindex characters, continuation
4691 Use of an exclamation point (@samp{!}) to begin a
4692 trailing comment (a comment that extends to the end of the same
4693 source line) is permitted under the following conditions:
4694
4695 @itemize @bullet
4696 @item
4697 The exclamation point does not appear in column 6.
4698 Otherwise, it is treated as an indicator of a continuation
4699 line.
4700
4701 @item
4702 The exclamation point appears outside a character or Hollerith
4703 constant.
4704 Otherwise, the exclamation point is considered part of the
4705 constant.
4706
4707 @item
4708 The exclamation point appears to the left of any other possible
4709 trailing comment.
4710 That is, a trailing comment may contain exclamation points
4711 in their commentary text.
4712 @end itemize
4713
4714 @cindex ;
4715 @cindex semicolon
4716 @cindex statements, separated by semicolon
4717 Use of a semicolon (@samp{;}) as a statement separator
4718 is permitted under the following conditions:
4719
4720 @itemize @bullet
4721 @item
4722 The semicolon appears outside a character or Hollerith
4723 constant.
4724 Otherwise, the semicolon is considered part of the
4725 constant.
4726
4727 @item
4728 The semicolon appears to the left of a trailing comment.
4729 Otherwise, the semicolon is considered part of that
4730 comment.
4731
4732 @item
4733 Neither a logical @code{IF} statement nor a non-construct
4734 @code{WHERE} statement (a Fortran 90 feature) may be
4735 followed (in the same, possibly continued, line) by
4736 a semicolon used as a statement separator.
4737
4738 This restriction avoids the confusion
4739 that can result when reading a line such as:
4740
4741 @smallexample
4742 IF (VALIDP) CALL FOO; CALL BAR
4743 @end smallexample
4744
4745 @noindent
4746 Some readers might think the @samp{CALL BAR} is executed
4747 only if @samp{VALIDP} is @code{.TRUE.}, while others might
4748 assume its execution is unconditional.
4749
4750 (At present, @code{g77} does not diagnose code that
4751 violates this restriction.)
4752 @end itemize
4753
4754 @node Scope of Names and Labels
4755 @subsection Scope of Symbolic Names and Statement Labels
4756 @cindex scope
4757
4758 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
4759
4760 Included in the list of entities that have a scope of a
4761 program unit are construct names (a Fortran 90 feature).
4762 @xref{Construct Names}, for more information.
4763
4764 @node Characters Lines Sequence
4765 @section Characters, Lines, and Execution Sequence
4766
4767 (The following information augments or overrides the information in
4768 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4769 language.
4770 Chapter 3 of that document otherwise serves as the basis
4771 for the relevant aspects of GNU Fortran.)
4772
4773 @menu
4774 * Character Set::
4775 * Lines::
4776 * Continuation Line::
4777 * Statements::
4778 * Statement Labels::
4779 * Order::
4780 * INCLUDE::
4781 * Cpp-style directives::
4782 @end menu
4783
4784 @node Character Set
4785 @subsection GNU Fortran Character Set
4786 @cindex characters
4787
4788 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
4789
4790 Letters include uppercase letters (the twenty-six characters
4791 of the English alphabet) and lowercase letters (their lowercase
4792 equivalent).
4793 Generally, lowercase letters may be used in place of uppercase
4794 letters, though in character and Hollerith constants, they
4795 are distinct.
4796
4797 Special characters include:
4798
4799 @itemize @bullet
4800 @item
4801 @cindex ;
4802 @cindex semicolon
4803 Semicolon (@samp{;})
4804
4805 @item
4806 @cindex !
4807 @cindex exclamation point
4808 Exclamation point (@samp{!})
4809
4810 @item
4811 @cindex "
4812 @cindex double quote
4813 Double quote (@samp{"})
4814
4815 @item
4816 @cindex \
4817 @cindex backslash
4818 Backslash (@samp{\})
4819
4820 @item
4821 @cindex ?
4822 @cindex question mark
4823 Question mark (@samp{?})
4824
4825 @item
4826 @cindex #
4827 @cindex hash mark
4828 @cindex pound sign
4829 Hash mark (@samp{#})
4830
4831 @item
4832 @cindex &
4833 @cindex ampersand
4834 Ampersand (@samp{&})
4835
4836 @item
4837 @cindex %
4838 @cindex percent sign
4839 Percent sign (@samp{%})
4840
4841 @item
4842 @cindex _
4843 @cindex underscore
4844 Underscore (@samp{_})
4845
4846 @item
4847 @cindex <
4848 @cindex open angle
4849 @cindex left angle
4850 @cindex open bracket
4851 @cindex left bracket
4852 Open angle (@samp{<})
4853
4854 @item
4855 @cindex >
4856 @cindex close angle
4857 @cindex right angle
4858 @cindex close bracket
4859 @cindex right bracket
4860 Close angle (@samp{>})
4861
4862 @item
4863 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
4864 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
4865 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
4866 and @samp{:})
4867 @end itemize
4868
4869 @cindex blank
4870 @cindex space
4871 @cindex SPC
4872 Note that this document refers to @key{SPC} as @dfn{space},
4873 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
4874
4875 @node Lines
4876 @subsection Lines
4877 @cindex lines
4878 @cindex source file format
4879 @cindex source format
4880 @cindex file, source
4881 @cindex source code
4882 @cindex code, source
4883 @cindex fixed form
4884 @cindex free form
4885
4886 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
4887
4888 The way a Fortran compiler views source files depends entirely on the
4889 implementation choices made for the compiler, since those choices
4890 are explicitly left to the implementation by the published Fortran
4891 standards.
4892
4893 The GNU Fortran language mandates a view applicable to UNIX-like
4894 text files---files that are made up of an arbitrary number of lines,
4895 each with an arbitrary number of characters (sometimes called stream-based
4896 files).
4897
4898 This view does not apply to types of files that are specified as
4899 having a particular number of characters on every single line (sometimes
4900 referred to as record-based files).
4901
4902 Because a ``line in a program unit is a sequence of 72 characters'',
4903 to quote X3.9-1978, the GNU Fortran language specifies that a
4904 stream-based text file is translated to GNU Fortran lines as follows:
4905
4906 @itemize @bullet
4907 @item
4908 A newline in the file is the character that represents the end of
4909 a line of text to the underlying system.
4910 For example, on ASCII-based systems, a newline is the @key{NL}
4911 character, which has ASCII value 12 (decimal).
4912
4913 @item
4914 Each newline in the file serves to end the line of text that precedes
4915 it (and that does not contain a newline).
4916
4917 @item
4918 The end-of-file marker (@code{EOF}) also serves to end the line
4919 of text that precedes it (and that does not contain a newline).
4920
4921 @item
4922 @cindex blank
4923 @cindex space
4924 @cindex SPC
4925 Any line of text that is shorter than 72 characters is padded to that length
4926 with spaces (called ``blanks'' in the standard).
4927
4928 @item
4929 Any line of text that is longer than 72 characters is truncated to that
4930 length, but the truncated remainder must consist entirely of spaces.
4931
4932 @item
4933 Characters other than newline and the GNU Fortran character set
4934 are invalid.
4935 @end itemize
4936
4937 For the purposes of the remainder of this description of the GNU
4938 Fortran language, the translation described above has already
4939 taken place, unless otherwise specified.
4940
4941 The result of the above translation is that the source file appears,
4942 in terms of the remainder of this description of the GNU Fortran language,
4943 as if it had an arbitrary
4944 number of 72-character lines, each character being among the GNU Fortran
4945 character set.
4946
4947 For example, if the source file itself has two newlines in a row,
4948 the second newline becomes, after the above translation, a single
4949 line containing 72 spaces.
4950
4951 @node Continuation Line
4952 @subsection Continuation Line
4953 @cindex continuation line, number of
4954 @cindex lines, continuation
4955 @cindex number of continuation lines
4956 @cindex limits, continuation lines
4957
4958 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
4959
4960 A continuation line is any line that both
4961
4962 @itemize @bullet
4963 @item
4964 Contains a continuation character, and
4965
4966 @item
4967 Contains only spaces in columns 1 through 5
4968 @end itemize
4969
4970 A continuation character is any character of the GNU Fortran character set
4971 other than space (@key{SPC}) or zero (@samp{0})
4972 in column 6, or a digit (@samp{0} through @samp{9}) in column
4973 7 through 72 of a line that has only spaces to the left of that
4974 digit.
4975
4976 The continuation character is ignored as far as the content of
4977 the statement is concerned.
4978
4979 The GNU Fortran language places no limit on the number of
4980 continuation lines in a statement.
4981 In practice, the limit depends on a variety of factors, such as
4982 available memory, statement content, and so on, but no
4983 GNU Fortran system may impose an arbitrary limit.
4984
4985 @node Statements
4986 @subsection Statements
4987
4988 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
4989
4990 Statements may be written using an arbitrary number of continuation
4991 lines.
4992
4993 Statements may be separated using the semicolon (@samp{;}), except
4994 that the logical @code{IF} and non-construct @code{WHERE} statements
4995 may not be separated from subsequent statements using only a semicolon
4996 as statement separator.
4997
4998 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
4999 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
5000 statement.
5001 These alternatives may be written as normal statements---they are not
5002 subject to the restrictions of the @code{END} statement.
5003
5004 However, no statement other than @code{END} may have an initial line
5005 that appears to be an @code{END} statement---even @code{END PROGRAM},
5006 for example, must not be written as:
5007
5008 @example
5009       END
5010      &PROGRAM
5011 @end example
5012
5013 @node Statement Labels
5014 @subsection Statement Labels
5015
5016 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
5017
5018 A statement separated from its predecessor via a semicolon may be
5019 labeled as follows:
5020
5021 @itemize @bullet
5022 @item
5023 The semicolon is followed by the label for the statement,
5024 which in turn follows the label.
5025
5026 @item
5027 The label must be no more than five digits in length.
5028
5029 @item
5030 The first digit of the label for the statement is not
5031 the first non-space character on a line.
5032 Otherwise, that character is treated as a continuation
5033 character.
5034 @end itemize
5035
5036 A statement may have only one label defined for it.
5037
5038 @node Order
5039 @subsection Order of Statements and Lines
5040
5041 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
5042
5043 Generally, @code{DATA} statements may precede executable statements.
5044 However, specification statements pertaining to any entities
5045 initialized by a @code{DATA} statement must precede that @code{DATA}
5046 statement.
5047 For example,
5048 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
5049 @samp{INTEGER J} is permitted.
5050
5051 The last line of a program unit may be an @code{END} statement,
5052 or may be:
5053
5054 @itemize @bullet
5055 @item
5056 An @code{END PROGRAM} statement, if the program unit is a main program.
5057
5058 @item
5059 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
5060
5061 @item
5062 An @code{END FUNCTION} statement, if the program unit is a function.
5063
5064 @item
5065 An @code{END BLOCK DATA} statement, if the program unit is a block data.
5066 @end itemize
5067
5068 @node INCLUDE
5069 @subsection Including Source Text
5070 @cindex INCLUDE directive
5071
5072 Additional source text may be included in the processing of
5073 the source file via the @code{INCLUDE} directive:
5074
5075 @example
5076 INCLUDE @var{filename}
5077 @end example
5078
5079 @noindent
5080 The source text to be included is identified by @var{filename},
5081 which is a literal GNU Fortran character constant.
5082 The meaning and interpretation of @var{filename} depends on the
5083 implementation, but typically is a filename.
5084
5085 (@code{g77} treats it as a filename that it searches for
5086 in the current directory and/or directories specified
5087 via the @samp{-I} command-line option.)
5088
5089 The effect of the @code{INCLUDE} directive is as if the
5090 included text directly replaced the directive in the source
5091 file prior to interpretation of the program.
5092 Included text may itself use @code{INCLUDE}.
5093 The depth of nested @code{INCLUDE} references depends on
5094 the implementation, but typically is a positive integer.
5095
5096 This virtual replacement treats the statements and @code{INCLUDE}
5097 directives in the included text as syntactically distinct from
5098 those in the including text.
5099
5100 Therefore, the first non-comment line of the included text
5101 must not be a continuation line.
5102 The included text must therefore have, after the non-comment
5103 lines, either an initial line (statement), an @code{INCLUDE}
5104 directive, or nothing (the end of the included text).
5105
5106 Similarly, the including text may end the @code{INCLUDE}
5107 directive with a semicolon or the end of the line, but it
5108 cannot follow an @code{INCLUDE} directive at the end of its
5109 line with a continuation line.
5110 Thus, the last statement in an included text may not be
5111 continued.
5112
5113 Any statements between two @code{INCLUDE} directives on the
5114 same line are treated as if they appeared in between the
5115 respective included texts.
5116 For example:
5117
5118 @smallexample
5119 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
5120 @end smallexample
5121
5122 @noindent
5123 If the text included by @samp{INCLUDE 'A'} constitutes
5124 a @samp{PRINT *, 'A'} statement and the text included by
5125 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
5126 then the output of the above sample program would be
5127
5128 @example
5129 A
5130 B
5131 C
5132 @end example
5133
5134 @noindent
5135 (with suitable allowances for how an implementation defines
5136 its handling of output).
5137
5138 Included text must not include itself directly or indirectly,
5139 regardless of whether the @var{filename} used to reference
5140 the text is the same.
5141
5142 Note that @code{INCLUDE} is @emph{not} a statement.
5143 As such, it is neither a non-executable or executable
5144 statement.
5145 However, if the text it includes constitutes one or more
5146 executable statements, then the placement of @code{INCLUDE}
5147 is subject to effectively the same restrictions as those
5148 on executable statements.
5149
5150 An @code{INCLUDE} directive may be continued across multiple
5151 lines as if it were a statement.
5152 This permits long names to be used for @var{filename}.
5153
5154 @node Cpp-style directives
5155 @subsection Cpp-style directives
5156 @cindex #
5157 @cindex preprocessor
5158
5159 @code{cpp} output-style @code{#} directives @xref{C Preprocessor
5160 Output,,, cpp, The C Preprocessor}, are recognized by the compiler even
5161 when the preprocessor isn't run on the input (as it is when compiling
5162 @samp{.F} files).  (Note the distinction between these @code{cpp}
5163 @code{#} @emph{output} directives and @code{#line} @emph{input}
5164 directives.)
5165
5166 @node Data Types and Constants
5167 @section Data Types and Constants
5168
5169 (The following information augments or overrides the information in
5170 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5171 language.
5172 Chapter 4 of that document otherwise serves as the basis
5173 for the relevant aspects of GNU Fortran.)
5174
5175 To more concisely express the appropriate types for
5176 entities, this document uses the more concise
5177 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
5178 instead of the more traditional, but less portably concise,
5179 byte-size-based nomenclature such as @code{INTEGER*4},
5180 wherever reasonable.
5181
5182 When referring to generic types---in contexts where the
5183 specific precision and range of a type are not important---this
5184 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
5185 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
5186
5187 In some cases, the context requires specification of a
5188 particular type.
5189 This document uses the @samp{KIND=} notation to accomplish
5190 this throughout, sometimes supplying the more traditional
5191 notation for clarification, though the traditional notation
5192 might not work the same way on all GNU Fortran implementations.
5193
5194 Use of @samp{KIND=} makes this document more concise because
5195 @code{g77} is able to define values for @samp{KIND=} that
5196 have the same meanings on all systems, due to the way the
5197 Fortran 90 standard specifies these values are to be used.
5198
5199 (In particular, that standard permits an implementation to
5200 arbitrarily assign nonnegative values.
5201 There are four distinct sets of assignments: one to the @code{CHARACTER}
5202 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
5203 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
5204 Implementations are free to assign these values in any order,
5205 leave gaps in the ordering of assignments, and assign more than
5206 one value to a representation.)
5207
5208 This makes @samp{KIND=} values superior to the values used
5209 in non-standard statements such as @samp{INTEGER*4}, because
5210 the meanings of the values in those statements vary from machine
5211 to machine, compiler to compiler, even operating system to
5212 operating system.
5213
5214 However, use of @samp{KIND=} is @emph{not} generally recommended
5215 when writing portable code (unless, for example, the code is
5216 going to be compiled only via @code{g77}, which is a widely
5217 ported compiler).
5218 GNU Fortran does not yet have adequate language constructs to
5219 permit use of @samp{KIND=} in a fashion that would make the
5220 code portable to Fortran 90 implementations; and, this construct
5221 is known to @emph{not} be accepted by many popular FORTRAN 77
5222 implementations, so it cannot be used in code that is to be ported
5223 to those.
5224
5225 The distinction here is that this document is able to use
5226 specific values for @samp{KIND=} to concisely document the
5227 types of various operations and operands.
5228
5229 A Fortran program should use the FORTRAN 77 designations for the
5230 appropriate GNU Fortran types---such as @code{INTEGER} for
5231 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
5232 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
5233 where no such designations exist, make use of appropriate
5234 techniques (preprocessor macros, parameters, and so on)
5235 to specify the types in a fashion that may be easily adjusted
5236 to suit each particular implementation to which the program
5237 is ported.
5238 (These types generally won't need to be adjusted for ports of
5239 @code{g77}.)
5240
5241 Further details regarding GNU Fortran data types and constants
5242 are provided below.
5243
5244 @menu
5245 * Types::
5246 * Constants::
5247 * Integer Type::
5248 * Character Type::
5249 @end menu
5250
5251 @node Types
5252 @subsection Data Types
5253
5254 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
5255
5256 GNU Fortran supports these types:
5257
5258 @enumerate
5259 @item
5260 Integer (generic type @code{INTEGER})
5261
5262 @item
5263 Real (generic type @code{REAL})
5264
5265 @item
5266 Double precision
5267
5268 @item
5269 Complex (generic type @code{COMPLEX})
5270
5271 @item
5272 Logical (generic type @code{LOGICAL})
5273
5274 @item
5275 Character (generic type @code{CHARACTER})
5276
5277 @item
5278 Double Complex
5279 @end enumerate
5280
5281 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
5282
5283 The generic types shown above are referred to in this document
5284 using only their generic type names.
5285 Such references usually indicate that any specific type (kind)
5286 of that generic type is valid.
5287
5288 For example, a context described in this document as accepting
5289 the @code{COMPLEX} type also is likely to accept the
5290 @code{DOUBLE COMPLEX} type.
5291
5292 The GNU Fortran language supports three ways to specify
5293 a specific kind of a generic type.
5294
5295 @menu
5296 * Double Notation::  As in @code{DOUBLE COMPLEX}.
5297 * Star Notation::    As in @code{INTEGER*4}.
5298 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
5299 @end menu
5300
5301 @node Double Notation
5302 @subsubsection Double Notation
5303
5304 The GNU Fortran language supports two uses of the keyword
5305 @code{DOUBLE} to specify a specific kind of type:
5306
5307 @itemize @bullet
5308 @item
5309 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
5310
5311 @item
5312 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
5313 @end itemize
5314
5315 Use one of the above forms where a type name is valid.
5316
5317 While use of this notation is popular, it doesn't scale
5318 well in a language or dialect rich in intrinsic types,
5319 as is the case for the GNU Fortran language (especially
5320 planned future versions of it).
5321
5322 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
5323 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
5324 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
5325 often are substituted for these, respectively, even though they
5326 do not always have the same meanings on all systems.
5327 (And, the fact that @samp{DOUBLE REAL} does not exist as such
5328 is an inconsistency.)
5329
5330 Therefore, this document uses ``double notation'' only on occasion
5331 for the benefit of those readers who are accustomed to it.
5332
5333 @node Star Notation
5334 @subsubsection Star Notation
5335 @cindex *@var{n} notation
5336
5337 The following notation specifies the storage size for a type:
5338
5339 @smallexample
5340 @var{generic-type}*@var{n}
5341 @end smallexample
5342
5343 @noindent
5344 @var{generic-type} must be a generic type---one of
5345 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
5346 or @code{CHARACTER}.
5347 @var{n} must be one or more digits comprising a decimal
5348 integer number greater than zero.
5349
5350 Use the above form where a type name is valid.
5351
5352 The @samp{*@var{n}} notation specifies that the amount of storage
5353 occupied by variables and array elements of that type is @var{n}
5354 times the storage occupied by a @code{CHARACTER*1} variable.
5355
5356 This notation might indicate a different degree of precision and/or
5357 range for such variables and array elements, and the functions that
5358 return values of types using this notation.
5359 It does not limit the precision or range of values of that type
5360 in any particular way---use explicit code to do that.
5361
5362 Further, the GNU Fortran language requires no particular values
5363 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
5364 notation.
5365 @code{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
5366 on all systems, for example,
5367 but not all implementations are required to do so, and @code{g77}
5368 is known to not support @code{REAL*1} on most (or all) systems.
5369
5370 As a result, except for @var{generic-type} of @code{CHARACTER},
5371 uses of this notation should be limited to isolated
5372 portions of a program that are intended to handle system-specific
5373 tasks and are expected to be non-portable.
5374
5375 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
5376 only @code{CHARACTER}, where it signifies not only the amount
5377 of storage occupied, but the number of characters in entities
5378 of that type.
5379 However, almost all Fortran compilers have supported this
5380 notation for generic types, though with a variety of meanings
5381 for @var{n}.)
5382
5383 Specifications of types using the @samp{*@var{n}} notation
5384 always are interpreted as specifications of the appropriate
5385 types described in this document using the @samp{KIND=@var{n}}
5386 notation, described below.
5387
5388 While use of this notation is popular, it doesn't serve well
5389 in the context of a widely portable dialect of Fortran, such as
5390 the GNU Fortran language.
5391
5392 For example, even on one particular machine, two or more popular
5393 Fortran compilers might well disagree on the size of a type
5394 declared @code{INTEGER*2} or @code{REAL*16}.
5395 Certainly there
5396 is known to be disagreement over such things among Fortran
5397 compilers on @emph{different} systems.
5398
5399 Further, this notation offers no elegant way to specify sizes
5400 that are not even multiples of the ``byte size'' typically
5401 designated by @code{INTEGER*1}.
5402 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
5403 certainly be possible, but would perhaps be stretching the original
5404 intent of this notation beyond the breaking point in terms
5405 of widespread readability of documentation and code making use
5406 of it.
5407
5408 Therefore, this document uses ``star notation'' only on occasion
5409 for the benefit of those readers who are accustomed to it.
5410
5411 @node Kind Notation
5412 @subsubsection Kind Notation
5413 @cindex KIND= notation
5414
5415 The following notation specifies the kind-type selector of a type:
5416
5417 @smallexample
5418 @var{generic-type}(KIND=@var{n})
5419 @end smallexample
5420
5421 @noindent
5422 Use the above form where a type name is valid.
5423
5424 @var{generic-type} must be a generic type---one of
5425 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
5426 or @code{CHARACTER}.
5427 @var{n} must be an integer initialization expression that
5428 is a positive, nonzero value.
5429
5430 Programmers are discouraged from writing these values directly
5431 into their code.
5432 Future versions of the GNU Fortran language will offer
5433 facilities that will make the writing of code portable
5434 to @code{g77} @emph{and} Fortran 90 implementations simpler.
5435
5436 However, writing code that ports to existing FORTRAN 77
5437 implementations depends on avoiding the @samp{KIND=} construct.
5438
5439 The @samp{KIND=} construct is thus useful in the context
5440 of GNU Fortran for two reasons:
5441
5442 @itemize @bullet
5443 @item
5444 It provides a means to specify a type in a fashion that
5445 is portable across all GNU Fortran implementations (though
5446 not other FORTRAN 77 and Fortran 90 implementations).
5447
5448 @item
5449 It provides a sort of Rosetta stone for this document to use
5450 to concisely describe the types of various operations and
5451 operands.
5452 @end itemize
5453
5454 The values of @var{n} in the GNU Fortran language are
5455 assigned using a scheme that:
5456
5457 @itemize @bullet
5458 @item
5459 Attempts to maximize the ability of readers
5460 of this document to quickly familiarize themselves
5461 with assignments for popular types
5462
5463 @item
5464 Provides a unique value for each specific desired
5465 meaning
5466
5467 @item
5468 Provides a means to automatically assign new values so
5469 they have a ``natural'' relationship to existing values,
5470 if appropriate, or, if no such relationship exists, will
5471 not interfere with future values assigned on the basis
5472 of such relationships
5473
5474 @item
5475 Avoids using values that are similar to values used
5476 in the existing, popular @samp{*@var{n}} notation,
5477 to prevent readers from expecting that these implied
5478 correspondences work on all GNU Fortran implementations
5479 @end itemize
5480
5481 The assignment system accomplishes this by assigning
5482 to each ``fundamental meaning'' of a specific type a
5483 unique prime number.
5484 Combinations of fundamental meanings---for example, a type
5485 that is two times the size of some other type---are assigned
5486 values of @var{n} that are the products of the values for
5487 those fundamental meanings.
5488
5489 A prime value of @var{n} is never given more than one fundamental
5490 meaning, to avoid situations where some code or system
5491 cannot reasonably provide those meanings in the form of a
5492 single type.
5493
5494 The values of @var{n} assigned so far are:
5495
5496 @table @code
5497 @item KIND=0
5498 This value is reserved for future use.
5499
5500 The planned future use is for this value to designate,
5501 explicitly, context-sensitive kind-type selection.
5502 For example, the expression @samp{1D0 * 0.1_0} would
5503 be equivalent to @samp{1D0 * 0.1D0}.
5504
5505 @item KIND=1
5506 This corresponds to the default types for
5507 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
5508 and @code{CHARACTER}, as appropriate.
5509
5510 These are the ``default'' types described in the Fortran 90 standard,
5511 though that standard does not assign any particular @samp{KIND=}
5512 value to these types.
5513
5514 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
5515 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
5516
5517 @item KIND=2
5518 This corresponds to types that occupy twice as much
5519 storage as the default types.
5520 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
5521 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
5522
5523 These are the ``double precision'' types described in the Fortran 90
5524 standard,
5525 though that standard does not assign any particular @samp{KIND=}
5526 value to these types.
5527
5528 @var{n} of 4 thus corresponds to types that occupy four times
5529 as much storage as the default types, @var{n} of 8 to types that
5530 occupy eight times as much storage, and so on.
5531
5532 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
5533 are not necessarily supported by every GNU Fortran implementation.
5534
5535 @item KIND=3
5536 This corresponds to types that occupy as much
5537 storage as the default @code{CHARACTER} type,
5538 which is the same effective type as @code{CHARACTER(KIND=1)}
5539 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
5540
5541 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
5542
5543 @var{n} of 6 thus corresponds to types that occupy twice as
5544 much storage as the @var{n}=3 types, @var{n} of 12 to types
5545 that occupy four times as much storage, and so on.
5546
5547 These are not necessarily supported by every GNU Fortran
5548 implementation.
5549
5550 @item KIND=5
5551 This corresponds to types that occupy half the
5552 storage as the default (@var{n}=1) types.
5553
5554 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
5555
5556 @var{n} of 25 thus corresponds to types that occupy one-quarter
5557 as much storage as the default types.
5558
5559 These are not necessarily supported by every GNU Fortran
5560 implementation.
5561
5562 @item KIND=7
5563 @cindex pointers
5564 This is valid only as @code{INTEGER(KIND=7)} and
5565 denotes the @code{INTEGER} type that has the smallest
5566 storage size that holds a pointer on the system.
5567
5568 A pointer representable by this type is capable of uniquely
5569 addressing a @code{CHARACTER*1} variable, array, array element,
5570 or substring.
5571
5572 (Typically this is equivalent to @code{INTEGER*4} or,
5573 on 64-bit systems, @code{INTEGER*8}.
5574 In a compatible C implementation, it typically would
5575 be the same size and semantics of the C type @code{void *}.)
5576 @end table
5577
5578 Note that these are @emph{proposed} correspondences and might change
5579 in future versions of @code{g77}---avoid writing code depending
5580 on them while @code{g77}, and therefore the GNU Fortran language
5581 it defines, is in beta testing.
5582
5583 Values not specified in the above list are reserved to
5584 future versions of the GNU Fortran language.
5585
5586 Implementation-dependent meanings will be assigned new,
5587 unique prime numbers so as to not interfere with other
5588 implementation-dependent meanings, and offer the possibility
5589 of increasing the portability of code depending on such
5590 types by offering support for them in other GNU Fortran
5591 implementations.
5592
5593 Other meanings that might be given unique values are:
5594
5595 @itemize @bullet
5596 @item
5597 Types that make use of only half their storage size for
5598 representing precision and range.
5599
5600 For example, some compilers offer options that cause
5601 @code{INTEGER} types to occupy the amount of storage
5602 that would be needed for @code{INTEGER(KIND=2)} types, but the
5603 range remains that of @code{INTEGER(KIND=1)}.
5604
5605 @item
5606 The IEEE single floating-point type.
5607
5608 @item
5609 Types with a specific bit pattern (endianness), such as the
5610 little-endian form of @code{INTEGER(KIND=1)}.
5611 These could permit, conceptually, use of portable code and
5612 implementations on data files written by existing systems.
5613 @end itemize
5614
5615 Future @emph{prime} numbers should be given meanings in as incremental
5616 a fashion as possible, to allow for flexibility and
5617 expressiveness in combining types.
5618
5619 For example, instead of defining a prime number for little-endian
5620 IEEE doubles, one prime number might be assigned the meaning
5621 ``little-endian'', another the meaning ``IEEE double'', and the
5622 value of @var{n} for a little-endian IEEE double would thus
5623 naturally be the product of those two respective assigned values.
5624 (It could even be reasonable to have IEEE values result from the
5625 products of prime values denoting exponent and fraction sizes
5626 and meanings, hidden bit usage, availability and representations
5627 of special values such as subnormals, infinities, and Not-A-Numbers
5628 (NaNs), and so on.)
5629
5630 This assignment mechanism, while not inherently required for
5631 future versions of the GNU Fortran language, is worth using
5632 because it could ease management of the ``space'' of supported
5633 types much easier in the long run.
5634
5635 The above approach suggests a mechanism for specifying inheritance
5636 of intrinsic (built-in) types for an entire, widely portable
5637 product line.
5638 It is certainly reasonable that, unlike programmers of other languages
5639 offering inheritance mechanisms that employ verbose names for classes
5640 and subclasses, along with graphical browsers to elucidate the
5641 relationships, Fortran programmers would employ
5642 a mechanism that works by multiplying prime numbers together
5643 and finding the prime factors of such products.
5644
5645 Most of the advantages for the above scheme have been explained
5646 above.
5647 One disadvantage is that it could lead to the defining,
5648 by the GNU Fortran language, of some fairly large prime numbers.
5649 This could lead to the GNU Fortran language being declared
5650 ``munitions'' by the United States Department of Defense.
5651
5652 @node Constants
5653 @subsection Constants
5654 @cindex constants
5655 @cindex types, constants
5656
5657 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
5658
5659 A @dfn{typeless constant} has one of the following forms:
5660
5661 @smallexample
5662 '@var{binary-digits}'B
5663 '@var{octal-digits}'O
5664 '@var{hexadecimal-digits}'Z
5665 '@var{hexadecimal-digits}'X
5666 @end smallexample
5667
5668 @noindent
5669 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
5670 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
5671 and @samp{0123456789ABCDEFabcdef}, respectively.
5672 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
5673 is 11, and so on.)
5674
5675 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
5676 treated as typeless.  @xref{Fortran Dialect Options,, Options
5677 Controlling Fortran Dialect}, for information on the
5678 @samp{-ftypeless-boz} option.
5679
5680 Typeless constants have values that depend on the context in which
5681 they are used.
5682
5683 All other constants, called @dfn{typed constants}, are interpreted---converted
5684 to internal form---according to their inherent type.
5685 Thus, context is @emph{never} a determining factor for the type, and hence
5686 the interpretation, of a typed constant.
5687 (All constants in the ANSI FORTRAN 77 language are typed constants.)
5688
5689 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
5690 Fortran (called default INTEGER in Fortran 90),
5691 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
5692 additional precision specified is lost, and even when used in a
5693 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
5694 and @samp{1D0} is always type @code{REAL(KIND=2)}.
5695
5696 @node Integer Type
5697 @subsection Integer Type
5698
5699 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
5700
5701 An integer constant also may have one of the following forms:
5702
5703 @smallexample
5704 B'@var{binary-digits}'
5705 O'@var{octal-digits}'
5706 Z'@var{hexadecimal-digits}'
5707 X'@var{hexadecimal-digits}'
5708 @end smallexample
5709
5710 @noindent
5711 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
5712 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
5713 and @samp{0123456789ABCDEFabcdef}, respectively.
5714 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
5715 is 11, and so on.)
5716
5717 @node Character Type
5718 @subsection Character Type
5719
5720 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
5721
5722 @cindex double quoted character constants
5723 A character constant may be delimited by a pair of double quotes
5724 (@samp{"}) instead of apostrophes.
5725 In this case, an apostrophe within the constant represents
5726 a single apostrophe, while a double quote is represented in
5727 the source text of the constant by two consecutive double
5728 quotes with no intervening spaces.
5729
5730 @cindex zero-length CHARACTER
5731 @cindex null CHARACTER strings
5732 @cindex empty CHARACTER strings
5733 @cindex strings, empty
5734 @cindex CHARACTER, null
5735 A character constant may be empty (have a length of zero).
5736
5737 A character constant may include a substring specification,
5738 The value of such a constant is the value of the substring---for
5739 example, the value of @samp{'hello'(3:5)} is the same
5740 as the value of @samp{'llo'}.
5741
5742 @node Expressions
5743 @section Expressions
5744
5745 (The following information augments or overrides the information in
5746 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5747 language.
5748 Chapter 6 of that document otherwise serves as the basis
5749 for the relevant aspects of GNU Fortran.)
5750
5751 @menu
5752 * %LOC()::
5753 @end menu
5754
5755 @node %LOC()
5756 @subsection The @code{%LOC()} Construct
5757 @cindex %LOC() construct
5758
5759 @example
5760 %LOC(@var{arg})
5761 @end example
5762
5763 The @code{%LOC()} construct is an expression
5764 that yields the value of the location of its argument,
5765 @var{arg}, in memory.
5766 The size of the type of the expression depends on the system---typically,
5767 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
5768 though it is actually type @code{INTEGER(KIND=7)}.
5769
5770 The argument to @code{%LOC()} must be suitable as the
5771 left-hand side of an assignment statement.
5772 That is, it may not be a general expression involving
5773 operators such as addition, subtraction, and so on,
5774 nor may it be a constant.
5775
5776 Use of @code{%LOC()} is recommended only for code that
5777 is accessing facilities outside of GNU Fortran, such as
5778 operating system or windowing facilities.
5779 It is best to constrain such uses to isolated portions of
5780 a program---portions that deal specifically and exclusively
5781 with low-level, system-dependent facilities.
5782 Such portions might well provide a portable interface for
5783 use by the program as a whole, but are themselves not
5784 portable, and should be thoroughly tested each time they
5785 are rebuilt using a new compiler or version of a compiler.
5786
5787 Do not depend on @code{%LOC()} returning a pointer that
5788 can be safely used to @emph{define} (change) the argument.
5789 While this might work in some circumstances, it is hard
5790 to predict whether it will continue to work when a program
5791 (that works using this unsafe behavior)
5792 is recompiled using different command-line options or
5793 a different version of @code{g77}.
5794
5795 Generally, @code{%LOC()} is safe when used as an argument
5796 to a procedure that makes use of the value of the corresponding
5797 dummy argument only during its activation, and only when
5798 such use is restricted to referencing (reading) the value
5799 of the argument to @code{%LOC()}.
5800
5801 @emph{Implementation Note:} Currently, @code{g77} passes
5802 arguments (those not passed using a construct such as @code{%VAL()})
5803 by reference or descriptor, depending on the type of
5804 the actual argument.
5805 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
5806 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
5807 in fact might compile to identical code.
5808
5809 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
5810 ``pass, by value, the address of @samp{I} in memory''.
5811 While @samp{CALL FOO(I)} might use that same approach in a
5812 particular version of @code{g77}, another version or compiler
5813 might choose a different implementation, such as copy-in/copy-out,
5814 to effect the desired behavior---and which will therefore not
5815 necessarily compile to the same code as would
5816 @samp{CALL FOO(%VAL(%LOC(I)))}
5817 using the same version or compiler.
5818
5819 @xref{Debugging and Interfacing}, for detailed information on
5820 how this particular version of @code{g77} implements various
5821 constructs.
5822
5823 @node Specification Statements
5824 @section Specification Statements
5825
5826 (The following information augments or overrides the information in
5827 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5828 language.
5829 Chapter 8 of that document otherwise serves as the basis
5830 for the relevant aspects of GNU Fortran.)
5831
5832 @menu
5833 * NAMELIST::
5834 * DOUBLE COMPLEX::
5835 @end menu
5836
5837 @node NAMELIST
5838 @subsection @code{NAMELIST} Statement
5839 @cindex NAMELIST statement
5840 @cindex statements, NAMELIST
5841
5842 The @code{NAMELIST} statement, and related I/O constructs, are
5843 supported by the GNU Fortran language in essentially the same
5844 way as they are by @code{f2c}.
5845
5846 This follows Fortran 90 with the restriction that on @code{NAMELIST}
5847 input, subscripts must have the form
5848 @smallexample
5849 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
5850 @end smallexample
5851 i.e.@:
5852 @smallexample
5853 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
5854 @end smallexample
5855 is allowed, but not, say,
5856 @smallexample
5857 &xx x(:3,8::2)=1,2,3,4,5,6/
5858 @end smallexample
5859
5860 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
5861 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
5862 @smallexample
5863 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
5864 @end smallexample
5865 could be used instead of the example above.
5866
5867 @node DOUBLE COMPLEX
5868 @subsection @code{DOUBLE COMPLEX} Statement
5869 @cindex DOUBLE COMPLEX
5870
5871 @code{DOUBLE COMPLEX} is a type-statement (and type) that
5872 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
5873
5874 @node Control Statements
5875 @section Control Statements
5876
5877 (The following information augments or overrides the information in
5878 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5879 language.
5880 Chapter 11 of that document otherwise serves as the basis
5881 for the relevant aspects of GNU Fortran.)
5882
5883 @menu
5884 * DO WHILE::
5885 * END DO::
5886 * Construct Names::
5887 * CYCLE and EXIT::
5888 @end menu
5889
5890 @node DO WHILE
5891 @subsection DO WHILE
5892 @cindex DO WHILE
5893 @cindex DO
5894 @cindex MIL-STD 1753
5895
5896 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
5897 Fortran 90 standards, is provided by the GNU Fortran language.
5898 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
5899 also supported.
5900
5901 @node END DO
5902 @subsection END DO
5903 @cindex END DO
5904 @cindex MIL-STD 1753
5905
5906 The @code{END DO} statement is provided by the GNU Fortran language.
5907
5908 This statement is used in one of two ways:
5909
5910 @itemize @bullet
5911 @item
5912 The Fortran 90 meaning, in which it specifies the termination
5913 point of a single @code{DO} loop started with a @code{DO} statement
5914 that specifies no termination label.
5915
5916 @item
5917 The MIL-STD 1753 meaning, in which it specifies the termination
5918 point of one or more @code{DO} loops, all of which start with a
5919 @code{DO} statement that specify the label defined for the
5920 @code{END DO} statement.
5921
5922 This kind of @code{END DO} statement is merely a synonym for
5923 @code{CONTINUE}, except it is permitted only when the statement
5924 is labeled and a target of one or more labeled @code{DO} loops.
5925
5926 It is expected that this use of @code{END DO} will be removed from
5927 the GNU Fortran language in the future, though it is likely that
5928 it will long be supported by @code{g77} as a dialect form.
5929 @end itemize
5930
5931 @node Construct Names
5932 @subsection Construct Names
5933 @cindex construct names
5934
5935 The GNU Fortran language supports construct names as defined
5936 by the Fortran 90 standard.
5937 These names are local to the program unit and are defined
5938 as follows:
5939
5940 @smallexample
5941 @var{construct-name}: @var{block-statement}
5942 @end smallexample
5943
5944 @noindent
5945 Here, @var{construct-name} is the construct name itself;
5946 its definition is connoted by the single colon (@samp{:}); and
5947 @var{block-statement} is an @code{IF}, @code{DO},
5948 or @code{SELECT CASE} statement that begins a block.
5949
5950 A block that is given a construct name must also specify the
5951 same construct name in its termination statement:
5952
5953 @example
5954 END @var{block} @var{construct-name}
5955 @end example
5956
5957 @noindent
5958 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
5959 as appropriate.
5960
5961 @node CYCLE and EXIT
5962 @subsection The @code{CYCLE} and @code{EXIT} Statements
5963
5964 @cindex CYCLE statement
5965 @cindex EXIT statement
5966 @cindex statements, CYCLE
5967 @cindex statements, EXIT
5968 The @code{CYCLE} and @code{EXIT} statements specify that
5969 the remaining statements in the current iteration of a
5970 particular active (enclosing) @code{DO} loop are to be skipped.
5971
5972 @code{CYCLE} specifies that these statements are skipped,
5973 but the @code{END DO} statement that marks the end of the
5974 @code{DO} loop be executed---that is, the next iteration,
5975 if any, is to be started.
5976 If the statement marking the end of the @code{DO} loop is
5977 not @code{END DO}---in other words, if the loop is not
5978 a block @code{DO}---the @code{CYCLE} statement does not
5979 execute that statement, but does start the next iteration (if any).
5980
5981 @code{EXIT} specifies that the loop specified by the
5982 @code{DO} construct is terminated.
5983
5984 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
5985 is the innermost enclosing @code{DO} loop when the following
5986 forms are used:
5987
5988 @example
5989 CYCLE
5990 EXIT
5991 @end example
5992
5993 Otherwise, the following forms specify the construct name
5994 of the pertinent @code{DO} loop:
5995
5996 @example
5997 CYCLE @var{construct-name}
5998 EXIT @var{construct-name}
5999 @end example
6000
6001 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
6002 statements.
6003 However, they cannot be easily thought of as @code{GO TO} statements
6004 in obscure cases involving FORTRAN 77 loops.
6005 For example:
6006
6007 @smallexample
6008       DO 10 I = 1, 5
6009       DO 10 J = 1, 5
6010          IF (J .EQ. 5) EXIT
6011       DO 10 K = 1, 5
6012          IF (K .EQ. 3) CYCLE
6013 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
6014 20    CONTINUE
6015 @end smallexample
6016
6017 @noindent
6018 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
6019 above are equivalent to a @code{GO TO} statement to either label
6020 @samp{10} or @samp{20}.
6021
6022 To understand the effect of @code{CYCLE} and @code{EXIT} in the
6023 above fragment, it is helpful to first translate it to its equivalent
6024 using only block @code{DO} loops:
6025
6026 @smallexample
6027       DO I = 1, 5
6028          DO J = 1, 5
6029             IF (J .EQ. 5) EXIT
6030             DO K = 1, 5
6031                IF (K .EQ. 3) CYCLE
6032 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
6033             END DO
6034          END DO
6035       END DO
6036 20    CONTINUE
6037 @end smallexample
6038
6039 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
6040 to @code{GO TO} so they may be more easily understood by programmers
6041 accustomed to FORTRAN coding:
6042
6043 @smallexample
6044       DO I = 1, 5
6045          DO J = 1, 5
6046             IF (J .EQ. 5) GOTO 18
6047             DO K = 1, 5
6048                IF (K .EQ. 3) GO TO 12
6049 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
6050 12          END DO
6051          END DO
6052 18    END DO
6053 20    CONTINUE
6054 @end smallexample
6055
6056 @noindent
6057 Thus, the @code{CYCLE} statement in the innermost loop skips over
6058 the @code{PRINT} statement as it begins the next iteration of the
6059 loop, while the @code{EXIT} statement in the middle loop ends that
6060 loop but @emph{not} the outermost loop.
6061
6062 @node Functions and Subroutines
6063 @section Functions and Subroutines
6064
6065 (The following information augments or overrides the information in
6066 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
6067 language.
6068 Chapter 15 of that document otherwise serves as the basis
6069 for the relevant aspects of GNU Fortran.)
6070
6071 @menu
6072 * %VAL()::
6073 * %REF()::
6074 * %DESCR()::
6075 * Generics and Specifics::
6076 * REAL() and AIMAG() of Complex::
6077 * CMPLX() of DOUBLE PRECISION::
6078 * MIL-STD 1753::
6079 * f77/f2c Intrinsics::
6080 * Table of Intrinsic Functions::
6081 @end menu
6082
6083 @node %VAL()
6084 @subsection The @code{%VAL()} Construct
6085 @cindex %VAL() construct
6086
6087 @example
6088 %VAL(@var{arg})
6089 @end example
6090
6091 The @code{%VAL()} construct specifies that an argument,
6092 @var{arg}, is to be passed by value, instead of by reference
6093 or descriptor.
6094
6095 @code{%VAL()} is restricted to actual arguments in
6096 invocations of external procedures.
6097
6098 Use of @code{%VAL()} is recommended only for code that
6099 is accessing facilities outside of GNU Fortran, such as
6100 operating system or windowing facilities.
6101 It is best to constrain such uses to isolated portions of
6102 a program---portions the deal specifically and exclusively
6103 with low-level, system-dependent facilities.
6104 Such portions might well provide a portable interface for
6105 use by the program as a whole, but are themselves not
6106 portable, and should be thoroughly tested each time they
6107 are rebuilt using a new compiler or version of a compiler.
6108
6109 @emph{Implementation Note:} Currently, @code{g77} passes
6110 all arguments either by reference or by descriptor.
6111
6112 Thus, use of @code{%VAL()} tends to be restricted to cases
6113 where the called procedure is written in a language other
6114 than Fortran that supports call-by-value semantics.
6115 (C is an example of such a language.)
6116
6117 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
6118 for detailed information on
6119 how this particular version of @code{g77} passes arguments
6120 to procedures.
6121
6122 @node %REF()
6123 @subsection The @code{%REF()} Construct
6124 @cindex %REF() construct
6125
6126 @example
6127 %REF(@var{arg})
6128 @end example
6129
6130 The @code{%REF()} construct specifies that an argument,
6131 @var{arg}, is to be passed by reference, instead of by
6132 value or descriptor.
6133
6134 @code{%REF()} is restricted to actual arguments in
6135 invocations of external procedures.
6136
6137 Use of @code{%REF()} is recommended only for code that
6138 is accessing facilities outside of GNU Fortran, such as
6139 operating system or windowing facilities.
6140 It is best to constrain such uses to isolated portions of
6141 a program---portions the deal specifically and exclusively
6142 with low-level, system-dependent facilities.
6143 Such portions might well provide a portable interface for
6144 use by the program as a whole, but are themselves not
6145 portable, and should be thoroughly tested each time they
6146 are rebuilt using a new compiler or version of a compiler.
6147
6148 Do not depend on @code{%REF()} supplying a pointer to the
6149 procedure being invoked.
6150 While that is a likely implementation choice, other
6151 implementation choices are available that preserve Fortran
6152 pass-by-reference semantics without passing a pointer to
6153 the argument, @var{arg}.
6154 (For example, a copy-in/copy-out implementation.)
6155
6156 @emph{Implementation Note:} Currently, @code{g77} passes
6157 all arguments
6158 (other than variables and arrays of type @code{CHARACTER})
6159 by reference.
6160 Future versions of, or dialects supported by, @code{g77} might
6161 not pass @code{CHARACTER} functions by reference.
6162
6163 Thus, use of @code{%REF()} tends to be restricted to cases
6164 where @var{arg} is type @code{CHARACTER} but the called
6165 procedure accesses it via a means other than the method
6166 used for Fortran @code{CHARACTER} arguments.
6167
6168 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
6169 how this particular version of @code{g77} passes arguments
6170 to procedures.
6171
6172 @node %DESCR()
6173 @subsection The @code{%DESCR()} Construct
6174 @cindex %DESCR() construct
6175
6176 @example
6177 %DESCR(@var{arg})
6178 @end example
6179
6180 The @code{%DESCR()} construct specifies that an argument,
6181 @var{arg}, is to be passed by descriptor, instead of by
6182 value or reference.
6183
6184 @code{%DESCR()} is restricted to actual arguments in
6185 invocations of external procedures.
6186
6187 Use of @code{%DESCR()} is recommended only for code that
6188 is accessing facilities outside of GNU Fortran, such as
6189 operating system or windowing facilities.
6190 It is best to constrain such uses to isolated portions of
6191 a program---portions the deal specifically and exclusively
6192 with low-level, system-dependent facilities.
6193 Such portions might well provide a portable interface for
6194 use by the program as a whole, but are themselves not
6195 portable, and should be thoroughly tested each time they
6196 are rebuilt using a new compiler or version of a compiler.
6197
6198 Do not depend on @code{%DESCR()} supplying a pointer
6199 and/or a length passed by value
6200 to the procedure being invoked.
6201 While that is a likely implementation choice, other
6202 implementation choices are available that preserve the
6203 pass-by-reference semantics without passing a pointer to
6204 the argument, @var{arg}.
6205 (For example, a copy-in/copy-out implementation.)
6206 And, future versions of @code{g77} might change the
6207 way descriptors are implemented, such as passing a
6208 single argument pointing to a record containing the
6209 pointer/length information instead of passing that same
6210 information via two arguments as it currently does.
6211
6212 @emph{Implementation Note:} Currently, @code{g77} passes
6213 all variables and arrays of type @code{CHARACTER}
6214 by descriptor.
6215 Future versions of, or dialects supported by, @code{g77} might
6216 pass @code{CHARACTER} functions by descriptor as well.
6217
6218 Thus, use of @code{%DESCR()} tends to be restricted to cases
6219 where @var{arg} is not type @code{CHARACTER} but the called
6220 procedure accesses it via a means similar to the method
6221 used for Fortran @code{CHARACTER} arguments.
6222
6223 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
6224 how this particular version of @code{g77} passes arguments
6225 to procedures.
6226
6227 @node Generics and Specifics
6228 @subsection Generics and Specifics
6229 @cindex generic intrinsics
6230 @cindex intrinsics, generic
6231
6232 The ANSI FORTRAN 77 language defines generic and specific
6233 intrinsics.
6234 In short, the distinctions are:
6235
6236 @itemize @bullet
6237 @item
6238 @emph{Specific} intrinsics have
6239 specific types for their arguments and a specific return
6240 type.
6241
6242 @item
6243 @emph{Generic} intrinsics are treated,
6244 on a case-by-case basis in the program's source code,
6245 as one of several possible specific intrinsics.
6246
6247 Typically, a generic intrinsic has a return type that
6248 is determined by the type of one or more of its arguments.
6249 @end itemize
6250
6251 The GNU Fortran language generalizes these concepts somewhat,
6252 especially by providing intrinsic subroutines and generic
6253 intrinsics that are treated as either a specific intrinsic subroutine
6254 or a specific intrinsic function (e.g. @code{SECOND}).
6255
6256 However, GNU Fortran avoids generalizing this concept to
6257 the point where existing code would be accepted as meaning
6258 something possibly different than what was intended.
6259
6260 For example, @code{ABS} is a generic intrinsic, so all working
6261 code written using @code{ABS} of an @code{INTEGER} argument
6262 expects an @code{INTEGER} return value.
6263 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
6264 argument returns an @code{INTEGER*2} return value.
6265
6266 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
6267 an @code{INTEGER(KIND=1)} argument.
6268 Code that passes something other than an @code{INTEGER(KIND=1)}
6269 argument to @code{IABS} is not valid GNU Fortran code, because
6270 it is not clear what the author intended.
6271
6272 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
6273 is not defined by the GNU Fortran language, because the programmer
6274 might have used that construct to mean any of the following, subtly
6275 different, things:
6276
6277 @itemize @bullet
6278 @item
6279 Convert @samp{J} to @code{INTEGER(KIND=1)} first
6280 (as if @samp{IABS(INT(J))} had been written).
6281
6282 @item
6283 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
6284 (as if @samp{INT(ABS(J))} had been written).
6285
6286 @item
6287 No conversion (as if @samp{ABS(J)} had been written).
6288 @end itemize
6289
6290 The distinctions matter especially when types and values wider than
6291 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
6292 operations performing more ``arithmetic'' than absolute-value, are involved.
6293
6294 The following sample program is not a valid GNU Fortran program, but
6295 might be accepted by other compilers.
6296 If so, the output is likely to be revealing in terms of how a given
6297 compiler treats intrinsics (that normally are specific) when they
6298 are given arguments that do not conform to their stated requirements:
6299
6300 @cindex JCB002 program
6301 @smallexample
6302       PROGRAM JCB002
6303 C Version 1:
6304 C Modified 1999-02-15 (Burley) to delete my email address.
6305 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
6306 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
6307 C
6308 C Version 0:
6309 C Written by James Craig Burley 1997-02-20.
6310 C
6311 C Purpose:
6312 C Determine how compilers handle non-standard IDIM
6313 C on INTEGER*2 operands, which presumably can be
6314 C extrapolated into understanding how the compiler
6315 C generally treats specific intrinsics that are passed
6316 C arguments not of the correct types.
6317 C
6318 C If your compiler implements INTEGER*2 and INTEGER
6319 C as the same type, change all INTEGER*2 below to
6320 C INTEGER*1.
6321 C
6322       INTEGER*2 I0, I4
6323       INTEGER I1, I2, I3
6324       INTEGER*2 ISMALL, ILARGE
6325       INTEGER*2 ITOOLG, ITWO
6326       INTEGER*2 ITMP
6327       LOGICAL L2, L3, L4
6328 C
6329 C Find smallest INTEGER*2 number.
6330 C
6331       ISMALL=0
6332  10   I0 = ISMALL-1
6333       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
6334       ISMALL = I0
6335       GOTO 10
6336  20   CONTINUE
6337 C
6338 C Find largest INTEGER*2 number.
6339 C
6340       ILARGE=0
6341  30   I0 = ILARGE+1
6342       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
6343       ILARGE = I0
6344       GOTO 30
6345  40   CONTINUE
6346 C
6347 C Multiplying by two adds stress to the situation.
6348 C
6349       ITWO = 2
6350 C
6351 C Need a number that, added to -2, is too wide to fit in I*2.
6352 C
6353       ITOOLG = ISMALL
6354 C
6355 C Use IDIM the straightforward way.
6356 C
6357       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
6358 C
6359 C Calculate result for first interpretation.
6360 C
6361       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
6362 C
6363 C Calculate result for second interpretation.
6364 C
6365       ITMP = ILARGE - ISMALL
6366       I3 = (INT (ITMP)) * ITWO + ITOOLG
6367 C
6368 C Calculate result for third interpretation.
6369 C
6370       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
6371 C
6372 C Print results.
6373 C
6374       PRINT *, 'ILARGE=', ILARGE
6375       PRINT *, 'ITWO=', ITWO
6376       PRINT *, 'ITOOLG=', ITOOLG
6377       PRINT *, 'ISMALL=', ISMALL
6378       PRINT *, 'I1=', I1
6379       PRINT *, 'I2=', I2
6380       PRINT *, 'I3=', I3
6381       PRINT *, 'I4=', I4
6382       PRINT *
6383       L2 = (I1 .EQ. I2)
6384       L3 = (I1 .EQ. I3)
6385       L4 = (I1 .EQ. I4)
6386       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
6387          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
6388          STOP
6389       END IF
6390       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
6391          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
6392          STOP
6393       END IF
6394       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
6395          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
6396          STOP
6397       END IF
6398       PRINT *, 'Results need careful analysis.'
6399       END
6400 @end smallexample
6401
6402 No future version of the GNU Fortran language
6403 will likely permit specific intrinsic invocations with wrong-typed
6404 arguments (such as @code{IDIM} in the above example), since
6405 it has been determined that disagreements exist among
6406 many production compilers on the interpretation of
6407 such invocations.
6408 These disagreements strongly suggest that Fortran programmers,
6409 and certainly existing Fortran programs, disagree about the
6410 meaning of such invocations.
6411
6412 The first version of @samp{JCB002} didn't accommodate some compilers'
6413 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
6414 @code{INTEGER*2}.
6415 In such a case, these compilers apparently convert both
6416 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
6417 instead of doing an @code{INTEGER*2} subtraction on the
6418 original values in @samp{I1} and @samp{I2}.
6419
6420 However, the results of the careful analyses done on the outputs
6421 of programs compiled by these various compilers show that they
6422 all implement either @samp{Interp 1} or @samp{Interp 2} above.
6423
6424 Specifically, it is believed that the new version of @samp{JCB002}
6425 above will confirm that:
6426
6427 @itemize @bullet
6428 @item
6429 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
6430 @code{f77} compilers all implement @samp{Interp 1}.
6431
6432 @item
6433 IRIX 5.3 @code{f77} compiler implements @samp{Interp 2}.
6434
6435 @item
6436 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
6437 and IRIX 6.1 @code{f77} compilers all implement @samp{Interp 3}.
6438 @end itemize
6439
6440 If you get different results than the above for the stated
6441 compilers, or have results for other compilers that might be
6442 worth adding to the above list, please let us know the details
6443 (compiler product, version, machine, results, and so on).
6444
6445 @node REAL() and AIMAG() of Complex
6446 @subsection @code{REAL()} and @code{AIMAG()} of Complex
6447 @cindex @code{Real} intrinsic
6448 @cindex intrinsics, @code{Real}
6449 @cindex @code{AImag} intrinsic
6450 @cindex intrinsics, @code{AImag}
6451
6452 The GNU Fortran language disallows @code{REAL(@var{expr})}
6453 and @code{AIMAG(@var{expr})},
6454 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
6455 except when they are used in the following way:
6456
6457 @example
6458 REAL(REAL(@var{expr}))
6459 REAL(AIMAG(@var{expr}))
6460 @end example
6461
6462 @noindent
6463 The above forms explicitly specify that the desired effect
6464 is to convert the real or imaginary part of @var{expr}, which might
6465 be some @code{REAL} type other than @code{REAL(KIND=1)},
6466 to type @code{REAL(KIND=1)},
6467 and have that serve as the value of the expression.
6468
6469 The GNU Fortran language offers clearly named intrinsics to extract the
6470 real and imaginary parts of a complex entity without any
6471 conversion:
6472
6473 @example
6474 REALPART(@var{expr})
6475 IMAGPART(@var{expr})
6476 @end example
6477
6478 To express the above using typical extended FORTRAN 77,
6479 use the following constructs
6480 (when @var{expr} is @code{COMPLEX(KIND=2)}):
6481
6482 @example
6483 DBLE(@var{expr})
6484 DIMAG(@var{expr})
6485 @end example
6486
6487 The FORTRAN 77 language offers no way
6488 to explicitly specify the real and imaginary parts of a complex expression of
6489 arbitrary type, apparently as a result of requiring support for
6490 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
6491 The concepts of converting an expression to type @code{REAL(KIND=1)} and
6492 of extracting the real part of a complex expression were
6493 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
6494 they happened to have the exact same effect in that language
6495 (due to having only one @code{COMPLEX} type).
6496
6497 @emph{Note:} When @samp{-ff90} is in effect,
6498 @code{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
6499 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
6500 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
6501 treated as @samp{REAL(REALPART(@var{expr}))}.
6502
6503 @xref{Ugly Complex Part Extraction}, for more information.
6504
6505 @node CMPLX() of DOUBLE PRECISION
6506 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
6507 @cindex @code{Cmplx} intrinsic
6508 @cindex intrinsics, @code{Cmplx}
6509
6510 In accordance with Fortran 90 and at least some (perhaps all)
6511 other compilers, the GNU Fortran language defines @code{CMPLX()}
6512 as always returning a result that is type @code{COMPLEX(KIND=1)}.
6513
6514 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
6515 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
6516
6517 @example
6518 CMPLX(SNGL(D1), SNGL(D2))
6519 @end example
6520
6521 (It was necessary for Fortran 90 to specify this behavior
6522 for @code{DOUBLE PRECISION} arguments, since that is
6523 the behavior mandated by FORTRAN 77.)
6524
6525 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
6526 which is provided by some FORTRAN 77 compilers to construct
6527 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
6528 operands.
6529 However, this solution does not scale well when more @code{COMPLEX} types
6530 (having various precisions and ranges) are offered by Fortran implementations.
6531
6532 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
6533 an extra argument used to specify the desired kind of complex
6534 result.
6535 However, this solution is somewhat awkward to use, and
6536 @code{g77} currently does not support it.
6537
6538 The GNU Fortran language provides a simple way to build a complex
6539 value out of two numbers, with the precise type of the value
6540 determined by the types of the two numbers (via the usual
6541 type-promotion mechanism):
6542
6543 @example
6544 COMPLEX(@var{real}, @var{imag})
6545 @end example
6546
6547 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
6548 performs no conversion other than to put them together to form a
6549 complex result of the same (complex version of real) type.
6550
6551 @xref{Complex Intrinsic}, for more information.
6552
6553 @node MIL-STD 1753
6554 @subsection MIL-STD 1753 Support
6555 @cindex MIL-STD 1753
6556
6557 The GNU Fortran language includes the MIL-STD 1753 intrinsics
6558 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
6559 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
6560 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
6561
6562 @node f77/f2c Intrinsics
6563 @subsection @code{f77}/@code{f2c} Intrinsics
6564
6565 The bit-manipulation intrinsics supported by traditional
6566 @code{f77} and by @code{f2c} are available in the GNU Fortran language.
6567 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
6568 and @code{XOR}.
6569
6570 Also supported are the intrinsics @code{CDABS},
6571 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
6572 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
6573 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
6574 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
6575 and @code{ZSQRT}.
6576
6577 @node Table of Intrinsic Functions
6578 @subsection Table of Intrinsic Functions
6579 @cindex intrinsics, table of
6580 @cindex table of intrinsics
6581
6582 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
6583
6584 The GNU Fortran language adds various functions, subroutines, types,
6585 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
6586 The complete set of intrinsics supported by the GNU Fortran language
6587 is described below.
6588
6589 Note that a name is not treated as that of an intrinsic if it is
6590 specified in an @code{EXTERNAL} statement in the same program unit;
6591 if a command-line option is used to disable the groups to which
6592 the intrinsic belongs; or if the intrinsic is not named in an
6593 @code{INTRINSIC} statement and a command-line option is used to
6594 hide the groups to which the intrinsic belongs.
6595
6596 So, it is recommended that any reference in a program unit to
6597 an intrinsic procedure that is not a standard FORTRAN 77
6598 intrinsic be accompanied by an appropriate @code{INTRINSIC}
6599 statement in that program unit.
6600 This sort of defensive programming makes it more
6601 likely that an implementation will issue a diagnostic rather
6602 than generate incorrect code for such a reference.
6603
6604 The terminology used below is based on that of the Fortran 90
6605 standard, so that the text may be more concise and accurate:
6606
6607 @itemize @bullet
6608 @item
6609 @code{OPTIONAL} means the argument may be omitted.
6610
6611 @item
6612 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
6613 (generally named @samp{A}) may be specified.
6614
6615 @item
6616 @samp{scalar} means the argument must not be an array (must
6617 be a variable or array element, or perhaps a constant if expressions
6618 are permitted).
6619
6620 @item
6621 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
6622
6623 @item
6624 @code{INTENT(IN)} means the argument must be an expression
6625 (such as a constant or a variable that is defined upon invocation
6626 of the intrinsic).
6627
6628 @item
6629 @code{INTENT(OUT)} means the argument must be definable by the
6630 invocation of the intrinsic (that is, must not be a constant nor
6631 an expression involving operators other than array reference and
6632 substring reference).
6633
6634 @item
6635 @code{INTENT(INOUT)} means the argument must be defined prior to,
6636 and definable by, invocation of the intrinsic (a combination of
6637 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
6638
6639 @item
6640 @xref{Kind Notation}, for an explanation of @code{KIND}.
6641 @end itemize
6642
6643 @ifinfo
6644 (Note that the empty lines appearing in the menu below
6645 are not intentional---they result from a bug in the
6646 GNU @code{makeinfo} program@dots{}a program that, if it
6647 did not exist, would leave this document in far worse shape!)
6648 @end ifinfo
6649
6650 @c The actual documentation for intrinsics comes from
6651 @c intdoc.texi, which in turn is automatically generated
6652 @c from the internal g77 tables in intrin.def _and_ the
6653 @c largely hand-written text in intdoc.h.  So, if you want
6654 @c to change or add to existing documentation on intrinsics,
6655 @c you probably want to edit intdoc.h.
6656 @c
6657 @set familyF77
6658 @set familyGNU
6659 @set familyASC
6660 @set familyMIL
6661 @set familyF90
6662 @clear familyVXT
6663 @clear familyFVZ
6664 @set familyF2C
6665 @set familyF2U
6666 @clear familyBADU77
6667 @include intdoc.texi
6668
6669 @node Scope and Classes of Names
6670 @section Scope and Classes of Symbolic Names
6671 @cindex symbol names, scope and classes
6672 @cindex scope
6673
6674 (The following information augments or overrides the information in
6675 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
6676 language.
6677 Chapter 18 of that document otherwise serves as the basis
6678 for the relevant aspects of GNU Fortran.)
6679
6680 @menu
6681 * Underscores in Symbol Names::
6682 @end menu
6683
6684 @node Underscores in Symbol Names
6685 @subsection Underscores in Symbol Names
6686 @cindex underscore
6687
6688 Underscores (@samp{_}) are accepted in symbol names after the first
6689 character (which must be a letter).
6690
6691 @node I/O
6692 @section I/O
6693
6694 @cindex dollar sign
6695 A dollar sign at the end of an output format specification suppresses
6696 the newline at the end of the output.
6697
6698 @cindex <> edit descriptor
6699 @cindex edit descriptor, <>
6700 Edit descriptors in @code{FORMAT} statements may contain compile-time
6701 @code{INTEGER} constant expressions in angle brackets, such as
6702 @smallexample
6703 10    FORMAT (I<WIDTH>)
6704 @end smallexample
6705
6706 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
6707
6708 These Fortran 90 features are supported:
6709 @itemize @bullet
6710 @item
6711 @cindex FORMAT descriptors
6712 @cindex Z edit descriptor
6713 @cindex edit descriptor, Z
6714 @cindex O edit descriptor
6715 @cindex edit descriptor, O
6716 The @code{O} and @code{Z} edit descriptors are supported for I/O of
6717 integers in octal and hexadecimal formats, respectively.
6718 @item
6719 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6720 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
6721 specifier is supported.
6722 @end itemize
6723
6724 @node Fortran 90 Features
6725 @section Fortran 90 Features
6726 @cindex Fortran 90
6727 @cindex extensions, from Fortran 90
6728
6729 For convenience this section collects a list (probably incomplete) of
6730 the Fortran 90 features supported by the GNU Fortran language, even if
6731 they are documented elsewhere.
6732 @c makeinfo 1.68 objects to the nested parens
6733 @ifnotinfo
6734 @xref{Characters Lines Sequence,,{Characters, Lines, and Execution Sequence}},
6735 @end ifnotinfo
6736 @ifinfo
6737 @xref{Characters Lines Sequence},
6738 @end ifinfo
6739 for information on additional fixed source form lexical issues.  In
6740 addition, the free source form is supported through the
6741 @cindex @samp{-ffree-form}
6742 @samp{-ffree-form} option.  Other Fortran 90 features can be turned on
6743 by the
6744 @cindex @samp{-ff90}
6745 @samp{-ff90} option, @ref{Fortran 90}.  For information on the Fortran
6746 90 intrinsics available @ref{Table of Intrinsic Functions}.
6747
6748 @table @asis
6749 @item Automatic arrays in procedures
6750 @item Character assignments
6751 @cindex character assignments
6752 In character assignments, the variable being assigned may occur on the
6753 right hand side of the assignment.
6754 @item Character strings
6755 @cindex double quoted character constants
6756 Strings may have zero length and substrings of character constants are
6757 permitted.  Character constants may be enclosed in double quotes
6758 (@code{"}) as well as single quotes.  @xref{Character Type}.
6759 @item Construct names
6760 (Symbolic tags on blocks.)  @xref{Construct Names }.
6761 @item @code{CYCLE} and @code{EXIT}
6762 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
6763 @item @code{DOUBLE COMPLEX}
6764 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement
6765 }.
6766 @item @code{DO WHILE}
6767 @xref{DO WHILE}.
6768 @item @code{END} decoration
6769 @xref{Statements}.
6770 @item @code{END DO}
6771 @xref{END DO}.
6772 @item @code{KIND}
6773 @item @code{IMPLICIT NONE}
6774 @item @code{INCLUDE} statements
6775 @xref{INCLUDE}.
6776 @item List-directed and namelist I/O on internal files
6777 @item Binary, octal and hexadecimal constants
6778 These are supported more generally than required by Fortran 90.
6779 @xref{Integer Type}.
6780 @item @samp{O} and @samp{Z} edit descriptors
6781 @item @code{NAMELIST}
6782 @xref{NAMELIST}.
6783 @item @code{OPEN} specifiers
6784 @code{STATUS='REPLACE'} is supported.
6785 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6786 @code{STATUS='SCRATCH'} is supplied.
6787 @item @code{FORMAT} edit descriptors
6788 @cindex FORMAT descriptors
6789 @cindex Z edit descriptor
6790 @cindex edit descriptor, Z
6791 The @code{Z} edit descriptor is supported.
6792 @item Relational operators
6793 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
6794 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
6795 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
6796 @item @code{SELECT CASE}
6797 Not fully implemented.  @xref{SELECT CASE on CHARACTER Type,,
6798 @code{SELECT CASE} on @code{CHARACTER} Type}.
6799 @item Specification statements
6800 A limited subset of the Fortran 90 syntax and semantics for variable
6801 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
6802 (@code{KIND} is of limited usefulness in the absence of the
6803 @code{KIND}-related intrinsics, since these intrinsics permit writing
6804 more widely portable code.)  An example of supported @code{KIND} usage
6805 is:
6806 @smallexample
6807 INTEGER (KIND=1) :: FOO=1, BAR=2
6808 CHARACTER (LEN=3) FOO
6809 @end smallexample
6810 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
6811 @end table
6812
6813 @node Other Dialects
6814 @chapter Other Dialects
6815
6816 GNU Fortran supports a variety of features that are not
6817 considered part of the GNU Fortran language itself, but
6818 are representative of various dialects of Fortran that
6819 @code{g77} supports in whole or in part.
6820
6821 Any of the features listed below might be disallowed by
6822 @code{g77} unless some command-line option is specified.
6823 Currently, some of the features are accepted using the
6824 default invocation of @code{g77}, but that might change
6825 in the future.
6826
6827 @emph{Note: This portion of the documentation definitely needs a lot
6828 of work!}
6829
6830 @menu
6831 * Source Form::       Details of fixed-form and free-form source.
6832 * Trailing Comment::  Use of @samp{/*} to start a comment.
6833 * Debug Line::        Use of @samp{D} in column 1.
6834 * Dollar Signs::      Use of @samp{$} in symbolic names.
6835 * Case Sensitivity::  Uppercase and lowercase in source files.
6836 * VXT Fortran::       @dots{}versus the GNU Fortran language.
6837 * Fortran 90::        @dots{}versus the GNU Fortran language.
6838 * Pedantic Compilation::  Enforcing the standard.
6839 * Distensions::       Misfeatures supported by GNU Fortran.
6840 @end menu
6841
6842 @node Source Form
6843 @section Source Form
6844 @cindex source file format
6845 @cindex source format
6846 @cindex file, source
6847 @cindex source code
6848 @cindex code, source
6849 @cindex fixed form
6850 @cindex free form
6851
6852 GNU Fortran accepts programs written in either fixed form or
6853 free form.
6854
6855 Fixed form
6856 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
6857 allowing tabs) and Fortran 90's fixed form.
6858
6859 Free form corresponds to
6860 Fortran 90's free form (though possibly not entirely up-to-date, and
6861 without complaining about some things that for which Fortran 90 requires
6862 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
6863
6864 The way a Fortran compiler views source files depends entirely on the
6865 implementation choices made for the compiler, since those choices
6866 are explicitly left to the implementation by the published Fortran
6867 standards.
6868 GNU Fortran currently tries to be somewhat like a few popular compilers
6869 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
6870 definition along with more
6871 flexibility offered by command-line options is likely to be offered
6872 in version 0.6.
6873
6874 This section describes how @code{g77} interprets source lines.
6875
6876 @menu
6877 * Carriage Returns::  Carriage returns ignored.
6878 * Tabs::              Tabs converted to spaces.
6879 * Short Lines::       Short lines padded with spaces (fixed-form only).
6880 * Long Lines::        Long lines truncated.
6881 * Ampersands::        Special Continuation Lines.
6882 @end menu
6883
6884 @node Carriage Returns
6885 @subsection Carriage Returns
6886 @cindex carriage returns
6887
6888 Carriage returns (@samp{\r}) in source lines are ignored.
6889 This is somewhat different from @code{f2c}, which seems to treat them as
6890 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
6891 inside such constants.
6892
6893 @node Tabs
6894 @subsection Tabs
6895 @cindex tab character
6896 @cindex horizontal tab
6897
6898 A source line with a @key{TAB} character anywhere in it is treated as
6899 entirely significant---however long it is---instead of ending in
6900 column 72 (for fixed-form source) or 132 (for free-form source).
6901 This also is different from @code{f2c}, which encodes tabs as
6902 @samp{\t} (the ASCII @key{TAB} character) inside character
6903 and Hollerith constants, but nevertheless seems to treat the column
6904 position as if it had been affected by the canonical tab positioning.
6905
6906 @code{g77} effectively
6907 translates tabs to the appropriate number of spaces (a la the default
6908 for the UNIX @code{expand} command) before doing any other processing, other
6909 than (currently) noting whether a tab was found on a line and using this
6910 information to decide how to interpret the length of the line and continued
6911 constants.
6912
6913 Note that this default behavior probably will change for version 0.6,
6914 when it will presumably be available via a command-line option.
6915 The default as of version 0.6 is planned to be a ``pure visual''
6916 model, where tabs are immediately
6917 converted to spaces and otherwise have no effect, so the way a typical
6918 user sees source lines produces a consistent result no matter how the
6919 spacing in those source lines is actually implemented via tabs, spaces,
6920 and trailing tabs/spaces before newline.
6921 Command-line options are likely to be added to specify whether all or
6922 just-tabbed lines are to be extended to 132 or full input-line length,
6923 and perhaps even an option will be added to specify the truncated-line
6924 behavior to which some Digital compilers default (and which affects
6925 the way continued character/Hollerith constants are interpreted).
6926
6927 @node Short Lines
6928 @subsection Short Lines
6929 @cindex short source lines
6930 @cindex space, padding with
6931 @cindex source lines, short
6932 @cindex lines, short
6933
6934 Source lines shorter than the applicable fixed-form length are treated as
6935 if they were padded with spaces to that length.
6936 (None of this is relevant to source files written in free form.)
6937
6938 This affects only
6939 continued character and Hollerith constants, and is a different
6940 interpretation than provided by some other popular compilers
6941 (although a bit more consistent with the traditional punched-card
6942 basis of Fortran and the way the Fortran standard expressed fixed
6943 source form).
6944
6945 @code{g77} might someday offer an option to warn about cases where differences
6946 might be seen as a result of this treatment, and perhaps an option to
6947 specify the alternate behavior as well.
6948
6949 Note that this padding cannot apply to lines that are effectively of
6950 infinite length---such lines are specified using command-line options
6951 like @samp{-ffixed-line-length-none}, for example.
6952
6953 @node Long Lines
6954 @subsection Long Lines
6955 @cindex long source lines
6956 @cindex truncation, of long lines
6957 @cindex lines, long
6958 @cindex source lines, long
6959
6960 Source lines longer than the applicable length are truncated to that
6961 length.
6962 Currently, @code{g77} does not warn if the truncated characters are
6963 not spaces, to accommodate existing code written for systems that
6964 treated truncated text as commentary (especially in columns 73 through 80).
6965
6966 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
6967 for information on the @samp{-ffixed-line-length-@var{n}} option,
6968 which can be used to set the line length applicable to fixed-form
6969 source files.
6970
6971 @node Ampersands
6972 @subsection Ampersand Continuation Line
6973 @cindex ampersand continuation line
6974 @cindex continuation line, ampersand
6975
6976 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
6977 continuation line, imitating the behavior of @code{f2c}.
6978
6979 @node Trailing Comment
6980 @section Trailing Comment
6981
6982 @cindex trailing comment
6983 @cindex comment
6984 @cindex characters, comment
6985 @cindex /*
6986 @cindex !
6987 @cindex exclamation point
6988 @code{g77} supports use of @samp{/*} to start a trailing
6989 comment.
6990 In the GNU Fortran language, @samp{!} is used for this purpose.
6991
6992 @samp{/*} is not in the GNU Fortran language
6993 because the use of @samp{/*} in a program might
6994 suggest to some readers that a block, not trailing, comment is
6995 started (and thus ended by @samp{*/}, not end of line),
6996 since that is the meaning of @samp{/*} in C.
6997
6998 Also, such readers might think they can use @samp{//} to start
6999 a trailing comment as an alternative to @samp{/*}, but
7000 @samp{//} already denotes concatenation, and such a ``comment''
7001 might actually result in a program that compiles without
7002 error (though it would likely behave incorrectly).
7003
7004 @node Debug Line
7005 @section Debug Line
7006 @cindex debug line
7007 @cindex comment line, debug
7008
7009 Use of @samp{D} or @samp{d} as the first character (column 1) of
7010 a source line denotes a debug line.
7011
7012 In turn, a debug line is treated as either a comment line
7013 or a normal line, depending on whether debug lines are enabled.
7014
7015 When treated as a comment line, a line beginning with @samp{D} or
7016 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
7017 When treated as a normal line, such a line is treated as if
7018 the first character was @key{SPC} (space).
7019
7020 (Currently, @code{g77} provides no means for treating debug
7021 lines as normal lines.)
7022
7023 @node Dollar Signs
7024 @section Dollar Signs in Symbol Names
7025 @cindex dollar sign
7026 @cindex $
7027
7028 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
7029 when the @samp{-fdollar-ok} option is specified.
7030
7031 @node Case Sensitivity
7032 @section Case Sensitivity
7033 @cindex case sensitivity
7034 @cindex source file format
7035 @cindex code, source
7036 @cindex source code
7037 @cindex uppercase letters
7038 @cindex lowercase letters
7039 @cindex letters, uppercase
7040 @cindex letters, lowercase
7041
7042 GNU Fortran offers the programmer way too much flexibility in deciding
7043 how source files are to be treated vis-a-vis uppercase and lowercase
7044 characters.
7045 There are 66 useful settings that affect case sensitivity, plus 10
7046 settings that are nearly useless, with the remaining 116 settings
7047 being either redundant or useless.
7048
7049 None of these settings have any effect on the contents of comments
7050 (the text after a @samp{c} or @samp{C} in Column 1, for example)
7051 or of character or Hollerith constants.
7052 Note that things like the @samp{E} in the statement
7053 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
7054 are considered built-in keywords, and so are affected by
7055 these settings.
7056
7057 Low-level switches are identified in this section as follows:
7058
7059 @itemize @w{}
7060 @item A
7061 Source Case Conversion:
7062
7063 @itemize @w{}
7064 @item 0
7065 Preserve (see Note 1)
7066 @item 1
7067 Convert to Upper Case
7068 @item 2
7069 Convert to Lower Case
7070 @end itemize
7071
7072 @item B
7073 Built-in Keyword Matching:
7074
7075 @itemize @w{}
7076 @item 0
7077 Match Any Case (per-character basis)
7078 @item 1
7079 Match Upper Case Only
7080 @item 2
7081 Match Lower Case Only
7082 @item 3
7083 Match InitialCaps Only (see tables for spellings)
7084 @end itemize
7085
7086 @item C
7087 Built-in Intrinsic Matching:
7088
7089 @itemize @w{}
7090 @item 0
7091 Match Any Case (per-character basis)
7092 @item 1
7093 Match Upper Case Only
7094 @item 2
7095 Match Lower Case Only
7096 @item 3
7097 Match InitialCaps Only (see tables for spellings)
7098 @end itemize
7099
7100 @item D
7101 User-defined Symbol Possibilities (warnings only):
7102
7103 @itemize @w{}
7104 @item 0
7105 Allow Any Case (per-character basis)
7106 @item 1
7107 Allow Upper Case Only
7108 @item 2
7109 Allow Lower Case Only
7110 @item 3
7111 Allow InitialCaps Only (see Note 2)
7112 @end itemize
7113 @end itemize
7114
7115 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
7116 consistent with these source switches---in the sense that input will be
7117 expected to meet the same requirements as source code in terms
7118 of matching symbol names and keywords (for the exponent letters).
7119
7120 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
7121 which uppercases @code{NAMELIST} input and symbol names for matching.
7122 This means not only that @code{NAMELIST} output currently shows symbol
7123 (and keyword) names in uppercase even if lower-case source
7124 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
7125 adequately supported when source case preservation (option A0)
7126 is selected.
7127
7128 If A0 is selected, a warning message will be
7129 output for each @code{NAMELIST} statement to this effect.
7130 The behavior
7131 of the program is undefined at run time if two or more symbol names
7132 appear in a given @code{NAMELIST} such that the names are identical
7133 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
7134 For complete and total elegance, perhaps there should be a warning
7135 when option A2 is selected, since the output of NAMELIST is currently
7136 in uppercase but will someday be lowercase (when a @code{libg77} is written),
7137 but that seems to be overkill for a product in beta test.
7138
7139 Note 2: Rules for InitialCaps names are:
7140
7141 @itemize --
7142 @item
7143 Must be a single uppercase letter, @strong{or}
7144 @item
7145 Must start with an uppercase letter and contain at least one
7146 lowercase letter.
7147 @end itemize
7148
7149 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
7150 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
7151 not.
7152 Note that most, but not all, built-in names meet these
7153 requirements---the exceptions are some of the two-letter format
7154 specifiers, such as @samp{BN} and @samp{BZ}.
7155
7156 Here are the names of the corresponding command-line options:
7157
7158 @smallexample
7159 A0: -fsource-case-preserve
7160 A1: -fsource-case-upper
7161 A2: -fsource-case-lower
7162
7163 B0: -fmatch-case-any
7164 B1: -fmatch-case-upper
7165 B2: -fmatch-case-lower
7166 B3: -fmatch-case-initcap
7167
7168 C0: -fintrin-case-any
7169 C1: -fintrin-case-upper
7170 C2: -fintrin-case-lower
7171 C3: -fintrin-case-initcap
7172
7173 D0: -fsymbol-case-any
7174 D1: -fsymbol-case-upper
7175 D2: -fsymbol-case-lower
7176 D3: -fsymbol-case-initcap
7177 @end smallexample
7178
7179 Useful combinations of the above settings, along with abbreviated
7180 option names that set some of these combinations all at once:
7181
7182 @smallexample
7183  1: A0--  B0---  C0---  D0---    -fcase-preserve
7184  2: A0--  B0---  C0---  D-1--
7185  3: A0--  B0---  C0---  D--2-
7186  4: A0--  B0---  C0---  D---3
7187  5: A0--  B0---  C-1--  D0---
7188  6: A0--  B0---  C-1--  D-1--
7189  7: A0--  B0---  C-1--  D--2-
7190  8: A0--  B0---  C-1--  D---3
7191  9: A0--  B0---  C--2-  D0---
7192 10: A0--  B0---  C--2-  D-1--
7193 11: A0--  B0---  C--2-  D--2-
7194 12: A0--  B0---  C--2-  D---3
7195 13: A0--  B0---  C---3  D0---
7196 14: A0--  B0---  C---3  D-1--
7197 15: A0--  B0---  C---3  D--2-
7198 16: A0--  B0---  C---3  D---3
7199 17: A0--  B-1--  C0---  D0---
7200 18: A0--  B-1--  C0---  D-1--
7201 19: A0--  B-1--  C0---  D--2-
7202 20: A0--  B-1--  C0---  D---3
7203 21: A0--  B-1--  C-1--  D0---
7204 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
7205 23: A0--  B-1--  C-1--  D--2-
7206 24: A0--  B-1--  C-1--  D---3
7207 25: A0--  B-1--  C--2-  D0---
7208 26: A0--  B-1--  C--2-  D-1--
7209 27: A0--  B-1--  C--2-  D--2-
7210 28: A0--  B-1--  C--2-  D---3
7211 29: A0--  B-1--  C---3  D0---
7212 30: A0--  B-1--  C---3  D-1--
7213 31: A0--  B-1--  C---3  D--2-
7214 32: A0--  B-1--  C---3  D---3
7215 33: A0--  B--2-  C0---  D0---
7216 34: A0--  B--2-  C0---  D-1--
7217 35: A0--  B--2-  C0---  D--2-
7218 36: A0--  B--2-  C0---  D---3
7219 37: A0--  B--2-  C-1--  D0---
7220 38: A0--  B--2-  C-1--  D-1--
7221 39: A0--  B--2-  C-1--  D--2-
7222 40: A0--  B--2-  C-1--  D---3
7223 41: A0--  B--2-  C--2-  D0---
7224 42: A0--  B--2-  C--2-  D-1--
7225 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
7226 44: A0--  B--2-  C--2-  D---3
7227 45: A0--  B--2-  C---3  D0---
7228 46: A0--  B--2-  C---3  D-1--
7229 47: A0--  B--2-  C---3  D--2-
7230 48: A0--  B--2-  C---3  D---3
7231 49: A0--  B---3  C0---  D0---
7232 50: A0--  B---3  C0---  D-1--
7233 51: A0--  B---3  C0---  D--2-
7234 52: A0--  B---3  C0---  D---3
7235 53: A0--  B---3  C-1--  D0---
7236 54: A0--  B---3  C-1--  D-1--
7237 55: A0--  B---3  C-1--  D--2-
7238 56: A0--  B---3  C-1--  D---3
7239 57: A0--  B---3  C--2-  D0---
7240 58: A0--  B---3  C--2-  D-1--
7241 59: A0--  B---3  C--2-  D--2-
7242 60: A0--  B---3  C--2-  D---3
7243 61: A0--  B---3  C---3  D0---
7244 62: A0--  B---3  C---3  D-1--
7245 63: A0--  B---3  C---3  D--2-
7246 64: A0--  B---3  C---3  D---3    -fcase-initcap
7247 65: A-1-  B01--  C01--  D01--    -fcase-upper
7248 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
7249 @end smallexample
7250
7251 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
7252 (except comments, character constants, and Hollerith strings) must
7253 be entered in uppercase.
7254 Use @samp{-fcase-strict-upper} to specify this
7255 combination.
7256
7257 Number 43 is like Number 22 except all input must be lowercase.  Use
7258 @samp{-fcase-strict-lower} to specify this combination.
7259
7260 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
7261 non-UNIX machines whereby all the source is translated to uppercase.
7262 Use @samp{-fcase-upper} to specify this combination.
7263
7264 Number 66 is the ``canonical'' UNIX model whereby all the source is
7265 translated to lowercase.
7266 Use @samp{-fcase-lower} to specify this combination.
7267
7268 There are a few nearly useless combinations:
7269
7270 @smallexample
7271 67: A-1-  B01--  C01--  D--2-
7272 68: A-1-  B01--  C01--  D---3
7273 69: A-1-  B01--  C--23  D01--
7274 70: A-1-  B01--  C--23  D--2-
7275 71: A-1-  B01--  C--23  D---3
7276 72: A--2  B01--  C0-2-  D-1--
7277 73: A--2  B01--  C0-2-  D---3
7278 74: A--2  B01--  C-1-3  D0-2-
7279 75: A--2  B01--  C-1-3  D-1--
7280 76: A--2  B01--  C-1-3  D---3
7281 @end smallexample
7282
7283 The above allow some programs to be compiled but with restrictions that
7284 make most useful programs impossible: Numbers 67 and 72 warn about
7285 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
7286 Numbers
7287 68 and 73 warn about any user-defined symbol names longer than one
7288 character that don't have at least one non-alphabetic character after
7289 the first;
7290 Numbers 69 and 74 disallow any references to intrinsics;
7291 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
7292 67+69, 68+69, 72+74, and 73+74, respectively.
7293
7294 All redundant combinations are shown in the above tables anyplace
7295 where more than one setting is shown for a low-level switch.
7296 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
7297 The ``proper'' setting in such a case is the one that copies the setting
7298 of switch A---any other setting might slightly reduce the speed of
7299 the compiler, though possibly to an unmeasurable extent.
7300
7301 All remaining combinations are useless in that they prevent successful
7302 compilation of non-null source files (source files with something other
7303 than comments).
7304
7305 @node VXT Fortran
7306 @section VXT Fortran
7307
7308 @cindex VXT extensions
7309 @cindex extensions, VXT
7310 @code{g77} supports certain constructs that
7311 have different meanings in VXT Fortran than they
7312 do in the GNU Fortran language.
7313
7314 Generally, this manual uses the invented term VXT Fortran to refer
7315 VAX FORTRAN (circa v4).
7316 That compiler offered many popular features, though not necessarily
7317 those that are specific to the VAX processor architecture,
7318 the VMS operating system,
7319 or Digital Equipment Corporation's Fortran product line.
7320 (VAX and VMS probably are trademarks of Digital Equipment
7321 Corporation.)
7322
7323 An extension offered by a Digital Fortran product that also is
7324 offered by several other Fortran products for different kinds of
7325 systems is probably going to be considered for inclusion in @code{g77}
7326 someday, and is considered a VXT Fortran feature.
7327
7328 The @samp{-fvxt} option generally specifies that, where
7329 the meaning of a construct is ambiguous (means one thing
7330 in GNU Fortran and another in VXT Fortran), the VXT Fortran
7331 meaning is to be assumed.
7332
7333 @menu
7334 * Double Quote Meaning::  @samp{"2000} as octal constant.
7335 * Exclamation Point::     @samp{!} in column 6.
7336 @end menu
7337
7338 @node Double Quote Meaning
7339 @subsection Meaning of Double Quote
7340 @cindex double quotes
7341 @cindex character constants
7342 @cindex constants, character
7343 @cindex octal constants
7344 @cindex constants, octal
7345
7346 @code{g77} treats double-quote (@samp{"})
7347 as beginning an octal constant of @code{INTEGER(KIND=1)} type
7348 when the @code{-fvxt} option is specified.
7349 The form of this octal constant is
7350
7351 @example
7352 "@var{octal-digits}
7353 @end example
7354
7355 @noindent
7356 where @var{octal-digits} is a nonempty string of characters in
7357 the set @samp{01234567}.
7358
7359 For example, the @code{-fvxt} option permits this:
7360
7361 @example
7362 PRINT *, "20
7363 END
7364 @end example
7365
7366 @noindent
7367 The above program would print the value @samp{16}.
7368
7369 @xref{Integer Type}, for information on the preferred construct
7370 for integer constants specified using GNU Fortran's octal notation.
7371
7372 (In the GNU Fortran language, the double-quote character (@samp{"})
7373 delimits a character constant just as does apostrophe (@samp{'}).
7374 There is no way to allow
7375 both constructs in the general case, since statements like
7376 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
7377
7378 @node Exclamation Point
7379 @subsection Meaning of Exclamation Point in Column 6
7380 @cindex !
7381 @cindex exclamation point
7382 @cindex continuation character
7383 @cindex characters, continuation
7384 @cindex comment character
7385 @cindex characters, comment
7386
7387 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
7388 a fixed-form source file
7389 as a continuation character rather than
7390 as the beginning of a comment
7391 (as it does in any other column)
7392 when the @code{-fvxt} option is specified.
7393
7394 The following program, when run, prints a message indicating
7395 whether it is interpreted according to GNU Fortran (and Fortran 90)
7396 rules or VXT Fortran rules:
7397
7398 @smallexample
7399 C234567  (This line begins in column 1.)
7400       I = 0
7401      !1
7402       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
7403       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
7404       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
7405       END
7406 @end smallexample
7407
7408 (In the GNU Fortran and Fortran 90 languages, exclamation point is
7409 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
7410 marks a line as a continuation line when it appears in column 6.)
7411
7412 @node Fortran 90
7413 @section Fortran 90
7414 @cindex compatibility, Fortran 90
7415 @cindex Fortran 90, compatibility
7416
7417 The GNU Fortran language includes a number of features that are
7418 part of Fortran 90, even when the @samp{-ff90} option is not specified.
7419 The features enabled by @samp{-ff90} are intended to be those that,
7420 when @samp{-ff90} is not specified, would have another
7421 meaning to @code{g77}---usually meaning something invalid in the
7422 GNU Fortran language.
7423
7424 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
7425 to gratuitously reject Fortran 90 constructs.
7426 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
7427 to do that, although its implementation is certainly incomplete at
7428 this point.
7429
7430 When @samp{-ff90} is specified:
7431
7432 @itemize @bullet
7433 @item
7434 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
7435 where @var{expr} is @code{COMPLEX} type,
7436 is the same type as the real part of @var{expr}.
7437
7438 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
7439 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
7440 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
7441 @end itemize
7442
7443 @node Pedantic Compilation
7444 @section Pedantic Compilation
7445 @cindex pedantic compilation
7446 @cindex compilation, pedantic
7447
7448 The @samp{-fpedantic} command-line option specifies that @code{g77}
7449 is to warn about code that is not standard-conforming.
7450 This is useful for finding
7451 some extensions @code{g77} accepts that other compilers might not accept.
7452 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
7453 always imply @samp{-fpedantic}.)
7454
7455 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
7456 for conforming code.
7457 With @samp{-ff90} in force, Fortran 90 is used.
7458
7459 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
7460 and @samp{-fno-f90} are in force are:
7461
7462 @itemize @bullet
7463 @item
7464 Automatic arrays, as in
7465
7466 @example
7467 SUBROUTINE X(N)
7468 REAL A(N)
7469 @dots{}
7470 @end example
7471
7472 @noindent
7473 where @samp{A} is not listed in any @code{ENTRY} statement,
7474 and thus is not a dummy argument.
7475
7476 @item
7477 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
7478
7479 These commas are disallowed by FORTRAN 77, but, while strictly
7480 superfluous, are syntactically elegant,
7481 especially given that commas are required in statements such
7482 as @samp{READ 99, I} and @samp{PRINT *, J}.
7483 Many compilers permit the superfluous commas for this reason.
7484
7485 @item
7486 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
7487
7488 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
7489 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
7490
7491 An example of an implicit use is the expression @samp{C*D},
7492 where @samp{C} is @code{COMPLEX(KIND=1)}
7493 and @samp{D} is @code{DOUBLE PRECISION}.
7494 This expression is prohibited by ANSI FORTRAN 77
7495 because the rules of promotion would suggest that it
7496 produce a @code{DOUBLE COMPLEX} result---a type not
7497 provided for by that standard.
7498
7499 @item
7500 Automatic conversion of numeric
7501 expressions to @code{INTEGER(KIND=1)} in contexts such as:
7502
7503 @itemize --
7504 @item
7505 Array-reference indexes.
7506 @item
7507 Alternate-return values.
7508 @item
7509 Computed @code{GOTO}.
7510 @item
7511 @code{FORMAT} run-time expressions (not yet supported).
7512 @item
7513 Dimension lists in specification statements.
7514 @item
7515 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
7516 @item
7517 Sizes of @code{CHARACTER} entities in specification statements.
7518 @item
7519 Kind types in specification entities (a Fortran 90 feature).
7520 @item
7521 Initial, terminal, and incrementation parameters for implied-@code{DO}
7522 constructs in @code{DATA} statements.
7523 @end itemize
7524
7525 @item
7526 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
7527 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
7528 expressions are disallowed anyway).
7529
7530 @item
7531 Zero-size array dimensions, as in:
7532
7533 @example
7534 INTEGER I(10,20,4:2)
7535 @end example
7536
7537 @item
7538 Zero-length @code{CHARACTER} entities, as in:
7539
7540 @example
7541 PRINT *, ''
7542 @end example
7543
7544 @item
7545 Substring operators applied to character constants and named
7546 constants, as in:
7547
7548 @example
7549 PRINT *, 'hello'(3:5)
7550 @end example
7551
7552 @item
7553 Null arguments passed to statement function, as in:
7554
7555 @example
7556 PRINT *, FOO(,3)
7557 @end example
7558
7559 @item
7560 Disagreement among program units regarding whether a given @code{COMMON}
7561 area is @code{SAVE}d (for targets where program units in a single source
7562 file are ``glued'' together as they typically are for UNIX development
7563 environments).
7564
7565 @item
7566 Disagreement among program units regarding the size of a
7567 named @code{COMMON} block.
7568
7569 @item
7570 Specification statements following first @code{DATA} statement.
7571
7572 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
7573 but not @samp{INTEGER I}.
7574 The @samp{-fpedantic} option disallows both of these.)
7575
7576 @item
7577 Semicolon as statement separator, as in:
7578
7579 @example
7580 CALL FOO; CALL BAR
7581 @end example
7582 @c
7583 @c @item
7584 @c Comma before list of I/O items in @code{WRITE}
7585 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
7586 @c statements, as with @code{READ} (as explained above).
7587
7588 @item
7589 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
7590
7591 @item
7592 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
7593 versa.
7594
7595 @item
7596 Expressions having two arithmetic operators in a row, such
7597 as @samp{X*-Y}.
7598 @end itemize
7599
7600 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
7601 following constructs result in diagnostics:
7602
7603 @itemize @bullet
7604 @item
7605 Use of semicolon as a statement separator on a line
7606 that has an @code{INCLUDE} directive.
7607 @end itemize
7608
7609 @node Distensions
7610 @section Distensions
7611 @cindex distensions
7612 @cindex ugly features
7613 @cindex features, ugly
7614
7615 The @samp{-fugly-*} command-line options determine whether certain
7616 features supported by VAX FORTRAN and other such compilers, but considered
7617 too ugly to be in code that can be changed to use safer and/or more
7618 portable constructs, are accepted.
7619 These are humorously referred to as ``distensions'',
7620 extensions that just plain look ugly in the harsh light of day.
7621
7622 @emph{Note:} The @samp{-fugly} option, which currently serves
7623 as shorthand to enable all of the distensions below, is likely to
7624 be removed in a future version of @code{g77}.
7625 That's because it's likely new distensions will be added that
7626 conflict with existing ones in terms of assigning meaning to
7627 a given chunk of code.
7628 (Also, it's pretty clear that users should not use @samp{-fugly}
7629 as shorthand when the next release of @code{g77} might add a
7630 distension to that that causes their existing code, when recompiled,
7631 to behave differently---perhaps even fail to compile or run
7632 correctly.)
7633
7634 @menu
7635 * Ugly Implicit Argument Conversion::  Disabled via @samp{-fno-ugly-args}.
7636 * Ugly Assumed-Size Arrays::           Enabled via @samp{-fugly-assumed}.
7637 * Ugly Null Arguments::                Enabled via @samp{-fugly-comma}.
7638 * Ugly Complex Part Extraction::       Enabled via @samp{-fugly-complex}.
7639 * Ugly Conversion of Initializers::    Disabled via @samp{-fno-ugly-init}.
7640 * Ugly Integer Conversions::           Enabled via @samp{-fugly-logint}.
7641 * Ugly Assigned Labels::               Enabled via @samp{-fugly-assign}.
7642 @end menu
7643
7644 @node Ugly Implicit Argument Conversion
7645 @subsection Implicit Argument Conversion
7646 @cindex Hollerith constants
7647 @cindex constants, Hollerith
7648
7649 The @samp{-fno-ugly-args} option disables
7650 passing typeless and Hollerith constants as actual arguments
7651 in procedure invocations.
7652 For example:
7653
7654 @example
7655 CALL FOO(4HABCD)
7656 CALL BAR('123'O)
7657 @end example
7658
7659 @noindent
7660 These constructs can be too easily used to create non-portable
7661 code, but are not considered as ``ugly'' as others.
7662 Further, they are widely used in existing Fortran source code
7663 in ways that often are quite portable.
7664 Therefore, they are enabled by default.
7665
7666 @node Ugly Assumed-Size Arrays
7667 @subsection Ugly Assumed-Size Arrays
7668 @cindex arrays, assumed-size
7669 @cindex assumed-size arrays
7670 @cindex DIMENSION X(1)
7671
7672 The @samp{-fugly-assumed} option enables
7673 the treatment of any array with a final dimension specified as @samp{1}
7674 as an assumed-size array, as if @samp{*} had been specified
7675 instead.
7676
7677 For example, @samp{DIMENSION X(1)} is treated as if it
7678 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
7679 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
7680 or @code{ENTRY} statement in the same program unit.
7681
7682 Use an explicit lower bound to avoid this interpretation.
7683 For example, @samp{DIMENSION X(1:1)} is never treated as if
7684 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
7685 Nor is @samp{DIMENSION X(2-1)} affected by this option,
7686 since that kind of expression is unlikely to have been
7687 intended to designate an assumed-size array.
7688
7689 This option is used to prevent warnings being issued about apparent
7690 out-of-bounds reference such as @samp{X(2) = 99}.
7691
7692 It also prevents the array from being used in contexts that
7693 disallow assumed-size arrays, such as @samp{PRINT *,X}.
7694 In such cases, a diagnostic is generated and the source file is
7695 not compiled.
7696
7697 The construct affected by this option is used only in old code
7698 that pre-exists the widespread acceptance of adjustable and assumed-size
7699 arrays in the Fortran community.
7700
7701 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
7702 treated if @samp{X} is listed as a dummy argument only
7703 @emph{after} the @code{DIMENSION} statement (presumably in
7704 an @code{ENTRY} statement).
7705 For example, @samp{-fugly-assumed} has no effect on the
7706 following program unit:
7707
7708 @example
7709 SUBROUTINE X
7710 REAL A(1)
7711 RETURN
7712 ENTRY Y(A)
7713 PRINT *, A
7714 END
7715 @end example
7716
7717 @node Ugly Complex Part Extraction
7718 @subsection Ugly Complex Part Extraction
7719 @cindex complex values
7720 @cindex real part
7721 @cindex imaginary part
7722
7723 The @samp{-fugly-complex} option enables
7724 use of the @code{REAL()} and @code{AIMAG()}
7725 intrinsics with arguments that are
7726 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
7727
7728 With @samp{-ff90} in effect, these intrinsics return
7729 the unconverted real and imaginary parts (respectively)
7730 of their argument.
7731
7732 With @samp{-fno-f90} in effect, these intrinsics convert
7733 the real and imaginary parts to @code{REAL(KIND=1)}, and return
7734 the result of that conversion.
7735
7736 Due to this ambiguity, the GNU Fortran language defines
7737 these constructs as invalid, except in the specific
7738 case where they are entirely and solely passed as an
7739 argument to an invocation of the @code{REAL()} intrinsic.
7740 For example,
7741
7742 @example
7743 REAL(REAL(Z))
7744 @end example
7745
7746 @noindent
7747 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
7748 and @samp{-fno-ugly-complex} is in effect, because the
7749 meaning is clear.
7750
7751 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
7752 is specified, in which case the appropriate interpretation is
7753 chosen and no diagnostic is issued.
7754
7755 @xref{CMPAMBIG}, for information on how to cope with existing
7756 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
7757 with @code{COMPLEX(KIND=2)} arguments.
7758
7759 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
7760 intrinsic, used to extract the real part of a complex expression
7761 without conversion.
7762 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
7763 intrinsic, used to extract the imaginary part of a complex expression
7764 without conversion.
7765
7766 @node Ugly Null Arguments
7767 @subsection Ugly Null Arguments
7768 @cindex trailing comma
7769 @cindex comma, trailing
7770 @cindex characters, comma
7771 @cindex null arguments
7772 @cindex arguments, null
7773
7774 The @samp{-fugly-comma} option enables use of a single trailing comma
7775 to mean ``pass an extra trailing null argument''
7776 in a list of actual arguments to an external procedure,
7777 and use of an empty list of arguments to such a procedure
7778 to mean ``pass a single null argument''.
7779
7780 @cindex omitting arguments
7781 @cindex arguments, omitting
7782 (Null arguments often are used in some procedure-calling
7783 schemes to indicate omitted arguments.)
7784
7785 For example, @samp{CALL FOO(,)} means ``pass
7786 two null arguments'', rather than ``pass one null argument''.
7787 Also, @samp{CALL BAR()} means ``pass one null argument''.
7788
7789 This construct is considered ``ugly'' because it does not
7790 provide an elegant way to pass a single null argument
7791 that is syntactically distinct from passing no arguments.
7792 That is, this construct changes the meaning of code that
7793 makes no use of the construct.
7794
7795 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
7796 and @samp{I = JFUNC()} pass a single null argument, instead
7797 of passing no arguments as required by the Fortran 77 and
7798 90 standards.
7799
7800 @emph{Note:} Many systems gracefully allow the case
7801 where a procedure call passes one extra argument that the
7802 called procedure does not expect.
7803
7804 So, in practice, there might be no difference in
7805 the behavior of a program that does @samp{CALL FOO()}
7806 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
7807 in force as compared to its behavior when compiled
7808 with the default, @samp{-fno-ugly-comma}, in force,
7809 assuming @samp{FOO} and @samp{JFUNC} do not expect any
7810 arguments to be passed.
7811
7812 @node Ugly Conversion of Initializers
7813 @subsection Ugly Conversion of Initializers
7814
7815 The constructs disabled by @samp{-fno-ugly-init} are:
7816
7817 @itemize @bullet
7818 @cindex Hollerith constants
7819 @cindex constants, Hollerith
7820 @item
7821 Use of Hollerith and typeless constants in contexts where they set
7822 initial (compile-time) values for variables, arrays, and named
7823 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
7824 type-declaration statements specifying initial values.
7825
7826 Here are some sample initializations that are disabled by the
7827 @samp{-fno-ugly-init} option:
7828
7829 @example
7830 PARAMETER (VAL='9A304FFE'X)
7831 REAL*8 STRING/8HOUTPUT00/
7832 DATA VAR/4HABCD/
7833 @end example
7834
7835 @cindex character constants
7836 @cindex constants, character
7837 @item
7838 In the same contexts as above, use of character constants to initialize
7839 numeric items and vice versa (one constant per item).
7840
7841 Here are more sample initializations that are disabled by the
7842 @samp{-fno-ugly-init} option:
7843
7844 @example
7845 INTEGER IA
7846 CHARACTER BELL
7847 PARAMETER (IA = 'A')
7848 PARAMETER (BELL = 7)
7849 @end example
7850
7851 @item
7852 Use of Hollerith and typeless constants on the right-hand side
7853 of assignment statements to numeric types, and in other
7854 contexts (such as passing arguments in invocations of
7855 intrinsic procedures and statement functions) that
7856 are treated as assignments to known types (the dummy
7857 arguments, in these cases).
7858
7859 Here are sample statements that are disabled by the
7860 @samp{-fno-ugly-init} option:
7861
7862 @example
7863 IVAR = 4HABCD
7864 PRINT *, IMAX0(2HAB, 2HBA)
7865 @end example
7866 @end itemize
7867
7868 The above constructs, when used,
7869 can tend to result in non-portable code.
7870 But, they are widely used in existing Fortran code in ways
7871 that often are quite portable.
7872 Therefore, they are enabled by default.
7873
7874 @node Ugly Integer Conversions
7875 @subsection Ugly Integer Conversions
7876
7877 The constructs enabled via @samp{-fugly-logint} are:
7878
7879 @itemize @bullet
7880 @item
7881 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
7882 dictated by
7883 context (typically implies nonportable dependencies on how a
7884 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
7885
7886 @item
7887 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
7888 statements.
7889 @end itemize
7890
7891 The above constructs are disabled by default because use
7892 of them tends to lead to non-portable code.
7893 Even existing Fortran code that uses that often turns out
7894 to be non-portable, if not outright buggy.
7895
7896 Some of this is due to differences among implementations as
7897 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
7898 @code{INTEGER} values---Fortran code that assumes a particular
7899 coding is likely to use one of the above constructs, and is
7900 also likely to not work correctly on implementations using
7901 different encodings.
7902
7903 @xref{Equivalence Versus Equality}, for more information.
7904
7905 @node Ugly Assigned Labels
7906 @subsection Ugly Assigned Labels
7907 @cindex ASSIGN statement
7908 @cindex statements, ASSIGN
7909 @cindex assigned labels
7910 @cindex pointers
7911
7912 The @samp{-fugly-assign} option forces @code{g77} to use the
7913 same storage for assigned labels as it would for a normal
7914 assignment to the same variable.
7915
7916 For example, consider the following code fragment:
7917
7918 @example
7919 I = 3
7920 ASSIGN 10 TO I
7921 @end example
7922
7923 @noindent
7924 Normally, for portability and improved diagnostics, @code{g77}
7925 reserves distinct storage for a ``sibling'' of @samp{I}, used
7926 only for @code{ASSIGN} statements to that variable (along with
7927 the corresponding assigned-@code{GOTO} and assigned-@samp{FORMAT}-I/O
7928 statements that reference the variable).
7929
7930 However, some code (that violates the ANSI FORTRAN 77 standard)
7931 attempts to copy assigned labels among variables involved with
7932 @code{ASSIGN} statements, as in:
7933
7934 @example
7935 ASSIGN 10 TO I
7936 ISTATE(5) = I
7937 @dots{}
7938 J = ISTATE(ICUR)
7939 GOTO J
7940 @end example
7941
7942 @noindent
7943 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
7944 is specified on the command-line, ensuring that the value of @code{I}
7945 referenced in the second line is whatever value @code{g77} uses
7946 to designate statement label @samp{10}, so the value may be
7947 copied into the @samp{ISTATE} array, later retrieved into a
7948 variable of the appropriate type (@samp{J}), and used as the target of
7949 an assigned-@code{GOTO} statement.
7950
7951 @emph{Note:} To avoid subtle program bugs,
7952 when @samp{-fugly-assign} is specified,
7953 @code{g77} requires the type of variables
7954 specified in assigned-label contexts
7955 @emph{must} be the same type returned by @code{%LOC()}.
7956 On many systems, this type is effectively the same
7957 as @code{INTEGER(KIND=1)}, while, on others, it is
7958 effectively the same as @code{INTEGER(KIND=2)}.
7959
7960 Do @emph{not} depend on @code{g77} actually writing valid pointers
7961 to these variables, however.
7962 While @code{g77} currently chooses that implementation, it might
7963 be changed in the future.
7964
7965 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
7966 for implementation details on assigned-statement labels.
7967
7968 @node Compiler
7969 @chapter The GNU Fortran Compiler
7970
7971 The GNU Fortran compiler, @code{g77}, supports programs written
7972 in the GNU Fortran language and in some other dialects of Fortran.
7973
7974 Some aspects of how @code{g77} works are universal regardless
7975 of dialect, and yet are not properly part of the GNU Fortran
7976 language itself.
7977 These are described below.
7978
7979 @emph{Note: This portion of the documentation definitely needs a lot
7980 of work!}
7981
7982 @menu
7983 * Compiler Limits::
7984 * Run-time Environment Limits::
7985 * Compiler Types::
7986 * Compiler Constants::
7987 * Compiler Intrinsics::
7988 @end menu
7989
7990 @node Compiler Limits
7991 @section Compiler Limits
7992 @cindex limits, compiler
7993 @cindex compiler limits
7994
7995 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
7996 on lengths of identifiers, number of continuation lines, number of external
7997 symbols in a program, and so on.
7998
7999 @cindex options, -Nl
8000 @cindex -Nl option
8001 @cindex options, -Nx
8002 @cindex -Nx option
8003 @cindex limits, continuation lines
8004 @cindex limits, lengths of names
8005 For example, some other Fortran compiler have an option
8006 (such as @samp{-Nl@var{x}}) to increase the limit on the
8007 number of continuation lines.
8008 Also, some Fortran compilation systems have an option
8009 (such as @samp{-Nx@var{x}}) to increase the limit on the
8010 number of external symbols.
8011
8012 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
8013 no equivalent options, since they do not impose arbitrary
8014 limits in these areas.
8015
8016 @cindex rank, maximum
8017 @cindex maximum rank
8018 @cindex number of dimensions, maximum
8019 @cindex maximum number of dimensions
8020 @cindex limits, rank
8021 @cindex limits, array dimensions
8022 @code{g77} does currently limit the number of dimensions in an array
8023 to the same degree as do the Fortran standards---seven (7).
8024 This restriction might be lifted in a future version.
8025
8026 @node Run-time Environment Limits
8027 @section Run-time Environment Limits
8028 @cindex limits, run-time library
8029 @cindex wraparound
8030
8031 As a portable Fortran implementation,
8032 @code{g77} offers its users direct access to,
8033 and otherwise depends upon,
8034 the underlying facilities of the system
8035 used to build @code{g77},
8036 the system on which @code{g77} itself is used to compile programs,
8037 and the system on which the @code{g77}-compiled program is actually run.
8038 (For most users, the three systems are of the same
8039 type---combination of operating environment and hardware---often
8040 the same physical system.)
8041
8042 The run-time environment for a particular system
8043 inevitably imposes some limits on a program's use
8044 of various system facilities.
8045 These limits vary from system to system.
8046
8047 Even when such limits might be well beyond the
8048 possibility of being encountered on a particular system,
8049 the @code{g77} run-time environment
8050 has certain built-in limits,
8051 usually, but not always, stemming from intrinsics
8052 with inherently limited interfaces.
8053
8054 Currently, the @code{g77} run-time environment
8055 does not generally offer a less-limiting environment
8056 by augmenting the underlying system's own environment.
8057
8058 Therefore, code written in the GNU Fortran language,
8059 while syntactically and semantically portable,
8060 might nevertheless make non-portable assumptions
8061 about the run-time environment---assumptions that
8062 prove to be false for some particular environments.
8063
8064 The GNU Fortran language,
8065 the @code{g77} compiler and run-time environment,
8066 and the @code{g77} documentation
8067 do not yet offer comprehensive portable work-arounds for such limits,
8068 though programmers should be able to
8069 find their own in specific instances.
8070
8071 Not all of the limitations are described in this document.
8072 Some of the known limitations include:
8073
8074 @menu
8075 * Timer Wraparounds::
8076 * Year 2000 (Y2K) Problems::
8077 * Array Size::
8078 * Character-variable Length::
8079 * Year 10000 (Y10K) Problems::
8080 @end menu
8081
8082 @node Timer Wraparounds
8083 @subsection Timer Wraparounds
8084
8085 Intrinsics that return values computed from system timers,
8086 whether elapsed (wall-clock) timers,
8087 process CPU timers,
8088 or other kinds of timers,
8089 are prone to experiencing wrap-around errors
8090 (or returning wrapped-around values from successive calls)
8091 due to insufficient ranges
8092 offered by the underlying system's timers.
8093
8094 @cindex negative time
8095 @cindex short time
8096 @cindex long time
8097 Some of the symptoms of such behaviors include
8098 apparently negative time being computed for a duration,
8099 an extremely short amount of time being computed for a long duration,
8100 and an extremely long amount of time being computed for a short duration.
8101
8102 See the following for intrinsics
8103 known to have potential problems in these areas
8104 on at least some systems:
8105 @ref{CPU_Time Intrinsic},
8106 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
8107 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
8108 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
8109 @ref{Secnds Intrinsic},
8110 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
8111 @ref{System_Clock Intrinsic},
8112 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
8113 @ref{Time8 Intrinsic}.
8114
8115 @node Year 2000 (Y2K) Problems
8116 @subsection Year 2000 (Y2K) Problems
8117 @cindex Y2K compliance
8118 @cindex Year 2000 compliance
8119
8120 While the @code{g77} compiler itself is believed to
8121 be Year-2000 (Y2K) compliant,
8122 some intrinsics are not,
8123 and, potentially, some underlying systems are not,
8124 perhaps rendering some Y2K-compliant intrinsics
8125 non-compliant when used on those particular systems.
8126
8127 Fortran code that uses non-Y2K-compliant intrinsics
8128 (listed below)
8129 is, itself, almost certainly not compliant,
8130 and should be modified to use Y2K-compliant intrinsics instead.
8131
8132 Fortran code that uses no non-Y2K-compliant intrinsics,
8133 but which currently is running on a non-Y2K-compliant system,
8134 can be made more Y2K compliant by compiling and
8135 linking it for use on a new Y2K-compliant system,
8136 such as a new version of an old, non-Y2K-compliant, system.
8137
8138 Currently, information on Y2K and related issues
8139 is being maintained at
8140 @uref{http://www.gnu.org/software/year2000-list.html}.
8141
8142 See the following for intrinsics
8143 known to have potential problems in these areas
8144 on at least some systems:
8145 @ref{Date Intrinsic},
8146 @ref{IDate Intrinsic (VXT)}.
8147
8148 @node Array Size
8149 @subsection Array Size
8150 @cindex limits, array size
8151 @cindex array size
8152
8153 Currently, @code{g77} uses the default @code{INTEGER} type
8154 for array indexes,
8155 which limits the sizes of single-dimension arrays
8156 on systems offering a larger address space
8157 than can be addressed by that type.
8158 (That @code{g77} puts all arrays in memory
8159 could be considered another limitation---it
8160 could use large temporary files---but that decision
8161 is left to the programmer as an implementation choice
8162 by most Fortran implementations.)
8163
8164 @c ??? Investigate this, to offer a more clear statement
8165 @c than the following paragraphs do.  -- burley 1999-02-17
8166 It is not yet clear whether this limitation
8167 never, sometimes, or always applies to the
8168 sizes of multiple-dimension arrays as a whole.
8169
8170 For example, on a system with 64-bit addresses
8171 and 32-bit default @code{INTEGER},
8172 an array with a size greater than can be addressed
8173 by a 32-bit offset
8174 can be declared using multiple dimensions.
8175 Such an array is therefore larger
8176 than a single-dimension array can be,
8177 on the same system.
8178
8179 @cindex limits, multi-dimension arrays
8180 @cindex multi-dimension arrays
8181 @cindex arrays, dimensioning
8182 Whether large multiple-dimension arrays are reliably supported
8183 depends mostly on the @code{gcc} back end (code generator)
8184 used by @code{g77}, and has not yet been fully investigated.
8185
8186 @node Character-variable Length
8187 @subsection Character-variable Length
8188 @cindex limits, on character-variable length
8189 @cindex character-variable length
8190
8191 Currently, @code{g77} uses the default @code{INTEGER} type
8192 for the lengths of @code{CHARACTER} variables
8193 and array elements.
8194
8195 This means that, for example,
8196 a system with a 64-bit address space
8197 and a 32-bit default @code{INTEGER} type
8198 does not, under @code{g77},
8199 support a @code{CHARACTER*@var{n}} declaration
8200 where @var{n} is greater than 2147483647.
8201
8202 @node Year 10000 (Y10K) Problems
8203 @subsection Year 10000 (Y10K) Problems
8204 @cindex Y10K compliance
8205 @cindex Year 10000 compliance
8206
8207 Most intrinsics returning, or computing values based on,
8208 date information are prone to Year-10000 (Y10K) problems,
8209 due to supporting only 4 digits for the year.
8210
8211 See the following for examples:
8212 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
8213 @ref{IDate Intrinsic (UNIX)},
8214 @ref{Time Intrinsic (VXT)},
8215 @ref{Date_and_Time Intrinsic}.
8216
8217 @node Compiler Types
8218 @section Compiler Types
8219 @cindex types, of data
8220 @cindex data types
8221
8222 Fortran implementations have a fair amount of freedom given them by the
8223 standard as far as how much storage space is used and how much precision
8224 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
8225 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
8226 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
8227 Further, many compilers offer so-called @samp{*@var{n}} notation, but
8228 the interpretation of @var{n} varies across compilers and target architectures.
8229
8230 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
8231 and @code{REAL(KIND=1)}
8232 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
8233 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
8234 Further, it requires that @code{COMPLEX(KIND=1)}
8235 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
8236 storage-associated (such as via @code{EQUIVALENCE})
8237 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
8238 corresponds to the real element and @samp{R(2)} to the imaginary
8239 element of the @code{COMPLEX(KIND=1)} variable.
8240
8241 (Few requirements as to precision or ranges of any of these are
8242 placed on the implementation, nor is the relationship of storage sizes of
8243 these types to the @code{CHARACTER} type specified, by the standard.)
8244
8245 @code{g77} follows the above requirements, warning when compiling
8246 a program requires placement of items in memory that contradict the
8247 requirements of the target architecture.
8248 (For example, a program can require placement of a @code{REAL(KIND=2)}
8249 on a boundary that is not an even multiple of its size, but still an
8250 even multiple of the size of a @code{REAL(KIND=1)} variable.
8251 On some target architectures, using the canonical
8252 mapping of Fortran types to underlying architectural types, such
8253 placement is prohibited by the machine definition or
8254 the Application Binary Interface (ABI) in force for
8255 the configuration defined for building @code{gcc} and @code{g77}.
8256 @code{g77} warns about such
8257 situations when it encounters them.)
8258
8259 @code{g77} follows consistent rules for configuring the mapping between Fortran
8260 types, including the @samp{*@var{n}} notation, and the underlying architectural
8261 types as accessed by a similarly-configured applicable version of the
8262 @code{gcc} compiler.
8263 These rules offer a widely portable, consistent Fortran/C
8264 environment, although they might well conflict with the expectations of
8265 users of Fortran compilers designed and written for particular
8266 architectures.
8267
8268 These rules are based on the configuration that is in force for the
8269 version of @code{gcc} built in the same release as @code{g77} (and
8270 which was therefore used to build both the @code{g77} compiler
8271 components and the @code{libg2c} run-time library):
8272
8273 @table @code
8274 @cindex REAL(KIND=1) type
8275 @cindex types, REAL(KIND=1)
8276 @item REAL(KIND=1)
8277 Same as @code{float} type.
8278
8279 @cindex REAL(KIND=2) type
8280 @cindex types, REAL(KIND=2)
8281 @item REAL(KIND=2)
8282 Same as whatever floating-point type that is twice the size
8283 of a @code{float}---usually, this is a @code{double}.
8284
8285 @cindex INTEGER(KIND=1) type
8286 @cindex types, INTEGER(KIND=1)
8287 @item INTEGER(KIND=1)
8288 Same as an integral type that is occupies the same amount
8289 of memory storage as @code{float}---usually, this is either
8290 an @code{int} or a @code{long int}.
8291
8292 @cindex LOGICAL(KIND=1) type
8293 @cindex types, LOGICAL(KIND=1)
8294 @item LOGICAL(KIND=1)
8295 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
8296
8297 @cindex INTEGER(KIND=2) type
8298 @cindex types, INTEGER(KIND=2)
8299 @item INTEGER(KIND=2)
8300 Twice the size, and usually nearly twice the range,
8301 as @code{INTEGER(KIND=1)}---usually, this is either
8302 a @code{long int} or a @code{long long int}.
8303
8304 @cindex LOGICAL(KIND=2) type
8305 @cindex types, LOGICAL(KIND=2)
8306 @item LOGICAL(KIND=2)
8307 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
8308
8309 @cindex INTEGER(KIND=3) type
8310 @cindex types, INTEGER(KIND=3)
8311 @item INTEGER(KIND=3)
8312 Same @code{gcc} type as signed @code{char}.
8313
8314 @cindex LOGICAL(KIND=3) type
8315 @cindex types, LOGICAL(KIND=3)
8316 @item LOGICAL(KIND=3)
8317 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
8318
8319 @cindex INTEGER(KIND=6) type
8320 @cindex types, INTEGER(KIND=6)
8321 @item INTEGER(KIND=6)
8322 Twice the size, and usually nearly twice the range,
8323 as @code{INTEGER(KIND=3)}---usually, this is
8324 a @code{short}.
8325
8326 @cindex LOGICAL(KIND=6) type
8327 @cindex types, LOGICAL(KIND=6)
8328 @item LOGICAL(KIND=6)
8329 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
8330
8331 @cindex COMPLEX(KIND=1) type
8332 @cindex types, COMPLEX(KIND=1)
8333 @item COMPLEX(KIND=1)
8334 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
8335 one for the imaginary part).
8336
8337 @cindex COMPLEX(KIND=2) type
8338 @cindex types, COMPLEX(KIND=2)
8339 @item COMPLEX(KIND=2)
8340 Two @code{REAL(KIND=2)} scalars.
8341
8342 @cindex *@var{n} notation
8343 @item @var{numeric-type}*@var{n}
8344 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
8345 Same as whatever @code{gcc} type occupies @var{n} times the storage
8346 space of a @code{gcc} @code{char} item.
8347
8348 @cindex DOUBLE PRECISION type
8349 @cindex types, DOUBLE PRECISION
8350 @item DOUBLE PRECISION
8351 Same as @code{REAL(KIND=2)}.
8352
8353 @cindex DOUBLE COMPLEX type
8354 @cindex types, DOUBLE COMPLEX
8355 @item DOUBLE COMPLEX
8356 Same as @code{COMPLEX(KIND=2)}.
8357 @end table
8358
8359 Note that the above are proposed correspondences and might change
8360 in future versions of @code{g77}---avoid writing code depending
8361 on them.
8362
8363 Other types supported by @code{g77}
8364 are derived from gcc types such as @code{char}, @code{short},
8365 @code{int}, @code{long int}, @code{long long int}, @code{long double},
8366 and so on.
8367 That is, whatever types @code{gcc} already supports, @code{g77} supports
8368 now or probably will support in a future version.
8369 The rules for the @samp{@var{numeric-type}*@var{n}} notation
8370 apply to these types,
8371 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
8372 assigned in a way that encourages clarity, consistency, and portability.
8373
8374 @node Compiler Constants
8375 @section Compiler Constants
8376 @cindex constants
8377 @cindex types, constants
8378
8379 @code{g77} strictly assigns types to @emph{all} constants not
8380 documented as ``typeless'' (typeless constants including @samp{'1'Z},
8381 for example).
8382 Many other Fortran compilers attempt to assign types to typed constants
8383 based on their context.
8384 This results in hard-to-find bugs, nonportable
8385 code, and is not in the spirit (though it strictly follows the letter)
8386 of the 77 and 90 standards.
8387
8388 @code{g77} might offer, in a future release, explicit constructs by
8389 which a wider variety of typeless constants may be specified, and/or
8390 user-requested warnings indicating places where @code{g77} might differ
8391 from how other compilers assign types to constants.
8392
8393 @xref{Context-Sensitive Constants}, for more information on this issue.
8394
8395 @node Compiler Intrinsics
8396 @section Compiler Intrinsics
8397
8398 @code{g77} offers an ever-widening set of intrinsics.
8399 Currently these all are procedures (functions and subroutines).
8400
8401 Some of these intrinsics are unimplemented, but their names reserved
8402 to reduce future problems with existing code as they are implemented.
8403 Others are implemented as part of the GNU Fortran language, while
8404 yet others are provided for compatibility with other dialects of
8405 Fortran but are not part of the GNU Fortran language.
8406
8407 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
8408 a facility that is simply an extension of the intrinsic groups provided
8409 by the GNU Fortran language.
8410
8411 @menu
8412 * Intrinsic Groups::  How intrinsics are grouped for easy management.
8413 * Other Intrinsics::  Intrinsics other than those in the GNU
8414                        Fortran language.
8415 @end menu
8416
8417 @node Intrinsic Groups
8418 @subsection Intrinsic Groups
8419 @cindex groups of intrinsics
8420 @cindex intrinsics, groups
8421
8422 A given specific intrinsic belongs in one or more groups.
8423 Each group is deleted, disabled, hidden, or enabled
8424 by default or a command-line option.
8425 The meaning of each term follows.
8426
8427 @table @b
8428 @cindex deleted intrinsics
8429 @cindex intrinsics, deleted
8430 @item Deleted
8431 No intrinsics are recognized as belonging to that group.
8432
8433 @cindex disabled intrinsics
8434 @cindex intrinsics, disabled
8435 @item Disabled
8436 Intrinsics are recognized as belonging to the group, but
8437 references to them (other than via the @code{INTRINSIC} statement)
8438 are disallowed through that group.
8439
8440 @cindex hidden intrinsics
8441 @cindex intrinsics, hidden
8442 @item Hidden
8443 Intrinsics in that group are recognized and enabled (if implemented)
8444 @emph{only} if the first mention of the actual name of an intrinsic
8445 in a program unit is in an @code{INTRINSIC} statement.
8446
8447 @cindex enabled intrinsics
8448 @cindex intrinsics, enabled
8449 @item Enabled
8450 Intrinsics in that group are recognized and enabled (if implemented).
8451 @end table
8452
8453 The distinction between deleting and disabling a group is illustrated
8454 by the following example.
8455 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
8456 If group @samp{FGR} is deleted, the following program unit will
8457 successfully compile, because @samp{FOO()} will be seen as a
8458 reference to an external function named @samp{FOO}:
8459
8460 @example
8461 PRINT *, FOO()
8462 END
8463 @end example
8464
8465 @noindent
8466 If group @samp{FGR} is disabled, compiling the above program will produce
8467 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
8468 or, if properly invoked, it is not enabled.
8469 To change the above program so it references an external function @samp{FOO}
8470 instead of the disabled @samp{FOO} intrinsic,
8471 add the following line to the top:
8472
8473 @example
8474 EXTERNAL FOO
8475 @end example
8476
8477 @noindent
8478 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
8479 that group do not exist at all, whereas disabling it tells @code{g77} to
8480 recognize them as (disabled) intrinsics in intrinsic-like contexts.
8481
8482 Hiding a group is like enabling it, but the intrinsic must be first
8483 named in an @code{INTRINSIC} statement to be considered a reference to the
8484 intrinsic rather than to an external procedure.
8485 This might be the ``safest'' way to treat a new group of intrinsics
8486 when compiling old
8487 code, because it allows the old code to be generally written as if
8488 those new intrinsics never existed, but to be changed to use them
8489 by inserting @code{INTRINSIC} statements in the appropriate places.
8490 However, it should be the goal of development to use @code{EXTERNAL}
8491 for all names of external procedures that might be intrinsic names.
8492
8493 If an intrinsic is in more than one group, it is enabled if any of its
8494 containing groups are enabled; if not so enabled, it is hidden if
8495 any of its containing groups are hidden; if not so hidden, it is disabled
8496 if any of its containing groups are disabled; if not so disabled, it is
8497 deleted.
8498 This extra complication is necessary because some intrinsics,
8499 such as @code{IBITS}, belong to more than one group, and hence should be
8500 enabled if any of the groups to which they belong are enabled, and so
8501 on.
8502
8503 The groups are:
8504
8505 @cindex intrinsics, groups of
8506 @cindex groups of intrinsics
8507 @table @code
8508 @cindex @code{badu77} intrinsics group
8509 @item badu77
8510 UNIX intrinsics having inappropriate forms (usually functions that
8511 have intended side effects).
8512
8513 @cindex @code{gnu} intrinsics group
8514 @item gnu
8515 Intrinsics the GNU Fortran language supports that are extensions to
8516 the Fortran standards (77 and 90).
8517
8518 @cindex @code{f2c} intrinsics group
8519 @item f2c
8520 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
8521
8522 @cindex @code{f90} intrinsics group
8523 @item f90
8524 Fortran 90 intrinsics.
8525
8526 @cindex @code{mil} intrinsics group
8527 @item mil
8528 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
8529
8530 @cindex @code{mil} intrinsics group
8531 @item unix
8532 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
8533
8534 @cindex @code{mil} intrinsics group
8535 @item vxt
8536 VAX/VMS FORTRAN (current as of v4) intrinsics.
8537 @end table
8538
8539 @node Other Intrinsics
8540 @subsection Other Intrinsics
8541 @cindex intrinsics, others
8542 @cindex other intrinsics
8543
8544 @code{g77} supports intrinsics other than those in the GNU Fortran
8545 language proper.
8546 This set of intrinsics is described below.
8547
8548 @ifinfo
8549 (Note that the empty lines appearing in the menu below
8550 are not intentional---they result from a bug in the
8551 @code{makeinfo} program.)
8552 @end ifinfo
8553
8554 @c The actual documentation for intrinsics comes from
8555 @c intdoc.texi, which in turn is automatically generated
8556 @c from the internal g77 tables in intrin.def _and_ the
8557 @c largely hand-written text in intdoc.h.  So, if you want
8558 @c to change or add to existing documentation on intrinsics,
8559 @c you probably want to edit intdoc.h.
8560 @c
8561 @clear familyF77
8562 @clear familyGNU
8563 @clear familyASC
8564 @clear familyMIL
8565 @clear familyF90
8566 @set familyVXT
8567 @set familyFVZ
8568 @clear familyF2C
8569 @clear familyF2U
8570 @set familyBADU77
8571 @include intdoc.texi
8572
8573 @node Other Compilers
8574 @chapter Other Compilers
8575
8576 An individual Fortran source file can be compiled to
8577 an object (@file{*.o}) file instead of to the final
8578 program executable.
8579 This allows several portions of a program to be compiled
8580 at different times and linked together whenever a new
8581 version of the program is needed.
8582 However, it introduces the issue of @dfn{object compatibility}
8583 across the various object files (and libraries, or @file{*.a}
8584 files) that are linked together to produce any particular
8585 executable file.
8586
8587 Object compatibility is an issue when combining, in one
8588 program, Fortran code compiled by more than one compiler
8589 (or more than one configuration of a compiler).
8590 If the compilers
8591 disagree on how to transform the names of procedures, there
8592 will normally be errors when linking such programs.
8593 Worse, if the compilers agree on naming, but disagree on issues
8594 like how to pass parameters, return arguments, and lay out
8595 @code{COMMON} areas, the earliest detected errors might be the
8596 incorrect results produced by the program (and that assumes
8597 these errors are detected, which is not always the case).
8598
8599 Normally, @code{g77} generates code that is
8600 object-compatible with code generated by a version of
8601 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
8602 to be generally compatible with @code{g77} as built by @code{gcc}.
8603 (Normally, @code{f2c} will, by default, conform to the appropriate
8604 configuration, but it is possible that older or perhaps even newer
8605 versions of @code{f2c}, or versions having certain configuration changes
8606 to @code{f2c} internals, will produce object files that are
8607 incompatible with @code{g77}.)
8608
8609 For example, a Fortran string subroutine
8610 argument will become two arguments on the C side: a @code{char *}
8611 and an @code{int} length.
8612
8613 Much of this compatibility results from the fact that
8614 @code{g77} uses the same run-time library,
8615 @code{libf2c}, used by @code{f2c},
8616 though @code{g77} gives its version the name @code{libg2c}
8617 so as to avoid conflicts when linking,
8618 installing them in the same directories,
8619 and so on.
8620
8621 Other compilers might or might not generate code that
8622 is object-compatible with @code{libg2c} and current @code{g77},
8623 and some might offer such compatibility only when explicitly
8624 selected via a command-line option to the compiler.
8625
8626 @emph{Note: This portion of the documentation definitely needs a lot
8627 of work!}
8628
8629 @menu
8630 * Dropping f2c Compatibility::  When speed is more important.
8631 * Compilers Other Than f2c::    Interoperation with code from other compilers.
8632 @end menu
8633
8634 @node Dropping f2c Compatibility
8635 @section Dropping @code{f2c} Compatibility
8636
8637 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
8638 some cases, faster code, by not needing to allow to the possibility
8639 of linking with code compiled by @code{f2c}.
8640
8641 For example, this affects how @code{REAL(KIND=1)},
8642 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
8643 With @samp{-fno-f2c}, they are
8644 compiled as returning the appropriate @code{gcc} type
8645 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
8646 in many configurations).
8647
8648 With @samp{-ff2c} in force, they
8649 are compiled differently (with perhaps slower run-time performance)
8650 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
8651 C as an intermediate language---@code{REAL(KIND=1)} functions
8652 return C's @code{double} type, while @code{COMPLEX} functions return
8653 @code{void} and use an extra argument pointing to a place for the functions to
8654 return their values.
8655
8656 It is possible that, in some cases, leaving @samp{-ff2c} in force
8657 might produce faster code than using @samp{-fno-f2c}.
8658 Feel free to experiment, but remember to experiment with changing the way
8659 @emph{entire programs and their Fortran libraries are compiled} at
8660 a time, since this sort of experimentation affects the interface
8661 of code generated for a Fortran source file---that is, it affects
8662 object compatibility.
8663
8664 Note that @code{f2c} compatibility is a fairly static target to achieve,
8665 though not necessarily perfectly so, since, like @code{g77}, it is
8666 still being improved.
8667 However, specifying @samp{-fno-f2c} causes @code{g77}
8668 to generate code that will probably be incompatible with code
8669 generated by future versions of @code{g77} when the same option
8670 is in force.
8671 You should make sure you are always able to recompile complete
8672 programs from source code when upgrading to new versions of @code{g77}
8673 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
8674
8675 Therefore, if you are using @code{g77} to compile libraries and other
8676 object files for possible future use and you don't want to require
8677 recompilation for future use with subsequent versions of @code{g77},
8678 you might want to stick with @code{f2c} compatibility for now, and
8679 carefully watch for any announcements about changes to the
8680 @code{f2c}/@code{libf2c} interface that might affect existing programs
8681 (thus requiring recompilation).
8682
8683 It is probable that a future version of @code{g77} will not,
8684 by default, generate object files compatible with @code{f2c},
8685 and that version probably would no longer use @code{libf2c}.
8686 If you expect to depend on this compatibility in the
8687 long term, use the options @samp{-ff2c -ff2c-library} when compiling
8688 all of the applicable code.
8689 This should cause future versions of @code{g77} either to produce
8690 compatible code (at the expense of the availability of some features and
8691 performance), or at the very least, to produce diagnostics.
8692
8693 (The library @code{g77} produces will no longer be named @file{libg2c}
8694 when it is no longer generally compatible with @file{libf2c}.
8695 It will likely be referred to, and, if installed as a distinct
8696 library, named @code{libg77}, or some other as-yet-unused name.)
8697
8698 @node Compilers Other Than f2c
8699 @section Compilers Other Than @code{f2c}
8700
8701 On systems with Fortran compilers other than @code{f2c} and @code{g77},
8702 code compiled by @code{g77} is not expected to work
8703 well with code compiled by the native compiler.
8704 (This is true for @code{f2c}-compiled objects as well.)
8705 Libraries compiled with the native compiler probably will have
8706 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
8707
8708 Reasons for such incompatibilities include:
8709
8710 @itemize @bullet
8711 @item
8712 There might be differences in the way names of Fortran procedures
8713 are translated for use in the system's object-file format.
8714 For example, the statement @samp{CALL FOO} might be compiled
8715 by @code{g77} to call a procedure the linker @code{ld} sees
8716 given the name @samp{_foo_}, while the apparently corresponding
8717 statement @samp{SUBROUTINE FOO} might be compiled by the
8718 native compiler to define the linker-visible name @samp{_foo},
8719 or @samp{_FOO_}, and so on.
8720
8721 @item
8722 There might be subtle type mismatches which cause subroutine arguments
8723 and function return values to get corrupted.
8724
8725 This is why simply getting @code{g77} to
8726 transform procedure names the same way a native
8727 compiler does is not usually a good idea---unless
8728 some effort has been made to ensure that, aside
8729 from the way the two compilers transform procedure
8730 names, everything else about the way they generate
8731 code for procedure interfaces is identical.
8732
8733 @item
8734 Native compilers
8735 use libraries of private I/O routines which will not be available
8736 at link time unless you have the native compiler---and you would
8737 have to explicitly ask for them.
8738
8739 For example, on the Sun you
8740 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
8741 command.
8742 @end itemize
8743
8744 @node Other Languages
8745 @chapter Other Languages
8746
8747 @emph{Note: This portion of the documentation definitely needs a lot
8748 of work!}
8749
8750 @menu
8751 * Interoperating with C and C++::
8752 @end menu
8753
8754 @node Interoperating with C and C++
8755 @section Tools and advice for interoperating with C and C++
8756
8757 @cindex C, linking with
8758 @cindex C++, linking with
8759 @cindex linking with C
8760 The following discussion assumes that you are running @code{g77} in @code{f2c}
8761 compatibility mode, i.e.@: not using @samp{-fno-f2c}.
8762 It provides some
8763 advice about quick and simple techniques for linking Fortran and C (or
8764 C++), the most common requirement.
8765 For the full story consult the
8766 description of code generation.
8767 @xref{Debugging and Interfacing}.
8768
8769 When linking Fortran and C, it's usually best to use @code{g77} to do
8770 the linking so that the correct libraries are included (including the
8771 maths one).
8772 If you're linking with C++ you will want to add
8773 @samp{-lstdc++}, @samp{-lg++} or whatever.
8774 If you need to use another
8775 driver program (or @code{ld} directly),
8776 you can find out what linkage
8777 options @code{g77} passes by running @samp{g77 -v}.
8778
8779 @menu
8780 * C Interfacing Tools::
8781 * C Access to Type Information::
8782 * f2c Skeletons and Prototypes::
8783 * C++ Considerations::
8784 * Startup Code::
8785 @end menu
8786
8787 @node C Interfacing Tools
8788 @subsection C Interfacing Tools
8789 @pindex f2c
8790 @cindex cfortran.h
8791 @cindex Netlib
8792 Even if you don't actually use it as a compiler, @samp{f2c} from
8793 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
8794 interfacing (linking) Fortran and C@.
8795 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
8796
8797 To use @code{f2c} for this purpose you only need retrieve and
8798 build the @file{src} directory from the distribution, consult the
8799 @file{README} instructions there for machine-specifics, and install the
8800 @code{f2c} program on your path.
8801
8802 Something else that might be useful is @samp{cfortran.h} from
8803 @uref{ftp://zebra/desy.de/cfortran}.
8804 This is a fairly general tool which
8805 can be used to generate interfaces for calling in both directions
8806 between Fortran and C@.
8807 It can be used in @code{f2c} mode with
8808 @code{g77}---consult its documentation for details.
8809
8810 @node C Access to Type Information
8811 @subsection Accessing Type Information in C
8812
8813 @cindex types, Fortran/C
8814 Generally, C code written to link with
8815 @code{g77} code---calling and/or being
8816 called from Fortran---should @samp{#include <g2c.h>} to define the C
8817 versions of the Fortran types.
8818 Don't assume Fortran @code{INTEGER} types
8819 correspond to C @samp{int}s, for instance; instead, declare them as
8820 @code{integer}, a type defined by @file{g2c.h}.
8821 @file{g2c.h} is installed where @code{gcc} will find it by
8822 default, assuming you use a copy of @code{gcc} compatible with
8823 @code{g77}, probably built at the same time as @code{g77}.
8824
8825 @node f2c Skeletons and Prototypes
8826 @subsection Generating Skeletons and Prototypes with @code{f2c}
8827
8828 @pindex f2c
8829 @cindex -fno-second-underscore
8830 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@: to
8831 interface with an existing library---is to write a file (named, for
8832 example, @file{fred.f}) of dummy Fortran
8833 skeletons comprising just the declaration of the routine(s) and dummy
8834 arguments plus @samp{END} statements.
8835 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
8836 into which you can edit
8837 useful code, confident the calling sequence is correct, at least.
8838 (There are some errors otherwise commonly made in generating C
8839 interfaces with @code{f2c} conventions,
8840 such as not using @code{doublereal}
8841 as the return type of a @code{REAL} @code{FUNCTION}.)
8842
8843 @pindex ftnchek
8844 @code{f2c} also can help with calling Fortran from C, using its
8845 @samp{-P} option to generate C prototypes appropriate for calling the
8846 Fortran.@footnote{The files generated like this can also be used for
8847 inter-unit consistency checking of dummy and actual arguments, although
8848 the @samp{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
8849 or @uref{ftp://ftp.dsm.fordham.edu} is
8850 probably better for this purpose.}
8851 If the Fortran code containing any
8852 routines to be called from C is in file @file{joe.f}, use the command
8853 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
8854 prototype information.
8855 @code{#include} this in the C which has to call
8856 the Fortran routines to make sure you get it right.
8857
8858 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
8859 between the way Fortran (including compilers like @code{g77}) and
8860 C handle arrays.
8861
8862 @node C++ Considerations
8863 @subsection C++ Considerations
8864
8865 @cindex C++
8866 @code{f2c} can be used to generate suitable code for compilation with a
8867 C++ system using the @samp{-C++} option.
8868 The important thing about linking @code{g77}-compiled
8869 code with C++ is that the prototypes for the @code{g77}
8870 routines must specify C linkage to avoid name mangling.
8871 So, use an @samp{extern "C"} declaration.
8872 @code{f2c}'s @samp{-C++} option will take care
8873 of this when generating skeletons or prototype files as above, and also
8874 avoid clashes with C++ reserved words in addition to those in C@.
8875
8876 @node Startup Code
8877 @subsection Startup Code
8878
8879 @cindex startup code
8880 @cindex run-time, initialization
8881 @cindex initialization, run-time
8882 Unlike with some runtime systems,
8883 it shouldn't be necessary
8884 (unless there are bugs)
8885 to use a Fortran main program unit to ensure the
8886 runtime---specifically the I/O system---is initialized.
8887
8888 However, to use the @code{g77} intrinsics @code{GETARG} and @code{IARGC},
8889 either the @code{main} routine from the @file{libg2c} library must be used,
8890 or the @code{f_setarg} routine
8891 (new as of @code{egcs} version 1.1 and @code{g77} version 0.5.23)
8892 must be called with the appropriate @code{argc} and @code{argv} arguments
8893 prior to the program calling @code{GETARG} or @code{IARGC}.
8894
8895 To provide more flexibility for mixed-language programming
8896 involving @code{g77} while allowing for shared libraries,
8897 as of @code{egcs} version 1.1 and @code{g77} version 0.5.23,
8898 @code{g77}'s @code{main} routine in @code{libg2c}
8899 does the following, in order:
8900
8901 @enumerate
8902 @item
8903 Calls @code{f_setarg}
8904 with the incoming @code{argc} and @code{argv} arguments,
8905 in the same order as for @code{main} itself.
8906
8907 This sets up the command-line environment
8908 for @code{GETARG} and @code{IARGC}.
8909
8910 @item
8911 Calls @code{f_setsig} (with no arguments).
8912
8913 This sets up the signaling and exception environment.
8914
8915 @item
8916 Calls @code{f_init} (with no arguments).
8917
8918 This initializes the I/O environment,
8919 though that should not be necessary,
8920 as all I/O functions in @code{libf2c}
8921 are believed to call @code{f_init} automatically,
8922 if necessary.
8923
8924 (A future version of @code{g77} might skip this explicit step,
8925 to speed up normal exit of a program.)
8926
8927 @item
8928 Arranges for @code{f_exit} to be called (with no arguments)
8929 when the program exits.
8930
8931 This ensures that the I/O environment is properly shut down
8932 before the program exits normally.
8933 Otherwise, output buffers might not be fully flushed,
8934 scratch files might not be deleted, and so on.
8935
8936 The simple way @code{main} does this is
8937 to call @code{f_exit} itself after calling
8938 @code{MAIN__} (in the next step).
8939
8940 However, this does not catch the cases where the program
8941 might call @code{exit} directly,
8942 instead of using the @code{EXIT} intrinsic
8943 (implemented as @code{exit_} in @code{libf2c}).
8944
8945 So, @code{main} attempts to use
8946 the operating environment's @code{onexit} or @code{atexit}
8947 facility, if available,
8948 to cause @code{f_exit} to be called automatically
8949 upon any invocation of @code{exit}.
8950
8951 @item
8952 Calls @code{MAIN__} (with no arguments).
8953
8954 This starts executing the Fortran main program unit for
8955 the application.
8956 (Both @code{g77} and @code{f2c} currently compile a main
8957 program unit so that its global name is @code{MAIN__}.)
8958
8959 @item
8960 If no @code{onexit} or @code{atexit} is provided by the system,
8961 calls @code{f_exit}.
8962
8963 @item
8964 Calls @code{exit} with a zero argument,
8965 to signal a successful program termination.
8966
8967 @item
8968 Returns a zero value to the caller,
8969 to signal a successful program termination,
8970 in case @code{exit} doesn't exit on the system.
8971 @end enumerate
8972
8973 All of the above names are C @code{extern} names,
8974 i.e.@: not mangled.
8975
8976 When using the @code{main} procedure provided by @code{g77}
8977 without a Fortran main program unit,
8978 you need to provide @code{MAIN__}
8979 as the entry point for your C code.
8980 (Make sure you link the object file that defines that
8981 entry point with the rest of your program.)
8982
8983 To provide your own @code{main} procedure
8984 in place of @code{g77}'s,
8985 make sure you specify the object file defining that procedure
8986 @emph{before} @samp{-lg2c} on the @code{g77} command line.
8987 Since the @samp{-lg2c} option is implicitly provided,
8988 this is usually straightforward.
8989 (Use the @samp{--verbose} option to see how and where
8990 @code{g77} implicitly adds @samp{-lg2c} in a command line
8991 that will link the program.
8992 Feel free to specify @samp{-lg2c} explicitly,
8993 as appropriate.)
8994
8995 However, when providing your own @code{main},
8996 make sure you perform the appropriate tasks in the
8997 appropriate order.
8998 For example, if your @code{main} does not call @code{f_setarg},
8999 make sure the rest of your application does not call
9000 @code{GETARG} or @code{IARGC}.
9001
9002 And, if your @code{main} fails to ensure that @code{f_exit}
9003 is called upon program exit,
9004 some files might end up incompletely written,
9005 some scratch files might be left lying around,
9006 and some existing files being written might be left
9007 with old data not properly truncated at the end.
9008
9009 Note that, generally, the @code{g77} operating environment
9010 does not depend on a procedure named @code{MAIN__} actually
9011 being called prior to any other @code{g77}-compiled code.
9012 That is, @code{MAIN__} does not, itself,
9013 set up any important operating-environment characteristics
9014 upon which other code might depend.
9015 This might change in future versions of @code{g77},
9016 with appropriate notification in the release notes.
9017
9018 For more information, consult the source code for the above routines.
9019 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
9020 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
9021
9022 Also, the file @file{@value{path-g77}/com.c} contains the code @code{g77}
9023 uses to open-code (inline) references to @code{IARGC}.
9024
9025 @include g77install.texi
9026
9027 @node Debugging and Interfacing
9028 @chapter Debugging and Interfacing
9029 @cindex debugging
9030 @cindex interfacing
9031 @cindex calling C routines
9032 @cindex C routines calling Fortran
9033 @cindex f2c compatibility
9034
9035 GNU Fortran currently generates code that is object-compatible with
9036 the @code{f2c} converter.
9037 Also, it avoids limitations in the current GBE, such as the
9038 inability to generate a procedure with
9039 multiple entry points, by generating code that is structured
9040 differently (in terms of procedure names, scopes, arguments, and
9041 so on) than might be expected.
9042
9043 As a result, writing code in other languages that calls on, is
9044 called by, or shares in-memory data with @code{g77}-compiled code generally
9045 requires some understanding of the way @code{g77} compiles code for
9046 various constructs.
9047
9048 Similarly, using a debugger to debug @code{g77}-compiled
9049 code, even if that debugger supports native Fortran debugging, generally
9050 requires this sort of information.
9051
9052 This section describes some of the basic information on how
9053 @code{g77} compiles code for constructs involving interfaces to other
9054 languages and to debuggers.
9055
9056 @emph{Caution:} Much or all of this information pertains to only the current
9057 release of @code{g77}, sometimes even to using certain compiler options
9058 with @code{g77} (such as @samp{-fno-f2c}).
9059 Do not write code that depends on this
9060 information without clearly marking said code as nonportable and
9061 subject to review for every new release of @code{g77}.
9062 This information
9063 is provided primarily to make debugging of code generated by this
9064 particular release of @code{g77} easier for the user, and partly to make
9065 writing (generally nonportable) interface code easier.
9066 Both of these
9067 activities require tracking changes in new version of @code{g77} as they
9068 are installed, because new versions can change the behaviors
9069 described in this section.
9070
9071 @menu
9072 * Main Program Unit::  How @code{g77} compiles a main program unit.
9073 * Procedures::         How @code{g77} constructs parameter lists
9074                        for procedures.
9075 * Functions::          Functions returning floating-point or character data.
9076 * Names::              Naming of user-defined variables, procedures, etc.
9077 * Common Blocks::      Accessing common variables while debugging.
9078 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
9079 * Complex Variables::  How @code{g77} performs complex arithmetic.
9080 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
9081 * Adjustable Arrays::  Special consideration for adjustable arrays.
9082 * Alternate Entry Points::  How @code{g77} implements alternate @code{ENTRY}.
9083 * Alternate Returns::  How @code{g77} handles alternate returns.
9084 * Assigned Statement Labels::  How @code{g77} handles @code{ASSIGN}.
9085 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
9086 @end menu
9087
9088 @node Main Program Unit
9089 @section Main Program Unit (PROGRAM)
9090 @cindex PROGRAM statement
9091 @cindex statements, PROGRAM
9092
9093 When @code{g77} compiles a main program unit, it gives it the public
9094 procedure name @samp{MAIN__}.
9095 The @code{libg2c} library has the actual @code{main()} procedure
9096 as is typical of C-based environments, and
9097 it is this procedure that performs some initial start-up
9098 activity and then calls @samp{MAIN__}.
9099
9100 Generally, @code{g77} and @code{libg2c} are designed so that you need not
9101 include a main program unit written in Fortran in your program---it
9102 can be written in C or some other language.
9103 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
9104 includes a bug fix for @code{libg2c} that solved a problem with using the
9105 @code{OPEN} statement as the first Fortran I/O activity in a program
9106 without a Fortran main program unit.
9107
9108 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
9109 your main program unit---that is, if you intend to compile a @code{main()}
9110 procedure using some other language---you should carefully
9111 examine the code for @code{main()} in @code{libg2c}, found in the source
9112 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
9113 might need to be done by your @code{main()} in order to provide the
9114 Fortran environment your Fortran code is expecting.
9115
9116 @cindex @code{IArgC} intrinsic
9117 @cindex intrinsics, @code{IArgC}
9118 @cindex @code{GetArg} intrinsic
9119 @cindex intrinsics, @code{GetArg}
9120 For example, @code{libg2c}'s @code{main()} sets up the information used by
9121 the @code{IARGC} and @code{GETARG} intrinsics.
9122 Bypassing @code{libg2c}'s @code{main()}
9123 without providing a substitute for this activity would mean
9124 that invoking @code{IARGC} and @code{GETARG} would produce undefined
9125 results.
9126
9127 @cindex debugging
9128 @cindex main program unit, debugging
9129 @cindex main()
9130 @cindex MAIN__()
9131 @cindex .gdbinit
9132 When debugging, one implication of the fact that @code{main()}, which
9133 is the place where the debugged program ``starts'' from the
9134 debugger's point of view, is in @code{libg2c} is that you won't be
9135 starting your Fortran program at a point you recognize as your
9136 Fortran code.
9137
9138 The standard way to get around this problem is to set a break
9139 point (a one-time, or temporary, break point will do) at
9140 the entrance to @samp{MAIN__}, and then run the program.
9141 A convenient way to do so is to add the @code{gdb} command
9142
9143 @example
9144 tbreak MAIN__
9145 @end example
9146
9147 @noindent
9148 to the file @file{.gdbinit} in the directory in which you're debugging
9149 (using @code{gdb}).
9150
9151 After doing this, the debugger will see the current execution
9152 point of the program as at the beginning of the main program
9153 unit of your program.
9154
9155 Of course, if you really want to set a break point at some
9156 other place in your program and just start the program
9157 running, without first breaking at @samp{MAIN__},
9158 that should work fine.
9159
9160 @node Procedures
9161 @section Procedures (SUBROUTINE and FUNCTION)
9162 @cindex procedures
9163 @cindex SUBROUTINE statement
9164 @cindex statements, SUBROUTINE
9165 @cindex FUNCTION statement
9166 @cindex statements, FUNCTION
9167 @cindex signature of procedures
9168
9169 Currently, @code{g77} passes arguments via reference---specifically,
9170 by passing a pointer to the location in memory of a variable, array,
9171 array element, a temporary location that holds the result of evaluating an
9172 expression, or a temporary or permanent location that holds the value
9173 of a constant.
9174
9175 Procedures that accept @code{CHARACTER} arguments are implemented by
9176 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
9177
9178 The first argument occupies the expected position in the
9179 argument list and has the user-specified name.
9180 This argument
9181 is a pointer to an array of characters, passed by the caller.
9182
9183 The second argument is appended to the end of the user-specified
9184 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
9185 is the user-specified name.
9186 This argument is of the C type @code{ftnlen}
9187 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
9188 is the number of characters the caller has allocated in the
9189 array pointed to by the first argument.
9190
9191 A procedure will ignore the length argument if @samp{X} is not declared
9192 @code{CHARACTER*(*)}, because for other declarations, it knows the
9193 length.
9194 Not all callers necessarily ``know'' this, however, which
9195 is why they all pass the extra argument.
9196
9197 The contents of the @code{CHARACTER} argument are specified by the
9198 address passed in the first argument (named after it).
9199 The procedure can read or write these contents as appropriate.
9200
9201 When more than one @code{CHARACTER} argument is present in the argument
9202 list, the length arguments are appended in the order
9203 the original arguments appear.
9204 So @samp{CALL FOO('HI','THERE')} is implemented in
9205 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
9206 does not provide the trailing null bytes on the constant
9207 strings (@code{f2c} does provide them, but they are unnecessary in
9208 a Fortran environment, and you should not expect them to be
9209 there).
9210
9211 Note that the above information applies to @code{CHARACTER} variables and
9212 arrays @strong{only}.
9213 It does @strong{not} apply to external @code{CHARACTER}
9214 functions or to intrinsic @code{CHARACTER} functions.
9215 That is, no second length argument is passed to @samp{FOO} in this case:
9216
9217 @example
9218 CHARACTER X
9219 EXTERNAL X
9220 CALL FOO(X)
9221 @end example
9222
9223 @noindent
9224 Nor does @samp{FOO} expect such an argument in this case:
9225
9226 @example
9227 SUBROUTINE FOO(X)
9228 CHARACTER X
9229 EXTERNAL X
9230 @end example
9231
9232 Because of this implementation detail, if a program has a bug
9233 such that there is disagreement as to whether an argument is
9234 a procedure, and the type of the argument is @code{CHARACTER}, subtle
9235 symptoms might appear.
9236
9237 @node Functions
9238 @section Functions (FUNCTION and RETURN)
9239 @cindex functions
9240 @cindex FUNCTION statement
9241 @cindex statements, FUNCTION
9242 @cindex RETURN statement
9243 @cindex statements, RETURN
9244 @cindex return type of functions
9245
9246 @code{g77} handles in a special way functions that return the following
9247 types:
9248
9249 @itemize @bullet
9250 @item
9251 @code{CHARACTER}
9252 @item
9253 @code{COMPLEX}
9254 @item
9255 @code{REAL(KIND=1)}
9256 @end itemize
9257
9258 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
9259 returning @code{void})
9260 with two arguments prepended: @samp{__g77_result}, which the caller passes
9261 as a pointer to a @code{char} array expected to hold the return value,
9262 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
9263 specifying the length of the return value as declared in the calling
9264 program.
9265 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
9266 to determine the size of the array that @samp{__g77_result} points to;
9267 otherwise, it ignores that argument.
9268
9269 For @code{COMPLEX}, when @samp{-ff2c} is in
9270 force, @code{g77} implements
9271 a subroutine with one argument prepended: @samp{__g77_result}, which the
9272 caller passes as a pointer to a variable of the type of the function.
9273 The called function writes the return value into this variable instead
9274 of returning it as a function value.
9275 When @samp{-fno-f2c} is in force,
9276 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
9277 @samp{__complex__ float} or @samp{__complex__ double} function
9278 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
9279 returning the result of the function in the same way as @code{gcc} would.
9280
9281 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
9282 a function that actually returns @code{REAL(KIND=2)} (typically
9283 C's @code{double} type).
9284 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
9285 functions return @code{float}.
9286
9287 @node Names
9288 @section Names
9289 @cindex symbol names
9290 @cindex transforming symbol names
9291
9292 Fortran permits each implementation to decide how to represent
9293 names as far as how they're seen in other contexts, such as debuggers
9294 and when interfacing to other languages, and especially as far
9295 as how casing is handled.
9296
9297 External names---names of entities that are public, or ``accessible'',
9298 to all modules in a program---normally have an underscore (@samp{_})
9299 appended by @code{g77},
9300 to generate code that is compatible with @code{f2c}.
9301 External names include names of Fortran things like common blocks,
9302 external procedures (subroutines and functions, but not including
9303 statement functions, which are internal procedures), and entry point
9304 names.
9305
9306 However, use of the @samp{-fno-underscoring} option
9307 disables this kind of transformation of external names (though inhibiting
9308 the transformation certainly improves the chances of colliding with
9309 incompatible externals written in other languages---but that
9310 might be intentional.
9311
9312 @cindex -fno-underscoring option
9313 @cindex options, -fno-underscoring
9314 @cindex -fno-second-underscore option
9315 @cindex options, -fno-underscoring
9316 When @samp{-funderscoring} is in force, any name (external or local)
9317 that already has at least one underscore in it is
9318 implemented by @code{g77} by appending two underscores.
9319 (This second underscore can be disabled via the
9320 @samp{-fno-second-underscore} option.)
9321 External names are changed this way for @code{f2c} compatibility.
9322 Local names are changed this way to avoid collisions with external names
9323 that are different in the source code---@code{f2c} does the same thing, but
9324 there's no compatibility issue there except for user expectations while
9325 debugging.
9326
9327 For example:
9328
9329 @example
9330 Max_Cost = 0
9331 @end example
9332
9333 @cindex debugging
9334 @noindent
9335 Here, a user would, in the debugger, refer to this variable using the
9336 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
9337 as described below).
9338 (We hope to improve @code{g77} in this regard in the future---don't
9339 write scripts depending on this behavior!
9340 Also, consider experimenting with the @samp{-fno-underscoring}
9341 option to try out debugging without having to massage names by
9342 hand like this.)
9343
9344 @code{g77} provides a number of command-line options that allow the user
9345 to control how case mapping is handled for source files.
9346 The default is the traditional UNIX model for Fortran compilers---names
9347 are mapped to lower case.
9348 Other command-line options can be specified to map names to upper
9349 case, or to leave them exactly as written in the source file.
9350
9351 For example:
9352
9353 @example
9354 Foo = 9.436
9355 @end example
9356
9357 @noindent
9358 Here, it is normally the case that the variable assigned will be named
9359 @samp{foo}.
9360 This would be the name to enter when using a debugger to
9361 access the variable.
9362
9363 However, depending on the command-line options specified, the
9364 name implemented by @code{g77} might instead be @samp{FOO} or even
9365 @samp{Foo}, thus affecting how debugging is done.
9366
9367 Also:
9368
9369 @example
9370 Call Foo
9371 @end example
9372
9373 @noindent
9374 This would normally call a procedure that, if it were in a separate C program,
9375 be defined starting with the line:
9376
9377 @example
9378 void foo_()
9379 @end example
9380
9381 @noindent
9382 However, @code{g77} command-line options could be used to change the casing
9383 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
9384 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
9385 could be used to inhibit the appending of the underscore to the name.
9386
9387 @node Common Blocks
9388 @section Common Blocks (COMMON)
9389 @cindex common blocks
9390 @cindex @code{COMMON} statement
9391 @cindex statements, @code{COMMON}
9392
9393 @code{g77} names and lays out @code{COMMON} areas
9394 the same way @code{f2c} does,
9395 for compatibility with @code{f2c}.
9396
9397 Currently, @code{g77} does not emit ``true'' debugging information for
9398 members of a @code{COMMON} area, due to an apparent bug in the GBE.
9399
9400 (As of Version 0.5.19, @code{g77} emits debugging information for such
9401 members in the form of a constant string specifying the base name of
9402 the aggregate area and the offset of the member in bytes from the start
9403 of the area.
9404 Use the @samp{-fdebug-kludge} option to enable this behavior.
9405 In @code{gdb}, use @samp{set language c} before printing the value
9406 of the member, then @samp{set language fortran} to restore the default
9407 language, since @code{gdb} doesn't provide a way to print a readable
9408 version of a character string in Fortran language mode.
9409
9410 This kludge will be removed in a future version of @code{g77} that,
9411 in conjunction with a contemporary version of @code{gdb},
9412 properly supports Fortran-language debugging, including access
9413 to members of @code{COMMON} areas.)
9414
9415 @xref{Code Gen Options,,Options for Code Generation Conventions},
9416 for information on the @samp{-fdebug-kludge} option.
9417
9418 Moreover, @code{g77} currently implements a @code{COMMON} area such that its
9419 type is an array of the C @code{char} data type.
9420
9421 So, when debugging, you must know the offset into a @code{COMMON} area
9422 for a particular item in that area, and you have to take into
9423 account the appropriate multiplier for the respective sizes
9424 of the types (as declared in your code) for the items preceding
9425 the item in question as compared to the size of the @code{char} type.
9426
9427 For example, using default implicit typing, the statement
9428
9429 @example
9430 COMMON I(15), R(20), T
9431 @end example
9432
9433 @noindent
9434 results in a public 144-byte @code{char} array named @samp{_BLNK__}
9435 with @samp{I} placed at @samp{_BLNK__[0]}, @samp{R} at @samp{_BLNK__[60]},
9436 and @samp{T} at @samp{_BLNK__[140]}.
9437 (This is assuming that the target machine for
9438 the compilation has 4-byte @code{INTEGER(KIND=1)} and @code{REAL(KIND=1)}
9439 types.)
9440
9441 @node Local Equivalence Areas
9442 @section Local Equivalence Areas (EQUIVALENCE)
9443 @cindex equivalence areas
9444 @cindex local equivalence areas
9445 @cindex EQUIVALENCE statement
9446 @cindex statements, EQUIVALENCE
9447
9448 @code{g77} treats storage-associated areas involving a @code{COMMON}
9449 block as explained in the section on common blocks.
9450
9451 A local @code{EQUIVALENCE} area is a collection of variables and arrays
9452 connected to each other in any way via @code{EQUIVALENCE}, none of which are
9453 listed in a @code{COMMON} statement.
9454
9455 Currently, @code{g77} does not emit ``true'' debugging information for
9456 members in a local @code{EQUIVALENCE} area, due to an apparent bug in the GBE.
9457
9458 (As of Version 0.5.19, @code{g77} does emit debugging information for such
9459 members in the form of a constant string specifying the base name of
9460 the aggregate area and the offset of the member in bytes from the start
9461 of the area.
9462 Use the @samp{-fdebug-kludge} option to enable this behavior.
9463 In @code{gdb}, use @samp{set language c} before printing the value
9464 of the member, then @samp{set language fortran} to restore the default
9465 language, since @code{gdb} doesn't provide a way to print a readable
9466 version of a character string in Fortran language mode.
9467
9468 This kludge will be removed in a future version of @code{g77} that,
9469 in conjunction with a contemporary version of @code{gdb},
9470 properly supports Fortran-language debugging, including access
9471 to members of @code{EQUIVALENCE} areas.)
9472
9473 @xref{Code Gen Options,,Options for Code Generation Conventions},
9474 for information on the @samp{-fdebug-kludge} option.
9475
9476 Moreover, @code{g77} implements a local @code{EQUIVALENCE} area such that its
9477 type is an array of the C @code{char} data type.
9478
9479 The name @code{g77} gives this array of @code{char} type is @samp{__g77_equiv_@var{x}},
9480 where @var{x} is the name of the item that is placed at the beginning (offset 0)
9481 of this array.
9482 If more than one such item is placed at the beginning, @var{x} is
9483 the name that sorts to the top in an alphabetical sort of the list of
9484 such items.
9485
9486 When debugging, you must therefore access members of @code{EQUIVALENCE}
9487 areas by specifying the appropriate @samp{__g77_equiv_@var{x}}
9488 array section with the appropriate offset.
9489 See the explanation of debugging @code{COMMON} blocks
9490 for info applicable to debugging local @code{EQUIVALENCE} areas.
9491
9492 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
9493 for @var{x} using a different method when more than one name was
9494 in the list of names of entities placed at the beginning of the
9495 array.
9496 Though the documentation specified that the first name listed in
9497 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
9498 in fact chose the name using a method that was so complicated,
9499 it seemed easier to change it to an alphabetical sort than to describe the
9500 previous method in the documentation.)
9501
9502 @node Complex Variables
9503 @section Complex Variables (COMPLEX)
9504 @cindex complex variables
9505 @cindex imaginary part
9506 @cindex COMPLEX statement
9507 @cindex statements, COMPLEX
9508
9509 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
9510 (and related intrinsics, constants, functions, and so on)
9511 in a manner that
9512 makes direct debugging involving these types in Fortran
9513 language mode difficult.
9514
9515 Essentially, @code{g77} implements these types using an
9516 internal construct similar to C's @code{struct}, at least
9517 as seen by the @code{gcc} back end.
9518
9519 Currently, the back end, when outputting debugging info with
9520 the compiled code for the assembler to digest, does not detect
9521 these @code{struct} types as being substitutes for Fortran
9522 complex.
9523 As a result, the Fortran language modes of debuggers such as
9524 @code{gdb} see these types as C @code{struct} types, which
9525 they might or might not support.
9526
9527 Until this is fixed, switch to C language mode to work with
9528 entities of @code{COMPLEX} type and then switch back to Fortran language
9529 mode afterward.
9530 (In @code{gdb}, this is accomplished via @samp{set lang c} and
9531 either @samp{set lang fortran} or @samp{set lang auto}.)
9532
9533 @emph{Note:} Compiling with the @samp{-fno-emulate-complex} option
9534 avoids the debugging problem, but is known to cause other problems
9535 like compiler crashes and generation of incorrect code, so it is
9536 not recommended.
9537
9538 @node Arrays
9539 @section Arrays (DIMENSION)
9540 @cindex DIMENSION statement
9541 @cindex statements, DIMENSION
9542 @cindex array ordering
9543 @cindex ordering, array
9544 @cindex column-major ordering
9545 @cindex row-major ordering
9546 @cindex arrays
9547
9548 Fortran uses ``column-major ordering'' in its arrays.
9549 This differs from other languages, such as C, which use ``row-major ordering''.
9550 The difference is that, with Fortran, array elements adjacent to
9551 each other in memory differ in the @emph{first} subscript instead of
9552 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
9553 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
9554
9555 This consideration
9556 affects not only interfacing with and debugging Fortran code,
9557 it can greatly affect how code is designed and written, especially
9558 when code speed and size is a concern.
9559
9560 Fortran also differs from C, a popular language for interfacing and
9561 to support directly in debuggers, in the way arrays are treated.
9562 In C, arrays are single-dimensional and have interesting relationships
9563 to pointers, neither of which is true for Fortran.
9564 As a result, dealing with Fortran arrays from within
9565 an environment limited to C concepts can be challenging.
9566
9567 For example, accessing the array element @samp{A(5,10,20)} is easy enough
9568 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
9569 are needed.
9570 First, C would treat the A array as a single-dimension array.
9571 Second, C does not understand low bounds for arrays as does Fortran.
9572 Third, C assumes a low bound of zero (0), while Fortran defaults to a
9573 low bound of one (1) and can supports an arbitrary low bound.
9574 Therefore, calculations must be done
9575 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
9576 calculations require knowing the dimensions of @samp{A}.
9577
9578 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
9579 @samp{A(5,10,20)} would be:
9580
9581 @example
9582   (5-2)
9583 + (10-1)*(11-2+1)
9584 + (20-0)*(11-2+1)*(21-1+1)
9585 = 4293
9586 @end example
9587
9588 @noindent
9589 So the C equivalent in this case would be @samp{a[4293]}.
9590
9591 When using a debugger directly on Fortran code, the C equivalent
9592 might not work, because some debuggers cannot understand the notion
9593 of low bounds other than zero.  However, unlike @code{f2c}, @code{g77}
9594 does inform the GBE that a multi-dimensional array (like @samp{A}
9595 in the above example) is really multi-dimensional, rather than a
9596 single-dimensional array, so at least the dimensionality of the array
9597 is preserved.
9598
9599 Debuggers that understand Fortran should have no trouble with
9600 non-zero low bounds, but for non-Fortran debuggers, especially
9601 C debuggers, the above example might have a C equivalent of
9602 @samp{a[4305]}.
9603 This calculation is arrived at by eliminating the subtraction
9604 of the lower bound in the first parenthesized expression on each
9605 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
9606 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
9607 Actually, the implication of
9608 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
9609 but that @samp{a[20][10][5]} produces the equivalent of
9610 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
9611
9612 Come to think of it, perhaps
9613 the behavior is due to the debugger internally compensating for
9614 the lower bounds by offsetting the base address of @samp{a}, leaving
9615 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
9616 its first element as identified by subscripts equal to the
9617 corresponding lower bounds).
9618
9619 You know, maybe nobody really needs to use arrays.
9620
9621 @node Adjustable Arrays
9622 @section Adjustable Arrays (DIMENSION)
9623 @cindex arrays, adjustable
9624 @cindex adjustable arrays
9625 @cindex arrays, automatic
9626 @cindex automatic arrays
9627 @cindex DIMENSION statement
9628 @cindex statements, DIMENSION
9629 @cindex dimensioning arrays
9630 @cindex arrays, dimensioning
9631
9632 Adjustable and automatic arrays in Fortran require the implementation
9633 (in this
9634 case, the @code{g77} compiler) to ``memorize'' the expressions that
9635 dimension the arrays each time the procedure is invoked.
9636 This is so that subsequent changes to variables used in those
9637 expressions, made during execution of the procedure, do not
9638 have any effect on the dimensions of those arrays.
9639
9640 For example:
9641
9642 @example
9643 REAL ARRAY(5)
9644 DATA ARRAY/5*2/
9645 CALL X(ARRAY, 5)
9646 END
9647 SUBROUTINE X(A, N)
9648 DIMENSION A(N)
9649 N = 20
9650 PRINT *, N, A
9651 END
9652 @end example
9653
9654 @noindent
9655 Here, the implementation should, when running the program, print something
9656 like:
9657
9658 @example
9659 20   2.  2.  2.  2.  2.
9660 @end example
9661
9662 @noindent
9663 Note that this shows that while the value of @samp{N} was successfully
9664 changed, the size of the @samp{A} array remained at 5 elements.
9665
9666 To support this, @code{g77} generates code that executes before any user
9667 code (and before the internally generated computed @code{GOTO} to handle
9668 alternate entry points, as described below) that evaluates each
9669 (nonconstant) expression in the list of subscripts for an
9670 array, and saves the result of each such evaluation to be used when
9671 determining the size of the array (instead of re-evaluating the
9672 expressions).
9673
9674 So, in the above example, when @samp{X} is first invoked, code is
9675 executed that copies the value of @samp{N} to a temporary.
9676 And that same temporary serves as the actual high bound for the single
9677 dimension of the @samp{A} array (the low bound being the constant 1).
9678 Since the user program cannot (legitimately) change the value
9679 of the temporary during execution of the procedure, the size
9680 of the array remains constant during each invocation.
9681
9682 For alternate entry points, the code @code{g77} generates takes into
9683 account the possibility that a dummy adjustable array is not actually
9684 passed to the actual entry point being invoked at that time.
9685 In that case, the public procedure implementing the entry point
9686 passes to the master private procedure implementing all the
9687 code for the entry points a @code{NULL} pointer where a pointer to that
9688 adjustable array would be expected.
9689 The @code{g77}-generated code
9690 doesn't attempt to evaluate any of the expressions in the subscripts
9691 for an array if the pointer to that array is @code{NULL} at run time in
9692 such cases.
9693 (Don't depend on this particular implementation
9694 by writing code that purposely passes @code{NULL} pointers where the
9695 callee expects adjustable arrays, even if you know the callee
9696 won't reference the arrays---nor should you pass @code{NULL} pointers
9697 for any dummy arguments used in calculating the bounds of such
9698 arrays or leave undefined any values used for that purpose in
9699 COMMON---because the way @code{g77} implements these things might
9700 change in the future!)
9701
9702 @node Alternate Entry Points
9703 @section Alternate Entry Points (ENTRY)
9704 @cindex alternate entry points
9705 @cindex entry points
9706 @cindex ENTRY statement
9707 @cindex statements, ENTRY
9708
9709 The GBE does not understand the general concept of
9710 alternate entry points as Fortran provides via the ENTRY statement.
9711 @code{g77} gets around this by using an approach to compiling procedures
9712 having at least one @code{ENTRY} statement that is almost identical to the
9713 approach used by @code{f2c}.
9714 (An alternate approach could be used that
9715 would probably generate faster, but larger, code that would also
9716 be a bit easier to debug.)
9717
9718 Information on how @code{g77} implements @code{ENTRY} is provided for those
9719 trying to debug such code.
9720 The choice of implementation seems
9721 unlikely to affect code (compiled in other languages) that interfaces
9722 to such code.
9723
9724 @code{g77} compiles exactly one public procedure for the primary entry
9725 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
9726 That is, in terms of the public interface, there is no difference
9727 between
9728
9729 @example
9730 SUBROUTINE X
9731 END
9732 SUBROUTINE Y
9733 END
9734 @end example
9735
9736 @noindent
9737 and:
9738
9739 @example
9740 SUBROUTINE X
9741 ENTRY Y
9742 END
9743 @end example
9744
9745 The difference between the above two cases lies in the code compiled
9746 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
9747 for the second case, an extra internal procedure is compiled.
9748
9749 For every Fortran procedure with at least one @code{ENTRY}
9750 statement, @code{g77} compiles an extra procedure
9751 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
9752 the name of the primary entry point (which, in the above case,
9753 using the standard compiler options, would be @samp{x_} in C).
9754
9755 This extra procedure is compiled as a private procedure---that is,
9756 a procedure not accessible by name to separately compiled modules.
9757 It contains all the code in the program unit, including the code
9758 for the primary entry point plus for every entry point.
9759 (The code for each public procedure is quite short, and explained later.)
9760
9761 The extra procedure has some other interesting characteristics.
9762
9763 The argument list for this procedure is invented by @code{g77}.
9764 It contains
9765 a single integer argument named @samp{__g77_which_entrypoint},
9766 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
9767 entry point index---0 for the primary entry point, 1 for the
9768 first entry point (the first @code{ENTRY} statement encountered), 2 for
9769 the second entry point, and so on.
9770
9771 It also contains, for functions returning @code{CHARACTER} and
9772 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
9773 and for functions returning different types among the
9774 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
9775 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
9776 is expected at run time to contain a pointer to where to store
9777 the result of the entry point.
9778 For @code{CHARACTER} functions, this
9779 storage area is an array of the appropriate number of characters;
9780 for @code{COMPLEX} functions, it is the appropriate area for the return
9781 type; for multiple-return-type functions, it is a union of all the supported return
9782 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
9783 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
9784 is not supported by @code{g77}).
9785
9786 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
9787 by yet another argument named @samp{__g77_length} that, at run time,
9788 specifies the caller's expected length of the returned value.
9789 Note that only @code{CHARACTER*(*)} functions and entry points actually
9790 make use of this argument, even though it is always passed by
9791 all callers of public @code{CHARACTER} functions (since the caller does not
9792 generally know whether such a function is @code{CHARACTER*(*)} or whether
9793 there are any other callers that don't have that information).
9794
9795 The rest of the argument list is the union of all the arguments
9796 specified for all the entry points (in their usual forms, e.g.
9797 @code{CHARACTER} arguments have extra length arguments, all appended at
9798 the end of this list).
9799 This is considered the ``master list'' of
9800 arguments.
9801
9802 The code for this procedure has, before the code for the first
9803 executable statement, code much like that for the following Fortran
9804 statement:
9805
9806 @smallexample
9807        GOTO (100000,100001,100002), __g77_which_entrypoint
9808 100000 @dots{}code for primary entry point@dots{}
9809 100001 @dots{}code immediately following first ENTRY statement@dots{}
9810 100002 @dots{}code immediately following second ENTRY statement@dots{}
9811 @end smallexample
9812
9813 @noindent
9814 (Note that invalid Fortran statement labels and variable names
9815 are used in the above example to highlight the fact that it
9816 represents code generated by the @code{g77} internals, not code to be
9817 written by the user.)
9818
9819 It is this code that, when the procedure is called, picks which
9820 entry point to start executing.
9821
9822 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
9823 example), those procedures are fairly simple.
9824 Their interfaces
9825 are just like they would be if they were self-contained procedures
9826 (without @code{ENTRY}), of course, since that is what the callers
9827 expect.
9828 Their code consists of simply calling the private
9829 procedure, described above, with the appropriate extra arguments
9830 (the entry point index, and perhaps a pointer to a multiple-type-
9831 return variable, local to the public procedure, that contains
9832 all the supported returnable non-character types).
9833 For arguments
9834 that are not listed for a given entry point that are listed for
9835 other entry points, and therefore that are in the ``master list''
9836 for the private procedure, null pointers (in C, the @code{NULL} macro)
9837 are passed.
9838 Also, for entry points that are part of a multiple-type-
9839 returning function, code is compiled after the call of the private
9840 procedure to extract from the multi-type union the appropriate result,
9841 depending on the type of the entry point in question, returning
9842 that result to the original caller.
9843
9844 When debugging a procedure containing alternate entry points, you
9845 can either set a break point on the public procedure itself (e.g.
9846 a break point on @samp{X} or @samp{Y}) or on the private procedure that
9847 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
9848 If you do the former, you should use the debugger's command to
9849 ``step into'' the called procedure to get to the actual code; with
9850 the latter approach, the break point leaves you right at the
9851 actual code, skipping over the public entry point and its call
9852 to the private procedure (unless you have set a break point there
9853 as well, of course).
9854
9855 Further, the list of dummy arguments that is visible when the
9856 private procedure is active is going to be the expanded version
9857 of the list for whichever particular entry point is active,
9858 as explained above, and the way in which return values are
9859 handled might well be different from how they would be handled
9860 for an equivalent single-entry function.
9861
9862 @node Alternate Returns
9863 @section Alternate Returns (SUBROUTINE and RETURN)
9864 @cindex subroutines
9865 @cindex alternate returns
9866 @cindex SUBROUTINE statement
9867 @cindex statements, SUBROUTINE
9868 @cindex RETURN statement
9869 @cindex statements, RETURN
9870
9871 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
9872 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
9873 the C @code{int} type.
9874 The actual alternate-return arguments are omitted from the calling sequence.
9875 Instead, the caller uses
9876 the return value to do a rough equivalent of the Fortran
9877 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
9878 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
9879 function), and the callee just returns whatever integer
9880 is specified in the @code{RETURN} statement for the subroutine
9881 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
9882 by @samp{RETURN}
9883 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
9884
9885 @node Assigned Statement Labels
9886 @section Assigned Statement Labels (ASSIGN and GOTO)
9887 @cindex assigned statement labels
9888 @cindex statement labels, assigned
9889 @cindex ASSIGN statement
9890 @cindex statements, ASSIGN
9891 @cindex GOTO statement
9892 @cindex statements, GOTO
9893
9894 For portability to machines where a pointer (such as to a label,
9895 which is how @code{g77} implements @code{ASSIGN} and its relatives,
9896 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
9897 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
9898 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
9899 than it does the numerical value in that variable, unless the
9900 variable is wide enough (can hold enough bits).
9901
9902 In particular, while @code{g77} implements
9903
9904 @example
9905 I = 10
9906 @end example
9907
9908 @noindent
9909 as, in C notation, @samp{i = 10;}, it implements
9910
9911 @example
9912 ASSIGN 10 TO I
9913 @end example
9914
9915 @noindent
9916 as, in GNU's extended C notation (for the label syntax),
9917 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
9918 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
9919 actually generate the name @samp{L10} or any other name like that,
9920 since debuggers cannot access labels anyway).
9921
9922 While this currently means that an @code{ASSIGN} statement does not
9923 overwrite the numeric contents of its target variable, @emph{do not}
9924 write any code depending on this feature.
9925 @code{g77} has already changed this implementation across
9926 versions and might do so in the future.
9927 This information is provided only to make debugging Fortran programs
9928 compiled with the current version of @code{g77} somewhat easier.
9929 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
9930 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
9931 means @code{g77} has decided it can store the pointer to the label directly
9932 into @samp{I} itself.
9933
9934 @xref{Ugly Assigned Labels}, for information on a command-line option
9935 to force @code{g77} to use the same storage for both normal and
9936 assigned-label uses of a variable.
9937
9938 @node Run-time Library Errors
9939 @section Run-time Library Errors
9940 @cindex IOSTAT=
9941 @cindex error values
9942 @cindex error messages
9943 @cindex messages, run-time
9944 @cindex I/O, errors
9945
9946 The @code{libg2c} library currently has the following table to relate
9947 error code numbers, returned in @code{IOSTAT=} variables, to messages.
9948 This information should, in future versions of this document, be
9949 expanded upon to include detailed descriptions of each message.
9950
9951 In line with good coding practices, any of the numbers in the
9952 list below should @emph{not} be directly written into Fortran
9953 code you write.
9954 Instead, make a separate @code{INCLUDE} file that defines
9955 @code{PARAMETER} names for them, and use those in your code,
9956 so you can more easily change the actual numbers in the future.
9957
9958 The information below is culled from the definition
9959 of @samp{F_err} in @file{f/runtime/libI77/err.c} in the
9960 @code{g77} source tree.
9961
9962 @smallexample
9963 100: "error in format"
9964 101: "illegal unit number"
9965 102: "formatted io not allowed"
9966 103: "unformatted io not allowed"
9967 104: "direct io not allowed"
9968 105: "sequential io not allowed"
9969 106: "can't backspace file"
9970 107: "null file name"
9971 108: "can't stat file"
9972 109: "unit not connected"
9973 110: "off end of record"
9974 111: "truncation failed in endfile"
9975 112: "incomprehensible list input"
9976 113: "out of free space"
9977 114: "unit not connected"
9978 115: "read unexpected character"
9979 116: "bad logical input field"
9980 117: "bad variable type"
9981 118: "bad namelist name"
9982 119: "variable not in namelist"
9983 120: "no end record"
9984 121: "variable count incorrect"
9985 122: "subscript for scalar variable"
9986 123: "invalid array section"
9987 124: "substring out of bounds"
9988 125: "subscript out of bounds"
9989 126: "can't read file"
9990 127: "can't write file"
9991 128: "'new' file exists"
9992 129: "can't append to file"
9993 130: "non-positive record number"
9994 131: "I/O started while already doing I/O"
9995 @end smallexample
9996
9997 @node Collected Fortran Wisdom
9998 @chapter Collected Fortran Wisdom
9999 @cindex wisdom
10000 @cindex legacy code
10001 @cindex code, legacy
10002 @cindex writing code
10003 @cindex code, writing
10004
10005 Most users of @code{g77} can be divided into two camps:
10006
10007 @itemize @bullet
10008 @item
10009 Those writing new Fortran code to be compiled by @code{g77}.
10010
10011 @item
10012 Those using @code{g77} to compile existing, ``legacy'' code.
10013 @end itemize
10014
10015 Users writing new code generally understand most of the necessary
10016 aspects of Fortran to write ``mainstream'' code, but often need
10017 help deciding how to handle problems, such as the construction
10018 of libraries containing @code{BLOCK DATA}.
10019
10020 Users dealing with ``legacy'' code sometimes don't have much
10021 experience with Fortran, but believe that the code they're compiling
10022 already works when compiled by other compilers (and might
10023 not understand why, as is sometimes the case, it doesn't work
10024 when compiled by @code{g77}).
10025
10026 The following information is designed to help users do a better job
10027 coping with existing, ``legacy'' Fortran code, and with writing
10028 new code as well.
10029
10030 @menu
10031 * Advantages Over f2c::        If @code{f2c} is so great, why @code{g77}?
10032 * Block Data and Libraries::   How @code{g77} solves a common problem.
10033 * Loops::                      Fortran @code{DO} loops surprise many people.
10034 * Working Programs::           Getting programs to work should be done first.
10035 * Overly Convenient Options::  Temptations to avoid, habits to not form.
10036 * Faster Programs::            Everybody wants these, but at what cost?
10037 @end menu
10038
10039 @node Advantages Over f2c
10040 @section Advantages Over f2c
10041
10042 Without @code{f2c}, @code{g77} would have taken much longer to
10043 do and probably not been as good for quite a while.
10044 Sometimes people who notice how much @code{g77} depends on, and
10045 documents encouragement to use, @code{f2c} ask why @code{g77}
10046 was created if @code{f2c} already existed.
10047
10048 This section gives some basic answers to these questions, though it
10049 is not intended to be comprehensive.
10050
10051 @menu
10052 * Language Extensions::  Features used by Fortran code.
10053 * Compiler Options::     Features helpful during development.
10054 * Compiler Speed::       Speed of the compilation process.
10055 * Program Speed::        Speed of the generated, optimized code.
10056 * Ease of Debugging::    Debugging ease-of-use at the source level.
10057 * Character and Hollerith Constants::  A byte saved is a byte earned.
10058 @end menu
10059
10060 @node Language Extensions
10061 @subsection Language Extensions
10062
10063 @code{g77} offers several extensions to the Fortran language that @code{f2c}
10064 doesn't.
10065
10066 However, @code{f2c} offers a few that @code{g77} doesn't, like
10067 fairly complete support for @code{INTEGER*2}.
10068 It is expected that @code{g77} will offer some or all of these missing
10069 features at some time in the future.
10070 (Version 0.5.18 of @code{g77} offers some rudimentary support for some
10071 of these features.)
10072
10073 @node Compiler Options
10074 @subsection Compiler Options
10075
10076 @code{g77} offers a whole bunch of compiler options that @code{f2c} doesn't.
10077
10078 However, @code{f2c} offers a few that @code{g77} doesn't, like an
10079 option to generate code to check array subscripts at run time.
10080 It is expected that @code{g77} will offer some or all of these
10081 missing options at some time in the future.
10082
10083 @node Compiler Speed
10084 @subsection Compiler Speed
10085
10086 Saving the steps of writing and then rereading C code is a big reason
10087 why @code{g77} should be able to compile code much faster than using
10088 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
10089
10090 However, due to @code{g77}'s youth, lots of self-checking is still being
10091 performed.
10092 As a result, this improvement is as yet unrealized
10093 (though the potential seems to be there for quite a big speedup
10094 in the future).
10095 It is possible that, as of version 0.5.18, @code{g77}
10096 is noticeably faster compiling many Fortran source files than using
10097 @code{f2c} in conjunction with @code{gcc}.
10098
10099 @node Program Speed
10100 @subsection Program Speed
10101
10102 @code{g77} has the potential to better optimize code than @code{f2c},
10103 even when @code{gcc} is used to compile the output of @code{f2c},
10104 because @code{f2c} must necessarily
10105 translate Fortran into a somewhat lower-level language (C) that cannot
10106 preserve all the information that is potentially useful for optimization,
10107 while @code{g77} can gather, preserve, and transmit that information directly
10108 to the GBE.
10109
10110 For example, @code{g77} implements @code{ASSIGN} and assigned
10111 @code{GOTO} using direct assignment of pointers to labels and direct
10112 jumps to labels, whereas @code{f2c} maps the assigned labels to
10113 integer values and then uses a C @code{switch} statement to encode
10114 the assigned @code{GOTO} statements.
10115
10116 However, as is typical, theory and reality don't quite match, at least
10117 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
10118 can generate code that is faster than @code{g77}.
10119
10120 Version 0.5.18 of @code{g77} offered default
10121 settings and options, via patches to the @code{gcc}
10122 back end, that allow for better program speed, though
10123 some of these improvements also affected the performance
10124 of programs translated by @code{f2c} and then compiled
10125 by @code{g77}'s version of @code{gcc}.
10126
10127 Version 0.5.20 of @code{g77} offers further performance
10128 improvements, at least one of which (alias analysis) is
10129 not generally applicable to @code{f2c} (though @code{f2c}
10130 could presumably be changed to also take advantage of
10131 this new capability of the @code{gcc} back end, assuming
10132 this is made available in an upcoming release of @code{gcc}).
10133
10134 @node Ease of Debugging
10135 @subsection Ease of Debugging
10136
10137 Because @code{g77} compiles directly to assembler code like @code{gcc},
10138 instead of translating to an intermediate language (C) as does @code{f2c},
10139 support for debugging can be better for @code{g77} than @code{f2c}.
10140
10141 However, although @code{g77} might be somewhat more ``native'' in terms of
10142 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
10143 of things ``not quite right''.
10144 Many of the important ones should be resolved in the near future.
10145
10146 For example, @code{g77} doesn't have to worry about reserved names
10147 like @code{f2c} does.
10148 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
10149 translate this to something @emph{other} than
10150 @samp{for = while;}, because C reserves those words.
10151
10152 However, @code{g77} does still uses things like an extra level of indirection
10153 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
10154 yet support multiple entry points.
10155
10156 Another example is that, given
10157
10158 @smallexample
10159 COMMON A, B
10160 EQUIVALENCE (B, C)
10161 @end smallexample
10162
10163 @noindent
10164 the @code{g77} user should be able to access the variables directly, by name,
10165 without having to traverse C-like structures and unions, while @code{f2c}
10166 is unlikely to ever offer this ability (due to limitations in the
10167 C language).
10168
10169 However, due to apparent bugs in the back end, @code{g77} currently doesn't
10170 take advantage of this facility at all---it doesn't emit any debugging
10171 information for @code{COMMON} and @code{EQUIVALENCE} areas,
10172 other than information
10173 on the array of @code{char} it creates (and, in the case
10174 of local @code{EQUIVALENCE}, names) for each such area.
10175
10176 Yet another example is arrays.
10177 @code{g77} represents them to the debugger
10178 using the same ``dimensionality'' as in the source code, while @code{f2c}
10179 must necessarily convert them all to one-dimensional arrays to fit
10180 into the confines of the C language.
10181 However, the level of support
10182 offered by debuggers for interactive Fortran-style access to arrays
10183 as compiled by @code{g77} can vary widely.
10184 In some cases, it can actually
10185 be an advantage that @code{f2c} converts everything to widely supported
10186 C semantics.
10187
10188 In fairness, @code{g77} could do many of the things @code{f2c} does
10189 to get things working at least as well as @code{f2c}---for now,
10190 the developers prefer making @code{g77} work the
10191 way they think it is supposed to, and finding help improving the
10192 other products (the back end of @code{gcc}; @code{gdb}; and so on)
10193 to get things working properly.
10194
10195 @node Character and Hollerith Constants
10196 @subsection Character and Hollerith Constants
10197 @cindex character constants
10198 @cindex constants, character
10199 @cindex Hollerith constants
10200 @cindex constants, Hollerith
10201 @cindex trailing null byte
10202 @cindex null byte, trailing
10203 @cindex zero byte, trailing
10204
10205 To avoid the extensive hassle that would be needed to avoid this,
10206 @code{f2c} uses C character constants to encode character and Hollerith
10207 constants.
10208 That means a constant like @samp{'HELLO'} is translated to
10209 @samp{"hello"} in C, which further means that an extra null byte is
10210 present at the end of the constant.
10211 This null byte is superfluous.
10212
10213 @code{g77} does not generate such null bytes.
10214 This represents significant
10215 savings of resources, such as on systems where @file{/dev/null} or
10216 @file{/dev/zero} represent bottlenecks in the systems' performance,
10217 because @code{g77} simply asks for fewer zeros from the operating
10218 system than @code{f2c}.
10219 (Avoiding spurious use of zero bytes, each byte typically have
10220 eight zero bits, also reduces the liabilities in case
10221 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
10222
10223 @node Block Data and Libraries
10224 @section Block Data and Libraries
10225 @cindex block data and libraries
10226 @cindex BLOCK DATA statement
10227 @cindex statements, BLOCK DATA
10228 @cindex libraries, containing BLOCK DATA
10229 @cindex f2c compatibility
10230 @cindex compatibility, f2c
10231
10232 To ensure that block data program units are linked, especially a concern
10233 when they are put into libraries, give each one a name (as in
10234 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
10235 statement in every program unit that uses any common block
10236 initialized by the corresponding @code{BLOCK DATA}.
10237 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
10238 @code{SUBROUTINE},
10239 that is, it generates an actual procedure having the appropriate name.
10240 The procedure does nothing but return immediately if it happens to be
10241 called.
10242 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
10243 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
10244 in the program and ensures that by generating a
10245 reference to it so the linker will make sure it is present.
10246 (Specifically, @code{g77} outputs in the data section a static pointer to the
10247 external name @samp{FOO}.)
10248
10249 The implementation @code{g77} currently uses to make this work is
10250 one of the few things not compatible with @code{f2c} as currently
10251 shipped.
10252 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
10253 issue a warning that @samp{FOO} is not otherwise referenced,
10254 and, for @samp{BLOCK DATA FOO},
10255 @code{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
10256 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
10257 this particular case.
10258 If you use @code{f2c} to compile @samp{BLOCK DATA FOO},
10259 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
10260 will result in an unresolved reference when linked.
10261 If you do the
10262 opposite, then @samp{FOO} might not be linked in under various
10263 circumstances (such as when @samp{FOO} is in a library, or you're
10264 using a ``clever'' linker---so clever, it produces a broken program
10265 with little or no warning by omitting initializations of global data
10266 because they are contained in unreferenced procedures).
10267
10268 The changes you make to your code to make @code{g77} handle this situation,
10269 however, appear to be a widely portable way to handle it.
10270 That is, many systems permit it (as they should, since the
10271 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
10272 is a block data program unit), and of the ones
10273 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
10274 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
10275 program units.
10276
10277 Here is the recommended approach to modifying a program containing
10278 a program unit such as the following:
10279
10280 @smallexample
10281 BLOCK DATA FOO
10282 COMMON /VARS/ X, Y, Z
10283 DATA X, Y, Z / 3., 4., 5. /
10284 END
10285 @end smallexample
10286
10287 @noindent
10288 If the above program unit might be placed in a library module, then
10289 ensure that every program unit in every program that references that
10290 particular @code{COMMON} area uses the @code{EXTERNAL} statement
10291 to force the area to be initialized.
10292
10293 For example, change a program unit that starts with
10294
10295 @smallexample
10296 INTEGER FUNCTION CURX()
10297 COMMON /VARS/ X, Y, Z
10298 CURX = X
10299 END
10300 @end smallexample
10301
10302 @noindent
10303 so that it uses the @code{EXTERNAL} statement, as in:
10304
10305 @smallexample
10306 INTEGER FUNCTION CURX()
10307 COMMON /VARS/ X, Y, Z
10308 EXTERNAL FOO
10309 CURX = X
10310 END
10311 @end smallexample
10312
10313 @noindent
10314 That way, @samp{CURX} is compiled by @code{g77} (and many other
10315 compilers) so that the linker knows it must include @samp{FOO},
10316 the @code{BLOCK DATA} program unit that sets the initial values
10317 for the variables in @samp{VAR}, in the executable program.
10318
10319 @node Loops
10320 @section Loops
10321 @cindex DO statement
10322 @cindex statements, DO
10323 @cindex trips, number of
10324 @cindex number of trips
10325
10326 The meaning of a @code{DO} loop in Fortran is precisely specified
10327 in the Fortran standard@dots{}and is quite different from what
10328 many programmers might expect.
10329
10330 In particular, Fortran iterative @code{DO} loops are implemented as if
10331 the number of trips through the loop is calculated @emph{before}
10332 the loop is entered.
10333
10334 The number of trips for a loop is calculated from the @var{start},
10335 @var{end}, and @var{increment} values specified in a statement such as:
10336
10337 @smallexample
10338 DO @var{iter} = @var{start}, @var{end}, @var{increment}
10339 @end smallexample
10340
10341 @noindent
10342 The trip count is evaluated using a fairly simple formula
10343 based on the three values following the @samp{=} in the
10344 statement, and it is that trip count that is effectively
10345 decremented during each iteration of the loop.
10346 If, at the beginning of an iteration of the loop, the
10347 trip count is zero or negative, the loop terminates.
10348 The per-loop-iteration modifications to @var{iter} are not
10349 related to determining whether to terminate the loop.
10350
10351 There are two important things to remember about the trip
10352 count:
10353
10354 @itemize @bullet
10355 @item
10356 It can be @emph{negative}, in which case it is
10357 treated as if it was zero---meaning the loop is
10358 not executed at all.
10359
10360 @item
10361 The type used to @emph{calculate} the trip count
10362 is the same type as @var{iter}, but the final
10363 calculation, and thus the type of the trip
10364 count itself, always is @code{INTEGER(KIND=1)}.
10365 @end itemize
10366
10367 These two items mean that there are loops that cannot
10368 be written in straightforward fashion using the Fortran @code{DO}.
10369
10370 For example, on a system with the canonical 32-bit two's-complement
10371 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
10372
10373 @smallexample
10374 DO I = -2000000000, 2000000000
10375 @end smallexample
10376
10377 @noindent
10378 Although the @var{start} and @var{end} values are well within
10379 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
10380 The expected trip count is 40000000001, which is outside
10381 the range of @code{INTEGER(KIND=1)} on many systems.
10382
10383 Instead, the above loop should be constructed this way:
10384
10385 @smallexample
10386 I = -2000000000
10387 DO
10388   IF (I .GT. 2000000000) EXIT
10389   @dots{}
10390   I = I + 1
10391 END DO
10392 @end smallexample
10393
10394 @noindent
10395 The simple @code{DO} construct and the @code{EXIT} statement
10396 (used to leave the innermost loop)
10397 are F90 features that @code{g77} supports.
10398
10399 Some Fortran compilers have buggy implementations of @code{DO},
10400 in that they don't follow the standard.
10401 They implement @code{DO} as a straightforward translation
10402 to what, in C, would be a @code{for} statement.
10403 Instead of creating a temporary variable to hold the trip count
10404 as calculated at run time, these compilers
10405 use the iteration variable @var{iter} to control
10406 whether the loop continues at each iteration.
10407
10408 The bug in such an implementation shows up when the
10409 trip count is within the range of the type of @var{iter},
10410 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
10411 exceeds that range.  For example:
10412
10413 @smallexample
10414 DO I = 2147483600, 2147483647
10415 @end smallexample
10416
10417 @noindent
10418 A loop started by the above statement will work as implemented
10419 by @code{g77}, but the use, by some compilers, of a
10420 more C-like implementation akin to
10421
10422 @smallexample
10423 for (i = 2147483600; i <= 2147483647; ++i)
10424 @end smallexample
10425
10426 @noindent
10427 produces a loop that does not terminate, because @samp{i}
10428 can never be greater than 2147483647, since incrementing it
10429 beyond that value overflows @samp{i}, setting it to -2147483648.
10430 This is a large, negative number that still is less than 2147483647.
10431
10432 Another example of unexpected behavior of @code{DO} involves
10433 using a nonintegral iteration variable @var{iter}, that is,
10434 a @code{REAL} variable.
10435 Consider the following program:
10436
10437 @smallexample
10438       DATA BEGIN, END, STEP /.1, .31, .007/
10439       DO 10 R = BEGIN, END, STEP
10440          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
10441          PRINT *,R
10442 10    CONTINUE
10443       PRINT *,'LAST = ',R
10444       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
10445       END
10446 @end smallexample
10447
10448 @noindent
10449 A C-like view of @code{DO} would hold that the two ``exclamatory''
10450 @code{PRINT} statements are never executed.
10451 However, this is the output of running the above program
10452 as compiled by @code{g77} on a GNU/Linux ix86 system:
10453
10454 @smallexample
10455  .100000001
10456  .107000001
10457  .114
10458  .120999999
10459  @dots{}
10460  .289000005
10461  .296000004
10462  .303000003
10463 LAST =   .310000002
10464  .310000002 .LE.   .310000002!!
10465 @end smallexample
10466
10467 Note that one of the two checks in the program turned up
10468 an apparent violation of the programmer's expectation---yet,
10469 the loop is correctly implemented by @code{g77}, in that
10470 it has 30 iterations.
10471 This trip count of 30 is correct when evaluated using
10472 the floating-point representations for the @var{begin},
10473 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
10474 ix86 are used.
10475 On other systems, an apparently more accurate trip count
10476 of 31 might result, but, nevertheless, @code{g77} is
10477 faithfully following the Fortran standard, and the result
10478 is not what the author of the sample program above
10479 apparently expected.
10480 (Such other systems might, for different values in the @code{DATA}
10481 statement, violate the other programmer's expectation,
10482 for example.)
10483
10484 Due to this combination of imprecise representation
10485 of floating-point values and the often-misunderstood
10486 interpretation of @code{DO} by standard-conforming
10487 compilers such as @code{g77}, use of @code{DO} loops
10488 with @code{REAL} iteration
10489 variables is not recommended.
10490 Such use can be caught by specifying @samp{-Wsurprising}.
10491 @xref{Warning Options}, for more information on this
10492 option.
10493
10494 @node Working Programs
10495 @section Working Programs
10496
10497 Getting Fortran programs to work in the first place can be
10498 quite a challenge---even when the programs already work on
10499 other systems, or when using other compilers.
10500
10501 @code{g77} offers some facilities that might be useful for
10502 tracking down bugs in such programs.
10503
10504 @menu
10505 * Not My Type::
10506 * Variables Assumed To Be Zero::
10507 * Variables Assumed To Be Saved::
10508 * Unwanted Variables::
10509 * Unused Arguments::
10510 * Surprising Interpretations of Code::
10511 * Aliasing Assumed To Work::
10512 * Output Assumed To Flush::
10513 * Large File Unit Numbers::
10514 * Floating-point precision::
10515 * Inconsistent Calling Sequences::
10516 @end menu
10517
10518 @node Not My Type
10519 @subsection Not My Type
10520 @cindex mistyped variables
10521 @cindex variables, mistyped
10522 @cindex mistyped functions
10523 @cindex functions, mistyped
10524 @cindex implicit typing
10525
10526 A fruitful source of bugs in Fortran source code is use, or
10527 mis-use, of Fortran's implicit-typing feature, whereby the
10528 type of a variable, array, or function is determined by the
10529 first character of its name.
10530
10531 Simple cases of this include statements like @samp{LOGX=9.227},
10532 without a statement such as @samp{REAL LOGX}.
10533 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
10534 type, with the result of the assignment being that it is given
10535 the value @samp{9}.
10536
10537 More involved cases include a function that is defined starting
10538 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
10539 Any caller of this function that does not also declare @samp{IPS}
10540 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
10541 is likely to assume it returns
10542 @code{INTEGER}, or some other type, leading to invalid results
10543 or even program crashes.
10544
10545 The @samp{-Wimplicit} option might catch failures to
10546 properly specify the types of
10547 variables, arrays, and functions in the code.
10548
10549 However, in code that makes heavy use of Fortran's
10550 implicit-typing facility, this option might produce so
10551 many warnings about cases that are working, it would be
10552 hard to find the one or two that represent bugs.
10553 This is why so many experienced Fortran programmers strongly
10554 recommend widespread use of the @code{IMPLICIT NONE} statement,
10555 despite it not being standard FORTRAN 77, to completely turn
10556 off implicit typing.
10557 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
10558 FORTRAN 77 compilers.)
10559
10560 Note that @samp{-Wimplicit} catches only implicit typing of
10561 @emph{names}.
10562 It does not catch implicit typing of expressions such
10563 as @samp{X**(2/3)}.
10564 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
10565 is equivalent to @samp{X**0}, due to the way Fortran expressions
10566 are given types and then evaluated.
10567 (In this particular case, the programmer probably wanted
10568 @samp{X**(2./3.)}.)
10569
10570 @node Variables Assumed To Be Zero
10571 @subsection Variables Assumed To Be Zero
10572 @cindex zero-initialized variables
10573 @cindex variables, assumed to be zero
10574 @cindex uninitialized variables
10575
10576 Many Fortran programs were developed on systems that provided
10577 automatic initialization of all, or some, variables and arrays
10578 to zero.
10579 As a result, many of these programs depend, sometimes
10580 inadvertently, on this behavior, though to do so violates
10581 the Fortran standards.
10582
10583 You can ask @code{g77} for this behavior by specifying the
10584 @samp{-finit-local-zero} option when compiling Fortran code.
10585 (You might want to specify @samp{-fno-automatic} as well,
10586 to avoid code-size inflation for non-optimized compilations.)
10587
10588 Note that a program that works better when compiled with the
10589 @samp{-finit-local-zero} option
10590 is almost certainly depending on a particular system's,
10591 or compiler's, tendency to initialize some variables to zero.
10592 It might be worthwhile finding such cases and fixing them,
10593 using techniques such as compiling with the @samp{-O -Wuninitialized}
10594 options using @code{g77}.
10595
10596 @node Variables Assumed To Be Saved
10597 @subsection Variables Assumed To Be Saved
10598 @cindex variables, retaining values across calls
10599 @cindex saved variables
10600 @cindex static variables
10601
10602 Many Fortran programs were developed on systems that
10603 saved the values of all, or some, variables and arrays
10604 across procedure calls.
10605 As a result, many of these programs depend, sometimes
10606 inadvertently, on being able to assign a value to a
10607 variable, perform a @code{RETURN} to a calling procedure,
10608 and, upon subsequent invocation, reference the previously
10609 assigned variable to obtain the value.
10610
10611 They expect this despite not using the @code{SAVE} statement
10612 to specify that the value in a variable is expected to survive
10613 procedure returns and calls.
10614 Depending on variables and arrays to retain values across
10615 procedure calls without using @code{SAVE} to require it violates
10616 the Fortran standards.
10617
10618 You can ask @code{g77} to assume @code{SAVE} is specified for all
10619 relevant (local) variables and arrays by using the
10620 @samp{-fno-automatic} option.
10621
10622 Note that a program that works better when compiled with the
10623 @samp{-fno-automatic} option
10624 is almost certainly depending on not having to use
10625 the @code{SAVE} statement as required by the Fortran standard.
10626 It might be worthwhile finding such cases and fixing them,
10627 using techniques such as compiling with the @samp{-O -Wuninitialized}
10628 options using @code{g77}.
10629
10630 @node Unwanted Variables
10631 @subsection Unwanted Variables
10632
10633 The @samp{-Wunused} option can find bugs involving
10634 implicit typing, sometimes
10635 more easily than using @samp{-Wimplicit} in code that makes
10636 heavy use of implicit typing.
10637 An unused variable or array might indicate that the
10638 spelling for its declaration is different from that of
10639 its intended uses.
10640
10641 Other than cases involving typos, unused variables rarely
10642 indicate actual bugs in a program.
10643 However, investigating such cases thoroughly has, on occasion,
10644 led to the discovery of code that had not been completely
10645 written---where the programmer wrote declarations as needed
10646 for the whole algorithm, wrote some or even most of the code
10647 for that algorithm, then got distracted and forgot that the
10648 job was not complete.
10649
10650 @node Unused Arguments
10651 @subsection Unused Arguments
10652 @cindex unused arguments
10653 @cindex arguments, unused
10654
10655 As with unused variables, It is possible that unused arguments
10656 to a procedure might indicate a bug.
10657 Compile with @samp{-W -Wunused} option to catch cases of
10658 unused arguments.
10659
10660 Note that @samp{-W} also enables warnings regarding overflow
10661 of floating-point constants under certain circumstances.
10662
10663 @node Surprising Interpretations of Code
10664 @subsection Surprising Interpretations of Code
10665
10666 The @samp{-Wsurprising} option can help find bugs involving
10667 expression evaluation or in
10668 the way @code{DO} loops with non-integral iteration variables
10669 are handled.
10670 Cases found by this option might indicate a difference of
10671 interpretation between the author of the code involved, and
10672 a standard-conforming compiler such as @code{g77}.
10673 Such a difference might produce actual bugs.
10674
10675 In any case, changing the code to explicitly do what the
10676 programmer might have expected it to do, so @code{g77} and
10677 other compilers are more likely to follow the programmer's
10678 expectations, might be worthwhile, especially if such changes
10679 make the program work better.
10680
10681 @node Aliasing Assumed To Work
10682 @subsection Aliasing Assumed To Work
10683 @cindex -falias-check option
10684 @cindex options, -falias-check
10685 @cindex -fargument-alias option
10686 @cindex options, -fargument-alias
10687 @cindex -fargument-noalias option
10688 @cindex options, -fargument-noalias
10689 @cindex -fno-argument-noalias-global option
10690 @cindex options, -fno-argument-noalias-global
10691 @cindex aliasing
10692 @cindex anti-aliasing
10693 @cindex overlapping arguments
10694 @cindex overlays
10695 @cindex association, storage
10696 @cindex storage association
10697 @cindex scheduling of reads and writes
10698 @cindex reads and writes, scheduling
10699
10700 The @samp{-falias-check}, @samp{-fargument-alias},
10701 @samp{-fargument-noalias},
10702 and @samp{-fno-argument-noalias-global} options,
10703 introduced in version 0.5.20 and
10704 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
10705 were withdrawn as of @code{g77} version 0.5.23
10706 due to their not being supported by @code{gcc} version 2.8.
10707
10708 These options, which control the assumptions regarding aliasing
10709 (overlapping) of writes and reads to main memory (core) made
10710 by the @code{gcc} back end,
10711 might well be added back (in some form) in a future version
10712 of @code{gcc}.
10713
10714 However, these options @emph{are} supported by @code{egcs}.
10715
10716 The information below still is useful, but applies to
10717 only those versions of @code{g77} that support the
10718 alias analysis implied by support for these options.
10719
10720 These options are effective only when compiling with @samp{-O}
10721 (specifying any level other than @samp{-O0})
10722 or with @samp{-falias-check}.
10723
10724 The default for Fortran code is @samp{-fargument-noalias-global}.
10725 (The default for C code and code written in other C-based languages
10726 is @samp{-fargument-alias}.
10727 These defaults apply regardless of whether you use @code{g77} or
10728 @code{gcc} to compile your code.)
10729
10730 Note that, on some systems, compiling with @samp{-fforce-addr} in
10731 effect can produce more optimal code when the default aliasing
10732 options are in effect (and when optimization is enabled).
10733
10734 If your program is not working when compiled with optimization,
10735 it is possible it is violating the Fortran standards (77 and 90)
10736 by relying on the ability to ``safely'' modify variables and
10737 arrays that are aliased, via procedure calls, to other variables
10738 and arrays, without using @code{EQUIVALENCE} to explicitly
10739 set up this kind of aliasing.
10740
10741 (The FORTRAN 77 standard's prohibition of this sort of
10742 overlap, generally referred to therein as ``storage
10743 assocation'', appears in Sections 15.9.3.6.
10744 This prohibition allows implementations, such as @code{g77},
10745 to, for example, implement the passing of procedures and
10746 even values in @code{COMMON} via copy operations into local,
10747 perhaps more efficiently accessed temporaries at entry to a
10748 procedure, and, where appropriate, via copy operations back
10749 out to their original locations in memory at exit from that
10750 procedure, without having to take into consideration the
10751 order in which the local copies are updated by the code,
10752 among other things.)
10753
10754 To test this hypothesis, try compiling your program with
10755 the @samp{-fargument-alias} option, which causes the
10756 compiler to revert to assumptions essentially the same as
10757 made by versions of @code{g77} prior to 0.5.20.
10758
10759 If the program works using this option, that strongly suggests
10760 that the bug is in your program.
10761 Finding and fixing the bug(s) should result in a program that
10762 is more standard-conforming and that can be compiled by @code{g77}
10763 in a way that results in a faster executable.
10764
10765 (You might want to try compiling with @samp{-fargument-noalias},
10766 a kind of half-way point, to see if the problem is limited to
10767 aliasing between dummy arguments and @code{COMMON} variables---this
10768 option assumes that such aliasing is not done, while still allowing
10769 aliasing among dummy arguments.)
10770
10771 An example of aliasing that is invalid according to the standards
10772 is shown in the following program, which might @emph{not} produce
10773 the expected results when executed:
10774
10775 @smallexample
10776 I = 1
10777 CALL FOO(I, I)
10778 PRINT *, I
10779 END
10780
10781 SUBROUTINE FOO(J, K)
10782 J = J + K
10783 K = J * K
10784 PRINT *, J, K
10785 END
10786 @end smallexample
10787
10788 The above program attempts to use the temporary aliasing of the
10789 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
10790 pathological behavior---the simultaneous changing of the values
10791 of @emph{both} @samp{J} and @samp{K} when either one of them
10792 is written.
10793
10794 The programmer likely expects the program to print these values:
10795
10796 @example
10797 2  4
10798 4
10799 @end example
10800
10801 However, since the program is not standard-conforming, an
10802 implementation's behavior when running it is undefined, because
10803 subroutine @samp{FOO} modifies at least one of the arguments,
10804 and they are aliased with each other.
10805 (Even if one of the assignment statements was deleted, the
10806 program would still violate these rules.
10807 This kind of on-the-fly aliasing is permitted by the standard
10808 only when none of the aliased items are defined, or written,
10809 while the aliasing is in effect.)
10810
10811 As a practical example, an optimizing compiler might schedule
10812 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
10813 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
10814 resulting in the following output:
10815
10816 @example
10817 2  2
10818 2
10819 @end example
10820
10821 Essentially, compilers are promised (by the standard and, therefore,
10822 by programmers who write code they claim to be standard-conforming)
10823 that if they cannot detect aliasing via static analysis of a single
10824 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
10825 such aliasing exists.
10826 In such cases, compilers are free to assume that an assignment to
10827 one variable will not change the value of another variable, allowing
10828 it to avoid generating code to re-read the value of the other
10829 variable, to re-schedule reads and writes, and so on, to produce
10830 a faster executable.
10831
10832 The same promise holds true for arrays (as seen by the called
10833 procedure)---an element of one dummy array cannot be aliased
10834 with, or overlap, any element of another dummy array or be
10835 in a @code{COMMON} area known to the procedure.
10836
10837 (These restrictions apply only when the procedure defines, or
10838 writes to, one of the aliased variables or arrays.)
10839
10840 Unfortunately, there is no way to find @emph{all} possible cases of
10841 violations of the prohibitions against aliasing in Fortran code.
10842 Static analysis is certainly imperfect, as is run-time analysis,
10843 since neither can catch all violations.
10844 (Static analysis can catch all likely violations, and some that
10845 might never actually happen, while run-time analysis can catch
10846 only those violations that actually happen during a particular run.
10847 Neither approach can cope with programs mixing Fortran code with
10848 routines written in other languages, however.)
10849
10850 Currently, @code{g77} provides neither static nor run-time facilities
10851 to detect any cases of this problem, although other products might.
10852 Run-time facilities are more likely to be offered by future
10853 versions of @code{g77}, though patches improving @code{g77} so that
10854 it provides either form of detection are welcome.
10855
10856 @node Output Assumed To Flush
10857 @subsection Output Assumed To Flush
10858 @cindex ALWAYS_FLUSH
10859 @cindex synchronous write errors
10860 @cindex disk full
10861 @cindex flushing output
10862 @cindex fflush()
10863 @cindex I/O, flushing
10864 @cindex output, flushing
10865 @cindex writes, flushing
10866 @cindex NFS
10867 @cindex network file system
10868
10869 For several versions prior to 0.5.20, @code{g77} configured its
10870 version of the @code{libf2c} run-time library so that one of
10871 its configuration macros, @samp{ALWAYS_FLUSH}, was defined.
10872
10873 This was done as a result of a belief that many programs expected
10874 output to be flushed to the operating system (under UNIX, via
10875 the @code{fflush()} library call) with the result that errors,
10876 such as disk full, would be immediately flagged via the
10877 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
10878
10879 Because of the adverse effects this approach had on the performance
10880 of many programs, @code{g77} no longer configures @code{libf2c}
10881 (now named @code{libg2c} in its @code{g77} incarnation)
10882 to always flush output.
10883
10884 If your program depends on this behavior, either insert the
10885 appropriate @samp{CALL FLUSH} statements, or modify the sources
10886 to the @code{libg2c}, rebuild and reinstall @code{g77}, and
10887 relink your programs with the modified library.
10888
10889 (Ideally, @code{libg2c} would offer the choice at run-time, so
10890 that a compile-time option to @code{g77} or @code{f2c} could
10891 result in generating the appropriate calls to flushing or
10892 non-flushing library routines.)
10893
10894 @xref{Always Flush Output}, for information on how to modify
10895 the @code{g77} source tree so that a version of @code{libg2c}
10896 can be built and installed with the @samp{ALWAYS_FLUSH} macro defined.
10897
10898 @node Large File Unit Numbers
10899 @subsection Large File Unit Numbers
10900 @cindex MXUNIT
10901 @cindex unit numbers
10902 @cindex maximum unit number
10903 @cindex illegal unit number
10904 @cindex increasing maximum unit number
10905
10906 If your program crashes at run time with a message including
10907 the text @samp{illegal unit number}, that probably is
10908 a message from the run-time library, @code{libg2c}.
10909
10910 The message means that your program has attempted to use a
10911 file unit number that is out of the range accepted by
10912 @code{libg2c}.
10913 Normally, this range is 0 through 99, and the high end
10914 of the range is controlled by a @code{libg2c} source-file
10915 macro named @samp{MXUNIT}.
10916
10917 If you can easily change your program to use unit numbers
10918 in the range 0 through 99, you should do so.
10919
10920 Otherwise, see @ref{Larger File Unit Numbers}, for information on how
10921 to change @samp{MXUNIT} in @code{libg2c} so you can build and
10922 install a new version of @code{libg2c} that supports the larger
10923 unit numbers you need.
10924
10925 @emph{Note:} While @code{libg2c} places a limit on the range
10926 of Fortran file-unit numbers, the underlying library and operating
10927 system might impose different kinds of limits.
10928 For example, some systems limit the number of files simultaneously
10929 open by a running program.
10930 Information on how to increase these limits should be found
10931 in your system's documentation.
10932
10933 @node Floating-point precision
10934 @subsection Floating-point precision
10935
10936 @cindex IEEE 754 conformance
10937 @cindex conformance, IEEE 754
10938 @cindex floating-point, precision
10939 @cindex ix86 floating-point
10940 @cindex x86 floating-point
10941 If your program depends on exact IEEE 754 floating-point handling it may
10942 help on some systems---specifically x86 or m68k hardware---to use
10943 the @code{-ffloat-store} option or to reset the precision flag on the
10944 floating-point unit @xref{Optimize Options}.
10945
10946 However, it might be better simply to put the FPU into double precision
10947 mode and not take the performance hit of @code{-ffloat-store}.  On x86
10948 and m68k GNU systems you can do this with a technique similar to that
10949 for turning on floating-point exceptions @xref{Floating-point Exception
10950 Handling}.  The control word could be set to double precision by
10951 replacing the @code{__setfpucw} call with one like this:
10952 @smallexample
10953   __setfpucw ((_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE);
10954 @end smallexample
10955 (It is not clear whether this has any effect on the operation of the GNU
10956 maths library, but we have no evidence of it causing trouble.)
10957
10958 Some targets (such as the Alpha) may need special options for full IEEE
10959 conformance @xref{Submodel Options,,Hardware Models and
10960 Configurations,gcc,Using and Porting GNU CC}.
10961
10962 @node Inconsistent Calling Sequences
10963 @subsection Inconsistent Calling Sequences
10964
10965 @pindex ftnchek
10966 @cindex floating-point, errors
10967 @cindex ix86 FPU stack
10968 @cindex x86 FPU stack
10969 Code containing inconsistent calling sequences in the same file is
10970 normally rejected @xref{GLOBALS}.  (Use, say, @code{ftnchek} to ensure
10971 consistency across source files
10972 @c makeinfo 1.68 objects to the nested parens
10973 @ifinfo
10974 @xref{f2c Skeletons and Prototypes}.)
10975 @end ifinfo
10976 @ifnotinfo
10977 @xref{f2c Skeletons and Prototypes,,
10978 {Generating Skeletons and Prototypes with @code{f2c}}}.)
10979 @end ifnotinfo
10980
10981 Mysterious errors, which may appear to be code generation problems, can
10982 appear specifically on the x86 architecture with some such
10983 inconsistencies.  On x86 hardware, floating-point return values of
10984 functions are placed on the floating-point unit's register stack, not
10985 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
10986 @code{FUNCTION} as some other sort of procedure, or vice versa,
10987 scrambles the floating-point stack.  This may break unrelated code
10988 executed later.  Similarly if, say, external C routines are written
10989 incorrectly.
10990
10991 @node Overly Convenient Options
10992 @section Overly Convenient Command-line Options
10993 @cindex overly convenient options
10994 @cindex options, overly convenient
10995
10996 These options should be used only as a quick-and-dirty way to determine
10997 how well your program will run under different compilation models
10998 without having to change the source.
10999 Some are more problematic
11000 than others, depending on how portable and maintainable you want the
11001 program to be (and, of course, whether you are allowed to change it
11002 at all is crucial).
11003
11004 You should not continue to use these command-line options to compile
11005 a given program, but rather should make changes to the source code:
11006
11007 @table @code
11008 @cindex -finit-local-zero option
11009 @cindex options, -finit-local-zero
11010 @item -finit-local-zero
11011 (This option specifies that any uninitialized local variables
11012 and arrays have default initialization to binary zeros.)
11013
11014 Many other compilers do this automatically, which means lots of
11015 Fortran code developed with those compilers depends on it.
11016
11017 It is safer (and probably
11018 would produce a faster program) to find the variables and arrays that
11019 need such initialization and provide it explicitly via @code{DATA}, so that
11020 @samp{-finit-local-zero} is not needed.
11021
11022 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
11023 find likely candidates, but
11024 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
11025 or this technique won't work.
11026
11027 @cindex -fno-automatic option
11028 @cindex options, -fno-automatic
11029 @item -fno-automatic
11030 (This option specifies that all local variables and arrays
11031 are to be treated as if they were named in @code{SAVE} statements.)
11032
11033 Many other compilers do this automatically, which means lots of
11034 Fortran code developed with those compilers depends on it.
11035
11036 The effect of this is that all non-automatic variables and arrays
11037 are made static, that is, not placed on the stack or in heap storage.
11038 This might cause a buggy program to appear to work better.
11039 If so, rather than relying on this command-line option (and hoping all
11040 compilers provide the equivalent one), add @code{SAVE}
11041 statements to some or all program unit sources, as appropriate.
11042 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
11043 to find likely candidates, but
11044 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
11045 or this technique won't work.
11046
11047 The default is @samp{-fautomatic}, which tells @code{g77} to try
11048 and put variables and arrays on the stack (or in fast registers)
11049 where possible and reasonable.
11050 This tends to make programs faster.
11051
11052 @cindex automatic arrays
11053 @cindex arrays, automatic
11054 @emph{Note:} Automatic variables and arrays are not affected
11055 by this option.
11056 These are variables and arrays that are @emph{necessarily} automatic,
11057 either due to explicit statements, or due to the way they are
11058 declared.
11059 Examples include local variables and arrays not given the
11060 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
11061 and local arrays declared with non-constant bounds (automatic
11062 arrays).
11063 Currently, @code{g77} supports only automatic arrays, not
11064 @code{RECURSIVE} procedures or other means of explicitly
11065 specifying that variables or arrays are automatic.
11066
11067 @cindex -fugly option
11068 @cindex options, -fugly
11069 @item -fugly
11070 Fix the source code so that @samp{-fno-ugly} will work.
11071 Note that, for many programs, it is difficult to practically
11072 avoid using the features enabled via @samp{-fugly-init}, and these
11073 features pose the lowest risk of writing nonportable code, among the
11074 various ``ugly'' features.
11075
11076 @cindex -f@var{group}-intrinsics-hide option
11077 @cindex options, -f@var{group}-intrinsics-hide
11078 @item -f@var{group}-intrinsics-hide
11079 Change the source code to use @code{EXTERNAL} for any external procedure
11080 that might be the name of an intrinsic.
11081 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
11082 @end table
11083
11084 @node Faster Programs
11085 @section Faster Programs
11086 @cindex speed, of programs
11087 @cindex programs, speeding up
11088
11089 Aside from the usual @code{gcc} options, such as @samp{-O},
11090 @samp{-ffast-math}, and so on, consider trying some of the
11091 following approaches to speed up your program (once you get
11092 it working).
11093
11094 @menu
11095 * Aligned Data::
11096 * Prefer Automatic Uninitialized Variables::
11097 * Avoid f2c Compatibility::
11098 * Use Submodel Options::
11099 @end menu
11100
11101 @node Aligned Data
11102 @subsection Aligned Data
11103 @cindex data, aligned
11104 @cindex stack, aligned
11105 @cindex aligned data
11106 @cindex aligned stack
11107 @cindex Pentium optimizations
11108 @cindex optimization, for Pentium
11109
11110 On some systems, such as those with Pentium Pro CPUs, programs
11111 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
11112 might run much slower
11113 than possible due to the compiler not aligning these 64-bit
11114 values to 64-bit boundaries in memory.
11115 (The effect also is present, though
11116 to a lesser extent, on the 586 (Pentium) architecture.)
11117
11118 The Intel x86 architecture generally ensures that these programs will
11119 work on all its implementations,
11120 but particular implementations (such as Pentium Pro)
11121 perform better with more strict alignment.
11122 (Such behavior isn't unique to the Intel x86 architecture.)
11123 Other architectures might @emph{demand} 64-bit alignment
11124 of 64-bit data.
11125
11126 There are a variety of approaches to use to address this problem:
11127
11128 @itemize @bullet
11129 @item
11130 @cindex @code{COMMON} layout
11131 @cindex layout of @code{COMMON} blocks
11132 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
11133 that the variables and arrays with the widest alignment
11134 guidelines come first.
11135
11136 For example, on most systems, this would mean placing
11137 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
11138 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
11139 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
11140 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
11141 and @code{INTEGER(KIND=3)} entities.
11142
11143 The reason to use such placement is it makes it more likely
11144 that your data will be aligned properly, without requiring
11145 you to do detailed analysis of each aggregate (@code{COMMON}
11146 and @code{EQUIVALENCE}) area.
11147
11148 Specifically, on systems where the above guidelines are
11149 appropriate, placing @code{CHARACTER} entities before
11150 @code{REAL(KIND=2)} entities can work just as well,
11151 but only if the number of bytes occupied by the @code{CHARACTER}
11152 entities is divisible by the recommended alignment for
11153 @code{REAL(KIND=2)}.
11154
11155 By ordering the placement of entities in aggregate
11156 areas according to the simple guidelines above, you
11157 avoid having to carefully count the number of bytes
11158 occupied by each entity to determine whether the
11159 actual alignment of each subsequent entity meets the
11160 alignment guidelines for the type of that entity.
11161
11162 If you don't ensure correct alignment of @code{COMMON} elements, the
11163 compiler may be forced by some systems to violate the Fortran semantics by
11164 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
11165 If the unfortunate practice is employed of overlaying different types of
11166 data in the @code{COMMON} block, the different variants
11167 of this block may become misaligned with respect to each other.
11168 Even if your platform doesn't require strict alignment,
11169 @code{COMMON} should be laid out as above for portability.
11170 (Unfortunately the FORTRAN 77 standard didn't anticipate this
11171 possible requirement, which is compiler-independent on a given platform.)
11172
11173 @item
11174 @cindex -malign-double option
11175 @cindex options, -malign-double
11176 Use the (x86-specific) @samp{-malign-double} option when compiling
11177 programs for the Pentium and Pentium Pro architectures (called 586
11178 and 686 in the @code{gcc} configuration subsystem).
11179 The warning about this in the @code{gcc} manual isn't
11180 generally relevant to Fortran,
11181 but using it will force @code{COMMON} to be padded if necessary to align
11182 @code{DOUBLE PRECISION} data.
11183
11184 When @code{DOUBLE PRECISION} data is forcibly aligned
11185 in @code{COMMON} by @code{g77} due to specifying @samp{-malign-double},
11186 @code{g77} issues a warning about the need to
11187 insert padding.
11188
11189 In this case, each and every program unit that uses
11190 the same @code{COMMON} area
11191 must specify the same layout of variables and their types
11192 for that area
11193 and be compiled with @samp{-malign-double} as well.
11194 @code{g77} will issue warnings in each case,
11195 but as long as every program unit using that area
11196 is compiled with the same warnings,
11197 the resulting object files should work when linked together
11198 unless the program makes additional assumptions about
11199 @code{COMMON} area layouts that are outside the scope
11200 of the FORTRAN 77 standard,
11201 or uses @code{EQUIVALENCE} or different layouts
11202 in ways that assume no padding is ever inserted by the compiler.
11203
11204 @emph{Note:} @samp{-malign-double} applies only to
11205 statically-allocated data.
11206 Double-precision data on the stack can still
11207 cause problems due to misalignment.
11208 @xref{Aligned Data}.
11209
11210 @item
11211 Ensure that @file{crt0.o} or @file{crt1.o}
11212 on your system guarantees a 64-bit
11213 aligned stack for @code{main()}.
11214 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
11215 but we don't know of any other x86 setups where it will be right.
11216 Read your system's documentation to determine if
11217 it is appropriate to upgrade to a more recent version
11218 to obtain the optimal alignment.
11219 @end itemize
11220
11221 Progress is being made on making this work
11222 ``out of the box'' on future versions of @code{g77},
11223 @code{gcc}, and some of the relevant operating systems
11224 (such as GNU/Linux).
11225
11226 @node Prefer Automatic Uninitialized Variables
11227 @subsection Prefer Automatic Uninitialized Variables
11228
11229 If you're using @samp{-fno-automatic} already, you probably
11230 should change your code to allow compilation with @samp{-fautomatic}
11231 (the default), to allow the program to run faster.
11232
11233 Similarly, you should be able to use @samp{-fno-init-local-zero}
11234 (the default) instead of @samp{-finit-local-zero}.
11235 This is because it is rare that every variable affected by these
11236 options in a given program actually needs to
11237 be so affected.
11238
11239 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
11240 every local non-automatic variable and array, affects even things like
11241 @code{DO} iteration
11242 variables, which rarely need to be @code{SAVE}d, and this often reduces
11243 run-time performances.
11244 Similarly, @samp{-fno-init-local-zero} forces such
11245 variables to be initialized to zero---when @code{SAVE}d (such as when
11246 @samp{-fno-automatic}), this by itself generally affects only
11247 startup time for a program, but when not @code{SAVE}d,
11248 it can slow down the procedure every time it is called.
11249
11250 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
11251 for information on the @samp{-fno-automatic} and
11252 @samp{-finit-local-zero} options and how to convert
11253 their use into selective changes in your own code.
11254
11255 @node Avoid f2c Compatibility
11256 @subsection Avoid f2c Compatibility
11257 @cindex -fno-f2c option
11258 @cindex options, -fno-f2c
11259 @cindex @code{f2c} compatibility
11260 @cindex compatibility, @code{f2c}
11261
11262 If you aren't linking with any code compiled using
11263 @code{f2c}, try using the @samp{-fno-f2c} option when
11264 compiling @emph{all} the code in your program.
11265 (Note that @code{libf2c} is @emph{not} an example of code
11266 that is compiled using @code{f2c}---it is compiled by a C
11267 compiler, typically @code{gcc}.)
11268
11269 @node Use Submodel Options
11270 @subsection Use Submodel Options
11271 @cindex Pentium optimizations
11272 @cindex optimization, for Pentium
11273 @cindex 586/686 CPUs
11274 @cindex submodels
11275
11276 Using an appropriate @samp{-m} option to generate specific code for your
11277 CPU may be worthwhile, though it may mean the executable won't run on
11278 other versions of the CPU that don't support the same instruction set.
11279 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
11280 Porting GNU CC}.
11281
11282 For recent CPUs that don't have explicit support in
11283 the released version of @code{gcc}, it may still be possible to get
11284 improvements.
11285 For instance, the flags recommended for 586/686
11286 (Pentium(Pro)) chips for building the Linux kernel are:
11287
11288 @smallexample
11289 -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2
11290 -fomit-frame-pointer
11291 @end smallexample
11292
11293 @noindent @samp{-fomit-frame-pointer} will, however, inhibit debugging
11294 on x86 systems.
11295
11296 @node Trouble
11297 @chapter Known Causes of Trouble with GNU Fortran
11298 @cindex bugs, known
11299 @cindex installation trouble
11300 @cindex known causes of trouble
11301
11302 This section describes known problems that affect users of GNU Fortran.
11303 Most of these are not GNU Fortran bugs per se---if they were, we would
11304 fix them.
11305 But the result for a user might be like the result of a bug.
11306
11307 Some of these problems are due to bugs in other software, some are
11308 missing features that are too much work to add, and some are places
11309 where people's opinions differ as to what is best.
11310
11311 Information on bugs that show up when configuring, porting, building,
11312 or installing @code{g77} is not provided here.
11313 @xref{Problems Installing}.
11314
11315 To find out about major bugs discovered in the current release and
11316 possible workarounds for them, retrieve
11317 @uref{ftp://alpha.gnu.org/g77.plan}.
11318
11319 (Note that some of this portion of the manual is lifted
11320 directly from the @code{gcc} manual, with minor modifications
11321 to tailor it to users of @code{g77}.
11322 Anytime a bug seems to have more to do with the @code{gcc}
11323 portion of @code{g77},
11324 @xref{Trouble,,Known Causes of Trouble with GNU CC,
11325 gcc,Using and Porting GNU CC}.)
11326
11327 @menu
11328 * But-bugs::         Bugs really in other programs or elsewhere.
11329 * Actual Bugs::      Bugs and misfeatures we will fix later.
11330 * Missing Features:: Features we already know we want to add later.
11331 * Disappointments::  Regrettable things we can't change.
11332 * Non-bugs::         Things we think are right, but some others disagree.
11333 * Warnings and Errors::  Which problems in your code get warnings,
11334                         and which get errors.
11335 @end menu
11336
11337 @node But-bugs
11338 @section Bugs Not In GNU Fortran
11339 @cindex but-bugs
11340
11341 These are bugs to which the maintainers often have to reply,
11342 ``but that isn't a bug in @code{g77}@dots{}''.
11343 Some of these already are fixed in new versions of other
11344 software; some still need to be fixed; some are problems
11345 with how @code{g77} is installed or is being used;
11346 some are the result of bad hardware that causes software
11347 to misbehave in sometimes bizarre ways;
11348 some just cannot be addressed at this time until more
11349 is known about the problem.
11350
11351 Please don't re-report these bugs to the @code{g77} maintainers---if
11352 you must remind someone how important it is to you that the problem
11353 be fixed, talk to the people responsible for the other products
11354 identified below, but preferably only after you've tried the
11355 latest versions of those products.
11356 The @code{g77} maintainers have their hands full working on
11357 just fixing and improving @code{g77}, without serving as a
11358 clearinghouse for all bugs that happen to affect @code{g77}
11359 users.
11360
11361 @xref{Collected Fortran Wisdom}, for information on behavior
11362 of Fortran programs, and the programs that compile them, that
11363 might be @emph{thought} to indicate bugs.
11364
11365 @menu
11366 * Signal 11 and Friends::  Strange behavior by any software.
11367 * Cannot Link Fortran Programs::  Unresolved references.
11368 * Large Common Blocks::    Problems on older GNU/Linux systems.
11369 * Debugger Problems::      When the debugger crashes.
11370 * NeXTStep Problems::      Misbehaving executables.
11371 * Stack Overflow::         More misbehaving executables.
11372 * Nothing Happens::        Less behaving executables.
11373 * Strange Behavior at Run Time::  Executables misbehaving due to
11374                             bugs in your program.
11375 * Floating-point Errors::  The results look wrong, but@dots{}.
11376 @end menu
11377
11378 @node Signal 11 and Friends
11379 @subsection Signal 11 and Friends
11380 @cindex signal 11
11381 @cindex hardware errors
11382
11383 A whole variety of strange behaviors can occur when the
11384 software, or the way you are using the software,
11385 stresses the hardware in a way that triggers hardware bugs.
11386 This might seem hard to believe, but it happens frequently
11387 enough that there exist documents explaining in detail
11388 what the various causes of the problems are, what
11389 typical symptoms look like, and so on.
11390
11391 Generally these problems are referred to in this document
11392 as ``signal 11'' crashes, because the Linux kernel, running
11393 on the most popular hardware (the Intel x86 line), often
11394 stresses the hardware more than other popular operating
11395 systems.
11396 When hardware problems do occur under GNU/Linux on x86
11397 systems, these often manifest themselves as ``signal 11''
11398 problems, as illustrated by the following diagnostic:
11399
11400 @smallexample
11401 sh# @kbd{g77 myprog.f}
11402 gcc: Internal compiler error: program f771 got fatal signal 11
11403 sh#
11404 @end smallexample
11405
11406 It is @emph{very} important to remember that the above
11407 message is @emph{not} the only one that indicates a
11408 hardware problem, nor does it always indicate a hardware
11409 problem.
11410
11411 In particular, on systems other than those running the Linux
11412 kernel, the message might appear somewhat or very different,
11413 as it will if the error manifests itself while running a
11414 program other than the @code{g77} compiler.
11415 For example,
11416 it will appear somewhat different when running your program,
11417 when running Emacs, and so on.
11418
11419 How to cope with such problems is well beyond the scope
11420 of this manual.
11421
11422 However, users of Linux-based systems (such as GNU/Linux)
11423 should review @uref{http://www.bitwizard.nl/sig11}, a source
11424 of detailed information on diagnosing hardware problems,
11425 by recognizing their common symptoms.
11426
11427 Users of other operating systems and hardware might
11428 find this reference useful as well.
11429 If you know of similar material for another hardware/software
11430 combination, please let us know so we can consider including
11431 a reference to it in future versions of this manual.
11432
11433 @node Cannot Link Fortran Programs
11434 @subsection Cannot Link Fortran Programs
11435 @cindex unresolved reference (various)
11436 @cindex linking error for user code
11437 @cindex code, user
11438 @cindex @code{ld}, error linking user code
11439 @cindex @code{ld}, can't find strange names
11440 On some systems, perhaps just those with out-of-date (shared?)
11441 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
11442 programs (which should be done using @code{g77}).
11443
11444 If this happens to you, try appending @samp{-lc} to the command you
11445 use to link the program, e.g. @samp{g77 foo.f -lc}.
11446 @code{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
11447 but it cannot also specify @samp{-lc} because not all systems have a
11448 file named @file{libc.a}.
11449
11450 It is unclear at this point whether there are legitimately installed
11451 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
11452 by @code{g77}.
11453
11454 @cindex undefined reference (_main)
11455 @cindex linking error, user code
11456 @cindex @code{ld}, error linking user code
11457 @cindex code, user
11458 @cindex @code{ld}, can't find @samp{_main}
11459 If your program doesn't link due to unresolved references to names
11460 like @samp{_main}, make sure you're using the @code{g77} command to do the
11461 link, since this command ensures that the necessary libraries are
11462 loaded by specifying @samp{-lg2c -lm} when it invokes the @code{gcc}
11463 command to do the actual link.
11464 (Use the @samp{-v} option to discover
11465 more about what actually happens when you use the @code{g77} and @code{gcc}
11466 commands.)
11467
11468 Also, try specifying @samp{-lc} as the last item on the @code{g77}
11469 command line, in case that helps.
11470
11471 @node Large Common Blocks
11472 @subsection Large Common Blocks
11473 @cindex common blocks, large
11474 @cindex large common blocks
11475 @cindex linking, errors
11476 @cindex @code{ld}, errors
11477 @cindex errors, linker
11478 On some older GNU/Linux systems, programs with common blocks larger
11479 than 16MB cannot be linked without some kind of error
11480 message being produced.
11481
11482 This is a bug in older versions of @code{ld}, fixed in
11483 more recent versions of @code{binutils}, such as version 2.6.
11484
11485 @node Debugger Problems
11486 @subsection Debugger Problems
11487 @cindex @code{gdb}, support
11488 @cindex support, @code{gdb}
11489 There are some known problems when using @code{gdb} on code
11490 compiled by @code{g77}.
11491 Inadequate investigation as of the release of 0.5.16 results in not
11492 knowing which products are the culprit, but @file{gdb-4.14} definitely
11493 crashes when, for example, an attempt is made to print the contents
11494 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
11495 machines, plus some others.
11496 Attempts to access assumed-size arrays are
11497 also known to crash recent versions of @code{gdb}.
11498 (@code{gdb}'s Fortran support was done for a different compiler
11499 and isn't properly compatible with @code{g77}.)
11500
11501 @node NeXTStep Problems
11502 @subsection NeXTStep Problems
11503 @cindex NeXTStep problems
11504 @cindex bus error
11505 @cindex segmentation violation
11506 Developers of Fortran code on NeXTStep (all architectures) have to
11507 watch out for the following problem when writing programs with
11508 large, statically allocated (i.e. non-stack based) data structures
11509 (common blocks, saved arrays).
11510
11511 Due to the way the native loader (@file{/bin/ld}) lays out
11512 data structures in virtual memory, it is very easy to create an
11513 executable wherein the @samp{__DATA} segment overlaps (has addresses in
11514 common) with the @samp{UNIX STACK} segment.
11515
11516 This leads to all sorts of trouble, from the executable simply not
11517 executing, to bus errors.
11518 The NeXTStep command line tool @code{ebadexec} points to
11519 the problem as follows:
11520
11521 @smallexample
11522 % @kbd{/bin/ebadexec a.out}
11523 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
11524 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
11525 STACK segment (truncated address = 0x400000 rounded size =
11526 0x3c00000) of executable file: a.out
11527 @end smallexample
11528
11529 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
11530 stack segment.)
11531
11532 This can be cured by assigning the @samp{__DATA} segment
11533 (virtual) addresses beyond the stack segment.
11534 A conservative
11535 estimate for this is from address 6000000 (hexadecimal) onwards---this
11536 has always worked for me [Toon Moene]:
11537
11538 @smallexample
11539 % @kbd{g77 -segaddr __DATA 6000000 test.f}
11540 % @kbd{ebadexec a.out}
11541 ebadexec: file: a.out appears to be executable
11542 %
11543 @end smallexample
11544
11545 Browsing through @file{@value{path-g77}/Makefile.in},
11546 you will find that the @code{f771} program itself also has to be
11547 linked with these flags---it has large statically allocated
11548 data structures.
11549 (Version 0.5.18 reduces this somewhat, but probably
11550 not enough.)
11551
11552 (The above item was contributed by Toon Moene
11553 (@email{toon@@moene.indiv.nluug.nl}).)
11554
11555 @node Stack Overflow
11556 @subsection Stack Overflow
11557 @cindex stack, overflow
11558 @cindex segmentation violation
11559 @code{g77} code might fail at runtime (probably with a ``segmentation
11560 violation'') due to overflowing the stack.
11561 This happens most often on systems with an environment
11562 that provides substantially more heap space (for use
11563 when arbitrarily allocating and freeing memory) than stack
11564 space.
11565
11566 Often this can be cured by
11567 increasing or removing your shell's limit on stack usage, typically
11568 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
11569 @kbd{ulimit -s} (in @code{sh} and derivatives).
11570
11571 Increasing the allowed stack size might, however, require
11572 changing some operating system or system configuration parameters.
11573
11574 You might be able to work around the problem by compiling with the
11575 @samp{-fno-automatic} option to reduce stack usage, probably at the
11576 expense of speed.
11577
11578 @xref{Maximum Stackable Size}, for information on patching
11579 @code{g77} to use different criteria for placing local
11580 non-automatic variables and arrays on the stack.
11581
11582 @cindex automatic arrays
11583 @cindex arrays, automatic
11584 However, if your program uses large automatic arrays
11585 (for example, has declarations like @samp{REAL A(N)} where
11586 @samp{A} is a local array and @samp{N} is a dummy or
11587 @code{COMMON} variable that can have a large value),
11588 neither use of @samp{-fno-automatic},
11589 nor changing the cut-off point for @code{g77} for using the stack,
11590 will solve the problem by changing the placement of these
11591 large arrays, as they are @emph{necessarily} automatic.
11592
11593 @code{g77} currently provides no means to specify that
11594 automatic arrays are to be allocated on the heap instead
11595 of the stack.
11596 So, other than increasing the stack size, your best bet is to
11597 change your source code to avoid large automatic arrays.
11598 Methods for doing this currently are outside the scope of
11599 this document.
11600
11601 (@emph{Note:} If your system puts stack and heap space in the
11602 same memory area, such that they are effectively combined, then
11603 a stack overflow probably indicates a program that is either
11604 simply too large for the system, or buggy.)
11605
11606 @node Nothing Happens
11607 @subsection Nothing Happens
11608 @cindex nothing happens
11609 @cindex naming programs
11610 @cindex @samp{test} programs
11611 @cindex programs, @samp{test}
11612 It is occasionally reported that a ``simple'' program,
11613 such as a ``Hello, World!'' program, does nothing when
11614 it is run, even though the compiler reported no errors,
11615 despite the program containing nothing other than a
11616 simple @code{PRINT} statement.
11617
11618 This most often happens because the program has been
11619 compiled and linked on a UNIX system and named @samp{test},
11620 though other names can lead to similarly unexpected
11621 run-time behavior on various systems.
11622
11623 Essentially this problem boils down to giving
11624 your program a name that is already known to
11625 the shell you are using to identify some other program,
11626 which the shell continues to execute instead of your
11627 program when you invoke it via, for example:
11628
11629 @smallexample
11630 sh# @kbd{test}
11631 sh#
11632 @end smallexample
11633
11634 Under UNIX and many other system, a simple command name
11635 invokes a searching mechanism that might well not choose
11636 the program located in the current working directory if
11637 there is another alternative (such as the @code{test}
11638 command commonly installed on UNIX systems).
11639
11640 The reliable way to invoke a program you just linked in
11641 the current directory under UNIX is to specify it using
11642 an explicit pathname, as in:
11643
11644 @smallexample
11645 sh# @kbd{./test}
11646  Hello, World!
11647 sh#
11648 @end smallexample
11649
11650 Users who encounter this problem should take the time to
11651 read up on how their shell searches for commands, how to
11652 set their search path, and so on.
11653 The relevant UNIX commands to learn about include
11654 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
11655 @code{set} and @code{env}), @code{which}, and @code{find}.
11656
11657 @node Strange Behavior at Run Time
11658 @subsection Strange Behavior at Run Time
11659 @cindex segmentation violation
11660 @cindex bus error
11661 @cindex overwritten data
11662 @cindex data, overwritten
11663 @code{g77} code might fail at runtime with ``segmentation violation'',
11664 ``bus error'', or even something as subtle as a procedure call
11665 overwriting a variable or array element that it is not supposed
11666 to touch.
11667
11668 These can be symptoms of a wide variety of actual bugs that
11669 occurred earlier during the program's run, but manifested
11670 themselves as @emph{visible} problems some time later.
11671
11672 Overflowing the bounds of an array---usually by writing beyond
11673 the end of it---is one of two kinds of bug that often occurs
11674 in Fortran code.
11675
11676 The other kind of bug is a mismatch between the actual arguments
11677 passed to a procedure and the dummy arguments as declared by that
11678 procedure.
11679
11680 Both of these kinds of bugs, and some others as well, can be
11681 difficult to track down, because the bug can change its behavior,
11682 or even appear to not occur, when using a debugger.
11683
11684 That is, these bugs can be quite sensitive to data, including
11685 data representing the placement of other data in memory (that is,
11686 pointers, such as the placement of stack frames in memory).
11687
11688 Plans call for improving @code{g77} so that it can offer the
11689 ability to catch and report some of these problems at compile, link, or
11690 run time, such as by generating code to detect references to
11691 beyond the bounds of an array, or checking for agreement between
11692 calling and called procedures.
11693
11694 In the meantime, finding and fixing the programming
11695 bugs that lead to these behaviors is, ultimately, the user's
11696 responsibility, as difficult as that task can sometimes be.
11697
11698 @cindex infinite spaces printed
11699 @cindex space, endless printing of
11700 @cindex libc, non-ANSI or non-default
11701 @cindex C library
11702 @cindex linking against non-standard library
11703 @cindex Solaris
11704 One runtime problem that has been observed might have a simple solution.
11705 If a formatted @code{WRITE} produces an endless stream of spaces, check
11706 that your program is linked against the correct version of the C library.
11707 The configuration process takes care to account for your
11708 system's normal @file{libc} not being ANSI-standard, which will
11709 otherwise cause this behaviour.
11710 If your system's default library is
11711 ANSI-standard and you subsequently link against a non-ANSI one, there
11712 might be problems such as this one.
11713
11714 Specifically, on Solaris2 systems,
11715 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
11716
11717 @node Floating-point Errors
11718 @subsection Floating-point Errors
11719 @cindex floating-point errors
11720 @cindex rounding errors
11721 @cindex inconsistent floating-point results
11722 @cindex results, inconsistent
11723 Some programs appear to produce inconsistent floating-point
11724 results compiled by @code{g77} versus by other compilers.
11725
11726 Often the reason for this behavior is the fact that floating-point
11727 values are represented on almost all Fortran systems by
11728 @emph{approximations}, and these approximations are inexact
11729 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
11730 0.7, 0.8, 0.9, 1.1, and so on.
11731 Most Fortran systems, including all current ports of @code{g77},
11732 use binary arithmetic to represent these approximations.
11733
11734 Therefore, the exact value of any floating-point approximation
11735 as manipulated by @code{g77}-compiled code is representable by
11736 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
11737 so on (just keep dividing by two) through the precision of the
11738 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
11739 @code{REAL(KIND=2)}), then multiplying the sum by a integral
11740 power of two (in Fortran, by @samp{2**N}) that typically is between
11741 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
11742 @code{REAL(KIND=2)}, then multiplying by -1 if the number
11743 is negative.
11744
11745 So, a value like 0.2 is exactly represented in decimal---since
11746 it is a fraction, @samp{2/10}, with a denominator that is compatible
11747 with the base of the number system (base 10).
11748 However, @samp{2/10} cannot be represented by any finite number
11749 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
11750 be exactly represented in binary notation.
11751
11752 (On the other hand, decimal notation can represent any binary
11753 number in a finite number of digits.
11754 Decimal notation cannot do so with ternary, or base-3,
11755 notation, which would represent floating-point numbers as
11756 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
11757 After all, no finite number of decimal digits can exactly
11758 represent @samp{1/3}.
11759 Fortunately, few systems use ternary notation.)
11760
11761 Moreover, differences in the way run-time I/O libraries convert
11762 between these approximations and the decimal representation often
11763 used by programmers and the programs they write can result in
11764 apparent differences between results that do not actually exist,
11765 or exist to such a small degree that they usually are not worth
11766 worrying about.
11767
11768 For example, consider the following program:
11769
11770 @smallexample
11771 PRINT *, 0.2
11772 END
11773 @end smallexample
11774
11775 When compiled by @code{g77}, the above program might output
11776 @samp{0.20000003}, while another compiler might produce a
11777 executable that outputs @samp{0.2}.
11778
11779 This particular difference is due to the fact that, currently,
11780 conversion of floating-point values by the @code{libg2c} library,
11781 used by @code{g77}, handles only double-precision values.
11782
11783 Since @samp{0.2} in the program is a single-precision value, it
11784 is converted to double precision (still in binary notation)
11785 before being converted back to decimal.
11786 The conversion to binary appends _binary_ zero digits to the
11787 original value---which, again, is an inexact approximation of
11788 0.2---resulting in an approximation that is much less exact
11789 than is connoted by the use of double precision.
11790
11791 (The appending of binary zero digits has essentially the same
11792 effect as taking a particular decimal approximation of
11793 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
11794 zeros to it, producing @samp{0.33333330000000000}.
11795 Treating the resulting decimal approximation as if it really
11796 had 18 or so digits of valid precision would make it seem
11797 a very poor approximation of @samp{1/3}.)
11798
11799 As a result of converting the single-precision approximation
11800 to double precision by appending binary zeros, the conversion
11801 of the resulting double-precision
11802 value to decimal produces what looks like an incorrect
11803 result, when in fact the result is @emph{inexact}, and
11804 is probably no less inaccurate or imprecise an approximation
11805 of 0.2 than is produced by other compilers that happen to output
11806 the converted value as ``exactly'' @samp{0.2}.
11807 (Some compilers behave in a way that can make them appear
11808 to retain more accuracy across a conversion of a single-precision
11809 constant to double precision.
11810 @xref{Context-Sensitive Constants}, to see why
11811 this practice is illusory and even dangerous.)
11812
11813 Note that a more exact approximation of the constant is
11814 computed when the program is changed to specify a
11815 double-precision constant:
11816
11817 @smallexample
11818 PRINT *, 0.2D0
11819 END
11820 @end smallexample
11821
11822 Future versions of @code{g77} and/or @code{libg2c} might convert
11823 single-precision values directly to decimal,
11824 instead of converting them to double precision first.
11825 This would tend to result in output that is more consistent
11826 with that produced by some other Fortran implementations.
11827
11828 A useful source of information on floating-point computation is David
11829 Goldberg, `What Every Computer Scientist Should Know About
11830 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
11831 5--48.
11832 An online version is available at
11833 @uref{http://docs.sun.com},
11834 and there is a supplemented version, in PostScript form, at
11835 @uref{http://www.validgh.com/goldberg/paper.ps}.
11836
11837 Information related to the IEEE 754
11838 floating-point standard by a leading light can be found at
11839 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status};
11840 see also slides from the short course referenced from
11841 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
11842 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
11843 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
11844 and library code for GNU/Linux x86 systems.
11845
11846 The supplement to the PostScript-formatted Goldberg document,
11847 referenced above, is available in HTML format.
11848 See `Differences Among IEEE 754 Implementations' by Doug Priest,
11849 available online at
11850 @uref{http://www.validgh.com/goldberg/addendum.html}.
11851 This document explores some of the issues surrounding computing
11852 of extended (80-bit) results on processors such as the x86,
11853 especially when those results are arbitrarily truncated
11854 to 32-bit or 64-bit values by the compiler
11855 as ``spills''.
11856
11857 @cindex spills of floating-point results
11858 @cindex 80-bit spills
11859 @cindex truncation, of floating-point values
11860 (@emph{Note:} @code{g77} specifically, and @code{gcc} generally,
11861 does arbitrarily truncate 80-bit results during spills
11862 as of this writing.
11863 It is not yet clear whether a future version of
11864 the GNU compiler suite will offer 80-bit spills
11865 as an option, or perhaps even as the default behavior.)
11866
11867 @c xref would be different between editions:
11868 The GNU C library provides routines for controlling the FPU, and other
11869 documentation about this.
11870
11871 @xref{Floating-point precision}, regarding IEEE 754 conformance.
11872
11873 @include bugs.texi
11874
11875 @node Missing Features
11876 @section Missing Features
11877
11878 This section lists features we know are missing from @code{g77},
11879 and which we want to add someday.
11880 (There is no priority implied in the ordering below.)
11881
11882 @menu
11883 GNU Fortran language:
11884 * Better Source Model::
11885 * Fortran 90 Support::
11886 * Intrinsics in PARAMETER Statements::
11887 * SELECT CASE on CHARACTER Type::
11888 * RECURSIVE Keyword::
11889 * Popular Non-standard Types::
11890 * Full Support for Compiler Types::
11891 * Array Bounds Expressions::
11892 * POINTER Statements::
11893 * Sensible Non-standard Constructs::
11894 * FLUSH Statement::
11895 * Expressions in FORMAT Statements::
11896 * Explicit Assembler Code::
11897 * Q Edit Descriptor::
11898
11899 GNU Fortran dialects:
11900 * Old-style PARAMETER Statements::
11901 * TYPE and ACCEPT I/O Statements::
11902 * STRUCTURE UNION RECORD MAP::
11903 * OPEN CLOSE and INQUIRE Keywords::
11904 * ENCODE and DECODE::
11905 * Suppressing Space Padding::
11906 * Fortran Preprocessor::
11907 * Bit Operations on Floating-point Data::
11908
11909 New facilities:
11910 * POSIX Standard::
11911 * Floating-point Exception Handling::
11912 * Nonportable Conversions::
11913 * Large Automatic Arrays::
11914 * Support for Threads::
11915 * Increasing Precision/Range::
11916
11917 Better diagnostics:
11918 * Gracefully Handle Sensible Bad Code::
11919 * Non-standard Conversions::
11920 * Non-standard Intrinsics::
11921 * Modifying DO Variable::
11922 * Better Pedantic Compilation::
11923 * Warn About Implicit Conversions::
11924 * Invalid Use of Hollerith Constant::
11925 * Dummy Array Without Dimensioning Dummy::
11926 * Invalid FORMAT Specifiers::
11927 * Ambiguous Dialects::
11928 * Unused Labels::
11929 * Informational Messages::
11930
11931 Run-time facilities:
11932 * Uninitialized Variables at Run Time::
11933 * Bounds Checking at Run Time::
11934 * Portable Unformatted Files::
11935
11936 Debugging:
11937 * Labels Visible to Debugger::
11938 @end menu
11939
11940 @node Better Source Model
11941 @subsection Better Source Model
11942
11943 @code{g77} needs to provide, as the default source-line model,
11944 a ``pure visual'' mode, where
11945 the interpretation of a source program in this mode can be accurately
11946 determined by a user looking at a traditionally displayed rendition
11947 of the program (assuming the user knows whether the program is fixed
11948 or free form).
11949
11950 The design should assume the user cannot tell tabs from spaces
11951 and cannot see trailing spaces on lines, but has canonical tab stops
11952 and, for fixed-form source, has the ability to always know exactly
11953 where column 72 is (since the Fortran standard itself requires
11954 this for fixed-form source).
11955
11956 This would change the default treatment of fixed-form source
11957 to not treat lines with tabs as if they were infinitely long---instead,
11958 they would end at column 72 just as if the tabs were replaced
11959 by spaces in the canonical way.
11960
11961 As part of this, provide common alternate models (Digital, @code{f2c},
11962 and so on) via command-line options.
11963 This includes allowing arbitrarily long
11964 lines for free-form source as well as fixed-form source and providing
11965 various limits and diagnostics as appropriate.
11966
11967 @cindex sequence numbers
11968 @cindex columns 73 through 80
11969 Also, @code{g77} should offer, perhaps even default to, warnings
11970 when characters beyond the last valid column are anything other
11971 than spaces.
11972 This would mean code with ``sequence numbers'' in columns 73 through 80
11973 would be rejected, and there's a lot of that kind of code around,
11974 but one of the most frequent bugs encountered by new users is
11975 accidentally writing fixed-form source code into and beyond
11976 column 73.
11977 So, maybe the users of old code would be able to more easily handle
11978 having to specify, say, a @code{-Wno-col73to80} option.
11979
11980 @node Fortran 90 Support
11981 @subsection Fortran 90 Support
11982 @cindex Fortran 90, support
11983 @cindex support, Fortran 90
11984
11985 @code{g77} does not support many of the features that
11986 distinguish Fortran 90 (and, now, Fortran 95) from
11987 ANSI FORTRAN 77.
11988
11989 Some Fortran 90 features are supported, because they
11990 make sense to offer even to die-hard users of F77.
11991 For example, many of them codify various ways F77 has
11992 been extended to meet users' needs during its tenure,
11993 so @code{g77} might as well offer them as the primary
11994 way to meet those same needs, even if it offers compatibility
11995 with one or more of the ways those needs were met
11996 by other F77 compilers in the industry.
11997
11998 Still, many important F90 features are not supported,
11999 because no attempt has been made to research each and
12000 every feature and assess its viability in @code{g77}.
12001 In the meantime, users who need those features must
12002 use Fortran 90 compilers anyway, and the best approach
12003 to adding some F90 features to GNU Fortran might well be
12004 to fund a comprehensive project to create GNU Fortran 95.
12005
12006 @node Intrinsics in PARAMETER Statements
12007 @subsection Intrinsics in @code{PARAMETER} Statements
12008 @cindex PARAMETER statement
12009 @cindex statements, PARAMETER
12010
12011 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
12012 This feature is considered to be absolutely vital, even though it
12013 is not standard-conforming, and is scheduled for version 0.6.
12014
12015 Related to this, @code{g77} doesn't allow non-integral
12016 exponentiation in @code{PARAMETER} statements, such as
12017 @samp{PARAMETER (R=2**.25)}.
12018 It is unlikely @code{g77} will ever support this feature,
12019 as doing it properly requires complete emulation of
12020 a target computer's floating-point facilities when
12021 building @code{g77} as a cross-compiler.
12022 But, if the @code{gcc} back end is enhanced to provide
12023 such a facility, @code{g77} will likely use that facility
12024 in implementing this feature soon afterwards.
12025
12026 @node SELECT CASE on CHARACTER Type
12027 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
12028
12029 Character-type selector/cases for @code{SELECT CASE} currently
12030 are not supported.
12031
12032 @node RECURSIVE Keyword
12033 @subsection @code{RECURSIVE} Keyword
12034 @cindex RECURSIVE keyword
12035 @cindex keywords, RECURSIVE
12036 @cindex recursion, lack of
12037 @cindex lack of recursion
12038
12039 @code{g77} doesn't support the @code{RECURSIVE} keyword that
12040 F90 compilers do.
12041 Nor does it provide any means for compiling procedures
12042 designed to do recursion.
12043
12044 All recursive code can be rewritten to not use recursion,
12045 but the result is not pretty.
12046
12047 @node Increasing Precision/Range
12048 @subsection Increasing Precision/Range
12049 @cindex -r8
12050 @cindex -qrealsize=8
12051 @cindex -i8
12052 @cindex f2c
12053 @cindex increasing precision
12054 @cindex precision, increasing
12055 @cindex increasing range
12056 @cindex range, increasing
12057 @cindex Toolpack
12058 @cindex Netlib
12059
12060 Some compilers, such as @code{f2c}, have an option (@samp{-r8},
12061 @samp{-qrealsize=8} or
12062 similar) that provides automatic treatment of @code{REAL}
12063 entities such that they have twice the storage size, and
12064 a corresponding increase in the range and precision, of what
12065 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
12066 (This affects @code{COMPLEX} the same way.)
12067
12068 They also typically offer another option (@samp{-i8}) to increase
12069 @code{INTEGER} entities so they are twice as large
12070 (with roughly twice as much range).
12071
12072 (There are potential pitfalls in using these options.)
12073
12074 @code{g77} does not yet offer any option that performs these
12075 kinds of transformations.
12076 Part of the problem is the lack of detailed specifications regarding
12077 exactly how these options affect the interpretation of constants,
12078 intrinsics, and so on.
12079
12080 Until @code{g77} addresses this need, programmers could improve
12081 the portability of their code by modifying it to not require
12082 compile-time options to produce correct results.
12083 Some free tools are available which may help, specifically
12084 in Toolpack (which one would expect to be sound) and the @file{fortran}
12085 section of the Netlib repository.
12086
12087 Use of preprocessors can provide a fairly portable means
12088 to work around the lack of widely portable methods in the Fortran
12089 language itself (though increasing acceptance of Fortran 90 would
12090 alleviate this problem).
12091
12092 @node Popular Non-standard Types
12093 @subsection Popular Non-standard Types
12094 @cindex @code{INTEGER*2} support
12095 @cindex types, @code{INTEGER*2}
12096 @cindex @code{LOGICAL*1} support
12097 @cindex types, @code{LOGICAL*1}
12098
12099 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
12100 and similar.
12101 Version 0.6 will provide full support for this very
12102 popular set of features.
12103 In the meantime, version 0.5.18 provides rudimentary support
12104 for them.
12105
12106 @node Full Support for Compiler Types
12107 @subsection Full Support for Compiler Types
12108
12109 @cindex @code{REAL*16} support
12110 @cindex types, @code{REAL*16}
12111 @cindex @code{INTEGER*8} support
12112 @cindex types, @code{INTEGER*8}
12113 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
12114 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
12115 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
12116 This means providing intrinsic support, and maybe constant
12117 support (using F90 syntax) as well, and, for most
12118 machines will result in automatic support of @code{INTEGER*1},
12119 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
12120 and so on.
12121 This is scheduled for version 0.6.
12122
12123 @node Array Bounds Expressions
12124 @subsection Array Bounds Expressions
12125 @cindex array elements, in adjustable array bounds
12126 @cindex function references, in adjustable array bounds
12127 @cindex array bounds, adjustable
12128 @cindex @code{DIMENSION} statement
12129 @cindex statements, @code{DIMENSION}
12130
12131 @code{g77} doesn't support more general expressions to dimension
12132 arrays, such as array element references, function
12133 references, etc.
12134
12135 For example, @code{g77} currently does not accept the following:
12136
12137 @smallexample
12138 SUBROUTINE X(M, N)
12139 INTEGER N(10), M(N(2), N(1))
12140 @end smallexample
12141
12142 @node POINTER Statements
12143 @subsection POINTER Statements
12144 @cindex POINTER statement
12145 @cindex statements, POINTER
12146 @cindex Cray pointers
12147
12148 @code{g77} doesn't support pointers or allocatable objects
12149 (other than automatic arrays).
12150 This set of features is
12151 probably considered just behind intrinsics
12152 in @code{PARAMETER} statements on the list of large,
12153 important things to add to @code{g77}.
12154
12155 In the meantime, consider using the @code{INTEGER(KIND=7)}
12156 declaration to specify that a variable must be
12157 able to hold a pointer.
12158 This construct is not portable to other non-GNU compilers,
12159 but it is portable to all machines GNU Fortran supports
12160 when @code{g77} is used.
12161
12162 @xref{Functions and Subroutines}, for information on
12163 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
12164 constructs, which are useful for passing pointers to
12165 procedures written in languages other than Fortran.
12166
12167 @node Sensible Non-standard Constructs
12168 @subsection Sensible Non-standard Constructs
12169
12170 @code{g77} rejects things other compilers accept,
12171 like @samp{INTRINSIC SQRT,SQRT}.
12172 As time permits in the future, some of these things that are easy for
12173 humans to read and write and unlikely to be intended to mean something
12174 else will be accepted by @code{g77} (though @samp{-fpedantic} should
12175 trigger warnings about such non-standard constructs).
12176
12177 Until @code{g77} no longer gratuitously rejects sensible code,
12178 you might as well fix your code
12179 to be more standard-conforming and portable.
12180
12181 The kind of case that is important to except from the
12182 recommendation to change your code is one where following
12183 good coding rules would force you to write non-standard
12184 code that nevertheless has a clear meaning.
12185
12186 For example, when writing an @code{INCLUDE} file that
12187 defines a common block, it might be appropriate to
12188 include a @code{SAVE} statement for the common block
12189 (such as @samp{SAVE /CBLOCK/}), so that variables
12190 defined in the common block retain their values even
12191 when all procedures declaring the common block become
12192 inactive (return to their callers).
12193
12194 However, putting @code{SAVE} statements in an @code{INCLUDE}
12195 file would prevent otherwise standard-conforming code
12196 from also specifying the @code{SAVE} statement, by itself,
12197 to indicate that all local variables and arrays are to
12198 have the @code{SAVE} attribute.
12199
12200 For this reason, @code{g77} already has been changed to
12201 allow this combination, because although the general
12202 problem of gratuitously rejecting unambiguous and
12203 ``safe'' constructs still exists in @code{g77}, this
12204 particular construct was deemed useful enough that
12205 it was worth fixing @code{g77} for just this case.
12206
12207 So, while there is no need to change your code
12208 to avoid using this particular construct, there
12209 might be other, equally appropriate but non-standard
12210 constructs, that you shouldn't have to stop using
12211 just because @code{g77} (or any other compiler)
12212 gratuitously rejects it.
12213
12214 Until the general problem is solved, if you have
12215 any such construct you believe is worthwhile
12216 using (e.g. not just an arbitrary, redundant
12217 specification of an attribute), please submit a
12218 bug report with an explanation, so we can consider
12219 fixing @code{g77} just for cases like yours.
12220
12221 @node FLUSH Statement
12222 @subsection @code{FLUSH} Statement
12223
12224 @code{g77} could perhaps use a @code{FLUSH} statement that
12225 does what @samp{CALL FLUSH} does,
12226 but that supports @samp{*} as the unit designator (same unit as for
12227 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
12228 specifiers.
12229
12230 @node Expressions in FORMAT Statements
12231 @subsection Expressions in @code{FORMAT} Statements
12232 @cindex FORMAT statement
12233 @cindex statements, FORMAT
12234
12235 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
12236 Supporting this requires a significant redesign or replacement
12237 of @code{libg2c}.
12238
12239 However, @code{g77} does support
12240 this construct when the expression is constant
12241 (as of version 0.5.22).
12242 For example:
12243
12244 @smallexample
12245       PARAMETER (IWIDTH = 12)
12246 10    FORMAT (I<IWIDTH>)
12247 @end smallexample
12248
12249 Otherwise, at least for output (@code{PRINT} and
12250 @code{WRITE}), Fortran code making use of this feature can
12251 be rewritten to avoid it by constructing the @code{FORMAT}
12252 string in a @code{CHARACTER} variable or array, then
12253 using that variable or array in place of the @code{FORMAT}
12254 statement label to do the original @code{PRINT} or @code{WRITE}.
12255
12256 Many uses of this feature on input can be rewritten this way
12257 as well, but not all can.
12258 For example, this can be rewritten:
12259
12260 @smallexample
12261       READ 20, I
12262 20    FORMAT (I<J>)
12263 @end smallexample
12264
12265 However, this cannot, in general, be rewritten, especially
12266 when @code{ERR=} and @code{END=} constructs are employed:
12267
12268 @smallexample
12269       READ 30, J, I
12270 30    FORMAT (I<J>)
12271 @end smallexample
12272
12273 @node Explicit Assembler Code
12274 @subsection Explicit Assembler Code
12275
12276 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
12277 code to specify explicit assembler code.
12278
12279 @node Q Edit Descriptor
12280 @subsection Q Edit Descriptor
12281 @cindex FORMAT statement
12282 @cindex Q edit descriptor
12283 @cindex edit descriptor, Q
12284
12285 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
12286 (This is meant to get the number of characters remaining in an input record.)
12287 Supporting this requires a significant redesign or replacement
12288 of @code{libg2c}.
12289
12290 A workaround might be using internal I/O or the stream-based intrinsics.
12291 @xref{FGetC Intrinsic (subroutine)}.
12292
12293 @node Old-style PARAMETER Statements
12294 @subsection Old-style PARAMETER Statements
12295 @cindex PARAMETER statement
12296 @cindex statements, PARAMETER
12297
12298 @code{g77} doesn't accept @samp{PARAMETER I=1}.
12299 Supporting this obsolete form of
12300 the @code{PARAMETER} statement would not be particularly hard, as most of the
12301 parsing code is already in place and working.
12302
12303 Until time/money is
12304 spent implementing it, you might as well fix your code to use the
12305 standard form, @samp{PARAMETER (I=1)} (possibly needing
12306 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
12307 otherwise, in the obsolete form of @code{PARAMETER}, the
12308 type of the variable is set from the type of the constant being
12309 assigned to it).
12310
12311 @node TYPE and ACCEPT I/O Statements
12312 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
12313 @cindex TYPE statement
12314 @cindex statements, TYPE
12315 @cindex ACCEPT statement
12316 @cindex statements, ACCEPT
12317
12318 @code{g77} doesn't support the I/O statements @code{TYPE} and
12319 @code{ACCEPT}.
12320 These are common extensions that should be easy to support,
12321 but also are fairly easy to work around in user code.
12322
12323 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
12324 by @samp{PRINT fmt,list}.
12325 And, any @samp{ACCEPT fmt,list} statement can be
12326 replaced by @samp{READ fmt,list}.
12327
12328 @node STRUCTURE UNION RECORD MAP
12329 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
12330 @cindex STRUCTURE statement
12331 @cindex statements, STRUCTURE
12332 @cindex UNION statement
12333 @cindex statements, UNION
12334 @cindex RECORD statement
12335 @cindex statements, RECORD
12336 @cindex MAP statement
12337 @cindex statements, MAP
12338
12339 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
12340 @code{MAP}.
12341 This set of extensions is quite a bit
12342 lower on the list of large, important things to add to @code{g77}, partly
12343 because it requires a great deal of work either upgrading or
12344 replacing @code{libg2c}.
12345
12346 @node OPEN CLOSE and INQUIRE Keywords
12347 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
12348 @cindex disposition of files
12349 @cindex OPEN statement
12350 @cindex statements, OPEN
12351 @cindex CLOSE statement
12352 @cindex statements, CLOSE
12353 @cindex INQUIRE statement
12354 @cindex statements, INQUIRE
12355
12356 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
12357 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
12358 These extensions are easy to add to @code{g77} itself, but
12359 require much more work on @code{libg2c}.
12360
12361 @cindex FORM='PRINT'
12362 @cindex ANS carriage control
12363 @cindex carriage control
12364 @pindex asa
12365 @pindex fpr
12366 @code{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
12367 translate the traditional `carriage control' characters in column 1 of
12368 output to use backspaces, carriage returns and the like.  However
12369 programs exist to translate them in output files (or standard output).
12370 These are typically called either @code{fpr} or @code{asa}.  You can get
12371 a version of @code{asa} from
12372 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
12373 systems which will probably build easily on other systems.
12374 Alternatively, @code{fpr} is in BSD distributions in various archive
12375 sites.
12376
12377 @c (Can both programs can be used in a pipeline,
12378 @c with a named input file,
12379 @c and/or with a named output file???)
12380
12381 @node ENCODE and DECODE
12382 @subsection @code{ENCODE} and @code{DECODE}
12383 @cindex ENCODE statement
12384 @cindex statements, ENCODE
12385 @cindex DECODE statement
12386 @cindex statements, DECODE
12387
12388 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
12389
12390 These statements are best replaced by READ and WRITE statements
12391 involving internal files (CHARACTER variables and arrays).
12392
12393 For example, replace a code fragment like
12394
12395 @smallexample
12396       INTEGER*1 LINE(80)
12397 @dots{}
12398       DECODE (80, 9000, LINE) A, B, C
12399 @dots{}
12400 9000  FORMAT (1X, 3(F10.5))
12401 @end smallexample
12402
12403 @noindent
12404 with:
12405
12406 @smallexample
12407       CHARACTER*80 LINE
12408 @dots{}
12409       READ (UNIT=LINE, FMT=9000) A, B, C
12410 @dots{}
12411 9000  FORMAT (1X, 3(F10.5))
12412 @end smallexample
12413
12414 Similarly, replace a code fragment like
12415
12416 @smallexample
12417       INTEGER*1 LINE(80)
12418 @dots{}
12419       ENCODE (80, 9000, LINE) A, B, C
12420 @dots{}
12421 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
12422 @end smallexample
12423
12424 @noindent
12425 with:
12426
12427 @smallexample
12428       CHARACTER*80 LINE
12429 @dots{}
12430       WRITE (UNIT=LINE, FMT=9000) A, B, C
12431 @dots{}
12432 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
12433 @end smallexample
12434
12435 It is entirely possible that @code{ENCODE} and @code{DECODE} will
12436 be supported by a future version of @code{g77}.
12437
12438 @node Suppressing Space Padding
12439 @subsection Suppressing Space Padding of Source Lines
12440
12441 @code{g77} should offer VXT-Fortran-style suppression of virtual
12442 spaces at the end of a source line
12443 if an appropriate command-line option is specified.
12444
12445 This affects cases where
12446 a character constant is continued onto the next line in a fixed-form
12447 source file, as in the following example:
12448
12449 @smallexample
12450 10    PRINT *,'HOW MANY
12451      1 SPACES?'
12452 @end smallexample
12453
12454 @noindent
12455 @code{g77}, and many other compilers, virtually extend
12456 the continued line through column 72 with spaces that become part
12457 of the character constant, but Digital Fortran normally didn't,
12458 leaving only one space between @samp{MANY} and @samp{SPACES?}
12459 in the output of the above statement.
12460
12461 Fairly recently, at least one version of Digital Fortran
12462 was enhanced to provide the other behavior when a
12463 command-line option is specified, apparently due to demand
12464 from readers of the USENET group @file{comp.lang.fortran}
12465 to offer conformance to this widespread practice in the
12466 industry.
12467 @code{g77} should return the favor by offering conformance
12468 to Digital's approach to handling the above example.
12469
12470 @node Fortran Preprocessor
12471 @subsection Fortran Preprocessor
12472
12473 @code{g77} should offer a preprocessor designed specifically
12474 for Fortran to replace @samp{cpp -traditional}.
12475 There are several out there worth evaluating, at least.
12476
12477 Such a preprocessor would recognize Hollerith constants,
12478 properly parse comments and character constants, and so on.
12479 It might also recognize, process, and thus preprocess
12480 files included via the @code{INCLUDE} directive.
12481
12482 @node Bit Operations on Floating-point Data
12483 @subsection Bit Operations on Floating-point Data
12484 @cindex @code{And} intrinsic
12485 @cindex intrinsics, @code{And}
12486 @cindex @code{Or} intrinsic
12487 @cindex intrinsics, @code{Or}
12488 @cindex @code{Shift} intrinsic
12489 @cindex intrinsics, @code{Shift}
12490
12491 @code{g77} does not allow @code{REAL} and other non-integral types for
12492 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
12493
12494 For example, this program is rejected by @code{g77}, because
12495 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
12496
12497 @smallexample
12498 DATA A/7.54/, B/9.112/
12499 PRINT *, IAND(A, B)
12500 END
12501 @end smallexample
12502
12503 @node POSIX Standard
12504 @subsection @code{POSIX} Standard
12505
12506 @code{g77} should support the POSIX standard for Fortran.
12507
12508 @node Floating-point Exception Handling
12509 @subsection Floating-point Exception Handling
12510 @cindex floating-point, exceptions
12511 @cindex exceptions, floating-point
12512 @cindex FPE handling
12513 @cindex NaN values
12514
12515 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
12516 general control over whether or not floating-point exceptions are trapped or
12517 ignored.
12518 (Ignoring them typically results in NaN values being
12519 propagated in systems that conform to IEEE 754.)
12520 The behaviour is normally inherited from the system-dependent startup
12521 code, though some targets, such as the Alpha, have code generation
12522 options which change the behaviour.
12523
12524 Most systems provide some C-callable mechanism to change this; this can
12525 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
12526 For example, just compiling and linking the following C code with your
12527 program will turn on exception trapping for the ``common'' exceptions
12528 on an x86-based GNU system:
12529
12530 @smallexample
12531 #include <fpu_control.h>
12532 static void __attribute__ ((constructor))
12533 trapfpe ()
12534 @{
12535   __setfpucw (_FPU_DEFAULT &
12536               ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM));
12537 @}
12538 @end smallexample
12539
12540 A convenient trick is to compile this something like:
12541 @smallexample
12542 gcc -o libtrapfpe.a trapfpe.c
12543 @end smallexample
12544 and then use it by adding @code{-trapfpe} to the @code{g77} command line
12545 when linking.
12546
12547 @node Nonportable Conversions
12548 @subsection Nonportable Conversions
12549 @cindex nonportable conversions
12550 @cindex conversions, nonportable
12551
12552 @code{g77} doesn't accept some particularly nonportable,
12553 silent data-type conversions such as @code{LOGICAL}
12554 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
12555 is type @code{REAL}), that other compilers might
12556 quietly accept.
12557
12558 Some of these conversions are accepted by @code{g77}
12559 when the @samp{-fugly} option is specified.
12560 Perhaps it should accept more or all of them.
12561
12562 @node Large Automatic Arrays
12563 @subsection Large Automatic Arrays
12564 @cindex automatic arrays
12565 @cindex arrays, automatic
12566
12567 Currently, automatic arrays always are allocated on the stack.
12568 For situations where the stack cannot be made large enough,
12569 @code{g77} should offer a compiler option that specifies
12570 allocation of automatic arrays in heap storage.
12571
12572 @node Support for Threads
12573 @subsection Support for Threads
12574 @cindex threads
12575 @cindex parallel processing
12576
12577 Neither the code produced by @code{g77} nor the @code{libg2c} library
12578 are thread-safe, nor does @code{g77} have support for parallel processing
12579 (other than the instruction-level parallelism available on some
12580 processors).
12581 A package such as PVM might help here.
12582
12583 @node Gracefully Handle Sensible Bad Code
12584 @subsection Gracefully Handle Sensible Bad Code
12585
12586 @code{g77} generally should continue processing for
12587 warnings and recoverable (user) errors whenever possible---that
12588 is, it shouldn't gratuitously make bad or useless code.
12589
12590 For example:
12591
12592 @smallexample
12593 INTRINSIC ZABS
12594 CALL FOO(ZABS)
12595 END
12596 @end smallexample
12597
12598 @noindent
12599 When compiling the above with @samp{-ff2c-intrinsics-disable},
12600 @code{g77} should indeed complain about passing @code{ZABS},
12601 but it still should compile, instead of rejecting
12602 the entire @code{CALL} statement.
12603 (Some of this is related to improving
12604 the compiler internals to improve how statements are analyzed.)
12605
12606 @node Non-standard Conversions
12607 @subsection Non-standard Conversions
12608
12609 @samp{-Wconversion} and related should flag places where non-standard
12610 conversions are found.
12611 Perhaps much of this would be part of @samp{-Wugly*}.
12612
12613 @node Non-standard Intrinsics
12614 @subsection Non-standard Intrinsics
12615
12616 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
12617 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
12618 This would help find code that might fail silently when ported to another
12619 compiler.
12620
12621 @node Modifying DO Variable
12622 @subsection Modifying @code{DO} Variable
12623
12624 @code{g77} should warn about modifying @code{DO} variables
12625 via @code{EQUIVALENCE}.
12626 (The internal information gathered to produce this warning
12627 might also be useful in setting the
12628 internal ``doiter'' flag for a variable or even array
12629 reference within a loop, since that might produce faster code someday.)
12630
12631 For example, this code is invalid, so @code{g77} should warn about
12632 the invalid assignment to @samp{NOTHER}:
12633
12634 @smallexample
12635 EQUIVALENCE (I, NOTHER)
12636 DO I = 1, 100
12637    IF (I.EQ. 10) NOTHER = 20
12638 END DO
12639 @end smallexample
12640
12641 @node Better Pedantic Compilation
12642 @subsection Better Pedantic Compilation
12643
12644 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
12645 and use it only to generate
12646 warnings instead of rejecting constructs outright.
12647 Have it warn:
12648 if a variable that dimensions an array is not a dummy or placed
12649 explicitly in @code{COMMON} (F77 does not allow it to be
12650 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
12651 follow statement-function-definition statements; about all sorts of
12652 syntactic extensions.
12653
12654 @node Warn About Implicit Conversions
12655 @subsection Warn About Implicit Conversions
12656
12657 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
12658 to expect automatic, silent, and
12659 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
12660 constants to @code{REAL(KIND=2)} based on context.
12661
12662 For example, it would warn about cases like this:
12663
12664 @smallexample
12665 DOUBLE PRECISION FOO
12666 PARAMETER (TZPHI = 9.435784839284958)
12667 FOO = TZPHI * 3D0
12668 @end smallexample
12669
12670 @node Invalid Use of Hollerith Constant
12671 @subsection Invalid Use of Hollerith Constant
12672
12673 @code{g77} should disallow statements like @samp{RETURN 2HAB},
12674 which are invalid in both source forms
12675 (unlike @samp{RETURN (2HAB)},
12676 which probably still makes no sense but at least can
12677 be reliably parsed).
12678 Fixed-form processing rejects it, but not free-form, except
12679 in a way that is a bit difficult to understand.
12680
12681 @node Dummy Array Without Dimensioning Dummy
12682 @subsection Dummy Array Without Dimensioning Dummy
12683
12684 @code{g77} should complain when a list of dummy arguments containing an
12685 adjustable dummy array does
12686 not also contain every variable listed in the dimension list of the
12687 adjustable array.
12688
12689 Currently, @code{g77} does complain about a variable that
12690 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
12691 area, but this needs to be extended to catch cases where it doesn't appear in
12692 every dummy list that also lists any arrays it dimensions.
12693
12694 For example, @code{g77} should warn about the entry point @samp{ALT}
12695 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
12696 list of arguments:
12697
12698 @smallexample
12699 SUBROUTINE PRIMARY(ARRAY, ISIZE)
12700 REAL ARRAY(ISIZE)
12701 ENTRY ALT(ARRAY)
12702 @end smallexample
12703
12704 @node Invalid FORMAT Specifiers
12705 @subsection Invalid FORMAT Specifiers
12706
12707 @code{g77} should check @code{FORMAT} specifiers for validity
12708 as it does @code{FORMAT} statements.
12709
12710 For example, a diagnostic would be produced for:
12711
12712 @smallexample
12713 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
12714 @end smallexample
12715
12716 @node Ambiguous Dialects
12717 @subsection Ambiguous Dialects
12718
12719 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
12720 @samp{-Wvxt}, @samp{-Wf90}, and so on.
12721 These would warn about places in the user's source where ambiguities
12722 are found, helpful in resolving ambiguities in the program's
12723 dialect or dialects.
12724
12725 @node Unused Labels
12726 @subsection Unused Labels
12727
12728 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
12729
12730 @node Informational Messages
12731 @subsection Informational Messages
12732
12733 @code{g77} needs an option to suppress information messages (notes).
12734 @samp{-w} does this but also suppresses warnings.
12735 The default should be to suppress info messages.
12736
12737 Perhaps info messages should simply be eliminated.
12738
12739 @node Uninitialized Variables at Run Time
12740 @subsection Uninitialized Variables at Run Time
12741
12742 @code{g77} needs an option to initialize everything (not otherwise
12743 explicitly initialized) to ``weird''
12744 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
12745 largest-magnitude integers, would help track down references to
12746 some kinds of uninitialized variables at run time.
12747
12748 Note that use of the options @samp{-O -Wuninitialized} can catch
12749 many such bugs at compile time.
12750
12751 @node Bounds Checking at Run Time
12752 @subsection Bounds Checking at Run Time
12753
12754 @code{g77} should offer run-time bounds-checking of array/subscript references
12755 in a fashion similar to @code{f2c}.
12756
12757 Note that @code{g77} already warns about references to out-of-bounds
12758 elements of arrays when it detects these at compile time.
12759
12760 @node Portable Unformatted Files
12761 @subsection Portable Unformatted Files
12762
12763 @cindex unformatted files
12764 @cindex file formats
12765 @cindex binary data
12766 @cindex byte ordering
12767 @code{g77} has no facility for exchanging unformatted files with systems
12768 using different number formats---even differing only in endianness (byte
12769 order)---or written by other compilers.  Some compilers provide
12770 facilities at least for doing byte-swapping during unformatted I/O.
12771
12772 It is unrealistic to expect to cope with exchanging unformatted files
12773 with arbitrary other compiler runtimes, but the @code{g77} runtime
12774 should at least be able to read files written by @code{g77} on systems
12775 with different number formats, particularly if they differ only in byte
12776 order.
12777
12778 In case you do need to write a program to translate to or from
12779 @code{g77} (@code{libf2c}) unformatted files, they are written as
12780 follows:
12781 @table @asis
12782 @item Sequential
12783 Unformatted sequential records consist of
12784 @enumerate
12785 @item
12786 A number giving the length of the record contents;
12787 @item
12788 the length of record contents again (for backspace).
12789 @end enumerate
12790
12791 The record length is of C type
12792 @code{long}; this means that it is 8 bytes on 64-bit systems such as
12793 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
12794 Consequently such files cannot be exchanged between 64-bit and 32-bit
12795 systems, even with the same basic number format.
12796 @item Direct access
12797 Unformatted direct access files form a byte stream of length
12798 @var{records}*@var{recl} bytes, where @var{records} is the maximum
12799 record number (@code{REC=@var{records}}) written and @var{recl} is the
12800 record length in bytes specified in the @code{OPEN} statement
12801 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
12802 the relevant @code{WRITE} statement.  Dummy records with arbitrary
12803 contents appear in the file in place of records which haven't been
12804 written.
12805 @end table
12806
12807 Thus for exchanging a sequential or direct access unformatted file
12808 between big- and little-endian 32-bit systems using IEEE 754 floating
12809 point it would be sufficient to reverse the bytes in consecutive words
12810 in the file @emph{iff} only @code{REAL*4}, @code{COMPLEX},
12811 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
12812 @code{g77}.
12813
12814 If necessary, it is possible to do byte-oriented i/o with @code{g77}'s
12815 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
12816 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
12817 array or a set of scalars.
12818
12819 @cindex HDF
12820 @cindex PDB
12821 If you need to exchange binary data between arbitrary system and
12822 compiler variations, we recommend using a portable binary format with
12823 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
12824 or PACT's PDB@footnote{No, not @emph{that} one.}
12825 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
12826 say, CDF or XDR, HDF-like systems write in the native number formats and
12827 only incur overhead when they are read on a system with a different
12828 format.)  A future @code{g77} runtime library should use such
12829 techniques.
12830
12831 @node Labels Visible to Debugger
12832 @subsection Labels Visible to Debugger
12833
12834 @code{g77} should output debugging information for statements labels,
12835 for use by debuggers that know how to support them.
12836 Same with weirder things like construct names.
12837 It is not yet known if any debug formats or debuggers support these.
12838
12839 @node Disappointments
12840 @section Disappointments and Misunderstandings
12841
12842 These problems are perhaps regrettable, but we don't know any practical
12843 way around them for now.
12844
12845 @menu
12846 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
12847                                               external name @samp{foo_}.
12848 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
12849                                               and @samp{SUBROUTINE FOO}.
12850 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
12851 @end menu
12852
12853 @node Mangling of Names
12854 @subsection Mangling of Names in Source Code
12855 @cindex naming issues
12856 @cindex external names
12857 @cindex common blocks
12858 @cindex name space
12859 @cindex underscore
12860
12861 The current external-interface design, which includes naming of
12862 external procedures, COMMON blocks, and the library interface,
12863 has various usability problems, including things like adding
12864 underscores where not really necessary (and preventing easier
12865 inter-language operability) and yet not providing complete
12866 namespace freedom for user C code linked with Fortran apps (due
12867 to the naming of functions in the library, among other things).
12868
12869 Project GNU should at least get all this ``right'' for systems
12870 it fully controls, such as the Hurd, and provide defaults and
12871 options for compatibility with existing systems and interoperability
12872 with popular existing compilers.
12873
12874 @node Multiple Definitions of External Names
12875 @subsection Multiple Definitions of External Names
12876 @cindex block data
12877 @cindex BLOCK DATA statement
12878 @cindex statements, BLOCK DATA
12879 @cindex @code{COMMON} statement
12880 @cindex statements, @code{COMMON}
12881 @cindex naming conflicts
12882
12883 @code{g77} doesn't allow a common block and an external procedure or
12884 @code{BLOCK DATA} to have the same name.
12885 Some systems allow this, but @code{g77} does not,
12886 to be compatible with @code{f2c}.
12887
12888 @code{g77} could special-case the way it handles
12889 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
12890 particular area (necessarily, since @code{g77} offers an
12891 important feature here), but
12892 it is likely that such special-casing would be very annoying to people
12893 with programs that use @samp{EXTERNAL FOO}, with no other mention of
12894 @samp{FOO} in the same program unit, to refer to external procedures, since
12895 the result would be that @code{g77} would treat these references as requests to
12896 force-load BLOCK DATA program units.
12897
12898 In that case, if @code{g77} modified
12899 names of @code{BLOCK DATA} so they could have the same names as
12900 @code{COMMON}, users
12901 would find that their programs wouldn't link because the @samp{FOO} procedure
12902 didn't have its name translated the same way.
12903
12904 (Strictly speaking,
12905 @code{g77} could emit a null-but-externally-satisfying definition of
12906 @samp{FOO} with its name transformed as if it had been a
12907 @code{BLOCK DATA}, but that probably invites more trouble than it's
12908 worth.)
12909
12910 @node Limitation on Implicit Declarations
12911 @subsection Limitation on Implicit Declarations
12912 @cindex IMPLICIT CHARACTER*(*) statement
12913 @cindex statements, IMPLICIT CHARACTER*(*)
12914
12915 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
12916 This is not standard-conforming.
12917
12918 @node Non-bugs
12919 @section Certain Changes We Don't Want to Make
12920
12921 This section lists changes that people frequently request, but which
12922 we do not make because we think GNU Fortran is better without them.
12923
12924 @menu
12925 * Backslash in Constants::           Why @samp{'\\'} is a constant that
12926                                        is one, not two, characters long.
12927 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
12928                                        @samp{COMMON VAR}.
12929 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
12930 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
12931                                        single-precision constant,
12932                                        and might be interpreted as
12933                                        @samp{9.435785} or similar.
12934 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
12935 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
12936                                        not behave as expected.
12937 @end menu
12938
12939 @node Backslash in Constants
12940 @subsection Backslash in Constants
12941 @cindex backslash
12942 @cindex @code{f77} support
12943 @cindex support, @code{f77}
12944
12945 In the opinion of many experienced Fortran users,
12946 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
12947 as currently set by @code{g77}.
12948
12949 First of all, you can always specify
12950 @samp{-fno-backslash} to turn off this processing.
12951
12952 Despite not being within the spirit (though apparently within the
12953 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
12954 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
12955 default to, and apparently lots of code depends on this feature.
12956
12957 This is a particularly troubling issue.
12958 The use of a C construct in the midst of Fortran code
12959 is bad enough, worse when it makes existing Fortran
12960 programs stop working (as happens when programs written
12961 for non-UNIX systems are ported to UNIX systems with
12962 compilers that provide the @samp{-fbackslash} feature
12963 as the default---sometimes with no option to turn it off).
12964
12965 The author of GNU Fortran wished, for reasons of linguistic
12966 purity, to make @samp{-fno-backslash} the default for GNU
12967 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
12968 to specify @samp{-fbackslash} to get the UNIX behavior.
12969
12970 However, the realization that @code{g77} is intended as
12971 a replacement for @emph{UNIX} @code{f77}, caused the author
12972 to choose to make @code{g77} as compatible with
12973 @code{f77} as feasible, which meant making @samp{-fbackslash}
12974 the default.
12975
12976 The primary focus on compatibility is at the source-code
12977 level, and the question became ``What will users expect
12978 a replacement for @code{f77} to do, by default?''
12979 Although at least one UNIX @code{f77} does not provide
12980 @samp{-fbackslash} as a default, it appears that
12981 the majority of them do, which suggests that
12982 the majority of code that is compiled by UNIX @code{f77}
12983 compilers expects @samp{-fbackslash} to be the default.
12984
12985 It is probably the case that more code exists
12986 that would @emph{not} work with @samp{-fbackslash}
12987 in force than code that requires it be in force.
12988
12989 However, most of @emph{that} code is not being compiled
12990 with @code{f77},
12991 and when it is, new build procedures (shell scripts,
12992 makefiles, and so on) must be set up anyway so that
12993 they work under UNIX.
12994 That makes a much more natural and safe opportunity for
12995 non-UNIX users to adapt their build procedures for
12996 @code{g77}'s default of @samp{-fbackslash} than would
12997 exist for the majority of UNIX @code{f77} users who
12998 would have to modify existing, working build procedures
12999 to explicitly specify @samp{-fbackslash} if that was
13000 not the default.
13001
13002 One suggestion has been to configure the default for
13003 @samp{-fbackslash} (and perhaps other options as well)
13004 based on the configuration of @code{g77}.
13005
13006 This is technically quite straightforward, but will be avoided
13007 even in cases where not configuring defaults to be
13008 dependent on a particular configuration greatly inconveniences
13009 some users of legacy code.
13010
13011 Many users appreciate the GNU compilers because they provide an
13012 environment that is uniform across machines.
13013 These users would be
13014 inconvenienced if the compiler treated things like the
13015 format of the source code differently on certain machines.
13016
13017 Occasionally users write programs intended only for a particular machine
13018 type.
13019 On these occasions, the users would benefit if the GNU Fortran compiler
13020 were to support by default the same dialect as the other compilers on
13021 that machine.
13022 But such applications are rare.
13023 And users writing a
13024 program to run on more than one type of machine cannot possibly benefit
13025 from this kind of compatibility.
13026 (This is consistent with the design goals for @code{gcc}.
13027 To change them for @code{g77}, you must first change them
13028 for @code{gcc}.
13029 Do not ask the maintainers of @code{g77} to do this for you,
13030 or to disassociate @code{g77} from the widely understood, if
13031 not widely agreed-upon, goals for GNU compilers in general.)
13032
13033 This is why GNU Fortran does and will treat backslashes in the same
13034 fashion on all types of machines (by default).
13035 @xref{Direction of Language Development}, for more information on
13036 this overall philosophy guiding the development of the GNU Fortran
13037 language.
13038
13039 Of course, users strongly concerned about portability should indicate
13040 explicitly in their build procedures which options are expected
13041 by their source code, or write source code that has as few such
13042 expectations as possible.
13043
13044 For example, avoid writing code that depends on backslash (@samp{\})
13045 being interpreted either way in particular, such as by
13046 starting a program unit with:
13047
13048 @smallexample
13049 CHARACTER BACKSL
13050 PARAMETER (BACKSL = '\\')
13051 @end smallexample
13052
13053 @noindent
13054 Then, use concatenation of @samp{BACKSL} anyplace a backslash
13055 is desired.
13056 In this way, users can write programs which have the same meaning
13057 in many Fortran dialects.
13058
13059 (However, this technique does not work for Hollerith constants---which
13060 is just as well, since the only generally portable uses for Hollerith
13061 constants are in places where character constants can and should
13062 be used instead, for readability.)
13063
13064 @node Initializing Before Specifying
13065 @subsection Initializing Before Specifying
13066 @cindex initialization, statement placement
13067 @cindex placing initialization statements
13068
13069 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
13070 source code before @samp{COMMON VAR},
13071 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
13072 In general, @code{g77} requires initialization of a variable
13073 or array to be specified @emph{after} all other specifications
13074 of attributes (type, size, placement, and so on) of that variable
13075 or array are specified (though @emph{confirmation} of data type is
13076 permitted).
13077
13078 It is @emph{possible} @code{g77} will someday allow all of this,
13079 even though it is not allowed by the FORTRAN 77 standard.
13080
13081 Then again, maybe it is better to have
13082 @code{g77} always require placement of @code{DATA}
13083 so that it can possibly immediately write constants
13084 to the output file, thus saving time and space.
13085
13086 That is, @samp{DATA A/1000000*1/} should perhaps always
13087 be immediately writable to canonical assembler, unless it's already known
13088 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
13089 and to do this it cannot be followed by @samp{COMMON A}.
13090
13091 @node Context-Sensitive Intrinsicness
13092 @subsection Context-Sensitive Intrinsicness
13093 @cindex intrinsics, context-sensitive
13094 @cindex context-sensitive intrinsics
13095
13096 @code{g77} treats procedure references to @emph{possible} intrinsic
13097 names as always enabling their intrinsic nature, regardless of
13098 whether the @emph{form} of the reference is valid for that
13099 intrinsic.
13100
13101 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
13102 an invalid reference to the @code{SQRT} intrinsic function,
13103 because the reference is a subroutine invocation.
13104
13105 First, @code{g77} recognizes the statement @samp{CALL SQRT}
13106 as a reference to a @emph{procedure} named @samp{SQRT}, not
13107 to a @emph{variable} with that name (as it would for a statement
13108 such as @samp{V = SQRT}).
13109
13110 Next, @code{g77} establishes that, in the program unit being compiled,
13111 @code{SQRT} is an intrinsic---not a subroutine that
13112 happens to have the same name as an intrinsic (as would be
13113 the case if, for example, @samp{EXTERNAL SQRT} was present).
13114
13115 Finally, @code{g77} recognizes that the @emph{form} of the
13116 reference is invalid for that particular intrinsic.
13117 That is, it recognizes that it is invalid for an intrinsic
13118 @emph{function}, such as @code{SQRT}, to be invoked as
13119 a @emph{subroutine}.
13120
13121 At that point, @code{g77} issues a diagnostic.
13122
13123 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
13124 references an external subroutine of their own, not an
13125 intrinsic function.
13126
13127 However, @code{g77} knows about intrinsic
13128 subroutines, not just functions, and is able to support both having
13129 the same names, for example.
13130
13131 As a result of this, @code{g77} rejects calls
13132 to intrinsics that are not subroutines, and function invocations
13133 of intrinsics that are not functions, just as it (and most compilers)
13134 rejects invocations of intrinsics with the wrong number (or types)
13135 of arguments.
13136
13137 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
13138 a user-written subroutine named @samp{SQRT}.
13139
13140 @node Context-Sensitive Constants
13141 @subsection Context-Sensitive Constants
13142 @cindex constants, context-sensitive
13143 @cindex context-sensitive constants
13144
13145 @code{g77} does not use context to determine the types of
13146 constants or named constants (@code{PARAMETER}), except
13147 for (non-standard) typeless constants such as @samp{'123'O}.
13148
13149 For example, consider the following statement:
13150
13151 @smallexample
13152 PRINT *, 9.435784839284958 * 2D0
13153 @end smallexample
13154
13155 @noindent
13156 @code{g77} will interpret the (truncated) constant
13157 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
13158 constant, because the suffix @code{D0} is not specified.
13159
13160 As a result, the output of the above statement when
13161 compiled by @code{g77} will appear to have ``less precision''
13162 than when compiled by other compilers.
13163
13164 In these and other cases, some compilers detect the
13165 fact that a single-precision constant is used in
13166 a double-precision context and therefore interpret the
13167 single-precision constant as if it was @emph{explicitly}
13168 specified as a double-precision constant.
13169 (This has the effect of appending @emph{decimal}, not
13170 @emph{binary}, zeros to the fractional part of the
13171 number---producing different computational results.)
13172
13173 The reason this misfeature is dangerous is that a slight,
13174 apparently innocuous change to the source code can change
13175 the computational results.
13176 Consider:
13177
13178 @smallexample
13179 REAL ALMOST, CLOSE
13180 DOUBLE PRECISION FIVE
13181 PARAMETER (ALMOST = 5.000000000001)
13182 FIVE = 5
13183 CLOSE = 5.000000000001
13184 PRINT *, 5.000000000001 - FIVE
13185 PRINT *, ALMOST - FIVE
13186 PRINT *, CLOSE - FIVE
13187 END
13188 @end smallexample
13189
13190 @noindent
13191 Running the above program should
13192 result in the same value being
13193 printed three times.
13194 With @code{g77} as the compiler,
13195 it does.
13196
13197 However, compiled by many other compilers,
13198 running the above program would print
13199 two or three distinct values, because
13200 in two or three of the statements, the
13201 constant @samp{5.000000000001}, which
13202 on most systems is exactly equal to @samp{5.}
13203 when interpreted as a single-precision constant,
13204 is instead interpreted as a double-precision
13205 constant, preserving the represented
13206 precision.
13207 However, this ``clever'' promotion of
13208 type does not extend to variables or,
13209 in some compilers, to named constants.
13210
13211 Since programmers often are encouraged to replace manifest
13212 constants or permanently-assigned variables with named
13213 constants (@code{PARAMETER} in Fortran), and might need
13214 to replace some constants with variables having the same
13215 values for pertinent portions of code,
13216 it is important that compilers treat code so modified in the
13217 same way so that the results of such programs are the same.
13218 @code{g77} helps in this regard by treating constants just
13219 the same as variables in terms of determining their types
13220 in a context-independent way.
13221
13222 Still, there is a lot of existing Fortran code that has
13223 been written to depend on the way other compilers freely
13224 interpret constants' types based on context, so anything
13225 @code{g77} can do to help flag cases of this in such code
13226 could be very helpful.
13227
13228 @node Equivalence Versus Equality
13229 @subsection Equivalence Versus Equality
13230 @cindex .EQV., with integer operands
13231 @cindex comparing logical expressions
13232 @cindex logical expressions, comparing
13233
13234 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
13235 is not supported, except via @samp{-fugly}, which is not
13236 recommended except for legacy code (where the behavior expected
13237 by the @emph{code} is assumed).
13238
13239 Legacy code should be changed, as resources permit, to use @code{.EQV.}
13240 and @code{.NEQV.} instead, as these are permitted by the various
13241 Fortran standards.
13242
13243 New code should never be written expecting @code{.EQ.} or @code{.NE.}
13244 to work if either of its operands is @code{LOGICAL}.
13245
13246 The problem with supporting this ``feature'' is that there is
13247 unlikely to be consensus on how it works, as illustrated by the
13248 following sample program:
13249
13250 @smallexample
13251 LOGICAL L,M,N
13252 DATA L,M,N /3*.FALSE./
13253 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
13254 END
13255 @end smallexample
13256
13257 The issue raised by the above sample program is: what is the
13258 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
13259 @code{LOGICAL} operands?
13260
13261 Some programmers will argue that it is the same as the precedence
13262 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
13263 operands.
13264 By this interpretation, the subexpression @samp{M.EQ.N} must be
13265 evaluated first in the above program, resulting in a program that,
13266 when run, does not execute the @code{PRINT} statement.
13267
13268 Other programmers will argue that the precedence is the same as
13269 the precedence for @code{.EQV.}, which is restricted by the standards
13270 to @code{LOGICAL} operands.
13271 By this interpretation, the subexpression @samp{L.AND.M} must be
13272 evaluated first, resulting in a program that @emph{does} execute
13273 the @code{PRINT} statement.
13274
13275 Assigning arbitrary semantic interpretations to syntactic expressions
13276 that might legitimately have more than one ``obvious'' interpretation
13277 is generally unwise.
13278
13279 The creators of the various Fortran standards have done a good job
13280 in this case, requiring a distinct set of operators (which have their
13281 own distinct precedence) to compare @code{LOGICAL} operands.
13282 This requirement results in expression syntax with more certain
13283 precedence (without requiring substantial context), making it easier
13284 for programmers to read existing code.
13285 @code{g77} will avoid muddying up elements of the Fortran language
13286 that were well-designed in the first place.
13287
13288 (Ask C programmers about the precedence of expressions such as
13289 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
13290 you, without knowing more context, whether the @samp{&} and @samp{-}
13291 operators are infix (binary) or unary!)
13292
13293 @node Order of Side Effects
13294 @subsection Order of Side Effects
13295 @cindex side effects, order of evaluation
13296 @cindex order of evaluation, side effects
13297
13298 @code{g77} does not necessarily produce code that, when run, performs
13299 side effects (such as those performed by function invocations)
13300 in the same order as in some other compiler---or even in the same
13301 order as another version, port, or invocation (using different
13302 command-line options) of @code{g77}.
13303
13304 It is never safe to depend on the order of evaluation of side effects.
13305 For example, an expression like this may very well behave differently
13306 from one compiler to another:
13307
13308 @smallexample
13309 J = IFUNC() - IFUNC()
13310 @end smallexample
13311
13312 @noindent
13313 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
13314 order.
13315 Either invocation might happen first.
13316 If @samp{IFUNC} returns 5 the first time it is invoked, and
13317 returns 12 the second time, @samp{J} might end up with the
13318 value @samp{7}, or it might end up with @samp{-7}.
13319
13320 Generally, in Fortran, procedures with side-effects intended to
13321 be visible to the caller are best designed as @emph{subroutines},
13322 not functions.
13323 Examples of such side-effects include:
13324
13325 @itemize @bullet
13326 @item
13327 The generation of random numbers
13328 that are intended to influence return values.
13329
13330 @item
13331 Performing I/O
13332 (other than internal I/O to local variables).
13333
13334 @item
13335 Updating information in common blocks.
13336 @end itemize
13337
13338 An example of a side-effect that is not intended to be visible
13339 to the caller is a function that maintains a cache of recently
13340 calculated results, intended solely to speed repeated invocations
13341 of the function with identical arguments.
13342 Such a function can be safely used in expressions, because
13343 if the compiler optimizes away one or more calls to the
13344 function, operation of the program is unaffected (aside
13345 from being speeded up).
13346
13347 @node Warnings and Errors
13348 @section Warning Messages and Error Messages
13349
13350 @cindex error messages
13351 @cindex warnings vs errors
13352 @cindex messages, warning and error
13353 The GNU compiler can produce two kinds of diagnostics: errors and
13354 warnings.
13355 Each kind has a different purpose:
13356
13357 @itemize @w{}
13358 @item
13359 @emph{Errors} report problems that make it impossible to compile your
13360 program.
13361 GNU Fortran reports errors with the source file name, line
13362 number, and column within the line where the problem is apparent.
13363
13364 @item
13365 @emph{Warnings} report other unusual conditions in your code that
13366 @emph{might} indicate a problem, although compilation can (and does)
13367 proceed.
13368 Warning messages also report the source file name, line number,
13369 and column information,
13370 but include the text @samp{warning:} to distinguish them
13371 from error messages.
13372 @end itemize
13373
13374 Warnings might indicate danger points where you should check to make sure
13375 that your program really does what you intend; or the use of obsolete
13376 features; or the use of nonstandard features of GNU Fortran.
13377 Many warnings are issued only if you ask for them, with one of the
13378 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
13379 useful warnings).
13380
13381 @emph{Note:} Currently, the text of the line and a pointer to the column
13382 is printed in most @code{g77} diagnostics.
13383 Probably, as of version 0.6, @code{g77} will
13384 no longer print the text of the source line, instead printing
13385 the column number following the file name and line number in
13386 a form that GNU Emacs recognizes.
13387 This change is expected to speed up and reduce the memory usage
13388 of the @code{g77} compiler.
13389 @c
13390 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
13391 @c
13392 @c GNU Fortran always tries to compile your program if possible; it never
13393 @c gratuitously rejects a program whose meaning is clear merely because
13394 @c (for instance) it fails to conform to a standard.  In some cases,
13395 @c however, the Fortran standard specifies that certain extensions are
13396 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
13397 @c compiler.  The @samp{-pedantic} option tells GNU Fortran to issue warnings
13398 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
13399 @c This does not mean that @emph{all} non-ANSI constructs get warnings
13400 @c or errors.
13401
13402 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
13403 more detail on these and related command-line options.
13404
13405 @node Open Questions
13406 @chapter Open Questions
13407
13408 Please consider offering useful answers to these questions!
13409
13410 @itemize @bullet
13411 @item
13412 @code{LOC()} and other intrinsics are probably somewhat misclassified.
13413 Is the a need for more precise classification of intrinsics, and if so,
13414 what are the appropriate groupings?
13415 Is there a need to individually
13416 enable/disable/delete/hide intrinsics from the command line?
13417 @end itemize
13418
13419 @node Bugs
13420 @chapter Reporting Bugs
13421 @cindex bugs
13422 @cindex reporting bugs
13423
13424 Your bug reports play an essential role in making GNU Fortran reliable.
13425
13426 When you encounter a problem, the first thing to do is to see if it is
13427 already known.
13428 @xref{Trouble}.
13429 If it isn't known, then you should report the problem.
13430
13431 Reporting a bug might help you by bringing a solution to your problem, or
13432 it might not.
13433 (If it does not, look in the service directory; see
13434 @ref{Service}.)
13435 In any case, the principal function of a bug report is
13436 to help the entire community by making the next version of GNU Fortran work
13437 better.
13438 Bug reports are your contribution to the maintenance of GNU Fortran.
13439
13440 Since the maintainers are very overloaded, we cannot respond to every
13441 bug report.
13442 However, if the bug has not been fixed, we are likely to
13443 send you a patch and ask you to tell us whether it works.
13444
13445 In order for a bug report to serve its purpose, you must include the
13446 information that makes for fixing the bug.
13447
13448 @menu
13449 * Criteria: Bug Criteria.    Have you really found a bug?
13450 * Where: Bug Lists.          Where to send your bug report.
13451 * Reporting: Bug Reporting.  How to report a bug effectively.
13452 * Patches: Sending Patches.  How to send a patch for GNU Fortran.
13453 @end menu
13454
13455 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
13456 for information on problems we already know about.
13457
13458 @xref{Service,,How To Get Help with GNU Fortran},
13459 for information on where to ask for help.
13460
13461 @node Bug Criteria
13462 @section Have You Found a Bug?
13463 @cindex bug criteria
13464
13465 If you are not sure whether you have found a bug, here are some guidelines:
13466
13467 @itemize @bullet
13468 @cindex fatal signal
13469 @cindex core dump
13470 @item
13471 If the compiler gets a fatal signal, for any input whatever, that is a
13472 compiler bug.
13473 Reliable compilers never crash---they just remain obsolete.
13474
13475 @cindex invalid assembly code
13476 @cindex assembly code, invalid
13477 @item
13478 If the compiler produces invalid assembly code, for any input whatever,
13479 @c (except an @code{asm} statement),
13480 that is a compiler bug, unless the
13481 compiler reports errors (not just warnings) which would ordinarily
13482 prevent the assembler from being run.
13483
13484 @cindex undefined behavior
13485 @cindex undefined function value
13486 @item
13487 If the compiler produces valid assembly code that does not correctly
13488 execute the input source code, that is a compiler bug.
13489
13490 However, you must double-check to make sure, because you might have run
13491 into an incompatibility between GNU Fortran and traditional Fortran.
13492 @c (@pxref{Incompatibilities}).
13493 These incompatibilities might be considered
13494 bugs, but they are inescapable consequences of valuable features.
13495
13496 Or you might have a program whose behavior is undefined, which happened
13497 by chance to give the desired results with another Fortran compiler.
13498 It is best to check the relevant Fortran standard thoroughly if
13499 it is possible that the program indeed does something undefined.
13500
13501 After you have localized the error to a single source line, it should
13502 be easy to check for these things.
13503 If your program is correct and well defined, you have found
13504 a compiler bug.
13505
13506 It might help if, in your submission, you identified the specific
13507 language in the relevant Fortran standard that specifies the
13508 desired behavior, if it isn't likely to be obvious and agreed-upon
13509 by all Fortran users.
13510
13511 @item
13512 If the compiler produces an error message for valid input, that is a
13513 compiler bug.
13514
13515 @cindex invalid input
13516 @item
13517 If the compiler does not produce an error message for invalid input,
13518 that is a compiler bug.
13519 However, you should note that your idea of
13520 ``invalid input'' might be someone else's idea
13521 of ``an extension'' or ``support for traditional practice''.
13522
13523 @item
13524 If you are an experienced user of Fortran compilers, your suggestions
13525 for improvement of GNU Fortran are welcome in any case.
13526 @end itemize
13527
13528 Many, perhaps most, bug reports against @code{g77} turn out to
13529 be bugs in the user's code.
13530 While we find such bug reports educational, they sometimes take
13531 a considerable amount of time to track down or at least respond
13532 to---time we could be spending making @code{g77}, not some user's
13533 code, better.
13534
13535 Some steps you can take to verify that the bug is not certainly
13536 in the code you're compiling with @code{g77}:
13537
13538 @itemize @bullet
13539 @item
13540 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
13541 These options enable many useful warning; the @samp{-O} option
13542 enables flow analysis that enables the uninitialized-variable
13543 warning.
13544
13545 If you investigate the warnings and find evidence of possible bugs
13546 in your code, fix them first and retry @code{g77}.
13547
13548 @item
13549 Compile your code using the @code{g77} options @samp{-finit-local-zero},
13550 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
13551 combinations thereof.
13552
13553 If your code works with any of these combinations, that is not
13554 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
13555 by your code might simply be avoided, or have a different, more subtle
13556 effect, when different options are used---but it can be a
13557 strong indicator that your code is making unwarranted assumptions
13558 about the Fortran dialect and/or underlying machine it is
13559 being compiled and run on.
13560
13561 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
13562 for information on the @samp{-fno-automatic} and
13563 @samp{-finit-local-zero} options and how to convert
13564 their use into selective changes in your own code.
13565
13566 @item
13567 @pindex ftnchek
13568 Validate your code with @code{ftnchek} or a similar code-checking
13569 tool.
13570 @code{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
13571 or @uref{ftp://ftp.dsm.fordham.edu}.
13572
13573 @pindex make
13574 @cindex Makefile example
13575 Here are some sample @file{Makefile} rules using @code{ftnchek}
13576 ``project'' files to do cross-file checking and @code{sfmakedepend}
13577 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
13578 to maintain dependencies automatically.
13579 These assume the use of GNU @code{make}.
13580
13581 @smallexample
13582 # Dummy suffix for ftnchek targets:
13583 .SUFFIXES: .chek
13584 .PHONY: chekall
13585
13586 # How to compile .f files (for implicit rule):
13587 FC = g77
13588 # Assume `include' directory:
13589 FFLAGS = -Iinclude -g -O -Wall
13590
13591 # Flags for ftnchek:
13592 CHEK1 = -array=0 -include=includes -noarray
13593 CHEK2 = -nonovice -usage=1 -notruncation
13594 CHEKFLAGS = $(CHEK1) $(CHEK2)
13595
13596 # Run ftnchek with all the .prj files except the one corresponding
13597 # to the target's root:
13598 %.chek : %.f ; \
13599   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
13600     -noextern -library $<
13601
13602 # Derive a project file from a source file:
13603 %.prj : %.f ; \
13604   ftnchek $(CHEKFLAGS) -noextern -project -library $<
13605
13606 # The list of objects is assumed to be in variable OBJS.
13607 # Sources corresponding to the objects:
13608 SRCS = $(OBJS:%.o=%.f)
13609 # ftnchek project files:
13610 PRJS = $(OBJS:%.o=%.prj)
13611
13612 # Build the program
13613 prog: $(OBJS) ; \
13614   $(FC) -o $@ $(OBJS)
13615
13616 chekall: $(PRJS) ; \
13617   ftnchek $(CHEKFLAGS) $(PRJS)
13618
13619 prjs: $(PRJS)
13620
13621 # For Emacs M-x find-tag:
13622 TAGS: $(SRCS) ; \
13623   etags $(SRCS)
13624
13625 # Rebuild dependencies:
13626 depend: ; \
13627   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
13628 @end smallexample
13629
13630 @item
13631 Try your code out using other Fortran compilers, such as @code{f2c}.
13632 If it does not work on at least one other compiler (assuming the
13633 compiler supports the features the code needs), that is a strong
13634 indicator of a bug in the code.
13635
13636 However, even if your code works on many compilers @emph{except}
13637 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
13638 It might mean the bug is in your code, and that @code{g77} simply
13639 exposes it more readily than other compilers.
13640 @end itemize
13641
13642 @node Bug Lists
13643 @section Where to Report Bugs
13644 @cindex bug report mailing lists
13645 @kindex @value{email-bugs}
13646 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
13647
13648 Often people think of posting bug reports to a newsgroup instead of
13649 mailing them.
13650 This sometimes appears to work, but it has one problem which can be
13651 crucial: a newsgroup posting does not contain a mail path back to the
13652 sender.
13653 Thus, if maintainers need more information, they might be unable
13654 to reach you.  For this reason, you should always send bug reports by
13655 mail to the proper mailing list.
13656
13657 As a last resort, send bug reports on paper to:
13658
13659 @example
13660 GNU Compiler Bugs
13661 Free Software Foundation
13662 59 Temple Place - Suite 330
13663 Boston, MA 02111-1307, USA
13664 @end example
13665
13666 @node Bug Reporting
13667 @section How to Report Bugs
13668 @cindex compiler bugs, reporting
13669
13670 The fundamental principle of reporting bugs usefully is this:
13671 @strong{report all the facts}.
13672 If you are not sure whether to state a
13673 fact or leave it out, state it!
13674
13675 Often people omit facts because they think they know what causes the
13676 problem and they conclude that some details don't matter.
13677 Thus, you might
13678 assume that the name of the variable you use in an example does not matter.
13679 Well, probably it doesn't, but one cannot be sure.
13680 Perhaps the bug is a
13681 stray memory reference which happens to fetch from the location where that
13682 name is stored in memory; perhaps, if the name were different, the contents
13683 of that location would fool the compiler into doing the right thing despite
13684 the bug.
13685 Play it safe and give a specific, complete example.
13686 That is the
13687 easiest thing for you to do, and the most helpful.
13688
13689 Keep in mind that the purpose of a bug report is to enable someone to
13690 fix the bug if it is not known.
13691 It isn't very important what happens if
13692 the bug is already known.
13693 Therefore, always write your bug reports on
13694 the assumption that the bug is not known.
13695
13696 Sometimes people give a few sketchy facts and ask, ``Does this ring a
13697 bell?''
13698 This cannot help us fix a bug, so it is rarely helpful.
13699 We respond by asking for enough details to enable us to investigate.
13700 You might as well expedite matters by sending them to begin with.
13701 (Besides, there are enough bells ringing around here as it is.)
13702
13703 Try to make your bug report self-contained.
13704 If we have to ask you for
13705 more information, it is best if you include all the previous information
13706 in your response, as well as the information that was missing.
13707
13708 Please report each bug in a separate message.
13709 This makes it easier for
13710 us to track which bugs have been fixed and to forward your bugs reports
13711 to the appropriate maintainer.
13712
13713 Do not compress and encode any part of your bug report using programs
13714 such as @file{uuencode}.
13715 If you do so it will slow down the processing
13716 of your bug.
13717 If you must submit multiple large files, use @file{shar},
13718 which allows us to read your message without having to run any
13719 decompression programs.
13720
13721 (As a special exception for GNU Fortran bug-reporting, at least
13722 for now, if you are sending more than a few lines of code, if
13723 your program's source file format contains ``interesting'' things
13724 like trailing spaces or strange characters, or if you need to
13725 include binary data files, it is acceptable to put all the
13726 files together in a @code{tar} archive, and, whether you need to
13727 do that, it is acceptable to then compress the single file (@code{tar}
13728 archive or source file)
13729 using @code{gzip} and encode it via @code{uuencode}.
13730 Do not use any MIME stuff---the current maintainer can't decode this.
13731 Using @code{compress} instead of @code{gzip} is acceptable, assuming
13732 you have licensed the use of the patented algorithm in
13733 @code{compress} from Unisys.)
13734
13735 To enable someone to investigate the bug, you should include all these
13736 things:
13737
13738 @itemize @bullet
13739 @item
13740 The version of GNU Fortran.
13741 You can get this by running @code{g77} with the @samp{-v} option.
13742 (Ignore any error messages that might be displayed
13743 when the linker is run.)
13744
13745 Without this, we won't know whether there is any point in looking for
13746 the bug in the current version of GNU Fortran.
13747
13748 @item
13749 @cindex preprocessor
13750 @cindex cpp program
13751 @cindex programs, cpp
13752 @pindex cpp
13753 A complete input file that will reproduce the bug.
13754
13755 If your source file(s) require preprocessing
13756 (for example, their names have suffixes like
13757 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
13758 and the bug is in the compiler proper (@file{f771})
13759 or in a subsequent phase of processing,
13760 run your source file through the C preprocessor
13761 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
13762 Then, include the contents of @var{newfile} in the bug report.
13763 (When you do this, use the same preprocessor options---such as
13764 @samp{-I}, @samp{-D}, and @samp{-U}---that you used in actual
13765 compilation.)
13766
13767 A single statement is not enough of an example.
13768 In order to compile it,
13769 it must be embedded in a complete file of compiler input.
13770 The bug might depend on the details of how this is done.
13771
13772 Without a real example one can compile,
13773 all anyone can do about your bug report is wish you luck.
13774 It would be futile to try to guess how to provoke the bug.
13775 For example, bugs in register allocation and reloading
13776 can depend on every little detail of the source and include files
13777 that trigger them.
13778
13779 @item
13780 @cindex included files
13781 @cindex INCLUDE directive
13782 @cindex directive, INCLUDE
13783 @cindex #include directive
13784 @cindex directive, #include
13785 Note that you should include with your bug report any files
13786 included by the source file
13787 (via the @code{#include} or @code{INCLUDE} directive)
13788 that you send, and any files they include, and so on.
13789
13790 It is not necessary to replace
13791 the @code{#include} and @code{INCLUDE} directives
13792 with the actual files in the version of the source file that
13793 you send, but it might make submitting the bug report easier
13794 in the end.
13795 However, be sure to @emph{reproduce} the bug using the @emph{exact}
13796 version of the source material you submit, to avoid wild-goose
13797 chases.
13798
13799 @item
13800 The command arguments you gave GNU Fortran to compile that example
13801 and observe the bug.  For example, did you use @samp{-O}?  To guarantee
13802 you won't omit something important, list all the options.
13803
13804 If we were to try to guess the arguments, we would probably guess wrong
13805 and then we would not encounter the bug.
13806
13807 @item
13808 The type of machine you are using, and the operating system name and
13809 version number.
13810 (Much of this information is printed by @samp{g77 -v}---if you
13811 include that, send along any additional info you have that you
13812 don't see clearly represented in that output.)
13813
13814 @item
13815 The operands you gave to the @code{configure} command when you installed
13816 the compiler.
13817
13818 @item
13819 A complete list of any modifications you have made to the compiler
13820 source.  (We don't promise to investigate the bug unless it happens in
13821 an unmodified compiler.  But if you've made modifications and don't tell
13822 us, then you are sending us on a wild-goose chase.)
13823
13824 Be precise about these changes.  A description in English is not
13825 enough---send a context diff for them.
13826
13827 Adding files of your own (such as a machine description for a machine we
13828 don't support) is a modification of the compiler source.
13829
13830 @item
13831 Details of any other deviations from the standard procedure for installing
13832 GNU Fortran.
13833
13834 @item
13835 A description of what behavior you observe that you believe is
13836 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
13837 ``The assembler instruction at line 208 in the output is incorrect.''
13838
13839 Of course, if the bug is that the compiler gets a fatal signal, then one
13840 can't miss it.  But if the bug is incorrect output, the maintainer might
13841 not notice unless it is glaringly wrong.  None of us has time to study
13842 all the assembler code from a 50-line Fortran program just on the chance that
13843 one instruction might be wrong.  We need @emph{you} to do this part!
13844
13845 Even if the problem you experience is a fatal signal, you should still
13846 say so explicitly.  Suppose something strange is going on, such as, your
13847 copy of the compiler is out of synch, or you have encountered a bug in
13848 the C library on your system.  (This has happened!)  Your copy might
13849 crash and the copy here would not.  If you @i{said} to expect a crash,
13850 then when the compiler here fails to crash, we would know that the bug
13851 was not happening.  If you don't say to expect a crash, then we would
13852 not know whether the bug was happening.  We would not be able to draw
13853 any conclusion from our observations.
13854
13855 If the problem is a diagnostic when building GNU Fortran with some other
13856 compiler, say whether it is a warning or an error.
13857
13858 Often the observed symptom is incorrect output when your program is run.
13859 Sad to say, this is not enough information unless the program is short
13860 and simple.  None of us has time to study a large program to figure out
13861 how it would work if compiled correctly, much less which line of it was
13862 compiled wrong.  So you will have to do that.  Tell us which source line
13863 it is, and what incorrect result happens when that line is executed.  A
13864 person who understands the program can find this as easily as finding a
13865 bug in the program itself.
13866
13867 @item
13868 If you send examples of assembler code output from GNU Fortran,
13869 please use @samp{-g} when you make them.  The debugging information
13870 includes source line numbers which are essential for correlating the
13871 output with the input.
13872
13873 @item
13874 If you wish to mention something in the GNU Fortran source, refer to it by
13875 context, not by line number.
13876
13877 The line numbers in the development sources don't match those in your
13878 sources.  Your line numbers would convey no convenient information to the
13879 maintainers.
13880
13881 @item
13882 Additional information from a debugger might enable someone to find a
13883 problem on a machine which he does not have available.  However, you
13884 need to think when you collect this information if you want it to have
13885 any chance of being useful.
13886
13887 @cindex backtrace for bug reports
13888 For example, many people send just a backtrace, but that is never
13889 useful by itself.  A simple backtrace with arguments conveys little
13890 about GNU Fortran because the compiler is largely data-driven; the same
13891 functions are called over and over for different RTL insns, doing
13892 different things depending on the details of the insn.
13893
13894 Most of the arguments listed in the backtrace are useless because they
13895 are pointers to RTL list structure.  The numeric values of the
13896 pointers, which the debugger prints in the backtrace, have no
13897 significance whatever; all that matters is the contents of the objects
13898 they point to (and most of the contents are other such pointers).
13899
13900 In addition, most compiler passes consist of one or more loops that
13901 scan the RTL insn sequence.  The most vital piece of information about
13902 such a loop---which insn it has reached---is usually in a local variable,
13903 not in an argument.
13904
13905 @findex debug_rtx
13906 What you need to provide in addition to a backtrace are the values of
13907 the local variables for several stack frames up.  When a local
13908 variable or an argument is an RTX, first print its value and then use
13909 the GDB command @code{pr} to print the RTL expression that it points
13910 to.  (If GDB doesn't run on your machine, use your debugger to call
13911 the function @code{debug_rtx} with the RTX as an argument.)  In
13912 general, whenever a variable is a pointer, its value is no use
13913 without the data it points to.
13914 @end itemize
13915
13916 Here are some things that are not necessary:
13917
13918 @itemize @bullet
13919 @item
13920 A description of the envelope of the bug.
13921
13922 Often people who encounter a bug spend a lot of time investigating
13923 which changes to the input file will make the bug go away and which
13924 changes will not affect it.
13925
13926 This is often time consuming and not very useful, because the way we
13927 will find the bug is by running a single example under the debugger with
13928 breakpoints, not by pure deduction from a series of examples.  You might
13929 as well save your time for something else.
13930
13931 Of course, if you can find a simpler example to report @emph{instead} of
13932 the original one, that is a convenience.  Errors in the output will be
13933 easier to spot, running under the debugger will take less time, etc.
13934 Most GNU Fortran bugs involve just one function, so the most straightforward
13935 way to simplify an example is to delete all the function definitions
13936 except the one where the bug occurs.  Those earlier in the file may be
13937 replaced by external declarations if the crucial function depends on
13938 them.  (Exception: inline functions might affect compilation of functions
13939 defined later in the file.)
13940
13941 However, simplification is not vital; if you don't want to do this,
13942 report the bug anyway and send the entire test case you used.
13943
13944 @item
13945 In particular, some people insert conditionals @samp{#ifdef BUG} around
13946 a statement which, if removed, makes the bug not happen.  These are just
13947 clutter; we won't pay any attention to them anyway.  Besides, you should
13948 send us preprocessor output, and that can't have conditionals.
13949
13950 @item
13951 A patch for the bug.
13952
13953 A patch for the bug is useful if it is a good one.  But don't omit the
13954 necessary information, such as the test case, on the assumption that a
13955 patch is all we need.  We might see problems with your patch and decide
13956 to fix the problem another way, or we might not understand it at all.
13957
13958 Sometimes with a program as complicated as GNU Fortran it is very hard to
13959 construct an example that will make the program follow a certain path
13960 through the code.  If you don't send the example, we won't be able to
13961 construct one, so we won't be able to verify that the bug is fixed.
13962
13963 And if we can't understand what bug you are trying to fix, or why your
13964 patch should be an improvement, we won't install it.  A test case will
13965 help us to understand.
13966
13967 @xref{Sending Patches}, for guidelines on how to make it easy for us to
13968 understand and install your patches.
13969
13970 @item
13971 A guess about what the bug is or what it depends on.
13972
13973 Such guesses are usually wrong.  Even the maintainer can't guess right
13974 about such things without first using the debugger to find the facts.
13975
13976 @item
13977 A core dump file.
13978
13979 We have no way of examining a core dump for your type of machine
13980 unless we have an identical system---and if we do have one,
13981 we should be able to reproduce the crash ourselves.
13982 @end itemize
13983
13984 @node Sending Patches
13985 @section Sending Patches for GNU Fortran
13986
13987 If you would like to write bug fixes or improvements for the GNU Fortran
13988 compiler, that is very helpful.
13989 Send suggested fixes to the bug report
13990 mailing list, @email{@value{email-bugs}}.
13991
13992 Please follow these guidelines so we can study your patches efficiently.
13993 If you don't follow these guidelines, your information might still be
13994 useful, but using it will take extra work.  Maintaining GNU Fortran is a lot
13995 of work in the best of circumstances, and we can't keep up unless you do
13996 your best to help.
13997
13998 @itemize @bullet
13999 @item
14000 Send an explanation with your changes of what problem they fix or what
14001 improvement they bring about.  For a bug fix, just include a copy of the
14002 bug report, and explain why the change fixes the bug.
14003
14004 (Referring to a bug report is not as good as including it, because then
14005 we will have to look it up, and we have probably already deleted it if
14006 we've already fixed the bug.)
14007
14008 @item
14009 Always include a proper bug report for the problem you think you have
14010 fixed.  We need to convince ourselves that the change is right before
14011 installing it.  Even if it is right, we might have trouble judging it if
14012 we don't have a way to reproduce the problem.
14013
14014 @item
14015 Include all the comments that are appropriate to help people reading the
14016 source in the future understand why this change was needed.
14017
14018 @item
14019 Don't mix together changes made for different reasons.
14020 Send them @emph{individually}.
14021
14022 If you make two changes for separate reasons, then we might not want to
14023 install them both.  We might want to install just one.  If you send them
14024 all jumbled together in a single set of diffs, we have to do extra work
14025 to disentangle them---to figure out which parts of the change serve
14026 which purpose.  If we don't have time for this, we might have to ignore
14027 your changes entirely.
14028
14029 If you send each change as soon as you have written it, with its own
14030 explanation, then the two changes never get tangled up, and we can
14031 consider each one properly without any extra work to disentangle them.
14032
14033 Ideally, each change you send should be impossible to subdivide into
14034 parts that we might want to consider separately, because each of its
14035 parts gets its motivation from the other parts.
14036
14037 @item
14038 Send each change as soon as that change is finished.  Sometimes people
14039 think they are helping us by accumulating many changes to send them all
14040 together.  As explained above, this is absolutely the worst thing you
14041 could do.
14042
14043 Since you should send each change separately, you might as well send it
14044 right away.  That gives us the option of installing it immediately if it
14045 is important.
14046
14047 @item
14048 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
14049 for us to install reliably.  More than that, they make it hard for us to
14050 study the diffs to decide whether we want to install them.  Unidiff
14051 format is better than contextless diffs, but not as easy to read as
14052 @samp{-c} format.
14053
14054 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
14055 function that each change occurs in.
14056 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
14057
14058 @item
14059 Write the change log entries for your changes.  We get lots of changes,
14060 and we don't have time to do all the change log writing ourselves.
14061
14062 Read the @file{ChangeLog} file to see what sorts of information to put
14063 in, and to learn the style that we use.  The purpose of the change log
14064 is to show people where to find what was changed.  So you need to be
14065 specific about what functions you changed; in large functions, it's
14066 often helpful to indicate where within the function the change was.
14067
14068 On the other hand, once you have shown people where to find the change,
14069 you need not explain its purpose.  Thus, if you add a new function, all
14070 you need to say about it is that it is new.  If you feel that the
14071 purpose needs explaining, it probably does---but the explanation will be
14072 much more useful if you put it in comments in the code.
14073
14074 If you would like your name to appear in the header line for who made
14075 the change, send us the header line.
14076
14077 @item
14078 When you write the fix, keep in mind that we can't install a change that
14079 would break other systems.
14080
14081 People often suggest fixing a problem by changing machine-independent
14082 files such as @file{toplev.c} to do something special that a particular
14083 system needs.  Sometimes it is totally obvious that such changes would
14084 break GNU Fortran for almost all users.  We can't possibly make a change like
14085 that.  At best it might tell us how to write another patch that would
14086 solve the problem acceptably.
14087
14088 Sometimes people send fixes that @emph{might} be an improvement in
14089 general---but it is hard to be sure of this.  It's hard to install
14090 such changes because we have to study them very carefully.  Of course,
14091 a good explanation of the reasoning by which you concluded the change
14092 was correct can help convince us.
14093
14094 The safest changes are changes to the configuration files for a
14095 particular machine.  These are safe because they can't create new bugs
14096 on other machines.
14097
14098 Please help us keep up with the workload by designing the patch in a
14099 form that is good to install.
14100 @end itemize
14101
14102 @node Service
14103 @chapter How To Get Help with GNU Fortran
14104
14105 If you need help installing, using or changing GNU Fortran, there are two
14106 ways to find it:
14107
14108 @itemize @bullet
14109 @item
14110 Look in the service directory for someone who might help you for a fee.
14111 The service directory is found in the file named @file{SERVICE} in the
14112 GNU CC distribution.
14113
14114 @item
14115 Send a message to @email{@value{email-general}}.
14116 @end itemize
14117
14118 @end ifset
14119 @ifset INTERNALS
14120 @node Adding Options
14121 @chapter Adding Options
14122 @cindex options, adding
14123 @cindex adding options
14124
14125 To add a new command-line option to @code{g77}, first decide
14126 what kind of option you wish to add.
14127 Search the @code{g77} and @code{gcc} documentation for one
14128 or more options that is most closely like the one you want to add
14129 (in terms of what kind of effect it has, and so on) to
14130 help clarify its nature.
14131
14132 @itemize @bullet
14133 @item
14134 @emph{Fortran options} are options that apply only
14135 when compiling Fortran programs.
14136 They are accepted by @code{g77} and @code{gcc}, but
14137 they apply only when compiling Fortran programs.
14138
14139 @item
14140 @emph{Compiler options} are options that apply
14141 when compiling most any kind of program.
14142 @end itemize
14143
14144 @emph{Fortran options} are listed in the file
14145 @file{@value{path-g77}/lang-options.h},
14146 which is used during the build of @code{gcc} to
14147 build a list of all options that are accepted by
14148 at least one language's compiler.
14149 This list goes into the @samp{lang_options} array
14150 in @file{gcc/toplev.c}, which uses this array to
14151 determine whether a particular option should be
14152 offered to the linked-in front end for processing
14153 by calling @samp{lang_option_decode}, which, for
14154 @code{g77}, is in @file{@value{path-g77}/com.c} and just
14155 calls @samp{ffe_decode_option}.
14156
14157 If the linked-in front end ``rejects'' a
14158 particular option passed to it, @file{toplev.c}
14159 just ignores the option, because @emph{some}
14160 language's compiler is willing to accept it.
14161
14162 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
14163 to work, even though Fortran compilation does
14164 not currently support the @samp{-fno-asm} option;
14165 even though the @code{f771} version of @samp{lang_decode_option}
14166 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
14167 produce a diagnostic because some other language (C)
14168 does accept it.
14169
14170 This also means that commands like
14171 @samp{g77 -fno-asm foo.f} yield no diagnostics,
14172 despite the fact that no phase of the command was
14173 able to recognize and process @samp{-fno-asm}---perhaps
14174 a warning about this would be helpful if it were
14175 possible.
14176
14177 Code that processes Fortran options is found in
14178 @file{@value{path-g77}/top.c}, function @samp{ffe_decode_option}.
14179 This code needs to check positive and negative forms
14180 of each option.
14181
14182 The defaults for Fortran options are set in their
14183 global definitions, also found in @file{@value{path-g77}/top.c}.
14184 Many of these defaults are actually macros defined
14185 in @file{@value{path-g77}/target.h}, since they might be
14186 machine-specific.
14187 However, since, in practice, GNU compilers
14188 should behave the same way on all configurations
14189 (especially when it comes to language constructs),
14190 the practice of setting defaults in @file{target.h}
14191 is likely to be deprecated and, ultimately, stopped
14192 in future versions of @code{g77}.
14193
14194 Accessor macros for Fortran options, used by code
14195 in the @code{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
14196
14197 @emph{Compiler options} are listed in @file{gcc/toplev.c}
14198 in the array @samp{f_options}.
14199 An option not listed in @samp{lang_options} is
14200 looked up in @samp{f_options} and handled from there.
14201
14202 The defaults for compiler options are set in the
14203 global definitions for the corresponding variables,
14204 some of which are in @file{gcc/toplev.c}.
14205
14206 You can set different defaults for @emph{Fortran-oriented}
14207 or @emph{Fortran-reticent} compiler options by changing
14208 the way @code{f771} handles the @samp{-fset-g77-defaults}
14209 option, which is always provided as the first option when
14210 called by @code{g77} or @code{gcc}.
14211
14212 This code is in @samp{ffe_decode_options} in @file{@value{path-g77}/top.c}.
14213 Have it change just the variables that you want to default
14214 to a different setting for Fortran compiles compared to
14215 compiles of other languages.
14216
14217 The @samp{-fset-g77-defaults} option is passed to @code{f771}
14218 automatically because of the specification information
14219 kept in @file{@value{path-g77}/lang-specs.h}.
14220 This file tells the @code{gcc} command how to recognize,
14221 in this case, Fortran source files (those to be preprocessed,
14222 and those that are not), and further, how to invoke the
14223 appropriate programs (including @code{f771}) to process
14224 those source files.
14225
14226 It is in @file{@value{path-g77}/lang-specs.h} that @samp{-fset-g77-defaults},
14227 @samp{-fversion}, and other options are passed, as appropriate,
14228 even when the user has not explicitly specified them.
14229 Other ``internal'' options such as @samp{-quiet} also
14230 are passed via this mechanism.
14231
14232 @node Projects
14233 @chapter Projects
14234 @cindex projects
14235
14236 If you want to contribute to @code{g77} by doing research,
14237 design, specification, documentation, coding, or testing,
14238 the following information should give you some ideas.
14239 More relevant information might be available from
14240 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
14241
14242 @menu
14243 * Efficiency::               Make @code{g77} itself compile code faster.
14244 * Better Optimization::      Teach @code{g77} to generate faster code.
14245 * Simplify Porting::         Make @code{g77} easier to configure, build,
14246                              and install.
14247 * More Extensions::          Features many users won't know to ask for.
14248 * Machine Model::            @code{g77} should better leverage @code{gcc}.
14249 * Internals Documentation::  Make maintenance easier.
14250 * Internals Improvements::   Make internals more robust.
14251 * Better Diagnostics::       Make using @code{g77} on new code easier.
14252 @end menu
14253
14254 @node Efficiency
14255 @section Improve Efficiency
14256 @cindex efficiency
14257
14258 Don't bother doing any performance analysis until most of the
14259 following items are taken care of, because there's no question
14260 they represent serious space/time problems, although some of
14261 them show up only given certain kinds of (popular) input.
14262
14263 @itemize @bullet
14264 @item
14265 Improve @samp{malloc} package and its uses to specify more info about
14266 memory pools and, where feasible, use obstacks to implement them.
14267
14268 @item
14269 Skip over uninitialized portions of aggregate areas (arrays,
14270 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
14271 This would reduce memory usage for large initialized aggregate
14272 areas, even ones with only one initialized element.
14273
14274 As of version 0.5.18, a portion of this item has already been
14275 accomplished.
14276
14277 @item
14278 Prescan the statement (in @file{sta.c}) so that the nature of the statement
14279 is determined as much as possible by looking entirely at its form,
14280 and not looking at any context (previous statements, including types
14281 of symbols).
14282 This would allow ripping out of the statement-confirmation,
14283 symbol retraction/confirmation, and diagnostic inhibition
14284 mechanisms.
14285 Plus, it would result in much-improved diagnostics.
14286 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
14287 is not a subroutine intrinsic, would result actual error instead of the
14288 unimplemented-statement catch-all.
14289
14290 @item
14291 Throughout @code{g77}, don't pass line/column pairs where
14292 a simple @samp{ffewhere} type, which points to the error as much as is
14293 desired by the configuration, will do, and don't pass @samp{ffelexToken} types
14294 where a simple @samp{ffewhere} type will do.
14295 Then, allow new default
14296 configuration of @samp{ffewhere} such that the source line text is not
14297 preserved, and leave it to things like Emacs' next-error function
14298 to point to them (now that @samp{next-error} supports column,
14299 or, perhaps, character-offset, numbers).
14300 The change in calling sequences should improve performance somewhat,
14301 as should not having to save source lines.
14302 (Whether this whole
14303 item will improve performance is questionable, but it should
14304 improve maintainability.)
14305
14306 @item
14307 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
14308 as regards the assembly output.
14309 Some of this might require improving
14310 the back end, but lots of improvement in space/time required in @code{g77}
14311 itself can be fairly easily obtained without touching the back end.
14312 Maybe type-conversion, where necessary, can be speeded up as well in
14313 cases like the one shown (converting the @samp{2} into @samp{2.}).
14314
14315 @item
14316 If analysis shows it to be worthwhile, optimize @file{lex.c}.
14317
14318 @item
14319 Consider redesigning @file{lex.c} to not need any feedback
14320 during tokenization, by keeping track of enough parse state on its
14321 own.
14322 @end itemize
14323
14324 @node Better Optimization
14325 @section Better Optimization
14326 @cindex optimization, better
14327 @cindex code generation, improving
14328
14329 Much of this work should be put off until after @code{g77} has
14330 all the features necessary for its widespread acceptance as a
14331 useful F77 compiler.
14332 However, perhaps this work can be done in parallel during
14333 the feature-adding work.
14334
14335 @itemize @bullet
14336 @item
14337 Do the equivalent of the trick of putting @samp{extern inline} in front
14338 of every function definition in @code{libg2c} and #include'ing the resulting
14339 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
14340 that are at all worth inlining.
14341 (Some of this has already been done, such as for integral exponentiation.)
14342
14343 @item
14344 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
14345 and it's clear that types line up
14346 and @samp{CHAR_VAR} is addressable or not a @samp{VAR_DECL},
14347 make @samp{CHAR_VAR}, not a
14348 temporary, be the receiver for @samp{CHAR_FUNC}.
14349 (This is now done for @code{COMPLEX} variables.)
14350
14351 @item
14352 Design and implement Fortran-specific optimizations that don't
14353 really belong in the back end, or where the front end needs to
14354 give the back end more info than it currently does.
14355
14356 @item
14357 Design and implement a new run-time library interface, with the
14358 code going into @code{libgcc} so no special linking is required to
14359 link Fortran programs using standard language features.
14360 This library
14361 would speed up lots of things, from I/O (using precompiled formats,
14362 doing just one, or, at most, very few, calls for arrays or array sections,
14363 and so on) to general computing (array/section implementations of
14364 various intrinsics, implementation of commonly performed loops that
14365 aren't likely to be optimally compiled otherwise, etc.).
14366
14367 Among the important things the library would do are:
14368
14369 @itemize @bullet
14370 @item
14371 Be a one-stop-shop-type
14372 library, hence shareable and usable by all, in that what are now
14373 library-build-time options in @code{libg2c} would be moved at least to the
14374 @code{g77} compile phase, if not to finer grains (such as choosing how
14375 list-directed I/O formatting is done by default at @code{OPEN} time, for
14376 preconnected units via options or even statements in the main program
14377 unit, maybe even on a per-I/O basis with appropriate pragma-like
14378 devices).
14379 @end itemize
14380
14381 @item
14382 Probably requiring the new library design, change interface to
14383 normally have @code{COMPLEX} functions return their values in the way
14384 @code{gcc} would if they were declared @code{__complex__ float},
14385 rather than using
14386 the mechanism currently used by @code{CHARACTER} functions (whereby the
14387 functions are compiled as returning void and their first arg is
14388 a pointer to where to store the result).
14389 (Don't append underscores to
14390 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
14391 @code{gcc} rather than @code{f2c} calling conventions.)
14392
14393 @item
14394 Do something useful with @samp{doiter} references where possible.
14395 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
14396 a @code{DO} loop that uses @samp{I} as the
14397 iteration variable, and the back end might find that info useful
14398 in determining whether it needs to read @samp{I} back into a register after
14399 the call.
14400 (It normally has to do that, unless it knows @samp{FOO} never
14401 modifies its passed-by-reference argument, which is rarely the case
14402 for Fortran-77 code.)
14403 @end itemize
14404
14405 @node Simplify Porting
14406 @section Simplify Porting
14407 @cindex porting, simplify
14408 @cindex simplify porting
14409
14410 Making @code{g77} easier to configure, port, build, and install, either
14411 as a single-system compiler or as a cross-compiler, would be
14412 very useful.
14413
14414 @itemize @bullet
14415 @item
14416 A new library (replacing @code{libg2c}) should improve portability as well as
14417 produce more optimal code.
14418 Further, @code{g77} and the new library should
14419 conspire to simplify naming of externals, such as by removing unnecessarily
14420 added underscores, and to reduce/eliminate the possibility of naming
14421 conflicts, while making debugger more straightforward.
14422
14423 Also, it should
14424 make multi-language applications more feasible, such as by providing
14425 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
14426 descriptors.
14427
14428 @item
14429 Possibly related to a new library, @code{g77} should produce the equivalent
14430 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
14431 main program unit, instead of compiling something that must be
14432 called by a library
14433 implementation of @code{main()}.
14434
14435 This would do many useful things such as
14436 provide more flexibility in terms of setting up exception handling,
14437 not requiring programmers to start their debugging sessions with
14438 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
14439
14440 @item
14441 The GBE needs to understand the difference between alignment
14442 requirements and desires.
14443 For example, on Intel x86 machines, @code{g77} currently imposes
14444 overly strict alignment requirements, due to the back end, but it
14445 would be useful for Fortran and C programmers to be able to override
14446 these @emph{recommendations} as long as they don't violate the actual
14447 processor @emph{requirements}.
14448 @end itemize
14449
14450 @node More Extensions
14451 @section More Extensions
14452 @cindex extensions, more
14453
14454 These extensions are not the sort of things users ask for ``by name'',
14455 but they might improve the usability of @code{g77}, and Fortran in
14456 general, in the long run.
14457 Some of these items really pertain to improving @code{g77} internals
14458 so that some popular extensions can be more easily supported.
14459
14460 @itemize @bullet
14461 @item
14462 Look through all the documentation on the GNU Fortran language,
14463 dialects, compiler, missing features, bugs, and so on.
14464 Many mentions of incomplete or missing features are
14465 sprinkled throughout.
14466 It is not worth repeating them here.
14467
14468 @item
14469 @cindex concatenation
14470 @cindex CHARACTER*(*)
14471 @cindex run-time, dynamic allocation
14472 Support arbitrary operands for concatenation, even in contexts where
14473 run-time allocation is required.
14474 For example:
14475
14476 @smallexample
14477 SUBROUTINE X(A)
14478 CHARACTER*(*) A
14479 CALL FOO(A // 'suffix')
14480 @end smallexample
14481
14482 @item
14483 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
14484 named and unnamed.
14485 The idea is to provide a forward-looking, effective
14486 replacement for things like the old-style @code{PARAMETER} statement
14487 when people
14488 really need typelessness in a maintainable, portable, clearly documented
14489 way.
14490 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
14491 and whatever else might come along.
14492 (This is not really a call for polymorphism per se, just
14493 an ability to express limited, syntactic polymorphism.)
14494
14495 @item
14496 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
14497
14498 @item
14499 Support arbitrary file unit numbers, instead of limiting them
14500 to 0 through @samp{MXUNIT-1}.
14501 (This is a @code{libg2c} issue.)
14502
14503 @item
14504 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
14505 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
14506 later @code{UNIT=} in the first example is invalid.
14507 Make sure this is what users of this feature would expect.
14508
14509 @item
14510 Currently @code{g77} disallows @samp{READ(1'10)} since
14511 it is an obnoxious syntax, but
14512 supporting it might be pretty easy if needed.
14513 More details are needed, such
14514 as whether general expressions separated by an apostrophe are supported,
14515 or maybe the record number can be a general expression, and so on.
14516
14517 @item
14518 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
14519 fully.
14520 Currently there is no support at all
14521 for @code{%FILL} in @code{STRUCTURE} and related syntax,
14522 whereas the rest of the
14523 stuff has at least some parsing support.
14524 This requires either major
14525 changes to @code{libg2c} or its replacement.
14526
14527 @item
14528 F90 and @code{g77} probably disagree about label scoping relative to
14529 @code{INTERFACE} and @code{END INTERFACE}, and their contained
14530 procedure interface bodies (blocks?).
14531
14532 @item
14533 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
14534 since that was added after S8.112.
14535
14536 @item
14537 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
14538 with the final form of the standard (it was vague at S8.112).
14539
14540 @item
14541 It seems to be an ``open'' question whether a file, immediately after being
14542 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
14543 might be nice to offer an option of opening to ``undefined'' status, requiring
14544 an explicit absolute-positioning operation to be performed before any
14545 other (besides @code{CLOSE}) to assist in making applications port to systems
14546 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
14547 @end itemize
14548
14549 @node Machine Model
14550 @section Machine Model
14551
14552 This items pertain to generalizing @code{g77}'s view of
14553 the machine model to more fully accept whatever the GBE
14554 provides it via its configuration.
14555
14556 @itemize @bullet
14557 @item
14558 Switch to using @samp{REAL_VALUE_TYPE} to represent floating-point constants
14559 exclusively so the target float format need not be required.
14560 This
14561 means changing the way @code{g77} handles initialization of aggregate areas
14562 having more than one type, such as @code{REAL} and @code{INTEGER},
14563 because currently
14564 it initializes them as if they were arrays of @code{char} and uses the
14565 bit patterns of the constants of the various types in them to determine
14566 what to stuff in elements of the arrays.
14567
14568 @item
14569 Rely more and more on back-end info and capabilities, especially in the
14570 area of constants (where having the @code{g77} front-end's IL just store
14571 the appropriate tree nodes containing constants might be best).
14572
14573 @item
14574 Suite of C and Fortran programs that a user/administrator can run on a
14575 machine to help determine the configuration for @code{g77} before building
14576 and help determine if the compiler works (especially with whatever
14577 libraries are installed) after building.
14578 @end itemize
14579
14580 @node Internals Documentation
14581 @section Internals Documentation
14582
14583 Better info on how @code{g77} works and how to port it is needed.
14584 Much of this should be done only after the redesign planned for
14585 0.6 is complete.
14586
14587 @node Internals Improvements
14588 @section Internals Improvements
14589
14590 Some more items that would make @code{g77} more reliable
14591 and easier to maintain:
14592
14593 @itemize @bullet
14594 @item
14595 Generally make expression handling focus
14596 more on critical syntax stuff, leaving semantics to callers.
14597 For example,
14598 anything a caller can check, semantically, let it do so, rather
14599 than having @file{expr.c} do it.
14600 (Exceptions might include things like
14601 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
14602 it seems
14603 important to preserve the left-to-right-in-source order of production
14604 of diagnostics.)
14605
14606 @item
14607 Come up with better naming conventions for @samp{-D} to establish requirements
14608 to achieve desired implementation dialect via @file{proj.h}.
14609
14610 @item
14611 Clean up used tokens and @samp{ffewhere}s in @samp{ffeglobal_terminate_1}.
14612
14613 @item
14614 Replace @file{sta.c} @samp{outpooldisp} mechanism with @samp{malloc_pool_use}.
14615
14616 @item
14617 Check for @samp{opANY} in more places in @file{com.c}, @file{std.c},
14618 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
14619 (after determining if there is indeed no real need for it).
14620
14621 @item
14622 Utility to read and check @file{bad.def} messages and their references in the
14623 code, to make sure calls are consistent with message templates.
14624
14625 @item
14626 Search and fix @samp{&ffe@dots{}} and similar so that
14627 @samp{ffe@dots{}ptr@dots{}} macros are
14628 available instead (a good argument for wishing this could have written all
14629 this stuff in C++, perhaps).
14630 On the other hand, it's questionable whether this sort of
14631 improvement is really necessary, given the availability of
14632 tools such as Emacs and Perl, which make finding any
14633 address-taking of structure members easy enough?
14634
14635 @item
14636 Some modules truly export the member names of their structures (and the
14637 structures themselves), maybe fix this, and fix other modules that just
14638 appear to as well (by appending @samp{_}, though it'd be ugly and probably
14639 not worth the time).
14640
14641 @item
14642 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
14643 in @file{proj.h}
14644 and use them throughout @code{g77} source code (especially in the definitions
14645 of access macros in @samp{.h} files) so they can be tailored
14646 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
14647
14648 @item
14649 Decorate throughout with @code{const} and other such stuff.
14650
14651 @item
14652 All F90 notational derivations in the source code are still based
14653 on the S8.112 version of the draft standard.
14654 Probably should update
14655 to the official standard, or put documentation of the rules as used
14656 in the code@dots{}uh@dots{}in the code.
14657
14658 @item
14659 Some @samp{ffebld_new} calls (those outside of @file{ffeexpr.c} or
14660 inside but invoked via paths not involving @samp{ffeexpr_lhs} or
14661 @samp{ffeexpr_rhs}) might be creating things
14662 in improper pools, leading to such things staying around too long or
14663 (doubtful, but possible and dangerous) not long enough.
14664
14665 @item
14666 Some @samp{ffebld_list_new} (or whatever) calls might not be matched by
14667 @samp{ffebld_list_bottom} (or whatever) calls, which might someday matter.
14668 (It definitely is not a problem just yet.)
14669
14670 @item
14671 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
14672 due to alignment/mismatch or other problems---they end up without
14673 @samp{ffestorag} objects, so maybe the backend (and other parts of the front
14674 end) can notice that and handle like an @samp{opANY} (do what it wants, just
14675 don't complain or crash).
14676 Most of this seems to have been addressed
14677 by now, but a code review wouldn't hurt.
14678 @end itemize
14679
14680 @node Better Diagnostics
14681 @section Better Diagnostics
14682
14683 These are things users might not ask about, or that need to
14684 be looked into, before worrying about.
14685 Also here are items that involve reducing unnecessary diagnostic
14686 clutter.
14687
14688 @itemize @bullet
14689 @item
14690 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
14691 lengths, type classes, and so on),
14692 @samp{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
14693 it specifies.
14694
14695 @item
14696 Speed up and improve error handling for data when repeat-count is
14697 specified.
14698 For example, don't output 20 unnecessary messages after the
14699 first necessary one for:
14700
14701 @smallexample
14702 INTEGER X(20)
14703 CONTINUE
14704 DATA (X(I), J= 1, 20) /20*5/
14705 END
14706 @end smallexample
14707
14708 @noindent
14709 (The @code{CONTINUE} statement ensures the @code{DATA} statement
14710 is processed in the context of executable, not specification,
14711 statements.)
14712 @end itemize
14713 @end ifset
14714
14715 @ifset USING
14716 @node Diagnostics
14717 @chapter Diagnostics
14718 @cindex diagnostics
14719
14720 Some diagnostics produced by @code{g77} require sufficient explanation
14721 that the explanations are given below, and the diagnostics themselves
14722 identify the appropriate explanation.
14723
14724 Identification uses the GNU Info format---specifically, the @code{info}
14725 command that displays the explanation is given within square
14726 brackets in the diagnostic.
14727 For example:
14728
14729 @smallexample
14730 foo.f:5: Invalid statement [info -f g77 M FOOEY]
14731 @end smallexample
14732
14733 More details about the above diagnostic is found in the @code{g77} Info
14734 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
14735 which is displayed by typing the UNIX command
14736 @samp{info -f g77 M FOOEY}.
14737
14738 Other Info readers, such as EMACS, may be just as easily used to display
14739 the pertinent node.
14740 In the above example, @samp{g77} is the Info document name,
14741 @samp{M} is the top-level menu item to select,
14742 and, in that node (named @samp{Diagnostics}, the name of
14743 this chapter, which is the very text you're reading now),
14744 @samp{FOOEY} is the menu item to select.
14745
14746 @iftex
14747 In this printed version of the @code{g77} manual, the above example
14748 points to a section, below, entitled @samp{FOOEY}---though, of course,
14749 as the above is just a sample, no such section exists.
14750 @end iftex
14751
14752 @menu
14753 * CMPAMBIG::    Ambiguous use of intrinsic.
14754 * EXPIMP::      Intrinsic used explicitly and implicitly.
14755 * INTGLOB::     Intrinsic also used as name of global.
14756 * LEX::         Various lexer messages
14757 * GLOBALS::     Disagreements about globals.
14758 * LINKFAIL::    When linking @samp{f771} fails.
14759 @end menu
14760
14761 @node CMPAMBIG
14762 @section @code{CMPAMBIG}
14763
14764 @noindent
14765 @smallexample
14766 Ambiguous use of intrinsic @var{intrinsic} @dots{}
14767 @end smallexample
14768
14769 The type of the argument to the invocation of the @var{intrinsic}
14770 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
14771 Typically, it is @code{COMPLEX(KIND=2)}, also known as
14772 @code{DOUBLE COMPLEX}.
14773
14774 The interpretation of this invocation depends on the particular
14775 dialect of Fortran for which the code was written.
14776 Some dialects convert the real part of the argument to
14777 @code{REAL(KIND=1)}, thus losing precision; other dialects,
14778 and Fortran 90, do no such conversion.
14779
14780 So, GNU Fortran rejects such invocations except under certain
14781 circumstances, to avoid making an incorrect assumption that results
14782 in generating the wrong code.
14783
14784 To determine the dialect of the program unit, perhaps even whether
14785 that particular invocation is properly coded, determine how the
14786 result of the intrinsic is used.
14787
14788 The result of @var{intrinsic} is expected (by the original programmer)
14789 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
14790
14791 @itemize @bullet
14792 @item
14793 It is passed as an argument to a procedure that explicitly or
14794 implicitly declares that argument @code{REAL(KIND=1)}.
14795
14796 For example,
14797 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
14798 statement specifying the dummy argument corresponding to an
14799 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14800 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14801 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
14802 of @code{REAL(KIND=2)}.
14803
14804 @item
14805 It is used in a context that would otherwise not include
14806 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
14807 invocation as @code{REAL(KIND=2)} would result in unnecessary
14808 promotions and (typically) more expensive operations on the
14809 wider type.
14810
14811 For example:
14812
14813 @smallexample
14814 DOUBLE COMPLEX Z
14815 @dots{}
14816 R(1) = T * REAL(Z)
14817 @end smallexample
14818
14819 The above example suggests the programmer expected the real part
14820 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
14821 multiplied by @samp{T} (presumed, along with @samp{R} above, to
14822 be type @code{REAL(KIND=1)}).
14823
14824 Otherwise, the conversion would have to be delayed until after
14825 the multiplication, requiring not only an extra conversion
14826 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
14827 expensive multiplication (a double-precision multiplication instead
14828 of a single-precision one).
14829 @end itemize
14830
14831 The result of @var{intrinsic} is expected (by the original programmer)
14832 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
14833
14834 @itemize @bullet
14835 @item
14836 It is passed as an argument to a procedure that explicitly or
14837 implicitly declares that argument @code{REAL(KIND=2)}.
14838
14839 For example, a procedure specifying a @code{DOUBLE PRECISION}
14840 dummy argument corresponding to an
14841 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14842 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14843 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
14844 of @code{REAL(KIND=1)}.
14845
14846 @item
14847 It is used in an expression context that includes
14848 other @code{REAL(KIND=2)} operands,
14849 or is assigned to a @code{REAL(KIND=2)} variable or array element.
14850
14851 For example:
14852
14853 @smallexample
14854 DOUBLE COMPLEX Z
14855 DOUBLE PRECISION R, T
14856 @dots{}
14857 R(1) = T * REAL(Z)
14858 @end smallexample
14859
14860 The above example suggests the programmer expected the real part
14861 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
14862 by the @code{REAL()} intrinsic.
14863
14864 Otherwise, the conversion would have to be immediately followed
14865 by a conversion back to @code{REAL(KIND=2)}, losing
14866 the original, full precision of the real part of @code{Z},
14867 before being multiplied by @samp{T}.
14868 @end itemize
14869
14870 Once you have determined whether a particular invocation of @var{intrinsic}
14871 expects the Fortran 90 interpretation, you can:
14872
14873 @itemize @bullet
14874 @item
14875 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
14876 @samp{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
14877 is @samp{AIMAG})
14878 if it expected the Fortran 90 interpretation.
14879
14880 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
14881 some other type, such as @code{COMPLEX*32}, you should use the
14882 appropriate intrinsic, such as the one to convert to @code{REAL*16}
14883 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
14884 @code{QIMAG()} in place of @code{DIMAG()}).
14885
14886 @item
14887 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
14888 otherwise.
14889 This converts to @code{REAL(KIND=1)} in all working
14890 Fortran compilers.
14891 @end itemize
14892
14893 If you don't want to change the code, and you are certain that all
14894 ambiguous invocations of @var{intrinsic} in the source file have
14895 the same expectation regarding interpretation, you can:
14896
14897 @itemize @bullet
14898 @item
14899 Compile with the @code{g77} option @samp{-ff90}, to enable the
14900 Fortran 90 interpretation.
14901
14902 @item
14903 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
14904 to enable the non-Fortran-90 interpretations.
14905 @end itemize
14906
14907 @xref{REAL() and AIMAG() of Complex}, for more information on this
14908 issue.
14909
14910 Note: If the above suggestions don't produce enough evidence
14911 as to whether a particular program expects the Fortran 90
14912 interpretation of this ambiguous invocation of @var{intrinsic},
14913 there is one more thing you can try.
14914
14915 If you have access to most or all the compilers used on the
14916 program to create successfully tested and deployed executables,
14917 read the documentation for, and @emph{also} test out, each compiler
14918 to determine how it treats the @var{intrinsic} intrinsic in
14919 this case.
14920 (If all the compilers don't agree on an interpretation, there
14921 might be lurking bugs in the deployed versions of the program.)
14922
14923 The following sample program might help:
14924
14925 @cindex JCB003 program
14926 @smallexample
14927       PROGRAM JCB003
14928 C
14929 C Written by James Craig Burley 1997-02-23.
14930 C
14931 C Determine how compilers handle non-standard REAL
14932 C and AIMAG on DOUBLE COMPLEX operands.
14933 C
14934       DOUBLE COMPLEX Z
14935       REAL R
14936       Z = (3.3D0, 4.4D0)
14937       R = Z
14938       CALL DUMDUM(Z, R)
14939       R = REAL(Z) - R
14940       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
14941       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
14942       R = 4.4D0
14943       CALL DUMDUM(Z, R)
14944       R = AIMAG(Z) - R
14945       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
14946       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
14947       END
14948 C
14949 C Just to make sure compiler doesn't use naive flow
14950 C analysis to optimize away careful work above,
14951 C which might invalidate results....
14952 C
14953       SUBROUTINE DUMDUM(Z, R)
14954       DOUBLE COMPLEX Z
14955       REAL R
14956       END
14957 @end smallexample
14958
14959 If the above program prints contradictory results on a
14960 particular compiler, run away!
14961
14962 @node EXPIMP
14963 @section @code{EXPIMP}
14964
14965 @noindent
14966 @smallexample
14967 Intrinsic @var{intrinsic} referenced @dots{}
14968 @end smallexample
14969
14970 The @var{intrinsic} is explicitly declared in one program
14971 unit in the source file and implicitly used as an intrinsic
14972 in another program unit in the same source file.
14973
14974 This diagnostic is designed to catch cases where a program
14975 might depend on using the name @var{intrinsic} as an intrinsic
14976 in one program unit and as a global name (such as the name
14977 of a subroutine or function) in another, but @code{g77} recognizes
14978 the name as an intrinsic in both cases.
14979
14980 After verifying that the program unit making implicit use
14981 of the intrinsic is indeed written expecting the intrinsic,
14982 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14983 program unit to prevent this warning.
14984
14985 This and related warnings are disabled by using
14986 the @samp{-Wno-globals} option when compiling.
14987
14988 Note that this warning is not issued for standard intrinsics.
14989 Standard intrinsics include those described in the FORTRAN 77
14990 standard and, if @samp{-ff90} is specified, those described
14991 in the Fortran 90 standard.
14992 Such intrinsics are not as likely to be confused with user
14993 procedures as intrinsics provided as extensions to the
14994 standard by @code{g77}.
14995
14996 @node INTGLOB
14997 @section @code{INTGLOB}
14998
14999 @noindent
15000 @smallexample
15001 Same name `@var{intrinsic}' given @dots{}
15002 @end smallexample
15003
15004 The name @var{intrinsic} is used for a global entity (a common
15005 block or a program unit) in one program unit and implicitly
15006 used as an intrinsic in another program unit.
15007
15008 This diagnostic is designed to catch cases where a program
15009 intends to use a name entirely as a global name, but @code{g77}
15010 recognizes the name as an intrinsic in the program unit that
15011 references the name, a situation that would likely produce
15012 incorrect code.
15013
15014 For example:
15015
15016 @smallexample
15017 INTEGER FUNCTION TIME()
15018 @dots{}
15019 END
15020 @dots{}
15021 PROGRAM SAMP
15022 INTEGER TIME
15023 PRINT *, 'Time is ', TIME()
15024 END
15025 @end smallexample
15026
15027 The above example defines a program unit named @samp{TIME}, but
15028 the reference to @samp{TIME} in the main program unit @samp{SAMP}
15029 is normally treated by @code{g77} as a reference to the intrinsic
15030 @code{TIME()} (unless a command-line option that prevents such
15031 treatment has been specified).
15032
15033 As a result, the program @samp{SAMP} will @emph{not}
15034 invoke the @samp{TIME} function in the same source file.
15035
15036 Since @code{g77} recognizes @code{libU77} procedures as
15037 intrinsics, and since some existing code uses the same names
15038 for its own procedures as used by some @code{libU77}
15039 procedures, this situation is expected to arise often enough
15040 to make this sort of warning worth issuing.
15041
15042 After verifying that the program unit making implicit use
15043 of the intrinsic is indeed written expecting the intrinsic,
15044 add an @samp{INTRINSIC @var{intrinsic}} statement to that
15045 program unit to prevent this warning.
15046
15047 Or, if you believe the program unit is designed to invoke the
15048 program-defined procedure instead of the intrinsic (as
15049 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
15050 statement to the program unit that references the name to
15051 prevent this warning.
15052
15053 This and related warnings are disabled by using
15054 the @samp{-Wno-globals} option when compiling.
15055
15056 Note that this warning is not issued for standard intrinsics.
15057 Standard intrinsics include those described in the FORTRAN 77
15058 standard and, if @samp{-ff90} is specified, those described
15059 in the Fortran 90 standard.
15060 Such intrinsics are not as likely to be confused with user
15061 procedures as intrinsics provided as extensions to the
15062 standard by @code{g77}.
15063
15064 @node LEX
15065 @section @code{LEX}
15066
15067 @noindent
15068 @smallexample
15069 Unrecognized character @dots{}
15070 Invalid first character @dots{}
15071 Line too long @dots{}
15072 Non-numeric character @dots{}
15073 Continuation indicator @dots{}
15074 Label at @dots{} invalid with continuation line indicator @dots{}
15075 Character constant @dots{}
15076 Continuation line @dots{}
15077 Statement at @dots{} begins with invalid token
15078 @end smallexample
15079
15080 Although the diagnostics identify specific problems, they can
15081 be produced when general problems such as the following occur:
15082
15083 @itemize @bullet
15084 @item
15085 The source file contains something other than Fortran code.
15086
15087 If the code in the file does not look like many of the examples
15088 elsewhere in this document, it might not be Fortran code.
15089 (Note that Fortran code often is written in lower case letters,
15090 while the examples in this document use upper case letters,
15091 for stylistic reasons.)
15092
15093 For example, if the file contains lots of strange-looking
15094 characters, it might be APL source code; if it contains lots
15095 of parentheses, it might be Lisp source code; if it
15096 contains lots of bugs, it might be C++ source code.
15097
15098 @item
15099 The source file contains free-form Fortran code, but @samp{-ffree-form}
15100 was not specified on the command line to compile it.
15101
15102 Free form is a newer form for Fortran code.
15103 The older, classic form is called fixed form.
15104
15105 @cindex continuation character
15106 @cindex characters, continuation
15107 Fixed-form code is visually fairly distinctive, because
15108 numerical labels and comments are all that appear in
15109 the first five columns of a line, the sixth column is
15110 reserved to denote continuation lines,
15111 and actual statements start at or beyond column 7.
15112 Spaces generally are not significant, so if you
15113 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
15114 you are looking at fixed-form code.
15115 @cindex *
15116 @cindex asterisk
15117 Comment lines are indicated by the letter @samp{C} or the symbol
15118 @samp{*} in column 1.
15119 @cindex trailing comment
15120 @cindex comment
15121 @cindex characters, comment
15122 @cindex !
15123 @cindex exclamation point
15124 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
15125 which many compilers support.)
15126
15127 Free-form code is distinguished from fixed-form source
15128 primarily by the fact that statements may start anywhere.
15129 (If lots of statements start in columns 1 through 6,
15130 that's a strong indicator of free-form source.)
15131 Consecutive keywords must be separated by spaces, so
15132 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
15133 There are no comment lines per se, but @samp{!} starts a
15134 comment anywhere in a line (other than within a character or
15135 Hollerith constant).
15136
15137 @xref{Source Form}, for more information.
15138
15139 @item
15140 The source file is in fixed form and has been edited without
15141 sensitivity to the column requirements.
15142
15143 Statements in fixed-form code must be entirely contained within
15144 columns 7 through 72 on a given line.
15145 Starting them ``early'' is more likely to result in diagnostics
15146 than finishing them ``late'', though both kinds of errors are
15147 often caught at compile time.
15148
15149 For example, if the following code fragment is edited by following
15150 the commented instructions literally, the result, shown afterward,
15151 would produce a diagnostic when compiled:
15152
15153 @smallexample
15154 C On XYZZY systems, remove "C" on next line:
15155 C     CALL XYZZY_RESET
15156 @end smallexample
15157
15158 The result of editing the above line might be:
15159
15160 @smallexample
15161 C On XYZZY systems, remove "C" on next line:
15162      CALL XYZZY_RESET
15163 @end smallexample
15164
15165 However, that leaves the first @samp{C} in the @samp{CALL}
15166 statement in column 6, making it a comment line, which is
15167 not really what the author intended, and which is likely
15168 to result in one of the above-listed diagnostics.
15169
15170 @emph{Replacing} the @samp{C} in column 1 with a space
15171 is the proper change to make, to ensure the @samp{CALL}
15172 keyword starts in or after column 7.
15173
15174 Another common mistake like this is to forget that fixed-form
15175 source lines are significant through only column 72, and that,
15176 normally, any text beyond column 72 is ignored or is diagnosed
15177 at compile time.
15178
15179 @xref{Source Form}, for more information.
15180
15181 @item
15182 The source file requires preprocessing, and the preprocessing
15183 is not being specified at compile time.
15184
15185 A source file containing lines beginning with @code{#define},
15186 @code{#include}, @code{#if}, and so on is likely one that
15187 requires preprocessing.
15188
15189 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
15190 the file normally will be compiled @emph{without} preprocessing
15191 by @code{g77}.
15192
15193 Change the file's suffix from @samp{.f} to @samp{.F}
15194 (or, on systems with case-insensitive file names,
15195 to @samp{.fpp} or @samp{.FPP}),
15196 from @samp{.for} to @samp{.fpp},
15197 or from @samp{.FOR} to @samp{.FPP}.
15198 @code{g77} compiles files with such names @emph{with}
15199 preprocessing.
15200
15201 @pindex cpp
15202 @cindex preprocessor
15203 @cindex cpp program
15204 @cindex programs, cpp
15205 @cindex @samp{-x f77-cpp-input} option
15206 @cindex options, @samp{-x f77-cpp-input}
15207 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
15208 the language @samp{f77-cpp-input} for Fortran files that
15209 require preprocessing.
15210 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
15211
15212 @item
15213 The source file is preprocessed, and the results of preprocessing
15214 result in syntactic errors that are not necessarily obvious to
15215 someone examining the source file itself.
15216
15217 Examples of errors resulting from preprocessor macro expansion
15218 include exceeding the line-length limit, improperly starting,
15219 terminating, or incorporating the apostrophe or double-quote in
15220 a character constant, improperly forming a Hollerith constant,
15221 and so on.
15222
15223 @xref{Overall Options,,Options Controlling the Kind of Output},
15224 for suggestions about how to use, and not use, preprocessing
15225 for Fortran code.
15226 @end itemize
15227
15228 @node GLOBALS
15229 @section @code{GLOBALS}
15230
15231 @noindent
15232 @smallexample
15233 Global name @var{name} defined at @dots{} already defined@dots{}
15234 Global name @var{name} at @dots{} has different type@dots{}
15235 Too many arguments passed to @var{name} at @dots{}
15236 Too few arguments passed to @var{name} at @dots{}
15237 Argument #@var{n} of @var{name} is @dots{}
15238 @end smallexample
15239
15240 These messages all identify disagreements about the
15241 global procedure named @var{name} among different program units
15242 (usually including @var{name} itself).
15243
15244 Whether a particular disagreement is reported
15245 as a warning or an error
15246 can depend on the relative order
15247 of the disagreeing portions of the source file.
15248
15249 Disagreements between a procedure invocation
15250 and the @emph{subsequent} procedure itself
15251 are, usually, diagnosed as errors
15252 when the procedure itself @emph{precedes} the invocation.
15253 Other disagreements are diagnosed via warnings.
15254
15255 @cindex forward references
15256 @cindex in-line code
15257 @cindex compilation, in-line
15258 This distinction, between warnings and errors,
15259 is due primarily to the present tendency of the @code{gcc} back end
15260 to inline only those procedure invocations that are
15261 @emph{preceded} by the corresponding procedure definitions.
15262 If the @code{gcc} back end is changed
15263 to inline ``forward references'',
15264 in which invocations precede definitions,
15265 the @code{g77} front end will be changed
15266 to treat both orderings as errors, accordingly.
15267
15268 The sorts of disagreements that are diagnosed by @code{g77} include
15269 whether a procedure is a subroutine or function;
15270 if it is a function, the type of the return value of the procedure;
15271 the number of arguments the procedure accepts;
15272 and the type of each argument.
15273
15274 Disagreements regarding global names among program units
15275 in a Fortran program @emph{should} be fixed in the code itself.
15276 However, if that is not immediately practical,
15277 and the code has been working for some time,
15278 it is possible it will work
15279 when compiled with the @samp{-fno-globals} option.
15280
15281 The @samp{-fno-globals} option
15282 causes these diagnostics to all be warnings
15283 and disables all inlining of references to global procedures
15284 (to avoid subsequent compiler crashes and bad-code generation).
15285 Use of the @samp{-Wno-globals} option as well as @samp{-fno-globals}
15286 suppresses all of these diagnostics.
15287 (@samp{-Wno-globals} by itself disables only the warnings,
15288 not the errors.)
15289
15290 After using @samp{-fno-globals} to work around these problems,
15291 it is wise to stop using that option and address them by fixing
15292 the Fortran code, because such problems, while they might not
15293 actually result in bugs on some systems, indicate that the code
15294 is not as portable as it could be.
15295 In particular, the code might appear to work on a particular
15296 system, but have bugs that affect the reliability of the data
15297 without exhibiting any other outward manifestations of the bugs.
15298
15299 @node LINKFAIL
15300 @section @code{LINKFAIL}
15301
15302 @noindent
15303 @smallexample
15304 If the above command failed due to an unresolved reference
15305 to strtoul, _strtoul, bsearch, _bsearch, or similar, see
15306 [info -f g77 M LINKFAIL] (a node in the g77 documentation)
15307 for information on what causes this, how to work around
15308 the problem by editing $@{srcdir@}/proj.c, and what else to do.
15309 @end smallexample
15310
15311 @xref{Missing strtoul or bsearch}, for more information on
15312 this problem,
15313 which occurs only in releases of @code{g77}
15314 based on @code{gcc}.
15315 (It does not occur in @code{egcs}.)
15316
15317 On AIX 4.1, @code{g77} might not build with the native (non-GNU) tools
15318 due to a linker bug in coping with the @samp{-bbigtoc} option which
15319 leads to a @samp{Relocation overflow} error.  The GNU linker is not
15320 recommended on current AIX versions, though; it was developed under a
15321 now-unsupported version.  This bug is said to be fixed by `update PTF
15322 U455193 for APAR IX75823'.
15323
15324 Compiling with @samp{-mminimal-toc}
15325 might solve this problem, e.g.@: by adding
15326 @smallexample
15327 BOOT_CFLAGS='-mminimal-toc -O2 -g'
15328 @end smallexample
15329 to the @code{make bootstrap} command line.
15330 @end ifset
15331
15332 @node Index
15333 @unnumbered Index
15334
15335 @printindex cp
15336 @summarycontents
15337 @contents
15338 @bye