OSDN Git Service

2001-06-03 Toon Moene <toon@moene.indiv.nluug.nl>
[pf3gnuchains/gcc-fork.git] / gcc / f / g77.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename g77.info
4
5 @set last-update 2001-06-03
6 @set copyrights-g77 1995,1996,1997,1998,1999,2000,2001
7
8 @include root.texi
9
10 @c This tells @include'd files that they're part of the overall G77 doc
11 @c set.  (They might be part of a higher-level doc set too.)
12 @set DOC-G77
13
14 @c @setfilename useg77.info
15 @c @setfilename portg77.info
16 @c To produce the full manual, use the "g77.info" setfilename, and
17 @c make sure the following do NOT begin with '@c' (and the @clear lines DO)
18 @set INTERNALS
19 @set USING
20 @c To produce a user-only manual, use the "useg77.info" setfilename, and
21 @c make sure the following does NOT begin with '@c':
22 @c @clear INTERNALS
23 @c To produce a porter-only manual, use the "portg77.info" setfilename,
24 @c and make sure the following does NOT begin with '@c':
25 @c @clear USING
26
27 @c 6/27/96 FSF DO wants smallbook fmt for 1st bound edition. (from gcc.texi)
28 @c @smallbook
29
30 @c i also commented out the finalout command, so if there *are* any
31 @c overfulls, you'll (hopefully) see the rectangle in the right hand
32 @c margin. -- burley 1999-03-13 (from mew's comment in gcc.texi).
33 @c @finalout
34
35 @ifset INTERNALS
36 @ifset USING
37 @settitle Using and Porting GNU Fortran
38 @end ifset
39 @end ifset
40 @c seems reasonable to assume at least one of INTERNALS or USING is set...
41 @ifclear INTERNALS
42 @settitle Using GNU Fortran
43 @end ifclear
44 @ifclear USING
45 @settitle Porting GNU Fortran
46 @end ifclear
47 @c then again, have some fun
48 @ifclear INTERNALS
49 @ifclear USING
50 @settitle Doing Squat with GNU Fortran
51 @end ifclear
52 @end ifclear
53
54 @syncodeindex fn cp
55 @syncodeindex vr cp
56 @c %**end of header
57
58 @c Cause even numbered pages to be printed on the left hand side of
59 @c the page and odd numbered pages to be printed on the right hand
60 @c side of the page.  Using this, you can print on both sides of a
61 @c sheet of paper and have the text on the same part of the sheet.
62
63 @c The text on right hand pages is pushed towards the right hand
64 @c margin and the text on left hand pages is pushed toward the left
65 @c hand margin.
66 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
67
68 @c @tex
69 @c \global\bindingoffset=0.75in
70 @c \global\normaloffset =0.75in
71 @c @end tex
72
73 @ifinfo
74 @dircategory Programming
75 @direntry
76 * g77: (g77).                  The GNU Fortran compiler.
77 @end direntry
78 @ifset INTERNALS
79 @ifset USING
80 This file documents the use and the internals of the GNU Fortran (@code{g77})
81 compiler.
82 It corresponds to the @value{which-g77} version of @code{g77}.
83 @end ifset
84 @end ifset
85 @ifclear USING
86 This file documents the internals of the GNU Fortran (@code{g77}) compiler.
87 It corresponds to the @value{which-g77} version of @code{g77}.
88 @end ifclear
89 @ifclear INTERNALS
90 This file documents the use of the GNU Fortran (@code{g77}) compiler.
91 It corresponds to the @value{which-g77} version of @code{g77}.
92 @end ifclear
93
94 Published by the Free Software Foundation
95 59 Temple Place - Suite 330
96 Boston, MA 02111-1307 USA
97
98 Copyright (C) @value{copyrights-g77} Free Software Foundation, Inc.
99
100
101 Permission is granted to copy, distribute and/or modify this document
102 under the terms of the GNU Free Documentation License, Version 1.1 or
103 any later version published by the Free Software Foundation; with the
104 Invariant Sections being ``GNU General Public License'', the Front-Cover
105 texts being (a) (see below), and with the Back-Cover Texts being (b)
106 (see below).  A copy of the license is included in the section entitled
107 ``GNU Free Documentation License''.
108
109 (a) The FSF's Front-Cover Text is:
110
111      A GNU Manual
112
113 (b) The FSF's Back-Cover Text is:
114
115      You have freedom to copy and modify this GNU Manual, like GNU
116      software.  Copies published by the Free Software Foundation raise
117      funds for GNU development.
118 @end ifinfo
119
120 Contributed by James Craig Burley (@email{@value{email-burley}}).
121 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
122 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
123
124 @setchapternewpage odd
125 @c @finalout
126 @titlepage
127 @ifset INTERNALS
128 @ifset USING
129 @center @titlefont{Using and Porting GNU Fortran}
130
131 @end ifset
132 @end ifset
133 @ifclear INTERNALS
134 @title Using GNU Fortran
135 @end ifclear
136 @ifclear USING
137 @title Porting GNU Fortran
138 @end ifclear
139 @sp 2
140 @center James Craig Burley
141 @sp 3
142 @center Last updated @value{last-update}
143 @sp 1
144 @center for version @value{version-g77}
145 @page
146 @vskip 0pt plus 1filll
147 Copyright @copyright{} @value{copyrights-g77} Free Software Foundation, Inc.
148 @sp 2
149 For the @value{which-g77} Version*
150 @sp 1
151 Published by the Free Software Foundation @*
152 59 Temple Place - Suite 330@*
153 Boston, MA 02111-1307, USA@*
154 @c Last printed ??ber, 19??.@*
155 @c Printed copies are available for $? each.@*
156 @c ISBN ???
157 @sp 1
158 Permission is granted to copy, distribute and/or modify this document
159 under the terms of the GNU Free Documentation License, Version 1.1 or
160 any later version published by the Free Software Foundation; with the
161 Invariant Sections being ``GNU General Public License'', the Front-Cover
162 texts being (a) (see below), and with the Back-Cover Texts being (b)
163 (see below).  A copy of the license is included in the section entitled
164 ``GNU Free Documentation License''.
165
166 (a) The FSF's Front-Cover Text is:
167
168      A GNU Manual
169
170 (b) The FSF's Back-Cover Text is:
171
172      You have freedom to copy and modify this GNU Manual, like GNU
173      software.  Copies published by the Free Software Foundation raise
174      funds for GNU development.
175 @end titlepage
176 @summarycontents
177 @contents
178 @page
179
180 @ifinfo
181
182 @node Top, Copying,, (DIR)
183 @top Introduction
184 @cindex Introduction
185
186 @ifset INTERNALS
187 @ifset USING
188 This manual documents how to run, install and port @code{g77},
189 as well as its new features and incompatibilities,
190 and how to report bugs.
191 It corresponds to the @value{which-g77} version of @code{g77}.
192 @end ifset
193 @end ifset
194
195 @ifclear INTERNALS
196 This manual documents how to run and install @code{g77},
197 as well as its new features and incompatibilities, and how to report
198 bugs.
199 It corresponds to the @value{which-g77} version of @code{g77}.
200 @end ifclear
201 @ifclear USING
202 This manual documents how to port @code{g77},
203 as well as its new features and incompatibilities,
204 and how to report bugs.
205 It corresponds to the @value{which-g77} version of @code{g77}.
206 @end ifclear
207
208 @end ifinfo
209
210 @ifset DEVELOPMENT
211 @emph{Warning:} This document is still under development,
212 and might not accurately reflect the @code{g77} code base
213 of which it is a part.
214 Efforts are made to keep it somewhat up-to-date,
215 but they are particularly concentrated
216 on any version of this information
217 that is distributed as part of a @emph{released} @code{g77}.
218
219 In particular, while this document is intended to apply to
220 the @value{which-g77} version of @code{g77},
221 only an official @emph{release} of that version
222 is expected to contain documentation that is
223 most consistent with the @code{g77} product in that version.
224 @end ifset
225
226 @menu
227 * Copying::         GNU General Public License says
228                     how you can copy and share GNU Fortran.
229 * GNU Free Documentation License::
230                     How you can copy and share this manual.
231 * Contributors::    People who have contributed to GNU Fortran.
232 * Funding::         How to help assure continued work for free software.
233 * Funding GNU Fortran::  How to help assure continued work on GNU Fortran.
234 * Look and Feel::   Protect your freedom---fight ``look and feel''.
235 @ifset USING
236 * Getting Started:: Finding your way around this manual.
237 * What is GNU Fortran?::  How @code{g77} fits into the universe.
238 * G77 and GCC::     You can compile Fortran, C, or other programs.
239 * Invoking G77::    Command options supported by @code{g77}.
240 * News::            News about recent releases of @code{g77}.
241 * Changes::         User-visible changes to recent releases of @code{g77}.
242 * Language::        The GNU Fortran language.
243 * Compiler::        The GNU Fortran compiler.
244 * Other Dialects::  Dialects of Fortran supported by @code{g77}.
245 * Other Compilers:: Fortran compilers other than @code{g77}.
246 * Other Languages:: Languages other than Fortran.
247 * Installation::    How to configure, compile and install GNU Fortran.
248 * Debugging and Interfacing::  How @code{g77} generates code.
249 * Collected Fortran Wisdom::  How to avoid Trouble.
250 * Trouble::         If you have trouble with GNU Fortran.
251 * Open Questions::  Things we'd like to know.
252 * Bugs::            How, why, and where to report bugs.
253 * Service::         How to find suppliers of support for GNU Fortran.
254 @end ifset
255 @ifset INTERNALS
256 * Adding Options::  Guidance on teaching @code{g77} about new options.
257 * Projects::        Projects for @code{g77} internals hackers.
258 * Front End::       Design and implementation of the @code{g77} front end.
259 @end ifset
260
261 * M: Diagnostics.   Diagnostics produced by @code{g77}.
262
263 * Index::           Index of concepts and symbol names.
264 @end menu
265 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
266
267 @node Copying
268 @unnumbered GNU GENERAL PUBLIC LICENSE
269 @center Version 2, June 1991
270
271 @display
272 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
273 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
274
275 Everyone is permitted to copy and distribute verbatim copies
276 of this license document, but changing it is not allowed.
277 @end display
278
279 @unnumberedsec Preamble
280
281   The licenses for most software are designed to take away your
282 freedom to share and change it.  By contrast, the GNU General Public
283 License is intended to guarantee your freedom to share and change free
284 software---to make sure the software is free for all its users.  This
285 General Public License applies to most of the Free Software
286 Foundation's software and to any other program whose authors commit to
287 using it.  (Some other Free Software Foundation software is covered by
288 the GNU Library General Public License instead.)  You can apply it to
289 your programs, too.
290
291   When we speak of free software, we are referring to freedom, not
292 price.  Our General Public Licenses are designed to make sure that you
293 have the freedom to distribute copies of free software (and charge for
294 this service if you wish), that you receive source code or can get it
295 if you want it, that you can change the software or use pieces of it
296 in new free programs; and that you know you can do these things.
297
298   To protect your rights, we need to make restrictions that forbid
299 anyone to deny you these rights or to ask you to surrender the rights.
300 These restrictions translate to certain responsibilities for you if you
301 distribute copies of the software, or if you modify it.
302
303   For example, if you distribute copies of such a program, whether
304 gratis or for a fee, you must give the recipients all the rights that
305 you have.  You must make sure that they, too, receive or can get the
306 source code.  And you must show them these terms so they know their
307 rights.
308
309   We protect your rights with two steps: (1) copyright the software, and
310 (2) offer you this license which gives you legal permission to copy,
311 distribute and/or modify the software.
312
313   Also, for each author's protection and ours, we want to make certain
314 that everyone understands that there is no warranty for this free
315 software.  If the software is modified by someone else and passed on, we
316 want its recipients to know that what they have is not the original, so
317 that any problems introduced by others will not reflect on the original
318 authors' reputations.
319
320   Finally, any free program is threatened constantly by software
321 patents.  We wish to avoid the danger that redistributors of a free
322 program will individually obtain patent licenses, in effect making the
323 program proprietary.  To prevent this, we have made it clear that any
324 patent must be licensed for everyone's free use or not licensed at all.
325
326   The precise terms and conditions for copying, distribution and
327 modification follow.
328
329 @iftex
330 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
331 @end iftex
332 @ifinfo
333 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
334 @end ifinfo
335
336 @enumerate 0
337 @item
338 This License applies to any program or other work which contains
339 a notice placed by the copyright holder saying it may be distributed
340 under the terms of this General Public License.  The ``Program'', below,
341 refers to any such program or work, and a ``work based on the Program''
342 means either the Program or any derivative work under copyright law:
343 that is to say, a work containing the Program or a portion of it,
344 either verbatim or with modifications and/or translated into another
345 language.  (Hereinafter, translation is included without limitation in
346 the term ``modification''.)  Each licensee is addressed as ``you''.
347
348 Activities other than copying, distribution and modification are not
349 covered by this License; they are outside its scope.  The act of
350 running the Program is not restricted, and the output from the Program
351 is covered only if its contents constitute a work based on the
352 Program (independent of having been made by running the Program).
353 Whether that is true depends on what the Program does.
354
355 @item
356 You may copy and distribute verbatim copies of the Program's
357 source code as you receive it, in any medium, provided that you
358 conspicuously and appropriately publish on each copy an appropriate
359 copyright notice and disclaimer of warranty; keep intact all the
360 notices that refer to this License and to the absence of any warranty;
361 and give any other recipients of the Program a copy of this License
362 along with the Program.
363
364 You may charge a fee for the physical act of transferring a copy, and
365 you may at your option offer warranty protection in exchange for a fee.
366
367 @item
368 You may modify your copy or copies of the Program or any portion
369 of it, thus forming a work based on the Program, and copy and
370 distribute such modifications or work under the terms of Section 1
371 above, provided that you also meet all of these conditions:
372
373 @enumerate a
374 @item
375 You must cause the modified files to carry prominent notices
376 stating that you changed the files and the date of any change.
377
378 @item
379 You must cause any work that you distribute or publish, that in
380 whole or in part contains or is derived from the Program or any
381 part thereof, to be licensed as a whole at no charge to all third
382 parties under the terms of this License.
383
384 @item
385 If the modified program normally reads commands interactively
386 when run, you must cause it, when started running for such
387 interactive use in the most ordinary way, to print or display an
388 announcement including an appropriate copyright notice and a
389 notice that there is no warranty (or else, saying that you provide
390 a warranty) and that users may redistribute the program under
391 these conditions, and telling the user how to view a copy of this
392 License.  (Exception: if the Program itself is interactive but
393 does not normally print such an announcement, your work based on
394 the Program is not required to print an announcement.)
395 @end enumerate
396
397 These requirements apply to the modified work as a whole.  If
398 identifiable sections of that work are not derived from the Program,
399 and can be reasonably considered independent and separate works in
400 themselves, then this License, and its terms, do not apply to those
401 sections when you distribute them as separate works.  But when you
402 distribute the same sections as part of a whole which is a work based
403 on the Program, the distribution of the whole must be on the terms of
404 this License, whose permissions for other licensees extend to the
405 entire whole, and thus to each and every part regardless of who wrote it.
406
407 Thus, it is not the intent of this section to claim rights or contest
408 your rights to work written entirely by you; rather, the intent is to
409 exercise the right to control the distribution of derivative or
410 collective works based on the Program.
411
412 In addition, mere aggregation of another work not based on the Program
413 with the Program (or with a work based on the Program) on a volume of
414 a storage or distribution medium does not bring the other work under
415 the scope of this License.
416
417 @item
418 You may copy and distribute the Program (or a work based on it,
419 under Section 2) in object code or executable form under the terms of
420 Sections 1 and 2 above provided that you also do one of the following:
421
422 @enumerate a
423 @item
424 Accompany it with the complete corresponding machine-readable
425 source code, which must be distributed under the terms of Sections
426 1 and 2 above on a medium customarily used for software interchange; or,
427
428 @item
429 Accompany it with a written offer, valid for at least three
430 years, to give any third party, for a charge no more than your
431 cost of physically performing source distribution, a complete
432 machine-readable copy of the corresponding source code, to be
433 distributed under the terms of Sections 1 and 2 above on a medium
434 customarily used for software interchange; or,
435
436 @item
437 Accompany it with the information you received as to the offer
438 to distribute corresponding source code.  (This alternative is
439 allowed only for noncommercial distribution and only if you
440 received the program in object code or executable form with such
441 an offer, in accord with Subsection b above.)
442 @end enumerate
443
444 The source code for a work means the preferred form of the work for
445 making modifications to it.  For an executable work, complete source
446 code means all the source code for all modules it contains, plus any
447 associated interface definition files, plus the scripts used to
448 control compilation and installation of the executable.  However, as a
449 special exception, the source code distributed need not include
450 anything that is normally distributed (in either source or binary
451 form) with the major components (compiler, kernel, and so on) of the
452 operating system on which the executable runs, unless that component
453 itself accompanies the executable.
454
455 If distribution of executable or object code is made by offering
456 access to copy from a designated place, then offering equivalent
457 access to copy the source code from the same place counts as
458 distribution of the source code, even though third parties are not
459 compelled to copy the source along with the object code.
460
461 @item
462 You may not copy, modify, sublicense, or distribute the Program
463 except as expressly provided under this License.  Any attempt
464 otherwise to copy, modify, sublicense or distribute the Program is
465 void, and will automatically terminate your rights under this License.
466 However, parties who have received copies, or rights, from you under
467 this License will not have their licenses terminated so long as such
468 parties remain in full compliance.
469
470 @item
471 You are not required to accept this License, since you have not
472 signed it.  However, nothing else grants you permission to modify or
473 distribute the Program or its derivative works.  These actions are
474 prohibited by law if you do not accept this License.  Therefore, by
475 modifying or distributing the Program (or any work based on the
476 Program), you indicate your acceptance of this License to do so, and
477 all its terms and conditions for copying, distributing or modifying
478 the Program or works based on it.
479
480 @item
481 Each time you redistribute the Program (or any work based on the
482 Program), the recipient automatically receives a license from the
483 original licensor to copy, distribute or modify the Program subject to
484 these terms and conditions.  You may not impose any further
485 restrictions on the recipients' exercise of the rights granted herein.
486 You are not responsible for enforcing compliance by third parties to
487 this License.
488
489 @item
490 If, as a consequence of a court judgment or allegation of patent
491 infringement or for any other reason (not limited to patent issues),
492 conditions are imposed on you (whether by court order, agreement or
493 otherwise) that contradict the conditions of this License, they do not
494 excuse you from the conditions of this License.  If you cannot
495 distribute so as to satisfy simultaneously your obligations under this
496 License and any other pertinent obligations, then as a consequence you
497 may not distribute the Program at all.  For example, if a patent
498 license would not permit royalty-free redistribution of the Program by
499 all those who receive copies directly or indirectly through you, then
500 the only way you could satisfy both it and this License would be to
501 refrain entirely from distribution of the Program.
502
503 If any portion of this section is held invalid or unenforceable under
504 any particular circumstance, the balance of the section is intended to
505 apply and the section as a whole is intended to apply in other
506 circumstances.
507
508 It is not the purpose of this section to induce you to infringe any
509 patents or other property right claims or to contest validity of any
510 such claims; this section has the sole purpose of protecting the
511 integrity of the free software distribution system, which is
512 implemented by public license practices.  Many people have made
513 generous contributions to the wide range of software distributed
514 through that system in reliance on consistent application of that
515 system; it is up to the author/donor to decide if he or she is willing
516 to distribute software through any other system and a licensee cannot
517 impose that choice.
518
519 This section is intended to make thoroughly clear what is believed to
520 be a consequence of the rest of this License.
521
522 @item
523 If the distribution and/or use of the Program is restricted in
524 certain countries either by patents or by copyrighted interfaces, the
525 original copyright holder who places the Program under this License
526 may add an explicit geographical distribution limitation excluding
527 those countries, so that distribution is permitted only in or among
528 countries not thus excluded.  In such case, this License incorporates
529 the limitation as if written in the body of this License.
530
531 @item
532 The Free Software Foundation may publish revised and/or new versions
533 of the General Public License from time to time.  Such new versions will
534 be similar in spirit to the present version, but may differ in detail to
535 address new problems or concerns.
536
537 Each version is given a distinguishing version number.  If the Program
538 specifies a version number of this License which applies to it and ``any
539 later version'', you have the option of following the terms and conditions
540 either of that version or of any later version published by the Free
541 Software Foundation.  If the Program does not specify a version number of
542 this License, you may choose any version ever published by the Free Software
543 Foundation.
544
545 @item
546 If you wish to incorporate parts of the Program into other free
547 programs whose distribution conditions are different, write to the author
548 to ask for permission.  For software which is copyrighted by the Free
549 Software Foundation, write to the Free Software Foundation; we sometimes
550 make exceptions for this.  Our decision will be guided by the two goals
551 of preserving the free status of all derivatives of our free software and
552 of promoting the sharing and reuse of software generally.
553
554 @iftex
555 @heading NO WARRANTY
556 @end iftex
557 @ifinfo
558 @center NO WARRANTY
559 @end ifinfo
560
561 @item
562 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
563 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
564 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
565 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
566 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
567 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
568 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
569 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
570 REPAIR OR CORRECTION.
571
572 @item
573 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
574 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
575 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
576 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
577 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
578 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
579 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
580 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
581 POSSIBILITY OF SUCH DAMAGES.
582 @end enumerate
583
584 @iftex
585 @heading END OF TERMS AND CONDITIONS
586 @end iftex
587 @ifinfo
588 @center END OF TERMS AND CONDITIONS
589 @end ifinfo
590
591 @page
592 @unnumberedsec How to Apply These Terms to Your New Programs
593
594   If you develop a new program, and you want it to be of the greatest
595 possible use to the public, the best way to achieve this is to make it
596 free software which everyone can redistribute and change under these terms.
597
598   To do so, attach the following notices to the program.  It is safest
599 to attach them to the start of each source file to most effectively
600 convey the exclusion of warranty; and each file should have at least
601 the ``copyright'' line and a pointer to where the full notice is found.
602
603 @smallexample
604 @var{one line to give the program's name and a brief idea of what it does.}
605 Copyright (C) @var{year}  @var{name of author}
606
607 This program is free software; you can redistribute it and/or modify
608 it under the terms of the GNU General Public License as published by
609 the Free Software Foundation; either version 2 of the License, or
610 (at your option) any later version.
611
612 This program is distributed in the hope that it will be useful,
613 but WITHOUT ANY WARRANTY; without even the implied warranty of
614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
615 GNU General Public License for more details.
616
617 You should have received a copy of the GNU General Public License
618 along with this program; if not, write to the Free Software
619 Foundation, Inc., 59 Temple Place - Suite 330,
620 Boston, MA 02111-1307, USA.
621 @end smallexample
622
623 Also add information on how to contact you by electronic and paper mail.
624
625 If the program is interactive, make it output a short notice like this
626 when it starts in an interactive mode:
627
628 @smallexample
629 Gnomovision version 69, Copyright (C) @var{year} @var{name of author}
630 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
631 type `show w'.
632 This is free software, and you are welcome to redistribute it
633 under certain conditions; type `show c' for details.
634 @end smallexample
635
636 The hypothetical commands @samp{show w} and @samp{show c} should show
637 the appropriate parts of the General Public License.  Of course, the
638 commands you use may be called something other than @samp{show w} and
639 @samp{show c}; they could even be mouse-clicks or menu items---whatever
640 suits your program.
641
642 You should also get your employer (if you work as a programmer) or your
643 school, if any, to sign a ``copyright disclaimer'' for the program, if
644 necessary.  Here is a sample; alter the names:
645
646 @smallexample
647 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
648 `Gnomovision' (which makes passes at compilers) written by James Hacker.
649
650 @var{signature of Ty Coon}, 1 April 1989
651 Ty Coon, President of Vice
652 @end smallexample
653
654 This General Public License does not permit incorporating your program into
655 proprietary programs.  If your program is a subroutine library, you may
656 consider it more useful to permit linking proprietary applications with the
657 library.  If this is what you want to do, use the GNU Library General
658 Public License instead of this License.
659
660 @include fdl.texi
661
662 @node Contributors
663 @unnumbered Contributors to GNU Fortran
664 @cindex contributors
665 @cindex credits
666
667 In addition to James Craig Burley, who wrote the front end,
668 many people have helped create and improve GNU Fortran.
669
670 @itemize @bullet
671 @item
672 The packaging and compiler portions of GNU Fortran are based largely
673 on the GNU CC compiler.
674 @xref{Contributors,,Contributors to GNU CC,gcc,Using and Porting GNU CC},
675 for more information.
676
677 @item
678 The run-time library used by GNU Fortran is a repackaged version
679 of the @code{libf2c} library (combined from the @code{libF77} and
680 @code{libI77} libraries) provided as part of @code{f2c}, available for
681 free from @code{netlib} sites on the Internet.
682
683 @item
684 Cygnus Support and The Free Software Foundation contributed
685 significant money and/or equipment to Craig's efforts.
686
687 @item
688 The following individuals served as alpha testers prior to @code{g77}'s
689 public release.  This work consisted of testing, researching, sometimes
690 debugging, and occasionally providing small amounts of code and fixes
691 for @code{g77}, plus offering plenty of helpful advice to Craig:
692
693 @itemize @w{}
694 @item
695 Jonathan Corbet
696 @item
697 Dr.@: Mark Fernyhough
698 @item
699 Takafumi Hayashi (The University of Aizu)---@email{takafumi@@u-aizu.ac.jp}
700 @item
701 Kate Hedstrom
702 @item
703 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
704 @item
705 Dr.@: A. O. V. Le Blanc
706 @item
707 Dave Love
708 @item
709 Rick Lutowski
710 @item
711 Toon Moene
712 @item
713 Rick Niles
714 @item
715 Derk Reefman
716 @item
717 Wayne K. Schroll
718 @item
719 Bill Thorson
720 @item
721 Pedro A. M. Vazquez
722 @item
723 Ian Watson
724 @end itemize
725
726 @item
727 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
728 provided the patch to add rudimentary support
729 for @code{INTEGER*1}, @code{INTEGER*2}, and
730 @code{LOGICAL*1}.
731 This inspired Craig to add further support,
732 even though the resulting support
733 would still be incomplete, because version 0.6 is still
734 a ways off.
735
736 @item
737 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
738 and encouraged Craig to rewrite the documentation in texinfo
739 format by contributing a first pass at a translation of the
740 old @file{g77-0.5.16/f/DOC} file.
741
742 @item
743 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
744 some analysis of generated code as part of an overall project
745 to improve @code{g77} code generation to at least be as good
746 as @code{f2c} used in conjunction with @code{gcc}.
747 So far, this has resulted in the three, somewhat
748 experimental, options added by @code{g77} to the @code{gcc}
749 compiler and its back end.
750
751 (These, in turn, had made their way into the @code{egcs}
752 version of the compiler, and do not exist in @code{gcc}
753 version 2.8 or versions of @code{g77} based on that version
754 of @code{gcc}.)
755
756 @item
757 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
758
759 @item
760 Thanks to Mary Cortani and the staff at Craftwork Solutions
761 (@email{support@@craftwork.com}) for all of their support.
762
763 @item
764 Many other individuals have helped debug, test, and improve @code{g77}
765 over the past several years, and undoubtedly more people
766 will be doing so in the future.
767 If you have done so, and would like
768 to see your name listed in the above list, please ask!
769 The default is that people wish to remain anonymous.
770 @end itemize
771
772 @node Funding
773 @chapter Funding Free Software
774
775 If you want to have more free software a few years from now, it makes
776 sense for you to help encourage people to contribute funds for its
777 development.  The most effective approach known is to encourage
778 commercial redistributors to donate.
779
780 Users of free software systems can boost the pace of development by
781 encouraging for-a-fee distributors to donate part of their selling price
782 to free software developers---the Free Software Foundation, and others.
783
784 The way to convince distributors to do this is to demand it and expect
785 it from them.  So when you compare distributors, judge them partly by
786 how much they give to free software development.  Show distributors
787 they must compete to be the one who gives the most.
788
789 To make this approach work, you must insist on numbers that you can
790 compare, such as, ``We will donate ten dollars to the Frobnitz project
791 for each disk sold.''  Don't be satisfied with a vague promise, such as
792 ``A portion of the profits are donated,'' since it doesn't give a basis
793 for comparison.
794
795 Even a precise fraction ``of the profits from this disk'' is not very
796 meaningful, since creative accounting and unrelated business decisions
797 can greatly alter what fraction of the sales price counts as profit.
798 If the price you pay is $50, ten percent of the profit is probably
799 less than a dollar; it might be a few cents, or nothing at all.
800
801 Some redistributors do development work themselves.  This is useful too;
802 but to keep everyone honest, you need to inquire how much they do, and
803 what kind.  Some kinds of development make much more long-term
804 difference than others.  For example, maintaining a separate version of
805 a program contributes very little; maintaining the standard version of a
806 program for the whole community contributes much.  Easy new ports
807 contribute little, since someone else would surely do them; difficult
808 ports such as adding a new CPU to the GNU C compiler contribute more;
809 major new features or packages contribute the most.
810
811 By establishing the idea that supporting further development is ``the
812 proper thing to do'' when distributing free software for a fee, we can
813 assure a steady flow of resources into making more free software.
814
815 @display
816 Copyright (C) 1994 Free Software Foundation, Inc.
817 Verbatim copying and redistribution of this section is permitted
818 without royalty; alteration is not permitted.
819 @end display
820
821 @node Funding GNU Fortran
822 @chapter Funding GNU Fortran
823 @cindex funding improvements
824 @cindex improvements, funding
825
826 James Craig Burley (@email{@value{email-burley}}), the original author
827 of g77, stopped working on it in September 1999
828 (He has a web page at @uref{@value{www-burley}}.)
829
830 GNU Fortran is currently maintained by Toon Moene
831 (@email{toon@@moene.indiv.nluug.nl}), with the help of countless other
832 volunteers.
833
834 As with other GNU software, funding is important because it can pay for
835 needed equipment, personnel, and so on.
836
837 @cindex FSF, funding the
838 @cindex funding the FSF
839 The FSF provides information on the best way to fund ongoing
840 development of GNU software (such as GNU Fortran) in documents
841 such as the ``GNUS Bulletin''.
842 Email @email{gnu@@gnu.org} for information on funding the FSF.
843
844 Another important way to support work on GNU Fortran is to volunteer
845 to help out.
846 Work is needed on documentation, testing, porting
847 to various machines, and in some cases, coding (although major
848 changes planned for version 0.6 make it difficult to add manpower to this
849 area).
850 Email @email{@value{email-general}} to volunteer for this work.
851
852 @xref{Funding,,Funding Free Software}, for more information.
853
854 @node Look and Feel
855 @chapter Protect Your Freedom---Fight ``Look And Feel''
856 @c the above chapter heading overflows onto the next line. --mew 1/26/93
857
858 To preserve the ability to write free software, including replacements
859 for proprietary software, authors must be free to replicate the
860 user interface to which users of existing software have become
861 accustomed.
862
863 @xref{Look and Feel,,Protect Your Freedom---Fight ``Look And Feel'',
864 gcc,Using and Porting GNU CC}, for more information.
865
866 @node Getting Started
867 @chapter Getting Started
868 @cindex getting started
869 @cindex new users
870 @cindex newbies
871 @cindex beginners
872
873 If you don't need help getting started reading the portions
874 of this manual that are most important to you, you should skip
875 this portion of the manual.
876
877 If you are new to compilers, especially Fortran compilers, or
878 new to how compilers are structured under UNIX and UNIX-like
879 systems, you'll want to see @ref{What is GNU Fortran?}.
880
881 If you are new to GNU compilers, or have used only one GNU
882 compiler in the past and not had to delve into how it lets
883 you manage various versions and configurations of @code{gcc},
884 you should see @ref{G77 and GCC}.
885
886 Everyone except experienced @code{g77} users should
887 see @ref{Invoking G77}.
888
889 If you're acquainted with previous versions of @code{g77},
890 you should see @ref{News,,News About GNU Fortran}.
891 Further, if you've actually used previous versions of @code{g77},
892 especially if you've written or modified Fortran code to
893 be compiled by previous versions of @code{g77}, you
894 should see @ref{Changes}.
895
896 If you intend to write or otherwise compile code that is
897 not already strictly conforming ANSI FORTRAN 77---and this
898 is probably everyone---you should see @ref{Language}.
899
900 If you don't already have @code{g77} installed on your
901 system, you must see @ref{Installation}.
902
903 If you run into trouble getting Fortran code to compile,
904 link, run, or work properly, you might find answers
905 if you see @ref{Debugging and Interfacing},
906 see @ref{Collected Fortran Wisdom},
907 and see @ref{Trouble}.
908 You might also find that the problems you are encountering
909 are bugs in @code{g77}---see @ref{Bugs}, for information on
910 reporting them, after reading the other material.
911
912 If you need further help with @code{g77}, or with
913 freely redistributable software in general,
914 see @ref{Service}.
915
916 If you would like to help the @code{g77} project,
917 see @ref{Funding GNU Fortran}, for information on
918 helping financially, and see @ref{Projects}, for information
919 on helping in other ways.
920
921 If you're generally curious about the future of
922 @code{g77}, see @ref{Projects}.
923 If you're curious about its past,
924 see @ref{Contributors},
925 and see @ref{Funding GNU Fortran}.
926
927 To see a few of the questions maintainers of @code{g77} have,
928 and that you might be able to answer,
929 see @ref{Open Questions}.
930
931 @ifset USING
932 @node What is GNU Fortran?
933 @chapter What is GNU Fortran?
934 @cindex concepts, basic
935 @cindex basic concepts
936
937 GNU Fortran, or @code{g77}, is designed initially as a free replacement
938 for, or alternative to, the UNIX @code{f77} command.
939 (Similarly, @code{gcc} is designed as a replacement
940 for the UNIX @code{cc} command.)
941
942 @code{g77} also is designed to fit in well with the other
943 fine GNU compilers and tools.
944
945 Sometimes these design goals conflict---in such cases, resolution
946 often is made in favor of fitting in well with Project GNU.
947 These cases are usually identified in the appropriate
948 sections of this manual.
949
950 @cindex compilers
951 As compilers, @code{g77}, @code{gcc}, and @code{f77}
952 share the following characteristics:
953
954 @itemize @bullet
955 @cindex source code
956 @cindex file, source
957 @cindex code, source
958 @cindex source file
959 @item
960 They read a user's program, stored in a file and
961 containing instructions written in the appropriate
962 language (Fortran, C, and so on).
963 This file contains @dfn{source code}.
964
965 @cindex translation of user programs
966 @cindex machine code
967 @cindex code, machine
968 @cindex mistakes
969 @item
970 They translate the user's program into instructions
971 a computer can carry out more quickly than it takes
972 to translate the instructions in the first place.
973 These instructions are called @dfn{machine code}---code
974 designed to be efficiently translated and processed
975 by a machine such as a computer.
976 Humans usually aren't as good writing machine code
977 as they are at writing Fortran or C, because
978 it is easy to make tiny mistakes writing machine code.
979 When writing Fortran or C, it is easy
980 to make big mistakes.
981
982 @cindex debugger
983 @cindex bugs, finding
984 @cindex @code{gdb}, command
985 @cindex commands, @code{gdb}
986 @item
987 They provide information in the generated machine code
988 that can make it easier to find bugs in the program
989 (using a debugging tool, called a @dfn{debugger},
990 such as @code{gdb}).
991
992 @cindex libraries
993 @cindex linking
994 @cindex @code{ld} command
995 @cindex commands, @code{ld}
996 @item
997 They locate and gather machine code already generated
998 to perform actions requested by statements in
999 the user's program.
1000 This machine code is organized
1001 into @dfn{libraries} and is located and gathered
1002 during the @dfn{link} phase of the compilation
1003 process.
1004 (Linking often is thought of as a separate
1005 step, because it can be directly invoked via the
1006 @code{ld} command.
1007 However, the @code{g77} and @code{gcc}
1008 commands, as with most compiler commands, automatically
1009 perform the linking step by calling on @code{ld}
1010 directly, unless asked to not do so by the user.)
1011
1012 @cindex language, incorrect use of
1013 @cindex incorrect use of language
1014 @item
1015 They attempt to diagnose cases where the user's
1016 program contains incorrect usages of the language.
1017 The @dfn{diagnostics} produced by the compiler
1018 indicate the problem and the location in the user's
1019 source file where the problem was first noticed.
1020 The user can use this information to locate and
1021 fix the problem.
1022 @cindex diagnostics, incorrect
1023 @cindex incorrect diagnostics
1024 @cindex error messages, incorrect
1025 @cindex incorrect error messages
1026 (Sometimes an incorrect usage
1027 of the language leads to a situation where the
1028 compiler can no longer make any sense of what
1029 follows---while a human might be able to---and
1030 thus ends up complaining about many ``problems''
1031 it encounters that, in fact, stem from just one
1032 problem, usually the first one reported.)
1033
1034 @cindex warnings
1035 @cindex questionable instructions
1036 @item
1037 They attempt to diagnose cases where the user's
1038 program contains a correct usage of the language,
1039 but instructs the computer to do something questionable.
1040 These diagnostics often are in the form of @dfn{warnings},
1041 instead of the @dfn{errors} that indicate incorrect
1042 usage of the language.
1043 @end itemize
1044
1045 How these actions are performed is generally under the
1046 control of the user.
1047 Using command-line options, the user can specify
1048 how persnickety the compiler is to be regarding
1049 the program (whether to diagnose questionable usage
1050 of the language), how much time to spend making
1051 the generated machine code run faster, and so on.
1052
1053 @cindex components of g77
1054 @cindex @code{g77}, components of
1055 @code{g77} consists of several components:
1056
1057 @cindex @code{gcc}, command
1058 @cindex commands, @code{gcc}
1059 @itemize @bullet
1060 @item
1061 A modified version of the @code{gcc} command, which also might be
1062 installed as the system's @code{cc} command.
1063 (In many cases, @code{cc} refers to the
1064 system's ``native'' C compiler, which
1065 might be a non-GNU compiler, or an older version
1066 of @code{gcc} considered more stable or that is
1067 used to build the operating system kernel.)
1068
1069 @cindex @code{g77}, command
1070 @cindex commands, @code{g77}
1071 @item
1072 The @code{g77} command itself, which also might be installed as the
1073 system's @code{f77} command.
1074
1075 @cindex libg2c library
1076 @cindex libf2c library
1077 @cindex libraries, libf2c
1078 @cindex libraries, libg2c
1079 @cindex run-time, library
1080 @item
1081 The @code{libg2c} run-time library.
1082 This library contains the machine code needed to support
1083 capabilities of the Fortran language that are not directly
1084 provided by the machine code generated by the @code{g77}
1085 compilation phase.
1086
1087 @code{libg2c} is just the unique name @code{g77} gives
1088 to its version of @code{libf2c} to distinguish it from
1089 any copy of @code{libf2c} installed from @code{f2c}
1090 (or versions of @code{g77} that built @code{libf2c} under
1091 that same name)
1092 on the system.
1093
1094 The maintainer of @code{libf2c} currently is
1095 @email{dmg@@bell-labs.com}.
1096
1097 @cindex @code{f771}, program
1098 @cindex programs, @code{f771}
1099 @cindex assembler
1100 @cindex @code{as} command
1101 @cindex commands, @code{as}
1102 @cindex assembly code
1103 @cindex code, assembly
1104 @item
1105 The compiler itself, internally named @code{f771}.
1106
1107 Note that @code{f771} does not generate machine code directly---it
1108 generates @dfn{assembly code} that is a more readable form
1109 of machine code, leaving the conversion to actual machine code
1110 to an @dfn{assembler}, usually named @code{as}.
1111 @end itemize
1112
1113 @code{gcc} is often thought of as ``the C compiler'' only,
1114 but it does more than that.
1115 Based on command-line options and the names given for files
1116 on the command line, @code{gcc} determines which actions to perform, including
1117 preprocessing, compiling (in a variety of possible languages), assembling,
1118 and linking.
1119
1120 @cindex driver, gcc command as
1121 @cindex @code{gcc}, command as driver
1122 @cindex executable file
1123 @cindex files, executable
1124 @cindex cc1 program
1125 @cindex programs, cc1
1126 @cindex preprocessor
1127 @cindex cpp program
1128 @cindex programs, cpp
1129 For example, the command @samp{gcc foo.c} @dfn{drives} the file
1130 @file{foo.c} through the preprocessor @code{cpp}, then
1131 the C compiler (internally named
1132 @code{cc1}), then the assembler (usually @code{as}), then the linker
1133 (@code{ld}), producing an executable program named @file{a.out} (on
1134 UNIX systems).
1135
1136 @cindex cc1plus program
1137 @cindex programs, cc1plus
1138 As another example, the command @samp{gcc foo.cc} would do much the same as
1139 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
1140 @code{gcc} would use the C++ compiler (named @code{cc1plus}).
1141
1142 @cindex @code{f771}, program
1143 @cindex programs, @code{f771}
1144 In a GNU Fortran installation, @code{gcc} recognizes Fortran source
1145 files by name just like it does C and C++ source files.
1146 It knows to use the Fortran compiler named @code{f771}, instead of
1147 @code{cc1} or @code{cc1plus}, to compile Fortran files.
1148
1149 @cindex @code{gcc}, not recognizing Fortran source
1150 @cindex unrecognized file format
1151 @cindex file format not recognized
1152 Non-Fortran-related operation of @code{gcc} is generally
1153 unaffected by installing the GNU Fortran version of @code{gcc}.
1154 However, without the installed version of @code{gcc} being the
1155 GNU Fortran version, @code{gcc} will not be able to compile
1156 and link Fortran programs---and since @code{g77} uses @code{gcc}
1157 to do most of the actual work, neither will @code{g77}!
1158
1159 @cindex @code{g77}, command
1160 @cindex commands, @code{g77}
1161 The @code{g77} command is essentially just a front-end for
1162 the @code{gcc} command.
1163 Fortran users will normally use @code{g77} instead of @code{gcc},
1164 because @code{g77}
1165 knows how to specify the libraries needed to link with Fortran programs
1166 (@code{libg2c} and @code{lm}).
1167 @code{g77} can still compile and link programs and
1168 source files written in other languages, just like @code{gcc}.
1169
1170 @cindex printing version information
1171 @cindex version information, printing
1172 The command @samp{g77 -v} is a quick
1173 way to display lots of version information for the various programs
1174 used to compile a typical preprocessed Fortran source file---this
1175 produces much more output than @samp{gcc -v} currently does.
1176 (If it produces an error message near the end of the output---diagnostics
1177 from the linker, usually @code{ld}---you might
1178 have an out-of-date @code{libf2c} that improperly handles
1179 complex arithmetic.)
1180 In the output of this command, the line beginning @samp{GNU Fortran Front
1181 End} identifies the version number of GNU Fortran; immediately
1182 preceding that line is a line identifying the version of @code{gcc}
1183 with which that version of @code{g77} was built.
1184
1185 @cindex libf2c library
1186 @cindex libraries, libf2c
1187 The @code{libf2c} library is distributed with GNU Fortran for
1188 the convenience of its users, but is not part of GNU Fortran.
1189 It contains the procedures
1190 needed by Fortran programs while they are running.
1191
1192 @cindex in-line code
1193 @cindex code, in-line
1194 For example, while code generated by @code{g77} is likely
1195 to do additions, subtractions, and multiplications @dfn{in line}---in
1196 the actual compiled code---it is not likely to do trigonometric
1197 functions this way.
1198
1199 Instead, operations like trigonometric
1200 functions are compiled by the @code{f771} compiler
1201 (invoked by @code{g77} when compiling Fortran code) into machine
1202 code that, when run, calls on functions in @code{libg2c}, so
1203 @code{libg2c} must be linked with almost every useful program
1204 having any component compiled by GNU Fortran.
1205 (As mentioned above, the @code{g77} command takes
1206 care of all this for you.)
1207
1208 The @code{f771} program represents most of what is unique to GNU Fortran.
1209 While much of the @code{libg2c} component comes from
1210 the @code{libf2c} component of @code{f2c},
1211 a free Fortran-to-C converter distributed by Bellcore (AT&T),
1212 plus @code{libU77}, provided by Dave Love,
1213 and the @code{g77} command is just a small front-end to @code{gcc},
1214 @code{f771} is a combination of two rather
1215 large chunks of code.
1216
1217 @cindex GNU Back End (GBE)
1218 @cindex GBE
1219 @cindex @code{gcc}, back end
1220 @cindex back end, gcc
1221 @cindex code generator
1222 One chunk is the so-called @dfn{GNU Back End}, or GBE,
1223 which knows how to generate fast code for a wide variety of processors.
1224 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
1225 @code{cc1plus}, and @code{f771}, plus others.
1226 Often the GBE is referred to as the ``gcc back end'' or
1227 even just ``gcc''---in this manual, the term GBE is used
1228 whenever the distinction is important.
1229
1230 @cindex GNU Fortran Front End (FFE)
1231 @cindex FFE
1232 @cindex @code{g77}, front end
1233 @cindex front end, @code{g77}
1234 The other chunk of @code{f771} is the
1235 majority of what is unique about GNU Fortran---the code that knows how
1236 to interpret Fortran programs to determine what they are intending to
1237 do, and then communicate that knowledge to the GBE for actual compilation
1238 of those programs.
1239 This chunk is called the @dfn{Fortran Front End} (FFE).
1240 The @code{cc1} and @code{cc1plus} programs have their own front ends,
1241 for the C and C++ languages, respectively.
1242 These fronts ends are responsible for diagnosing
1243 incorrect usage of their respective languages by the
1244 programs the process, and are responsible for most of
1245 the warnings about questionable constructs as well.
1246 (The GBE handles producing some warnings, like those
1247 concerning possible references to undefined variables.)
1248
1249 Because so much is shared among the compilers for various languages,
1250 much of the behavior and many of the user-selectable options for these
1251 compilers are similar.
1252 For example, diagnostics (error messages and
1253 warnings) are similar in appearance; command-line
1254 options like @samp{-Wall} have generally similar effects; and the quality
1255 of generated code (in terms of speed and size) is roughly similar
1256 (since that work is done by the shared GBE).
1257
1258 @node G77 and GCC
1259 @chapter Compile Fortran, C, or Other Programs
1260 @cindex compiling programs
1261 @cindex programs, compiling
1262
1263 @cindex @code{gcc}, command
1264 @cindex commands, @code{gcc}
1265 A GNU Fortran installation includes a modified version of the @code{gcc}
1266 command.
1267
1268 In a non-Fortran installation, @code{gcc} recognizes C, C++,
1269 and Objective-C source files.
1270
1271 In a GNU Fortran installation, @code{gcc} also recognizes Fortran source
1272 files and accepts Fortran-specific command-line options, plus some
1273 command-line options that are designed to cater to Fortran users
1274 but apply to other languages as well.
1275
1276 @xref{G++ and GCC,,Compile C; C++; or Objective-C,gcc,Using and Porting GNU CC},
1277 for information on the way different languages are handled
1278 by the GNU CC compiler (@code{gcc}).
1279
1280 @cindex @code{g77}, command
1281 @cindex commands, @code{g77}
1282 Also provided as part of GNU Fortran is the @code{g77} command.
1283 The @code{g77} command is designed to make compiling and linking Fortran
1284 programs somewhat easier than when using the @code{gcc} command for
1285 these tasks.
1286 It does this by analyzing the command line somewhat and changing it
1287 appropriately before submitting it to the @code{gcc} command.
1288
1289 @cindex -v option
1290 @cindex @code{g77} options, -v
1291 @cindex options, -v
1292 Use the @samp{-v} option with @code{g77}
1293 to see what is going on---the first line of output is the invocation
1294 of the @code{gcc} command.
1295
1296 @node Invoking G77
1297 @chapter GNU Fortran Command Options
1298 @cindex GNU Fortran command options
1299 @cindex command options
1300 @cindex options, GNU Fortran command
1301
1302 The @code{g77} command supports all the options supported by the
1303 @code{gcc} command.
1304 @xref{Invoking GCC,,GNU CC Command Options,gcc,Using and Porting GNU CC},
1305 for information
1306 on the non-Fortran-specific aspects of the @code{gcc} command (and,
1307 therefore, the @code{g77} command).
1308
1309 @cindex options, negative forms
1310 @cindex negative forms of options
1311 All @code{gcc} and @code{g77} options
1312 are accepted both by @code{g77} and by @code{gcc}
1313 (as well as any other drivers built at the same time,
1314 such as @code{g++}),
1315 since adding @code{g77} to the @code{gcc} distribution
1316 enables acceptance of @code{g77}-specific options
1317 by all of the relevant drivers.
1318
1319 In some cases, options have positive and negative forms;
1320 the negative form of @samp{-ffoo} would be @samp{-fno-foo}.
1321 This manual documents only one of these two forms, whichever
1322 one is not the default.
1323
1324 @menu
1325 * Option Summary::      Brief list of all @code{g77} options,
1326                         without explanations.
1327 * Overall Options::     Controlling the kind of output:
1328                         an executable, object files, assembler files,
1329                         or preprocessed source.
1330 * Shorthand Options::   Options that are shorthand for other options.
1331 * Fortran Dialect Options::  Controlling the variant of Fortran language
1332                              compiled.
1333 * Warning Options::     How picky should the compiler be?
1334 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1335 * Optimize Options::    How much optimization?
1336 * Preprocessor Options:: Controlling header files and macro definitions.
1337                          Also, getting dependency information for Make.
1338 * Directory Options::   Where to find header files and libraries.
1339                         Where to find the compiler executable files.
1340 * Code Gen Options::    Specifying conventions for function calls, data layout
1341                         and register usage.
1342 * Environment Variables:: Env vars that affect GNU Fortran.
1343 @end menu
1344
1345 @node Option Summary
1346 @section Option Summary
1347
1348 Here is a summary of all the options specific to GNU Fortran, grouped
1349 by type.  Explanations are in the following sections.
1350
1351 @table @emph
1352 @item Overall Options
1353 @xref{Overall Options,,Options Controlling the Kind of Output}.
1354 @smallexample
1355 -fversion  -fset-g77-defaults  -fno-silent
1356 @end smallexample
1357
1358 @item Shorthand Options
1359 @xref{Shorthand Options}.
1360 @smallexample
1361 -ff66  -fno-f66  -ff77  -fno-f77  -fno-ugly
1362 @end smallexample
1363
1364 @item Fortran Language Options
1365 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
1366 @smallexample
1367 -ffree-form  -fno-fixed-form  -ff90
1368 -fvxt  -fdollar-ok  -fno-backslash
1369 -fno-ugly-args  -fno-ugly-assign  -fno-ugly-assumed
1370 -fugly-comma  -fugly-complex  -fugly-init  -fugly-logint
1371 -fonetrip  -ftypeless-boz
1372 -fintrin-case-initcap  -fintrin-case-upper
1373 -fintrin-case-lower  -fintrin-case-any
1374 -fmatch-case-initcap  -fmatch-case-upper
1375 -fmatch-case-lower  -fmatch-case-any
1376 -fsource-case-upper  -fsource-case-lower
1377 -fsource-case-preserve
1378 -fsymbol-case-initcap  -fsymbol-case-upper
1379 -fsymbol-case-lower  -fsymbol-case-any
1380 -fcase-strict-upper  -fcase-strict-lower
1381 -fcase-initcap  -fcase-upper  -fcase-lower  -fcase-preserve
1382 -ff2c-intrinsics-delete  -ff2c-intrinsics-hide
1383 -ff2c-intrinsics-disable  -ff2c-intrinsics-enable
1384 -fbadu77-intrinsics-delete  -fbadu77-intrinsics-hide
1385 -fbadu77-intrinsics-disable  -fbadu77-intrinsics-enable
1386 -ff90-intrinsics-delete  -ff90-intrinsics-hide
1387 -ff90-intrinsics-disable  -ff90-intrinsics-enable
1388 -fgnu-intrinsics-delete  -fgnu-intrinsics-hide
1389 -fgnu-intrinsics-disable  -fgnu-intrinsics-enable
1390 -fmil-intrinsics-delete  -fmil-intrinsics-hide
1391 -fmil-intrinsics-disable  -fmil-intrinsics-enable
1392 -funix-intrinsics-delete  -funix-intrinsics-hide
1393 -funix-intrinsics-disable  -funix-intrinsics-enable
1394 -fvxt-intrinsics-delete  -fvxt-intrinsics-hide
1395 -fvxt-intrinsics-disable  -fvxt-intrinsics-enable
1396 -ffixed-line-length-@var{n}  -ffixed-line-length-none
1397 @end smallexample
1398
1399 @item Warning Options
1400 @xref{Warning Options,,Options to Request or Suppress Warnings}.
1401 @smallexample
1402 -fsyntax-only  -pedantic  -pedantic-errors  -fpedantic
1403 -w  -Wno-globals  -Wimplicit  -Wunused  -Wuninitialized
1404 -Wall  -Wsurprising
1405 -Werror  -W
1406 @end smallexample
1407
1408 @item Debugging Options
1409 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
1410 @smallexample
1411 -g
1412 @end smallexample
1413
1414 @item Optimization Options
1415 @xref{Optimize Options,,Options that Control Optimization}.
1416 @smallexample
1417 -malign-double
1418 -ffloat-store  -fforce-mem  -fforce-addr  -fno-inline
1419 -ffast-math  -fstrength-reduce  -frerun-cse-after-loop
1420 -funsafe-math-optimizations -fno-trapping-math
1421 -fexpensive-optimizations  -fdelayed-branch
1422 -fschedule-insns  -fschedule-insn2  -fcaller-saves
1423 -funroll-loops  -funroll-all-loops
1424 -fno-move-all-movables  -fno-reduce-all-givs
1425 -fno-rerun-loop-opt
1426 @end smallexample
1427
1428 @item Directory Options
1429 @xref{Directory Options,,Options for Directory Search}.
1430 @smallexample
1431 -I@var{dir}  -I-
1432 @end smallexample
1433
1434 @item Code Generation Options
1435 @xref{Code Gen Options,,Options for Code Generation Conventions}.
1436 @smallexample
1437 -fno-automatic  -finit-local-zero  -fno-f2c
1438 -ff2c-library  -fno-underscoring  -fno-ident
1439 -fpcc-struct-return  -freg-struct-return
1440 -fshort-double  -fno-common  -fpack-struct
1441 -fzeros  -fno-second-underscore
1442 -femulate-complex
1443 -falias-check  -fargument-alias
1444 -fargument-noalias  -fno-argument-noalias-global
1445 -fno-globals  -fflatten-arrays
1446 -fbounds-check  -ffortran-bounds-check
1447 @end smallexample
1448 @end table
1449
1450 @menu
1451 * Overall Options::     Controlling the kind of output:
1452                         an executable, object files, assembler files,
1453                         or preprocessed source.
1454 * Shorthand Options::   Options that are shorthand for other options.
1455 * Fortran Dialect Options::  Controlling the variant of Fortran language
1456                              compiled.
1457 * Warning Options::     How picky should the compiler be?
1458 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1459 * Optimize Options::    How much optimization?
1460 * Preprocessor Options:: Controlling header files and macro definitions.
1461                          Also, getting dependency information for Make.
1462 * Directory Options::   Where to find header files and libraries.
1463                         Where to find the compiler executable files.
1464 * Code Gen Options::    Specifying conventions for function calls, data layout
1465                         and register usage.
1466 @end menu
1467
1468 @node Overall Options
1469 @section Options Controlling the Kind of Output
1470 @cindex overall options
1471 @cindex options, overall
1472
1473 Compilation can involve as many as four stages: preprocessing, code
1474 generation (often what is really meant by the term ``compilation''),
1475 assembly, and linking, always in that order.  The first three
1476 stages apply to an individual source file, and end by producing an
1477 object file; linking combines all the object files (those newly
1478 compiled, and those specified as input) into an executable file.
1479
1480 @cindex file name suffix
1481 @cindex suffixes, file name
1482 @cindex file name extension
1483 @cindex extensions, file name
1484 @cindex file type
1485 @cindex types, file
1486 For any given input file, the file name suffix determines what kind of
1487 program is contained in the file---that is, the language in which the
1488 program is written is generally indicated by the suffix.
1489 Suffixes specific to GNU Fortran are listed below.
1490 @xref{Overall Options,,gcc,Using and Porting GNU CC}, for
1491 information on suffixes recognized by GNU CC.
1492
1493 @table @code
1494 @cindex .f filename suffix
1495 @cindex .for filename suffix
1496 @cindex .FOR filename suffix
1497 @item @var{file}.f
1498 @item @var{file}.for
1499 @item @var{file}.FOR
1500 Fortran source code that should not be preprocessed.
1501
1502 Such source code cannot contain any preprocessor directives, such
1503 as @code{#include}, @code{#define}, @code{#if}, and so on.
1504
1505 You can force @samp{.f} files to be preprocessed by @code{cpp} by using
1506 @samp{-x f77-cpp-input}.
1507 @xref{LEX}.
1508
1509 @cindex preprocessor
1510 @cindex C preprocessor
1511 @cindex cpp preprocessor
1512 @cindex Fortran preprocessor
1513 @cindex cpp program
1514 @cindex programs, cpp
1515 @cindex .F filename suffix
1516 @cindex .fpp filename suffix
1517 @cindex .FPP filename suffix
1518 @item @var{file}.F
1519 @item @var{file}.fpp
1520 @item @var{file}.FPP
1521 Fortran source code that must be preprocessed (by the C preprocessor
1522 @code{cpp}, which is part of GNU CC).
1523
1524 Note that preprocessing is not extended to the contents of
1525 files included by the @code{INCLUDE} directive---the @code{#include}
1526 preprocessor directive must be used instead.
1527
1528 @cindex Ratfor preprocessor
1529 @cindex programs, @code{ratfor}
1530 @cindex @samp{.r} filename suffix
1531 @cindex @code{ratfor}
1532 @item @var{file}.r
1533 Ratfor source code, which must be preprocessed by the @code{ratfor}
1534 command, which is available separately (as it is not yet part of the GNU
1535 Fortran distribution).
1536 One version in Fortran, adapted for use with @code{g77}, is at
1537 @uref{ftp://members.aol.com/n8tm/rat7.uue} (of uncertain copyright
1538 status).  Another, public domain version in C is at
1539 @uref{http://sepwww.stanford.edu/sep/prof/ratfor.shar.2}.
1540 @end table
1541
1542 UNIX users typically use the @file{@var{file}.f} and @file{@var{file}.F}
1543 nomenclature.
1544 Users of other operating systems, especially those that cannot
1545 distinguish upper-case
1546 letters from lower-case letters in their file names, typically use
1547 the @file{@var{file}.for} and @file{@var{file}.fpp} nomenclature.
1548
1549 @cindex #define
1550 @cindex #include
1551 @cindex #if
1552 Use of the preprocessor @code{cpp} allows use of C-like
1553 constructs such as @code{#define} and @code{#include}, but can
1554 lead to unexpected, even mistaken, results due to Fortran's source file
1555 format.
1556 It is recommended that use of the C preprocessor
1557 be limited to @code{#include} and, in
1558 conjunction with @code{#define}, only @code{#if} and related directives,
1559 thus avoiding in-line macro expansion entirely.
1560 This recommendation applies especially
1561 when using the traditional fixed source form.
1562 With free source form,
1563 fewer unexpected transformations are likely to happen, but use of
1564 constructs such as Hollerith and character constants can nevertheless
1565 present problems, especially when these are continued across multiple
1566 source lines.
1567 These problems result, primarily, from differences between the way
1568 such constants are interpreted by the C preprocessor and by a Fortran
1569 compiler.
1570
1571 Another example of a problem that results from using the C preprocessor
1572 is that a Fortran comment line that happens to contain any
1573 characters ``interesting'' to the C preprocessor,
1574 such as a backslash at the end of the line,
1575 is not recognized by the preprocessor as a comment line,
1576 so instead of being passed through ``raw'',
1577 the line is edited according to the rules for the preprocessor.
1578 For example, the backslash at the end of the line is removed,
1579 along with the subsequent newline, resulting in the next
1580 line being effectively commented out---unfortunate if that
1581 line is a non-comment line of important code!
1582
1583 @emph{Note:} The @samp{-traditional} and @samp{-undef} flags are supplied
1584 to @code{cpp} by default, to help avoid unpleasant surprises.
1585 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
1586 gcc,Using and Porting GNU CC}.
1587 This means that ANSI C preprocessor features (such as the @samp{#}
1588 operator) aren't available, and only variables in the C reserved
1589 namespace (generally, names with a leading underscore) are liable to
1590 substitution by C predefines.
1591 Thus, if you want to do system-specific
1592 tests, use, for example, @samp{#ifdef __linux__} rather than @samp{#ifdef linux}.
1593 Use the @samp{-v} option to see exactly how the preprocessor is invoked.
1594
1595 @cindex /*
1596 Unfortunately, the @samp{-traditional} flag will not avoid an error from
1597 anything that @code{cpp} sees as an unterminated C comment, such as:
1598 @smallexample
1599 C Some Fortran compilers accept /* as starting
1600 C an inline comment.
1601 @end smallexample
1602 @xref{Trailing Comment}.
1603
1604 The following options that affect overall processing are recognized
1605 by the @code{g77} and @code{gcc} commands in a GNU Fortran installation:
1606
1607 @table @code
1608 @cindex -fversion option
1609 @cindex options, -fversion
1610 @cindex printing version information
1611 @cindex version information, printing
1612 @cindex consistency checks
1613 @cindex internal consistency checks
1614 @cindex checks, of internal consistency
1615 @item -fversion
1616 Ensure that the @code{g77}-specific version of the compiler phase is reported,
1617 if run,
1618 and, starting in @code{egcs} version 1.1,
1619 that internal consistency checks in the @file{f771} program are run.
1620
1621 This option is supplied automatically when @samp{-v} or @samp{--verbose}
1622 is specified as a command-line option for @code{g77} or @code{gcc}
1623 and when the resulting commands compile Fortran source files.
1624
1625 @cindex -fset-g77-defaults option
1626 @cindex options, -fset-g77-defaults
1627 @item -fset-g77-defaults
1628 @emph{Version info:}
1629 This option was obsolete as of @code{egcs}
1630 version 1.1.
1631 The effect is instead achieved
1632 by the @code{lang_init_options} routine
1633 in @file{gcc/gcc/f/com.c}.
1634
1635 @cindex consistency checks
1636 @cindex internal consistency checks
1637 @cindex checks, of internal consistency
1638 Set up whatever @code{gcc} options are to apply to Fortran
1639 compilations, and avoid running internal consistency checks
1640 that might take some time.
1641
1642 This option is supplied automatically when compiling Fortran code
1643 via the @code{g77} or @code{gcc} command.
1644 The description of this option is provided so that users seeing
1645 it in the output of, say, @samp{g77 -v} understand why it is
1646 there.
1647
1648 @cindex modifying g77
1649 @cindex code, modifying
1650 Also, developers who run @code{f771} directly might want to specify it
1651 by hand to get the same defaults as they would running @code{f771}
1652 via @code{g77} or @code{gcc}.
1653 However, such developers should, after linking a new @code{f771}
1654 executable, invoke it without this option once,
1655 e.g. via @kbd{./f771 -quiet < /dev/null},
1656 to ensure that they have not introduced any
1657 internal inconsistencies (such as in the table of
1658 intrinsics) before proceeding---@code{g77} will crash
1659 with a diagnostic if it detects an inconsistency.
1660
1661 @cindex -fno-silent option
1662 @cindex options, -fno-silent
1663 @cindex f2c compatibility
1664 @cindex compatibility, f2c
1665 @cindex status, compilation
1666 @cindex compilation, status
1667 @cindex reporting compilation status
1668 @cindex printing compilation status
1669 @item -fno-silent
1670 Print (to @code{stderr}) the names of the program units as
1671 they are compiled, in a form similar to that used by popular
1672 UNIX @code{f77} implementations and @code{f2c}.
1673 @end table
1674
1675 @xref{Overall Options,,Options Controlling the Kind of Output,
1676 gcc,Using and Porting GNU CC}, for information
1677 on more options that control the overall operation of the @code{gcc} command
1678 (and, by extension, the @code{g77} command).
1679
1680 @node Shorthand Options
1681 @section Shorthand Options
1682 @cindex shorthand options
1683 @cindex options, shorthand
1684 @cindex macro options
1685 @cindex options, macro
1686
1687 The following options serve as ``shorthand''
1688 for other options accepted by the compiler:
1689
1690 @table @code
1691 @cindex -fugly option
1692 @cindex options, -fugly
1693 @item -fugly
1694 @cindex ugly features
1695 @cindex features, ugly
1696 @emph{Note:} This option is no longer supported.
1697 The information, below, is provided to aid
1698 in the conversion of old scripts.
1699
1700 Specify that certain ``ugly'' constructs are to be quietly accepted.
1701 Same as:
1702
1703 @smallexample
1704 -fugly-args -fugly-assign -fugly-assumed
1705 -fugly-comma -fugly-complex -fugly-init
1706 -fugly-logint
1707 @end smallexample
1708
1709 These constructs are considered inappropriate to use in new
1710 or well-maintained portable Fortran code, but widely used
1711 in old code.
1712 @xref{Distensions}, for more information.
1713
1714 @cindex -fno-ugly option
1715 @cindex options, -fno-ugly
1716 @item -fno-ugly
1717 @cindex ugly features
1718 @cindex features, ugly
1719 Specify that all ``ugly'' constructs are to be noisily rejected.
1720 Same as:
1721
1722 @smallexample
1723 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1724 -fno-ugly-comma -fno-ugly-complex -fno-ugly-init
1725 -fno-ugly-logint
1726 @end smallexample
1727
1728 @xref{Distensions}, for more information.
1729
1730 @cindex -ff66 option
1731 @cindex options, -ff66
1732 @item -ff66
1733 @cindex FORTRAN 66
1734 @cindex compatibility, FORTRAN 66
1735 Specify that the program is written in idiomatic FORTRAN 66.
1736 Same as @samp{-fonetrip -fugly-assumed}.
1737
1738 The @samp{-fno-f66} option is the inverse of @samp{-ff66}.
1739 As such, it is the same as @samp{-fno-onetrip -fno-ugly-assumed}.
1740
1741 The meaning of this option is likely to be refined as future
1742 versions of @code{g77} provide more compatibility with other
1743 existing and obsolete Fortran implementations.
1744
1745 @cindex -ff77 option
1746 @cindex options, -ff77
1747 @item -ff77
1748 @cindex UNIX f77
1749 @cindex f2c compatibility
1750 @cindex compatibility, f2c
1751 @cindex f77 compatibility
1752 @cindex compatibility, f77
1753 Specify that the program is written in idiomatic UNIX FORTRAN 77
1754 and/or the dialect accepted by the @code{f2c} product.
1755 Same as @samp{-fbackslash -fno-typeless-boz}.
1756
1757 The meaning of this option is likely to be refined as future
1758 versions of @code{g77} provide more compatibility with other
1759 existing and obsolete Fortran implementations.
1760
1761 @cindex -fno-f77 option
1762 @cindex options, -fno-f77
1763 @item -fno-f77
1764 @cindex UNIX f77
1765 The @samp{-fno-f77} option is @emph{not} the inverse
1766 of @samp{-ff77}.
1767 It specifies that the program is not written in idiomatic UNIX
1768 FORTRAN 77 or @code{f2c}, but in a more widely portable dialect.
1769 @samp{-fno-f77} is the same as @samp{-fno-backslash}.
1770
1771 The meaning of this option is likely to be refined as future
1772 versions of @code{g77} provide more compatibility with other
1773 existing and obsolete Fortran implementations.
1774 @end table
1775
1776 @node Fortran Dialect Options
1777 @section Options Controlling Fortran Dialect
1778 @cindex dialect options
1779 @cindex language, dialect options
1780 @cindex options, dialect
1781
1782 The following options control the dialect of Fortran
1783 that the compiler accepts:
1784
1785 @table @code
1786 @cindex -ffree-form option
1787 @cindex options, -ffree-form
1788 @cindex -fno-fixed-form option
1789 @cindex options, -fno-fixed-form
1790 @cindex source file format
1791 @cindex free form
1792 @cindex fixed form
1793 @cindex Fortran 90, features
1794 @item -ffree-form
1795 @item -fno-fixed-form
1796 Specify that the source file is written in free form
1797 (introduced in Fortran 90) instead of the more-traditional fixed form.
1798
1799 @cindex -ff90 option
1800 @cindex options, -ff90
1801 @cindex Fortran 90, features
1802 @item -ff90
1803 Allow certain Fortran-90 constructs.
1804
1805 This option controls whether certain
1806 Fortran 90 constructs are recognized.
1807 (Other Fortran 90 constructs
1808 might or might not be recognized depending on other options such as
1809 @samp{-fvxt}, @samp{-ff90-intrinsics-enable}, and the
1810 current level of support for Fortran 90.)
1811
1812 @xref{Fortran 90}, for more information.
1813
1814 @cindex -fvxt option
1815 @cindex options, -fvxt
1816 @item -fvxt
1817 @cindex Fortran 90, features
1818 @cindex VXT extensions
1819 Specify the treatment of certain constructs that have different
1820 meanings depending on whether the code is written in
1821 GNU Fortran (based on FORTRAN 77 and akin to Fortran 90)
1822 or VXT Fortran (more like VAX FORTRAN).
1823
1824 The default is @samp{-fno-vxt}.
1825 @samp{-fvxt} specifies that the VXT Fortran interpretations
1826 for those constructs are to be chosen.
1827
1828 @xref{VXT Fortran}, for more information.
1829
1830 @cindex -fdollar-ok option
1831 @cindex options, -fdollar-ok
1832 @item -fdollar-ok
1833 @cindex dollar sign
1834 @cindex symbol names
1835 @cindex character set
1836 Allow @samp{$} as a valid character in a symbol name.
1837
1838 @cindex -fno-backslash option
1839 @cindex options, -fno-backslash
1840 @item -fno-backslash
1841 @cindex backslash
1842 @cindex character constants
1843 @cindex Hollerith constants
1844 Specify that @samp{\} is not to be specially interpreted in character
1845 and Hollerith constants a la C and many UNIX Fortran compilers.
1846
1847 For example, with @samp{-fbackslash} in effect, @samp{A\nB} specifies
1848 three characters, with the second one being newline.
1849 With @samp{-fno-backslash}, it specifies four characters,
1850 @samp{A}, @samp{\}, @samp{n}, and @samp{B}.
1851
1852 Note that @code{g77} implements a fairly general form of backslash
1853 processing that is incompatible with the narrower forms supported
1854 by some other compilers.
1855 For example, @samp{'A\003B'} is a three-character string in @code{g77},
1856 whereas other compilers that support backslash might not support
1857 the three-octal-digit form, and thus treat that string as longer
1858 than three characters.
1859
1860 @xref{Backslash in Constants}, for
1861 information on why @samp{-fbackslash} is the default
1862 instead of @samp{-fno-backslash}.
1863
1864 @cindex -fno-ugly-args option
1865 @cindex options, -fno-ugly-args
1866 @item -fno-ugly-args
1867 Disallow passing Hollerith and typeless constants as actual
1868 arguments (for example, @samp{CALL FOO(4HABCD)}).
1869
1870 @xref{Ugly Implicit Argument Conversion}, for more information.
1871
1872 @cindex -fugly-assign option
1873 @cindex options, -fugly-assign
1874 @item -fugly-assign
1875 Use the same storage for a given variable regardless of
1876 whether it is used to hold an assigned-statement label
1877 (as in @samp{ASSIGN 10 TO I}) or used to hold numeric data
1878 (as in @samp{I = 3}).
1879
1880 @xref{Ugly Assigned Labels}, for more information.
1881
1882 @cindex -fugly-assumed option
1883 @cindex options, -fugly-assumed
1884 @item -fugly-assumed
1885 Assume any dummy array with a final dimension specified as @samp{1}
1886 is really an assumed-size array, as if @samp{*} had been specified
1887 for the final dimension instead of @samp{1}.
1888
1889 For example, @samp{DIMENSION X(1)} is treated as if it
1890 had read @samp{DIMENSION X(*)}.
1891
1892 @xref{Ugly Assumed-Size Arrays}, for more information.
1893
1894 @cindex -fugly-comma option
1895 @cindex options, -fugly-comma
1896 @item -fugly-comma
1897 In an external-procedure invocation,
1898 treat a trailing comma in the argument list
1899 as specification of a trailing null argument,
1900 and treat an empty argument list
1901 as specification of a single null argument.
1902
1903 For example, @samp{CALL FOO(,)} is treated as
1904 @samp{CALL FOO(%VAL(0), %VAL(0))}.
1905 That is, @emph{two} null arguments are specified
1906 by the procedure call when @samp{-fugly-comma} is in force.
1907 And @samp{F = FUNC()} is treated as @samp{F = FUNC(%VAL(0))}.
1908
1909 The default behavior, @samp{-fno-ugly-comma}, is to ignore
1910 a single trailing comma in an argument list.
1911 So, by default, @samp{CALL FOO(X,)} is treated
1912 exactly the same as @samp{CALL FOO(X)}.
1913
1914 @xref{Ugly Null Arguments}, for more information.
1915
1916 @cindex -fugly-complex option
1917 @cindex options, -fugly-complex
1918 @item -fugly-complex
1919 Do not complain about @samp{REAL(@var{expr})} or
1920 @samp{AIMAG(@var{expr})} when @var{expr} is a @code{COMPLEX}
1921 type other than @code{COMPLEX(KIND=1)}---usually
1922 this is used to permit @code{COMPLEX(KIND=2)}
1923 (@code{DOUBLE COMPLEX}) operands.
1924
1925 The @samp{-ff90} option controls the interpretation
1926 of this construct.
1927
1928 @xref{Ugly Complex Part Extraction}, for more information.
1929
1930 @cindex -fno-ugly-init option
1931 @cindex options, -fno-ugly-init
1932 @item -fno-ugly-init
1933 Disallow use of Hollerith and typeless constants as initial
1934 values (in @code{PARAMETER} and @code{DATA} statements), and
1935 use of character constants to
1936 initialize numeric types and vice versa.
1937
1938 For example, @samp{DATA I/'F'/, CHRVAR/65/, J/4HABCD/} is disallowed by
1939 @samp{-fno-ugly-init}.
1940
1941 @xref{Ugly Conversion of Initializers}, for more information.
1942
1943 @cindex -fugly-logint option
1944 @cindex options, -fugly-logint
1945 @item -fugly-logint
1946 Treat @code{INTEGER} and @code{LOGICAL} variables and
1947 expressions as potential stand-ins for each other.
1948
1949 For example, automatic conversion between @code{INTEGER} and
1950 @code{LOGICAL} is enabled, for many contexts, via this option.
1951
1952 @xref{Ugly Integer Conversions}, for more information.
1953
1954 @cindex -fonetrip option
1955 @cindex options, -fonetrip
1956 @item -fonetrip
1957 @cindex FORTRAN 66
1958 @cindex @code{DO} loops, one-trip
1959 @cindex one-trip @code{DO} loops
1960 @cindex @code{DO} loops, zero-trip
1961 @cindex zero-trip @code{DO} loops
1962 @cindex compatibility, FORTRAN 66
1963 Executable iterative @code{DO} loops are to be executed at
1964 least once each time they are reached.
1965
1966 ANSI FORTRAN 77 and more recent versions of the Fortran standard
1967 specify that the body of an iterative @code{DO} loop is not executed
1968 if the number of iterations calculated from the parameters of the
1969 loop is less than 1.
1970 (For example, @samp{DO 10 I = 1, 0}.)
1971 Such a loop is called a @dfn{zero-trip loop}.
1972
1973 Prior to ANSI FORTRAN 77, many compilers implemented @code{DO} loops
1974 such that the body of a loop would be executed at least once, even
1975 if the iteration count was zero.
1976 Fortran code written assuming this behavior is said to require
1977 @dfn{one-trip loops}.
1978 For example, some code written to the FORTRAN 66 standard
1979 expects this behavior from its @code{DO} loops, although that
1980 standard did not specify this behavior.
1981
1982 The @samp{-fonetrip} option specifies that the source file(s) being
1983 compiled require one-trip loops.
1984
1985 This option affects only those loops specified by the (iterative) @code{DO}
1986 statement and by implied-@code{DO} lists in I/O statements.
1987 Loops specified by implied-@code{DO} lists in @code{DATA} and
1988 specification (non-executable) statements are not affected.
1989
1990 @cindex -ftypeless-boz option
1991 @cindex options, -ftypeless-boz
1992 @cindex prefix-radix constants
1993 @cindex constants, prefix-radix
1994 @cindex constants, types
1995 @cindex types, constants
1996 @item -ftypeless-boz
1997 Specifies that prefix-radix non-decimal constants, such as
1998 @samp{Z'ABCD'}, are typeless instead of @code{INTEGER(KIND=1)}.
1999
2000 You can test for yourself whether a particular compiler treats
2001 the prefix form as @code{INTEGER(KIND=1)} or typeless by running the
2002 following program:
2003
2004 @smallexample
2005 EQUIVALENCE (I, R)
2006 R = Z'ABCD1234'
2007 J = Z'ABCD1234'
2008 IF (J .EQ. I) PRINT *, 'Prefix form is TYPELESS'
2009 IF (J .NE. I) PRINT *, 'Prefix form is INTEGER'
2010 END
2011 @end smallexample
2012
2013 Reports indicate that many compilers process this form as
2014 @code{INTEGER(KIND=1)}, though a few as typeless, and at least one
2015 based on a command-line option specifying some kind of
2016 compatibility.
2017
2018 @cindex -fintrin-case-initcap option
2019 @cindex options, -fintrin-case-initcap
2020 @item -fintrin-case-initcap
2021 @cindex -fintrin-case-upper option
2022 @cindex options, -fintrin-case-upper
2023 @item -fintrin-case-upper
2024 @cindex -fintrin-case-lower option
2025 @cindex options, -fintrin-case-lower
2026 @item -fintrin-case-lower
2027 @cindex -fintrin-case-any option
2028 @cindex options, -fintrin-case-any
2029 @item -fintrin-case-any
2030 Specify expected case for intrinsic names.
2031 @samp{-fintrin-case-lower} is the default.
2032
2033 @cindex -fmatch-case-initcap option
2034 @cindex options, -fmatch-case-initcap
2035 @item -fmatch-case-initcap
2036 @cindex -fmatch-case-upper option
2037 @cindex options, -fmatch-case-upper
2038 @item -fmatch-case-upper
2039 @cindex -fmatch-case-lower option
2040 @cindex options, -fmatch-case-lower
2041 @item -fmatch-case-lower
2042 @cindex -fmatch-case-any option
2043 @cindex options, -fmatch-case-any
2044 @item -fmatch-case-any
2045 Specify expected case for keywords.
2046 @samp{-fmatch-case-lower} is the default.
2047
2048 @cindex -fsource-case-upper option
2049 @cindex options, -fsource-case-upper
2050 @item -fsource-case-upper
2051 @cindex -fsource-case-lower option
2052 @cindex options, -fsource-case-lower
2053 @item -fsource-case-lower
2054 @cindex -fsource-case-preserve option
2055 @cindex options, -fsource-case-preserve
2056 @item -fsource-case-preserve
2057 Specify whether source text other than character and Hollerith constants
2058 is to be translated to uppercase, to lowercase, or preserved as is.
2059 @samp{-fsource-case-lower} is the default.
2060
2061 @cindex -fsymbol-case-initcap option
2062 @cindex options, -fsymbol-case-initcap
2063 @item -fsymbol-case-initcap
2064 @cindex -fsymbol-case-upper option
2065 @cindex options, -fsymbol-case-upper
2066 @item -fsymbol-case-upper
2067 @cindex -fsymbol-case-lower option
2068 @cindex options, -fsymbol-case-lower
2069 @item -fsymbol-case-lower
2070 @cindex -fsymbol-case-any option
2071 @cindex options, -fsymbol-case-any
2072 @item -fsymbol-case-any
2073 Specify valid cases for user-defined symbol names.
2074 @samp{-fsymbol-case-any} is the default.
2075
2076 @cindex -fcase-strict-upper option
2077 @cindex options, -fcase-strict-upper
2078 @item -fcase-strict-upper
2079 Same as @samp{-fintrin-case-upper -fmatch-case-upper -fsource-case-preserve
2080 -fsymbol-case-upper}.
2081 (Requires all pertinent source to be in uppercase.)
2082
2083 @cindex -fcase-strict-lower option
2084 @cindex options, -fcase-strict-lower
2085 @item -fcase-strict-lower
2086 Same as @samp{-fintrin-case-lower -fmatch-case-lower -fsource-case-preserve
2087 -fsymbol-case-lower}.
2088 (Requires all pertinent source to be in lowercase.)
2089
2090 @cindex -fcase-initcap option
2091 @cindex options, -fcase-initcap
2092 @item -fcase-initcap
2093 Same as @samp{-fintrin-case-initcap -fmatch-case-initcap -fsource-case-preserve
2094 -fsymbol-case-initcap}.
2095 (Requires all pertinent source to be in initial capitals,
2096 as in @samp{Print *,SqRt(Value)}.)
2097
2098 @cindex -fcase-upper option
2099 @cindex options, -fcase-upper
2100 @item -fcase-upper
2101 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-upper
2102 -fsymbol-case-any}.
2103 (Maps all pertinent source to uppercase.)
2104
2105 @cindex -fcase-lower option
2106 @cindex options, -fcase-lower
2107 @item -fcase-lower
2108 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-lower
2109 -fsymbol-case-any}.
2110 (Maps all pertinent source to lowercase.)
2111
2112 @cindex -fcase-preserve option
2113 @cindex options, -fcase-preserve
2114 @item -fcase-preserve
2115 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-preserve
2116 -fsymbol-case-any}.
2117 (Preserves all case in user-defined symbols,
2118 while allowing any-case matching of intrinsics and keywords.
2119 For example, @samp{call Foo(i,I)} would pass two @emph{different}
2120 variables named @samp{i} and @samp{I} to a procedure named @samp{Foo}.)
2121
2122 @cindex -fbadu77-intrinsics-delete option
2123 @cindex options, -fbadu77-intrinsics-delete
2124 @item -fbadu77-intrinsics-delete
2125 @cindex -fbadu77-intrinsics-hide option
2126 @cindex options, -fbadu77-intrinsics-hide
2127 @item -fbadu77-intrinsics-hide
2128 @cindex -fbadu77-intrinsics-disable option
2129 @cindex options, -fbadu77-intrinsics-disable
2130 @item -fbadu77-intrinsics-disable
2131 @cindex -fbadu77-intrinsics-enable option
2132 @cindex options, -fbadu77-intrinsics-enable
2133 @item -fbadu77-intrinsics-enable
2134 @cindex @code{badu77} intrinsics
2135 @cindex intrinsics, @code{badu77}
2136 Specify status of UNIX intrinsics having inappropriate forms.
2137 @samp{-fbadu77-intrinsics-enable} is the default.
2138 @xref{Intrinsic Groups}.
2139
2140 @cindex -ff2c-intrinsics-delete option
2141 @cindex options, -ff2c-intrinsics-delete
2142 @item -ff2c-intrinsics-delete
2143 @cindex -ff2c-intrinsics-hide option
2144 @cindex options, -ff2c-intrinsics-hide
2145 @item -ff2c-intrinsics-hide
2146 @cindex -ff2c-intrinsics-disable option
2147 @cindex options, -ff2c-intrinsics-disable
2148 @item -ff2c-intrinsics-disable
2149 @cindex -ff2c-intrinsics-enable option
2150 @cindex options, -ff2c-intrinsics-enable
2151 @item -ff2c-intrinsics-enable
2152 @cindex @code{f2c} intrinsics
2153 @cindex intrinsics, @code{f2c}
2154 Specify status of f2c-specific intrinsics.
2155 @samp{-ff2c-intrinsics-enable} is the default.
2156 @xref{Intrinsic Groups}.
2157
2158 @cindex -ff90-intrinsics-delete option
2159 @cindex options, -ff90-intrinsics-delete
2160 @item -ff90-intrinsics-delete
2161 @cindex -ff90-intrinsics-hide option
2162 @cindex options, -ff90-intrinsics-hide
2163 @item -ff90-intrinsics-hide
2164 @cindex -ff90-intrinsics-disable option
2165 @cindex options, -ff90-intrinsics-disable
2166 @item -ff90-intrinsics-disable
2167 @cindex -ff90-intrinsics-enable option
2168 @cindex options, -ff90-intrinsics-enable
2169 @item -ff90-intrinsics-enable
2170 @cindex Fortran 90, intrinsics
2171 @cindex intrinsics, Fortran 90
2172 Specify status of F90-specific intrinsics.
2173 @samp{-ff90-intrinsics-enable} is the default.
2174 @xref{Intrinsic Groups}.
2175
2176 @cindex -fgnu-intrinsics-delete option
2177 @cindex options, -fgnu-intrinsics-delete
2178 @item -fgnu-intrinsics-delete
2179 @cindex -fgnu-intrinsics-hide option
2180 @cindex options, -fgnu-intrinsics-hide
2181 @item -fgnu-intrinsics-hide
2182 @cindex -fgnu-intrinsics-disable option
2183 @cindex options, -fgnu-intrinsics-disable
2184 @item -fgnu-intrinsics-disable
2185 @cindex -fgnu-intrinsics-enable option
2186 @cindex options, -fgnu-intrinsics-enable
2187 @item -fgnu-intrinsics-enable
2188 @cindex Digital Fortran features
2189 @cindex @code{COMPLEX} intrinsics
2190 @cindex intrinsics, @code{COMPLEX}
2191 Specify status of Digital's COMPLEX-related intrinsics.
2192 @samp{-fgnu-intrinsics-enable} is the default.
2193 @xref{Intrinsic Groups}.
2194
2195 @cindex -fmil-intrinsics-delete option
2196 @cindex options, -fmil-intrinsics-delete
2197 @item -fmil-intrinsics-delete
2198 @cindex -fmil-intrinsics-hide option
2199 @cindex options, -fmil-intrinsics-hide
2200 @item -fmil-intrinsics-hide
2201 @cindex -fmil-intrinsics-disable option
2202 @cindex options, -fmil-intrinsics-disable
2203 @item -fmil-intrinsics-disable
2204 @cindex -fmil-intrinsics-enable option
2205 @cindex options, -fmil-intrinsics-enable
2206 @item -fmil-intrinsics-enable
2207 @cindex MIL-STD 1753
2208 @cindex intrinsics, MIL-STD 1753
2209 Specify status of MIL-STD-1753-specific intrinsics.
2210 @samp{-fmil-intrinsics-enable} is the default.
2211 @xref{Intrinsic Groups}.
2212
2213 @cindex -funix-intrinsics-delete option
2214 @cindex options, -funix-intrinsics-delete
2215 @item -funix-intrinsics-delete
2216 @cindex -funix-intrinsics-hide option
2217 @cindex options, -funix-intrinsics-hide
2218 @item -funix-intrinsics-hide
2219 @cindex -funix-intrinsics-disable option
2220 @cindex options, -funix-intrinsics-disable
2221 @item -funix-intrinsics-disable
2222 @cindex -funix-intrinsics-enable option
2223 @cindex options, -funix-intrinsics-enable
2224 @item -funix-intrinsics-enable
2225 @cindex UNIX intrinsics
2226 @cindex intrinsics, UNIX
2227 Specify status of UNIX intrinsics.
2228 @samp{-funix-intrinsics-enable} is the default.
2229 @xref{Intrinsic Groups}.
2230
2231 @cindex -fvxt-intrinsics-delete option
2232 @cindex options, -fvxt-intrinsics-delete
2233 @item -fvxt-intrinsics-delete
2234 @cindex -fvxt-intrinsics-hide option
2235 @cindex options, -fvxt-intrinsics-hide
2236 @item -fvxt-intrinsics-hide
2237 @cindex -fvxt-intrinsics-disable option
2238 @cindex options, -fvxt-intrinsics-disable
2239 @item -fvxt-intrinsics-disable
2240 @cindex -fvxt-intrinsics-enable option
2241 @cindex options, -fvxt-intrinsics-enable
2242 @item -fvxt-intrinsics-enable
2243 @cindex VXT intrinsics
2244 @cindex intrinsics, VXT
2245 Specify status of VXT intrinsics.
2246 @samp{-fvxt-intrinsics-enable} is the default.
2247 @xref{Intrinsic Groups}.
2248
2249 @cindex -ffixed-line-length-@var{n} option
2250 @cindex options, -ffixed-line-length-@var{n}
2251 @item -ffixed-line-length-@var{n}
2252 @cindex source file format
2253 @cindex lines, length
2254 @cindex length of source lines
2255 @cindex fixed form
2256 @cindex limits, lengths of source lines
2257 Set column after which characters are ignored in typical fixed-form
2258 lines in the source file, and through which spaces are assumed (as
2259 if padded to that length) after the ends of short fixed-form lines.
2260
2261 @cindex card image
2262 @cindex extended-source option
2263 Popular values for @var{n} include 72 (the
2264 standard and the default), 80 (card image), and 132 (corresponds
2265 to ``extended-source'' options in some popular compilers).
2266 @var{n} may be @samp{none}, meaning that the entire line is meaningful
2267 and that continued character constants never have implicit spaces appended
2268 to them to fill out the line.
2269 @samp{-ffixed-line-length-0} means the same thing as
2270 @samp{-ffixed-line-length-none}.
2271
2272 @xref{Source Form}, for more information.
2273 @end table
2274
2275 @node Warning Options
2276 @section Options to Request or Suppress Warnings
2277 @cindex options, warnings
2278 @cindex warnings, suppressing
2279 @cindex messages, warning
2280 @cindex suppressing warnings
2281
2282 Warnings are diagnostic messages that report constructions which
2283 are not inherently erroneous but which are risky or suggest there
2284 might have been an error.
2285
2286 You can request many specific warnings with options beginning @samp{-W},
2287 for example @samp{-Wimplicit} to request warnings on implicit
2288 declarations.  Each of these specific warning options also has a
2289 negative form beginning @samp{-Wno-} to turn off warnings;
2290 for example, @samp{-Wno-implicit}.  This manual lists only one of the
2291 two forms, whichever is not the default.
2292
2293 These options control the amount and kinds of warnings produced by GNU
2294 Fortran:
2295
2296 @table @code
2297 @cindex syntax checking
2298 @cindex -fsyntax-only option
2299 @cindex options, -fsyntax-only
2300 @item -fsyntax-only
2301 Check the code for syntax errors, but don't do anything beyond that.
2302
2303 @cindex -pedantic option
2304 @cindex options, -pedantic
2305 @item -pedantic
2306 Issue warnings for uses of extensions to ANSI FORTRAN 77.
2307 @samp{-pedantic} also applies to C-language constructs where they
2308 occur in GNU Fortran source files, such as use of @samp{\e} in a
2309 character constant within a directive like @samp{#include}.
2310
2311 Valid ANSI FORTRAN 77 programs should compile properly with or without
2312 this option.
2313 However, without this option, certain GNU extensions and traditional
2314 Fortran features are supported as well.
2315 With this option, many of them are rejected.
2316
2317 Some users try to use @samp{-pedantic} to check programs for strict ANSI
2318 conformance.
2319 They soon find that it does not do quite what they want---it finds some
2320 non-ANSI practices, but not all.
2321 However, improvements to @code{g77} in this area are welcome.
2322
2323 @cindex -pedantic-errors option
2324 @cindex options, -pedantic-errors
2325 @item -pedantic-errors
2326 Like @samp{-pedantic}, except that errors are produced rather than
2327 warnings.
2328
2329 @cindex -fpedantic option
2330 @cindex options, -fpedantic
2331 @item -fpedantic
2332 Like @samp{-pedantic}, but applies only to Fortran constructs.
2333
2334 @cindex -w option
2335 @cindex options, -w
2336 @item -w
2337 Inhibit all warning messages.
2338
2339 @cindex -Wno-globals option
2340 @cindex options, -Wno-globals
2341 @item -Wno-globals
2342 @cindex global names, warning
2343 @cindex warnings, global names
2344 Inhibit warnings about use of a name as both a global name
2345 (a subroutine, function, or block data program unit, or a
2346 common block) and implicitly as the name of an intrinsic
2347 in a source file.
2348
2349 Also inhibit warnings about inconsistent invocations and/or
2350 definitions of global procedures (function and subroutines).
2351 Such inconsistencies include different numbers of arguments
2352 and different types of arguments.
2353
2354 @cindex -Wimplicit option
2355 @cindex options, -Wimplicit
2356 @item -Wimplicit
2357 @cindex implicit declaration, warning
2358 @cindex warnings, implicit declaration
2359 @cindex -u option
2360 @cindex /WARNINGS=DECLARATIONS switch
2361 @cindex IMPLICIT NONE, similar effect
2362 @cindex effecting IMPLICIT NONE
2363 Warn whenever a variable, array, or function is implicitly
2364 declared.
2365 Has an effect similar to using the @code{IMPLICIT NONE} statement
2366 in every program unit.
2367 (Some Fortran compilers provide this feature by an option
2368 named @samp{-u} or @samp{/WARNINGS=DECLARATIONS}.)
2369
2370 @cindex -Wunused option
2371 @cindex options, -Wunused
2372 @item -Wunused
2373 @cindex unused variables
2374 @cindex variables, unused
2375 Warn whenever a variable is unused aside from its declaration.
2376
2377 @cindex -Wuninitialized option
2378 @cindex options, -Wuninitialized
2379 @item -Wuninitialized
2380 @cindex uninitialized variables
2381 @cindex variables, uninitialized
2382 Warn whenever an automatic variable is used without first being initialized.
2383
2384 These warnings are possible only in optimizing compilation,
2385 because they require data-flow information that is computed only
2386 when optimizing.  If you don't specify @samp{-O}, you simply won't
2387 get these warnings.
2388
2389 These warnings occur only for variables that are candidates for
2390 register allocation.  Therefore, they do not occur for a variable
2391 @c that is declared @code{VOLATILE}, or
2392 whose address is taken, or whose size
2393 is other than 1, 2, 4 or 8 bytes.  Also, they do not occur for
2394 arrays, even when they are in registers.
2395
2396 Note that there might be no warning about a variable that is used only
2397 to compute a value that itself is never used, because such
2398 computations may be deleted by data-flow analysis before the warnings
2399 are printed.
2400
2401 These warnings are made optional because GNU Fortran is not smart
2402 enough to see all the reasons why the code might be correct
2403 despite appearing to have an error.  Here is one example of how
2404 this can happen:
2405
2406 @example
2407 SUBROUTINE DISPAT(J)
2408 IF (J.EQ.1) I=1
2409 IF (J.EQ.2) I=4
2410 IF (J.EQ.3) I=5
2411 CALL FOO(I)
2412 END
2413 @end example
2414
2415 @noindent
2416 If the value of @code{J} is always 1, 2 or 3, then @code{I} is
2417 always initialized, but GNU Fortran doesn't know this.  Here is
2418 another common case:
2419
2420 @example
2421 SUBROUTINE MAYBE(FLAG)
2422 LOGICAL FLAG
2423 IF (FLAG) VALUE = 9.4
2424 @dots{}
2425 IF (FLAG) PRINT *, VALUE
2426 END
2427 @end example
2428
2429 @noindent
2430 This has no bug because @code{VALUE} is used only if it is set.
2431
2432 @cindex -Wall option
2433 @cindex options, -Wall
2434 @item -Wall
2435 @cindex all warnings
2436 @cindex warnings, all
2437 The @samp{-Wunused} and @samp{-Wuninitialized} options combined.
2438 These are all the
2439 options which pertain to usage that we recommend avoiding and that we
2440 believe is easy to avoid.
2441 (As more warnings are added to @code{g77}, some might
2442 be added to the list enabled by @samp{-Wall}.)
2443 @end table
2444
2445 The remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}
2446 because they warn about constructions that we consider reasonable to
2447 use, on occasion, in clean programs.
2448
2449 @table @code
2450 @c @item -W
2451 @c Print extra warning messages for these events:
2452 @c
2453 @c @itemize @bullet
2454 @c @item
2455 @c If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused
2456 @c arguments.
2457 @c
2458 @c @end itemize
2459 @c
2460 @cindex -Wsurprising option
2461 @cindex options, -Wsurprising
2462 @item -Wsurprising
2463 Warn about ``suspicious'' constructs that are interpreted
2464 by the compiler in a way that might well be surprising to
2465 someone reading the code.
2466 These differences can result in subtle, compiler-dependent
2467 (even machine-dependent) behavioral differences.
2468 The constructs warned about include:
2469
2470 @itemize @bullet
2471 @item
2472 Expressions having two arithmetic operators in a row, such
2473 as @samp{X*-Y}.
2474 Such a construct is nonstandard, and can produce
2475 unexpected results in more complicated situations such
2476 as @samp{X**-Y*Z}.
2477 @code{g77}, along with many other compilers, interprets
2478 this example differently than many programmers, and a few
2479 other compilers.
2480 Specifically, @code{g77} interprets @samp{X**-Y*Z} as
2481 @samp{(X**(-Y))*Z}, while others might think it should
2482 be interpreted as @samp{X**(-(Y*Z))}.
2483
2484 A revealing example is the constant expression @samp{2**-2*1.},
2485 which @code{g77} evaluates to .25, while others might evaluate
2486 it to 0., the difference resulting from the way precedence affects
2487 type promotion.
2488
2489 (The @samp{-fpedantic} option also warns about expressions
2490 having two arithmetic operators in a row.)
2491
2492 @item
2493 Expressions with a unary minus followed by an operand and then
2494 a binary operator other than plus or minus.
2495 For example, @samp{-2**2} produces a warning, because
2496 the precedence is @samp{-(2**2)}, yielding -4, not
2497 @samp{(-2)**2}, which yields 4, and which might represent
2498 what a programmer expects.
2499
2500 An example of an expression producing different results
2501 in a surprising way is @samp{-I*S}, where @var{I} holds
2502 the value @samp{-2147483648} and @var{S} holds @samp{0.5}.
2503 On many systems, negating @var{I} results in the same
2504 value, not a positive number, because it is already the
2505 lower bound of what an @code{INTEGER(KIND=1)} variable can hold.
2506 So, the expression evaluates to a positive number, while
2507 the ``expected'' interpretation, @samp{(-I)*S}, would
2508 evaluate to a negative number.
2509
2510 Even cases such as @samp{-I*J} produce warnings,
2511 even though, in most configurations and situations,
2512 there is no computational difference between the
2513 results of the two interpretations---the purpose
2514 of this warning is to warn about differing interpretations
2515 and encourage a better style of coding, not to identify
2516 only those places where bugs might exist in the user's
2517 code.
2518
2519 @cindex DO statement
2520 @cindex statements, DO
2521 @item
2522 @code{DO} loops with @code{DO} variables that are not
2523 of integral type---that is, using @code{REAL}
2524 variables as loop control variables.
2525 Although such loops can be written to work in the
2526 ``obvious'' way, the way @code{g77} is required by the
2527 Fortran standard to interpret such code is likely to
2528 be quite different from the way many programmers expect.
2529 (This is true of all @code{DO} loops, but the differences
2530 are pronounced for non-integral loop control variables.)
2531
2532 @xref{Loops}, for more information.
2533 @end itemize
2534
2535 @cindex -Werror option
2536 @cindex options, -Werror
2537 @item -Werror
2538 Make all warnings into errors.
2539
2540 @cindex -W option
2541 @cindex options, -W
2542 @item -W
2543 @cindex extra warnings
2544 @cindex warnings, extra
2545 Turns on ``extra warnings'' and, if optimization is specified
2546 via @samp{-O}, the @samp{-Wuninitialized} option.
2547 (This might change in future versions of @code{g77}.)
2548
2549 ``Extra warnings'' are issued for:
2550
2551 @itemize @bullet
2552 @item
2553 @cindex unused parameters
2554 @cindex parameters, unused
2555 @cindex unused arguments
2556 @cindex arguments, unused
2557 @cindex unused dummies
2558 @cindex dummies, unused
2559 Unused parameters to a procedure (when @samp{-Wunused} also is
2560 specified).
2561
2562 @item
2563 @cindex overflow
2564 Overflows involving floating-point constants (not available
2565 for certain configurations).
2566 @end itemize
2567 @end table
2568
2569 @xref{Warning Options,,Options to Request or Suppress Warnings,
2570 gcc,Using and Porting GNU CC}, for information on more options offered
2571 by the GBE shared by @code{g77}, @code{gcc}, and other GNU compilers.
2572
2573 Some of these have no effect when compiling programs written in Fortran:
2574
2575 @table @code
2576 @cindex -Wcomment option
2577 @cindex options, -Wcomment
2578 @item -Wcomment
2579 @cindex -Wformat option
2580 @cindex options, -Wformat
2581 @item -Wformat
2582 @cindex -Wparentheses option
2583 @cindex options, -Wparentheses
2584 @item -Wparentheses
2585 @cindex -Wswitch option
2586 @cindex options, -Wswitch
2587 @item -Wswitch
2588 @cindex -Wtraditional option
2589 @cindex options, -Wtraditional
2590 @item -Wtraditional
2591 @cindex -Wshadow option
2592 @cindex options, -Wshadow
2593 @item -Wshadow
2594 @cindex -Wid-clash-@var{len} option
2595 @cindex options, -Wid-clash-@var{len}
2596 @item -Wid-clash-@var{len}
2597 @cindex -Wlarger-than-@var{len} option
2598 @cindex options, -Wlarger-than-@var{len}
2599 @item -Wlarger-than-@var{len}
2600 @cindex -Wconversion option
2601 @cindex options, -Wconversion
2602 @item -Wconversion
2603 @cindex -Waggregate-return option
2604 @cindex options, -Waggregate-return
2605 @item -Waggregate-return
2606 @cindex -Wredundant-decls option
2607 @cindex options, -Wredundant-decls
2608 @item -Wredundant-decls
2609 @cindex unsupported warnings
2610 @cindex warnings, unsupported
2611 These options all could have some relevant meaning for
2612 GNU Fortran programs, but are not yet supported.
2613 @end table
2614
2615 @node Debugging Options
2616 @section Options for Debugging Your Program or GNU Fortran
2617 @cindex options, debugging
2618 @cindex debugging information options
2619
2620 GNU Fortran has various special options that are used for debugging
2621 either your program or @code{g77}.
2622
2623 @table @code
2624 @cindex -g option
2625 @cindex options, -g
2626 @item -g
2627 Produce debugging information in the operating system's native format
2628 (stabs, COFF, XCOFF, or DWARF).  GDB can work with this debugging
2629 information.
2630 @end table
2631
2632 @xref{Debugging Options,,Options for Debugging Your Program or GNU CC,
2633 gcc,Using and Porting GNU CC}, for more information on debugging options.
2634
2635 @node Optimize Options
2636 @section Options That Control Optimization
2637 @cindex optimize options
2638 @cindex options, optimization
2639
2640 Most Fortran users will want to use no optimization when
2641 developing and testing programs, and use @samp{-O} or @samp{-O2} when
2642 compiling programs for late-cycle testing and for production use.
2643 However, note that certain diagnostics---such as for uninitialized
2644 variables---depend on the flow analysis done by @samp{-O}, i.e.@: you
2645 must use @samp{-O} or @samp{-O2} to get such diagnostics.
2646
2647 The following flags have particular applicability when
2648 compiling Fortran programs:
2649
2650 @table @code
2651 @cindex -malign-double option
2652 @cindex options, -malign-double
2653 @item -malign-double
2654 (Intel x86 architecture only.)
2655
2656 Noticeably improves performance of @code{g77} programs making
2657 heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data
2658 on some systems.
2659 In particular, systems using Pentium, Pentium Pro, 586, and
2660 686 implementations
2661 of the i386 architecture execute programs faster when
2662 @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data are
2663 aligned on 64-bit boundaries
2664 in memory.
2665
2666 This option can, at least, make benchmark results more consistent
2667 across various system configurations, versions of the program,
2668 and data sets.
2669
2670 @emph{Note:} The warning in the @code{gcc} documentation about
2671 this option does not apply, generally speaking, to Fortran
2672 code compiled by @code{g77}.
2673
2674 @xref{Aligned Data}, for more information on alignment issues.
2675
2676 @emph{Also also note:} The negative form of @samp{-malign-double}
2677 is @samp{-mno-align-double}, not @samp{-benign-double}.
2678
2679 @cindex -ffloat-store option
2680 @cindex options, -ffloat-store
2681 @item -ffloat-store
2682 @cindex IEEE 754 conformance
2683 @cindex conformance, IEEE 754
2684 @cindex floating-point, precision
2685 Might help a Fortran program that depends on exact IEEE conformance on
2686 some machines, but might slow down a program that doesn't.
2687
2688 This option is effective when the floating-point unit is set to work in
2689 IEEE 854 `extended precision'---as it typically is on x86 and m68k GNU
2690 systems---rather than IEEE 754 double precision.  @samp{-ffloat-store}
2691 tries to remove the extra precision by spilling data from floating-point
2692 registers into memory and this typically involves a big performance
2693 hit.  However, it doesn't affect intermediate results, so that it is
2694 only partially effective.  `Excess precision' is avoided in code like:
2695 @smallexample
2696 a = b + c
2697 d = a * e
2698 @end smallexample
2699 but not in code like:
2700 @smallexample
2701       d = (b + c) * e
2702 @end smallexample
2703
2704 For another, potentially better, way of controlling the precision,
2705 see @ref{Floating-point precision}.
2706
2707 @cindex -fforce-mem option
2708 @cindex options, -fforce-mem
2709 @item -fforce-mem
2710 @cindex -fforce-addr option
2711 @cindex options, -fforce-addr
2712 @item -fforce-addr
2713 @cindex loops, speeding up
2714 @cindex speed, of loops
2715 Might improve optimization of loops.
2716
2717 @cindex -fno-inline option
2718 @cindex options, -fno-inline
2719 @item -fno-inline
2720 @cindex in-line code
2721 @cindex compilation, in-line
2722 @c DL: Only relevant for -O3?
2723 Don't compile statement functions inline.
2724 Might reduce the size of a program unit---which might be at
2725 expense of some speed (though it should compile faster).
2726 Note that if you are not optimizing, no functions can be expanded inline.
2727
2728 @cindex -ffast-math option
2729 @cindex options, -ffast-math
2730 @item -ffast-math
2731 @cindex IEEE 754 conformance
2732 @cindex conformance, IEEE 754
2733 Might allow some programs designed to not be too dependent
2734 on IEEE behavior for floating-point to run faster, or die trying.
2735 Sets @samp{-funsafe-math-optimizations}, and
2736 @samp{-fno-trapping-math}.
2737
2738 @cindex -funsafe-math-optimizations option
2739 @cindex options, -funsafe-math-optimizations
2740 @item -funsafe-math-optimizations
2741 Allow optimizations that may be give incorrect results
2742 for certain IEEE inputs.
2743
2744 @cindex -fno-trapping-math option
2745 @cindex options, -fno-trapping-math
2746 @item -fno-trapping-math
2747 Allow the compiler to assume that floating-point arithmetic
2748 will not generate traps on any inputs.  This is useful, for
2749 example, when running a program using IEEE "non-stop"
2750 floating-point arithmetic.
2751
2752 @cindex -fstrength-reduce option
2753 @cindex options, -fstrength-reduce
2754 @item -fstrength-reduce
2755 @cindex loops, speeding up
2756 @cindex speed, of loops
2757 @c DL: normally defaulted?
2758 Might make some loops run faster.
2759
2760 @cindex -frerun-cse-after-loop option
2761 @cindex options, -frerun-cse-after-loop
2762 @item -frerun-cse-after-loop
2763 @cindex -fexpensive-optimizations option
2764 @cindex options, -fexpensive-optimizations
2765 @c DL: This is -O2?
2766 @item -fexpensive-optimizations
2767 @cindex -fdelayed-branch option
2768 @cindex options, -fdelayed-branch
2769 @item -fdelayed-branch
2770 @cindex -fschedule-insns option
2771 @cindex options, -fschedule-insns
2772 @item -fschedule-insns
2773 @cindex -fschedule-insns2 option
2774 @cindex options, -fschedule-insns2
2775 @item -fschedule-insns2
2776 @cindex -fcaller-saves option
2777 @cindex options, -fcaller-saves
2778 @item -fcaller-saves
2779 Might improve performance on some code.
2780
2781 @cindex -funroll-loops option
2782 @cindex options, -funroll-loops
2783 @item -funroll-loops
2784 @cindex loops, unrolling
2785 @cindex unrolling loops
2786 @cindex loops, optimizing
2787 @cindex indexed (iterative) @code{DO}
2788 @cindex iterative @code{DO}
2789 @c DL: fixme: Craig doesn't like `indexed' but f95 doesn't seem to
2790 @c provide a suitable term
2791 @c CB: I've decided on `iterative', for the time being, and changed
2792 @c my previous, rather bizarre, use of `imperative' to that
2793 @c (though `precomputed-trip' would be a more precise adjective)
2794 Typically improves performance on code using iterative @code{DO} loops by
2795 unrolling them and is probably generally appropriate for Fortran, though
2796 it is not turned on at any optimization level.
2797 Note that outer loop unrolling isn't done specifically; decisions about
2798 whether to unroll a loop are made on the basis of its instruction count.
2799
2800 @c DL: Fixme: This should obviously go somewhere else...
2801 Also, no `loop discovery'@footnote{@dfn{loop discovery} refers to the
2802 process by which a compiler, or indeed any reader of a program,
2803 determines which portions of the program are more likely to be executed
2804 repeatedly as it is being run.  Such discovery typically is done early
2805 when compiling using optimization techniques, so the ``discovered''
2806 loops get more attention---and more run-time resources, such as
2807 registers---from the compiler.  It is easy to ``discover'' loops that are
2808 constructed out of looping constructs in the language
2809 (such as Fortran's @code{DO}).  For some programs, ``discovering'' loops
2810 constructed out of lower-level constructs (such as @code{IF} and
2811 @code{GOTO}) can lead to generation of more optimal code
2812 than otherwise.} is done, so only loops written with @code{DO}
2813 benefit from loop optimizations, including---but not limited
2814 to---unrolling.  Loops written with @code{IF} and @code{GOTO} are not
2815 currently recognized as such.  This option unrolls only iterative
2816 @code{DO} loops, not @code{DO WHILE} loops.
2817
2818 @cindex -funroll-all-loops option
2819 @cindex options, -funroll-all-loops
2820 @cindex DO WHILE
2821 @item -funroll-all-loops
2822 @c DL: Check my understanding of -funroll-all-loops v. -funroll-loops is correct.
2823 Probably improves performance on code using @code{DO WHILE} loops by
2824 unrolling them in addition to iterative @code{DO} loops.  In the absence
2825 of @code{DO WHILE}, this option is equivalent to @samp{-funroll-loops}
2826 but possibly slower.
2827
2828 @item -fno-move-all-movables
2829 @cindex -fno-move-all-movables option
2830 @cindex options, -fno-move-all-movables
2831 @item -fno-reduce-all-givs
2832 @cindex -fno-reduce-all-givs option
2833 @cindex options, -fno-reduce-all-givs
2834 @item -fno-rerun-loop-opt
2835 @cindex -fno-rerun-loop-opt option
2836 @cindex options, -fno-rerun-loop-opt
2837 @emph{Version info:}
2838 These options are not supported by
2839 versions of @code{g77} based on @code{gcc} version 2.8.
2840
2841 Each of these might improve performance on some code.
2842
2843 Analysis of Fortran code optimization and the resulting
2844 optimizations triggered by the above options were
2845 contributed by Toon Moene (@email{toon@@moene.indiv.nluug.nl}).
2846
2847 These three options are intended to be removed someday, once
2848 they have helped determine the efficacy of various
2849 approaches to improving the performance of Fortran code.
2850
2851 Please let us know how use of these options affects
2852 the performance of your production code.
2853 We're particularly interested in code that runs faster
2854 when these options are @emph{disabled}, and in
2855 non-Fortran code that benefits when they are
2856 @emph{enabled} via the above @code{gcc} command-line options.
2857 @end table
2858
2859 @xref{Optimize Options,,Options That Control Optimization,
2860 gcc,Using and Porting GNU CC}, for more information on options
2861 to optimize the generated machine code.
2862
2863 @node Preprocessor Options
2864 @section Options Controlling the Preprocessor
2865 @cindex preprocessor options
2866 @cindex options, preprocessor
2867 @cindex cpp program
2868 @cindex programs, cpp
2869
2870 These options control the C preprocessor, which is run on each C source
2871 file before actual compilation.
2872
2873 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
2874 gcc,Using and Porting GNU CC}, for information on C preprocessor options.
2875
2876 @cindex INCLUDE directive
2877 @cindex directive, INCLUDE
2878 Some of these options also affect how @code{g77} processes the
2879 @code{INCLUDE} directive.
2880 Since this directive is processed even when preprocessing
2881 is not requested, it is not described in this section.
2882 @xref{Directory Options,,Options for Directory Search}, for
2883 information on how @code{g77} processes the @code{INCLUDE} directive.
2884
2885 However, the @code{INCLUDE} directive does not apply
2886 preprocessing to the contents of the included file itself.
2887
2888 Therefore, any file that contains preprocessor directives
2889 (such as @code{#include}, @code{#define}, and @code{#if})
2890 must be included via the @code{#include} directive, not
2891 via the @code{INCLUDE} directive.
2892 Therefore, any file containing preprocessor directives,
2893 if included, is necessarily included by a file that itself
2894 contains preprocessor directives.
2895
2896 @node Directory Options
2897 @section Options for Directory Search
2898 @cindex directory, options
2899 @cindex options, directory search
2900 @cindex search path
2901
2902 These options affect how the @code{cpp} preprocessor searches
2903 for files specified via the @code{#include} directive.
2904 Therefore, when compiling Fortran programs, they are meaningful
2905 when the preprocessor is used.
2906
2907 @cindex INCLUDE directive
2908 @cindex directive, INCLUDE
2909 Some of these options also affect how @code{g77} searches
2910 for files specified via the @code{INCLUDE} directive,
2911 although files included by that directive are not,
2912 themselves, preprocessed.
2913 These options are:
2914
2915 @table @code
2916 @cindex -I- option
2917 @cindex options, -I-
2918 @item -I-
2919 @cindex -Idir option
2920 @cindex options, -Idir
2921 @item -I@var{dir}
2922 @cindex directory, search paths for inclusion
2923 @cindex inclusion, directory search paths for
2924 @cindex search paths, for included files
2925 @cindex paths, search
2926 These affect interpretation of the @code{INCLUDE} directive
2927 (as well as of the @code{#include} directive of the @code{cpp}
2928 preprocessor).
2929
2930 Note that @samp{-I@var{dir}} must be specified @emph{without} any
2931 spaces between @samp{-I} and the directory name---that is,
2932 @samp{-Ifoo/bar} is valid, but @samp{-I foo/bar}
2933 is rejected by the @code{g77} compiler (though the preprocessor supports
2934 the latter form).
2935 @c this is due to toplev.c's inflexible option processing
2936 Also note that the general behavior of @samp{-I} and
2937 @code{INCLUDE} is pretty much the same as of @samp{-I} with
2938 @code{#include} in the @code{cpp} preprocessor, with regard to
2939 looking for @file{header.gcc} files and other such things.
2940
2941 @xref{Directory Options,,Options for Directory Search,
2942 gcc,Using and Porting GNU CC}, for information on the @samp{-I} option.
2943 @end table
2944
2945 @node Code Gen Options
2946 @section Options for Code Generation Conventions
2947 @cindex code generation, conventions
2948 @cindex options, code generation
2949 @cindex run-time, options
2950
2951 These machine-independent options control the interface conventions
2952 used in code generation.
2953
2954 Most of them have both positive and negative forms; the negative form
2955 of @samp{-ffoo} would be @samp{-fno-foo}.  In the table below, only
2956 one of the forms is listed---the one which is not the default.  You
2957 can figure out the other form by either removing @samp{no-} or adding
2958 it.
2959
2960 @table @code
2961 @cindex -fno-automatic option
2962 @cindex options, -fno-automatic
2963 @item -fno-automatic
2964 @cindex SAVE statement
2965 @cindex statements, SAVE
2966 Treat each program unit as if the @code{SAVE} statement was specified
2967 for every local variable and array referenced in it.
2968 Does not affect common blocks.
2969 (Some Fortran compilers provide this option under
2970 the name @samp{-static}.)
2971
2972 @cindex -finit-local-zero option
2973 @cindex options, -finit-local-zero
2974 @item -finit-local-zero
2975 @cindex DATA statement
2976 @cindex statements, DATA
2977 @cindex initialization, of local variables
2978 @cindex variables, initialization of
2979 @cindex uninitialized variables
2980 @cindex variables, uninitialized
2981 Specify that variables and arrays that are local to a program unit
2982 (not in a common block and not passed as an argument) are to be initialized
2983 to binary zeros.
2984
2985 Since there is a run-time penalty for initialization of variables
2986 that are not given the @code{SAVE} attribute, it might be a
2987 good idea to also use @samp{-fno-automatic} with @samp{-finit-local-zero}.
2988
2989 @cindex -fno-f2c option
2990 @cindex options, -fno-f2c
2991 @item -fno-f2c
2992 @cindex @code{f2c} compatibility
2993 @cindex compatibility, @code{f2c}
2994 Do not generate code designed to be compatible with code generated
2995 by @code{f2c}; use the GNU calling conventions instead.
2996
2997 The @code{f2c} calling conventions require functions that return
2998 type @code{REAL(KIND=1)} to actually return the C type @code{double},
2999 and functions that return type @code{COMPLEX} to return the
3000 values via an extra argument in the calling sequence that points
3001 to where to store the return value.
3002 Under the GNU calling conventions, such functions simply return
3003 their results as they would in GNU C---@code{REAL(KIND=1)} functions
3004 return the C type @code{float}, and @code{COMPLEX} functions
3005 return the GNU C type @code{complex} (or its @code{struct}
3006 equivalent).
3007
3008 This does not affect the generation of code that interfaces with the
3009 @code{libg2c} library.
3010
3011 However, because the @code{libg2c} library uses @code{f2c}
3012 calling conventions, @code{g77} rejects attempts to pass
3013 intrinsics implemented by routines in this library as actual
3014 arguments when @samp{-fno-f2c} is used, to avoid bugs when
3015 they are actually called by code expecting the GNU calling
3016 conventions to work.
3017
3018 For example, @samp{INTRINSIC ABS;CALL FOO(ABS)} is
3019 rejected when @samp{-fno-f2c} is in force.
3020 (Future versions of the @code{g77} run-time library might
3021 offer routines that provide GNU-callable versions of the
3022 routines that implement the @code{f2c}-callable intrinsics
3023 that may be passed as actual arguments, so that
3024 valid programs need not be rejected when @samp{-fno-f2c}
3025 is used.)
3026
3027 @strong{Caution:} If @samp{-fno-f2c} is used when compiling any
3028 source file used in a program, it must be used when compiling
3029 @emph{all} Fortran source files used in that program.
3030
3031 @c seems kinda dumb to tell people about an option they can't use -- jcb
3032 @c then again, we want users building future-compatible libraries with it.
3033 @cindex -ff2c-library option
3034 @cindex options, -ff2c-library
3035 @item -ff2c-library
3036 Specify that use of @code{libg2c} (or the original @code{libf2c})
3037 is required.
3038 This is the default for the current version of @code{g77}.
3039
3040 Currently it is not
3041 valid to specify @samp{-fno-f2c-library}.
3042 This option is provided so users can specify it in shell
3043 scripts that build programs and libraries that require the
3044 @code{libf2c} library, even when being compiled by future
3045 versions of @code{g77} that might otherwise default to
3046 generating code for an incompatible library.
3047
3048 @cindex -fno-underscoring option
3049 @cindex options, -fno-underscoring
3050 @item -fno-underscoring
3051 @cindex underscore
3052 @cindex symbol names, underscores
3053 @cindex transforming symbol names
3054 @cindex symbol names, transforming
3055 Do not transform names of entities specified in the Fortran
3056 source file by appending underscores to them.
3057
3058 With @samp{-funderscoring} in effect, @code{g77} appends two underscores
3059 to names with underscores and one underscore to external names with
3060 no underscores.  (@code{g77} also appends two underscores to internal
3061 names with underscores to avoid naming collisions with external names.
3062 The @samp{-fno-second-underscore} option disables appending of the
3063 second underscore in all cases.)
3064
3065 This is done to ensure compatibility with code produced by many
3066 UNIX Fortran compilers, including @code{f2c}, which perform the
3067 same transformations.
3068
3069 Use of @samp{-fno-underscoring} is not recommended unless you are
3070 experimenting with issues such as integration of (GNU) Fortran into
3071 existing system environments (vis-a-vis existing libraries, tools, and
3072 so on).
3073
3074 For example, with @samp{-funderscoring}, and assuming other defaults like
3075 @samp{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
3076 external functions while @samp{my_var} and @samp{lvar} are local variables,
3077 a statement like
3078
3079 @smallexample
3080 I = J() + MAX_COUNT (MY_VAR, LVAR)
3081 @end smallexample
3082
3083 @noindent
3084 is implemented as something akin to:
3085
3086 @smallexample
3087 i = j_() + max_count__(&my_var__, &lvar);
3088 @end smallexample
3089
3090 With @samp{-fno-underscoring}, the same statement is implemented as:
3091
3092 @smallexample
3093 i = j() + max_count(&my_var, &lvar);
3094 @end smallexample
3095
3096 Use of @samp{-fno-underscoring} allows direct specification of
3097 user-defined names while debugging and when interfacing @code{g77}-compiled
3098 code with other languages.
3099
3100 Note that just because the names match does @emph{not} mean that the
3101 interface implemented by @code{g77} for an external name matches the
3102 interface implemented by some other language for that same name.
3103 That is, getting code produced by @code{g77} to link to code produced
3104 by some other compiler using this or any other method can be only a
3105 small part of the overall solution---getting the code generated by
3106 both compilers to agree on issues other than naming can require
3107 significant effort, and, unlike naming disagreements, linkers normally
3108 cannot detect disagreements in these other areas.
3109
3110 Also, note that with @samp{-fno-underscoring}, the lack of appended
3111 underscores introduces the very real possibility that a user-defined
3112 external name will conflict with a name in a system library, which
3113 could make finding unresolved-reference bugs quite difficult in some
3114 cases---they might occur at program run time, and show up only as
3115 buggy behavior at run time.
3116
3117 In future versions of @code{g77}, we hope to improve naming and linking
3118 issues so that debugging always involves using the names as they appear
3119 in the source, even if the names as seen by the linker are mangled to
3120 prevent accidental linking between procedures with incompatible
3121 interfaces.
3122
3123 @cindex -fno-second-underscore option
3124 @cindex options, -fno-second-underscore
3125 @item -fno-second-underscore
3126 @cindex underscore
3127 @cindex symbol names, underscores
3128 @cindex transforming symbol names
3129 @cindex symbol names, transforming
3130 Do not append a second underscore to names of entities specified
3131 in the Fortran source file.
3132
3133 This option has no effect if @samp{-fno-underscoring} is
3134 in effect.
3135
3136 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
3137 is implemented as a reference to the link-time external symbol
3138 @samp{max_count_}, instead of @samp{max_count__}.
3139
3140 @cindex -fno-ident option
3141 @cindex options, -fno-ident
3142 @item -fno-ident
3143 Ignore the @samp{#ident} directive.
3144
3145 @cindex -fzeros option
3146 @cindex options, -fzeros
3147 @item -fzeros
3148 Treat initial values of zero as if they were any other value.
3149
3150 As of version 0.5.18, @code{g77} normally treats @code{DATA} and
3151 other statements that are used to specify initial values of zero
3152 for variables and arrays as if no values were actually specified,
3153 in the sense that no diagnostics regarding multiple initializations
3154 are produced.
3155
3156 This is done to speed up compiling of programs that initialize
3157 large arrays to zeros.
3158
3159 Use @samp{-fzeros} to revert to the simpler, slower behavior
3160 that can catch multiple initializations by keeping track of
3161 all initializations, zero or otherwise.
3162
3163 @emph{Caution:} Future versions of @code{g77} might disregard this option
3164 (and its negative form, the default) or interpret it somewhat
3165 differently.
3166 The interpretation changes will affect only non-standard
3167 programs; standard-conforming programs should not be affected.
3168
3169 @cindex -femulate-complex option
3170 @cindex options, -femulate-complex
3171 @item -femulate-complex
3172 Implement @code{COMPLEX} arithmetic via emulation,
3173 instead of using the facilities of
3174 the @code{gcc} back end that provide direct support of
3175 @code{complex} arithmetic.
3176
3177 (@code{gcc} had some bugs in its back-end support
3178 for @code{complex} arithmetic, due primarily to the support not being
3179 completed as of version 2.8.1 and @code{egcs} 1.1.2.)
3180
3181 Use @samp{-femulate-complex} if you suspect code-generation bugs,
3182 or experience compiler crashes,
3183 that might result from @code{g77} using the @code{COMPLEX} support
3184 in the @code{gcc} back end.
3185 If using that option fixes the bugs or crashes you are seeing,
3186 that indicates a likely @code{g77} bugs
3187 (though, all compiler crashes are considered bugs),
3188 so, please report it.
3189 (Note that the known bugs, now believed fixed, produced compiler crashes
3190 rather than causing the generation of incorrect code.)
3191
3192 Use of this option should not affect how Fortran code compiled
3193 by @code{g77} works in terms of its interfaces to other code,
3194 e.g. that compiled by @code{f2c}.
3195
3196 @emph{Caution:} Future versions of @code{g77} might ignore both forms
3197 of this option.
3198
3199 @cindex -falias-check option
3200 @cindex options, -falias-check
3201 @cindex -fargument-alias option
3202 @cindex options, -fargument-alias
3203 @cindex -fargument-noalias option
3204 @cindex options, -fargument-noalias
3205 @cindex -fno-argument-noalias-global option
3206 @cindex options, -fno-argument-noalias-global
3207 @item -falias-check
3208 @item -fargument-alias
3209 @item -fargument-noalias
3210 @item -fno-argument-noalias-global
3211 @emph{Version info:}
3212 These options are not supported by
3213 versions of @code{g77} based on @code{gcc} version 2.8.
3214
3215 These options specify to what degree aliasing
3216 (overlap)
3217 is permitted between
3218 arguments (passed as pointers) and @code{COMMON} (external, or
3219 public) storage.
3220
3221 The default for Fortran code, as mandated by the FORTRAN 77 and
3222 Fortran 90 standards, is @samp{-fargument-noalias-global}.
3223 The default for code written in the C language family is
3224 @samp{-fargument-alias}.
3225
3226 Note that, on some systems, compiling with @samp{-fforce-addr} in
3227 effect can produce more optimal code when the default aliasing
3228 options are in effect (and when optimization is enabled).
3229
3230 @xref{Aliasing Assumed To Work}, for detailed information on the implications
3231 of compiling Fortran code that depends on the ability to alias dummy
3232 arguments.
3233
3234 @cindex -fno-globals option
3235 @cindex options, -fno-globals
3236 @item -fno-globals
3237 @cindex global names, warning
3238 @cindex warnings, global names
3239 @cindex in-line code
3240 @cindex compilation, in-line
3241 Disable diagnostics about inter-procedural
3242 analysis problems, such as disagreements about the
3243 type of a function or a procedure's argument,
3244 that might cause a compiler crash when attempting
3245 to inline a reference to a procedure within a
3246 program unit.
3247 (The diagnostics themselves are still produced, but
3248 as warnings, unless @samp{-Wno-globals} is specified,
3249 in which case no relevant diagnostics are produced.)
3250
3251 Further, this option disables such inlining, to
3252 avoid compiler crashes resulting from incorrect
3253 code that would otherwise be diagnosed.
3254
3255 As such, this option might be quite useful when
3256 compiling existing, ``working'' code that happens
3257 to have a few bugs that do not generally show themselves,
3258 but which @code{g77} diagnoses.
3259
3260 Use of this option therefore has the effect of
3261 instructing @code{g77} to behave more like it did
3262 up through version 0.5.19.1, when it paid little or
3263 no attention to disagreements between program units
3264 about a procedure's type and argument information,
3265 and when it performed no inlining of procedures
3266 (except statement functions).
3267
3268 Without this option, @code{g77} defaults to performing
3269 the potentially inlining procedures as it started doing
3270 in version 0.5.20, but as of version 0.5.21, it also
3271 diagnoses disagreements that might cause such inlining
3272 to crash the compiler as (fatal) errors,
3273 and warns about similar disagreements
3274 that are currently believed to not
3275 likely to result in the compiler later crashing
3276 or producing incorrect code.
3277
3278 @cindex -fflatten-arrays option
3279 @item -fflatten-arrays
3280 @cindex array performance
3281 @cindex arrays, flattening
3282 Use back end's C-like constructs
3283 (pointer plus offset)
3284 instead of its @code{ARRAY_REF} construct
3285 to handle all array references.
3286
3287 @emph{Note:} This option is not supported.
3288 It is intended for use only by @code{g77} developers,
3289 to evaluate code-generation issues.
3290 It might be removed at any time.
3291
3292 @cindex -fbounds-check option
3293 @cindex -ffortran-bounds-check option
3294 @item -fbounds-check
3295 @itemx -ffortran-bounds-check
3296 @cindex bounds checking
3297 @cindex range checking
3298 @cindex array bounds checking
3299 @cindex subscript checking
3300 @cindex substring checking
3301 @cindex checking subscripts
3302 @cindex checking substrings
3303 Enable generation of run-time checks for array subscripts
3304 and substring start and end points
3305 against the (locally) declared minimum and maximum values.
3306
3307 The current implementation uses the @code{libf2c}
3308 library routine @code{s_rnge} to print the diagnostic.
3309
3310 However, whereas @code{f2c} generates a single check per
3311 reference for a multi-dimensional array, of the computed
3312 offset against the valid offset range (0 through the size of the array),
3313 @code{g77} generates a single check per @emph{subscript} expression.
3314 This catches some cases of potential bugs that @code{f2c} does not,
3315 such as references to below the beginning of an assumed-size array.
3316
3317 @code{g77} also generates checks for @code{CHARACTER} substring references,
3318 something @code{f2c} currently does not do.
3319
3320 Use the new @samp{-ffortran-bounds-check} option
3321 to specify bounds-checking for only the Fortran code you are compiling,
3322 not necessarily for code written in other languages.
3323
3324 @emph{Note:} To provide more detailed information on the offending subscript,
3325 @code{g77} provides the @code{libg2c} run-time library routine @code{s_rnge}
3326 with somewhat differently-formatted information.
3327 Here's a sample diagnostic:
3328
3329 @smallexample
3330 Subscript out of range on file line 4, procedure rnge.f/bf.
3331 Attempt to access the -6-th element of variable b[subscript-2-of-2].
3332 Aborted
3333 @end smallexample
3334
3335 The above message indicates that the offending source line is
3336 line 4 of the file @file{rnge.f},
3337 within the program unit (or statement function) named @samp{bf}.
3338 The offended array is named @samp{b}.
3339 The offended array dimension is the second for a two-dimensional array,
3340 and the offending, computed subscript expression was @samp{-6}.
3341
3342 For a @code{CHARACTER} substring reference, the second line has
3343 this appearance:
3344
3345 @smallexample
3346 Attempt to access the 11-th element of variable a[start-substring].
3347 @end smallexample
3348
3349 This indicates that the offended @code{CHARACTER} variable or array
3350 is named @samp{a},
3351 the offended substring position is the starting (leftmost) position,
3352 and the offending substring expression is @samp{11}.
3353
3354 (Though the verbage of @code{s_rnge} is not ideal
3355 for the purpose of the @code{g77} compiler,
3356 the above information should provide adequate diagnostic abilities
3357 to it users.)
3358 @end table
3359
3360 @xref{Code Gen Options,,Options for Code Generation Conventions,
3361 gcc,Using and Porting GNU CC}, for information on more options
3362 offered by the GBE
3363 shared by @code{g77}, @code{gcc}, and other GNU compilers.
3364
3365 Some of these do @emph{not} work when compiling programs written in Fortran:
3366
3367 @table @code
3368 @cindex -fpcc-struct-return option
3369 @cindex options, -fpcc-struct-return
3370 @item -fpcc-struct-return
3371 @cindex -freg-struct-return option
3372 @cindex options, -freg-struct-return
3373 @item -freg-struct-return
3374 You should not use these except strictly the same way as you
3375 used them to build the version of @code{libg2c} with which
3376 you will be linking all code compiled by @code{g77} with the
3377 same option.
3378
3379 @cindex -fshort-double option
3380 @cindex options, -fshort-double
3381 @item -fshort-double
3382 This probably either has no effect on Fortran programs, or
3383 makes them act loopy.
3384
3385 @cindex -fno-common option
3386 @cindex options, -fno-common
3387 @item -fno-common
3388 Do not use this when compiling Fortran programs,
3389 or there will be Trouble.
3390
3391 @cindex -fpack-struct option
3392 @cindex options, -fpack-struct
3393 @item -fpack-struct
3394 This probably will break any calls to the @code{libg2c} library,
3395 at the very least, even if it is built with the same option.
3396 @end table
3397
3398 @node Environment Variables
3399 @section Environment Variables Affecting GNU Fortran
3400 @cindex environment variables
3401
3402 GNU Fortran currently does not make use of any environment
3403 variables to control its operation above and beyond those
3404 that affect the operation of @code{gcc}.
3405
3406 @xref{Environment Variables,,Environment Variables Affecting GNU CC,
3407 gcc,Using and Porting GNU CC}, for information on environment
3408 variables.
3409
3410 @include news.texi
3411
3412 @set USERVISONLY
3413 @include news.texi
3414 @clear USERVISONLY
3415
3416 @node Language
3417 @chapter The GNU Fortran Language
3418
3419 @cindex standard, ANSI FORTRAN 77
3420 @cindex ANSI FORTRAN 77 standard
3421 @cindex reference works
3422 GNU Fortran supports a variety of extensions to, and dialects
3423 of, the Fortran language.
3424 Its primary base is the ANSI FORTRAN 77 standard, currently available on
3425 the network at
3426 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
3427 or as monolithic text at
3428 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
3429 It offers some extensions that are popular among users
3430 of UNIX @code{f77} and @code{f2c} compilers, some that
3431 are popular among users of other compilers (such as Digital
3432 products), some that are popular among users of the
3433 newer Fortran 90 standard, and some that are introduced
3434 by GNU Fortran.
3435
3436 @cindex textbooks
3437 (If you need a text on Fortran,
3438 a few freely available electronic references have pointers from
3439 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
3440 net project', @cite{User Notes on Fortran Programming} at
3441 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
3442 material might not apply specifically to @code{g77}.)
3443
3444 Part of what defines a particular implementation of a Fortran
3445 system, such as @code{g77}, is the particular characteristics
3446 of how it supports types, constants, and so on.
3447 Much of this is left up to the implementation by the various
3448 Fortran standards and accepted practice in the industry.
3449
3450 The GNU Fortran @emph{language} is described below.
3451 Much of the material is organized along the same lines
3452 as the ANSI FORTRAN 77 standard itself.
3453
3454 @xref{Other Dialects}, for information on features @code{g77} supports
3455 that are not part of the GNU Fortran language.
3456
3457 @emph{Note}: This portion of the documentation definitely needs a lot
3458 of work!
3459
3460 @menu
3461 Relationship to the ANSI FORTRAN 77 standard:
3462 * Direction of Language Development::  Where GNU Fortran is headed.
3463 * Standard Support::  Degree of support for the standard.
3464
3465 Extensions to the ANSI FORTRAN 77 standard:
3466 * Conformance::
3467 * Notation Used::
3468 * Terms and Concepts::
3469 * Characters Lines Sequence::
3470 * Data Types and Constants::
3471 * Expressions::
3472 * Specification Statements::
3473 * Control Statements::
3474 * Functions and Subroutines::
3475 * Scope and Classes of Names::
3476 * I/O::
3477 * Fortran 90 Features::
3478 @end menu
3479
3480 @node Direction of Language Development
3481 @section Direction of Language Development
3482 @cindex direction of language development
3483 @cindex features, language
3484 @cindex language, features
3485
3486 The purpose of the following description of the GNU Fortran
3487 language is to promote wide portability of GNU Fortran programs.
3488
3489 GNU Fortran is an evolving language, due to the
3490 fact that @code{g77} itself is in beta test.
3491 Some current features of the language might later
3492 be redefined as dialects of Fortran supported by @code{g77}
3493 when better ways to express these features are added to @code{g77},
3494 for example.
3495 Such features would still be supported by
3496 @code{g77}, but would be available only when
3497 one or more command-line options were used.
3498
3499 The GNU Fortran @emph{language} is distinct from the
3500 GNU Fortran @emph{compilation system} (@code{g77}).
3501
3502 For example, @code{g77} supports various dialects of
3503 Fortran---in a sense, these are languages other than
3504 GNU Fortran---though its primary
3505 purpose is to support the GNU Fortran language, which also is
3506 described in its documentation and by its implementation.
3507
3508 On the other hand, non-GNU compilers might offer
3509 support for the GNU Fortran language, and are encouraged
3510 to do so.
3511
3512 Currently, the GNU Fortran language is a fairly fuzzy object.
3513 It represents something of a cross between what @code{g77} accepts
3514 when compiling using the prevailing defaults and what this
3515 document describes as being part of the language.
3516
3517 Future versions of @code{g77} are expected to clarify the
3518 definition of the language in the documentation.
3519 Often, this will mean adding new features to the language, in the form
3520 of both new documentation and new support in @code{g77}.
3521 However, it might occasionally mean removing a feature
3522 from the language itself to ``dialect'' status.
3523 In such a case, the documentation would be adjusted
3524 to reflect the change, and @code{g77} itself would likely be changed
3525 to require one or more command-line options to continue supporting
3526 the feature.
3527
3528 The development of the GNU Fortran language is intended to strike
3529 a balance between:
3530
3531 @itemize @bullet
3532 @item
3533 Serving as a mostly-upwards-compatible language from the
3534 de facto UNIX Fortran dialect as supported by @code{f77}.
3535
3536 @item
3537 Offering new, well-designed language features.
3538 Attributes of such features include
3539 not making existing code any harder to read
3540 (for those who might be unaware that the new
3541 features are not in use) and
3542 not making state-of-the-art
3543 compilers take longer to issue diagnostics,
3544 among others.
3545
3546 @item
3547 Supporting existing, well-written code without gratuitously
3548 rejecting non-standard constructs, regardless of the origin
3549 of the code (its dialect).
3550
3551 @item
3552 Offering default behavior and command-line options to reduce
3553 and, where reasonable, eliminate the need for programmers to make
3554 any modifications to code that already works in existing
3555 production environments.
3556
3557 @item
3558 Diagnosing constructs that have different meanings in different
3559 systems, languages, and dialects, while offering clear,
3560 less ambiguous ways to express each of the different meanings
3561 so programmers can change their code appropriately.
3562 @end itemize
3563
3564 One of the biggest practical challenges for the developers of the
3565 GNU Fortran language is meeting the sometimes contradictory demands
3566 of the above items.
3567
3568 For example, a feature might be widely used in one popular environment,
3569 but the exact same code that utilizes that feature might not work
3570 as expected---perhaps it might mean something entirely different---in
3571 another popular environment.
3572
3573 Traditionally, Fortran compilers---even portable ones---have solved this
3574 problem by simply offering the appropriate feature to users of
3575 the respective systems.
3576 This approach treats users of various Fortran systems and dialects
3577 as remote ``islands'', or camps, of programmers, and assume that these
3578 camps rarely come into contact with each other (or,
3579 especially, with each other's code).
3580
3581 Project GNU takes a radically different approach to software and language
3582 design, in that it assumes that users of GNU software do not necessarily
3583 care what kind of underlying system they are using, regardless
3584 of whether they are using software (at the user-interface
3585 level) or writing it (for example, writing Fortran or C code).
3586
3587 As such, GNU users rarely need consider just what kind of underlying
3588 hardware (or, in many cases, operating system) they are using at any
3589 particular time.
3590 They can use and write software designed for a general-purpose,
3591 widely portable, heterogenous environment---the GNU environment.
3592
3593 In line with this philosophy, GNU Fortran must evolve into a product
3594 that is widely ported and portable not only in the sense that it can
3595 be successfully built, installed, and run by users, but in the larger
3596 sense that its users can use it in the same way, and expect largely the
3597 same behaviors from it, regardless of the kind of system they are using
3598 at any particular time.
3599
3600 This approach constrains the solutions @code{g77} can use to resolve
3601 conflicts between various camps of Fortran users.
3602 If these two camps disagree about what a particular construct should
3603 mean, @code{g77} cannot simply be changed to treat that particular construct as
3604 having one meaning without comment (such as a warning), lest the users
3605 expecting it to have the other meaning are unpleasantly surprised that
3606 their code misbehaves when executed.
3607
3608 The use of the ASCII backslash character in character constants is
3609 an excellent (and still somewhat unresolved) example of this kind of
3610 controversy.
3611 @xref{Backslash in Constants}.
3612 Other examples are likely to arise in the future, as @code{g77} developers
3613 strive to improve its ability to accept an ever-wider variety of existing
3614 Fortran code without requiring significant modifications to said code.
3615
3616 Development of GNU Fortran is further constrained by the desire
3617 to avoid requiring programmers to change their code.
3618 This is important because it allows programmers, administrators,
3619 and others to more faithfully evaluate and validate @code{g77}
3620 (as an overall product and as new versions are distributed)
3621 without having to support multiple versions of their programs
3622 so that they continue to work the same way on their existing
3623 systems (non-GNU perhaps, but possibly also earlier versions
3624 of @code{g77}).
3625
3626 @node Standard Support
3627 @section ANSI FORTRAN 77 Standard Support
3628 @cindex ANSI FORTRAN 77 support
3629 @cindex standard, support for
3630 @cindex support, FORTRAN 77
3631 @cindex compatibility, FORTRAN 77
3632 @cindex FORTRAN 77 compatibility
3633
3634 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
3635 In summary, the only ANSI FORTRAN 77 features @code{g77} doesn't
3636 support are those that are probably rarely used in actual code,
3637 some of which are explicitly disallowed by the Fortran 90 standard.
3638
3639 @menu
3640 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
3641 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
3642 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
3643 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
3644 @end menu
3645
3646 @node No Passing External Assumed-length
3647 @subsection No Passing External Assumed-length
3648
3649 @code{g77} disallows passing of an external procedure
3650 as an actual argument if the procedure's
3651 type is declared @code{CHARACTER*(*)}.  For example:
3652
3653 @example
3654 CHARACTER*(*) CFUNC
3655 EXTERNAL CFUNC
3656 CALL FOO(CFUNC)
3657 END
3658 @end example
3659
3660 @noindent
3661 It isn't clear whether the standard considers this conforming.
3662
3663 @node No Passing Dummy Assumed-length
3664 @subsection No Passing Dummy Assumed-length
3665
3666 @code{g77} disallows passing of a dummy procedure
3667 as an actual argument if the procedure's
3668 type is declared @code{CHARACTER*(*)}.
3669
3670 @example
3671 SUBROUTINE BAR(CFUNC)
3672 CHARACTER*(*) CFUNC
3673 EXTERNAL CFUNC
3674 CALL FOO(CFUNC)
3675 END
3676 @end example
3677
3678 @noindent
3679 It isn't clear whether the standard considers this conforming.
3680
3681 @node No Pathological Implied-DO
3682 @subsection No Pathological Implied-DO
3683
3684 The @code{DO} variable for an implied-@code{DO} construct in a
3685 @code{DATA} statement may not be used as the @code{DO} variable
3686 for an outer implied-@code{DO} construct.  For example, this
3687 fragment is disallowed by @code{g77}:
3688
3689 @smallexample
3690 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
3691 @end smallexample
3692
3693 @noindent
3694 This also is disallowed by Fortran 90, as it offers no additional
3695 capabilities and would have a variety of possible meanings.
3696
3697 Note that it is @emph{very} unlikely that any production Fortran code
3698 tries to use this unsupported construct.
3699
3700 @node No Useless Implied-DO
3701 @subsection No Useless Implied-DO
3702
3703 An array element initializer in an implied-@code{DO} construct in a
3704 @code{DATA} statement must contain at least one reference to the @code{DO}
3705 variables of each outer implied-@code{DO} construct.  For example,
3706 this fragment is disallowed by @code{g77}:
3707
3708 @smallexample
3709 DATA (A, I= 1, 1) /1./
3710 @end smallexample
3711
3712 @noindent
3713 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
3714 requirements offer no additional capabilities.
3715 However, @code{g77} doesn't necessarily diagnose all cases
3716 where this requirement is not met.
3717
3718 Note that it is @emph{very} unlikely that any production Fortran code
3719 tries to use this unsupported construct.
3720
3721 @node Conformance
3722 @section Conformance
3723
3724 (The following information augments or overrides the information in
3725 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3726 language.
3727 Chapter 1 of that document otherwise serves as the basis
3728 for the relevant aspects of GNU Fortran.)
3729
3730 The definition of the GNU Fortran language is akin to that of
3731 the ANSI FORTRAN 77 language in that it does not generally require
3732 conforming implementations to diagnose cases where programs do
3733 not conform to the language.
3734
3735 However, @code{g77} as a compiler is being developed in a way that
3736 is intended to enable it to diagnose such cases in an easy-to-understand
3737 manner.
3738
3739 A program that conforms to the GNU Fortran language should, when
3740 compiled, linked, and executed using a properly installed @code{g77}
3741 system, perform as described by the GNU Fortran language definition.
3742 Reasons for different behavior include, among others:
3743
3744 @itemize @bullet
3745 @item
3746 Use of resources (memory---heap, stack, and so on; disk space; CPU
3747 time; etc.) exceeds those of the system.
3748
3749 @item
3750 Range and/or precision of calculations required by the program
3751 exceeds that of the system.
3752
3753 @item
3754 Excessive reliance on behaviors that are system-dependent
3755 (non-portable Fortran code).
3756
3757 @item
3758 Bugs in the program.
3759
3760 @item
3761 Bug in @code{g77}.
3762
3763 @item
3764 Bugs in the system.
3765 @end itemize
3766
3767 Despite these ``loopholes'', the availability of a clear specification
3768 of the language of programs submitted to @code{g77}, as this document
3769 is intended to provide, is considered an important aspect of providing
3770 a robust, clean, predictable Fortran implementation.
3771
3772 The definition of the GNU Fortran language, while having no special
3773 legal status, can therefore be viewed as a sort of contract, or agreement.
3774 This agreement says, in essence, ``if you write a program in this language,
3775 and run it in an environment (such as a @code{g77} system) that supports
3776 this language, the program should behave in a largely predictable way''.
3777
3778 @node Notation Used
3779 @section Notation Used in This Chapter
3780
3781 (The following information augments or overrides the information in
3782 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3783 language.
3784 Chapter 1 of that document otherwise serves as the basis
3785 for the relevant aspects of GNU Fortran.)
3786
3787 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
3788 and ``must not'' and ``may not'' denote prohibition.
3789 Terms such as ``might'', ``should'', and ``can'' generally add little or
3790 nothing in the way of weight to the GNU Fortran language itself,
3791 but are used to explain or illustrate the language.
3792
3793 For example:
3794
3795 @display
3796 ``The @code{FROBNITZ} statement must precede all executable
3797 statements in a program unit, and may not specify any dummy
3798 arguments.  It may specify local or common variables and arrays.
3799 Its use should be limited to portions of the program designed to
3800 be non-portable and system-specific, because it might cause the
3801 containing program unit to behave quite differently on different
3802 systems.''
3803 @end display
3804
3805 Insofar as the GNU Fortran language is specified,
3806 the requirements and permissions denoted by the above sample statement
3807 are limited to the placement of the statement and the kinds of
3808 things it may specify.
3809 The rest of the statement---the content regarding non-portable portions
3810 of the program and the differing behavior of program units containing
3811 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
3812 language itself.
3813 That content offers advice and warnings about the @code{FROBNITZ}
3814 statement.
3815
3816 @emph{Remember:} The GNU Fortran language definition specifies
3817 both what constitutes a valid GNU Fortran program and how,
3818 given such a program, a valid GNU Fortran implementation is
3819 to interpret that program.
3820
3821 It is @emph{not} incumbent upon a valid GNU Fortran implementation
3822 to behave in any particular way, any consistent way, or any
3823 predictable way when it is asked to interpret input that is
3824 @emph{not} a valid GNU Fortran program.
3825
3826 Such input is said to have @dfn{undefined} behavior when
3827 interpreted by a valid GNU Fortran implementation, though
3828 an implementation may choose to specify behaviors for some
3829 cases of inputs that are not valid GNU Fortran programs.
3830
3831 Other notation used herein is that of the GNU texinfo format,
3832 which is used to generate printed hardcopy, on-line hypertext
3833 (Info), and on-line HTML versions, all from a single source
3834 document.
3835 This notation is used as follows:
3836
3837 @itemize @bullet
3838 @item
3839 Keywords defined by the GNU Fortran language are shown
3840 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
3841 @code{BLOCK DATA}.
3842
3843 Note that, in practice, many Fortran programs are written
3844 in lowercase---uppercase is used in this manual as a
3845 means to readily distinguish keywords and sample Fortran-related
3846 text from the prose in this document.
3847
3848 @item
3849 Portions of actual sample program, input, or output text
3850 look like this: @samp{Actual program text}.
3851
3852 Generally, uppercase is used for all Fortran-specific and
3853 Fortran-related text, though this does not always include
3854 literal text within Fortran code.
3855
3856 For example: @samp{PRINT *, 'My name is Bob'}.
3857
3858 @item
3859 A metasyntactic variable---that is, a name used in this document
3860 to serve as a placeholder for whatever text is used by the
3861 user or programmer---appears as shown in the following example:
3862
3863 ``The @code{INTEGER @var{ivar}} statement specifies that
3864 @var{ivar} is a variable or array of type @code{INTEGER}.''
3865
3866 In the above example, any valid text may be substituted for
3867 the metasyntactic variable @var{ivar} to make the statement
3868 apply to a specific instance, as long as the same text is
3869 substituted for @emph{both} occurrences of @var{ivar}.
3870
3871 @item
3872 Ellipses (``@dots{}'') are used to indicate further text that
3873 is either unimportant or expanded upon further, elsewhere.
3874
3875 @item
3876 Names of data types are in the style of Fortran 90, in most
3877 cases.
3878
3879 @xref{Kind Notation}, for information on the relationship
3880 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
3881 and the more traditional, less portably concise nomenclature
3882 (such as @code{INTEGER*4}).
3883 @end itemize
3884
3885 @node Terms and Concepts
3886 @section Fortran Terms and Concepts
3887
3888 (The following information augments or overrides the information in
3889 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3890 language.
3891 Chapter 2 of that document otherwise serves as the basis
3892 for the relevant aspects of GNU Fortran.)
3893
3894 @menu
3895 * Syntactic Items::
3896 * Statements Comments Lines::
3897 * Scope of Names and Labels::
3898 @end menu
3899
3900 @node Syntactic Items
3901 @subsection Syntactic Items
3902
3903 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
3904
3905 @cindex limits, lengths of names
3906 In GNU Fortran, a symbolic name is at least one character long,
3907 and has no arbitrary upper limit on length.
3908 However, names of entities requiring external linkage (such as
3909 external functions, external subroutines, and @code{COMMON} areas)
3910 might be restricted to some arbitrary length by the system.
3911 Such a restriction is no more constrained than that of one
3912 through six characters.
3913
3914 Underscores (@samp{_}) are accepted in symbol names after the first
3915 character (which must be a letter).
3916
3917 @node Statements Comments Lines
3918 @subsection Statements, Comments, and Lines
3919
3920 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
3921
3922 @cindex trailing comment
3923 @cindex comment
3924 @cindex characters, comment
3925 @cindex !
3926 @cindex exclamation point
3927 @cindex continuation character
3928 @cindex characters, continuation
3929 Use of an exclamation point (@samp{!}) to begin a
3930 trailing comment (a comment that extends to the end of the same
3931 source line) is permitted under the following conditions:
3932
3933 @itemize @bullet
3934 @item
3935 The exclamation point does not appear in column 6.
3936 Otherwise, it is treated as an indicator of a continuation
3937 line.
3938
3939 @item
3940 The exclamation point appears outside a character or Hollerith
3941 constant.
3942 Otherwise, the exclamation point is considered part of the
3943 constant.
3944
3945 @item
3946 The exclamation point appears to the left of any other possible
3947 trailing comment.
3948 That is, a trailing comment may contain exclamation points
3949 in their commentary text.
3950 @end itemize
3951
3952 @cindex ;
3953 @cindex semicolon
3954 @cindex statements, separated by semicolon
3955 Use of a semicolon (@samp{;}) as a statement separator
3956 is permitted under the following conditions:
3957
3958 @itemize @bullet
3959 @item
3960 The semicolon appears outside a character or Hollerith
3961 constant.
3962 Otherwise, the semicolon is considered part of the
3963 constant.
3964
3965 @item
3966 The semicolon appears to the left of a trailing comment.
3967 Otherwise, the semicolon is considered part of that
3968 comment.
3969
3970 @item
3971 Neither a logical @code{IF} statement nor a non-construct
3972 @code{WHERE} statement (a Fortran 90 feature) may be
3973 followed (in the same, possibly continued, line) by
3974 a semicolon used as a statement separator.
3975
3976 This restriction avoids the confusion
3977 that can result when reading a line such as:
3978
3979 @smallexample
3980 IF (VALIDP) CALL FOO; CALL BAR
3981 @end smallexample
3982
3983 @noindent
3984 Some readers might think the @samp{CALL BAR} is executed
3985 only if @samp{VALIDP} is @code{.TRUE.}, while others might
3986 assume its execution is unconditional.
3987
3988 (At present, @code{g77} does not diagnose code that
3989 violates this restriction.)
3990 @end itemize
3991
3992 @node Scope of Names and Labels
3993 @subsection Scope of Symbolic Names and Statement Labels
3994 @cindex scope
3995
3996 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
3997
3998 Included in the list of entities that have a scope of a
3999 program unit are construct names (a Fortran 90 feature).
4000 @xref{Construct Names}, for more information.
4001
4002 @node Characters Lines Sequence
4003 @section Characters, Lines, and Execution Sequence
4004
4005 (The following information augments or overrides the information in
4006 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4007 language.
4008 Chapter 3 of that document otherwise serves as the basis
4009 for the relevant aspects of GNU Fortran.)
4010
4011 @menu
4012 * Character Set::
4013 * Lines::
4014 * Continuation Line::
4015 * Statements::
4016 * Statement Labels::
4017 * Order::
4018 * INCLUDE::
4019 * Cpp-style directives::
4020 @end menu
4021
4022 @node Character Set
4023 @subsection GNU Fortran Character Set
4024 @cindex characters
4025
4026 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
4027
4028 Letters include uppercase letters (the twenty-six characters
4029 of the English alphabet) and lowercase letters (their lowercase
4030 equivalent).
4031 Generally, lowercase letters may be used in place of uppercase
4032 letters, though in character and Hollerith constants, they
4033 are distinct.
4034
4035 Special characters include:
4036
4037 @itemize @bullet
4038 @item
4039 @cindex ;
4040 @cindex semicolon
4041 Semicolon (@samp{;})
4042
4043 @item
4044 @cindex !
4045 @cindex exclamation point
4046 Exclamation point (@samp{!})
4047
4048 @item
4049 @cindex "
4050 @cindex double quote
4051 Double quote (@samp{"})
4052
4053 @item
4054 @cindex \
4055 @cindex backslash
4056 Backslash (@samp{\})
4057
4058 @item
4059 @cindex ?
4060 @cindex question mark
4061 Question mark (@samp{?})
4062
4063 @item
4064 @cindex #
4065 @cindex hash mark
4066 @cindex pound sign
4067 Hash mark (@samp{#})
4068
4069 @item
4070 @cindex &
4071 @cindex ampersand
4072 Ampersand (@samp{&})
4073
4074 @item
4075 @cindex %
4076 @cindex percent sign
4077 Percent sign (@samp{%})
4078
4079 @item
4080 @cindex _
4081 @cindex underscore
4082 Underscore (@samp{_})
4083
4084 @item
4085 @cindex <
4086 @cindex open angle
4087 @cindex left angle
4088 @cindex open bracket
4089 @cindex left bracket
4090 Open angle (@samp{<})
4091
4092 @item
4093 @cindex >
4094 @cindex close angle
4095 @cindex right angle
4096 @cindex close bracket
4097 @cindex right bracket
4098 Close angle (@samp{>})
4099
4100 @item
4101 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
4102 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
4103 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
4104 and @samp{:})
4105 @end itemize
4106
4107 @cindex blank
4108 @cindex space
4109 @cindex SPC
4110 Note that this document refers to @key{SPC} as @dfn{space},
4111 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
4112
4113 @node Lines
4114 @subsection Lines
4115 @cindex lines
4116 @cindex source file format
4117 @cindex source format
4118 @cindex file, source
4119 @cindex source code
4120 @cindex code, source
4121 @cindex fixed form
4122 @cindex free form
4123
4124 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
4125
4126 The way a Fortran compiler views source files depends entirely on the
4127 implementation choices made for the compiler, since those choices
4128 are explicitly left to the implementation by the published Fortran
4129 standards.
4130
4131 The GNU Fortran language mandates a view applicable to UNIX-like
4132 text files---files that are made up of an arbitrary number of lines,
4133 each with an arbitrary number of characters (sometimes called stream-based
4134 files).
4135
4136 This view does not apply to types of files that are specified as
4137 having a particular number of characters on every single line (sometimes
4138 referred to as record-based files).
4139
4140 Because a ``line in a program unit is a sequence of 72 characters'',
4141 to quote X3.9-1978, the GNU Fortran language specifies that a
4142 stream-based text file is translated to GNU Fortran lines as follows:
4143
4144 @itemize @bullet
4145 @item
4146 A newline in the file is the character that represents the end of
4147 a line of text to the underlying system.
4148 For example, on ASCII-based systems, a newline is the @key{NL}
4149 character, which has ASCII value 10 (decimal).
4150
4151 @item
4152 Each newline in the file serves to end the line of text that precedes
4153 it (and that does not contain a newline).
4154
4155 @item
4156 The end-of-file marker (@code{EOF}) also serves to end the line
4157 of text that precedes it (and that does not contain a newline).
4158
4159 @item
4160 @cindex blank
4161 @cindex space
4162 @cindex SPC
4163 Any line of text that is shorter than 72 characters is padded to that length
4164 with spaces (called ``blanks'' in the standard).
4165
4166 @item
4167 Any line of text that is longer than 72 characters is truncated to that
4168 length, but the truncated remainder must consist entirely of spaces.
4169
4170 @item
4171 Characters other than newline and the GNU Fortran character set
4172 are invalid.
4173 @end itemize
4174
4175 For the purposes of the remainder of this description of the GNU
4176 Fortran language, the translation described above has already
4177 taken place, unless otherwise specified.
4178
4179 The result of the above translation is that the source file appears,
4180 in terms of the remainder of this description of the GNU Fortran language,
4181 as if it had an arbitrary
4182 number of 72-character lines, each character being among the GNU Fortran
4183 character set.
4184
4185 For example, if the source file itself has two newlines in a row,
4186 the second newline becomes, after the above translation, a single
4187 line containing 72 spaces.
4188
4189 @node Continuation Line
4190 @subsection Continuation Line
4191 @cindex continuation line, number of
4192 @cindex lines, continuation
4193 @cindex number of continuation lines
4194 @cindex limits, continuation lines
4195
4196 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
4197
4198 A continuation line is any line that both
4199
4200 @itemize @bullet
4201 @item
4202 Contains a continuation character, and
4203
4204 @item
4205 Contains only spaces in columns 1 through 5
4206 @end itemize
4207
4208 A continuation character is any character of the GNU Fortran character set
4209 other than space (@key{SPC}) or zero (@samp{0})
4210 in column 6, or a digit (@samp{0} through @samp{9}) in column
4211 7 through 72 of a line that has only spaces to the left of that
4212 digit.
4213
4214 The continuation character is ignored as far as the content of
4215 the statement is concerned.
4216
4217 The GNU Fortran language places no limit on the number of
4218 continuation lines in a statement.
4219 In practice, the limit depends on a variety of factors, such as
4220 available memory, statement content, and so on, but no
4221 GNU Fortran system may impose an arbitrary limit.
4222
4223 @node Statements
4224 @subsection Statements
4225
4226 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
4227
4228 Statements may be written using an arbitrary number of continuation
4229 lines.
4230
4231 Statements may be separated using the semicolon (@samp{;}), except
4232 that the logical @code{IF} and non-construct @code{WHERE} statements
4233 may not be separated from subsequent statements using only a semicolon
4234 as statement separator.
4235
4236 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
4237 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
4238 statement.
4239 These alternatives may be written as normal statements---they are not
4240 subject to the restrictions of the @code{END} statement.
4241
4242 However, no statement other than @code{END} may have an initial line
4243 that appears to be an @code{END} statement---even @code{END PROGRAM},
4244 for example, must not be written as:
4245
4246 @example
4247       END
4248      &PROGRAM
4249 @end example
4250
4251 @node Statement Labels
4252 @subsection Statement Labels
4253
4254 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
4255
4256 A statement separated from its predecessor via a semicolon may be
4257 labeled as follows:
4258
4259 @itemize @bullet
4260 @item
4261 The semicolon is followed by the label for the statement,
4262 which in turn follows the label.
4263
4264 @item
4265 The label must be no more than five digits in length.
4266
4267 @item
4268 The first digit of the label for the statement is not
4269 the first non-space character on a line.
4270 Otherwise, that character is treated as a continuation
4271 character.
4272 @end itemize
4273
4274 A statement may have only one label defined for it.
4275
4276 @node Order
4277 @subsection Order of Statements and Lines
4278
4279 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
4280
4281 Generally, @code{DATA} statements may precede executable statements.
4282 However, specification statements pertaining to any entities
4283 initialized by a @code{DATA} statement must precede that @code{DATA}
4284 statement.
4285 For example,
4286 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
4287 @samp{INTEGER J} is permitted.
4288
4289 The last line of a program unit may be an @code{END} statement,
4290 or may be:
4291
4292 @itemize @bullet
4293 @item
4294 An @code{END PROGRAM} statement, if the program unit is a main program.
4295
4296 @item
4297 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
4298
4299 @item
4300 An @code{END FUNCTION} statement, if the program unit is a function.
4301
4302 @item
4303 An @code{END BLOCK DATA} statement, if the program unit is a block data.
4304 @end itemize
4305
4306 @node INCLUDE
4307 @subsection Including Source Text
4308 @cindex INCLUDE directive
4309
4310 Additional source text may be included in the processing of
4311 the source file via the @code{INCLUDE} directive:
4312
4313 @example
4314 INCLUDE @var{filename}
4315 @end example
4316
4317 @noindent
4318 The source text to be included is identified by @var{filename},
4319 which is a literal GNU Fortran character constant.
4320 The meaning and interpretation of @var{filename} depends on the
4321 implementation, but typically is a filename.
4322
4323 (@code{g77} treats it as a filename that it searches for
4324 in the current directory and/or directories specified
4325 via the @samp{-I} command-line option.)
4326
4327 The effect of the @code{INCLUDE} directive is as if the
4328 included text directly replaced the directive in the source
4329 file prior to interpretation of the program.
4330 Included text may itself use @code{INCLUDE}.
4331 The depth of nested @code{INCLUDE} references depends on
4332 the implementation, but typically is a positive integer.
4333
4334 This virtual replacement treats the statements and @code{INCLUDE}
4335 directives in the included text as syntactically distinct from
4336 those in the including text.
4337
4338 Therefore, the first non-comment line of the included text
4339 must not be a continuation line.
4340 The included text must therefore have, after the non-comment
4341 lines, either an initial line (statement), an @code{INCLUDE}
4342 directive, or nothing (the end of the included text).
4343
4344 Similarly, the including text may end the @code{INCLUDE}
4345 directive with a semicolon or the end of the line, but it
4346 cannot follow an @code{INCLUDE} directive at the end of its
4347 line with a continuation line.
4348 Thus, the last statement in an included text may not be
4349 continued.
4350
4351 Any statements between two @code{INCLUDE} directives on the
4352 same line are treated as if they appeared in between the
4353 respective included texts.
4354 For example:
4355
4356 @smallexample
4357 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
4358 @end smallexample
4359
4360 @noindent
4361 If the text included by @samp{INCLUDE 'A'} constitutes
4362 a @samp{PRINT *, 'A'} statement and the text included by
4363 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
4364 then the output of the above sample program would be
4365
4366 @example
4367 A
4368 B
4369 C
4370 @end example
4371
4372 @noindent
4373 (with suitable allowances for how an implementation defines
4374 its handling of output).
4375
4376 Included text must not include itself directly or indirectly,
4377 regardless of whether the @var{filename} used to reference
4378 the text is the same.
4379
4380 Note that @code{INCLUDE} is @emph{not} a statement.
4381 As such, it is neither a non-executable or executable
4382 statement.
4383 However, if the text it includes constitutes one or more
4384 executable statements, then the placement of @code{INCLUDE}
4385 is subject to effectively the same restrictions as those
4386 on executable statements.
4387
4388 An @code{INCLUDE} directive may be continued across multiple
4389 lines as if it were a statement.
4390 This permits long names to be used for @var{filename}.
4391
4392 @node Cpp-style directives
4393 @subsection Cpp-style directives
4394 @cindex #
4395 @cindex preprocessor
4396
4397 @code{cpp} output-style @code{#} directives
4398 (@pxref{C Preprocessor Output,,, cpp, The C Preprocessor})
4399 are recognized by the compiler even
4400 when the preprocessor isn't run on the input (as it is when compiling
4401 @samp{.F} files).  (Note the distinction between these @code{cpp}
4402 @code{#} @emph{output} directives and @code{#line} @emph{input}
4403 directives.)
4404
4405 @node Data Types and Constants
4406 @section Data Types and Constants
4407
4408 (The following information augments or overrides the information in
4409 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4410 language.
4411 Chapter 4 of that document otherwise serves as the basis
4412 for the relevant aspects of GNU Fortran.)
4413
4414 To more concisely express the appropriate types for
4415 entities, this document uses the more concise
4416 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
4417 instead of the more traditional, but less portably concise,
4418 byte-size-based nomenclature such as @code{INTEGER*4},
4419 wherever reasonable.
4420
4421 When referring to generic types---in contexts where the
4422 specific precision and range of a type are not important---this
4423 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
4424 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
4425
4426 In some cases, the context requires specification of a
4427 particular type.
4428 This document uses the @samp{KIND=} notation to accomplish
4429 this throughout, sometimes supplying the more traditional
4430 notation for clarification, though the traditional notation
4431 might not work the same way on all GNU Fortran implementations.
4432
4433 Use of @samp{KIND=} makes this document more concise because
4434 @code{g77} is able to define values for @samp{KIND=} that
4435 have the same meanings on all systems, due to the way the
4436 Fortran 90 standard specifies these values are to be used.
4437
4438 (In particular, that standard permits an implementation to
4439 arbitrarily assign nonnegative values.
4440 There are four distinct sets of assignments: one to the @code{CHARACTER}
4441 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
4442 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
4443 Implementations are free to assign these values in any order,
4444 leave gaps in the ordering of assignments, and assign more than
4445 one value to a representation.)
4446
4447 This makes @samp{KIND=} values superior to the values used
4448 in non-standard statements such as @samp{INTEGER*4}, because
4449 the meanings of the values in those statements vary from machine
4450 to machine, compiler to compiler, even operating system to
4451 operating system.
4452
4453 However, use of @samp{KIND=} is @emph{not} generally recommended
4454 when writing portable code (unless, for example, the code is
4455 going to be compiled only via @code{g77}, which is a widely
4456 ported compiler).
4457 GNU Fortran does not yet have adequate language constructs to
4458 permit use of @samp{KIND=} in a fashion that would make the
4459 code portable to Fortran 90 implementations; and, this construct
4460 is known to @emph{not} be accepted by many popular FORTRAN 77
4461 implementations, so it cannot be used in code that is to be ported
4462 to those.
4463
4464 The distinction here is that this document is able to use
4465 specific values for @samp{KIND=} to concisely document the
4466 types of various operations and operands.
4467
4468 A Fortran program should use the FORTRAN 77 designations for the
4469 appropriate GNU Fortran types---such as @code{INTEGER} for
4470 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
4471 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
4472 where no such designations exist, make use of appropriate
4473 techniques (preprocessor macros, parameters, and so on)
4474 to specify the types in a fashion that may be easily adjusted
4475 to suit each particular implementation to which the program
4476 is ported.
4477 (These types generally won't need to be adjusted for ports of
4478 @code{g77}.)
4479
4480 Further details regarding GNU Fortran data types and constants
4481 are provided below.
4482
4483 @menu
4484 * Types::
4485 * Constants::
4486 * Integer Type::
4487 * Character Type::
4488 @end menu
4489
4490 @node Types
4491 @subsection Data Types
4492
4493 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
4494
4495 GNU Fortran supports these types:
4496
4497 @enumerate
4498 @item
4499 Integer (generic type @code{INTEGER})
4500
4501 @item
4502 Real (generic type @code{REAL})
4503
4504 @item
4505 Double precision
4506
4507 @item
4508 Complex (generic type @code{COMPLEX})
4509
4510 @item
4511 Logical (generic type @code{LOGICAL})
4512
4513 @item
4514 Character (generic type @code{CHARACTER})
4515
4516 @item
4517 Double Complex
4518 @end enumerate
4519
4520 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
4521
4522 The generic types shown above are referred to in this document
4523 using only their generic type names.
4524 Such references usually indicate that any specific type (kind)
4525 of that generic type is valid.
4526
4527 For example, a context described in this document as accepting
4528 the @code{COMPLEX} type also is likely to accept the
4529 @code{DOUBLE COMPLEX} type.
4530
4531 The GNU Fortran language supports three ways to specify
4532 a specific kind of a generic type.
4533
4534 @menu
4535 * Double Notation::  As in @code{DOUBLE COMPLEX}.
4536 * Star Notation::    As in @code{INTEGER*4}.
4537 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
4538 @end menu
4539
4540 @node Double Notation
4541 @subsubsection Double Notation
4542
4543 The GNU Fortran language supports two uses of the keyword
4544 @code{DOUBLE} to specify a specific kind of type:
4545
4546 @itemize @bullet
4547 @item
4548 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
4549
4550 @item
4551 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
4552 @end itemize
4553
4554 Use one of the above forms where a type name is valid.
4555
4556 While use of this notation is popular, it doesn't scale
4557 well in a language or dialect rich in intrinsic types,
4558 as is the case for the GNU Fortran language (especially
4559 planned future versions of it).
4560
4561 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
4562 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
4563 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
4564 often are substituted for these, respectively, even though they
4565 do not always have the same meanings on all systems.
4566 (And, the fact that @samp{DOUBLE REAL} does not exist as such
4567 is an inconsistency.)
4568
4569 Therefore, this document uses ``double notation'' only on occasion
4570 for the benefit of those readers who are accustomed to it.
4571
4572 @node Star Notation
4573 @subsubsection Star Notation
4574 @cindex *@var{n} notation
4575
4576 The following notation specifies the storage size for a type:
4577
4578 @smallexample
4579 @var{generic-type}*@var{n}
4580 @end smallexample
4581
4582 @noindent
4583 @var{generic-type} must be a generic type---one of
4584 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4585 or @code{CHARACTER}.
4586 @var{n} must be one or more digits comprising a decimal
4587 integer number greater than zero.
4588
4589 Use the above form where a type name is valid.
4590
4591 The @samp{*@var{n}} notation specifies that the amount of storage
4592 occupied by variables and array elements of that type is @var{n}
4593 times the storage occupied by a @code{CHARACTER*1} variable.
4594
4595 This notation might indicate a different degree of precision and/or
4596 range for such variables and array elements, and the functions that
4597 return values of types using this notation.
4598 It does not limit the precision or range of values of that type
4599 in any particular way---use explicit code to do that.
4600
4601 Further, the GNU Fortran language requires no particular values
4602 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
4603 notation.
4604 @code{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
4605 on all systems, for example,
4606 but not all implementations are required to do so, and @code{g77}
4607 is known to not support @code{REAL*1} on most (or all) systems.
4608
4609 As a result, except for @var{generic-type} of @code{CHARACTER},
4610 uses of this notation should be limited to isolated
4611 portions of a program that are intended to handle system-specific
4612 tasks and are expected to be non-portable.
4613
4614 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
4615 only @code{CHARACTER}, where it signifies not only the amount
4616 of storage occupied, but the number of characters in entities
4617 of that type.
4618 However, almost all Fortran compilers have supported this
4619 notation for generic types, though with a variety of meanings
4620 for @var{n}.)
4621
4622 Specifications of types using the @samp{*@var{n}} notation
4623 always are interpreted as specifications of the appropriate
4624 types described in this document using the @samp{KIND=@var{n}}
4625 notation, described below.
4626
4627 While use of this notation is popular, it doesn't serve well
4628 in the context of a widely portable dialect of Fortran, such as
4629 the GNU Fortran language.
4630
4631 For example, even on one particular machine, two or more popular
4632 Fortran compilers might well disagree on the size of a type
4633 declared @code{INTEGER*2} or @code{REAL*16}.
4634 Certainly there
4635 is known to be disagreement over such things among Fortran
4636 compilers on @emph{different} systems.
4637
4638 Further, this notation offers no elegant way to specify sizes
4639 that are not even multiples of the ``byte size'' typically
4640 designated by @code{INTEGER*1}.
4641 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
4642 certainly be possible, but would perhaps be stretching the original
4643 intent of this notation beyond the breaking point in terms
4644 of widespread readability of documentation and code making use
4645 of it.
4646
4647 Therefore, this document uses ``star notation'' only on occasion
4648 for the benefit of those readers who are accustomed to it.
4649
4650 @node Kind Notation
4651 @subsubsection Kind Notation
4652 @cindex KIND= notation
4653
4654 The following notation specifies the kind-type selector of a type:
4655
4656 @smallexample
4657 @var{generic-type}(KIND=@var{n})
4658 @end smallexample
4659
4660 @noindent
4661 Use the above form where a type name is valid.
4662
4663 @var{generic-type} must be a generic type---one of
4664 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4665 or @code{CHARACTER}.
4666 @var{n} must be an integer initialization expression that
4667 is a positive, nonzero value.
4668
4669 Programmers are discouraged from writing these values directly
4670 into their code.
4671 Future versions of the GNU Fortran language will offer
4672 facilities that will make the writing of code portable
4673 to @code{g77} @emph{and} Fortran 90 implementations simpler.
4674
4675 However, writing code that ports to existing FORTRAN 77
4676 implementations depends on avoiding the @samp{KIND=} construct.
4677
4678 The @samp{KIND=} construct is thus useful in the context
4679 of GNU Fortran for two reasons:
4680
4681 @itemize @bullet
4682 @item
4683 It provides a means to specify a type in a fashion that
4684 is portable across all GNU Fortran implementations (though
4685 not other FORTRAN 77 and Fortran 90 implementations).
4686
4687 @item
4688 It provides a sort of Rosetta stone for this document to use
4689 to concisely describe the types of various operations and
4690 operands.
4691 @end itemize
4692
4693 The values of @var{n} in the GNU Fortran language are
4694 assigned using a scheme that:
4695
4696 @itemize @bullet
4697 @item
4698 Attempts to maximize the ability of readers
4699 of this document to quickly familiarize themselves
4700 with assignments for popular types
4701
4702 @item
4703 Provides a unique value for each specific desired
4704 meaning
4705
4706 @item
4707 Provides a means to automatically assign new values so
4708 they have a ``natural'' relationship to existing values,
4709 if appropriate, or, if no such relationship exists, will
4710 not interfere with future values assigned on the basis
4711 of such relationships
4712
4713 @item
4714 Avoids using values that are similar to values used
4715 in the existing, popular @samp{*@var{n}} notation,
4716 to prevent readers from expecting that these implied
4717 correspondences work on all GNU Fortran implementations
4718 @end itemize
4719
4720 The assignment system accomplishes this by assigning
4721 to each ``fundamental meaning'' of a specific type a
4722 unique prime number.
4723 Combinations of fundamental meanings---for example, a type
4724 that is two times the size of some other type---are assigned
4725 values of @var{n} that are the products of the values for
4726 those fundamental meanings.
4727
4728 A prime value of @var{n} is never given more than one fundamental
4729 meaning, to avoid situations where some code or system
4730 cannot reasonably provide those meanings in the form of a
4731 single type.
4732
4733 The values of @var{n} assigned so far are:
4734
4735 @table @code
4736 @item KIND=0
4737 This value is reserved for future use.
4738
4739 The planned future use is for this value to designate,
4740 explicitly, context-sensitive kind-type selection.
4741 For example, the expression @samp{1D0 * 0.1_0} would
4742 be equivalent to @samp{1D0 * 0.1D0}.
4743
4744 @item KIND=1
4745 This corresponds to the default types for
4746 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
4747 and @code{CHARACTER}, as appropriate.
4748
4749 These are the ``default'' types described in the Fortran 90 standard,
4750 though that standard does not assign any particular @samp{KIND=}
4751 value to these types.
4752
4753 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
4754 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
4755
4756 @item KIND=2
4757 This corresponds to types that occupy twice as much
4758 storage as the default types.
4759 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
4760 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
4761
4762 These are the ``double precision'' types described in the Fortran 90
4763 standard,
4764 though that standard does not assign any particular @samp{KIND=}
4765 value to these types.
4766
4767 @var{n} of 4 thus corresponds to types that occupy four times
4768 as much storage as the default types, @var{n} of 8 to types that
4769 occupy eight times as much storage, and so on.
4770
4771 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
4772 are not necessarily supported by every GNU Fortran implementation.
4773
4774 @item KIND=3
4775 This corresponds to types that occupy as much
4776 storage as the default @code{CHARACTER} type,
4777 which is the same effective type as @code{CHARACTER(KIND=1)}
4778 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
4779
4780 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
4781
4782 @var{n} of 6 thus corresponds to types that occupy twice as
4783 much storage as the @var{n}=3 types, @var{n} of 12 to types
4784 that occupy four times as much storage, and so on.
4785
4786 These are not necessarily supported by every GNU Fortran
4787 implementation.
4788
4789 @item KIND=5
4790 This corresponds to types that occupy half the
4791 storage as the default (@var{n}=1) types.
4792
4793 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
4794
4795 @var{n} of 25 thus corresponds to types that occupy one-quarter
4796 as much storage as the default types.
4797
4798 These are not necessarily supported by every GNU Fortran
4799 implementation.
4800
4801 @item KIND=7
4802 @cindex pointers
4803 This is valid only as @code{INTEGER(KIND=7)} and
4804 denotes the @code{INTEGER} type that has the smallest
4805 storage size that holds a pointer on the system.
4806
4807 A pointer representable by this type is capable of uniquely
4808 addressing a @code{CHARACTER*1} variable, array, array element,
4809 or substring.
4810
4811 (Typically this is equivalent to @code{INTEGER*4} or,
4812 on 64-bit systems, @code{INTEGER*8}.
4813 In a compatible C implementation, it typically would
4814 be the same size and semantics of the C type @code{void *}.)
4815 @end table
4816
4817 Note that these are @emph{proposed} correspondences and might change
4818 in future versions of @code{g77}---avoid writing code depending
4819 on them while @code{g77}, and therefore the GNU Fortran language
4820 it defines, is in beta testing.
4821
4822 Values not specified in the above list are reserved to
4823 future versions of the GNU Fortran language.
4824
4825 Implementation-dependent meanings will be assigned new,
4826 unique prime numbers so as to not interfere with other
4827 implementation-dependent meanings, and offer the possibility
4828 of increasing the portability of code depending on such
4829 types by offering support for them in other GNU Fortran
4830 implementations.
4831
4832 Other meanings that might be given unique values are:
4833
4834 @itemize @bullet
4835 @item
4836 Types that make use of only half their storage size for
4837 representing precision and range.
4838
4839 For example, some compilers offer options that cause
4840 @code{INTEGER} types to occupy the amount of storage
4841 that would be needed for @code{INTEGER(KIND=2)} types, but the
4842 range remains that of @code{INTEGER(KIND=1)}.
4843
4844 @item
4845 The IEEE single floating-point type.
4846
4847 @item
4848 Types with a specific bit pattern (endianness), such as the
4849 little-endian form of @code{INTEGER(KIND=1)}.
4850 These could permit, conceptually, use of portable code and
4851 implementations on data files written by existing systems.
4852 @end itemize
4853
4854 Future @emph{prime} numbers should be given meanings in as incremental
4855 a fashion as possible, to allow for flexibility and
4856 expressiveness in combining types.
4857
4858 For example, instead of defining a prime number for little-endian
4859 IEEE doubles, one prime number might be assigned the meaning
4860 ``little-endian'', another the meaning ``IEEE double'', and the
4861 value of @var{n} for a little-endian IEEE double would thus
4862 naturally be the product of those two respective assigned values.
4863 (It could even be reasonable to have IEEE values result from the
4864 products of prime values denoting exponent and fraction sizes
4865 and meanings, hidden bit usage, availability and representations
4866 of special values such as subnormals, infinities, and Not-A-Numbers
4867 (NaNs), and so on.)
4868
4869 This assignment mechanism, while not inherently required for
4870 future versions of the GNU Fortran language, is worth using
4871 because it could ease management of the ``space'' of supported
4872 types much easier in the long run.
4873
4874 The above approach suggests a mechanism for specifying inheritance
4875 of intrinsic (built-in) types for an entire, widely portable
4876 product line.
4877 It is certainly reasonable that, unlike programmers of other languages
4878 offering inheritance mechanisms that employ verbose names for classes
4879 and subclasses, along with graphical browsers to elucidate the
4880 relationships, Fortran programmers would employ
4881 a mechanism that works by multiplying prime numbers together
4882 and finding the prime factors of such products.
4883
4884 Most of the advantages for the above scheme have been explained
4885 above.
4886 One disadvantage is that it could lead to the defining,
4887 by the GNU Fortran language, of some fairly large prime numbers.
4888 This could lead to the GNU Fortran language being declared
4889 ``munitions'' by the United States Department of Defense.
4890
4891 @node Constants
4892 @subsection Constants
4893 @cindex constants
4894 @cindex types, constants
4895
4896 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
4897
4898 A @dfn{typeless constant} has one of the following forms:
4899
4900 @smallexample
4901 '@var{binary-digits}'B
4902 '@var{octal-digits}'O
4903 '@var{hexadecimal-digits}'Z
4904 '@var{hexadecimal-digits}'X
4905 @end smallexample
4906
4907 @noindent
4908 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
4909 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
4910 and @samp{0123456789ABCDEFabcdef}, respectively.
4911 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
4912 is 11, and so on.)
4913
4914 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
4915 treated as typeless.  @xref{Fortran Dialect Options,, Options
4916 Controlling Fortran Dialect}, for information on the
4917 @samp{-ftypeless-boz} option.
4918
4919 Typeless constants have values that depend on the context in which
4920 they are used.
4921
4922 All other constants, called @dfn{typed constants}, are interpreted---converted
4923 to internal form---according to their inherent type.
4924 Thus, context is @emph{never} a determining factor for the type, and hence
4925 the interpretation, of a typed constant.
4926 (All constants in the ANSI FORTRAN 77 language are typed constants.)
4927
4928 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
4929 Fortran (called default INTEGER in Fortran 90),
4930 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
4931 additional precision specified is lost, and even when used in a
4932 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
4933 and @samp{1D0} is always type @code{REAL(KIND=2)}.
4934
4935 @node Integer Type
4936 @subsection Integer Type
4937
4938 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
4939
4940 An integer constant also may have one of the following forms:
4941
4942 @smallexample
4943 B'@var{binary-digits}'
4944 O'@var{octal-digits}'
4945 Z'@var{hexadecimal-digits}'
4946 X'@var{hexadecimal-digits}'
4947 @end smallexample
4948
4949 @noindent
4950 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
4951 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
4952 and @samp{0123456789ABCDEFabcdef}, respectively.
4953 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
4954 is 11, and so on.)
4955
4956 @node Character Type
4957 @subsection Character Type
4958
4959 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
4960
4961 @cindex double quoted character constants
4962 A character constant may be delimited by a pair of double quotes
4963 (@samp{"}) instead of apostrophes.
4964 In this case, an apostrophe within the constant represents
4965 a single apostrophe, while a double quote is represented in
4966 the source text of the constant by two consecutive double
4967 quotes with no intervening spaces.
4968
4969 @cindex zero-length CHARACTER
4970 @cindex null CHARACTER strings
4971 @cindex empty CHARACTER strings
4972 @cindex strings, empty
4973 @cindex CHARACTER, null
4974 A character constant may be empty (have a length of zero).
4975
4976 A character constant may include a substring specification,
4977 The value of such a constant is the value of the substring---for
4978 example, the value of @samp{'hello'(3:5)} is the same
4979 as the value of @samp{'llo'}.
4980
4981 @node Expressions
4982 @section Expressions
4983
4984 (The following information augments or overrides the information in
4985 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4986 language.
4987 Chapter 6 of that document otherwise serves as the basis
4988 for the relevant aspects of GNU Fortran.)
4989
4990 @menu
4991 * %LOC()::
4992 @end menu
4993
4994 @node %LOC()
4995 @subsection The @code{%LOC()} Construct
4996 @cindex %LOC() construct
4997
4998 @example
4999 %LOC(@var{arg})
5000 @end example
5001
5002 The @code{%LOC()} construct is an expression
5003 that yields the value of the location of its argument,
5004 @var{arg}, in memory.
5005 The size of the type of the expression depends on the system---typically,
5006 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
5007 though it is actually type @code{INTEGER(KIND=7)}.
5008
5009 The argument to @code{%LOC()} must be suitable as the
5010 left-hand side of an assignment statement.
5011 That is, it may not be a general expression involving
5012 operators such as addition, subtraction, and so on,
5013 nor may it be a constant.
5014
5015 Use of @code{%LOC()} is recommended only for code that
5016 is accessing facilities outside of GNU Fortran, such as
5017 operating system or windowing facilities.
5018 It is best to constrain such uses to isolated portions of
5019 a program---portions that deal specifically and exclusively
5020 with low-level, system-dependent facilities.
5021 Such portions might well provide a portable interface for
5022 use by the program as a whole, but are themselves not
5023 portable, and should be thoroughly tested each time they
5024 are rebuilt using a new compiler or version of a compiler.
5025
5026 Do not depend on @code{%LOC()} returning a pointer that
5027 can be safely used to @emph{define} (change) the argument.
5028 While this might work in some circumstances, it is hard
5029 to predict whether it will continue to work when a program
5030 (that works using this unsafe behavior)
5031 is recompiled using different command-line options or
5032 a different version of @code{g77}.
5033
5034 Generally, @code{%LOC()} is safe when used as an argument
5035 to a procedure that makes use of the value of the corresponding
5036 dummy argument only during its activation, and only when
5037 such use is restricted to referencing (reading) the value
5038 of the argument to @code{%LOC()}.
5039
5040 @emph{Implementation Note:} Currently, @code{g77} passes
5041 arguments (those not passed using a construct such as @code{%VAL()})
5042 by reference or descriptor, depending on the type of
5043 the actual argument.
5044 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
5045 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
5046 in fact might compile to identical code.
5047
5048 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
5049 ``pass, by value, the address of @samp{I} in memory''.
5050 While @samp{CALL FOO(I)} might use that same approach in a
5051 particular version of @code{g77}, another version or compiler
5052 might choose a different implementation, such as copy-in/copy-out,
5053 to effect the desired behavior---and which will therefore not
5054 necessarily compile to the same code as would
5055 @samp{CALL FOO(%VAL(%LOC(I)))}
5056 using the same version or compiler.
5057
5058 @xref{Debugging and Interfacing}, for detailed information on
5059 how this particular version of @code{g77} implements various
5060 constructs.
5061
5062 @node Specification Statements
5063 @section Specification Statements
5064
5065 (The following information augments or overrides the information in
5066 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5067 language.
5068 Chapter 8 of that document otherwise serves as the basis
5069 for the relevant aspects of GNU Fortran.)
5070
5071 @menu
5072 * NAMELIST::
5073 * DOUBLE COMPLEX::
5074 @end menu
5075
5076 @node NAMELIST
5077 @subsection @code{NAMELIST} Statement
5078 @cindex NAMELIST statement
5079 @cindex statements, NAMELIST
5080
5081 The @code{NAMELIST} statement, and related I/O constructs, are
5082 supported by the GNU Fortran language in essentially the same
5083 way as they are by @code{f2c}.
5084
5085 This follows Fortran 90 with the restriction that on @code{NAMELIST}
5086 input, subscripts must have the form
5087 @smallexample
5088 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
5089 @end smallexample
5090 i.e.@:
5091 @smallexample
5092 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
5093 @end smallexample
5094 is allowed, but not, say,
5095 @smallexample
5096 &xx x(:3,8::2)=1,2,3,4,5,6/
5097 @end smallexample
5098
5099 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
5100 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
5101 @smallexample
5102 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
5103 @end smallexample
5104 could be used instead of the example above.
5105
5106 @node DOUBLE COMPLEX
5107 @subsection @code{DOUBLE COMPLEX} Statement
5108 @cindex DOUBLE COMPLEX
5109
5110 @code{DOUBLE COMPLEX} is a type-statement (and type) that
5111 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
5112
5113 @node Control Statements
5114 @section Control Statements
5115
5116 (The following information augments or overrides the information in
5117 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5118 language.
5119 Chapter 11 of that document otherwise serves as the basis
5120 for the relevant aspects of GNU Fortran.)
5121
5122 @menu
5123 * DO WHILE::
5124 * END DO::
5125 * Construct Names::
5126 * CYCLE and EXIT::
5127 @end menu
5128
5129 @node DO WHILE
5130 @subsection DO WHILE
5131 @cindex DO WHILE
5132 @cindex DO
5133 @cindex MIL-STD 1753
5134
5135 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
5136 Fortran 90 standards, is provided by the GNU Fortran language.
5137 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
5138 also supported.
5139
5140 @node END DO
5141 @subsection END DO
5142 @cindex END DO
5143 @cindex MIL-STD 1753
5144
5145 The @code{END DO} statement is provided by the GNU Fortran language.
5146
5147 This statement is used in one of two ways:
5148
5149 @itemize @bullet
5150 @item
5151 The Fortran 90 meaning, in which it specifies the termination
5152 point of a single @code{DO} loop started with a @code{DO} statement
5153 that specifies no termination label.
5154
5155 @item
5156 The MIL-STD 1753 meaning, in which it specifies the termination
5157 point of one or more @code{DO} loops, all of which start with a
5158 @code{DO} statement that specify the label defined for the
5159 @code{END DO} statement.
5160
5161 This kind of @code{END DO} statement is merely a synonym for
5162 @code{CONTINUE}, except it is permitted only when the statement
5163 is labeled and a target of one or more labeled @code{DO} loops.
5164
5165 It is expected that this use of @code{END DO} will be removed from
5166 the GNU Fortran language in the future, though it is likely that
5167 it will long be supported by @code{g77} as a dialect form.
5168 @end itemize
5169
5170 @node Construct Names
5171 @subsection Construct Names
5172 @cindex construct names
5173
5174 The GNU Fortran language supports construct names as defined
5175 by the Fortran 90 standard.
5176 These names are local to the program unit and are defined
5177 as follows:
5178
5179 @smallexample
5180 @var{construct-name}: @var{block-statement}
5181 @end smallexample
5182
5183 @noindent
5184 Here, @var{construct-name} is the construct name itself;
5185 its definition is connoted by the single colon (@samp{:}); and
5186 @var{block-statement} is an @code{IF}, @code{DO},
5187 or @code{SELECT CASE} statement that begins a block.
5188
5189 A block that is given a construct name must also specify the
5190 same construct name in its termination statement:
5191
5192 @example
5193 END @var{block} @var{construct-name}
5194 @end example
5195
5196 @noindent
5197 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
5198 as appropriate.
5199
5200 @node CYCLE and EXIT
5201 @subsection The @code{CYCLE} and @code{EXIT} Statements
5202
5203 @cindex CYCLE statement
5204 @cindex EXIT statement
5205 @cindex statements, CYCLE
5206 @cindex statements, EXIT
5207 The @code{CYCLE} and @code{EXIT} statements specify that
5208 the remaining statements in the current iteration of a
5209 particular active (enclosing) @code{DO} loop are to be skipped.
5210
5211 @code{CYCLE} specifies that these statements are skipped,
5212 but the @code{END DO} statement that marks the end of the
5213 @code{DO} loop be executed---that is, the next iteration,
5214 if any, is to be started.
5215 If the statement marking the end of the @code{DO} loop is
5216 not @code{END DO}---in other words, if the loop is not
5217 a block @code{DO}---the @code{CYCLE} statement does not
5218 execute that statement, but does start the next iteration (if any).
5219
5220 @code{EXIT} specifies that the loop specified by the
5221 @code{DO} construct is terminated.
5222
5223 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
5224 is the innermost enclosing @code{DO} loop when the following
5225 forms are used:
5226
5227 @example
5228 CYCLE
5229 EXIT
5230 @end example
5231
5232 Otherwise, the following forms specify the construct name
5233 of the pertinent @code{DO} loop:
5234
5235 @example
5236 CYCLE @var{construct-name}
5237 EXIT @var{construct-name}
5238 @end example
5239
5240 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
5241 statements.
5242 However, they cannot be easily thought of as @code{GO TO} statements
5243 in obscure cases involving FORTRAN 77 loops.
5244 For example:
5245
5246 @smallexample
5247       DO 10 I = 1, 5
5248       DO 10 J = 1, 5
5249          IF (J .EQ. 5) EXIT
5250       DO 10 K = 1, 5
5251          IF (K .EQ. 3) CYCLE
5252 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
5253 20    CONTINUE
5254 @end smallexample
5255
5256 @noindent
5257 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
5258 above are equivalent to a @code{GO TO} statement to either label
5259 @samp{10} or @samp{20}.
5260
5261 To understand the effect of @code{CYCLE} and @code{EXIT} in the
5262 above fragment, it is helpful to first translate it to its equivalent
5263 using only block @code{DO} loops:
5264
5265 @smallexample
5266       DO I = 1, 5
5267          DO J = 1, 5
5268             IF (J .EQ. 5) EXIT
5269             DO K = 1, 5
5270                IF (K .EQ. 3) CYCLE
5271 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
5272             END DO
5273          END DO
5274       END DO
5275 20    CONTINUE
5276 @end smallexample
5277
5278 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
5279 to @code{GO TO} so they may be more easily understood by programmers
5280 accustomed to FORTRAN coding:
5281
5282 @smallexample
5283       DO I = 1, 5
5284          DO J = 1, 5
5285             IF (J .EQ. 5) GOTO 18
5286             DO K = 1, 5
5287                IF (K .EQ. 3) GO TO 12
5288 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
5289 12          END DO
5290          END DO
5291 18    END DO
5292 20    CONTINUE
5293 @end smallexample
5294
5295 @noindent
5296 Thus, the @code{CYCLE} statement in the innermost loop skips over
5297 the @code{PRINT} statement as it begins the next iteration of the
5298 loop, while the @code{EXIT} statement in the middle loop ends that
5299 loop but @emph{not} the outermost loop.
5300
5301 @node Functions and Subroutines
5302 @section Functions and Subroutines
5303
5304 (The following information augments or overrides the information in
5305 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5306 language.
5307 Chapter 15 of that document otherwise serves as the basis
5308 for the relevant aspects of GNU Fortran.)
5309
5310 @menu
5311 * %VAL()::
5312 * %REF()::
5313 * %DESCR()::
5314 * Generics and Specifics::
5315 * REAL() and AIMAG() of Complex::
5316 * CMPLX() of DOUBLE PRECISION::
5317 * MIL-STD 1753::
5318 * f77/f2c Intrinsics::
5319 * Table of Intrinsic Functions::
5320 @end menu
5321
5322 @node %VAL()
5323 @subsection The @code{%VAL()} Construct
5324 @cindex %VAL() construct
5325
5326 @example
5327 %VAL(@var{arg})
5328 @end example
5329
5330 The @code{%VAL()} construct specifies that an argument,
5331 @var{arg}, is to be passed by value, instead of by reference
5332 or descriptor.
5333
5334 @code{%VAL()} is restricted to actual arguments in
5335 invocations of external procedures.
5336
5337 Use of @code{%VAL()} is recommended only for code that
5338 is accessing facilities outside of GNU Fortran, such as
5339 operating system or windowing facilities.
5340 It is best to constrain such uses to isolated portions of
5341 a program---portions the deal specifically and exclusively
5342 with low-level, system-dependent facilities.
5343 Such portions might well provide a portable interface for
5344 use by the program as a whole, but are themselves not
5345 portable, and should be thoroughly tested each time they
5346 are rebuilt using a new compiler or version of a compiler.
5347
5348 @emph{Implementation Note:} Currently, @code{g77} passes
5349 all arguments either by reference or by descriptor.
5350
5351 Thus, use of @code{%VAL()} tends to be restricted to cases
5352 where the called procedure is written in a language other
5353 than Fortran that supports call-by-value semantics.
5354 (C is an example of such a language.)
5355
5356 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
5357 for detailed information on
5358 how this particular version of @code{g77} passes arguments
5359 to procedures.
5360
5361 @node %REF()
5362 @subsection The @code{%REF()} Construct
5363 @cindex %REF() construct
5364
5365 @example
5366 %REF(@var{arg})
5367 @end example
5368
5369 The @code{%REF()} construct specifies that an argument,
5370 @var{arg}, is to be passed by reference, instead of by
5371 value or descriptor.
5372
5373 @code{%REF()} is restricted to actual arguments in
5374 invocations of external procedures.
5375
5376 Use of @code{%REF()} is recommended only for code that
5377 is accessing facilities outside of GNU Fortran, such as
5378 operating system or windowing facilities.
5379 It is best to constrain such uses to isolated portions of
5380 a program---portions the deal specifically and exclusively
5381 with low-level, system-dependent facilities.
5382 Such portions might well provide a portable interface for
5383 use by the program as a whole, but are themselves not
5384 portable, and should be thoroughly tested each time they
5385 are rebuilt using a new compiler or version of a compiler.
5386
5387 Do not depend on @code{%REF()} supplying a pointer to the
5388 procedure being invoked.
5389 While that is a likely implementation choice, other
5390 implementation choices are available that preserve Fortran
5391 pass-by-reference semantics without passing a pointer to
5392 the argument, @var{arg}.
5393 (For example, a copy-in/copy-out implementation.)
5394
5395 @emph{Implementation Note:} Currently, @code{g77} passes
5396 all arguments
5397 (other than variables and arrays of type @code{CHARACTER})
5398 by reference.
5399 Future versions of, or dialects supported by, @code{g77} might
5400 not pass @code{CHARACTER} functions by reference.
5401
5402 Thus, use of @code{%REF()} tends to be restricted to cases
5403 where @var{arg} is type @code{CHARACTER} but the called
5404 procedure accesses it via a means other than the method
5405 used for Fortran @code{CHARACTER} arguments.
5406
5407 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5408 how this particular version of @code{g77} passes arguments
5409 to procedures.
5410
5411 @node %DESCR()
5412 @subsection The @code{%DESCR()} Construct
5413 @cindex %DESCR() construct
5414
5415 @example
5416 %DESCR(@var{arg})
5417 @end example
5418
5419 The @code{%DESCR()} construct specifies that an argument,
5420 @var{arg}, is to be passed by descriptor, instead of by
5421 value or reference.
5422
5423 @code{%DESCR()} is restricted to actual arguments in
5424 invocations of external procedures.
5425
5426 Use of @code{%DESCR()} is recommended only for code that
5427 is accessing facilities outside of GNU Fortran, such as
5428 operating system or windowing facilities.
5429 It is best to constrain such uses to isolated portions of
5430 a program---portions the deal specifically and exclusively
5431 with low-level, system-dependent facilities.
5432 Such portions might well provide a portable interface for
5433 use by the program as a whole, but are themselves not
5434 portable, and should be thoroughly tested each time they
5435 are rebuilt using a new compiler or version of a compiler.
5436
5437 Do not depend on @code{%DESCR()} supplying a pointer
5438 and/or a length passed by value
5439 to the procedure being invoked.
5440 While that is a likely implementation choice, other
5441 implementation choices are available that preserve the
5442 pass-by-reference semantics without passing a pointer to
5443 the argument, @var{arg}.
5444 (For example, a copy-in/copy-out implementation.)
5445 And, future versions of @code{g77} might change the
5446 way descriptors are implemented, such as passing a
5447 single argument pointing to a record containing the
5448 pointer/length information instead of passing that same
5449 information via two arguments as it currently does.
5450
5451 @emph{Implementation Note:} Currently, @code{g77} passes
5452 all variables and arrays of type @code{CHARACTER}
5453 by descriptor.
5454 Future versions of, or dialects supported by, @code{g77} might
5455 pass @code{CHARACTER} functions by descriptor as well.
5456
5457 Thus, use of @code{%DESCR()} tends to be restricted to cases
5458 where @var{arg} is not type @code{CHARACTER} but the called
5459 procedure accesses it via a means similar to the method
5460 used for Fortran @code{CHARACTER} arguments.
5461
5462 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5463 how this particular version of @code{g77} passes arguments
5464 to procedures.
5465
5466 @node Generics and Specifics
5467 @subsection Generics and Specifics
5468 @cindex generic intrinsics
5469 @cindex intrinsics, generic
5470
5471 The ANSI FORTRAN 77 language defines generic and specific
5472 intrinsics.
5473 In short, the distinctions are:
5474
5475 @itemize @bullet
5476 @item
5477 @emph{Specific} intrinsics have
5478 specific types for their arguments and a specific return
5479 type.
5480
5481 @item
5482 @emph{Generic} intrinsics are treated,
5483 on a case-by-case basis in the program's source code,
5484 as one of several possible specific intrinsics.
5485
5486 Typically, a generic intrinsic has a return type that
5487 is determined by the type of one or more of its arguments.
5488 @end itemize
5489
5490 The GNU Fortran language generalizes these concepts somewhat,
5491 especially by providing intrinsic subroutines and generic
5492 intrinsics that are treated as either a specific intrinsic subroutine
5493 or a specific intrinsic function (e.g. @code{SECOND}).
5494
5495 However, GNU Fortran avoids generalizing this concept to
5496 the point where existing code would be accepted as meaning
5497 something possibly different than what was intended.
5498
5499 For example, @code{ABS} is a generic intrinsic, so all working
5500 code written using @code{ABS} of an @code{INTEGER} argument
5501 expects an @code{INTEGER} return value.
5502 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
5503 argument returns an @code{INTEGER*2} return value.
5504
5505 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
5506 an @code{INTEGER(KIND=1)} argument.
5507 Code that passes something other than an @code{INTEGER(KIND=1)}
5508 argument to @code{IABS} is not valid GNU Fortran code, because
5509 it is not clear what the author intended.
5510
5511 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
5512 is not defined by the GNU Fortran language, because the programmer
5513 might have used that construct to mean any of the following, subtly
5514 different, things:
5515
5516 @itemize @bullet
5517 @item
5518 Convert @samp{J} to @code{INTEGER(KIND=1)} first
5519 (as if @samp{IABS(INT(J))} had been written).
5520
5521 @item
5522 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
5523 (as if @samp{INT(ABS(J))} had been written).
5524
5525 @item
5526 No conversion (as if @samp{ABS(J)} had been written).
5527 @end itemize
5528
5529 The distinctions matter especially when types and values wider than
5530 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
5531 operations performing more ``arithmetic'' than absolute-value, are involved.
5532
5533 The following sample program is not a valid GNU Fortran program, but
5534 might be accepted by other compilers.
5535 If so, the output is likely to be revealing in terms of how a given
5536 compiler treats intrinsics (that normally are specific) when they
5537 are given arguments that do not conform to their stated requirements:
5538
5539 @cindex JCB002 program
5540 @smallexample
5541       PROGRAM JCB002
5542 C Version 1:
5543 C Modified 1999-02-15 (Burley) to delete my email address.
5544 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
5545 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
5546 C
5547 C Version 0:
5548 C Written by James Craig Burley 1997-02-20.
5549 C
5550 C Purpose:
5551 C Determine how compilers handle non-standard IDIM
5552 C on INTEGER*2 operands, which presumably can be
5553 C extrapolated into understanding how the compiler
5554 C generally treats specific intrinsics that are passed
5555 C arguments not of the correct types.
5556 C
5557 C If your compiler implements INTEGER*2 and INTEGER
5558 C as the same type, change all INTEGER*2 below to
5559 C INTEGER*1.
5560 C
5561       INTEGER*2 I0, I4
5562       INTEGER I1, I2, I3
5563       INTEGER*2 ISMALL, ILARGE
5564       INTEGER*2 ITOOLG, ITWO
5565       INTEGER*2 ITMP
5566       LOGICAL L2, L3, L4
5567 C
5568 C Find smallest INTEGER*2 number.
5569 C
5570       ISMALL=0
5571  10   I0 = ISMALL-1
5572       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
5573       ISMALL = I0
5574       GOTO 10
5575  20   CONTINUE
5576 C
5577 C Find largest INTEGER*2 number.
5578 C
5579       ILARGE=0
5580  30   I0 = ILARGE+1
5581       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
5582       ILARGE = I0
5583       GOTO 30
5584  40   CONTINUE
5585 C
5586 C Multiplying by two adds stress to the situation.
5587 C
5588       ITWO = 2
5589 C
5590 C Need a number that, added to -2, is too wide to fit in I*2.
5591 C
5592       ITOOLG = ISMALL
5593 C
5594 C Use IDIM the straightforward way.
5595 C
5596       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
5597 C
5598 C Calculate result for first interpretation.
5599 C
5600       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
5601 C
5602 C Calculate result for second interpretation.
5603 C
5604       ITMP = ILARGE - ISMALL
5605       I3 = (INT (ITMP)) * ITWO + ITOOLG
5606 C
5607 C Calculate result for third interpretation.
5608 C
5609       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
5610 C
5611 C Print results.
5612 C
5613       PRINT *, 'ILARGE=', ILARGE
5614       PRINT *, 'ITWO=', ITWO
5615       PRINT *, 'ITOOLG=', ITOOLG
5616       PRINT *, 'ISMALL=', ISMALL
5617       PRINT *, 'I1=', I1
5618       PRINT *, 'I2=', I2
5619       PRINT *, 'I3=', I3
5620       PRINT *, 'I4=', I4
5621       PRINT *
5622       L2 = (I1 .EQ. I2)
5623       L3 = (I1 .EQ. I3)
5624       L4 = (I1 .EQ. I4)
5625       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
5626          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
5627          STOP
5628       END IF
5629       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
5630          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
5631          STOP
5632       END IF
5633       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
5634          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
5635          STOP
5636       END IF
5637       PRINT *, 'Results need careful analysis.'
5638       END
5639 @end smallexample
5640
5641 No future version of the GNU Fortran language
5642 will likely permit specific intrinsic invocations with wrong-typed
5643 arguments (such as @code{IDIM} in the above example), since
5644 it has been determined that disagreements exist among
5645 many production compilers on the interpretation of
5646 such invocations.
5647 These disagreements strongly suggest that Fortran programmers,
5648 and certainly existing Fortran programs, disagree about the
5649 meaning of such invocations.
5650
5651 The first version of @code{JCB002} didn't accommodate some compilers'
5652 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
5653 @code{INTEGER*2}.
5654 In such a case, these compilers apparently convert both
5655 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
5656 instead of doing an @code{INTEGER*2} subtraction on the
5657 original values in @samp{I1} and @samp{I2}.
5658
5659 However, the results of the careful analyses done on the outputs
5660 of programs compiled by these various compilers show that they
5661 all implement either @samp{Interp 1} or @samp{Interp 2} above.
5662
5663 Specifically, it is believed that the new version of @code{JCB002}
5664 above will confirm that:
5665
5666 @itemize @bullet
5667 @item
5668 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
5669 @code{f77} compilers all implement @samp{Interp 1}.
5670
5671 @item
5672 IRIX 5.3 @code{f77} compiler implements @samp{Interp 2}.
5673
5674 @item
5675 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
5676 and IRIX 6.1 @code{f77} compilers all implement @samp{Interp 3}.
5677 @end itemize
5678
5679 If you get different results than the above for the stated
5680 compilers, or have results for other compilers that might be
5681 worth adding to the above list, please let us know the details
5682 (compiler product, version, machine, results, and so on).
5683
5684 @node REAL() and AIMAG() of Complex
5685 @subsection @code{REAL()} and @code{AIMAG()} of Complex
5686 @cindex @code{Real} intrinsic
5687 @cindex intrinsics, @code{Real}
5688 @cindex @code{AImag} intrinsic
5689 @cindex intrinsics, @code{AImag}
5690
5691 The GNU Fortran language disallows @code{REAL(@var{expr})}
5692 and @code{AIMAG(@var{expr})},
5693 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
5694 except when they are used in the following way:
5695
5696 @example
5697 REAL(REAL(@var{expr}))
5698 REAL(AIMAG(@var{expr}))
5699 @end example
5700
5701 @noindent
5702 The above forms explicitly specify that the desired effect
5703 is to convert the real or imaginary part of @var{expr}, which might
5704 be some @code{REAL} type other than @code{REAL(KIND=1)},
5705 to type @code{REAL(KIND=1)},
5706 and have that serve as the value of the expression.
5707
5708 The GNU Fortran language offers clearly named intrinsics to extract the
5709 real and imaginary parts of a complex entity without any
5710 conversion:
5711
5712 @example
5713 REALPART(@var{expr})
5714 IMAGPART(@var{expr})
5715 @end example
5716
5717 To express the above using typical extended FORTRAN 77,
5718 use the following constructs
5719 (when @var{expr} is @code{COMPLEX(KIND=2)}):
5720
5721 @example
5722 DBLE(@var{expr})
5723 DIMAG(@var{expr})
5724 @end example
5725
5726 The FORTRAN 77 language offers no way
5727 to explicitly specify the real and imaginary parts of a complex expression of
5728 arbitrary type, apparently as a result of requiring support for
5729 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
5730 The concepts of converting an expression to type @code{REAL(KIND=1)} and
5731 of extracting the real part of a complex expression were
5732 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
5733 they happened to have the exact same effect in that language
5734 (due to having only one @code{COMPLEX} type).
5735
5736 @emph{Note:} When @samp{-ff90} is in effect,
5737 @code{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
5738 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
5739 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
5740 treated as @samp{REAL(REALPART(@var{expr}))}.
5741
5742 @xref{Ugly Complex Part Extraction}, for more information.
5743
5744 @node CMPLX() of DOUBLE PRECISION
5745 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
5746 @cindex @code{Cmplx} intrinsic
5747 @cindex intrinsics, @code{Cmplx}
5748
5749 In accordance with Fortran 90 and at least some (perhaps all)
5750 other compilers, the GNU Fortran language defines @code{CMPLX()}
5751 as always returning a result that is type @code{COMPLEX(KIND=1)}.
5752
5753 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
5754 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
5755
5756 @example
5757 CMPLX(SNGL(D1), SNGL(D2))
5758 @end example
5759
5760 (It was necessary for Fortran 90 to specify this behavior
5761 for @code{DOUBLE PRECISION} arguments, since that is
5762 the behavior mandated by FORTRAN 77.)
5763
5764 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
5765 which is provided by some FORTRAN 77 compilers to construct
5766 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
5767 operands.
5768 However, this solution does not scale well when more @code{COMPLEX} types
5769 (having various precisions and ranges) are offered by Fortran implementations.
5770
5771 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
5772 an extra argument used to specify the desired kind of complex
5773 result.
5774 However, this solution is somewhat awkward to use, and
5775 @code{g77} currently does not support it.
5776
5777 The GNU Fortran language provides a simple way to build a complex
5778 value out of two numbers, with the precise type of the value
5779 determined by the types of the two numbers (via the usual
5780 type-promotion mechanism):
5781
5782 @example
5783 COMPLEX(@var{real}, @var{imag})
5784 @end example
5785
5786 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
5787 performs no conversion other than to put them together to form a
5788 complex result of the same (complex version of real) type.
5789
5790 @xref{Complex Intrinsic}, for more information.
5791
5792 @node MIL-STD 1753
5793 @subsection MIL-STD 1753 Support
5794 @cindex MIL-STD 1753
5795
5796 The GNU Fortran language includes the MIL-STD 1753 intrinsics
5797 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
5798 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
5799 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
5800
5801 @node f77/f2c Intrinsics
5802 @subsection @code{f77}/@code{f2c} Intrinsics
5803
5804 The bit-manipulation intrinsics supported by traditional
5805 @code{f77} and by @code{f2c} are available in the GNU Fortran language.
5806 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
5807 and @code{XOR}.
5808
5809 Also supported are the intrinsics @code{CDABS},
5810 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
5811 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
5812 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
5813 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
5814 and @code{ZSQRT}.
5815
5816 @node Table of Intrinsic Functions
5817 @subsection Table of Intrinsic Functions
5818 @cindex intrinsics, table of
5819 @cindex table of intrinsics
5820
5821 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
5822
5823 The GNU Fortran language adds various functions, subroutines, types,
5824 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
5825 The complete set of intrinsics supported by the GNU Fortran language
5826 is described below.
5827
5828 Note that a name is not treated as that of an intrinsic if it is
5829 specified in an @code{EXTERNAL} statement in the same program unit;
5830 if a command-line option is used to disable the groups to which
5831 the intrinsic belongs; or if the intrinsic is not named in an
5832 @code{INTRINSIC} statement and a command-line option is used to
5833 hide the groups to which the intrinsic belongs.
5834
5835 So, it is recommended that any reference in a program unit to
5836 an intrinsic procedure that is not a standard FORTRAN 77
5837 intrinsic be accompanied by an appropriate @code{INTRINSIC}
5838 statement in that program unit.
5839 This sort of defensive programming makes it more
5840 likely that an implementation will issue a diagnostic rather
5841 than generate incorrect code for such a reference.
5842
5843 The terminology used below is based on that of the Fortran 90
5844 standard, so that the text may be more concise and accurate:
5845
5846 @itemize @bullet
5847 @item
5848 @code{OPTIONAL} means the argument may be omitted.
5849
5850 @item
5851 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
5852 (generally named @samp{A}) may be specified.
5853
5854 @item
5855 @samp{scalar} means the argument must not be an array (must
5856 be a variable or array element, or perhaps a constant if expressions
5857 are permitted).
5858
5859 @item
5860 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
5861
5862 @item
5863 @code{INTENT(IN)} means the argument must be an expression
5864 (such as a constant or a variable that is defined upon invocation
5865 of the intrinsic).
5866
5867 @item
5868 @code{INTENT(OUT)} means the argument must be definable by the
5869 invocation of the intrinsic (that is, must not be a constant nor
5870 an expression involving operators other than array reference and
5871 substring reference).
5872
5873 @item
5874 @code{INTENT(INOUT)} means the argument must be defined prior to,
5875 and definable by, invocation of the intrinsic (a combination of
5876 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
5877
5878 @item
5879 @xref{Kind Notation}, for an explanation of @code{KIND}.
5880 @end itemize
5881
5882 @ifinfo
5883 (Note that the empty lines appearing in the menu below
5884 are not intentional---they result from a bug in the
5885 GNU @code{makeinfo} program@dots{}a program that, if it
5886 did not exist, would leave this document in far worse shape!)
5887 @end ifinfo
5888
5889 @c The actual documentation for intrinsics comes from
5890 @c intdoc.texi, which in turn is automatically generated
5891 @c from the internal g77 tables in intrin.def _and_ the
5892 @c largely hand-written text in intdoc.h.  So, if you want
5893 @c to change or add to existing documentation on intrinsics,
5894 @c you probably want to edit intdoc.h.
5895 @c
5896 @set familyF77
5897 @set familyGNU
5898 @set familyASC
5899 @set familyMIL
5900 @set familyF90
5901 @clear familyVXT
5902 @clear familyFVZ
5903 @set familyF2C
5904 @set familyF2U
5905 @clear familyBADU77
5906 @include intdoc.texi
5907
5908 @node Scope and Classes of Names
5909 @section Scope and Classes of Symbolic Names
5910 @cindex symbol names, scope and classes
5911 @cindex scope
5912
5913 (The following information augments or overrides the information in
5914 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5915 language.
5916 Chapter 18 of that document otherwise serves as the basis
5917 for the relevant aspects of GNU Fortran.)
5918
5919 @menu
5920 * Underscores in Symbol Names::
5921 @end menu
5922
5923 @node Underscores in Symbol Names
5924 @subsection Underscores in Symbol Names
5925 @cindex underscore
5926
5927 Underscores (@samp{_}) are accepted in symbol names after the first
5928 character (which must be a letter).
5929
5930 @node I/O
5931 @section I/O
5932
5933 @cindex dollar sign
5934 A dollar sign at the end of an output format specification suppresses
5935 the newline at the end of the output.
5936
5937 @cindex <> edit descriptor
5938 @cindex edit descriptor, <>
5939 Edit descriptors in @code{FORMAT} statements may contain compile-time
5940 @code{INTEGER} constant expressions in angle brackets, such as
5941 @smallexample
5942 10    FORMAT (I<WIDTH>)
5943 @end smallexample
5944
5945 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
5946
5947 These Fortran 90 features are supported:
5948 @itemize @bullet
5949 @item
5950 @cindex FORMAT descriptors
5951 @cindex Z edit descriptor
5952 @cindex edit descriptor, Z
5953 @cindex O edit descriptor
5954 @cindex edit descriptor, O
5955 The @code{O} and @code{Z} edit descriptors are supported for I/O of
5956 integers in octal and hexadecimal formats, respectively.
5957 @item
5958 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
5959 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
5960 specifier is supported.
5961 @end itemize
5962
5963 @node Fortran 90 Features
5964 @section Fortran 90 Features
5965 @cindex Fortran 90
5966 @cindex extensions, from Fortran 90
5967
5968 For convenience this section collects a list (probably incomplete) of
5969 the Fortran 90 features supported by the GNU Fortran language, even if
5970 they are documented elsewhere.
5971 @xref{Characters Lines Sequence,,@asis{Characters, Lines, and Execution Sequence}},
5972 for information on additional fixed source form lexical issues.
5973 @cindex @samp{-ffree-form}
5974 Further, the free source form is supported through the
5975 @samp{-ffree-form} option.
5976 @cindex @samp{-ff90}
5977 Other Fortran 90 features can be turned on by the @samp{-ff90} option;
5978 see @ref{Fortran 90}.
5979 For information on the Fortran 90 intrinsics available,
5980 see @ref{Table of Intrinsic Functions}.
5981
5982 @table @asis
5983 @item Automatic arrays in procedures
5984 @item Character assignments
5985 @cindex character assignments
5986 In character assignments, the variable being assigned may occur on the
5987 right hand side of the assignment.
5988 @item Character strings
5989 @cindex double quoted character constants
5990 Strings may have zero length and substrings of character constants are
5991 permitted.  Character constants may be enclosed in double quotes
5992 (@code{"}) as well as single quotes.  @xref{Character Type}.
5993 @item Construct names
5994 (Symbolic tags on blocks.)  @xref{Construct Names}.
5995 @item @code{CYCLE} and @code{EXIT}
5996 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
5997 @item @code{DOUBLE COMPLEX}
5998 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement}.
5999 @item @code{DO WHILE}
6000 @xref{DO WHILE}.
6001 @item @code{END} decoration
6002 @xref{Statements}.
6003 @item @code{END DO}
6004 @xref{END DO}.
6005 @item @code{KIND}
6006 @item @code{IMPLICIT NONE}
6007 @item @code{INCLUDE} statements
6008 @xref{INCLUDE}.
6009 @item List-directed and namelist I/O on internal files
6010 @item Binary, octal and hexadecimal constants
6011 These are supported more generally than required by Fortran 90.
6012 @xref{Integer Type}.
6013 @item @samp{O} and @samp{Z} edit descriptors
6014 @item @code{NAMELIST}
6015 @xref{NAMELIST}.
6016 @item @code{OPEN} specifiers
6017 @code{STATUS='REPLACE'} is supported.
6018 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6019 @code{STATUS='SCRATCH'} is supplied.
6020 @item @code{FORMAT} edit descriptors
6021 @cindex FORMAT descriptors
6022 @cindex Z edit descriptor
6023 @cindex edit descriptor, Z
6024 The @code{Z} edit descriptor is supported.
6025 @item Relational operators
6026 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
6027 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
6028 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
6029 @item @code{SELECT CASE}
6030 Not fully implemented.
6031 @xref{SELECT CASE on CHARACTER Type,, @code{SELECT CASE} on @code{CHARACTER} Type}.
6032 @item Specification statements
6033 A limited subset of the Fortran 90 syntax and semantics for variable
6034 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
6035 (@code{KIND} is of limited usefulness in the absence of the
6036 @code{KIND}-related intrinsics, since these intrinsics permit writing
6037 more widely portable code.)  An example of supported @code{KIND} usage
6038 is:
6039 @smallexample
6040 INTEGER (KIND=1) :: FOO=1, BAR=2
6041 CHARACTER (LEN=3) FOO
6042 @end smallexample
6043 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
6044 @end table
6045
6046 @node Other Dialects
6047 @chapter Other Dialects
6048
6049 GNU Fortran supports a variety of features that are not
6050 considered part of the GNU Fortran language itself, but
6051 are representative of various dialects of Fortran that
6052 @code{g77} supports in whole or in part.
6053
6054 Any of the features listed below might be disallowed by
6055 @code{g77} unless some command-line option is specified.
6056 Currently, some of the features are accepted using the
6057 default invocation of @code{g77}, but that might change
6058 in the future.
6059
6060 @emph{Note: This portion of the documentation definitely needs a lot
6061 of work!}
6062
6063 @menu
6064 * Source Form::       Details of fixed-form and free-form source.
6065 * Trailing Comment::  Use of @samp{/*} to start a comment.
6066 * Debug Line::        Use of @samp{D} in column 1.
6067 * Dollar Signs::      Use of @samp{$} in symbolic names.
6068 * Case Sensitivity::  Uppercase and lowercase in source files.
6069 * VXT Fortran::       @dots{}versus the GNU Fortran language.
6070 * Fortran 90::        @dots{}versus the GNU Fortran language.
6071 * Pedantic Compilation::  Enforcing the standard.
6072 * Distensions::       Misfeatures supported by GNU Fortran.
6073 @end menu
6074
6075 @node Source Form
6076 @section Source Form
6077 @cindex source file format
6078 @cindex source format
6079 @cindex file, source
6080 @cindex source code
6081 @cindex code, source
6082 @cindex fixed form
6083 @cindex free form
6084
6085 GNU Fortran accepts programs written in either fixed form or
6086 free form.
6087
6088 Fixed form
6089 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
6090 allowing tabs) and Fortran 90's fixed form.
6091
6092 Free form corresponds to
6093 Fortran 90's free form (though possibly not entirely up-to-date, and
6094 without complaining about some things that for which Fortran 90 requires
6095 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
6096
6097 The way a Fortran compiler views source files depends entirely on the
6098 implementation choices made for the compiler, since those choices
6099 are explicitly left to the implementation by the published Fortran
6100 standards.
6101 GNU Fortran currently tries to be somewhat like a few popular compilers
6102 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
6103 definition along with more
6104 flexibility offered by command-line options is likely to be offered
6105 in version 0.6.
6106
6107 This section describes how @code{g77} interprets source lines.
6108
6109 @menu
6110 * Carriage Returns::  Carriage returns ignored.
6111 * Tabs::              Tabs converted to spaces.
6112 * Short Lines::       Short lines padded with spaces (fixed-form only).
6113 * Long Lines::        Long lines truncated.
6114 * Ampersands::        Special Continuation Lines.
6115 @end menu
6116
6117 @node Carriage Returns
6118 @subsection Carriage Returns
6119 @cindex carriage returns
6120
6121 Carriage returns (@samp{\r}) in source lines are ignored.
6122 This is somewhat different from @code{f2c}, which seems to treat them as
6123 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
6124 inside such constants.
6125
6126 @node Tabs
6127 @subsection Tabs
6128 @cindex tab character
6129 @cindex horizontal tab
6130
6131 A source line with a @key{TAB} character anywhere in it is treated as
6132 entirely significant---however long it is---instead of ending in
6133 column 72 (for fixed-form source) or 132 (for free-form source).
6134 This also is different from @code{f2c}, which encodes tabs as
6135 @samp{\t} (the ASCII @key{TAB} character) inside character
6136 and Hollerith constants, but nevertheless seems to treat the column
6137 position as if it had been affected by the canonical tab positioning.
6138
6139 @code{g77} effectively
6140 translates tabs to the appropriate number of spaces (a la the default
6141 for the UNIX @code{expand} command) before doing any other processing, other
6142 than (currently) noting whether a tab was found on a line and using this
6143 information to decide how to interpret the length of the line and continued
6144 constants.
6145
6146 Note that this default behavior probably will change for version 0.6,
6147 when it will presumably be available via a command-line option.
6148 The default as of version 0.6 is planned to be a ``pure visual''
6149 model, where tabs are immediately
6150 converted to spaces and otherwise have no effect, so the way a typical
6151 user sees source lines produces a consistent result no matter how the
6152 spacing in those source lines is actually implemented via tabs, spaces,
6153 and trailing tabs/spaces before newline.
6154 Command-line options are likely to be added to specify whether all or
6155 just-tabbed lines are to be extended to 132 or full input-line length,
6156 and perhaps even an option will be added to specify the truncated-line
6157 behavior to which some Digital compilers default (and which affects
6158 the way continued character/Hollerith constants are interpreted).
6159
6160 @node Short Lines
6161 @subsection Short Lines
6162 @cindex short source lines
6163 @cindex space, padding with
6164 @cindex source lines, short
6165 @cindex lines, short
6166
6167 Source lines shorter than the applicable fixed-form length are treated as
6168 if they were padded with spaces to that length.
6169 (None of this is relevant to source files written in free form.)
6170
6171 This affects only
6172 continued character and Hollerith constants, and is a different
6173 interpretation than provided by some other popular compilers
6174 (although a bit more consistent with the traditional punched-card
6175 basis of Fortran and the way the Fortran standard expressed fixed
6176 source form).
6177
6178 @code{g77} might someday offer an option to warn about cases where differences
6179 might be seen as a result of this treatment, and perhaps an option to
6180 specify the alternate behavior as well.
6181
6182 Note that this padding cannot apply to lines that are effectively of
6183 infinite length---such lines are specified using command-line options
6184 like @samp{-ffixed-line-length-none}, for example.
6185
6186 @node Long Lines
6187 @subsection Long Lines
6188 @cindex long source lines
6189 @cindex truncation, of long lines
6190 @cindex lines, long
6191 @cindex source lines, long
6192
6193 Source lines longer than the applicable length are truncated to that
6194 length.
6195 Currently, @code{g77} does not warn if the truncated characters are
6196 not spaces, to accommodate existing code written for systems that
6197 treated truncated text as commentary (especially in columns 73 through 80).
6198
6199 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
6200 for information on the @samp{-ffixed-line-length-@var{n}} option,
6201 which can be used to set the line length applicable to fixed-form
6202 source files.
6203
6204 @node Ampersands
6205 @subsection Ampersand Continuation Line
6206 @cindex ampersand continuation line
6207 @cindex continuation line, ampersand
6208
6209 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
6210 continuation line, imitating the behavior of @code{f2c}.
6211
6212 @node Trailing Comment
6213 @section Trailing Comment
6214
6215 @cindex trailing comment
6216 @cindex comment
6217 @cindex characters, comment
6218 @cindex /*
6219 @cindex !
6220 @cindex exclamation point
6221 @code{g77} supports use of @samp{/*} to start a trailing
6222 comment.
6223 In the GNU Fortran language, @samp{!} is used for this purpose.
6224
6225 @samp{/*} is not in the GNU Fortran language
6226 because the use of @samp{/*} in a program might
6227 suggest to some readers that a block, not trailing, comment is
6228 started (and thus ended by @samp{*/}, not end of line),
6229 since that is the meaning of @samp{/*} in C.
6230
6231 Also, such readers might think they can use @samp{//} to start
6232 a trailing comment as an alternative to @samp{/*}, but
6233 @samp{//} already denotes concatenation, and such a ``comment''
6234 might actually result in a program that compiles without
6235 error (though it would likely behave incorrectly).
6236
6237 @node Debug Line
6238 @section Debug Line
6239 @cindex debug line
6240 @cindex comment line, debug
6241
6242 Use of @samp{D} or @samp{d} as the first character (column 1) of
6243 a source line denotes a debug line.
6244
6245 In turn, a debug line is treated as either a comment line
6246 or a normal line, depending on whether debug lines are enabled.
6247
6248 When treated as a comment line, a line beginning with @samp{D} or
6249 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
6250 When treated as a normal line, such a line is treated as if
6251 the first character was @key{SPC} (space).
6252
6253 (Currently, @code{g77} provides no means for treating debug
6254 lines as normal lines.)
6255
6256 @node Dollar Signs
6257 @section Dollar Signs in Symbol Names
6258 @cindex dollar sign
6259 @cindex $
6260
6261 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
6262 when the @samp{-fdollar-ok} option is specified.
6263
6264 @node Case Sensitivity
6265 @section Case Sensitivity
6266 @cindex case sensitivity
6267 @cindex source file format
6268 @cindex code, source
6269 @cindex source code
6270 @cindex uppercase letters
6271 @cindex lowercase letters
6272 @cindex letters, uppercase
6273 @cindex letters, lowercase
6274
6275 GNU Fortran offers the programmer way too much flexibility in deciding
6276 how source files are to be treated vis-a-vis uppercase and lowercase
6277 characters.
6278 There are 66 useful settings that affect case sensitivity, plus 10
6279 settings that are nearly useless, with the remaining 116 settings
6280 being either redundant or useless.
6281
6282 None of these settings have any effect on the contents of comments
6283 (the text after a @samp{c} or @samp{C} in Column 1, for example)
6284 or of character or Hollerith constants.
6285 Note that things like the @samp{E} in the statement
6286 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
6287 are considered built-in keywords, and so are affected by
6288 these settings.
6289
6290 Low-level switches are identified in this section as follows:
6291
6292 @itemize @w{}
6293 @item A
6294 Source Case Conversion:
6295
6296 @itemize @w{}
6297 @item 0
6298 Preserve (see Note 1)
6299 @item 1
6300 Convert to Upper Case
6301 @item 2
6302 Convert to Lower Case
6303 @end itemize
6304
6305 @item B
6306 Built-in Keyword Matching:
6307
6308 @itemize @w{}
6309 @item 0
6310 Match Any Case (per-character basis)
6311 @item 1
6312 Match Upper Case Only
6313 @item 2
6314 Match Lower Case Only
6315 @item 3
6316 Match InitialCaps Only (see tables for spellings)
6317 @end itemize
6318
6319 @item C
6320 Built-in Intrinsic Matching:
6321
6322 @itemize @w{}
6323 @item 0
6324 Match Any Case (per-character basis)
6325 @item 1
6326 Match Upper Case Only
6327 @item 2
6328 Match Lower Case Only
6329 @item 3
6330 Match InitialCaps Only (see tables for spellings)
6331 @end itemize
6332
6333 @item D
6334 User-defined Symbol Possibilities (warnings only):
6335
6336 @itemize @w{}
6337 @item 0
6338 Allow Any Case (per-character basis)
6339 @item 1
6340 Allow Upper Case Only
6341 @item 2
6342 Allow Lower Case Only
6343 @item 3
6344 Allow InitialCaps Only (see Note 2)
6345 @end itemize
6346 @end itemize
6347
6348 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
6349 consistent with these source switches---in the sense that input will be
6350 expected to meet the same requirements as source code in terms
6351 of matching symbol names and keywords (for the exponent letters).
6352
6353 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
6354 which uppercases @code{NAMELIST} input and symbol names for matching.
6355 This means not only that @code{NAMELIST} output currently shows symbol
6356 (and keyword) names in uppercase even if lower-case source
6357 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
6358 adequately supported when source case preservation (option A0)
6359 is selected.
6360
6361 If A0 is selected, a warning message will be
6362 output for each @code{NAMELIST} statement to this effect.
6363 The behavior
6364 of the program is undefined at run time if two or more symbol names
6365 appear in a given @code{NAMELIST} such that the names are identical
6366 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
6367 For complete and total elegance, perhaps there should be a warning
6368 when option A2 is selected, since the output of NAMELIST is currently
6369 in uppercase but will someday be lowercase (when a @code{libg77} is written),
6370 but that seems to be overkill for a product in beta test.
6371
6372 Note 2: Rules for InitialCaps names are:
6373
6374 @itemize @minus
6375 @item
6376 Must be a single uppercase letter, @strong{or}
6377 @item
6378 Must start with an uppercase letter and contain at least one
6379 lowercase letter.
6380 @end itemize
6381
6382 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
6383 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
6384 not.
6385 Note that most, but not all, built-in names meet these
6386 requirements---the exceptions are some of the two-letter format
6387 specifiers, such as @code{BN} and @code{BZ}.
6388
6389 Here are the names of the corresponding command-line options:
6390
6391 @smallexample
6392 A0: -fsource-case-preserve
6393 A1: -fsource-case-upper
6394 A2: -fsource-case-lower
6395
6396 B0: -fmatch-case-any
6397 B1: -fmatch-case-upper
6398 B2: -fmatch-case-lower
6399 B3: -fmatch-case-initcap
6400
6401 C0: -fintrin-case-any
6402 C1: -fintrin-case-upper
6403 C2: -fintrin-case-lower
6404 C3: -fintrin-case-initcap
6405
6406 D0: -fsymbol-case-any
6407 D1: -fsymbol-case-upper
6408 D2: -fsymbol-case-lower
6409 D3: -fsymbol-case-initcap
6410 @end smallexample
6411
6412 Useful combinations of the above settings, along with abbreviated
6413 option names that set some of these combinations all at once:
6414
6415 @smallexample
6416  1: A0--  B0---  C0---  D0---    -fcase-preserve
6417  2: A0--  B0---  C0---  D-1--
6418  3: A0--  B0---  C0---  D--2-
6419  4: A0--  B0---  C0---  D---3
6420  5: A0--  B0---  C-1--  D0---
6421  6: A0--  B0---  C-1--  D-1--
6422  7: A0--  B0---  C-1--  D--2-
6423  8: A0--  B0---  C-1--  D---3
6424  9: A0--  B0---  C--2-  D0---
6425 10: A0--  B0---  C--2-  D-1--
6426 11: A0--  B0---  C--2-  D--2-
6427 12: A0--  B0---  C--2-  D---3
6428 13: A0--  B0---  C---3  D0---
6429 14: A0--  B0---  C---3  D-1--
6430 15: A0--  B0---  C---3  D--2-
6431 16: A0--  B0---  C---3  D---3
6432 17: A0--  B-1--  C0---  D0---
6433 18: A0--  B-1--  C0---  D-1--
6434 19: A0--  B-1--  C0---  D--2-
6435 20: A0--  B-1--  C0---  D---3
6436 21: A0--  B-1--  C-1--  D0---
6437 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
6438 23: A0--  B-1--  C-1--  D--2-
6439 24: A0--  B-1--  C-1--  D---3
6440 25: A0--  B-1--  C--2-  D0---
6441 26: A0--  B-1--  C--2-  D-1--
6442 27: A0--  B-1--  C--2-  D--2-
6443 28: A0--  B-1--  C--2-  D---3
6444 29: A0--  B-1--  C---3  D0---
6445 30: A0--  B-1--  C---3  D-1--
6446 31: A0--  B-1--  C---3  D--2-
6447 32: A0--  B-1--  C---3  D---3
6448 33: A0--  B--2-  C0---  D0---
6449 34: A0--  B--2-  C0---  D-1--
6450 35: A0--  B--2-  C0---  D--2-
6451 36: A0--  B--2-  C0---  D---3
6452 37: A0--  B--2-  C-1--  D0---
6453 38: A0--  B--2-  C-1--  D-1--
6454 39: A0--  B--2-  C-1--  D--2-
6455 40: A0--  B--2-  C-1--  D---3
6456 41: A0--  B--2-  C--2-  D0---
6457 42: A0--  B--2-  C--2-  D-1--
6458 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
6459 44: A0--  B--2-  C--2-  D---3
6460 45: A0--  B--2-  C---3  D0---
6461 46: A0--  B--2-  C---3  D-1--
6462 47: A0--  B--2-  C---3  D--2-
6463 48: A0--  B--2-  C---3  D---3
6464 49: A0--  B---3  C0---  D0---
6465 50: A0--  B---3  C0---  D-1--
6466 51: A0--  B---3  C0---  D--2-
6467 52: A0--  B---3  C0---  D---3
6468 53: A0--  B---3  C-1--  D0---
6469 54: A0--  B---3  C-1--  D-1--
6470 55: A0--  B---3  C-1--  D--2-
6471 56: A0--  B---3  C-1--  D---3
6472 57: A0--  B---3  C--2-  D0---
6473 58: A0--  B---3  C--2-  D-1--
6474 59: A0--  B---3  C--2-  D--2-
6475 60: A0--  B---3  C--2-  D---3
6476 61: A0--  B---3  C---3  D0---
6477 62: A0--  B---3  C---3  D-1--
6478 63: A0--  B---3  C---3  D--2-
6479 64: A0--  B---3  C---3  D---3    -fcase-initcap
6480 65: A-1-  B01--  C01--  D01--    -fcase-upper
6481 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
6482 @end smallexample
6483
6484 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
6485 (except comments, character constants, and Hollerith strings) must
6486 be entered in uppercase.
6487 Use @samp{-fcase-strict-upper} to specify this
6488 combination.
6489
6490 Number 43 is like Number 22 except all input must be lowercase.  Use
6491 @samp{-fcase-strict-lower} to specify this combination.
6492
6493 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
6494 non-UNIX machines whereby all the source is translated to uppercase.
6495 Use @samp{-fcase-upper} to specify this combination.
6496
6497 Number 66 is the ``canonical'' UNIX model whereby all the source is
6498 translated to lowercase.
6499 Use @samp{-fcase-lower} to specify this combination.
6500
6501 There are a few nearly useless combinations:
6502
6503 @smallexample
6504 67: A-1-  B01--  C01--  D--2-
6505 68: A-1-  B01--  C01--  D---3
6506 69: A-1-  B01--  C--23  D01--
6507 70: A-1-  B01--  C--23  D--2-
6508 71: A-1-  B01--  C--23  D---3
6509 72: A--2  B01--  C0-2-  D-1--
6510 73: A--2  B01--  C0-2-  D---3
6511 74: A--2  B01--  C-1-3  D0-2-
6512 75: A--2  B01--  C-1-3  D-1--
6513 76: A--2  B01--  C-1-3  D---3
6514 @end smallexample
6515
6516 The above allow some programs to be compiled but with restrictions that
6517 make most useful programs impossible: Numbers 67 and 72 warn about
6518 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
6519 Numbers
6520 68 and 73 warn about any user-defined symbol names longer than one
6521 character that don't have at least one non-alphabetic character after
6522 the first;
6523 Numbers 69 and 74 disallow any references to intrinsics;
6524 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
6525 67+69, 68+69, 72+74, and 73+74, respectively.
6526
6527 All redundant combinations are shown in the above tables anyplace
6528 where more than one setting is shown for a low-level switch.
6529 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
6530 The ``proper'' setting in such a case is the one that copies the setting
6531 of switch A---any other setting might slightly reduce the speed of
6532 the compiler, though possibly to an unmeasurable extent.
6533
6534 All remaining combinations are useless in that they prevent successful
6535 compilation of non-null source files (source files with something other
6536 than comments).
6537
6538 @node VXT Fortran
6539 @section VXT Fortran
6540
6541 @cindex VXT extensions
6542 @cindex extensions, VXT
6543 @code{g77} supports certain constructs that
6544 have different meanings in VXT Fortran than they
6545 do in the GNU Fortran language.
6546
6547 Generally, this manual uses the invented term VXT Fortran to refer
6548 VAX FORTRAN (circa v4).
6549 That compiler offered many popular features, though not necessarily
6550 those that are specific to the VAX processor architecture,
6551 the VMS operating system,
6552 or Digital Equipment Corporation's Fortran product line.
6553 (VAX and VMS probably are trademarks of Digital Equipment
6554 Corporation.)
6555
6556 An extension offered by a Digital Fortran product that also is
6557 offered by several other Fortran products for different kinds of
6558 systems is probably going to be considered for inclusion in @code{g77}
6559 someday, and is considered a VXT Fortran feature.
6560
6561 The @samp{-fvxt} option generally specifies that, where
6562 the meaning of a construct is ambiguous (means one thing
6563 in GNU Fortran and another in VXT Fortran), the VXT Fortran
6564 meaning is to be assumed.
6565
6566 @menu
6567 * Double Quote Meaning::  @samp{"2000} as octal constant.
6568 * Exclamation Point::     @samp{!} in column 6.
6569 @end menu
6570
6571 @node Double Quote Meaning
6572 @subsection Meaning of Double Quote
6573 @cindex double quotes
6574 @cindex character constants
6575 @cindex constants, character
6576 @cindex octal constants
6577 @cindex constants, octal
6578
6579 @code{g77} treats double-quote (@samp{"})
6580 as beginning an octal constant of @code{INTEGER(KIND=1)} type
6581 when the @samp{-fvxt} option is specified.
6582 The form of this octal constant is
6583
6584 @example
6585 "@var{octal-digits}
6586 @end example
6587
6588 @noindent
6589 where @var{octal-digits} is a nonempty string of characters in
6590 the set @samp{01234567}.
6591
6592 For example, the @samp{-fvxt} option permits this:
6593
6594 @example
6595 PRINT *, "20
6596 END
6597 @end example
6598
6599 @noindent
6600 The above program would print the value @samp{16}.
6601
6602 @xref{Integer Type}, for information on the preferred construct
6603 for integer constants specified using GNU Fortran's octal notation.
6604
6605 (In the GNU Fortran language, the double-quote character (@samp{"})
6606 delimits a character constant just as does apostrophe (@samp{'}).
6607 There is no way to allow
6608 both constructs in the general case, since statements like
6609 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
6610
6611 @node Exclamation Point
6612 @subsection Meaning of Exclamation Point in Column 6
6613 @cindex !
6614 @cindex exclamation point
6615 @cindex continuation character
6616 @cindex characters, continuation
6617 @cindex comment character
6618 @cindex characters, comment
6619
6620 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
6621 a fixed-form source file
6622 as a continuation character rather than
6623 as the beginning of a comment
6624 (as it does in any other column)
6625 when the @samp{-fvxt} option is specified.
6626
6627 The following program, when run, prints a message indicating
6628 whether it is interpreted according to GNU Fortran (and Fortran 90)
6629 rules or VXT Fortran rules:
6630
6631 @smallexample
6632 C234567  (This line begins in column 1.)
6633       I = 0
6634      !1
6635       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
6636       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
6637       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
6638       END
6639 @end smallexample
6640
6641 (In the GNU Fortran and Fortran 90 languages, exclamation point is
6642 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
6643 marks a line as a continuation line when it appears in column 6.)
6644
6645 @node Fortran 90
6646 @section Fortran 90
6647 @cindex compatibility, Fortran 90
6648 @cindex Fortran 90, compatibility
6649
6650 The GNU Fortran language includes a number of features that are
6651 part of Fortran 90, even when the @samp{-ff90} option is not specified.
6652 The features enabled by @samp{-ff90} are intended to be those that,
6653 when @samp{-ff90} is not specified, would have another
6654 meaning to @code{g77}---usually meaning something invalid in the
6655 GNU Fortran language.
6656
6657 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
6658 to gratuitously reject Fortran 90 constructs.
6659 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
6660 to do that, although its implementation is certainly incomplete at
6661 this point.
6662
6663 When @samp{-ff90} is specified:
6664
6665 @itemize @bullet
6666 @item
6667 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
6668 where @var{expr} is @code{COMPLEX} type,
6669 is the same type as the real part of @var{expr}.
6670
6671 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
6672 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
6673 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
6674 @end itemize
6675
6676 @node Pedantic Compilation
6677 @section Pedantic Compilation
6678 @cindex pedantic compilation
6679 @cindex compilation, pedantic
6680
6681 The @samp{-fpedantic} command-line option specifies that @code{g77}
6682 is to warn about code that is not standard-conforming.
6683 This is useful for finding
6684 some extensions @code{g77} accepts that other compilers might not accept.
6685 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
6686 always imply @samp{-fpedantic}.)
6687
6688 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
6689 for conforming code.
6690 With @samp{-ff90} in force, Fortran 90 is used.
6691
6692 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
6693 and @samp{-fno-f90} are in force are:
6694
6695 @itemize @bullet
6696 @item
6697 Automatic arrays, as in
6698
6699 @example
6700 SUBROUTINE X(N)
6701 REAL A(N)
6702 @dots{}
6703 @end example
6704
6705 @noindent
6706 where @samp{A} is not listed in any @code{ENTRY} statement,
6707 and thus is not a dummy argument.
6708
6709 @item
6710 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
6711
6712 These commas are disallowed by FORTRAN 77, but, while strictly
6713 superfluous, are syntactically elegant,
6714 especially given that commas are required in statements such
6715 as @samp{READ 99, I} and @samp{PRINT *, J}.
6716 Many compilers permit the superfluous commas for this reason.
6717
6718 @item
6719 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
6720
6721 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
6722 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
6723
6724 An example of an implicit use is the expression @samp{C*D},
6725 where @samp{C} is @code{COMPLEX(KIND=1)}
6726 and @samp{D} is @code{DOUBLE PRECISION}.
6727 This expression is prohibited by ANSI FORTRAN 77
6728 because the rules of promotion would suggest that it
6729 produce a @code{DOUBLE COMPLEX} result---a type not
6730 provided for by that standard.
6731
6732 @item
6733 Automatic conversion of numeric
6734 expressions to @code{INTEGER(KIND=1)} in contexts such as:
6735
6736 @itemize @minus
6737 @item
6738 Array-reference indexes.
6739 @item
6740 Alternate-return values.
6741 @item
6742 Computed @code{GOTO}.
6743 @item
6744 @code{FORMAT} run-time expressions (not yet supported).
6745 @item
6746 Dimension lists in specification statements.
6747 @item
6748 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
6749 @item
6750 Sizes of @code{CHARACTER} entities in specification statements.
6751 @item
6752 Kind types in specification entities (a Fortran 90 feature).
6753 @item
6754 Initial, terminal, and incrementation parameters for implied-@code{DO}
6755 constructs in @code{DATA} statements.
6756 @end itemize
6757
6758 @item
6759 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
6760 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
6761 expressions are disallowed anyway).
6762
6763 @item
6764 Zero-size array dimensions, as in:
6765
6766 @example
6767 INTEGER I(10,20,4:2)
6768 @end example
6769
6770 @item
6771 Zero-length @code{CHARACTER} entities, as in:
6772
6773 @example
6774 PRINT *, ''
6775 @end example
6776
6777 @item
6778 Substring operators applied to character constants and named
6779 constants, as in:
6780
6781 @example
6782 PRINT *, 'hello'(3:5)
6783 @end example
6784
6785 @item
6786 Null arguments passed to statement function, as in:
6787
6788 @example
6789 PRINT *, FOO(,3)
6790 @end example
6791
6792 @item
6793 Disagreement among program units regarding whether a given @code{COMMON}
6794 area is @code{SAVE}d (for targets where program units in a single source
6795 file are ``glued'' together as they typically are for UNIX development
6796 environments).
6797
6798 @item
6799 Disagreement among program units regarding the size of a
6800 named @code{COMMON} block.
6801
6802 @item
6803 Specification statements following first @code{DATA} statement.
6804
6805 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
6806 but not @samp{INTEGER I}.
6807 The @samp{-fpedantic} option disallows both of these.)
6808
6809 @item
6810 Semicolon as statement separator, as in:
6811
6812 @example
6813 CALL FOO; CALL BAR
6814 @end example
6815 @c
6816 @c @item
6817 @c Comma before list of I/O items in @code{WRITE}
6818 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
6819 @c statements, as with @code{READ} (as explained above).
6820
6821 @item
6822 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
6823
6824 @item
6825 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
6826 versa.
6827
6828 @item
6829 Expressions having two arithmetic operators in a row, such
6830 as @samp{X*-Y}.
6831 @end itemize
6832
6833 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
6834 following constructs result in diagnostics:
6835
6836 @itemize @bullet
6837 @item
6838 Use of semicolon as a statement separator on a line
6839 that has an @code{INCLUDE} directive.
6840 @end itemize
6841
6842 @node Distensions
6843 @section Distensions
6844 @cindex distensions
6845 @cindex ugly features
6846 @cindex features, ugly
6847
6848 The @samp{-fugly-*} command-line options determine whether certain
6849 features supported by VAX FORTRAN and other such compilers, but considered
6850 too ugly to be in code that can be changed to use safer and/or more
6851 portable constructs, are accepted.
6852 These are humorously referred to as ``distensions'',
6853 extensions that just plain look ugly in the harsh light of day.
6854
6855 @menu
6856 * Ugly Implicit Argument Conversion::  Disabled via @samp{-fno-ugly-args}.
6857 * Ugly Assumed-Size Arrays::           Enabled via @samp{-fugly-assumed}.
6858 * Ugly Null Arguments::                Enabled via @samp{-fugly-comma}.
6859 * Ugly Complex Part Extraction::       Enabled via @samp{-fugly-complex}.
6860 * Ugly Conversion of Initializers::    Disabled via @samp{-fno-ugly-init}.
6861 * Ugly Integer Conversions::           Enabled via @samp{-fugly-logint}.
6862 * Ugly Assigned Labels::               Enabled via @samp{-fugly-assign}.
6863 @end menu
6864
6865 @node Ugly Implicit Argument Conversion
6866 @subsection Implicit Argument Conversion
6867 @cindex Hollerith constants
6868 @cindex constants, Hollerith
6869
6870 The @samp{-fno-ugly-args} option disables
6871 passing typeless and Hollerith constants as actual arguments
6872 in procedure invocations.
6873 For example:
6874
6875 @example
6876 CALL FOO(4HABCD)
6877 CALL BAR('123'O)
6878 @end example
6879
6880 @noindent
6881 These constructs can be too easily used to create non-portable
6882 code, but are not considered as ``ugly'' as others.
6883 Further, they are widely used in existing Fortran source code
6884 in ways that often are quite portable.
6885 Therefore, they are enabled by default.
6886
6887 @node Ugly Assumed-Size Arrays
6888 @subsection Ugly Assumed-Size Arrays
6889 @cindex arrays, assumed-size
6890 @cindex assumed-size arrays
6891 @cindex DIMENSION X(1)
6892
6893 The @samp{-fugly-assumed} option enables
6894 the treatment of any array with a final dimension specified as @samp{1}
6895 as an assumed-size array, as if @samp{*} had been specified
6896 instead.
6897
6898 For example, @samp{DIMENSION X(1)} is treated as if it
6899 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
6900 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
6901 or @code{ENTRY} statement in the same program unit.
6902
6903 Use an explicit lower bound to avoid this interpretation.
6904 For example, @samp{DIMENSION X(1:1)} is never treated as if
6905 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
6906 Nor is @samp{DIMENSION X(2-1)} affected by this option,
6907 since that kind of expression is unlikely to have been
6908 intended to designate an assumed-size array.
6909
6910 This option is used to prevent warnings being issued about apparent
6911 out-of-bounds reference such as @samp{X(2) = 99}.
6912
6913 It also prevents the array from being used in contexts that
6914 disallow assumed-size arrays, such as @samp{PRINT *,X}.
6915 In such cases, a diagnostic is generated and the source file is
6916 not compiled.
6917
6918 The construct affected by this option is used only in old code
6919 that pre-exists the widespread acceptance of adjustable and assumed-size
6920 arrays in the Fortran community.
6921
6922 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
6923 treated if @samp{X} is listed as a dummy argument only
6924 @emph{after} the @code{DIMENSION} statement (presumably in
6925 an @code{ENTRY} statement).
6926 For example, @samp{-fugly-assumed} has no effect on the
6927 following program unit:
6928
6929 @example
6930 SUBROUTINE X
6931 REAL A(1)
6932 RETURN
6933 ENTRY Y(A)
6934 PRINT *, A
6935 END
6936 @end example
6937
6938 @node Ugly Complex Part Extraction
6939 @subsection Ugly Complex Part Extraction
6940 @cindex complex values
6941 @cindex real part
6942 @cindex imaginary part
6943
6944 The @samp{-fugly-complex} option enables
6945 use of the @code{REAL()} and @code{AIMAG()}
6946 intrinsics with arguments that are
6947 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
6948
6949 With @samp{-ff90} in effect, these intrinsics return
6950 the unconverted real and imaginary parts (respectively)
6951 of their argument.
6952
6953 With @samp{-fno-f90} in effect, these intrinsics convert
6954 the real and imaginary parts to @code{REAL(KIND=1)}, and return
6955 the result of that conversion.
6956
6957 Due to this ambiguity, the GNU Fortran language defines
6958 these constructs as invalid, except in the specific
6959 case where they are entirely and solely passed as an
6960 argument to an invocation of the @code{REAL()} intrinsic.
6961 For example,
6962
6963 @example
6964 REAL(REAL(Z))
6965 @end example
6966
6967 @noindent
6968 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
6969 and @samp{-fno-ugly-complex} is in effect, because the
6970 meaning is clear.
6971
6972 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
6973 is specified, in which case the appropriate interpretation is
6974 chosen and no diagnostic is issued.
6975
6976 @xref{CMPAMBIG}, for information on how to cope with existing
6977 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
6978 with @code{COMPLEX(KIND=2)} arguments.
6979
6980 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
6981 intrinsic, used to extract the real part of a complex expression
6982 without conversion.
6983 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
6984 intrinsic, used to extract the imaginary part of a complex expression
6985 without conversion.
6986
6987 @node Ugly Null Arguments
6988 @subsection Ugly Null Arguments
6989 @cindex trailing comma
6990 @cindex comma, trailing
6991 @cindex characters, comma
6992 @cindex null arguments
6993 @cindex arguments, null
6994
6995 The @samp{-fugly-comma} option enables use of a single trailing comma
6996 to mean ``pass an extra trailing null argument''
6997 in a list of actual arguments to an external procedure,
6998 and use of an empty list of arguments to such a procedure
6999 to mean ``pass a single null argument''.
7000
7001 @cindex omitting arguments
7002 @cindex arguments, omitting
7003 (Null arguments often are used in some procedure-calling
7004 schemes to indicate omitted arguments.)
7005
7006 For example, @samp{CALL FOO(,)} means ``pass
7007 two null arguments'', rather than ``pass one null argument''.
7008 Also, @samp{CALL BAR()} means ``pass one null argument''.
7009
7010 This construct is considered ``ugly'' because it does not
7011 provide an elegant way to pass a single null argument
7012 that is syntactically distinct from passing no arguments.
7013 That is, this construct changes the meaning of code that
7014 makes no use of the construct.
7015
7016 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
7017 and @samp{I = JFUNC()} pass a single null argument, instead
7018 of passing no arguments as required by the Fortran 77 and
7019 90 standards.
7020
7021 @emph{Note:} Many systems gracefully allow the case
7022 where a procedure call passes one extra argument that the
7023 called procedure does not expect.
7024
7025 So, in practice, there might be no difference in
7026 the behavior of a program that does @samp{CALL FOO()}
7027 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
7028 in force as compared to its behavior when compiled
7029 with the default, @samp{-fno-ugly-comma}, in force,
7030 assuming @samp{FOO} and @samp{JFUNC} do not expect any
7031 arguments to be passed.
7032
7033 @node Ugly Conversion of Initializers
7034 @subsection Ugly Conversion of Initializers
7035
7036 The constructs disabled by @samp{-fno-ugly-init} are:
7037
7038 @itemize @bullet
7039 @cindex Hollerith constants
7040 @cindex constants, Hollerith
7041 @item
7042 Use of Hollerith and typeless constants in contexts where they set
7043 initial (compile-time) values for variables, arrays, and named
7044 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
7045 type-declaration statements specifying initial values.
7046
7047 Here are some sample initializations that are disabled by the
7048 @samp{-fno-ugly-init} option:
7049
7050 @example
7051 PARAMETER (VAL='9A304FFE'X)
7052 REAL*8 STRING/8HOUTPUT00/
7053 DATA VAR/4HABCD/
7054 @end example
7055
7056 @cindex character constants
7057 @cindex constants, character
7058 @item
7059 In the same contexts as above, use of character constants to initialize
7060 numeric items and vice versa (one constant per item).
7061
7062 Here are more sample initializations that are disabled by the
7063 @samp{-fno-ugly-init} option:
7064
7065 @example
7066 INTEGER IA
7067 CHARACTER BELL
7068 PARAMETER (IA = 'A')
7069 PARAMETER (BELL = 7)
7070 @end example
7071
7072 @item
7073 Use of Hollerith and typeless constants on the right-hand side
7074 of assignment statements to numeric types, and in other
7075 contexts (such as passing arguments in invocations of
7076 intrinsic procedures and statement functions) that
7077 are treated as assignments to known types (the dummy
7078 arguments, in these cases).
7079
7080 Here are sample statements that are disabled by the
7081 @samp{-fno-ugly-init} option:
7082
7083 @example
7084 IVAR = 4HABCD
7085 PRINT *, IMAX0(2HAB, 2HBA)
7086 @end example
7087 @end itemize
7088
7089 The above constructs, when used,
7090 can tend to result in non-portable code.
7091 But, they are widely used in existing Fortran code in ways
7092 that often are quite portable.
7093 Therefore, they are enabled by default.
7094
7095 @node Ugly Integer Conversions
7096 @subsection Ugly Integer Conversions
7097
7098 The constructs enabled via @samp{-fugly-logint} are:
7099
7100 @itemize @bullet
7101 @item
7102 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
7103 dictated by
7104 context (typically implies nonportable dependencies on how a
7105 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
7106
7107 @item
7108 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
7109 statements.
7110 @end itemize
7111
7112 The above constructs are disabled by default because use
7113 of them tends to lead to non-portable code.
7114 Even existing Fortran code that uses that often turns out
7115 to be non-portable, if not outright buggy.
7116
7117 Some of this is due to differences among implementations as
7118 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
7119 @code{INTEGER} values---Fortran code that assumes a particular
7120 coding is likely to use one of the above constructs, and is
7121 also likely to not work correctly on implementations using
7122 different encodings.
7123
7124 @xref{Equivalence Versus Equality}, for more information.
7125
7126 @node Ugly Assigned Labels
7127 @subsection Ugly Assigned Labels
7128 @cindex ASSIGN statement
7129 @cindex statements, ASSIGN
7130 @cindex assigned labels
7131 @cindex pointers
7132
7133 The @samp{-fugly-assign} option forces @code{g77} to use the
7134 same storage for assigned labels as it would for a normal
7135 assignment to the same variable.
7136
7137 For example, consider the following code fragment:
7138
7139 @example
7140 I = 3
7141 ASSIGN 10 TO I
7142 @end example
7143
7144 @noindent
7145 Normally, for portability and improved diagnostics, @code{g77}
7146 reserves distinct storage for a ``sibling'' of @samp{I}, used
7147 only for @code{ASSIGN} statements to that variable (along with
7148 the corresponding assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O
7149 statements that reference the variable).
7150
7151 However, some code (that violates the ANSI FORTRAN 77 standard)
7152 attempts to copy assigned labels among variables involved with
7153 @code{ASSIGN} statements, as in:
7154
7155 @example
7156 ASSIGN 10 TO I
7157 ISTATE(5) = I
7158 @dots{}
7159 J = ISTATE(ICUR)
7160 GOTO J
7161 @end example
7162
7163 @noindent
7164 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
7165 is specified on the command-line, ensuring that the value of @code{I}
7166 referenced in the second line is whatever value @code{g77} uses
7167 to designate statement label @samp{10}, so the value may be
7168 copied into the @samp{ISTATE} array, later retrieved into a
7169 variable of the appropriate type (@samp{J}), and used as the target of
7170 an assigned-@code{GOTO} statement.
7171
7172 @emph{Note:} To avoid subtle program bugs,
7173 when @samp{-fugly-assign} is specified,
7174 @code{g77} requires the type of variables
7175 specified in assigned-label contexts
7176 @emph{must} be the same type returned by @code{%LOC()}.
7177 On many systems, this type is effectively the same
7178 as @code{INTEGER(KIND=1)}, while, on others, it is
7179 effectively the same as @code{INTEGER(KIND=2)}.
7180
7181 Do @emph{not} depend on @code{g77} actually writing valid pointers
7182 to these variables, however.
7183 While @code{g77} currently chooses that implementation, it might
7184 be changed in the future.
7185
7186 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
7187 for implementation details on assigned-statement labels.
7188
7189 @node Compiler
7190 @chapter The GNU Fortran Compiler
7191
7192 The GNU Fortran compiler, @code{g77}, supports programs written
7193 in the GNU Fortran language and in some other dialects of Fortran.
7194
7195 Some aspects of how @code{g77} works are universal regardless
7196 of dialect, and yet are not properly part of the GNU Fortran
7197 language itself.
7198 These are described below.
7199
7200 @emph{Note: This portion of the documentation definitely needs a lot
7201 of work!}
7202
7203 @menu
7204 * Compiler Limits::
7205 * Run-time Environment Limits::
7206 * Compiler Types::
7207 * Compiler Constants::
7208 * Compiler Intrinsics::
7209 @end menu
7210
7211 @node Compiler Limits
7212 @section Compiler Limits
7213 @cindex limits, compiler
7214 @cindex compiler limits
7215
7216 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
7217 on lengths of identifiers, number of continuation lines, number of external
7218 symbols in a program, and so on.
7219
7220 @cindex options, -Nl
7221 @cindex -Nl option
7222 @cindex options, -Nx
7223 @cindex -Nx option
7224 @cindex limits, continuation lines
7225 @cindex limits, lengths of names
7226 For example, some other Fortran compiler have an option
7227 (such as @samp{-Nl@var{x}}) to increase the limit on the
7228 number of continuation lines.
7229 Also, some Fortran compilation systems have an option
7230 (such as @samp{-Nx@var{x}}) to increase the limit on the
7231 number of external symbols.
7232
7233 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
7234 no equivalent options, since they do not impose arbitrary
7235 limits in these areas.
7236
7237 @cindex rank, maximum
7238 @cindex maximum rank
7239 @cindex number of dimensions, maximum
7240 @cindex maximum number of dimensions
7241 @cindex limits, rank
7242 @cindex limits, array dimensions
7243 @code{g77} does currently limit the number of dimensions in an array
7244 to the same degree as do the Fortran standards---seven (7).
7245 This restriction might be lifted in a future version.
7246
7247 @node Run-time Environment Limits
7248 @section Run-time Environment Limits
7249 @cindex limits, run-time library
7250 @cindex wraparound
7251
7252 As a portable Fortran implementation,
7253 @code{g77} offers its users direct access to,
7254 and otherwise depends upon,
7255 the underlying facilities of the system
7256 used to build @code{g77},
7257 the system on which @code{g77} itself is used to compile programs,
7258 and the system on which the @code{g77}-compiled program is actually run.
7259 (For most users, the three systems are of the same
7260 type---combination of operating environment and hardware---often
7261 the same physical system.)
7262
7263 The run-time environment for a particular system
7264 inevitably imposes some limits on a program's use
7265 of various system facilities.
7266 These limits vary from system to system.
7267
7268 Even when such limits might be well beyond the
7269 possibility of being encountered on a particular system,
7270 the @code{g77} run-time environment
7271 has certain built-in limits,
7272 usually, but not always, stemming from intrinsics
7273 with inherently limited interfaces.
7274
7275 Currently, the @code{g77} run-time environment
7276 does not generally offer a less-limiting environment
7277 by augmenting the underlying system's own environment.
7278
7279 Therefore, code written in the GNU Fortran language,
7280 while syntactically and semantically portable,
7281 might nevertheless make non-portable assumptions
7282 about the run-time environment---assumptions that
7283 prove to be false for some particular environments.
7284
7285 The GNU Fortran language,
7286 the @code{g77} compiler and run-time environment,
7287 and the @code{g77} documentation
7288 do not yet offer comprehensive portable work-arounds for such limits,
7289 though programmers should be able to
7290 find their own in specific instances.
7291
7292 Not all of the limitations are described in this document.
7293 Some of the known limitations include:
7294
7295 @menu
7296 * Timer Wraparounds::
7297 * Year 2000 (Y2K) Problems::
7298 * Array Size::
7299 * Character-variable Length::
7300 * Year 10000 (Y10K) Problems::
7301 @end menu
7302
7303 @node Timer Wraparounds
7304 @subsection Timer Wraparounds
7305
7306 Intrinsics that return values computed from system timers,
7307 whether elapsed (wall-clock) timers,
7308 process CPU timers,
7309 or other kinds of timers,
7310 are prone to experiencing wrap-around errors
7311 (or returning wrapped-around values from successive calls)
7312 due to insufficient ranges
7313 offered by the underlying system's timers.
7314
7315 @cindex negative time
7316 @cindex short time
7317 @cindex long time
7318 Some of the symptoms of such behaviors include
7319 apparently negative time being computed for a duration,
7320 an extremely short amount of time being computed for a long duration,
7321 and an extremely long amount of time being computed for a short duration.
7322
7323 See the following for intrinsics
7324 known to have potential problems in these areas
7325 on at least some systems:
7326 @ref{CPU_Time Intrinsic},
7327 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
7328 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
7329 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
7330 @ref{Secnds Intrinsic},
7331 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
7332 @ref{System_Clock Intrinsic},
7333 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
7334 @ref{Time8 Intrinsic}.
7335
7336 @node Year 2000 (Y2K) Problems
7337 @subsection Year 2000 (Y2K) Problems
7338 @cindex Y2K compliance
7339 @cindex Year 2000 compliance
7340
7341 While the @code{g77} compiler itself is believed to
7342 be Year-2000 (Y2K) compliant,
7343 some intrinsics are not,
7344 and, potentially, some underlying systems are not,
7345 perhaps rendering some Y2K-compliant intrinsics
7346 non-compliant when used on those particular systems.
7347
7348 Fortran code that uses non-Y2K-compliant intrinsics
7349 (listed below)
7350 is, itself, almost certainly not compliant,
7351 and should be modified to use Y2K-compliant intrinsics instead.
7352
7353 Fortran code that uses no non-Y2K-compliant intrinsics,
7354 but which currently is running on a non-Y2K-compliant system,
7355 can be made more Y2K compliant by compiling and
7356 linking it for use on a new Y2K-compliant system,
7357 such as a new version of an old, non-Y2K-compliant, system.
7358
7359 Currently, information on Y2K and related issues
7360 is being maintained at
7361 @uref{http://www.gnu.org/software/year2000-list.html}.
7362
7363 See the following for intrinsics
7364 known to have potential problems in these areas
7365 on at least some systems:
7366 @ref{Date Intrinsic},
7367 @ref{IDate Intrinsic (VXT)}.
7368
7369 @cindex y2kbuggy
7370 @cindex date_y2kbuggy_0
7371 @cindex vxtidate_y2kbuggy_0
7372 @cindex G77_date_y2kbuggy_0
7373 @cindex G77_vxtidate_y2kbuggy_0
7374 The @code{libg2c} library
7375 shipped with any @code{g77} that warns
7376 about invocation of a non-Y2K-compliant intrinsic
7377 has renamed the @code{EXTERNAL} procedure names
7378 of those intrinsics.
7379 This is done so that
7380 the @code{libg2c} implementations of these intrinsics
7381 cannot be directly linked to
7382 as @code{EXTERNAL} names
7383 (which normally would avoid the non-Y2K-intrinsic warning).
7384
7385 The renamed forms of the @code{EXTERNAL} names
7386 of these renamed procedures
7387 may be linked to
7388 by appending the string @samp{_y2kbug}
7389 to the name of the procedure
7390 in the source code.
7391 For example:
7392
7393 @smallexample
7394 CHARACTER*20 STR
7395 INTEGER YY, MM, DD
7396 EXTERNAL DATE_Y2KBUG, VXTIDATE_Y2KBUG
7397 CALL DATE_Y2KBUG (STR)
7398 CALL VXTIDATE_Y2KBUG (MM, DD, YY)
7399 @end smallexample
7400
7401 (Note that the @code{EXTERNAL} statement
7402 is not actually required,
7403 since the modified names are not recognized as intrinsics
7404 by the current version of @code{g77}.
7405 But it is shown in this specific case,
7406 for purposes of illustration.)
7407
7408 The renaming of @code{EXTERNAL} procedure names of these intrinsics
7409 causes unresolved references at link time.
7410 For example, @samp{EXTERNAL DATE; CALL DATE(STR)}
7411 is normally compiled by @code{g77}
7412 as, in C, @samp{date_(&str, 20);}.
7413 This, in turn, links to the @code{date_} procedure
7414 in the @code{libE77} portion of @code{libg2c},
7415 which purposely calls a nonexistent procedure
7416 named @code{G77_date_y2kbuggy_0}.
7417 The resulting link-time error is designed, via this name,
7418 to encourage the programmer to look up the
7419 index entries to this portion of the @code{g77} documentation.
7420
7421 Generally, we recommend that the @code{EXTERNAL} method
7422 of invoking procedures in @code{libg2c}
7423 @emph{not} be used.
7424 When used, some of the correctness checking
7425 normally performed by @code{g77}
7426 is skipped.
7427
7428 In particular, it is probably better to use the
7429 @code{INTRINSIC} method of invoking
7430 non-Y2K-compliant procedures,
7431 so anyone compiling the code
7432 can quickly notice the potential Y2K problems
7433 (via the warnings printing by @code{g77})
7434 without having to even look at the code itself.
7435
7436 If there are problems linking @code{libg2c}
7437 to code compiled by @code{g77}
7438 that involve the string @samp{y2kbug},
7439 and these are not explained above,
7440 that probably indicates
7441 that a version of @code{libg2c}
7442 older than @code{g77}
7443 is being linked to,
7444 or that the new library is being linked
7445 to code compiled by an older version of @code{g77}.
7446
7447 That's because, as of the version that warns about
7448 non-Y2K-compliant intrinsic invocation,
7449 @code{g77} references the @code{libg2c} implementations
7450 of those intrinsics
7451 using new names, containing the string @samp{y2kbug}.
7452
7453 So, linking newly-compiled code
7454 (invoking one of the intrinsics in question)
7455 to an old library
7456 might yield an unresolved reference
7457 to @code{G77_date_y2kbug_0}.
7458 (The old library calls it @code{G77_date_0}.)
7459
7460 Similarly, linking previously-compiled code
7461 to a new library
7462 might yield an unresolved reference
7463 to @code{G77_vxtidate_0}.
7464 (The new library calls it @code{G77_vxtidate_y2kbug_0}.)
7465
7466 The proper fix for the above problems
7467 is to obtain the latest release of @code{g77}
7468 and related products
7469 (including @code{libg2c})
7470 and install them on all systems,
7471 then recompile, relink, and install
7472 (as appropriate)
7473 all existing Fortran programs.
7474
7475 (Normally, this sort of renaming is steadfastly avoided.
7476 In this case, however, it seems more important to highlight
7477 potential Y2K problems
7478 than to ease the transition
7479 of potentially non-Y2K-compliant code
7480 to new versions of @code{g77} and @code{libg2c}.)
7481
7482 @node Array Size
7483 @subsection Array Size
7484 @cindex limits, array size
7485 @cindex array size
7486
7487 Currently, @code{g77} uses the default @code{INTEGER} type
7488 for array indexes,
7489 which limits the sizes of single-dimension arrays
7490 on systems offering a larger address space
7491 than can be addressed by that type.
7492 (That @code{g77} puts all arrays in memory
7493 could be considered another limitation---it
7494 could use large temporary files---but that decision
7495 is left to the programmer as an implementation choice
7496 by most Fortran implementations.)
7497
7498 @c ??? Investigate this, to offer a more clear statement
7499 @c than the following paragraphs do.  -- burley 1999-02-17
7500 It is not yet clear whether this limitation
7501 never, sometimes, or always applies to the
7502 sizes of multiple-dimension arrays as a whole.
7503
7504 For example, on a system with 64-bit addresses
7505 and 32-bit default @code{INTEGER},
7506 an array with a size greater than can be addressed
7507 by a 32-bit offset
7508 can be declared using multiple dimensions.
7509 Such an array is therefore larger
7510 than a single-dimension array can be,
7511 on the same system.
7512
7513 @cindex limits, multi-dimension arrays
7514 @cindex multi-dimension arrays
7515 @cindex arrays, dimensioning
7516 Whether large multiple-dimension arrays are reliably supported
7517 depends mostly on the @code{gcc} back end (code generator)
7518 used by @code{g77}, and has not yet been fully investigated.
7519
7520 @node Character-variable Length
7521 @subsection Character-variable Length
7522 @cindex limits, on character-variable length
7523 @cindex character-variable length
7524
7525 Currently, @code{g77} uses the default @code{INTEGER} type
7526 for the lengths of @code{CHARACTER} variables
7527 and array elements.
7528
7529 This means that, for example,
7530 a system with a 64-bit address space
7531 and a 32-bit default @code{INTEGER} type
7532 does not, under @code{g77},
7533 support a @code{CHARACTER*@var{n}} declaration
7534 where @var{n} is greater than 2147483647.
7535
7536 @node Year 10000 (Y10K) Problems
7537 @subsection Year 10000 (Y10K) Problems
7538 @cindex Y10K compliance
7539 @cindex Year 10000 compliance
7540
7541 Most intrinsics returning, or computing values based on,
7542 date information are prone to Year-10000 (Y10K) problems,
7543 due to supporting only 4 digits for the year.
7544
7545 See the following for examples:
7546 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
7547 @ref{IDate Intrinsic (UNIX)},
7548 @ref{Time Intrinsic (VXT)},
7549 @ref{Date_and_Time Intrinsic}.
7550
7551 @node Compiler Types
7552 @section Compiler Types
7553 @cindex types, of data
7554 @cindex data types
7555
7556 Fortran implementations have a fair amount of freedom given them by the
7557 standard as far as how much storage space is used and how much precision
7558 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
7559 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
7560 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
7561 Further, many compilers offer so-called @samp{*@var{n}} notation, but
7562 the interpretation of @var{n} varies across compilers and target architectures.
7563
7564 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
7565 and @code{REAL(KIND=1)}
7566 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
7567 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
7568 Further, it requires that @code{COMPLEX(KIND=1)}
7569 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
7570 storage-associated (such as via @code{EQUIVALENCE})
7571 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
7572 corresponds to the real element and @samp{R(2)} to the imaginary
7573 element of the @code{COMPLEX(KIND=1)} variable.
7574
7575 (Few requirements as to precision or ranges of any of these are
7576 placed on the implementation, nor is the relationship of storage sizes of
7577 these types to the @code{CHARACTER} type specified, by the standard.)
7578
7579 @code{g77} follows the above requirements, warning when compiling
7580 a program requires placement of items in memory that contradict the
7581 requirements of the target architecture.
7582 (For example, a program can require placement of a @code{REAL(KIND=2)}
7583 on a boundary that is not an even multiple of its size, but still an
7584 even multiple of the size of a @code{REAL(KIND=1)} variable.
7585 On some target architectures, using the canonical
7586 mapping of Fortran types to underlying architectural types, such
7587 placement is prohibited by the machine definition or
7588 the Application Binary Interface (ABI) in force for
7589 the configuration defined for building @code{gcc} and @code{g77}.
7590 @code{g77} warns about such
7591 situations when it encounters them.)
7592
7593 @code{g77} follows consistent rules for configuring the mapping between Fortran
7594 types, including the @samp{*@var{n}} notation, and the underlying architectural
7595 types as accessed by a similarly-configured applicable version of the
7596 @code{gcc} compiler.
7597 These rules offer a widely portable, consistent Fortran/C
7598 environment, although they might well conflict with the expectations of
7599 users of Fortran compilers designed and written for particular
7600 architectures.
7601
7602 These rules are based on the configuration that is in force for the
7603 version of @code{gcc} built in the same release as @code{g77} (and
7604 which was therefore used to build both the @code{g77} compiler
7605 components and the @code{libg2c} run-time library):
7606
7607 @table @code
7608 @cindex REAL(KIND=1) type
7609 @cindex types, REAL(KIND=1)
7610 @item REAL(KIND=1)
7611 Same as @code{float} type.
7612
7613 @cindex REAL(KIND=2) type
7614 @cindex types, REAL(KIND=2)
7615 @item REAL(KIND=2)
7616 Same as whatever floating-point type that is twice the size
7617 of a @code{float}---usually, this is a @code{double}.
7618
7619 @cindex INTEGER(KIND=1) type
7620 @cindex types, INTEGER(KIND=1)
7621 @item INTEGER(KIND=1)
7622 Same as an integral type that is occupies the same amount
7623 of memory storage as @code{float}---usually, this is either
7624 an @code{int} or a @code{long int}.
7625
7626 @cindex LOGICAL(KIND=1) type
7627 @cindex types, LOGICAL(KIND=1)
7628 @item LOGICAL(KIND=1)
7629 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
7630
7631 @cindex INTEGER(KIND=2) type
7632 @cindex types, INTEGER(KIND=2)
7633 @item INTEGER(KIND=2)
7634 Twice the size, and usually nearly twice the range,
7635 as @code{INTEGER(KIND=1)}---usually, this is either
7636 a @code{long int} or a @code{long long int}.
7637
7638 @cindex LOGICAL(KIND=2) type
7639 @cindex types, LOGICAL(KIND=2)
7640 @item LOGICAL(KIND=2)
7641 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
7642
7643 @cindex INTEGER(KIND=3) type
7644 @cindex types, INTEGER(KIND=3)
7645 @item INTEGER(KIND=3)
7646 Same @code{gcc} type as signed @code{char}.
7647
7648 @cindex LOGICAL(KIND=3) type
7649 @cindex types, LOGICAL(KIND=3)
7650 @item LOGICAL(KIND=3)
7651 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
7652
7653 @cindex INTEGER(KIND=6) type
7654 @cindex types, INTEGER(KIND=6)
7655 @item INTEGER(KIND=6)
7656 Twice the size, and usually nearly twice the range,
7657 as @code{INTEGER(KIND=3)}---usually, this is
7658 a @code{short}.
7659
7660 @cindex LOGICAL(KIND=6) type
7661 @cindex types, LOGICAL(KIND=6)
7662 @item LOGICAL(KIND=6)
7663 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
7664
7665 @cindex COMPLEX(KIND=1) type
7666 @cindex types, COMPLEX(KIND=1)
7667 @item COMPLEX(KIND=1)
7668 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
7669 one for the imaginary part).
7670
7671 @cindex COMPLEX(KIND=2) type
7672 @cindex types, COMPLEX(KIND=2)
7673 @item COMPLEX(KIND=2)
7674 Two @code{REAL(KIND=2)} scalars.
7675
7676 @cindex *@var{n} notation
7677 @item @var{numeric-type}*@var{n}
7678 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
7679 Same as whatever @code{gcc} type occupies @var{n} times the storage
7680 space of a @code{gcc} @code{char} item.
7681
7682 @cindex DOUBLE PRECISION type
7683 @cindex types, DOUBLE PRECISION
7684 @item DOUBLE PRECISION
7685 Same as @code{REAL(KIND=2)}.
7686
7687 @cindex DOUBLE COMPLEX type
7688 @cindex types, DOUBLE COMPLEX
7689 @item DOUBLE COMPLEX
7690 Same as @code{COMPLEX(KIND=2)}.
7691 @end table
7692
7693 Note that the above are proposed correspondences and might change
7694 in future versions of @code{g77}---avoid writing code depending
7695 on them.
7696
7697 Other types supported by @code{g77}
7698 are derived from gcc types such as @code{char}, @code{short},
7699 @code{int}, @code{long int}, @code{long long int}, @code{long double},
7700 and so on.
7701 That is, whatever types @code{gcc} already supports, @code{g77} supports
7702 now or probably will support in a future version.
7703 The rules for the @samp{@var{numeric-type}*@var{n}} notation
7704 apply to these types,
7705 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
7706 assigned in a way that encourages clarity, consistency, and portability.
7707
7708 @node Compiler Constants
7709 @section Compiler Constants
7710 @cindex constants
7711 @cindex types, constants
7712
7713 @code{g77} strictly assigns types to @emph{all} constants not
7714 documented as ``typeless'' (typeless constants including @samp{'1'Z},
7715 for example).
7716 Many other Fortran compilers attempt to assign types to typed constants
7717 based on their context.
7718 This results in hard-to-find bugs, nonportable
7719 code, and is not in the spirit (though it strictly follows the letter)
7720 of the 77 and 90 standards.
7721
7722 @code{g77} might offer, in a future release, explicit constructs by
7723 which a wider variety of typeless constants may be specified, and/or
7724 user-requested warnings indicating places where @code{g77} might differ
7725 from how other compilers assign types to constants.
7726
7727 @xref{Context-Sensitive Constants}, for more information on this issue.
7728
7729 @node Compiler Intrinsics
7730 @section Compiler Intrinsics
7731
7732 @code{g77} offers an ever-widening set of intrinsics.
7733 Currently these all are procedures (functions and subroutines).
7734
7735 Some of these intrinsics are unimplemented, but their names reserved
7736 to reduce future problems with existing code as they are implemented.
7737 Others are implemented as part of the GNU Fortran language, while
7738 yet others are provided for compatibility with other dialects of
7739 Fortran but are not part of the GNU Fortran language.
7740
7741 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
7742 a facility that is simply an extension of the intrinsic groups provided
7743 by the GNU Fortran language.
7744
7745 @menu
7746 * Intrinsic Groups::  How intrinsics are grouped for easy management.
7747 * Other Intrinsics::  Intrinsics other than those in the GNU
7748                        Fortran language.
7749 @end menu
7750
7751 @node Intrinsic Groups
7752 @subsection Intrinsic Groups
7753 @cindex groups of intrinsics
7754 @cindex intrinsics, groups
7755
7756 A given specific intrinsic belongs in one or more groups.
7757 Each group is deleted, disabled, hidden, or enabled
7758 by default or a command-line option.
7759 The meaning of each term follows.
7760
7761 @table @b
7762 @cindex deleted intrinsics
7763 @cindex intrinsics, deleted
7764 @item Deleted
7765 No intrinsics are recognized as belonging to that group.
7766
7767 @cindex disabled intrinsics
7768 @cindex intrinsics, disabled
7769 @item Disabled
7770 Intrinsics are recognized as belonging to the group, but
7771 references to them (other than via the @code{INTRINSIC} statement)
7772 are disallowed through that group.
7773
7774 @cindex hidden intrinsics
7775 @cindex intrinsics, hidden
7776 @item Hidden
7777 Intrinsics in that group are recognized and enabled (if implemented)
7778 @emph{only} if the first mention of the actual name of an intrinsic
7779 in a program unit is in an @code{INTRINSIC} statement.
7780
7781 @cindex enabled intrinsics
7782 @cindex intrinsics, enabled
7783 @item Enabled
7784 Intrinsics in that group are recognized and enabled (if implemented).
7785 @end table
7786
7787 The distinction between deleting and disabling a group is illustrated
7788 by the following example.
7789 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
7790 If group @samp{FGR} is deleted, the following program unit will
7791 successfully compile, because @samp{FOO()} will be seen as a
7792 reference to an external function named @samp{FOO}:
7793
7794 @example
7795 PRINT *, FOO()
7796 END
7797 @end example
7798
7799 @noindent
7800 If group @samp{FGR} is disabled, compiling the above program will produce
7801 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
7802 or, if properly invoked, it is not enabled.
7803 To change the above program so it references an external function @samp{FOO}
7804 instead of the disabled @samp{FOO} intrinsic,
7805 add the following line to the top:
7806
7807 @example
7808 EXTERNAL FOO
7809 @end example
7810
7811 @noindent
7812 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
7813 that group do not exist at all, whereas disabling it tells @code{g77} to
7814 recognize them as (disabled) intrinsics in intrinsic-like contexts.
7815
7816 Hiding a group is like enabling it, but the intrinsic must be first
7817 named in an @code{INTRINSIC} statement to be considered a reference to the
7818 intrinsic rather than to an external procedure.
7819 This might be the ``safest'' way to treat a new group of intrinsics
7820 when compiling old
7821 code, because it allows the old code to be generally written as if
7822 those new intrinsics never existed, but to be changed to use them
7823 by inserting @code{INTRINSIC} statements in the appropriate places.
7824 However, it should be the goal of development to use @code{EXTERNAL}
7825 for all names of external procedures that might be intrinsic names.
7826
7827 If an intrinsic is in more than one group, it is enabled if any of its
7828 containing groups are enabled; if not so enabled, it is hidden if
7829 any of its containing groups are hidden; if not so hidden, it is disabled
7830 if any of its containing groups are disabled; if not so disabled, it is
7831 deleted.
7832 This extra complication is necessary because some intrinsics,
7833 such as @code{IBITS}, belong to more than one group, and hence should be
7834 enabled if any of the groups to which they belong are enabled, and so
7835 on.
7836
7837 The groups are:
7838
7839 @cindex intrinsics, groups of
7840 @cindex groups of intrinsics
7841 @table @code
7842 @cindex @code{badu77} intrinsics group
7843 @item badu77
7844 UNIX intrinsics having inappropriate forms (usually functions that
7845 have intended side effects).
7846
7847 @cindex @code{gnu} intrinsics group
7848 @item gnu
7849 Intrinsics the GNU Fortran language supports that are extensions to
7850 the Fortran standards (77 and 90).
7851
7852 @cindex @code{f2c} intrinsics group
7853 @item f2c
7854 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
7855
7856 @cindex @code{f90} intrinsics group
7857 @item f90
7858 Fortran 90 intrinsics.
7859
7860 @cindex @code{mil} intrinsics group
7861 @item mil
7862 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
7863
7864 @cindex @code{mil} intrinsics group
7865 @item unix
7866 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
7867
7868 @cindex @code{mil} intrinsics group
7869 @item vxt
7870 VAX/VMS FORTRAN (current as of v4) intrinsics.
7871 @end table
7872
7873 @node Other Intrinsics
7874 @subsection Other Intrinsics
7875 @cindex intrinsics, others
7876 @cindex other intrinsics
7877
7878 @code{g77} supports intrinsics other than those in the GNU Fortran
7879 language proper.
7880 This set of intrinsics is described below.
7881
7882 @ifinfo
7883 (Note that the empty lines appearing in the menu below
7884 are not intentional---they result from a bug in the
7885 @code{makeinfo} program.)
7886 @end ifinfo
7887
7888 @c The actual documentation for intrinsics comes from
7889 @c intdoc.texi, which in turn is automatically generated
7890 @c from the internal g77 tables in intrin.def _and_ the
7891 @c largely hand-written text in intdoc.h.  So, if you want
7892 @c to change or add to existing documentation on intrinsics,
7893 @c you probably want to edit intdoc.h.
7894 @c
7895 @clear familyF77
7896 @clear familyGNU
7897 @clear familyASC
7898 @clear familyMIL
7899 @clear familyF90
7900 @set familyVXT
7901 @set familyFVZ
7902 @clear familyF2C
7903 @clear familyF2U
7904 @set familyBADU77
7905 @include intdoc.texi
7906
7907 @node Other Compilers
7908 @chapter Other Compilers
7909
7910 An individual Fortran source file can be compiled to
7911 an object (@file{*.o}) file instead of to the final
7912 program executable.
7913 This allows several portions of a program to be compiled
7914 at different times and linked together whenever a new
7915 version of the program is needed.
7916 However, it introduces the issue of @dfn{object compatibility}
7917 across the various object files (and libraries, or @file{*.a}
7918 files) that are linked together to produce any particular
7919 executable file.
7920
7921 Object compatibility is an issue when combining, in one
7922 program, Fortran code compiled by more than one compiler
7923 (or more than one configuration of a compiler).
7924 If the compilers
7925 disagree on how to transform the names of procedures, there
7926 will normally be errors when linking such programs.
7927 Worse, if the compilers agree on naming, but disagree on issues
7928 like how to pass parameters, return arguments, and lay out
7929 @code{COMMON} areas, the earliest detected errors might be the
7930 incorrect results produced by the program (and that assumes
7931 these errors are detected, which is not always the case).
7932
7933 Normally, @code{g77} generates code that is
7934 object-compatible with code generated by a version of
7935 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
7936 to be generally compatible with @code{g77} as built by @code{gcc}.
7937 (Normally, @code{f2c} will, by default, conform to the appropriate
7938 configuration, but it is possible that older or perhaps even newer
7939 versions of @code{f2c}, or versions having certain configuration changes
7940 to @code{f2c} internals, will produce object files that are
7941 incompatible with @code{g77}.)
7942
7943 For example, a Fortran string subroutine
7944 argument will become two arguments on the C side: a @code{char *}
7945 and an @code{int} length.
7946
7947 Much of this compatibility results from the fact that
7948 @code{g77} uses the same run-time library,
7949 @code{libf2c}, used by @code{f2c},
7950 though @code{g77} gives its version the name @code{libg2c}
7951 so as to avoid conflicts when linking,
7952 installing them in the same directories,
7953 and so on.
7954
7955 Other compilers might or might not generate code that
7956 is object-compatible with @code{libg2c} and current @code{g77},
7957 and some might offer such compatibility only when explicitly
7958 selected via a command-line option to the compiler.
7959
7960 @emph{Note: This portion of the documentation definitely needs a lot
7961 of work!}
7962
7963 @menu
7964 * Dropping f2c Compatibility::  When speed is more important.
7965 * Compilers Other Than f2c::    Interoperation with code from other compilers.
7966 @end menu
7967
7968 @node Dropping f2c Compatibility
7969 @section Dropping @code{f2c} Compatibility
7970
7971 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
7972 some cases, faster code, by not needing to allow to the possibility
7973 of linking with code compiled by @code{f2c}.
7974
7975 For example, this affects how @code{REAL(KIND=1)},
7976 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
7977 With @samp{-fno-f2c}, they are
7978 compiled as returning the appropriate @code{gcc} type
7979 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
7980 in many configurations).
7981
7982 With @samp{-ff2c} in force, they
7983 are compiled differently (with perhaps slower run-time performance)
7984 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
7985 C as an intermediate language---@code{REAL(KIND=1)} functions
7986 return C's @code{double} type, while @code{COMPLEX} functions return
7987 @code{void} and use an extra argument pointing to a place for the functions to
7988 return their values.
7989
7990 It is possible that, in some cases, leaving @samp{-ff2c} in force
7991 might produce faster code than using @samp{-fno-f2c}.
7992 Feel free to experiment, but remember to experiment with changing the way
7993 @emph{entire programs and their Fortran libraries are compiled} at
7994 a time, since this sort of experimentation affects the interface
7995 of code generated for a Fortran source file---that is, it affects
7996 object compatibility.
7997
7998 Note that @code{f2c} compatibility is a fairly static target to achieve,
7999 though not necessarily perfectly so, since, like @code{g77}, it is
8000 still being improved.
8001 However, specifying @samp{-fno-f2c} causes @code{g77}
8002 to generate code that will probably be incompatible with code
8003 generated by future versions of @code{g77} when the same option
8004 is in force.
8005 You should make sure you are always able to recompile complete
8006 programs from source code when upgrading to new versions of @code{g77}
8007 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
8008
8009 Therefore, if you are using @code{g77} to compile libraries and other
8010 object files for possible future use and you don't want to require
8011 recompilation for future use with subsequent versions of @code{g77},
8012 you might want to stick with @code{f2c} compatibility for now, and
8013 carefully watch for any announcements about changes to the
8014 @code{f2c}/@code{libf2c} interface that might affect existing programs
8015 (thus requiring recompilation).
8016
8017 It is probable that a future version of @code{g77} will not,
8018 by default, generate object files compatible with @code{f2c},
8019 and that version probably would no longer use @code{libf2c}.
8020 If you expect to depend on this compatibility in the
8021 long term, use the options @samp{-ff2c -ff2c-library} when compiling
8022 all of the applicable code.
8023 This should cause future versions of @code{g77} either to produce
8024 compatible code (at the expense of the availability of some features and
8025 performance), or at the very least, to produce diagnostics.
8026
8027 (The library @code{g77} produces will no longer be named @file{libg2c}
8028 when it is no longer generally compatible with @file{libf2c}.
8029 It will likely be referred to, and, if installed as a distinct
8030 library, named @code{libg77}, or some other as-yet-unused name.)
8031
8032 @node Compilers Other Than f2c
8033 @section Compilers Other Than @code{f2c}
8034
8035 On systems with Fortran compilers other than @code{f2c} and @code{g77},
8036 code compiled by @code{g77} is not expected to work
8037 well with code compiled by the native compiler.
8038 (This is true for @code{f2c}-compiled objects as well.)
8039 Libraries compiled with the native compiler probably will have
8040 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
8041
8042 Reasons for such incompatibilities include:
8043
8044 @itemize @bullet
8045 @item
8046 There might be differences in the way names of Fortran procedures
8047 are translated for use in the system's object-file format.
8048 For example, the statement @samp{CALL FOO} might be compiled
8049 by @code{g77} to call a procedure the linker @code{ld} sees
8050 given the name @samp{_foo_}, while the apparently corresponding
8051 statement @samp{SUBROUTINE FOO} might be compiled by the
8052 native compiler to define the linker-visible name @samp{_foo},
8053 or @samp{_FOO_}, and so on.
8054
8055 @item
8056 There might be subtle type mismatches which cause subroutine arguments
8057 and function return values to get corrupted.
8058
8059 This is why simply getting @code{g77} to
8060 transform procedure names the same way a native
8061 compiler does is not usually a good idea---unless
8062 some effort has been made to ensure that, aside
8063 from the way the two compilers transform procedure
8064 names, everything else about the way they generate
8065 code for procedure interfaces is identical.
8066
8067 @item
8068 Native compilers
8069 use libraries of private I/O routines which will not be available
8070 at link time unless you have the native compiler---and you would
8071 have to explicitly ask for them.
8072
8073 For example, on the Sun you
8074 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
8075 command.
8076 @end itemize
8077
8078 @node Other Languages
8079 @chapter Other Languages
8080
8081 @emph{Note: This portion of the documentation definitely needs a lot
8082 of work!}
8083
8084 @menu
8085 * Interoperating with C and C++::
8086 @end menu
8087
8088 @node Interoperating with C and C++
8089 @section Tools and advice for interoperating with C and C++
8090
8091 @cindex C, linking with
8092 @cindex C++, linking with
8093 @cindex linking with C
8094 The following discussion assumes that you are running @code{g77} in @code{f2c}
8095 compatibility mode, i.e.@: not using @samp{-fno-f2c}.
8096 It provides some
8097 advice about quick and simple techniques for linking Fortran and C (or
8098 C++), the most common requirement.
8099 For the full story consult the
8100 description of code generation.
8101 @xref{Debugging and Interfacing}.
8102
8103 When linking Fortran and C, it's usually best to use @code{g77} to do
8104 the linking so that the correct libraries are included (including the
8105 maths one).
8106 If you're linking with C++ you will want to add
8107 @samp{-lstdc++}, @samp{-lg++} or whatever.
8108 If you need to use another
8109 driver program (or @code{ld} directly),
8110 you can find out what linkage
8111 options @code{g77} passes by running @samp{g77 -v}.
8112
8113 @menu
8114 * C Interfacing Tools::
8115 * C Access to Type Information::
8116 * f2c Skeletons and Prototypes::
8117 * C++ Considerations::
8118 * Startup Code::
8119 @end menu
8120
8121 @node C Interfacing Tools
8122 @subsection C Interfacing Tools
8123 @pindex f2c
8124 @cindex cfortran.h
8125 @cindex Netlib
8126 Even if you don't actually use it as a compiler, @code{f2c} from
8127 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
8128 interfacing (linking) Fortran and C@.
8129 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
8130
8131 To use @code{f2c} for this purpose you only need retrieve and
8132 build the @file{src} directory from the distribution, consult the
8133 @file{README} instructions there for machine-specifics, and install the
8134 @code{f2c} program on your path.
8135
8136 Something else that might be useful is @samp{cfortran.h} from
8137 @uref{ftp://zebra.desy.de/cfortran}.
8138 This is a fairly general tool which
8139 can be used to generate interfaces for calling in both directions
8140 between Fortran and C@.
8141 It can be used in @code{f2c} mode with
8142 @code{g77}---consult its documentation for details.
8143
8144 @node C Access to Type Information
8145 @subsection Accessing Type Information in C
8146
8147 @cindex types, Fortran/C
8148 Generally, C code written to link with
8149 @code{g77} code---calling and/or being
8150 called from Fortran---should @samp{#include <g2c.h>} to define the C
8151 versions of the Fortran types.
8152 Don't assume Fortran @code{INTEGER} types
8153 correspond to C @code{int}s, for instance; instead, declare them as
8154 @code{integer}, a type defined by @file{g2c.h}.
8155 @file{g2c.h} is installed where @code{gcc} will find it by
8156 default, assuming you use a copy of @code{gcc} compatible with
8157 @code{g77}, probably built at the same time as @code{g77}.
8158
8159 @node f2c Skeletons and Prototypes
8160 @subsection Generating Skeletons and Prototypes with @code{f2c}
8161
8162 @pindex f2c
8163 @cindex -fno-second-underscore
8164 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@: to
8165 interface with an existing library---is to write a file (named, for
8166 example, @file{fred.f}) of dummy Fortran
8167 skeletons comprising just the declaration of the routine(s) and dummy
8168 arguments plus @code{END} statements.
8169 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
8170 into which you can edit
8171 useful code, confident the calling sequence is correct, at least.
8172 (There are some errors otherwise commonly made in generating C
8173 interfaces with @code{f2c} conventions,
8174 such as not using @code{doublereal}
8175 as the return type of a @code{REAL} @code{FUNCTION}.)
8176
8177 @pindex ftnchek
8178 @code{f2c} also can help with calling Fortran from C, using its
8179 @samp{-P} option to generate C prototypes appropriate for calling the
8180 Fortran.@footnote{The files generated like this can also be used for
8181 inter-unit consistency checking of dummy and actual arguments, although
8182 the @code{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
8183 or @uref{ftp://ftp.dsm.fordham.edu} is
8184 probably better for this purpose.}
8185 If the Fortran code containing any
8186 routines to be called from C is in file @file{joe.f}, use the command
8187 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
8188 prototype information.
8189 @code{#include} this in the C which has to call
8190 the Fortran routines to make sure you get it right.
8191
8192 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
8193 between the way Fortran (including compilers like @code{g77}) and
8194 C handle arrays.
8195
8196 @node C++ Considerations
8197 @subsection C++ Considerations
8198
8199 @cindex C++
8200 @code{f2c} can be used to generate suitable code for compilation with a
8201 C++ system using the @samp{-C++} option.
8202 The important thing about linking @code{g77}-compiled
8203 code with C++ is that the prototypes for the @code{g77}
8204 routines must specify C linkage to avoid name mangling.
8205 So, use an @samp{extern "C"} declaration.
8206 @code{f2c}'s @samp{-C++} option will take care
8207 of this when generating skeletons or prototype files as above, and also
8208 avoid clashes with C++ reserved words in addition to those in C@.
8209
8210 @node Startup Code
8211 @subsection Startup Code
8212
8213 @cindex startup code
8214 @cindex run-time, initialization
8215 @cindex initialization, run-time
8216 Unlike with some runtime systems,
8217 it shouldn't be necessary
8218 (unless there are bugs)
8219 to use a Fortran main program unit to ensure the
8220 runtime---specifically the I/O system---is initialized.
8221
8222 However, to use the @code{g77} intrinsics @code{GETARG} and @code{IARGC},
8223 either the @code{main} routine from the @file{libg2c} library must be used,
8224 or the @code{f_setarg} routine
8225 (new as of @code{egcs} version 1.1 and @code{g77} version 0.5.23)
8226 must be called with the appropriate @code{argc} and @code{argv} arguments
8227 prior to the program calling @code{GETARG} or @code{IARGC}.
8228
8229 To provide more flexibility for mixed-language programming
8230 involving @code{g77} while allowing for shared libraries,
8231 as of @code{egcs} version 1.1 and @code{g77} version 0.5.23,
8232 @code{g77}'s @code{main} routine in @code{libg2c}
8233 does the following, in order:
8234
8235 @enumerate
8236 @item
8237 Calls @code{f_setarg}
8238 with the incoming @code{argc} and @code{argv} arguments,
8239 in the same order as for @code{main} itself.
8240
8241 This sets up the command-line environment
8242 for @code{GETARG} and @code{IARGC}.
8243
8244 @item
8245 Calls @code{f_setsig} (with no arguments).
8246
8247 This sets up the signaling and exception environment.
8248
8249 @item
8250 Calls @code{f_init} (with no arguments).
8251
8252 This initializes the I/O environment,
8253 though that should not be necessary,
8254 as all I/O functions in @code{libf2c}
8255 are believed to call @code{f_init} automatically,
8256 if necessary.
8257
8258 (A future version of @code{g77} might skip this explicit step,
8259 to speed up normal exit of a program.)
8260
8261 @item
8262 Arranges for @code{f_exit} to be called (with no arguments)
8263 when the program exits.
8264
8265 This ensures that the I/O environment is properly shut down
8266 before the program exits normally.
8267 Otherwise, output buffers might not be fully flushed,
8268 scratch files might not be deleted, and so on.
8269
8270 The simple way @code{main} does this is
8271 to call @code{f_exit} itself after calling
8272 @code{MAIN__} (in the next step).
8273
8274 However, this does not catch the cases where the program
8275 might call @code{exit} directly,
8276 instead of using the @code{EXIT} intrinsic
8277 (implemented as @code{exit_} in @code{libf2c}).
8278
8279 So, @code{main} attempts to use
8280 the operating environment's @code{onexit} or @code{atexit}
8281 facility, if available,
8282 to cause @code{f_exit} to be called automatically
8283 upon any invocation of @code{exit}.
8284
8285 @item
8286 Calls @code{MAIN__} (with no arguments).
8287
8288 This starts executing the Fortran main program unit for
8289 the application.
8290 (Both @code{g77} and @code{f2c} currently compile a main
8291 program unit so that its global name is @code{MAIN__}.)
8292
8293 @item
8294 If no @code{onexit} or @code{atexit} is provided by the system,
8295 calls @code{f_exit}.
8296
8297 @item
8298 Calls @code{exit} with a zero argument,
8299 to signal a successful program termination.
8300
8301 @item
8302 Returns a zero value to the caller,
8303 to signal a successful program termination,
8304 in case @code{exit} doesn't exit on the system.
8305 @end enumerate
8306
8307 All of the above names are C @code{extern} names,
8308 i.e.@: not mangled.
8309
8310 When using the @code{main} procedure provided by @code{g77}
8311 without a Fortran main program unit,
8312 you need to provide @code{MAIN__}
8313 as the entry point for your C code.
8314 (Make sure you link the object file that defines that
8315 entry point with the rest of your program.)
8316
8317 To provide your own @code{main} procedure
8318 in place of @code{g77}'s,
8319 make sure you specify the object file defining that procedure
8320 @emph{before} @samp{-lg2c} on the @code{g77} command line.
8321 Since the @samp{-lg2c} option is implicitly provided,
8322 this is usually straightforward.
8323 (Use the @samp{--verbose} option to see how and where
8324 @code{g77} implicitly adds @samp{-lg2c} in a command line
8325 that will link the program.
8326 Feel free to specify @samp{-lg2c} explicitly,
8327 as appropriate.)
8328
8329 However, when providing your own @code{main},
8330 make sure you perform the appropriate tasks in the
8331 appropriate order.
8332 For example, if your @code{main} does not call @code{f_setarg},
8333 make sure the rest of your application does not call
8334 @code{GETARG} or @code{IARGC}.
8335
8336 And, if your @code{main} fails to ensure that @code{f_exit}
8337 is called upon program exit,
8338 some files might end up incompletely written,
8339 some scratch files might be left lying around,
8340 and some existing files being written might be left
8341 with old data not properly truncated at the end.
8342
8343 Note that, generally, the @code{g77} operating environment
8344 does not depend on a procedure named @code{MAIN__} actually
8345 being called prior to any other @code{g77}-compiled code.
8346 That is, @code{MAIN__} does not, itself,
8347 set up any important operating-environment characteristics
8348 upon which other code might depend.
8349 This might change in future versions of @code{g77},
8350 with appropriate notification in the release notes.
8351
8352 For more information, consult the source code for the above routines.
8353 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
8354 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
8355
8356 Also, the file @file{@value{path-g77}/com.c} contains the code @code{g77}
8357 uses to open-code (inline) references to @code{IARGC}.
8358
8359 @include g77install.texi
8360
8361 @node Debugging and Interfacing
8362 @chapter Debugging and Interfacing
8363 @cindex debugging
8364 @cindex interfacing
8365 @cindex calling C routines
8366 @cindex C routines calling Fortran
8367 @cindex f2c compatibility
8368
8369 GNU Fortran currently generates code that is object-compatible with
8370 the @code{f2c} converter.
8371 Also, it avoids limitations in the current GBE, such as the
8372 inability to generate a procedure with
8373 multiple entry points, by generating code that is structured
8374 differently (in terms of procedure names, scopes, arguments, and
8375 so on) than might be expected.
8376
8377 As a result, writing code in other languages that calls on, is
8378 called by, or shares in-memory data with @code{g77}-compiled code generally
8379 requires some understanding of the way @code{g77} compiles code for
8380 various constructs.
8381
8382 Similarly, using a debugger to debug @code{g77}-compiled
8383 code, even if that debugger supports native Fortran debugging, generally
8384 requires this sort of information.
8385
8386 This section describes some of the basic information on how
8387 @code{g77} compiles code for constructs involving interfaces to other
8388 languages and to debuggers.
8389
8390 @emph{Caution:} Much or all of this information pertains to only the current
8391 release of @code{g77}, sometimes even to using certain compiler options
8392 with @code{g77} (such as @samp{-fno-f2c}).
8393 Do not write code that depends on this
8394 information without clearly marking said code as nonportable and
8395 subject to review for every new release of @code{g77}.
8396 This information
8397 is provided primarily to make debugging of code generated by this
8398 particular release of @code{g77} easier for the user, and partly to make
8399 writing (generally nonportable) interface code easier.
8400 Both of these
8401 activities require tracking changes in new version of @code{g77} as they
8402 are installed, because new versions can change the behaviors
8403 described in this section.
8404
8405 @menu
8406 * Main Program Unit::  How @code{g77} compiles a main program unit.
8407 * Procedures::         How @code{g77} constructs parameter lists
8408                        for procedures.
8409 * Functions::          Functions returning floating-point or character data.
8410 * Names::              Naming of user-defined variables, procedures, etc.
8411 * Common Blocks::      Accessing common variables while debugging.
8412 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
8413 * Complex Variables::  How @code{g77} performs complex arithmetic.
8414 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
8415 * Adjustable Arrays::  Special consideration for adjustable arrays.
8416 * Alternate Entry Points::  How @code{g77} implements alternate @code{ENTRY}.
8417 * Alternate Returns::  How @code{g77} handles alternate returns.
8418 * Assigned Statement Labels::  How @code{g77} handles @code{ASSIGN}.
8419 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
8420 @end menu
8421
8422 @node Main Program Unit
8423 @section Main Program Unit (PROGRAM)
8424 @cindex PROGRAM statement
8425 @cindex statements, PROGRAM
8426
8427 When @code{g77} compiles a main program unit, it gives it the public
8428 procedure name @code{MAIN__}.
8429 The @code{libg2c} library has the actual @code{main()} procedure
8430 as is typical of C-based environments, and
8431 it is this procedure that performs some initial start-up
8432 activity and then calls @code{MAIN__}.
8433
8434 Generally, @code{g77} and @code{libg2c} are designed so that you need not
8435 include a main program unit written in Fortran in your program---it
8436 can be written in C or some other language.
8437 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
8438 includes a bug fix for @code{libg2c} that solved a problem with using the
8439 @code{OPEN} statement as the first Fortran I/O activity in a program
8440 without a Fortran main program unit.
8441
8442 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
8443 your main program unit---that is, if you intend to compile a @code{main()}
8444 procedure using some other language---you should carefully
8445 examine the code for @code{main()} in @code{libg2c}, found in the source
8446 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
8447 might need to be done by your @code{main()} in order to provide the
8448 Fortran environment your Fortran code is expecting.
8449
8450 @cindex @code{IArgC} intrinsic
8451 @cindex intrinsics, @code{IArgC}
8452 @cindex @code{GetArg} intrinsic
8453 @cindex intrinsics, @code{GetArg}
8454 For example, @code{libg2c}'s @code{main()} sets up the information used by
8455 the @code{IARGC} and @code{GETARG} intrinsics.
8456 Bypassing @code{libg2c}'s @code{main()}
8457 without providing a substitute for this activity would mean
8458 that invoking @code{IARGC} and @code{GETARG} would produce undefined
8459 results.
8460
8461 @cindex debugging
8462 @cindex main program unit, debugging
8463 @cindex main()
8464 @cindex MAIN__()
8465 @cindex .gdbinit
8466 When debugging, one implication of the fact that @code{main()}, which
8467 is the place where the debugged program ``starts'' from the
8468 debugger's point of view, is in @code{libg2c} is that you won't be
8469 starting your Fortran program at a point you recognize as your
8470 Fortran code.
8471
8472 The standard way to get around this problem is to set a break
8473 point (a one-time, or temporary, break point will do) at
8474 the entrance to @code{MAIN__}, and then run the program.
8475 A convenient way to do so is to add the @code{gdb} command
8476
8477 @example
8478 tbreak MAIN__
8479 @end example
8480
8481 @noindent
8482 to the file @file{.gdbinit} in the directory in which you're debugging
8483 (using @code{gdb}).
8484
8485 After doing this, the debugger will see the current execution
8486 point of the program as at the beginning of the main program
8487 unit of your program.
8488
8489 Of course, if you really want to set a break point at some
8490 other place in your program and just start the program
8491 running, without first breaking at @code{MAIN__},
8492 that should work fine.
8493
8494 @node Procedures
8495 @section Procedures (SUBROUTINE and FUNCTION)
8496 @cindex procedures
8497 @cindex SUBROUTINE statement
8498 @cindex statements, SUBROUTINE
8499 @cindex FUNCTION statement
8500 @cindex statements, FUNCTION
8501 @cindex signature of procedures
8502
8503 Currently, @code{g77} passes arguments via reference---specifically,
8504 by passing a pointer to the location in memory of a variable, array,
8505 array element, a temporary location that holds the result of evaluating an
8506 expression, or a temporary or permanent location that holds the value
8507 of a constant.
8508
8509 Procedures that accept @code{CHARACTER} arguments are implemented by
8510 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
8511
8512 The first argument occupies the expected position in the
8513 argument list and has the user-specified name.
8514 This argument
8515 is a pointer to an array of characters, passed by the caller.
8516
8517 The second argument is appended to the end of the user-specified
8518 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
8519 is the user-specified name.
8520 This argument is of the C type @code{ftnlen}
8521 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
8522 is the number of characters the caller has allocated in the
8523 array pointed to by the first argument.
8524
8525 A procedure will ignore the length argument if @samp{X} is not declared
8526 @code{CHARACTER*(*)}, because for other declarations, it knows the
8527 length.
8528 Not all callers necessarily ``know'' this, however, which
8529 is why they all pass the extra argument.
8530
8531 The contents of the @code{CHARACTER} argument are specified by the
8532 address passed in the first argument (named after it).
8533 The procedure can read or write these contents as appropriate.
8534
8535 When more than one @code{CHARACTER} argument is present in the argument
8536 list, the length arguments are appended in the order
8537 the original arguments appear.
8538 So @samp{CALL FOO('HI','THERE')} is implemented in
8539 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
8540 does not provide the trailing null bytes on the constant
8541 strings (@code{f2c} does provide them, but they are unnecessary in
8542 a Fortran environment, and you should not expect them to be
8543 there).
8544
8545 Note that the above information applies to @code{CHARACTER} variables and
8546 arrays @strong{only}.
8547 It does @strong{not} apply to external @code{CHARACTER}
8548 functions or to intrinsic @code{CHARACTER} functions.
8549 That is, no second length argument is passed to @samp{FOO} in this case:
8550
8551 @example
8552 CHARACTER X
8553 EXTERNAL X
8554 CALL FOO(X)
8555 @end example
8556
8557 @noindent
8558 Nor does @samp{FOO} expect such an argument in this case:
8559
8560 @example
8561 SUBROUTINE FOO(X)
8562 CHARACTER X
8563 EXTERNAL X
8564 @end example
8565
8566 Because of this implementation detail, if a program has a bug
8567 such that there is disagreement as to whether an argument is
8568 a procedure, and the type of the argument is @code{CHARACTER}, subtle
8569 symptoms might appear.
8570
8571 @node Functions
8572 @section Functions (FUNCTION and RETURN)
8573 @cindex functions
8574 @cindex FUNCTION statement
8575 @cindex statements, FUNCTION
8576 @cindex RETURN statement
8577 @cindex statements, RETURN
8578 @cindex return type of functions
8579
8580 @code{g77} handles in a special way functions that return the following
8581 types:
8582
8583 @itemize @bullet
8584 @item
8585 @code{CHARACTER}
8586 @item
8587 @code{COMPLEX}
8588 @item
8589 @code{REAL(KIND=1)}
8590 @end itemize
8591
8592 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
8593 returning @code{void})
8594 with two arguments prepended: @samp{__g77_result}, which the caller passes
8595 as a pointer to a @code{char} array expected to hold the return value,
8596 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
8597 specifying the length of the return value as declared in the calling
8598 program.
8599 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
8600 to determine the size of the array that @samp{__g77_result} points to;
8601 otherwise, it ignores that argument.
8602
8603 For @code{COMPLEX}, when @samp{-ff2c} is in
8604 force, @code{g77} implements
8605 a subroutine with one argument prepended: @samp{__g77_result}, which the
8606 caller passes as a pointer to a variable of the type of the function.
8607 The called function writes the return value into this variable instead
8608 of returning it as a function value.
8609 When @samp{-fno-f2c} is in force,
8610 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
8611 @samp{__complex__ float} or @samp{__complex__ double} function
8612 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
8613 returning the result of the function in the same way as @code{gcc} would.
8614
8615 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
8616 a function that actually returns @code{REAL(KIND=2)} (typically
8617 C's @code{double} type).
8618 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
8619 functions return @code{float}.
8620
8621 @node Names
8622 @section Names
8623 @cindex symbol names
8624 @cindex transforming symbol names
8625
8626 Fortran permits each implementation to decide how to represent
8627 names as far as how they're seen in other contexts, such as debuggers
8628 and when interfacing to other languages, and especially as far
8629 as how casing is handled.
8630
8631 External names---names of entities that are public, or ``accessible'',
8632 to all modules in a program---normally have an underscore (@samp{_})
8633 appended by @code{g77},
8634 to generate code that is compatible with @code{f2c}.
8635 External names include names of Fortran things like common blocks,
8636 external procedures (subroutines and functions, but not including
8637 statement functions, which are internal procedures), and entry point
8638 names.
8639
8640 However, use of the @samp{-fno-underscoring} option
8641 disables this kind of transformation of external names (though inhibiting
8642 the transformation certainly improves the chances of colliding with
8643 incompatible externals written in other languages---but that
8644 might be intentional.
8645
8646 @cindex -fno-underscoring option
8647 @cindex options, -fno-underscoring
8648 @cindex -fno-second-underscore option
8649 @cindex options, -fno-underscoring
8650 When @samp{-funderscoring} is in force, any name (external or local)
8651 that already has at least one underscore in it is
8652 implemented by @code{g77} by appending two underscores.
8653 (This second underscore can be disabled via the
8654 @samp{-fno-second-underscore} option.)
8655 External names are changed this way for @code{f2c} compatibility.
8656 Local names are changed this way to avoid collisions with external names
8657 that are different in the source code---@code{f2c} does the same thing, but
8658 there's no compatibility issue there except for user expectations while
8659 debugging.
8660
8661 For example:
8662
8663 @example
8664 Max_Cost = 0
8665 @end example
8666
8667 @cindex debugging
8668 @noindent
8669 Here, a user would, in the debugger, refer to this variable using the
8670 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
8671 as described below).
8672 (We hope to improve @code{g77} in this regard in the future---don't
8673 write scripts depending on this behavior!
8674 Also, consider experimenting with the @samp{-fno-underscoring}
8675 option to try out debugging without having to massage names by
8676 hand like this.)
8677
8678 @code{g77} provides a number of command-line options that allow the user
8679 to control how case mapping is handled for source files.
8680 The default is the traditional UNIX model for Fortran compilers---names
8681 are mapped to lower case.
8682 Other command-line options can be specified to map names to upper
8683 case, or to leave them exactly as written in the source file.
8684
8685 For example:
8686
8687 @example
8688 Foo = 9.436
8689 @end example
8690
8691 @noindent
8692 Here, it is normally the case that the variable assigned will be named
8693 @samp{foo}.
8694 This would be the name to enter when using a debugger to
8695 access the variable.
8696
8697 However, depending on the command-line options specified, the
8698 name implemented by @code{g77} might instead be @samp{FOO} or even
8699 @samp{Foo}, thus affecting how debugging is done.
8700
8701 Also:
8702
8703 @example
8704 Call Foo
8705 @end example
8706
8707 @noindent
8708 This would normally call a procedure that, if it were in a separate C program,
8709 be defined starting with the line:
8710
8711 @example
8712 void foo_()
8713 @end example
8714
8715 @noindent
8716 However, @code{g77} command-line options could be used to change the casing
8717 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
8718 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
8719 could be used to inhibit the appending of the underscore to the name.
8720
8721 @node Common Blocks
8722 @section Common Blocks (COMMON)
8723 @cindex common blocks
8724 @cindex @code{COMMON} statement
8725 @cindex statements, @code{COMMON}
8726
8727 @code{g77} names and lays out @code{COMMON} areas
8728 the same way @code{f2c} does,
8729 for compatibility with @code{f2c}.
8730
8731 @node Local Equivalence Areas
8732 @section Local Equivalence Areas (EQUIVALENCE)
8733 @cindex equivalence areas
8734 @cindex local equivalence areas
8735 @cindex EQUIVALENCE statement
8736 @cindex statements, EQUIVALENCE
8737
8738 @code{g77} treats storage-associated areas involving a @code{COMMON}
8739 block as explained in the section on common blocks.
8740
8741 A local @code{EQUIVALENCE} area is a collection of variables and arrays
8742 connected to each other in any way via @code{EQUIVALENCE}, none of which are
8743 listed in a @code{COMMON} statement.
8744
8745 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
8746 for @var{x} using a different method when more than one name was
8747 in the list of names of entities placed at the beginning of the
8748 array.
8749 Though the documentation specified that the first name listed in
8750 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
8751 in fact chose the name using a method that was so complicated,
8752 it seemed easier to change it to an alphabetical sort than to describe the
8753 previous method in the documentation.)
8754
8755 @node Complex Variables
8756 @section Complex Variables (COMPLEX)
8757 @cindex complex variables
8758 @cindex imaginary part
8759 @cindex COMPLEX statement
8760 @cindex statements, COMPLEX
8761
8762 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
8763 (and related intrinsics, constants, functions, and so on)
8764 in a manner that
8765 makes direct debugging involving these types in Fortran
8766 language mode difficult.
8767
8768 Essentially, @code{g77} implements these types using an
8769 internal construct similar to C's @code{struct}, at least
8770 as seen by the @code{gcc} back end.
8771
8772 Currently, the back end, when outputting debugging info with
8773 the compiled code for the assembler to digest, does not detect
8774 these @code{struct} types as being substitutes for Fortran
8775 complex.
8776 As a result, the Fortran language modes of debuggers such as
8777 @code{gdb} see these types as C @code{struct} types, which
8778 they might or might not support.
8779
8780 Until this is fixed, switch to C language mode to work with
8781 entities of @code{COMPLEX} type and then switch back to Fortran language
8782 mode afterward.
8783 (In @code{gdb}, this is accomplished via @samp{set lang c} and
8784 either @samp{set lang fortran} or @samp{set lang auto}.)
8785
8786 @node Arrays
8787 @section Arrays (DIMENSION)
8788 @cindex DIMENSION statement
8789 @cindex statements, DIMENSION
8790 @cindex array ordering
8791 @cindex ordering, array
8792 @cindex column-major ordering
8793 @cindex row-major ordering
8794 @cindex arrays
8795
8796 Fortran uses ``column-major ordering'' in its arrays.
8797 This differs from other languages, such as C, which use ``row-major ordering''.
8798 The difference is that, with Fortran, array elements adjacent to
8799 each other in memory differ in the @emph{first} subscript instead of
8800 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
8801 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
8802
8803 This consideration
8804 affects not only interfacing with and debugging Fortran code,
8805 it can greatly affect how code is designed and written, especially
8806 when code speed and size is a concern.
8807
8808 Fortran also differs from C, a popular language for interfacing and
8809 to support directly in debuggers, in the way arrays are treated.
8810 In C, arrays are single-dimensional and have interesting relationships
8811 to pointers, neither of which is true for Fortran.
8812 As a result, dealing with Fortran arrays from within
8813 an environment limited to C concepts can be challenging.
8814
8815 For example, accessing the array element @samp{A(5,10,20)} is easy enough
8816 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
8817 are needed.
8818 First, C would treat the A array as a single-dimension array.
8819 Second, C does not understand low bounds for arrays as does Fortran.
8820 Third, C assumes a low bound of zero (0), while Fortran defaults to a
8821 low bound of one (1) and can supports an arbitrary low bound.
8822 Therefore, calculations must be done
8823 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
8824 calculations require knowing the dimensions of @samp{A}.
8825
8826 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
8827 @samp{A(5,10,20)} would be:
8828
8829 @example
8830   (5-2)
8831 + (10-1)*(11-2+1)
8832 + (20-0)*(11-2+1)*(21-1+1)
8833 = 4293
8834 @end example
8835
8836 @noindent
8837 So the C equivalent in this case would be @samp{a[4293]}.
8838
8839 When using a debugger directly on Fortran code, the C equivalent
8840 might not work, because some debuggers cannot understand the notion
8841 of low bounds other than zero.  However, unlike @code{f2c}, @code{g77}
8842 does inform the GBE that a multi-dimensional array (like @samp{A}
8843 in the above example) is really multi-dimensional, rather than a
8844 single-dimensional array, so at least the dimensionality of the array
8845 is preserved.
8846
8847 Debuggers that understand Fortran should have no trouble with
8848 non-zero low bounds, but for non-Fortran debuggers, especially
8849 C debuggers, the above example might have a C equivalent of
8850 @samp{a[4305]}.
8851 This calculation is arrived at by eliminating the subtraction
8852 of the lower bound in the first parenthesized expression on each
8853 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
8854 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
8855 Actually, the implication of
8856 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
8857 but that @samp{a[20][10][5]} produces the equivalent of
8858 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
8859
8860 Come to think of it, perhaps
8861 the behavior is due to the debugger internally compensating for
8862 the lower bounds by offsetting the base address of @samp{a}, leaving
8863 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
8864 its first element as identified by subscripts equal to the
8865 corresponding lower bounds).
8866
8867 You know, maybe nobody really needs to use arrays.
8868
8869 @node Adjustable Arrays
8870 @section Adjustable Arrays (DIMENSION)
8871 @cindex arrays, adjustable
8872 @cindex adjustable arrays
8873 @cindex arrays, automatic
8874 @cindex automatic arrays
8875 @cindex DIMENSION statement
8876 @cindex statements, DIMENSION
8877 @cindex dimensioning arrays
8878 @cindex arrays, dimensioning
8879
8880 Adjustable and automatic arrays in Fortran require the implementation
8881 (in this
8882 case, the @code{g77} compiler) to ``memorize'' the expressions that
8883 dimension the arrays each time the procedure is invoked.
8884 This is so that subsequent changes to variables used in those
8885 expressions, made during execution of the procedure, do not
8886 have any effect on the dimensions of those arrays.
8887
8888 For example:
8889
8890 @example
8891 REAL ARRAY(5)
8892 DATA ARRAY/5*2/
8893 CALL X(ARRAY, 5)
8894 END
8895 SUBROUTINE X(A, N)
8896 DIMENSION A(N)
8897 N = 20
8898 PRINT *, N, A
8899 END
8900 @end example
8901
8902 @noindent
8903 Here, the implementation should, when running the program, print something
8904 like:
8905
8906 @example
8907 20   2.  2.  2.  2.  2.
8908 @end example
8909
8910 @noindent
8911 Note that this shows that while the value of @samp{N} was successfully
8912 changed, the size of the @samp{A} array remained at 5 elements.
8913
8914 To support this, @code{g77} generates code that executes before any user
8915 code (and before the internally generated computed @code{GOTO} to handle
8916 alternate entry points, as described below) that evaluates each
8917 (nonconstant) expression in the list of subscripts for an
8918 array, and saves the result of each such evaluation to be used when
8919 determining the size of the array (instead of re-evaluating the
8920 expressions).
8921
8922 So, in the above example, when @samp{X} is first invoked, code is
8923 executed that copies the value of @samp{N} to a temporary.
8924 And that same temporary serves as the actual high bound for the single
8925 dimension of the @samp{A} array (the low bound being the constant 1).
8926 Since the user program cannot (legitimately) change the value
8927 of the temporary during execution of the procedure, the size
8928 of the array remains constant during each invocation.
8929
8930 For alternate entry points, the code @code{g77} generates takes into
8931 account the possibility that a dummy adjustable array is not actually
8932 passed to the actual entry point being invoked at that time.
8933 In that case, the public procedure implementing the entry point
8934 passes to the master private procedure implementing all the
8935 code for the entry points a @code{NULL} pointer where a pointer to that
8936 adjustable array would be expected.
8937 The @code{g77}-generated code
8938 doesn't attempt to evaluate any of the expressions in the subscripts
8939 for an array if the pointer to that array is @code{NULL} at run time in
8940 such cases.
8941 (Don't depend on this particular implementation
8942 by writing code that purposely passes @code{NULL} pointers where the
8943 callee expects adjustable arrays, even if you know the callee
8944 won't reference the arrays---nor should you pass @code{NULL} pointers
8945 for any dummy arguments used in calculating the bounds of such
8946 arrays or leave undefined any values used for that purpose in
8947 COMMON---because the way @code{g77} implements these things might
8948 change in the future!)
8949
8950 @node Alternate Entry Points
8951 @section Alternate Entry Points (ENTRY)
8952 @cindex alternate entry points
8953 @cindex entry points
8954 @cindex ENTRY statement
8955 @cindex statements, ENTRY
8956
8957 The GBE does not understand the general concept of
8958 alternate entry points as Fortran provides via the ENTRY statement.
8959 @code{g77} gets around this by using an approach to compiling procedures
8960 having at least one @code{ENTRY} statement that is almost identical to the
8961 approach used by @code{f2c}.
8962 (An alternate approach could be used that
8963 would probably generate faster, but larger, code that would also
8964 be a bit easier to debug.)
8965
8966 Information on how @code{g77} implements @code{ENTRY} is provided for those
8967 trying to debug such code.
8968 The choice of implementation seems
8969 unlikely to affect code (compiled in other languages) that interfaces
8970 to such code.
8971
8972 @code{g77} compiles exactly one public procedure for the primary entry
8973 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
8974 That is, in terms of the public interface, there is no difference
8975 between
8976
8977 @example
8978 SUBROUTINE X
8979 END
8980 SUBROUTINE Y
8981 END
8982 @end example
8983
8984 @noindent
8985 and:
8986
8987 @example
8988 SUBROUTINE X
8989 ENTRY Y
8990 END
8991 @end example
8992
8993 The difference between the above two cases lies in the code compiled
8994 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
8995 for the second case, an extra internal procedure is compiled.
8996
8997 For every Fortran procedure with at least one @code{ENTRY}
8998 statement, @code{g77} compiles an extra procedure
8999 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
9000 the name of the primary entry point (which, in the above case,
9001 using the standard compiler options, would be @samp{x_} in C).
9002
9003 This extra procedure is compiled as a private procedure---that is,
9004 a procedure not accessible by name to separately compiled modules.
9005 It contains all the code in the program unit, including the code
9006 for the primary entry point plus for every entry point.
9007 (The code for each public procedure is quite short, and explained later.)
9008
9009 The extra procedure has some other interesting characteristics.
9010
9011 The argument list for this procedure is invented by @code{g77}.
9012 It contains
9013 a single integer argument named @samp{__g77_which_entrypoint},
9014 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
9015 entry point index---0 for the primary entry point, 1 for the
9016 first entry point (the first @code{ENTRY} statement encountered), 2 for
9017 the second entry point, and so on.
9018
9019 It also contains, for functions returning @code{CHARACTER} and
9020 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
9021 and for functions returning different types among the
9022 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
9023 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
9024 is expected at run time to contain a pointer to where to store
9025 the result of the entry point.
9026 For @code{CHARACTER} functions, this
9027 storage area is an array of the appropriate number of characters;
9028 for @code{COMPLEX} functions, it is the appropriate area for the return
9029 type; for multiple-return-type functions, it is a union of all the supported return
9030 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
9031 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
9032 is not supported by @code{g77}).
9033
9034 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
9035 by yet another argument named @samp{__g77_length} that, at run time,
9036 specifies the caller's expected length of the returned value.
9037 Note that only @code{CHARACTER*(*)} functions and entry points actually
9038 make use of this argument, even though it is always passed by
9039 all callers of public @code{CHARACTER} functions (since the caller does not
9040 generally know whether such a function is @code{CHARACTER*(*)} or whether
9041 there are any other callers that don't have that information).
9042
9043 The rest of the argument list is the union of all the arguments
9044 specified for all the entry points (in their usual forms, e.g.
9045 @code{CHARACTER} arguments have extra length arguments, all appended at
9046 the end of this list).
9047 This is considered the ``master list'' of
9048 arguments.
9049
9050 The code for this procedure has, before the code for the first
9051 executable statement, code much like that for the following Fortran
9052 statement:
9053
9054 @smallexample
9055        GOTO (100000,100001,100002), __g77_which_entrypoint
9056 100000 @dots{}code for primary entry point@dots{}
9057 100001 @dots{}code immediately following first ENTRY statement@dots{}
9058 100002 @dots{}code immediately following second ENTRY statement@dots{}
9059 @end smallexample
9060
9061 @noindent
9062 (Note that invalid Fortran statement labels and variable names
9063 are used in the above example to highlight the fact that it
9064 represents code generated by the @code{g77} internals, not code to be
9065 written by the user.)
9066
9067 It is this code that, when the procedure is called, picks which
9068 entry point to start executing.
9069
9070 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
9071 example), those procedures are fairly simple.
9072 Their interfaces
9073 are just like they would be if they were self-contained procedures
9074 (without @code{ENTRY}), of course, since that is what the callers
9075 expect.
9076 Their code consists of simply calling the private
9077 procedure, described above, with the appropriate extra arguments
9078 (the entry point index, and perhaps a pointer to a multiple-type-
9079 return variable, local to the public procedure, that contains
9080 all the supported returnable non-character types).
9081 For arguments
9082 that are not listed for a given entry point that are listed for
9083 other entry points, and therefore that are in the ``master list''
9084 for the private procedure, null pointers (in C, the @code{NULL} macro)
9085 are passed.
9086 Also, for entry points that are part of a multiple-type-
9087 returning function, code is compiled after the call of the private
9088 procedure to extract from the multi-type union the appropriate result,
9089 depending on the type of the entry point in question, returning
9090 that result to the original caller.
9091
9092 When debugging a procedure containing alternate entry points, you
9093 can either set a break point on the public procedure itself (e.g.
9094 a break point on @samp{X} or @samp{Y}) or on the private procedure that
9095 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
9096 If you do the former, you should use the debugger's command to
9097 ``step into'' the called procedure to get to the actual code; with
9098 the latter approach, the break point leaves you right at the
9099 actual code, skipping over the public entry point and its call
9100 to the private procedure (unless you have set a break point there
9101 as well, of course).
9102
9103 Further, the list of dummy arguments that is visible when the
9104 private procedure is active is going to be the expanded version
9105 of the list for whichever particular entry point is active,
9106 as explained above, and the way in which return values are
9107 handled might well be different from how they would be handled
9108 for an equivalent single-entry function.
9109
9110 @node Alternate Returns
9111 @section Alternate Returns (SUBROUTINE and RETURN)
9112 @cindex subroutines
9113 @cindex alternate returns
9114 @cindex SUBROUTINE statement
9115 @cindex statements, SUBROUTINE
9116 @cindex RETURN statement
9117 @cindex statements, RETURN
9118
9119 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
9120 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
9121 the C @code{int} type.
9122 The actual alternate-return arguments are omitted from the calling sequence.
9123 Instead, the caller uses
9124 the return value to do a rough equivalent of the Fortran
9125 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
9126 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
9127 function), and the callee just returns whatever integer
9128 is specified in the @code{RETURN} statement for the subroutine
9129 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
9130 by @samp{RETURN}
9131 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
9132
9133 @node Assigned Statement Labels
9134 @section Assigned Statement Labels (ASSIGN and GOTO)
9135 @cindex assigned statement labels
9136 @cindex statement labels, assigned
9137 @cindex ASSIGN statement
9138 @cindex statements, ASSIGN
9139 @cindex GOTO statement
9140 @cindex statements, GOTO
9141
9142 For portability to machines where a pointer (such as to a label,
9143 which is how @code{g77} implements @code{ASSIGN} and its relatives,
9144 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
9145 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
9146 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
9147 than it does the numerical value in that variable, unless the
9148 variable is wide enough (can hold enough bits).
9149
9150 In particular, while @code{g77} implements
9151
9152 @example
9153 I = 10
9154 @end example
9155
9156 @noindent
9157 as, in C notation, @samp{i = 10;}, it implements
9158
9159 @example
9160 ASSIGN 10 TO I
9161 @end example
9162
9163 @noindent
9164 as, in GNU's extended C notation (for the label syntax),
9165 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
9166 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
9167 actually generate the name @samp{L10} or any other name like that,
9168 since debuggers cannot access labels anyway).
9169
9170 While this currently means that an @code{ASSIGN} statement does not
9171 overwrite the numeric contents of its target variable, @emph{do not}
9172 write any code depending on this feature.
9173 @code{g77} has already changed this implementation across
9174 versions and might do so in the future.
9175 This information is provided only to make debugging Fortran programs
9176 compiled with the current version of @code{g77} somewhat easier.
9177 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
9178 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
9179 means @code{g77} has decided it can store the pointer to the label directly
9180 into @samp{I} itself.
9181
9182 @xref{Ugly Assigned Labels}, for information on a command-line option
9183 to force @code{g77} to use the same storage for both normal and
9184 assigned-label uses of a variable.
9185
9186 @node Run-time Library Errors
9187 @section Run-time Library Errors
9188 @cindex IOSTAT=
9189 @cindex error values
9190 @cindex error messages
9191 @cindex messages, run-time
9192 @cindex I/O, errors
9193
9194 The @code{libg2c} library currently has the following table to relate
9195 error code numbers, returned in @code{IOSTAT=} variables, to messages.
9196 This information should, in future versions of this document, be
9197 expanded upon to include detailed descriptions of each message.
9198
9199 In line with good coding practices, any of the numbers in the
9200 list below should @emph{not} be directly written into Fortran
9201 code you write.
9202 Instead, make a separate @code{INCLUDE} file that defines
9203 @code{PARAMETER} names for them, and use those in your code,
9204 so you can more easily change the actual numbers in the future.
9205
9206 The information below is culled from the definition
9207 of @code{F_err} in @file{f/runtime/libI77/err.c} in the
9208 @code{g77} source tree.
9209
9210 @smallexample
9211 100: "error in format"
9212 101: "illegal unit number"
9213 102: "formatted io not allowed"
9214 103: "unformatted io not allowed"
9215 104: "direct io not allowed"
9216 105: "sequential io not allowed"
9217 106: "can't backspace file"
9218 107: "null file name"
9219 108: "can't stat file"
9220 109: "unit not connected"
9221 110: "off end of record"
9222 111: "truncation failed in endfile"
9223 112: "incomprehensible list input"
9224 113: "out of free space"
9225 114: "unit not connected"
9226 115: "read unexpected character"
9227 116: "bad logical input field"
9228 117: "bad variable type"
9229 118: "bad namelist name"
9230 119: "variable not in namelist"
9231 120: "no end record"
9232 121: "variable count incorrect"
9233 122: "subscript for scalar variable"
9234 123: "invalid array section"
9235 124: "substring out of bounds"
9236 125: "subscript out of bounds"
9237 126: "can't read file"
9238 127: "can't write file"
9239 128: "'new' file exists"
9240 129: "can't append to file"
9241 130: "non-positive record number"
9242 131: "I/O started while already doing I/O"
9243 @end smallexample
9244
9245 @node Collected Fortran Wisdom
9246 @chapter Collected Fortran Wisdom
9247 @cindex wisdom
9248 @cindex legacy code
9249 @cindex code, legacy
9250 @cindex writing code
9251 @cindex code, writing
9252
9253 Most users of @code{g77} can be divided into two camps:
9254
9255 @itemize @bullet
9256 @item
9257 Those writing new Fortran code to be compiled by @code{g77}.
9258
9259 @item
9260 Those using @code{g77} to compile existing, ``legacy'' code.
9261 @end itemize
9262
9263 Users writing new code generally understand most of the necessary
9264 aspects of Fortran to write ``mainstream'' code, but often need
9265 help deciding how to handle problems, such as the construction
9266 of libraries containing @code{BLOCK DATA}.
9267
9268 Users dealing with ``legacy'' code sometimes don't have much
9269 experience with Fortran, but believe that the code they're compiling
9270 already works when compiled by other compilers (and might
9271 not understand why, as is sometimes the case, it doesn't work
9272 when compiled by @code{g77}).
9273
9274 The following information is designed to help users do a better job
9275 coping with existing, ``legacy'' Fortran code, and with writing
9276 new code as well.
9277
9278 @menu
9279 * Advantages Over f2c::        If @code{f2c} is so great, why @code{g77}?
9280 * Block Data and Libraries::   How @code{g77} solves a common problem.
9281 * Loops::                      Fortran @code{DO} loops surprise many people.
9282 * Working Programs::           Getting programs to work should be done first.
9283 * Overly Convenient Options::  Temptations to avoid, habits to not form.
9284 * Faster Programs::            Everybody wants these, but at what cost?
9285 @end menu
9286
9287 @node Advantages Over f2c
9288 @section Advantages Over f2c
9289
9290 Without @code{f2c}, @code{g77} would have taken much longer to
9291 do and probably not been as good for quite a while.
9292 Sometimes people who notice how much @code{g77} depends on, and
9293 documents encouragement to use, @code{f2c} ask why @code{g77}
9294 was created if @code{f2c} already existed.
9295
9296 This section gives some basic answers to these questions, though it
9297 is not intended to be comprehensive.
9298
9299 @menu
9300 * Language Extensions::  Features used by Fortran code.
9301 * Diagnostic Abilities:: Abilities to spot problems early.
9302 * Compiler Options::     Features helpful to accommodate legacy code, etc.
9303 * Compiler Speed::       Speed of the compilation process.
9304 * Program Speed::        Speed of the generated, optimized code.
9305 * Ease of Debugging::    Debugging ease-of-use at the source level.
9306 * Character and Hollerith Constants::  A byte saved is a byte earned.
9307 @end menu
9308
9309 @node Language Extensions
9310 @subsection Language Extensions
9311
9312 @code{g77} offers several extensions to FORTRAN 77 language that @code{f2c}
9313 doesn't:
9314
9315 @itemize @bullet
9316 @item
9317 Automatic arrays
9318
9319 @item
9320 @code{CYCLE} and @code{EXIT}
9321
9322 @item
9323 Construct names
9324
9325 @item
9326 @code{SELECT CASE}
9327
9328 @item
9329 @code{KIND=} and @code{LEN=} notation
9330
9331 @item
9332 Semicolon as statement separator
9333
9334 @item
9335 Constant expressions in @code{FORMAT} statements
9336 (such as @samp{FORMAT(I<J>)},
9337 where @samp{J} is a @code{PARAMETER} named constant)
9338
9339 @item
9340 @code{MvBits} intrinsic
9341
9342 @item
9343 @code{libU77} (Unix-compatibility) library,
9344 with routines known to compiler as intrinsics
9345 (so they work even when compiler options are used
9346 to change the interfaces used by Fortran routines)
9347 @end itemize
9348
9349 @code{g77} also implements iterative @code{DO} loops
9350 so that they work even in the presence of certain ``extreme'' inputs,
9351 unlike @code{f2c}.
9352 @xref{Loops}.
9353
9354 However, @code{f2c} offers a few that @code{g77} doesn't, such as:
9355
9356 @itemize @bullet
9357 @item
9358 Intrinsics in @code{PARAMETER} statements
9359
9360 @item
9361 Array bounds expressions (such as @samp{REAL M(N(2))})
9362
9363 @item
9364 @code{AUTOMATIC} statement
9365 @end itemize
9366
9367 It is expected that @code{g77} will offer some or all of these missing
9368 features at some time in the future.
9369
9370 @node Diagnostic Abilities
9371 @subsection Diagnostic Abilities
9372
9373 @code{g77} offers better diagnosis of problems in @code{FORMAT} statements.
9374 @code{f2c} doesn't, for example, emit any diagnostic for
9375 @samp{FORMAT(XZFAJG10324)},
9376 leaving that to be diagnosed, at run time, by
9377 the @code{libf2c} run-time library.
9378
9379 @node Compiler Options
9380 @subsection Compiler Options
9381
9382 @code{g77} offers compiler options that @code{f2c} doesn't,
9383 most of which are designed to more easily accommodate
9384 legacy code:
9385
9386 @itemize @bullet
9387 @item
9388 Two that control the automatic appending of extra
9389 underscores to external names
9390
9391 @item
9392 One that allows dollar signs (@samp{$}) in symbol names
9393
9394 @item
9395 A variety that control acceptance of various
9396 ``ugly'' constructs
9397
9398 @item
9399 Several that specify acceptable use of upper and lower case
9400 in the source code
9401
9402 @item
9403 Many that enable, disable, delete, or hide
9404 groups of intrinsics
9405
9406 @item
9407 One to specify the length of fixed-form source lines
9408 (normally 72)
9409
9410 @item
9411 One to specify the the source code is written in
9412 Fortran-90-style free-form
9413 @end itemize
9414
9415 However, @code{f2c} offers a few that @code{g77} doesn't,
9416 like an option to have @code{REAL} default to @code{REAL*8}.
9417 It is expected that @code{g77} will offer all of the
9418 missing options pertinent to being a Fortran compiler
9419 at some time in the future.
9420
9421 @node Compiler Speed
9422 @subsection Compiler Speed
9423
9424 Saving the steps of writing and then rereading C code is a big reason
9425 why @code{g77} should be able to compile code much faster than using
9426 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
9427
9428 However, due to @code{g77}'s youth, lots of self-checking is still being
9429 performed.
9430 As a result, this improvement is as yet unrealized
9431 (though the potential seems to be there for quite a big speedup
9432 in the future).
9433 It is possible that, as of version 0.5.18, @code{g77}
9434 is noticeably faster compiling many Fortran source files than using
9435 @code{f2c} in conjunction with @code{gcc}.
9436
9437 @node Program Speed
9438 @subsection Program Speed
9439
9440 @code{g77} has the potential to better optimize code than @code{f2c},
9441 even when @code{gcc} is used to compile the output of @code{f2c},
9442 because @code{f2c} must necessarily
9443 translate Fortran into a somewhat lower-level language (C) that cannot
9444 preserve all the information that is potentially useful for optimization,
9445 while @code{g77} can gather, preserve, and transmit that information directly
9446 to the GBE.
9447
9448 For example, @code{g77} implements @code{ASSIGN} and assigned
9449 @code{GOTO} using direct assignment of pointers to labels and direct
9450 jumps to labels, whereas @code{f2c} maps the assigned labels to
9451 integer values and then uses a C @code{switch} statement to encode
9452 the assigned @code{GOTO} statements.
9453
9454 However, as is typical, theory and reality don't quite match, at least
9455 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
9456 can generate code that is faster than @code{g77}.
9457
9458 Version 0.5.18 of @code{g77} offered default
9459 settings and options, via patches to the @code{gcc}
9460 back end, that allow for better program speed, though
9461 some of these improvements also affected the performance
9462 of programs translated by @code{f2c} and then compiled
9463 by @code{g77}'s version of @code{gcc}.
9464
9465 Version 0.5.20 of @code{g77} offers further performance
9466 improvements, at least one of which (alias analysis) is
9467 not generally applicable to @code{f2c} (though @code{f2c}
9468 could presumably be changed to also take advantage of
9469 this new capability of the @code{gcc} back end, assuming
9470 this is made available in an upcoming release of @code{gcc}).
9471
9472 @node Ease of Debugging
9473 @subsection Ease of Debugging
9474
9475 Because @code{g77} compiles directly to assembler code like @code{gcc},
9476 instead of translating to an intermediate language (C) as does @code{f2c},
9477 support for debugging can be better for @code{g77} than @code{f2c}.
9478
9479 However, although @code{g77} might be somewhat more ``native'' in terms of
9480 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
9481 of things ``not quite right''.
9482 Many of the important ones should be resolved in the near future.
9483
9484 For example, @code{g77} doesn't have to worry about reserved names
9485 like @code{f2c} does.
9486 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
9487 translate this to something @emph{other} than
9488 @samp{for = while;}, because C reserves those words.
9489
9490 However, @code{g77} does still uses things like an extra level of indirection
9491 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
9492 yet support multiple entry points.
9493
9494 Another example is that, given
9495
9496 @smallexample
9497 COMMON A, B
9498 EQUIVALENCE (B, C)
9499 @end smallexample
9500
9501 @noindent
9502 the @code{g77} user should be able to access the variables directly, by name,
9503 without having to traverse C-like structures and unions, while @code{f2c}
9504 is unlikely to ever offer this ability (due to limitations in the
9505 C language).
9506
9507 However, due to apparent bugs in the back end, @code{g77} currently doesn't
9508 take advantage of this facility at all---it doesn't emit any debugging
9509 information for @code{COMMON} and @code{EQUIVALENCE} areas,
9510 other than information
9511 on the array of @code{char} it creates (and, in the case
9512 of local @code{EQUIVALENCE}, names) for each such area.
9513
9514 Yet another example is arrays.
9515 @code{g77} represents them to the debugger
9516 using the same ``dimensionality'' as in the source code, while @code{f2c}
9517 must necessarily convert them all to one-dimensional arrays to fit
9518 into the confines of the C language.
9519 However, the level of support
9520 offered by debuggers for interactive Fortran-style access to arrays
9521 as compiled by @code{g77} can vary widely.
9522 In some cases, it can actually
9523 be an advantage that @code{f2c} converts everything to widely supported
9524 C semantics.
9525
9526 In fairness, @code{g77} could do many of the things @code{f2c} does
9527 to get things working at least as well as @code{f2c}---for now,
9528 the developers prefer making @code{g77} work the
9529 way they think it is supposed to, and finding help improving the
9530 other products (the back end of @code{gcc}; @code{gdb}; and so on)
9531 to get things working properly.
9532
9533 @node Character and Hollerith Constants
9534 @subsection Character and Hollerith Constants
9535 @cindex character constants
9536 @cindex constants, character
9537 @cindex Hollerith constants
9538 @cindex constants, Hollerith
9539 @cindex trailing null byte
9540 @cindex null byte, trailing
9541 @cindex zero byte, trailing
9542
9543 To avoid the extensive hassle that would be needed to avoid this,
9544 @code{f2c} uses C character constants to encode character and Hollerith
9545 constants.
9546 That means a constant like @samp{'HELLO'} is translated to
9547 @samp{"hello"} in C, which further means that an extra null byte is
9548 present at the end of the constant.
9549 This null byte is superfluous.
9550
9551 @code{g77} does not generate such null bytes.
9552 This represents significant
9553 savings of resources, such as on systems where @file{/dev/null} or
9554 @file{/dev/zero} represent bottlenecks in the systems' performance,
9555 because @code{g77} simply asks for fewer zeros from the operating
9556 system than @code{f2c}.
9557 (Avoiding spurious use of zero bytes, each byte typically have
9558 eight zero bits, also reduces the liabilities in case
9559 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
9560
9561 @node Block Data and Libraries
9562 @section Block Data and Libraries
9563 @cindex block data and libraries
9564 @cindex BLOCK DATA statement
9565 @cindex statements, BLOCK DATA
9566 @cindex libraries, containing BLOCK DATA
9567 @cindex f2c compatibility
9568 @cindex compatibility, f2c
9569
9570 To ensure that block data program units are linked, especially a concern
9571 when they are put into libraries, give each one a name (as in
9572 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
9573 statement in every program unit that uses any common block
9574 initialized by the corresponding @code{BLOCK DATA}.
9575 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
9576 @code{SUBROUTINE},
9577 that is, it generates an actual procedure having the appropriate name.
9578 The procedure does nothing but return immediately if it happens to be
9579 called.
9580 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
9581 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
9582 in the program and ensures that by generating a
9583 reference to it so the linker will make sure it is present.
9584 (Specifically, @code{g77} outputs in the data section a static pointer to the
9585 external name @samp{FOO}.)
9586
9587 The implementation @code{g77} currently uses to make this work is
9588 one of the few things not compatible with @code{f2c} as currently
9589 shipped.
9590 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
9591 issue a warning that @samp{FOO} is not otherwise referenced,
9592 and, for @samp{BLOCK DATA FOO},
9593 @code{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
9594 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
9595 this particular case.
9596 If you use @code{f2c} to compile @samp{BLOCK DATA FOO},
9597 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
9598 will result in an unresolved reference when linked.
9599 If you do the
9600 opposite, then @samp{FOO} might not be linked in under various
9601 circumstances (such as when @samp{FOO} is in a library, or you're
9602 using a ``clever'' linker---so clever, it produces a broken program
9603 with little or no warning by omitting initializations of global data
9604 because they are contained in unreferenced procedures).
9605
9606 The changes you make to your code to make @code{g77} handle this situation,
9607 however, appear to be a widely portable way to handle it.
9608 That is, many systems permit it (as they should, since the
9609 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
9610 is a block data program unit), and of the ones
9611 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
9612 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
9613 program units.
9614
9615 Here is the recommended approach to modifying a program containing
9616 a program unit such as the following:
9617
9618 @smallexample
9619 BLOCK DATA FOO
9620 COMMON /VARS/ X, Y, Z
9621 DATA X, Y, Z / 3., 4., 5. /
9622 END
9623 @end smallexample
9624
9625 @noindent
9626 If the above program unit might be placed in a library module, then
9627 ensure that every program unit in every program that references that
9628 particular @code{COMMON} area uses the @code{EXTERNAL} statement
9629 to force the area to be initialized.
9630
9631 For example, change a program unit that starts with
9632
9633 @smallexample
9634 INTEGER FUNCTION CURX()
9635 COMMON /VARS/ X, Y, Z
9636 CURX = X
9637 END
9638 @end smallexample
9639
9640 @noindent
9641 so that it uses the @code{EXTERNAL} statement, as in:
9642
9643 @smallexample
9644 INTEGER FUNCTION CURX()
9645 COMMON /VARS/ X, Y, Z
9646 EXTERNAL FOO
9647 CURX = X
9648 END
9649 @end smallexample
9650
9651 @noindent
9652 That way, @samp{CURX} is compiled by @code{g77} (and many other
9653 compilers) so that the linker knows it must include @samp{FOO},
9654 the @code{BLOCK DATA} program unit that sets the initial values
9655 for the variables in @samp{VAR}, in the executable program.
9656
9657 @node Loops
9658 @section Loops
9659 @cindex DO statement
9660 @cindex statements, DO
9661 @cindex trips, number of
9662 @cindex number of trips
9663
9664 The meaning of a @code{DO} loop in Fortran is precisely specified
9665 in the Fortran standard@dots{}and is quite different from what
9666 many programmers might expect.
9667
9668 In particular, Fortran iterative @code{DO} loops are implemented as if
9669 the number of trips through the loop is calculated @emph{before}
9670 the loop is entered.
9671
9672 The number of trips for a loop is calculated from the @var{start},
9673 @var{end}, and @var{increment} values specified in a statement such as:
9674
9675 @smallexample
9676 DO @var{iter} = @var{start}, @var{end}, @var{increment}
9677 @end smallexample
9678
9679 @noindent
9680 The trip count is evaluated using a fairly simple formula
9681 based on the three values following the @samp{=} in the
9682 statement, and it is that trip count that is effectively
9683 decremented during each iteration of the loop.
9684 If, at the beginning of an iteration of the loop, the
9685 trip count is zero or negative, the loop terminates.
9686 The per-loop-iteration modifications to @var{iter} are not
9687 related to determining whether to terminate the loop.
9688
9689 There are two important things to remember about the trip
9690 count:
9691
9692 @itemize @bullet
9693 @item
9694 It can be @emph{negative}, in which case it is
9695 treated as if it was zero---meaning the loop is
9696 not executed at all.
9697
9698 @item
9699 The type used to @emph{calculate} the trip count
9700 is the same type as @var{iter}, but the final
9701 calculation, and thus the type of the trip
9702 count itself, always is @code{INTEGER(KIND=1)}.
9703 @end itemize
9704
9705 These two items mean that there are loops that cannot
9706 be written in straightforward fashion using the Fortran @code{DO}.
9707
9708 For example, on a system with the canonical 32-bit two's-complement
9709 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
9710
9711 @smallexample
9712 DO I = -2000000000, 2000000000
9713 @end smallexample
9714
9715 @noindent
9716 Although the @var{start} and @var{end} values are well within
9717 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
9718 The expected trip count is 40000000001, which is outside
9719 the range of @code{INTEGER(KIND=1)} on many systems.
9720
9721 Instead, the above loop should be constructed this way:
9722
9723 @smallexample
9724 I = -2000000000
9725 DO
9726   IF (I .GT. 2000000000) EXIT
9727   @dots{}
9728   I = I + 1
9729 END DO
9730 @end smallexample
9731
9732 @noindent
9733 The simple @code{DO} construct and the @code{EXIT} statement
9734 (used to leave the innermost loop)
9735 are F90 features that @code{g77} supports.
9736
9737 Some Fortran compilers have buggy implementations of @code{DO},
9738 in that they don't follow the standard.
9739 They implement @code{DO} as a straightforward translation
9740 to what, in C, would be a @code{for} statement.
9741 Instead of creating a temporary variable to hold the trip count
9742 as calculated at run time, these compilers
9743 use the iteration variable @var{iter} to control
9744 whether the loop continues at each iteration.
9745
9746 The bug in such an implementation shows up when the
9747 trip count is within the range of the type of @var{iter},
9748 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
9749 exceeds that range.  For example:
9750
9751 @smallexample
9752 DO I = 2147483600, 2147483647
9753 @end smallexample
9754
9755 @noindent
9756 A loop started by the above statement will work as implemented
9757 by @code{g77}, but the use, by some compilers, of a
9758 more C-like implementation akin to
9759
9760 @smallexample
9761 for (i = 2147483600; i <= 2147483647; ++i)
9762 @end smallexample
9763
9764 @noindent
9765 produces a loop that does not terminate, because @samp{i}
9766 can never be greater than 2147483647, since incrementing it
9767 beyond that value overflows @samp{i}, setting it to -2147483648.
9768 This is a large, negative number that still is less than 2147483647.
9769
9770 Another example of unexpected behavior of @code{DO} involves
9771 using a nonintegral iteration variable @var{iter}, that is,
9772 a @code{REAL} variable.
9773 Consider the following program:
9774
9775 @smallexample
9776       DATA BEGIN, END, STEP /.1, .31, .007/
9777       DO 10 R = BEGIN, END, STEP
9778          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
9779          PRINT *,R
9780 10    CONTINUE
9781       PRINT *,'LAST = ',R
9782       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
9783       END
9784 @end smallexample
9785
9786 @noindent
9787 A C-like view of @code{DO} would hold that the two ``exclamatory''
9788 @code{PRINT} statements are never executed.
9789 However, this is the output of running the above program
9790 as compiled by @code{g77} on a GNU/Linux ix86 system:
9791
9792 @smallexample
9793  .100000001
9794  .107000001
9795  .114
9796  .120999999
9797  @dots{}
9798  .289000005
9799  .296000004
9800  .303000003
9801 LAST =   .310000002
9802  .310000002 .LE.   .310000002!!
9803 @end smallexample
9804
9805 Note that one of the two checks in the program turned up
9806 an apparent violation of the programmer's expectation---yet,
9807 the loop is correctly implemented by @code{g77}, in that
9808 it has 30 iterations.
9809 This trip count of 30 is correct when evaluated using
9810 the floating-point representations for the @var{begin},
9811 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
9812 ix86 are used.
9813 On other systems, an apparently more accurate trip count
9814 of 31 might result, but, nevertheless, @code{g77} is
9815 faithfully following the Fortran standard, and the result
9816 is not what the author of the sample program above
9817 apparently expected.
9818 (Such other systems might, for different values in the @code{DATA}
9819 statement, violate the other programmer's expectation,
9820 for example.)
9821
9822 Due to this combination of imprecise representation
9823 of floating-point values and the often-misunderstood
9824 interpretation of @code{DO} by standard-conforming
9825 compilers such as @code{g77}, use of @code{DO} loops
9826 with @code{REAL} iteration
9827 variables is not recommended.
9828 Such use can be caught by specifying @samp{-Wsurprising}.
9829 @xref{Warning Options}, for more information on this
9830 option.
9831
9832 @node Working Programs
9833 @section Working Programs
9834
9835 Getting Fortran programs to work in the first place can be
9836 quite a challenge---even when the programs already work on
9837 other systems, or when using other compilers.
9838
9839 @code{g77} offers some facilities that might be useful for
9840 tracking down bugs in such programs.
9841
9842 @menu
9843 * Not My Type::
9844 * Variables Assumed To Be Zero::
9845 * Variables Assumed To Be Saved::
9846 * Unwanted Variables::
9847 * Unused Arguments::
9848 * Surprising Interpretations of Code::
9849 * Aliasing Assumed To Work::
9850 * Output Assumed To Flush::
9851 * Large File Unit Numbers::
9852 * Floating-point precision::
9853 * Inconsistent Calling Sequences::
9854 @end menu
9855
9856 @node Not My Type
9857 @subsection Not My Type
9858 @cindex mistyped variables
9859 @cindex variables, mistyped
9860 @cindex mistyped functions
9861 @cindex functions, mistyped
9862 @cindex implicit typing
9863
9864 A fruitful source of bugs in Fortran source code is use, or
9865 mis-use, of Fortran's implicit-typing feature, whereby the
9866 type of a variable, array, or function is determined by the
9867 first character of its name.
9868
9869 Simple cases of this include statements like @samp{LOGX=9.227},
9870 without a statement such as @samp{REAL LOGX}.
9871 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
9872 type, with the result of the assignment being that it is given
9873 the value @samp{9}.
9874
9875 More involved cases include a function that is defined starting
9876 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
9877 Any caller of this function that does not also declare @samp{IPS}
9878 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
9879 is likely to assume it returns
9880 @code{INTEGER}, or some other type, leading to invalid results
9881 or even program crashes.
9882
9883 The @samp{-Wimplicit} option might catch failures to
9884 properly specify the types of
9885 variables, arrays, and functions in the code.
9886
9887 However, in code that makes heavy use of Fortran's
9888 implicit-typing facility, this option might produce so
9889 many warnings about cases that are working, it would be
9890 hard to find the one or two that represent bugs.
9891 This is why so many experienced Fortran programmers strongly
9892 recommend widespread use of the @code{IMPLICIT NONE} statement,
9893 despite it not being standard FORTRAN 77, to completely turn
9894 off implicit typing.
9895 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
9896 FORTRAN 77 compilers.)
9897
9898 Note that @samp{-Wimplicit} catches only implicit typing of
9899 @emph{names}.
9900 It does not catch implicit typing of expressions such
9901 as @samp{X**(2/3)}.
9902 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
9903 is equivalent to @samp{X**0}, due to the way Fortran expressions
9904 are given types and then evaluated.
9905 (In this particular case, the programmer probably wanted
9906 @samp{X**(2./3.)}.)
9907
9908 @node Variables Assumed To Be Zero
9909 @subsection Variables Assumed To Be Zero
9910 @cindex zero-initialized variables
9911 @cindex variables, assumed to be zero
9912 @cindex uninitialized variables
9913
9914 Many Fortran programs were developed on systems that provided
9915 automatic initialization of all, or some, variables and arrays
9916 to zero.
9917 As a result, many of these programs depend, sometimes
9918 inadvertently, on this behavior, though to do so violates
9919 the Fortran standards.
9920
9921 You can ask @code{g77} for this behavior by specifying the
9922 @samp{-finit-local-zero} option when compiling Fortran code.
9923 (You might want to specify @samp{-fno-automatic} as well,
9924 to avoid code-size inflation for non-optimized compilations.)
9925
9926 Note that a program that works better when compiled with the
9927 @samp{-finit-local-zero} option
9928 is almost certainly depending on a particular system's,
9929 or compiler's, tendency to initialize some variables to zero.
9930 It might be worthwhile finding such cases and fixing them,
9931 using techniques such as compiling with the @samp{-O -Wuninitialized}
9932 options using @code{g77}.
9933
9934 @node Variables Assumed To Be Saved
9935 @subsection Variables Assumed To Be Saved
9936 @cindex variables, retaining values across calls
9937 @cindex saved variables
9938 @cindex static variables
9939
9940 Many Fortran programs were developed on systems that
9941 saved the values of all, or some, variables and arrays
9942 across procedure calls.
9943 As a result, many of these programs depend, sometimes
9944 inadvertently, on being able to assign a value to a
9945 variable, perform a @code{RETURN} to a calling procedure,
9946 and, upon subsequent invocation, reference the previously
9947 assigned variable to obtain the value.
9948
9949 They expect this despite not using the @code{SAVE} statement
9950 to specify that the value in a variable is expected to survive
9951 procedure returns and calls.
9952 Depending on variables and arrays to retain values across
9953 procedure calls without using @code{SAVE} to require it violates
9954 the Fortran standards.
9955
9956 You can ask @code{g77} to assume @code{SAVE} is specified for all
9957 relevant (local) variables and arrays by using the
9958 @samp{-fno-automatic} option.
9959
9960 Note that a program that works better when compiled with the
9961 @samp{-fno-automatic} option
9962 is almost certainly depending on not having to use
9963 the @code{SAVE} statement as required by the Fortran standard.
9964 It might be worthwhile finding such cases and fixing them,
9965 using techniques such as compiling with the @samp{-O -Wuninitialized}
9966 options using @code{g77}.
9967
9968 @node Unwanted Variables
9969 @subsection Unwanted Variables
9970
9971 The @samp{-Wunused} option can find bugs involving
9972 implicit typing, sometimes
9973 more easily than using @samp{-Wimplicit} in code that makes
9974 heavy use of implicit typing.
9975 An unused variable or array might indicate that the
9976 spelling for its declaration is different from that of
9977 its intended uses.
9978
9979 Other than cases involving typos, unused variables rarely
9980 indicate actual bugs in a program.
9981 However, investigating such cases thoroughly has, on occasion,
9982 led to the discovery of code that had not been completely
9983 written---where the programmer wrote declarations as needed
9984 for the whole algorithm, wrote some or even most of the code
9985 for that algorithm, then got distracted and forgot that the
9986 job was not complete.
9987
9988 @node Unused Arguments
9989 @subsection Unused Arguments
9990 @cindex unused arguments
9991 @cindex arguments, unused
9992
9993 As with unused variables, It is possible that unused arguments
9994 to a procedure might indicate a bug.
9995 Compile with @samp{-W -Wunused} option to catch cases of
9996 unused arguments.
9997
9998 Note that @samp{-W} also enables warnings regarding overflow
9999 of floating-point constants under certain circumstances.
10000
10001 @node Surprising Interpretations of Code
10002 @subsection Surprising Interpretations of Code
10003
10004 The @samp{-Wsurprising} option can help find bugs involving
10005 expression evaluation or in
10006 the way @code{DO} loops with non-integral iteration variables
10007 are handled.
10008 Cases found by this option might indicate a difference of
10009 interpretation between the author of the code involved, and
10010 a standard-conforming compiler such as @code{g77}.
10011 Such a difference might produce actual bugs.
10012
10013 In any case, changing the code to explicitly do what the
10014 programmer might have expected it to do, so @code{g77} and
10015 other compilers are more likely to follow the programmer's
10016 expectations, might be worthwhile, especially if such changes
10017 make the program work better.
10018
10019 @node Aliasing Assumed To Work
10020 @subsection Aliasing Assumed To Work
10021 @cindex -falias-check option
10022 @cindex options, -falias-check
10023 @cindex -fargument-alias option
10024 @cindex options, -fargument-alias
10025 @cindex -fargument-noalias option
10026 @cindex options, -fargument-noalias
10027 @cindex -fno-argument-noalias-global option
10028 @cindex options, -fno-argument-noalias-global
10029 @cindex aliasing
10030 @cindex anti-aliasing
10031 @cindex overlapping arguments
10032 @cindex overlays
10033 @cindex association, storage
10034 @cindex storage association
10035 @cindex scheduling of reads and writes
10036 @cindex reads and writes, scheduling
10037
10038 The @samp{-falias-check}, @samp{-fargument-alias},
10039 @samp{-fargument-noalias},
10040 and @samp{-fno-argument-noalias-global} options,
10041 introduced in version 0.5.20 and
10042 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
10043 were withdrawn as of @code{g77} version 0.5.23
10044 due to their not being supported by @code{gcc} version 2.8.
10045
10046 These options control the assumptions regarding aliasing
10047 (overlapping) of writes and reads to main memory (core) made
10048 by the @code{gcc} back end.
10049
10050 The information below still is useful, but applies to
10051 only those versions of @code{g77} that support the
10052 alias analysis implied by support for these options.
10053
10054 These options are effective only when compiling with @samp{-O}
10055 (specifying any level other than @samp{-O0})
10056 or with @samp{-falias-check}.
10057
10058 The default for Fortran code is @samp{-fargument-noalias-global}.
10059 (The default for C code and code written in other C-based languages
10060 is @samp{-fargument-alias}.
10061 These defaults apply regardless of whether you use @code{g77} or
10062 @code{gcc} to compile your code.)
10063
10064 Note that, on some systems, compiling with @samp{-fforce-addr} in
10065 effect can produce more optimal code when the default aliasing
10066 options are in effect (and when optimization is enabled).
10067
10068 If your program is not working when compiled with optimization,
10069 it is possible it is violating the Fortran standards (77 and 90)
10070 by relying on the ability to ``safely'' modify variables and
10071 arrays that are aliased, via procedure calls, to other variables
10072 and arrays, without using @code{EQUIVALENCE} to explicitly
10073 set up this kind of aliasing.
10074
10075 (The FORTRAN 77 standard's prohibition of this sort of
10076 overlap, generally referred to therein as ``storage
10077 assocation'', appears in Sections 15.9.3.6.
10078 This prohibition allows implementations, such as @code{g77},
10079 to, for example, implement the passing of procedures and
10080 even values in @code{COMMON} via copy operations into local,
10081 perhaps more efficiently accessed temporaries at entry to a
10082 procedure, and, where appropriate, via copy operations back
10083 out to their original locations in memory at exit from that
10084 procedure, without having to take into consideration the
10085 order in which the local copies are updated by the code,
10086 among other things.)
10087
10088 To test this hypothesis, try compiling your program with
10089 the @samp{-fargument-alias} option, which causes the
10090 compiler to revert to assumptions essentially the same as
10091 made by versions of @code{g77} prior to 0.5.20.
10092
10093 If the program works using this option, that strongly suggests
10094 that the bug is in your program.
10095 Finding and fixing the bug(s) should result in a program that
10096 is more standard-conforming and that can be compiled by @code{g77}
10097 in a way that results in a faster executable.
10098
10099 (You might want to try compiling with @samp{-fargument-noalias},
10100 a kind of half-way point, to see if the problem is limited to
10101 aliasing between dummy arguments and @code{COMMON} variables---this
10102 option assumes that such aliasing is not done, while still allowing
10103 aliasing among dummy arguments.)
10104
10105 An example of aliasing that is invalid according to the standards
10106 is shown in the following program, which might @emph{not} produce
10107 the expected results when executed:
10108
10109 @smallexample
10110 I = 1
10111 CALL FOO(I, I)
10112 PRINT *, I
10113 END
10114
10115 SUBROUTINE FOO(J, K)
10116 J = J + K
10117 K = J * K
10118 PRINT *, J, K
10119 END
10120 @end smallexample
10121
10122 The above program attempts to use the temporary aliasing of the
10123 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
10124 pathological behavior---the simultaneous changing of the values
10125 of @emph{both} @samp{J} and @samp{K} when either one of them
10126 is written.
10127
10128 The programmer likely expects the program to print these values:
10129
10130 @example
10131 2  4
10132 4
10133 @end example
10134
10135 However, since the program is not standard-conforming, an
10136 implementation's behavior when running it is undefined, because
10137 subroutine @samp{FOO} modifies at least one of the arguments,
10138 and they are aliased with each other.
10139 (Even if one of the assignment statements was deleted, the
10140 program would still violate these rules.
10141 This kind of on-the-fly aliasing is permitted by the standard
10142 only when none of the aliased items are defined, or written,
10143 while the aliasing is in effect.)
10144
10145 As a practical example, an optimizing compiler might schedule
10146 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
10147 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
10148 resulting in the following output:
10149
10150 @example
10151 2  2
10152 2
10153 @end example
10154
10155 Essentially, compilers are promised (by the standard and, therefore,
10156 by programmers who write code they claim to be standard-conforming)
10157 that if they cannot detect aliasing via static analysis of a single
10158 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
10159 such aliasing exists.
10160 In such cases, compilers are free to assume that an assignment to
10161 one variable will not change the value of another variable, allowing
10162 it to avoid generating code to re-read the value of the other
10163 variable, to re-schedule reads and writes, and so on, to produce
10164 a faster executable.
10165
10166 The same promise holds true for arrays (as seen by the called
10167 procedure)---an element of one dummy array cannot be aliased
10168 with, or overlap, any element of another dummy array or be
10169 in a @code{COMMON} area known to the procedure.
10170
10171 (These restrictions apply only when the procedure defines, or
10172 writes to, one of the aliased variables or arrays.)
10173
10174 Unfortunately, there is no way to find @emph{all} possible cases of
10175 violations of the prohibitions against aliasing in Fortran code.
10176 Static analysis is certainly imperfect, as is run-time analysis,
10177 since neither can catch all violations.
10178 (Static analysis can catch all likely violations, and some that
10179 might never actually happen, while run-time analysis can catch
10180 only those violations that actually happen during a particular run.
10181 Neither approach can cope with programs mixing Fortran code with
10182 routines written in other languages, however.)
10183
10184 Currently, @code{g77} provides neither static nor run-time facilities
10185 to detect any cases of this problem, although other products might.
10186 Run-time facilities are more likely to be offered by future
10187 versions of @code{g77}, though patches improving @code{g77} so that
10188 it provides either form of detection are welcome.
10189
10190 @node Output Assumed To Flush
10191 @subsection Output Assumed To Flush
10192 @cindex ALWAYS_FLUSH
10193 @cindex synchronous write errors
10194 @cindex disk full
10195 @cindex flushing output
10196 @cindex fflush()
10197 @cindex I/O, flushing
10198 @cindex output, flushing
10199 @cindex writes, flushing
10200 @cindex NFS
10201 @cindex network file system
10202
10203 For several versions prior to 0.5.20, @code{g77} configured its
10204 version of the @code{libf2c} run-time library so that one of
10205 its configuration macros, @code{ALWAYS_FLUSH}, was defined.
10206
10207 This was done as a result of a belief that many programs expected
10208 output to be flushed to the operating system (under UNIX, via
10209 the @code{fflush()} library call) with the result that errors,
10210 such as disk full, would be immediately flagged via the
10211 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
10212
10213 Because of the adverse effects this approach had on the performance
10214 of many programs, @code{g77} no longer configures @code{libf2c}
10215 (now named @code{libg2c} in its @code{g77} incarnation)
10216 to always flush output.
10217
10218 If your program depends on this behavior, either insert the
10219 appropriate @samp{CALL FLUSH} statements, or modify the sources
10220 to the @code{libg2c}, rebuild and reinstall @code{g77}, and
10221 relink your programs with the modified library.
10222
10223 (Ideally, @code{libg2c} would offer the choice at run-time, so
10224 that a compile-time option to @code{g77} or @code{f2c} could
10225 result in generating the appropriate calls to flushing or
10226 non-flushing library routines.)
10227
10228 @xref{Always Flush Output}, for information on how to modify
10229 the @code{g77} source tree so that a version of @code{libg2c}
10230 can be built and installed with the @code{ALWAYS_FLUSH} macro defined.
10231
10232 @node Large File Unit Numbers
10233 @subsection Large File Unit Numbers
10234 @cindex MXUNIT
10235 @cindex unit numbers
10236 @cindex maximum unit number
10237 @cindex illegal unit number
10238 @cindex increasing maximum unit number
10239
10240 If your program crashes at run time with a message including
10241 the text @samp{illegal unit number}, that probably is
10242 a message from the run-time library, @code{libg2c}.
10243
10244 The message means that your program has attempted to use a
10245 file unit number that is out of the range accepted by
10246 @code{libg2c}.
10247 Normally, this range is 0 through 99, and the high end
10248 of the range is controlled by a @code{libg2c} source-file
10249 macro named @code{MXUNIT}.
10250
10251 If you can easily change your program to use unit numbers
10252 in the range 0 through 99, you should do so.
10253
10254 Otherwise, see @ref{Larger File Unit Numbers}, for information on how
10255 to change @code{MXUNIT} in @code{libg2c} so you can build and
10256 install a new version of @code{libg2c} that supports the larger
10257 unit numbers you need.
10258
10259 @emph{Note:} While @code{libg2c} places a limit on the range
10260 of Fortran file-unit numbers, the underlying library and operating
10261 system might impose different kinds of limits.
10262 For example, some systems limit the number of files simultaneously
10263 open by a running program.
10264 Information on how to increase these limits should be found
10265 in your system's documentation.
10266
10267 @node Floating-point precision
10268 @subsection Floating-point precision
10269
10270 @cindex IEEE 754 conformance
10271 @cindex conformance, IEEE 754
10272 @cindex floating-point, precision
10273 @cindex ix86 floating-point
10274 @cindex x86 floating-point
10275 If your program depends on exact IEEE 754 floating-point handling it may
10276 help on some systems---specifically x86 or m68k hardware---to use
10277 the @samp{-ffloat-store} option or to reset the precision flag on the
10278 floating-point unit.
10279 @xref{Optimize Options}.
10280
10281 However, it might be better simply to put the FPU into double precision
10282 mode and not take the performance hit of @samp{-ffloat-store}.  On x86
10283 and m68k GNU systems you can do this with a technique similar to that
10284 for turning on floating-point exceptions
10285 (@pxref{Floating-point Exception Handling}).
10286 The control word could be set to double precision by some code like this
10287 one:
10288 @smallexample
10289 #include <fpu_control.h>
10290 @{
10291   fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
10292   _FPU_SETCW(cw);
10293 @}
10294 @end smallexample
10295 (It is not clear whether this has any effect on the operation of the GNU
10296 maths library, but we have no evidence of it causing trouble.)
10297
10298 Some targets (such as the Alpha) may need special options for full IEEE
10299 conformance.
10300 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and Porting GNU CC}.
10301
10302 @node Inconsistent Calling Sequences
10303 @subsection Inconsistent Calling Sequences
10304
10305 @pindex ftnchek
10306 @cindex floating-point, errors
10307 @cindex ix86 FPU stack
10308 @cindex x86 FPU stack
10309 Code containing inconsistent calling sequences in the same file is
10310 normally rejected---see @ref{GLOBALS}.
10311 (Use, say, @code{ftnchek} to ensure
10312 consistency across source files.
10313 @xref{f2c Skeletons and Prototypes,,
10314 Generating Skeletons and Prototypes with @code{f2c}}.)
10315
10316 Mysterious errors, which may appear to be code generation problems, can
10317 appear specifically on the x86 architecture with some such
10318 inconsistencies.  On x86 hardware, floating-point return values of
10319 functions are placed on the floating-point unit's register stack, not
10320 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
10321 @code{FUNCTION} as some other sort of procedure, or vice versa,
10322 scrambles the floating-point stack.  This may break unrelated code
10323 executed later.  Similarly if, say, external C routines are written
10324 incorrectly.
10325
10326 @node Overly Convenient Options
10327 @section Overly Convenient Command-line Options
10328 @cindex overly convenient options
10329 @cindex options, overly convenient
10330
10331 These options should be used only as a quick-and-dirty way to determine
10332 how well your program will run under different compilation models
10333 without having to change the source.
10334 Some are more problematic
10335 than others, depending on how portable and maintainable you want the
10336 program to be (and, of course, whether you are allowed to change it
10337 at all is crucial).
10338
10339 You should not continue to use these command-line options to compile
10340 a given program, but rather should make changes to the source code:
10341
10342 @table @code
10343 @cindex -finit-local-zero option
10344 @cindex options, -finit-local-zero
10345 @item -finit-local-zero
10346 (This option specifies that any uninitialized local variables
10347 and arrays have default initialization to binary zeros.)
10348
10349 Many other compilers do this automatically, which means lots of
10350 Fortran code developed with those compilers depends on it.
10351
10352 It is safer (and probably
10353 would produce a faster program) to find the variables and arrays that
10354 need such initialization and provide it explicitly via @code{DATA}, so that
10355 @samp{-finit-local-zero} is not needed.
10356
10357 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
10358 find likely candidates, but
10359 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
10360 or this technique won't work.
10361
10362 @cindex -fno-automatic option
10363 @cindex options, -fno-automatic
10364 @item -fno-automatic
10365 (This option specifies that all local variables and arrays
10366 are to be treated as if they were named in @code{SAVE} statements.)
10367
10368 Many other compilers do this automatically, which means lots of
10369 Fortran code developed with those compilers depends on it.
10370
10371 The effect of this is that all non-automatic variables and arrays
10372 are made static, that is, not placed on the stack or in heap storage.
10373 This might cause a buggy program to appear to work better.
10374 If so, rather than relying on this command-line option (and hoping all
10375 compilers provide the equivalent one), add @code{SAVE}
10376 statements to some or all program unit sources, as appropriate.
10377 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
10378 to find likely candidates, but
10379 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
10380 or this technique won't work.
10381
10382 The default is @samp{-fautomatic}, which tells @code{g77} to try
10383 and put variables and arrays on the stack (or in fast registers)
10384 where possible and reasonable.
10385 This tends to make programs faster.
10386
10387 @cindex automatic arrays
10388 @cindex arrays, automatic
10389 @emph{Note:} Automatic variables and arrays are not affected
10390 by this option.
10391 These are variables and arrays that are @emph{necessarily} automatic,
10392 either due to explicit statements, or due to the way they are
10393 declared.
10394 Examples include local variables and arrays not given the
10395 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
10396 and local arrays declared with non-constant bounds (automatic
10397 arrays).
10398 Currently, @code{g77} supports only automatic arrays, not
10399 @code{RECURSIVE} procedures or other means of explicitly
10400 specifying that variables or arrays are automatic.
10401
10402 @cindex -f@var{group}-intrinsics-hide option
10403 @cindex options, -f@var{group}-intrinsics-hide
10404 @item -f@var{group}-intrinsics-hide
10405 Change the source code to use @code{EXTERNAL} for any external procedure
10406 that might be the name of an intrinsic.
10407 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
10408 @end table
10409
10410 @node Faster Programs
10411 @section Faster Programs
10412 @cindex speed, of programs
10413 @cindex programs, speeding up
10414
10415 Aside from the usual @code{gcc} options, such as @samp{-O},
10416 @samp{-ffast-math}, and so on, consider trying some of the
10417 following approaches to speed up your program (once you get
10418 it working).
10419
10420 @menu
10421 * Aligned Data::
10422 * Prefer Automatic Uninitialized Variables::
10423 * Avoid f2c Compatibility::
10424 * Use Submodel Options::
10425 @end menu
10426
10427 @node Aligned Data
10428 @subsection Aligned Data
10429 @cindex alignment
10430 @cindex data, aligned
10431 @cindex stack, aligned
10432 @cindex aligned data
10433 @cindex aligned stack
10434 @cindex Pentium optimizations
10435 @cindex optimization, for Pentium
10436
10437 On some systems, such as those with Pentium Pro CPUs, programs
10438 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
10439 might run much slower
10440 than possible due to the compiler not aligning these 64-bit
10441 values to 64-bit boundaries in memory.
10442 (The effect also is present, though
10443 to a lesser extent, on the 586 (Pentium) architecture.)
10444
10445 The Intel x86 architecture generally ensures that these programs will
10446 work on all its implementations,
10447 but particular implementations (such as Pentium Pro)
10448 perform better with more strict alignment.
10449 (Such behavior isn't unique to the Intel x86 architecture.)
10450 Other architectures might @emph{demand} 64-bit alignment
10451 of 64-bit data.
10452
10453 There are a variety of approaches to use to address this problem:
10454
10455 @itemize @bullet
10456 @item
10457 @cindex @code{COMMON} layout
10458 @cindex layout of @code{COMMON} blocks
10459 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
10460 that the variables and arrays with the widest alignment
10461 guidelines come first.
10462
10463 For example, on most systems, this would mean placing
10464 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
10465 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
10466 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
10467 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
10468 and @code{INTEGER(KIND=3)} entities.
10469
10470 The reason to use such placement is it makes it more likely
10471 that your data will be aligned properly, without requiring
10472 you to do detailed analysis of each aggregate (@code{COMMON}
10473 and @code{EQUIVALENCE}) area.
10474
10475 Specifically, on systems where the above guidelines are
10476 appropriate, placing @code{CHARACTER} entities before
10477 @code{REAL(KIND=2)} entities can work just as well,
10478 but only if the number of bytes occupied by the @code{CHARACTER}
10479 entities is divisible by the recommended alignment for
10480 @code{REAL(KIND=2)}.
10481
10482 By ordering the placement of entities in aggregate
10483 areas according to the simple guidelines above, you
10484 avoid having to carefully count the number of bytes
10485 occupied by each entity to determine whether the
10486 actual alignment of each subsequent entity meets the
10487 alignment guidelines for the type of that entity.
10488
10489 If you don't ensure correct alignment of @code{COMMON} elements, the
10490 compiler may be forced by some systems to violate the Fortran semantics by
10491 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
10492 If the unfortunate practice is employed of overlaying different types of
10493 data in the @code{COMMON} block, the different variants
10494 of this block may become misaligned with respect to each other.
10495 Even if your platform doesn't require strict alignment,
10496 @code{COMMON} should be laid out as above for portability.
10497 (Unfortunately the FORTRAN 77 standard didn't anticipate this
10498 possible requirement, which is compiler-independent on a given platform.)
10499
10500 @item
10501 @cindex -malign-double option
10502 @cindex options, -malign-double
10503 Use the (x86-specific) @samp{-malign-double} option when compiling
10504 programs for the Pentium and Pentium Pro architectures (called 586
10505 and 686 in the @code{gcc} configuration subsystem).
10506 The warning about this in the @code{gcc} manual isn't
10507 generally relevant to Fortran,
10508 but using it will force @code{COMMON} to be padded if necessary to align
10509 @code{DOUBLE PRECISION} data.
10510
10511 When @code{DOUBLE PRECISION} data is forcibly aligned
10512 in @code{COMMON} by @code{g77} due to specifying @samp{-malign-double},
10513 @code{g77} issues a warning about the need to
10514 insert padding.
10515
10516 In this case, each and every program unit that uses
10517 the same @code{COMMON} area
10518 must specify the same layout of variables and their types
10519 for that area
10520 and be compiled with @samp{-malign-double} as well.
10521 @code{g77} will issue warnings in each case,
10522 but as long as every program unit using that area
10523 is compiled with the same warnings,
10524 the resulting object files should work when linked together
10525 unless the program makes additional assumptions about
10526 @code{COMMON} area layouts that are outside the scope
10527 of the FORTRAN 77 standard,
10528 or uses @code{EQUIVALENCE} or different layouts
10529 in ways that assume no padding is ever inserted by the compiler.
10530
10531 @item
10532 Ensure that @file{crt0.o} or @file{crt1.o}
10533 on your system guarantees a 64-bit
10534 aligned stack for @code{main()}.
10535 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
10536 but we don't know of any other x86 setups where it will be right.
10537 Read your system's documentation to determine if
10538 it is appropriate to upgrade to a more recent version
10539 to obtain the optimal alignment.
10540 @end itemize
10541
10542 Progress is being made on making this work
10543 ``out of the box'' on future versions of @code{g77},
10544 @code{gcc}, and some of the relevant operating systems
10545 (such as GNU/Linux).
10546
10547 @cindex alignment testing
10548 @cindex testing alignment
10549 A package that tests the degree to which a Fortran compiler
10550 (such as @code{g77})
10551 aligns 64-bit floating-point variables and arrays
10552 is available at @uref{ftp://alpha.gnu.org/gnu/g77/align/}.
10553
10554 @node Prefer Automatic Uninitialized Variables
10555 @subsection Prefer Automatic Uninitialized Variables
10556
10557 If you're using @samp{-fno-automatic} already, you probably
10558 should change your code to allow compilation with @samp{-fautomatic}
10559 (the default), to allow the program to run faster.
10560
10561 Similarly, you should be able to use @samp{-fno-init-local-zero}
10562 (the default) instead of @samp{-finit-local-zero}.
10563 This is because it is rare that every variable affected by these
10564 options in a given program actually needs to
10565 be so affected.
10566
10567 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
10568 every local non-automatic variable and array, affects even things like
10569 @code{DO} iteration
10570 variables, which rarely need to be @code{SAVE}d, and this often reduces
10571 run-time performances.
10572 Similarly, @samp{-fno-init-local-zero} forces such
10573 variables to be initialized to zero---when @code{SAVE}d (such as when
10574 @samp{-fno-automatic}), this by itself generally affects only
10575 startup time for a program, but when not @code{SAVE}d,
10576 it can slow down the procedure every time it is called.
10577
10578 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10579 for information on the @samp{-fno-automatic} and
10580 @samp{-finit-local-zero} options and how to convert
10581 their use into selective changes in your own code.
10582
10583 @node Avoid f2c Compatibility
10584 @subsection Avoid f2c Compatibility
10585 @cindex -fno-f2c option
10586 @cindex options, -fno-f2c
10587 @cindex @code{f2c} compatibility
10588 @cindex compatibility, @code{f2c}
10589
10590 If you aren't linking with any code compiled using
10591 @code{f2c}, try using the @samp{-fno-f2c} option when
10592 compiling @emph{all} the code in your program.
10593 (Note that @code{libf2c} is @emph{not} an example of code
10594 that is compiled using @code{f2c}---it is compiled by a C
10595 compiler, typically @code{gcc}.)
10596
10597 @node Use Submodel Options
10598 @subsection Use Submodel Options
10599 @cindex submodels
10600
10601 Using an appropriate @samp{-m} option to generate specific code for your
10602 CPU may be worthwhile, though it may mean the executable won't run on
10603 other versions of the CPU that don't support the same instruction set.
10604 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
10605 Porting GNU CC}.  For instance on an x86 system the compiler might have
10606 been built---as shown by @samp{g77 -v}---for the target
10607 @samp{i386-pc-linux-gnu}, i.e.@: an @samp{i386} CPU@.  In that case to
10608 generate code best optimized for a Pentium you could use the option
10609 @samp{-march=pentium}.
10610
10611 For recent CPUs that don't have explicit support in the released version
10612 of @code{gcc}, it @emph{might} still be possible to get improvements
10613 with certain @samp{-m} options.
10614
10615 @samp{-fomit-frame-pointer} can help performance on x86 systems and
10616 others.  It will, however, inhibit debugging on the systems on which it
10617 is not turned on anyway by @samp{-O}.
10618
10619 @node Trouble
10620 @chapter Known Causes of Trouble with GNU Fortran
10621 @cindex bugs, known
10622 @cindex installation trouble
10623 @cindex known causes of trouble
10624
10625 This section describes known problems that affect users of GNU Fortran.
10626 Most of these are not GNU Fortran bugs per se---if they were, we would
10627 fix them.
10628 But the result for a user might be like the result of a bug.
10629
10630 Some of these problems are due to bugs in other software, some are
10631 missing features that are too much work to add, and some are places
10632 where people's opinions differ as to what is best.
10633
10634 Information on bugs that show up when configuring, porting, building,
10635 or installing @code{g77} is not provided here.
10636 @xref{Problems Installing}.
10637
10638 To find out about major bugs discovered in the current release and
10639 possible workarounds for them, see
10640 @uref{ftp://alpha.gnu.org/g77.plan}.
10641
10642 (Note that some of this portion of the manual is lifted
10643 directly from the @code{gcc} manual, with minor modifications
10644 to tailor it to users of @code{g77}.
10645 Anytime a bug seems to have more to do with the @code{gcc}
10646 portion of @code{g77}, see
10647 @ref{Trouble,,Known Causes of Trouble with GNU CC,
10648 gcc,Using and Porting GNU CC}.)
10649
10650 @menu
10651 * But-bugs::         Bugs really in other programs or elsewhere.
10652 * Known Bugs::       Bugs known to be in this version of @code{g77}.
10653 * Missing Features:: Features we already know we want to add later.
10654 * Disappointments::  Regrettable things we can't change.
10655 * Non-bugs::         Things we think are right, but some others disagree.
10656 * Warnings and Errors::  Which problems in your code get warnings,
10657                         and which get errors.
10658 @end menu
10659
10660 @node But-bugs
10661 @section Bugs Not In GNU Fortran
10662 @cindex but-bugs
10663
10664 These are bugs to which the maintainers often have to reply,
10665 ``but that isn't a bug in @code{g77}@dots{}''.
10666 Some of these already are fixed in new versions of other
10667 software; some still need to be fixed; some are problems
10668 with how @code{g77} is installed or is being used;
10669 some are the result of bad hardware that causes software
10670 to misbehave in sometimes bizarre ways;
10671 some just cannot be addressed at this time until more
10672 is known about the problem.
10673
10674 Please don't re-report these bugs to the @code{g77} maintainers---if
10675 you must remind someone how important it is to you that the problem
10676 be fixed, talk to the people responsible for the other products
10677 identified below, but preferably only after you've tried the
10678 latest versions of those products.
10679 The @code{g77} maintainers have their hands full working on
10680 just fixing and improving @code{g77}, without serving as a
10681 clearinghouse for all bugs that happen to affect @code{g77}
10682 users.
10683
10684 @xref{Collected Fortran Wisdom}, for information on behavior
10685 of Fortran programs, and the programs that compile them, that
10686 might be @emph{thought} to indicate bugs.
10687
10688 @menu
10689 * Signal 11 and Friends::  Strange behavior by any software.
10690 * Cannot Link Fortran Programs::  Unresolved references.
10691 * Large Common Blocks::    Problems on older GNU/Linux systems.
10692 * Debugger Problems::      When the debugger crashes.
10693 * NeXTStep Problems::      Misbehaving executables.
10694 * Stack Overflow::         More misbehaving executables.
10695 * Nothing Happens::        Less behaving executables.
10696 * Strange Behavior at Run Time::  Executables misbehaving due to
10697                             bugs in your program.
10698 * Floating-point Errors::  The results look wrong, but@dots{}.
10699 @end menu
10700
10701 @node Signal 11 and Friends
10702 @subsection Signal 11 and Friends
10703 @cindex signal 11
10704 @cindex hardware errors
10705
10706 A whole variety of strange behaviors can occur when the
10707 software, or the way you are using the software,
10708 stresses the hardware in a way that triggers hardware bugs.
10709 This might seem hard to believe, but it happens frequently
10710 enough that there exist documents explaining in detail
10711 what the various causes of the problems are, what
10712 typical symptoms look like, and so on.
10713
10714 Generally these problems are referred to in this document
10715 as ``signal 11'' crashes, because the Linux kernel, running
10716 on the most popular hardware (the Intel x86 line), often
10717 stresses the hardware more than other popular operating
10718 systems.
10719 When hardware problems do occur under GNU/Linux on x86
10720 systems, these often manifest themselves as ``signal 11''
10721 problems, as illustrated by the following diagnostic:
10722
10723 @smallexample
10724 sh# @kbd{g77 myprog.f}
10725 gcc: Internal compiler error: program f771 got fatal signal 11
10726 sh#
10727 @end smallexample
10728
10729 It is @emph{very} important to remember that the above
10730 message is @emph{not} the only one that indicates a
10731 hardware problem, nor does it always indicate a hardware
10732 problem.
10733
10734 In particular, on systems other than those running the Linux
10735 kernel, the message might appear somewhat or very different,
10736 as it will if the error manifests itself while running a
10737 program other than the @code{g77} compiler.
10738 For example,
10739 it will appear somewhat different when running your program,
10740 when running Emacs, and so on.
10741
10742 How to cope with such problems is well beyond the scope
10743 of this manual.
10744
10745 However, users of Linux-based systems (such as GNU/Linux)
10746 should review @uref{http://www.bitwizard.nl/sig11/}, a source
10747 of detailed information on diagnosing hardware problems,
10748 by recognizing their common symptoms.
10749
10750 Users of other operating systems and hardware might
10751 find this reference useful as well.
10752 If you know of similar material for another hardware/software
10753 combination, please let us know so we can consider including
10754 a reference to it in future versions of this manual.
10755
10756 @node Cannot Link Fortran Programs
10757 @subsection Cannot Link Fortran Programs
10758 @cindex unresolved reference (various)
10759 @cindex linking error for user code
10760 @cindex code, user
10761 @cindex @code{ld}, error linking user code
10762 @cindex @code{ld}, can't find strange names
10763 On some systems, perhaps just those with out-of-date (shared?)
10764 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
10765 programs (which should be done using @code{g77}).
10766
10767 If this happens to you, try appending @samp{-lc} to the command you
10768 use to link the program, e.g. @samp{g77 foo.f -lc}.
10769 @code{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
10770 but it cannot also specify @samp{-lc} because not all systems have a
10771 file named @file{libc.a}.
10772
10773 It is unclear at this point whether there are legitimately installed
10774 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
10775 by @code{g77}.
10776
10777 @cindex undefined reference (_main)
10778 @cindex linking error, user code
10779 @cindex @code{ld}, error linking user code
10780 @cindex code, user
10781 @cindex @code{ld}, can't find @samp{_main}
10782 If your program doesn't link due to unresolved references to names
10783 like @samp{_main}, make sure you're using the @code{g77} command to do the
10784 link, since this command ensures that the necessary libraries are
10785 loaded by specifying @samp{-lg2c -lm} when it invokes the @code{gcc}
10786 command to do the actual link.
10787 (Use the @samp{-v} option to discover
10788 more about what actually happens when you use the @code{g77} and @code{gcc}
10789 commands.)
10790
10791 Also, try specifying @samp{-lc} as the last item on the @code{g77}
10792 command line, in case that helps.
10793
10794 @node Large Common Blocks
10795 @subsection Large Common Blocks
10796 @cindex common blocks, large
10797 @cindex large common blocks
10798 @cindex linking, errors
10799 @cindex @code{ld}, errors
10800 @cindex errors, linker
10801 On some older GNU/Linux systems, programs with common blocks larger
10802 than 16MB cannot be linked without some kind of error
10803 message being produced.
10804
10805 This is a bug in older versions of @code{ld}, fixed in
10806 more recent versions of @code{binutils}, such as version 2.6.
10807
10808 @node Debugger Problems
10809 @subsection Debugger Problems
10810 @cindex @code{gdb}, support
10811 @cindex support, @code{gdb}
10812 There are some known problems when using @code{gdb} on code
10813 compiled by @code{g77}.
10814 Inadequate investigation as of the release of 0.5.16 results in not
10815 knowing which products are the culprit, but @file{gdb-4.14} definitely
10816 crashes when, for example, an attempt is made to print the contents
10817 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
10818 machines, plus some others.
10819 Attempts to access assumed-size arrays are
10820 also known to crash recent versions of @code{gdb}.
10821 (@code{gdb}'s Fortran support was done for a different compiler
10822 and isn't properly compatible with @code{g77}.)
10823
10824 @node NeXTStep Problems
10825 @subsection NeXTStep Problems
10826 @cindex NeXTStep problems
10827 @cindex bus error
10828 @cindex segmentation violation
10829 Developers of Fortran code on NeXTStep (all architectures) have to
10830 watch out for the following problem when writing programs with
10831 large, statically allocated (i.e. non-stack based) data structures
10832 (common blocks, saved arrays).
10833
10834 Due to the way the native loader (@file{/bin/ld}) lays out
10835 data structures in virtual memory, it is very easy to create an
10836 executable wherein the @samp{__DATA} segment overlaps (has addresses in
10837 common) with the @samp{UNIX STACK} segment.
10838
10839 This leads to all sorts of trouble, from the executable simply not
10840 executing, to bus errors.
10841 The NeXTStep command line tool @code{ebadexec} points to
10842 the problem as follows:
10843
10844 @smallexample
10845 % @kbd{/bin/ebadexec a.out}
10846 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
10847 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
10848 STACK segment (truncated address = 0x400000 rounded size =
10849 0x3c00000) of executable file: a.out
10850 @end smallexample
10851
10852 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
10853 stack segment.)
10854
10855 This can be cured by assigning the @samp{__DATA} segment
10856 (virtual) addresses beyond the stack segment.
10857 A conservative
10858 estimate for this is from address 6000000 (hexadecimal) onwards---this
10859 has always worked for me [Toon Moene]:
10860
10861 @smallexample
10862 % @kbd{g77 -segaddr __DATA 6000000 test.f}
10863 % @kbd{ebadexec a.out}
10864 ebadexec: file: a.out appears to be executable
10865 %
10866 @end smallexample
10867
10868 Browsing through @file{@value{path-g77}/Makefile.in},
10869 you will find that the @code{f771} program itself also has to be
10870 linked with these flags---it has large statically allocated
10871 data structures.
10872 (Version 0.5.18 reduces this somewhat, but probably
10873 not enough.)
10874
10875 (The above item was contributed by Toon Moene
10876 (@email{toon@@moene.indiv.nluug.nl}).)
10877
10878 @node Stack Overflow
10879 @subsection Stack Overflow
10880 @cindex stack, overflow
10881 @cindex segmentation violation
10882 @code{g77} code might fail at runtime (probably with a ``segmentation
10883 violation'') due to overflowing the stack.
10884 This happens most often on systems with an environment
10885 that provides substantially more heap space (for use
10886 when arbitrarily allocating and freeing memory) than stack
10887 space.
10888
10889 Often this can be cured by
10890 increasing or removing your shell's limit on stack usage, typically
10891 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
10892 @kbd{ulimit -s} (in @code{sh} and derivatives).
10893
10894 Increasing the allowed stack size might, however, require
10895 changing some operating system or system configuration parameters.
10896
10897 You might be able to work around the problem by compiling with the
10898 @samp{-fno-automatic} option to reduce stack usage, probably at the
10899 expense of speed.
10900
10901 @xref{Maximum Stackable Size}, for information on patching
10902 @code{g77} to use different criteria for placing local
10903 non-automatic variables and arrays on the stack.
10904
10905 @cindex automatic arrays
10906 @cindex arrays, automatic
10907 However, if your program uses large automatic arrays
10908 (for example, has declarations like @samp{REAL A(N)} where
10909 @samp{A} is a local array and @samp{N} is a dummy or
10910 @code{COMMON} variable that can have a large value),
10911 neither use of @samp{-fno-automatic},
10912 nor changing the cut-off point for @code{g77} for using the stack,
10913 will solve the problem by changing the placement of these
10914 large arrays, as they are @emph{necessarily} automatic.
10915
10916 @code{g77} currently provides no means to specify that
10917 automatic arrays are to be allocated on the heap instead
10918 of the stack.
10919 So, other than increasing the stack size, your best bet is to
10920 change your source code to avoid large automatic arrays.
10921 Methods for doing this currently are outside the scope of
10922 this document.
10923
10924 (@emph{Note:} If your system puts stack and heap space in the
10925 same memory area, such that they are effectively combined, then
10926 a stack overflow probably indicates a program that is either
10927 simply too large for the system, or buggy.)
10928
10929 @node Nothing Happens
10930 @subsection Nothing Happens
10931 @cindex nothing happens
10932 @cindex naming programs
10933 @cindex @code{test} programs
10934 @cindex programs, @code{test}
10935 It is occasionally reported that a ``simple'' program,
10936 such as a ``Hello, World!'' program, does nothing when
10937 it is run, even though the compiler reported no errors,
10938 despite the program containing nothing other than a
10939 simple @code{PRINT} statement.
10940
10941 This most often happens because the program has been
10942 compiled and linked on a UNIX system and named @code{test},
10943 though other names can lead to similarly unexpected
10944 run-time behavior on various systems.
10945
10946 Essentially this problem boils down to giving
10947 your program a name that is already known to
10948 the shell you are using to identify some other program,
10949 which the shell continues to execute instead of your
10950 program when you invoke it via, for example:
10951
10952 @smallexample
10953 sh# @kbd{test}
10954 sh#
10955 @end smallexample
10956
10957 Under UNIX and many other system, a simple command name
10958 invokes a searching mechanism that might well not choose
10959 the program located in the current working directory if
10960 there is another alternative (such as the @code{test}
10961 command commonly installed on UNIX systems).
10962
10963 The reliable way to invoke a program you just linked in
10964 the current directory under UNIX is to specify it using
10965 an explicit pathname, as in:
10966
10967 @smallexample
10968 sh# @kbd{./test}
10969  Hello, World!
10970 sh#
10971 @end smallexample
10972
10973 Users who encounter this problem should take the time to
10974 read up on how their shell searches for commands, how to
10975 set their search path, and so on.
10976 The relevant UNIX commands to learn about include
10977 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
10978 @code{set} and @code{env}), @code{which}, and @code{find}.
10979
10980 @node Strange Behavior at Run Time
10981 @subsection Strange Behavior at Run Time
10982 @cindex segmentation violation
10983 @cindex bus error
10984 @cindex overwritten data
10985 @cindex data, overwritten
10986 @code{g77} code might fail at runtime with ``segmentation violation'',
10987 ``bus error'', or even something as subtle as a procedure call
10988 overwriting a variable or array element that it is not supposed
10989 to touch.
10990
10991 These can be symptoms of a wide variety of actual bugs that
10992 occurred earlier during the program's run, but manifested
10993 themselves as @emph{visible} problems some time later.
10994
10995 Overflowing the bounds of an array---usually by writing beyond
10996 the end of it---is one of two kinds of bug that often occurs
10997 in Fortran code.
10998 (Compile your code with the @samp{-fbounds-check} option
10999 to catch many of these kinds of errors at program run time.)
11000
11001 The other kind of bug is a mismatch between the actual arguments
11002 passed to a procedure and the dummy arguments as declared by that
11003 procedure.
11004
11005 Both of these kinds of bugs, and some others as well, can be
11006 difficult to track down, because the bug can change its behavior,
11007 or even appear to not occur, when using a debugger.
11008
11009 That is, these bugs can be quite sensitive to data, including
11010 data representing the placement of other data in memory (that is,
11011 pointers, such as the placement of stack frames in memory).
11012
11013 @code{g77} now offers the
11014 ability to catch and report some of these problems at compile, link, or
11015 run time, such as by generating code to detect references to
11016 beyond the bounds of most arrays (except assumed-size arrays),
11017 and checking for agreement between calling and called procedures.
11018 Future improvements are likely to be made in the procedure-mismatch area,
11019 at least.
11020
11021 In the meantime, finding and fixing the programming
11022 bugs that lead to these behaviors is, ultimately, the user's
11023 responsibility, as difficult as that task can sometimes be.
11024
11025 @cindex infinite spaces printed
11026 @cindex space, endless printing of
11027 @cindex libc, non-ANSI or non-default
11028 @cindex C library
11029 @cindex linking against non-standard library
11030 @cindex Solaris
11031 One runtime problem that has been observed might have a simple solution.
11032 If a formatted @code{WRITE} produces an endless stream of spaces, check
11033 that your program is linked against the correct version of the C library.
11034 The configuration process takes care to account for your
11035 system's normal @file{libc} not being ANSI-standard, which will
11036 otherwise cause this behaviour.
11037 If your system's default library is
11038 ANSI-standard and you subsequently link against a non-ANSI one, there
11039 might be problems such as this one.
11040
11041 Specifically, on Solaris2 systems,
11042 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
11043
11044 @node Floating-point Errors
11045 @subsection Floating-point Errors
11046 @cindex floating-point errors
11047 @cindex rounding errors
11048 @cindex inconsistent floating-point results
11049 @cindex results, inconsistent
11050 Some programs appear to produce inconsistent floating-point
11051 results compiled by @code{g77} versus by other compilers.
11052
11053 Often the reason for this behavior is the fact that floating-point
11054 values are represented on almost all Fortran systems by
11055 @emph{approximations}, and these approximations are inexact
11056 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
11057 0.7, 0.8, 0.9, 1.1, and so on.
11058 Most Fortran systems, including all current ports of @code{g77},
11059 use binary arithmetic to represent these approximations.
11060
11061 Therefore, the exact value of any floating-point approximation
11062 as manipulated by @code{g77}-compiled code is representable by
11063 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
11064 so on (just keep dividing by two) through the precision of the
11065 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
11066 @code{REAL(KIND=2)}), then multiplying the sum by a integral
11067 power of two (in Fortran, by @samp{2**N}) that typically is between
11068 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
11069 @code{REAL(KIND=2)}, then multiplying by -1 if the number
11070 is negative.
11071
11072 So, a value like 0.2 is exactly represented in decimal---since
11073 it is a fraction, @samp{2/10}, with a denominator that is compatible
11074 with the base of the number system (base 10).
11075 However, @samp{2/10} cannot be represented by any finite number
11076 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
11077 be exactly represented in binary notation.
11078
11079 (On the other hand, decimal notation can represent any binary
11080 number in a finite number of digits.
11081 Decimal notation cannot do so with ternary, or base-3,
11082 notation, which would represent floating-point numbers as
11083 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
11084 After all, no finite number of decimal digits can exactly
11085 represent @samp{1/3}.
11086 Fortunately, few systems use ternary notation.)
11087
11088 Moreover, differences in the way run-time I/O libraries convert
11089 between these approximations and the decimal representation often
11090 used by programmers and the programs they write can result in
11091 apparent differences between results that do not actually exist,
11092 or exist to such a small degree that they usually are not worth
11093 worrying about.
11094
11095 For example, consider the following program:
11096
11097 @smallexample
11098 PRINT *, 0.2
11099 END
11100 @end smallexample
11101
11102 When compiled by @code{g77}, the above program might output
11103 @samp{0.20000003}, while another compiler might produce a
11104 executable that outputs @samp{0.2}.
11105
11106 This particular difference is due to the fact that, currently,
11107 conversion of floating-point values by the @code{libg2c} library,
11108 used by @code{g77}, handles only double-precision values.
11109
11110 Since @samp{0.2} in the program is a single-precision value, it
11111 is converted to double precision (still in binary notation)
11112 before being converted back to decimal.
11113 The conversion to binary appends @emph{binary} zero digits to the
11114 original value---which, again, is an inexact approximation of
11115 0.2---resulting in an approximation that is much less exact
11116 than is connoted by the use of double precision.
11117
11118 (The appending of binary zero digits has essentially the same
11119 effect as taking a particular decimal approximation of
11120 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
11121 zeros to it, producing @samp{0.33333330000000000}.
11122 Treating the resulting decimal approximation as if it really
11123 had 18 or so digits of valid precision would make it seem
11124 a very poor approximation of @samp{1/3}.)
11125
11126 As a result of converting the single-precision approximation
11127 to double precision by appending binary zeros, the conversion
11128 of the resulting double-precision
11129 value to decimal produces what looks like an incorrect
11130 result, when in fact the result is @emph{inexact}, and
11131 is probably no less inaccurate or imprecise an approximation
11132 of 0.2 than is produced by other compilers that happen to output
11133 the converted value as ``exactly'' @samp{0.2}.
11134 (Some compilers behave in a way that can make them appear
11135 to retain more accuracy across a conversion of a single-precision
11136 constant to double precision.
11137 @xref{Context-Sensitive Constants}, to see why
11138 this practice is illusory and even dangerous.)
11139
11140 Note that a more exact approximation of the constant is
11141 computed when the program is changed to specify a
11142 double-precision constant:
11143
11144 @smallexample
11145 PRINT *, 0.2D0
11146 END
11147 @end smallexample
11148
11149 Future versions of @code{g77} and/or @code{libg2c} might convert
11150 single-precision values directly to decimal,
11151 instead of converting them to double precision first.
11152 This would tend to result in output that is more consistent
11153 with that produced by some other Fortran implementations.
11154
11155 A useful source of information on floating-point computation is David
11156 Goldberg, `What Every Computer Scientist Should Know About
11157 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
11158 5-48.
11159 An online version is available at
11160 @uref{http://docs.sun.com/},
11161 and there is a supplemented version, in PostScript form, at
11162 @uref{http://www.validgh.com/goldberg/paper.ps}.
11163
11164 Information related to the IEEE 754
11165 floating-point standard by a leading light can be found at
11166 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status/};
11167 see also slides from the short course referenced from
11168 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
11169 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
11170 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
11171 and library code for GNU/Linux x86 systems.
11172
11173 The supplement to the PostScript-formatted Goldberg document,
11174 referenced above, is available in HTML format.
11175 See `Differences Among IEEE 754 Implementations' by Doug Priest,
11176 available online at
11177 @uref{http://www.validgh.com/goldberg/addendum.html}.
11178 This document explores some of the issues surrounding computing
11179 of extended (80-bit) results on processors such as the x86,
11180 especially when those results are arbitrarily truncated
11181 to 32-bit or 64-bit values by the compiler
11182 as ``spills''.
11183
11184 @cindex spills of floating-point results
11185 @cindex 80-bit spills
11186 @cindex truncation, of floating-point values
11187 (@emph{Note:} @code{g77} specifically, and @code{gcc} generally,
11188 does arbitrarily truncate 80-bit results during spills
11189 as of this writing.
11190 It is not yet clear whether a future version of
11191 the GNU compiler suite will offer 80-bit spills
11192 as an option, or perhaps even as the default behavior.)
11193
11194 @c xref would be different between editions:
11195 The GNU C library provides routines for controlling the FPU, and other
11196 documentation about this.
11197
11198 @xref{Floating-point precision}, regarding IEEE 754 conformance.
11199
11200 @include bugs.texi
11201
11202 @node Missing Features
11203 @section Missing Features
11204
11205 This section lists features we know are missing from @code{g77},
11206 and which we want to add someday.
11207 (There is no priority implied in the ordering below.)
11208
11209 @menu
11210 GNU Fortran language:
11211 * Better Source Model::
11212 * Fortran 90 Support::
11213 * Intrinsics in PARAMETER Statements::
11214 * Arbitrary Concatenation::
11215 * SELECT CASE on CHARACTER Type::
11216 * RECURSIVE Keyword::
11217 * Popular Non-standard Types::
11218 * Full Support for Compiler Types::
11219 * Array Bounds Expressions::
11220 * POINTER Statements::
11221 * Sensible Non-standard Constructs::
11222 * READONLY Keyword::
11223 * FLUSH Statement::
11224 * Expressions in FORMAT Statements::
11225 * Explicit Assembler Code::
11226 * Q Edit Descriptor::
11227
11228 GNU Fortran dialects:
11229 * Old-style PARAMETER Statements::
11230 * TYPE and ACCEPT I/O Statements::
11231 * STRUCTURE UNION RECORD MAP::
11232 * OPEN CLOSE and INQUIRE Keywords::
11233 * ENCODE and DECODE::
11234 * AUTOMATIC Statement::
11235 * Suppressing Space Padding::
11236 * Fortran Preprocessor::
11237 * Bit Operations on Floating-point Data::
11238 * Really Ugly Character Assignments::
11239
11240 New facilities:
11241 * POSIX Standard::
11242 * Floating-point Exception Handling::
11243 * Nonportable Conversions::
11244 * Large Automatic Arrays::
11245 * Support for Threads::
11246 * Increasing Precision/Range::
11247 * Enabling Debug Lines::
11248
11249 Better diagnostics:
11250 * Better Warnings::
11251 * Gracefully Handle Sensible Bad Code::
11252 * Non-standard Conversions::
11253 * Non-standard Intrinsics::
11254 * Modifying DO Variable::
11255 * Better Pedantic Compilation::
11256 * Warn About Implicit Conversions::
11257 * Invalid Use of Hollerith Constant::
11258 * Dummy Array Without Dimensioning Dummy::
11259 * Invalid FORMAT Specifiers::
11260 * Ambiguous Dialects::
11261 * Unused Labels::
11262 * Informational Messages::
11263
11264 Run-time facilities:
11265 * Uninitialized Variables at Run Time::
11266 * Portable Unformatted Files::
11267 * Better List-directed I/O::
11268 * Default to Console I/O::
11269
11270 Debugging:
11271 * Labels Visible to Debugger::
11272 @end menu
11273
11274 @node Better Source Model
11275 @subsection Better Source Model
11276
11277 @code{g77} needs to provide, as the default source-line model,
11278 a ``pure visual'' mode, where
11279 the interpretation of a source program in this mode can be accurately
11280 determined by a user looking at a traditionally displayed rendition
11281 of the program (assuming the user knows whether the program is fixed
11282 or free form).
11283
11284 The design should assume the user cannot tell tabs from spaces
11285 and cannot see trailing spaces on lines, but has canonical tab stops
11286 and, for fixed-form source, has the ability to always know exactly
11287 where column 72 is (since the Fortran standard itself requires
11288 this for fixed-form source).
11289
11290 This would change the default treatment of fixed-form source
11291 to not treat lines with tabs as if they were infinitely long---instead,
11292 they would end at column 72 just as if the tabs were replaced
11293 by spaces in the canonical way.
11294
11295 As part of this, provide common alternate models (Digital, @code{f2c},
11296 and so on) via command-line options.
11297 This includes allowing arbitrarily long
11298 lines for free-form source as well as fixed-form source and providing
11299 various limits and diagnostics as appropriate.
11300
11301 @cindex sequence numbers
11302 @cindex columns 73 through 80
11303 Also, @code{g77} should offer, perhaps even default to, warnings
11304 when characters beyond the last valid column are anything other
11305 than spaces.
11306 This would mean code with ``sequence numbers'' in columns 73 through 80
11307 would be rejected, and there's a lot of that kind of code around,
11308 but one of the most frequent bugs encountered by new users is
11309 accidentally writing fixed-form source code into and beyond
11310 column 73.
11311 So, maybe the users of old code would be able to more easily handle
11312 having to specify, say, a @samp{-Wno-col73to80} option.
11313
11314 @node Fortran 90 Support
11315 @subsection Fortran 90 Support
11316 @cindex Fortran 90, support
11317 @cindex support, Fortran 90
11318
11319 @code{g77} does not support many of the features that
11320 distinguish Fortran 90 (and, now, Fortran 95) from
11321 ANSI FORTRAN 77.
11322
11323 Some Fortran 90 features are supported, because they
11324 make sense to offer even to die-hard users of F77.
11325 For example, many of them codify various ways F77 has
11326 been extended to meet users' needs during its tenure,
11327 so @code{g77} might as well offer them as the primary
11328 way to meet those same needs, even if it offers compatibility
11329 with one or more of the ways those needs were met
11330 by other F77 compilers in the industry.
11331
11332 Still, many important F90 features are not supported,
11333 because no attempt has been made to research each and
11334 every feature and assess its viability in @code{g77}.
11335 In the meantime, users who need those features must
11336 use Fortran 90 compilers anyway, and the best approach
11337 to adding some F90 features to GNU Fortran might well be
11338 to fund a comprehensive project to create GNU Fortran 95.
11339
11340 @node Intrinsics in PARAMETER Statements
11341 @subsection Intrinsics in @code{PARAMETER} Statements
11342 @cindex PARAMETER statement
11343 @cindex statements, PARAMETER
11344
11345 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
11346 This feature is considered to be absolutely vital, even though it
11347 is not standard-conforming, and is scheduled for version 0.6.
11348
11349 Related to this, @code{g77} doesn't allow non-integral
11350 exponentiation in @code{PARAMETER} statements, such as
11351 @samp{PARAMETER (R=2**.25)}.
11352 It is unlikely @code{g77} will ever support this feature,
11353 as doing it properly requires complete emulation of
11354 a target computer's floating-point facilities when
11355 building @code{g77} as a cross-compiler.
11356 But, if the @code{gcc} back end is enhanced to provide
11357 such a facility, @code{g77} will likely use that facility
11358 in implementing this feature soon afterwards.
11359
11360 @node Arbitrary Concatenation
11361 @subsection Arbitrary Concatenation
11362 @cindex concatenation
11363 @cindex CHARACTER*(*)
11364 @cindex run-time, dynamic allocation
11365
11366 @code{g77} doesn't support arbitrary operands for concatenation
11367 in contexts where run-time allocation is required.
11368 For example:
11369
11370 @smallexample
11371 SUBROUTINE X(A)
11372 CHARACTER*(*) A
11373 CALL FOO(A // 'suffix')
11374 @end smallexample
11375
11376 @node SELECT CASE on CHARACTER Type
11377 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
11378
11379 Character-type selector/cases for @code{SELECT CASE} currently
11380 are not supported.
11381
11382 @node RECURSIVE Keyword
11383 @subsection @code{RECURSIVE} Keyword
11384 @cindex RECURSIVE keyword
11385 @cindex keywords, RECURSIVE
11386 @cindex recursion, lack of
11387 @cindex lack of recursion
11388
11389 @code{g77} doesn't support the @code{RECURSIVE} keyword that
11390 F90 compilers do.
11391 Nor does it provide any means for compiling procedures
11392 designed to do recursion.
11393
11394 All recursive code can be rewritten to not use recursion,
11395 but the result is not pretty.
11396
11397 @node Increasing Precision/Range
11398 @subsection Increasing Precision/Range
11399 @cindex -r8
11400 @cindex -qrealsize=8
11401 @cindex -i8
11402 @cindex f2c
11403 @cindex increasing precision
11404 @cindex precision, increasing
11405 @cindex increasing range
11406 @cindex range, increasing
11407 @cindex Toolpack
11408 @cindex Netlib
11409
11410 Some compilers, such as @code{f2c}, have an option (@samp{-r8},
11411 @samp{-qrealsize=8} or
11412 similar) that provides automatic treatment of @code{REAL}
11413 entities such that they have twice the storage size, and
11414 a corresponding increase in the range and precision, of what
11415 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
11416 (This affects @code{COMPLEX} the same way.)
11417
11418 They also typically offer another option (@samp{-i8}) to increase
11419 @code{INTEGER} entities so they are twice as large
11420 (with roughly twice as much range).
11421
11422 (There are potential pitfalls in using these options.)
11423
11424 @code{g77} does not yet offer any option that performs these
11425 kinds of transformations.
11426 Part of the problem is the lack of detailed specifications regarding
11427 exactly how these options affect the interpretation of constants,
11428 intrinsics, and so on.
11429
11430 Until @code{g77} addresses this need, programmers could improve
11431 the portability of their code by modifying it to not require
11432 compile-time options to produce correct results.
11433 Some free tools are available which may help, specifically
11434 in Toolpack (which one would expect to be sound) and the @file{fortran}
11435 section of the Netlib repository.
11436
11437 Use of preprocessors can provide a fairly portable means
11438 to work around the lack of widely portable methods in the Fortran
11439 language itself (though increasing acceptance of Fortran 90 would
11440 alleviate this problem).
11441
11442 @node Popular Non-standard Types
11443 @subsection Popular Non-standard Types
11444 @cindex @code{INTEGER*2} support
11445 @cindex types, @code{INTEGER*2}
11446 @cindex @code{LOGICAL*1} support
11447 @cindex types, @code{LOGICAL*1}
11448
11449 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
11450 and similar.
11451 Version 0.6 will provide full support for this very
11452 popular set of features.
11453 In the meantime, version 0.5.18 provides rudimentary support
11454 for them.
11455
11456 @node Full Support for Compiler Types
11457 @subsection Full Support for Compiler Types
11458
11459 @cindex @code{REAL*16} support
11460 @cindex types, @code{REAL*16}
11461 @cindex @code{INTEGER*8} support
11462 @cindex types, @code{INTEGER*8}
11463 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
11464 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
11465 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
11466 This means providing intrinsic support, and maybe constant
11467 support (using F90 syntax) as well, and, for most
11468 machines will result in automatic support of @code{INTEGER*1},
11469 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
11470 and so on.
11471 This is scheduled for version 0.6.
11472
11473 @node Array Bounds Expressions
11474 @subsection Array Bounds Expressions
11475 @cindex array elements, in adjustable array bounds
11476 @cindex function references, in adjustable array bounds
11477 @cindex array bounds, adjustable
11478 @cindex @code{DIMENSION} statement
11479 @cindex statements, @code{DIMENSION}
11480
11481 @code{g77} doesn't support more general expressions to dimension
11482 arrays, such as array element references, function
11483 references, etc.
11484
11485 For example, @code{g77} currently does not accept the following:
11486
11487 @smallexample
11488 SUBROUTINE X(M, N)
11489 INTEGER N(10), M(N(2), N(1))
11490 @end smallexample
11491
11492 @node POINTER Statements
11493 @subsection POINTER Statements
11494 @cindex POINTER statement
11495 @cindex statements, POINTER
11496 @cindex Cray pointers
11497
11498 @code{g77} doesn't support pointers or allocatable objects
11499 (other than automatic arrays).
11500 This set of features is
11501 probably considered just behind intrinsics
11502 in @code{PARAMETER} statements on the list of large,
11503 important things to add to @code{g77}.
11504
11505 In the meantime, consider using the @code{INTEGER(KIND=7)}
11506 declaration to specify that a variable must be
11507 able to hold a pointer.
11508 This construct is not portable to other non-GNU compilers,
11509 but it is portable to all machines GNU Fortran supports
11510 when @code{g77} is used.
11511
11512 @xref{Functions and Subroutines}, for information on
11513 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
11514 constructs, which are useful for passing pointers to
11515 procedures written in languages other than Fortran.
11516
11517 @node Sensible Non-standard Constructs
11518 @subsection Sensible Non-standard Constructs
11519
11520 @code{g77} rejects things other compilers accept,
11521 like @samp{INTRINSIC SQRT,SQRT}.
11522 As time permits in the future, some of these things that are easy for
11523 humans to read and write and unlikely to be intended to mean something
11524 else will be accepted by @code{g77} (though @samp{-fpedantic} should
11525 trigger warnings about such non-standard constructs).
11526
11527 Until @code{g77} no longer gratuitously rejects sensible code,
11528 you might as well fix your code
11529 to be more standard-conforming and portable.
11530
11531 The kind of case that is important to except from the
11532 recommendation to change your code is one where following
11533 good coding rules would force you to write non-standard
11534 code that nevertheless has a clear meaning.
11535
11536 For example, when writing an @code{INCLUDE} file that
11537 defines a common block, it might be appropriate to
11538 include a @code{SAVE} statement for the common block
11539 (such as @samp{SAVE /CBLOCK/}), so that variables
11540 defined in the common block retain their values even
11541 when all procedures declaring the common block become
11542 inactive (return to their callers).
11543
11544 However, putting @code{SAVE} statements in an @code{INCLUDE}
11545 file would prevent otherwise standard-conforming code
11546 from also specifying the @code{SAVE} statement, by itself,
11547 to indicate that all local variables and arrays are to
11548 have the @code{SAVE} attribute.
11549
11550 For this reason, @code{g77} already has been changed to
11551 allow this combination, because although the general
11552 problem of gratuitously rejecting unambiguous and
11553 ``safe'' constructs still exists in @code{g77}, this
11554 particular construct was deemed useful enough that
11555 it was worth fixing @code{g77} for just this case.
11556
11557 So, while there is no need to change your code
11558 to avoid using this particular construct, there
11559 might be other, equally appropriate but non-standard
11560 constructs, that you shouldn't have to stop using
11561 just because @code{g77} (or any other compiler)
11562 gratuitously rejects it.
11563
11564 Until the general problem is solved, if you have
11565 any such construct you believe is worthwhile
11566 using (e.g. not just an arbitrary, redundant
11567 specification of an attribute), please submit a
11568 bug report with an explanation, so we can consider
11569 fixing @code{g77} just for cases like yours.
11570
11571 @node READONLY Keyword
11572 @subsection @code{READONLY} Keyword
11573 @cindex READONLY
11574
11575 Support for @code{READONLY}, in @code{OPEN} statements,
11576 requires @code{libg2c} support,
11577 to make sure that @samp{CLOSE(@dots{},STATUS='DELETE')}
11578 does not delete a file opened on a unit
11579 with the @code{READONLY} keyword,
11580 and perhaps to trigger a fatal diagnostic
11581 if a @code{WRITE} or @code{PRINT}
11582 to such a unit is attempted.
11583
11584 @emph{Note:} It is not sufficient for @code{g77} and @code{libg2c}
11585 (its version of @code{libf2c})
11586 to assume that @code{READONLY} does not need some kind of explicit support
11587 at run time,
11588 due to UNIX systems not (generally) needing it.
11589 @code{g77} is not just a UNIX-based compiler!
11590
11591 Further, mounting of non-UNIX filesystems on UNIX systems
11592 (such as via NFS)
11593 might require proper @code{READONLY} support.
11594
11595 @cindex SHARED
11596 (Similar issues might be involved with supporting the @code{SHARED}
11597 keyword.)
11598
11599 @node FLUSH Statement
11600 @subsection @code{FLUSH} Statement
11601
11602 @code{g77} could perhaps use a @code{FLUSH} statement that
11603 does what @samp{CALL FLUSH} does,
11604 but that supports @samp{*} as the unit designator (same unit as for
11605 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
11606 specifiers.
11607
11608 @node Expressions in FORMAT Statements
11609 @subsection Expressions in @code{FORMAT} Statements
11610 @cindex FORMAT statement
11611 @cindex statements, FORMAT
11612
11613 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
11614 Supporting this requires a significant redesign or replacement
11615 of @code{libg2c}.
11616
11617 However, @code{g77} does support
11618 this construct when the expression is constant
11619 (as of version 0.5.22).
11620 For example:
11621
11622 @smallexample
11623       PARAMETER (IWIDTH = 12)
11624 10    FORMAT (I<IWIDTH>)
11625 @end smallexample
11626
11627 Otherwise, at least for output (@code{PRINT} and
11628 @code{WRITE}), Fortran code making use of this feature can
11629 be rewritten to avoid it by constructing the @code{FORMAT}
11630 string in a @code{CHARACTER} variable or array, then
11631 using that variable or array in place of the @code{FORMAT}
11632 statement label to do the original @code{PRINT} or @code{WRITE}.
11633
11634 Many uses of this feature on input can be rewritten this way
11635 as well, but not all can.
11636 For example, this can be rewritten:
11637
11638 @smallexample
11639       READ 20, I
11640 20    FORMAT (I<J>)
11641 @end smallexample
11642
11643 However, this cannot, in general, be rewritten, especially
11644 when @code{ERR=} and @code{END=} constructs are employed:
11645
11646 @smallexample
11647       READ 30, J, I
11648 30    FORMAT (I<J>)
11649 @end smallexample
11650
11651 @node Explicit Assembler Code
11652 @subsection Explicit Assembler Code
11653
11654 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
11655 code to specify explicit assembler code.
11656
11657 @node Q Edit Descriptor
11658 @subsection Q Edit Descriptor
11659 @cindex FORMAT statement
11660 @cindex Q edit descriptor
11661 @cindex edit descriptor, Q
11662
11663 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
11664 (This is meant to get the number of characters remaining in an input record.)
11665 Supporting this requires a significant redesign or replacement
11666 of @code{libg2c}.
11667
11668 A workaround might be using internal I/O or the stream-based intrinsics.
11669 @xref{FGetC Intrinsic (subroutine)}.
11670
11671 @node Old-style PARAMETER Statements
11672 @subsection Old-style PARAMETER Statements
11673 @cindex PARAMETER statement
11674 @cindex statements, PARAMETER
11675
11676 @code{g77} doesn't accept @samp{PARAMETER I=1}.
11677 Supporting this obsolete form of
11678 the @code{PARAMETER} statement would not be particularly hard, as most of the
11679 parsing code is already in place and working.
11680
11681 Until time/money is
11682 spent implementing it, you might as well fix your code to use the
11683 standard form, @samp{PARAMETER (I=1)} (possibly needing
11684 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
11685 otherwise, in the obsolete form of @code{PARAMETER}, the
11686 type of the variable is set from the type of the constant being
11687 assigned to it).
11688
11689 @node TYPE and ACCEPT I/O Statements
11690 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
11691 @cindex TYPE statement
11692 @cindex statements, TYPE
11693 @cindex ACCEPT statement
11694 @cindex statements, ACCEPT
11695
11696 @code{g77} doesn't support the I/O statements @code{TYPE} and
11697 @code{ACCEPT}.
11698 These are common extensions that should be easy to support,
11699 but also are fairly easy to work around in user code.
11700
11701 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
11702 by @samp{PRINT fmt,list}.
11703 And, any @samp{ACCEPT fmt,list} statement can be
11704 replaced by @samp{READ fmt,list}.
11705
11706 @node STRUCTURE UNION RECORD MAP
11707 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
11708 @cindex STRUCTURE statement
11709 @cindex statements, STRUCTURE
11710 @cindex UNION statement
11711 @cindex statements, UNION
11712 @cindex RECORD statement
11713 @cindex statements, RECORD
11714 @cindex MAP statement
11715 @cindex statements, MAP
11716
11717 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
11718 @code{MAP}.
11719 This set of extensions is quite a bit
11720 lower on the list of large, important things to add to @code{g77}, partly
11721 because it requires a great deal of work either upgrading or
11722 replacing @code{libg2c}.
11723
11724 @node OPEN CLOSE and INQUIRE Keywords
11725 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
11726 @cindex disposition of files
11727 @cindex OPEN statement
11728 @cindex statements, OPEN
11729 @cindex CLOSE statement
11730 @cindex statements, CLOSE
11731 @cindex INQUIRE statement
11732 @cindex statements, INQUIRE
11733
11734 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
11735 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
11736 These extensions are easy to add to @code{g77} itself, but
11737 require much more work on @code{libg2c}.
11738
11739 @cindex FORM='PRINT'
11740 @cindex ANS carriage control
11741 @cindex carriage control
11742 @pindex asa
11743 @pindex fpr
11744 @code{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
11745 translate the traditional `carriage control' characters in column 1 of
11746 output to use backspaces, carriage returns and the like.  However
11747 programs exist to translate them in output files (or standard output).
11748 These are typically called either @code{fpr} or @code{asa}.  You can get
11749 a version of @code{asa} from
11750 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
11751 systems which will probably build easily on other systems.
11752 Alternatively, @code{fpr} is in BSD distributions in various archive
11753 sites.
11754
11755 @c (Can both programs can be used in a pipeline,
11756 @c with a named input file,
11757 @c and/or with a named output file???)
11758
11759 @node ENCODE and DECODE
11760 @subsection @code{ENCODE} and @code{DECODE}
11761 @cindex ENCODE statement
11762 @cindex statements, ENCODE
11763 @cindex DECODE statement
11764 @cindex statements, DECODE
11765
11766 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
11767
11768 These statements are best replaced by READ and WRITE statements
11769 involving internal files (CHARACTER variables and arrays).
11770
11771 For example, replace a code fragment like
11772
11773 @smallexample
11774       INTEGER*1 LINE(80)
11775 @dots{}
11776       DECODE (80, 9000, LINE) A, B, C
11777 @dots{}
11778 9000  FORMAT (1X, 3(F10.5))
11779 @end smallexample
11780
11781 @noindent
11782 with:
11783
11784 @smallexample
11785       CHARACTER*80 LINE
11786 @dots{}
11787       READ (UNIT=LINE, FMT=9000) A, B, C
11788 @dots{}
11789 9000  FORMAT (1X, 3(F10.5))
11790 @end smallexample
11791
11792 Similarly, replace a code fragment like
11793
11794 @smallexample
11795       INTEGER*1 LINE(80)
11796 @dots{}
11797       ENCODE (80, 9000, LINE) A, B, C
11798 @dots{}
11799 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11800 @end smallexample
11801
11802 @noindent
11803 with:
11804
11805 @smallexample
11806       CHARACTER*80 LINE
11807 @dots{}
11808       WRITE (UNIT=LINE, FMT=9000) A, B, C
11809 @dots{}
11810 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11811 @end smallexample
11812
11813 It is entirely possible that @code{ENCODE} and @code{DECODE} will
11814 be supported by a future version of @code{g77}.
11815
11816 @node AUTOMATIC Statement
11817 @subsection @code{AUTOMATIC} Statement
11818 @cindex @code{AUTOMATIC} statement
11819 @cindex statements, @code{AUTOMATIC}
11820 @cindex automatic variables
11821 @cindex variables, automatic
11822
11823 @code{g77} doesn't support the @code{AUTOMATIC} statement that
11824 @code{f2c} does.
11825
11826 @code{AUTOMATIC} would identify a variable or array
11827 as not being @code{SAVE}'d, which is normally the default,
11828 but which would be especially useful for code that, @emph{generally},
11829 needed to be compiled with the @samp{-fno-automatic} option.
11830
11831 @code{AUTOMATIC} also would serve as a hint to the compiler that placing
11832 the variable or array---even a very large array--on the stack is acceptable.
11833
11834 @code{AUTOMATIC} would not, by itself, designate the containing procedure
11835 as recursive.
11836
11837 @code{AUTOMATIC} should work syntactically like @code{SAVE},
11838 in that @code{AUTOMATIC} with no variables listed should apply to
11839 all pertinent variables and arrays
11840 (which would not include common blocks or their members).
11841
11842 Variables and arrays denoted as @code{AUTOMATIC}
11843 would not be permitted to be initialized via @code{DATA}
11844 or other specification of any initial values,
11845 requiring explicit initialization,
11846 such as via assignment statements.
11847
11848 @cindex UNSAVE
11849 @cindex STATIC
11850 Perhaps @code{UNSAVE} and @code{STATIC},
11851 as strict semantic opposites to @code{SAVE} and @code{AUTOMATIC},
11852 should be provided as well.
11853
11854 @node Suppressing Space Padding
11855 @subsection Suppressing Space Padding of Source Lines
11856
11857 @code{g77} should offer VXT-Fortran-style suppression of virtual
11858 spaces at the end of a source line
11859 if an appropriate command-line option is specified.
11860
11861 This affects cases where
11862 a character constant is continued onto the next line in a fixed-form
11863 source file, as in the following example:
11864
11865 @smallexample
11866 10    PRINT *,'HOW MANY
11867      1 SPACES?'
11868 @end smallexample
11869
11870 @noindent
11871 @code{g77}, and many other compilers, virtually extend
11872 the continued line through column 72 with spaces that become part
11873 of the character constant, but Digital Fortran normally didn't,
11874 leaving only one space between @samp{MANY} and @samp{SPACES?}
11875 in the output of the above statement.
11876
11877 Fairly recently, at least one version of Digital Fortran
11878 was enhanced to provide the other behavior when a
11879 command-line option is specified, apparently due to demand
11880 from readers of the USENET group @file{comp.lang.fortran}
11881 to offer conformance to this widespread practice in the
11882 industry.
11883 @code{g77} should return the favor by offering conformance
11884 to Digital's approach to handling the above example.
11885
11886 @node Fortran Preprocessor
11887 @subsection Fortran Preprocessor
11888
11889 @code{g77} should offer a preprocessor designed specifically
11890 for Fortran to replace @samp{cpp -traditional}.
11891 There are several out there worth evaluating, at least.
11892
11893 Such a preprocessor would recognize Hollerith constants,
11894 properly parse comments and character constants, and so on.
11895 It might also recognize, process, and thus preprocess
11896 files included via the @code{INCLUDE} directive.
11897
11898 @node Bit Operations on Floating-point Data
11899 @subsection Bit Operations on Floating-point Data
11900 @cindex @code{And} intrinsic
11901 @cindex intrinsics, @code{And}
11902 @cindex @code{Or} intrinsic
11903 @cindex intrinsics, @code{Or}
11904 @cindex @code{Shift} intrinsic
11905 @cindex intrinsics, @code{Shift}
11906
11907 @code{g77} does not allow @code{REAL} and other non-integral types for
11908 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
11909
11910 For example, this program is rejected by @code{g77}, because
11911 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
11912
11913 @smallexample
11914 DATA A/7.54/, B/9.112/
11915 PRINT *, IAND(A, B)
11916 END
11917 @end smallexample
11918
11919 @node Really Ugly Character Assignments
11920 @subsection Really Ugly Character Assignments
11921
11922 An option such as @samp{-fugly-char} should be provided
11923 to allow
11924
11925 @smallexample
11926 REAL*8 A1
11927 DATA A1 / '12345678' /
11928 @end smallexample
11929
11930 and:
11931
11932 @smallexample
11933 REAL*8 A1
11934 A1 = 'ABCDEFGH'
11935 @end smallexample
11936
11937 @node POSIX Standard
11938 @subsection @code{POSIX} Standard
11939
11940 @code{g77} should support the POSIX standard for Fortran.
11941
11942 @node Floating-point Exception Handling
11943 @subsection Floating-point Exception Handling
11944 @cindex floating-point, exceptions
11945 @cindex exceptions, floating-point
11946 @cindex FPE handling
11947 @cindex NaN values
11948
11949 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
11950 general control over whether or not floating-point exceptions are trapped or
11951 ignored.
11952 (Ignoring them typically results in NaN values being
11953 propagated in systems that conform to IEEE 754.)
11954 The behaviour is normally inherited from the system-dependent startup
11955 code, though some targets, such as the Alpha, have code generation
11956 options which change the behaviour.
11957
11958 Most systems provide some C-callable mechanism to change this; this can
11959 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
11960 For example, just compiling and linking the following C code with your
11961 program will turn on exception trapping for the ``common'' exceptions
11962 on a GNU system using glibc 2.2 or newer:
11963
11964 @smallexample
11965 #define _GNU_SOURCE 1
11966 #include <fenv.h>
11967 static void __attribute__ ((constructor))
11968 trapfpe ()
11969 @{
11970   /* Enable some exceptions.  At startup all exceptions are masked.  */
11971   
11972   feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
11973 @}
11974 @end smallexample
11975
11976 A convenient trick is to compile this something like:
11977 @smallexample
11978 gcc -o libtrapfpe.a trapfpe.c
11979 @end smallexample
11980 and then use it by adding @samp{-trapfpe} to the @code{g77} command line
11981 when linking.
11982
11983 @node Nonportable Conversions
11984 @subsection Nonportable Conversions
11985 @cindex nonportable conversions
11986 @cindex conversions, nonportable
11987
11988 @code{g77} doesn't accept some particularly nonportable,
11989 silent data-type conversions such as @code{LOGICAL}
11990 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
11991 is type @code{REAL}), that other compilers might
11992 quietly accept.
11993
11994 Some of these conversions are accepted by @code{g77}
11995 when the @samp{-fugly-logint} option is specified.
11996 Perhaps it should accept more or all of them.
11997
11998 @node Large Automatic Arrays
11999 @subsection Large Automatic Arrays
12000 @cindex automatic arrays
12001 @cindex arrays, automatic
12002
12003 Currently, automatic arrays always are allocated on the stack.
12004 For situations where the stack cannot be made large enough,
12005 @code{g77} should offer a compiler option that specifies
12006 allocation of automatic arrays in heap storage.
12007
12008 @node Support for Threads
12009 @subsection Support for Threads
12010 @cindex threads
12011 @cindex parallel processing
12012
12013 Neither the code produced by @code{g77} nor the @code{libg2c} library
12014 are thread-safe, nor does @code{g77} have support for parallel processing
12015 (other than the instruction-level parallelism available on some
12016 processors).
12017 A package such as PVM might help here.
12018
12019 @node Enabling Debug Lines
12020 @subsection Enabling Debug Lines
12021 @cindex debug line
12022 @cindex comment line, debug
12023
12024 An option such as @samp{-fdebug-lines} should be provided
12025 to turn fixed-form lines beginning with @samp{D}
12026 to be treated as if they began with a space,
12027 instead of as if they began with a @samp{C}
12028 (as comment lines).
12029
12030 @node Better Warnings
12031 @subsection Better Warnings
12032
12033 Because of how @code{g77} generates code via the back end,
12034 it doesn't always provide warnings the user wants.
12035 Consider:
12036
12037 @smallexample
12038 PROGRAM X
12039 PRINT *, A
12040 END
12041 @end smallexample
12042
12043 Currently, the above is not flagged as a case of
12044 using an uninitialized variable,
12045 because @code{g77} generates a run-time library call that looks,
12046 to the GBE, like it might actually @emph{modify} @samp{A} at run time.
12047 (And, in fact, depending on the previous run-time library call,
12048 it would!)
12049
12050 Fixing this requires one of the following:
12051
12052 @itemize @bullet
12053 @item
12054 Switch to new library, @code{libg77}, that provides
12055 a more ``clean'' interface,
12056 vis-a-vis input, output, and modified arguments,
12057 so the GBE can tell what's going on.
12058
12059 This would provide a pretty big performance improvement,
12060 at least theoretically, and, ultimately, in practice,
12061 for some types of code.
12062
12063 @item
12064 Have @code{g77} pass a pointer to a temporary
12065 containing a copy of @samp{A},
12066 instead of to @samp{A} itself.
12067 The GBE would then complain about the copy operation
12068 involving a potentially uninitialized variable.
12069
12070 This might also provide a performance boost for some code,
12071 because @samp{A} might then end up living in a register,
12072 which could help with inner loops.
12073
12074 @item
12075 Have @code{g77} use a GBE construct similar to @code{ADDR_EXPR}
12076 but with extra information on the fact that the
12077 item pointed to won't be modified
12078 (a la @code{const} in C).
12079
12080 Probably the best solution for now, but not quite trivial
12081 to implement in the general case.
12082 Worth considering after @code{g77} 0.6 is considered
12083 pretty solid.
12084 @end itemize
12085
12086 @node Gracefully Handle Sensible Bad Code
12087 @subsection Gracefully Handle Sensible Bad Code
12088
12089 @code{g77} generally should continue processing for
12090 warnings and recoverable (user) errors whenever possible---that
12091 is, it shouldn't gratuitously make bad or useless code.
12092
12093 For example:
12094
12095 @smallexample
12096 INTRINSIC ZABS
12097 CALL FOO(ZABS)
12098 END
12099 @end smallexample
12100
12101 @noindent
12102 When compiling the above with @samp{-ff2c-intrinsics-disable},
12103 @code{g77} should indeed complain about passing @code{ZABS},
12104 but it still should compile, instead of rejecting
12105 the entire @code{CALL} statement.
12106 (Some of this is related to improving
12107 the compiler internals to improve how statements are analyzed.)
12108
12109 @node Non-standard Conversions
12110 @subsection Non-standard Conversions
12111
12112 @samp{-Wconversion} and related should flag places where non-standard
12113 conversions are found.
12114 Perhaps much of this would be part of @samp{-Wugly*}.
12115
12116 @node Non-standard Intrinsics
12117 @subsection Non-standard Intrinsics
12118
12119 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
12120 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
12121 This would help find code that might fail silently when ported to another
12122 compiler.
12123
12124 @node Modifying DO Variable
12125 @subsection Modifying @code{DO} Variable
12126
12127 @code{g77} should warn about modifying @code{DO} variables
12128 via @code{EQUIVALENCE}.
12129 (The internal information gathered to produce this warning
12130 might also be useful in setting the
12131 internal ``doiter'' flag for a variable or even array
12132 reference within a loop, since that might produce faster code someday.)
12133
12134 For example, this code is invalid, so @code{g77} should warn about
12135 the invalid assignment to @samp{NOTHER}:
12136
12137 @smallexample
12138 EQUIVALENCE (I, NOTHER)
12139 DO I = 1, 100
12140    IF (I.EQ. 10) NOTHER = 20
12141 END DO
12142 @end smallexample
12143
12144 @node Better Pedantic Compilation
12145 @subsection Better Pedantic Compilation
12146
12147 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
12148 and use it only to generate
12149 warnings instead of rejecting constructs outright.
12150 Have it warn:
12151 if a variable that dimensions an array is not a dummy or placed
12152 explicitly in @code{COMMON} (F77 does not allow it to be
12153 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
12154 follow statement-function-definition statements; about all sorts of
12155 syntactic extensions.
12156
12157 @node Warn About Implicit Conversions
12158 @subsection Warn About Implicit Conversions
12159
12160 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
12161 to expect automatic, silent, and
12162 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
12163 constants to @code{REAL(KIND=2)} based on context.
12164
12165 For example, it would warn about cases like this:
12166
12167 @smallexample
12168 DOUBLE PRECISION FOO
12169 PARAMETER (TZPHI = 9.435784839284958)
12170 FOO = TZPHI * 3D0
12171 @end smallexample
12172
12173 @node Invalid Use of Hollerith Constant
12174 @subsection Invalid Use of Hollerith Constant
12175
12176 @code{g77} should disallow statements like @samp{RETURN 2HAB},
12177 which are invalid in both source forms
12178 (unlike @samp{RETURN (2HAB)},
12179 which probably still makes no sense but at least can
12180 be reliably parsed).
12181 Fixed-form processing rejects it, but not free-form, except
12182 in a way that is a bit difficult to understand.
12183
12184 @node Dummy Array Without Dimensioning Dummy
12185 @subsection Dummy Array Without Dimensioning Dummy
12186
12187 @code{g77} should complain when a list of dummy arguments containing an
12188 adjustable dummy array does
12189 not also contain every variable listed in the dimension list of the
12190 adjustable array.
12191
12192 Currently, @code{g77} does complain about a variable that
12193 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
12194 area, but this needs to be extended to catch cases where it doesn't appear in
12195 every dummy list that also lists any arrays it dimensions.
12196
12197 For example, @code{g77} should warn about the entry point @samp{ALT}
12198 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
12199 list of arguments:
12200
12201 @smallexample
12202 SUBROUTINE PRIMARY(ARRAY, ISIZE)
12203 REAL ARRAY(ISIZE)
12204 ENTRY ALT(ARRAY)
12205 @end smallexample
12206
12207 @node Invalid FORMAT Specifiers
12208 @subsection Invalid FORMAT Specifiers
12209
12210 @code{g77} should check @code{FORMAT} specifiers for validity
12211 as it does @code{FORMAT} statements.
12212
12213 For example, a diagnostic would be produced for:
12214
12215 @smallexample
12216 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
12217 @end smallexample
12218
12219 @node Ambiguous Dialects
12220 @subsection Ambiguous Dialects
12221
12222 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
12223 @samp{-Wvxt}, @samp{-Wf90}, and so on.
12224 These would warn about places in the user's source where ambiguities
12225 are found, helpful in resolving ambiguities in the program's
12226 dialect or dialects.
12227
12228 @node Unused Labels
12229 @subsection Unused Labels
12230
12231 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
12232
12233 @node Informational Messages
12234 @subsection Informational Messages
12235
12236 @code{g77} needs an option to suppress information messages (notes).
12237 @samp{-w} does this but also suppresses warnings.
12238 The default should be to suppress info messages.
12239
12240 Perhaps info messages should simply be eliminated.
12241
12242 @node Uninitialized Variables at Run Time
12243 @subsection Uninitialized Variables at Run Time
12244
12245 @code{g77} needs an option to initialize everything (not otherwise
12246 explicitly initialized) to ``weird''
12247 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
12248 largest-magnitude integers, would help track down references to
12249 some kinds of uninitialized variables at run time.
12250
12251 Note that use of the options @samp{-O -Wuninitialized} can catch
12252 many such bugs at compile time.
12253
12254 @node Portable Unformatted Files
12255 @subsection Portable Unformatted Files
12256
12257 @cindex unformatted files
12258 @cindex file formats
12259 @cindex binary data
12260 @cindex byte ordering
12261 @code{g77} has no facility for exchanging unformatted files with systems
12262 using different number formats---even differing only in endianness (byte
12263 order)---or written by other compilers.  Some compilers provide
12264 facilities at least for doing byte-swapping during unformatted I/O.
12265
12266 It is unrealistic to expect to cope with exchanging unformatted files
12267 with arbitrary other compiler runtimes, but the @code{g77} runtime
12268 should at least be able to read files written by @code{g77} on systems
12269 with different number formats, particularly if they differ only in byte
12270 order.
12271
12272 In case you do need to write a program to translate to or from
12273 @code{g77} (@code{libf2c}) unformatted files, they are written as
12274 follows:
12275 @table @asis
12276 @item Sequential
12277 Unformatted sequential records consist of
12278 @enumerate
12279 @item
12280 A number giving the length of the record contents;
12281 @item
12282 the length of record contents again (for backspace).
12283 @end enumerate
12284
12285 The record length is of C type
12286 @code{long}; this means that it is 8 bytes on 64-bit systems such as
12287 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
12288 Consequently such files cannot be exchanged between 64-bit and 32-bit
12289 systems, even with the same basic number format.
12290 @item Direct access
12291 Unformatted direct access files form a byte stream of length
12292 @var{records}*@var{recl} bytes, where @var{records} is the maximum
12293 record number (@code{REC=@var{records}}) written and @var{recl} is the
12294 record length in bytes specified in the @code{OPEN} statement
12295 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
12296 the relevant @code{WRITE} statement.  Dummy records with arbitrary
12297 contents appear in the file in place of records which haven't been
12298 written.
12299 @end table
12300
12301 Thus for exchanging a sequential or direct access unformatted file
12302 between big- and little-endian 32-bit systems using IEEE 754 floating
12303 point it would be sufficient to reverse the bytes in consecutive words
12304 in the file if, and @emph{only} if, only @code{REAL*4}, @code{COMPLEX},
12305 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
12306 @code{g77}.
12307
12308 If necessary, it is possible to do byte-oriented i/o with @code{g77}'s
12309 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
12310 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
12311 array or a set of scalars.
12312
12313 @cindex HDF
12314 @cindex PDB
12315 If you need to exchange binary data between arbitrary system and
12316 compiler variations, we recommend using a portable binary format with
12317 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
12318 or PACT's PDB@footnote{No, not @emph{that} one.}
12319 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
12320 say, CDF or XDR, HDF-like systems write in the native number formats and
12321 only incur overhead when they are read on a system with a different
12322 format.)  A future @code{g77} runtime library should use such
12323 techniques.
12324
12325 @node Better List-directed I/O
12326 @subsection Better List-directed I/O
12327
12328 Values output using list-directed I/O
12329 (@samp{PRINT *, R, D})
12330 should be written with a field width, precision, and so on
12331 appropriate for the type (precision) of each value.
12332
12333 (Currently, no distinction is made between single-precision
12334 and double-precision values
12335 by @code{libf2c}.)
12336
12337 It is likely this item will require the @code{libg77} project
12338 to be undertaken.
12339
12340 In the meantime, use of formatted I/O is recommended.
12341 While it might be of little consolation,
12342 @code{g77} does support @samp{FORMAT(F<WIDTH>.4)}, for example,
12343 as long as @samp{WIDTH} is defined as a named constant
12344 (via @code{PARAMETER}).
12345 That at least allows some compile-time specification
12346 of the precision of a data type,
12347 perhaps controlled by preprocessing directives.
12348
12349 @node Default to Console I/O
12350 @subsection Default to Console I/O
12351
12352 The default I/O units,
12353 specified by @samp{READ @var{fmt}},
12354 @samp{READ (UNIT=*)},
12355 @samp{WRITE (UNIT=*)}, and
12356 @samp{PRINT @var{fmt}},
12357 should not be units 5 (input) and 6 (output),
12358 but, rather, unit numbers not normally available
12359 for use in statements such as @code{OPEN} and @code{CLOSE}.
12360
12361 Changing this would allow a program to connect units 5 and 6
12362 to files via @code{OPEN},
12363 but still use @samp{READ (UNIT=*)} and @samp{PRINT}
12364 to do I/O to the ``console''.
12365
12366 This change probably requires the @code{libg77} project.
12367
12368 @node Labels Visible to Debugger
12369 @subsection Labels Visible to Debugger
12370
12371 @code{g77} should output debugging information for statements labels,
12372 for use by debuggers that know how to support them.
12373 Same with weirder things like construct names.
12374 It is not yet known if any debug formats or debuggers support these.
12375
12376 @node Disappointments
12377 @section Disappointments and Misunderstandings
12378
12379 These problems are perhaps regrettable, but we don't know any practical
12380 way around them for now.
12381
12382 @menu
12383 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
12384                                               external name @samp{foo_}.
12385 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
12386                                               and @samp{SUBROUTINE FOO}.
12387 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
12388 @end menu
12389
12390 @node Mangling of Names
12391 @subsection Mangling of Names in Source Code
12392 @cindex naming issues
12393 @cindex external names
12394 @cindex common blocks
12395 @cindex name space
12396 @cindex underscore
12397
12398 The current external-interface design, which includes naming of
12399 external procedures, COMMON blocks, and the library interface,
12400 has various usability problems, including things like adding
12401 underscores where not really necessary (and preventing easier
12402 inter-language operability) and yet not providing complete
12403 namespace freedom for user C code linked with Fortran apps (due
12404 to the naming of functions in the library, among other things).
12405
12406 Project GNU should at least get all this ``right'' for systems
12407 it fully controls, such as the Hurd, and provide defaults and
12408 options for compatibility with existing systems and interoperability
12409 with popular existing compilers.
12410
12411 @node Multiple Definitions of External Names
12412 @subsection Multiple Definitions of External Names
12413 @cindex block data
12414 @cindex BLOCK DATA statement
12415 @cindex statements, BLOCK DATA
12416 @cindex @code{COMMON} statement
12417 @cindex statements, @code{COMMON}
12418 @cindex naming conflicts
12419
12420 @code{g77} doesn't allow a common block and an external procedure or
12421 @code{BLOCK DATA} to have the same name.
12422 Some systems allow this, but @code{g77} does not,
12423 to be compatible with @code{f2c}.
12424
12425 @code{g77} could special-case the way it handles
12426 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
12427 particular area (necessarily, since @code{g77} offers an
12428 important feature here), but
12429 it is likely that such special-casing would be very annoying to people
12430 with programs that use @samp{EXTERNAL FOO}, with no other mention of
12431 @samp{FOO} in the same program unit, to refer to external procedures, since
12432 the result would be that @code{g77} would treat these references as requests to
12433 force-load BLOCK DATA program units.
12434
12435 In that case, if @code{g77} modified
12436 names of @code{BLOCK DATA} so they could have the same names as
12437 @code{COMMON}, users
12438 would find that their programs wouldn't link because the @samp{FOO} procedure
12439 didn't have its name translated the same way.
12440
12441 (Strictly speaking,
12442 @code{g77} could emit a null-but-externally-satisfying definition of
12443 @samp{FOO} with its name transformed as if it had been a
12444 @code{BLOCK DATA}, but that probably invites more trouble than it's
12445 worth.)
12446
12447 @node Limitation on Implicit Declarations
12448 @subsection Limitation on Implicit Declarations
12449 @cindex IMPLICIT CHARACTER*(*) statement
12450 @cindex statements, IMPLICIT CHARACTER*(*)
12451
12452 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
12453 This is not standard-conforming.
12454
12455 @node Non-bugs
12456 @section Certain Changes We Don't Want to Make
12457
12458 This section lists changes that people frequently request, but which
12459 we do not make because we think GNU Fortran is better without them.
12460
12461 @menu
12462 * Backslash in Constants::           Why @samp{'\\'} is a constant that
12463                                        is one, not two, characters long.
12464 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
12465                                        @samp{COMMON VAR}.
12466 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
12467 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
12468                                        single-precision constant,
12469                                        and might be interpreted as
12470                                        @samp{9.435785} or similar.
12471 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
12472 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
12473                                        not behave as expected.
12474 @end menu
12475
12476 @node Backslash in Constants
12477 @subsection Backslash in Constants
12478 @cindex backslash
12479 @cindex @code{f77} support
12480 @cindex support, @code{f77}
12481
12482 In the opinion of many experienced Fortran users,
12483 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
12484 as currently set by @code{g77}.
12485
12486 First of all, you can always specify
12487 @samp{-fno-backslash} to turn off this processing.
12488
12489 Despite not being within the spirit (though apparently within the
12490 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
12491 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
12492 default to, and apparently lots of code depends on this feature.
12493
12494 This is a particularly troubling issue.
12495 The use of a C construct in the midst of Fortran code
12496 is bad enough, worse when it makes existing Fortran
12497 programs stop working (as happens when programs written
12498 for non-UNIX systems are ported to UNIX systems with
12499 compilers that provide the @samp{-fbackslash} feature
12500 as the default---sometimes with no option to turn it off).
12501
12502 The author of GNU Fortran wished, for reasons of linguistic
12503 purity, to make @samp{-fno-backslash} the default for GNU
12504 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
12505 to specify @samp{-fbackslash} to get the UNIX behavior.
12506
12507 However, the realization that @code{g77} is intended as
12508 a replacement for @emph{UNIX} @code{f77}, caused the author
12509 to choose to make @code{g77} as compatible with
12510 @code{f77} as feasible, which meant making @samp{-fbackslash}
12511 the default.
12512
12513 The primary focus on compatibility is at the source-code
12514 level, and the question became ``What will users expect
12515 a replacement for @code{f77} to do, by default?''
12516 Although at least one UNIX @code{f77} does not provide
12517 @samp{-fbackslash} as a default, it appears that
12518 the majority of them do, which suggests that
12519 the majority of code that is compiled by UNIX @code{f77}
12520 compilers expects @samp{-fbackslash} to be the default.
12521
12522 It is probably the case that more code exists
12523 that would @emph{not} work with @samp{-fbackslash}
12524 in force than code that requires it be in force.
12525
12526 However, most of @emph{that} code is not being compiled
12527 with @code{f77},
12528 and when it is, new build procedures (shell scripts,
12529 makefiles, and so on) must be set up anyway so that
12530 they work under UNIX.
12531 That makes a much more natural and safe opportunity for
12532 non-UNIX users to adapt their build procedures for
12533 @code{g77}'s default of @samp{-fbackslash} than would
12534 exist for the majority of UNIX @code{f77} users who
12535 would have to modify existing, working build procedures
12536 to explicitly specify @samp{-fbackslash} if that was
12537 not the default.
12538
12539 One suggestion has been to configure the default for
12540 @samp{-fbackslash} (and perhaps other options as well)
12541 based on the configuration of @code{g77}.
12542
12543 This is technically quite straightforward, but will be avoided
12544 even in cases where not configuring defaults to be
12545 dependent on a particular configuration greatly inconveniences
12546 some users of legacy code.
12547
12548 Many users appreciate the GNU compilers because they provide an
12549 environment that is uniform across machines.
12550 These users would be
12551 inconvenienced if the compiler treated things like the
12552 format of the source code differently on certain machines.
12553
12554 Occasionally users write programs intended only for a particular machine
12555 type.
12556 On these occasions, the users would benefit if the GNU Fortran compiler
12557 were to support by default the same dialect as the other compilers on
12558 that machine.
12559 But such applications are rare.
12560 And users writing a
12561 program to run on more than one type of machine cannot possibly benefit
12562 from this kind of compatibility.
12563 (This is consistent with the design goals for @code{gcc}.
12564 To change them for @code{g77}, you must first change them
12565 for @code{gcc}.
12566 Do not ask the maintainers of @code{g77} to do this for you,
12567 or to disassociate @code{g77} from the widely understood, if
12568 not widely agreed-upon, goals for GNU compilers in general.)
12569
12570 This is why GNU Fortran does and will treat backslashes in the same
12571 fashion on all types of machines (by default).
12572 @xref{Direction of Language Development}, for more information on
12573 this overall philosophy guiding the development of the GNU Fortran
12574 language.
12575
12576 Of course, users strongly concerned about portability should indicate
12577 explicitly in their build procedures which options are expected
12578 by their source code, or write source code that has as few such
12579 expectations as possible.
12580
12581 For example, avoid writing code that depends on backslash (@samp{\})
12582 being interpreted either way in particular, such as by
12583 starting a program unit with:
12584
12585 @smallexample
12586 CHARACTER BACKSL
12587 PARAMETER (BACKSL = '\\')
12588 @end smallexample
12589
12590 @noindent
12591 Then, use concatenation of @samp{BACKSL} anyplace a backslash
12592 is desired.
12593 In this way, users can write programs which have the same meaning
12594 in many Fortran dialects.
12595
12596 (However, this technique does not work for Hollerith constants---which
12597 is just as well, since the only generally portable uses for Hollerith
12598 constants are in places where character constants can and should
12599 be used instead, for readability.)
12600
12601 @node Initializing Before Specifying
12602 @subsection Initializing Before Specifying
12603 @cindex initialization, statement placement
12604 @cindex placing initialization statements
12605
12606 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
12607 source code before @samp{COMMON VAR},
12608 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
12609 In general, @code{g77} requires initialization of a variable
12610 or array to be specified @emph{after} all other specifications
12611 of attributes (type, size, placement, and so on) of that variable
12612 or array are specified (though @emph{confirmation} of data type is
12613 permitted).
12614
12615 It is @emph{possible} @code{g77} will someday allow all of this,
12616 even though it is not allowed by the FORTRAN 77 standard.
12617
12618 Then again, maybe it is better to have
12619 @code{g77} always require placement of @code{DATA}
12620 so that it can possibly immediately write constants
12621 to the output file, thus saving time and space.
12622
12623 That is, @samp{DATA A/1000000*1/} should perhaps always
12624 be immediately writable to canonical assembler, unless it's already known
12625 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
12626 and to do this it cannot be followed by @samp{COMMON A}.
12627
12628 @node Context-Sensitive Intrinsicness
12629 @subsection Context-Sensitive Intrinsicness
12630 @cindex intrinsics, context-sensitive
12631 @cindex context-sensitive intrinsics
12632
12633 @code{g77} treats procedure references to @emph{possible} intrinsic
12634 names as always enabling their intrinsic nature, regardless of
12635 whether the @emph{form} of the reference is valid for that
12636 intrinsic.
12637
12638 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
12639 an invalid reference to the @code{SQRT} intrinsic function,
12640 because the reference is a subroutine invocation.
12641
12642 First, @code{g77} recognizes the statement @samp{CALL SQRT}
12643 as a reference to a @emph{procedure} named @samp{SQRT}, not
12644 to a @emph{variable} with that name (as it would for a statement
12645 such as @samp{V = SQRT}).
12646
12647 Next, @code{g77} establishes that, in the program unit being compiled,
12648 @code{SQRT} is an intrinsic---not a subroutine that
12649 happens to have the same name as an intrinsic (as would be
12650 the case if, for example, @samp{EXTERNAL SQRT} was present).
12651
12652 Finally, @code{g77} recognizes that the @emph{form} of the
12653 reference is invalid for that particular intrinsic.
12654 That is, it recognizes that it is invalid for an intrinsic
12655 @emph{function}, such as @code{SQRT}, to be invoked as
12656 a @emph{subroutine}.
12657
12658 At that point, @code{g77} issues a diagnostic.
12659
12660 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
12661 references an external subroutine of their own, not an
12662 intrinsic function.
12663
12664 However, @code{g77} knows about intrinsic
12665 subroutines, not just functions, and is able to support both having
12666 the same names, for example.
12667
12668 As a result of this, @code{g77} rejects calls
12669 to intrinsics that are not subroutines, and function invocations
12670 of intrinsics that are not functions, just as it (and most compilers)
12671 rejects invocations of intrinsics with the wrong number (or types)
12672 of arguments.
12673
12674 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
12675 a user-written subroutine named @samp{SQRT}.
12676
12677 @node Context-Sensitive Constants
12678 @subsection Context-Sensitive Constants
12679 @cindex constants, context-sensitive
12680 @cindex context-sensitive constants
12681
12682 @code{g77} does not use context to determine the types of
12683 constants or named constants (@code{PARAMETER}), except
12684 for (non-standard) typeless constants such as @samp{'123'O}.
12685
12686 For example, consider the following statement:
12687
12688 @smallexample
12689 PRINT *, 9.435784839284958 * 2D0
12690 @end smallexample
12691
12692 @noindent
12693 @code{g77} will interpret the (truncated) constant
12694 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
12695 constant, because the suffix @code{D0} is not specified.
12696
12697 As a result, the output of the above statement when
12698 compiled by @code{g77} will appear to have ``less precision''
12699 than when compiled by other compilers.
12700
12701 In these and other cases, some compilers detect the
12702 fact that a single-precision constant is used in
12703 a double-precision context and therefore interpret the
12704 single-precision constant as if it was @emph{explicitly}
12705 specified as a double-precision constant.
12706 (This has the effect of appending @emph{decimal}, not
12707 @emph{binary}, zeros to the fractional part of the
12708 number---producing different computational results.)
12709
12710 The reason this misfeature is dangerous is that a slight,
12711 apparently innocuous change to the source code can change
12712 the computational results.
12713 Consider:
12714
12715 @smallexample
12716 REAL ALMOST, CLOSE
12717 DOUBLE PRECISION FIVE
12718 PARAMETER (ALMOST = 5.000000000001)
12719 FIVE = 5
12720 CLOSE = 5.000000000001
12721 PRINT *, 5.000000000001 - FIVE
12722 PRINT *, ALMOST - FIVE
12723 PRINT *, CLOSE - FIVE
12724 END
12725 @end smallexample
12726
12727 @noindent
12728 Running the above program should
12729 result in the same value being
12730 printed three times.
12731 With @code{g77} as the compiler,
12732 it does.
12733
12734 However, compiled by many other compilers,
12735 running the above program would print
12736 two or three distinct values, because
12737 in two or three of the statements, the
12738 constant @samp{5.000000000001}, which
12739 on most systems is exactly equal to @samp{5.}
12740 when interpreted as a single-precision constant,
12741 is instead interpreted as a double-precision
12742 constant, preserving the represented
12743 precision.
12744 However, this ``clever'' promotion of
12745 type does not extend to variables or,
12746 in some compilers, to named constants.
12747
12748 Since programmers often are encouraged to replace manifest
12749 constants or permanently-assigned variables with named
12750 constants (@code{PARAMETER} in Fortran), and might need
12751 to replace some constants with variables having the same
12752 values for pertinent portions of code,
12753 it is important that compilers treat code so modified in the
12754 same way so that the results of such programs are the same.
12755 @code{g77} helps in this regard by treating constants just
12756 the same as variables in terms of determining their types
12757 in a context-independent way.
12758
12759 Still, there is a lot of existing Fortran code that has
12760 been written to depend on the way other compilers freely
12761 interpret constants' types based on context, so anything
12762 @code{g77} can do to help flag cases of this in such code
12763 could be very helpful.
12764
12765 @node Equivalence Versus Equality
12766 @subsection Equivalence Versus Equality
12767 @cindex .EQV., with integer operands
12768 @cindex comparing logical expressions
12769 @cindex logical expressions, comparing
12770
12771 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
12772 is not supported, except via @samp{-fugly-logint}, which is not
12773 recommended except for legacy code (where the behavior expected
12774 by the @emph{code} is assumed).
12775
12776 Legacy code should be changed, as resources permit, to use @code{.EQV.}
12777 and @code{.NEQV.} instead, as these are permitted by the various
12778 Fortran standards.
12779
12780 New code should never be written expecting @code{.EQ.} or @code{.NE.}
12781 to work if either of its operands is @code{LOGICAL}.
12782
12783 The problem with supporting this ``feature'' is that there is
12784 unlikely to be consensus on how it works, as illustrated by the
12785 following sample program:
12786
12787 @smallexample
12788 LOGICAL L,M,N
12789 DATA L,M,N /3*.FALSE./
12790 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
12791 END
12792 @end smallexample
12793
12794 The issue raised by the above sample program is: what is the
12795 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
12796 @code{LOGICAL} operands?
12797
12798 Some programmers will argue that it is the same as the precedence
12799 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
12800 operands.
12801 By this interpretation, the subexpression @samp{M.EQ.N} must be
12802 evaluated first in the above program, resulting in a program that,
12803 when run, does not execute the @code{PRINT} statement.
12804
12805 Other programmers will argue that the precedence is the same as
12806 the precedence for @code{.EQV.}, which is restricted by the standards
12807 to @code{LOGICAL} operands.
12808 By this interpretation, the subexpression @samp{L.AND.M} must be
12809 evaluated first, resulting in a program that @emph{does} execute
12810 the @code{PRINT} statement.
12811
12812 Assigning arbitrary semantic interpretations to syntactic expressions
12813 that might legitimately have more than one ``obvious'' interpretation
12814 is generally unwise.
12815
12816 The creators of the various Fortran standards have done a good job
12817 in this case, requiring a distinct set of operators (which have their
12818 own distinct precedence) to compare @code{LOGICAL} operands.
12819 This requirement results in expression syntax with more certain
12820 precedence (without requiring substantial context), making it easier
12821 for programmers to read existing code.
12822 @code{g77} will avoid muddying up elements of the Fortran language
12823 that were well-designed in the first place.
12824
12825 (Ask C programmers about the precedence of expressions such as
12826 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
12827 you, without knowing more context, whether the @samp{&} and @samp{-}
12828 operators are infix (binary) or unary!)
12829
12830 Most dangerous of all is the fact that,
12831 even assuming consensus on its meaning,
12832 an expression like @samp{L.AND.M.EQ.N},
12833 if it is the result of a typographical error,
12834 doesn't @emph{look} like it has such a typo.
12835 Even experienced Fortran programmers would not likely notice that
12836 @samp{L.AND.M.EQV.N} was, in fact, intended.
12837
12838 So, this is a prime example of a circumstance in which
12839 a quality compiler diagnoses the code,
12840 instead of leaving it up to someone debugging it
12841 to know to turn on special compiler options
12842 that might diagnose it.
12843
12844 @node Order of Side Effects
12845 @subsection Order of Side Effects
12846 @cindex side effects, order of evaluation
12847 @cindex order of evaluation, side effects
12848
12849 @code{g77} does not necessarily produce code that, when run, performs
12850 side effects (such as those performed by function invocations)
12851 in the same order as in some other compiler---or even in the same
12852 order as another version, port, or invocation (using different
12853 command-line options) of @code{g77}.
12854
12855 It is never safe to depend on the order of evaluation of side effects.
12856 For example, an expression like this may very well behave differently
12857 from one compiler to another:
12858
12859 @smallexample
12860 J = IFUNC() - IFUNC()
12861 @end smallexample
12862
12863 @noindent
12864 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
12865 order.
12866 Either invocation might happen first.
12867 If @samp{IFUNC} returns 5 the first time it is invoked, and
12868 returns 12 the second time, @samp{J} might end up with the
12869 value @samp{7}, or it might end up with @samp{-7}.
12870
12871 Generally, in Fortran, procedures with side-effects intended to
12872 be visible to the caller are best designed as @emph{subroutines},
12873 not functions.
12874 Examples of such side-effects include:
12875
12876 @itemize @bullet
12877 @item
12878 The generation of random numbers
12879 that are intended to influence return values.
12880
12881 @item
12882 Performing I/O
12883 (other than internal I/O to local variables).
12884
12885 @item
12886 Updating information in common blocks.
12887 @end itemize
12888
12889 An example of a side-effect that is not intended to be visible
12890 to the caller is a function that maintains a cache of recently
12891 calculated results, intended solely to speed repeated invocations
12892 of the function with identical arguments.
12893 Such a function can be safely used in expressions, because
12894 if the compiler optimizes away one or more calls to the
12895 function, operation of the program is unaffected (aside
12896 from being speeded up).
12897
12898 @node Warnings and Errors
12899 @section Warning Messages and Error Messages
12900
12901 @cindex error messages
12902 @cindex warnings vs errors
12903 @cindex messages, warning and error
12904 The GNU compiler can produce two kinds of diagnostics: errors and
12905 warnings.
12906 Each kind has a different purpose:
12907
12908 @itemize @w{}
12909 @item
12910 @emph{Errors} report problems that make it impossible to compile your
12911 program.
12912 GNU Fortran reports errors with the source file name, line
12913 number, and column within the line where the problem is apparent.
12914
12915 @item
12916 @emph{Warnings} report other unusual conditions in your code that
12917 @emph{might} indicate a problem, although compilation can (and does)
12918 proceed.
12919 Warning messages also report the source file name, line number,
12920 and column information,
12921 but include the text @samp{warning:} to distinguish them
12922 from error messages.
12923 @end itemize
12924
12925 Warnings might indicate danger points where you should check to make sure
12926 that your program really does what you intend; or the use of obsolete
12927 features; or the use of nonstandard features of GNU Fortran.
12928 Many warnings are issued only if you ask for them, with one of the
12929 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
12930 useful warnings).
12931
12932 @emph{Note:} Currently, the text of the line and a pointer to the column
12933 is printed in most @code{g77} diagnostics.
12934 Probably, as of version 0.6, @code{g77} will
12935 no longer print the text of the source line, instead printing
12936 the column number following the file name and line number in
12937 a form that GNU Emacs recognizes.
12938 This change is expected to speed up and reduce the memory usage
12939 of the @code{g77} compiler.
12940 @c
12941 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
12942 @c
12943 @c GNU Fortran always tries to compile your program if possible; it never
12944 @c gratuitously rejects a program whose meaning is clear merely because
12945 @c (for instance) it fails to conform to a standard.  In some cases,
12946 @c however, the Fortran standard specifies that certain extensions are
12947 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
12948 @c compiler.  The @samp{-pedantic} option tells GNU Fortran to issue warnings
12949 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
12950 @c This does not mean that @emph{all} non-ANSI constructs get warnings
12951 @c or errors.
12952
12953 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
12954 more detail on these and related command-line options.
12955
12956 @node Open Questions
12957 @chapter Open Questions
12958
12959 Please consider offering useful answers to these questions!
12960
12961 @itemize @bullet
12962 @item
12963 @code{LOC()} and other intrinsics are probably somewhat misclassified.
12964 Is the a need for more precise classification of intrinsics, and if so,
12965 what are the appropriate groupings?
12966 Is there a need to individually
12967 enable/disable/delete/hide intrinsics from the command line?
12968 @end itemize
12969
12970 @node Bugs
12971 @chapter Reporting Bugs
12972 @cindex bugs
12973 @cindex reporting bugs
12974
12975 Your bug reports play an essential role in making GNU Fortran reliable.
12976
12977 When you encounter a problem, the first thing to do is to see if it is
12978 already known.
12979 @xref{Trouble}.
12980 If it isn't known, then you should report the problem.
12981
12982 Reporting a bug might help you by bringing a solution to your problem, or
12983 it might not.
12984 (If it does not, look in the service directory; see
12985 @ref{Service}.)
12986 In any case, the principal function of a bug report is
12987 to help the entire community by making the next version of GNU Fortran work
12988 better.
12989 Bug reports are your contribution to the maintenance of GNU Fortran.
12990
12991 Since the maintainers are very overloaded, we cannot respond to every
12992 bug report.
12993 However, if the bug has not been fixed, we are likely to
12994 send you a patch and ask you to tell us whether it works.
12995
12996 In order for a bug report to serve its purpose, you must include the
12997 information that makes for fixing the bug.
12998
12999 @menu
13000 * Criteria: Bug Criteria.    Have you really found a bug?
13001 * Where: Bug Lists.          Where to send your bug report.
13002 * Reporting: Bug Reporting.  How to report a bug effectively.
13003 * Patches: Sending Patches.  How to send a patch for GNU Fortran.
13004 @end menu
13005
13006 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
13007 for information on problems we already know about.
13008
13009 @xref{Service,,How To Get Help with GNU Fortran},
13010 for information on where to ask for help.
13011
13012 @node Bug Criteria
13013 @section Have You Found a Bug?
13014 @cindex bug criteria
13015
13016 If you are not sure whether you have found a bug, here are some guidelines:
13017
13018 @itemize @bullet
13019 @cindex fatal signal
13020 @cindex core dump
13021 @item
13022 If the compiler gets a fatal signal, for any input whatever, that is a
13023 compiler bug.
13024 Reliable compilers never crash---they just remain obsolete.
13025
13026 @cindex invalid assembly code
13027 @cindex assembly code, invalid
13028 @item
13029 If the compiler produces invalid assembly code, for any input whatever,
13030 @c (except an @code{asm} statement),
13031 that is a compiler bug, unless the
13032 compiler reports errors (not just warnings) which would ordinarily
13033 prevent the assembler from being run.
13034
13035 @cindex undefined behavior
13036 @cindex undefined function value
13037 @item
13038 If the compiler produces valid assembly code that does not correctly
13039 execute the input source code, that is a compiler bug.
13040
13041 However, you must double-check to make sure, because you might have run
13042 into an incompatibility between GNU Fortran and traditional Fortran.
13043 @c (@pxref{Incompatibilities}).
13044 These incompatibilities might be considered
13045 bugs, but they are inescapable consequences of valuable features.
13046
13047 Or you might have a program whose behavior is undefined, which happened
13048 by chance to give the desired results with another Fortran compiler.
13049 It is best to check the relevant Fortran standard thoroughly if
13050 it is possible that the program indeed does something undefined.
13051
13052 After you have localized the error to a single source line, it should
13053 be easy to check for these things.
13054 If your program is correct and well defined, you have found
13055 a compiler bug.
13056
13057 It might help if, in your submission, you identified the specific
13058 language in the relevant Fortran standard that specifies the
13059 desired behavior, if it isn't likely to be obvious and agreed-upon
13060 by all Fortran users.
13061
13062 @item
13063 If the compiler produces an error message for valid input, that is a
13064 compiler bug.
13065
13066 @cindex invalid input
13067 @item
13068 If the compiler does not produce an error message for invalid input,
13069 that is a compiler bug.
13070 However, you should note that your idea of
13071 ``invalid input'' might be someone else's idea
13072 of ``an extension'' or ``support for traditional practice''.
13073
13074 @item
13075 If you are an experienced user of Fortran compilers, your suggestions
13076 for improvement of GNU Fortran are welcome in any case.
13077 @end itemize
13078
13079 Many, perhaps most, bug reports against @code{g77} turn out to
13080 be bugs in the user's code.
13081 While we find such bug reports educational, they sometimes take
13082 a considerable amount of time to track down or at least respond
13083 to---time we could be spending making @code{g77}, not some user's
13084 code, better.
13085
13086 Some steps you can take to verify that the bug is not certainly
13087 in the code you're compiling with @code{g77}:
13088
13089 @itemize @bullet
13090 @item
13091 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
13092 These options enable many useful warning; the @samp{-O} option
13093 enables flow analysis that enables the uninitialized-variable
13094 warning.
13095
13096 If you investigate the warnings and find evidence of possible bugs
13097 in your code, fix them first and retry @code{g77}.
13098
13099 @item
13100 Compile your code using the @code{g77} options @samp{-finit-local-zero},
13101 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
13102 combinations thereof.
13103
13104 If your code works with any of these combinations, that is not
13105 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
13106 by your code might simply be avoided, or have a different, more subtle
13107 effect, when different options are used---but it can be a
13108 strong indicator that your code is making unwarranted assumptions
13109 about the Fortran dialect and/or underlying machine it is
13110 being compiled and run on.
13111
13112 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
13113 for information on the @samp{-fno-automatic} and
13114 @samp{-finit-local-zero} options and how to convert
13115 their use into selective changes in your own code.
13116
13117 @item
13118 @pindex ftnchek
13119 Validate your code with @code{ftnchek} or a similar code-checking
13120 tool.
13121 @code{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
13122 or @uref{ftp://ftp.dsm.fordham.edu}.
13123
13124 @pindex make
13125 @cindex Makefile example
13126 Here are some sample @file{Makefile} rules using @code{ftnchek}
13127 ``project'' files to do cross-file checking and @code{sfmakedepend}
13128 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
13129 to maintain dependencies automatically.
13130 These assume the use of GNU @code{make}.
13131
13132 @smallexample
13133 # Dummy suffix for ftnchek targets:
13134 .SUFFIXES: .chek
13135 .PHONY: chekall
13136
13137 # How to compile .f files (for implicit rule):
13138 FC = g77
13139 # Assume `include' directory:
13140 FFLAGS = -Iinclude -g -O -Wall
13141
13142 # Flags for ftnchek:
13143 CHEK1 = -array=0 -include=includes -noarray
13144 CHEK2 = -nonovice -usage=1 -notruncation
13145 CHEKFLAGS = $(CHEK1) $(CHEK2)
13146
13147 # Run ftnchek with all the .prj files except the one corresponding
13148 # to the target's root:
13149 %.chek : %.f ; \
13150   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
13151     -noextern -library $<
13152
13153 # Derive a project file from a source file:
13154 %.prj : %.f ; \
13155   ftnchek $(CHEKFLAGS) -noextern -project -library $<
13156
13157 # The list of objects is assumed to be in variable OBJS.
13158 # Sources corresponding to the objects:
13159 SRCS = $(OBJS:%.o=%.f)
13160 # ftnchek project files:
13161 PRJS = $(OBJS:%.o=%.prj)
13162
13163 # Build the program
13164 prog: $(OBJS) ; \
13165   $(FC) -o $@ $(OBJS)
13166
13167 chekall: $(PRJS) ; \
13168   ftnchek $(CHEKFLAGS) $(PRJS)
13169
13170 prjs: $(PRJS)
13171
13172 # For Emacs M-x find-tag:
13173 TAGS: $(SRCS) ; \
13174   etags $(SRCS)
13175
13176 # Rebuild dependencies:
13177 depend: ; \
13178   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
13179 @end smallexample
13180
13181 @item
13182 Try your code out using other Fortran compilers, such as @code{f2c}.
13183 If it does not work on at least one other compiler (assuming the
13184 compiler supports the features the code needs), that is a strong
13185 indicator of a bug in the code.
13186
13187 However, even if your code works on many compilers @emph{except}
13188 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
13189 It might mean the bug is in your code, and that @code{g77} simply
13190 exposes it more readily than other compilers.
13191 @end itemize
13192
13193 @node Bug Lists
13194 @section Where to Report Bugs
13195 @cindex bug report mailing lists
13196 @kindex @value{email-bugs}
13197 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
13198
13199 Often people think of posting bug reports to a newsgroup instead of
13200 mailing them.
13201 This sometimes appears to work, but it has one problem which can be
13202 crucial: a newsgroup posting does not contain a mail path back to the
13203 sender.
13204 Thus, if maintainers need more information, they might be unable
13205 to reach you.  For this reason, you should always send bug reports by
13206 mail to the proper mailing list.
13207
13208 As a last resort, send bug reports on paper to:
13209
13210 @example
13211 GNU Compiler Bugs
13212 Free Software Foundation
13213 59 Temple Place - Suite 330
13214 Boston, MA 02111-1307, USA
13215 @end example
13216
13217 @node Bug Reporting
13218 @section How to Report Bugs
13219 @cindex compiler bugs, reporting
13220
13221 The fundamental principle of reporting bugs usefully is this:
13222 @strong{report all the facts}.
13223 If you are not sure whether to state a
13224 fact or leave it out, state it!
13225
13226 Often people omit facts because they think they know what causes the
13227 problem and they conclude that some details don't matter.
13228 Thus, you might
13229 assume that the name of the variable you use in an example does not matter.
13230 Well, probably it doesn't, but one cannot be sure.
13231 Perhaps the bug is a
13232 stray memory reference which happens to fetch from the location where that
13233 name is stored in memory; perhaps, if the name were different, the contents
13234 of that location would fool the compiler into doing the right thing despite
13235 the bug.
13236 Play it safe and give a specific, complete example.
13237 That is the
13238 easiest thing for you to do, and the most helpful.
13239
13240 Keep in mind that the purpose of a bug report is to enable someone to
13241 fix the bug if it is not known.
13242 It isn't very important what happens if
13243 the bug is already known.
13244 Therefore, always write your bug reports on
13245 the assumption that the bug is not known.
13246
13247 Sometimes people give a few sketchy facts and ask, ``Does this ring a
13248 bell?''
13249 This cannot help us fix a bug, so it is rarely helpful.
13250 We respond by asking for enough details to enable us to investigate.
13251 You might as well expedite matters by sending them to begin with.
13252 (Besides, there are enough bells ringing around here as it is.)
13253
13254 Try to make your bug report self-contained.
13255 If we have to ask you for
13256 more information, it is best if you include all the previous information
13257 in your response, as well as the information that was missing.
13258
13259 Please report each bug in a separate message.
13260 This makes it easier for
13261 us to track which bugs have been fixed and to forward your bugs reports
13262 to the appropriate maintainer.
13263
13264 Do not compress and encode any part of your bug report using programs
13265 such as @file{uuencode}.
13266 If you do so it will slow down the processing
13267 of your bug.
13268 If you must submit multiple large files, use @file{shar},
13269 which allows us to read your message without having to run any
13270 decompression programs.
13271
13272 (As a special exception for GNU Fortran bug-reporting, at least
13273 for now, if you are sending more than a few lines of code, if
13274 your program's source file format contains ``interesting'' things
13275 like trailing spaces or strange characters, or if you need to
13276 include binary data files, it is acceptable to put all the
13277 files together in a @code{tar} archive, and, whether you need to
13278 do that, it is acceptable to then compress the single file (@code{tar}
13279 archive or source file)
13280 using @code{gzip} and encode it via @code{uuencode}.
13281 Do not use any MIME stuff---the current maintainer can't decode this.
13282 Using @code{compress} instead of @code{gzip} is acceptable, assuming
13283 you have licensed the use of the patented algorithm in
13284 @code{compress} from Unisys.)
13285
13286 To enable someone to investigate the bug, you should include all these
13287 things:
13288
13289 @itemize @bullet
13290 @item
13291 The version of GNU Fortran.
13292 You can get this by running @code{g77} with the @samp{-v} option.
13293 (Ignore any error messages that might be displayed
13294 when the linker is run.)
13295
13296 Without this, we won't know whether there is any point in looking for
13297 the bug in the current version of GNU Fortran.
13298
13299 @item
13300 @cindex preprocessor
13301 @cindex cpp program
13302 @cindex programs, cpp
13303 @pindex cpp
13304 A complete input file that will reproduce the bug.
13305
13306 If your source file(s) require preprocessing
13307 (for example, their names have suffixes like
13308 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
13309 and the bug is in the compiler proper (@file{f771})
13310 or in a subsequent phase of processing,
13311 run your source file through the C preprocessor
13312 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
13313 Then, include the contents of @var{newfile} in the bug report.
13314 (When you do this, use the same preprocessor options---such as
13315 @samp{-I}, @samp{-D}, and @samp{-U}---that you used in actual
13316 compilation.)
13317
13318 A single statement is not enough of an example.
13319 In order to compile it,
13320 it must be embedded in a complete file of compiler input.
13321 The bug might depend on the details of how this is done.
13322
13323 Without a real example one can compile,
13324 all anyone can do about your bug report is wish you luck.
13325 It would be futile to try to guess how to provoke the bug.
13326 For example, bugs in register allocation and reloading
13327 can depend on every little detail of the source and include files
13328 that trigger them.
13329
13330 @item
13331 @cindex included files
13332 @cindex INCLUDE directive
13333 @cindex directive, INCLUDE
13334 @cindex #include directive
13335 @cindex directive, #include
13336 Note that you should include with your bug report any files
13337 included by the source file
13338 (via the @code{#include} or @code{INCLUDE} directive)
13339 that you send, and any files they include, and so on.
13340
13341 It is not necessary to replace
13342 the @code{#include} and @code{INCLUDE} directives
13343 with the actual files in the version of the source file that
13344 you send, but it might make submitting the bug report easier
13345 in the end.
13346 However, be sure to @emph{reproduce} the bug using the @emph{exact}
13347 version of the source material you submit, to avoid wild-goose
13348 chases.
13349
13350 @item
13351 The command arguments you gave GNU Fortran to compile that example
13352 and observe the bug.  For example, did you use @samp{-O}?  To guarantee
13353 you won't omit something important, list all the options.
13354
13355 If we were to try to guess the arguments, we would probably guess wrong
13356 and then we would not encounter the bug.
13357
13358 @item
13359 The type of machine you are using, and the operating system name and
13360 version number.
13361 (Much of this information is printed by @samp{g77 -v}---if you
13362 include that, send along any additional info you have that you
13363 don't see clearly represented in that output.)
13364
13365 @item
13366 The operands you gave to the @code{configure} command when you installed
13367 the compiler.
13368
13369 @item
13370 A complete list of any modifications you have made to the compiler
13371 source.  (We don't promise to investigate the bug unless it happens in
13372 an unmodified compiler.  But if you've made modifications and don't tell
13373 us, then you are sending us on a wild-goose chase.)
13374
13375 Be precise about these changes.  A description in English is not
13376 enough---send a context diff for them.
13377
13378 Adding files of your own (such as a machine description for a machine we
13379 don't support) is a modification of the compiler source.
13380
13381 @item
13382 Details of any other deviations from the standard procedure for installing
13383 GNU Fortran.
13384
13385 @item
13386 A description of what behavior you observe that you believe is
13387 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
13388 ``The assembler instruction at line 208 in the output is incorrect.''
13389
13390 Of course, if the bug is that the compiler gets a fatal signal, then one
13391 can't miss it.  But if the bug is incorrect output, the maintainer might
13392 not notice unless it is glaringly wrong.  None of us has time to study
13393 all the assembler code from a 50-line Fortran program just on the chance that
13394 one instruction might be wrong.  We need @emph{you} to do this part!
13395
13396 Even if the problem you experience is a fatal signal, you should still
13397 say so explicitly.  Suppose something strange is going on, such as, your
13398 copy of the compiler is out of synch, or you have encountered a bug in
13399 the C library on your system.  (This has happened!)  Your copy might
13400 crash and the copy here would not.  If you @i{said} to expect a crash,
13401 then when the compiler here fails to crash, we would know that the bug
13402 was not happening.  If you don't say to expect a crash, then we would
13403 not know whether the bug was happening.  We would not be able to draw
13404 any conclusion from our observations.
13405
13406 If the problem is a diagnostic when building GNU Fortran with some other
13407 compiler, say whether it is a warning or an error.
13408
13409 Often the observed symptom is incorrect output when your program is run.
13410 Sad to say, this is not enough information unless the program is short
13411 and simple.  None of us has time to study a large program to figure out
13412 how it would work if compiled correctly, much less which line of it was
13413 compiled wrong.  So you will have to do that.  Tell us which source line
13414 it is, and what incorrect result happens when that line is executed.  A
13415 person who understands the program can find this as easily as finding a
13416 bug in the program itself.
13417
13418 @item
13419 If you send examples of assembler code output from GNU Fortran,
13420 please use @samp{-g} when you make them.  The debugging information
13421 includes source line numbers which are essential for correlating the
13422 output with the input.
13423
13424 @item
13425 If you wish to mention something in the GNU Fortran source, refer to it by
13426 context, not by line number.
13427
13428 The line numbers in the development sources don't match those in your
13429 sources.  Your line numbers would convey no convenient information to the
13430 maintainers.
13431
13432 @item
13433 Additional information from a debugger might enable someone to find a
13434 problem on a machine which he does not have available.  However, you
13435 need to think when you collect this information if you want it to have
13436 any chance of being useful.
13437
13438 @cindex backtrace for bug reports
13439 For example, many people send just a backtrace, but that is never
13440 useful by itself.  A simple backtrace with arguments conveys little
13441 about GNU Fortran because the compiler is largely data-driven; the same
13442 functions are called over and over for different RTL insns, doing
13443 different things depending on the details of the insn.
13444
13445 Most of the arguments listed in the backtrace are useless because they
13446 are pointers to RTL list structure.  The numeric values of the
13447 pointers, which the debugger prints in the backtrace, have no
13448 significance whatever; all that matters is the contents of the objects
13449 they point to (and most of the contents are other such pointers).
13450
13451 In addition, most compiler passes consist of one or more loops that
13452 scan the RTL insn sequence.  The most vital piece of information about
13453 such a loop---which insn it has reached---is usually in a local variable,
13454 not in an argument.
13455
13456 @findex debug_rtx
13457 What you need to provide in addition to a backtrace are the values of
13458 the local variables for several stack frames up.  When a local
13459 variable or an argument is an RTX, first print its value and then use
13460 the GDB command @code{pr} to print the RTL expression that it points
13461 to.  (If GDB doesn't run on your machine, use your debugger to call
13462 the function @code{debug_rtx} with the RTX as an argument.)  In
13463 general, whenever a variable is a pointer, its value is no use
13464 without the data it points to.
13465 @end itemize
13466
13467 Here are some things that are not necessary:
13468
13469 @itemize @bullet
13470 @item
13471 A description of the envelope of the bug.
13472
13473 Often people who encounter a bug spend a lot of time investigating
13474 which changes to the input file will make the bug go away and which
13475 changes will not affect it.
13476
13477 This is often time consuming and not very useful, because the way we
13478 will find the bug is by running a single example under the debugger with
13479 breakpoints, not by pure deduction from a series of examples.  You might
13480 as well save your time for something else.
13481
13482 Of course, if you can find a simpler example to report @emph{instead} of
13483 the original one, that is a convenience.  Errors in the output will be
13484 easier to spot, running under the debugger will take less time, etc.
13485 Most GNU Fortran bugs involve just one function, so the most straightforward
13486 way to simplify an example is to delete all the function definitions
13487 except the one where the bug occurs.  Those earlier in the file may be
13488 replaced by external declarations if the crucial function depends on
13489 them.  (Exception: inline functions might affect compilation of functions
13490 defined later in the file.)
13491
13492 However, simplification is not vital; if you don't want to do this,
13493 report the bug anyway and send the entire test case you used.
13494
13495 @item
13496 In particular, some people insert conditionals @samp{#ifdef BUG} around
13497 a statement which, if removed, makes the bug not happen.  These are just
13498 clutter; we won't pay any attention to them anyway.  Besides, you should
13499 send us preprocessor output, and that can't have conditionals.
13500
13501 @item
13502 A patch for the bug.
13503
13504 A patch for the bug is useful if it is a good one.  But don't omit the
13505 necessary information, such as the test case, on the assumption that a
13506 patch is all we need.  We might see problems with your patch and decide
13507 to fix the problem another way, or we might not understand it at all.
13508
13509 Sometimes with a program as complicated as GNU Fortran it is very hard to
13510 construct an example that will make the program follow a certain path
13511 through the code.  If you don't send the example, we won't be able to
13512 construct one, so we won't be able to verify that the bug is fixed.
13513
13514 And if we can't understand what bug you are trying to fix, or why your
13515 patch should be an improvement, we won't install it.  A test case will
13516 help us to understand.
13517
13518 @xref{Sending Patches}, for guidelines on how to make it easy for us to
13519 understand and install your patches.
13520
13521 @item
13522 A guess about what the bug is or what it depends on.
13523
13524 Such guesses are usually wrong.  Even the maintainer can't guess right
13525 about such things without first using the debugger to find the facts.
13526
13527 @item
13528 A core dump file.
13529
13530 We have no way of examining a core dump for your type of machine
13531 unless we have an identical system---and if we do have one,
13532 we should be able to reproduce the crash ourselves.
13533 @end itemize
13534
13535 @node Sending Patches
13536 @section Sending Patches for GNU Fortran
13537
13538 If you would like to write bug fixes or improvements for the GNU Fortran
13539 compiler, that is very helpful.
13540 Send suggested fixes to the mailing list for patches,
13541 @email{@value{email-patch}}.
13542
13543 Please follow these guidelines so we can study your patches efficiently.
13544 If you don't follow these guidelines, your information might still be
13545 useful, but using it will take extra work.  Maintaining GNU Fortran is a lot
13546 of work in the best of circumstances, and we can't keep up unless you do
13547 your best to help.
13548
13549 @itemize @bullet
13550 @item
13551 Send an explanation with your changes of what problem they fix or what
13552 improvement they bring about.  For a bug fix, just include a copy of the
13553 bug report, and explain why the change fixes the bug.
13554
13555 (Referring to a bug report is not as good as including it, because then
13556 we will have to look it up, and we have probably already deleted it if
13557 we've already fixed the bug.)
13558
13559 @item
13560 Always include a proper bug report for the problem you think you have
13561 fixed.  We need to convince ourselves that the change is right before
13562 installing it.  Even if it is right, we might have trouble judging it if
13563 we don't have a way to reproduce the problem.
13564
13565 @item
13566 Include all the comments that are appropriate to help people reading the
13567 source in the future understand why this change was needed.
13568
13569 @item
13570 Don't mix together changes made for different reasons.
13571 Send them @emph{individually}.
13572
13573 If you make two changes for separate reasons, then we might not want to
13574 install them both.  We might want to install just one.  If you send them
13575 all jumbled together in a single set of diffs, we have to do extra work
13576 to disentangle them---to figure out which parts of the change serve
13577 which purpose.  If we don't have time for this, we might have to ignore
13578 your changes entirely.
13579
13580 If you send each change as soon as you have written it, with its own
13581 explanation, then the two changes never get tangled up, and we can
13582 consider each one properly without any extra work to disentangle them.
13583
13584 Ideally, each change you send should be impossible to subdivide into
13585 parts that we might want to consider separately, because each of its
13586 parts gets its motivation from the other parts.
13587
13588 @item
13589 Send each change as soon as that change is finished.  Sometimes people
13590 think they are helping us by accumulating many changes to send them all
13591 together.  As explained above, this is absolutely the worst thing you
13592 could do.
13593
13594 Since you should send each change separately, you might as well send it
13595 right away.  That gives us the option of installing it immediately if it
13596 is important.
13597
13598 @item
13599 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
13600 for us to install reliably.  More than that, they make it hard for us to
13601 study the diffs to decide whether we want to install them.  Unidiff
13602 format is better than contextless diffs, but not as easy to read as
13603 @samp{-c} format.
13604
13605 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
13606 function that each change occurs in.
13607 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
13608
13609 @item
13610 Write the change log entries for your changes.  We get lots of changes,
13611 and we don't have time to do all the change log writing ourselves.
13612
13613 Read the @file{ChangeLog} file to see what sorts of information to put
13614 in, and to learn the style that we use.  The purpose of the change log
13615 is to show people where to find what was changed.  So you need to be
13616 specific about what functions you changed; in large functions, it's
13617 often helpful to indicate where within the function the change was.
13618
13619 On the other hand, once you have shown people where to find the change,
13620 you need not explain its purpose.  Thus, if you add a new function, all
13621 you need to say about it is that it is new.  If you feel that the
13622 purpose needs explaining, it probably does---but the explanation will be
13623 much more useful if you put it in comments in the code.
13624
13625 If you would like your name to appear in the header line for who made
13626 the change, send us the header line.
13627
13628 @item
13629 When you write the fix, keep in mind that we can't install a change that
13630 would break other systems.
13631
13632 People often suggest fixing a problem by changing machine-independent
13633 files such as @file{toplev.c} to do something special that a particular
13634 system needs.  Sometimes it is totally obvious that such changes would
13635 break GNU Fortran for almost all users.  We can't possibly make a change like
13636 that.  At best it might tell us how to write another patch that would
13637 solve the problem acceptably.
13638
13639 Sometimes people send fixes that @emph{might} be an improvement in
13640 general---but it is hard to be sure of this.  It's hard to install
13641 such changes because we have to study them very carefully.  Of course,
13642 a good explanation of the reasoning by which you concluded the change
13643 was correct can help convince us.
13644
13645 The safest changes are changes to the configuration files for a
13646 particular machine.  These are safe because they can't create new bugs
13647 on other machines.
13648
13649 Please help us keep up with the workload by designing the patch in a
13650 form that is good to install.
13651 @end itemize
13652
13653 @node Service
13654 @chapter How To Get Help with GNU Fortran
13655
13656 If you need help installing, using or changing GNU Fortran, there are two
13657 ways to find it:
13658
13659 @itemize @bullet
13660 @item
13661 Look in the service directory for someone who might help you for a fee.
13662 The service directory is found in the file named @file{SERVICE} in the
13663 GNU CC distribution.
13664
13665 @item
13666 Send a message to @email{@value{email-help}}.
13667 @end itemize
13668
13669 @end ifset
13670 @ifset INTERNALS
13671 @node Adding Options
13672 @chapter Adding Options
13673 @cindex options, adding
13674 @cindex adding options
13675
13676 To add a new command-line option to @code{g77}, first decide
13677 what kind of option you wish to add.
13678 Search the @code{g77} and @code{gcc} documentation for one
13679 or more options that is most closely like the one you want to add
13680 (in terms of what kind of effect it has, and so on) to
13681 help clarify its nature.
13682
13683 @itemize @bullet
13684 @item
13685 @emph{Fortran options} are options that apply only
13686 when compiling Fortran programs.
13687 They are accepted by @code{g77} and @code{gcc}, but
13688 they apply only when compiling Fortran programs.
13689
13690 @item
13691 @emph{Compiler options} are options that apply
13692 when compiling most any kind of program.
13693 @end itemize
13694
13695 @emph{Fortran options} are listed in the file
13696 @file{@value{path-g77}/lang-options.h},
13697 which is used during the build of @code{gcc} to
13698 build a list of all options that are accepted by
13699 at least one language's compiler.
13700 This list goes into the @code{documented_lang_options} array
13701 in @file{gcc/toplev.c}, which uses this array to
13702 determine whether a particular option should be
13703 offered to the linked-in front end for processing
13704 by calling @code{lang_option_decode}, which, for
13705 @code{g77}, is in @file{@value{path-g77}/com.c} and just
13706 calls @code{ffe_decode_option}.
13707
13708 If the linked-in front end ``rejects'' a
13709 particular option passed to it, @file{toplev.c}
13710 just ignores the option, because @emph{some}
13711 language's compiler is willing to accept it.
13712
13713 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
13714 to work, even though Fortran compilation does
13715 not currently support the @samp{-fno-asm} option;
13716 even though the @code{f771} version of @code{lang_decode_option}
13717 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
13718 produce a diagnostic because some other language (C)
13719 does accept it.
13720
13721 This also means that commands like
13722 @samp{g77 -fno-asm foo.f} yield no diagnostics,
13723 despite the fact that no phase of the command was
13724 able to recognize and process @samp{-fno-asm}---perhaps
13725 a warning about this would be helpful if it were
13726 possible.
13727
13728 Code that processes Fortran options is found in
13729 @file{@value{path-g77}/top.c}, function @code{ffe_decode_option}.
13730 This code needs to check positive and negative forms
13731 of each option.
13732
13733 The defaults for Fortran options are set in their
13734 global definitions, also found in @file{@value{path-g77}/top.c}.
13735 Many of these defaults are actually macros defined
13736 in @file{@value{path-g77}/target.h}, since they might be
13737 machine-specific.
13738 However, since, in practice, GNU compilers
13739 should behave the same way on all configurations
13740 (especially when it comes to language constructs),
13741 the practice of setting defaults in @file{target.h}
13742 is likely to be deprecated and, ultimately, stopped
13743 in future versions of @code{g77}.
13744
13745 Accessor macros for Fortran options, used by code
13746 in the @code{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
13747
13748 @emph{Compiler options} are listed in @file{gcc/toplev.c}
13749 in the array @code{f_options}.
13750 An option not listed in @code{lang_options} is
13751 looked up in @code{f_options} and handled from there.
13752
13753 The defaults for compiler options are set in the
13754 global definitions for the corresponding variables,
13755 some of which are in @file{gcc/toplev.c}.
13756
13757 You can set different defaults for @emph{Fortran-oriented}
13758 or @emph{Fortran-reticent} compiler options by changing
13759 the source code of @code{g77} and rebuilding.
13760 How to do this depends on the version of @code{g77}:
13761
13762 @table @code
13763 @item G77 0.5.24 (EGCS 1.1)
13764 @itemx G77 0.5.25 (EGCS 1.2 - which became GCC 2.95)
13765 Change the @code{lang_init_options} routine in @file{gcc/gcc/f/com.c}.
13766
13767 (Note that these versions of @code{g77}
13768 perform internal consistency checking automatically
13769 when the @samp{-fversion} option is specified.)
13770
13771 @item G77 0.5.23
13772 @itemx G77 0.5.24 (EGCS 1.0)
13773 Change the way @code{f771} handles the @samp{-fset-g77-defaults}
13774 option, which is always provided as the first option when
13775 called by @code{g77} or @code{gcc}.
13776
13777 This code is in @code{ffe_decode_options} in @file{@value{path-g77}/top.c}.
13778 Have it change just the variables that you want to default
13779 to a different setting for Fortran compiles compared to
13780 compiles of other languages.
13781
13782 The @samp{-fset-g77-defaults} option is passed to @code{f771}
13783 automatically because of the specification information
13784 kept in @file{@value{path-g77}/lang-specs.h}.
13785 This file tells the @code{gcc} command how to recognize,
13786 in this case, Fortran source files (those to be preprocessed,
13787 and those that are not), and further, how to invoke the
13788 appropriate programs (including @code{f771}) to process
13789 those source files.
13790
13791 It is in @file{@value{path-g77}/lang-specs.h} that @samp{-fset-g77-defaults},
13792 @samp{-fversion}, and other options are passed, as appropriate,
13793 even when the user has not explicitly specified them.
13794 Other ``internal'' options such as @samp{-quiet} also
13795 are passed via this mechanism.
13796 @end table
13797
13798 @node Projects
13799 @chapter Projects
13800 @cindex projects
13801
13802 If you want to contribute to @code{g77} by doing research,
13803 design, specification, documentation, coding, or testing,
13804 the following information should give you some ideas.
13805 More relevant information might be available from
13806 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
13807
13808 @menu
13809 * Efficiency::               Make @code{g77} itself compile code faster.
13810 * Better Optimization::      Teach @code{g77} to generate faster code.
13811 * Simplify Porting::         Make @code{g77} easier to configure, build,
13812                              and install.
13813 * More Extensions::          Features many users won't know to ask for.
13814 * Machine Model::            @code{g77} should better leverage @code{gcc}.
13815 * Internals Documentation::  Make maintenance easier.
13816 * Internals Improvements::   Make internals more robust.
13817 * Better Diagnostics::       Make using @code{g77} on new code easier.
13818 @end menu
13819
13820 @node Efficiency
13821 @section Improve Efficiency
13822 @cindex efficiency
13823
13824 Don't bother doing any performance analysis until most of the
13825 following items are taken care of, because there's no question
13826 they represent serious space/time problems, although some of
13827 them show up only given certain kinds of (popular) input.
13828
13829 @itemize @bullet
13830 @item
13831 Improve @code{malloc} package and its uses to specify more info about
13832 memory pools and, where feasible, use obstacks to implement them.
13833
13834 @item
13835 Skip over uninitialized portions of aggregate areas (arrays,
13836 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
13837 This would reduce memory usage for large initialized aggregate
13838 areas, even ones with only one initialized element.
13839
13840 As of version 0.5.18, a portion of this item has already been
13841 accomplished.
13842
13843 @item
13844 Prescan the statement (in @file{sta.c}) so that the nature of the statement
13845 is determined as much as possible by looking entirely at its form,
13846 and not looking at any context (previous statements, including types
13847 of symbols).
13848 This would allow ripping out of the statement-confirmation,
13849 symbol retraction/confirmation, and diagnostic inhibition
13850 mechanisms.
13851 Plus, it would result in much-improved diagnostics.
13852 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
13853 is not a subroutine intrinsic, would result actual error instead of the
13854 unimplemented-statement catch-all.
13855
13856 @item
13857 Throughout @code{g77}, don't pass line/column pairs where
13858 a simple @code{ffewhere} type, which points to the error as much as is
13859 desired by the configuration, will do, and don't pass @code{ffelexToken} types
13860 where a simple @code{ffewhere} type will do.
13861 Then, allow new default
13862 configuration of @code{ffewhere} such that the source line text is not
13863 preserved, and leave it to things like Emacs' next-error function
13864 to point to them (now that @samp{next-error} supports column,
13865 or, perhaps, character-offset, numbers).
13866 The change in calling sequences should improve performance somewhat,
13867 as should not having to save source lines.
13868 (Whether this whole
13869 item will improve performance is questionable, but it should
13870 improve maintainability.)
13871
13872 @item
13873 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
13874 as regards the assembly output.
13875 Some of this might require improving
13876 the back end, but lots of improvement in space/time required in @code{g77}
13877 itself can be fairly easily obtained without touching the back end.
13878 Maybe type-conversion, where necessary, can be speeded up as well in
13879 cases like the one shown (converting the @samp{2} into @samp{2.}).
13880
13881 @item
13882 If analysis shows it to be worthwhile, optimize @file{lex.c}.
13883
13884 @item
13885 Consider redesigning @file{lex.c} to not need any feedback
13886 during tokenization, by keeping track of enough parse state on its
13887 own.
13888 @end itemize
13889
13890 @node Better Optimization
13891 @section Better Optimization
13892 @cindex optimization, better
13893 @cindex code generation, improving
13894
13895 Much of this work should be put off until after @code{g77} has
13896 all the features necessary for its widespread acceptance as a
13897 useful F77 compiler.
13898 However, perhaps this work can be done in parallel during
13899 the feature-adding work.
13900
13901 @itemize @bullet
13902 @item
13903 Do the equivalent of the trick of putting @samp{extern inline} in front
13904 of every function definition in @code{libg2c} and #include'ing the resulting
13905 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
13906 that are at all worth inlining.
13907 (Some of this has already been done, such as for integral exponentiation.)
13908
13909 @item
13910 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
13911 and it's clear that types line up
13912 and @samp{CHAR_VAR} is addressable or not a @code{VAR_DECL},
13913 make @samp{CHAR_VAR}, not a
13914 temporary, be the receiver for @samp{CHAR_FUNC}.
13915 (This is now done for @code{COMPLEX} variables.)
13916
13917 @item
13918 Design and implement Fortran-specific optimizations that don't
13919 really belong in the back end, or where the front end needs to
13920 give the back end more info than it currently does.
13921
13922 @item
13923 Design and implement a new run-time library interface, with the
13924 code going into @code{libgcc} so no special linking is required to
13925 link Fortran programs using standard language features.
13926 This library
13927 would speed up lots of things, from I/O (using precompiled formats,
13928 doing just one, or, at most, very few, calls for arrays or array sections,
13929 and so on) to general computing (array/section implementations of
13930 various intrinsics, implementation of commonly performed loops that
13931 aren't likely to be optimally compiled otherwise, etc.).
13932
13933 Among the important things the library would do are:
13934
13935 @itemize @bullet
13936 @item
13937 Be a one-stop-shop-type
13938 library, hence shareable and usable by all, in that what are now
13939 library-build-time options in @code{libg2c} would be moved at least to the
13940 @code{g77} compile phase, if not to finer grains (such as choosing how
13941 list-directed I/O formatting is done by default at @code{OPEN} time, for
13942 preconnected units via options or even statements in the main program
13943 unit, maybe even on a per-I/O basis with appropriate pragma-like
13944 devices).
13945 @end itemize
13946
13947 @item
13948 Probably requiring the new library design, change interface to
13949 normally have @code{COMPLEX} functions return their values in the way
13950 @code{gcc} would if they were declared @code{__complex__ float},
13951 rather than using
13952 the mechanism currently used by @code{CHARACTER} functions (whereby the
13953 functions are compiled as returning void and their first arg is
13954 a pointer to where to store the result).
13955 (Don't append underscores to
13956 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
13957 @code{gcc} rather than @code{f2c} calling conventions.)
13958
13959 @item
13960 Do something useful with @code{doiter} references where possible.
13961 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
13962 a @code{DO} loop that uses @samp{I} as the
13963 iteration variable, and the back end might find that info useful
13964 in determining whether it needs to read @samp{I} back into a register after
13965 the call.
13966 (It normally has to do that, unless it knows @samp{FOO} never
13967 modifies its passed-by-reference argument, which is rarely the case
13968 for Fortran-77 code.)
13969 @end itemize
13970
13971 @node Simplify Porting
13972 @section Simplify Porting
13973 @cindex porting, simplify
13974 @cindex simplify porting
13975
13976 Making @code{g77} easier to configure, port, build, and install, either
13977 as a single-system compiler or as a cross-compiler, would be
13978 very useful.
13979
13980 @itemize @bullet
13981 @item
13982 A new library (replacing @code{libg2c}) should improve portability as well as
13983 produce more optimal code.
13984 Further, @code{g77} and the new library should
13985 conspire to simplify naming of externals, such as by removing unnecessarily
13986 added underscores, and to reduce/eliminate the possibility of naming
13987 conflicts, while making debugger more straightforward.
13988
13989 Also, it should
13990 make multi-language applications more feasible, such as by providing
13991 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
13992 descriptors.
13993
13994 @item
13995 Possibly related to a new library, @code{g77} should produce the equivalent
13996 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
13997 main program unit, instead of compiling something that must be
13998 called by a library
13999 implementation of @code{main()}.
14000
14001 This would do many useful things such as
14002 provide more flexibility in terms of setting up exception handling,
14003 not requiring programmers to start their debugging sessions with
14004 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
14005
14006 @item
14007 The GBE needs to understand the difference between alignment
14008 requirements and desires.
14009 For example, on Intel x86 machines, @code{g77} currently imposes
14010 overly strict alignment requirements, due to the back end, but it
14011 would be useful for Fortran and C programmers to be able to override
14012 these @emph{recommendations} as long as they don't violate the actual
14013 processor @emph{requirements}.
14014 @end itemize
14015
14016 @node More Extensions
14017 @section More Extensions
14018 @cindex extensions, more
14019
14020 These extensions are not the sort of things users ask for ``by name'',
14021 but they might improve the usability of @code{g77}, and Fortran in
14022 general, in the long run.
14023 Some of these items really pertain to improving @code{g77} internals
14024 so that some popular extensions can be more easily supported.
14025
14026 @itemize @bullet
14027 @item
14028 Look through all the documentation on the GNU Fortran language,
14029 dialects, compiler, missing features, bugs, and so on.
14030 Many mentions of incomplete or missing features are
14031 sprinkled throughout.
14032 It is not worth repeating them here.
14033
14034 @item
14035 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
14036 named and unnamed.
14037 The idea is to provide a forward-looking, effective
14038 replacement for things like the old-style @code{PARAMETER} statement
14039 when people
14040 really need typelessness in a maintainable, portable, clearly documented
14041 way.
14042 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
14043 and whatever else might come along.
14044 (This is not really a call for polymorphism per se, just
14045 an ability to express limited, syntactic polymorphism.)
14046
14047 @item
14048 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
14049
14050 @item
14051 Support arbitrary file unit numbers, instead of limiting them
14052 to 0 through @samp{MXUNIT-1}.
14053 (This is a @code{libg2c} issue.)
14054
14055 @item
14056 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
14057 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
14058 later @code{UNIT=} in the first example is invalid.
14059 Make sure this is what users of this feature would expect.
14060
14061 @item
14062 Currently @code{g77} disallows @samp{READ(1'10)} since
14063 it is an obnoxious syntax, but
14064 supporting it might be pretty easy if needed.
14065 More details are needed, such
14066 as whether general expressions separated by an apostrophe are supported,
14067 or maybe the record number can be a general expression, and so on.
14068
14069 @item
14070 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
14071 fully.
14072 Currently there is no support at all
14073 for @code{%FILL} in @code{STRUCTURE} and related syntax,
14074 whereas the rest of the
14075 stuff has at least some parsing support.
14076 This requires either major
14077 changes to @code{libg2c} or its replacement.
14078
14079 @item
14080 F90 and @code{g77} probably disagree about label scoping relative to
14081 @code{INTERFACE} and @code{END INTERFACE}, and their contained
14082 procedure interface bodies (blocks?).
14083
14084 @item
14085 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
14086 since that was added after S8.112.
14087
14088 @item
14089 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
14090 with the final form of the standard (it was vague at S8.112).
14091
14092 @item
14093 It seems to be an ``open'' question whether a file, immediately after being
14094 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
14095 might be nice to offer an option of opening to ``undefined'' status, requiring
14096 an explicit absolute-positioning operation to be performed before any
14097 other (besides @code{CLOSE}) to assist in making applications port to systems
14098 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
14099 @end itemize
14100
14101 @node Machine Model
14102 @section Machine Model
14103
14104 This items pertain to generalizing @code{g77}'s view of
14105 the machine model to more fully accept whatever the GBE
14106 provides it via its configuration.
14107
14108 @itemize @bullet
14109 @item
14110 Switch to using @code{REAL_VALUE_TYPE} to represent floating-point constants
14111 exclusively so the target float format need not be required.
14112 This
14113 means changing the way @code{g77} handles initialization of aggregate areas
14114 having more than one type, such as @code{REAL} and @code{INTEGER},
14115 because currently
14116 it initializes them as if they were arrays of @code{char} and uses the
14117 bit patterns of the constants of the various types in them to determine
14118 what to stuff in elements of the arrays.
14119
14120 @item
14121 Rely more and more on back-end info and capabilities, especially in the
14122 area of constants (where having the @code{g77} front-end's IL just store
14123 the appropriate tree nodes containing constants might be best).
14124
14125 @item
14126 Suite of C and Fortran programs that a user/administrator can run on a
14127 machine to help determine the configuration for @code{g77} before building
14128 and help determine if the compiler works (especially with whatever
14129 libraries are installed) after building.
14130 @end itemize
14131
14132 @node Internals Documentation
14133 @section Internals Documentation
14134
14135 Better info on how @code{g77} works and how to port it is needed.
14136 Much of this should be done only after the redesign planned for
14137 0.6 is complete.
14138
14139 @xref{Front End}, which contains some information
14140 on @code{g77} internals.
14141
14142 @node Internals Improvements
14143 @section Internals Improvements
14144
14145 Some more items that would make @code{g77} more reliable
14146 and easier to maintain:
14147
14148 @itemize @bullet
14149 @item
14150 Generally make expression handling focus
14151 more on critical syntax stuff, leaving semantics to callers.
14152 For example,
14153 anything a caller can check, semantically, let it do so, rather
14154 than having @file{expr.c} do it.
14155 (Exceptions might include things like
14156 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
14157 it seems
14158 important to preserve the left-to-right-in-source order of production
14159 of diagnostics.)
14160
14161 @item
14162 Come up with better naming conventions for @samp{-D} to establish requirements
14163 to achieve desired implementation dialect via @file{proj.h}.
14164
14165 @item
14166 Clean up used tokens and @code{ffewhere}s in @code{ffeglobal_terminate_1}.
14167
14168 @item
14169 Replace @file{sta.c} @code{outpooldisp} mechanism with @code{malloc_pool_use}.
14170
14171 @item
14172 Check for @code{opANY} in more places in @file{com.c}, @file{std.c},
14173 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
14174 (after determining if there is indeed no real need for it).
14175
14176 @item
14177 Utility to read and check @file{bad.def} messages and their references in the
14178 code, to make sure calls are consistent with message templates.
14179
14180 @item
14181 Search and fix @samp{&ffe@dots{}} and similar so that
14182 @samp{ffe@dots{}ptr@dots{}} macros are
14183 available instead (a good argument for wishing this could have written all
14184 this stuff in C++, perhaps).
14185 On the other hand, it's questionable whether this sort of
14186 improvement is really necessary, given the availability of
14187 tools such as Emacs and Perl, which make finding any
14188 address-taking of structure members easy enough?
14189
14190 @item
14191 Some modules truly export the member names of their structures (and the
14192 structures themselves), maybe fix this, and fix other modules that just
14193 appear to as well (by appending @samp{_}, though it'd be ugly and probably
14194 not worth the time).
14195
14196 @item
14197 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
14198 in @file{proj.h}
14199 and use them throughout @code{g77} source code (especially in the definitions
14200 of access macros in @samp{.h} files) so they can be tailored
14201 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
14202
14203 @item
14204 Decorate throughout with @code{const} and other such stuff.
14205
14206 @item
14207 All F90 notational derivations in the source code are still based
14208 on the S8.112 version of the draft standard.
14209 Probably should update
14210 to the official standard, or put documentation of the rules as used
14211 in the code@dots{}uh@dots{}in the code.
14212
14213 @item
14214 Some @code{ffebld_new} calls (those outside of @file{ffeexpr.c} or
14215 inside but invoked via paths not involving @code{ffeexpr_lhs} or
14216 @code{ffeexpr_rhs}) might be creating things
14217 in improper pools, leading to such things staying around too long or
14218 (doubtful, but possible and dangerous) not long enough.
14219
14220 @item
14221 Some @code{ffebld_list_new} (or whatever) calls might not be matched by
14222 @code{ffebld_list_bottom} (or whatever) calls, which might someday matter.
14223 (It definitely is not a problem just yet.)
14224
14225 @item
14226 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
14227 due to alignment/mismatch or other problems---they end up without
14228 @code{ffestorag} objects, so maybe the backend (and other parts of the front
14229 end) can notice that and handle like an @code{opANY} (do what it wants, just
14230 don't complain or crash).
14231 Most of this seems to have been addressed
14232 by now, but a code review wouldn't hurt.
14233 @end itemize
14234
14235 @node Better Diagnostics
14236 @section Better Diagnostics
14237
14238 These are things users might not ask about, or that need to
14239 be looked into, before worrying about.
14240 Also here are items that involve reducing unnecessary diagnostic
14241 clutter.
14242
14243 @itemize @bullet
14244 @item
14245 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
14246 lengths, type classes, and so on),
14247 @code{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
14248 it specifies.
14249
14250 @item
14251 Speed up and improve error handling for data when repeat-count is
14252 specified.
14253 For example, don't output 20 unnecessary messages after the
14254 first necessary one for:
14255
14256 @smallexample
14257 INTEGER X(20)
14258 CONTINUE
14259 DATA (X(I), J= 1, 20) /20*5/
14260 END
14261 @end smallexample
14262
14263 @noindent
14264 (The @code{CONTINUE} statement ensures the @code{DATA} statement
14265 is processed in the context of executable, not specification,
14266 statements.)
14267 @end itemize
14268
14269 @include ffe.texi
14270
14271 @end ifset
14272
14273 @ifset USING
14274 @node Diagnostics
14275 @chapter Diagnostics
14276 @cindex diagnostics
14277
14278 Some diagnostics produced by @code{g77} require sufficient explanation
14279 that the explanations are given below, and the diagnostics themselves
14280 identify the appropriate explanation.
14281
14282 Identification uses the GNU Info format---specifically, the @code{info}
14283 command that displays the explanation is given within square
14284 brackets in the diagnostic.
14285 For example:
14286
14287 @smallexample
14288 foo.f:5: Invalid statement [info -f g77 M FOOEY]
14289 @end smallexample
14290
14291 More details about the above diagnostic is found in the @code{g77} Info
14292 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
14293 which is displayed by typing the UNIX command
14294 @samp{info -f g77 M FOOEY}.
14295
14296 Other Info readers, such as EMACS, may be just as easily used to display
14297 the pertinent node.
14298 In the above example, @samp{g77} is the Info document name,
14299 @samp{M} is the top-level menu item to select,
14300 and, in that node (named @samp{Diagnostics}, the name of
14301 this chapter, which is the very text you're reading now),
14302 @samp{FOOEY} is the menu item to select.
14303
14304 @iftex
14305 In this printed version of the @code{g77} manual, the above example
14306 points to a section, below, entitled @samp{FOOEY}---though, of course,
14307 as the above is just a sample, no such section exists.
14308 @end iftex
14309
14310 @menu
14311 * CMPAMBIG::    Ambiguous use of intrinsic.
14312 * EXPIMP::      Intrinsic used explicitly and implicitly.
14313 * INTGLOB::     Intrinsic also used as name of global.
14314 * LEX::         Various lexer messages
14315 * GLOBALS::     Disagreements about globals.
14316 * LINKFAIL::    When linking @code{f771} fails.
14317 * Y2KBAD::      Use of non-Y2K-compliant intrinsic.
14318 @end menu
14319
14320 @node CMPAMBIG
14321 @section @code{CMPAMBIG}
14322
14323 @noindent
14324 @smallexample
14325 Ambiguous use of intrinsic @var{intrinsic} @dots{}
14326 @end smallexample
14327
14328 The type of the argument to the invocation of the @var{intrinsic}
14329 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
14330 Typically, it is @code{COMPLEX(KIND=2)}, also known as
14331 @code{DOUBLE COMPLEX}.
14332
14333 The interpretation of this invocation depends on the particular
14334 dialect of Fortran for which the code was written.
14335 Some dialects convert the real part of the argument to
14336 @code{REAL(KIND=1)}, thus losing precision; other dialects,
14337 and Fortran 90, do no such conversion.
14338
14339 So, GNU Fortran rejects such invocations except under certain
14340 circumstances, to avoid making an incorrect assumption that results
14341 in generating the wrong code.
14342
14343 To determine the dialect of the program unit, perhaps even whether
14344 that particular invocation is properly coded, determine how the
14345 result of the intrinsic is used.
14346
14347 The result of @var{intrinsic} is expected (by the original programmer)
14348 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
14349
14350 @itemize @bullet
14351 @item
14352 It is passed as an argument to a procedure that explicitly or
14353 implicitly declares that argument @code{REAL(KIND=1)}.
14354
14355 For example,
14356 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
14357 statement specifying the dummy argument corresponding to an
14358 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14359 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14360 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
14361 of @code{REAL(KIND=2)}.
14362
14363 @item
14364 It is used in a context that would otherwise not include
14365 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
14366 invocation as @code{REAL(KIND=2)} would result in unnecessary
14367 promotions and (typically) more expensive operations on the
14368 wider type.
14369
14370 For example:
14371
14372 @smallexample
14373 DOUBLE COMPLEX Z
14374 @dots{}
14375 R(1) = T * REAL(Z)
14376 @end smallexample
14377
14378 The above example suggests the programmer expected the real part
14379 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
14380 multiplied by @samp{T} (presumed, along with @samp{R} above, to
14381 be type @code{REAL(KIND=1)}).
14382
14383 Otherwise, the conversion would have to be delayed until after
14384 the multiplication, requiring not only an extra conversion
14385 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
14386 expensive multiplication (a double-precision multiplication instead
14387 of a single-precision one).
14388 @end itemize
14389
14390 The result of @var{intrinsic} is expected (by the original programmer)
14391 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
14392
14393 @itemize @bullet
14394 @item
14395 It is passed as an argument to a procedure that explicitly or
14396 implicitly declares that argument @code{REAL(KIND=2)}.
14397
14398 For example, a procedure specifying a @code{DOUBLE PRECISION}
14399 dummy argument corresponding to an
14400 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14401 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14402 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
14403 of @code{REAL(KIND=1)}.
14404
14405 @item
14406 It is used in an expression context that includes
14407 other @code{REAL(KIND=2)} operands,
14408 or is assigned to a @code{REAL(KIND=2)} variable or array element.
14409
14410 For example:
14411
14412 @smallexample
14413 DOUBLE COMPLEX Z
14414 DOUBLE PRECISION R, T
14415 @dots{}
14416 R(1) = T * REAL(Z)
14417 @end smallexample
14418
14419 The above example suggests the programmer expected the real part
14420 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
14421 by the @code{REAL()} intrinsic.
14422
14423 Otherwise, the conversion would have to be immediately followed
14424 by a conversion back to @code{REAL(KIND=2)}, losing
14425 the original, full precision of the real part of @code{Z},
14426 before being multiplied by @samp{T}.
14427 @end itemize
14428
14429 Once you have determined whether a particular invocation of @var{intrinsic}
14430 expects the Fortran 90 interpretation, you can:
14431
14432 @itemize @bullet
14433 @item
14434 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
14435 @code{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
14436 is @code{AIMAG})
14437 if it expected the Fortran 90 interpretation.
14438
14439 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
14440 some other type, such as @code{COMPLEX*32}, you should use the
14441 appropriate intrinsic, such as the one to convert to @code{REAL*16}
14442 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
14443 @code{QIMAG()} in place of @code{DIMAG()}).
14444
14445 @item
14446 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
14447 otherwise.
14448 This converts to @code{REAL(KIND=1)} in all working
14449 Fortran compilers.
14450 @end itemize
14451
14452 If you don't want to change the code, and you are certain that all
14453 ambiguous invocations of @var{intrinsic} in the source file have
14454 the same expectation regarding interpretation, you can:
14455
14456 @itemize @bullet
14457 @item
14458 Compile with the @code{g77} option @samp{-ff90}, to enable the
14459 Fortran 90 interpretation.
14460
14461 @item
14462 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
14463 to enable the non-Fortran-90 interpretations.
14464 @end itemize
14465
14466 @xref{REAL() and AIMAG() of Complex}, for more information on this
14467 issue.
14468
14469 Note: If the above suggestions don't produce enough evidence
14470 as to whether a particular program expects the Fortran 90
14471 interpretation of this ambiguous invocation of @var{intrinsic},
14472 there is one more thing you can try.
14473
14474 If you have access to most or all the compilers used on the
14475 program to create successfully tested and deployed executables,
14476 read the documentation for, and @emph{also} test out, each compiler
14477 to determine how it treats the @var{intrinsic} intrinsic in
14478 this case.
14479 (If all the compilers don't agree on an interpretation, there
14480 might be lurking bugs in the deployed versions of the program.)
14481
14482 The following sample program might help:
14483
14484 @cindex JCB003 program
14485 @smallexample
14486       PROGRAM JCB003
14487 C
14488 C Written by James Craig Burley 1997-02-23.
14489 C
14490 C Determine how compilers handle non-standard REAL
14491 C and AIMAG on DOUBLE COMPLEX operands.
14492 C
14493       DOUBLE COMPLEX Z
14494       REAL R
14495       Z = (3.3D0, 4.4D0)
14496       R = Z
14497       CALL DUMDUM(Z, R)
14498       R = REAL(Z) - R
14499       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
14500       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
14501       R = 4.4D0
14502       CALL DUMDUM(Z, R)
14503       R = AIMAG(Z) - R
14504       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
14505       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
14506       END
14507 C
14508 C Just to make sure compiler doesn't use naive flow
14509 C analysis to optimize away careful work above,
14510 C which might invalidate results....
14511 C
14512       SUBROUTINE DUMDUM(Z, R)
14513       DOUBLE COMPLEX Z
14514       REAL R
14515       END
14516 @end smallexample
14517
14518 If the above program prints contradictory results on a
14519 particular compiler, run away!
14520
14521 @node EXPIMP
14522 @section @code{EXPIMP}
14523
14524 @noindent
14525 @smallexample
14526 Intrinsic @var{intrinsic} referenced @dots{}
14527 @end smallexample
14528
14529 The @var{intrinsic} is explicitly declared in one program
14530 unit in the source file and implicitly used as an intrinsic
14531 in another program unit in the same source file.
14532
14533 This diagnostic is designed to catch cases where a program
14534 might depend on using the name @var{intrinsic} as an intrinsic
14535 in one program unit and as a global name (such as the name
14536 of a subroutine or function) in another, but @code{g77} recognizes
14537 the name as an intrinsic in both cases.
14538
14539 After verifying that the program unit making implicit use
14540 of the intrinsic is indeed written expecting the intrinsic,
14541 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14542 program unit to prevent this warning.
14543
14544 This and related warnings are disabled by using
14545 the @samp{-Wno-globals} option when compiling.
14546
14547 Note that this warning is not issued for standard intrinsics.
14548 Standard intrinsics include those described in the FORTRAN 77
14549 standard and, if @samp{-ff90} is specified, those described
14550 in the Fortran 90 standard.
14551 Such intrinsics are not as likely to be confused with user
14552 procedures as intrinsics provided as extensions to the
14553 standard by @code{g77}.
14554
14555 @node INTGLOB
14556 @section @code{INTGLOB}
14557
14558 @noindent
14559 @smallexample
14560 Same name `@var{intrinsic}' given @dots{}
14561 @end smallexample
14562
14563 The name @var{intrinsic} is used for a global entity (a common
14564 block or a program unit) in one program unit and implicitly
14565 used as an intrinsic in another program unit.
14566
14567 This diagnostic is designed to catch cases where a program
14568 intends to use a name entirely as a global name, but @code{g77}
14569 recognizes the name as an intrinsic in the program unit that
14570 references the name, a situation that would likely produce
14571 incorrect code.
14572
14573 For example:
14574
14575 @smallexample
14576 INTEGER FUNCTION TIME()
14577 @dots{}
14578 END
14579 @dots{}
14580 PROGRAM SAMP
14581 INTEGER TIME
14582 PRINT *, 'Time is ', TIME()
14583 END
14584 @end smallexample
14585
14586 The above example defines a program unit named @samp{TIME}, but
14587 the reference to @samp{TIME} in the main program unit @samp{SAMP}
14588 is normally treated by @code{g77} as a reference to the intrinsic
14589 @code{TIME()} (unless a command-line option that prevents such
14590 treatment has been specified).
14591
14592 As a result, the program @samp{SAMP} will @emph{not}
14593 invoke the @samp{TIME} function in the same source file.
14594
14595 Since @code{g77} recognizes @code{libU77} procedures as
14596 intrinsics, and since some existing code uses the same names
14597 for its own procedures as used by some @code{libU77}
14598 procedures, this situation is expected to arise often enough
14599 to make this sort of warning worth issuing.
14600
14601 After verifying that the program unit making implicit use
14602 of the intrinsic is indeed written expecting the intrinsic,
14603 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14604 program unit to prevent this warning.
14605
14606 Or, if you believe the program unit is designed to invoke the
14607 program-defined procedure instead of the intrinsic (as
14608 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
14609 statement to the program unit that references the name to
14610 prevent this warning.
14611
14612 This and related warnings are disabled by using
14613 the @samp{-Wno-globals} option when compiling.
14614
14615 Note that this warning is not issued for standard intrinsics.
14616 Standard intrinsics include those described in the FORTRAN 77
14617 standard and, if @samp{-ff90} is specified, those described
14618 in the Fortran 90 standard.
14619 Such intrinsics are not as likely to be confused with user
14620 procedures as intrinsics provided as extensions to the
14621 standard by @code{g77}.
14622
14623 @node LEX
14624 @section @code{LEX}
14625
14626 @noindent
14627 @smallexample
14628 Unrecognized character @dots{}
14629 Invalid first character @dots{}
14630 Line too long @dots{}
14631 Non-numeric character @dots{}
14632 Continuation indicator @dots{}
14633 Label at @dots{} invalid with continuation line indicator @dots{}
14634 Character constant @dots{}
14635 Continuation line @dots{}
14636 Statement at @dots{} begins with invalid token
14637 @end smallexample
14638
14639 Although the diagnostics identify specific problems, they can
14640 be produced when general problems such as the following occur:
14641
14642 @itemize @bullet
14643 @item
14644 The source file contains something other than Fortran code.
14645
14646 If the code in the file does not look like many of the examples
14647 elsewhere in this document, it might not be Fortran code.
14648 (Note that Fortran code often is written in lower case letters,
14649 while the examples in this document use upper case letters,
14650 for stylistic reasons.)
14651
14652 For example, if the file contains lots of strange-looking
14653 characters, it might be APL source code; if it contains lots
14654 of parentheses, it might be Lisp source code; if it
14655 contains lots of bugs, it might be C++ source code.
14656
14657 @item
14658 The source file contains free-form Fortran code, but @samp{-ffree-form}
14659 was not specified on the command line to compile it.
14660
14661 Free form is a newer form for Fortran code.
14662 The older, classic form is called fixed form.
14663
14664 @cindex continuation character
14665 @cindex characters, continuation
14666 Fixed-form code is visually fairly distinctive, because
14667 numerical labels and comments are all that appear in
14668 the first five columns of a line, the sixth column is
14669 reserved to denote continuation lines,
14670 and actual statements start at or beyond column 7.
14671 Spaces generally are not significant, so if you
14672 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
14673 you are looking at fixed-form code.
14674 @cindex *
14675 @cindex asterisk
14676 Comment lines are indicated by the letter @samp{C} or the symbol
14677 @samp{*} in column 1.
14678 @cindex trailing comment
14679 @cindex comment
14680 @cindex characters, comment
14681 @cindex !
14682 @cindex exclamation point
14683 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
14684 which many compilers support.)
14685
14686 Free-form code is distinguished from fixed-form source
14687 primarily by the fact that statements may start anywhere.
14688 (If lots of statements start in columns 1 through 6,
14689 that's a strong indicator of free-form source.)
14690 Consecutive keywords must be separated by spaces, so
14691 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
14692 There are no comment lines per se, but @samp{!} starts a
14693 comment anywhere in a line (other than within a character or
14694 Hollerith constant).
14695
14696 @xref{Source Form}, for more information.
14697
14698 @item
14699 The source file is in fixed form and has been edited without
14700 sensitivity to the column requirements.
14701
14702 Statements in fixed-form code must be entirely contained within
14703 columns 7 through 72 on a given line.
14704 Starting them ``early'' is more likely to result in diagnostics
14705 than finishing them ``late'', though both kinds of errors are
14706 often caught at compile time.
14707
14708 For example, if the following code fragment is edited by following
14709 the commented instructions literally, the result, shown afterward,
14710 would produce a diagnostic when compiled:
14711
14712 @smallexample
14713 C On XYZZY systems, remove "C" on next line:
14714 C     CALL XYZZY_RESET
14715 @end smallexample
14716
14717 The result of editing the above line might be:
14718
14719 @smallexample
14720 C On XYZZY systems, remove "C" on next line:
14721      CALL XYZZY_RESET
14722 @end smallexample
14723
14724 However, that leaves the first @samp{C} in the @code{CALL}
14725 statement in column 6, making it a comment line, which is
14726 not really what the author intended, and which is likely
14727 to result in one of the above-listed diagnostics.
14728
14729 @emph{Replacing} the @samp{C} in column 1 with a space
14730 is the proper change to make, to ensure the @code{CALL}
14731 keyword starts in or after column 7.
14732
14733 Another common mistake like this is to forget that fixed-form
14734 source lines are significant through only column 72, and that,
14735 normally, any text beyond column 72 is ignored or is diagnosed
14736 at compile time.
14737
14738 @xref{Source Form}, for more information.
14739
14740 @item
14741 The source file requires preprocessing, and the preprocessing
14742 is not being specified at compile time.
14743
14744 A source file containing lines beginning with @code{#define},
14745 @code{#include}, @code{#if}, and so on is likely one that
14746 requires preprocessing.
14747
14748 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
14749 the file normally will be compiled @emph{without} preprocessing
14750 by @code{g77}.
14751
14752 Change the file's suffix from @samp{.f} to @samp{.F}
14753 (or, on systems with case-insensitive file names,
14754 to @samp{.fpp} or @samp{.FPP}),
14755 from @samp{.for} to @samp{.fpp},
14756 or from @samp{.FOR} to @samp{.FPP}.
14757 @code{g77} compiles files with such names @emph{with}
14758 preprocessing.
14759
14760 @pindex cpp
14761 @cindex preprocessor
14762 @cindex cpp program
14763 @cindex programs, cpp
14764 @cindex @samp{-x f77-cpp-input} option
14765 @cindex options, @samp{-x f77-cpp-input}
14766 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
14767 the language @samp{f77-cpp-input} for Fortran files that
14768 require preprocessing.
14769 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
14770
14771 @item
14772 The source file is preprocessed, and the results of preprocessing
14773 result in syntactic errors that are not necessarily obvious to
14774 someone examining the source file itself.
14775
14776 Examples of errors resulting from preprocessor macro expansion
14777 include exceeding the line-length limit, improperly starting,
14778 terminating, or incorporating the apostrophe or double-quote in
14779 a character constant, improperly forming a Hollerith constant,
14780 and so on.
14781
14782 @xref{Overall Options,,Options Controlling the Kind of Output},
14783 for suggestions about how to use, and not use, preprocessing
14784 for Fortran code.
14785 @end itemize
14786
14787 @node GLOBALS
14788 @section @code{GLOBALS}
14789
14790 @noindent
14791 @smallexample
14792 Global name @var{name} defined at @dots{} already defined@dots{}
14793 Global name @var{name} at @dots{} has different type@dots{}
14794 Too many arguments passed to @var{name} at @dots{}
14795 Too few arguments passed to @var{name} at @dots{}
14796 Argument #@var{n} of @var{name} is @dots{}
14797 @end smallexample
14798
14799 These messages all identify disagreements about the
14800 global procedure named @var{name} among different program units
14801 (usually including @var{name} itself).
14802
14803 Whether a particular disagreement is reported
14804 as a warning or an error
14805 can depend on the relative order
14806 of the disagreeing portions of the source file.
14807
14808 Disagreements between a procedure invocation
14809 and the @emph{subsequent} procedure itself
14810 are, usually, diagnosed as errors
14811 when the procedure itself @emph{precedes} the invocation.
14812 Other disagreements are diagnosed via warnings.
14813
14814 @cindex forward references
14815 @cindex in-line code
14816 @cindex compilation, in-line
14817 This distinction, between warnings and errors,
14818 is due primarily to the present tendency of the @code{gcc} back end
14819 to inline only those procedure invocations that are
14820 @emph{preceded} by the corresponding procedure definitions.
14821 If the @code{gcc} back end is changed
14822 to inline ``forward references'',
14823 in which invocations precede definitions,
14824 the @code{g77} front end will be changed
14825 to treat both orderings as errors, accordingly.
14826
14827 The sorts of disagreements that are diagnosed by @code{g77} include
14828 whether a procedure is a subroutine or function;
14829 if it is a function, the type of the return value of the procedure;
14830 the number of arguments the procedure accepts;
14831 and the type of each argument.
14832
14833 Disagreements regarding global names among program units
14834 in a Fortran program @emph{should} be fixed in the code itself.
14835 However, if that is not immediately practical,
14836 and the code has been working for some time,
14837 it is possible it will work
14838 when compiled with the @samp{-fno-globals} option.
14839
14840 The @samp{-fno-globals} option
14841 causes these diagnostics to all be warnings
14842 and disables all inlining of references to global procedures
14843 (to avoid subsequent compiler crashes and bad-code generation).
14844 Use of the @samp{-Wno-globals} option as well as @samp{-fno-globals}
14845 suppresses all of these diagnostics.
14846 (@samp{-Wno-globals} by itself disables only the warnings,
14847 not the errors.)
14848
14849 After using @samp{-fno-globals} to work around these problems,
14850 it is wise to stop using that option and address them by fixing
14851 the Fortran code, because such problems, while they might not
14852 actually result in bugs on some systems, indicate that the code
14853 is not as portable as it could be.
14854 In particular, the code might appear to work on a particular
14855 system, but have bugs that affect the reliability of the data
14856 without exhibiting any other outward manifestations of the bugs.
14857
14858 @node LINKFAIL
14859 @section @code{LINKFAIL}
14860
14861 @noindent
14862 @smallexample
14863 If the above command failed due to an unresolved reference
14864 to strtoul, _strtoul, bsearch, _bsearch, or similar, see
14865 [info -f g77 M LINKFAIL] (a node in the g77 documentation)
14866 for information on what causes this, how to work around
14867 the problem by editing $@{srcdir@}/proj.c, and what else to do.
14868 @end smallexample
14869
14870 @xref{Missing strtoul or bsearch}, for more information on
14871 this problem,
14872 which occurs only in releases of @code{g77}
14873 based on @code{gcc}.
14874 (It did not occur in @code{egcs}.)
14875
14876 On AIX 4.1, @code{g77} might not build with the native (non-GNU) tools
14877 due to a linker bug in coping with the @samp{-bbigtoc} option which
14878 leads to a @samp{Relocation overflow} error.  The GNU linker is not
14879 recommended on current AIX versions, though; it was developed under a
14880 now-unsupported version.  This bug is said to be fixed by `update PTF
14881 U455193 for APAR IX75823'.
14882
14883 Compiling with @samp{-mminimal-toc}
14884 might solve this problem, e.g.@: by adding
14885 @smallexample
14886 BOOT_CFLAGS='-mminimal-toc -O2 -g'
14887 @end smallexample
14888 to the @code{make bootstrap} command line.
14889
14890 @node Y2KBAD
14891 @section @code{Y2KBAD}
14892 @cindex Y2K compliance
14893 @cindex Year 2000 compliance
14894
14895 @noindent
14896 @smallexample
14897 Intrinsic `@var{name}', invoked at (^), known to be non-Y2K-compliant@dots{}
14898 @end smallexample
14899
14900 This diagnostic indicates that
14901 the specific intrinsic invoked by the name @var{name}
14902 is known to have an interface
14903 that is not Year-2000 (Y2K) compliant.
14904
14905 @xref{Year 2000 (Y2K) Problems}.
14906
14907 @end ifset
14908
14909 @node Index
14910 @unnumbered Index
14911
14912 @printindex cp
14913 @bye