OSDN Git Service

clarify g77 bug-reporting docs
[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-02
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}.
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 The @code{Z} edit descriptor is supported.
6715 @item
6716 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6717 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
6718 specifier is supported.
6719 @end itemize
6720
6721 @node Fortran 90 Features
6722 @section Fortran 90 Features
6723 @cindex Fortran 90
6724 @cindex extensions, from Fortran 90
6725
6726 For convenience this section collects a list (probably incomplete) of
6727 the Fortran 90 features supported by the GNU Fortran language, even if
6728 they are documented elsewhere.
6729 @c makeinfo 1.68 objects to the nested parens
6730 @ifnotinfo
6731 @xref{Characters Lines Sequence,,{Characters, Lines, and Execution Sequence}},
6732 @end ifnotinfo
6733 @ifinfo
6734 @xref{Characters Lines Sequence},
6735 @end ifinfo
6736 for information on additional fixed source form lexical issues.  In
6737 addition, the free source form is supported through the
6738 @cindex @samp{-ffree-form}
6739 @samp{-ffree-form} option.  Other Fortran 90 features can be turned on
6740 by the
6741 @cindex @samp{-ff90}
6742 @samp{-ff90} option, @ref{Fortran 90}.  For information on the Fortran
6743 90 intrinsics available @ref{Table of Intrinsic Functions}.
6744
6745 @table @asis
6746 @item Automatic arrays in procedures
6747 @item Character assignments
6748 @cindex character assignments
6749 In character assignments, the variable being assigned may occur on the
6750 right hand side of the assignment.
6751 @item Character strings
6752 @cindex double quoted character constants
6753 Strings may have zero length and substrings of character constants are
6754 permitted.  Character constants may be enclosed in double quotes
6755 (@code{"}) as well as single quotes.  @xref{Character Type}.
6756 @item Construct names
6757 (Symbolic tags on blocks.)  @xref{Construct Names }.
6758 @item @code{CYCLE} and @code{EXIT}
6759 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
6760 @item @code{DOUBLE COMPLEX}
6761 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement
6762 }.
6763 @item @code{DO WHILE}
6764 @xref{DO WHILE}.
6765 @item @code{END} decoration
6766 @xref{Statements}.
6767 @item @code{END DO}
6768 @xref{END DO}.
6769 @item @code{KIND}
6770 @item @code{IMPLICIT NONE}
6771 @item @code{INCLUDE} statements
6772 @xref{INCLUDE}.
6773 @item List-directed and namelist I/O on internal files
6774 @item Binary, octal and hexadecimal constants
6775 These are supported more generally than required by Fortran 90.
6776 @xref{Integer Type}.
6777 @item @code{NAMELIST}
6778 @xref{NAMELIST}.
6779 @item @code{OPEN} specifiers
6780 @code{STATUS='REPLACE'} is supported.
6781 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6782 @code{STATUS='SCRATCH'} is supplied.
6783 @item @code{FORMAT} edit descriptors
6784 @cindex FORMAT descriptors
6785 @cindex Z edit descriptor
6786 @cindex edit descriptor, Z
6787 The @code{Z} edit descriptor is supported.
6788 @item Relational operators
6789 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
6790 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
6791 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
6792 @item @code{SELECT CASE}
6793 Not fully implemented.  @xref{SELECT CASE on CHARACTER Type,,
6794 @code{SELECT CASE} on @code{CHARACTER} Type}.
6795 @item Specification statements
6796 A limited subset of the Fortran 90 syntax and semantics for variable
6797 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
6798 (@code{KIND} is of limited usefulness in the absence of the
6799 @code{KIND}-related intrinsics, since these intrinsics permit writing
6800 more widely portable code.)  An example of supported @code{KIND} usage
6801 is:
6802 @smallexample
6803 INTEGER (KIND=1) :: FOO=1, BAR=2
6804 CHARACTER (LEN=3) FOO
6805 @end smallexample
6806 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
6807 @end table
6808
6809 @node Other Dialects
6810 @chapter Other Dialects
6811
6812 GNU Fortran supports a variety of features that are not
6813 considered part of the GNU Fortran language itself, but
6814 are representative of various dialects of Fortran that
6815 @code{g77} supports in whole or in part.
6816
6817 Any of the features listed below might be disallowed by
6818 @code{g77} unless some command-line option is specified.
6819 Currently, some of the features are accepted using the
6820 default invocation of @code{g77}, but that might change
6821 in the future.
6822
6823 @emph{Note: This portion of the documentation definitely needs a lot
6824 of work!}
6825
6826 @menu
6827 * Source Form::       Details of fixed-form and free-form source.
6828 * Trailing Comment::  Use of @samp{/*} to start a comment.
6829 * Debug Line::        Use of @samp{D} in column 1.
6830 * Dollar Signs::      Use of @samp{$} in symbolic names.
6831 * Case Sensitivity::  Uppercase and lowercase in source files.
6832 * VXT Fortran::       @dots{}versus the GNU Fortran language.
6833 * Fortran 90::        @dots{}versus the GNU Fortran language.
6834 * Pedantic Compilation::  Enforcing the standard.
6835 * Distensions::       Misfeatures supported by GNU Fortran.
6836 @end menu
6837
6838 @node Source Form
6839 @section Source Form
6840 @cindex source file format
6841 @cindex source format
6842 @cindex file, source
6843 @cindex source code
6844 @cindex code, source
6845 @cindex fixed form
6846 @cindex free form
6847
6848 GNU Fortran accepts programs written in either fixed form or
6849 free form.
6850
6851 Fixed form
6852 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
6853 allowing tabs) and Fortran 90's fixed form.
6854
6855 Free form corresponds to
6856 Fortran 90's free form (though possibly not entirely up-to-date, and
6857 without complaining about some things that for which Fortran 90 requires
6858 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
6859
6860 The way a Fortran compiler views source files depends entirely on the
6861 implementation choices made for the compiler, since those choices
6862 are explicitly left to the implementation by the published Fortran
6863 standards.
6864 GNU Fortran currently tries to be somewhat like a few popular compilers
6865 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
6866 definition along with more
6867 flexibility offered by command-line options is likely to be offered
6868 in version 0.6.
6869
6870 This section describes how @code{g77} interprets source lines.
6871
6872 @menu
6873 * Carriage Returns::  Carriage returns ignored.
6874 * Tabs::              Tabs converted to spaces.
6875 * Short Lines::       Short lines padded with spaces (fixed-form only).
6876 * Long Lines::        Long lines truncated.
6877 * Ampersands::        Special Continuation Lines.
6878 @end menu
6879
6880 @node Carriage Returns
6881 @subsection Carriage Returns
6882 @cindex carriage returns
6883
6884 Carriage returns (@samp{\r}) in source lines are ignored.
6885 This is somewhat different from @code{f2c}, which seems to treat them as
6886 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
6887 inside such constants.
6888
6889 @node Tabs
6890 @subsection Tabs
6891 @cindex tab character
6892 @cindex horizontal tab
6893
6894 A source line with a @key{TAB} character anywhere in it is treated as
6895 entirely significant---however long it is---instead of ending in
6896 column 72 (for fixed-form source) or 132 (for free-form source).
6897 This also is different from @code{f2c}, which encodes tabs as
6898 @samp{\t} (the ASCII @key{TAB} character) inside character
6899 and Hollerith constants, but nevertheless seems to treat the column
6900 position as if it had been affected by the canonical tab positioning.
6901
6902 @code{g77} effectively
6903 translates tabs to the appropriate number of spaces (a la the default
6904 for the UNIX @code{expand} command) before doing any other processing, other
6905 than (currently) noting whether a tab was found on a line and using this
6906 information to decide how to interpret the length of the line and continued
6907 constants.
6908
6909 Note that this default behavior probably will change for version 0.6,
6910 when it will presumably be available via a command-line option.
6911 The default as of version 0.6 is planned to be a ``pure visual''
6912 model, where tabs are immediately
6913 converted to spaces and otherwise have no effect, so the way a typical
6914 user sees source lines produces a consistent result no matter how the
6915 spacing in those source lines is actually implemented via tabs, spaces,
6916 and trailing tabs/spaces before newline.
6917 Command-line options are likely to be added to specify whether all or
6918 just-tabbed lines are to be extended to 132 or full input-line length,
6919 and perhaps even an option will be added to specify the truncated-line
6920 behavior to which some Digital compilers default (and which affects
6921 the way continued character/Hollerith constants are interpreted).
6922
6923 @node Short Lines
6924 @subsection Short Lines
6925 @cindex short source lines
6926 @cindex space, padding with
6927 @cindex source lines, short
6928 @cindex lines, short
6929
6930 Source lines shorter than the applicable fixed-form length are treated as
6931 if they were padded with spaces to that length.
6932 (None of this is relevant to source files written in free form.)
6933
6934 This affects only
6935 continued character and Hollerith constants, and is a different
6936 interpretation than provided by some other popular compilers
6937 (although a bit more consistent with the traditional punched-card
6938 basis of Fortran and the way the Fortran standard expressed fixed
6939 source form).
6940
6941 @code{g77} might someday offer an option to warn about cases where differences
6942 might be seen as a result of this treatment, and perhaps an option to
6943 specify the alternate behavior as well.
6944
6945 Note that this padding cannot apply to lines that are effectively of
6946 infinite length---such lines are specified using command-line options
6947 like @samp{-ffixed-line-length-none}, for example.
6948
6949 @node Long Lines
6950 @subsection Long Lines
6951 @cindex long source lines
6952 @cindex truncation, of long lines
6953 @cindex lines, long
6954 @cindex source lines, long
6955
6956 Source lines longer than the applicable length are truncated to that
6957 length.
6958 Currently, @code{g77} does not warn if the truncated characters are
6959 not spaces, to accommodate existing code written for systems that
6960 treated truncated text as commentary (especially in columns 73 through 80).
6961
6962 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
6963 for information on the @samp{-ffixed-line-length-@var{n}} option,
6964 which can be used to set the line length applicable to fixed-form
6965 source files.
6966
6967 @node Ampersands
6968 @subsection Ampersand Continuation Line
6969 @cindex ampersand continuation line
6970 @cindex continuation line, ampersand
6971
6972 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
6973 continuation line, imitating the behavior of @code{f2c}.
6974
6975 @node Trailing Comment
6976 @section Trailing Comment
6977
6978 @cindex trailing comment
6979 @cindex comment
6980 @cindex characters, comment
6981 @cindex /*
6982 @cindex !
6983 @cindex exclamation point
6984 @code{g77} supports use of @samp{/*} to start a trailing
6985 comment.
6986 In the GNU Fortran language, @samp{!} is used for this purpose.
6987
6988 @samp{/*} is not in the GNU Fortran language
6989 because the use of @samp{/*} in a program might
6990 suggest to some readers that a block, not trailing, comment is
6991 started (and thus ended by @samp{*/}, not end of line),
6992 since that is the meaning of @samp{/*} in C.
6993
6994 Also, such readers might think they can use @samp{//} to start
6995 a trailing comment as an alternative to @samp{/*}, but
6996 @samp{//} already denotes concatenation, and such a ``comment''
6997 might actually result in a program that compiles without
6998 error (though it would likely behave incorrectly).
6999
7000 @node Debug Line
7001 @section Debug Line
7002 @cindex debug line
7003 @cindex comment line, debug
7004
7005 Use of @samp{D} or @samp{d} as the first character (column 1) of
7006 a source line denotes a debug line.
7007
7008 In turn, a debug line is treated as either a comment line
7009 or a normal line, depending on whether debug lines are enabled.
7010
7011 When treated as a comment line, a line beginning with @samp{D} or
7012 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
7013 When treated as a normal line, such a line is treated as if
7014 the first character was @key{SPC} (space).
7015
7016 (Currently, @code{g77} provides no means for treating debug
7017 lines as normal lines.)
7018
7019 @node Dollar Signs
7020 @section Dollar Signs in Symbol Names
7021 @cindex dollar sign
7022 @cindex $
7023
7024 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
7025 when the @samp{-fdollar-ok} option is specified.
7026
7027 @node Case Sensitivity
7028 @section Case Sensitivity
7029 @cindex case sensitivity
7030 @cindex source file format
7031 @cindex code, source
7032 @cindex source code
7033 @cindex uppercase letters
7034 @cindex lowercase letters
7035 @cindex letters, uppercase
7036 @cindex letters, lowercase
7037
7038 GNU Fortran offers the programmer way too much flexibility in deciding
7039 how source files are to be treated vis-a-vis uppercase and lowercase
7040 characters.
7041 There are 66 useful settings that affect case sensitivity, plus 10
7042 settings that are nearly useless, with the remaining 116 settings
7043 being either redundant or useless.
7044
7045 None of these settings have any effect on the contents of comments
7046 (the text after a @samp{c} or @samp{C} in Column 1, for example)
7047 or of character or Hollerith constants.
7048 Note that things like the @samp{E} in the statement
7049 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
7050 are considered built-in keywords, and so are affected by
7051 these settings.
7052
7053 Low-level switches are identified in this section as follows:
7054
7055 @itemize @w{}
7056 @item A
7057 Source Case Conversion:
7058
7059 @itemize @w{}
7060 @item 0
7061 Preserve (see Note 1)
7062 @item 1
7063 Convert to Upper Case
7064 @item 2
7065 Convert to Lower Case
7066 @end itemize
7067
7068 @item B
7069 Built-in Keyword Matching:
7070
7071 @itemize @w{}
7072 @item 0
7073 Match Any Case (per-character basis)
7074 @item 1
7075 Match Upper Case Only
7076 @item 2
7077 Match Lower Case Only
7078 @item 3
7079 Match InitialCaps Only (see tables for spellings)
7080 @end itemize
7081
7082 @item C
7083 Built-in Intrinsic Matching:
7084
7085 @itemize @w{}
7086 @item 0
7087 Match Any Case (per-character basis)
7088 @item 1
7089 Match Upper Case Only
7090 @item 2
7091 Match Lower Case Only
7092 @item 3
7093 Match InitialCaps Only (see tables for spellings)
7094 @end itemize
7095
7096 @item D
7097 User-defined Symbol Possibilities (warnings only):
7098
7099 @itemize @w{}
7100 @item 0
7101 Allow Any Case (per-character basis)
7102 @item 1
7103 Allow Upper Case Only
7104 @item 2
7105 Allow Lower Case Only
7106 @item 3
7107 Allow InitialCaps Only (see Note 2)
7108 @end itemize
7109 @end itemize
7110
7111 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
7112 consistent with these source switches---in the sense that input will be
7113 expected to meet the same requirements as source code in terms
7114 of matching symbol names and keywords (for the exponent letters).
7115
7116 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
7117 which uppercases @code{NAMELIST} input and symbol names for matching.
7118 This means not only that @code{NAMELIST} output currently shows symbol
7119 (and keyword) names in uppercase even if lower-case source
7120 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
7121 adequately supported when source case preservation (option A0)
7122 is selected.
7123
7124 If A0 is selected, a warning message will be
7125 output for each @code{NAMELIST} statement to this effect.
7126 The behavior
7127 of the program is undefined at run time if two or more symbol names
7128 appear in a given @code{NAMELIST} such that the names are identical
7129 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
7130 For complete and total elegance, perhaps there should be a warning
7131 when option A2 is selected, since the output of NAMELIST is currently
7132 in uppercase but will someday be lowercase (when a @code{libg77} is written),
7133 but that seems to be overkill for a product in beta test.
7134
7135 Note 2: Rules for InitialCaps names are:
7136
7137 @itemize --
7138 @item
7139 Must be a single uppercase letter, @strong{or}
7140 @item
7141 Must start with an uppercase letter and contain at least one
7142 lowercase letter.
7143 @end itemize
7144
7145 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
7146 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
7147 not.
7148 Note that most, but not all, built-in names meet these
7149 requirements---the exceptions are some of the two-letter format
7150 specifiers, such as @samp{BN} and @samp{BZ}.
7151
7152 Here are the names of the corresponding command-line options:
7153
7154 @smallexample
7155 A0: -fsource-case-preserve
7156 A1: -fsource-case-upper
7157 A2: -fsource-case-lower
7158
7159 B0: -fmatch-case-any
7160 B1: -fmatch-case-upper
7161 B2: -fmatch-case-lower
7162 B3: -fmatch-case-initcap
7163
7164 C0: -fintrin-case-any
7165 C1: -fintrin-case-upper
7166 C2: -fintrin-case-lower
7167 C3: -fintrin-case-initcap
7168
7169 D0: -fsymbol-case-any
7170 D1: -fsymbol-case-upper
7171 D2: -fsymbol-case-lower
7172 D3: -fsymbol-case-initcap
7173 @end smallexample
7174
7175 Useful combinations of the above settings, along with abbreviated
7176 option names that set some of these combinations all at once:
7177
7178 @smallexample
7179  1: A0--  B0---  C0---  D0---    -fcase-preserve
7180  2: A0--  B0---  C0---  D-1--
7181  3: A0--  B0---  C0---  D--2-
7182  4: A0--  B0---  C0---  D---3
7183  5: A0--  B0---  C-1--  D0---
7184  6: A0--  B0---  C-1--  D-1--
7185  7: A0--  B0---  C-1--  D--2-
7186  8: A0--  B0---  C-1--  D---3
7187  9: A0--  B0---  C--2-  D0---
7188 10: A0--  B0---  C--2-  D-1--
7189 11: A0--  B0---  C--2-  D--2-
7190 12: A0--  B0---  C--2-  D---3
7191 13: A0--  B0---  C---3  D0---
7192 14: A0--  B0---  C---3  D-1--
7193 15: A0--  B0---  C---3  D--2-
7194 16: A0--  B0---  C---3  D---3
7195 17: A0--  B-1--  C0---  D0---
7196 18: A0--  B-1--  C0---  D-1--
7197 19: A0--  B-1--  C0---  D--2-
7198 20: A0--  B-1--  C0---  D---3
7199 21: A0--  B-1--  C-1--  D0---
7200 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
7201 23: A0--  B-1--  C-1--  D--2-
7202 24: A0--  B-1--  C-1--  D---3
7203 25: A0--  B-1--  C--2-  D0---
7204 26: A0--  B-1--  C--2-  D-1--
7205 27: A0--  B-1--  C--2-  D--2-
7206 28: A0--  B-1--  C--2-  D---3
7207 29: A0--  B-1--  C---3  D0---
7208 30: A0--  B-1--  C---3  D-1--
7209 31: A0--  B-1--  C---3  D--2-
7210 32: A0--  B-1--  C---3  D---3
7211 33: A0--  B--2-  C0---  D0---
7212 34: A0--  B--2-  C0---  D-1--
7213 35: A0--  B--2-  C0---  D--2-
7214 36: A0--  B--2-  C0---  D---3
7215 37: A0--  B--2-  C-1--  D0---
7216 38: A0--  B--2-  C-1--  D-1--
7217 39: A0--  B--2-  C-1--  D--2-
7218 40: A0--  B--2-  C-1--  D---3
7219 41: A0--  B--2-  C--2-  D0---
7220 42: A0--  B--2-  C--2-  D-1--
7221 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
7222 44: A0--  B--2-  C--2-  D---3
7223 45: A0--  B--2-  C---3  D0---
7224 46: A0--  B--2-  C---3  D-1--
7225 47: A0--  B--2-  C---3  D--2-
7226 48: A0--  B--2-  C---3  D---3
7227 49: A0--  B---3  C0---  D0---
7228 50: A0--  B---3  C0---  D-1--
7229 51: A0--  B---3  C0---  D--2-
7230 52: A0--  B---3  C0---  D---3
7231 53: A0--  B---3  C-1--  D0---
7232 54: A0--  B---3  C-1--  D-1--
7233 55: A0--  B---3  C-1--  D--2-
7234 56: A0--  B---3  C-1--  D---3
7235 57: A0--  B---3  C--2-  D0---
7236 58: A0--  B---3  C--2-  D-1--
7237 59: A0--  B---3  C--2-  D--2-
7238 60: A0--  B---3  C--2-  D---3
7239 61: A0--  B---3  C---3  D0---
7240 62: A0--  B---3  C---3  D-1--
7241 63: A0--  B---3  C---3  D--2-
7242 64: A0--  B---3  C---3  D---3    -fcase-initcap
7243 65: A-1-  B01--  C01--  D01--    -fcase-upper
7244 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
7245 @end smallexample
7246
7247 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
7248 (except comments, character constants, and Hollerith strings) must
7249 be entered in uppercase.
7250 Use @samp{-fcase-strict-upper} to specify this
7251 combination.
7252
7253 Number 43 is like Number 22 except all input must be lowercase.  Use
7254 @samp{-fcase-strict-lower} to specify this combination.
7255
7256 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
7257 non-UNIX machines whereby all the source is translated to uppercase.
7258 Use @samp{-fcase-upper} to specify this combination.
7259
7260 Number 66 is the ``canonical'' UNIX model whereby all the source is
7261 translated to lowercase.
7262 Use @samp{-fcase-lower} to specify this combination.
7263
7264 There are a few nearly useless combinations:
7265
7266 @smallexample
7267 67: A-1-  B01--  C01--  D--2-
7268 68: A-1-  B01--  C01--  D---3
7269 69: A-1-  B01--  C--23  D01--
7270 70: A-1-  B01--  C--23  D--2-
7271 71: A-1-  B01--  C--23  D---3
7272 72: A--2  B01--  C0-2-  D-1--
7273 73: A--2  B01--  C0-2-  D---3
7274 74: A--2  B01--  C-1-3  D0-2-
7275 75: A--2  B01--  C-1-3  D-1--
7276 76: A--2  B01--  C-1-3  D---3
7277 @end smallexample
7278
7279 The above allow some programs to be compiled but with restrictions that
7280 make most useful programs impossible: Numbers 67 and 72 warn about
7281 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
7282 Numbers
7283 68 and 73 warn about any user-defined symbol names longer than one
7284 character that don't have at least one non-alphabetic character after
7285 the first;
7286 Numbers 69 and 74 disallow any references to intrinsics;
7287 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
7288 67+69, 68+69, 72+74, and 73+74, respectively.
7289
7290 All redundant combinations are shown in the above tables anyplace
7291 where more than one setting is shown for a low-level switch.
7292 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
7293 The ``proper'' setting in such a case is the one that copies the setting
7294 of switch A---any other setting might slightly reduce the speed of
7295 the compiler, though possibly to an unmeasurable extent.
7296
7297 All remaining combinations are useless in that they prevent successful
7298 compilation of non-null source files (source files with something other
7299 than comments).
7300
7301 @node VXT Fortran
7302 @section VXT Fortran
7303
7304 @cindex VXT extensions
7305 @cindex extensions, VXT
7306 @code{g77} supports certain constructs that
7307 have different meanings in VXT Fortran than they
7308 do in the GNU Fortran language.
7309
7310 Generally, this manual uses the invented term VXT Fortran to refer
7311 VAX FORTRAN (circa v4).
7312 That compiler offered many popular features, though not necessarily
7313 those that are specific to the VAX processor architecture,
7314 the VMS operating system,
7315 or Digital Equipment Corporation's Fortran product line.
7316 (VAX and VMS probably are trademarks of Digital Equipment
7317 Corporation.)
7318
7319 An extension offered by a Digital Fortran product that also is
7320 offered by several other Fortran products for different kinds of
7321 systems is probably going to be considered for inclusion in @code{g77}
7322 someday, and is considered a VXT Fortran feature.
7323
7324 The @samp{-fvxt} option generally specifies that, where
7325 the meaning of a construct is ambiguous (means one thing
7326 in GNU Fortran and another in VXT Fortran), the VXT Fortran
7327 meaning is to be assumed.
7328
7329 @menu
7330 * Double Quote Meaning::  @samp{"2000} as octal constant.
7331 * Exclamation Point::     @samp{!} in column 6.
7332 @end menu
7333
7334 @node Double Quote Meaning
7335 @subsection Meaning of Double Quote
7336 @cindex double quotes
7337 @cindex character constants
7338 @cindex constants, character
7339 @cindex octal constants
7340 @cindex constants, octal
7341
7342 @code{g77} treats double-quote (@samp{"})
7343 as beginning an octal constant of @code{INTEGER(KIND=1)} type
7344 when the @code{-fvxt} option is specified.
7345 The form of this octal constant is
7346
7347 @example
7348 "@var{octal-digits}
7349 @end example
7350
7351 @noindent
7352 where @var{octal-digits} is a nonempty string of characters in
7353 the set @samp{01234567}.
7354
7355 For example, the @code{-fvxt} option permits this:
7356
7357 @example
7358 PRINT *, "20
7359 END
7360 @end example
7361
7362 @noindent
7363 The above program would print the value @samp{16}.
7364
7365 @xref{Integer Type}, for information on the preferred construct
7366 for integer constants specified using GNU Fortran's octal notation.
7367
7368 (In the GNU Fortran language, the double-quote character (@samp{"})
7369 delimits a character constant just as does apostrophe (@samp{'}).
7370 There is no way to allow
7371 both constructs in the general case, since statements like
7372 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
7373
7374 @node Exclamation Point
7375 @subsection Meaning of Exclamation Point in Column 6
7376 @cindex !
7377 @cindex exclamation point
7378 @cindex continuation character
7379 @cindex characters, continuation
7380 @cindex comment character
7381 @cindex characters, comment
7382
7383 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
7384 a fixed-form source file
7385 as a continuation character rather than
7386 as the beginning of a comment
7387 (as it does in any other column)
7388 when the @code{-fvxt} option is specified.
7389
7390 The following program, when run, prints a message indicating
7391 whether it is interpreted according to GNU Fortran (and Fortran 90)
7392 rules or VXT Fortran rules:
7393
7394 @smallexample
7395 C234567  (This line begins in column 1.)
7396       I = 0
7397      !1
7398       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
7399       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
7400       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
7401       END
7402 @end smallexample
7403
7404 (In the GNU Fortran and Fortran 90 languages, exclamation point is
7405 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
7406 marks a line as a continuation line when it appears in column 6.)
7407
7408 @node Fortran 90
7409 @section Fortran 90
7410 @cindex compatibility, Fortran 90
7411 @cindex Fortran 90, compatibility
7412
7413 The GNU Fortran language includes a number of features that are
7414 part of Fortran 90, even when the @samp{-ff90} option is not specified.
7415 The features enabled by @samp{-ff90} are intended to be those that,
7416 when @samp{-ff90} is not specified, would have another
7417 meaning to @code{g77}---usually meaning something invalid in the
7418 GNU Fortran language.
7419
7420 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
7421 to gratuitously reject Fortran 90 constructs.
7422 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
7423 to do that, although its implementation is certainly incomplete at
7424 this point.
7425
7426 When @samp{-ff90} is specified:
7427
7428 @itemize @bullet
7429 @item
7430 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
7431 where @var{expr} is @code{COMPLEX} type,
7432 is the same type as the real part of @var{expr}.
7433
7434 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
7435 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
7436 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
7437 @end itemize
7438
7439 @node Pedantic Compilation
7440 @section Pedantic Compilation
7441 @cindex pedantic compilation
7442 @cindex compilation, pedantic
7443
7444 The @samp{-fpedantic} command-line option specifies that @code{g77}
7445 is to warn about code that is not standard-conforming.
7446 This is useful for finding
7447 some extensions @code{g77} accepts that other compilers might not accept.
7448 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
7449 always imply @samp{-fpedantic}.)
7450
7451 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
7452 for conforming code.
7453 With @samp{-ff90} in force, Fortran 90 is used.
7454
7455 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
7456 and @samp{-fno-f90} are in force are:
7457
7458 @itemize @bullet
7459 @item
7460 Automatic arrays, as in
7461
7462 @example
7463 SUBROUTINE X(N)
7464 REAL A(N)
7465 @dots{}
7466 @end example
7467
7468 @noindent
7469 where @samp{A} is not listed in any @code{ENTRY} statement,
7470 and thus is not a dummy argument.
7471
7472 @item
7473 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
7474
7475 These commas are disallowed by FORTRAN 77, but, while strictly
7476 superfluous, are syntactically elegant,
7477 especially given that commas are required in statements such
7478 as @samp{READ 99, I} and @samp{PRINT *, J}.
7479 Many compilers permit the superfluous commas for this reason.
7480
7481 @item
7482 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
7483
7484 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
7485 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
7486
7487 An example of an implicit use is the expression @samp{C*D},
7488 where @samp{C} is @code{COMPLEX(KIND=1)}
7489 and @samp{D} is @code{DOUBLE PRECISION}.
7490 This expression is prohibited by ANSI FORTRAN 77
7491 because the rules of promotion would suggest that it
7492 produce a @code{DOUBLE COMPLEX} result---a type not
7493 provided for by that standard.
7494
7495 @item
7496 Automatic conversion of numeric
7497 expressions to @code{INTEGER(KIND=1)} in contexts such as:
7498
7499 @itemize --
7500 @item
7501 Array-reference indexes.
7502 @item
7503 Alternate-return values.
7504 @item
7505 Computed @code{GOTO}.
7506 @item
7507 @code{FORMAT} run-time expressions (not yet supported).
7508 @item
7509 Dimension lists in specification statements.
7510 @item
7511 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
7512 @item
7513 Sizes of @code{CHARACTER} entities in specification statements.
7514 @item
7515 Kind types in specification entities (a Fortran 90 feature).
7516 @item
7517 Initial, terminal, and incrementation parameters for implied-@code{DO}
7518 constructs in @code{DATA} statements.
7519 @end itemize
7520
7521 @item
7522 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
7523 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
7524 expressions are disallowed anyway).
7525
7526 @item
7527 Zero-size array dimensions, as in:
7528
7529 @example
7530 INTEGER I(10,20,4:2)
7531 @end example
7532
7533 @item
7534 Zero-length @code{CHARACTER} entities, as in:
7535
7536 @example
7537 PRINT *, ''
7538 @end example
7539
7540 @item
7541 Substring operators applied to character constants and named
7542 constants, as in:
7543
7544 @example
7545 PRINT *, 'hello'(3:5)
7546 @end example
7547
7548 @item
7549 Null arguments passed to statement function, as in:
7550
7551 @example
7552 PRINT *, FOO(,3)
7553 @end example
7554
7555 @item
7556 Disagreement among program units regarding whether a given @code{COMMON}
7557 area is @code{SAVE}d (for targets where program units in a single source
7558 file are ``glued'' together as they typically are for UNIX development
7559 environments).
7560
7561 @item
7562 Disagreement among program units regarding the size of a
7563 named @code{COMMON} block.
7564
7565 @item
7566 Specification statements following first @code{DATA} statement.
7567
7568 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
7569 but not @samp{INTEGER I}.
7570 The @samp{-fpedantic} option disallows both of these.)
7571
7572 @item
7573 Semicolon as statement separator, as in:
7574
7575 @example
7576 CALL FOO; CALL BAR
7577 @end example
7578 @c
7579 @c @item
7580 @c Comma before list of I/O items in @code{WRITE}
7581 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
7582 @c statements, as with @code{READ} (as explained above).
7583
7584 @item
7585 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
7586
7587 @item
7588 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
7589 versa.
7590
7591 @item
7592 Expressions having two arithmetic operators in a row, such
7593 as @samp{X*-Y}.
7594 @end itemize
7595
7596 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
7597 following constructs result in diagnostics:
7598
7599 @itemize @bullet
7600 @item
7601 Use of semicolon as a statement separator on a line
7602 that has an @code{INCLUDE} directive.
7603 @end itemize
7604
7605 @node Distensions
7606 @section Distensions
7607 @cindex distensions
7608 @cindex ugly features
7609 @cindex features, ugly
7610
7611 The @samp{-fugly-*} command-line options determine whether certain
7612 features supported by VAX FORTRAN and other such compilers, but considered
7613 too ugly to be in code that can be changed to use safer and/or more
7614 portable constructs, are accepted.
7615 These are humorously referred to as ``distensions'',
7616 extensions that just plain look ugly in the harsh light of day.
7617
7618 @emph{Note:} The @samp{-fugly} option, which currently serves
7619 as shorthand to enable all of the distensions below, is likely to
7620 be removed in a future version of @code{g77}.
7621 That's because it's likely new distensions will be added that
7622 conflict with existing ones in terms of assigning meaning to
7623 a given chunk of code.
7624 (Also, it's pretty clear that users should not use @samp{-fugly}
7625 as shorthand when the next release of @code{g77} might add a
7626 distension to that that causes their existing code, when recompiled,
7627 to behave differently---perhaps even fail to compile or run
7628 correctly.)
7629
7630 @menu
7631 * Ugly Implicit Argument Conversion::  Disabled via @samp{-fno-ugly-args}.
7632 * Ugly Assumed-Size Arrays::           Enabled via @samp{-fugly-assumed}.
7633 * Ugly Null Arguments::                Enabled via @samp{-fugly-comma}.
7634 * Ugly Complex Part Extraction::       Enabled via @samp{-fugly-complex}.
7635 * Ugly Conversion of Initializers::    Disabled via @samp{-fno-ugly-init}.
7636 * Ugly Integer Conversions::           Enabled via @samp{-fugly-logint}.
7637 * Ugly Assigned Labels::               Enabled via @samp{-fugly-assign}.
7638 @end menu
7639
7640 @node Ugly Implicit Argument Conversion
7641 @subsection Implicit Argument Conversion
7642 @cindex Hollerith constants
7643 @cindex constants, Hollerith
7644
7645 The @samp{-fno-ugly-args} option disables
7646 passing typeless and Hollerith constants as actual arguments
7647 in procedure invocations.
7648 For example:
7649
7650 @example
7651 CALL FOO(4HABCD)
7652 CALL BAR('123'O)
7653 @end example
7654
7655 @noindent
7656 These constructs can be too easily used to create non-portable
7657 code, but are not considered as ``ugly'' as others.
7658 Further, they are widely used in existing Fortran source code
7659 in ways that often are quite portable.
7660 Therefore, they are enabled by default.
7661
7662 @node Ugly Assumed-Size Arrays
7663 @subsection Ugly Assumed-Size Arrays
7664 @cindex arrays, assumed-size
7665 @cindex assumed-size arrays
7666 @cindex DIMENSION X(1)
7667
7668 The @samp{-fugly-assumed} option enables
7669 the treatment of any array with a final dimension specified as @samp{1}
7670 as an assumed-size array, as if @samp{*} had been specified
7671 instead.
7672
7673 For example, @samp{DIMENSION X(1)} is treated as if it
7674 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
7675 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
7676 or @code{ENTRY} statement in the same program unit.
7677
7678 Use an explicit lower bound to avoid this interpretation.
7679 For example, @samp{DIMENSION X(1:1)} is never treated as if
7680 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
7681 Nor is @samp{DIMENSION X(2-1)} affected by this option,
7682 since that kind of expression is unlikely to have been
7683 intended to designate an assumed-size array.
7684
7685 This option is used to prevent warnings being issued about apparent
7686 out-of-bounds reference such as @samp{X(2) = 99}.
7687
7688 It also prevents the array from being used in contexts that
7689 disallow assumed-size arrays, such as @samp{PRINT *,X}.
7690 In such cases, a diagnostic is generated and the source file is
7691 not compiled.
7692
7693 The construct affected by this option is used only in old code
7694 that pre-exists the widespread acceptance of adjustable and assumed-size
7695 arrays in the Fortran community.
7696
7697 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
7698 treated if @samp{X} is listed as a dummy argument only
7699 @emph{after} the @code{DIMENSION} statement (presumably in
7700 an @code{ENTRY} statement).
7701 For example, @samp{-fugly-assumed} has no effect on the
7702 following program unit:
7703
7704 @example
7705 SUBROUTINE X
7706 REAL A(1)
7707 RETURN
7708 ENTRY Y(A)
7709 PRINT *, A
7710 END
7711 @end example
7712
7713 @node Ugly Complex Part Extraction
7714 @subsection Ugly Complex Part Extraction
7715 @cindex complex values
7716 @cindex real part
7717 @cindex imaginary part
7718
7719 The @samp{-fugly-complex} option enables
7720 use of the @code{REAL()} and @code{AIMAG()}
7721 intrinsics with arguments that are
7722 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
7723
7724 With @samp{-ff90} in effect, these intrinsics return
7725 the unconverted real and imaginary parts (respectively)
7726 of their argument.
7727
7728 With @samp{-fno-f90} in effect, these intrinsics convert
7729 the real and imaginary parts to @code{REAL(KIND=1)}, and return
7730 the result of that conversion.
7731
7732 Due to this ambiguity, the GNU Fortran language defines
7733 these constructs as invalid, except in the specific
7734 case where they are entirely and solely passed as an
7735 argument to an invocation of the @code{REAL()} intrinsic.
7736 For example,
7737
7738 @example
7739 REAL(REAL(Z))
7740 @end example
7741
7742 @noindent
7743 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
7744 and @samp{-fno-ugly-complex} is in effect, because the
7745 meaning is clear.
7746
7747 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
7748 is specified, in which case the appropriate interpretation is
7749 chosen and no diagnostic is issued.
7750
7751 @xref{CMPAMBIG}, for information on how to cope with existing
7752 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
7753 with @code{COMPLEX(KIND=2)} arguments.
7754
7755 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
7756 intrinsic, used to extract the real part of a complex expression
7757 without conversion.
7758 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
7759 intrinsic, used to extract the imaginary part of a complex expression
7760 without conversion.
7761
7762 @node Ugly Null Arguments
7763 @subsection Ugly Null Arguments
7764 @cindex trailing comma
7765 @cindex comma, trailing
7766 @cindex characters, comma
7767 @cindex null arguments
7768 @cindex arguments, null
7769
7770 The @samp{-fugly-comma} option enables use of a single trailing comma
7771 to mean ``pass an extra trailing null argument''
7772 in a list of actual arguments to an external procedure,
7773 and use of an empty list of arguments to such a procedure
7774 to mean ``pass a single null argument''.
7775
7776 @cindex omitting arguments
7777 @cindex arguments, omitting
7778 (Null arguments often are used in some procedure-calling
7779 schemes to indicate omitted arguments.)
7780
7781 For example, @samp{CALL FOO(,)} means ``pass
7782 two null arguments'', rather than ``pass one null argument''.
7783 Also, @samp{CALL BAR()} means ``pass one null argument''.
7784
7785 This construct is considered ``ugly'' because it does not
7786 provide an elegant way to pass a single null argument
7787 that is syntactically distinct from passing no arguments.
7788 That is, this construct changes the meaning of code that
7789 makes no use of the construct.
7790
7791 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
7792 and @samp{I = JFUNC()} pass a single null argument, instead
7793 of passing no arguments as required by the Fortran 77 and
7794 90 standards.
7795
7796 @emph{Note:} Many systems gracefully allow the case
7797 where a procedure call passes one extra argument that the
7798 called procedure does not expect.
7799
7800 So, in practice, there might be no difference in
7801 the behavior of a program that does @samp{CALL FOO()}
7802 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
7803 in force as compared to its behavior when compiled
7804 with the default, @samp{-fno-ugly-comma}, in force,
7805 assuming @samp{FOO} and @samp{JFUNC} do not expect any
7806 arguments to be passed.
7807
7808 @node Ugly Conversion of Initializers
7809 @subsection Ugly Conversion of Initializers
7810
7811 The constructs disabled by @samp{-fno-ugly-init} are:
7812
7813 @itemize @bullet
7814 @cindex Hollerith constants
7815 @cindex constants, Hollerith
7816 @item
7817 Use of Hollerith and typeless constants in contexts where they set
7818 initial (compile-time) values for variables, arrays, and named
7819 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
7820 type-declaration statements specifying initial values.
7821
7822 Here are some sample initializations that are disabled by the
7823 @samp{-fno-ugly-init} option:
7824
7825 @example
7826 PARAMETER (VAL='9A304FFE'X)
7827 REAL*8 STRING/8HOUTPUT00/
7828 DATA VAR/4HABCD/
7829 @end example
7830
7831 @cindex character constants
7832 @cindex constants, character
7833 @item
7834 In the same contexts as above, use of character constants to initialize
7835 numeric items and vice versa (one constant per item).
7836
7837 Here are more sample initializations that are disabled by the
7838 @samp{-fno-ugly-init} option:
7839
7840 @example
7841 INTEGER IA
7842 CHARACTER BELL
7843 PARAMETER (IA = 'A')
7844 PARAMETER (BELL = 7)
7845 @end example
7846
7847 @item
7848 Use of Hollerith and typeless constants on the right-hand side
7849 of assignment statements to numeric types, and in other
7850 contexts (such as passing arguments in invocations of
7851 intrinsic procedures and statement functions) that
7852 are treated as assignments to known types (the dummy
7853 arguments, in these cases).
7854
7855 Here are sample statements that are disabled by the
7856 @samp{-fno-ugly-init} option:
7857
7858 @example
7859 IVAR = 4HABCD
7860 PRINT *, IMAX0(2HAB, 2HBA)
7861 @end example
7862 @end itemize
7863
7864 The above constructs, when used,
7865 can tend to result in non-portable code.
7866 But, they are widely used in existing Fortran code in ways
7867 that often are quite portable.
7868 Therefore, they are enabled by default.
7869
7870 @node Ugly Integer Conversions
7871 @subsection Ugly Integer Conversions
7872
7873 The constructs enabled via @samp{-fugly-logint} are:
7874
7875 @itemize @bullet
7876 @item
7877 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
7878 dictated by
7879 context (typically implies nonportable dependencies on how a
7880 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
7881
7882 @item
7883 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
7884 statements.
7885 @end itemize
7886
7887 The above constructs are disabled by default because use
7888 of them tends to lead to non-portable code.
7889 Even existing Fortran code that uses that often turns out
7890 to be non-portable, if not outright buggy.
7891
7892 Some of this is due to differences among implementations as
7893 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
7894 @code{INTEGER} values---Fortran code that assumes a particular
7895 coding is likely to use one of the above constructs, and is
7896 also likely to not work correctly on implementations using
7897 different encodings.
7898
7899 @xref{Equivalence Versus Equality}, for more information.
7900
7901 @node Ugly Assigned Labels
7902 @subsection Ugly Assigned Labels
7903 @cindex ASSIGN statement
7904 @cindex statements, ASSIGN
7905 @cindex assigned labels
7906 @cindex pointers
7907
7908 The @samp{-fugly-assign} option forces @code{g77} to use the
7909 same storage for assigned labels as it would for a normal
7910 assignment to the same variable.
7911
7912 For example, consider the following code fragment:
7913
7914 @example
7915 I = 3
7916 ASSIGN 10 TO I
7917 @end example
7918
7919 @noindent
7920 Normally, for portability and improved diagnostics, @code{g77}
7921 reserves distinct storage for a ``sibling'' of @samp{I}, used
7922 only for @code{ASSIGN} statements to that variable (along with
7923 the corresponding assigned-@code{GOTO} and assigned-@samp{FORMAT}-I/O
7924 statements that reference the variable).
7925
7926 However, some code (that violates the ANSI FORTRAN 77 standard)
7927 attempts to copy assigned labels among variables involved with
7928 @code{ASSIGN} statements, as in:
7929
7930 @example
7931 ASSIGN 10 TO I
7932 ISTATE(5) = I
7933 @dots{}
7934 J = ISTATE(ICUR)
7935 GOTO J
7936 @end example
7937
7938 @noindent
7939 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
7940 is specified on the command-line, ensuring that the value of @code{I}
7941 referenced in the second line is whatever value @code{g77} uses
7942 to designate statement label @samp{10}, so the value may be
7943 copied into the @samp{ISTATE} array, later retrieved into a
7944 variable of the appropriate type (@samp{J}), and used as the target of
7945 an assigned-@code{GOTO} statement.
7946
7947 @emph{Note:} To avoid subtle program bugs,
7948 when @samp{-fugly-assign} is specified,
7949 @code{g77} requires the type of variables
7950 specified in assigned-label contexts
7951 @emph{must} be the same type returned by @code{%LOC()}.
7952 On many systems, this type is effectively the same
7953 as @code{INTEGER(KIND=1)}, while, on others, it is
7954 effectively the same as @code{INTEGER(KIND=2)}.
7955
7956 Do @emph{not} depend on @code{g77} actually writing valid pointers
7957 to these variables, however.
7958 While @code{g77} currently chooses that implementation, it might
7959 be changed in the future.
7960
7961 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
7962 for implementation details on assigned-statement labels.
7963
7964 @node Compiler
7965 @chapter The GNU Fortran Compiler
7966
7967 The GNU Fortran compiler, @code{g77}, supports programs written
7968 in the GNU Fortran language and in some other dialects of Fortran.
7969
7970 Some aspects of how @code{g77} works are universal regardless
7971 of dialect, and yet are not properly part of the GNU Fortran
7972 language itself.
7973 These are described below.
7974
7975 @emph{Note: This portion of the documentation definitely needs a lot
7976 of work!}
7977
7978 @menu
7979 * Compiler Limits::
7980 * Run-time Environment Limits::
7981 * Compiler Types::
7982 * Compiler Constants::
7983 * Compiler Intrinsics::
7984 @end menu
7985
7986 @node Compiler Limits
7987 @section Compiler Limits
7988 @cindex limits, compiler
7989 @cindex compiler limits
7990
7991 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
7992 on lengths of identifiers, number of continuation lines, number of external
7993 symbols in a program, and so on.
7994
7995 @cindex options, -Nl
7996 @cindex -Nl option
7997 @cindex options, -Nx
7998 @cindex -Nx option
7999 @cindex limits, continuation lines
8000 @cindex limits, lengths of names
8001 For example, some other Fortran compiler have an option
8002 (such as @samp{-Nl@var{x}}) to increase the limit on the
8003 number of continuation lines.
8004 Also, some Fortran compilation systems have an option
8005 (such as @samp{-Nx@var{x}}) to increase the limit on the
8006 number of external symbols.
8007
8008 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
8009 no equivalent options, since they do not impose arbitrary
8010 limits in these areas.
8011
8012 @cindex rank, maximum
8013 @cindex maximum rank
8014 @cindex number of dimensions, maximum
8015 @cindex maximum number of dimensions
8016 @cindex limits, rank
8017 @cindex limits, array dimensions
8018 @code{g77} does currently limit the number of dimensions in an array
8019 to the same degree as do the Fortran standards---seven (7).
8020 This restriction might be lifted in a future version.
8021
8022 @node Run-time Environment Limits
8023 @section Run-time Environment Limits
8024 @cindex limits, run-time library
8025 @cindex wraparound
8026
8027 As a portable Fortran implementation,
8028 @code{g77} offers its users direct access to,
8029 and otherwise depends upon,
8030 the underlying facilities of the system
8031 used to build @code{g77},
8032 the system on which @code{g77} itself is used to compile programs,
8033 and the system on which the @code{g77}-compiled program is actually run.
8034 (For most users, the three systems are of the same
8035 type---combination of operating environment and hardware---often
8036 the same physical system.)
8037
8038 The run-time environment for a particular system
8039 inevitably imposes some limits on a program's use
8040 of various system facilities.
8041 These limits vary from system to system.
8042
8043 Even when such limits might be well beyond the
8044 possibility of being encountered on a particular system,
8045 the @code{g77} run-time environment
8046 has certain built-in limits,
8047 usually, but not always, stemming from intrinsics
8048 with inherently limited interfaces.
8049
8050 Currently, the @code{g77} run-time environment
8051 does not generally offer a less-limiting environment
8052 by augmenting the underlying system's own environment.
8053
8054 Therefore, code written in the GNU Fortran language,
8055 while syntactically and semantically portable,
8056 might nevertheless make non-portable assumptions
8057 about the run-time environment---assumptions that
8058 prove to be false for some particular environments.
8059
8060 The GNU Fortran language,
8061 the @code{g77} compiler and run-time environment,
8062 and the @code{g77} documentation
8063 do not yet offer comprehensive portable work-arounds for such limits,
8064 though programmers should be able to
8065 find their own in specific instances.
8066
8067 Not all of the limitations are described in this document.
8068 Some of the known limitations include:
8069
8070 @menu
8071 * Timer Wraparounds::
8072 * Year 2000 (Y2K) Problems::
8073 * Array Size::
8074 * Character-variable Length::
8075 * Year 10000 (Y10K) Problems::
8076 @end menu
8077
8078 @node Timer Wraparounds
8079 @subsection Timer Wraparounds
8080
8081 Intrinsics that return values computed from system timers,
8082 whether elapsed (wall-clock) timers,
8083 process CPU timers,
8084 or other kinds of timers,
8085 are prone to experiencing wrap-around errors
8086 (or returning wrapped-around values from successive calls)
8087 due to insufficient ranges
8088 offered by the underlying system's timers.
8089
8090 @cindex negative time
8091 @cindex short time
8092 @cindex long time
8093 Some of the symptoms of such behaviors include
8094 apparently negative time being computed for a duration,
8095 an extremely short amount of time being computed for a long duration,
8096 and an extremely long amount of time being computed for a short duration.
8097
8098 See the following for intrinsics
8099 known to have potential problems in these areas
8100 on at least some systems:
8101 @ref{CPU_Time Intrinsic},
8102 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
8103 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
8104 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
8105 @ref{Secnds Intrinsic},
8106 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
8107 @ref{System_Clock Intrinsic},
8108 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
8109 @ref{Time8 Intrinsic}.
8110
8111 @node Year 2000 (Y2K) Problems
8112 @subsection Year 2000 (Y2K) Problems
8113 @cindex Y2K compliance
8114 @cindex Year 2000 compliance
8115
8116 While the @code{g77} compiler itself is believed to
8117 be Year-2000 (Y2K) compliant,
8118 some intrinsics are not,
8119 and, potentially, some underlying systems are not,
8120 perhaps rendering some Y2K-compliant intrinsics
8121 non-compliant when used on those particular systems.
8122
8123 Fortran code that uses non-Y2K-compliant intrinsics
8124 (listed below)
8125 is, itself, almost certainly not compliant,
8126 and should be modified to use Y2K-compliant intrinsics instead.
8127
8128 Fortran code that uses no non-Y2K-compliant intrinsics,
8129 but which currently is running on a non-Y2K-compliant system,
8130 can be made more Y2K compliant by compiling and
8131 linking it for use on a new Y2K-compliant system,
8132 such as a new version of an old, non-Y2K-compliant, system.
8133
8134 Currently, information on Y2K and related issues
8135 is being maintained at
8136 @uref{http://www.gnu.org/software/year2000-list.html}.
8137
8138 See the following for intrinsics
8139 known to have potential problems in these areas
8140 on at least some systems:
8141 @ref{Date Intrinsic},
8142 @ref{IDate Intrinsic (VXT)}.
8143
8144 @node Array Size
8145 @subsection Array Size
8146 @cindex limits, array size
8147 @cindex array size
8148
8149 Currently, @code{g77} uses the default @code{INTEGER} type
8150 for array indexes,
8151 which limits the sizes of single-dimension arrays
8152 on systems offering a larger address space
8153 than can be addressed by that type.
8154 (That @code{g77} puts all arrays in memory
8155 could be considered another limitation---it
8156 could use large temporary files---but that decision
8157 is left to the programmer as an implementation choice
8158 by most Fortran implementations.)
8159
8160 @c ??? Investigate this, to offer a more clear statement
8161 @c than the following paragraphs do.  -- burley 1999-02-17
8162 It is not yet clear whether this limitation
8163 never, sometimes, or always applies to the
8164 sizes of multiple-dimension arrays as a whole.
8165
8166 For example, on a system with 64-bit addresses
8167 and 32-bit default @code{INTEGER},
8168 an array with a size greater than can be addressed
8169 by a 32-bit offset
8170 can be declared using multiple dimensions.
8171 Such an array is therefore larger
8172 than a single-dimension array can be,
8173 on the same system.
8174
8175 @cindex limits, multi-dimension arrays
8176 @cindex multi-dimension arrays
8177 @cindex arrays, dimensioning
8178 Whether large multiple-dimension arrays are reliably supported
8179 depends mostly on the @code{gcc} back end (code generator)
8180 used by @code{g77}, and has not yet been fully investigated.
8181
8182 @node Character-variable Length
8183 @subsection Character-variable Length
8184 @cindex limits, on character-variable length
8185 @cindex character-variable length
8186
8187 Currently, @code{g77} uses the default @code{INTEGER} type
8188 for the lengths of @code{CHARACTER} variables
8189 and array elements.
8190
8191 This means that, for example,
8192 a system with a 64-bit address space
8193 and a 32-bit default @code{INTEGER} type
8194 does not, under @code{g77},
8195 support a @code{CHARACTER*@var{n}} declaration
8196 where @var{n} is greater than 2147483647.
8197
8198 @node Year 10000 (Y10K) Problems
8199 @subsection Year 10000 (Y10K) Problems
8200 @cindex Y10K compliance
8201 @cindex Year 10000 compliance
8202
8203 Most intrinsics returning, or computing values based on,
8204 date information are prone to Year-10000 (Y10K) problems,
8205 due to supporting only 4 digits for the year.
8206
8207 See the following for examples:
8208 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
8209 @ref{IDate Intrinsic (UNIX)},
8210 @ref{Time Intrinsic (VXT)},
8211 @ref{Date_and_Time Intrinsic}.
8212
8213 @node Compiler Types
8214 @section Compiler Types
8215 @cindex types, of data
8216 @cindex data types
8217
8218 Fortran implementations have a fair amount of freedom given them by the
8219 standard as far as how much storage space is used and how much precision
8220 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
8221 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
8222 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
8223 Further, many compilers offer so-called @samp{*@var{n}} notation, but
8224 the interpretation of @var{n} varies across compilers and target architectures.
8225
8226 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
8227 and @code{REAL(KIND=1)}
8228 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
8229 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
8230 Further, it requires that @code{COMPLEX(KIND=1)}
8231 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
8232 storage-associated (such as via @code{EQUIVALENCE})
8233 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
8234 corresponds to the real element and @samp{R(2)} to the imaginary
8235 element of the @code{COMPLEX(KIND=1)} variable.
8236
8237 (Few requirements as to precision or ranges of any of these are
8238 placed on the implementation, nor is the relationship of storage sizes of
8239 these types to the @code{CHARACTER} type specified, by the standard.)
8240
8241 @code{g77} follows the above requirements, warning when compiling
8242 a program requires placement of items in memory that contradict the
8243 requirements of the target architecture.
8244 (For example, a program can require placement of a @code{REAL(KIND=2)}
8245 on a boundary that is not an even multiple of its size, but still an
8246 even multiple of the size of a @code{REAL(KIND=1)} variable.
8247 On some target architectures, using the canonical
8248 mapping of Fortran types to underlying architectural types, such
8249 placement is prohibited by the machine definition or
8250 the Application Binary Interface (ABI) in force for
8251 the configuration defined for building @code{gcc} and @code{g77}.
8252 @code{g77} warns about such
8253 situations when it encounters them.)
8254
8255 @code{g77} follows consistent rules for configuring the mapping between Fortran
8256 types, including the @samp{*@var{n}} notation, and the underlying architectural
8257 types as accessed by a similarly-configured applicable version of the
8258 @code{gcc} compiler.
8259 These rules offer a widely portable, consistent Fortran/C
8260 environment, although they might well conflict with the expectations of
8261 users of Fortran compilers designed and written for particular
8262 architectures.
8263
8264 These rules are based on the configuration that is in force for the
8265 version of @code{gcc} built in the same release as @code{g77} (and
8266 which was therefore used to build both the @code{g77} compiler
8267 components and the @code{libg2c} run-time library):
8268
8269 @table @code
8270 @cindex REAL(KIND=1) type
8271 @cindex types, REAL(KIND=1)
8272 @item REAL(KIND=1)
8273 Same as @code{float} type.
8274
8275 @cindex REAL(KIND=2) type
8276 @cindex types, REAL(KIND=2)
8277 @item REAL(KIND=2)
8278 Same as whatever floating-point type that is twice the size
8279 of a @code{float}---usually, this is a @code{double}.
8280
8281 @cindex INTEGER(KIND=1) type
8282 @cindex types, INTEGER(KIND=1)
8283 @item INTEGER(KIND=1)
8284 Same as an integral type that is occupies the same amount
8285 of memory storage as @code{float}---usually, this is either
8286 an @code{int} or a @code{long int}.
8287
8288 @cindex LOGICAL(KIND=1) type
8289 @cindex types, LOGICAL(KIND=1)
8290 @item LOGICAL(KIND=1)
8291 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
8292
8293 @cindex INTEGER(KIND=2) type
8294 @cindex types, INTEGER(KIND=2)
8295 @item INTEGER(KIND=2)
8296 Twice the size, and usually nearly twice the range,
8297 as @code{INTEGER(KIND=1)}---usually, this is either
8298 a @code{long int} or a @code{long long int}.
8299
8300 @cindex LOGICAL(KIND=2) type
8301 @cindex types, LOGICAL(KIND=2)
8302 @item LOGICAL(KIND=2)
8303 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
8304
8305 @cindex INTEGER(KIND=3) type
8306 @cindex types, INTEGER(KIND=3)
8307 @item INTEGER(KIND=3)
8308 Same @code{gcc} type as signed @code{char}.
8309
8310 @cindex LOGICAL(KIND=3) type
8311 @cindex types, LOGICAL(KIND=3)
8312 @item LOGICAL(KIND=3)
8313 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
8314
8315 @cindex INTEGER(KIND=6) type
8316 @cindex types, INTEGER(KIND=6)
8317 @item INTEGER(KIND=6)
8318 Twice the size, and usually nearly twice the range,
8319 as @code{INTEGER(KIND=3)}---usually, this is
8320 a @code{short}.
8321
8322 @cindex LOGICAL(KIND=6) type
8323 @cindex types, LOGICAL(KIND=6)
8324 @item LOGICAL(KIND=6)
8325 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
8326
8327 @cindex COMPLEX(KIND=1) type
8328 @cindex types, COMPLEX(KIND=1)
8329 @item COMPLEX(KIND=1)
8330 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
8331 one for the imaginary part).
8332
8333 @cindex COMPLEX(KIND=2) type
8334 @cindex types, COMPLEX(KIND=2)
8335 @item COMPLEX(KIND=2)
8336 Two @code{REAL(KIND=2)} scalars.
8337
8338 @cindex *@var{n} notation
8339 @item @var{numeric-type}*@var{n}
8340 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
8341 Same as whatever @code{gcc} type occupies @var{n} times the storage
8342 space of a @code{gcc} @code{char} item.
8343
8344 @cindex DOUBLE PRECISION type
8345 @cindex types, DOUBLE PRECISION
8346 @item DOUBLE PRECISION
8347 Same as @code{REAL(KIND=2)}.
8348
8349 @cindex DOUBLE COMPLEX type
8350 @cindex types, DOUBLE COMPLEX
8351 @item DOUBLE COMPLEX
8352 Same as @code{COMPLEX(KIND=2)}.
8353 @end table
8354
8355 Note that the above are proposed correspondences and might change
8356 in future versions of @code{g77}---avoid writing code depending
8357 on them.
8358
8359 Other types supported by @code{g77}
8360 are derived from gcc types such as @code{char}, @code{short},
8361 @code{int}, @code{long int}, @code{long long int}, @code{long double},
8362 and so on.
8363 That is, whatever types @code{gcc} already supports, @code{g77} supports
8364 now or probably will support in a future version.
8365 The rules for the @samp{@var{numeric-type}*@var{n}} notation
8366 apply to these types,
8367 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
8368 assigned in a way that encourages clarity, consistency, and portability.
8369
8370 @node Compiler Constants
8371 @section Compiler Constants
8372 @cindex constants
8373 @cindex types, constants
8374
8375 @code{g77} strictly assigns types to @emph{all} constants not
8376 documented as ``typeless'' (typeless constants including @samp{'1'Z},
8377 for example).
8378 Many other Fortran compilers attempt to assign types to typed constants
8379 based on their context.
8380 This results in hard-to-find bugs, nonportable
8381 code, and is not in the spirit (though it strictly follows the letter)
8382 of the 77 and 90 standards.
8383
8384 @code{g77} might offer, in a future release, explicit constructs by
8385 which a wider variety of typeless constants may be specified, and/or
8386 user-requested warnings indicating places where @code{g77} might differ
8387 from how other compilers assign types to constants.
8388
8389 @xref{Context-Sensitive Constants}, for more information on this issue.
8390
8391 @node Compiler Intrinsics
8392 @section Compiler Intrinsics
8393
8394 @code{g77} offers an ever-widening set of intrinsics.
8395 Currently these all are procedures (functions and subroutines).
8396
8397 Some of these intrinsics are unimplemented, but their names reserved
8398 to reduce future problems with existing code as they are implemented.
8399 Others are implemented as part of the GNU Fortran language, while
8400 yet others are provided for compatibility with other dialects of
8401 Fortran but are not part of the GNU Fortran language.
8402
8403 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
8404 a facility that is simply an extension of the intrinsic groups provided
8405 by the GNU Fortran language.
8406
8407 @menu
8408 * Intrinsic Groups::  How intrinsics are grouped for easy management.
8409 * Other Intrinsics::  Intrinsics other than those in the GNU
8410                        Fortran language.
8411 @end menu
8412
8413 @node Intrinsic Groups
8414 @subsection Intrinsic Groups
8415 @cindex groups of intrinsics
8416 @cindex intrinsics, groups
8417
8418 A given specific intrinsic belongs in one or more groups.
8419 Each group is deleted, disabled, hidden, or enabled
8420 by default or a command-line option.
8421 The meaning of each term follows.
8422
8423 @table @b
8424 @cindex deleted intrinsics
8425 @cindex intrinsics, deleted
8426 @item Deleted
8427 No intrinsics are recognized as belonging to that group.
8428
8429 @cindex disabled intrinsics
8430 @cindex intrinsics, disabled
8431 @item Disabled
8432 Intrinsics are recognized as belonging to the group, but
8433 references to them (other than via the @code{INTRINSIC} statement)
8434 are disallowed through that group.
8435
8436 @cindex hidden intrinsics
8437 @cindex intrinsics, hidden
8438 @item Hidden
8439 Intrinsics in that group are recognized and enabled (if implemented)
8440 @emph{only} if the first mention of the actual name of an intrinsic
8441 in a program unit is in an @code{INTRINSIC} statement.
8442
8443 @cindex enabled intrinsics
8444 @cindex intrinsics, enabled
8445 @item Enabled
8446 Intrinsics in that group are recognized and enabled (if implemented).
8447 @end table
8448
8449 The distinction between deleting and disabling a group is illustrated
8450 by the following example.
8451 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
8452 If group @samp{FGR} is deleted, the following program unit will
8453 successfully compile, because @samp{FOO()} will be seen as a
8454 reference to an external function named @samp{FOO}:
8455
8456 @example
8457 PRINT *, FOO()
8458 END
8459 @end example
8460
8461 @noindent
8462 If group @samp{FGR} is disabled, compiling the above program will produce
8463 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
8464 or, if properly invoked, it is not enabled.
8465 To change the above program so it references an external function @samp{FOO}
8466 instead of the disabled @samp{FOO} intrinsic,
8467 add the following line to the top:
8468
8469 @example
8470 EXTERNAL FOO
8471 @end example
8472
8473 @noindent
8474 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
8475 that group do not exist at all, whereas disabling it tells @code{g77} to
8476 recognize them as (disabled) intrinsics in intrinsic-like contexts.
8477
8478 Hiding a group is like enabling it, but the intrinsic must be first
8479 named in an @code{INTRINSIC} statement to be considered a reference to the
8480 intrinsic rather than to an external procedure.
8481 This might be the ``safest'' way to treat a new group of intrinsics
8482 when compiling old
8483 code, because it allows the old code to be generally written as if
8484 those new intrinsics never existed, but to be changed to use them
8485 by inserting @code{INTRINSIC} statements in the appropriate places.
8486 However, it should be the goal of development to use @code{EXTERNAL}
8487 for all names of external procedures that might be intrinsic names.
8488
8489 If an intrinsic is in more than one group, it is enabled if any of its
8490 containing groups are enabled; if not so enabled, it is hidden if
8491 any of its containing groups are hidden; if not so hidden, it is disabled
8492 if any of its containing groups are disabled; if not so disabled, it is
8493 deleted.
8494 This extra complication is necessary because some intrinsics,
8495 such as @code{IBITS}, belong to more than one group, and hence should be
8496 enabled if any of the groups to which they belong are enabled, and so
8497 on.
8498
8499 The groups are:
8500
8501 @cindex intrinsics, groups of
8502 @cindex groups of intrinsics
8503 @table @code
8504 @cindex @code{badu77} intrinsics group
8505 @item badu77
8506 UNIX intrinsics having inappropriate forms (usually functions that
8507 have intended side effects).
8508
8509 @cindex @code{gnu} intrinsics group
8510 @item gnu
8511 Intrinsics the GNU Fortran language supports that are extensions to
8512 the Fortran standards (77 and 90).
8513
8514 @cindex @code{f2c} intrinsics group
8515 @item f2c
8516 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
8517
8518 @cindex @code{f90} intrinsics group
8519 @item f90
8520 Fortran 90 intrinsics.
8521
8522 @cindex @code{mil} intrinsics group
8523 @item mil
8524 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
8525
8526 @cindex @code{mil} intrinsics group
8527 @item unix
8528 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
8529
8530 @cindex @code{mil} intrinsics group
8531 @item vxt
8532 VAX/VMS FORTRAN (current as of v4) intrinsics.
8533 @end table
8534
8535 @node Other Intrinsics
8536 @subsection Other Intrinsics
8537 @cindex intrinsics, others
8538 @cindex other intrinsics
8539
8540 @code{g77} supports intrinsics other than those in the GNU Fortran
8541 language proper.
8542 This set of intrinsics is described below.
8543
8544 @ifinfo
8545 (Note that the empty lines appearing in the menu below
8546 are not intentional---they result from a bug in the
8547 @code{makeinfo} program.)
8548 @end ifinfo
8549
8550 @c The actual documentation for intrinsics comes from
8551 @c intdoc.texi, which in turn is automatically generated
8552 @c from the internal g77 tables in intrin.def _and_ the
8553 @c largely hand-written text in intdoc.h.  So, if you want
8554 @c to change or add to existing documentation on intrinsics,
8555 @c you probably want to edit intdoc.h.
8556 @c
8557 @clear familyF77
8558 @clear familyGNU
8559 @clear familyASC
8560 @clear familyMIL
8561 @clear familyF90
8562 @set familyVXT
8563 @set familyFVZ
8564 @clear familyF2C
8565 @clear familyF2U
8566 @set familyBADU77
8567 @include intdoc.texi
8568
8569 @node Other Compilers
8570 @chapter Other Compilers
8571
8572 An individual Fortran source file can be compiled to
8573 an object (@file{*.o}) file instead of to the final
8574 program executable.
8575 This allows several portions of a program to be compiled
8576 at different times and linked together whenever a new
8577 version of the program is needed.
8578 However, it introduces the issue of @dfn{object compatibility}
8579 across the various object files (and libraries, or @file{*.a}
8580 files) that are linked together to produce any particular
8581 executable file.
8582
8583 Object compatibility is an issue when combining, in one
8584 program, Fortran code compiled by more than one compiler
8585 (or more than one configuration of a compiler).
8586 If the compilers
8587 disagree on how to transform the names of procedures, there
8588 will normally be errors when linking such programs.
8589 Worse, if the compilers agree on naming, but disagree on issues
8590 like how to pass parameters, return arguments, and lay out
8591 @code{COMMON} areas, the earliest detected errors might be the
8592 incorrect results produced by the program (and that assumes
8593 these errors are detected, which is not always the case).
8594
8595 Normally, @code{g77} generates code that is
8596 object-compatible with code generated by a version of
8597 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
8598 to be generally compatible with @code{g77} as built by @code{gcc}.
8599 (Normally, @code{f2c} will, by default, conform to the appropriate
8600 configuration, but it is possible that older or perhaps even newer
8601 versions of @code{f2c}, or versions having certain configuration changes
8602 to @code{f2c} internals, will produce object files that are
8603 incompatible with @code{g77}.)
8604
8605 For example, a Fortran string subroutine
8606 argument will become two arguments on the C side: a @code{char *}
8607 and an @code{int} length.
8608
8609 Much of this compatibility results from the fact that
8610 @code{g77} uses the same run-time library,
8611 @code{libf2c}, used by @code{f2c},
8612 though @code{g77} gives its version the name @code{libg2c}
8613 so as to avoid conflicts when linking,
8614 installing them in the same directories,
8615 and so on.
8616
8617 Other compilers might or might not generate code that
8618 is object-compatible with @code{libg2c} and current @code{g77},
8619 and some might offer such compatibility only when explicitly
8620 selected via a command-line option to the compiler.
8621
8622 @emph{Note: This portion of the documentation definitely needs a lot
8623 of work!}
8624
8625 @menu
8626 * Dropping f2c Compatibility::  When speed is more important.
8627 * Compilers Other Than f2c::    Interoperation with code from other compilers.
8628 @end menu
8629
8630 @node Dropping f2c Compatibility
8631 @section Dropping @code{f2c} Compatibility
8632
8633 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
8634 some cases, faster code, by not needing to allow to the possibility
8635 of linking with code compiled by @code{f2c}.
8636
8637 For example, this affects how @code{REAL(KIND=1)},
8638 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
8639 With @samp{-fno-f2c}, they are
8640 compiled as returning the appropriate @code{gcc} type
8641 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
8642 in many configurations).
8643
8644 With @samp{-ff2c} in force, they
8645 are compiled differently (with perhaps slower run-time performance)
8646 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
8647 C as an intermediate language---@code{REAL(KIND=1)} functions
8648 return C's @code{double} type, while @code{COMPLEX} functions return
8649 @code{void} and use an extra argument pointing to a place for the functions to
8650 return their values.
8651
8652 It is possible that, in some cases, leaving @samp{-ff2c} in force
8653 might produce faster code than using @samp{-fno-f2c}.
8654 Feel free to experiment, but remember to experiment with changing the way
8655 @emph{entire programs and their Fortran libraries are compiled} at
8656 a time, since this sort of experimentation affects the interface
8657 of code generated for a Fortran source file---that is, it affects
8658 object compatibility.
8659
8660 Note that @code{f2c} compatibility is a fairly static target to achieve,
8661 though not necessarily perfectly so, since, like @code{g77}, it is
8662 still being improved.
8663 However, specifying @samp{-fno-f2c} causes @code{g77}
8664 to generate code that will probably be incompatible with code
8665 generated by future versions of @code{g77} when the same option
8666 is in force.
8667 You should make sure you are always able to recompile complete
8668 programs from source code when upgrading to new versions of @code{g77}
8669 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
8670
8671 Therefore, if you are using @code{g77} to compile libraries and other
8672 object files for possible future use and you don't want to require
8673 recompilation for future use with subsequent versions of @code{g77},
8674 you might want to stick with @code{f2c} compatibility for now, and
8675 carefully watch for any announcements about changes to the
8676 @code{f2c}/@code{libf2c} interface that might affect existing programs
8677 (thus requiring recompilation).
8678
8679 It is probable that a future version of @code{g77} will not,
8680 by default, generate object files compatible with @code{f2c},
8681 and that version probably would no longer use @code{libf2c}.
8682 If you expect to depend on this compatibility in the
8683 long term, use the options @samp{-ff2c -ff2c-library} when compiling
8684 all of the applicable code.
8685 This should cause future versions of @code{g77} either to produce
8686 compatible code (at the expense of the availability of some features and
8687 performance), or at the very least, to produce diagnostics.
8688
8689 (The library @code{g77} produces will no longer be named @file{libg2c}
8690 when it is no longer generally compatible with @file{libf2c}.
8691 It will likely be referred to, and, if installed as a distinct
8692 library, named @code{libg77}, or some other as-yet-unused name.)
8693
8694 @node Compilers Other Than f2c
8695 @section Compilers Other Than @code{f2c}
8696
8697 On systems with Fortran compilers other than @code{f2c} and @code{g77},
8698 code compiled by @code{g77} is not expected to work
8699 well with code compiled by the native compiler.
8700 (This is true for @code{f2c}-compiled objects as well.)
8701 Libraries compiled with the native compiler probably will have
8702 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
8703
8704 Reasons for such incompatibilities include:
8705
8706 @itemize @bullet
8707 @item
8708 There might be differences in the way names of Fortran procedures
8709 are translated for use in the system's object-file format.
8710 For example, the statement @samp{CALL FOO} might be compiled
8711 by @code{g77} to call a procedure the linker @code{ld} sees
8712 given the name @samp{_foo_}, while the apparently corresponding
8713 statement @samp{SUBROUTINE FOO} might be compiled by the
8714 native compiler to define the linker-visible name @samp{_foo},
8715 or @samp{_FOO_}, and so on.
8716
8717 @item
8718 There might be subtle type mismatches which cause subroutine arguments
8719 and function return values to get corrupted.
8720
8721 This is why simply getting @code{g77} to
8722 transform procedure names the same way a native
8723 compiler does is not usually a good idea---unless
8724 some effort has been made to ensure that, aside
8725 from the way the two compilers transform procedure
8726 names, everything else about the way they generate
8727 code for procedure interfaces is identical.
8728
8729 @item
8730 Native compilers
8731 use libraries of private I/O routines which will not be available
8732 at link time unless you have the native compiler---and you would
8733 have to explicitly ask for them.
8734
8735 For example, on the Sun you
8736 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
8737 command.
8738 @end itemize
8739
8740 @node Other Languages
8741 @chapter Other Languages
8742
8743 @emph{Note: This portion of the documentation definitely needs a lot
8744 of work!}
8745
8746 @menu
8747 * Interoperating with C and C++::
8748 @end menu
8749
8750 @node Interoperating with C and C++
8751 @section Tools and advice for interoperating with C and C++
8752
8753 @cindex C, linking with
8754 @cindex C++, linking with
8755 @cindex linking with C
8756 The following discussion assumes that you are running @code{g77} in @code{f2c}
8757 compatibility mode, i.e.@: not using @samp{-fno-f2c}.
8758 It provides some
8759 advice about quick and simple techniques for linking Fortran and C (or
8760 C++), the most common requirement.
8761 For the full story consult the
8762 description of code generation.
8763 @xref{Debugging and Interfacing}.
8764
8765 When linking Fortran and C, it's usually best to use @code{g77} to do
8766 the linking so that the correct libraries are included (including the
8767 maths one).
8768 If you're linking with C++ you will want to add
8769 @samp{-lstdc++}, @samp{-lg++} or whatever.
8770 If you need to use another
8771 driver program (or @code{ld} directly),
8772 you can find out what linkage
8773 options @code{g77} passes by running @samp{g77 -v}.
8774
8775 @menu
8776 * C Interfacing Tools::
8777 * C Access to Type Information::
8778 * f2c Skeletons and Prototypes::
8779 * C++ Considerations::
8780 * Startup Code::
8781 @end menu
8782
8783 @node C Interfacing Tools
8784 @subsection C Interfacing Tools
8785 @pindex f2c
8786 @cindex cfortran.h
8787 @cindex Netlib
8788 Even if you don't actually use it as a compiler, @samp{f2c} from
8789 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
8790 interfacing (linking) Fortran and C@.
8791 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
8792
8793 To use @code{f2c} for this purpose you only need retrieve and
8794 build the @file{src} directory from the distribution, consult the
8795 @file{README} instructions there for machine-specifics, and install the
8796 @code{f2c} program on your path.
8797
8798 Something else that might be useful is @samp{cfortran.h} from
8799 @uref{ftp://zebra/desy.de/cfortran}.
8800 This is a fairly general tool which
8801 can be used to generate interfaces for calling in both directions
8802 between Fortran and C@.
8803 It can be used in @code{f2c} mode with
8804 @code{g77}---consult its documentation for details.
8805
8806 @node C Access to Type Information
8807 @subsection Accessing Type Information in C
8808
8809 @cindex types, Fortran/C
8810 Generally, C code written to link with
8811 @code{g77} code---calling and/or being
8812 called from Fortran---should @samp{#include <g2c.h>} to define the C
8813 versions of the Fortran types.
8814 Don't assume Fortran @code{INTEGER} types
8815 correspond to C @samp{int}s, for instance; instead, declare them as
8816 @code{integer}, a type defined by @file{g2c.h}.
8817 @file{g2c.h} is installed where @code{gcc} will find it by
8818 default, assuming you use a copy of @code{gcc} compatible with
8819 @code{g77}, probably built at the same time as @code{g77}.
8820
8821 @node f2c Skeletons and Prototypes
8822 @subsection Generating Skeletons and Prototypes with @code{f2c}
8823
8824 @pindex f2c
8825 @cindex -fno-second-underscore
8826 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@: to
8827 interface with an existing library---is to write a file (named, for
8828 example, @file{fred.f}) of dummy Fortran
8829 skeletons comprising just the declaration of the routine(s) and dummy
8830 arguments plus @samp{END} statements.
8831 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
8832 into which you can edit
8833 useful code, confident the calling sequence is correct, at least.
8834 (There are some errors otherwise commonly made in generating C
8835 interfaces with @code{f2c} conventions,
8836 such as not using @code{doublereal}
8837 as the return type of a @code{REAL} @code{FUNCTION}.)
8838
8839 @pindex ftnchek
8840 @code{f2c} also can help with calling Fortran from C, using its
8841 @samp{-P} option to generate C prototypes appropriate for calling the
8842 Fortran.@footnote{The files generated like this can also be used for
8843 inter-unit consistency checking of dummy and actual arguments, although
8844 the @samp{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
8845 or @uref{ftp://ftp.dsm.fordham.edu} is
8846 probably better for this purpose.}
8847 If the Fortran code containing any
8848 routines to be called from C is in file @file{joe.f}, use the command
8849 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
8850 prototype information.
8851 @code{#include} this in the C which has to call
8852 the Fortran routines to make sure you get it right.
8853
8854 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
8855 between the way Fortran (including compilers like @code{g77}) and
8856 C handle arrays.
8857
8858 @node C++ Considerations
8859 @subsection C++ Considerations
8860
8861 @cindex C++
8862 @code{f2c} can be used to generate suitable code for compilation with a
8863 C++ system using the @samp{-C++} option.
8864 The important thing about linking @code{g77}-compiled
8865 code with C++ is that the prototypes for the @code{g77}
8866 routines must specify C linkage to avoid name mangling.
8867 So, use an @samp{extern "C"} declaration.
8868 @code{f2c}'s @samp{-C++} option will take care
8869 of this when generating skeletons or prototype files as above, and also
8870 avoid clashes with C++ reserved words in addition to those in C@.
8871
8872 @node Startup Code
8873 @subsection Startup Code
8874
8875 @cindex startup code
8876 @cindex run-time, initialization
8877 @cindex initialization, run-time
8878 Unlike with some runtime systems,
8879 it shouldn't be necessary
8880 (unless there are bugs)
8881 to use a Fortran main program unit to ensure the
8882 runtime---specifically the I/O system---is initialized.
8883
8884 However, to use the @code{g77} intrinsics @code{GETARG} and @code{IARGC},
8885 either the @code{main} routine from the @file{libg2c} library must be used,
8886 or the @code{f_setarg} routine
8887 (new as of @code{egcs} version 1.1 and @code{g77} version 0.5.23)
8888 must be called with the appropriate @code{argc} and @code{argv} arguments
8889 prior to the program calling @code{GETARG} or @code{IARGC}.
8890
8891 To provide more flexibility for mixed-language programming
8892 involving @code{g77} while allowing for shared libraries,
8893 as of @code{egcs} version 1.1 and @code{g77} version 0.5.23,
8894 @code{g77}'s @code{main} routine in @code{libg2c}
8895 does the following, in order:
8896
8897 @enumerate
8898 @item
8899 Calls @code{f_setarg}
8900 with the incoming @code{argc} and @code{argv} arguments,
8901 in the same order as for @code{main} itself.
8902
8903 This sets up the command-line environment
8904 for @code{GETARG} and @code{IARGC}.
8905
8906 @item
8907 Calls @code{f_setsig} (with no arguments).
8908
8909 This sets up the signaling and exception environment.
8910
8911 @item
8912 Calls @code{f_init} (with no arguments).
8913
8914 This initializes the I/O environment,
8915 though that should not be necessary,
8916 as all I/O functions in @code{libf2c}
8917 are believed to call @code{f_init} automatically,
8918 if necessary.
8919
8920 (A future version of @code{g77} might skip this explicit step,
8921 to speed up normal exit of a program.)
8922
8923 @item
8924 Arranges for @code{f_exit} to be called (with no arguments)
8925 when the program exits.
8926
8927 This ensures that the I/O environment is properly shut down
8928 before the program exits normally.
8929 Otherwise, output buffers might not be fully flushed,
8930 scratch files might not be deleted, and so on.
8931
8932 The simple way @code{main} does this is
8933 to call @code{f_exit} itself after calling
8934 @code{MAIN__} (in the next step).
8935
8936 However, this does not catch the cases where the program
8937 might call @code{exit} directly,
8938 instead of using the @code{EXIT} intrinsic
8939 (implemented as @code{exit_} in @code{libf2c}).
8940
8941 So, @code{main} attempts to use
8942 the operating environment's @code{onexit} or @code{atexit}
8943 facility, if available,
8944 to cause @code{f_exit} to be called automatically
8945 upon any invocation of @code{exit}.
8946
8947 @item
8948 Calls @code{MAIN__} (with no arguments).
8949
8950 This starts executing the Fortran main program unit for
8951 the application.
8952 (Both @code{g77} and @code{f2c} currently compile a main
8953 program unit so that its global name is @code{MAIN__}.)
8954
8955 @item
8956 If no @code{onexit} or @code{atexit} is provided by the system,
8957 calls @code{f_exit}.
8958
8959 @item
8960 Calls @code{exit} with a zero argument,
8961 to signal a successful program termination.
8962
8963 @item
8964 Returns a zero value to the caller,
8965 to signal a successful program termination,
8966 in case @code{exit} doesn't exit on the system.
8967 @end enumerate
8968
8969 All of the above names are C @code{extern} names,
8970 i.e.@: not mangled.
8971
8972 When using the @code{main} procedure provided by @code{g77}
8973 without a Fortran main program unit,
8974 you need to provide @code{MAIN__}
8975 as the entry point for your C code.
8976 (Make sure you link the object file that defines that
8977 entry point with the rest of your program.)
8978
8979 To provide your own @code{main} procedure
8980 in place of @code{g77}'s,
8981 make sure you specify the object file defining that procedure
8982 @emph{before} @samp{-lg2c} on the @code{g77} command line.
8983 Since the @samp{-lg2c} option is implicitly provided,
8984 this is usually straightforward.
8985 (Use the @samp{--verbose} option to see how and where
8986 @code{g77} implicitly adds @samp{-lg2c} in a command line
8987 that will link the program.
8988 Feel free to specify @samp{-lg2c} explicitly,
8989 as appropriate.)
8990
8991 However, when providing your own @code{main},
8992 make sure you perform the appropriate tasks in the
8993 appropriate order.
8994 For example, if your @code{main} does not call @code{f_setarg},
8995 make sure the rest of your application does not call
8996 @code{GETARG} or @code{IARGC}.
8997
8998 And, if your @code{main} fails to ensure that @code{f_exit}
8999 is called upon program exit,
9000 some files might end up incompletely written,
9001 some scratch files might be left lying around,
9002 and some existing files being written might be left
9003 with old data not properly truncated at the end.
9004
9005 Note that, generally, the @code{g77} operating environment
9006 does not depend on a procedure named @code{MAIN__} actually
9007 being called prior to any other @code{g77}-compiled code.
9008 That is, @code{MAIN__} does not, itself,
9009 set up any important operating-environment characteristics
9010 upon which other code might depend.
9011 This might change in future versions of @code{g77},
9012 with appropriate notification in the release notes.
9013
9014 For more information, consult the source code for the above routines.
9015 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
9016 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
9017
9018 Also, the file @file{@value{path-g77}/com.c} contains the code @code{g77}
9019 uses to open-code (inline) references to @code{IARGC}.
9020
9021 @include g77install.texi
9022
9023 @node Debugging and Interfacing
9024 @chapter Debugging and Interfacing
9025 @cindex debugging
9026 @cindex interfacing
9027 @cindex calling C routines
9028 @cindex C routines calling Fortran
9029 @cindex f2c compatibility
9030
9031 GNU Fortran currently generates code that is object-compatible with
9032 the @code{f2c} converter.
9033 Also, it avoids limitations in the current GBE, such as the
9034 inability to generate a procedure with
9035 multiple entry points, by generating code that is structured
9036 differently (in terms of procedure names, scopes, arguments, and
9037 so on) than might be expected.
9038
9039 As a result, writing code in other languages that calls on, is
9040 called by, or shares in-memory data with @code{g77}-compiled code generally
9041 requires some understanding of the way @code{g77} compiles code for
9042 various constructs.
9043
9044 Similarly, using a debugger to debug @code{g77}-compiled
9045 code, even if that debugger supports native Fortran debugging, generally
9046 requires this sort of information.
9047
9048 This section describes some of the basic information on how
9049 @code{g77} compiles code for constructs involving interfaces to other
9050 languages and to debuggers.
9051
9052 @emph{Caution:} Much or all of this information pertains to only the current
9053 release of @code{g77}, sometimes even to using certain compiler options
9054 with @code{g77} (such as @samp{-fno-f2c}).
9055 Do not write code that depends on this
9056 information without clearly marking said code as nonportable and
9057 subject to review for every new release of @code{g77}.
9058 This information
9059 is provided primarily to make debugging of code generated by this
9060 particular release of @code{g77} easier for the user, and partly to make
9061 writing (generally nonportable) interface code easier.
9062 Both of these
9063 activities require tracking changes in new version of @code{g77} as they
9064 are installed, because new versions can change the behaviors
9065 described in this section.
9066
9067 @menu
9068 * Main Program Unit::  How @code{g77} compiles a main program unit.
9069 * Procedures::         How @code{g77} constructs parameter lists
9070                        for procedures.
9071 * Functions::          Functions returning floating-point or character data.
9072 * Names::              Naming of user-defined variables, procedures, etc.
9073 * Common Blocks::      Accessing common variables while debugging.
9074 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
9075 * Complex Variables::  How @code{g77} performs complex arithmetic.
9076 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
9077 * Adjustable Arrays::  Special consideration for adjustable arrays.
9078 * Alternate Entry Points::  How @code{g77} implements alternate @code{ENTRY}.
9079 * Alternate Returns::  How @code{g77} handles alternate returns.
9080 * Assigned Statement Labels::  How @code{g77} handles @code{ASSIGN}.
9081 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
9082 @end menu
9083
9084 @node Main Program Unit
9085 @section Main Program Unit (PROGRAM)
9086 @cindex PROGRAM statement
9087 @cindex statements, PROGRAM
9088
9089 When @code{g77} compiles a main program unit, it gives it the public
9090 procedure name @samp{MAIN__}.
9091 The @code{libg2c} library has the actual @code{main()} procedure
9092 as is typical of C-based environments, and
9093 it is this procedure that performs some initial start-up
9094 activity and then calls @samp{MAIN__}.
9095
9096 Generally, @code{g77} and @code{libg2c} are designed so that you need not
9097 include a main program unit written in Fortran in your program---it
9098 can be written in C or some other language.
9099 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
9100 includes a bug fix for @code{libg2c} that solved a problem with using the
9101 @code{OPEN} statement as the first Fortran I/O activity in a program
9102 without a Fortran main program unit.
9103
9104 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
9105 your main program unit---that is, if you intend to compile a @code{main()}
9106 procedure using some other language---you should carefully
9107 examine the code for @code{main()} in @code{libg2c}, found in the source
9108 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
9109 might need to be done by your @code{main()} in order to provide the
9110 Fortran environment your Fortran code is expecting.
9111
9112 @cindex @code{IArgC} intrinsic
9113 @cindex intrinsics, @code{IArgC}
9114 @cindex @code{GetArg} intrinsic
9115 @cindex intrinsics, @code{GetArg}
9116 For example, @code{libg2c}'s @code{main()} sets up the information used by
9117 the @code{IARGC} and @code{GETARG} intrinsics.
9118 Bypassing @code{libg2c}'s @code{main()}
9119 without providing a substitute for this activity would mean
9120 that invoking @code{IARGC} and @code{GETARG} would produce undefined
9121 results.
9122
9123 @cindex debugging
9124 @cindex main program unit, debugging
9125 @cindex main()
9126 @cindex MAIN__()
9127 @cindex .gdbinit
9128 When debugging, one implication of the fact that @code{main()}, which
9129 is the place where the debugged program ``starts'' from the
9130 debugger's point of view, is in @code{libg2c} is that you won't be
9131 starting your Fortran program at a point you recognize as your
9132 Fortran code.
9133
9134 The standard way to get around this problem is to set a break
9135 point (a one-time, or temporary, break point will do) at
9136 the entrance to @samp{MAIN__}, and then run the program.
9137 A convenient way to do so is to add the @code{gdb} command
9138
9139 @example
9140 tbreak MAIN__
9141 @end example
9142
9143 @noindent
9144 to the file @file{.gdbinit} in the directory in which you're debugging
9145 (using @code{gdb}).
9146
9147 After doing this, the debugger will see the current execution
9148 point of the program as at the beginning of the main program
9149 unit of your program.
9150
9151 Of course, if you really want to set a break point at some
9152 other place in your program and just start the program
9153 running, without first breaking at @samp{MAIN__},
9154 that should work fine.
9155
9156 @node Procedures
9157 @section Procedures (SUBROUTINE and FUNCTION)
9158 @cindex procedures
9159 @cindex SUBROUTINE statement
9160 @cindex statements, SUBROUTINE
9161 @cindex FUNCTION statement
9162 @cindex statements, FUNCTION
9163 @cindex signature of procedures
9164
9165 Currently, @code{g77} passes arguments via reference---specifically,
9166 by passing a pointer to the location in memory of a variable, array,
9167 array element, a temporary location that holds the result of evaluating an
9168 expression, or a temporary or permanent location that holds the value
9169 of a constant.
9170
9171 Procedures that accept @code{CHARACTER} arguments are implemented by
9172 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
9173
9174 The first argument occupies the expected position in the
9175 argument list and has the user-specified name.
9176 This argument
9177 is a pointer to an array of characters, passed by the caller.
9178
9179 The second argument is appended to the end of the user-specified
9180 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
9181 is the user-specified name.
9182 This argument is of the C type @code{ftnlen}
9183 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
9184 is the number of characters the caller has allocated in the
9185 array pointed to by the first argument.
9186
9187 A procedure will ignore the length argument if @samp{X} is not declared
9188 @code{CHARACTER*(*)}, because for other declarations, it knows the
9189 length.
9190 Not all callers necessarily ``know'' this, however, which
9191 is why they all pass the extra argument.
9192
9193 The contents of the @code{CHARACTER} argument are specified by the
9194 address passed in the first argument (named after it).
9195 The procedure can read or write these contents as appropriate.
9196
9197 When more than one @code{CHARACTER} argument is present in the argument
9198 list, the length arguments are appended in the order
9199 the original arguments appear.
9200 So @samp{CALL FOO('HI','THERE')} is implemented in
9201 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
9202 does not provide the trailing null bytes on the constant
9203 strings (@code{f2c} does provide them, but they are unnecessary in
9204 a Fortran environment, and you should not expect them to be
9205 there).
9206
9207 Note that the above information applies to @code{CHARACTER} variables and
9208 arrays @strong{only}.
9209 It does @strong{not} apply to external @code{CHARACTER}
9210 functions or to intrinsic @code{CHARACTER} functions.
9211 That is, no second length argument is passed to @samp{FOO} in this case:
9212
9213 @example
9214 CHARACTER X
9215 EXTERNAL X
9216 CALL FOO(X)
9217 @end example
9218
9219 @noindent
9220 Nor does @samp{FOO} expect such an argument in this case:
9221
9222 @example
9223 SUBROUTINE FOO(X)
9224 CHARACTER X
9225 EXTERNAL X
9226 @end example
9227
9228 Because of this implementation detail, if a program has a bug
9229 such that there is disagreement as to whether an argument is
9230 a procedure, and the type of the argument is @code{CHARACTER}, subtle
9231 symptoms might appear.
9232
9233 @node Functions
9234 @section Functions (FUNCTION and RETURN)
9235 @cindex functions
9236 @cindex FUNCTION statement
9237 @cindex statements, FUNCTION
9238 @cindex RETURN statement
9239 @cindex statements, RETURN
9240 @cindex return type of functions
9241
9242 @code{g77} handles in a special way functions that return the following
9243 types:
9244
9245 @itemize @bullet
9246 @item
9247 @code{CHARACTER}
9248 @item
9249 @code{COMPLEX}
9250 @item
9251 @code{REAL(KIND=1)}
9252 @end itemize
9253
9254 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
9255 returning @code{void})
9256 with two arguments prepended: @samp{__g77_result}, which the caller passes
9257 as a pointer to a @code{char} array expected to hold the return value,
9258 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
9259 specifying the length of the return value as declared in the calling
9260 program.
9261 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
9262 to determine the size of the array that @samp{__g77_result} points to;
9263 otherwise, it ignores that argument.
9264
9265 For @code{COMPLEX}, when @samp{-ff2c} is in
9266 force, @code{g77} implements
9267 a subroutine with one argument prepended: @samp{__g77_result}, which the
9268 caller passes as a pointer to a variable of the type of the function.
9269 The called function writes the return value into this variable instead
9270 of returning it as a function value.
9271 When @samp{-fno-f2c} is in force,
9272 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
9273 @samp{__complex__ float} or @samp{__complex__ double} function
9274 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
9275 returning the result of the function in the same way as @code{gcc} would.
9276
9277 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
9278 a function that actually returns @code{REAL(KIND=2)} (typically
9279 C's @code{double} type).
9280 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
9281 functions return @code{float}.
9282
9283 @node Names
9284 @section Names
9285 @cindex symbol names
9286 @cindex transforming symbol names
9287
9288 Fortran permits each implementation to decide how to represent
9289 names as far as how they're seen in other contexts, such as debuggers
9290 and when interfacing to other languages, and especially as far
9291 as how casing is handled.
9292
9293 External names---names of entities that are public, or ``accessible'',
9294 to all modules in a program---normally have an underscore (@samp{_})
9295 appended by @code{g77},
9296 to generate code that is compatible with @code{f2c}.
9297 External names include names of Fortran things like common blocks,
9298 external procedures (subroutines and functions, but not including
9299 statement functions, which are internal procedures), and entry point
9300 names.
9301
9302 However, use of the @samp{-fno-underscoring} option
9303 disables this kind of transformation of external names (though inhibiting
9304 the transformation certainly improves the chances of colliding with
9305 incompatible externals written in other languages---but that
9306 might be intentional.
9307
9308 @cindex -fno-underscoring option
9309 @cindex options, -fno-underscoring
9310 @cindex -fno-second-underscore option
9311 @cindex options, -fno-underscoring
9312 When @samp{-funderscoring} is in force, any name (external or local)
9313 that already has at least one underscore in it is
9314 implemented by @code{g77} by appending two underscores.
9315 (This second underscore can be disabled via the
9316 @samp{-fno-second-underscore} option.)
9317 External names are changed this way for @code{f2c} compatibility.
9318 Local names are changed this way to avoid collisions with external names
9319 that are different in the source code---@code{f2c} does the same thing, but
9320 there's no compatibility issue there except for user expectations while
9321 debugging.
9322
9323 For example:
9324
9325 @example
9326 Max_Cost = 0
9327 @end example
9328
9329 @cindex debugging
9330 @noindent
9331 Here, a user would, in the debugger, refer to this variable using the
9332 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
9333 as described below).
9334 (We hope to improve @code{g77} in this regard in the future---don't
9335 write scripts depending on this behavior!
9336 Also, consider experimenting with the @samp{-fno-underscoring}
9337 option to try out debugging without having to massage names by
9338 hand like this.)
9339
9340 @code{g77} provides a number of command-line options that allow the user
9341 to control how case mapping is handled for source files.
9342 The default is the traditional UNIX model for Fortran compilers---names
9343 are mapped to lower case.
9344 Other command-line options can be specified to map names to upper
9345 case, or to leave them exactly as written in the source file.
9346
9347 For example:
9348
9349 @example
9350 Foo = 9.436
9351 @end example
9352
9353 @noindent
9354 Here, it is normally the case that the variable assigned will be named
9355 @samp{foo}.
9356 This would be the name to enter when using a debugger to
9357 access the variable.
9358
9359 However, depending on the command-line options specified, the
9360 name implemented by @code{g77} might instead be @samp{FOO} or even
9361 @samp{Foo}, thus affecting how debugging is done.
9362
9363 Also:
9364
9365 @example
9366 Call Foo
9367 @end example
9368
9369 @noindent
9370 This would normally call a procedure that, if it were in a separate C program,
9371 be defined starting with the line:
9372
9373 @example
9374 void foo_()
9375 @end example
9376
9377 @noindent
9378 However, @code{g77} command-line options could be used to change the casing
9379 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
9380 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
9381 could be used to inhibit the appending of the underscore to the name.
9382
9383 @node Common Blocks
9384 @section Common Blocks (COMMON)
9385 @cindex common blocks
9386 @cindex @code{COMMON} statement
9387 @cindex statements, @code{COMMON}
9388
9389 @code{g77} names and lays out @code{COMMON} areas
9390 the same way @code{f2c} does,
9391 for compatibility with @code{f2c}.
9392
9393 Currently, @code{g77} does not emit ``true'' debugging information for
9394 members of a @code{COMMON} area, due to an apparent bug in the GBE.
9395
9396 (As of Version 0.5.19, @code{g77} emits debugging information for such
9397 members in the form of a constant string specifying the base name of
9398 the aggregate area and the offset of the member in bytes from the start
9399 of the area.
9400 Use the @samp{-fdebug-kludge} option to enable this behavior.
9401 In @code{gdb}, use @samp{set language c} before printing the value
9402 of the member, then @samp{set language fortran} to restore the default
9403 language, since @code{gdb} doesn't provide a way to print a readable
9404 version of a character string in Fortran language mode.
9405
9406 This kludge will be removed in a future version of @code{g77} that,
9407 in conjunction with a contemporary version of @code{gdb},
9408 properly supports Fortran-language debugging, including access
9409 to members of @code{COMMON} areas.)
9410
9411 @xref{Code Gen Options,,Options for Code Generation Conventions},
9412 for information on the @samp{-fdebug-kludge} option.
9413
9414 Moreover, @code{g77} currently implements a @code{COMMON} area such that its
9415 type is an array of the C @code{char} data type.
9416
9417 So, when debugging, you must know the offset into a @code{COMMON} area
9418 for a particular item in that area, and you have to take into
9419 account the appropriate multiplier for the respective sizes
9420 of the types (as declared in your code) for the items preceding
9421 the item in question as compared to the size of the @code{char} type.
9422
9423 For example, using default implicit typing, the statement
9424
9425 @example
9426 COMMON I(15), R(20), T
9427 @end example
9428
9429 @noindent
9430 results in a public 144-byte @code{char} array named @samp{_BLNK__}
9431 with @samp{I} placed at @samp{_BLNK__[0]}, @samp{R} at @samp{_BLNK__[60]},
9432 and @samp{T} at @samp{_BLNK__[140]}.
9433 (This is assuming that the target machine for
9434 the compilation has 4-byte @code{INTEGER(KIND=1)} and @code{REAL(KIND=1)}
9435 types.)
9436
9437 @node Local Equivalence Areas
9438 @section Local Equivalence Areas (EQUIVALENCE)
9439 @cindex equivalence areas
9440 @cindex local equivalence areas
9441 @cindex EQUIVALENCE statement
9442 @cindex statements, EQUIVALENCE
9443
9444 @code{g77} treats storage-associated areas involving a @code{COMMON}
9445 block as explained in the section on common blocks.
9446
9447 A local @code{EQUIVALENCE} area is a collection of variables and arrays
9448 connected to each other in any way via @code{EQUIVALENCE}, none of which are
9449 listed in a @code{COMMON} statement.
9450
9451 Currently, @code{g77} does not emit ``true'' debugging information for
9452 members in a local @code{EQUIVALENCE} area, due to an apparent bug in the GBE.
9453
9454 (As of Version 0.5.19, @code{g77} does emit debugging information for such
9455 members in the form of a constant string specifying the base name of
9456 the aggregate area and the offset of the member in bytes from the start
9457 of the area.
9458 Use the @samp{-fdebug-kludge} option to enable this behavior.
9459 In @code{gdb}, use @samp{set language c} before printing the value
9460 of the member, then @samp{set language fortran} to restore the default
9461 language, since @code{gdb} doesn't provide a way to print a readable
9462 version of a character string in Fortran language mode.
9463
9464 This kludge will be removed in a future version of @code{g77} that,
9465 in conjunction with a contemporary version of @code{gdb},
9466 properly supports Fortran-language debugging, including access
9467 to members of @code{EQUIVALENCE} areas.)
9468
9469 @xref{Code Gen Options,,Options for Code Generation Conventions},
9470 for information on the @samp{-fdebug-kludge} option.
9471
9472 Moreover, @code{g77} implements a local @code{EQUIVALENCE} area such that its
9473 type is an array of the C @code{char} data type.
9474
9475 The name @code{g77} gives this array of @code{char} type is @samp{__g77_equiv_@var{x}},
9476 where @var{x} is the name of the item that is placed at the beginning (offset 0)
9477 of this array.
9478 If more than one such item is placed at the beginning, @var{x} is
9479 the name that sorts to the top in an alphabetical sort of the list of
9480 such items.
9481
9482 When debugging, you must therefore access members of @code{EQUIVALENCE}
9483 areas by specifying the appropriate @samp{__g77_equiv_@var{x}}
9484 array section with the appropriate offset.
9485 See the explanation of debugging @code{COMMON} blocks
9486 for info applicable to debugging local @code{EQUIVALENCE} areas.
9487
9488 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
9489 for @var{x} using a different method when more than one name was
9490 in the list of names of entities placed at the beginning of the
9491 array.
9492 Though the documentation specified that the first name listed in
9493 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
9494 in fact chose the name using a method that was so complicated,
9495 it seemed easier to change it to an alphabetical sort than to describe the
9496 previous method in the documentation.)
9497
9498 @node Complex Variables
9499 @section Complex Variables (COMPLEX)
9500 @cindex complex variables
9501 @cindex imaginary part
9502 @cindex COMPLEX statement
9503 @cindex statements, COMPLEX
9504
9505 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
9506 (and related intrinsics, constants, functions, and so on)
9507 in a manner that
9508 makes direct debugging involving these types in Fortran
9509 language mode difficult.
9510
9511 Essentially, @code{g77} implements these types using an
9512 internal construct similar to C's @code{struct}, at least
9513 as seen by the @code{gcc} back end.
9514
9515 Currently, the back end, when outputting debugging info with
9516 the compiled code for the assembler to digest, does not detect
9517 these @code{struct} types as being substitutes for Fortran
9518 complex.
9519 As a result, the Fortran language modes of debuggers such as
9520 @code{gdb} see these types as C @code{struct} types, which
9521 they might or might not support.
9522
9523 Until this is fixed, switch to C language mode to work with
9524 entities of @code{COMPLEX} type and then switch back to Fortran language
9525 mode afterward.
9526 (In @code{gdb}, this is accomplished via @samp{set lang c} and
9527 either @samp{set lang fortran} or @samp{set lang auto}.)
9528
9529 @emph{Note:} Compiling with the @samp{-fno-emulate-complex} option
9530 avoids the debugging problem, but is known to cause other problems
9531 like compiler crashes and generation of incorrect code, so it is
9532 not recommended.
9533
9534 @node Arrays
9535 @section Arrays (DIMENSION)
9536 @cindex DIMENSION statement
9537 @cindex statements, DIMENSION
9538 @cindex array ordering
9539 @cindex ordering, array
9540 @cindex column-major ordering
9541 @cindex row-major ordering
9542 @cindex arrays
9543
9544 Fortran uses ``column-major ordering'' in its arrays.
9545 This differs from other languages, such as C, which use ``row-major ordering''.
9546 The difference is that, with Fortran, array elements adjacent to
9547 each other in memory differ in the @emph{first} subscript instead of
9548 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
9549 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
9550
9551 This consideration
9552 affects not only interfacing with and debugging Fortran code,
9553 it can greatly affect how code is designed and written, especially
9554 when code speed and size is a concern.
9555
9556 Fortran also differs from C, a popular language for interfacing and
9557 to support directly in debuggers, in the way arrays are treated.
9558 In C, arrays are single-dimensional and have interesting relationships
9559 to pointers, neither of which is true for Fortran.
9560 As a result, dealing with Fortran arrays from within
9561 an environment limited to C concepts can be challenging.
9562
9563 For example, accessing the array element @samp{A(5,10,20)} is easy enough
9564 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
9565 are needed.
9566 First, C would treat the A array as a single-dimension array.
9567 Second, C does not understand low bounds for arrays as does Fortran.
9568 Third, C assumes a low bound of zero (0), while Fortran defaults to a
9569 low bound of one (1) and can supports an arbitrary low bound.
9570 Therefore, calculations must be done
9571 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
9572 calculations require knowing the dimensions of @samp{A}.
9573
9574 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
9575 @samp{A(5,10,20)} would be:
9576
9577 @example
9578   (5-2)
9579 + (10-1)*(11-2+1)
9580 + (20-0)*(11-2+1)*(21-1+1)
9581 = 4293
9582 @end example
9583
9584 @noindent
9585 So the C equivalent in this case would be @samp{a[4293]}.
9586
9587 When using a debugger directly on Fortran code, the C equivalent
9588 might not work, because some debuggers cannot understand the notion
9589 of low bounds other than zero.  However, unlike @code{f2c}, @code{g77}
9590 does inform the GBE that a multi-dimensional array (like @samp{A}
9591 in the above example) is really multi-dimensional, rather than a
9592 single-dimensional array, so at least the dimensionality of the array
9593 is preserved.
9594
9595 Debuggers that understand Fortran should have no trouble with
9596 non-zero low bounds, but for non-Fortran debuggers, especially
9597 C debuggers, the above example might have a C equivalent of
9598 @samp{a[4305]}.
9599 This calculation is arrived at by eliminating the subtraction
9600 of the lower bound in the first parenthesized expression on each
9601 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
9602 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
9603 Actually, the implication of
9604 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
9605 but that @samp{a[20][10][5]} produces the equivalent of
9606 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
9607
9608 Come to think of it, perhaps
9609 the behavior is due to the debugger internally compensating for
9610 the lower bounds by offsetting the base address of @samp{a}, leaving
9611 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
9612 its first element as identified by subscripts equal to the
9613 corresponding lower bounds).
9614
9615 You know, maybe nobody really needs to use arrays.
9616
9617 @node Adjustable Arrays
9618 @section Adjustable Arrays (DIMENSION)
9619 @cindex arrays, adjustable
9620 @cindex adjustable arrays
9621 @cindex arrays, automatic
9622 @cindex automatic arrays
9623 @cindex DIMENSION statement
9624 @cindex statements, DIMENSION
9625 @cindex dimensioning arrays
9626 @cindex arrays, dimensioning
9627
9628 Adjustable and automatic arrays in Fortran require the implementation
9629 (in this
9630 case, the @code{g77} compiler) to ``memorize'' the expressions that
9631 dimension the arrays each time the procedure is invoked.
9632 This is so that subsequent changes to variables used in those
9633 expressions, made during execution of the procedure, do not
9634 have any effect on the dimensions of those arrays.
9635
9636 For example:
9637
9638 @example
9639 REAL ARRAY(5)
9640 DATA ARRAY/5*2/
9641 CALL X(ARRAY, 5)
9642 END
9643 SUBROUTINE X(A, N)
9644 DIMENSION A(N)
9645 N = 20
9646 PRINT *, N, A
9647 END
9648 @end example
9649
9650 @noindent
9651 Here, the implementation should, when running the program, print something
9652 like:
9653
9654 @example
9655 20   2.  2.  2.  2.  2.
9656 @end example
9657
9658 @noindent
9659 Note that this shows that while the value of @samp{N} was successfully
9660 changed, the size of the @samp{A} array remained at 5 elements.
9661
9662 To support this, @code{g77} generates code that executes before any user
9663 code (and before the internally generated computed @code{GOTO} to handle
9664 alternate entry points, as described below) that evaluates each
9665 (nonconstant) expression in the list of subscripts for an
9666 array, and saves the result of each such evaluation to be used when
9667 determining the size of the array (instead of re-evaluating the
9668 expressions).
9669
9670 So, in the above example, when @samp{X} is first invoked, code is
9671 executed that copies the value of @samp{N} to a temporary.
9672 And that same temporary serves as the actual high bound for the single
9673 dimension of the @samp{A} array (the low bound being the constant 1).
9674 Since the user program cannot (legitimately) change the value
9675 of the temporary during execution of the procedure, the size
9676 of the array remains constant during each invocation.
9677
9678 For alternate entry points, the code @code{g77} generates takes into
9679 account the possibility that a dummy adjustable array is not actually
9680 passed to the actual entry point being invoked at that time.
9681 In that case, the public procedure implementing the entry point
9682 passes to the master private procedure implementing all the
9683 code for the entry points a @code{NULL} pointer where a pointer to that
9684 adjustable array would be expected.
9685 The @code{g77}-generated code
9686 doesn't attempt to evaluate any of the expressions in the subscripts
9687 for an array if the pointer to that array is @code{NULL} at run time in
9688 such cases.
9689 (Don't depend on this particular implementation
9690 by writing code that purposely passes @code{NULL} pointers where the
9691 callee expects adjustable arrays, even if you know the callee
9692 won't reference the arrays---nor should you pass @code{NULL} pointers
9693 for any dummy arguments used in calculating the bounds of such
9694 arrays or leave undefined any values used for that purpose in
9695 COMMON---because the way @code{g77} implements these things might
9696 change in the future!)
9697
9698 @node Alternate Entry Points
9699 @section Alternate Entry Points (ENTRY)
9700 @cindex alternate entry points
9701 @cindex entry points
9702 @cindex ENTRY statement
9703 @cindex statements, ENTRY
9704
9705 The GBE does not understand the general concept of
9706 alternate entry points as Fortran provides via the ENTRY statement.
9707 @code{g77} gets around this by using an approach to compiling procedures
9708 having at least one @code{ENTRY} statement that is almost identical to the
9709 approach used by @code{f2c}.
9710 (An alternate approach could be used that
9711 would probably generate faster, but larger, code that would also
9712 be a bit easier to debug.)
9713
9714 Information on how @code{g77} implements @code{ENTRY} is provided for those
9715 trying to debug such code.
9716 The choice of implementation seems
9717 unlikely to affect code (compiled in other languages) that interfaces
9718 to such code.
9719
9720 @code{g77} compiles exactly one public procedure for the primary entry
9721 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
9722 That is, in terms of the public interface, there is no difference
9723 between
9724
9725 @example
9726 SUBROUTINE X
9727 END
9728 SUBROUTINE Y
9729 END
9730 @end example
9731
9732 @noindent
9733 and:
9734
9735 @example
9736 SUBROUTINE X
9737 ENTRY Y
9738 END
9739 @end example
9740
9741 The difference between the above two cases lies in the code compiled
9742 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
9743 for the second case, an extra internal procedure is compiled.
9744
9745 For every Fortran procedure with at least one @code{ENTRY}
9746 statement, @code{g77} compiles an extra procedure
9747 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
9748 the name of the primary entry point (which, in the above case,
9749 using the standard compiler options, would be @samp{x_} in C).
9750
9751 This extra procedure is compiled as a private procedure---that is,
9752 a procedure not accessible by name to separately compiled modules.
9753 It contains all the code in the program unit, including the code
9754 for the primary entry point plus for every entry point.
9755 (The code for each public procedure is quite short, and explained later.)
9756
9757 The extra procedure has some other interesting characteristics.
9758
9759 The argument list for this procedure is invented by @code{g77}.
9760 It contains
9761 a single integer argument named @samp{__g77_which_entrypoint},
9762 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
9763 entry point index---0 for the primary entry point, 1 for the
9764 first entry point (the first @code{ENTRY} statement encountered), 2 for
9765 the second entry point, and so on.
9766
9767 It also contains, for functions returning @code{CHARACTER} and
9768 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
9769 and for functions returning different types among the
9770 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
9771 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
9772 is expected at run time to contain a pointer to where to store
9773 the result of the entry point.
9774 For @code{CHARACTER} functions, this
9775 storage area is an array of the appropriate number of characters;
9776 for @code{COMPLEX} functions, it is the appropriate area for the return
9777 type; for multiple-return-type functions, it is a union of all the supported return
9778 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
9779 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
9780 is not supported by @code{g77}).
9781
9782 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
9783 by yet another argument named @samp{__g77_length} that, at run time,
9784 specifies the caller's expected length of the returned value.
9785 Note that only @code{CHARACTER*(*)} functions and entry points actually
9786 make use of this argument, even though it is always passed by
9787 all callers of public @code{CHARACTER} functions (since the caller does not
9788 generally know whether such a function is @code{CHARACTER*(*)} or whether
9789 there are any other callers that don't have that information).
9790
9791 The rest of the argument list is the union of all the arguments
9792 specified for all the entry points (in their usual forms, e.g.
9793 @code{CHARACTER} arguments have extra length arguments, all appended at
9794 the end of this list).
9795 This is considered the ``master list'' of
9796 arguments.
9797
9798 The code for this procedure has, before the code for the first
9799 executable statement, code much like that for the following Fortran
9800 statement:
9801
9802 @smallexample
9803        GOTO (100000,100001,100002), __g77_which_entrypoint
9804 100000 @dots{}code for primary entry point@dots{}
9805 100001 @dots{}code immediately following first ENTRY statement@dots{}
9806 100002 @dots{}code immediately following second ENTRY statement@dots{}
9807 @end smallexample
9808
9809 @noindent
9810 (Note that invalid Fortran statement labels and variable names
9811 are used in the above example to highlight the fact that it
9812 represents code generated by the @code{g77} internals, not code to be
9813 written by the user.)
9814
9815 It is this code that, when the procedure is called, picks which
9816 entry point to start executing.
9817
9818 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
9819 example), those procedures are fairly simple.
9820 Their interfaces
9821 are just like they would be if they were self-contained procedures
9822 (without @code{ENTRY}), of course, since that is what the callers
9823 expect.
9824 Their code consists of simply calling the private
9825 procedure, described above, with the appropriate extra arguments
9826 (the entry point index, and perhaps a pointer to a multiple-type-
9827 return variable, local to the public procedure, that contains
9828 all the supported returnable non-character types).
9829 For arguments
9830 that are not listed for a given entry point that are listed for
9831 other entry points, and therefore that are in the ``master list''
9832 for the private procedure, null pointers (in C, the @code{NULL} macro)
9833 are passed.
9834 Also, for entry points that are part of a multiple-type-
9835 returning function, code is compiled after the call of the private
9836 procedure to extract from the multi-type union the appropriate result,
9837 depending on the type of the entry point in question, returning
9838 that result to the original caller.
9839
9840 When debugging a procedure containing alternate entry points, you
9841 can either set a break point on the public procedure itself (e.g.
9842 a break point on @samp{X} or @samp{Y}) or on the private procedure that
9843 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
9844 If you do the former, you should use the debugger's command to
9845 ``step into'' the called procedure to get to the actual code; with
9846 the latter approach, the break point leaves you right at the
9847 actual code, skipping over the public entry point and its call
9848 to the private procedure (unless you have set a break point there
9849 as well, of course).
9850
9851 Further, the list of dummy arguments that is visible when the
9852 private procedure is active is going to be the expanded version
9853 of the list for whichever particular entry point is active,
9854 as explained above, and the way in which return values are
9855 handled might well be different from how they would be handled
9856 for an equivalent single-entry function.
9857
9858 @node Alternate Returns
9859 @section Alternate Returns (SUBROUTINE and RETURN)
9860 @cindex subroutines
9861 @cindex alternate returns
9862 @cindex SUBROUTINE statement
9863 @cindex statements, SUBROUTINE
9864 @cindex RETURN statement
9865 @cindex statements, RETURN
9866
9867 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
9868 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
9869 the C @code{int} type.
9870 The actual alternate-return arguments are omitted from the calling sequence.
9871 Instead, the caller uses
9872 the return value to do a rough equivalent of the Fortran
9873 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
9874 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
9875 function), and the callee just returns whatever integer
9876 is specified in the @code{RETURN} statement for the subroutine
9877 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
9878 by @samp{RETURN}
9879 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
9880
9881 @node Assigned Statement Labels
9882 @section Assigned Statement Labels (ASSIGN and GOTO)
9883 @cindex assigned statement labels
9884 @cindex statement labels, assigned
9885 @cindex ASSIGN statement
9886 @cindex statements, ASSIGN
9887 @cindex GOTO statement
9888 @cindex statements, GOTO
9889
9890 For portability to machines where a pointer (such as to a label,
9891 which is how @code{g77} implements @code{ASSIGN} and its relatives,
9892 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
9893 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
9894 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
9895 than it does the numerical value in that variable, unless the
9896 variable is wide enough (can hold enough bits).
9897
9898 In particular, while @code{g77} implements
9899
9900 @example
9901 I = 10
9902 @end example
9903
9904 @noindent
9905 as, in C notation, @samp{i = 10;}, it implements
9906
9907 @example
9908 ASSIGN 10 TO I
9909 @end example
9910
9911 @noindent
9912 as, in GNU's extended C notation (for the label syntax),
9913 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
9914 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
9915 actually generate the name @samp{L10} or any other name like that,
9916 since debuggers cannot access labels anyway).
9917
9918 While this currently means that an @code{ASSIGN} statement does not
9919 overwrite the numeric contents of its target variable, @emph{do not}
9920 write any code depending on this feature.
9921 @code{g77} has already changed this implementation across
9922 versions and might do so in the future.
9923 This information is provided only to make debugging Fortran programs
9924 compiled with the current version of @code{g77} somewhat easier.
9925 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
9926 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
9927 means @code{g77} has decided it can store the pointer to the label directly
9928 into @samp{I} itself.
9929
9930 @xref{Ugly Assigned Labels}, for information on a command-line option
9931 to force @code{g77} to use the same storage for both normal and
9932 assigned-label uses of a variable.
9933
9934 @node Run-time Library Errors
9935 @section Run-time Library Errors
9936 @cindex IOSTAT=
9937 @cindex error values
9938 @cindex error messages
9939 @cindex messages, run-time
9940 @cindex I/O, errors
9941
9942 The @code{libg2c} library currently has the following table to relate
9943 error code numbers, returned in @code{IOSTAT=} variables, to messages.
9944 This information should, in future versions of this document, be
9945 expanded upon to include detailed descriptions of each message.
9946
9947 In line with good coding practices, any of the numbers in the
9948 list below should @emph{not} be directly written into Fortran
9949 code you write.
9950 Instead, make a separate @code{INCLUDE} file that defines
9951 @code{PARAMETER} names for them, and use those in your code,
9952 so you can more easily change the actual numbers in the future.
9953
9954 The information below is culled from the definition
9955 of @samp{F_err} in @file{f/runtime/libI77/err.c} in the
9956 @code{g77} source tree.
9957
9958 @smallexample
9959 100: "error in format"
9960 101: "illegal unit number"
9961 102: "formatted io not allowed"
9962 103: "unformatted io not allowed"
9963 104: "direct io not allowed"
9964 105: "sequential io not allowed"
9965 106: "can't backspace file"
9966 107: "null file name"
9967 108: "can't stat file"
9968 109: "unit not connected"
9969 110: "off end of record"
9970 111: "truncation failed in endfile"
9971 112: "incomprehensible list input"
9972 113: "out of free space"
9973 114: "unit not connected"
9974 115: "read unexpected character"
9975 116: "bad logical input field"
9976 117: "bad variable type"
9977 118: "bad namelist name"
9978 119: "variable not in namelist"
9979 120: "no end record"
9980 121: "variable count incorrect"
9981 122: "subscript for scalar variable"
9982 123: "invalid array section"
9983 124: "substring out of bounds"
9984 125: "subscript out of bounds"
9985 126: "can't read file"
9986 127: "can't write file"
9987 128: "'new' file exists"
9988 129: "can't append to file"
9989 130: "non-positive record number"
9990 131: "I/O started while already doing I/O"
9991 @end smallexample
9992
9993 @node Collected Fortran Wisdom
9994 @chapter Collected Fortran Wisdom
9995 @cindex wisdom
9996 @cindex legacy code
9997 @cindex code, legacy
9998 @cindex writing code
9999 @cindex code, writing
10000
10001 Most users of @code{g77} can be divided into two camps:
10002
10003 @itemize @bullet
10004 @item
10005 Those writing new Fortran code to be compiled by @code{g77}.
10006
10007 @item
10008 Those using @code{g77} to compile existing, ``legacy'' code.
10009 @end itemize
10010
10011 Users writing new code generally understand most of the necessary
10012 aspects of Fortran to write ``mainstream'' code, but often need
10013 help deciding how to handle problems, such as the construction
10014 of libraries containing @code{BLOCK DATA}.
10015
10016 Users dealing with ``legacy'' code sometimes don't have much
10017 experience with Fortran, but believe that the code they're compiling
10018 already works when compiled by other compilers (and might
10019 not understand why, as is sometimes the case, it doesn't work
10020 when compiled by @code{g77}).
10021
10022 The following information is designed to help users do a better job
10023 coping with existing, ``legacy'' Fortran code, and with writing
10024 new code as well.
10025
10026 @menu
10027 * Advantages Over f2c::        If @code{f2c} is so great, why @code{g77}?
10028 * Block Data and Libraries::   How @code{g77} solves a common problem.
10029 * Loops::                      Fortran @code{DO} loops surprise many people.
10030 * Working Programs::           Getting programs to work should be done first.
10031 * Overly Convenient Options::  Temptations to avoid, habits to not form.
10032 * Faster Programs::            Everybody wants these, but at what cost?
10033 @end menu
10034
10035 @node Advantages Over f2c
10036 @section Advantages Over f2c
10037
10038 Without @code{f2c}, @code{g77} would have taken much longer to
10039 do and probably not been as good for quite a while.
10040 Sometimes people who notice how much @code{g77} depends on, and
10041 documents encouragement to use, @code{f2c} ask why @code{g77}
10042 was created if @code{f2c} already existed.
10043
10044 This section gives some basic answers to these questions, though it
10045 is not intended to be comprehensive.
10046
10047 @menu
10048 * Language Extensions::  Features used by Fortran code.
10049 * Compiler Options::     Features helpful during development.
10050 * Compiler Speed::       Speed of the compilation process.
10051 * Program Speed::        Speed of the generated, optimized code.
10052 * Ease of Debugging::    Debugging ease-of-use at the source level.
10053 * Character and Hollerith Constants::  A byte saved is a byte earned.
10054 @end menu
10055
10056 @node Language Extensions
10057 @subsection Language Extensions
10058
10059 @code{g77} offers several extensions to the Fortran language that @code{f2c}
10060 doesn't.
10061
10062 However, @code{f2c} offers a few that @code{g77} doesn't, like
10063 fairly complete support for @code{INTEGER*2}.
10064 It is expected that @code{g77} will offer some or all of these missing
10065 features at some time in the future.
10066 (Version 0.5.18 of @code{g77} offers some rudimentary support for some
10067 of these features.)
10068
10069 @node Compiler Options
10070 @subsection Compiler Options
10071
10072 @code{g77} offers a whole bunch of compiler options that @code{f2c} doesn't.
10073
10074 However, @code{f2c} offers a few that @code{g77} doesn't, like an
10075 option to generate code to check array subscripts at run time.
10076 It is expected that @code{g77} will offer some or all of these
10077 missing options at some time in the future.
10078
10079 @node Compiler Speed
10080 @subsection Compiler Speed
10081
10082 Saving the steps of writing and then rereading C code is a big reason
10083 why @code{g77} should be able to compile code much faster than using
10084 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
10085
10086 However, due to @code{g77}'s youth, lots of self-checking is still being
10087 performed.
10088 As a result, this improvement is as yet unrealized
10089 (though the potential seems to be there for quite a big speedup
10090 in the future).
10091 It is possible that, as of version 0.5.18, @code{g77}
10092 is noticeably faster compiling many Fortran source files than using
10093 @code{f2c} in conjunction with @code{gcc}.
10094
10095 @node Program Speed
10096 @subsection Program Speed
10097
10098 @code{g77} has the potential to better optimize code than @code{f2c},
10099 even when @code{gcc} is used to compile the output of @code{f2c},
10100 because @code{f2c} must necessarily
10101 translate Fortran into a somewhat lower-level language (C) that cannot
10102 preserve all the information that is potentially useful for optimization,
10103 while @code{g77} can gather, preserve, and transmit that information directly
10104 to the GBE.
10105
10106 For example, @code{g77} implements @code{ASSIGN} and assigned
10107 @code{GOTO} using direct assignment of pointers to labels and direct
10108 jumps to labels, whereas @code{f2c} maps the assigned labels to
10109 integer values and then uses a C @code{switch} statement to encode
10110 the assigned @code{GOTO} statements.
10111
10112 However, as is typical, theory and reality don't quite match, at least
10113 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
10114 can generate code that is faster than @code{g77}.
10115
10116 Version 0.5.18 of @code{g77} offered default
10117 settings and options, via patches to the @code{gcc}
10118 back end, that allow for better program speed, though
10119 some of these improvements also affected the performance
10120 of programs translated by @code{f2c} and then compiled
10121 by @code{g77}'s version of @code{gcc}.
10122
10123 Version 0.5.20 of @code{g77} offers further performance
10124 improvements, at least one of which (alias analysis) is
10125 not generally applicable to @code{f2c} (though @code{f2c}
10126 could presumably be changed to also take advantage of
10127 this new capability of the @code{gcc} back end, assuming
10128 this is made available in an upcoming release of @code{gcc}).
10129
10130 @node Ease of Debugging
10131 @subsection Ease of Debugging
10132
10133 Because @code{g77} compiles directly to assembler code like @code{gcc},
10134 instead of translating to an intermediate language (C) as does @code{f2c},
10135 support for debugging can be better for @code{g77} than @code{f2c}.
10136
10137 However, although @code{g77} might be somewhat more ``native'' in terms of
10138 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
10139 of things ``not quite right''.
10140 Many of the important ones should be resolved in the near future.
10141
10142 For example, @code{g77} doesn't have to worry about reserved names
10143 like @code{f2c} does.
10144 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
10145 translate this to something @emph{other} than
10146 @samp{for = while;}, because C reserves those words.
10147
10148 However, @code{g77} does still uses things like an extra level of indirection
10149 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
10150 yet support multiple entry points.
10151
10152 Another example is that, given
10153
10154 @smallexample
10155 COMMON A, B
10156 EQUIVALENCE (B, C)
10157 @end smallexample
10158
10159 @noindent
10160 the @code{g77} user should be able to access the variables directly, by name,
10161 without having to traverse C-like structures and unions, while @code{f2c}
10162 is unlikely to ever offer this ability (due to limitations in the
10163 C language).
10164
10165 However, due to apparent bugs in the back end, @code{g77} currently doesn't
10166 take advantage of this facility at all---it doesn't emit any debugging
10167 information for @code{COMMON} and @code{EQUIVALENCE} areas,
10168 other than information
10169 on the array of @code{char} it creates (and, in the case
10170 of local @code{EQUIVALENCE}, names) for each such area.
10171
10172 Yet another example is arrays.
10173 @code{g77} represents them to the debugger
10174 using the same ``dimensionality'' as in the source code, while @code{f2c}
10175 must necessarily convert them all to one-dimensional arrays to fit
10176 into the confines of the C language.
10177 However, the level of support
10178 offered by debuggers for interactive Fortran-style access to arrays
10179 as compiled by @code{g77} can vary widely.
10180 In some cases, it can actually
10181 be an advantage that @code{f2c} converts everything to widely supported
10182 C semantics.
10183
10184 In fairness, @code{g77} could do many of the things @code{f2c} does
10185 to get things working at least as well as @code{f2c}---for now,
10186 the developers prefer making @code{g77} work the
10187 way they think it is supposed to, and finding help improving the
10188 other products (the back end of @code{gcc}; @code{gdb}; and so on)
10189 to get things working properly.
10190
10191 @node Character and Hollerith Constants
10192 @subsection Character and Hollerith Constants
10193 @cindex character constants
10194 @cindex constants, character
10195 @cindex Hollerith constants
10196 @cindex constants, Hollerith
10197 @cindex trailing null byte
10198 @cindex null byte, trailing
10199 @cindex zero byte, trailing
10200
10201 To avoid the extensive hassle that would be needed to avoid this,
10202 @code{f2c} uses C character constants to encode character and Hollerith
10203 constants.
10204 That means a constant like @samp{'HELLO'} is translated to
10205 @samp{"hello"} in C, which further means that an extra null byte is
10206 present at the end of the constant.
10207 This null byte is superfluous.
10208
10209 @code{g77} does not generate such null bytes.
10210 This represents significant
10211 savings of resources, such as on systems where @file{/dev/null} or
10212 @file{/dev/zero} represent bottlenecks in the systems' performance,
10213 because @code{g77} simply asks for fewer zeros from the operating
10214 system than @code{f2c}.
10215 (Avoiding spurious use of zero bytes, each byte typically have
10216 eight zero bits, also reduces the liabilities in case
10217 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
10218
10219 @node Block Data and Libraries
10220 @section Block Data and Libraries
10221 @cindex block data and libraries
10222 @cindex BLOCK DATA statement
10223 @cindex statements, BLOCK DATA
10224 @cindex libraries, containing BLOCK DATA
10225 @cindex f2c compatibility
10226 @cindex compatibility, f2c
10227
10228 To ensure that block data program units are linked, especially a concern
10229 when they are put into libraries, give each one a name (as in
10230 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
10231 statement in every program unit that uses any common block
10232 initialized by the corresponding @code{BLOCK DATA}.
10233 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
10234 @code{SUBROUTINE},
10235 that is, it generates an actual procedure having the appropriate name.
10236 The procedure does nothing but return immediately if it happens to be
10237 called.
10238 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
10239 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
10240 in the program and ensures that by generating a
10241 reference to it so the linker will make sure it is present.
10242 (Specifically, @code{g77} outputs in the data section a static pointer to the
10243 external name @samp{FOO}.)
10244
10245 The implementation @code{g77} currently uses to make this work is
10246 one of the few things not compatible with @code{f2c} as currently
10247 shipped.
10248 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
10249 issue a warning that @samp{FOO} is not otherwise referenced,
10250 and, for @samp{BLOCK DATA FOO},
10251 @code{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
10252 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
10253 this particular case.
10254 If you use @code{f2c} to compile @samp{BLOCK DATA FOO},
10255 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
10256 will result in an unresolved reference when linked.
10257 If you do the
10258 opposite, then @samp{FOO} might not be linked in under various
10259 circumstances (such as when @samp{FOO} is in a library, or you're
10260 using a ``clever'' linker---so clever, it produces a broken program
10261 with little or no warning by omitting initializations of global data
10262 because they are contained in unreferenced procedures).
10263
10264 The changes you make to your code to make @code{g77} handle this situation,
10265 however, appear to be a widely portable way to handle it.
10266 That is, many systems permit it (as they should, since the
10267 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
10268 is a block data program unit), and of the ones
10269 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
10270 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
10271 program units.
10272
10273 Here is the recommended approach to modifying a program containing
10274 a program unit such as the following:
10275
10276 @smallexample
10277 BLOCK DATA FOO
10278 COMMON /VARS/ X, Y, Z
10279 DATA X, Y, Z / 3., 4., 5. /
10280 END
10281 @end smallexample
10282
10283 @noindent
10284 If the above program unit might be placed in a library module, then
10285 ensure that every program unit in every program that references that
10286 particular @code{COMMON} area uses the @code{EXTERNAL} statement
10287 to force the area to be initialized.
10288
10289 For example, change a program unit that starts with
10290
10291 @smallexample
10292 INTEGER FUNCTION CURX()
10293 COMMON /VARS/ X, Y, Z
10294 CURX = X
10295 END
10296 @end smallexample
10297
10298 @noindent
10299 so that it uses the @code{EXTERNAL} statement, as in:
10300
10301 @smallexample
10302 INTEGER FUNCTION CURX()
10303 COMMON /VARS/ X, Y, Z
10304 EXTERNAL FOO
10305 CURX = X
10306 END
10307 @end smallexample
10308
10309 @noindent
10310 That way, @samp{CURX} is compiled by @code{g77} (and many other
10311 compilers) so that the linker knows it must include @samp{FOO},
10312 the @code{BLOCK DATA} program unit that sets the initial values
10313 for the variables in @samp{VAR}, in the executable program.
10314
10315 @node Loops
10316 @section Loops
10317 @cindex DO statement
10318 @cindex statements, DO
10319 @cindex trips, number of
10320 @cindex number of trips
10321
10322 The meaning of a @code{DO} loop in Fortran is precisely specified
10323 in the Fortran standard@dots{}and is quite different from what
10324 many programmers might expect.
10325
10326 In particular, Fortran iterative @code{DO} loops are implemented as if
10327 the number of trips through the loop is calculated @emph{before}
10328 the loop is entered.
10329
10330 The number of trips for a loop is calculated from the @var{start},
10331 @var{end}, and @var{increment} values specified in a statement such as:
10332
10333 @smallexample
10334 DO @var{iter} = @var{start}, @var{end}, @var{increment}
10335 @end smallexample
10336
10337 @noindent
10338 The trip count is evaluated using a fairly simple formula
10339 based on the three values following the @samp{=} in the
10340 statement, and it is that trip count that is effectively
10341 decremented during each iteration of the loop.
10342 If, at the beginning of an iteration of the loop, the
10343 trip count is zero or negative, the loop terminates.
10344 The per-loop-iteration modifications to @var{iter} are not
10345 related to determining whether to terminate the loop.
10346
10347 There are two important things to remember about the trip
10348 count:
10349
10350 @itemize @bullet
10351 @item
10352 It can be @emph{negative}, in which case it is
10353 treated as if it was zero---meaning the loop is
10354 not executed at all.
10355
10356 @item
10357 The type used to @emph{calculate} the trip count
10358 is the same type as @var{iter}, but the final
10359 calculation, and thus the type of the trip
10360 count itself, always is @code{INTEGER(KIND=1)}.
10361 @end itemize
10362
10363 These two items mean that there are loops that cannot
10364 be written in straightforward fashion using the Fortran @code{DO}.
10365
10366 For example, on a system with the canonical 32-bit two's-complement
10367 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
10368
10369 @smallexample
10370 DO I = -2000000000, 2000000000
10371 @end smallexample
10372
10373 @noindent
10374 Although the @var{start} and @var{end} values are well within
10375 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
10376 The expected trip count is 40000000001, which is outside
10377 the range of @code{INTEGER(KIND=1)} on many systems.
10378
10379 Instead, the above loop should be constructed this way:
10380
10381 @smallexample
10382 I = -2000000000
10383 DO
10384   IF (I .GT. 2000000000) EXIT
10385   @dots{}
10386   I = I + 1
10387 END DO
10388 @end smallexample
10389
10390 @noindent
10391 The simple @code{DO} construct and the @code{EXIT} statement
10392 (used to leave the innermost loop)
10393 are F90 features that @code{g77} supports.
10394
10395 Some Fortran compilers have buggy implementations of @code{DO},
10396 in that they don't follow the standard.
10397 They implement @code{DO} as a straightforward translation
10398 to what, in C, would be a @code{for} statement.
10399 Instead of creating a temporary variable to hold the trip count
10400 as calculated at run time, these compilers
10401 use the iteration variable @var{iter} to control
10402 whether the loop continues at each iteration.
10403
10404 The bug in such an implementation shows up when the
10405 trip count is within the range of the type of @var{iter},
10406 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
10407 exceeds that range.  For example:
10408
10409 @smallexample
10410 DO I = 2147483600, 2147483647
10411 @end smallexample
10412
10413 @noindent
10414 A loop started by the above statement will work as implemented
10415 by @code{g77}, but the use, by some compilers, of a
10416 more C-like implementation akin to
10417
10418 @smallexample
10419 for (i = 2147483600; i <= 2147483647; ++i)
10420 @end smallexample
10421
10422 @noindent
10423 produces a loop that does not terminate, because @samp{i}
10424 can never be greater than 2147483647, since incrementing it
10425 beyond that value overflows @samp{i}, setting it to -2147483648.
10426 This is a large, negative number that still is less than 2147483647.
10427
10428 Another example of unexpected behavior of @code{DO} involves
10429 using a nonintegral iteration variable @var{iter}, that is,
10430 a @code{REAL} variable.
10431 Consider the following program:
10432
10433 @smallexample
10434       DATA BEGIN, END, STEP /.1, .31, .007/
10435       DO 10 R = BEGIN, END, STEP
10436          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
10437          PRINT *,R
10438 10    CONTINUE
10439       PRINT *,'LAST = ',R
10440       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
10441       END
10442 @end smallexample
10443
10444 @noindent
10445 A C-like view of @code{DO} would hold that the two ``exclamatory''
10446 @code{PRINT} statements are never executed.
10447 However, this is the output of running the above program
10448 as compiled by @code{g77} on a GNU/Linux ix86 system:
10449
10450 @smallexample
10451  .100000001
10452  .107000001
10453  .114
10454  .120999999
10455  @dots{}
10456  .289000005
10457  .296000004
10458  .303000003
10459 LAST =   .310000002
10460  .310000002 .LE.   .310000002!!
10461 @end smallexample
10462
10463 Note that one of the two checks in the program turned up
10464 an apparent violation of the programmer's expectation---yet,
10465 the loop is correctly implemented by @code{g77}, in that
10466 it has 30 iterations.
10467 This trip count of 30 is correct when evaluated using
10468 the floating-point representations for the @var{begin},
10469 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
10470 ix86 are used.
10471 On other systems, an apparently more accurate trip count
10472 of 31 might result, but, nevertheless, @code{g77} is
10473 faithfully following the Fortran standard, and the result
10474 is not what the author of the sample program above
10475 apparently expected.
10476 (Such other systems might, for different values in the @code{DATA}
10477 statement, violate the other programmer's expectation,
10478 for example.)
10479
10480 Due to this combination of imprecise representation
10481 of floating-point values and the often-misunderstood
10482 interpretation of @code{DO} by standard-conforming
10483 compilers such as @code{g77}, use of @code{DO} loops
10484 with @code{REAL} iteration
10485 variables is not recommended.
10486 Such use can be caught by specifying @samp{-Wsurprising}.
10487 @xref{Warning Options}, for more information on this
10488 option.
10489
10490 @node Working Programs
10491 @section Working Programs
10492
10493 Getting Fortran programs to work in the first place can be
10494 quite a challenge---even when the programs already work on
10495 other systems, or when using other compilers.
10496
10497 @code{g77} offers some facilities that might be useful for
10498 tracking down bugs in such programs.
10499
10500 @menu
10501 * Not My Type::
10502 * Variables Assumed To Be Zero::
10503 * Variables Assumed To Be Saved::
10504 * Unwanted Variables::
10505 * Unused Arguments::
10506 * Surprising Interpretations of Code::
10507 * Aliasing Assumed To Work::
10508 * Output Assumed To Flush::
10509 * Large File Unit Numbers::
10510 * Floating-point precision::
10511 * Inconsistent Calling Sequences::
10512 @end menu
10513
10514 @node Not My Type
10515 @subsection Not My Type
10516 @cindex mistyped variables
10517 @cindex variables, mistyped
10518 @cindex mistyped functions
10519 @cindex functions, mistyped
10520 @cindex implicit typing
10521
10522 A fruitful source of bugs in Fortran source code is use, or
10523 mis-use, of Fortran's implicit-typing feature, whereby the
10524 type of a variable, array, or function is determined by the
10525 first character of its name.
10526
10527 Simple cases of this include statements like @samp{LOGX=9.227},
10528 without a statement such as @samp{REAL LOGX}.
10529 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
10530 type, with the result of the assignment being that it is given
10531 the value @samp{9}.
10532
10533 More involved cases include a function that is defined starting
10534 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
10535 Any caller of this function that does not also declare @samp{IPS}
10536 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
10537 is likely to assume it returns
10538 @code{INTEGER}, or some other type, leading to invalid results
10539 or even program crashes.
10540
10541 The @samp{-Wimplicit} option might catch failures to
10542 properly specify the types of
10543 variables, arrays, and functions in the code.
10544
10545 However, in code that makes heavy use of Fortran's
10546 implicit-typing facility, this option might produce so
10547 many warnings about cases that are working, it would be
10548 hard to find the one or two that represent bugs.
10549 This is why so many experienced Fortran programmers strongly
10550 recommend widespread use of the @code{IMPLICIT NONE} statement,
10551 despite it not being standard FORTRAN 77, to completely turn
10552 off implicit typing.
10553 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
10554 FORTRAN 77 compilers.)
10555
10556 Note that @samp{-Wimplicit} catches only implicit typing of
10557 @emph{names}.
10558 It does not catch implicit typing of expressions such
10559 as @samp{X**(2/3)}.
10560 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
10561 is equivalent to @samp{X**0}, due to the way Fortran expressions
10562 are given types and then evaluated.
10563 (In this particular case, the programmer probably wanted
10564 @samp{X**(2./3.)}.)
10565
10566 @node Variables Assumed To Be Zero
10567 @subsection Variables Assumed To Be Zero
10568 @cindex zero-initialized variables
10569 @cindex variables, assumed to be zero
10570 @cindex uninitialized variables
10571
10572 Many Fortran programs were developed on systems that provided
10573 automatic initialization of all, or some, variables and arrays
10574 to zero.
10575 As a result, many of these programs depend, sometimes
10576 inadvertently, on this behavior, though to do so violates
10577 the Fortran standards.
10578
10579 You can ask @code{g77} for this behavior by specifying the
10580 @samp{-finit-local-zero} option when compiling Fortran code.
10581 (You might want to specify @samp{-fno-automatic} as well,
10582 to avoid code-size inflation for non-optimized compilations.)
10583
10584 Note that a program that works better when compiled with the
10585 @samp{-finit-local-zero} option
10586 is almost certainly depending on a particular system's,
10587 or compiler's, tendency to initialize some variables to zero.
10588 It might be worthwhile finding such cases and fixing them,
10589 using techniques such as compiling with the @samp{-O -Wuninitialized}
10590 options using @code{g77}.
10591
10592 @node Variables Assumed To Be Saved
10593 @subsection Variables Assumed To Be Saved
10594 @cindex variables, retaining values across calls
10595 @cindex saved variables
10596 @cindex static variables
10597
10598 Many Fortran programs were developed on systems that
10599 saved the values of all, or some, variables and arrays
10600 across procedure calls.
10601 As a result, many of these programs depend, sometimes
10602 inadvertently, on being able to assign a value to a
10603 variable, perform a @code{RETURN} to a calling procedure,
10604 and, upon subsequent invocation, reference the previously
10605 assigned variable to obtain the value.
10606
10607 They expect this despite not using the @code{SAVE} statement
10608 to specify that the value in a variable is expected to survive
10609 procedure returns and calls.
10610 Depending on variables and arrays to retain values across
10611 procedure calls without using @code{SAVE} to require it violates
10612 the Fortran standards.
10613
10614 You can ask @code{g77} to assume @code{SAVE} is specified for all
10615 relevant (local) variables and arrays by using the
10616 @samp{-fno-automatic} option.
10617
10618 Note that a program that works better when compiled with the
10619 @samp{-fno-automatic} option
10620 is almost certainly depending on not having to use
10621 the @code{SAVE} statement as required by the Fortran standard.
10622 It might be worthwhile finding such cases and fixing them,
10623 using techniques such as compiling with the @samp{-O -Wuninitialized}
10624 options using @code{g77}.
10625
10626 @node Unwanted Variables
10627 @subsection Unwanted Variables
10628
10629 The @samp{-Wunused} option can find bugs involving
10630 implicit typing, sometimes
10631 more easily than using @samp{-Wimplicit} in code that makes
10632 heavy use of implicit typing.
10633 An unused variable or array might indicate that the
10634 spelling for its declaration is different from that of
10635 its intended uses.
10636
10637 Other than cases involving typos, unused variables rarely
10638 indicate actual bugs in a program.
10639 However, investigating such cases thoroughly has, on occasion,
10640 led to the discovery of code that had not been completely
10641 written---where the programmer wrote declarations as needed
10642 for the whole algorithm, wrote some or even most of the code
10643 for that algorithm, then got distracted and forgot that the
10644 job was not complete.
10645
10646 @node Unused Arguments
10647 @subsection Unused Arguments
10648 @cindex unused arguments
10649 @cindex arguments, unused
10650
10651 As with unused variables, It is possible that unused arguments
10652 to a procedure might indicate a bug.
10653 Compile with @samp{-W -Wunused} option to catch cases of
10654 unused arguments.
10655
10656 Note that @samp{-W} also enables warnings regarding overflow
10657 of floating-point constants under certain circumstances.
10658
10659 @node Surprising Interpretations of Code
10660 @subsection Surprising Interpretations of Code
10661
10662 The @samp{-Wsurprising} option can help find bugs involving
10663 expression evaluation or in
10664 the way @code{DO} loops with non-integral iteration variables
10665 are handled.
10666 Cases found by this option might indicate a difference of
10667 interpretation between the author of the code involved, and
10668 a standard-conforming compiler such as @code{g77}.
10669 Such a difference might produce actual bugs.
10670
10671 In any case, changing the code to explicitly do what the
10672 programmer might have expected it to do, so @code{g77} and
10673 other compilers are more likely to follow the programmer's
10674 expectations, might be worthwhile, especially if such changes
10675 make the program work better.
10676
10677 @node Aliasing Assumed To Work
10678 @subsection Aliasing Assumed To Work
10679 @cindex -falias-check option
10680 @cindex options, -falias-check
10681 @cindex -fargument-alias option
10682 @cindex options, -fargument-alias
10683 @cindex -fargument-noalias option
10684 @cindex options, -fargument-noalias
10685 @cindex -fno-argument-noalias-global option
10686 @cindex options, -fno-argument-noalias-global
10687 @cindex aliasing
10688 @cindex anti-aliasing
10689 @cindex overlapping arguments
10690 @cindex overlays
10691 @cindex association, storage
10692 @cindex storage association
10693 @cindex scheduling of reads and writes
10694 @cindex reads and writes, scheduling
10695
10696 The @samp{-falias-check}, @samp{-fargument-alias},
10697 @samp{-fargument-noalias},
10698 and @samp{-fno-argument-noalias-global} options,
10699 introduced in version 0.5.20 and
10700 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
10701 were withdrawn as of @code{g77} version 0.5.23
10702 due to their not being supported by @code{gcc} version 2.8.
10703
10704 These options, which control the assumptions regarding aliasing
10705 (overlapping) of writes and reads to main memory (core) made
10706 by the @code{gcc} back end,
10707 might well be added back (in some form) in a future version
10708 of @code{gcc}.
10709
10710 However, these options @emph{are} supported by @code{egcs}.
10711
10712 The information below still is useful, but applies to
10713 only those versions of @code{g77} that support the
10714 alias analysis implied by support for these options.
10715
10716 These options are effective only when compiling with @samp{-O}
10717 (specifying any level other than @samp{-O0})
10718 or with @samp{-falias-check}.
10719
10720 The default for Fortran code is @samp{-fargument-noalias-global}.
10721 (The default for C code and code written in other C-based languages
10722 is @samp{-fargument-alias}.
10723 These defaults apply regardless of whether you use @code{g77} or
10724 @code{gcc} to compile your code.)
10725
10726 Note that, on some systems, compiling with @samp{-fforce-addr} in
10727 effect can produce more optimal code when the default aliasing
10728 options are in effect (and when optimization is enabled).
10729
10730 If your program is not working when compiled with optimization,
10731 it is possible it is violating the Fortran standards (77 and 90)
10732 by relying on the ability to ``safely'' modify variables and
10733 arrays that are aliased, via procedure calls, to other variables
10734 and arrays, without using @code{EQUIVALENCE} to explicitly
10735 set up this kind of aliasing.
10736
10737 (The FORTRAN 77 standard's prohibition of this sort of
10738 overlap, generally referred to therein as ``storage
10739 assocation'', appears in Sections 15.9.3.6.
10740 This prohibition allows implementations, such as @code{g77},
10741 to, for example, implement the passing of procedures and
10742 even values in @code{COMMON} via copy operations into local,
10743 perhaps more efficiently accessed temporaries at entry to a
10744 procedure, and, where appropriate, via copy operations back
10745 out to their original locations in memory at exit from that
10746 procedure, without having to take into consideration the
10747 order in which the local copies are updated by the code,
10748 among other things.)
10749
10750 To test this hypothesis, try compiling your program with
10751 the @samp{-fargument-alias} option, which causes the
10752 compiler to revert to assumptions essentially the same as
10753 made by versions of @code{g77} prior to 0.5.20.
10754
10755 If the program works using this option, that strongly suggests
10756 that the bug is in your program.
10757 Finding and fixing the bug(s) should result in a program that
10758 is more standard-conforming and that can be compiled by @code{g77}
10759 in a way that results in a faster executable.
10760
10761 (You might want to try compiling with @samp{-fargument-noalias},
10762 a kind of half-way point, to see if the problem is limited to
10763 aliasing between dummy arguments and @code{COMMON} variables---this
10764 option assumes that such aliasing is not done, while still allowing
10765 aliasing among dummy arguments.)
10766
10767 An example of aliasing that is invalid according to the standards
10768 is shown in the following program, which might @emph{not} produce
10769 the expected results when executed:
10770
10771 @smallexample
10772 I = 1
10773 CALL FOO(I, I)
10774 PRINT *, I
10775 END
10776
10777 SUBROUTINE FOO(J, K)
10778 J = J + K
10779 K = J * K
10780 PRINT *, J, K
10781 END
10782 @end smallexample
10783
10784 The above program attempts to use the temporary aliasing of the
10785 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
10786 pathological behavior---the simultaneous changing of the values
10787 of @emph{both} @samp{J} and @samp{K} when either one of them
10788 is written.
10789
10790 The programmer likely expects the program to print these values:
10791
10792 @example
10793 2  4
10794 4
10795 @end example
10796
10797 However, since the program is not standard-conforming, an
10798 implementation's behavior when running it is undefined, because
10799 subroutine @samp{FOO} modifies at least one of the arguments,
10800 and they are aliased with each other.
10801 (Even if one of the assignment statements was deleted, the
10802 program would still violate these rules.
10803 This kind of on-the-fly aliasing is permitted by the standard
10804 only when none of the aliased items are defined, or written,
10805 while the aliasing is in effect.)
10806
10807 As a practical example, an optimizing compiler might schedule
10808 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
10809 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
10810 resulting in the following output:
10811
10812 @example
10813 2  2
10814 2
10815 @end example
10816
10817 Essentially, compilers are promised (by the standard and, therefore,
10818 by programmers who write code they claim to be standard-conforming)
10819 that if they cannot detect aliasing via static analysis of a single
10820 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
10821 such aliasing exists.
10822 In such cases, compilers are free to assume that an assignment to
10823 one variable will not change the value of another variable, allowing
10824 it to avoid generating code to re-read the value of the other
10825 variable, to re-schedule reads and writes, and so on, to produce
10826 a faster executable.
10827
10828 The same promise holds true for arrays (as seen by the called
10829 procedure)---an element of one dummy array cannot be aliased
10830 with, or overlap, any element of another dummy array or be
10831 in a @code{COMMON} area known to the procedure.
10832
10833 (These restrictions apply only when the procedure defines, or
10834 writes to, one of the aliased variables or arrays.)
10835
10836 Unfortunately, there is no way to find @emph{all} possible cases of
10837 violations of the prohibitions against aliasing in Fortran code.
10838 Static analysis is certainly imperfect, as is run-time analysis,
10839 since neither can catch all violations.
10840 (Static analysis can catch all likely violations, and some that
10841 might never actually happen, while run-time analysis can catch
10842 only those violations that actually happen during a particular run.
10843 Neither approach can cope with programs mixing Fortran code with
10844 routines written in other languages, however.)
10845
10846 Currently, @code{g77} provides neither static nor run-time facilities
10847 to detect any cases of this problem, although other products might.
10848 Run-time facilities are more likely to be offered by future
10849 versions of @code{g77}, though patches improving @code{g77} so that
10850 it provides either form of detection are welcome.
10851
10852 @node Output Assumed To Flush
10853 @subsection Output Assumed To Flush
10854 @cindex ALWAYS_FLUSH
10855 @cindex synchronous write errors
10856 @cindex disk full
10857 @cindex flushing output
10858 @cindex fflush()
10859 @cindex I/O, flushing
10860 @cindex output, flushing
10861 @cindex writes, flushing
10862 @cindex NFS
10863 @cindex network file system
10864
10865 For several versions prior to 0.5.20, @code{g77} configured its
10866 version of the @code{libf2c} run-time library so that one of
10867 its configuration macros, @samp{ALWAYS_FLUSH}, was defined.
10868
10869 This was done as a result of a belief that many programs expected
10870 output to be flushed to the operating system (under UNIX, via
10871 the @code{fflush()} library call) with the result that errors,
10872 such as disk full, would be immediately flagged via the
10873 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
10874
10875 Because of the adverse effects this approach had on the performance
10876 of many programs, @code{g77} no longer configures @code{libf2c}
10877 (now named @code{libg2c} in its @code{g77} incarnation)
10878 to always flush output.
10879
10880 If your program depends on this behavior, either insert the
10881 appropriate @samp{CALL FLUSH} statements, or modify the sources
10882 to the @code{libg2c}, rebuild and reinstall @code{g77}, and
10883 relink your programs with the modified library.
10884
10885 (Ideally, @code{libg2c} would offer the choice at run-time, so
10886 that a compile-time option to @code{g77} or @code{f2c} could
10887 result in generating the appropriate calls to flushing or
10888 non-flushing library routines.)
10889
10890 @xref{Always Flush Output}, for information on how to modify
10891 the @code{g77} source tree so that a version of @code{libg2c}
10892 can be built and installed with the @samp{ALWAYS_FLUSH} macro defined.
10893
10894 @node Large File Unit Numbers
10895 @subsection Large File Unit Numbers
10896 @cindex MXUNIT
10897 @cindex unit numbers
10898 @cindex maximum unit number
10899 @cindex illegal unit number
10900 @cindex increasing maximum unit number
10901
10902 If your program crashes at run time with a message including
10903 the text @samp{illegal unit number}, that probably is
10904 a message from the run-time library, @code{libg2c}.
10905
10906 The message means that your program has attempted to use a
10907 file unit number that is out of the range accepted by
10908 @code{libg2c}.
10909 Normally, this range is 0 through 99, and the high end
10910 of the range is controlled by a @code{libg2c} source-file
10911 macro named @samp{MXUNIT}.
10912
10913 If you can easily change your program to use unit numbers
10914 in the range 0 through 99, you should do so.
10915
10916 Otherwise, see @ref{Larger File Unit Numbers}, for information on how
10917 to change @samp{MXUNIT} in @code{libg2c} so you can build and
10918 install a new version of @code{libg2c} that supports the larger
10919 unit numbers you need.
10920
10921 @emph{Note:} While @code{libg2c} places a limit on the range
10922 of Fortran file-unit numbers, the underlying library and operating
10923 system might impose different kinds of limits.
10924 For example, some systems limit the number of files simultaneously
10925 open by a running program.
10926 Information on how to increase these limits should be found
10927 in your system's documentation.
10928
10929 @node Floating-point precision
10930 @subsection Floating-point precision
10931
10932 @cindex IEEE 754 conformance
10933 @cindex conformance, IEEE 754
10934 @cindex floating-point, precision
10935 @cindex ix86 floating-point
10936 @cindex x86 floating-point
10937 If your program depends on exact IEEE 754 floating-point handling it may
10938 help on some systems---specifically x86 or m68k hardware---to use
10939 the @code{-ffloat-store} option or to reset the precision flag on the
10940 floating-point unit @xref{Optimize Options}.
10941
10942 However, it might be better simply to put the FPU into double precision
10943 mode and not take the performance hit of @code{-ffloat-store}.  On x86
10944 and m68k GNU systems you can do this with a technique similar to that
10945 for turning on floating-point exceptions @xref{Floating-point Exception
10946 Handling}.  The control word could be set to double precision by
10947 replacing the @code{__setfpucw} call with one like this:
10948 @smallexample
10949   __setfpucw ((_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE);
10950 @end smallexample
10951 (It is not clear whether this has any effect on the operation of the GNU
10952 maths library, but we have no evidence of it causing trouble.)
10953
10954 Some targets (such as the Alpha) may need special options for full IEEE
10955 conformance @xref{Submodel Options,,Hardware Models and
10956 Configurations,gcc,Using and Porting GNU CC}.
10957
10958 @node Inconsistent Calling Sequences
10959 @subsection Inconsistent Calling Sequences
10960
10961 @pindex ftnchek
10962 @cindex floating-point, errors
10963 @cindex ix86 FPU stack
10964 @cindex x86 FPU stack
10965 Code containing inconsistent calling sequences in the same file is
10966 normally rejected @xref{GLOBALS}.  (Use, say, @code{ftnchek} to ensure
10967 consistency across source files
10968 @c makeinfo 1.68 objects to the nested parens
10969 @ifinfo
10970 @xref{f2c Skeletons and Prototypes}.)
10971 @end ifinfo
10972 @ifnotinfo
10973 @xref{f2c Skeletons and Prototypes,,
10974 {Generating Skeletons and Prototypes with @code{f2c}}}.)
10975 @end ifnotinfo
10976
10977 Mysterious errors, which may appear to be code generation problems, can
10978 appear specifically on the x86 architecture with some such
10979 inconsistencies.  On x86 hardware, floating-point return values of
10980 functions are placed on the floating-point unit's register stack, not
10981 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
10982 @code{FUNCTION} as some other sort of procedure, or vice versa,
10983 scrambles the floating-point stack.  This may break unrelated code
10984 executed later.  Similarly if, say, external C routines are written
10985 incorrectly.
10986
10987 @node Overly Convenient Options
10988 @section Overly Convenient Command-line Options
10989 @cindex overly convenient options
10990 @cindex options, overly convenient
10991
10992 These options should be used only as a quick-and-dirty way to determine
10993 how well your program will run under different compilation models
10994 without having to change the source.
10995 Some are more problematic
10996 than others, depending on how portable and maintainable you want the
10997 program to be (and, of course, whether you are allowed to change it
10998 at all is crucial).
10999
11000 You should not continue to use these command-line options to compile
11001 a given program, but rather should make changes to the source code:
11002
11003 @table @code
11004 @cindex -finit-local-zero option
11005 @cindex options, -finit-local-zero
11006 @item -finit-local-zero
11007 (This option specifies that any uninitialized local variables
11008 and arrays have default initialization to binary zeros.)
11009
11010 Many other compilers do this automatically, which means lots of
11011 Fortran code developed with those compilers depends on it.
11012
11013 It is safer (and probably
11014 would produce a faster program) to find the variables and arrays that
11015 need such initialization and provide it explicitly via @code{DATA}, so that
11016 @samp{-finit-local-zero} is not needed.
11017
11018 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
11019 find likely candidates, but
11020 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
11021 or this technique won't work.
11022
11023 @cindex -fno-automatic option
11024 @cindex options, -fno-automatic
11025 @item -fno-automatic
11026 (This option specifies that all local variables and arrays
11027 are to be treated as if they were named in @code{SAVE} statements.)
11028
11029 Many other compilers do this automatically, which means lots of
11030 Fortran code developed with those compilers depends on it.
11031
11032 The effect of this is that all non-automatic variables and arrays
11033 are made static, that is, not placed on the stack or in heap storage.
11034 This might cause a buggy program to appear to work better.
11035 If so, rather than relying on this command-line option (and hoping all
11036 compilers provide the equivalent one), add @code{SAVE}
11037 statements to some or all program unit sources, as appropriate.
11038 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
11039 to find likely candidates, but
11040 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
11041 or this technique won't work.
11042
11043 The default is @samp{-fautomatic}, which tells @code{g77} to try
11044 and put variables and arrays on the stack (or in fast registers)
11045 where possible and reasonable.
11046 This tends to make programs faster.
11047
11048 @cindex automatic arrays
11049 @cindex arrays, automatic
11050 @emph{Note:} Automatic variables and arrays are not affected
11051 by this option.
11052 These are variables and arrays that are @emph{necessarily} automatic,
11053 either due to explicit statements, or due to the way they are
11054 declared.
11055 Examples include local variables and arrays not given the
11056 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
11057 and local arrays declared with non-constant bounds (automatic
11058 arrays).
11059 Currently, @code{g77} supports only automatic arrays, not
11060 @code{RECURSIVE} procedures or other means of explicitly
11061 specifying that variables or arrays are automatic.
11062
11063 @cindex -fugly option
11064 @cindex options, -fugly
11065 @item -fugly
11066 Fix the source code so that @samp{-fno-ugly} will work.
11067 Note that, for many programs, it is difficult to practically
11068 avoid using the features enabled via @samp{-fugly-init}, and these
11069 features pose the lowest risk of writing nonportable code, among the
11070 various ``ugly'' features.
11071
11072 @cindex -f@var{group}-intrinsics-hide option
11073 @cindex options, -f@var{group}-intrinsics-hide
11074 @item -f@var{group}-intrinsics-hide
11075 Change the source code to use @code{EXTERNAL} for any external procedure
11076 that might be the name of an intrinsic.
11077 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
11078 @end table
11079
11080 @node Faster Programs
11081 @section Faster Programs
11082 @cindex speed, of programs
11083 @cindex programs, speeding up
11084
11085 Aside from the usual @code{gcc} options, such as @samp{-O},
11086 @samp{-ffast-math}, and so on, consider trying some of the
11087 following approaches to speed up your program (once you get
11088 it working).
11089
11090 @menu
11091 * Aligned Data::
11092 * Prefer Automatic Uninitialized Variables::
11093 * Avoid f2c Compatibility::
11094 * Use Submodel Options::
11095 @end menu
11096
11097 @node Aligned Data
11098 @subsection Aligned Data
11099 @cindex data, aligned
11100 @cindex stack, aligned
11101 @cindex aligned data
11102 @cindex aligned stack
11103 @cindex Pentium optimizations
11104 @cindex optimization, for Pentium
11105
11106 On some systems, such as those with Pentium Pro CPUs, programs
11107 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
11108 might run much slower
11109 than possible due to the compiler not aligning these 64-bit
11110 values to 64-bit boundaries in memory.
11111 (The effect also is present, though
11112 to a lesser extent, on the 586 (Pentium) architecture.)
11113
11114 The Intel x86 architecture generally ensures that these programs will
11115 work on all its implementations,
11116 but particular implementations (such as Pentium Pro)
11117 perform better with more strict alignment.
11118 (Such behavior isn't unique to the Intel x86 architecture.)
11119 Other architectures might @emph{demand} 64-bit alignment
11120 of 64-bit data.
11121
11122 There are a variety of approaches to use to address this problem:
11123
11124 @itemize @bullet
11125 @item
11126 @cindex @code{COMMON} layout
11127 @cindex layout of @code{COMMON} blocks
11128 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
11129 that the variables and arrays with the widest alignment
11130 guidelines come first.
11131
11132 For example, on most systems, this would mean placing
11133 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
11134 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
11135 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
11136 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
11137 and @code{INTEGER(KIND=3)} entities.
11138
11139 The reason to use such placement is it makes it more likely
11140 that your data will be aligned properly, without requiring
11141 you to do detailed analysis of each aggregate (@code{COMMON}
11142 and @code{EQUIVALENCE}) area.
11143
11144 Specifically, on systems where the above guidelines are
11145 appropriate, placing @code{CHARACTER} entities before
11146 @code{REAL(KIND=2)} entities can work just as well,
11147 but only if the number of bytes occupied by the @code{CHARACTER}
11148 entities is divisible by the recommended alignment for
11149 @code{REAL(KIND=2)}.
11150
11151 By ordering the placement of entities in aggregate
11152 areas according to the simple guidelines above, you
11153 avoid having to carefully count the number of bytes
11154 occupied by each entity to determine whether the
11155 actual alignment of each subsequent entity meets the
11156 alignment guidelines for the type of that entity.
11157
11158 If you don't ensure correct alignment of @code{COMMON} elements, the
11159 compiler may be forced by some systems to violate the Fortran semantics by
11160 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
11161 If the unfortunate practice is employed of overlaying different types of
11162 data in the @code{COMMON} block, the different variants
11163 of this block may become misaligned with respect to each other.
11164 Even if your platform doesn't require strict alignment,
11165 @code{COMMON} should be laid out as above for portability.
11166 (Unfortunately the FORTRAN 77 standard didn't anticipate this
11167 possible requirement, which is compiler-independent on a given platform.)
11168
11169 @item
11170 @cindex -malign-double option
11171 @cindex options, -malign-double
11172 Use the (x86-specific) @samp{-malign-double} option when compiling
11173 programs for the Pentium and Pentium Pro architectures (called 586
11174 and 686 in the @code{gcc} configuration subsystem).
11175 The warning about this in the @code{gcc} manual isn't
11176 generally relevant to Fortran,
11177 but using it will force @code{COMMON} to be padded if necessary to align
11178 @code{DOUBLE PRECISION} data.
11179
11180 When @code{DOUBLE PRECISION} data is forcibly aligned
11181 in @code{COMMON} by @code{g77} due to specifying @samp{-malign-double},
11182 @code{g77} issues a warning about the need to
11183 insert padding.
11184
11185 In this case, each and every program unit that uses
11186 the same @code{COMMON} area
11187 must specify the same layout of variables and their types
11188 for that area
11189 and be compiled with @samp{-malign-double} as well.
11190 @code{g77} will issue warnings in each case,
11191 but as long as every program unit using that area
11192 is compiled with the same warnings,
11193 the resulting object files should work when linked together
11194 unless the program makes additional assumptions about
11195 @code{COMMON} area layouts that are outside the scope
11196 of the FORTRAN 77 standard,
11197 or uses @code{EQUIVALENCE} or different layouts
11198 in ways that assume no padding is ever inserted by the compiler.
11199
11200 @emph{Note:} @samp{-malign-double} applies only to
11201 statically-allocated data.
11202 Double-precision data on the stack can still
11203 cause problems due to misalignment.
11204 @xref{Aligned Data}.
11205
11206 @item
11207 Ensure that @file{crt0.o} or @file{crt1.o}
11208 on your system guarantees a 64-bit
11209 aligned stack for @code{main()}.
11210 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
11211 but we don't know of any other x86 setups where it will be right.
11212 Read your system's documentation to determine if
11213 it is appropriate to upgrade to a more recent version
11214 to obtain the optimal alignment.
11215 @end itemize
11216
11217 Progress is being made on making this work
11218 ``out of the box'' on future versions of @code{g77},
11219 @code{gcc}, and some of the relevant operating systems
11220 (such as GNU/Linux).
11221
11222 @node Prefer Automatic Uninitialized Variables
11223 @subsection Prefer Automatic Uninitialized Variables
11224
11225 If you're using @samp{-fno-automatic} already, you probably
11226 should change your code to allow compilation with @samp{-fautomatic}
11227 (the default), to allow the program to run faster.
11228
11229 Similarly, you should be able to use @samp{-fno-init-local-zero}
11230 (the default) instead of @samp{-finit-local-zero}.
11231 This is because it is rare that every variable affected by these
11232 options in a given program actually needs to
11233 be so affected.
11234
11235 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
11236 every local non-automatic variable and array, affects even things like
11237 @code{DO} iteration
11238 variables, which rarely need to be @code{SAVE}d, and this often reduces
11239 run-time performances.
11240 Similarly, @samp{-fno-init-local-zero} forces such
11241 variables to be initialized to zero---when @code{SAVE}d (such as when
11242 @samp{-fno-automatic}), this by itself generally affects only
11243 startup time for a program, but when not @code{SAVE}d,
11244 it can slow down the procedure every time it is called.
11245
11246 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
11247 for information on the @samp{-fno-automatic} and
11248 @samp{-finit-local-zero} options and how to convert
11249 their use into selective changes in your own code.
11250
11251 @node Avoid f2c Compatibility
11252 @subsection Avoid f2c Compatibility
11253 @cindex -fno-f2c option
11254 @cindex options, -fno-f2c
11255 @cindex @code{f2c} compatibility
11256 @cindex compatibility, @code{f2c}
11257
11258 If you aren't linking with any code compiled using
11259 @code{f2c}, try using the @samp{-fno-f2c} option when
11260 compiling @emph{all} the code in your program.
11261 (Note that @code{libf2c} is @emph{not} an example of code
11262 that is compiled using @code{f2c}---it is compiled by a C
11263 compiler, typically @code{gcc}.)
11264
11265 @node Use Submodel Options
11266 @subsection Use Submodel Options
11267 @cindex Pentium optimizations
11268 @cindex optimization, for Pentium
11269 @cindex 586/686 CPUs
11270 @cindex submodels
11271
11272 Using an appropriate @samp{-m} option to generate specific code for your
11273 CPU may be worthwhile, though it may mean the executable won't run on
11274 other versions of the CPU that don't support the same instruction set.
11275 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
11276 Porting GNU CC}.
11277
11278 For recent CPUs that don't have explicit support in
11279 the released version of @code{gcc}, it may still be possible to get
11280 improvements.
11281 For instance, the flags recommended for 586/686
11282 (Pentium(Pro)) chips for building the Linux kernel are:
11283
11284 @smallexample
11285 -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2
11286 -fomit-frame-pointer
11287 @end smallexample
11288
11289 @noindent @samp{-fomit-frame-pointer} will, however, inhibit debugging
11290 on x86 systems.
11291
11292 @node Trouble
11293 @chapter Known Causes of Trouble with GNU Fortran
11294 @cindex bugs, known
11295 @cindex installation trouble
11296 @cindex known causes of trouble
11297
11298 This section describes known problems that affect users of GNU Fortran.
11299 Most of these are not GNU Fortran bugs per se---if they were, we would
11300 fix them.
11301 But the result for a user might be like the result of a bug.
11302
11303 Some of these problems are due to bugs in other software, some are
11304 missing features that are too much work to add, and some are places
11305 where people's opinions differ as to what is best.
11306
11307 Information on bugs that show up when configuring, porting, building,
11308 or installing @code{g77} is not provided here.
11309 @xref{Problems Installing}.
11310
11311 To find out about major bugs discovered in the current release and
11312 possible workarounds for them, retrieve
11313 @uref{ftp://alpha.gnu.org/g77.plan}.
11314
11315 (Note that some of this portion of the manual is lifted
11316 directly from the @code{gcc} manual, with minor modifications
11317 to tailor it to users of @code{g77}.
11318 Anytime a bug seems to have more to do with the @code{gcc}
11319 portion of @code{g77},
11320 @xref{Trouble,,Known Causes of Trouble with GNU CC,
11321 gcc,Using and Porting GNU CC}.)
11322
11323 @menu
11324 * But-bugs::         Bugs really in other programs or elsewhere.
11325 * Actual Bugs::      Bugs and misfeatures we will fix later.
11326 * Missing Features:: Features we already know we want to add later.
11327 * Disappointments::  Regrettable things we can't change.
11328 * Non-bugs::         Things we think are right, but some others disagree.
11329 * Warnings and Errors::  Which problems in your code get warnings,
11330                         and which get errors.
11331 @end menu
11332
11333 @node But-bugs
11334 @section Bugs Not In GNU Fortran
11335 @cindex but-bugs
11336
11337 These are bugs to which the maintainers often have to reply,
11338 ``but that isn't a bug in @code{g77}@dots{}''.
11339 Some of these already are fixed in new versions of other
11340 software; some still need to be fixed; some are problems
11341 with how @code{g77} is installed or is being used;
11342 some are the result of bad hardware that causes software
11343 to misbehave in sometimes bizarre ways;
11344 some just cannot be addressed at this time until more
11345 is known about the problem.
11346
11347 Please don't re-report these bugs to the @code{g77} maintainers---if
11348 you must remind someone how important it is to you that the problem
11349 be fixed, talk to the people responsible for the other products
11350 identified below, but preferably only after you've tried the
11351 latest versions of those products.
11352 The @code{g77} maintainers have their hands full working on
11353 just fixing and improving @code{g77}, without serving as a
11354 clearinghouse for all bugs that happen to affect @code{g77}
11355 users.
11356
11357 @xref{Collected Fortran Wisdom}, for information on behavior
11358 of Fortran programs, and the programs that compile them, that
11359 might be @emph{thought} to indicate bugs.
11360
11361 @menu
11362 * Signal 11 and Friends::  Strange behavior by any software.
11363 * Cannot Link Fortran Programs::  Unresolved references.
11364 * Large Common Blocks::    Problems on older GNU/Linux systems.
11365 * Debugger Problems::      When the debugger crashes.
11366 * NeXTStep Problems::      Misbehaving executables.
11367 * Stack Overflow::         More misbehaving executables.
11368 * Nothing Happens::        Less behaving executables.
11369 * Strange Behavior at Run Time::  Executables misbehaving due to
11370                             bugs in your program.
11371 * Floating-point Errors::  The results look wrong, but@dots{}.
11372 @end menu
11373
11374 @node Signal 11 and Friends
11375 @subsection Signal 11 and Friends
11376 @cindex signal 11
11377 @cindex hardware errors
11378
11379 A whole variety of strange behaviors can occur when the
11380 software, or the way you are using the software,
11381 stresses the hardware in a way that triggers hardware bugs.
11382 This might seem hard to believe, but it happens frequently
11383 enough that there exist documents explaining in detail
11384 what the various causes of the problems are, what
11385 typical symptoms look like, and so on.
11386
11387 Generally these problems are referred to in this document
11388 as ``signal 11'' crashes, because the Linux kernel, running
11389 on the most popular hardware (the Intel x86 line), often
11390 stresses the hardware more than other popular operating
11391 systems.
11392 When hardware problems do occur under GNU/Linux on x86
11393 systems, these often manifest themselves as ``signal 11''
11394 problems, as illustrated by the following diagnostic:
11395
11396 @smallexample
11397 sh# @kbd{g77 myprog.f}
11398 gcc: Internal compiler error: program f771 got fatal signal 11
11399 sh#
11400 @end smallexample
11401
11402 It is @emph{very} important to remember that the above
11403 message is @emph{not} the only one that indicates a
11404 hardware problem, nor does it always indicate a hardware
11405 problem.
11406
11407 In particular, on systems other than those running the Linux
11408 kernel, the message might appear somewhat or very different,
11409 as it will if the error manifests itself while running a
11410 program other than the @code{g77} compiler.
11411 For example,
11412 it will appear somewhat different when running your program,
11413 when running Emacs, and so on.
11414
11415 How to cope with such problems is well beyond the scope
11416 of this manual.
11417
11418 However, users of Linux-based systems (such as GNU/Linux)
11419 should review @uref{http://www.bitwizard.nl/sig11}, a source
11420 of detailed information on diagnosing hardware problems,
11421 by recognizing their common symptoms.
11422
11423 Users of other operating systems and hardware might
11424 find this reference useful as well.
11425 If you know of similar material for another hardware/software
11426 combination, please let us know so we can consider including
11427 a reference to it in future versions of this manual.
11428
11429 @node Cannot Link Fortran Programs
11430 @subsection Cannot Link Fortran Programs
11431 @cindex unresolved reference (various)
11432 @cindex linking error for user code
11433 @cindex code, user
11434 @cindex @code{ld}, error linking user code
11435 @cindex @code{ld}, can't find strange names
11436 On some systems, perhaps just those with out-of-date (shared?)
11437 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
11438 programs (which should be done using @code{g77}).
11439
11440 If this happens to you, try appending @samp{-lc} to the command you
11441 use to link the program, e.g. @samp{g77 foo.f -lc}.
11442 @code{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
11443 but it cannot also specify @samp{-lc} because not all systems have a
11444 file named @file{libc.a}.
11445
11446 It is unclear at this point whether there are legitimately installed
11447 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
11448 by @code{g77}.
11449
11450 @cindex undefined reference (_main)
11451 @cindex linking error, user code
11452 @cindex @code{ld}, error linking user code
11453 @cindex code, user
11454 @cindex @code{ld}, can't find @samp{_main}
11455 If your program doesn't link due to unresolved references to names
11456 like @samp{_main}, make sure you're using the @code{g77} command to do the
11457 link, since this command ensures that the necessary libraries are
11458 loaded by specifying @samp{-lg2c -lm} when it invokes the @code{gcc}
11459 command to do the actual link.
11460 (Use the @samp{-v} option to discover
11461 more about what actually happens when you use the @code{g77} and @code{gcc}
11462 commands.)
11463
11464 Also, try specifying @samp{-lc} as the last item on the @code{g77}
11465 command line, in case that helps.
11466
11467 @node Large Common Blocks
11468 @subsection Large Common Blocks
11469 @cindex common blocks, large
11470 @cindex large common blocks
11471 @cindex linking, errors
11472 @cindex @code{ld}, errors
11473 @cindex errors, linker
11474 On some older GNU/Linux systems, programs with common blocks larger
11475 than 16MB cannot be linked without some kind of error
11476 message being produced.
11477
11478 This is a bug in older versions of @code{ld}, fixed in
11479 more recent versions of @code{binutils}, such as version 2.6.
11480
11481 @node Debugger Problems
11482 @subsection Debugger Problems
11483 @cindex @code{gdb}, support
11484 @cindex support, @code{gdb}
11485 There are some known problems when using @code{gdb} on code
11486 compiled by @code{g77}.
11487 Inadequate investigation as of the release of 0.5.16 results in not
11488 knowing which products are the culprit, but @file{gdb-4.14} definitely
11489 crashes when, for example, an attempt is made to print the contents
11490 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
11491 machines, plus some others.
11492 Attempts to access assumed-size arrays are
11493 also known to crash recent versions of @code{gdb}.
11494 (@code{gdb}'s Fortran support was done for a different compiler
11495 and isn't properly compatible with @code{g77}.)
11496
11497 @node NeXTStep Problems
11498 @subsection NeXTStep Problems
11499 @cindex NeXTStep problems
11500 @cindex bus error
11501 @cindex segmentation violation
11502 Developers of Fortran code on NeXTStep (all architectures) have to
11503 watch out for the following problem when writing programs with
11504 large, statically allocated (i.e. non-stack based) data structures
11505 (common blocks, saved arrays).
11506
11507 Due to the way the native loader (@file{/bin/ld}) lays out
11508 data structures in virtual memory, it is very easy to create an
11509 executable wherein the @samp{__DATA} segment overlaps (has addresses in
11510 common) with the @samp{UNIX STACK} segment.
11511
11512 This leads to all sorts of trouble, from the executable simply not
11513 executing, to bus errors.
11514 The NeXTStep command line tool @code{ebadexec} points to
11515 the problem as follows:
11516
11517 @smallexample
11518 % @kbd{/bin/ebadexec a.out}
11519 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
11520 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
11521 STACK segment (truncated address = 0x400000 rounded size =
11522 0x3c00000) of executable file: a.out
11523 @end smallexample
11524
11525 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
11526 stack segment.)
11527
11528 This can be cured by assigning the @samp{__DATA} segment
11529 (virtual) addresses beyond the stack segment.
11530 A conservative
11531 estimate for this is from address 6000000 (hexadecimal) onwards---this
11532 has always worked for me [Toon Moene]:
11533
11534 @smallexample
11535 % @kbd{g77 -segaddr __DATA 6000000 test.f}
11536 % @kbd{ebadexec a.out}
11537 ebadexec: file: a.out appears to be executable
11538 %
11539 @end smallexample
11540
11541 Browsing through @file{@value{path-g77}/Makefile.in},
11542 you will find that the @code{f771} program itself also has to be
11543 linked with these flags---it has large statically allocated
11544 data structures.
11545 (Version 0.5.18 reduces this somewhat, but probably
11546 not enough.)
11547
11548 (The above item was contributed by Toon Moene
11549 (@email{toon@@moene.indiv.nluug.nl}).)
11550
11551 @node Stack Overflow
11552 @subsection Stack Overflow
11553 @cindex stack, overflow
11554 @cindex segmentation violation
11555 @code{g77} code might fail at runtime (probably with a ``segmentation
11556 violation'') due to overflowing the stack.
11557 This happens most often on systems with an environment
11558 that provides substantially more heap space (for use
11559 when arbitrarily allocating and freeing memory) than stack
11560 space.
11561
11562 Often this can be cured by
11563 increasing or removing your shell's limit on stack usage, typically
11564 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
11565 @kbd{ulimit -s} (in @code{sh} and derivatives).
11566
11567 Increasing the allowed stack size might, however, require
11568 changing some operating system or system configuration parameters.
11569
11570 You might be able to work around the problem by compiling with the
11571 @samp{-fno-automatic} option to reduce stack usage, probably at the
11572 expense of speed.
11573
11574 @xref{Maximum Stackable Size}, for information on patching
11575 @code{g77} to use different criteria for placing local
11576 non-automatic variables and arrays on the stack.
11577
11578 @cindex automatic arrays
11579 @cindex arrays, automatic
11580 However, if your program uses large automatic arrays
11581 (for example, has declarations like @samp{REAL A(N)} where
11582 @samp{A} is a local array and @samp{N} is a dummy or
11583 @code{COMMON} variable that can have a large value),
11584 neither use of @samp{-fno-automatic},
11585 nor changing the cut-off point for @code{g77} for using the stack,
11586 will solve the problem by changing the placement of these
11587 large arrays, as they are @emph{necessarily} automatic.
11588
11589 @code{g77} currently provides no means to specify that
11590 automatic arrays are to be allocated on the heap instead
11591 of the stack.
11592 So, other than increasing the stack size, your best bet is to
11593 change your source code to avoid large automatic arrays.
11594 Methods for doing this currently are outside the scope of
11595 this document.
11596
11597 (@emph{Note:} If your system puts stack and heap space in the
11598 same memory area, such that they are effectively combined, then
11599 a stack overflow probably indicates a program that is either
11600 simply too large for the system, or buggy.)
11601
11602 @node Nothing Happens
11603 @subsection Nothing Happens
11604 @cindex nothing happens
11605 @cindex naming programs
11606 @cindex @samp{test} programs
11607 @cindex programs, @samp{test}
11608 It is occasionally reported that a ``simple'' program,
11609 such as a ``Hello, World!'' program, does nothing when
11610 it is run, even though the compiler reported no errors,
11611 despite the program containing nothing other than a
11612 simple @code{PRINT} statement.
11613
11614 This most often happens because the program has been
11615 compiled and linked on a UNIX system and named @samp{test},
11616 though other names can lead to similarly unexpected
11617 run-time behavior on various systems.
11618
11619 Essentially this problem boils down to giving
11620 your program a name that is already known to
11621 the shell you are using to identify some other program,
11622 which the shell continues to execute instead of your
11623 program when you invoke it via, for example:
11624
11625 @smallexample
11626 sh# @kbd{test}
11627 sh#
11628 @end smallexample
11629
11630 Under UNIX and many other system, a simple command name
11631 invokes a searching mechanism that might well not choose
11632 the program located in the current working directory if
11633 there is another alternative (such as the @code{test}
11634 command commonly installed on UNIX systems).
11635
11636 The reliable way to invoke a program you just linked in
11637 the current directory under UNIX is to specify it using
11638 an explicit pathname, as in:
11639
11640 @smallexample
11641 sh# @kbd{./test}
11642  Hello, World!
11643 sh#
11644 @end smallexample
11645
11646 Users who encounter this problem should take the time to
11647 read up on how their shell searches for commands, how to
11648 set their search path, and so on.
11649 The relevant UNIX commands to learn about include
11650 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
11651 @code{set} and @code{env}), @code{which}, and @code{find}.
11652
11653 @node Strange Behavior at Run Time
11654 @subsection Strange Behavior at Run Time
11655 @cindex segmentation violation
11656 @cindex bus error
11657 @cindex overwritten data
11658 @cindex data, overwritten
11659 @code{g77} code might fail at runtime with ``segmentation violation'',
11660 ``bus error'', or even something as subtle as a procedure call
11661 overwriting a variable or array element that it is not supposed
11662 to touch.
11663
11664 These can be symptoms of a wide variety of actual bugs that
11665 occurred earlier during the program's run, but manifested
11666 themselves as @emph{visible} problems some time later.
11667
11668 Overflowing the bounds of an array---usually by writing beyond
11669 the end of it---is one of two kinds of bug that often occurs
11670 in Fortran code.
11671
11672 The other kind of bug is a mismatch between the actual arguments
11673 passed to a procedure and the dummy arguments as declared by that
11674 procedure.
11675
11676 Both of these kinds of bugs, and some others as well, can be
11677 difficult to track down, because the bug can change its behavior,
11678 or even appear to not occur, when using a debugger.
11679
11680 That is, these bugs can be quite sensitive to data, including
11681 data representing the placement of other data in memory (that is,
11682 pointers, such as the placement of stack frames in memory).
11683
11684 Plans call for improving @code{g77} so that it can offer the
11685 ability to catch and report some of these problems at compile, link, or
11686 run time, such as by generating code to detect references to
11687 beyond the bounds of an array, or checking for agreement between
11688 calling and called procedures.
11689
11690 In the meantime, finding and fixing the programming
11691 bugs that lead to these behaviors is, ultimately, the user's
11692 responsibility, as difficult as that task can sometimes be.
11693
11694 @cindex infinite spaces printed
11695 @cindex space, endless printing of
11696 @cindex libc, non-ANSI or non-default
11697 @cindex C library
11698 @cindex linking against non-standard library
11699 @cindex Solaris
11700 One runtime problem that has been observed might have a simple solution.
11701 If a formatted @code{WRITE} produces an endless stream of spaces, check
11702 that your program is linked against the correct version of the C library.
11703 The configuration process takes care to account for your
11704 system's normal @file{libc} not being ANSI-standard, which will
11705 otherwise cause this behaviour.
11706 If your system's default library is
11707 ANSI-standard and you subsequently link against a non-ANSI one, there
11708 might be problems such as this one.
11709
11710 Specifically, on Solaris2 systems,
11711 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
11712
11713 @node Floating-point Errors
11714 @subsection Floating-point Errors
11715 @cindex floating-point errors
11716 @cindex rounding errors
11717 @cindex inconsistent floating-point results
11718 @cindex results, inconsistent
11719 Some programs appear to produce inconsistent floating-point
11720 results compiled by @code{g77} versus by other compilers.
11721
11722 Often the reason for this behavior is the fact that floating-point
11723 values are represented on almost all Fortran systems by
11724 @emph{approximations}, and these approximations are inexact
11725 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
11726 0.7, 0.8, 0.9, 1.1, and so on.
11727 Most Fortran systems, including all current ports of @code{g77},
11728 use binary arithmetic to represent these approximations.
11729
11730 Therefore, the exact value of any floating-point approximation
11731 as manipulated by @code{g77}-compiled code is representable by
11732 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
11733 so on (just keep dividing by two) through the precision of the
11734 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
11735 @code{REAL(KIND=2)}), then multiplying the sum by a integral
11736 power of two (in Fortran, by @samp{2**N}) that typically is between
11737 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
11738 @code{REAL(KIND=2)}, then multiplying by -1 if the number
11739 is negative.
11740
11741 So, a value like 0.2 is exactly represented in decimal---since
11742 it is a fraction, @samp{2/10}, with a denominator that is compatible
11743 with the base of the number system (base 10).
11744 However, @samp{2/10} cannot be represented by any finite number
11745 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
11746 be exactly represented in binary notation.
11747
11748 (On the other hand, decimal notation can represent any binary
11749 number in a finite number of digits.
11750 Decimal notation cannot do so with ternary, or base-3,
11751 notation, which would represent floating-point numbers as
11752 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
11753 After all, no finite number of decimal digits can exactly
11754 represent @samp{1/3}.
11755 Fortunately, few systems use ternary notation.)
11756
11757 Moreover, differences in the way run-time I/O libraries convert
11758 between these approximations and the decimal representation often
11759 used by programmers and the programs they write can result in
11760 apparent differences between results that do not actually exist,
11761 or exist to such a small degree that they usually are not worth
11762 worrying about.
11763
11764 For example, consider the following program:
11765
11766 @smallexample
11767 PRINT *, 0.2
11768 END
11769 @end smallexample
11770
11771 When compiled by @code{g77}, the above program might output
11772 @samp{0.20000003}, while another compiler might produce a
11773 executable that outputs @samp{0.2}.
11774
11775 This particular difference is due to the fact that, currently,
11776 conversion of floating-point values by the @code{libg2c} library,
11777 used by @code{g77}, handles only double-precision values.
11778
11779 Since @samp{0.2} in the program is a single-precision value, it
11780 is converted to double precision (still in binary notation)
11781 before being converted back to decimal.
11782 The conversion to binary appends _binary_ zero digits to the
11783 original value---which, again, is an inexact approximation of
11784 0.2---resulting in an approximation that is much less exact
11785 than is connoted by the use of double precision.
11786
11787 (The appending of binary zero digits has essentially the same
11788 effect as taking a particular decimal approximation of
11789 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
11790 zeros to it, producing @samp{0.33333330000000000}.
11791 Treating the resulting decimal approximation as if it really
11792 had 18 or so digits of valid precision would make it seem
11793 a very poor approximation of @samp{1/3}.)
11794
11795 As a result of converting the single-precision approximation
11796 to double precision by appending binary zeros, the conversion
11797 of the resulting double-precision
11798 value to decimal produces what looks like an incorrect
11799 result, when in fact the result is @emph{inexact}, and
11800 is probably no less inaccurate or imprecise an approximation
11801 of 0.2 than is produced by other compilers that happen to output
11802 the converted value as ``exactly'' @samp{0.2}.
11803 (Some compilers behave in a way that can make them appear
11804 to retain more accuracy across a conversion of a single-precision
11805 constant to double precision.
11806 @xref{Context-Sensitive Constants}, to see why
11807 this practice is illusory and even dangerous.)
11808
11809 Note that a more exact approximation of the constant is
11810 computed when the program is changed to specify a
11811 double-precision constant:
11812
11813 @smallexample
11814 PRINT *, 0.2D0
11815 END
11816 @end smallexample
11817
11818 Future versions of @code{g77} and/or @code{libg2c} might convert
11819 single-precision values directly to decimal,
11820 instead of converting them to double precision first.
11821 This would tend to result in output that is more consistent
11822 with that produced by some other Fortran implementations.
11823
11824 A useful source of information on floating-point computation is David
11825 Goldberg, `What Every Computer Scientist Should Know About
11826 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
11827 5--48.
11828 An online version is available at
11829 @uref{http://docs.sun.com},
11830 and there is a supplemented version, in PostScript form, at
11831 @uref{http://www.validgh.com/goldberg/paper.ps}.
11832
11833 Information related to the IEEE 754
11834 floating-point standard by a leading light can be found at
11835 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status};
11836 see also slides from the short course referenced from
11837 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
11838 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
11839 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
11840 and library code for GNU/Linux x86 systems.
11841
11842 The supplement to the PostScript-formatted Goldberg document,
11843 referenced above, is available in HTML format.
11844 See `Differences Among IEEE 754 Implementations' by Doug Priest,
11845 available online at
11846 @uref{http://www.validgh.com/goldberg/addendum.html}.
11847 This document explores some of the issues surrounding computing
11848 of extended (80-bit) results on processors such as the x86,
11849 especially when those results are arbitrarily truncated
11850 to 32-bit or 64-bit values by the compiler
11851 as ``spills''.
11852
11853 @cindex spills of floating-point results
11854 @cindex 80-bit spills
11855 @cindex truncation, of floating-point values
11856 (@emph{Note:} @code{g77} specifically, and @code{gcc} generally,
11857 does arbitrarily truncate 80-bit results during spills
11858 as of this writing.
11859 It is not yet clear whether a future version of
11860 the GNU compiler suite will offer 80-bit spills
11861 as an option, or perhaps even as the default behavior.)
11862
11863 @c xref would be different between editions:
11864 The GNU C library provides routines for controlling the FPU, and other
11865 documentation about this.
11866
11867 @xref{Floating-point precision}, regarding IEEE 754 conformance.
11868
11869 @include bugs.texi
11870
11871 @node Missing Features
11872 @section Missing Features
11873
11874 This section lists features we know are missing from @code{g77},
11875 and which we want to add someday.
11876 (There is no priority implied in the ordering below.)
11877
11878 @menu
11879 GNU Fortran language:
11880 * Better Source Model::
11881 * Fortran 90 Support::
11882 * Intrinsics in PARAMETER Statements::
11883 * SELECT CASE on CHARACTER Type::
11884 * RECURSIVE Keyword::
11885 * Popular Non-standard Types::
11886 * Full Support for Compiler Types::
11887 * Array Bounds Expressions::
11888 * POINTER Statements::
11889 * Sensible Non-standard Constructs::
11890 * FLUSH Statement::
11891 * Expressions in FORMAT Statements::
11892 * Explicit Assembler Code::
11893 * Q Edit Descriptor::
11894
11895 GNU Fortran dialects:
11896 * Old-style PARAMETER Statements::
11897 * TYPE and ACCEPT I/O Statements::
11898 * STRUCTURE UNION RECORD MAP::
11899 * OPEN CLOSE and INQUIRE Keywords::
11900 * ENCODE and DECODE::
11901 * Suppressing Space Padding::
11902 * Fortran Preprocessor::
11903 * Bit Operations on Floating-point Data::
11904
11905 New facilities:
11906 * POSIX Standard::
11907 * Floating-point Exception Handling::
11908 * Nonportable Conversions::
11909 * Large Automatic Arrays::
11910 * Support for Threads::
11911 * Increasing Precision/Range::
11912
11913 Better diagnostics:
11914 * Gracefully Handle Sensible Bad Code::
11915 * Non-standard Conversions::
11916 * Non-standard Intrinsics::
11917 * Modifying DO Variable::
11918 * Better Pedantic Compilation::
11919 * Warn About Implicit Conversions::
11920 * Invalid Use of Hollerith Constant::
11921 * Dummy Array Without Dimensioning Dummy::
11922 * Invalid FORMAT Specifiers::
11923 * Ambiguous Dialects::
11924 * Unused Labels::
11925 * Informational Messages::
11926
11927 Run-time facilities:
11928 * Uninitialized Variables at Run Time::
11929 * Bounds Checking at Run Time::
11930 * Portable Unformatted Files::
11931
11932 Debugging:
11933 * Labels Visible to Debugger::
11934 @end menu
11935
11936 @node Better Source Model
11937 @subsection Better Source Model
11938
11939 @code{g77} needs to provide, as the default source-line model,
11940 a ``pure visual'' mode, where
11941 the interpretation of a source program in this mode can be accurately
11942 determined by a user looking at a traditionally displayed rendition
11943 of the program (assuming the user knows whether the program is fixed
11944 or free form).
11945
11946 The design should assume the user cannot tell tabs from spaces
11947 and cannot see trailing spaces on lines, but has canonical tab stops
11948 and, for fixed-form source, has the ability to always know exactly
11949 where column 72 is (since the Fortran standard itself requires
11950 this for fixed-form source).
11951
11952 This would change the default treatment of fixed-form source
11953 to not treat lines with tabs as if they were infinitely long---instead,
11954 they would end at column 72 just as if the tabs were replaced
11955 by spaces in the canonical way.
11956
11957 As part of this, provide common alternate models (Digital, @code{f2c},
11958 and so on) via command-line options.
11959 This includes allowing arbitrarily long
11960 lines for free-form source as well as fixed-form source and providing
11961 various limits and diagnostics as appropriate.
11962
11963 @cindex sequence numbers
11964 @cindex columns 73 through 80
11965 Also, @code{g77} should offer, perhaps even default to, warnings
11966 when characters beyond the last valid column are anything other
11967 than spaces.
11968 This would mean code with ``sequence numbers'' in columns 73 through 80
11969 would be rejected, and there's a lot of that kind of code around,
11970 but one of the most frequent bugs encountered by new users is
11971 accidentally writing fixed-form source code into and beyond
11972 column 73.
11973 So, maybe the users of old code would be able to more easily handle
11974 having to specify, say, a @code{-Wno-col73to80} option.
11975
11976 @node Fortran 90 Support
11977 @subsection Fortran 90 Support
11978 @cindex Fortran 90, support
11979 @cindex support, Fortran 90
11980
11981 @code{g77} does not support many of the features that
11982 distinguish Fortran 90 (and, now, Fortran 95) from
11983 ANSI FORTRAN 77.
11984
11985 Some Fortran 90 features are supported, because they
11986 make sense to offer even to die-hard users of F77.
11987 For example, many of them codify various ways F77 has
11988 been extended to meet users' needs during its tenure,
11989 so @code{g77} might as well offer them as the primary
11990 way to meet those same needs, even if it offers compatibility
11991 with one or more of the ways those needs were met
11992 by other F77 compilers in the industry.
11993
11994 Still, many important F90 features are not supported,
11995 because no attempt has been made to research each and
11996 every feature and assess its viability in @code{g77}.
11997 In the meantime, users who need those features must
11998 use Fortran 90 compilers anyway, and the best approach
11999 to adding some F90 features to GNU Fortran might well be
12000 to fund a comprehensive project to create GNU Fortran 95.
12001
12002 @node Intrinsics in PARAMETER Statements
12003 @subsection Intrinsics in @code{PARAMETER} Statements
12004 @cindex PARAMETER statement
12005 @cindex statements, PARAMETER
12006
12007 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
12008 This feature is considered to be absolutely vital, even though it
12009 is not standard-conforming, and is scheduled for version 0.6.
12010
12011 Related to this, @code{g77} doesn't allow non-integral
12012 exponentiation in @code{PARAMETER} statements, such as
12013 @samp{PARAMETER (R=2**.25)}.
12014 It is unlikely @code{g77} will ever support this feature,
12015 as doing it properly requires complete emulation of
12016 a target computer's floating-point facilities when
12017 building @code{g77} as a cross-compiler.
12018 But, if the @code{gcc} back end is enhanced to provide
12019 such a facility, @code{g77} will likely use that facility
12020 in implementing this feature soon afterwards.
12021
12022 @node SELECT CASE on CHARACTER Type
12023 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
12024
12025 Character-type selector/cases for @code{SELECT CASE} currently
12026 are not supported.
12027
12028 @node RECURSIVE Keyword
12029 @subsection @code{RECURSIVE} Keyword
12030 @cindex RECURSIVE keyword
12031 @cindex keywords, RECURSIVE
12032 @cindex recursion, lack of
12033 @cindex lack of recursion
12034
12035 @code{g77} doesn't support the @code{RECURSIVE} keyword that
12036 F90 compilers do.
12037 Nor does it provide any means for compiling procedures
12038 designed to do recursion.
12039
12040 All recursive code can be rewritten to not use recursion,
12041 but the result is not pretty.
12042
12043 @node Increasing Precision/Range
12044 @subsection Increasing Precision/Range
12045 @cindex -r8
12046 @cindex -qrealsize=8
12047 @cindex -i8
12048 @cindex f2c
12049 @cindex increasing precision
12050 @cindex precision, increasing
12051 @cindex increasing range
12052 @cindex range, increasing
12053 @cindex Toolpack
12054 @cindex Netlib
12055
12056 Some compilers, such as @code{f2c}, have an option (@samp{-r8},
12057 @samp{-qrealsize=8} or
12058 similar) that provides automatic treatment of @code{REAL}
12059 entities such that they have twice the storage size, and
12060 a corresponding increase in the range and precision, of what
12061 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
12062 (This affects @code{COMPLEX} the same way.)
12063
12064 They also typically offer another option (@samp{-i8}) to increase
12065 @code{INTEGER} entities so they are twice as large
12066 (with roughly twice as much range).
12067
12068 (There are potential pitfalls in using these options.)
12069
12070 @code{g77} does not yet offer any option that performs these
12071 kinds of transformations.
12072 Part of the problem is the lack of detailed specifications regarding
12073 exactly how these options affect the interpretation of constants,
12074 intrinsics, and so on.
12075
12076 Until @code{g77} addresses this need, programmers could improve
12077 the portability of their code by modifying it to not require
12078 compile-time options to produce correct results.
12079 Some free tools are available which may help, specifically
12080 in Toolpack (which one would expect to be sound) and the @file{fortran}
12081 section of the Netlib repository.
12082
12083 Use of preprocessors can provide a fairly portable means
12084 to work around the lack of widely portable methods in the Fortran
12085 language itself (though increasing acceptance of Fortran 90 would
12086 alleviate this problem).
12087
12088 @node Popular Non-standard Types
12089 @subsection Popular Non-standard Types
12090 @cindex @code{INTEGER*2} support
12091 @cindex types, @code{INTEGER*2}
12092 @cindex @code{LOGICAL*1} support
12093 @cindex types, @code{LOGICAL*1}
12094
12095 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
12096 and similar.
12097 Version 0.6 will provide full support for this very
12098 popular set of features.
12099 In the meantime, version 0.5.18 provides rudimentary support
12100 for them.
12101
12102 @node Full Support for Compiler Types
12103 @subsection Full Support for Compiler Types
12104
12105 @cindex @code{REAL*16} support
12106 @cindex types, @code{REAL*16}
12107 @cindex @code{INTEGER*8} support
12108 @cindex types, @code{INTEGER*8}
12109 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
12110 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
12111 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
12112 This means providing intrinsic support, and maybe constant
12113 support (using F90 syntax) as well, and, for most
12114 machines will result in automatic support of @code{INTEGER*1},
12115 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
12116 and so on.
12117 This is scheduled for version 0.6.
12118
12119 @node Array Bounds Expressions
12120 @subsection Array Bounds Expressions
12121 @cindex array elements, in adjustable array bounds
12122 @cindex function references, in adjustable array bounds
12123 @cindex array bounds, adjustable
12124 @cindex @code{DIMENSION} statement
12125 @cindex statements, @code{DIMENSION}
12126
12127 @code{g77} doesn't support more general expressions to dimension
12128 arrays, such as array element references, function
12129 references, etc.
12130
12131 For example, @code{g77} currently does not accept the following:
12132
12133 @smallexample
12134 SUBROUTINE X(M, N)
12135 INTEGER N(10), M(N(2), N(1))
12136 @end smallexample
12137
12138 @node POINTER Statements
12139 @subsection POINTER Statements
12140 @cindex POINTER statement
12141 @cindex statements, POINTER
12142 @cindex Cray pointers
12143
12144 @code{g77} doesn't support pointers or allocatable objects
12145 (other than automatic arrays).
12146 This set of features is
12147 probably considered just behind intrinsics
12148 in @code{PARAMETER} statements on the list of large,
12149 important things to add to @code{g77}.
12150
12151 In the meantime, consider using the @code{INTEGER(KIND=7)}
12152 declaration to specify that a variable must be
12153 able to hold a pointer.
12154 This construct is not portable to other non-GNU compilers,
12155 but it is portable to all machines GNU Fortran supports
12156 when @code{g77} is used.
12157
12158 @xref{Functions and Subroutines}, for information on
12159 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
12160 constructs, which are useful for passing pointers to
12161 procedures written in languages other than Fortran.
12162
12163 @node Sensible Non-standard Constructs
12164 @subsection Sensible Non-standard Constructs
12165
12166 @code{g77} rejects things other compilers accept,
12167 like @samp{INTRINSIC SQRT,SQRT}.
12168 As time permits in the future, some of these things that are easy for
12169 humans to read and write and unlikely to be intended to mean something
12170 else will be accepted by @code{g77} (though @samp{-fpedantic} should
12171 trigger warnings about such non-standard constructs).
12172
12173 Until @code{g77} no longer gratuitously rejects sensible code,
12174 you might as well fix your code
12175 to be more standard-conforming and portable.
12176
12177 The kind of case that is important to except from the
12178 recommendation to change your code is one where following
12179 good coding rules would force you to write non-standard
12180 code that nevertheless has a clear meaning.
12181
12182 For example, when writing an @code{INCLUDE} file that
12183 defines a common block, it might be appropriate to
12184 include a @code{SAVE} statement for the common block
12185 (such as @samp{SAVE /CBLOCK/}), so that variables
12186 defined in the common block retain their values even
12187 when all procedures declaring the common block become
12188 inactive (return to their callers).
12189
12190 However, putting @code{SAVE} statements in an @code{INCLUDE}
12191 file would prevent otherwise standard-conforming code
12192 from also specifying the @code{SAVE} statement, by itself,
12193 to indicate that all local variables and arrays are to
12194 have the @code{SAVE} attribute.
12195
12196 For this reason, @code{g77} already has been changed to
12197 allow this combination, because although the general
12198 problem of gratuitously rejecting unambiguous and
12199 ``safe'' constructs still exists in @code{g77}, this
12200 particular construct was deemed useful enough that
12201 it was worth fixing @code{g77} for just this case.
12202
12203 So, while there is no need to change your code
12204 to avoid using this particular construct, there
12205 might be other, equally appropriate but non-standard
12206 constructs, that you shouldn't have to stop using
12207 just because @code{g77} (or any other compiler)
12208 gratuitously rejects it.
12209
12210 Until the general problem is solved, if you have
12211 any such construct you believe is worthwhile
12212 using (e.g. not just an arbitrary, redundant
12213 specification of an attribute), please submit a
12214 bug report with an explanation, so we can consider
12215 fixing @code{g77} just for cases like yours.
12216
12217 @node FLUSH Statement
12218 @subsection @code{FLUSH} Statement
12219
12220 @code{g77} could perhaps use a @code{FLUSH} statement that
12221 does what @samp{CALL FLUSH} does,
12222 but that supports @samp{*} as the unit designator (same unit as for
12223 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
12224 specifiers.
12225
12226 @node Expressions in FORMAT Statements
12227 @subsection Expressions in @code{FORMAT} Statements
12228 @cindex FORMAT statement
12229 @cindex statements, FORMAT
12230
12231 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
12232 Supporting this requires a significant redesign or replacement
12233 of @code{libg2c}.
12234
12235 However, @code{g77} does support
12236 this construct when the expression is constant
12237 (as of version 0.5.22).
12238 For example:
12239
12240 @smallexample
12241       PARAMETER (IWIDTH = 12)
12242 10    FORMAT (I<IWIDTH>)
12243 @end smallexample
12244
12245 Otherwise, at least for output (@code{PRINT} and
12246 @code{WRITE}), Fortran code making use of this feature can
12247 be rewritten to avoid it by constructing the @code{FORMAT}
12248 string in a @code{CHARACTER} variable or array, then
12249 using that variable or array in place of the @code{FORMAT}
12250 statement label to do the original @code{PRINT} or @code{WRITE}.
12251
12252 Many uses of this feature on input can be rewritten this way
12253 as well, but not all can.
12254 For example, this can be rewritten:
12255
12256 @smallexample
12257       READ 20, I
12258 20    FORMAT (I<J>)
12259 @end smallexample
12260
12261 However, this cannot, in general, be rewritten, especially
12262 when @code{ERR=} and @code{END=} constructs are employed:
12263
12264 @smallexample
12265       READ 30, J, I
12266 30    FORMAT (I<J>)
12267 @end smallexample
12268
12269 @node Explicit Assembler Code
12270 @subsection Explicit Assembler Code
12271
12272 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
12273 code to specify explicit assembler code.
12274
12275 @node Q Edit Descriptor
12276 @subsection Q Edit Descriptor
12277 @cindex FORMAT statement
12278 @cindex Q edit descriptor
12279 @cindex edit descriptor, Q
12280
12281 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
12282 (This is meant to get the number of characters remaining in an input record.)
12283 Supporting this requires a significant redesign or replacement
12284 of @code{libg2c}.
12285
12286 A workaround might be using internal I/O or the stream-based intrinsics.
12287 @xref{FGetC Intrinsic (subroutine)}.
12288
12289 @node Old-style PARAMETER Statements
12290 @subsection Old-style PARAMETER Statements
12291 @cindex PARAMETER statement
12292 @cindex statements, PARAMETER
12293
12294 @code{g77} doesn't accept @samp{PARAMETER I=1}.
12295 Supporting this obsolete form of
12296 the @code{PARAMETER} statement would not be particularly hard, as most of the
12297 parsing code is already in place and working.
12298
12299 Until time/money is
12300 spent implementing it, you might as well fix your code to use the
12301 standard form, @samp{PARAMETER (I=1)} (possibly needing
12302 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
12303 otherwise, in the obsolete form of @code{PARAMETER}, the
12304 type of the variable is set from the type of the constant being
12305 assigned to it).
12306
12307 @node TYPE and ACCEPT I/O Statements
12308 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
12309 @cindex TYPE statement
12310 @cindex statements, TYPE
12311 @cindex ACCEPT statement
12312 @cindex statements, ACCEPT
12313
12314 @code{g77} doesn't support the I/O statements @code{TYPE} and
12315 @code{ACCEPT}.
12316 These are common extensions that should be easy to support,
12317 but also are fairly easy to work around in user code.
12318
12319 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
12320 by @samp{PRINT fmt,list}.
12321 And, any @samp{ACCEPT fmt,list} statement can be
12322 replaced by @samp{READ fmt,list}.
12323
12324 @node STRUCTURE UNION RECORD MAP
12325 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
12326 @cindex STRUCTURE statement
12327 @cindex statements, STRUCTURE
12328 @cindex UNION statement
12329 @cindex statements, UNION
12330 @cindex RECORD statement
12331 @cindex statements, RECORD
12332 @cindex MAP statement
12333 @cindex statements, MAP
12334
12335 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
12336 @code{MAP}.
12337 This set of extensions is quite a bit
12338 lower on the list of large, important things to add to @code{g77}, partly
12339 because it requires a great deal of work either upgrading or
12340 replacing @code{libg2c}.
12341
12342 @node OPEN CLOSE and INQUIRE Keywords
12343 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
12344 @cindex disposition of files
12345 @cindex OPEN statement
12346 @cindex statements, OPEN
12347 @cindex CLOSE statement
12348 @cindex statements, CLOSE
12349 @cindex INQUIRE statement
12350 @cindex statements, INQUIRE
12351
12352 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
12353 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
12354 These extensions are easy to add to @code{g77} itself, but
12355 require much more work on @code{libg2c}.
12356
12357 @cindex FORM='PRINT'
12358 @cindex ANS carriage control
12359 @cindex carriage control
12360 @pindex asa
12361 @pindex fpr
12362 @code{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
12363 translate the traditional `carriage control' characters in column 1 of
12364 output to use backspaces, carriage returns and the like.  However
12365 programs exist to translate them in output files (or standard output).
12366 These are typically called either @code{fpr} or @code{asa}.  You can get
12367 a version of @code{asa} from
12368 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
12369 systems which will probably build easily on other systems.
12370 Alternatively, @code{fpr} is in BSD distributions in various archive
12371 sites.
12372
12373 @c (Can both programs can be used in a pipeline,
12374 @c with a named input file,
12375 @c and/or with a named output file???)
12376
12377 @node ENCODE and DECODE
12378 @subsection @code{ENCODE} and @code{DECODE}
12379 @cindex ENCODE statement
12380 @cindex statements, ENCODE
12381 @cindex DECODE statement
12382 @cindex statements, DECODE
12383
12384 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
12385
12386 These statements are best replaced by READ and WRITE statements
12387 involving internal files (CHARACTER variables and arrays).
12388
12389 For example, replace a code fragment like
12390
12391 @smallexample
12392       INTEGER*1 LINE(80)
12393 @dots{}
12394       DECODE (80, 9000, LINE) A, B, C
12395 @dots{}
12396 9000  FORMAT (1X, 3(F10.5))
12397 @end smallexample
12398
12399 @noindent
12400 with:
12401
12402 @smallexample
12403       CHARACTER*80 LINE
12404 @dots{}
12405       READ (UNIT=LINE, FMT=9000) A, B, C
12406 @dots{}
12407 9000  FORMAT (1X, 3(F10.5))
12408 @end smallexample
12409
12410 Similarly, replace a code fragment like
12411
12412 @smallexample
12413       INTEGER*1 LINE(80)
12414 @dots{}
12415       ENCODE (80, 9000, LINE) A, B, C
12416 @dots{}
12417 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
12418 @end smallexample
12419
12420 @noindent
12421 with:
12422
12423 @smallexample
12424       CHARACTER*80 LINE
12425 @dots{}
12426       WRITE (UNIT=LINE, FMT=9000) A, B, C
12427 @dots{}
12428 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
12429 @end smallexample
12430
12431 It is entirely possible that @code{ENCODE} and @code{DECODE} will
12432 be supported by a future version of @code{g77}.
12433
12434 @node Suppressing Space Padding
12435 @subsection Suppressing Space Padding of Source Lines
12436
12437 @code{g77} should offer VXT-Fortran-style suppression of virtual
12438 spaces at the end of a source line
12439 if an appropriate command-line option is specified.
12440
12441 This affects cases where
12442 a character constant is continued onto the next line in a fixed-form
12443 source file, as in the following example:
12444
12445 @smallexample
12446 10    PRINT *,'HOW MANY
12447      1 SPACES?'
12448 @end smallexample
12449
12450 @noindent
12451 @code{g77}, and many other compilers, virtually extend
12452 the continued line through column 72 with spaces that become part
12453 of the character constant, but Digital Fortran normally didn't,
12454 leaving only one space between @samp{MANY} and @samp{SPACES?}
12455 in the output of the above statement.
12456
12457 Fairly recently, at least one version of Digital Fortran
12458 was enhanced to provide the other behavior when a
12459 command-line option is specified, apparently due to demand
12460 from readers of the USENET group @file{comp.lang.fortran}
12461 to offer conformance to this widespread practice in the
12462 industry.
12463 @code{g77} should return the favor by offering conformance
12464 to Digital's approach to handling the above example.
12465
12466 @node Fortran Preprocessor
12467 @subsection Fortran Preprocessor
12468
12469 @code{g77} should offer a preprocessor designed specifically
12470 for Fortran to replace @samp{cpp -traditional}.
12471 There are several out there worth evaluating, at least.
12472
12473 Such a preprocessor would recognize Hollerith constants,
12474 properly parse comments and character constants, and so on.
12475 It might also recognize, process, and thus preprocess
12476 files included via the @code{INCLUDE} directive.
12477
12478 @node Bit Operations on Floating-point Data
12479 @subsection Bit Operations on Floating-point Data
12480 @cindex @code{And} intrinsic
12481 @cindex intrinsics, @code{And}
12482 @cindex @code{Or} intrinsic
12483 @cindex intrinsics, @code{Or}
12484 @cindex @code{Shift} intrinsic
12485 @cindex intrinsics, @code{Shift}
12486
12487 @code{g77} does not allow @code{REAL} and other non-integral types for
12488 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
12489
12490 For example, this program is rejected by @code{g77}, because
12491 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
12492
12493 @smallexample
12494 DATA A/7.54/, B/9.112/
12495 PRINT *, IAND(A, B)
12496 END
12497 @end smallexample
12498
12499 @node POSIX Standard
12500 @subsection @code{POSIX} Standard
12501
12502 @code{g77} should support the POSIX standard for Fortran.
12503
12504 @node Floating-point Exception Handling
12505 @subsection Floating-point Exception Handling
12506 @cindex floating-point, exceptions
12507 @cindex exceptions, floating-point
12508 @cindex FPE handling
12509 @cindex NaN values
12510
12511 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
12512 general control over whether or not floating-point exceptions are trapped or
12513 ignored.
12514 (Ignoring them typically results in NaN values being
12515 propagated in systems that conform to IEEE 754.)
12516 The behaviour is normally inherited from the system-dependent startup
12517 code, though some targets, such as the Alpha, have code generation
12518 options which change the behaviour.
12519
12520 Most systems provide some C-callable mechanism to change this; this can
12521 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
12522 For example, just compiling and linking the following C code with your
12523 program will turn on exception trapping for the ``common'' exceptions
12524 on an x86-based GNU system:
12525
12526 @smallexample
12527 #include <fpu_control.h>
12528 static void __attribute__ ((constructor))
12529 trapfpe ()
12530 @{
12531   __setfpucw (_FPU_DEFAULT &
12532               ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM));
12533 @}
12534 @end smallexample
12535
12536 A convenient trick is to compile this something like:
12537 @smallexample
12538 gcc -o libtrapfpe.a trapfpe.c
12539 @end smallexample
12540 and then use it by adding @code{-trapfpe} to the @code{g77} command line
12541 when linking.
12542
12543 @node Nonportable Conversions
12544 @subsection Nonportable Conversions
12545 @cindex nonportable conversions
12546 @cindex conversions, nonportable
12547
12548 @code{g77} doesn't accept some particularly nonportable,
12549 silent data-type conversions such as @code{LOGICAL}
12550 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
12551 is type @code{REAL}), that other compilers might
12552 quietly accept.
12553
12554 Some of these conversions are accepted by @code{g77}
12555 when the @samp{-fugly} option is specified.
12556 Perhaps it should accept more or all of them.
12557
12558 @node Large Automatic Arrays
12559 @subsection Large Automatic Arrays
12560 @cindex automatic arrays
12561 @cindex arrays, automatic
12562
12563 Currently, automatic arrays always are allocated on the stack.
12564 For situations where the stack cannot be made large enough,
12565 @code{g77} should offer a compiler option that specifies
12566 allocation of automatic arrays in heap storage.
12567
12568 @node Support for Threads
12569 @subsection Support for Threads
12570 @cindex threads
12571 @cindex parallel processing
12572
12573 Neither the code produced by @code{g77} nor the @code{libg2c} library
12574 are thread-safe, nor does @code{g77} have support for parallel processing
12575 (other than the instruction-level parallelism available on some
12576 processors).
12577 A package such as PVM might help here.
12578
12579 @node Gracefully Handle Sensible Bad Code
12580 @subsection Gracefully Handle Sensible Bad Code
12581
12582 @code{g77} generally should continue processing for
12583 warnings and recoverable (user) errors whenever possible---that
12584 is, it shouldn't gratuitously make bad or useless code.
12585
12586 For example:
12587
12588 @smallexample
12589 INTRINSIC ZABS
12590 CALL FOO(ZABS)
12591 END
12592 @end smallexample
12593
12594 @noindent
12595 When compiling the above with @samp{-ff2c-intrinsics-disable},
12596 @code{g77} should indeed complain about passing @code{ZABS},
12597 but it still should compile, instead of rejecting
12598 the entire @code{CALL} statement.
12599 (Some of this is related to improving
12600 the compiler internals to improve how statements are analyzed.)
12601
12602 @node Non-standard Conversions
12603 @subsection Non-standard Conversions
12604
12605 @samp{-Wconversion} and related should flag places where non-standard
12606 conversions are found.
12607 Perhaps much of this would be part of @samp{-Wugly*}.
12608
12609 @node Non-standard Intrinsics
12610 @subsection Non-standard Intrinsics
12611
12612 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
12613 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
12614 This would help find code that might fail silently when ported to another
12615 compiler.
12616
12617 @node Modifying DO Variable
12618 @subsection Modifying @code{DO} Variable
12619
12620 @code{g77} should warn about modifying @code{DO} variables
12621 via @code{EQUIVALENCE}.
12622 (The internal information gathered to produce this warning
12623 might also be useful in setting the
12624 internal ``doiter'' flag for a variable or even array
12625 reference within a loop, since that might produce faster code someday.)
12626
12627 For example, this code is invalid, so @code{g77} should warn about
12628 the invalid assignment to @samp{NOTHER}:
12629
12630 @smallexample
12631 EQUIVALENCE (I, NOTHER)
12632 DO I = 1, 100
12633    IF (I.EQ. 10) NOTHER = 20
12634 END DO
12635 @end smallexample
12636
12637 @node Better Pedantic Compilation
12638 @subsection Better Pedantic Compilation
12639
12640 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
12641 and use it only to generate
12642 warnings instead of rejecting constructs outright.
12643 Have it warn:
12644 if a variable that dimensions an array is not a dummy or placed
12645 explicitly in @code{COMMON} (F77 does not allow it to be
12646 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
12647 follow statement-function-definition statements; about all sorts of
12648 syntactic extensions.
12649
12650 @node Warn About Implicit Conversions
12651 @subsection Warn About Implicit Conversions
12652
12653 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
12654 to expect automatic, silent, and
12655 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
12656 constants to @code{REAL(KIND=2)} based on context.
12657
12658 For example, it would warn about cases like this:
12659
12660 @smallexample
12661 DOUBLE PRECISION FOO
12662 PARAMETER (TZPHI = 9.435784839284958)
12663 FOO = TZPHI * 3D0
12664 @end smallexample
12665
12666 @node Invalid Use of Hollerith Constant
12667 @subsection Invalid Use of Hollerith Constant
12668
12669 @code{g77} should disallow statements like @samp{RETURN 2HAB},
12670 which are invalid in both source forms
12671 (unlike @samp{RETURN (2HAB)},
12672 which probably still makes no sense but at least can
12673 be reliably parsed).
12674 Fixed-form processing rejects it, but not free-form, except
12675 in a way that is a bit difficult to understand.
12676
12677 @node Dummy Array Without Dimensioning Dummy
12678 @subsection Dummy Array Without Dimensioning Dummy
12679
12680 @code{g77} should complain when a list of dummy arguments containing an
12681 adjustable dummy array does
12682 not also contain every variable listed in the dimension list of the
12683 adjustable array.
12684
12685 Currently, @code{g77} does complain about a variable that
12686 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
12687 area, but this needs to be extended to catch cases where it doesn't appear in
12688 every dummy list that also lists any arrays it dimensions.
12689
12690 For example, @code{g77} should warn about the entry point @samp{ALT}
12691 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
12692 list of arguments:
12693
12694 @smallexample
12695 SUBROUTINE PRIMARY(ARRAY, ISIZE)
12696 REAL ARRAY(ISIZE)
12697 ENTRY ALT(ARRAY)
12698 @end smallexample
12699
12700 @node Invalid FORMAT Specifiers
12701 @subsection Invalid FORMAT Specifiers
12702
12703 @code{g77} should check @code{FORMAT} specifiers for validity
12704 as it does @code{FORMAT} statements.
12705
12706 For example, a diagnostic would be produced for:
12707
12708 @smallexample
12709 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
12710 @end smallexample
12711
12712 @node Ambiguous Dialects
12713 @subsection Ambiguous Dialects
12714
12715 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
12716 @samp{-Wvxt}, @samp{-Wf90}, and so on.
12717 These would warn about places in the user's source where ambiguities
12718 are found, helpful in resolving ambiguities in the program's
12719 dialect or dialects.
12720
12721 @node Unused Labels
12722 @subsection Unused Labels
12723
12724 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
12725
12726 @node Informational Messages
12727 @subsection Informational Messages
12728
12729 @code{g77} needs an option to suppress information messages (notes).
12730 @samp{-w} does this but also suppresses warnings.
12731 The default should be to suppress info messages.
12732
12733 Perhaps info messages should simply be eliminated.
12734
12735 @node Uninitialized Variables at Run Time
12736 @subsection Uninitialized Variables at Run Time
12737
12738 @code{g77} needs an option to initialize everything (not otherwise
12739 explicitly initialized) to ``weird''
12740 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
12741 largest-magnitude integers, would help track down references to
12742 some kinds of uninitialized variables at run time.
12743
12744 Note that use of the options @samp{-O -Wuninitialized} can catch
12745 many such bugs at compile time.
12746
12747 @node Bounds Checking at Run Time
12748 @subsection Bounds Checking at Run Time
12749
12750 @code{g77} should offer run-time bounds-checking of array/subscript references
12751 in a fashion similar to @code{f2c}.
12752
12753 Note that @code{g77} already warns about references to out-of-bounds
12754 elements of arrays when it detects these at compile time.
12755
12756 @node Portable Unformatted Files
12757 @subsection Portable Unformatted Files
12758
12759 @cindex unformatted files
12760 @cindex file formats
12761 @cindex binary data
12762 @cindex byte ordering
12763 @code{g77} has no facility for exchanging unformatted files with systems
12764 using different number formats---even differing only in endianness (byte
12765 order)---or written by other compilers.  Some compilers provide
12766 facilities at least for doing byte-swapping during unformatted I/O.
12767
12768 It is unrealistic to expect to cope with exchanging unformatted files
12769 with arbitrary other compiler runtimes, but the @code{g77} runtime
12770 should at least be able to read files written by @code{g77} on systems
12771 with different number formats, particularly if they differ only in byte
12772 order.
12773
12774 In case you do need to write a program to translate to or from
12775 @code{g77} (@code{libf2c}) unformatted files, they are written as
12776 follows:
12777 @table @asis
12778 @item Sequential
12779 Unformatted sequential records consist of
12780 @enumerate
12781 @item
12782 A number giving the length of the record contents;
12783 @item
12784 the length of record contents again (for backspace).
12785 @end enumerate
12786
12787 The record length is of C type
12788 @code{long}; this means that it is 8 bytes on 64-bit systems such as
12789 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
12790 Consequently such files cannot be exchanged between 64-bit and 32-bit
12791 systems, even with the same basic number format.
12792 @item Direct access
12793 Unformatted direct access files form a byte stream of length
12794 @var{records}*@var{recl} bytes, where @var{records} is the maximum
12795 record number (@code{REC=@var{records}}) written and @var{recl} is the
12796 record length in bytes specified in the @code{OPEN} statement
12797 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
12798 the relevant @code{WRITE} statement.  Dummy records with arbitrary
12799 contents appear in the file in place of records which haven't been
12800 written.
12801 @end table
12802
12803 Thus for exchanging a sequential or direct access unformatted file
12804 between big- and little-endian 32-bit systems using IEEE 754 floating
12805 point it would be sufficient to reverse the bytes in consecutive words
12806 in the file @emph{iff} only @code{REAL*4}, @code{COMPLEX},
12807 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
12808 @code{g77}.
12809
12810 If necessary, it is possible to do byte-oriented i/o with @code{g77}'s
12811 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
12812 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
12813 array or a set of scalars.
12814
12815 @cindex HDF
12816 @cindex PDB
12817 If you need to exchange binary data between arbitrary system and
12818 compiler variations, we recommend using a portable binary format with
12819 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
12820 or PACT's PDB@footnote{No, not @emph{that} one.}
12821 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
12822 say, CDF or XDR, HDF-like systems write in the native number formats and
12823 only incur overhead when they are read on a system with a different
12824 format.)  A future @code{g77} runtime library should use such
12825 techniques.
12826
12827 @node Labels Visible to Debugger
12828 @subsection Labels Visible to Debugger
12829
12830 @code{g77} should output debugging information for statements labels,
12831 for use by debuggers that know how to support them.
12832 Same with weirder things like construct names.
12833 It is not yet known if any debug formats or debuggers support these.
12834
12835 @node Disappointments
12836 @section Disappointments and Misunderstandings
12837
12838 These problems are perhaps regrettable, but we don't know any practical
12839 way around them for now.
12840
12841 @menu
12842 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
12843                                               external name @samp{foo_}.
12844 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
12845                                               and @samp{SUBROUTINE FOO}.
12846 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
12847 @end menu
12848
12849 @node Mangling of Names
12850 @subsection Mangling of Names in Source Code
12851 @cindex naming issues
12852 @cindex external names
12853 @cindex common blocks
12854 @cindex name space
12855 @cindex underscore
12856
12857 The current external-interface design, which includes naming of
12858 external procedures, COMMON blocks, and the library interface,
12859 has various usability problems, including things like adding
12860 underscores where not really necessary (and preventing easier
12861 inter-language operability) and yet not providing complete
12862 namespace freedom for user C code linked with Fortran apps (due
12863 to the naming of functions in the library, among other things).
12864
12865 Project GNU should at least get all this ``right'' for systems
12866 it fully controls, such as the Hurd, and provide defaults and
12867 options for compatibility with existing systems and interoperability
12868 with popular existing compilers.
12869
12870 @node Multiple Definitions of External Names
12871 @subsection Multiple Definitions of External Names
12872 @cindex block data
12873 @cindex BLOCK DATA statement
12874 @cindex statements, BLOCK DATA
12875 @cindex @code{COMMON} statement
12876 @cindex statements, @code{COMMON}
12877 @cindex naming conflicts
12878
12879 @code{g77} doesn't allow a common block and an external procedure or
12880 @code{BLOCK DATA} to have the same name.
12881 Some systems allow this, but @code{g77} does not,
12882 to be compatible with @code{f2c}.
12883
12884 @code{g77} could special-case the way it handles
12885 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
12886 particular area (necessarily, since @code{g77} offers an
12887 important feature here), but
12888 it is likely that such special-casing would be very annoying to people
12889 with programs that use @samp{EXTERNAL FOO}, with no other mention of
12890 @samp{FOO} in the same program unit, to refer to external procedures, since
12891 the result would be that @code{g77} would treat these references as requests to
12892 force-load BLOCK DATA program units.
12893
12894 In that case, if @code{g77} modified
12895 names of @code{BLOCK DATA} so they could have the same names as
12896 @code{COMMON}, users
12897 would find that their programs wouldn't link because the @samp{FOO} procedure
12898 didn't have its name translated the same way.
12899
12900 (Strictly speaking,
12901 @code{g77} could emit a null-but-externally-satisfying definition of
12902 @samp{FOO} with its name transformed as if it had been a
12903 @code{BLOCK DATA}, but that probably invites more trouble than it's
12904 worth.)
12905
12906 @node Limitation on Implicit Declarations
12907 @subsection Limitation on Implicit Declarations
12908 @cindex IMPLICIT CHARACTER*(*) statement
12909 @cindex statements, IMPLICIT CHARACTER*(*)
12910
12911 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
12912 This is not standard-conforming.
12913
12914 @node Non-bugs
12915 @section Certain Changes We Don't Want to Make
12916
12917 This section lists changes that people frequently request, but which
12918 we do not make because we think GNU Fortran is better without them.
12919
12920 @menu
12921 * Backslash in Constants::           Why @samp{'\\'} is a constant that
12922                                        is one, not two, characters long.
12923 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
12924                                        @samp{COMMON VAR}.
12925 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
12926 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
12927                                        single-precision constant,
12928                                        and might be interpreted as
12929                                        @samp{9.435785} or similar.
12930 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
12931 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
12932                                        not behave as expected.
12933 @end menu
12934
12935 @node Backslash in Constants
12936 @subsection Backslash in Constants
12937 @cindex backslash
12938 @cindex @code{f77} support
12939 @cindex support, @code{f77}
12940
12941 In the opinion of many experienced Fortran users,
12942 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
12943 as currently set by @code{g77}.
12944
12945 First of all, you can always specify
12946 @samp{-fno-backslash} to turn off this processing.
12947
12948 Despite not being within the spirit (though apparently within the
12949 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
12950 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
12951 default to, and apparently lots of code depends on this feature.
12952
12953 This is a particularly troubling issue.
12954 The use of a C construct in the midst of Fortran code
12955 is bad enough, worse when it makes existing Fortran
12956 programs stop working (as happens when programs written
12957 for non-UNIX systems are ported to UNIX systems with
12958 compilers that provide the @samp{-fbackslash} feature
12959 as the default---sometimes with no option to turn it off).
12960
12961 The author of GNU Fortran wished, for reasons of linguistic
12962 purity, to make @samp{-fno-backslash} the default for GNU
12963 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
12964 to specify @samp{-fbackslash} to get the UNIX behavior.
12965
12966 However, the realization that @code{g77} is intended as
12967 a replacement for @emph{UNIX} @code{f77}, caused the author
12968 to choose to make @code{g77} as compatible with
12969 @code{f77} as feasible, which meant making @samp{-fbackslash}
12970 the default.
12971
12972 The primary focus on compatibility is at the source-code
12973 level, and the question became ``What will users expect
12974 a replacement for @code{f77} to do, by default?''
12975 Although at least one UNIX @code{f77} does not provide
12976 @samp{-fbackslash} as a default, it appears that
12977 the majority of them do, which suggests that
12978 the majority of code that is compiled by UNIX @code{f77}
12979 compilers expects @samp{-fbackslash} to be the default.
12980
12981 It is probably the case that more code exists
12982 that would @emph{not} work with @samp{-fbackslash}
12983 in force than code that requires it be in force.
12984
12985 However, most of @emph{that} code is not being compiled
12986 with @code{f77},
12987 and when it is, new build procedures (shell scripts,
12988 makefiles, and so on) must be set up anyway so that
12989 they work under UNIX.
12990 That makes a much more natural and safe opportunity for
12991 non-UNIX users to adapt their build procedures for
12992 @code{g77}'s default of @samp{-fbackslash} than would
12993 exist for the majority of UNIX @code{f77} users who
12994 would have to modify existing, working build procedures
12995 to explicitly specify @samp{-fbackslash} if that was
12996 not the default.
12997
12998 One suggestion has been to configure the default for
12999 @samp{-fbackslash} (and perhaps other options as well)
13000 based on the configuration of @code{g77}.
13001
13002 This is technically quite straightforward, but will be avoided
13003 even in cases where not configuring defaults to be
13004 dependent on a particular configuration greatly inconveniences
13005 some users of legacy code.
13006
13007 Many users appreciate the GNU compilers because they provide an
13008 environment that is uniform across machines.
13009 These users would be
13010 inconvenienced if the compiler treated things like the
13011 format of the source code differently on certain machines.
13012
13013 Occasionally users write programs intended only for a particular machine
13014 type.
13015 On these occasions, the users would benefit if the GNU Fortran compiler
13016 were to support by default the same dialect as the other compilers on
13017 that machine.
13018 But such applications are rare.
13019 And users writing a
13020 program to run on more than one type of machine cannot possibly benefit
13021 from this kind of compatibility.
13022 (This is consistent with the design goals for @code{gcc}.
13023 To change them for @code{g77}, you must first change them
13024 for @code{gcc}.
13025 Do not ask the maintainers of @code{g77} to do this for you,
13026 or to disassociate @code{g77} from the widely understood, if
13027 not widely agreed-upon, goals for GNU compilers in general.)
13028
13029 This is why GNU Fortran does and will treat backslashes in the same
13030 fashion on all types of machines (by default).
13031 @xref{Direction of Language Development}, for more information on
13032 this overall philosophy guiding the development of the GNU Fortran
13033 language.
13034
13035 Of course, users strongly concerned about portability should indicate
13036 explicitly in their build procedures which options are expected
13037 by their source code, or write source code that has as few such
13038 expectations as possible.
13039
13040 For example, avoid writing code that depends on backslash (@samp{\})
13041 being interpreted either way in particular, such as by
13042 starting a program unit with:
13043
13044 @smallexample
13045 CHARACTER BACKSL
13046 PARAMETER (BACKSL = '\\')
13047 @end smallexample
13048
13049 @noindent
13050 Then, use concatenation of @samp{BACKSL} anyplace a backslash
13051 is desired.
13052 In this way, users can write programs which have the same meaning
13053 in many Fortran dialects.
13054
13055 (However, this technique does not work for Hollerith constants---which
13056 is just as well, since the only generally portable uses for Hollerith
13057 constants are in places where character constants can and should
13058 be used instead, for readability.)
13059
13060 @node Initializing Before Specifying
13061 @subsection Initializing Before Specifying
13062 @cindex initialization, statement placement
13063 @cindex placing initialization statements
13064
13065 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
13066 source code before @samp{COMMON VAR},
13067 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
13068 In general, @code{g77} requires initialization of a variable
13069 or array to be specified @emph{after} all other specifications
13070 of attributes (type, size, placement, and so on) of that variable
13071 or array are specified (though @emph{confirmation} of data type is
13072 permitted).
13073
13074 It is @emph{possible} @code{g77} will someday allow all of this,
13075 even though it is not allowed by the FORTRAN 77 standard.
13076
13077 Then again, maybe it is better to have
13078 @code{g77} always require placement of @code{DATA}
13079 so that it can possibly immediately write constants
13080 to the output file, thus saving time and space.
13081
13082 That is, @samp{DATA A/1000000*1/} should perhaps always
13083 be immediately writable to canonical assembler, unless it's already known
13084 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
13085 and to do this it cannot be followed by @samp{COMMON A}.
13086
13087 @node Context-Sensitive Intrinsicness
13088 @subsection Context-Sensitive Intrinsicness
13089 @cindex intrinsics, context-sensitive
13090 @cindex context-sensitive intrinsics
13091
13092 @code{g77} treats procedure references to @emph{possible} intrinsic
13093 names as always enabling their intrinsic nature, regardless of
13094 whether the @emph{form} of the reference is valid for that
13095 intrinsic.
13096
13097 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
13098 an invalid reference to the @code{SQRT} intrinsic function,
13099 because the reference is a subroutine invocation.
13100
13101 First, @code{g77} recognizes the statement @samp{CALL SQRT}
13102 as a reference to a @emph{procedure} named @samp{SQRT}, not
13103 to a @emph{variable} with that name (as it would for a statement
13104 such as @samp{V = SQRT}).
13105
13106 Next, @code{g77} establishes that, in the program unit being compiled,
13107 @code{SQRT} is an intrinsic---not a subroutine that
13108 happens to have the same name as an intrinsic (as would be
13109 the case if, for example, @samp{EXTERNAL SQRT} was present).
13110
13111 Finally, @code{g77} recognizes that the @emph{form} of the
13112 reference is invalid for that particular intrinsic.
13113 That is, it recognizes that it is invalid for an intrinsic
13114 @emph{function}, such as @code{SQRT}, to be invoked as
13115 a @emph{subroutine}.
13116
13117 At that point, @code{g77} issues a diagnostic.
13118
13119 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
13120 references an external subroutine of their own, not an
13121 intrinsic function.
13122
13123 However, @code{g77} knows about intrinsic
13124 subroutines, not just functions, and is able to support both having
13125 the same names, for example.
13126
13127 As a result of this, @code{g77} rejects calls
13128 to intrinsics that are not subroutines, and function invocations
13129 of intrinsics that are not functions, just as it (and most compilers)
13130 rejects invocations of intrinsics with the wrong number (or types)
13131 of arguments.
13132
13133 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
13134 a user-written subroutine named @samp{SQRT}.
13135
13136 @node Context-Sensitive Constants
13137 @subsection Context-Sensitive Constants
13138 @cindex constants, context-sensitive
13139 @cindex context-sensitive constants
13140
13141 @code{g77} does not use context to determine the types of
13142 constants or named constants (@code{PARAMETER}), except
13143 for (non-standard) typeless constants such as @samp{'123'O}.
13144
13145 For example, consider the following statement:
13146
13147 @smallexample
13148 PRINT *, 9.435784839284958 * 2D0
13149 @end smallexample
13150
13151 @noindent
13152 @code{g77} will interpret the (truncated) constant
13153 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
13154 constant, because the suffix @code{D0} is not specified.
13155
13156 As a result, the output of the above statement when
13157 compiled by @code{g77} will appear to have ``less precision''
13158 than when compiled by other compilers.
13159
13160 In these and other cases, some compilers detect the
13161 fact that a single-precision constant is used in
13162 a double-precision context and therefore interpret the
13163 single-precision constant as if it was @emph{explicitly}
13164 specified as a double-precision constant.
13165 (This has the effect of appending @emph{decimal}, not
13166 @emph{binary}, zeros to the fractional part of the
13167 number---producing different computational results.)
13168
13169 The reason this misfeature is dangerous is that a slight,
13170 apparently innocuous change to the source code can change
13171 the computational results.
13172 Consider:
13173
13174 @smallexample
13175 REAL ALMOST, CLOSE
13176 DOUBLE PRECISION FIVE
13177 PARAMETER (ALMOST = 5.000000000001)
13178 FIVE = 5
13179 CLOSE = 5.000000000001
13180 PRINT *, 5.000000000001 - FIVE
13181 PRINT *, ALMOST - FIVE
13182 PRINT *, CLOSE - FIVE
13183 END
13184 @end smallexample
13185
13186 @noindent
13187 Running the above program should
13188 result in the same value being
13189 printed three times.
13190 With @code{g77} as the compiler,
13191 it does.
13192
13193 However, compiled by many other compilers,
13194 running the above program would print
13195 two or three distinct values, because
13196 in two or three of the statements, the
13197 constant @samp{5.000000000001}, which
13198 on most systems is exactly equal to @samp{5.}
13199 when interpreted as a single-precision constant,
13200 is instead interpreted as a double-precision
13201 constant, preserving the represented
13202 precision.
13203 However, this ``clever'' promotion of
13204 type does not extend to variables or,
13205 in some compilers, to named constants.
13206
13207 Since programmers often are encouraged to replace manifest
13208 constants or permanently-assigned variables with named
13209 constants (@code{PARAMETER} in Fortran), and might need
13210 to replace some constants with variables having the same
13211 values for pertinent portions of code,
13212 it is important that compilers treat code so modified in the
13213 same way so that the results of such programs are the same.
13214 @code{g77} helps in this regard by treating constants just
13215 the same as variables in terms of determining their types
13216 in a context-independent way.
13217
13218 Still, there is a lot of existing Fortran code that has
13219 been written to depend on the way other compilers freely
13220 interpret constants' types based on context, so anything
13221 @code{g77} can do to help flag cases of this in such code
13222 could be very helpful.
13223
13224 @node Equivalence Versus Equality
13225 @subsection Equivalence Versus Equality
13226 @cindex .EQV., with integer operands
13227 @cindex comparing logical expressions
13228 @cindex logical expressions, comparing
13229
13230 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
13231 is not supported, except via @samp{-fugly}, which is not
13232 recommended except for legacy code (where the behavior expected
13233 by the @emph{code} is assumed).
13234
13235 Legacy code should be changed, as resources permit, to use @code{.EQV.}
13236 and @code{.NEQV.} instead, as these are permitted by the various
13237 Fortran standards.
13238
13239 New code should never be written expecting @code{.EQ.} or @code{.NE.}
13240 to work if either of its operands is @code{LOGICAL}.
13241
13242 The problem with supporting this ``feature'' is that there is
13243 unlikely to be consensus on how it works, as illustrated by the
13244 following sample program:
13245
13246 @smallexample
13247 LOGICAL L,M,N
13248 DATA L,M,N /3*.FALSE./
13249 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
13250 END
13251 @end smallexample
13252
13253 The issue raised by the above sample program is: what is the
13254 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
13255 @code{LOGICAL} operands?
13256
13257 Some programmers will argue that it is the same as the precedence
13258 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
13259 operands.
13260 By this interpretation, the subexpression @samp{M.EQ.N} must be
13261 evaluated first in the above program, resulting in a program that,
13262 when run, does not execute the @code{PRINT} statement.
13263
13264 Other programmers will argue that the precedence is the same as
13265 the precedence for @code{.EQV.}, which is restricted by the standards
13266 to @code{LOGICAL} operands.
13267 By this interpretation, the subexpression @samp{L.AND.M} must be
13268 evaluated first, resulting in a program that @emph{does} execute
13269 the @code{PRINT} statement.
13270
13271 Assigning arbitrary semantic interpretations to syntactic expressions
13272 that might legitimately have more than one ``obvious'' interpretation
13273 is generally unwise.
13274
13275 The creators of the various Fortran standards have done a good job
13276 in this case, requiring a distinct set of operators (which have their
13277 own distinct precedence) to compare @code{LOGICAL} operands.
13278 This requirement results in expression syntax with more certain
13279 precedence (without requiring substantial context), making it easier
13280 for programmers to read existing code.
13281 @code{g77} will avoid muddying up elements of the Fortran language
13282 that were well-designed in the first place.
13283
13284 (Ask C programmers about the precedence of expressions such as
13285 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
13286 you, without knowing more context, whether the @samp{&} and @samp{-}
13287 operators are infix (binary) or unary!)
13288
13289 @node Order of Side Effects
13290 @subsection Order of Side Effects
13291 @cindex side effects, order of evaluation
13292 @cindex order of evaluation, side effects
13293
13294 @code{g77} does not necessarily produce code that, when run, performs
13295 side effects (such as those performed by function invocations)
13296 in the same order as in some other compiler---or even in the same
13297 order as another version, port, or invocation (using different
13298 command-line options) of @code{g77}.
13299
13300 It is never safe to depend on the order of evaluation of side effects.
13301 For example, an expression like this may very well behave differently
13302 from one compiler to another:
13303
13304 @smallexample
13305 J = IFUNC() - IFUNC()
13306 @end smallexample
13307
13308 @noindent
13309 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
13310 order.
13311 Either invocation might happen first.
13312 If @samp{IFUNC} returns 5 the first time it is invoked, and
13313 returns 12 the second time, @samp{J} might end up with the
13314 value @samp{7}, or it might end up with @samp{-7}.
13315
13316 Generally, in Fortran, procedures with side-effects intended to
13317 be visible to the caller are best designed as @emph{subroutines},
13318 not functions.
13319 Examples of such side-effects include:
13320
13321 @itemize @bullet
13322 @item
13323 The generation of random numbers
13324 that are intended to influence return values.
13325
13326 @item
13327 Performing I/O
13328 (other than internal I/O to local variables).
13329
13330 @item
13331 Updating information in common blocks.
13332 @end itemize
13333
13334 An example of a side-effect that is not intended to be visible
13335 to the caller is a function that maintains a cache of recently
13336 calculated results, intended solely to speed repeated invocations
13337 of the function with identical arguments.
13338 Such a function can be safely used in expressions, because
13339 if the compiler optimizes away one or more calls to the
13340 function, operation of the program is unaffected (aside
13341 from being speeded up).
13342
13343 @node Warnings and Errors
13344 @section Warning Messages and Error Messages
13345
13346 @cindex error messages
13347 @cindex warnings vs errors
13348 @cindex messages, warning and error
13349 The GNU compiler can produce two kinds of diagnostics: errors and
13350 warnings.
13351 Each kind has a different purpose:
13352
13353 @itemize @w{}
13354 @item
13355 @emph{Errors} report problems that make it impossible to compile your
13356 program.
13357 GNU Fortran reports errors with the source file name, line
13358 number, and column within the line where the problem is apparent.
13359
13360 @item
13361 @emph{Warnings} report other unusual conditions in your code that
13362 @emph{might} indicate a problem, although compilation can (and does)
13363 proceed.
13364 Warning messages also report the source file name, line number,
13365 and column information,
13366 but include the text @samp{warning:} to distinguish them
13367 from error messages.
13368 @end itemize
13369
13370 Warnings might indicate danger points where you should check to make sure
13371 that your program really does what you intend; or the use of obsolete
13372 features; or the use of nonstandard features of GNU Fortran.
13373 Many warnings are issued only if you ask for them, with one of the
13374 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
13375 useful warnings).
13376
13377 @emph{Note:} Currently, the text of the line and a pointer to the column
13378 is printed in most @code{g77} diagnostics.
13379 Probably, as of version 0.6, @code{g77} will
13380 no longer print the text of the source line, instead printing
13381 the column number following the file name and line number in
13382 a form that GNU Emacs recognizes.
13383 This change is expected to speed up and reduce the memory usage
13384 of the @code{g77} compiler.
13385 @c
13386 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
13387 @c
13388 @c GNU Fortran always tries to compile your program if possible; it never
13389 @c gratuitously rejects a program whose meaning is clear merely because
13390 @c (for instance) it fails to conform to a standard.  In some cases,
13391 @c however, the Fortran standard specifies that certain extensions are
13392 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
13393 @c compiler.  The @samp{-pedantic} option tells GNU Fortran to issue warnings
13394 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
13395 @c This does not mean that @emph{all} non-ANSI constructs get warnings
13396 @c or errors.
13397
13398 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
13399 more detail on these and related command-line options.
13400
13401 @node Open Questions
13402 @chapter Open Questions
13403
13404 Please consider offering useful answers to these questions!
13405
13406 @itemize @bullet
13407 @item
13408 @code{LOC()} and other intrinsics are probably somewhat misclassified.
13409 Is the a need for more precise classification of intrinsics, and if so,
13410 what are the appropriate groupings?
13411 Is there a need to individually
13412 enable/disable/delete/hide intrinsics from the command line?
13413 @end itemize
13414
13415 @node Bugs
13416 @chapter Reporting Bugs
13417 @cindex bugs
13418 @cindex reporting bugs
13419
13420 Your bug reports play an essential role in making GNU Fortran reliable.
13421
13422 When you encounter a problem, the first thing to do is to see if it is
13423 already known.
13424 @xref{Trouble}.
13425 If it isn't known, then you should report the problem.
13426
13427 Reporting a bug might help you by bringing a solution to your problem, or
13428 it might not.
13429 (If it does not, look in the service directory; see
13430 @ref{Service}.)
13431 In any case, the principal function of a bug report is
13432 to help the entire community by making the next version of GNU Fortran work
13433 better.
13434 Bug reports are your contribution to the maintenance of GNU Fortran.
13435
13436 Since the maintainers are very overloaded, we cannot respond to every
13437 bug report.
13438 However, if the bug has not been fixed, we are likely to
13439 send you a patch and ask you to tell us whether it works.
13440
13441 In order for a bug report to serve its purpose, you must include the
13442 information that makes for fixing the bug.
13443
13444 @menu
13445 * Criteria: Bug Criteria.    Have you really found a bug?
13446 * Where: Bug Lists.          Where to send your bug report.
13447 * Reporting: Bug Reporting.  How to report a bug effectively.
13448 * Patches: Sending Patches.  How to send a patch for GNU Fortran.
13449 @end menu
13450
13451 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
13452 for information on problems we already know about.
13453
13454 @xref{Service,,How To Get Help with GNU Fortran},
13455 for information on where to ask for help.
13456
13457 @node Bug Criteria
13458 @section Have You Found a Bug?
13459 @cindex bug criteria
13460
13461 If you are not sure whether you have found a bug, here are some guidelines:
13462
13463 @itemize @bullet
13464 @cindex fatal signal
13465 @cindex core dump
13466 @item
13467 If the compiler gets a fatal signal, for any input whatever, that is a
13468 compiler bug.
13469 Reliable compilers never crash---they just remain obsolete.
13470
13471 @cindex invalid assembly code
13472 @cindex assembly code, invalid
13473 @item
13474 If the compiler produces invalid assembly code, for any input whatever,
13475 @c (except an @code{asm} statement),
13476 that is a compiler bug, unless the
13477 compiler reports errors (not just warnings) which would ordinarily
13478 prevent the assembler from being run.
13479
13480 @cindex undefined behavior
13481 @cindex undefined function value
13482 @item
13483 If the compiler produces valid assembly code that does not correctly
13484 execute the input source code, that is a compiler bug.
13485
13486 However, you must double-check to make sure, because you might have run
13487 into an incompatibility between GNU Fortran and traditional Fortran.
13488 @c (@pxref{Incompatibilities}).
13489 These incompatibilities might be considered
13490 bugs, but they are inescapable consequences of valuable features.
13491
13492 Or you might have a program whose behavior is undefined, which happened
13493 by chance to give the desired results with another Fortran compiler.
13494 It is best to check the relevant Fortran standard thoroughly if
13495 it is possible that the program indeed does something undefined.
13496
13497 After you have localized the error to a single source line, it should
13498 be easy to check for these things.
13499 If your program is correct and well defined, you have found
13500 a compiler bug.
13501
13502 It might help if, in your submission, you identified the specific
13503 language in the relevant Fortran standard that specifies the
13504 desired behavior, if it isn't likely to be obvious and agreed-upon
13505 by all Fortran users.
13506
13507 @item
13508 If the compiler produces an error message for valid input, that is a
13509 compiler bug.
13510
13511 @cindex invalid input
13512 @item
13513 If the compiler does not produce an error message for invalid input,
13514 that is a compiler bug.
13515 However, you should note that your idea of
13516 ``invalid input'' might be someone else's idea
13517 of ``an extension'' or ``support for traditional practice''.
13518
13519 @item
13520 If you are an experienced user of Fortran compilers, your suggestions
13521 for improvement of GNU Fortran are welcome in any case.
13522 @end itemize
13523
13524 Many, perhaps most, bug reports against @code{g77} turn out to
13525 be bugs in the user's code.
13526 While we find such bug reports educational, they sometimes take
13527 a considerable amount of time to track down or at least respond
13528 to---time we could be spending making @code{g77}, not some user's
13529 code, better.
13530
13531 Some steps you can take to verify that the bug is not certainly
13532 in the code you're compiling with @code{g77}:
13533
13534 @itemize @bullet
13535 @item
13536 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
13537 These options enable many useful warning; the @samp{-O} option
13538 enables flow analysis that enables the uninitialized-variable
13539 warning.
13540
13541 If you investigate the warnings and find evidence of possible bugs
13542 in your code, fix them first and retry @code{g77}.
13543
13544 @item
13545 Compile your code using the @code{g77} options @samp{-finit-local-zero},
13546 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
13547 combinations thereof.
13548
13549 If your code works with any of these combinations, that is not
13550 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
13551 by your code might simply be avoided, or have a different, more subtle
13552 effect, when different options are used---but it can be a
13553 strong indicator that your code is making unwarranted assumptions
13554 about the Fortran dialect and/or underlying machine it is
13555 being compiled and run on.
13556
13557 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
13558 for information on the @samp{-fno-automatic} and
13559 @samp{-finit-local-zero} options and how to convert
13560 their use into selective changes in your own code.
13561
13562 @item
13563 @pindex ftnchek
13564 Validate your code with @code{ftnchek} or a similar code-checking
13565 tool.
13566 @code{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
13567 or @uref{ftp://ftp.dsm.fordham.edu}.
13568
13569 @pindex make
13570 @cindex Makefile example
13571 Here are some sample @file{Makefile} rules using @code{ftnchek}
13572 ``project'' files to do cross-file checking and @code{sfmakedepend}
13573 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
13574 to maintain dependencies automatically.
13575 These assume the use of GNU @code{make}.
13576
13577 @smallexample
13578 # Dummy suffix for ftnchek targets:
13579 .SUFFIXES: .chek
13580 .PHONY: chekall
13581
13582 # How to compile .f files (for implicit rule):
13583 FC = g77
13584 # Assume `include' directory:
13585 FFLAGS = -Iinclude -g -O -Wall
13586
13587 # Flags for ftnchek:
13588 CHEK1 = -array=0 -include=includes -noarray
13589 CHEK2 = -nonovice -usage=1 -notruncation
13590 CHEKFLAGS = $(CHEK1) $(CHEK2)
13591
13592 # Run ftnchek with all the .prj files except the one corresponding
13593 # to the target's root:
13594 %.chek : %.f ; \
13595   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
13596     -noextern -library $<
13597
13598 # Derive a project file from a source file:
13599 %.prj : %.f ; \
13600   ftnchek $(CHEKFLAGS) -noextern -project -library $<
13601
13602 # The list of objects is assumed to be in variable OBJS.
13603 # Sources corresponding to the objects:
13604 SRCS = $(OBJS:%.o=%.f)
13605 # ftnchek project files:
13606 PRJS = $(OBJS:%.o=%.prj)
13607
13608 # Build the program
13609 prog: $(OBJS) ; \
13610   $(FC) -o $@ $(OBJS)
13611
13612 chekall: $(PRJS) ; \
13613   ftnchek $(CHEKFLAGS) $(PRJS)
13614
13615 prjs: $(PRJS)
13616
13617 # For Emacs M-x find-tag:
13618 TAGS: $(SRCS) ; \
13619   etags $(SRCS)
13620
13621 # Rebuild dependencies:
13622 depend: ; \
13623   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
13624 @end smallexample
13625
13626 @item
13627 Try your code out using other Fortran compilers, such as @code{f2c}.
13628 If it does not work on at least one other compiler (assuming the
13629 compiler supports the features the code needs), that is a strong
13630 indicator of a bug in the code.
13631
13632 However, even if your code works on many compilers @emph{except}
13633 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
13634 It might mean the bug is in your code, and that @code{g77} simply
13635 exposes it more readily than other compilers.
13636 @end itemize
13637
13638 @node Bug Lists
13639 @section Where to Report Bugs
13640 @cindex bug report mailing lists
13641 @kindex @value{email-bugs}
13642 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
13643
13644 Often people think of posting bug reports to a newsgroup instead of
13645 mailing them.
13646 This sometimes appears to work, but it has one problem which can be
13647 crucial: a newsgroup posting does not contain a mail path back to the
13648 sender.
13649 Thus, if maintainers need more information, they might be unable
13650 to reach you.  For this reason, you should always send bug reports by
13651 mail to the proper mailing list.
13652
13653 As a last resort, send bug reports on paper to:
13654
13655 @example
13656 GNU Compiler Bugs
13657 Free Software Foundation
13658 59 Temple Place - Suite 330
13659 Boston, MA 02111-1307, USA
13660 @end example
13661
13662 @node Bug Reporting
13663 @section How to Report Bugs
13664 @cindex compiler bugs, reporting
13665
13666 The fundamental principle of reporting bugs usefully is this:
13667 @strong{report all the facts}.
13668 If you are not sure whether to state a
13669 fact or leave it out, state it!
13670
13671 Often people omit facts because they think they know what causes the
13672 problem and they conclude that some details don't matter.
13673 Thus, you might
13674 assume that the name of the variable you use in an example does not matter.
13675 Well, probably it doesn't, but one cannot be sure.
13676 Perhaps the bug is a
13677 stray memory reference which happens to fetch from the location where that
13678 name is stored in memory; perhaps, if the name were different, the contents
13679 of that location would fool the compiler into doing the right thing despite
13680 the bug.
13681 Play it safe and give a specific, complete example.
13682 That is the
13683 easiest thing for you to do, and the most helpful.
13684
13685 Keep in mind that the purpose of a bug report is to enable someone to
13686 fix the bug if it is not known.
13687 It isn't very important what happens if
13688 the bug is already known.
13689 Therefore, always write your bug reports on
13690 the assumption that the bug is not known.
13691
13692 Sometimes people give a few sketchy facts and ask, ``Does this ring a
13693 bell?''
13694 This cannot help us fix a bug, so it is rarely helpful.
13695 We respond by asking for enough details to enable us to investigate.
13696 You might as well expedite matters by sending them to begin with.
13697 (Besides, there are enough bells ringing around here as it is.)
13698
13699 Try to make your bug report self-contained.
13700 If we have to ask you for
13701 more information, it is best if you include all the previous information
13702 in your response, as well as the information that was missing.
13703
13704 Please report each bug in a separate message.
13705 This makes it easier for
13706 us to track which bugs have been fixed and to forward your bugs reports
13707 to the appropriate maintainer.
13708
13709 Do not compress and encode any part of your bug report using programs
13710 such as @file{uuencode}.
13711 If you do so it will slow down the processing
13712 of your bug.
13713 If you must submit multiple large files, use @file{shar},
13714 which allows us to read your message without having to run any
13715 decompression programs.
13716
13717 (As a special exception for GNU Fortran bug-reporting, at least
13718 for now, if you are sending more than a few lines of code, if
13719 your program's source file format contains ``interesting'' things
13720 like trailing spaces or strange characters, or if you need to
13721 include binary data files, it is acceptable to put all the
13722 files together in a @code{tar} archive, and, whether you need to
13723 do that, it is acceptable to then compress the single file (@code{tar}
13724 archive or source file)
13725 using @code{gzip} and encode it via @code{uuencode}.
13726 Do not use any MIME stuff---the current maintainer can't decode this.
13727 Using @code{compress} instead of @code{gzip} is acceptable, assuming
13728 you have licensed the use of the patented algorithm in
13729 @code{compress} from Unisys.)
13730
13731 To enable someone to investigate the bug, you should include all these
13732 things:
13733
13734 @itemize @bullet
13735 @item
13736 The version of GNU Fortran.
13737 You can get this by running @code{g77} with the @samp{-v} option.
13738 (Ignore any error messages that might be displayed
13739 when the linker is run.)
13740
13741 Without this, we won't know whether there is any point in looking for
13742 the bug in the current version of GNU Fortran.
13743
13744 @item
13745 @cindex preprocessor
13746 @cindex cpp program
13747 @cindex programs, cpp
13748 @pindex cpp
13749 A complete input file that will reproduce the bug.
13750
13751 If your source file(s) require preprocessing
13752 (for example, their names have suffixes like
13753 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
13754 and the bug is in the compiler proper (@file{f771})
13755 or in a subsequent phase of processing,
13756 run your source file through the C preprocessor
13757 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
13758 Then, include the contents of @var{newfile} in the bug report.
13759 (When you do this, use the same preprocessor options---such as
13760 @samp{-I}, @samp{-D}, and @samp{-U}---that you used in actual
13761 compilation.)
13762
13763 A single statement is not enough of an example.
13764 In order to compile it,
13765 it must be embedded in a complete file of compiler input.
13766 The bug might depend on the details of how this is done.
13767
13768 Without a real example one can compile,
13769 all anyone can do about your bug report is wish you luck.
13770 It would be futile to try to guess how to provoke the bug.
13771 For example, bugs in register allocation and reloading
13772 can depend on every little detail of the source and include files
13773 that trigger them.
13774
13775 @item
13776 @cindex included files
13777 @cindex INCLUDE directive
13778 @cindex directive, INCLUDE
13779 @cindex #include directive
13780 @cindex directive, #include
13781 Note that you should include with your bug report any files
13782 included by the source file
13783 (via the @code{#include} or @code{INCLUDE} directive)
13784 that you send, and any files they include, and so on.
13785
13786 It is not necessary to replace
13787 the @code{#include} and @code{INCLUDE} directives
13788 with the actual files in the version of the source file that
13789 you send, but it might make submitting the bug report easier
13790 in the end.
13791 However, be sure to @emph{reproduce} the bug using the @emph{exact}
13792 version of the source material you submit, to avoid wild-goose
13793 chases.
13794
13795 @item
13796 The command arguments you gave GNU Fortran to compile that example
13797 and observe the bug.  For example, did you use @samp{-O}?  To guarantee
13798 you won't omit something important, list all the options.
13799
13800 If we were to try to guess the arguments, we would probably guess wrong
13801 and then we would not encounter the bug.
13802
13803 @item
13804 The type of machine you are using, and the operating system name and
13805 version number.
13806 (Much of this information is printed by @samp{g77 -v}---if you
13807 include that, send along any additional info you have that you
13808 don't see clearly represented in that output.)
13809
13810 @item
13811 The operands you gave to the @code{configure} command when you installed
13812 the compiler.
13813
13814 @item
13815 A complete list of any modifications you have made to the compiler
13816 source.  (We don't promise to investigate the bug unless it happens in
13817 an unmodified compiler.  But if you've made modifications and don't tell
13818 us, then you are sending us on a wild-goose chase.)
13819
13820 Be precise about these changes.  A description in English is not
13821 enough---send a context diff for them.
13822
13823 Adding files of your own (such as a machine description for a machine we
13824 don't support) is a modification of the compiler source.
13825
13826 @item
13827 Details of any other deviations from the standard procedure for installing
13828 GNU Fortran.
13829
13830 @item
13831 A description of what behavior you observe that you believe is
13832 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
13833 ``The assembler instruction at line 208 in the output is incorrect.''
13834
13835 Of course, if the bug is that the compiler gets a fatal signal, then one
13836 can't miss it.  But if the bug is incorrect output, the maintainer might
13837 not notice unless it is glaringly wrong.  None of us has time to study
13838 all the assembler code from a 50-line Fortran program just on the chance that
13839 one instruction might be wrong.  We need @emph{you} to do this part!
13840
13841 Even if the problem you experience is a fatal signal, you should still
13842 say so explicitly.  Suppose something strange is going on, such as, your
13843 copy of the compiler is out of synch, or you have encountered a bug in
13844 the C library on your system.  (This has happened!)  Your copy might
13845 crash and the copy here would not.  If you @i{said} to expect a crash,
13846 then when the compiler here fails to crash, we would know that the bug
13847 was not happening.  If you don't say to expect a crash, then we would
13848 not know whether the bug was happening.  We would not be able to draw
13849 any conclusion from our observations.
13850
13851 If the problem is a diagnostic when building GNU Fortran with some other
13852 compiler, say whether it is a warning or an error.
13853
13854 Often the observed symptom is incorrect output when your program is run.
13855 Sad to say, this is not enough information unless the program is short
13856 and simple.  None of us has time to study a large program to figure out
13857 how it would work if compiled correctly, much less which line of it was
13858 compiled wrong.  So you will have to do that.  Tell us which source line
13859 it is, and what incorrect result happens when that line is executed.  A
13860 person who understands the program can find this as easily as finding a
13861 bug in the program itself.
13862
13863 @item
13864 If you send examples of assembler code output from GNU Fortran,
13865 please use @samp{-g} when you make them.  The debugging information
13866 includes source line numbers which are essential for correlating the
13867 output with the input.
13868
13869 @item
13870 If you wish to mention something in the GNU Fortran source, refer to it by
13871 context, not by line number.
13872
13873 The line numbers in the development sources don't match those in your
13874 sources.  Your line numbers would convey no convenient information to the
13875 maintainers.
13876
13877 @item
13878 Additional information from a debugger might enable someone to find a
13879 problem on a machine which he does not have available.  However, you
13880 need to think when you collect this information if you want it to have
13881 any chance of being useful.
13882
13883 @cindex backtrace for bug reports
13884 For example, many people send just a backtrace, but that is never
13885 useful by itself.  A simple backtrace with arguments conveys little
13886 about GNU Fortran because the compiler is largely data-driven; the same
13887 functions are called over and over for different RTL insns, doing
13888 different things depending on the details of the insn.
13889
13890 Most of the arguments listed in the backtrace are useless because they
13891 are pointers to RTL list structure.  The numeric values of the
13892 pointers, which the debugger prints in the backtrace, have no
13893 significance whatever; all that matters is the contents of the objects
13894 they point to (and most of the contents are other such pointers).
13895
13896 In addition, most compiler passes consist of one or more loops that
13897 scan the RTL insn sequence.  The most vital piece of information about
13898 such a loop---which insn it has reached---is usually in a local variable,
13899 not in an argument.
13900
13901 @findex debug_rtx
13902 What you need to provide in addition to a backtrace are the values of
13903 the local variables for several stack frames up.  When a local
13904 variable or an argument is an RTX, first print its value and then use
13905 the GDB command @code{pr} to print the RTL expression that it points
13906 to.  (If GDB doesn't run on your machine, use your debugger to call
13907 the function @code{debug_rtx} with the RTX as an argument.)  In
13908 general, whenever a variable is a pointer, its value is no use
13909 without the data it points to.
13910 @end itemize
13911
13912 Here are some things that are not necessary:
13913
13914 @itemize @bullet
13915 @item
13916 A description of the envelope of the bug.
13917
13918 Often people who encounter a bug spend a lot of time investigating
13919 which changes to the input file will make the bug go away and which
13920 changes will not affect it.
13921
13922 This is often time consuming and not very useful, because the way we
13923 will find the bug is by running a single example under the debugger with
13924 breakpoints, not by pure deduction from a series of examples.  You might
13925 as well save your time for something else.
13926
13927 Of course, if you can find a simpler example to report @emph{instead} of
13928 the original one, that is a convenience.  Errors in the output will be
13929 easier to spot, running under the debugger will take less time, etc.
13930 Most GNU Fortran bugs involve just one function, so the most straightforward
13931 way to simplify an example is to delete all the function definitions
13932 except the one where the bug occurs.  Those earlier in the file may be
13933 replaced by external declarations if the crucial function depends on
13934 them.  (Exception: inline functions might affect compilation of functions
13935 defined later in the file.)
13936
13937 However, simplification is not vital; if you don't want to do this,
13938 report the bug anyway and send the entire test case you used.
13939
13940 @item
13941 In particular, some people insert conditionals @samp{#ifdef BUG} around
13942 a statement which, if removed, makes the bug not happen.  These are just
13943 clutter; we won't pay any attention to them anyway.  Besides, you should
13944 send us preprocessor output, and that can't have conditionals.
13945
13946 @item
13947 A patch for the bug.
13948
13949 A patch for the bug is useful if it is a good one.  But don't omit the
13950 necessary information, such as the test case, on the assumption that a
13951 patch is all we need.  We might see problems with your patch and decide
13952 to fix the problem another way, or we might not understand it at all.
13953
13954 Sometimes with a program as complicated as GNU Fortran it is very hard to
13955 construct an example that will make the program follow a certain path
13956 through the code.  If you don't send the example, we won't be able to
13957 construct one, so we won't be able to verify that the bug is fixed.
13958
13959 And if we can't understand what bug you are trying to fix, or why your
13960 patch should be an improvement, we won't install it.  A test case will
13961 help us to understand.
13962
13963 @xref{Sending Patches}, for guidelines on how to make it easy for us to
13964 understand and install your patches.
13965
13966 @item
13967 A guess about what the bug is or what it depends on.
13968
13969 Such guesses are usually wrong.  Even the maintainer can't guess right
13970 about such things without first using the debugger to find the facts.
13971
13972 @item
13973 A core dump file.
13974
13975 We have no way of examining a core dump for your type of machine
13976 unless we have an identical system---and if we do have one,
13977 we should be able to reproduce the crash ourselves.
13978 @end itemize
13979
13980 @node Sending Patches
13981 @section Sending Patches for GNU Fortran
13982
13983 If you would like to write bug fixes or improvements for the GNU Fortran
13984 compiler, that is very helpful.
13985 Send suggested fixes to the bug report
13986 mailing list, @email{@value{email-bugs}}.
13987
13988 Please follow these guidelines so we can study your patches efficiently.
13989 If you don't follow these guidelines, your information might still be
13990 useful, but using it will take extra work.  Maintaining GNU Fortran is a lot
13991 of work in the best of circumstances, and we can't keep up unless you do
13992 your best to help.
13993
13994 @itemize @bullet
13995 @item
13996 Send an explanation with your changes of what problem they fix or what
13997 improvement they bring about.  For a bug fix, just include a copy of the
13998 bug report, and explain why the change fixes the bug.
13999
14000 (Referring to a bug report is not as good as including it, because then
14001 we will have to look it up, and we have probably already deleted it if
14002 we've already fixed the bug.)
14003
14004 @item
14005 Always include a proper bug report for the problem you think you have
14006 fixed.  We need to convince ourselves that the change is right before
14007 installing it.  Even if it is right, we might have trouble judging it if
14008 we don't have a way to reproduce the problem.
14009
14010 @item
14011 Include all the comments that are appropriate to help people reading the
14012 source in the future understand why this change was needed.
14013
14014 @item
14015 Don't mix together changes made for different reasons.
14016 Send them @emph{individually}.
14017
14018 If you make two changes for separate reasons, then we might not want to
14019 install them both.  We might want to install just one.  If you send them
14020 all jumbled together in a single set of diffs, we have to do extra work
14021 to disentangle them---to figure out which parts of the change serve
14022 which purpose.  If we don't have time for this, we might have to ignore
14023 your changes entirely.
14024
14025 If you send each change as soon as you have written it, with its own
14026 explanation, then the two changes never get tangled up, and we can
14027 consider each one properly without any extra work to disentangle them.
14028
14029 Ideally, each change you send should be impossible to subdivide into
14030 parts that we might want to consider separately, because each of its
14031 parts gets its motivation from the other parts.
14032
14033 @item
14034 Send each change as soon as that change is finished.  Sometimes people
14035 think they are helping us by accumulating many changes to send them all
14036 together.  As explained above, this is absolutely the worst thing you
14037 could do.
14038
14039 Since you should send each change separately, you might as well send it
14040 right away.  That gives us the option of installing it immediately if it
14041 is important.
14042
14043 @item
14044 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
14045 for us to install reliably.  More than that, they make it hard for us to
14046 study the diffs to decide whether we want to install them.  Unidiff
14047 format is better than contextless diffs, but not as easy to read as
14048 @samp{-c} format.
14049
14050 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
14051 function that each change occurs in.
14052 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
14053
14054 @item
14055 Write the change log entries for your changes.  We get lots of changes,
14056 and we don't have time to do all the change log writing ourselves.
14057
14058 Read the @file{ChangeLog} file to see what sorts of information to put
14059 in, and to learn the style that we use.  The purpose of the change log
14060 is to show people where to find what was changed.  So you need to be
14061 specific about what functions you changed; in large functions, it's
14062 often helpful to indicate where within the function the change was.
14063
14064 On the other hand, once you have shown people where to find the change,
14065 you need not explain its purpose.  Thus, if you add a new function, all
14066 you need to say about it is that it is new.  If you feel that the
14067 purpose needs explaining, it probably does---but the explanation will be
14068 much more useful if you put it in comments in the code.
14069
14070 If you would like your name to appear in the header line for who made
14071 the change, send us the header line.
14072
14073 @item
14074 When you write the fix, keep in mind that we can't install a change that
14075 would break other systems.
14076
14077 People often suggest fixing a problem by changing machine-independent
14078 files such as @file{toplev.c} to do something special that a particular
14079 system needs.  Sometimes it is totally obvious that such changes would
14080 break GNU Fortran for almost all users.  We can't possibly make a change like
14081 that.  At best it might tell us how to write another patch that would
14082 solve the problem acceptably.
14083
14084 Sometimes people send fixes that @emph{might} be an improvement in
14085 general---but it is hard to be sure of this.  It's hard to install
14086 such changes because we have to study them very carefully.  Of course,
14087 a good explanation of the reasoning by which you concluded the change
14088 was correct can help convince us.
14089
14090 The safest changes are changes to the configuration files for a
14091 particular machine.  These are safe because they can't create new bugs
14092 on other machines.
14093
14094 Please help us keep up with the workload by designing the patch in a
14095 form that is good to install.
14096 @end itemize
14097
14098 @node Service
14099 @chapter How To Get Help with GNU Fortran
14100
14101 If you need help installing, using or changing GNU Fortran, there are two
14102 ways to find it:
14103
14104 @itemize @bullet
14105 @item
14106 Look in the service directory for someone who might help you for a fee.
14107 The service directory is found in the file named @file{SERVICE} in the
14108 GNU CC distribution.
14109
14110 @item
14111 Send a message to @email{@value{email-general}}.
14112 @end itemize
14113
14114 @end ifset
14115 @ifset INTERNALS
14116 @node Adding Options
14117 @chapter Adding Options
14118 @cindex options, adding
14119 @cindex adding options
14120
14121 To add a new command-line option to @code{g77}, first decide
14122 what kind of option you wish to add.
14123 Search the @code{g77} and @code{gcc} documentation for one
14124 or more options that is most closely like the one you want to add
14125 (in terms of what kind of effect it has, and so on) to
14126 help clarify its nature.
14127
14128 @itemize @bullet
14129 @item
14130 @emph{Fortran options} are options that apply only
14131 when compiling Fortran programs.
14132 They are accepted by @code{g77} and @code{gcc}, but
14133 they apply only when compiling Fortran programs.
14134
14135 @item
14136 @emph{Compiler options} are options that apply
14137 when compiling most any kind of program.
14138 @end itemize
14139
14140 @emph{Fortran options} are listed in the file
14141 @file{@value{path-g77}/lang-options.h},
14142 which is used during the build of @code{gcc} to
14143 build a list of all options that are accepted by
14144 at least one language's compiler.
14145 This list goes into the @samp{lang_options} array
14146 in @file{gcc/toplev.c}, which uses this array to
14147 determine whether a particular option should be
14148 offered to the linked-in front end for processing
14149 by calling @samp{lang_option_decode}, which, for
14150 @code{g77}, is in @file{@value{path-g77}/com.c} and just
14151 calls @samp{ffe_decode_option}.
14152
14153 If the linked-in front end ``rejects'' a
14154 particular option passed to it, @file{toplev.c}
14155 just ignores the option, because @emph{some}
14156 language's compiler is willing to accept it.
14157
14158 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
14159 to work, even though Fortran compilation does
14160 not currently support the @samp{-fno-asm} option;
14161 even though the @code{f771} version of @samp{lang_decode_option}
14162 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
14163 produce a diagnostic because some other language (C)
14164 does accept it.
14165
14166 This also means that commands like
14167 @samp{g77 -fno-asm foo.f} yield no diagnostics,
14168 despite the fact that no phase of the command was
14169 able to recognize and process @samp{-fno-asm}---perhaps
14170 a warning about this would be helpful if it were
14171 possible.
14172
14173 Code that processes Fortran options is found in
14174 @file{@value{path-g77}/top.c}, function @samp{ffe_decode_option}.
14175 This code needs to check positive and negative forms
14176 of each option.
14177
14178 The defaults for Fortran options are set in their
14179 global definitions, also found in @file{@value{path-g77}/top.c}.
14180 Many of these defaults are actually macros defined
14181 in @file{@value{path-g77}/target.h}, since they might be
14182 machine-specific.
14183 However, since, in practice, GNU compilers
14184 should behave the same way on all configurations
14185 (especially when it comes to language constructs),
14186 the practice of setting defaults in @file{target.h}
14187 is likely to be deprecated and, ultimately, stopped
14188 in future versions of @code{g77}.
14189
14190 Accessor macros for Fortran options, used by code
14191 in the @code{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
14192
14193 @emph{Compiler options} are listed in @file{gcc/toplev.c}
14194 in the array @samp{f_options}.
14195 An option not listed in @samp{lang_options} is
14196 looked up in @samp{f_options} and handled from there.
14197
14198 The defaults for compiler options are set in the
14199 global definitions for the corresponding variables,
14200 some of which are in @file{gcc/toplev.c}.
14201
14202 You can set different defaults for @emph{Fortran-oriented}
14203 or @emph{Fortran-reticent} compiler options by changing
14204 the way @code{f771} handles the @samp{-fset-g77-defaults}
14205 option, which is always provided as the first option when
14206 called by @code{g77} or @code{gcc}.
14207
14208 This code is in @samp{ffe_decode_options} in @file{@value{path-g77}/top.c}.
14209 Have it change just the variables that you want to default
14210 to a different setting for Fortran compiles compared to
14211 compiles of other languages.
14212
14213 The @samp{-fset-g77-defaults} option is passed to @code{f771}
14214 automatically because of the specification information
14215 kept in @file{@value{path-g77}/lang-specs.h}.
14216 This file tells the @code{gcc} command how to recognize,
14217 in this case, Fortran source files (those to be preprocessed,
14218 and those that are not), and further, how to invoke the
14219 appropriate programs (including @code{f771}) to process
14220 those source files.
14221
14222 It is in @file{@value{path-g77}/lang-specs.h} that @samp{-fset-g77-defaults},
14223 @samp{-fversion}, and other options are passed, as appropriate,
14224 even when the user has not explicitly specified them.
14225 Other ``internal'' options such as @samp{-quiet} also
14226 are passed via this mechanism.
14227
14228 @node Projects
14229 @chapter Projects
14230 @cindex projects
14231
14232 If you want to contribute to @code{g77} by doing research,
14233 design, specification, documentation, coding, or testing,
14234 the following information should give you some ideas.
14235 More relevant information might be available from
14236 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
14237
14238 @menu
14239 * Efficiency::               Make @code{g77} itself compile code faster.
14240 * Better Optimization::      Teach @code{g77} to generate faster code.
14241 * Simplify Porting::         Make @code{g77} easier to configure, build,
14242                              and install.
14243 * More Extensions::          Features many users won't know to ask for.
14244 * Machine Model::            @code{g77} should better leverage @code{gcc}.
14245 * Internals Documentation::  Make maintenance easier.
14246 * Internals Improvements::   Make internals more robust.
14247 * Better Diagnostics::       Make using @code{g77} on new code easier.
14248 @end menu
14249
14250 @node Efficiency
14251 @section Improve Efficiency
14252 @cindex efficiency
14253
14254 Don't bother doing any performance analysis until most of the
14255 following items are taken care of, because there's no question
14256 they represent serious space/time problems, although some of
14257 them show up only given certain kinds of (popular) input.
14258
14259 @itemize @bullet
14260 @item
14261 Improve @samp{malloc} package and its uses to specify more info about
14262 memory pools and, where feasible, use obstacks to implement them.
14263
14264 @item
14265 Skip over uninitialized portions of aggregate areas (arrays,
14266 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
14267 This would reduce memory usage for large initialized aggregate
14268 areas, even ones with only one initialized element.
14269
14270 As of version 0.5.18, a portion of this item has already been
14271 accomplished.
14272
14273 @item
14274 Prescan the statement (in @file{sta.c}) so that the nature of the statement
14275 is determined as much as possible by looking entirely at its form,
14276 and not looking at any context (previous statements, including types
14277 of symbols).
14278 This would allow ripping out of the statement-confirmation,
14279 symbol retraction/confirmation, and diagnostic inhibition
14280 mechanisms.
14281 Plus, it would result in much-improved diagnostics.
14282 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
14283 is not a subroutine intrinsic, would result actual error instead of the
14284 unimplemented-statement catch-all.
14285
14286 @item
14287 Throughout @code{g77}, don't pass line/column pairs where
14288 a simple @samp{ffewhere} type, which points to the error as much as is
14289 desired by the configuration, will do, and don't pass @samp{ffelexToken} types
14290 where a simple @samp{ffewhere} type will do.
14291 Then, allow new default
14292 configuration of @samp{ffewhere} such that the source line text is not
14293 preserved, and leave it to things like Emacs' next-error function
14294 to point to them (now that @samp{next-error} supports column,
14295 or, perhaps, character-offset, numbers).
14296 The change in calling sequences should improve performance somewhat,
14297 as should not having to save source lines.
14298 (Whether this whole
14299 item will improve performance is questionable, but it should
14300 improve maintainability.)
14301
14302 @item
14303 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
14304 as regards the assembly output.
14305 Some of this might require improving
14306 the back end, but lots of improvement in space/time required in @code{g77}
14307 itself can be fairly easily obtained without touching the back end.
14308 Maybe type-conversion, where necessary, can be speeded up as well in
14309 cases like the one shown (converting the @samp{2} into @samp{2.}).
14310
14311 @item
14312 If analysis shows it to be worthwhile, optimize @file{lex.c}.
14313
14314 @item
14315 Consider redesigning @file{lex.c} to not need any feedback
14316 during tokenization, by keeping track of enough parse state on its
14317 own.
14318 @end itemize
14319
14320 @node Better Optimization
14321 @section Better Optimization
14322 @cindex optimization, better
14323 @cindex code generation, improving
14324
14325 Much of this work should be put off until after @code{g77} has
14326 all the features necessary for its widespread acceptance as a
14327 useful F77 compiler.
14328 However, perhaps this work can be done in parallel during
14329 the feature-adding work.
14330
14331 @itemize @bullet
14332 @item
14333 Do the equivalent of the trick of putting @samp{extern inline} in front
14334 of every function definition in @code{libg2c} and #include'ing the resulting
14335 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
14336 that are at all worth inlining.
14337 (Some of this has already been done, such as for integral exponentiation.)
14338
14339 @item
14340 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
14341 and it's clear that types line up
14342 and @samp{CHAR_VAR} is addressable or not a @samp{VAR_DECL},
14343 make @samp{CHAR_VAR}, not a
14344 temporary, be the receiver for @samp{CHAR_FUNC}.
14345 (This is now done for @code{COMPLEX} variables.)
14346
14347 @item
14348 Design and implement Fortran-specific optimizations that don't
14349 really belong in the back end, or where the front end needs to
14350 give the back end more info than it currently does.
14351
14352 @item
14353 Design and implement a new run-time library interface, with the
14354 code going into @code{libgcc} so no special linking is required to
14355 link Fortran programs using standard language features.
14356 This library
14357 would speed up lots of things, from I/O (using precompiled formats,
14358 doing just one, or, at most, very few, calls for arrays or array sections,
14359 and so on) to general computing (array/section implementations of
14360 various intrinsics, implementation of commonly performed loops that
14361 aren't likely to be optimally compiled otherwise, etc.).
14362
14363 Among the important things the library would do are:
14364
14365 @itemize @bullet
14366 @item
14367 Be a one-stop-shop-type
14368 library, hence shareable and usable by all, in that what are now
14369 library-build-time options in @code{libg2c} would be moved at least to the
14370 @code{g77} compile phase, if not to finer grains (such as choosing how
14371 list-directed I/O formatting is done by default at @code{OPEN} time, for
14372 preconnected units via options or even statements in the main program
14373 unit, maybe even on a per-I/O basis with appropriate pragma-like
14374 devices).
14375 @end itemize
14376
14377 @item
14378 Probably requiring the new library design, change interface to
14379 normally have @code{COMPLEX} functions return their values in the way
14380 @code{gcc} would if they were declared @code{__complex__ float},
14381 rather than using
14382 the mechanism currently used by @code{CHARACTER} functions (whereby the
14383 functions are compiled as returning void and their first arg is
14384 a pointer to where to store the result).
14385 (Don't append underscores to
14386 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
14387 @code{gcc} rather than @code{f2c} calling conventions.)
14388
14389 @item
14390 Do something useful with @samp{doiter} references where possible.
14391 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
14392 a @code{DO} loop that uses @samp{I} as the
14393 iteration variable, and the back end might find that info useful
14394 in determining whether it needs to read @samp{I} back into a register after
14395 the call.
14396 (It normally has to do that, unless it knows @samp{FOO} never
14397 modifies its passed-by-reference argument, which is rarely the case
14398 for Fortran-77 code.)
14399 @end itemize
14400
14401 @node Simplify Porting
14402 @section Simplify Porting
14403 @cindex porting, simplify
14404 @cindex simplify porting
14405
14406 Making @code{g77} easier to configure, port, build, and install, either
14407 as a single-system compiler or as a cross-compiler, would be
14408 very useful.
14409
14410 @itemize @bullet
14411 @item
14412 A new library (replacing @code{libg2c}) should improve portability as well as
14413 produce more optimal code.
14414 Further, @code{g77} and the new library should
14415 conspire to simplify naming of externals, such as by removing unnecessarily
14416 added underscores, and to reduce/eliminate the possibility of naming
14417 conflicts, while making debugger more straightforward.
14418
14419 Also, it should
14420 make multi-language applications more feasible, such as by providing
14421 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
14422 descriptors.
14423
14424 @item
14425 Possibly related to a new library, @code{g77} should produce the equivalent
14426 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
14427 main program unit, instead of compiling something that must be
14428 called by a library
14429 implementation of @code{main()}.
14430
14431 This would do many useful things such as
14432 provide more flexibility in terms of setting up exception handling,
14433 not requiring programmers to start their debugging sessions with
14434 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
14435
14436 @item
14437 The GBE needs to understand the difference between alignment
14438 requirements and desires.
14439 For example, on Intel x86 machines, @code{g77} currently imposes
14440 overly strict alignment requirements, due to the back end, but it
14441 would be useful for Fortran and C programmers to be able to override
14442 these @emph{recommendations} as long as they don't violate the actual
14443 processor @emph{requirements}.
14444 @end itemize
14445
14446 @node More Extensions
14447 @section More Extensions
14448 @cindex extensions, more
14449
14450 These extensions are not the sort of things users ask for ``by name'',
14451 but they might improve the usability of @code{g77}, and Fortran in
14452 general, in the long run.
14453 Some of these items really pertain to improving @code{g77} internals
14454 so that some popular extensions can be more easily supported.
14455
14456 @itemize @bullet
14457 @item
14458 Look through all the documentation on the GNU Fortran language,
14459 dialects, compiler, missing features, bugs, and so on.
14460 Many mentions of incomplete or missing features are
14461 sprinkled throughout.
14462 It is not worth repeating them here.
14463
14464 @item
14465 @cindex concatenation
14466 @cindex CHARACTER*(*)
14467 @cindex run-time, dynamic allocation
14468 Support arbitrary operands for concatenation, even in contexts where
14469 run-time allocation is required.
14470 For example:
14471
14472 @smallexample
14473 SUBROUTINE X(A)
14474 CHARACTER*(*) A
14475 CALL FOO(A // 'suffix')
14476 @end smallexample
14477
14478 @item
14479 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
14480 named and unnamed.
14481 The idea is to provide a forward-looking, effective
14482 replacement for things like the old-style @code{PARAMETER} statement
14483 when people
14484 really need typelessness in a maintainable, portable, clearly documented
14485 way.
14486 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
14487 and whatever else might come along.
14488 (This is not really a call for polymorphism per se, just
14489 an ability to express limited, syntactic polymorphism.)
14490
14491 @item
14492 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
14493
14494 @item
14495 Support arbitrary file unit numbers, instead of limiting them
14496 to 0 through @samp{MXUNIT-1}.
14497 (This is a @code{libg2c} issue.)
14498
14499 @item
14500 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
14501 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
14502 later @code{UNIT=} in the first example is invalid.
14503 Make sure this is what users of this feature would expect.
14504
14505 @item
14506 Currently @code{g77} disallows @samp{READ(1'10)} since
14507 it is an obnoxious syntax, but
14508 supporting it might be pretty easy if needed.
14509 More details are needed, such
14510 as whether general expressions separated by an apostrophe are supported,
14511 or maybe the record number can be a general expression, and so on.
14512
14513 @item
14514 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
14515 fully.
14516 Currently there is no support at all
14517 for @code{%FILL} in @code{STRUCTURE} and related syntax,
14518 whereas the rest of the
14519 stuff has at least some parsing support.
14520 This requires either major
14521 changes to @code{libg2c} or its replacement.
14522
14523 @item
14524 F90 and @code{g77} probably disagree about label scoping relative to
14525 @code{INTERFACE} and @code{END INTERFACE}, and their contained
14526 procedure interface bodies (blocks?).
14527
14528 @item
14529 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
14530 since that was added after S8.112.
14531
14532 @item
14533 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
14534 with the final form of the standard (it was vague at S8.112).
14535
14536 @item
14537 It seems to be an ``open'' question whether a file, immediately after being
14538 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
14539 might be nice to offer an option of opening to ``undefined'' status, requiring
14540 an explicit absolute-positioning operation to be performed before any
14541 other (besides @code{CLOSE}) to assist in making applications port to systems
14542 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
14543 @end itemize
14544
14545 @node Machine Model
14546 @section Machine Model
14547
14548 This items pertain to generalizing @code{g77}'s view of
14549 the machine model to more fully accept whatever the GBE
14550 provides it via its configuration.
14551
14552 @itemize @bullet
14553 @item
14554 Switch to using @samp{REAL_VALUE_TYPE} to represent floating-point constants
14555 exclusively so the target float format need not be required.
14556 This
14557 means changing the way @code{g77} handles initialization of aggregate areas
14558 having more than one type, such as @code{REAL} and @code{INTEGER},
14559 because currently
14560 it initializes them as if they were arrays of @code{char} and uses the
14561 bit patterns of the constants of the various types in them to determine
14562 what to stuff in elements of the arrays.
14563
14564 @item
14565 Rely more and more on back-end info and capabilities, especially in the
14566 area of constants (where having the @code{g77} front-end's IL just store
14567 the appropriate tree nodes containing constants might be best).
14568
14569 @item
14570 Suite of C and Fortran programs that a user/administrator can run on a
14571 machine to help determine the configuration for @code{g77} before building
14572 and help determine if the compiler works (especially with whatever
14573 libraries are installed) after building.
14574 @end itemize
14575
14576 @node Internals Documentation
14577 @section Internals Documentation
14578
14579 Better info on how @code{g77} works and how to port it is needed.
14580 Much of this should be done only after the redesign planned for
14581 0.6 is complete.
14582
14583 @node Internals Improvements
14584 @section Internals Improvements
14585
14586 Some more items that would make @code{g77} more reliable
14587 and easier to maintain:
14588
14589 @itemize @bullet
14590 @item
14591 Generally make expression handling focus
14592 more on critical syntax stuff, leaving semantics to callers.
14593 For example,
14594 anything a caller can check, semantically, let it do so, rather
14595 than having @file{expr.c} do it.
14596 (Exceptions might include things like
14597 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
14598 it seems
14599 important to preserve the left-to-right-in-source order of production
14600 of diagnostics.)
14601
14602 @item
14603 Come up with better naming conventions for @samp{-D} to establish requirements
14604 to achieve desired implementation dialect via @file{proj.h}.
14605
14606 @item
14607 Clean up used tokens and @samp{ffewhere}s in @samp{ffeglobal_terminate_1}.
14608
14609 @item
14610 Replace @file{sta.c} @samp{outpooldisp} mechanism with @samp{malloc_pool_use}.
14611
14612 @item
14613 Check for @samp{opANY} in more places in @file{com.c}, @file{std.c},
14614 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
14615 (after determining if there is indeed no real need for it).
14616
14617 @item
14618 Utility to read and check @file{bad.def} messages and their references in the
14619 code, to make sure calls are consistent with message templates.
14620
14621 @item
14622 Search and fix @samp{&ffe@dots{}} and similar so that
14623 @samp{ffe@dots{}ptr@dots{}} macros are
14624 available instead (a good argument for wishing this could have written all
14625 this stuff in C++, perhaps).
14626 On the other hand, it's questionable whether this sort of
14627 improvement is really necessary, given the availability of
14628 tools such as Emacs and Perl, which make finding any
14629 address-taking of structure members easy enough?
14630
14631 @item
14632 Some modules truly export the member names of their structures (and the
14633 structures themselves), maybe fix this, and fix other modules that just
14634 appear to as well (by appending @samp{_}, though it'd be ugly and probably
14635 not worth the time).
14636
14637 @item
14638 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
14639 in @file{proj.h}
14640 and use them throughout @code{g77} source code (especially in the definitions
14641 of access macros in @samp{.h} files) so they can be tailored
14642 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
14643
14644 @item
14645 Decorate throughout with @code{const} and other such stuff.
14646
14647 @item
14648 All F90 notational derivations in the source code are still based
14649 on the S8.112 version of the draft standard.
14650 Probably should update
14651 to the official standard, or put documentation of the rules as used
14652 in the code@dots{}uh@dots{}in the code.
14653
14654 @item
14655 Some @samp{ffebld_new} calls (those outside of @file{ffeexpr.c} or
14656 inside but invoked via paths not involving @samp{ffeexpr_lhs} or
14657 @samp{ffeexpr_rhs}) might be creating things
14658 in improper pools, leading to such things staying around too long or
14659 (doubtful, but possible and dangerous) not long enough.
14660
14661 @item
14662 Some @samp{ffebld_list_new} (or whatever) calls might not be matched by
14663 @samp{ffebld_list_bottom} (or whatever) calls, which might someday matter.
14664 (It definitely is not a problem just yet.)
14665
14666 @item
14667 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
14668 due to alignment/mismatch or other problems---they end up without
14669 @samp{ffestorag} objects, so maybe the backend (and other parts of the front
14670 end) can notice that and handle like an @samp{opANY} (do what it wants, just
14671 don't complain or crash).
14672 Most of this seems to have been addressed
14673 by now, but a code review wouldn't hurt.
14674 @end itemize
14675
14676 @node Better Diagnostics
14677 @section Better Diagnostics
14678
14679 These are things users might not ask about, or that need to
14680 be looked into, before worrying about.
14681 Also here are items that involve reducing unnecessary diagnostic
14682 clutter.
14683
14684 @itemize @bullet
14685 @item
14686 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
14687 lengths, type classes, and so on),
14688 @samp{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
14689 it specifies.
14690
14691 @item
14692 Speed up and improve error handling for data when repeat-count is
14693 specified.
14694 For example, don't output 20 unnecessary messages after the
14695 first necessary one for:
14696
14697 @smallexample
14698 INTEGER X(20)
14699 CONTINUE
14700 DATA (X(I), J= 1, 20) /20*5/
14701 END
14702 @end smallexample
14703
14704 @noindent
14705 (The @code{CONTINUE} statement ensures the @code{DATA} statement
14706 is processed in the context of executable, not specification,
14707 statements.)
14708 @end itemize
14709 @end ifset
14710
14711 @ifset USING
14712 @node Diagnostics
14713 @chapter Diagnostics
14714 @cindex diagnostics
14715
14716 Some diagnostics produced by @code{g77} require sufficient explanation
14717 that the explanations are given below, and the diagnostics themselves
14718 identify the appropriate explanation.
14719
14720 Identification uses the GNU Info format---specifically, the @code{info}
14721 command that displays the explanation is given within square
14722 brackets in the diagnostic.
14723 For example:
14724
14725 @smallexample
14726 foo.f:5: Invalid statement [info -f g77 M FOOEY]
14727 @end smallexample
14728
14729 More details about the above diagnostic is found in the @code{g77} Info
14730 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
14731 which is displayed by typing the UNIX command
14732 @samp{info -f g77 M FOOEY}.
14733
14734 Other Info readers, such as EMACS, may be just as easily used to display
14735 the pertinent node.
14736 In the above example, @samp{g77} is the Info document name,
14737 @samp{M} is the top-level menu item to select,
14738 and, in that node (named @samp{Diagnostics}, the name of
14739 this chapter, which is the very text you're reading now),
14740 @samp{FOOEY} is the menu item to select.
14741
14742 @iftex
14743 In this printed version of the @code{g77} manual, the above example
14744 points to a section, below, entitled @samp{FOOEY}---though, of course,
14745 as the above is just a sample, no such section exists.
14746 @end iftex
14747
14748 @menu
14749 * CMPAMBIG::    Ambiguous use of intrinsic.
14750 * EXPIMP::      Intrinsic used explicitly and implicitly.
14751 * INTGLOB::     Intrinsic also used as name of global.
14752 * LEX::         Various lexer messages
14753 * GLOBALS::     Disagreements about globals.
14754 * LINKFAIL::    When linking @samp{f771} fails.
14755 @end menu
14756
14757 @node CMPAMBIG
14758 @section @code{CMPAMBIG}
14759
14760 @noindent
14761 @smallexample
14762 Ambiguous use of intrinsic @var{intrinsic} @dots{}
14763 @end smallexample
14764
14765 The type of the argument to the invocation of the @var{intrinsic}
14766 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
14767 Typically, it is @code{COMPLEX(KIND=2)}, also known as
14768 @code{DOUBLE COMPLEX}.
14769
14770 The interpretation of this invocation depends on the particular
14771 dialect of Fortran for which the code was written.
14772 Some dialects convert the real part of the argument to
14773 @code{REAL(KIND=1)}, thus losing precision; other dialects,
14774 and Fortran 90, do no such conversion.
14775
14776 So, GNU Fortran rejects such invocations except under certain
14777 circumstances, to avoid making an incorrect assumption that results
14778 in generating the wrong code.
14779
14780 To determine the dialect of the program unit, perhaps even whether
14781 that particular invocation is properly coded, determine how the
14782 result of the intrinsic is used.
14783
14784 The result of @var{intrinsic} is expected (by the original programmer)
14785 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
14786
14787 @itemize @bullet
14788 @item
14789 It is passed as an argument to a procedure that explicitly or
14790 implicitly declares that argument @code{REAL(KIND=1)}.
14791
14792 For example,
14793 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
14794 statement specifying the dummy argument corresponding to an
14795 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14796 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14797 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
14798 of @code{REAL(KIND=2)}.
14799
14800 @item
14801 It is used in a context that would otherwise not include
14802 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
14803 invocation as @code{REAL(KIND=2)} would result in unnecessary
14804 promotions and (typically) more expensive operations on the
14805 wider type.
14806
14807 For example:
14808
14809 @smallexample
14810 DOUBLE COMPLEX Z
14811 @dots{}
14812 R(1) = T * REAL(Z)
14813 @end smallexample
14814
14815 The above example suggests the programmer expected the real part
14816 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
14817 multiplied by @samp{T} (presumed, along with @samp{R} above, to
14818 be type @code{REAL(KIND=1)}).
14819
14820 Otherwise, the conversion would have to be delayed until after
14821 the multiplication, requiring not only an extra conversion
14822 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
14823 expensive multiplication (a double-precision multiplication instead
14824 of a single-precision one).
14825 @end itemize
14826
14827 The result of @var{intrinsic} is expected (by the original programmer)
14828 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
14829
14830 @itemize @bullet
14831 @item
14832 It is passed as an argument to a procedure that explicitly or
14833 implicitly declares that argument @code{REAL(KIND=2)}.
14834
14835 For example, a procedure specifying a @code{DOUBLE PRECISION}
14836 dummy argument corresponding to an
14837 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14838 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14839 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
14840 of @code{REAL(KIND=1)}.
14841
14842 @item
14843 It is used in an expression context that includes
14844 other @code{REAL(KIND=2)} operands,
14845 or is assigned to a @code{REAL(KIND=2)} variable or array element.
14846
14847 For example:
14848
14849 @smallexample
14850 DOUBLE COMPLEX Z
14851 DOUBLE PRECISION R, T
14852 @dots{}
14853 R(1) = T * REAL(Z)
14854 @end smallexample
14855
14856 The above example suggests the programmer expected the real part
14857 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
14858 by the @code{REAL()} intrinsic.
14859
14860 Otherwise, the conversion would have to be immediately followed
14861 by a conversion back to @code{REAL(KIND=2)}, losing
14862 the original, full precision of the real part of @code{Z},
14863 before being multiplied by @samp{T}.
14864 @end itemize
14865
14866 Once you have determined whether a particular invocation of @var{intrinsic}
14867 expects the Fortran 90 interpretation, you can:
14868
14869 @itemize @bullet
14870 @item
14871 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
14872 @samp{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
14873 is @samp{AIMAG})
14874 if it expected the Fortran 90 interpretation.
14875
14876 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
14877 some other type, such as @code{COMPLEX*32}, you should use the
14878 appropriate intrinsic, such as the one to convert to @code{REAL*16}
14879 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
14880 @code{QIMAG()} in place of @code{DIMAG()}).
14881
14882 @item
14883 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
14884 otherwise.
14885 This converts to @code{REAL(KIND=1)} in all working
14886 Fortran compilers.
14887 @end itemize
14888
14889 If you don't want to change the code, and you are certain that all
14890 ambiguous invocations of @var{intrinsic} in the source file have
14891 the same expectation regarding interpretation, you can:
14892
14893 @itemize @bullet
14894 @item
14895 Compile with the @code{g77} option @samp{-ff90}, to enable the
14896 Fortran 90 interpretation.
14897
14898 @item
14899 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
14900 to enable the non-Fortran-90 interpretations.
14901 @end itemize
14902
14903 @xref{REAL() and AIMAG() of Complex}, for more information on this
14904 issue.
14905
14906 Note: If the above suggestions don't produce enough evidence
14907 as to whether a particular program expects the Fortran 90
14908 interpretation of this ambiguous invocation of @var{intrinsic},
14909 there is one more thing you can try.
14910
14911 If you have access to most or all the compilers used on the
14912 program to create successfully tested and deployed executables,
14913 read the documentation for, and @emph{also} test out, each compiler
14914 to determine how it treats the @var{intrinsic} intrinsic in
14915 this case.
14916 (If all the compilers don't agree on an interpretation, there
14917 might be lurking bugs in the deployed versions of the program.)
14918
14919 The following sample program might help:
14920
14921 @cindex JCB003 program
14922 @smallexample
14923       PROGRAM JCB003
14924 C
14925 C Written by James Craig Burley 1997-02-23.
14926 C
14927 C Determine how compilers handle non-standard REAL
14928 C and AIMAG on DOUBLE COMPLEX operands.
14929 C
14930       DOUBLE COMPLEX Z
14931       REAL R
14932       Z = (3.3D0, 4.4D0)
14933       R = Z
14934       CALL DUMDUM(Z, R)
14935       R = REAL(Z) - R
14936       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
14937       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
14938       R = 4.4D0
14939       CALL DUMDUM(Z, R)
14940       R = AIMAG(Z) - R
14941       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
14942       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
14943       END
14944 C
14945 C Just to make sure compiler doesn't use naive flow
14946 C analysis to optimize away careful work above,
14947 C which might invalidate results....
14948 C
14949       SUBROUTINE DUMDUM(Z, R)
14950       DOUBLE COMPLEX Z
14951       REAL R
14952       END
14953 @end smallexample
14954
14955 If the above program prints contradictory results on a
14956 particular compiler, run away!
14957
14958 @node EXPIMP
14959 @section @code{EXPIMP}
14960
14961 @noindent
14962 @smallexample
14963 Intrinsic @var{intrinsic} referenced @dots{}
14964 @end smallexample
14965
14966 The @var{intrinsic} is explicitly declared in one program
14967 unit in the source file and implicitly used as an intrinsic
14968 in another program unit in the same source file.
14969
14970 This diagnostic is designed to catch cases where a program
14971 might depend on using the name @var{intrinsic} as an intrinsic
14972 in one program unit and as a global name (such as the name
14973 of a subroutine or function) in another, but @code{g77} recognizes
14974 the name as an intrinsic in both cases.
14975
14976 After verifying that the program unit making implicit use
14977 of the intrinsic is indeed written expecting the intrinsic,
14978 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14979 program unit to prevent this warning.
14980
14981 This and related warnings are disabled by using
14982 the @samp{-Wno-globals} option when compiling.
14983
14984 Note that this warning is not issued for standard intrinsics.
14985 Standard intrinsics include those described in the FORTRAN 77
14986 standard and, if @samp{-ff90} is specified, those described
14987 in the Fortran 90 standard.
14988 Such intrinsics are not as likely to be confused with user
14989 procedures as intrinsics provided as extensions to the
14990 standard by @code{g77}.
14991
14992 @node INTGLOB
14993 @section @code{INTGLOB}
14994
14995 @noindent
14996 @smallexample
14997 Same name `@var{intrinsic}' given @dots{}
14998 @end smallexample
14999
15000 The name @var{intrinsic} is used for a global entity (a common
15001 block or a program unit) in one program unit and implicitly
15002 used as an intrinsic in another program unit.
15003
15004 This diagnostic is designed to catch cases where a program
15005 intends to use a name entirely as a global name, but @code{g77}
15006 recognizes the name as an intrinsic in the program unit that
15007 references the name, a situation that would likely produce
15008 incorrect code.
15009
15010 For example:
15011
15012 @smallexample
15013 INTEGER FUNCTION TIME()
15014 @dots{}
15015 END
15016 @dots{}
15017 PROGRAM SAMP
15018 INTEGER TIME
15019 PRINT *, 'Time is ', TIME()
15020 END
15021 @end smallexample
15022
15023 The above example defines a program unit named @samp{TIME}, but
15024 the reference to @samp{TIME} in the main program unit @samp{SAMP}
15025 is normally treated by @code{g77} as a reference to the intrinsic
15026 @code{TIME()} (unless a command-line option that prevents such
15027 treatment has been specified).
15028
15029 As a result, the program @samp{SAMP} will @emph{not}
15030 invoke the @samp{TIME} function in the same source file.
15031
15032 Since @code{g77} recognizes @code{libU77} procedures as
15033 intrinsics, and since some existing code uses the same names
15034 for its own procedures as used by some @code{libU77}
15035 procedures, this situation is expected to arise often enough
15036 to make this sort of warning worth issuing.
15037
15038 After verifying that the program unit making implicit use
15039 of the intrinsic is indeed written expecting the intrinsic,
15040 add an @samp{INTRINSIC @var{intrinsic}} statement to that
15041 program unit to prevent this warning.
15042
15043 Or, if you believe the program unit is designed to invoke the
15044 program-defined procedure instead of the intrinsic (as
15045 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
15046 statement to the program unit that references the name to
15047 prevent this warning.
15048
15049 This and related warnings are disabled by using
15050 the @samp{-Wno-globals} option when compiling.
15051
15052 Note that this warning is not issued for standard intrinsics.
15053 Standard intrinsics include those described in the FORTRAN 77
15054 standard and, if @samp{-ff90} is specified, those described
15055 in the Fortran 90 standard.
15056 Such intrinsics are not as likely to be confused with user
15057 procedures as intrinsics provided as extensions to the
15058 standard by @code{g77}.
15059
15060 @node LEX
15061 @section @code{LEX}
15062
15063 @noindent
15064 @smallexample
15065 Unrecognized character @dots{}
15066 Invalid first character @dots{}
15067 Line too long @dots{}
15068 Non-numeric character @dots{}
15069 Continuation indicator @dots{}
15070 Label at @dots{} invalid with continuation line indicator @dots{}
15071 Character constant @dots{}
15072 Continuation line @dots{}
15073 Statement at @dots{} begins with invalid token
15074 @end smallexample
15075
15076 Although the diagnostics identify specific problems, they can
15077 be produced when general problems such as the following occur:
15078
15079 @itemize @bullet
15080 @item
15081 The source file contains something other than Fortran code.
15082
15083 If the code in the file does not look like many of the examples
15084 elsewhere in this document, it might not be Fortran code.
15085 (Note that Fortran code often is written in lower case letters,
15086 while the examples in this document use upper case letters,
15087 for stylistic reasons.)
15088
15089 For example, if the file contains lots of strange-looking
15090 characters, it might be APL source code; if it contains lots
15091 of parentheses, it might be Lisp source code; if it
15092 contains lots of bugs, it might be C++ source code.
15093
15094 @item
15095 The source file contains free-form Fortran code, but @samp{-ffree-form}
15096 was not specified on the command line to compile it.
15097
15098 Free form is a newer form for Fortran code.
15099 The older, classic form is called fixed form.
15100
15101 @cindex continuation character
15102 @cindex characters, continuation
15103 Fixed-form code is visually fairly distinctive, because
15104 numerical labels and comments are all that appear in
15105 the first five columns of a line, the sixth column is
15106 reserved to denote continuation lines,
15107 and actual statements start at or beyond column 7.
15108 Spaces generally are not significant, so if you
15109 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
15110 you are looking at fixed-form code.
15111 @cindex *
15112 @cindex asterisk
15113 Comment lines are indicated by the letter @samp{C} or the symbol
15114 @samp{*} in column 1.
15115 @cindex trailing comment
15116 @cindex comment
15117 @cindex characters, comment
15118 @cindex !
15119 @cindex exclamation point
15120 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
15121 which many compilers support.)
15122
15123 Free-form code is distinguished from fixed-form source
15124 primarily by the fact that statements may start anywhere.
15125 (If lots of statements start in columns 1 through 6,
15126 that's a strong indicator of free-form source.)
15127 Consecutive keywords must be separated by spaces, so
15128 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
15129 There are no comment lines per se, but @samp{!} starts a
15130 comment anywhere in a line (other than within a character or
15131 Hollerith constant).
15132
15133 @xref{Source Form}, for more information.
15134
15135 @item
15136 The source file is in fixed form and has been edited without
15137 sensitivity to the column requirements.
15138
15139 Statements in fixed-form code must be entirely contained within
15140 columns 7 through 72 on a given line.
15141 Starting them ``early'' is more likely to result in diagnostics
15142 than finishing them ``late'', though both kinds of errors are
15143 often caught at compile time.
15144
15145 For example, if the following code fragment is edited by following
15146 the commented instructions literally, the result, shown afterward,
15147 would produce a diagnostic when compiled:
15148
15149 @smallexample
15150 C On XYZZY systems, remove "C" on next line:
15151 C     CALL XYZZY_RESET
15152 @end smallexample
15153
15154 The result of editing the above line might be:
15155
15156 @smallexample
15157 C On XYZZY systems, remove "C" on next line:
15158      CALL XYZZY_RESET
15159 @end smallexample
15160
15161 However, that leaves the first @samp{C} in the @samp{CALL}
15162 statement in column 6, making it a comment line, which is
15163 not really what the author intended, and which is likely
15164 to result in one of the above-listed diagnostics.
15165
15166 @emph{Replacing} the @samp{C} in column 1 with a space
15167 is the proper change to make, to ensure the @samp{CALL}
15168 keyword starts in or after column 7.
15169
15170 Another common mistake like this is to forget that fixed-form
15171 source lines are significant through only column 72, and that,
15172 normally, any text beyond column 72 is ignored or is diagnosed
15173 at compile time.
15174
15175 @xref{Source Form}, for more information.
15176
15177 @item
15178 The source file requires preprocessing, and the preprocessing
15179 is not being specified at compile time.
15180
15181 A source file containing lines beginning with @code{#define},
15182 @code{#include}, @code{#if}, and so on is likely one that
15183 requires preprocessing.
15184
15185 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
15186 the file normally will be compiled @emph{without} preprocessing
15187 by @code{g77}.
15188
15189 Change the file's suffix from @samp{.f} to @samp{.F}
15190 (or, on systems with case-insensitive file names,
15191 to @samp{.fpp} or @samp{.FPP}),
15192 from @samp{.for} to @samp{.fpp},
15193 or from @samp{.FOR} to @samp{.FPP}.
15194 @code{g77} compiles files with such names @emph{with}
15195 preprocessing.
15196
15197 @pindex cpp
15198 @cindex preprocessor
15199 @cindex cpp program
15200 @cindex programs, cpp
15201 @cindex @samp{-x f77-cpp-input} option
15202 @cindex options, @samp{-x f77-cpp-input}
15203 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
15204 the language @samp{f77-cpp-input} for Fortran files that
15205 require preprocessing.
15206 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
15207
15208 @item
15209 The source file is preprocessed, and the results of preprocessing
15210 result in syntactic errors that are not necessarily obvious to
15211 someone examining the source file itself.
15212
15213 Examples of errors resulting from preprocessor macro expansion
15214 include exceeding the line-length limit, improperly starting,
15215 terminating, or incorporating the apostrophe or double-quote in
15216 a character constant, improperly forming a Hollerith constant,
15217 and so on.
15218
15219 @xref{Overall Options,,Options Controlling the Kind of Output},
15220 for suggestions about how to use, and not use, preprocessing
15221 for Fortran code.
15222 @end itemize
15223
15224 @node GLOBALS
15225 @section @code{GLOBALS}
15226
15227 @noindent
15228 @smallexample
15229 Global name @var{name} defined at @dots{} already defined@dots{}
15230 Global name @var{name} at @dots{} has different type@dots{}
15231 Too many arguments passed to @var{name} at @dots{}
15232 Too few arguments passed to @var{name} at @dots{}
15233 Argument #@var{n} of @var{name} is @dots{}
15234 @end smallexample
15235
15236 These messages all identify disagreements about the
15237 global procedure named @var{name} among different program units
15238 (usually including @var{name} itself).
15239
15240 Whether a particular disagreement is reported
15241 as a warning or an error
15242 can depend on the relative order
15243 of the disagreeing portions of the source file.
15244
15245 Disagreements between a procedure invocation
15246 and the @emph{subsequent} procedure itself
15247 are, usually, diagnosed as errors
15248 when the procedure itself @emph{precedes} the invocation.
15249 Other disagreements are diagnosed via warnings.
15250
15251 @cindex forward references
15252 @cindex in-line code
15253 @cindex compilation, in-line
15254 This distinction, between warnings and errors,
15255 is due primarily to the present tendency of the @code{gcc} back end
15256 to inline only those procedure invocations that are
15257 @emph{preceded} by the corresponding procedure definitions.
15258 If the @code{gcc} back end is changed
15259 to inline ``forward references'',
15260 in which invocations precede definitions,
15261 the @code{g77} front end will be changed
15262 to treat both orderings as errors, accordingly.
15263
15264 The sorts of disagreements that are diagnosed by @code{g77} include
15265 whether a procedure is a subroutine or function;
15266 if it is a function, the type of the return value of the procedure;
15267 the number of arguments the procedure accepts;
15268 and the type of each argument.
15269
15270 Disagreements regarding global names among program units
15271 in a Fortran program @emph{should} be fixed in the code itself.
15272 However, if that is not immediately practical,
15273 and the code has been working for some time,
15274 it is possible it will work
15275 when compiled with the @samp{-fno-globals} option.
15276
15277 The @samp{-fno-globals} option
15278 causes these diagnostics to all be warnings
15279 and disables all inlining of references to global procedures
15280 (to avoid subsequent compiler crashes and bad-code generation).
15281 Use of the @samp{-Wno-globals} option as well as @samp{-fno-globals}
15282 suppresses all of these diagnostics.
15283 (@samp{-Wno-globals} by itself disables only the warnings,
15284 not the errors.)
15285
15286 After using @samp{-fno-globals} to work around these problems,
15287 it is wise to stop using that option and address them by fixing
15288 the Fortran code, because such problems, while they might not
15289 actually result in bugs on some systems, indicate that the code
15290 is not as portable as it could be.
15291 In particular, the code might appear to work on a particular
15292 system, but have bugs that affect the reliability of the data
15293 without exhibiting any other outward manifestations of the bugs.
15294
15295 @node LINKFAIL
15296 @section @code{LINKFAIL}
15297
15298 @noindent
15299 @smallexample
15300 If the above command failed due to an unresolved reference
15301 to strtoul, _strtoul, bsearch, _bsearch, or similar, see
15302 [info -f g77 M LINKFAIL] (a node in the g77 documentation)
15303 for information on what causes this, how to work around
15304 the problem by editing $@{srcdir@}/proj.c, and what else to do.
15305 @end smallexample
15306
15307 @xref{Missing strtoul or bsearch}, for more information on
15308 this problem,
15309 which occurs only in releases of @code{g77}
15310 based on @code{gcc}.
15311 (It does not occur in @code{egcs}.)
15312
15313 On AIX 4.1, @code{g77} might not build with the native (non-GNU) tools
15314 due to a linker bug in coping with the @samp{-bbigtoc} option which
15315 leads to a @samp{Relocation overflow} error.  The GNU linker is not
15316 recommended on current AIX versions, though; it was developed under a
15317 now-unsupported version.  This bug is said to be fixed by `update PTF
15318 U455193 for APAR IX75823'.
15319
15320 Compiling with @samp{-mminimal-toc}
15321 might solve this problem, e.g.@: by adding
15322 @smallexample
15323 BOOT_CFLAGS='-mminimal-toc -O2 -g'
15324 @end smallexample
15325 to the @code{make bootstrap} command line.
15326 @end ifset
15327
15328 @node Index
15329 @unnumbered Index
15330
15331 @printindex cp
15332 @summarycontents
15333 @contents
15334 @bye