OSDN Git Service

* g77.texi: Update links.
[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 1999-06-06
6 @set copyrights-g77 1995-1999
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 Permission is granted to make and distribute verbatim copies of
101 this manual provided the copyright notice and this permission notice
102 are preserved on all copies.
103
104 @ignore
105 Permission is granted to process this file through Tex and print the
106 results, provided the printed document carries copying permission
107 notice identical to this one except for the removal of this paragraph
108 (this paragraph not being relevant to the printed manual).
109
110 @end ignore
111 Permission is granted to copy and distribute modified versions of this
112 manual under the conditions for verbatim copying, provided also that the
113 sections entitled ``GNU General Public License,'' ``Funding for Free
114 Software,'' and ``Protect Your Freedom---Fight `Look And Feel'@w{}'' are
115 included exactly as in the original, and provided that the entire
116 resulting derived work is distributed under the terms of a permission
117 notice identical to this one.
118
119 Permission is granted to copy and distribute translations of this manual
120 into another language, under the above conditions for modified versions,
121 except that the sections entitled ``GNU General Public License,''
122 ``Funding for Free Software,'' and ``Protect Your Freedom---Fight `Look
123 And Feel'@w{}'', and this permission notice, may be included in
124 translations approved by the Free Software Foundation instead of in the
125 original English.
126 @end ifinfo
127
128 Contributed by James Craig Burley (@email{@value{email-burley}}).
129 Inspired by a first pass at translating @file{g77-0.5.16/f/DOC} that
130 was contributed to Craig by David Ronis (@email{ronis@@onsager.chem.mcgill.ca}).
131
132 @setchapternewpage odd
133 @c @finalout
134 @titlepage
135 @ifset INTERNALS
136 @ifset USING
137 @center @titlefont{Using and Porting GNU Fortran}
138
139 @end ifset
140 @end ifset
141 @ifclear INTERNALS
142 @title Using GNU Fortran
143 @end ifclear
144 @ifclear USING
145 @title Porting GNU Fortran
146 @end ifclear
147 @sp 2
148 @center James Craig Burley
149 @sp 3
150 @center Last updated @value{last-update}
151 @sp 1
152 @center for version @value{version-g77}
153 @page
154 @vskip 0pt plus 1filll
155 Copyright @copyright{} @value{copyrights-g77} Free Software Foundation, Inc.
156 @sp 2
157 For the @value{which-g77} Version*
158 @sp 1
159 Published by the Free Software Foundation @*
160 59 Temple Place - Suite 330@*
161 Boston, MA 02111-1307, USA@*
162 @c Last printed ??ber, 19??.@*
163 @c Printed copies are available for $? each.@*
164 @c ISBN ???
165 @sp 1
166 Permission is granted to make and distribute verbatim copies of
167 this manual provided the copyright notice and this permission notice
168 are preserved on all copies.
169
170 Permission is granted to copy and distribute modified versions of this
171 manual under the conditions for verbatim copying, provided also that the
172 sections entitled ``GNU General Public License,'' ``Funding for Free
173 Software,'' and ``Protect Your Freedom---Fight `Look And Feel'@w{}'' are
174 included exactly as in the original, and provided that the entire
175 resulting derived work is distributed under the terms of a permission
176 notice identical to this one.
177
178 Permission is granted to copy and distribute translations of this manual
179 into another language, under the above conditions for modified versions,
180 except that the sections entitled ``GNU General Public License,''
181 ``Funding for Free Software,'' and ``Protect Your Freedom---Fight `Look
182 And Feel'@w{}'', and this permission notice, may be included in
183 translations approved by the Free Software Foundation instead of in the
184 original English.
185 @end titlepage
186 @page
187
188 @ifinfo
189
190 @node Top, Copying,, (DIR)
191 @top Introduction
192 @cindex Introduction
193
194 @ifset INTERNALS
195 @ifset USING
196 This manual documents how to run, install and port @code{g77},
197 as well as its new features and incompatibilities,
198 and how to report bugs.
199 It corresponds to the @value{which-g77} version of @code{g77}.
200 @end ifset
201 @end ifset
202
203 @ifclear INTERNALS
204 This manual documents how to run and install @code{g77},
205 as well as its new features and incompatibilities, and how to report
206 bugs.
207 It corresponds to the @value{which-g77} version of @code{g77}.
208 @end ifclear
209 @ifclear USING
210 This manual documents how to port @code{g77},
211 as well as its new features and incompatibilities,
212 and how to report bugs.
213 It corresponds to the @value{which-g77} version of @code{g77}.
214 @end ifclear
215
216 @end ifinfo
217
218 @ifset DEVELOPMENT
219 @emph{Warning:} This document is still under development,
220 and might not accurately reflect the @code{g77} code base
221 of which it is a part.
222 Efforts are made to keep it somewhat up-to-date,
223 but they are particularly concentrated
224 on any version of this information
225 that is distributed as part of a @emph{released} @code{g77}.
226
227 In particular, while this document is intended to apply to
228 the @value{which-g77} version of @code{g77},
229 only an official @emph{release} of that version
230 is expected to contain documentation that is
231 most consistent with the @code{g77} product in that version.
232 @end ifset
233
234 @menu
235 * Copying::         GNU General Public License says
236                     how you can copy and share GNU Fortran.
237 * Contributors::    People who have contributed to GNU Fortran.
238 * Funding::         How to help assure continued work for free software.
239 * Funding GNU Fortran::  How to help assure continued work on GNU Fortran.
240 * Look and Feel::   Protect your freedom---fight ``look and feel''.
241 @ifset USING
242 * Getting Started:: Finding your way around this manual.
243 * What is GNU Fortran?::  How @code{g77} fits into the universe.
244 * G77 and GCC::     You can compile Fortran, C, or other programs.
245 * Invoking G77::    Command options supported by @code{g77}.
246 * News::            News about recent releases of @code{g77}.
247 * Changes::         User-visible changes to recent releases of @code{g77}.
248 * Language::        The GNU Fortran language.
249 * Compiler::        The GNU Fortran compiler.
250 * Other Dialects::  Dialects of Fortran supported by @code{g77}.
251 * Other Compilers:: Fortran compilers other than @code{g77}.
252 * Other Languages:: Languages other than Fortran.
253 * Installation::    How to configure, compile and install GNU Fortran.
254 * Debugging and Interfacing::  How @code{g77} generates code.
255 * Collected Fortran Wisdom::  How to avoid Trouble.
256 * Trouble::         If you have trouble with GNU Fortran.
257 * Open Questions::  Things we'd like to know.
258 * Bugs::            How, why, and where to report bugs.
259 * Service::         How to find suppliers of support for GNU Fortran.
260 @end ifset
261 @ifset INTERNALS
262 * Adding Options::  Guidance on teaching @code{g77} about new options.
263 * Projects::        Projects for @code{g77} internals hackers.
264 * Front End::       Design and implementation of the @code{g77} front end.
265 @end ifset
266
267 * M: Diagnostics.   Diagnostics produced by @code{g77}.
268
269 * Index::           Index of concepts and symbol names.
270 @end menu
271 @c yes, the "M: " @emph{is} intentional -- bad.def references it (CMPAMBIG)!
272
273 @node Copying
274 @unnumbered GNU GENERAL PUBLIC LICENSE
275 @center Version 2, June 1991
276
277 @display
278 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
279 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
280
281 Everyone is permitted to copy and distribute verbatim copies
282 of this license document, but changing it is not allowed.
283 @end display
284
285 @unnumberedsec Preamble
286
287   The licenses for most software are designed to take away your
288 freedom to share and change it.  By contrast, the GNU General Public
289 License is intended to guarantee your freedom to share and change free
290 software---to make sure the software is free for all its users.  This
291 General Public License applies to most of the Free Software
292 Foundation's software and to any other program whose authors commit to
293 using it.  (Some other Free Software Foundation software is covered by
294 the GNU Library General Public License instead.)  You can apply it to
295 your programs, too.
296
297   When we speak of free software, we are referring to freedom, not
298 price.  Our General Public Licenses are designed to make sure that you
299 have the freedom to distribute copies of free software (and charge for
300 this service if you wish), that you receive source code or can get it
301 if you want it, that you can change the software or use pieces of it
302 in new free programs; and that you know you can do these things.
303
304   To protect your rights, we need to make restrictions that forbid
305 anyone to deny you these rights or to ask you to surrender the rights.
306 These restrictions translate to certain responsibilities for you if you
307 distribute copies of the software, or if you modify it.
308
309   For example, if you distribute copies of such a program, whether
310 gratis or for a fee, you must give the recipients all the rights that
311 you have.  You must make sure that they, too, receive or can get the
312 source code.  And you must show them these terms so they know their
313 rights.
314
315   We protect your rights with two steps: (1) copyright the software, and
316 (2) offer you this license which gives you legal permission to copy,
317 distribute and/or modify the software.
318
319   Also, for each author's protection and ours, we want to make certain
320 that everyone understands that there is no warranty for this free
321 software.  If the software is modified by someone else and passed on, we
322 want its recipients to know that what they have is not the original, so
323 that any problems introduced by others will not reflect on the original
324 authors' reputations.
325
326   Finally, any free program is threatened constantly by software
327 patents.  We wish to avoid the danger that redistributors of a free
328 program will individually obtain patent licenses, in effect making the
329 program proprietary.  To prevent this, we have made it clear that any
330 patent must be licensed for everyone's free use or not licensed at all.
331
332   The precise terms and conditions for copying, distribution and
333 modification follow.
334
335 @iftex
336 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
337 @end iftex
338 @ifinfo
339 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
340 @end ifinfo
341
342 @enumerate 0
343 @item
344 This License applies to any program or other work which contains
345 a notice placed by the copyright holder saying it may be distributed
346 under the terms of this General Public License.  The ``Program'', below,
347 refers to any such program or work, and a ``work based on the Program''
348 means either the Program or any derivative work under copyright law:
349 that is to say, a work containing the Program or a portion of it,
350 either verbatim or with modifications and/or translated into another
351 language.  (Hereinafter, translation is included without limitation in
352 the term ``modification''.)  Each licensee is addressed as ``you''.
353
354 Activities other than copying, distribution and modification are not
355 covered by this License; they are outside its scope.  The act of
356 running the Program is not restricted, and the output from the Program
357 is covered only if its contents constitute a work based on the
358 Program (independent of having been made by running the Program).
359 Whether that is true depends on what the Program does.
360
361 @item
362 You may copy and distribute verbatim copies of the Program's
363 source code as you receive it, in any medium, provided that you
364 conspicuously and appropriately publish on each copy an appropriate
365 copyright notice and disclaimer of warranty; keep intact all the
366 notices that refer to this License and to the absence of any warranty;
367 and give any other recipients of the Program a copy of this License
368 along with the Program.
369
370 You may charge a fee for the physical act of transferring a copy, and
371 you may at your option offer warranty protection in exchange for a fee.
372
373 @item
374 You may modify your copy or copies of the Program or any portion
375 of it, thus forming a work based on the Program, and copy and
376 distribute such modifications or work under the terms of Section 1
377 above, provided that you also meet all of these conditions:
378
379 @enumerate a
380 @item
381 You must cause the modified files to carry prominent notices
382 stating that you changed the files and the date of any change.
383
384 @item
385 You must cause any work that you distribute or publish, that in
386 whole or in part contains or is derived from the Program or any
387 part thereof, to be licensed as a whole at no charge to all third
388 parties under the terms of this License.
389
390 @item
391 If the modified program normally reads commands interactively
392 when run, you must cause it, when started running for such
393 interactive use in the most ordinary way, to print or display an
394 announcement including an appropriate copyright notice and a
395 notice that there is no warranty (or else, saying that you provide
396 a warranty) and that users may redistribute the program under
397 these conditions, and telling the user how to view a copy of this
398 License.  (Exception: if the Program itself is interactive but
399 does not normally print such an announcement, your work based on
400 the Program is not required to print an announcement.)
401 @end enumerate
402
403 These requirements apply to the modified work as a whole.  If
404 identifiable sections of that work are not derived from the Program,
405 and can be reasonably considered independent and separate works in
406 themselves, then this License, and its terms, do not apply to those
407 sections when you distribute them as separate works.  But when you
408 distribute the same sections as part of a whole which is a work based
409 on the Program, the distribution of the whole must be on the terms of
410 this License, whose permissions for other licensees extend to the
411 entire whole, and thus to each and every part regardless of who wrote it.
412
413 Thus, it is not the intent of this section to claim rights or contest
414 your rights to work written entirely by you; rather, the intent is to
415 exercise the right to control the distribution of derivative or
416 collective works based on the Program.
417
418 In addition, mere aggregation of another work not based on the Program
419 with the Program (or with a work based on the Program) on a volume of
420 a storage or distribution medium does not bring the other work under
421 the scope of this License.
422
423 @item
424 You may copy and distribute the Program (or a work based on it,
425 under Section 2) in object code or executable form under the terms of
426 Sections 1 and 2 above provided that you also do one of the following:
427
428 @enumerate a
429 @item
430 Accompany it with the complete corresponding machine-readable
431 source code, which must be distributed under the terms of Sections
432 1 and 2 above on a medium customarily used for software interchange; or,
433
434 @item
435 Accompany it with a written offer, valid for at least three
436 years, to give any third party, for a charge no more than your
437 cost of physically performing source distribution, a complete
438 machine-readable copy of the corresponding source code, to be
439 distributed under the terms of Sections 1 and 2 above on a medium
440 customarily used for software interchange; or,
441
442 @item
443 Accompany it with the information you received as to the offer
444 to distribute corresponding source code.  (This alternative is
445 allowed only for noncommercial distribution and only if you
446 received the program in object code or executable form with such
447 an offer, in accord with Subsection b above.)
448 @end enumerate
449
450 The source code for a work means the preferred form of the work for
451 making modifications to it.  For an executable work, complete source
452 code means all the source code for all modules it contains, plus any
453 associated interface definition files, plus the scripts used to
454 control compilation and installation of the executable.  However, as a
455 special exception, the source code distributed need not include
456 anything that is normally distributed (in either source or binary
457 form) with the major components (compiler, kernel, and so on) of the
458 operating system on which the executable runs, unless that component
459 itself accompanies the executable.
460
461 If distribution of executable or object code is made by offering
462 access to copy from a designated place, then offering equivalent
463 access to copy the source code from the same place counts as
464 distribution of the source code, even though third parties are not
465 compelled to copy the source along with the object code.
466
467 @item
468 You may not copy, modify, sublicense, or distribute the Program
469 except as expressly provided under this License.  Any attempt
470 otherwise to copy, modify, sublicense or distribute the Program is
471 void, and will automatically terminate your rights under this License.
472 However, parties who have received copies, or rights, from you under
473 this License will not have their licenses terminated so long as such
474 parties remain in full compliance.
475
476 @item
477 You are not required to accept this License, since you have not
478 signed it.  However, nothing else grants you permission to modify or
479 distribute the Program or its derivative works.  These actions are
480 prohibited by law if you do not accept this License.  Therefore, by
481 modifying or distributing the Program (or any work based on the
482 Program), you indicate your acceptance of this License to do so, and
483 all its terms and conditions for copying, distributing or modifying
484 the Program or works based on it.
485
486 @item
487 Each time you redistribute the Program (or any work based on the
488 Program), the recipient automatically receives a license from the
489 original licensor to copy, distribute or modify the Program subject to
490 these terms and conditions.  You may not impose any further
491 restrictions on the recipients' exercise of the rights granted herein.
492 You are not responsible for enforcing compliance by third parties to
493 this License.
494
495 @item
496 If, as a consequence of a court judgment or allegation of patent
497 infringement or for any other reason (not limited to patent issues),
498 conditions are imposed on you (whether by court order, agreement or
499 otherwise) that contradict the conditions of this License, they do not
500 excuse you from the conditions of this License.  If you cannot
501 distribute so as to satisfy simultaneously your obligations under this
502 License and any other pertinent obligations, then as a consequence you
503 may not distribute the Program at all.  For example, if a patent
504 license would not permit royalty-free redistribution of the Program by
505 all those who receive copies directly or indirectly through you, then
506 the only way you could satisfy both it and this License would be to
507 refrain entirely from distribution of the Program.
508
509 If any portion of this section is held invalid or unenforceable under
510 any particular circumstance, the balance of the section is intended to
511 apply and the section as a whole is intended to apply in other
512 circumstances.
513
514 It is not the purpose of this section to induce you to infringe any
515 patents or other property right claims or to contest validity of any
516 such claims; this section has the sole purpose of protecting the
517 integrity of the free software distribution system, which is
518 implemented by public license practices.  Many people have made
519 generous contributions to the wide range of software distributed
520 through that system in reliance on consistent application of that
521 system; it is up to the author/donor to decide if he or she is willing
522 to distribute software through any other system and a licensee cannot
523 impose that choice.
524
525 This section is intended to make thoroughly clear what is believed to
526 be a consequence of the rest of this License.
527
528 @item
529 If the distribution and/or use of the Program is restricted in
530 certain countries either by patents or by copyrighted interfaces, the
531 original copyright holder who places the Program under this License
532 may add an explicit geographical distribution limitation excluding
533 those countries, so that distribution is permitted only in or among
534 countries not thus excluded.  In such case, this License incorporates
535 the limitation as if written in the body of this License.
536
537 @item
538 The Free Software Foundation may publish revised and/or new versions
539 of the General Public License from time to time.  Such new versions will
540 be similar in spirit to the present version, but may differ in detail to
541 address new problems or concerns.
542
543 Each version is given a distinguishing version number.  If the Program
544 specifies a version number of this License which applies to it and ``any
545 later version'', you have the option of following the terms and conditions
546 either of that version or of any later version published by the Free
547 Software Foundation.  If the Program does not specify a version number of
548 this License, you may choose any version ever published by the Free Software
549 Foundation.
550
551 @item
552 If you wish to incorporate parts of the Program into other free
553 programs whose distribution conditions are different, write to the author
554 to ask for permission.  For software which is copyrighted by the Free
555 Software Foundation, write to the Free Software Foundation; we sometimes
556 make exceptions for this.  Our decision will be guided by the two goals
557 of preserving the free status of all derivatives of our free software and
558 of promoting the sharing and reuse of software generally.
559
560 @iftex
561 @heading NO WARRANTY
562 @end iftex
563 @ifinfo
564 @center NO WARRANTY
565 @end ifinfo
566
567 @item
568 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
569 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
570 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
571 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
572 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
573 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
574 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
575 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
576 REPAIR OR CORRECTION.
577
578 @item
579 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
580 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
581 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
582 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
583 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
584 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
585 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
586 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
587 POSSIBILITY OF SUCH DAMAGES.
588 @end enumerate
589
590 @iftex
591 @heading END OF TERMS AND CONDITIONS
592 @end iftex
593 @ifinfo
594 @center END OF TERMS AND CONDITIONS
595 @end ifinfo
596
597 @page
598 @unnumberedsec How to Apply These Terms to Your New Programs
599
600   If you develop a new program, and you want it to be of the greatest
601 possible use to the public, the best way to achieve this is to make it
602 free software which everyone can redistribute and change under these terms.
603
604   To do so, attach the following notices to the program.  It is safest
605 to attach them to the start of each source file to most effectively
606 convey the exclusion of warranty; and each file should have at least
607 the ``copyright'' line and a pointer to where the full notice is found.
608
609 @smallexample
610 @var{one line to give the program's name and a brief idea of what it does.}
611 Copyright (C) 19@var{yy}  @var{name of author}
612
613 This program is free software; you can redistribute it and/or modify
614 it under the terms of the GNU General Public License as published by
615 the Free Software Foundation; either version 2 of the License, or
616 (at your option) any later version.
617
618 This program is distributed in the hope that it will be useful,
619 but WITHOUT ANY WARRANTY; without even the implied warranty of
620 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
621 GNU General Public License for more details.
622
623 You should have received a copy of the GNU General Public License
624 along with this program; if not, write to the Free Software
625 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
626 @end smallexample
627
628 Also add information on how to contact you by electronic and paper mail.
629
630 If the program is interactive, make it output a short notice like this
631 when it starts in an interactive mode:
632
633 @smallexample
634 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
635 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
636 type `show w'.
637 This is free software, and you are welcome to redistribute it
638 under certain conditions; type `show c' for details.
639 @end smallexample
640
641 The hypothetical commands @samp{show w} and @samp{show c} should show
642 the appropriate parts of the General Public License.  Of course, the
643 commands you use may be called something other than @samp{show w} and
644 @samp{show c}; they could even be mouse-clicks or menu items---whatever
645 suits your program.
646
647 You should also get your employer (if you work as a programmer) or your
648 school, if any, to sign a ``copyright disclaimer'' for the program, if
649 necessary.  Here is a sample; alter the names:
650
651 @smallexample
652 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
653 `Gnomovision' (which makes passes at compilers) written by James Hacker.
654
655 @var{signature of Ty Coon}, 1 April 1989
656 Ty Coon, President of Vice
657 @end smallexample
658
659 This General Public License does not permit incorporating your program into
660 proprietary programs.  If your program is a subroutine library, you may
661 consider it more useful to permit linking proprietary applications with the
662 library.  If this is what you want to do, use the GNU Library General
663 Public License instead of this License.
664
665 @node Contributors
666 @unnumbered Contributors to GNU Fortran
667 @cindex contributors
668 @cindex credits
669
670 In addition to James Craig Burley, who wrote the front end,
671 many people have helped create and improve GNU Fortran.
672
673 @itemize @bullet
674 @item
675 The packaging and compiler portions of GNU Fortran are based largely
676 on the GNU CC compiler.
677 @xref{Contributors,,Contributors to GNU CC,gcc,Using and Porting GNU CC},
678 for more information.
679
680 @item
681 The run-time library used by GNU Fortran is a repackaged version
682 of the @code{libf2c} library (combined from the @code{libF77} and
683 @code{libI77} libraries) provided as part of @code{f2c}, available for
684 free from @code{netlib} sites on the Internet.
685
686 @item
687 Cygnus Support and The Free Software Foundation contributed
688 significant money and/or equipment to Craig's efforts.
689
690 @item
691 The following individuals served as alpha testers prior to @code{g77}'s
692 public release.  This work consisted of testing, researching, sometimes
693 debugging, and occasionally providing small amounts of code and fixes
694 for @code{g77}, plus offering plenty of helpful advice to Craig:
695
696 @itemize @w{}
697 @item
698 Jonathan Corbet
699 @item
700 Dr.@: Mark Fernyhough
701 @item
702 Takafumi Hayashi (The University of Aizu)---@email{takafumi@@u-aizu.ac.jp}
703 @item
704 Kate Hedstrom
705 @item
706 Michel Kern (INRIA and Rice University)---@email{Michel.Kern@@inria.fr}
707 @item
708 Dr.@: A. O. V. Le Blanc
709 @item
710 Dave Love
711 @item
712 Rick Lutowski
713 @item
714 Toon Moene
715 @item
716 Rick Niles
717 @item
718 Derk Reefman
719 @item
720 Wayne K. Schroll
721 @item
722 Bill Thorson
723 @item
724 Pedro A. M. Vazquez
725 @item
726 Ian Watson
727 @end itemize
728
729 @item
730 Scott Snyder (@email{snyder@@d0sgif.fnal.gov})
731 provided the patch to add rudimentary support
732 for @code{INTEGER*1}, @code{INTEGER*2}, and
733 @code{LOGICAL*1}.
734 This inspired Craig to add further support,
735 even though the resulting support
736 would still be incomplete, because version 0.6 is still
737 a ways off.
738
739 @item
740 David Ronis (@email{ronis@@onsager.chem.mcgill.ca}) inspired
741 and encouraged Craig to rewrite the documentation in texinfo
742 format by contributing a first pass at a translation of the
743 old @file{g77-0.5.16/f/DOC} file.
744
745 @item
746 Toon Moene (@email{toon@@moene.indiv.nluug.nl}) performed
747 some analysis of generated code as part of an overall project
748 to improve @code{g77} code generation to at least be as good
749 as @code{f2c} used in conjunction with @code{gcc}.
750 So far, this has resulted in the three, somewhat
751 experimental, options added by @code{g77} to the @code{gcc}
752 compiler and its back end.
753
754 (These, in turn, have made their way into the @code{egcs}
755 version of the compiler, and do not exist in @code{gcc}
756 version 2.8 or versions of @code{g77} based on that version
757 of @code{gcc}.)
758
759 @item
760 John Carr (@email{jfc@@mit.edu}) wrote the alias analysis improvements.
761
762 @item
763 Thanks to Mary Cortani and the staff at Craftwork Solutions
764 (@email{support@@craftwork.com}) for all of their support.
765
766 @item
767 Many other individuals have helped debug, test, and improve @code{g77}
768 over the past several years, and undoubtedly more people
769 will be doing so in the future.
770 If you have done so, and would like
771 to see your name listed in the above list, please ask!
772 The default is that people wish to remain anonymous.
773 @end itemize
774
775 @node Funding
776 @chapter Funding Free Software
777
778 If you want to have more free software a few years from now, it makes
779 sense for you to help encourage people to contribute funds for its
780 development.  The most effective approach known is to encourage
781 commercial redistributors to donate.
782
783 Users of free software systems can boost the pace of development by
784 encouraging for-a-fee distributors to donate part of their selling price
785 to free software developers---the Free Software Foundation, and others.
786
787 The way to convince distributors to do this is to demand it and expect
788 it from them.  So when you compare distributors, judge them partly by
789 how much they give to free software development.  Show distributors
790 they must compete to be the one who gives the most.
791
792 To make this approach work, you must insist on numbers that you can
793 compare, such as, ``We will donate ten dollars to the Frobnitz project
794 for each disk sold.''  Don't be satisfied with a vague promise, such as
795 ``A portion of the profits are donated,'' since it doesn't give a basis
796 for comparison.
797
798 Even a precise fraction ``of the profits from this disk'' is not very
799 meaningful, since creative accounting and unrelated business decisions
800 can greatly alter what fraction of the sales price counts as profit.
801 If the price you pay is $50, ten percent of the profit is probably
802 less than a dollar; it might be a few cents, or nothing at all.
803
804 Some redistributors do development work themselves.  This is useful too;
805 but to keep everyone honest, you need to inquire how much they do, and
806 what kind.  Some kinds of development make much more long-term
807 difference than others.  For example, maintaining a separate version of
808 a program contributes very little; maintaining the standard version of a
809 program for the whole community contributes much.  Easy new ports
810 contribute little, since someone else would surely do them; difficult
811 ports such as adding a new CPU to the GNU C compiler contribute more;
812 major new features or packages contribute the most.
813
814 By establishing the idea that supporting further development is ``the
815 proper thing to do'' when distributing free software for a fee, we can
816 assure a steady flow of resources into making more free software.
817
818 @display
819 Copyright (C) 1994 Free Software Foundation, Inc.
820 Verbatim copying and redistribution of this section is permitted
821 without royalty; alteration is not permitted.
822 @end display
823
824 @node Funding GNU Fortran
825 @chapter Funding GNU Fortran
826 @cindex funding improvements
827 @cindex improvements, funding
828
829 Work on GNU Fortran is still being done mostly by its author,
830 James Craig Burley (@email{@value{email-burley}}), who is a volunteer
831 for, not an employee of, the Free Software Foundation (FSF).
832 (He has a web page at @uref{@value{www-burley}}.)
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 To fund specific GNU Fortran work in particular, the FSF might
845 provide a means for that, but the FSF does not provide direct funding
846 to the author of GNU Fortran to continue his work.  The FSF has
847 employee salary restrictions that can be incompatible with the
848 financial needs of some volunteers, who therefore choose to
849 remain volunteers and thus be able to be free to do contract work
850 and otherwise make their own schedules for doing GNU work.
851
852 Still, funding the FSF at least indirectly benefits work
853 on specific projects like GNU Fortran because it ensures the
854 continuing operation of the FSF offices, their workstations, their
855 network connections, and so on, which are invaluable to volunteers.
856 (Similarly, hiring Cygnus Support can help a project like GNU
857 Fortran---Cygnus has been a long-time donor of equipment usage to the author
858 of GNU Fortran, and this too has been invaluable---see @ref{Contributors}.)
859
860 Currently, the only way to directly fund the author of GNU Fortran
861 in his work on that project is to hire him for the work you want
862 him to do, or donate money to him.
863 Several people have done this
864 already, with the result that he has not needed to immediately find
865 contract work on a few occasions.
866 If more people did this, he
867 would be able to plan on not doing contract work for many months and
868 could thus devote that time to work on projects (such as the planned
869 changes for 0.6) that require longer timeframes to complete.
870 For the latest information on the status of the author, do
871 @kbd{finger -l burley@@gnu.org} on a UNIX system
872 (or any system with a command like UNIX @code{finger}).
873
874 Another important way to support work on GNU Fortran is to volunteer
875 to help out.
876 Work is needed on documentation, testing, porting
877 to various machines, and in some cases, coding (although major
878 changes planned for version 0.6 make it difficult to add manpower to this
879 area).
880 Email @email{@value{email-general}} to volunteer for this work.
881
882 @xref{Funding,,Funding Free Software}, for more information.
883
884 @node Look and Feel
885 @chapter Protect Your Freedom---Fight ``Look And Feel''
886 @c the above chapter heading overflows onto the next line. --mew 1/26/93
887
888 To preserve the ability to write free software, including replacements
889 for proprietary software, authors must be free to replicate the
890 user interface to which users of existing software have become
891 accustomed.
892
893 @xref{Look and Feel,,Protect Your Freedom---Fight ``Look And Feel'',
894 gcc,Using and Porting GNU CC}, for more information.
895
896 @node Getting Started
897 @chapter Getting Started
898 @cindex getting started
899 @cindex new users
900 @cindex newbies
901 @cindex beginners
902
903 If you don't need help getting started reading the portions
904 of this manual that are most important to you, you should skip
905 this portion of the manual.
906
907 If you are new to compilers, especially Fortran compilers, or
908 new to how compilers are structured under UNIX and UNIX-like
909 systems, you'll want to see @ref{What is GNU Fortran?}.
910
911 If you are new to GNU compilers, or have used only one GNU
912 compiler in the past and not had to delve into how it lets
913 you manage various versions and configurations of @code{gcc},
914 you should see @ref{G77 and GCC}.
915
916 Everyone except experienced @code{g77} users should
917 see @ref{Invoking G77}.
918
919 If you're acquainted with previous versions of @code{g77},
920 you should see @ref{News,,News About GNU Fortran}.
921 Further, if you've actually used previous versions of @code{g77},
922 especially if you've written or modified Fortran code to
923 be compiled by previous versions of @code{g77}, you
924 should see @ref{Changes}.
925
926 If you intend to write or otherwise compile code that is
927 not already strictly conforming ANSI FORTRAN 77---and this
928 is probably everyone---you should see @ref{Language}.
929
930 If you don't already have @code{g77} installed on your
931 system, you must see @ref{Installation}.
932
933 If you run into trouble getting Fortran code to compile,
934 link, run, or work properly, you might find answers
935 if you see @ref{Debugging and Interfacing},
936 see @ref{Collected Fortran Wisdom},
937 and see @ref{Trouble}.
938 You might also find that the problems you are encountering
939 are bugs in @code{g77}---see @ref{Bugs}, for information on
940 reporting them, after reading the other material.
941
942 If you need further help with @code{g77}, or with
943 freely redistributable software in general,
944 see @ref{Service}.
945
946 If you would like to help the @code{g77} project,
947 see @ref{Funding GNU Fortran}, for information on
948 helping financially, and see @ref{Projects}, for information
949 on helping in other ways.
950
951 If you're generally curious about the future of
952 @code{g77}, see @ref{Projects}.
953 If you're curious about its past,
954 see @ref{Contributors},
955 and see @ref{Funding GNU Fortran}.
956
957 To see a few of the questions maintainers of @code{g77} have,
958 and that you might be able to answer,
959 see @ref{Open Questions}.
960
961 @ifset USING
962 @node What is GNU Fortran?
963 @chapter What is GNU Fortran?
964 @cindex concepts, basic
965 @cindex basic concepts
966
967 GNU Fortran, or @code{g77}, is designed initially as a free replacement
968 for, or alternative to, the UNIX @code{f77} command.
969 (Similarly, @code{gcc} is designed as a replacement
970 for the UNIX @code{cc} command.)
971
972 @code{g77} also is designed to fit in well with the other
973 fine GNU compilers and tools.
974
975 Sometimes these design goals conflict---in such cases, resolution
976 often is made in favor of fitting in well with Project GNU.
977 These cases are usually identified in the appropriate
978 sections of this manual.
979
980 @cindex compilers
981 As compilers, @code{g77}, @code{gcc}, and @code{f77}
982 share the following characteristics:
983
984 @itemize @bullet
985 @cindex source code
986 @cindex file, source
987 @cindex code, source
988 @cindex source file
989 @item
990 They read a user's program, stored in a file and
991 containing instructions written in the appropriate
992 language (Fortran, C, and so on).
993 This file contains @dfn{source code}.
994
995 @cindex translation of user programs
996 @cindex machine code
997 @cindex code, machine
998 @cindex mistakes
999 @item
1000 They translate the user's program into instructions
1001 a computer can carry out more quickly than it takes
1002 to translate the instructions in the first place.
1003 These instructions are called @dfn{machine code}---code
1004 designed to be efficiently translated and processed
1005 by a machine such as a computer.
1006 Humans usually aren't as good writing machine code
1007 as they are at writing Fortran or C, because
1008 it is easy to make tiny mistakes writing machine code.
1009 When writing Fortran or C, it is easy
1010 to make big mistakes.
1011
1012 @cindex debugger
1013 @cindex bugs, finding
1014 @cindex @code{gdb}, command
1015 @cindex commands, @code{gdb}
1016 @item
1017 They provide information in the generated machine code
1018 that can make it easier to find bugs in the program
1019 (using a debugging tool, called a @dfn{debugger},
1020 such as @code{gdb}).
1021
1022 @cindex libraries
1023 @cindex linking
1024 @cindex @code{ld} command
1025 @cindex commands, @code{ld}
1026 @item
1027 They locate and gather machine code already generated
1028 to perform actions requested by statements in
1029 the user's program.
1030 This machine code is organized
1031 into @dfn{libraries} and is located and gathered
1032 during the @dfn{link} phase of the compilation
1033 process.
1034 (Linking often is thought of as a separate
1035 step, because it can be directly invoked via the
1036 @code{ld} command.
1037 However, the @code{g77} and @code{gcc}
1038 commands, as with most compiler commands, automatically
1039 perform the linking step by calling on @code{ld}
1040 directly, unless asked to not do so by the user.)
1041
1042 @cindex language, incorrect use of
1043 @cindex incorrect use of language
1044 @item
1045 They attempt to diagnose cases where the user's
1046 program contains incorrect usages of the language.
1047 The @dfn{diagnostics} produced by the compiler
1048 indicate the problem and the location in the user's
1049 source file where the problem was first noticed.
1050 The user can use this information to locate and
1051 fix the problem.
1052 @cindex diagnostics, incorrect
1053 @cindex incorrect diagnostics
1054 @cindex error messages, incorrect
1055 @cindex incorrect error messages
1056 (Sometimes an incorrect usage
1057 of the language leads to a situation where the
1058 compiler can no longer make any sense of what
1059 follows---while a human might be able to---and
1060 thus ends up complaining about many ``problems''
1061 it encounters that, in fact, stem from just one
1062 problem, usually the first one reported.)
1063
1064 @cindex warnings
1065 @cindex questionable instructions
1066 @item
1067 They attempt to diagnose cases where the user's
1068 program contains a correct usage of the language,
1069 but instructs the computer to do something questionable.
1070 These diagnostics often are in the form of @dfn{warnings},
1071 instead of the @dfn{errors} that indicate incorrect
1072 usage of the language.
1073 @end itemize
1074
1075 How these actions are performed is generally under the
1076 control of the user.
1077 Using command-line options, the user can specify
1078 how persnickety the compiler is to be regarding
1079 the program (whether to diagnose questionable usage
1080 of the language), how much time to spend making
1081 the generated machine code run faster, and so on.
1082
1083 @cindex components of g77
1084 @cindex @code{g77}, components of
1085 @code{g77} consists of several components:
1086
1087 @cindex @code{gcc}, command
1088 @cindex commands, @code{gcc}
1089 @itemize @bullet
1090 @item
1091 A modified version of the @code{gcc} command, which also might be
1092 installed as the system's @code{cc} command.
1093 (In many cases, @code{cc} refers to the
1094 system's ``native'' C compiler, which
1095 might be a non-GNU compiler, or an older version
1096 of @code{gcc} considered more stable or that is
1097 used to build the operating system kernel.)
1098
1099 @cindex @code{g77}, command
1100 @cindex commands, @code{g77}
1101 @item
1102 The @code{g77} command itself, which also might be installed as the
1103 system's @code{f77} command.
1104
1105 @cindex libg2c library
1106 @cindex libf2c library
1107 @cindex libraries, libf2c
1108 @cindex libraries, libg2c
1109 @cindex run-time, library
1110 @item
1111 The @code{libg2c} run-time library.
1112 This library contains the machine code needed to support
1113 capabilities of the Fortran language that are not directly
1114 provided by the machine code generated by the @code{g77}
1115 compilation phase.
1116
1117 @code{libg2c} is just the unique name @code{g77} gives
1118 to its version of @code{libf2c} to distinguish it from
1119 any copy of @code{libf2c} installed from @code{f2c}
1120 (or versions of @code{g77} that built @code{libf2c} under
1121 that same name)
1122 on the system.
1123
1124 The maintainer of @code{libf2c} currently is
1125 @email{dmg@@bell-labs.com}.
1126
1127 @cindex @code{f771}, program
1128 @cindex programs, @code{f771}
1129 @cindex assembler
1130 @cindex @code{as} command
1131 @cindex commands, @code{as}
1132 @cindex assembly code
1133 @cindex code, assembly
1134 @item
1135 The compiler itself, internally named @code{f771}.
1136
1137 Note that @code{f771} does not generate machine code directly---it
1138 generates @dfn{assembly code} that is a more readable form
1139 of machine code, leaving the conversion to actual machine code
1140 to an @dfn{assembler}, usually named @code{as}.
1141 @end itemize
1142
1143 @code{gcc} is often thought of as ``the C compiler'' only,
1144 but it does more than that.
1145 Based on command-line options and the names given for files
1146 on the command line, @code{gcc} determines which actions to perform, including
1147 preprocessing, compiling (in a variety of possible languages), assembling,
1148 and linking.
1149
1150 @cindex driver, gcc command as
1151 @cindex @code{gcc}, command as driver
1152 @cindex executable file
1153 @cindex files, executable
1154 @cindex cc1 program
1155 @cindex programs, cc1
1156 @cindex preprocessor
1157 @cindex cpp program
1158 @cindex programs, cpp
1159 For example, the command @samp{gcc foo.c} @dfn{drives} the file
1160 @file{foo.c} through the preprocessor @code{cpp}, then
1161 the C compiler (internally named
1162 @code{cc1}), then the assembler (usually @code{as}), then the linker
1163 (@code{ld}), producing an executable program named @file{a.out} (on
1164 UNIX systems).
1165
1166 @cindex cc1plus program
1167 @cindex programs, cc1plus
1168 As another example, the command @samp{gcc foo.cc} would do much the same as
1169 @samp{gcc foo.c}, but instead of using the C compiler named @code{cc1},
1170 @code{gcc} would use the C++ compiler (named @code{cc1plus}).
1171
1172 @cindex @code{f771}, program
1173 @cindex programs, @code{f771}
1174 In a GNU Fortran installation, @code{gcc} recognizes Fortran source
1175 files by name just like it does C and C++ source files.
1176 It knows to use the Fortran compiler named @code{f771}, instead of
1177 @code{cc1} or @code{cc1plus}, to compile Fortran files.
1178
1179 @cindex @code{gcc}, not recognizing Fortran source
1180 @cindex unrecognized file format
1181 @cindex file format not recognized
1182 Non-Fortran-related operation of @code{gcc} is generally
1183 unaffected by installing the GNU Fortran version of @code{gcc}.
1184 However, without the installed version of @code{gcc} being the
1185 GNU Fortran version, @code{gcc} will not be able to compile
1186 and link Fortran programs---and since @code{g77} uses @code{gcc}
1187 to do most of the actual work, neither will @code{g77}!
1188
1189 @cindex @code{g77}, command
1190 @cindex commands, @code{g77}
1191 The @code{g77} command is essentially just a front-end for
1192 the @code{gcc} command.
1193 Fortran users will normally use @code{g77} instead of @code{gcc},
1194 because @code{g77}
1195 knows how to specify the libraries needed to link with Fortran programs
1196 (@code{libg2c} and @code{lm}).
1197 @code{g77} can still compile and link programs and
1198 source files written in other languages, just like @code{gcc}.
1199
1200 @cindex printing version information
1201 @cindex version information, printing
1202 The command @samp{g77 -v} is a quick
1203 way to display lots of version information for the various programs
1204 used to compile a typical preprocessed Fortran source file---this
1205 produces much more output than @samp{gcc -v} currently does.
1206 (If it produces an error message near the end of the output---diagnostics
1207 from the linker, usually @code{ld}---you might
1208 have an out-of-date @code{libf2c} that improperly handles
1209 complex arithmetic.)
1210 In the output of this command, the line beginning @samp{GNU Fortran Front
1211 End} identifies the version number of GNU Fortran; immediately
1212 preceding that line is a line identifying the version of @code{gcc}
1213 with which that version of @code{g77} was built.
1214
1215 @cindex libf2c library
1216 @cindex libraries, libf2c
1217 The @code{libf2c} library is distributed with GNU Fortran for
1218 the convenience of its users, but is not part of GNU Fortran.
1219 It contains the procedures
1220 needed by Fortran programs while they are running.
1221
1222 @cindex in-line code
1223 @cindex code, in-line
1224 For example, while code generated by @code{g77} is likely
1225 to do additions, subtractions, and multiplications @dfn{in line}---in
1226 the actual compiled code---it is not likely to do trigonometric
1227 functions this way.
1228
1229 Instead, operations like trigonometric
1230 functions are compiled by the @code{f771} compiler
1231 (invoked by @code{g77} when compiling Fortran code) into machine
1232 code that, when run, calls on functions in @code{libg2c}, so
1233 @code{libg2c} must be linked with almost every useful program
1234 having any component compiled by GNU Fortran.
1235 (As mentioned above, the @code{g77} command takes
1236 care of all this for you.)
1237
1238 The @code{f771} program represents most of what is unique to GNU Fortran.
1239 While much of the @code{libg2c} component comes from
1240 the @code{libf2c} component of @code{f2c},
1241 a free Fortran-to-C converter distributed by Bellcore (AT&T),
1242 plus @code{libU77}, provided by Dave Love,
1243 and the @code{g77} command is just a small front-end to @code{gcc},
1244 @code{f771} is a combination of two rather
1245 large chunks of code.
1246
1247 @cindex GNU Back End (GBE)
1248 @cindex GBE
1249 @cindex @code{gcc}, back end
1250 @cindex back end, gcc
1251 @cindex code generator
1252 One chunk is the so-called @dfn{GNU Back End}, or GBE,
1253 which knows how to generate fast code for a wide variety of processors.
1254 The same GBE is used by the C, C++, and Fortran compiler programs @code{cc1},
1255 @code{cc1plus}, and @code{f771}, plus others.
1256 Often the GBE is referred to as the ``gcc back end'' or
1257 even just ``gcc''---in this manual, the term GBE is used
1258 whenever the distinction is important.
1259
1260 @cindex GNU Fortran Front End (FFE)
1261 @cindex FFE
1262 @cindex @code{g77}, front end
1263 @cindex front end, @code{g77}
1264 The other chunk of @code{f771} is the
1265 majority of what is unique about GNU Fortran---the code that knows how
1266 to interpret Fortran programs to determine what they are intending to
1267 do, and then communicate that knowledge to the GBE for actual compilation
1268 of those programs.
1269 This chunk is called the @dfn{Fortran Front End} (FFE).
1270 The @code{cc1} and @code{cc1plus} programs have their own front ends,
1271 for the C and C++ languages, respectively.
1272 These fronts ends are responsible for diagnosing
1273 incorrect usage of their respective languages by the
1274 programs the process, and are responsible for most of
1275 the warnings about questionable constructs as well.
1276 (The GBE handles producing some warnings, like those
1277 concerning possible references to undefined variables.)
1278
1279 Because so much is shared among the compilers for various languages,
1280 much of the behavior and many of the user-selectable options for these
1281 compilers are similar.
1282 For example, diagnostics (error messages and
1283 warnings) are similar in appearance; command-line
1284 options like @samp{-Wall} have generally similar effects; and the quality
1285 of generated code (in terms of speed and size) is roughly similar
1286 (since that work is done by the shared GBE).
1287
1288 @node G77 and GCC
1289 @chapter Compile Fortran, C, or Other Programs
1290 @cindex compiling programs
1291 @cindex programs, compiling
1292
1293 @cindex @code{gcc}, command
1294 @cindex commands, @code{gcc}
1295 A GNU Fortran installation includes a modified version of the @code{gcc}
1296 command.
1297
1298 In a non-Fortran installation, @code{gcc} recognizes C, C++,
1299 and Objective-C source files.
1300
1301 In a GNU Fortran installation, @code{gcc} also recognizes Fortran source
1302 files and accepts Fortran-specific command-line options, plus some
1303 command-line options that are designed to cater to Fortran users
1304 but apply to other languages as well.
1305
1306 @xref{G++ and GCC,,Compile C; C++; or Objective-C,gcc,Using and Porting GNU CC},
1307 for information on the way different languages are handled
1308 by the GNU CC compiler (@code{gcc}).
1309
1310 @cindex @code{g77}, command
1311 @cindex commands, @code{g77}
1312 Also provided as part of GNU Fortran is the @code{g77} command.
1313 The @code{g77} command is designed to make compiling and linking Fortran
1314 programs somewhat easier than when using the @code{gcc} command for
1315 these tasks.
1316 It does this by analyzing the command line somewhat and changing it
1317 appropriately before submitting it to the @code{gcc} command.
1318
1319 @cindex -v option
1320 @cindex @code{g77} options, -v
1321 @cindex options, -v
1322 Use the @samp{-v} option with @code{g77}
1323 to see what is going on---the first line of output is the invocation
1324 of the @code{gcc} command.
1325
1326 @node Invoking G77
1327 @chapter GNU Fortran Command Options
1328 @cindex GNU Fortran command options
1329 @cindex command options
1330 @cindex options, GNU Fortran command
1331
1332 The @code{g77} command supports all the options supported by the
1333 @code{gcc} command.
1334 @xref{Invoking GCC,,GNU CC Command Options,gcc,Using and Porting GNU CC},
1335 for information
1336 on the non-Fortran-specific aspects of the @code{gcc} command (and,
1337 therefore, the @code{g77} command).
1338
1339 @cindex options, negative forms
1340 @cindex negative forms of options
1341 All @code{gcc} and @code{g77} options
1342 are accepted both by @code{g77} and by @code{gcc}
1343 (as well as any other drivers built at the same time,
1344 such as @code{g++}),
1345 since adding @code{g77} to the @code{gcc} distribution
1346 enables acceptance of @code{g77}-specific options
1347 by all of the relevant drivers.
1348
1349 In some cases, options have positive and negative forms;
1350 the negative form of @samp{-ffoo} would be @samp{-fno-foo}.
1351 This manual documents only one of these two forms, whichever
1352 one is not the default.
1353
1354 @menu
1355 * Option Summary::      Brief list of all @code{g77} options,
1356                         without explanations.
1357 * Overall Options::     Controlling the kind of output:
1358                         an executable, object files, assembler files,
1359                         or preprocessed source.
1360 * Shorthand Options::   Options that are shorthand for other options.
1361 * Fortran Dialect Options::  Controlling the variant of Fortran language
1362                              compiled.
1363 * Warning Options::     How picky should the compiler be?
1364 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1365 * Optimize Options::    How much optimization?
1366 * Preprocessor Options:: Controlling header files and macro definitions.
1367                          Also, getting dependency information for Make.
1368 * Directory Options::   Where to find header files and libraries.
1369                         Where to find the compiler executable files.
1370 * Code Gen Options::    Specifying conventions for function calls, data layout
1371                         and register usage.
1372 * Environment Variables:: Env vars that affect GNU Fortran.
1373 @end menu
1374
1375 @node Option Summary
1376 @section Option Summary
1377
1378 Here is a summary of all the options specific to GNU Fortran, grouped
1379 by type.  Explanations are in the following sections.
1380
1381 @table @emph
1382 @item Overall Options
1383 @xref{Overall Options,,Options Controlling the Kind of Output}.
1384 @smallexample
1385 -fversion  -fset-g77-defaults  -fno-silent
1386 @end smallexample
1387
1388 @item Shorthand Options
1389 @xref{Shorthand Options}.
1390 @smallexample
1391 -ff66  -fno-f66  -ff77  -fno-f77  -fno-ugly
1392 @end smallexample
1393
1394 @item Fortran Language Options
1395 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
1396 @smallexample
1397 -ffree-form  -fno-fixed-form  -ff90
1398 -fvxt  -fdollar-ok  -fno-backslash
1399 -fno-ugly-args  -fno-ugly-assign  -fno-ugly-assumed
1400 -fugly-comma  -fugly-complex  -fugly-init  -fugly-logint
1401 -fonetrip  -ftypeless-boz
1402 -fintrin-case-initcap  -fintrin-case-upper
1403 -fintrin-case-lower  -fintrin-case-any
1404 -fmatch-case-initcap  -fmatch-case-upper
1405 -fmatch-case-lower  -fmatch-case-any
1406 -fsource-case-upper -fsource-case-lower  -fsource-case-preserve
1407 -fsymbol-case-initcap  -fsymbol-case-upper
1408 -fsymbol-case-lower  -fsymbol-case-any
1409 -fcase-strict-upper  -fcase-strict-lower
1410 -fcase-initcap  -fcase-upper  -fcase-lower  -fcase-preserve
1411 -ff2c-intrinsics-delete  -ff2c-intrinsics-hide
1412 -ff2c-intrinsics-disable  -ff2c-intrinsics-enable
1413 -fbadu77-intrinsics-delete  -fbadu77-intrinsics-hide
1414 -fbadu77-intrinsics-disable  -fbadu77-intrinsics-enable
1415 -ff90-intrinsics-delete  -ff90-intrinsics-hide
1416 -ff90-intrinsics-disable  -ff90-intrinsics-enable
1417 -fgnu-intrinsics-delete  -fgnu-intrinsics-hide
1418 -fgnu-intrinsics-disable  -fgnu-intrinsics-enable
1419 -fmil-intrinsics-delete  -fmil-intrinsics-hide
1420 -fmil-intrinsics-disable  -fmil-intrinsics-enable
1421 -funix-intrinsics-delete  -funix-intrinsics-hide
1422 -funix-intrinsics-disable  -funix-intrinsics-enable
1423 -fvxt-intrinsics-delete  -fvxt-intrinsics-hide
1424 -fvxt-intrinsics-disable  -fvxt-intrinsics-enable
1425 -ffixed-line-length-@var{n}  -ffixed-line-length-none
1426 @end smallexample
1427
1428 @item Warning Options
1429 @xref{Warning Options,,Options to Request or Suppress Warnings}.
1430 @smallexample
1431 -fsyntax-only  -pedantic  -pedantic-errors  -fpedantic
1432 -w  -Wno-globals  -Wimplicit -Wunused  -Wuninitialized
1433 -Wall  -Wsurprising
1434 -Werror  -W
1435 @end smallexample
1436
1437 @item Debugging Options
1438 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
1439 @smallexample
1440 -g
1441 @end smallexample
1442
1443 @item Optimization Options
1444 @xref{Optimize Options,,Options that Control Optimization}.
1445 @smallexample
1446 -malign-double
1447 -ffloat-store  -fforce-mem  -fforce-addr  -fno-inline
1448 -ffast-math  -fstrength-reduce  -frerun-cse-after-loop
1449 -fexpensive-optimizations  -fdelayed-branch
1450 -fschedule-insns  -fschedule-insn2  -fcaller-saves
1451 -funroll-loops  -funroll-all-loops
1452 -fno-move-all-movables  -fno-reduce-all-givs
1453 -fno-rerun-loop-opt
1454 @end smallexample
1455
1456 @item Directory Options
1457 @xref{Directory Options,,Options for Directory Search}.
1458 @smallexample
1459 -I@var{dir}  -I-
1460 @end smallexample
1461
1462 @item Code Generation Options
1463 @xref{Code Gen Options,,Options for Code Generation Conventions}.
1464 @smallexample
1465 -fno-automatic  -finit-local-zero  -fno-f2c
1466 -ff2c-library  -fno-underscoring  -fno-ident
1467 -fpcc-struct-return  -freg-struct-return
1468 -fshort-double  -fno-common  -fpack-struct
1469 -fzeros  -fno-second-underscore
1470 -fdebug-kludge  -femulate-complex
1471 -falias-check  -fargument-alias
1472 -fargument-noalias  -fno-argument-noalias-global
1473 -fno-globals  -fflatten-arrays
1474 -fbounds-check  -ffortran-bounds-check
1475 @end smallexample
1476 @end table
1477
1478 @menu
1479 * Overall Options::     Controlling the kind of output:
1480                         an executable, object files, assembler files,
1481                         or preprocessed source.
1482 * Shorthand Options::   Options that are shorthand for other options.
1483 * Fortran Dialect Options::  Controlling the variant of Fortran language
1484                              compiled.
1485 * Warning Options::     How picky should the compiler be?
1486 * Debugging Options::   Symbol tables, measurements, and debugging dumps.
1487 * Optimize Options::    How much optimization?
1488 * Preprocessor Options:: Controlling header files and macro definitions.
1489                          Also, getting dependency information for Make.
1490 * Directory Options::   Where to find header files and libraries.
1491                         Where to find the compiler executable files.
1492 * Code Gen Options::    Specifying conventions for function calls, data layout
1493                         and register usage.
1494 @end menu
1495
1496 @node Overall Options
1497 @section Options Controlling the Kind of Output
1498 @cindex overall options
1499 @cindex options, overall
1500
1501 Compilation can involve as many as four stages: preprocessing, code
1502 generation (often what is really meant by the term ``compilation''),
1503 assembly, and linking, always in that order.  The first three
1504 stages apply to an individual source file, and end by producing an
1505 object file; linking combines all the object files (those newly
1506 compiled, and those specified as input) into an executable file.
1507
1508 @cindex file name suffix
1509 @cindex suffixes, file name
1510 @cindex file name extension
1511 @cindex extensions, file name
1512 @cindex file type
1513 @cindex types, file
1514 For any given input file, the file name suffix determines what kind of
1515 program is contained in the file---that is, the language in which the
1516 program is written is generally indicated by the suffix.
1517 Suffixes specific to GNU Fortran are listed below.
1518 @xref{Overall Options,,gcc,Using and Porting GNU CC}, for
1519 information on suffixes recognized by GNU CC.
1520
1521 @table @code
1522 @cindex .f filename suffix
1523 @cindex .for filename suffix
1524 @cindex .FOR filename suffix
1525 @item @var{file}.f
1526 @item @var{file}.for
1527 @item @var{file}.FOR
1528 Fortran source code that should not be preprocessed.
1529
1530 Such source code cannot contain any preprocessor directives, such
1531 as @code{#include}, @code{#define}, @code{#if}, and so on.
1532
1533 You can force @samp{.f} files to be preprocessed by @code{cpp} by using
1534 @samp{-x f77-cpp-input}.
1535 @xref{LEX}.
1536
1537 @cindex preprocessor
1538 @cindex C preprocessor
1539 @cindex cpp preprocessor
1540 @cindex Fortran preprocessor
1541 @cindex cpp program
1542 @cindex programs, cpp
1543 @cindex .F filename suffix
1544 @cindex .fpp filename suffix
1545 @cindex .FPP filename suffix
1546 @item @var{file}.F
1547 @item @var{file}.fpp
1548 @item @var{file}.FPP
1549 Fortran source code that must be preprocessed (by the C preprocessor
1550 @code{cpp}, which is part of GNU CC).
1551
1552 Note that preprocessing is not extended to the contents of
1553 files included by the @code{INCLUDE} directive---the @code{#include}
1554 preprocessor directive must be used instead.
1555
1556 @cindex Ratfor preprocessor
1557 @cindex programs, @code{ratfor}
1558 @cindex @samp{.r} filename suffix
1559 @cindex @code{ratfor}
1560 @item @var{file}.r
1561 Ratfor source code, which must be preprocessed by the @code{ratfor}
1562 command, which is available separately (as it is not yet part of the GNU
1563 Fortran distribution).
1564 One version in Fortran, adapted for use with @code{g77}, is at
1565 @uref{ftp://members.aol.com/n8tm/rat7.uue} (of uncertain copyright
1566 status).  Another, public domain version in C is at
1567 @uref{http://sepwww.stanford.edu/sep/prof/ratfor.shar.2}.
1568 @end table
1569
1570 UNIX users typically use the @file{@var{file}.f} and @file{@var{file}.F}
1571 nomenclature.
1572 Users of other operating systems, especially those that cannot
1573 distinguish upper-case
1574 letters from lower-case letters in their file names, typically use
1575 the @file{@var{file}.for} and @file{@var{file}.fpp} nomenclature.
1576
1577 @cindex #define
1578 @cindex #include
1579 @cindex #if
1580 Use of the preprocessor @code{cpp} allows use of C-like
1581 constructs such as @code{#define} and @code{#include}, but can
1582 lead to unexpected, even mistaken, results due to Fortran's source file
1583 format.
1584 It is recommended that use of the C preprocessor
1585 be limited to @code{#include} and, in
1586 conjunction with @code{#define}, only @code{#if} and related directives,
1587 thus avoiding in-line macro expansion entirely.
1588 This recommendation applies especially
1589 when using the traditional fixed source form.
1590 With free source form,
1591 fewer unexpected transformations are likely to happen, but use of
1592 constructs such as Hollerith and character constants can nevertheless
1593 present problems, especially when these are continued across multiple
1594 source lines.
1595 These problems result, primarily, from differences between the way
1596 such constants are interpreted by the C preprocessor and by a Fortran
1597 compiler.
1598
1599 Another example of a problem that results from using the C preprocessor
1600 is that a Fortran comment line that happens to contain any
1601 characters ``interesting'' to the C preprocessor,
1602 such as a backslash at the end of the line,
1603 is not recognized by the preprocessor as a comment line,
1604 so instead of being passed through ``raw'',
1605 the line is edited according to the rules for the preprocessor.
1606 For example, the backslash at the end of the line is removed,
1607 along with the subsequent newline, resulting in the next
1608 line being effectively commented out---unfortunate if that
1609 line is a non-comment line of important code!
1610
1611 @emph{Note:} The @samp{-traditional} and @samp{-undef} flags are supplied
1612 to @code{cpp} by default, to help avoid unpleasant surprises.
1613 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
1614 gcc,Using and Porting GNU CC}.
1615 This means that ANSI C preprocessor features (such as the @samp{#}
1616 operator) aren't available, and only variables in the C reserved
1617 namespace (generally, names with a leading underscore) are liable to
1618 substitution by C predefines.
1619 Thus, if you want to do system-specific
1620 tests, use, for example, @samp{#ifdef __linux__} rather than @samp{#ifdef linux}.
1621 Use the @samp{-v} option to see exactly how the preprocessor is invoked.
1622
1623 @cindex /*
1624 Unfortunately, the @samp{-traditional} flag will not avoid an error from
1625 anything that @code{cpp} sees as an unterminated C comment, such as:
1626 @smallexample
1627 C Some Fortran compilers accept /* as starting
1628 C an inline comment.
1629 @end smallexample
1630 @xref{Trailing Comment}.
1631
1632 The following options that affect overall processing are recognized
1633 by the @code{g77} and @code{gcc} commands in a GNU Fortran installation:
1634
1635 @table @code
1636 @cindex -fversion option
1637 @cindex options, -fversion
1638 @cindex printing version information
1639 @cindex version information, printing
1640 @cindex consistency checks
1641 @cindex internal consistency checks
1642 @cindex checks, of internal consistency
1643 @item -fversion
1644 Ensure that the @code{g77}-specific version of the compiler phase is reported,
1645 if run,
1646 and, starting in @code{egcs} version 1.1,
1647 that internal consistency checks in the @file{f771} program are run.
1648
1649 This option is supplied automatically when @samp{-v} or @samp{--verbose}
1650 is specified as a command-line option for @code{g77} or @code{gcc}
1651 and when the resulting commands compile Fortran source files.
1652
1653 @cindex -fset-g77-defaults option
1654 @cindex options, -fset-g77-defaults
1655 @item -fset-g77-defaults
1656 @emph{Version info:}
1657 This option is obsolete in @code{egcs}
1658 as of version 1.1.
1659 The effect is instead achieved
1660 by the @code{lang_init_options} routine
1661 in @file{egcs/gcc/f/com.c}.
1662
1663 @cindex consistency checks
1664 @cindex internal consistency checks
1665 @cindex checks, of internal consistency
1666 Set up whatever @code{gcc} options are to apply to Fortran
1667 compilations, and avoid running internal consistency checks
1668 that might take some time.
1669
1670 This option is supplied automatically when compiling Fortran code
1671 via the @code{g77} or @code{gcc} command.
1672 The description of this option is provided so that users seeing
1673 it in the output of, say, @samp{g77 -v} understand why it is
1674 there.
1675
1676 @cindex modifying g77
1677 @cindex code, modifying
1678 Also, developers who run @code{f771} directly might want to specify it
1679 by hand to get the same defaults as they would running @code{f771}
1680 via @code{g77} or @code{gcc}.
1681 However, such developers should, after linking a new @code{f771}
1682 executable, invoke it without this option once,
1683 e.g. via @kbd{./f771 -quiet < /dev/null},
1684 to ensure that they have not introduced any
1685 internal inconsistencies (such as in the table of
1686 intrinsics) before proceeding---@code{g77} will crash
1687 with a diagnostic if it detects an inconsistency.
1688
1689 @cindex -fno-silent option
1690 @cindex options, -fno-silent
1691 @cindex f2c compatibility
1692 @cindex compatibility, f2c
1693 @cindex status, compilation
1694 @cindex compilation, status
1695 @cindex reporting compilation status
1696 @cindex printing compilation status
1697 @item -fno-silent
1698 Print (to @code{stderr}) the names of the program units as
1699 they are compiled, in a form similar to that used by popular
1700 UNIX @code{f77} implementations and @code{f2c}.
1701 @end table
1702
1703 @xref{Overall Options,,Options Controlling the Kind of Output,
1704 gcc,Using and Porting GNU CC}, for information
1705 on more options that control the overall operation of the @code{gcc} command
1706 (and, by extension, the @code{g77} command).
1707
1708 @node Shorthand Options
1709 @section Shorthand Options
1710 @cindex shorthand options
1711 @cindex options, shorthand
1712 @cindex macro options
1713 @cindex options, macro
1714
1715 The following options serve as ``shorthand''
1716 for other options accepted by the compiler:
1717
1718 @table @code
1719 @cindex -fugly option
1720 @cindex options, -fugly
1721 @item -fugly
1722 @cindex ugly features
1723 @cindex features, ugly
1724 @emph{Note:} This option is no longer supported.
1725 The information, below, is provided to aid
1726 in the conversion of old scripts.
1727
1728 Specify that certain ``ugly'' constructs are to be quietly accepted.
1729 Same as:
1730
1731 @smallexample
1732 -fugly-args -fugly-assign -fugly-assumed
1733 -fugly-comma -fugly-complex -fugly-init
1734 -fugly-logint
1735 @end smallexample
1736
1737 These constructs are considered inappropriate to use in new
1738 or well-maintained portable Fortran code, but widely used
1739 in old code.
1740 @xref{Distensions}, for more information.
1741
1742 @cindex -fno-ugly option
1743 @cindex options, -fno-ugly
1744 @item -fno-ugly
1745 @cindex ugly features
1746 @cindex features, ugly
1747 Specify that all ``ugly'' constructs are to be noisily rejected.
1748 Same as:
1749
1750 @smallexample
1751 -fno-ugly-args -fno-ugly-assign -fno-ugly-assumed
1752 -fno-ugly-comma -fno-ugly-complex -fno-ugly-init
1753 -fno-ugly-logint
1754 @end smallexample
1755
1756 @xref{Distensions}, for more information.
1757
1758 @cindex -ff66 option
1759 @cindex options, -ff66
1760 @item -ff66
1761 @cindex FORTRAN 66
1762 @cindex compatibility, FORTRAN 66
1763 Specify that the program is written in idiomatic FORTRAN 66.
1764 Same as @samp{-fonetrip -fugly-assumed}.
1765
1766 The @samp{-fno-f66} option is the inverse of @samp{-ff66}.
1767 As such, it is the same as @samp{-fno-onetrip -fno-ugly-assumed}.
1768
1769 The meaning of this option is likely to be refined as future
1770 versions of @code{g77} provide more compatibility with other
1771 existing and obsolete Fortran implementations.
1772
1773 @cindex -ff77 option
1774 @cindex options, -ff77
1775 @item -ff77
1776 @cindex UNIX f77
1777 @cindex f2c compatibility
1778 @cindex compatibility, f2c
1779 @cindex f77 compatibility
1780 @cindex compatibility, f77
1781 Specify that the program is written in idiomatic UNIX FORTRAN 77
1782 and/or the dialect accepted by the @code{f2c} product.
1783 Same as @samp{-fbackslash -fno-typeless-boz}.
1784
1785 The meaning of this option is likely to be refined as future
1786 versions of @code{g77} provide more compatibility with other
1787 existing and obsolete Fortran implementations.
1788
1789 @cindex -fno-f77 option
1790 @cindex options, -fno-f77
1791 @item -fno-f77
1792 @cindex UNIX f77
1793 The @samp{-fno-f77} option is @emph{not} the inverse
1794 of @samp{-ff77}.
1795 It specifies that the program is not written in idiomatic UNIX
1796 FORTRAN 77 or @code{f2c}, but in a more widely portable dialect.
1797 @samp{-fno-f77} is the same as @samp{-fno-backslash}.
1798
1799 The meaning of this option is likely to be refined as future
1800 versions of @code{g77} provide more compatibility with other
1801 existing and obsolete Fortran implementations.
1802 @end table
1803
1804 @node Fortran Dialect Options
1805 @section Options Controlling Fortran Dialect
1806 @cindex dialect options
1807 @cindex language, dialect options
1808 @cindex options, dialect
1809
1810 The following options control the dialect of Fortran
1811 that the compiler accepts:
1812
1813 @table @code
1814 @cindex -ffree-form option
1815 @cindex options, -ffree-form
1816 @cindex -fno-fixed-form option
1817 @cindex options, -fno-fixed-form
1818 @cindex source file format
1819 @cindex free form
1820 @cindex fixed form
1821 @cindex Fortran 90, features
1822 @item -ffree-form
1823 @item -fno-fixed-form
1824 Specify that the source file is written in free form
1825 (introduced in Fortran 90) instead of the more-traditional fixed form.
1826
1827 @cindex -ff90 option
1828 @cindex options, -ff90
1829 @cindex Fortran 90, features
1830 @item -ff90
1831 Allow certain Fortran-90 constructs.
1832
1833 This option controls whether certain
1834 Fortran 90 constructs are recognized.
1835 (Other Fortran 90 constructs
1836 might or might not be recognized depending on other options such as
1837 @samp{-fvxt}, @samp{-ff90-intrinsics-enable}, and the
1838 current level of support for Fortran 90.)
1839
1840 @xref{Fortran 90}, for more information.
1841
1842 @cindex -fvxt option
1843 @cindex options, -fvxt
1844 @item -fvxt
1845 @cindex Fortran 90, features
1846 @cindex VXT extensions
1847 Specify the treatment of certain constructs that have different
1848 meanings depending on whether the code is written in
1849 GNU Fortran (based on FORTRAN 77 and akin to Fortran 90)
1850 or VXT Fortran (more like VAX FORTRAN).
1851
1852 The default is @samp{-fno-vxt}.
1853 @samp{-fvxt} specifies that the VXT Fortran interpretations
1854 for those constructs are to be chosen.
1855
1856 @xref{VXT Fortran}, for more information.
1857
1858 @cindex -fdollar-ok option
1859 @cindex options, -fdollar-ok
1860 @item -fdollar-ok
1861 @cindex dollar sign
1862 @cindex symbol names
1863 @cindex character set
1864 Allow @samp{$} as a valid character in a symbol name.
1865
1866 @cindex -fno-backslash option
1867 @cindex options, -fno-backslash
1868 @item -fno-backslash
1869 @cindex backslash
1870 @cindex character constants
1871 @cindex Hollerith constants
1872 Specify that @samp{\} is not to be specially interpreted in character
1873 and Hollerith constants a la C and many UNIX Fortran compilers.
1874
1875 For example, with @samp{-fbackslash} in effect, @samp{A\nB} specifies
1876 three characters, with the second one being newline.
1877 With @samp{-fno-backslash}, it specifies four characters,
1878 @samp{A}, @samp{\}, @samp{n}, and @samp{B}.
1879
1880 Note that @code{g77} implements a fairly general form of backslash
1881 processing that is incompatible with the narrower forms supported
1882 by some other compilers.
1883 For example, @samp{'A\003B'} is a three-character string in @code{g77},
1884 whereas other compilers that support backslash might not support
1885 the three-octal-digit form, and thus treat that string as longer
1886 than three characters.
1887
1888 @xref{Backslash in Constants}, for
1889 information on why @samp{-fbackslash} is the default
1890 instead of @samp{-fno-backslash}.
1891
1892 @cindex -fno-ugly-args option
1893 @cindex options, -fno-ugly-args
1894 @item -fno-ugly-args
1895 Disallow passing Hollerith and typeless constants as actual
1896 arguments (for example, @samp{CALL FOO(4HABCD)}).
1897
1898 @xref{Ugly Implicit Argument Conversion}, for more information.
1899
1900 @cindex -fugly-assign option
1901 @cindex options, -fugly-assign
1902 @item -fugly-assign
1903 Use the same storage for a given variable regardless of
1904 whether it is used to hold an assigned-statement label
1905 (as in @samp{ASSIGN 10 TO I}) or used to hold numeric data
1906 (as in @samp{I = 3}).
1907
1908 @xref{Ugly Assigned Labels}, for more information.
1909
1910 @cindex -fugly-assumed option
1911 @cindex options, -fugly-assumed
1912 @item -fugly-assumed
1913 Assume any dummy array with a final dimension specified as @samp{1}
1914 is really an assumed-size array, as if @samp{*} had been specified
1915 for the final dimension instead of @samp{1}.
1916
1917 For example, @samp{DIMENSION X(1)} is treated as if it
1918 had read @samp{DIMENSION X(*)}.
1919
1920 @xref{Ugly Assumed-Size Arrays}, for more information.
1921
1922 @cindex -fugly-comma option
1923 @cindex options, -fugly-comma
1924 @item -fugly-comma
1925 In an external-procedure invocation,
1926 treat a trailing comma in the argument list
1927 as specification of a trailing null argument,
1928 and treat an empty argument list
1929 as specification of a single null argument.
1930
1931 For example, @samp{CALL FOO(,)} is treated as
1932 @samp{CALL FOO(%VAL(0), %VAL(0))}.
1933 That is, @emph{two} null arguments are specified
1934 by the procedure call when @samp{-fugly-comma} is in force.
1935 And @samp{F = FUNC()} is treated as @samp{F = FUNC(%VAL(0))}.
1936
1937 The default behavior, @samp{-fno-ugly-comma}, is to ignore
1938 a single trailing comma in an argument list.
1939 So, by default, @samp{CALL FOO(X,)} is treated
1940 exactly the same as @samp{CALL FOO(X)}.
1941
1942 @xref{Ugly Null Arguments}, for more information.
1943
1944 @cindex -fugly-complex option
1945 @cindex options, -fugly-complex
1946 @item -fugly-complex
1947 Do not complain about @samp{REAL(@var{expr})} or
1948 @samp{AIMAG(@var{expr})} when @var{expr} is a @code{COMPLEX}
1949 type other than @code{COMPLEX(KIND=1)}---usually
1950 this is used to permit @code{COMPLEX(KIND=2)}
1951 (@code{DOUBLE COMPLEX}) operands.
1952
1953 The @samp{-ff90} option controls the interpretation
1954 of this construct.
1955
1956 @xref{Ugly Complex Part Extraction}, for more information.
1957
1958 @cindex -fno-ugly-init option
1959 @cindex options, -fno-ugly-init
1960 @item -fno-ugly-init
1961 Disallow use of Hollerith and typeless constants as initial
1962 values (in @code{PARAMETER} and @code{DATA} statements), and
1963 use of character constants to
1964 initialize numeric types and vice versa.
1965
1966 For example, @samp{DATA I/'F'/, CHRVAR/65/, J/4HABCD/} is disallowed by
1967 @samp{-fno-ugly-init}.
1968
1969 @xref{Ugly Conversion of Initializers}, for more information.
1970
1971 @cindex -fugly-logint option
1972 @cindex options, -fugly-logint
1973 @item -fugly-logint
1974 Treat @code{INTEGER} and @code{LOGICAL} variables and
1975 expressions as potential stand-ins for each other.
1976
1977 For example, automatic conversion between @code{INTEGER} and
1978 @code{LOGICAL} is enabled, for many contexts, via this option.
1979
1980 @xref{Ugly Integer Conversions}, for more information.
1981
1982 @cindex -fonetrip option
1983 @cindex options, -fonetrip
1984 @item -fonetrip
1985 @cindex FORTRAN 66
1986 @cindex @code{DO} loops, one-trip
1987 @cindex one-trip @code{DO} loops
1988 @cindex @code{DO} loops, zero-trip
1989 @cindex zero-trip @code{DO} loops
1990 @cindex compatibility, FORTRAN 66
1991 Executable iterative @code{DO} loops are to be executed at
1992 least once each time they are reached.
1993
1994 ANSI FORTRAN 77 and more recent versions of the Fortran standard
1995 specify that the body of an iterative @code{DO} loop is not executed
1996 if the number of iterations calculated from the parameters of the
1997 loop is less than 1.
1998 (For example, @samp{DO 10 I = 1, 0}.)
1999 Such a loop is called a @dfn{zero-trip loop}.
2000
2001 Prior to ANSI FORTRAN 77, many compilers implemented @code{DO} loops
2002 such that the body of a loop would be executed at least once, even
2003 if the iteration count was zero.
2004 Fortran code written assuming this behavior is said to require
2005 @dfn{one-trip loops}.
2006 For example, some code written to the FORTRAN 66 standard
2007 expects this behavior from its @code{DO} loops, although that
2008 standard did not specify this behavior.
2009
2010 The @samp{-fonetrip} option specifies that the source file(s) being
2011 compiled require one-trip loops.
2012
2013 This option affects only those loops specified by the (iterative) @code{DO}
2014 statement and by implied-@code{DO} lists in I/O statements.
2015 Loops specified by implied-@code{DO} lists in @code{DATA} and
2016 specification (non-executable) statements are not affected.
2017
2018 @cindex -ftypeless-boz option
2019 @cindex options, -ftypeless-boz
2020 @cindex prefix-radix constants
2021 @cindex constants, prefix-radix
2022 @cindex constants, types
2023 @cindex types, constants
2024 @item -ftypeless-boz
2025 Specifies that prefix-radix non-decimal constants, such as
2026 @samp{Z'ABCD'}, are typeless instead of @code{INTEGER(KIND=1)}.
2027
2028 You can test for yourself whether a particular compiler treats
2029 the prefix form as @code{INTEGER(KIND=1)} or typeless by running the
2030 following program:
2031
2032 @smallexample
2033 EQUIVALENCE (I, R)
2034 R = Z'ABCD1234'
2035 J = Z'ABCD1234'
2036 IF (J .EQ. I) PRINT *, 'Prefix form is TYPELESS'
2037 IF (J .NE. I) PRINT *, 'Prefix form is INTEGER'
2038 END
2039 @end smallexample
2040
2041 Reports indicate that many compilers process this form as
2042 @code{INTEGER(KIND=1)}, though a few as typeless, and at least one
2043 based on a command-line option specifying some kind of
2044 compatibility.
2045
2046 @cindex -fintrin-case-initcap option
2047 @cindex options, -fintrin-case-initcap
2048 @item -fintrin-case-initcap
2049 @cindex -fintrin-case-upper option
2050 @cindex options, -fintrin-case-upper
2051 @item -fintrin-case-upper
2052 @cindex -fintrin-case-lower option
2053 @cindex options, -fintrin-case-lower
2054 @item -fintrin-case-lower
2055 @cindex -fintrin-case-any option
2056 @cindex options, -fintrin-case-any
2057 @item -fintrin-case-any
2058 Specify expected case for intrinsic names.
2059 @samp{-fintrin-case-lower} is the default.
2060
2061 @cindex -fmatch-case-initcap option
2062 @cindex options, -fmatch-case-initcap
2063 @item -fmatch-case-initcap
2064 @cindex -fmatch-case-upper option
2065 @cindex options, -fmatch-case-upper
2066 @item -fmatch-case-upper
2067 @cindex -fmatch-case-lower option
2068 @cindex options, -fmatch-case-lower
2069 @item -fmatch-case-lower
2070 @cindex -fmatch-case-any option
2071 @cindex options, -fmatch-case-any
2072 @item -fmatch-case-any
2073 Specify expected case for keywords.
2074 @samp{-fmatch-case-lower} is the default.
2075
2076 @cindex -fsource-case-upper option
2077 @cindex options, -fsource-case-upper
2078 @item -fsource-case-upper
2079 @cindex -fsource-case-lower option
2080 @cindex options, -fsource-case-lower
2081 @item -fsource-case-lower
2082 @cindex -fsource-case-preserve option
2083 @cindex options, -fsource-case-preserve
2084 @item -fsource-case-preserve
2085 Specify whether source text other than character and Hollerith constants
2086 is to be translated to uppercase, to lowercase, or preserved as is.
2087 @samp{-fsource-case-lower} is the default.
2088
2089 @cindex -fsymbol-case-initcap option
2090 @cindex options, -fsymbol-case-initcap
2091 @item -fsymbol-case-initcap
2092 @cindex -fsymbol-case-upper option
2093 @cindex options, -fsymbol-case-upper
2094 @item -fsymbol-case-upper
2095 @cindex -fsymbol-case-lower option
2096 @cindex options, -fsymbol-case-lower
2097 @item -fsymbol-case-lower
2098 @cindex -fsymbol-case-any option
2099 @cindex options, -fsymbol-case-any
2100 @item -fsymbol-case-any
2101 Specify valid cases for user-defined symbol names.
2102 @samp{-fsymbol-case-any} is the default.
2103
2104 @cindex -fcase-strict-upper option
2105 @cindex options, -fcase-strict-upper
2106 @item -fcase-strict-upper
2107 Same as @samp{-fintrin-case-upper -fmatch-case-upper -fsource-case-preserve
2108 -fsymbol-case-upper}.
2109 (Requires all pertinent source to be in uppercase.)
2110
2111 @cindex -fcase-strict-lower option
2112 @cindex options, -fcase-strict-lower
2113 @item -fcase-strict-lower
2114 Same as @samp{-fintrin-case-lower -fmatch-case-lower -fsource-case-preserve
2115 -fsymbol-case-lower}.
2116 (Requires all pertinent source to be in lowercase.)
2117
2118 @cindex -fcase-initcap option
2119 @cindex options, -fcase-initcap
2120 @item -fcase-initcap
2121 Same as @samp{-fintrin-case-initcap -fmatch-case-initcap -fsource-case-preserve
2122 -fsymbol-case-initcap}.
2123 (Requires all pertinent source to be in initial capitals,
2124 as in @samp{Print *,SqRt(Value)}.)
2125
2126 @cindex -fcase-upper option
2127 @cindex options, -fcase-upper
2128 @item -fcase-upper
2129 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-upper
2130 -fsymbol-case-any}.
2131 (Maps all pertinent source to uppercase.)
2132
2133 @cindex -fcase-lower option
2134 @cindex options, -fcase-lower
2135 @item -fcase-lower
2136 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-lower
2137 -fsymbol-case-any}.
2138 (Maps all pertinent source to lowercase.)
2139
2140 @cindex -fcase-preserve option
2141 @cindex options, -fcase-preserve
2142 @item -fcase-preserve
2143 Same as @samp{-fintrin-case-any -fmatch-case-any -fsource-case-preserve
2144 -fsymbol-case-any}.
2145 (Preserves all case in user-defined symbols,
2146 while allowing any-case matching of intrinsics and keywords.
2147 For example, @samp{call Foo(i,I)} would pass two @emph{different}
2148 variables named @samp{i} and @samp{I} to a procedure named @samp{Foo}.)
2149
2150 @cindex -fbadu77-intrinsics-delete option
2151 @cindex options, -fbadu77-intrinsics-delete
2152 @item -fbadu77-intrinsics-delete
2153 @cindex -fbadu77-intrinsics-hide option
2154 @cindex options, -fbadu77-intrinsics-hide
2155 @item -fbadu77-intrinsics-hide
2156 @cindex -fbadu77-intrinsics-disable option
2157 @cindex options, -fbadu77-intrinsics-disable
2158 @item -fbadu77-intrinsics-disable
2159 @cindex -fbadu77-intrinsics-enable option
2160 @cindex options, -fbadu77-intrinsics-enable
2161 @item -fbadu77-intrinsics-enable
2162 @cindex @code{badu77} intrinsics
2163 @cindex intrinsics, @code{badu77}
2164 Specify status of UNIX intrinsics having inappropriate forms.
2165 @samp{-fbadu77-intrinsics-enable} is the default.
2166 @xref{Intrinsic Groups}.
2167
2168 @cindex -ff2c-intrinsics-delete option
2169 @cindex options, -ff2c-intrinsics-delete
2170 @item -ff2c-intrinsics-delete
2171 @cindex -ff2c-intrinsics-hide option
2172 @cindex options, -ff2c-intrinsics-hide
2173 @item -ff2c-intrinsics-hide
2174 @cindex -ff2c-intrinsics-disable option
2175 @cindex options, -ff2c-intrinsics-disable
2176 @item -ff2c-intrinsics-disable
2177 @cindex -ff2c-intrinsics-enable option
2178 @cindex options, -ff2c-intrinsics-enable
2179 @item -ff2c-intrinsics-enable
2180 @cindex @code{f2c} intrinsics
2181 @cindex intrinsics, @code{f2c}
2182 Specify status of f2c-specific intrinsics.
2183 @samp{-ff2c-intrinsics-enable} is the default.
2184 @xref{Intrinsic Groups}.
2185
2186 @cindex -ff90-intrinsics-delete option
2187 @cindex options, -ff90-intrinsics-delete
2188 @item -ff90-intrinsics-delete
2189 @cindex -ff90-intrinsics-hide option
2190 @cindex options, -ff90-intrinsics-hide
2191 @item -ff90-intrinsics-hide
2192 @cindex -ff90-intrinsics-disable option
2193 @cindex options, -ff90-intrinsics-disable
2194 @item -ff90-intrinsics-disable
2195 @cindex -ff90-intrinsics-enable option
2196 @cindex options, -ff90-intrinsics-enable
2197 @item -ff90-intrinsics-enable
2198 @cindex Fortran 90, intrinsics
2199 @cindex intrinsics, Fortran 90
2200 Specify status of F90-specific intrinsics.
2201 @samp{-ff90-intrinsics-enable} is the default.
2202 @xref{Intrinsic Groups}.
2203
2204 @cindex -fgnu-intrinsics-delete option
2205 @cindex options, -fgnu-intrinsics-delete
2206 @item -fgnu-intrinsics-delete
2207 @cindex -fgnu-intrinsics-hide option
2208 @cindex options, -fgnu-intrinsics-hide
2209 @item -fgnu-intrinsics-hide
2210 @cindex -fgnu-intrinsics-disable option
2211 @cindex options, -fgnu-intrinsics-disable
2212 @item -fgnu-intrinsics-disable
2213 @cindex -fgnu-intrinsics-enable option
2214 @cindex options, -fgnu-intrinsics-enable
2215 @item -fgnu-intrinsics-enable
2216 @cindex Digital Fortran features
2217 @cindex @code{COMPLEX} intrinsics
2218 @cindex intrinsics, @code{COMPLEX}
2219 Specify status of Digital's COMPLEX-related intrinsics.
2220 @samp{-fgnu-intrinsics-enable} is the default.
2221 @xref{Intrinsic Groups}.
2222
2223 @cindex -fmil-intrinsics-delete option
2224 @cindex options, -fmil-intrinsics-delete
2225 @item -fmil-intrinsics-delete
2226 @cindex -fmil-intrinsics-hide option
2227 @cindex options, -fmil-intrinsics-hide
2228 @item -fmil-intrinsics-hide
2229 @cindex -fmil-intrinsics-disable option
2230 @cindex options, -fmil-intrinsics-disable
2231 @item -fmil-intrinsics-disable
2232 @cindex -fmil-intrinsics-enable option
2233 @cindex options, -fmil-intrinsics-enable
2234 @item -fmil-intrinsics-enable
2235 @cindex MIL-STD 1753
2236 @cindex intrinsics, MIL-STD 1753
2237 Specify status of MIL-STD-1753-specific intrinsics.
2238 @samp{-fmil-intrinsics-enable} is the default.
2239 @xref{Intrinsic Groups}.
2240
2241 @cindex -funix-intrinsics-delete option
2242 @cindex options, -funix-intrinsics-delete
2243 @item -funix-intrinsics-delete
2244 @cindex -funix-intrinsics-hide option
2245 @cindex options, -funix-intrinsics-hide
2246 @item -funix-intrinsics-hide
2247 @cindex -funix-intrinsics-disable option
2248 @cindex options, -funix-intrinsics-disable
2249 @item -funix-intrinsics-disable
2250 @cindex -funix-intrinsics-enable option
2251 @cindex options, -funix-intrinsics-enable
2252 @item -funix-intrinsics-enable
2253 @cindex UNIX intrinsics
2254 @cindex intrinsics, UNIX
2255 Specify status of UNIX intrinsics.
2256 @samp{-funix-intrinsics-enable} is the default.
2257 @xref{Intrinsic Groups}.
2258
2259 @cindex -fvxt-intrinsics-delete option
2260 @cindex options, -fvxt-intrinsics-delete
2261 @item -fvxt-intrinsics-delete
2262 @cindex -fvxt-intrinsics-hide option
2263 @cindex options, -fvxt-intrinsics-hide
2264 @item -fvxt-intrinsics-hide
2265 @cindex -fvxt-intrinsics-disable option
2266 @cindex options, -fvxt-intrinsics-disable
2267 @item -fvxt-intrinsics-disable
2268 @cindex -fvxt-intrinsics-enable option
2269 @cindex options, -fvxt-intrinsics-enable
2270 @item -fvxt-intrinsics-enable
2271 @cindex VXT intrinsics
2272 @cindex intrinsics, VXT
2273 Specify status of VXT intrinsics.
2274 @samp{-fvxt-intrinsics-enable} is the default.
2275 @xref{Intrinsic Groups}.
2276
2277 @cindex -ffixed-line-length-@var{n} option
2278 @cindex options, -ffixed-line-length-@var{n}
2279 @item -ffixed-line-length-@var{n}
2280 @cindex source file format
2281 @cindex lines, length
2282 @cindex length of source lines
2283 @cindex fixed form
2284 @cindex limits, lengths of source lines
2285 Set column after which characters are ignored in typical fixed-form
2286 lines in the source file, and through which spaces are assumed (as
2287 if padded to that length) after the ends of short fixed-form lines.
2288
2289 @cindex card image
2290 @cindex extended-source option
2291 Popular values for @var{n} include 72 (the
2292 standard and the default), 80 (card image), and 132 (corresponds
2293 to ``extended-source'' options in some popular compilers).
2294 @var{n} may be @samp{none}, meaning that the entire line is meaningful
2295 and that continued character constants never have implicit spaces appended
2296 to them to fill out the line.
2297 @samp{-ffixed-line-length-0} means the same thing as
2298 @samp{-ffixed-line-length-none}.
2299
2300 @xref{Source Form}, for more information.
2301 @end table
2302
2303 @node Warning Options
2304 @section Options to Request or Suppress Warnings
2305 @cindex options, warnings
2306 @cindex warnings, suppressing
2307 @cindex messages, warning
2308 @cindex suppressing warnings
2309
2310 Warnings are diagnostic messages that report constructions which
2311 are not inherently erroneous but which are risky or suggest there
2312 might have been an error.
2313
2314 You can request many specific warnings with options beginning @samp{-W},
2315 for example @samp{-Wimplicit} to request warnings on implicit
2316 declarations.  Each of these specific warning options also has a
2317 negative form beginning @samp{-Wno-} to turn off warnings;
2318 for example, @samp{-Wno-implicit}.  This manual lists only one of the
2319 two forms, whichever is not the default.
2320
2321 These options control the amount and kinds of warnings produced by GNU
2322 Fortran:
2323
2324 @table @code
2325 @cindex syntax checking
2326 @cindex -fsyntax-only option
2327 @cindex options, -fsyntax-only
2328 @item -fsyntax-only
2329 Check the code for syntax errors, but don't do anything beyond that.
2330
2331 @cindex -pedantic option
2332 @cindex options, -pedantic
2333 @item -pedantic
2334 Issue warnings for uses of extensions to ANSI FORTRAN 77.
2335 @samp{-pedantic} also applies to C-language constructs where they
2336 occur in GNU Fortran source files, such as use of @samp{\e} in a
2337 character constant within a directive like @samp{#include}.
2338
2339 Valid ANSI FORTRAN 77 programs should compile properly with or without
2340 this option.
2341 However, without this option, certain GNU extensions and traditional
2342 Fortran features are supported as well.
2343 With this option, many of them are rejected.
2344
2345 Some users try to use @samp{-pedantic} to check programs for strict ANSI
2346 conformance.
2347 They soon find that it does not do quite what they want---it finds some
2348 non-ANSI practices, but not all.
2349 However, improvements to @code{g77} in this area are welcome.
2350
2351 @cindex -pedantic-errors option
2352 @cindex options, -pedantic-errors
2353 @item -pedantic-errors
2354 Like @samp{-pedantic}, except that errors are produced rather than
2355 warnings.
2356
2357 @cindex -fpedantic option
2358 @cindex options, -fpedantic
2359 @item -fpedantic
2360 Like @samp{-pedantic}, but applies only to Fortran constructs.
2361
2362 @cindex -w option
2363 @cindex options, -w
2364 @item -w
2365 Inhibit all warning messages.
2366
2367 @cindex -Wno-globals option
2368 @cindex options, -Wno-globals
2369 @item -Wno-globals
2370 @cindex global names, warning
2371 @cindex warnings, global names
2372 Inhibit warnings about use of a name as both a global name
2373 (a subroutine, function, or block data program unit, or a
2374 common block) and implicitly as the name of an intrinsic
2375 in a source file.
2376
2377 Also inhibit warnings about inconsistent invocations and/or
2378 definitions of global procedures (function and subroutines).
2379 Such inconsistencies include different numbers of arguments
2380 and different types of arguments.
2381
2382 @cindex -Wimplicit option
2383 @cindex options, -Wimplicit
2384 @item -Wimplicit
2385 @cindex implicit declaration, warning
2386 @cindex warnings, implicit declaration
2387 @cindex -u option
2388 @cindex /WARNINGS=DECLARATIONS switch
2389 @cindex IMPLICIT NONE, similar effect
2390 @cindex effecting IMPLICIT NONE
2391 Warn whenever a variable, array, or function is implicitly
2392 declared.
2393 Has an effect similar to using the @code{IMPLICIT NONE} statement
2394 in every program unit.
2395 (Some Fortran compilers provide this feature by an option
2396 named @samp{-u} or @samp{/WARNINGS=DECLARATIONS}.)
2397
2398 @cindex -Wunused option
2399 @cindex options, -Wunused
2400 @item -Wunused
2401 @cindex unused variables
2402 @cindex variables, unused
2403 Warn whenever a variable is unused aside from its declaration.
2404
2405 @cindex -Wuninitialized option
2406 @cindex options, -Wuninitialized
2407 @item -Wuninitialized
2408 @cindex uninitialized variables
2409 @cindex variables, uninitialized
2410 Warn whenever an automatic variable is used without first being initialized.
2411
2412 These warnings are possible only in optimizing compilation,
2413 because they require data-flow information that is computed only
2414 when optimizing.  If you don't specify @samp{-O}, you simply won't
2415 get these warnings.
2416
2417 These warnings occur only for variables that are candidates for
2418 register allocation.  Therefore, they do not occur for a variable
2419 @c that is declared @code{VOLATILE}, or
2420 whose address is taken, or whose size
2421 is other than 1, 2, 4 or 8 bytes.  Also, they do not occur for
2422 arrays, even when they are in registers.
2423
2424 Note that there might be no warning about a variable that is used only
2425 to compute a value that itself is never used, because such
2426 computations may be deleted by data-flow analysis before the warnings
2427 are printed.
2428
2429 These warnings are made optional because GNU Fortran is not smart
2430 enough to see all the reasons why the code might be correct
2431 despite appearing to have an error.  Here is one example of how
2432 this can happen:
2433
2434 @example
2435 SUBROUTINE DISPAT(J)
2436 IF (J.EQ.1) I=1
2437 IF (J.EQ.2) I=4
2438 IF (J.EQ.3) I=5
2439 CALL FOO(I)
2440 END
2441 @end example
2442
2443 @noindent
2444 If the value of @code{J} is always 1, 2 or 3, then @code{I} is
2445 always initialized, but GNU Fortran doesn't know this.  Here is
2446 another common case:
2447
2448 @example
2449 SUBROUTINE MAYBE(FLAG)
2450 LOGICAL FLAG
2451 IF (FLAG) VALUE = 9.4
2452 @dots{}
2453 IF (FLAG) PRINT *, VALUE
2454 END
2455 @end example
2456
2457 @noindent
2458 This has no bug because @code{VALUE} is used only if it is set.
2459
2460 @cindex -Wall option
2461 @cindex options, -Wall
2462 @item -Wall
2463 @cindex all warnings
2464 @cindex warnings, all
2465 The @samp{-Wunused} and @samp{-Wuninitialized} options combined.
2466 These are all the
2467 options which pertain to usage that we recommend avoiding and that we
2468 believe is easy to avoid.
2469 (As more warnings are added to @code{g77}, some might
2470 be added to the list enabled by @samp{-Wall}.)
2471 @end table
2472
2473 The remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}
2474 because they warn about constructions that we consider reasonable to
2475 use, on occasion, in clean programs.
2476
2477 @table @code
2478 @c @item -W
2479 @c Print extra warning messages for these events:
2480 @c
2481 @c @itemize @bullet
2482 @c @item
2483 @c If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused
2484 @c arguments.
2485 @c
2486 @c @end itemize
2487 @c
2488 @cindex -Wsurprising option
2489 @cindex options, -Wsurprising
2490 @item -Wsurprising
2491 Warn about ``suspicious'' constructs that are interpreted
2492 by the compiler in a way that might well be surprising to
2493 someone reading the code.
2494 These differences can result in subtle, compiler-dependent
2495 (even machine-dependent) behavioral differences.
2496 The constructs warned about include:
2497
2498 @itemize @bullet
2499 @item
2500 Expressions having two arithmetic operators in a row, such
2501 as @samp{X*-Y}.
2502 Such a construct is nonstandard, and can produce
2503 unexpected results in more complicated situations such
2504 as @samp{X**-Y*Z}.
2505 @code{g77}, along with many other compilers, interprets
2506 this example differently than many programmers, and a few
2507 other compilers.
2508 Specifically, @code{g77} interprets @samp{X**-Y*Z} as
2509 @samp{(X**(-Y))*Z}, while others might think it should
2510 be interpreted as @samp{X**(-(Y*Z))}.
2511
2512 A revealing example is the constant expression @samp{2**-2*1.},
2513 which @code{g77} evaluates to .25, while others might evaluate
2514 it to 0., the difference resulting from the way precedence affects
2515 type promotion.
2516
2517 (The @samp{-fpedantic} option also warns about expressions
2518 having two arithmetic operators in a row.)
2519
2520 @item
2521 Expressions with a unary minus followed by an operand and then
2522 a binary operator other than plus or minus.
2523 For example, @samp{-2**2} produces a warning, because
2524 the precedence is @samp{-(2**2)}, yielding -4, not
2525 @samp{(-2)**2}, which yields 4, and which might represent
2526 what a programmer expects.
2527
2528 An example of an expression producing different results
2529 in a surprising way is @samp{-I*S}, where @var{I} holds
2530 the value @samp{-2147483648} and @var{S} holds @samp{0.5}.
2531 On many systems, negating @var{I} results in the same
2532 value, not a positive number, because it is already the
2533 lower bound of what an @code{INTEGER(KIND=1)} variable can hold.
2534 So, the expression evaluates to a positive number, while
2535 the ``expected'' interpretation, @samp{(-I)*S}, would
2536 evaluate to a negative number.
2537
2538 Even cases such as @samp{-I*J} produce warnings,
2539 even though, in most configurations and situations,
2540 there is no computational difference between the
2541 results of the two interpretations---the purpose
2542 of this warning is to warn about differing interpretations
2543 and encourage a better style of coding, not to identify
2544 only those places where bugs might exist in the user's
2545 code.
2546
2547 @cindex DO statement
2548 @cindex statements, DO
2549 @item
2550 @code{DO} loops with @code{DO} variables that are not
2551 of integral type---that is, using @code{REAL}
2552 variables as loop control variables.
2553 Although such loops can be written to work in the
2554 ``obvious'' way, the way @code{g77} is required by the
2555 Fortran standard to interpret such code is likely to
2556 be quite different from the way many programmers expect.
2557 (This is true of all @code{DO} loops, but the differences
2558 are pronounced for non-integral loop control variables.)
2559
2560 @xref{Loops}, for more information.
2561 @end itemize
2562
2563 @cindex -Werror option
2564 @cindex options, -Werror
2565 @item -Werror
2566 Make all warnings into errors.
2567
2568 @cindex -W option
2569 @cindex options, -W
2570 @item -W
2571 @cindex extra warnings
2572 @cindex warnings, extra
2573 Turns on ``extra warnings'' and, if optimization is specified
2574 via @samp{-O}, the @samp{-Wuninitialized} option.
2575 (This might change in future versions of @code{g77}.)
2576
2577 ``Extra warnings'' are issued for:
2578
2579 @itemize @bullet
2580 @item
2581 @cindex unused parameters
2582 @cindex parameters, unused
2583 @cindex unused arguments
2584 @cindex arguments, unused
2585 @cindex unused dummies
2586 @cindex dummies, unused
2587 Unused parameters to a procedure (when @samp{-Wunused} also is
2588 specified).
2589
2590 @item
2591 @cindex overflow
2592 Overflows involving floating-point constants (not available
2593 for certain configurations).
2594 @end itemize
2595 @end table
2596
2597 @xref{Warning Options,,Options to Request or Suppress Warnings,
2598 gcc,Using and Porting GNU CC}, for information on more options offered
2599 by the GBE shared by @code{g77}, @code{gcc}, and other GNU compilers.
2600
2601 Some of these have no effect when compiling programs written in Fortran:
2602
2603 @table @code
2604 @cindex -Wcomment option
2605 @cindex options, -Wcomment
2606 @item -Wcomment
2607 @cindex -Wformat option
2608 @cindex options, -Wformat
2609 @item -Wformat
2610 @cindex -Wparentheses option
2611 @cindex options, -Wparentheses
2612 @item -Wparentheses
2613 @cindex -Wswitch option
2614 @cindex options, -Wswitch
2615 @item -Wswitch
2616 @cindex -Wtraditional option
2617 @cindex options, -Wtraditional
2618 @item -Wtraditional
2619 @cindex -Wshadow option
2620 @cindex options, -Wshadow
2621 @item -Wshadow
2622 @cindex -Wid-clash-@var{len} option
2623 @cindex options, -Wid-clash-@var{len}
2624 @item -Wid-clash-@var{len}
2625 @cindex -Wlarger-than-@var{len} option
2626 @cindex options, -Wlarger-than-@var{len}
2627 @item -Wlarger-than-@var{len}
2628 @cindex -Wconversion option
2629 @cindex options, -Wconversion
2630 @item -Wconversion
2631 @cindex -Waggregate-return option
2632 @cindex options, -Waggregate-return
2633 @item -Waggregate-return
2634 @cindex -Wredundant-decls option
2635 @cindex options, -Wredundant-decls
2636 @item -Wredundant-decls
2637 @cindex unsupported warnings
2638 @cindex warnings, unsupported
2639 These options all could have some relevant meaning for
2640 GNU Fortran programs, but are not yet supported.
2641 @end table
2642
2643 @node Debugging Options
2644 @section Options for Debugging Your Program or GNU Fortran
2645 @cindex options, debugging
2646 @cindex debugging information options
2647
2648 GNU Fortran has various special options that are used for debugging
2649 either your program or @code{g77}.
2650
2651 @table @code
2652 @cindex -g option
2653 @cindex options, -g
2654 @item -g
2655 Produce debugging information in the operating system's native format
2656 (stabs, COFF, XCOFF, or DWARF).  GDB can work with this debugging
2657 information.
2658
2659 @cindex common blocks
2660 @cindex equivalence areas
2661 @cindex missing debug features
2662 Support for this option in Fortran programs is incomplete.
2663 In particular, names of variables and arrays in common blocks
2664 or that are storage-associated via @code{EQUIVALENCE} are
2665 unavailable to the debugger.
2666
2667 However, version 0.5.19 of @code{g77} does provide this information
2668 in a rudimentary way, as controlled by the
2669 @samp{-fdebug-kludge} option.
2670
2671 @xref{Code Gen Options,,Options for Code Generation Conventions},
2672 for more information.
2673 @end table
2674
2675 @xref{Debugging Options,,Options for Debugging Your Program or GNU CC,
2676 gcc,Using and Porting GNU CC}, for more information on debugging options.
2677
2678 @node Optimize Options
2679 @section Options That Control Optimization
2680 @cindex optimize options
2681 @cindex options, optimization
2682
2683 Most Fortran users will want to use no optimization when
2684 developing and testing programs, and use @samp{-O} or @samp{-O2} when
2685 compiling programs for late-cycle testing and for production use.
2686 However, note that certain diagnostics---such as for uninitialized
2687 variables---depend on the flow analysis done by @samp{-O}, i.e.@: you
2688 must use @samp{-O} or @samp{-O2} to get such diagnostics.
2689
2690 The following flags have particular applicability when
2691 compiling Fortran programs:
2692
2693 @table @code
2694 @cindex -malign-double option
2695 @cindex options, -malign-double
2696 @item -malign-double
2697 (Intel x86 architecture only.)
2698
2699 Noticeably improves performance of @code{g77} programs making
2700 heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data
2701 on some systems.
2702 In particular, systems using Pentium, Pentium Pro, 586, and
2703 686 implementations
2704 of the i386 architecture execute programs faster when
2705 @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}) data are
2706 aligned on 64-bit boundaries
2707 in memory.
2708
2709 This option can, at least, make benchmark results more consistent
2710 across various system configurations, versions of the program,
2711 and data sets.
2712
2713 @emph{Note:} The warning in the @code{gcc} documentation about
2714 this option does not apply, generally speaking, to Fortran
2715 code compiled by @code{g77}.
2716
2717 @xref{Aligned Data}, for more information on alignment issues.
2718
2719 @emph{Also also note:} The negative form of @samp{-malign-double}
2720 is @samp{-mno-align-double}, not @samp{-benign-double}.
2721
2722 @cindex -ffloat-store option
2723 @cindex options, -ffloat-store
2724 @item -ffloat-store
2725 @cindex IEEE 754 conformance
2726 @cindex conformance, IEEE 754
2727 @cindex floating-point, precision
2728 Might help a Fortran program that depends on exact IEEE conformance on
2729 some machines, but might slow down a program that doesn't.
2730
2731 This option is effective when the floating-point unit is set to work in
2732 IEEE 854 `extended precision'---as it typically is on x86 and m68k GNU
2733 systems---rather than IEEE 754 double precision.  @samp{-ffloat-store}
2734 tries to remove the extra precision by spilling data from floating-point
2735 registers into memory and this typically involves a big performance
2736 hit.  However, it doesn't affect intermediate results, so that it is
2737 only partially effective.  `Excess precision' is avoided in code like:
2738 @smallexample
2739 a = b + c
2740 d = a * e
2741 @end smallexample
2742 but not in code like:
2743 @smallexample
2744       d = (b + c) * e
2745 @end smallexample
2746
2747 For another, potentially better, way of controlling the precision,
2748 see @ref{Floating-point precision}.
2749
2750 @cindex -fforce-mem option
2751 @cindex options, -fforce-mem
2752 @item -fforce-mem
2753 @cindex -fforce-addr option
2754 @cindex options, -fforce-addr
2755 @item -fforce-addr
2756 @cindex loops, speeding up
2757 @cindex speed, of loops
2758 Might improve optimization of loops.
2759
2760 @cindex -fno-inline option
2761 @cindex options, -fno-inline
2762 @item -fno-inline
2763 @cindex in-line code
2764 @cindex compilation, in-line
2765 @c DL: Only relevant for -O3?
2766 Don't compile statement functions inline.
2767 Might reduce the size of a program unit---which might be at
2768 expense of some speed (though it should compile faster).
2769 Note that if you are not optimizing, no functions can be expanded inline.
2770
2771 @cindex -ffast-math option
2772 @cindex options, -ffast-math
2773 @item -ffast-math
2774 @cindex IEEE 754 conformance
2775 @cindex conformance, IEEE 754
2776 Might allow some programs designed to not be too dependent
2777 on IEEE behavior for floating-point to run faster, or die trying.
2778
2779 @cindex -fstrength-reduce option
2780 @cindex options, -fstrength-reduce
2781 @item -fstrength-reduce
2782 @cindex loops, speeding up
2783 @cindex speed, of loops
2784 @c DL: normally defaulted?
2785 Might make some loops run faster.
2786
2787 @cindex -frerun-cse-after-loop option
2788 @cindex options, -frerun-cse-after-loop
2789 @item -frerun-cse-after-loop
2790 @cindex -fexpensive-optimizations option
2791 @cindex options, -fexpensive-optimizations
2792 @c DL: This is -O2?
2793 @item -fexpensive-optimizations
2794 @cindex -fdelayed-branch option
2795 @cindex options, -fdelayed-branch
2796 @item -fdelayed-branch
2797 @cindex -fschedule-insns option
2798 @cindex options, -fschedule-insns
2799 @item -fschedule-insns
2800 @cindex -fschedule-insns2 option
2801 @cindex options, -fschedule-insns2
2802 @item -fschedule-insns2
2803 @cindex -fcaller-saves option
2804 @cindex options, -fcaller-saves
2805 @item -fcaller-saves
2806 Might improve performance on some code.
2807
2808 @cindex -funroll-loops option
2809 @cindex options, -funroll-loops
2810 @item -funroll-loops
2811 @cindex loops, unrolling
2812 @cindex unrolling loops
2813 @cindex loops, optimizing
2814 @cindex indexed (iterative) @code{DO}
2815 @cindex iterative @code{DO}
2816 @c DL: fixme: Craig doesn't like `indexed' but f95 doesn't seem to
2817 @c provide a suitable term
2818 @c CB: I've decided on `iterative', for the time being, and changed
2819 @c my previous, rather bizarre, use of `imperative' to that
2820 @c (though `precomputed-trip' would be a more precise adjective)
2821 Typically improves performance on code using iterative @code{DO} loops by
2822 unrolling them and is probably generally appropriate for Fortran, though
2823 it is not turned on at any optimization level.
2824 Note that outer loop unrolling isn't done specifically; decisions about
2825 whether to unroll a loop are made on the basis of its instruction count.
2826
2827 @c DL: Fixme: This should obviously go somewhere else...
2828 Also, no `loop discovery'@footnote{@dfn{loop discovery} refers to the
2829 process by which a compiler, or indeed any reader of a program,
2830 determines which portions of the program are more likely to be executed
2831 repeatedly as it is being run.  Such discovery typically is done early
2832 when compiling using optimization techniques, so the ``discovered''
2833 loops get more attention---and more run-time resources, such as
2834 registers---from the compiler.  It is easy to ``discover'' loops that are
2835 constructed out of looping constructs in the language
2836 (such as Fortran's @code{DO}).  For some programs, ``discovering'' loops
2837 constructed out of lower-level constructs (such as @code{IF} and
2838 @code{GOTO}) can lead to generation of more optimal code
2839 than otherwise.} is done, so only loops written with @code{DO}
2840 benefit from loop optimizations, including---but not limited
2841 to---unrolling.  Loops written with @code{IF} and @code{GOTO} are not
2842 currently recognized as such.  This option unrolls only iterative
2843 @code{DO} loops, not @code{DO WHILE} loops.
2844
2845 @cindex -funroll-all-loops option
2846 @cindex options, -funroll-all-loops
2847 @cindex DO WHILE
2848 @item -funroll-all-loops
2849 @c DL: Check my understanding of -funroll-all-loops v. -funroll-loops is correct.
2850 Probably improves performance on code using @code{DO WHILE} loops by
2851 unrolling them in addition to iterative @code{DO} loops.  In the absence
2852 of @code{DO WHILE}, this option is equivalent to @samp{-funroll-loops}
2853 but possibly slower.
2854
2855 @item -fno-move-all-movables
2856 @cindex -fno-move-all-movables option
2857 @cindex options, -fno-move-all-movables
2858 @item -fno-reduce-all-givs
2859 @cindex -fno-reduce-all-givs option
2860 @cindex options, -fno-reduce-all-givs
2861 @item -fno-rerun-loop-opt
2862 @cindex -fno-rerun-loop-opt option
2863 @cindex options, -fno-rerun-loop-opt
2864 @emph{Version info:}
2865 These options are not supported by
2866 versions of @code{g77} based on @code{gcc} version 2.8.
2867
2868 Each of these might improve performance on some code.
2869
2870 Analysis of Fortran code optimization and the resulting
2871 optimizations triggered by the above options were
2872 contributed by Toon Moene (@email{toon@@moene.indiv.nluug.nl}).
2873
2874 These three options are intended to be removed someday, once
2875 they have helped determine the efficacy of various
2876 approaches to improving the performance of Fortran code.
2877
2878 Please let us know how use of these options affects
2879 the performance of your production code.
2880 We're particularly interested in code that runs faster
2881 when these options are @emph{disabled}, and in
2882 non-Fortran code that benefits when they are
2883 @emph{enabled} via the above @code{gcc} command-line options.
2884 @end table
2885
2886 @xref{Optimize Options,,Options That Control Optimization,
2887 gcc,Using and Porting GNU CC}, for more information on options
2888 to optimize the generated machine code.
2889
2890 @node Preprocessor Options
2891 @section Options Controlling the Preprocessor
2892 @cindex preprocessor options
2893 @cindex options, preprocessor
2894 @cindex cpp program
2895 @cindex programs, cpp
2896
2897 These options control the C preprocessor, which is run on each C source
2898 file before actual compilation.
2899
2900 @xref{Preprocessor Options,,Options Controlling the Preprocessor,
2901 gcc,Using and Porting GNU CC}, for information on C preprocessor options.
2902
2903 @cindex INCLUDE directive
2904 @cindex directive, INCLUDE
2905 Some of these options also affect how @code{g77} processes the
2906 @code{INCLUDE} directive.
2907 Since this directive is processed even when preprocessing
2908 is not requested, it is not described in this section.
2909 @xref{Directory Options,,Options for Directory Search}, for
2910 information on how @code{g77} processes the @code{INCLUDE} directive.
2911
2912 However, the @code{INCLUDE} directive does not apply
2913 preprocessing to the contents of the included file itself.
2914
2915 Therefore, any file that contains preprocessor directives
2916 (such as @code{#include}, @code{#define}, and @code{#if})
2917 must be included via the @code{#include} directive, not
2918 via the @code{INCLUDE} directive.
2919 Therefore, any file containing preprocessor directives,
2920 if included, is necessarily included by a file that itself
2921 contains preprocessor directives.
2922
2923 @node Directory Options
2924 @section Options for Directory Search
2925 @cindex directory, options
2926 @cindex options, directory search
2927 @cindex search path
2928
2929 These options affect how the @code{cpp} preprocessor searches
2930 for files specified via the @code{#include} directive.
2931 Therefore, when compiling Fortran programs, they are meaningful
2932 when the preprocessor is used.
2933
2934 @cindex INCLUDE directive
2935 @cindex directive, INCLUDE
2936 Some of these options also affect how @code{g77} searches
2937 for files specified via the @code{INCLUDE} directive,
2938 although files included by that directive are not,
2939 themselves, preprocessed.
2940 These options are:
2941
2942 @table @code
2943 @cindex -I- option
2944 @cindex options, -I-
2945 @item -I-
2946 @cindex -Idir option
2947 @cindex options, -Idir
2948 @item -I@var{dir}
2949 @cindex directory, search paths for inclusion
2950 @cindex inclusion, directory search paths for
2951 @cindex search paths, for included files
2952 @cindex paths, search
2953 These affect interpretation of the @code{INCLUDE} directive
2954 (as well as of the @code{#include} directive of the @code{cpp}
2955 preprocessor).
2956
2957 Note that @samp{-I@var{dir}} must be specified @emph{without} any
2958 spaces between @samp{-I} and the directory name---that is,
2959 @samp{-Ifoo/bar} is valid, but @samp{-I foo/bar}
2960 is rejected by the @code{g77} compiler (though the preprocessor supports
2961 the latter form).
2962 @c this is due to toplev.c's inflexible option processing
2963 Also note that the general behavior of @samp{-I} and
2964 @code{INCLUDE} is pretty much the same as of @samp{-I} with
2965 @code{#include} in the @code{cpp} preprocessor, with regard to
2966 looking for @file{header.gcc} files and other such things.
2967
2968 @xref{Directory Options,,Options for Directory Search,
2969 gcc,Using and Porting GNU CC}, for information on the @samp{-I} option.
2970 @end table
2971
2972 @node Code Gen Options
2973 @section Options for Code Generation Conventions
2974 @cindex code generation, conventions
2975 @cindex options, code generation
2976 @cindex run-time, options
2977
2978 These machine-independent options control the interface conventions
2979 used in code generation.
2980
2981 Most of them have both positive and negative forms; the negative form
2982 of @samp{-ffoo} would be @samp{-fno-foo}.  In the table below, only
2983 one of the forms is listed---the one which is not the default.  You
2984 can figure out the other form by either removing @samp{no-} or adding
2985 it.
2986
2987 @table @code
2988 @cindex -fno-automatic option
2989 @cindex options, -fno-automatic
2990 @item -fno-automatic
2991 @cindex SAVE statement
2992 @cindex statements, SAVE
2993 Treat each program unit as if the @code{SAVE} statement was specified
2994 for every local variable and array referenced in it.
2995 Does not affect common blocks.
2996 (Some Fortran compilers provide this option under
2997 the name @samp{-static}.)
2998
2999 @cindex -finit-local-zero option
3000 @cindex options, -finit-local-zero
3001 @item -finit-local-zero
3002 @cindex DATA statement
3003 @cindex statements, DATA
3004 @cindex initialization, of local variables
3005 @cindex variables, initialization of
3006 @cindex uninitialized variables
3007 @cindex variables, uninitialized
3008 Specify that variables and arrays that are local to a program unit
3009 (not in a common block and not passed as an argument) are to be initialized
3010 to binary zeros.
3011
3012 Since there is a run-time penalty for initialization of variables
3013 that are not given the @code{SAVE} attribute, it might be a
3014 good idea to also use @samp{-fno-automatic} with @samp{-finit-local-zero}.
3015
3016 @cindex -fno-f2c option
3017 @cindex options, -fno-f2c
3018 @item -fno-f2c
3019 @cindex @code{f2c} compatibility
3020 @cindex compatibility, @code{f2c}
3021 Do not generate code designed to be compatible with code generated
3022 by @code{f2c}; use the GNU calling conventions instead.
3023
3024 The @code{f2c} calling conventions require functions that return
3025 type @code{REAL(KIND=1)} to actually return the C type @code{double},
3026 and functions that return type @code{COMPLEX} to return the
3027 values via an extra argument in the calling sequence that points
3028 to where to store the return value.
3029 Under the GNU calling conventions, such functions simply return
3030 their results as they would in GNU C---@code{REAL(KIND=1)} functions
3031 return the C type @code{float}, and @code{COMPLEX} functions
3032 return the GNU C type @code{complex} (or its @code{struct}
3033 equivalent).
3034
3035 This does not affect the generation of code that interfaces with the
3036 @code{libg2c} library.
3037
3038 However, because the @code{libg2c} library uses @code{f2c}
3039 calling conventions, @code{g77} rejects attempts to pass
3040 intrinsics implemented by routines in this library as actual
3041 arguments when @samp{-fno-f2c} is used, to avoid bugs when
3042 they are actually called by code expecting the GNU calling
3043 conventions to work.
3044
3045 For example, @samp{INTRINSIC ABS;CALL FOO(ABS)} is
3046 rejected when @samp{-fno-f2c} is in force.
3047 (Future versions of the @code{g77} run-time library might
3048 offer routines that provide GNU-callable versions of the
3049 routines that implement the @code{f2c}-callable intrinsics
3050 that may be passed as actual arguments, so that
3051 valid programs need not be rejected when @samp{-fno-f2c}
3052 is used.)
3053
3054 @strong{Caution:} If @samp{-fno-f2c} is used when compiling any
3055 source file used in a program, it must be used when compiling
3056 @emph{all} Fortran source files used in that program.
3057
3058 @c seems kinda dumb to tell people about an option they can't use -- jcb
3059 @c then again, we want users building future-compatible libraries with it.
3060 @cindex -ff2c-library option
3061 @cindex options, -ff2c-library
3062 @item -ff2c-library
3063 Specify that use of @code{libg2c} (or the original @code{libf2c})
3064 is required.
3065 This is the default for the current version of @code{g77}.
3066
3067 Currently it is not
3068 valid to specify @samp{-fno-f2c-library}.
3069 This option is provided so users can specify it in shell
3070 scripts that build programs and libraries that require the
3071 @code{libf2c} library, even when being compiled by future
3072 versions of @code{g77} that might otherwise default to
3073 generating code for an incompatible library.
3074
3075 @cindex -fno-underscoring option
3076 @cindex options, -fno-underscoring
3077 @item -fno-underscoring
3078 @cindex underscore
3079 @cindex symbol names, underscores
3080 @cindex transforming symbol names
3081 @cindex symbol names, transforming
3082 Do not transform names of entities specified in the Fortran
3083 source file by appending underscores to them.
3084
3085 With @samp{-funderscoring} in effect, @code{g77} appends two underscores
3086 to names with underscores and one underscore to external names with
3087 no underscores.  (@code{g77} also appends two underscores to internal
3088 names with underscores to avoid naming collisions with external names.
3089 The @samp{-fno-second-underscore} option disables appending of the
3090 second underscore in all cases.)
3091
3092 This is done to ensure compatibility with code produced by many
3093 UNIX Fortran compilers, including @code{f2c}, which perform the
3094 same transformations.
3095
3096 Use of @samp{-fno-underscoring} is not recommended unless you are
3097 experimenting with issues such as integration of (GNU) Fortran into
3098 existing system environments (vis-a-vis existing libraries, tools, and
3099 so on).
3100
3101 For example, with @samp{-funderscoring}, and assuming other defaults like
3102 @samp{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
3103 external functions while @samp{my_var} and @samp{lvar} are local variables,
3104 a statement like
3105
3106 @smallexample
3107 I = J() + MAX_COUNT (MY_VAR, LVAR)
3108 @end smallexample
3109
3110 @noindent
3111 is implemented as something akin to:
3112
3113 @smallexample
3114 i = j_() + max_count__(&my_var__, &lvar);
3115 @end smallexample
3116
3117 With @samp{-fno-underscoring}, the same statement is implemented as:
3118
3119 @smallexample
3120 i = j() + max_count(&my_var, &lvar);
3121 @end smallexample
3122
3123 Use of @samp{-fno-underscoring} allows direct specification of
3124 user-defined names while debugging and when interfacing @code{g77}-compiled
3125 code with other languages.
3126
3127 Note that just because the names match does @emph{not} mean that the
3128 interface implemented by @code{g77} for an external name matches the
3129 interface implemented by some other language for that same name.
3130 That is, getting code produced by @code{g77} to link to code produced
3131 by some other compiler using this or any other method can be only a
3132 small part of the overall solution---getting the code generated by
3133 both compilers to agree on issues other than naming can require
3134 significant effort, and, unlike naming disagreements, linkers normally
3135 cannot detect disagreements in these other areas.
3136
3137 Also, note that with @samp{-fno-underscoring}, the lack of appended
3138 underscores introduces the very real possibility that a user-defined
3139 external name will conflict with a name in a system library, which
3140 could make finding unresolved-reference bugs quite difficult in some
3141 cases---they might occur at program run time, and show up only as
3142 buggy behavior at run time.
3143
3144 In future versions of @code{g77}, we hope to improve naming and linking
3145 issues so that debugging always involves using the names as they appear
3146 in the source, even if the names as seen by the linker are mangled to
3147 prevent accidental linking between procedures with incompatible
3148 interfaces.
3149
3150 @cindex -fno-second-underscore option
3151 @cindex options, -fno-second-underscore
3152 @item -fno-second-underscore
3153 @cindex underscore
3154 @cindex symbol names, underscores
3155 @cindex transforming symbol names
3156 @cindex symbol names, transforming
3157 Do not append a second underscore to names of entities specified
3158 in the Fortran source file.
3159
3160 This option has no effect if @samp{-fno-underscoring} is
3161 in effect.
3162
3163 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
3164 is implemented as a reference to the link-time external symbol
3165 @samp{max_count_}, instead of @samp{max_count__}.
3166
3167 @cindex -fno-ident option
3168 @cindex options, -fno-ident
3169 @item -fno-ident
3170 Ignore the @samp{#ident} directive.
3171
3172 @cindex -fzeros option
3173 @cindex options, -fzeros
3174 @item -fzeros
3175 Treat initial values of zero as if they were any other value.
3176
3177 As of version 0.5.18, @code{g77} normally treats @code{DATA} and
3178 other statements that are used to specify initial values of zero
3179 for variables and arrays as if no values were actually specified,
3180 in the sense that no diagnostics regarding multiple initializations
3181 are produced.
3182
3183 This is done to speed up compiling of programs that initialize
3184 large arrays to zeros.
3185
3186 Use @samp{-fzeros} to revert to the simpler, slower behavior
3187 that can catch multiple initializations by keeping track of
3188 all initializations, zero or otherwise.
3189
3190 @emph{Caution:} Future versions of @code{g77} might disregard this option
3191 (and its negative form, the default) or interpret it somewhat
3192 differently.
3193 The interpretation changes will affect only non-standard
3194 programs; standard-conforming programs should not be affected.
3195
3196 @cindex -fdebug-kludge option
3197 @cindex options, -fdebug-kludge
3198 @item -fdebug-kludge
3199 Emit information on @code{COMMON} and @code{EQUIVALENCE} members
3200 that might help users of debuggers work around lack of proper debugging
3201 information on such members.
3202
3203 As of version 0.5.19, @code{g77} offers this option to emit
3204 information on members of aggregate areas to help users while debugging.
3205 This information consists of establishing the type and contents of each
3206 such member so that, when a debugger is asked to print the contents,
3207 the printed information provides rudimentary debugging information.
3208 This information identifies the name of the aggregate area (either the
3209 @code{COMMON} block name, or the @code{g77}-assigned name for the
3210 @code{EQUIVALENCE} name) and the offset, in bytes, of the member from
3211 the beginning of the area.
3212
3213 Using @code{gdb}, this information is not coherently displayed in the Fortran
3214 language mode, so temporarily switching to the C language mode to display the
3215 information is suggested.
3216 Use @samp{set language c} and @samp{set language fortran} to accomplish this.
3217
3218 For example:
3219
3220 @smallexample
3221       COMMON /X/A,B
3222       EQUIVALENCE (C,D)
3223       CHARACTER XX*50
3224       EQUIVALENCE (I,XX(20:20))
3225       END
3226
3227 GDB is free software and you are welcome to distribute copies of it
3228  under certain conditions; type "show copying" to see the conditions.
3229 There is absolutely no warranty for GDB; type "show warranty" for details.
3230 GDB 4.16 (lm-gnits-dwim), Copyright 1996 Free Software Foundation, Inc...
3231 (gdb) b MAIN__
3232 Breakpoint 1 at 0t1200000201120112: file cd.f, line 5.
3233 (gdb) r
3234 Starting program: /home/user/a.out
3235
3236 Breakpoint 1, MAIN__ () at cd.f:5
3237 Current language:  auto; currently fortran
3238 (gdb) set language c
3239 Warning: the current language does not match this frame.
3240 (gdb) p a
3241 $2 = "At (COMMON) `x_' plus 0 bytes"
3242 (gdb) p b
3243 $3 = "At (COMMON) `x_' plus 4 bytes"
3244 (gdb) p c
3245 $4 = "At (EQUIVALENCE) `__g77_equiv_c' plus 0 bytes"
3246 (gdb) p d
3247 $5 = "At (EQUIVALENCE) `__g77_equiv_c' plus 0 bytes"
3248 (gdb) p i
3249 $6 = "At (EQUIVALENCE) `__g77_equiv_xx' plus 20 bytes"
3250 (gdb) p xx
3251 $7 = "At (EQUIVALENCE) `__g77_equiv_xx' plus 1 bytes"
3252 (gdb) set language fortran
3253 (gdb)
3254 @end smallexample
3255
3256 @noindent
3257 Use @samp{-fdebug-kludge} to generate this information,
3258 which might make some programs noticeably larger.
3259
3260 @emph{Caution:} Future versions of @code{g77} might disregard this option
3261 (and its negative form).
3262 Current plans call for this to happen when published versions of @code{g77}
3263 and @code{gdb} exist that provide proper access to debugging information on
3264 @code{COMMON} and @code{EQUIVALENCE} members.
3265
3266 @cindex -femulate-complex option
3267 @cindex options, -femulate-complex
3268 @item -femulate-complex
3269 Implement @code{COMPLEX} arithmetic via emulation,
3270 instead of using the facilities of
3271 the @code{gcc} back end that provide direct support of
3272 @code{complex} arithmetic.
3273
3274 (@code{gcc} had some bugs in its back-end support
3275 for @code{complex} arithmetic, due primarily to the support not being
3276 completed as of version 2.8.1 and @code{egcs} 1.1.2.)
3277
3278 Use @samp{-femulate-complex} if you suspect code-generation bugs,
3279 or experience compiler crashes,
3280 that might result from @code{g77} using the @code{COMPLEX} support
3281 in the @code{gcc} back end.
3282 If using that option fixes the bugs or crashes you are seeing,
3283 that indicates a likely @code{g77} bugs
3284 (though, all compiler crashes are considered bugs),
3285 so, please report it.
3286 (Note that the known bugs, now believed fixed, produced compiler crashes
3287 rather than causing the generation of incorrect code.)
3288
3289 Use of this option should not affect how Fortran code compiled
3290 by @code{g77} works in terms of its interfaces to other code,
3291 e.g. that compiled by @code{f2c}.
3292
3293 @emph{Caution:} Future versions of @code{g77} might ignore both forms
3294 of this option.
3295
3296 @cindex -falias-check option
3297 @cindex options, -falias-check
3298 @cindex -fargument-alias option
3299 @cindex options, -fargument-alias
3300 @cindex -fargument-noalias option
3301 @cindex options, -fargument-noalias
3302 @cindex -fno-argument-noalias-global option
3303 @cindex options, -fno-argument-noalias-global
3304 @item -falias-check
3305 @item -fargument-alias
3306 @item -fargument-noalias
3307 @item -fno-argument-noalias-global
3308 @emph{Version info:}
3309 These options are not supported by
3310 versions of @code{g77} based on @code{gcc} version 2.8.
3311
3312 These options specify to what degree aliasing
3313 (overlap)
3314 is permitted between
3315 arguments (passed as pointers) and @code{COMMON} (external, or
3316 public) storage.
3317
3318 The default for Fortran code, as mandated by the FORTRAN 77 and
3319 Fortran 90 standards, is @samp{-fargument-noalias-global}.
3320 The default for code written in the C language family is
3321 @samp{-fargument-alias}.
3322
3323 Note that, on some systems, compiling with @samp{-fforce-addr} in
3324 effect can produce more optimal code when the default aliasing
3325 options are in effect (and when optimization is enabled).
3326
3327 @xref{Aliasing Assumed To Work}, for detailed information on the implications
3328 of compiling Fortran code that depends on the ability to alias dummy
3329 arguments.
3330
3331 @cindex -fno-globals option
3332 @cindex options, -fno-globals
3333 @item -fno-globals
3334 @cindex global names, warning
3335 @cindex warnings, global names
3336 @cindex in-line code
3337 @cindex compilation, in-line
3338 Disable diagnostics about inter-procedural
3339 analysis problems, such as disagreements about the
3340 type of a function or a procedure's argument,
3341 that might cause a compiler crash when attempting
3342 to inline a reference to a procedure within a
3343 program unit.
3344 (The diagnostics themselves are still produced, but
3345 as warnings, unless @samp{-Wno-globals} is specified,
3346 in which case no relevant diagnostics are produced.)
3347
3348 Further, this option disables such inlining, to
3349 avoid compiler crashes resulting from incorrect
3350 code that would otherwise be diagnosed.
3351
3352 As such, this option might be quite useful when
3353 compiling existing, ``working'' code that happens
3354 to have a few bugs that do not generally show themselves,
3355 but which @code{g77} diagnoses.
3356
3357 Use of this option therefore has the effect of
3358 instructing @code{g77} to behave more like it did
3359 up through version 0.5.19.1, when it paid little or
3360 no attention to disagreements between program units
3361 about a procedure's type and argument information,
3362 and when it performed no inlining of procedures
3363 (except statement functions).
3364
3365 Without this option, @code{g77} defaults to performing
3366 the potentially inlining procedures as it started doing
3367 in version 0.5.20, but as of version 0.5.21, it also
3368 diagnoses disagreements that might cause such inlining
3369 to crash the compiler as (fatal) errors,
3370 and warns about similar disagreements
3371 that are currently believed to not
3372 likely to result in the compiler later crashing
3373 or producing incorrect code.
3374
3375 @cindex -fflatten-arrays option
3376 @item -fflatten-arrays
3377 @cindex array performance
3378 @cindex arrays, flattening
3379 Use back end's C-like constructs
3380 (pointer plus offset)
3381 instead of its @code{ARRAY_REF} construct
3382 to handle all array references.
3383
3384 @emph{Note:} This option is not supported.
3385 It is intended for use only by @code{g77} developers,
3386 to evaluate code-generation issues.
3387 It might be removed at any time.
3388
3389 @cindex -fbounds-check option
3390 @cindex -ffortran-bounds-check option
3391 @item -fbounds-check
3392 @itemx -ffortran-bounds-check
3393 @cindex bounds checking
3394 @cindex range checking
3395 @cindex array bounds checking
3396 @cindex subscript checking
3397 @cindex substring checking
3398 @cindex checking subscripts
3399 @cindex checking substrings
3400 Enable generation of run-time checks for array subscripts
3401 and substring start and end points
3402 against the (locally) declared minimum and maximum values.
3403
3404 The current implementation uses the @code{libf2c}
3405 library routine @code{s_rnge} to print the diagnostic.
3406
3407 However, whereas @code{f2c} generates a single check per
3408 reference for a multi-dimensional array, of the computed
3409 offset against the valid offset range (0 through the size of the array),
3410 @code{g77} generates a single check per @emph{subscript} expression.
3411 This catches some cases of potential bugs that @code{f2c} does not,
3412 such as references to below the beginning of an assumed-size array.
3413
3414 @code{g77} also generates checks for @code{CHARACTER} substring references,
3415 something @code{f2c} currently does not do.
3416
3417 Use the new @samp{-ffortran-bounds-check} option
3418 to specify bounds-checking for only the Fortran code you are compiling,
3419 not necessarily for code written in other languages.
3420
3421 @emph{Note:} To provide more detailed information on the offending subscript,
3422 @code{g77} provides the @code{libg2c} run-time library routine @code{s_rnge}
3423 with somewhat differently-formatted information.
3424 Here's a sample diagnostic:
3425
3426 @smallexample
3427 Subscript out of range on file line 4, procedure rnge.f/bf.
3428 Attempt to access the -6-th element of variable b[subscript-2-of-2].
3429 Aborted
3430 @end smallexample
3431
3432 The above message indicates that the offending source line is
3433 line 4 of the file @file{rnge.f},
3434 within the program unit (or statement function) named @samp{bf}.
3435 The offended array is named @samp{b}.
3436 The offended array dimension is the second for a two-dimensional array,
3437 and the offending, computed subscript expression was @samp{-6}.
3438
3439 For a @code{CHARACTER} substring reference, the second line has
3440 this appearance:
3441
3442 @smallexample
3443 Attempt to access the 11-th element of variable a[start-substring].
3444 @end smallexample
3445
3446 This indicates that the offended @code{CHARACTER} variable or array
3447 is named @samp{a},
3448 the offended substring position is the starting (leftmost) position,
3449 and the offending substring expression is @samp{11}.
3450
3451 (Though the verbage of @code{s_rnge} is not ideal
3452 for the purpose of the @code{g77} compiler,
3453 the above information should provide adequate diagnostic abilities
3454 to it users.)
3455 @end table
3456
3457 @xref{Code Gen Options,,Options for Code Generation Conventions,
3458 gcc,Using and Porting GNU CC}, for information on more options
3459 offered by the GBE
3460 shared by @code{g77}, @code{gcc}, and other GNU compilers.
3461
3462 Some of these do @emph{not} work when compiling programs written in Fortran:
3463
3464 @table @code
3465 @cindex -fpcc-struct-return option
3466 @cindex options, -fpcc-struct-return
3467 @item -fpcc-struct-return
3468 @cindex -freg-struct-return option
3469 @cindex options, -freg-struct-return
3470 @item -freg-struct-return
3471 You should not use these except strictly the same way as you
3472 used them to build the version of @code{libg2c} with which
3473 you will be linking all code compiled by @code{g77} with the
3474 same option.
3475
3476 @cindex -fshort-double option
3477 @cindex options, -fshort-double
3478 @item -fshort-double
3479 This probably either has no effect on Fortran programs, or
3480 makes them act loopy.
3481
3482 @cindex -fno-common option
3483 @cindex options, -fno-common
3484 @item -fno-common
3485 Do not use this when compiling Fortran programs,
3486 or there will be Trouble.
3487
3488 @cindex -fpack-struct option
3489 @cindex options, -fpack-struct
3490 @item -fpack-struct
3491 This probably will break any calls to the @code{libg2c} library,
3492 at the very least, even if it is built with the same option.
3493 @end table
3494
3495 @node Environment Variables
3496 @section Environment Variables Affecting GNU Fortran
3497 @cindex environment variables
3498
3499 GNU Fortran currently does not make use of any environment
3500 variables to control its operation above and beyond those
3501 that affect the operation of @code{gcc}.
3502
3503 @xref{Environment Variables,,Environment Variables Affecting GNU CC,
3504 gcc,Using and Porting GNU CC}, for information on environment
3505 variables.
3506
3507 @include news.texi
3508
3509 @set USERVISONLY
3510 @include news.texi
3511 @clear USERVISONLY
3512
3513 @node Language
3514 @chapter The GNU Fortran Language
3515
3516 @cindex standard, ANSI FORTRAN 77
3517 @cindex ANSI FORTRAN 77 standard
3518 @cindex reference works
3519 GNU Fortran supports a variety of extensions to, and dialects
3520 of, the Fortran language.
3521 Its primary base is the ANSI FORTRAN 77 standard, currently available on
3522 the network at
3523 @uref{http://www.fortran.com/fortran/F77_std/rjcnf0001.html}
3524 or as monolithic text at
3525 @uref{http://www.fortran.com/fortran/F77_std/f77_std.html}.
3526 It offers some extensions that are popular among users
3527 of UNIX @code{f77} and @code{f2c} compilers, some that
3528 are popular among users of other compilers (such as Digital
3529 products), some that are popular among users of the
3530 newer Fortran 90 standard, and some that are introduced
3531 by GNU Fortran.
3532
3533 @cindex textbooks
3534 (If you need a text on Fortran,
3535 a few freely available electronic references have pointers from
3536 @uref{http://www.fortran.com/fortran/Books/}.  There is a `cooperative
3537 net project', @cite{User Notes on Fortran Programming} at
3538 @uref{ftp://vms.huji.ac.il/fortran/} and mirrors elsewhere; some of this
3539 material might not apply specifically to @code{g77}.)
3540
3541 Part of what defines a particular implementation of a Fortran
3542 system, such as @code{g77}, is the particular characteristics
3543 of how it supports types, constants, and so on.
3544 Much of this is left up to the implementation by the various
3545 Fortran standards and accepted practice in the industry.
3546
3547 The GNU Fortran @emph{language} is described below.
3548 Much of the material is organized along the same lines
3549 as the ANSI FORTRAN 77 standard itself.
3550
3551 @xref{Other Dialects}, for information on features @code{g77} supports
3552 that are not part of the GNU Fortran language.
3553
3554 @emph{Note}: This portion of the documentation definitely needs a lot
3555 of work!
3556
3557 @menu
3558 Relationship to the ANSI FORTRAN 77 standard:
3559 * Direction of Language Development::  Where GNU Fortran is headed.
3560 * Standard Support::  Degree of support for the standard.
3561
3562 Extensions to the ANSI FORTRAN 77 standard:
3563 * Conformance::
3564 * Notation Used::
3565 * Terms and Concepts::
3566 * Characters Lines Sequence::
3567 * Data Types and Constants::
3568 * Expressions::
3569 * Specification Statements::
3570 * Control Statements::
3571 * Functions and Subroutines::
3572 * Scope and Classes of Names::
3573 * I/O::
3574 * Fortran 90 Features::
3575 @end menu
3576
3577 @node Direction of Language Development
3578 @section Direction of Language Development
3579 @cindex direction of language development
3580 @cindex features, language
3581 @cindex language, features
3582
3583 The purpose of the following description of the GNU Fortran
3584 language is to promote wide portability of GNU Fortran programs.
3585
3586 GNU Fortran is an evolving language, due to the
3587 fact that @code{g77} itself is in beta test.
3588 Some current features of the language might later
3589 be redefined as dialects of Fortran supported by @code{g77}
3590 when better ways to express these features are added to @code{g77},
3591 for example.
3592 Such features would still be supported by
3593 @code{g77}, but would be available only when
3594 one or more command-line options were used.
3595
3596 The GNU Fortran @emph{language} is distinct from the
3597 GNU Fortran @emph{compilation system} (@code{g77}).
3598
3599 For example, @code{g77} supports various dialects of
3600 Fortran---in a sense, these are languages other than
3601 GNU Fortran---though its primary
3602 purpose is to support the GNU Fortran language, which also is
3603 described in its documentation and by its implementation.
3604
3605 On the other hand, non-GNU compilers might offer
3606 support for the GNU Fortran language, and are encouraged
3607 to do so.
3608
3609 Currently, the GNU Fortran language is a fairly fuzzy object.
3610 It represents something of a cross between what @code{g77} accepts
3611 when compiling using the prevailing defaults and what this
3612 document describes as being part of the language.
3613
3614 Future versions of @code{g77} are expected to clarify the
3615 definition of the language in the documentation.
3616 Often, this will mean adding new features to the language, in the form
3617 of both new documentation and new support in @code{g77}.
3618 However, it might occasionally mean removing a feature
3619 from the language itself to ``dialect'' status.
3620 In such a case, the documentation would be adjusted
3621 to reflect the change, and @code{g77} itself would likely be changed
3622 to require one or more command-line options to continue supporting
3623 the feature.
3624
3625 The development of the GNU Fortran language is intended to strike
3626 a balance between:
3627
3628 @itemize @bullet
3629 @item
3630 Serving as a mostly-upwards-compatible language from the
3631 de facto UNIX Fortran dialect as supported by @code{f77}.
3632
3633 @item
3634 Offering new, well-designed language features.
3635 Attributes of such features include
3636 not making existing code any harder to read
3637 (for those who might be unaware that the new
3638 features are not in use) and
3639 not making state-of-the-art
3640 compilers take longer to issue diagnostics,
3641 among others.
3642
3643 @item
3644 Supporting existing, well-written code without gratuitously
3645 rejecting non-standard constructs, regardless of the origin
3646 of the code (its dialect).
3647
3648 @item
3649 Offering default behavior and command-line options to reduce
3650 and, where reasonable, eliminate the need for programmers to make
3651 any modifications to code that already works in existing
3652 production environments.
3653
3654 @item
3655 Diagnosing constructs that have different meanings in different
3656 systems, languages, and dialects, while offering clear,
3657 less ambiguous ways to express each of the different meanings
3658 so programmers can change their code appropriately.
3659 @end itemize
3660
3661 One of the biggest practical challenges for the developers of the
3662 GNU Fortran language is meeting the sometimes contradictory demands
3663 of the above items.
3664
3665 For example, a feature might be widely used in one popular environment,
3666 but the exact same code that utilizes that feature might not work
3667 as expected---perhaps it might mean something entirely different---in
3668 another popular environment.
3669
3670 Traditionally, Fortran compilers---even portable ones---have solved this
3671 problem by simply offering the appropriate feature to users of
3672 the respective systems.
3673 This approach treats users of various Fortran systems and dialects
3674 as remote ``islands'', or camps, of programmers, and assume that these
3675 camps rarely come into contact with each other (or,
3676 especially, with each other's code).
3677
3678 Project GNU takes a radically different approach to software and language
3679 design, in that it assumes that users of GNU software do not necessarily
3680 care what kind of underlying system they are using, regardless
3681 of whether they are using software (at the user-interface
3682 level) or writing it (for example, writing Fortran or C code).
3683
3684 As such, GNU users rarely need consider just what kind of underlying
3685 hardware (or, in many cases, operating system) they are using at any
3686 particular time.
3687 They can use and write software designed for a general-purpose,
3688 widely portable, heterogenous environment---the GNU environment.
3689
3690 In line with this philosophy, GNU Fortran must evolve into a product
3691 that is widely ported and portable not only in the sense that it can
3692 be successfully built, installed, and run by users, but in the larger
3693 sense that its users can use it in the same way, and expect largely the
3694 same behaviors from it, regardless of the kind of system they are using
3695 at any particular time.
3696
3697 This approach constrains the solutions @code{g77} can use to resolve
3698 conflicts between various camps of Fortran users.
3699 If these two camps disagree about what a particular construct should
3700 mean, @code{g77} cannot simply be changed to treat that particular construct as
3701 having one meaning without comment (such as a warning), lest the users
3702 expecting it to have the other meaning are unpleasantly surprised that
3703 their code misbehaves when executed.
3704
3705 The use of the ASCII backslash character in character constants is
3706 an excellent (and still somewhat unresolved) example of this kind of
3707 controversy.
3708 @xref{Backslash in Constants}.
3709 Other examples are likely to arise in the future, as @code{g77} developers
3710 strive to improve its ability to accept an ever-wider variety of existing
3711 Fortran code without requiring significant modifications to said code.
3712
3713 Development of GNU Fortran is further constrained by the desire
3714 to avoid requiring programmers to change their code.
3715 This is important because it allows programmers, administrators,
3716 and others to more faithfully evaluate and validate @code{g77}
3717 (as an overall product and as new versions are distributed)
3718 without having to support multiple versions of their programs
3719 so that they continue to work the same way on their existing
3720 systems (non-GNU perhaps, but possibly also earlier versions
3721 of @code{g77}).
3722
3723 @node Standard Support
3724 @section ANSI FORTRAN 77 Standard Support
3725 @cindex ANSI FORTRAN 77 support
3726 @cindex standard, support for
3727 @cindex support, FORTRAN 77
3728 @cindex compatibility, FORTRAN 77
3729 @cindex FORTRAN 77 compatibility
3730
3731 GNU Fortran supports ANSI FORTRAN 77 with the following caveats.
3732 In summary, the only ANSI FORTRAN 77 features @code{g77} doesn't
3733 support are those that are probably rarely used in actual code,
3734 some of which are explicitly disallowed by the Fortran 90 standard.
3735
3736 @menu
3737 * No Passing External Assumed-length::  CHAR*(*) CFUNC restriction.
3738 * No Passing Dummy Assumed-length::     CHAR*(*) CFUNC restriction.
3739 * No Pathological Implied-DO::          No @samp{((@dots{}, I=@dots{}), I=@dots{})}.
3740 * No Useless Implied-DO::               No @samp{(A, I=1, 1)}.
3741 @end menu
3742
3743 @node No Passing External Assumed-length
3744 @subsection No Passing External Assumed-length
3745
3746 @code{g77} disallows passing of an external procedure
3747 as an actual argument if the procedure's
3748 type is declared @code{CHARACTER*(*)}.  For example:
3749
3750 @example
3751 CHARACTER*(*) CFUNC
3752 EXTERNAL CFUNC
3753 CALL FOO(CFUNC)
3754 END
3755 @end example
3756
3757 @noindent
3758 It isn't clear whether the standard considers this conforming.
3759
3760 @node No Passing Dummy Assumed-length
3761 @subsection No Passing Dummy Assumed-length
3762
3763 @code{g77} disallows passing of a dummy procedure
3764 as an actual argument if the procedure's
3765 type is declared @code{CHARACTER*(*)}.
3766
3767 @example
3768 SUBROUTINE BAR(CFUNC)
3769 CHARACTER*(*) CFUNC
3770 EXTERNAL CFUNC
3771 CALL FOO(CFUNC)
3772 END
3773 @end example
3774
3775 @noindent
3776 It isn't clear whether the standard considers this conforming.
3777
3778 @node No Pathological Implied-DO
3779 @subsection No Pathological Implied-DO
3780
3781 The @code{DO} variable for an implied-@code{DO} construct in a
3782 @code{DATA} statement may not be used as the @code{DO} variable
3783 for an outer implied-@code{DO} construct.  For example, this
3784 fragment is disallowed by @code{g77}:
3785
3786 @smallexample
3787 DATA ((A(I, I), I= 1, 10), I= 1, 10) /@dots{}/
3788 @end smallexample
3789
3790 @noindent
3791 This also is disallowed by Fortran 90, as it offers no additional
3792 capabilities and would have a variety of possible meanings.
3793
3794 Note that it is @emph{very} unlikely that any production Fortran code
3795 tries to use this unsupported construct.
3796
3797 @node No Useless Implied-DO
3798 @subsection No Useless Implied-DO
3799
3800 An array element initializer in an implied-@code{DO} construct in a
3801 @code{DATA} statement must contain at least one reference to the @code{DO}
3802 variables of each outer implied-@code{DO} construct.  For example,
3803 this fragment is disallowed by @code{g77}:
3804
3805 @smallexample
3806 DATA (A, I= 1, 1) /1./
3807 @end smallexample
3808
3809 @noindent
3810 This also is disallowed by Fortran 90, as FORTRAN 77's more permissive
3811 requirements offer no additional capabilities.
3812 However, @code{g77} doesn't necessarily diagnose all cases
3813 where this requirement is not met.
3814
3815 Note that it is @emph{very} unlikely that any production Fortran code
3816 tries to use this unsupported construct.
3817
3818 @node Conformance
3819 @section Conformance
3820
3821 (The following information augments or overrides the information in
3822 Section 1.4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3823 language.
3824 Chapter 1 of that document otherwise serves as the basis
3825 for the relevant aspects of GNU Fortran.)
3826
3827 The definition of the GNU Fortran language is akin to that of
3828 the ANSI FORTRAN 77 language in that it does not generally require
3829 conforming implementations to diagnose cases where programs do
3830 not conform to the language.
3831
3832 However, @code{g77} as a compiler is being developed in a way that
3833 is intended to enable it to diagnose such cases in an easy-to-understand
3834 manner.
3835
3836 A program that conforms to the GNU Fortran language should, when
3837 compiled, linked, and executed using a properly installed @code{g77}
3838 system, perform as described by the GNU Fortran language definition.
3839 Reasons for different behavior include, among others:
3840
3841 @itemize @bullet
3842 @item
3843 Use of resources (memory---heap, stack, and so on; disk space; CPU
3844 time; etc.) exceeds those of the system.
3845
3846 @item
3847 Range and/or precision of calculations required by the program
3848 exceeds that of the system.
3849
3850 @item
3851 Excessive reliance on behaviors that are system-dependent
3852 (non-portable Fortran code).
3853
3854 @item
3855 Bugs in the program.
3856
3857 @item
3858 Bug in @code{g77}.
3859
3860 @item
3861 Bugs in the system.
3862 @end itemize
3863
3864 Despite these ``loopholes'', the availability of a clear specification
3865 of the language of programs submitted to @code{g77}, as this document
3866 is intended to provide, is considered an important aspect of providing
3867 a robust, clean, predictable Fortran implementation.
3868
3869 The definition of the GNU Fortran language, while having no special
3870 legal status, can therefore be viewed as a sort of contract, or agreement.
3871 This agreement says, in essence, ``if you write a program in this language,
3872 and run it in an environment (such as a @code{g77} system) that supports
3873 this language, the program should behave in a largely predictable way''.
3874
3875 @node Notation Used
3876 @section Notation Used in This Chapter
3877
3878 (The following information augments or overrides the information in
3879 Section 1.5 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3880 language.
3881 Chapter 1 of that document otherwise serves as the basis
3882 for the relevant aspects of GNU Fortran.)
3883
3884 In this chapter, ``must'' denotes a requirement, ``may'' denotes permission,
3885 and ``must not'' and ``may not'' denote prohibition.
3886 Terms such as ``might'', ``should'', and ``can'' generally add little or
3887 nothing in the way of weight to the GNU Fortran language itself,
3888 but are used to explain or illustrate the language.
3889
3890 For example:
3891
3892 @display
3893 ``The @code{FROBNITZ} statement must precede all executable
3894 statements in a program unit, and may not specify any dummy
3895 arguments.  It may specify local or common variables and arrays.
3896 Its use should be limited to portions of the program designed to
3897 be non-portable and system-specific, because it might cause the
3898 containing program unit to behave quite differently on different
3899 systems.''
3900 @end display
3901
3902 Insofar as the GNU Fortran language is specified,
3903 the requirements and permissions denoted by the above sample statement
3904 are limited to the placement of the statement and the kinds of
3905 things it may specify.
3906 The rest of the statement---the content regarding non-portable portions
3907 of the program and the differing behavior of program units containing
3908 the @code{FROBNITZ} statement---does not pertain the GNU Fortran
3909 language itself.
3910 That content offers advice and warnings about the @code{FROBNITZ}
3911 statement.
3912
3913 @emph{Remember:} The GNU Fortran language definition specifies
3914 both what constitutes a valid GNU Fortran program and how,
3915 given such a program, a valid GNU Fortran implementation is
3916 to interpret that program.
3917
3918 It is @emph{not} incumbent upon a valid GNU Fortran implementation
3919 to behave in any particular way, any consistent way, or any
3920 predictable way when it is asked to interpret input that is
3921 @emph{not} a valid GNU Fortran program.
3922
3923 Such input is said to have @dfn{undefined} behavior when
3924 interpreted by a valid GNU Fortran implementation, though
3925 an implementation may choose to specify behaviors for some
3926 cases of inputs that are not valid GNU Fortran programs.
3927
3928 Other notation used herein is that of the GNU texinfo format,
3929 which is used to generate printed hardcopy, on-line hypertext
3930 (Info), and on-line HTML versions, all from a single source
3931 document.
3932 This notation is used as follows:
3933
3934 @itemize @bullet
3935 @item
3936 Keywords defined by the GNU Fortran language are shown
3937 in uppercase, as in: @code{COMMON}, @code{INTEGER}, and
3938 @code{BLOCK DATA}.
3939
3940 Note that, in practice, many Fortran programs are written
3941 in lowercase---uppercase is used in this manual as a
3942 means to readily distinguish keywords and sample Fortran-related
3943 text from the prose in this document.
3944
3945 @item
3946 Portions of actual sample program, input, or output text
3947 look like this: @samp{Actual program text}.
3948
3949 Generally, uppercase is used for all Fortran-specific and
3950 Fortran-related text, though this does not always include
3951 literal text within Fortran code.
3952
3953 For example: @samp{PRINT *, 'My name is Bob'}.
3954
3955 @item
3956 A metasyntactic variable---that is, a name used in this document
3957 to serve as a placeholder for whatever text is used by the
3958 user or programmer---appears as shown in the following example:
3959
3960 ``The @code{INTEGER @var{ivar}} statement specifies that
3961 @var{ivar} is a variable or array of type @code{INTEGER}.''
3962
3963 In the above example, any valid text may be substituted for
3964 the metasyntactic variable @var{ivar} to make the statement
3965 apply to a specific instance, as long as the same text is
3966 substituted for @emph{both} occurrences of @var{ivar}.
3967
3968 @item
3969 Ellipses (``@dots{}'') are used to indicate further text that
3970 is either unimportant or expanded upon further, elsewhere.
3971
3972 @item
3973 Names of data types are in the style of Fortran 90, in most
3974 cases.
3975
3976 @xref{Kind Notation}, for information on the relationship
3977 between Fortran 90 nomenclature (such as @code{INTEGER(KIND=1)})
3978 and the more traditional, less portably concise nomenclature
3979 (such as @code{INTEGER*4}).
3980 @end itemize
3981
3982 @node Terms and Concepts
3983 @section Fortran Terms and Concepts
3984
3985 (The following information augments or overrides the information in
3986 Chapter 2 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
3987 language.
3988 Chapter 2 of that document otherwise serves as the basis
3989 for the relevant aspects of GNU Fortran.)
3990
3991 @menu
3992 * Syntactic Items::
3993 * Statements Comments Lines::
3994 * Scope of Names and Labels::
3995 @end menu
3996
3997 @node Syntactic Items
3998 @subsection Syntactic Items
3999
4000 (Corresponds to Section 2.2 of ANSI X3.9-1978 FORTRAN 77.)
4001
4002 @cindex limits, lengths of names
4003 In GNU Fortran, a symbolic name is at least one character long,
4004 and has no arbitrary upper limit on length.
4005 However, names of entities requiring external linkage (such as
4006 external functions, external subroutines, and @code{COMMON} areas)
4007 might be restricted to some arbitrary length by the system.
4008 Such a restriction is no more constrained than that of one
4009 through six characters.
4010
4011 Underscores (@samp{_}) are accepted in symbol names after the first
4012 character (which must be a letter).
4013
4014 @node Statements Comments Lines
4015 @subsection Statements, Comments, and Lines
4016
4017 (Corresponds to Section 2.3 of ANSI X3.9-1978 FORTRAN 77.)
4018
4019 @cindex trailing comment
4020 @cindex comment
4021 @cindex characters, comment
4022 @cindex !
4023 @cindex exclamation point
4024 @cindex continuation character
4025 @cindex characters, continuation
4026 Use of an exclamation point (@samp{!}) to begin a
4027 trailing comment (a comment that extends to the end of the same
4028 source line) is permitted under the following conditions:
4029
4030 @itemize @bullet
4031 @item
4032 The exclamation point does not appear in column 6.
4033 Otherwise, it is treated as an indicator of a continuation
4034 line.
4035
4036 @item
4037 The exclamation point appears outside a character or Hollerith
4038 constant.
4039 Otherwise, the exclamation point is considered part of the
4040 constant.
4041
4042 @item
4043 The exclamation point appears to the left of any other possible
4044 trailing comment.
4045 That is, a trailing comment may contain exclamation points
4046 in their commentary text.
4047 @end itemize
4048
4049 @cindex ;
4050 @cindex semicolon
4051 @cindex statements, separated by semicolon
4052 Use of a semicolon (@samp{;}) as a statement separator
4053 is permitted under the following conditions:
4054
4055 @itemize @bullet
4056 @item
4057 The semicolon appears outside a character or Hollerith
4058 constant.
4059 Otherwise, the semicolon is considered part of the
4060 constant.
4061
4062 @item
4063 The semicolon appears to the left of a trailing comment.
4064 Otherwise, the semicolon is considered part of that
4065 comment.
4066
4067 @item
4068 Neither a logical @code{IF} statement nor a non-construct
4069 @code{WHERE} statement (a Fortran 90 feature) may be
4070 followed (in the same, possibly continued, line) by
4071 a semicolon used as a statement separator.
4072
4073 This restriction avoids the confusion
4074 that can result when reading a line such as:
4075
4076 @smallexample
4077 IF (VALIDP) CALL FOO; CALL BAR
4078 @end smallexample
4079
4080 @noindent
4081 Some readers might think the @samp{CALL BAR} is executed
4082 only if @samp{VALIDP} is @code{.TRUE.}, while others might
4083 assume its execution is unconditional.
4084
4085 (At present, @code{g77} does not diagnose code that
4086 violates this restriction.)
4087 @end itemize
4088
4089 @node Scope of Names and Labels
4090 @subsection Scope of Symbolic Names and Statement Labels
4091 @cindex scope
4092
4093 (Corresponds to Section 2.9 of ANSI X3.9-1978 FORTRAN 77.)
4094
4095 Included in the list of entities that have a scope of a
4096 program unit are construct names (a Fortran 90 feature).
4097 @xref{Construct Names}, for more information.
4098
4099 @node Characters Lines Sequence
4100 @section Characters, Lines, and Execution Sequence
4101
4102 (The following information augments or overrides the information in
4103 Chapter 3 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4104 language.
4105 Chapter 3 of that document otherwise serves as the basis
4106 for the relevant aspects of GNU Fortran.)
4107
4108 @menu
4109 * Character Set::
4110 * Lines::
4111 * Continuation Line::
4112 * Statements::
4113 * Statement Labels::
4114 * Order::
4115 * INCLUDE::
4116 * Cpp-style directives::
4117 @end menu
4118
4119 @node Character Set
4120 @subsection GNU Fortran Character Set
4121 @cindex characters
4122
4123 (Corresponds to Section 3.1 of ANSI X3.9-1978 FORTRAN 77.)
4124
4125 Letters include uppercase letters (the twenty-six characters
4126 of the English alphabet) and lowercase letters (their lowercase
4127 equivalent).
4128 Generally, lowercase letters may be used in place of uppercase
4129 letters, though in character and Hollerith constants, they
4130 are distinct.
4131
4132 Special characters include:
4133
4134 @itemize @bullet
4135 @item
4136 @cindex ;
4137 @cindex semicolon
4138 Semicolon (@samp{;})
4139
4140 @item
4141 @cindex !
4142 @cindex exclamation point
4143 Exclamation point (@samp{!})
4144
4145 @item
4146 @cindex "
4147 @cindex double quote
4148 Double quote (@samp{"})
4149
4150 @item
4151 @cindex \
4152 @cindex backslash
4153 Backslash (@samp{\})
4154
4155 @item
4156 @cindex ?
4157 @cindex question mark
4158 Question mark (@samp{?})
4159
4160 @item
4161 @cindex #
4162 @cindex hash mark
4163 @cindex pound sign
4164 Hash mark (@samp{#})
4165
4166 @item
4167 @cindex &
4168 @cindex ampersand
4169 Ampersand (@samp{&})
4170
4171 @item
4172 @cindex %
4173 @cindex percent sign
4174 Percent sign (@samp{%})
4175
4176 @item
4177 @cindex _
4178 @cindex underscore
4179 Underscore (@samp{_})
4180
4181 @item
4182 @cindex <
4183 @cindex open angle
4184 @cindex left angle
4185 @cindex open bracket
4186 @cindex left bracket
4187 Open angle (@samp{<})
4188
4189 @item
4190 @cindex >
4191 @cindex close angle
4192 @cindex right angle
4193 @cindex close bracket
4194 @cindex right bracket
4195 Close angle (@samp{>})
4196
4197 @item
4198 The FORTRAN 77 special characters (@key{SPC}, @samp{=},
4199 @samp{+}, @samp{-}, @samp{*}, @samp{/}, @samp{(},
4200 @samp{)}, @samp{,}, @samp{.}, @samp{$}, @samp{'},
4201 and @samp{:})
4202 @end itemize
4203
4204 @cindex blank
4205 @cindex space
4206 @cindex SPC
4207 Note that this document refers to @key{SPC} as @dfn{space},
4208 while X3.9-1978 FORTRAN 77 refers to it as @dfn{blank}.
4209
4210 @node Lines
4211 @subsection Lines
4212 @cindex lines
4213 @cindex source file format
4214 @cindex source format
4215 @cindex file, source
4216 @cindex source code
4217 @cindex code, source
4218 @cindex fixed form
4219 @cindex free form
4220
4221 (Corresponds to Section 3.2 of ANSI X3.9-1978 FORTRAN 77.)
4222
4223 The way a Fortran compiler views source files depends entirely on the
4224 implementation choices made for the compiler, since those choices
4225 are explicitly left to the implementation by the published Fortran
4226 standards.
4227
4228 The GNU Fortran language mandates a view applicable to UNIX-like
4229 text files---files that are made up of an arbitrary number of lines,
4230 each with an arbitrary number of characters (sometimes called stream-based
4231 files).
4232
4233 This view does not apply to types of files that are specified as
4234 having a particular number of characters on every single line (sometimes
4235 referred to as record-based files).
4236
4237 Because a ``line in a program unit is a sequence of 72 characters'',
4238 to quote X3.9-1978, the GNU Fortran language specifies that a
4239 stream-based text file is translated to GNU Fortran lines as follows:
4240
4241 @itemize @bullet
4242 @item
4243 A newline in the file is the character that represents the end of
4244 a line of text to the underlying system.
4245 For example, on ASCII-based systems, a newline is the @key{NL}
4246 character, which has ASCII value 10 (decimal).
4247
4248 @item
4249 Each newline in the file serves to end the line of text that precedes
4250 it (and that does not contain a newline).
4251
4252 @item
4253 The end-of-file marker (@code{EOF}) also serves to end the line
4254 of text that precedes it (and that does not contain a newline).
4255
4256 @item
4257 @cindex blank
4258 @cindex space
4259 @cindex SPC
4260 Any line of text that is shorter than 72 characters is padded to that length
4261 with spaces (called ``blanks'' in the standard).
4262
4263 @item
4264 Any line of text that is longer than 72 characters is truncated to that
4265 length, but the truncated remainder must consist entirely of spaces.
4266
4267 @item
4268 Characters other than newline and the GNU Fortran character set
4269 are invalid.
4270 @end itemize
4271
4272 For the purposes of the remainder of this description of the GNU
4273 Fortran language, the translation described above has already
4274 taken place, unless otherwise specified.
4275
4276 The result of the above translation is that the source file appears,
4277 in terms of the remainder of this description of the GNU Fortran language,
4278 as if it had an arbitrary
4279 number of 72-character lines, each character being among the GNU Fortran
4280 character set.
4281
4282 For example, if the source file itself has two newlines in a row,
4283 the second newline becomes, after the above translation, a single
4284 line containing 72 spaces.
4285
4286 @node Continuation Line
4287 @subsection Continuation Line
4288 @cindex continuation line, number of
4289 @cindex lines, continuation
4290 @cindex number of continuation lines
4291 @cindex limits, continuation lines
4292
4293 (Corresponds to Section 3.2.3 of ANSI X3.9-1978 FORTRAN 77.)
4294
4295 A continuation line is any line that both
4296
4297 @itemize @bullet
4298 @item
4299 Contains a continuation character, and
4300
4301 @item
4302 Contains only spaces in columns 1 through 5
4303 @end itemize
4304
4305 A continuation character is any character of the GNU Fortran character set
4306 other than space (@key{SPC}) or zero (@samp{0})
4307 in column 6, or a digit (@samp{0} through @samp{9}) in column
4308 7 through 72 of a line that has only spaces to the left of that
4309 digit.
4310
4311 The continuation character is ignored as far as the content of
4312 the statement is concerned.
4313
4314 The GNU Fortran language places no limit on the number of
4315 continuation lines in a statement.
4316 In practice, the limit depends on a variety of factors, such as
4317 available memory, statement content, and so on, but no
4318 GNU Fortran system may impose an arbitrary limit.
4319
4320 @node Statements
4321 @subsection Statements
4322
4323 (Corresponds to Section 3.3 of ANSI X3.9-1978 FORTRAN 77.)
4324
4325 Statements may be written using an arbitrary number of continuation
4326 lines.
4327
4328 Statements may be separated using the semicolon (@samp{;}), except
4329 that the logical @code{IF} and non-construct @code{WHERE} statements
4330 may not be separated from subsequent statements using only a semicolon
4331 as statement separator.
4332
4333 The @code{END PROGRAM}, @code{END SUBROUTINE}, @code{END FUNCTION},
4334 and @code{END BLOCK DATA} statements are alternatives to the @code{END}
4335 statement.
4336 These alternatives may be written as normal statements---they are not
4337 subject to the restrictions of the @code{END} statement.
4338
4339 However, no statement other than @code{END} may have an initial line
4340 that appears to be an @code{END} statement---even @code{END PROGRAM},
4341 for example, must not be written as:
4342
4343 @example
4344       END
4345      &PROGRAM
4346 @end example
4347
4348 @node Statement Labels
4349 @subsection Statement Labels
4350
4351 (Corresponds to Section 3.4 of ANSI X3.9-1978 FORTRAN 77.)
4352
4353 A statement separated from its predecessor via a semicolon may be
4354 labeled as follows:
4355
4356 @itemize @bullet
4357 @item
4358 The semicolon is followed by the label for the statement,
4359 which in turn follows the label.
4360
4361 @item
4362 The label must be no more than five digits in length.
4363
4364 @item
4365 The first digit of the label for the statement is not
4366 the first non-space character on a line.
4367 Otherwise, that character is treated as a continuation
4368 character.
4369 @end itemize
4370
4371 A statement may have only one label defined for it.
4372
4373 @node Order
4374 @subsection Order of Statements and Lines
4375
4376 (Corresponds to Section 3.5 of ANSI X3.9-1978 FORTRAN 77.)
4377
4378 Generally, @code{DATA} statements may precede executable statements.
4379 However, specification statements pertaining to any entities
4380 initialized by a @code{DATA} statement must precede that @code{DATA}
4381 statement.
4382 For example,
4383 after @samp{DATA I/1/}, @samp{INTEGER I} is not permitted, but
4384 @samp{INTEGER J} is permitted.
4385
4386 The last line of a program unit may be an @code{END} statement,
4387 or may be:
4388
4389 @itemize @bullet
4390 @item
4391 An @code{END PROGRAM} statement, if the program unit is a main program.
4392
4393 @item
4394 An @code{END SUBROUTINE} statement, if the program unit is a subroutine.
4395
4396 @item
4397 An @code{END FUNCTION} statement, if the program unit is a function.
4398
4399 @item
4400 An @code{END BLOCK DATA} statement, if the program unit is a block data.
4401 @end itemize
4402
4403 @node INCLUDE
4404 @subsection Including Source Text
4405 @cindex INCLUDE directive
4406
4407 Additional source text may be included in the processing of
4408 the source file via the @code{INCLUDE} directive:
4409
4410 @example
4411 INCLUDE @var{filename}
4412 @end example
4413
4414 @noindent
4415 The source text to be included is identified by @var{filename},
4416 which is a literal GNU Fortran character constant.
4417 The meaning and interpretation of @var{filename} depends on the
4418 implementation, but typically is a filename.
4419
4420 (@code{g77} treats it as a filename that it searches for
4421 in the current directory and/or directories specified
4422 via the @samp{-I} command-line option.)
4423
4424 The effect of the @code{INCLUDE} directive is as if the
4425 included text directly replaced the directive in the source
4426 file prior to interpretation of the program.
4427 Included text may itself use @code{INCLUDE}.
4428 The depth of nested @code{INCLUDE} references depends on
4429 the implementation, but typically is a positive integer.
4430
4431 This virtual replacement treats the statements and @code{INCLUDE}
4432 directives in the included text as syntactically distinct from
4433 those in the including text.
4434
4435 Therefore, the first non-comment line of the included text
4436 must not be a continuation line.
4437 The included text must therefore have, after the non-comment
4438 lines, either an initial line (statement), an @code{INCLUDE}
4439 directive, or nothing (the end of the included text).
4440
4441 Similarly, the including text may end the @code{INCLUDE}
4442 directive with a semicolon or the end of the line, but it
4443 cannot follow an @code{INCLUDE} directive at the end of its
4444 line with a continuation line.
4445 Thus, the last statement in an included text may not be
4446 continued.
4447
4448 Any statements between two @code{INCLUDE} directives on the
4449 same line are treated as if they appeared in between the
4450 respective included texts.
4451 For example:
4452
4453 @smallexample
4454 INCLUDE 'A'; PRINT *, 'B'; INCLUDE 'C'; END PROGRAM
4455 @end smallexample
4456
4457 @noindent
4458 If the text included by @samp{INCLUDE 'A'} constitutes
4459 a @samp{PRINT *, 'A'} statement and the text included by
4460 @samp{INCLUDE 'C'} constitutes a @samp{PRINT *, 'C'} statement,
4461 then the output of the above sample program would be
4462
4463 @example
4464 A
4465 B
4466 C
4467 @end example
4468
4469 @noindent
4470 (with suitable allowances for how an implementation defines
4471 its handling of output).
4472
4473 Included text must not include itself directly or indirectly,
4474 regardless of whether the @var{filename} used to reference
4475 the text is the same.
4476
4477 Note that @code{INCLUDE} is @emph{not} a statement.
4478 As such, it is neither a non-executable or executable
4479 statement.
4480 However, if the text it includes constitutes one or more
4481 executable statements, then the placement of @code{INCLUDE}
4482 is subject to effectively the same restrictions as those
4483 on executable statements.
4484
4485 An @code{INCLUDE} directive may be continued across multiple
4486 lines as if it were a statement.
4487 This permits long names to be used for @var{filename}.
4488
4489 @node Cpp-style directives
4490 @subsection Cpp-style directives
4491 @cindex #
4492 @cindex preprocessor
4493
4494 @code{cpp} output-style @code{#} directives
4495 (@pxref{C Preprocessor Output,,, cpp, The C Preprocessor})
4496 are recognized by the compiler even
4497 when the preprocessor isn't run on the input (as it is when compiling
4498 @samp{.F} files).  (Note the distinction between these @code{cpp}
4499 @code{#} @emph{output} directives and @code{#line} @emph{input}
4500 directives.)
4501
4502 @node Data Types and Constants
4503 @section Data Types and Constants
4504
4505 (The following information augments or overrides the information in
4506 Chapter 4 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
4507 language.
4508 Chapter 4 of that document otherwise serves as the basis
4509 for the relevant aspects of GNU Fortran.)
4510
4511 To more concisely express the appropriate types for
4512 entities, this document uses the more concise
4513 Fortran 90 nomenclature such as @code{INTEGER(KIND=1)}
4514 instead of the more traditional, but less portably concise,
4515 byte-size-based nomenclature such as @code{INTEGER*4},
4516 wherever reasonable.
4517
4518 When referring to generic types---in contexts where the
4519 specific precision and range of a type are not important---this
4520 document uses the generic type names @code{INTEGER}, @code{LOGICAL},
4521 @code{REAL}, @code{COMPLEX}, and @code{CHARACTER}.
4522
4523 In some cases, the context requires specification of a
4524 particular type.
4525 This document uses the @samp{KIND=} notation to accomplish
4526 this throughout, sometimes supplying the more traditional
4527 notation for clarification, though the traditional notation
4528 might not work the same way on all GNU Fortran implementations.
4529
4530 Use of @samp{KIND=} makes this document more concise because
4531 @code{g77} is able to define values for @samp{KIND=} that
4532 have the same meanings on all systems, due to the way the
4533 Fortran 90 standard specifies these values are to be used.
4534
4535 (In particular, that standard permits an implementation to
4536 arbitrarily assign nonnegative values.
4537 There are four distinct sets of assignments: one to the @code{CHARACTER}
4538 type; one to the @code{INTEGER} type; one to the @code{LOGICAL} type;
4539 and the fourth to both the @code{REAL} and @code{COMPLEX} types.
4540 Implementations are free to assign these values in any order,
4541 leave gaps in the ordering of assignments, and assign more than
4542 one value to a representation.)
4543
4544 This makes @samp{KIND=} values superior to the values used
4545 in non-standard statements such as @samp{INTEGER*4}, because
4546 the meanings of the values in those statements vary from machine
4547 to machine, compiler to compiler, even operating system to
4548 operating system.
4549
4550 However, use of @samp{KIND=} is @emph{not} generally recommended
4551 when writing portable code (unless, for example, the code is
4552 going to be compiled only via @code{g77}, which is a widely
4553 ported compiler).
4554 GNU Fortran does not yet have adequate language constructs to
4555 permit use of @samp{KIND=} in a fashion that would make the
4556 code portable to Fortran 90 implementations; and, this construct
4557 is known to @emph{not} be accepted by many popular FORTRAN 77
4558 implementations, so it cannot be used in code that is to be ported
4559 to those.
4560
4561 The distinction here is that this document is able to use
4562 specific values for @samp{KIND=} to concisely document the
4563 types of various operations and operands.
4564
4565 A Fortran program should use the FORTRAN 77 designations for the
4566 appropriate GNU Fortran types---such as @code{INTEGER} for
4567 @code{INTEGER(KIND=1)}, @code{REAL} for @code{REAL(KIND=1)},
4568 and @code{DOUBLE COMPLEX} for @code{COMPLEX(KIND=2)}---and,
4569 where no such designations exist, make use of appropriate
4570 techniques (preprocessor macros, parameters, and so on)
4571 to specify the types in a fashion that may be easily adjusted
4572 to suit each particular implementation to which the program
4573 is ported.
4574 (These types generally won't need to be adjusted for ports of
4575 @code{g77}.)
4576
4577 Further details regarding GNU Fortran data types and constants
4578 are provided below.
4579
4580 @menu
4581 * Types::
4582 * Constants::
4583 * Integer Type::
4584 * Character Type::
4585 @end menu
4586
4587 @node Types
4588 @subsection Data Types
4589
4590 (Corresponds to Section 4.1 of ANSI X3.9-1978 FORTRAN 77.)
4591
4592 GNU Fortran supports these types:
4593
4594 @enumerate
4595 @item
4596 Integer (generic type @code{INTEGER})
4597
4598 @item
4599 Real (generic type @code{REAL})
4600
4601 @item
4602 Double precision
4603
4604 @item
4605 Complex (generic type @code{COMPLEX})
4606
4607 @item
4608 Logical (generic type @code{LOGICAL})
4609
4610 @item
4611 Character (generic type @code{CHARACTER})
4612
4613 @item
4614 Double Complex
4615 @end enumerate
4616
4617 (The types numbered 1 through 6 above are standard FORTRAN 77 types.)
4618
4619 The generic types shown above are referred to in this document
4620 using only their generic type names.
4621 Such references usually indicate that any specific type (kind)
4622 of that generic type is valid.
4623
4624 For example, a context described in this document as accepting
4625 the @code{COMPLEX} type also is likely to accept the
4626 @code{DOUBLE COMPLEX} type.
4627
4628 The GNU Fortran language supports three ways to specify
4629 a specific kind of a generic type.
4630
4631 @menu
4632 * Double Notation::  As in @code{DOUBLE COMPLEX}.
4633 * Star Notation::    As in @code{INTEGER*4}.
4634 * Kind Notation::    As in @code{INTEGER(KIND=1)}.
4635 @end menu
4636
4637 @node Double Notation
4638 @subsubsection Double Notation
4639
4640 The GNU Fortran language supports two uses of the keyword
4641 @code{DOUBLE} to specify a specific kind of type:
4642
4643 @itemize @bullet
4644 @item
4645 @code{DOUBLE PRECISION}, equivalent to @code{REAL(KIND=2)}
4646
4647 @item
4648 @code{DOUBLE COMPLEX}, equivalent to @code{COMPLEX(KIND=2)}
4649 @end itemize
4650
4651 Use one of the above forms where a type name is valid.
4652
4653 While use of this notation is popular, it doesn't scale
4654 well in a language or dialect rich in intrinsic types,
4655 as is the case for the GNU Fortran language (especially
4656 planned future versions of it).
4657
4658 After all, one rarely sees type names such as @samp{DOUBLE INTEGER},
4659 @samp{QUADRUPLE REAL}, or @samp{QUARTER INTEGER}.
4660 Instead, @code{INTEGER*8}, @code{REAL*16}, and @code{INTEGER*1}
4661 often are substituted for these, respectively, even though they
4662 do not always have the same meanings on all systems.
4663 (And, the fact that @samp{DOUBLE REAL} does not exist as such
4664 is an inconsistency.)
4665
4666 Therefore, this document uses ``double notation'' only on occasion
4667 for the benefit of those readers who are accustomed to it.
4668
4669 @node Star Notation
4670 @subsubsection Star Notation
4671 @cindex *@var{n} notation
4672
4673 The following notation specifies the storage size for a type:
4674
4675 @smallexample
4676 @var{generic-type}*@var{n}
4677 @end smallexample
4678
4679 @noindent
4680 @var{generic-type} must be a generic type---one of
4681 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4682 or @code{CHARACTER}.
4683 @var{n} must be one or more digits comprising a decimal
4684 integer number greater than zero.
4685
4686 Use the above form where a type name is valid.
4687
4688 The @samp{*@var{n}} notation specifies that the amount of storage
4689 occupied by variables and array elements of that type is @var{n}
4690 times the storage occupied by a @code{CHARACTER*1} variable.
4691
4692 This notation might indicate a different degree of precision and/or
4693 range for such variables and array elements, and the functions that
4694 return values of types using this notation.
4695 It does not limit the precision or range of values of that type
4696 in any particular way---use explicit code to do that.
4697
4698 Further, the GNU Fortran language requires no particular values
4699 for @var{n} to be supported by an implementation via the @samp{*@var{n}}
4700 notation.
4701 @code{g77} supports @code{INTEGER*1} (as @code{INTEGER(KIND=3)})
4702 on all systems, for example,
4703 but not all implementations are required to do so, and @code{g77}
4704 is known to not support @code{REAL*1} on most (or all) systems.
4705
4706 As a result, except for @var{generic-type} of @code{CHARACTER},
4707 uses of this notation should be limited to isolated
4708 portions of a program that are intended to handle system-specific
4709 tasks and are expected to be non-portable.
4710
4711 (Standard FORTRAN 77 supports the @samp{*@var{n}} notation for
4712 only @code{CHARACTER}, where it signifies not only the amount
4713 of storage occupied, but the number of characters in entities
4714 of that type.
4715 However, almost all Fortran compilers have supported this
4716 notation for generic types, though with a variety of meanings
4717 for @var{n}.)
4718
4719 Specifications of types using the @samp{*@var{n}} notation
4720 always are interpreted as specifications of the appropriate
4721 types described in this document using the @samp{KIND=@var{n}}
4722 notation, described below.
4723
4724 While use of this notation is popular, it doesn't serve well
4725 in the context of a widely portable dialect of Fortran, such as
4726 the GNU Fortran language.
4727
4728 For example, even on one particular machine, two or more popular
4729 Fortran compilers might well disagree on the size of a type
4730 declared @code{INTEGER*2} or @code{REAL*16}.
4731 Certainly there
4732 is known to be disagreement over such things among Fortran
4733 compilers on @emph{different} systems.
4734
4735 Further, this notation offers no elegant way to specify sizes
4736 that are not even multiples of the ``byte size'' typically
4737 designated by @code{INTEGER*1}.
4738 Use of ``absurd'' values (such as @code{INTEGER*1000}) would
4739 certainly be possible, but would perhaps be stretching the original
4740 intent of this notation beyond the breaking point in terms
4741 of widespread readability of documentation and code making use
4742 of it.
4743
4744 Therefore, this document uses ``star notation'' only on occasion
4745 for the benefit of those readers who are accustomed to it.
4746
4747 @node Kind Notation
4748 @subsubsection Kind Notation
4749 @cindex KIND= notation
4750
4751 The following notation specifies the kind-type selector of a type:
4752
4753 @smallexample
4754 @var{generic-type}(KIND=@var{n})
4755 @end smallexample
4756
4757 @noindent
4758 Use the above form where a type name is valid.
4759
4760 @var{generic-type} must be a generic type---one of
4761 @code{INTEGER}, @code{REAL}, @code{COMPLEX}, @code{LOGICAL},
4762 or @code{CHARACTER}.
4763 @var{n} must be an integer initialization expression that
4764 is a positive, nonzero value.
4765
4766 Programmers are discouraged from writing these values directly
4767 into their code.
4768 Future versions of the GNU Fortran language will offer
4769 facilities that will make the writing of code portable
4770 to @code{g77} @emph{and} Fortran 90 implementations simpler.
4771
4772 However, writing code that ports to existing FORTRAN 77
4773 implementations depends on avoiding the @samp{KIND=} construct.
4774
4775 The @samp{KIND=} construct is thus useful in the context
4776 of GNU Fortran for two reasons:
4777
4778 @itemize @bullet
4779 @item
4780 It provides a means to specify a type in a fashion that
4781 is portable across all GNU Fortran implementations (though
4782 not other FORTRAN 77 and Fortran 90 implementations).
4783
4784 @item
4785 It provides a sort of Rosetta stone for this document to use
4786 to concisely describe the types of various operations and
4787 operands.
4788 @end itemize
4789
4790 The values of @var{n} in the GNU Fortran language are
4791 assigned using a scheme that:
4792
4793 @itemize @bullet
4794 @item
4795 Attempts to maximize the ability of readers
4796 of this document to quickly familiarize themselves
4797 with assignments for popular types
4798
4799 @item
4800 Provides a unique value for each specific desired
4801 meaning
4802
4803 @item
4804 Provides a means to automatically assign new values so
4805 they have a ``natural'' relationship to existing values,
4806 if appropriate, or, if no such relationship exists, will
4807 not interfere with future values assigned on the basis
4808 of such relationships
4809
4810 @item
4811 Avoids using values that are similar to values used
4812 in the existing, popular @samp{*@var{n}} notation,
4813 to prevent readers from expecting that these implied
4814 correspondences work on all GNU Fortran implementations
4815 @end itemize
4816
4817 The assignment system accomplishes this by assigning
4818 to each ``fundamental meaning'' of a specific type a
4819 unique prime number.
4820 Combinations of fundamental meanings---for example, a type
4821 that is two times the size of some other type---are assigned
4822 values of @var{n} that are the products of the values for
4823 those fundamental meanings.
4824
4825 A prime value of @var{n} is never given more than one fundamental
4826 meaning, to avoid situations where some code or system
4827 cannot reasonably provide those meanings in the form of a
4828 single type.
4829
4830 The values of @var{n} assigned so far are:
4831
4832 @table @code
4833 @item KIND=0
4834 This value is reserved for future use.
4835
4836 The planned future use is for this value to designate,
4837 explicitly, context-sensitive kind-type selection.
4838 For example, the expression @samp{1D0 * 0.1_0} would
4839 be equivalent to @samp{1D0 * 0.1D0}.
4840
4841 @item KIND=1
4842 This corresponds to the default types for
4843 @code{REAL}, @code{INTEGER}, @code{LOGICAL}, @code{COMPLEX},
4844 and @code{CHARACTER}, as appropriate.
4845
4846 These are the ``default'' types described in the Fortran 90 standard,
4847 though that standard does not assign any particular @samp{KIND=}
4848 value to these types.
4849
4850 (Typically, these are @code{REAL*4}, @code{INTEGER*4},
4851 @code{LOGICAL*4}, and @code{COMPLEX*8}.)
4852
4853 @item KIND=2
4854 This corresponds to types that occupy twice as much
4855 storage as the default types.
4856 @code{REAL(KIND=2)} is @code{DOUBLE PRECISION} (typically @code{REAL*8}),
4857 @code{COMPLEX(KIND=2)} is @code{DOUBLE COMPLEX} (typically @code{COMPLEX*16}),
4858
4859 These are the ``double precision'' types described in the Fortran 90
4860 standard,
4861 though that standard does not assign any particular @samp{KIND=}
4862 value to these types.
4863
4864 @var{n} of 4 thus corresponds to types that occupy four times
4865 as much storage as the default types, @var{n} of 8 to types that
4866 occupy eight times as much storage, and so on.
4867
4868 The @code{INTEGER(KIND=2)} and @code{LOGICAL(KIND=2)} types
4869 are not necessarily supported by every GNU Fortran implementation.
4870
4871 @item KIND=3
4872 This corresponds to types that occupy as much
4873 storage as the default @code{CHARACTER} type,
4874 which is the same effective type as @code{CHARACTER(KIND=1)}
4875 (making that type effectively the same as @code{CHARACTER(KIND=3)}).
4876
4877 (Typically, these are @code{INTEGER*1} and @code{LOGICAL*1}.)
4878
4879 @var{n} of 6 thus corresponds to types that occupy twice as
4880 much storage as the @var{n}=3 types, @var{n} of 12 to types
4881 that occupy four times as much storage, and so on.
4882
4883 These are not necessarily supported by every GNU Fortran
4884 implementation.
4885
4886 @item KIND=5
4887 This corresponds to types that occupy half the
4888 storage as the default (@var{n}=1) types.
4889
4890 (Typically, these are @code{INTEGER*2} and @code{LOGICAL*2}.)
4891
4892 @var{n} of 25 thus corresponds to types that occupy one-quarter
4893 as much storage as the default types.
4894
4895 These are not necessarily supported by every GNU Fortran
4896 implementation.
4897
4898 @item KIND=7
4899 @cindex pointers
4900 This is valid only as @code{INTEGER(KIND=7)} and
4901 denotes the @code{INTEGER} type that has the smallest
4902 storage size that holds a pointer on the system.
4903
4904 A pointer representable by this type is capable of uniquely
4905 addressing a @code{CHARACTER*1} variable, array, array element,
4906 or substring.
4907
4908 (Typically this is equivalent to @code{INTEGER*4} or,
4909 on 64-bit systems, @code{INTEGER*8}.
4910 In a compatible C implementation, it typically would
4911 be the same size and semantics of the C type @code{void *}.)
4912 @end table
4913
4914 Note that these are @emph{proposed} correspondences and might change
4915 in future versions of @code{g77}---avoid writing code depending
4916 on them while @code{g77}, and therefore the GNU Fortran language
4917 it defines, is in beta testing.
4918
4919 Values not specified in the above list are reserved to
4920 future versions of the GNU Fortran language.
4921
4922 Implementation-dependent meanings will be assigned new,
4923 unique prime numbers so as to not interfere with other
4924 implementation-dependent meanings, and offer the possibility
4925 of increasing the portability of code depending on such
4926 types by offering support for them in other GNU Fortran
4927 implementations.
4928
4929 Other meanings that might be given unique values are:
4930
4931 @itemize @bullet
4932 @item
4933 Types that make use of only half their storage size for
4934 representing precision and range.
4935
4936 For example, some compilers offer options that cause
4937 @code{INTEGER} types to occupy the amount of storage
4938 that would be needed for @code{INTEGER(KIND=2)} types, but the
4939 range remains that of @code{INTEGER(KIND=1)}.
4940
4941 @item
4942 The IEEE single floating-point type.
4943
4944 @item
4945 Types with a specific bit pattern (endianness), such as the
4946 little-endian form of @code{INTEGER(KIND=1)}.
4947 These could permit, conceptually, use of portable code and
4948 implementations on data files written by existing systems.
4949 @end itemize
4950
4951 Future @emph{prime} numbers should be given meanings in as incremental
4952 a fashion as possible, to allow for flexibility and
4953 expressiveness in combining types.
4954
4955 For example, instead of defining a prime number for little-endian
4956 IEEE doubles, one prime number might be assigned the meaning
4957 ``little-endian'', another the meaning ``IEEE double'', and the
4958 value of @var{n} for a little-endian IEEE double would thus
4959 naturally be the product of those two respective assigned values.
4960 (It could even be reasonable to have IEEE values result from the
4961 products of prime values denoting exponent and fraction sizes
4962 and meanings, hidden bit usage, availability and representations
4963 of special values such as subnormals, infinities, and Not-A-Numbers
4964 (NaNs), and so on.)
4965
4966 This assignment mechanism, while not inherently required for
4967 future versions of the GNU Fortran language, is worth using
4968 because it could ease management of the ``space'' of supported
4969 types much easier in the long run.
4970
4971 The above approach suggests a mechanism for specifying inheritance
4972 of intrinsic (built-in) types for an entire, widely portable
4973 product line.
4974 It is certainly reasonable that, unlike programmers of other languages
4975 offering inheritance mechanisms that employ verbose names for classes
4976 and subclasses, along with graphical browsers to elucidate the
4977 relationships, Fortran programmers would employ
4978 a mechanism that works by multiplying prime numbers together
4979 and finding the prime factors of such products.
4980
4981 Most of the advantages for the above scheme have been explained
4982 above.
4983 One disadvantage is that it could lead to the defining,
4984 by the GNU Fortran language, of some fairly large prime numbers.
4985 This could lead to the GNU Fortran language being declared
4986 ``munitions'' by the United States Department of Defense.
4987
4988 @node Constants
4989 @subsection Constants
4990 @cindex constants
4991 @cindex types, constants
4992
4993 (Corresponds to Section 4.2 of ANSI X3.9-1978 FORTRAN 77.)
4994
4995 A @dfn{typeless constant} has one of the following forms:
4996
4997 @smallexample
4998 '@var{binary-digits}'B
4999 '@var{octal-digits}'O
5000 '@var{hexadecimal-digits}'Z
5001 '@var{hexadecimal-digits}'X
5002 @end smallexample
5003
5004 @noindent
5005 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
5006 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
5007 and @samp{0123456789ABCDEFabcdef}, respectively.
5008 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
5009 is 11, and so on.)
5010
5011 A prefix-radix constant, such as @samp{Z'ABCD'}, can optionally be
5012 treated as typeless.  @xref{Fortran Dialect Options,, Options
5013 Controlling Fortran Dialect}, for information on the
5014 @samp{-ftypeless-boz} option.
5015
5016 Typeless constants have values that depend on the context in which
5017 they are used.
5018
5019 All other constants, called @dfn{typed constants}, are interpreted---converted
5020 to internal form---according to their inherent type.
5021 Thus, context is @emph{never} a determining factor for the type, and hence
5022 the interpretation, of a typed constant.
5023 (All constants in the ANSI FORTRAN 77 language are typed constants.)
5024
5025 For example, @samp{1} is always type @code{INTEGER(KIND=1)} in GNU
5026 Fortran (called default INTEGER in Fortran 90),
5027 @samp{9.435784839284958} is always type @code{REAL(KIND=1)} (even if the
5028 additional precision specified is lost, and even when used in a
5029 @code{REAL(KIND=2)} context), @samp{1E0} is always type @code{REAL(KIND=2)},
5030 and @samp{1D0} is always type @code{REAL(KIND=2)}.
5031
5032 @node Integer Type
5033 @subsection Integer Type
5034
5035 (Corresponds to Section 4.3 of ANSI X3.9-1978 FORTRAN 77.)
5036
5037 An integer constant also may have one of the following forms:
5038
5039 @smallexample
5040 B'@var{binary-digits}'
5041 O'@var{octal-digits}'
5042 Z'@var{hexadecimal-digits}'
5043 X'@var{hexadecimal-digits}'
5044 @end smallexample
5045
5046 @noindent
5047 @var{binary-digits}, @var{octal-digits}, and @var{hexadecimal-digits}
5048 are nonempty strings of characters in the set @samp{01}, @samp{01234567},
5049 and @samp{0123456789ABCDEFabcdef}, respectively.
5050 (The value for @samp{A} (and @samp{a}) is 10, for @samp{B} and @samp{b}
5051 is 11, and so on.)
5052
5053 @node Character Type
5054 @subsection Character Type
5055
5056 (Corresponds to Section 4.8 of ANSI X3.9-1978 FORTRAN 77.)
5057
5058 @cindex double quoted character constants
5059 A character constant may be delimited by a pair of double quotes
5060 (@samp{"}) instead of apostrophes.
5061 In this case, an apostrophe within the constant represents
5062 a single apostrophe, while a double quote is represented in
5063 the source text of the constant by two consecutive double
5064 quotes with no intervening spaces.
5065
5066 @cindex zero-length CHARACTER
5067 @cindex null CHARACTER strings
5068 @cindex empty CHARACTER strings
5069 @cindex strings, empty
5070 @cindex CHARACTER, null
5071 A character constant may be empty (have a length of zero).
5072
5073 A character constant may include a substring specification,
5074 The value of such a constant is the value of the substring---for
5075 example, the value of @samp{'hello'(3:5)} is the same
5076 as the value of @samp{'llo'}.
5077
5078 @node Expressions
5079 @section Expressions
5080
5081 (The following information augments or overrides the information in
5082 Chapter 6 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5083 language.
5084 Chapter 6 of that document otherwise serves as the basis
5085 for the relevant aspects of GNU Fortran.)
5086
5087 @menu
5088 * %LOC()::
5089 @end menu
5090
5091 @node %LOC()
5092 @subsection The @code{%LOC()} Construct
5093 @cindex %LOC() construct
5094
5095 @example
5096 %LOC(@var{arg})
5097 @end example
5098
5099 The @code{%LOC()} construct is an expression
5100 that yields the value of the location of its argument,
5101 @var{arg}, in memory.
5102 The size of the type of the expression depends on the system---typically,
5103 it is equivalent to either @code{INTEGER(KIND=1)} or @code{INTEGER(KIND=2)},
5104 though it is actually type @code{INTEGER(KIND=7)}.
5105
5106 The argument to @code{%LOC()} must be suitable as the
5107 left-hand side of an assignment statement.
5108 That is, it may not be a general expression involving
5109 operators such as addition, subtraction, and so on,
5110 nor may it be a constant.
5111
5112 Use of @code{%LOC()} is recommended only for code that
5113 is accessing facilities outside of GNU Fortran, such as
5114 operating system or windowing facilities.
5115 It is best to constrain such uses to isolated portions of
5116 a program---portions that deal specifically and exclusively
5117 with low-level, system-dependent facilities.
5118 Such portions might well provide a portable interface for
5119 use by the program as a whole, but are themselves not
5120 portable, and should be thoroughly tested each time they
5121 are rebuilt using a new compiler or version of a compiler.
5122
5123 Do not depend on @code{%LOC()} returning a pointer that
5124 can be safely used to @emph{define} (change) the argument.
5125 While this might work in some circumstances, it is hard
5126 to predict whether it will continue to work when a program
5127 (that works using this unsafe behavior)
5128 is recompiled using different command-line options or
5129 a different version of @code{g77}.
5130
5131 Generally, @code{%LOC()} is safe when used as an argument
5132 to a procedure that makes use of the value of the corresponding
5133 dummy argument only during its activation, and only when
5134 such use is restricted to referencing (reading) the value
5135 of the argument to @code{%LOC()}.
5136
5137 @emph{Implementation Note:} Currently, @code{g77} passes
5138 arguments (those not passed using a construct such as @code{%VAL()})
5139 by reference or descriptor, depending on the type of
5140 the actual argument.
5141 Thus, given @samp{INTEGER I}, @samp{CALL FOO(I)} would
5142 seem to mean the same thing as @samp{CALL FOO(%VAL(%LOC(I)))}, and
5143 in fact might compile to identical code.
5144
5145 However, @samp{CALL FOO(%VAL(%LOC(I)))} emphatically means
5146 ``pass, by value, the address of @samp{I} in memory''.
5147 While @samp{CALL FOO(I)} might use that same approach in a
5148 particular version of @code{g77}, another version or compiler
5149 might choose a different implementation, such as copy-in/copy-out,
5150 to effect the desired behavior---and which will therefore not
5151 necessarily compile to the same code as would
5152 @samp{CALL FOO(%VAL(%LOC(I)))}
5153 using the same version or compiler.
5154
5155 @xref{Debugging and Interfacing}, for detailed information on
5156 how this particular version of @code{g77} implements various
5157 constructs.
5158
5159 @node Specification Statements
5160 @section Specification Statements
5161
5162 (The following information augments or overrides the information in
5163 Chapter 8 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5164 language.
5165 Chapter 8 of that document otherwise serves as the basis
5166 for the relevant aspects of GNU Fortran.)
5167
5168 @menu
5169 * NAMELIST::
5170 * DOUBLE COMPLEX::
5171 @end menu
5172
5173 @node NAMELIST
5174 @subsection @code{NAMELIST} Statement
5175 @cindex NAMELIST statement
5176 @cindex statements, NAMELIST
5177
5178 The @code{NAMELIST} statement, and related I/O constructs, are
5179 supported by the GNU Fortran language in essentially the same
5180 way as they are by @code{f2c}.
5181
5182 This follows Fortran 90 with the restriction that on @code{NAMELIST}
5183 input, subscripts must have the form
5184 @smallexample
5185 @var{subscript} [ @code{:} @var{subscript} [ @code{:} @var{stride}]]
5186 @end smallexample
5187 i.e.@:
5188 @smallexample
5189 &xx x(1:3,8:10:2)=1,2,3,4,5,6/
5190 @end smallexample
5191 is allowed, but not, say,
5192 @smallexample
5193 &xx x(:3,8::2)=1,2,3,4,5,6/
5194 @end smallexample
5195
5196 As an extension of the Fortran 90 form, @code{$} and @code{$END} may be
5197 used in place of @code{&} and @code{/} in @code{NAMELIST} input, so that
5198 @smallexample
5199 $&xx x(1:3,8:10:2)=1,2,3,4,5,6 $end
5200 @end smallexample
5201 could be used instead of the example above.
5202
5203 @node DOUBLE COMPLEX
5204 @subsection @code{DOUBLE COMPLEX} Statement
5205 @cindex DOUBLE COMPLEX
5206
5207 @code{DOUBLE COMPLEX} is a type-statement (and type) that
5208 specifies the type @code{COMPLEX(KIND=2)} in GNU Fortran.
5209
5210 @node Control Statements
5211 @section Control Statements
5212
5213 (The following information augments or overrides the information in
5214 Chapter 11 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5215 language.
5216 Chapter 11 of that document otherwise serves as the basis
5217 for the relevant aspects of GNU Fortran.)
5218
5219 @menu
5220 * DO WHILE::
5221 * END DO::
5222 * Construct Names::
5223 * CYCLE and EXIT::
5224 @end menu
5225
5226 @node DO WHILE
5227 @subsection DO WHILE
5228 @cindex DO WHILE
5229 @cindex DO
5230 @cindex MIL-STD 1753
5231
5232 The @code{DO WHILE} statement, a feature of both the MIL-STD 1753 and
5233 Fortran 90 standards, is provided by the GNU Fortran language.
5234 The Fortran 90 ``do forever'' statement comprising just @code{DO} is
5235 also supported.
5236
5237 @node END DO
5238 @subsection END DO
5239 @cindex END DO
5240 @cindex MIL-STD 1753
5241
5242 The @code{END DO} statement is provided by the GNU Fortran language.
5243
5244 This statement is used in one of two ways:
5245
5246 @itemize @bullet
5247 @item
5248 The Fortran 90 meaning, in which it specifies the termination
5249 point of a single @code{DO} loop started with a @code{DO} statement
5250 that specifies no termination label.
5251
5252 @item
5253 The MIL-STD 1753 meaning, in which it specifies the termination
5254 point of one or more @code{DO} loops, all of which start with a
5255 @code{DO} statement that specify the label defined for the
5256 @code{END DO} statement.
5257
5258 This kind of @code{END DO} statement is merely a synonym for
5259 @code{CONTINUE}, except it is permitted only when the statement
5260 is labeled and a target of one or more labeled @code{DO} loops.
5261
5262 It is expected that this use of @code{END DO} will be removed from
5263 the GNU Fortran language in the future, though it is likely that
5264 it will long be supported by @code{g77} as a dialect form.
5265 @end itemize
5266
5267 @node Construct Names
5268 @subsection Construct Names
5269 @cindex construct names
5270
5271 The GNU Fortran language supports construct names as defined
5272 by the Fortran 90 standard.
5273 These names are local to the program unit and are defined
5274 as follows:
5275
5276 @smallexample
5277 @var{construct-name}: @var{block-statement}
5278 @end smallexample
5279
5280 @noindent
5281 Here, @var{construct-name} is the construct name itself;
5282 its definition is connoted by the single colon (@samp{:}); and
5283 @var{block-statement} is an @code{IF}, @code{DO},
5284 or @code{SELECT CASE} statement that begins a block.
5285
5286 A block that is given a construct name must also specify the
5287 same construct name in its termination statement:
5288
5289 @example
5290 END @var{block} @var{construct-name}
5291 @end example
5292
5293 @noindent
5294 Here, @var{block} must be @code{IF}, @code{DO}, or @code{SELECT},
5295 as appropriate.
5296
5297 @node CYCLE and EXIT
5298 @subsection The @code{CYCLE} and @code{EXIT} Statements
5299
5300 @cindex CYCLE statement
5301 @cindex EXIT statement
5302 @cindex statements, CYCLE
5303 @cindex statements, EXIT
5304 The @code{CYCLE} and @code{EXIT} statements specify that
5305 the remaining statements in the current iteration of a
5306 particular active (enclosing) @code{DO} loop are to be skipped.
5307
5308 @code{CYCLE} specifies that these statements are skipped,
5309 but the @code{END DO} statement that marks the end of the
5310 @code{DO} loop be executed---that is, the next iteration,
5311 if any, is to be started.
5312 If the statement marking the end of the @code{DO} loop is
5313 not @code{END DO}---in other words, if the loop is not
5314 a block @code{DO}---the @code{CYCLE} statement does not
5315 execute that statement, but does start the next iteration (if any).
5316
5317 @code{EXIT} specifies that the loop specified by the
5318 @code{DO} construct is terminated.
5319
5320 The @code{DO} loop affected by @code{CYCLE} and @code{EXIT}
5321 is the innermost enclosing @code{DO} loop when the following
5322 forms are used:
5323
5324 @example
5325 CYCLE
5326 EXIT
5327 @end example
5328
5329 Otherwise, the following forms specify the construct name
5330 of the pertinent @code{DO} loop:
5331
5332 @example
5333 CYCLE @var{construct-name}
5334 EXIT @var{construct-name}
5335 @end example
5336
5337 @code{CYCLE} and @code{EXIT} can be viewed as glorified @code{GO TO}
5338 statements.
5339 However, they cannot be easily thought of as @code{GO TO} statements
5340 in obscure cases involving FORTRAN 77 loops.
5341 For example:
5342
5343 @smallexample
5344       DO 10 I = 1, 5
5345       DO 10 J = 1, 5
5346          IF (J .EQ. 5) EXIT
5347       DO 10 K = 1, 5
5348          IF (K .EQ. 3) CYCLE
5349 10    PRINT *, 'I=', I, ' J=', J, ' K=', K
5350 20    CONTINUE
5351 @end smallexample
5352
5353 @noindent
5354 In particular, neither the @code{EXIT} nor @code{CYCLE} statements
5355 above are equivalent to a @code{GO TO} statement to either label
5356 @samp{10} or @samp{20}.
5357
5358 To understand the effect of @code{CYCLE} and @code{EXIT} in the
5359 above fragment, it is helpful to first translate it to its equivalent
5360 using only block @code{DO} loops:
5361
5362 @smallexample
5363       DO I = 1, 5
5364          DO J = 1, 5
5365             IF (J .EQ. 5) EXIT
5366             DO K = 1, 5
5367                IF (K .EQ. 3) CYCLE
5368 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
5369             END DO
5370          END DO
5371       END DO
5372 20    CONTINUE
5373 @end smallexample
5374
5375 Adding new labels allows translation of @code{CYCLE} and @code{EXIT}
5376 to @code{GO TO} so they may be more easily understood by programmers
5377 accustomed to FORTRAN coding:
5378
5379 @smallexample
5380       DO I = 1, 5
5381          DO J = 1, 5
5382             IF (J .EQ. 5) GOTO 18
5383             DO K = 1, 5
5384                IF (K .EQ. 3) GO TO 12
5385 10             PRINT *, 'I=', I, ' J=', J, ' K=', K
5386 12          END DO
5387          END DO
5388 18    END DO
5389 20    CONTINUE
5390 @end smallexample
5391
5392 @noindent
5393 Thus, the @code{CYCLE} statement in the innermost loop skips over
5394 the @code{PRINT} statement as it begins the next iteration of the
5395 loop, while the @code{EXIT} statement in the middle loop ends that
5396 loop but @emph{not} the outermost loop.
5397
5398 @node Functions and Subroutines
5399 @section Functions and Subroutines
5400
5401 (The following information augments or overrides the information in
5402 Chapter 15 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
5403 language.
5404 Chapter 15 of that document otherwise serves as the basis
5405 for the relevant aspects of GNU Fortran.)
5406
5407 @menu
5408 * %VAL()::
5409 * %REF()::
5410 * %DESCR()::
5411 * Generics and Specifics::
5412 * REAL() and AIMAG() of Complex::
5413 * CMPLX() of DOUBLE PRECISION::
5414 * MIL-STD 1753::
5415 * f77/f2c Intrinsics::
5416 * Table of Intrinsic Functions::
5417 @end menu
5418
5419 @node %VAL()
5420 @subsection The @code{%VAL()} Construct
5421 @cindex %VAL() construct
5422
5423 @example
5424 %VAL(@var{arg})
5425 @end example
5426
5427 The @code{%VAL()} construct specifies that an argument,
5428 @var{arg}, is to be passed by value, instead of by reference
5429 or descriptor.
5430
5431 @code{%VAL()} is restricted to actual arguments in
5432 invocations of external procedures.
5433
5434 Use of @code{%VAL()} is recommended only for code that
5435 is accessing facilities outside of GNU Fortran, such as
5436 operating system or windowing facilities.
5437 It is best to constrain such uses to isolated portions of
5438 a program---portions the deal specifically and exclusively
5439 with low-level, system-dependent facilities.
5440 Such portions might well provide a portable interface for
5441 use by the program as a whole, but are themselves not
5442 portable, and should be thoroughly tested each time they
5443 are rebuilt using a new compiler or version of a compiler.
5444
5445 @emph{Implementation Note:} Currently, @code{g77} passes
5446 all arguments either by reference or by descriptor.
5447
5448 Thus, use of @code{%VAL()} tends to be restricted to cases
5449 where the called procedure is written in a language other
5450 than Fortran that supports call-by-value semantics.
5451 (C is an example of such a language.)
5452
5453 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)},
5454 for detailed information on
5455 how this particular version of @code{g77} passes arguments
5456 to procedures.
5457
5458 @node %REF()
5459 @subsection The @code{%REF()} Construct
5460 @cindex %REF() construct
5461
5462 @example
5463 %REF(@var{arg})
5464 @end example
5465
5466 The @code{%REF()} construct specifies that an argument,
5467 @var{arg}, is to be passed by reference, instead of by
5468 value or descriptor.
5469
5470 @code{%REF()} is restricted to actual arguments in
5471 invocations of external procedures.
5472
5473 Use of @code{%REF()} is recommended only for code that
5474 is accessing facilities outside of GNU Fortran, such as
5475 operating system or windowing facilities.
5476 It is best to constrain such uses to isolated portions of
5477 a program---portions the deal specifically and exclusively
5478 with low-level, system-dependent facilities.
5479 Such portions might well provide a portable interface for
5480 use by the program as a whole, but are themselves not
5481 portable, and should be thoroughly tested each time they
5482 are rebuilt using a new compiler or version of a compiler.
5483
5484 Do not depend on @code{%REF()} supplying a pointer to the
5485 procedure being invoked.
5486 While that is a likely implementation choice, other
5487 implementation choices are available that preserve Fortran
5488 pass-by-reference semantics without passing a pointer to
5489 the argument, @var{arg}.
5490 (For example, a copy-in/copy-out implementation.)
5491
5492 @emph{Implementation Note:} Currently, @code{g77} passes
5493 all arguments
5494 (other than variables and arrays of type @code{CHARACTER})
5495 by reference.
5496 Future versions of, or dialects supported by, @code{g77} might
5497 not pass @code{CHARACTER} functions by reference.
5498
5499 Thus, use of @code{%REF()} tends to be restricted to cases
5500 where @var{arg} is type @code{CHARACTER} but the called
5501 procedure accesses it via a means other than the method
5502 used for Fortran @code{CHARACTER} arguments.
5503
5504 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5505 how this particular version of @code{g77} passes arguments
5506 to procedures.
5507
5508 @node %DESCR()
5509 @subsection The @code{%DESCR()} Construct
5510 @cindex %DESCR() construct
5511
5512 @example
5513 %DESCR(@var{arg})
5514 @end example
5515
5516 The @code{%DESCR()} construct specifies that an argument,
5517 @var{arg}, is to be passed by descriptor, instead of by
5518 value or reference.
5519
5520 @code{%DESCR()} is restricted to actual arguments in
5521 invocations of external procedures.
5522
5523 Use of @code{%DESCR()} is recommended only for code that
5524 is accessing facilities outside of GNU Fortran, such as
5525 operating system or windowing facilities.
5526 It is best to constrain such uses to isolated portions of
5527 a program---portions the deal specifically and exclusively
5528 with low-level, system-dependent facilities.
5529 Such portions might well provide a portable interface for
5530 use by the program as a whole, but are themselves not
5531 portable, and should be thoroughly tested each time they
5532 are rebuilt using a new compiler or version of a compiler.
5533
5534 Do not depend on @code{%DESCR()} supplying a pointer
5535 and/or a length passed by value
5536 to the procedure being invoked.
5537 While that is a likely implementation choice, other
5538 implementation choices are available that preserve the
5539 pass-by-reference semantics without passing a pointer to
5540 the argument, @var{arg}.
5541 (For example, a copy-in/copy-out implementation.)
5542 And, future versions of @code{g77} might change the
5543 way descriptors are implemented, such as passing a
5544 single argument pointing to a record containing the
5545 pointer/length information instead of passing that same
5546 information via two arguments as it currently does.
5547
5548 @emph{Implementation Note:} Currently, @code{g77} passes
5549 all variables and arrays of type @code{CHARACTER}
5550 by descriptor.
5551 Future versions of, or dialects supported by, @code{g77} might
5552 pass @code{CHARACTER} functions by descriptor as well.
5553
5554 Thus, use of @code{%DESCR()} tends to be restricted to cases
5555 where @var{arg} is not type @code{CHARACTER} but the called
5556 procedure accesses it via a means similar to the method
5557 used for Fortran @code{CHARACTER} arguments.
5558
5559 @xref{Procedures,,Procedures (SUBROUTINE and FUNCTION)}, for detailed information on
5560 how this particular version of @code{g77} passes arguments
5561 to procedures.
5562
5563 @node Generics and Specifics
5564 @subsection Generics and Specifics
5565 @cindex generic intrinsics
5566 @cindex intrinsics, generic
5567
5568 The ANSI FORTRAN 77 language defines generic and specific
5569 intrinsics.
5570 In short, the distinctions are:
5571
5572 @itemize @bullet
5573 @item
5574 @emph{Specific} intrinsics have
5575 specific types for their arguments and a specific return
5576 type.
5577
5578 @item
5579 @emph{Generic} intrinsics are treated,
5580 on a case-by-case basis in the program's source code,
5581 as one of several possible specific intrinsics.
5582
5583 Typically, a generic intrinsic has a return type that
5584 is determined by the type of one or more of its arguments.
5585 @end itemize
5586
5587 The GNU Fortran language generalizes these concepts somewhat,
5588 especially by providing intrinsic subroutines and generic
5589 intrinsics that are treated as either a specific intrinsic subroutine
5590 or a specific intrinsic function (e.g. @code{SECOND}).
5591
5592 However, GNU Fortran avoids generalizing this concept to
5593 the point where existing code would be accepted as meaning
5594 something possibly different than what was intended.
5595
5596 For example, @code{ABS} is a generic intrinsic, so all working
5597 code written using @code{ABS} of an @code{INTEGER} argument
5598 expects an @code{INTEGER} return value.
5599 Similarly, all such code expects that @code{ABS} of an @code{INTEGER*2}
5600 argument returns an @code{INTEGER*2} return value.
5601
5602 Yet, @code{IABS} is a @emph{specific} intrinsic that accepts only
5603 an @code{INTEGER(KIND=1)} argument.
5604 Code that passes something other than an @code{INTEGER(KIND=1)}
5605 argument to @code{IABS} is not valid GNU Fortran code, because
5606 it is not clear what the author intended.
5607
5608 For example, if @samp{J} is @code{INTEGER(KIND=6)}, @samp{IABS(J)}
5609 is not defined by the GNU Fortran language, because the programmer
5610 might have used that construct to mean any of the following, subtly
5611 different, things:
5612
5613 @itemize @bullet
5614 @item
5615 Convert @samp{J} to @code{INTEGER(KIND=1)} first
5616 (as if @samp{IABS(INT(J))} had been written).
5617
5618 @item
5619 Convert the result of the intrinsic to @code{INTEGER(KIND=1)}
5620 (as if @samp{INT(ABS(J))} had been written).
5621
5622 @item
5623 No conversion (as if @samp{ABS(J)} had been written).
5624 @end itemize
5625
5626 The distinctions matter especially when types and values wider than
5627 @code{INTEGER(KIND=1)} (such as @code{INTEGER(KIND=2)}), or when
5628 operations performing more ``arithmetic'' than absolute-value, are involved.
5629
5630 The following sample program is not a valid GNU Fortran program, but
5631 might be accepted by other compilers.
5632 If so, the output is likely to be revealing in terms of how a given
5633 compiler treats intrinsics (that normally are specific) when they
5634 are given arguments that do not conform to their stated requirements:
5635
5636 @cindex JCB002 program
5637 @smallexample
5638       PROGRAM JCB002
5639 C Version 1:
5640 C Modified 1999-02-15 (Burley) to delete my email address.
5641 C Modified 1997-05-21 (Burley) to accommodate compilers that implement
5642 C INT(I1-I2) as INT(I1)-INT(I2) given INTEGER*2 I1,I2.
5643 C
5644 C Version 0:
5645 C Written by James Craig Burley 1997-02-20.
5646 C
5647 C Purpose:
5648 C Determine how compilers handle non-standard IDIM
5649 C on INTEGER*2 operands, which presumably can be
5650 C extrapolated into understanding how the compiler
5651 C generally treats specific intrinsics that are passed
5652 C arguments not of the correct types.
5653 C
5654 C If your compiler implements INTEGER*2 and INTEGER
5655 C as the same type, change all INTEGER*2 below to
5656 C INTEGER*1.
5657 C
5658       INTEGER*2 I0, I4
5659       INTEGER I1, I2, I3
5660       INTEGER*2 ISMALL, ILARGE
5661       INTEGER*2 ITOOLG, ITWO
5662       INTEGER*2 ITMP
5663       LOGICAL L2, L3, L4
5664 C
5665 C Find smallest INTEGER*2 number.
5666 C
5667       ISMALL=0
5668  10   I0 = ISMALL-1
5669       IF ((I0 .GE. ISMALL) .OR. (I0+1 .NE. ISMALL)) GOTO 20
5670       ISMALL = I0
5671       GOTO 10
5672  20   CONTINUE
5673 C
5674 C Find largest INTEGER*2 number.
5675 C
5676       ILARGE=0
5677  30   I0 = ILARGE+1
5678       IF ((I0 .LE. ILARGE) .OR. (I0-1 .NE. ILARGE)) GOTO 40
5679       ILARGE = I0
5680       GOTO 30
5681  40   CONTINUE
5682 C
5683 C Multiplying by two adds stress to the situation.
5684 C
5685       ITWO = 2
5686 C
5687 C Need a number that, added to -2, is too wide to fit in I*2.
5688 C
5689       ITOOLG = ISMALL
5690 C
5691 C Use IDIM the straightforward way.
5692 C
5693       I1 = IDIM (ILARGE, ISMALL) * ITWO + ITOOLG
5694 C
5695 C Calculate result for first interpretation.
5696 C
5697       I2 = (INT (ILARGE) - INT (ISMALL)) * ITWO + ITOOLG
5698 C
5699 C Calculate result for second interpretation.
5700 C
5701       ITMP = ILARGE - ISMALL
5702       I3 = (INT (ITMP)) * ITWO + ITOOLG
5703 C
5704 C Calculate result for third interpretation.
5705 C
5706       I4 = (ILARGE - ISMALL) * ITWO + ITOOLG
5707 C
5708 C Print results.
5709 C
5710       PRINT *, 'ILARGE=', ILARGE
5711       PRINT *, 'ITWO=', ITWO
5712       PRINT *, 'ITOOLG=', ITOOLG
5713       PRINT *, 'ISMALL=', ISMALL
5714       PRINT *, 'I1=', I1
5715       PRINT *, 'I2=', I2
5716       PRINT *, 'I3=', I3
5717       PRINT *, 'I4=', I4
5718       PRINT *
5719       L2 = (I1 .EQ. I2)
5720       L3 = (I1 .EQ. I3)
5721       L4 = (I1 .EQ. I4)
5722       IF (L2 .AND. .NOT.L3 .AND. .NOT.L4) THEN
5723          PRINT *, 'Interp 1: IDIM(I*2,I*2) => IDIM(INT(I*2),INT(I*2))'
5724          STOP
5725       END IF
5726       IF (L3 .AND. .NOT.L2 .AND. .NOT.L4) THEN
5727          PRINT *, 'Interp 2: IDIM(I*2,I*2) => INT(DIM(I*2,I*2))'
5728          STOP
5729       END IF
5730       IF (L4 .AND. .NOT.L2 .AND. .NOT.L3) THEN
5731          PRINT *, 'Interp 3: IDIM(I*2,I*2) => DIM(I*2,I*2)'
5732          STOP
5733       END IF
5734       PRINT *, 'Results need careful analysis.'
5735       END
5736 @end smallexample
5737
5738 No future version of the GNU Fortran language
5739 will likely permit specific intrinsic invocations with wrong-typed
5740 arguments (such as @code{IDIM} in the above example), since
5741 it has been determined that disagreements exist among
5742 many production compilers on the interpretation of
5743 such invocations.
5744 These disagreements strongly suggest that Fortran programmers,
5745 and certainly existing Fortran programs, disagree about the
5746 meaning of such invocations.
5747
5748 The first version of @code{JCB002} didn't accommodate some compilers'
5749 treatment of @samp{INT(I1-I2)} where @samp{I1} and @samp{I2} are
5750 @code{INTEGER*2}.
5751 In such a case, these compilers apparently convert both
5752 operands to @code{INTEGER*4} and then do an @code{INTEGER*4} subtraction,
5753 instead of doing an @code{INTEGER*2} subtraction on the
5754 original values in @samp{I1} and @samp{I2}.
5755
5756 However, the results of the careful analyses done on the outputs
5757 of programs compiled by these various compilers show that they
5758 all implement either @samp{Interp 1} or @samp{Interp 2} above.
5759
5760 Specifically, it is believed that the new version of @code{JCB002}
5761 above will confirm that:
5762
5763 @itemize @bullet
5764 @item
5765 Digital Semiconductor (``DEC'') Alpha OSF/1, HP-UX 10.0.1, AIX 3.2.5
5766 @code{f77} compilers all implement @samp{Interp 1}.
5767
5768 @item
5769 IRIX 5.3 @code{f77} compiler implements @samp{Interp 2}.
5770
5771 @item
5772 Solaris 2.5, SunOS 4.1.3, DECstation ULTRIX 4.3,
5773 and IRIX 6.1 @code{f77} compilers all implement @samp{Interp 3}.
5774 @end itemize
5775
5776 If you get different results than the above for the stated
5777 compilers, or have results for other compilers that might be
5778 worth adding to the above list, please let us know the details
5779 (compiler product, version, machine, results, and so on).
5780
5781 @node REAL() and AIMAG() of Complex
5782 @subsection @code{REAL()} and @code{AIMAG()} of Complex
5783 @cindex @code{Real} intrinsic
5784 @cindex intrinsics, @code{Real}
5785 @cindex @code{AImag} intrinsic
5786 @cindex intrinsics, @code{AImag}
5787
5788 The GNU Fortran language disallows @code{REAL(@var{expr})}
5789 and @code{AIMAG(@var{expr})},
5790 where @var{expr} is any @code{COMPLEX} type other than @code{COMPLEX(KIND=1)},
5791 except when they are used in the following way:
5792
5793 @example
5794 REAL(REAL(@var{expr}))
5795 REAL(AIMAG(@var{expr}))
5796 @end example
5797
5798 @noindent
5799 The above forms explicitly specify that the desired effect
5800 is to convert the real or imaginary part of @var{expr}, which might
5801 be some @code{REAL} type other than @code{REAL(KIND=1)},
5802 to type @code{REAL(KIND=1)},
5803 and have that serve as the value of the expression.
5804
5805 The GNU Fortran language offers clearly named intrinsics to extract the
5806 real and imaginary parts of a complex entity without any
5807 conversion:
5808
5809 @example
5810 REALPART(@var{expr})
5811 IMAGPART(@var{expr})
5812 @end example
5813
5814 To express the above using typical extended FORTRAN 77,
5815 use the following constructs
5816 (when @var{expr} is @code{COMPLEX(KIND=2)}):
5817
5818 @example
5819 DBLE(@var{expr})
5820 DIMAG(@var{expr})
5821 @end example
5822
5823 The FORTRAN 77 language offers no way
5824 to explicitly specify the real and imaginary parts of a complex expression of
5825 arbitrary type, apparently as a result of requiring support for
5826 only one @code{COMPLEX} type (@code{COMPLEX(KIND=1)}).
5827 The concepts of converting an expression to type @code{REAL(KIND=1)} and
5828 of extracting the real part of a complex expression were
5829 thus ``smooshed'' by FORTRAN 77 into a single intrinsic, since
5830 they happened to have the exact same effect in that language
5831 (due to having only one @code{COMPLEX} type).
5832
5833 @emph{Note:} When @samp{-ff90} is in effect,
5834 @code{g77} treats @samp{REAL(@var{expr})}, where @var{expr} is of
5835 type @code{COMPLEX}, as @samp{REALPART(@var{expr})},
5836 whereas with @samp{-fugly-complex -fno-f90} in effect, it is
5837 treated as @samp{REAL(REALPART(@var{expr}))}.
5838
5839 @xref{Ugly Complex Part Extraction}, for more information.
5840
5841 @node CMPLX() of DOUBLE PRECISION
5842 @subsection @code{CMPLX()} of @code{DOUBLE PRECISION}
5843 @cindex @code{Cmplx} intrinsic
5844 @cindex intrinsics, @code{Cmplx}
5845
5846 In accordance with Fortran 90 and at least some (perhaps all)
5847 other compilers, the GNU Fortran language defines @code{CMPLX()}
5848 as always returning a result that is type @code{COMPLEX(KIND=1)}.
5849
5850 This means @samp{CMPLX(D1,D2)}, where @samp{D1} and @samp{D2}
5851 are @code{REAL(KIND=2)} (@code{DOUBLE PRECISION}), is treated as:
5852
5853 @example
5854 CMPLX(SNGL(D1), SNGL(D2))
5855 @end example
5856
5857 (It was necessary for Fortran 90 to specify this behavior
5858 for @code{DOUBLE PRECISION} arguments, since that is
5859 the behavior mandated by FORTRAN 77.)
5860
5861 The GNU Fortran language also provides the @code{DCMPLX()} intrinsic,
5862 which is provided by some FORTRAN 77 compilers to construct
5863 a @code{DOUBLE COMPLEX} entity from of @code{DOUBLE PRECISION}
5864 operands.
5865 However, this solution does not scale well when more @code{COMPLEX} types
5866 (having various precisions and ranges) are offered by Fortran implementations.
5867
5868 Fortran 90 extends the @code{CMPLX()} intrinsic by adding
5869 an extra argument used to specify the desired kind of complex
5870 result.
5871 However, this solution is somewhat awkward to use, and
5872 @code{g77} currently does not support it.
5873
5874 The GNU Fortran language provides a simple way to build a complex
5875 value out of two numbers, with the precise type of the value
5876 determined by the types of the two numbers (via the usual
5877 type-promotion mechanism):
5878
5879 @example
5880 COMPLEX(@var{real}, @var{imag})
5881 @end example
5882
5883 When @var{real} and @var{imag} are the same @code{REAL} types, @code{COMPLEX()}
5884 performs no conversion other than to put them together to form a
5885 complex result of the same (complex version of real) type.
5886
5887 @xref{Complex Intrinsic}, for more information.
5888
5889 @node MIL-STD 1753
5890 @subsection MIL-STD 1753 Support
5891 @cindex MIL-STD 1753
5892
5893 The GNU Fortran language includes the MIL-STD 1753 intrinsics
5894 @code{BTEST}, @code{IAND}, @code{IBCLR}, @code{IBITS},
5895 @code{IBSET}, @code{IEOR}, @code{IOR}, @code{ISHFT},
5896 @code{ISHFTC}, @code{MVBITS}, and @code{NOT}.
5897
5898 @node f77/f2c Intrinsics
5899 @subsection @code{f77}/@code{f2c} Intrinsics
5900
5901 The bit-manipulation intrinsics supported by traditional
5902 @code{f77} and by @code{f2c} are available in the GNU Fortran language.
5903 These include @code{AND}, @code{LSHIFT}, @code{OR}, @code{RSHIFT},
5904 and @code{XOR}.
5905
5906 Also supported are the intrinsics @code{CDABS},
5907 @code{CDCOS}, @code{CDEXP}, @code{CDLOG}, @code{CDSIN},
5908 @code{CDSQRT}, @code{DCMPLX}, @code{DCONJG}, @code{DFLOAT},
5909 @code{DIMAG}, @code{DREAL}, and @code{IMAG},
5910 @code{ZABS}, @code{ZCOS}, @code{ZEXP}, @code{ZLOG}, @code{ZSIN},
5911 and @code{ZSQRT}.
5912
5913 @node Table of Intrinsic Functions
5914 @subsection Table of Intrinsic Functions
5915 @cindex intrinsics, table of
5916 @cindex table of intrinsics
5917
5918 (Corresponds to Section 15.10 of ANSI X3.9-1978 FORTRAN 77.)
5919
5920 The GNU Fortran language adds various functions, subroutines, types,
5921 and arguments to the set of intrinsic functions in ANSI FORTRAN 77.
5922 The complete set of intrinsics supported by the GNU Fortran language
5923 is described below.
5924
5925 Note that a name is not treated as that of an intrinsic if it is
5926 specified in an @code{EXTERNAL} statement in the same program unit;
5927 if a command-line option is used to disable the groups to which
5928 the intrinsic belongs; or if the intrinsic is not named in an
5929 @code{INTRINSIC} statement and a command-line option is used to
5930 hide the groups to which the intrinsic belongs.
5931
5932 So, it is recommended that any reference in a program unit to
5933 an intrinsic procedure that is not a standard FORTRAN 77
5934 intrinsic be accompanied by an appropriate @code{INTRINSIC}
5935 statement in that program unit.
5936 This sort of defensive programming makes it more
5937 likely that an implementation will issue a diagnostic rather
5938 than generate incorrect code for such a reference.
5939
5940 The terminology used below is based on that of the Fortran 90
5941 standard, so that the text may be more concise and accurate:
5942
5943 @itemize @bullet
5944 @item
5945 @code{OPTIONAL} means the argument may be omitted.
5946
5947 @item
5948 @samp{A-1, A-2, @dots{}, A-n} means more than one argument
5949 (generally named @samp{A}) may be specified.
5950
5951 @item
5952 @samp{scalar} means the argument must not be an array (must
5953 be a variable or array element, or perhaps a constant if expressions
5954 are permitted).
5955
5956 @item
5957 @samp{DIMENSION(4)} means the argument must be an array having 4 elements.
5958
5959 @item
5960 @code{INTENT(IN)} means the argument must be an expression
5961 (such as a constant or a variable that is defined upon invocation
5962 of the intrinsic).
5963
5964 @item
5965 @code{INTENT(OUT)} means the argument must be definable by the
5966 invocation of the intrinsic (that is, must not be a constant nor
5967 an expression involving operators other than array reference and
5968 substring reference).
5969
5970 @item
5971 @code{INTENT(INOUT)} means the argument must be defined prior to,
5972 and definable by, invocation of the intrinsic (a combination of
5973 the requirements of @code{INTENT(IN)} and @code{INTENT(OUT)}.
5974
5975 @item
5976 @xref{Kind Notation}, for an explanation of @code{KIND}.
5977 @end itemize
5978
5979 @ifinfo
5980 (Note that the empty lines appearing in the menu below
5981 are not intentional---they result from a bug in the
5982 GNU @code{makeinfo} program@dots{}a program that, if it
5983 did not exist, would leave this document in far worse shape!)
5984 @end ifinfo
5985
5986 @c The actual documentation for intrinsics comes from
5987 @c intdoc.texi, which in turn is automatically generated
5988 @c from the internal g77 tables in intrin.def _and_ the
5989 @c largely hand-written text in intdoc.h.  So, if you want
5990 @c to change or add to existing documentation on intrinsics,
5991 @c you probably want to edit intdoc.h.
5992 @c
5993 @set familyF77
5994 @set familyGNU
5995 @set familyASC
5996 @set familyMIL
5997 @set familyF90
5998 @clear familyVXT
5999 @clear familyFVZ
6000 @set familyF2C
6001 @set familyF2U
6002 @clear familyBADU77
6003 @include intdoc.texi
6004
6005 @node Scope and Classes of Names
6006 @section Scope and Classes of Symbolic Names
6007 @cindex symbol names, scope and classes
6008 @cindex scope
6009
6010 (The following information augments or overrides the information in
6011 Chapter 18 of ANSI X3.9-1978 FORTRAN 77 in specifying the GNU Fortran
6012 language.
6013 Chapter 18 of that document otherwise serves as the basis
6014 for the relevant aspects of GNU Fortran.)
6015
6016 @menu
6017 * Underscores in Symbol Names::
6018 @end menu
6019
6020 @node Underscores in Symbol Names
6021 @subsection Underscores in Symbol Names
6022 @cindex underscore
6023
6024 Underscores (@samp{_}) are accepted in symbol names after the first
6025 character (which must be a letter).
6026
6027 @node I/O
6028 @section I/O
6029
6030 @cindex dollar sign
6031 A dollar sign at the end of an output format specification suppresses
6032 the newline at the end of the output.
6033
6034 @cindex <> edit descriptor
6035 @cindex edit descriptor, <>
6036 Edit descriptors in @code{FORMAT} statements may contain compile-time
6037 @code{INTEGER} constant expressions in angle brackets, such as
6038 @smallexample
6039 10    FORMAT (I<WIDTH>)
6040 @end smallexample
6041
6042 The @code{OPEN} specifier @code{NAME=} is equivalent to @code{FILE=}.
6043
6044 These Fortran 90 features are supported:
6045 @itemize @bullet
6046 @item
6047 @cindex FORMAT descriptors
6048 @cindex Z edit descriptor
6049 @cindex edit descriptor, Z
6050 @cindex O edit descriptor
6051 @cindex edit descriptor, O
6052 The @code{O} and @code{Z} edit descriptors are supported for I/O of
6053 integers in octal and hexadecimal formats, respectively.
6054 @item
6055 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6056 @code{STATUS='SCRATCH'} is supplied.  The @code{STATUS='REPLACE'}
6057 specifier is supported.
6058 @end itemize
6059
6060 @node Fortran 90 Features
6061 @section Fortran 90 Features
6062 @cindex Fortran 90
6063 @cindex extensions, from Fortran 90
6064
6065 For convenience this section collects a list (probably incomplete) of
6066 the Fortran 90 features supported by the GNU Fortran language, even if
6067 they are documented elsewhere.
6068 @xref{Characters Lines Sequence,,@asis{Characters, Lines, and Execution Sequence}},
6069 for information on additional fixed source form lexical issues.
6070 @cindex @samp{-ffree-form}
6071 Further, the free source form is supported through the
6072 @samp{-ffree-form} option.
6073 @cindex @samp{-ff90}
6074 Other Fortran 90 features can be turned on by the @samp{-ff90} option;
6075 see @ref{Fortran 90}.
6076 For information on the Fortran 90 intrinsics available,
6077 see @ref{Table of Intrinsic Functions}.
6078
6079 @table @asis
6080 @item Automatic arrays in procedures
6081 @item Character assignments
6082 @cindex character assignments
6083 In character assignments, the variable being assigned may occur on the
6084 right hand side of the assignment.
6085 @item Character strings
6086 @cindex double quoted character constants
6087 Strings may have zero length and substrings of character constants are
6088 permitted.  Character constants may be enclosed in double quotes
6089 (@code{"}) as well as single quotes.  @xref{Character Type}.
6090 @item Construct names
6091 (Symbolic tags on blocks.)  @xref{Construct Names}.
6092 @item @code{CYCLE} and @code{EXIT}
6093 @xref{CYCLE and EXIT,,The @code{CYCLE} and @code{EXIT} Statements}.
6094 @item @code{DOUBLE COMPLEX}
6095 @xref{DOUBLE COMPLEX,,@code{DOUBLE COMPLEX} Statement}.
6096 @item @code{DO WHILE}
6097 @xref{DO WHILE}.
6098 @item @code{END} decoration
6099 @xref{Statements}.
6100 @item @code{END DO}
6101 @xref{END DO}.
6102 @item @code{KIND}
6103 @item @code{IMPLICIT NONE}
6104 @item @code{INCLUDE} statements
6105 @xref{INCLUDE}.
6106 @item List-directed and namelist I/O on internal files
6107 @item Binary, octal and hexadecimal constants
6108 These are supported more generally than required by Fortran 90.
6109 @xref{Integer Type}.
6110 @item @samp{O} and @samp{Z} edit descriptors
6111 @item @code{NAMELIST}
6112 @xref{NAMELIST}.
6113 @item @code{OPEN} specifiers
6114 @code{STATUS='REPLACE'} is supported.
6115 The @code{FILE=} specifier may be omitted in an @code{OPEN} statement if
6116 @code{STATUS='SCRATCH'} is supplied.
6117 @item @code{FORMAT} edit descriptors
6118 @cindex FORMAT descriptors
6119 @cindex Z edit descriptor
6120 @cindex edit descriptor, Z
6121 The @code{Z} edit descriptor is supported.
6122 @item Relational operators
6123 The operators @code{<}, @code{<=}, @code{==}, @code{/=}, @code{>} and
6124 @code{>=} may be used instead of @code{.LT.}, @code{.LE.}, @code{.EQ.},
6125 @code{.NE.}, @code{.GT.} and @code{.GE.} respectively.
6126 @item @code{SELECT CASE}
6127 Not fully implemented.
6128 @xref{SELECT CASE on CHARACTER Type,, @code{SELECT CASE} on @code{CHARACTER} Type}.
6129 @item Specification statements
6130 A limited subset of the Fortran 90 syntax and semantics for variable
6131 declarations is supported, including @code{KIND}.  @xref{Kind Notation}.
6132 (@code{KIND} is of limited usefulness in the absence of the
6133 @code{KIND}-related intrinsics, since these intrinsics permit writing
6134 more widely portable code.)  An example of supported @code{KIND} usage
6135 is:
6136 @smallexample
6137 INTEGER (KIND=1) :: FOO=1, BAR=2
6138 CHARACTER (LEN=3) FOO
6139 @end smallexample
6140 @code{PARAMETER} and @code{DIMENSION} attributes aren't supported.
6141 @end table
6142
6143 @node Other Dialects
6144 @chapter Other Dialects
6145
6146 GNU Fortran supports a variety of features that are not
6147 considered part of the GNU Fortran language itself, but
6148 are representative of various dialects of Fortran that
6149 @code{g77} supports in whole or in part.
6150
6151 Any of the features listed below might be disallowed by
6152 @code{g77} unless some command-line option is specified.
6153 Currently, some of the features are accepted using the
6154 default invocation of @code{g77}, but that might change
6155 in the future.
6156
6157 @emph{Note: This portion of the documentation definitely needs a lot
6158 of work!}
6159
6160 @menu
6161 * Source Form::       Details of fixed-form and free-form source.
6162 * Trailing Comment::  Use of @samp{/*} to start a comment.
6163 * Debug Line::        Use of @samp{D} in column 1.
6164 * Dollar Signs::      Use of @samp{$} in symbolic names.
6165 * Case Sensitivity::  Uppercase and lowercase in source files.
6166 * VXT Fortran::       @dots{}versus the GNU Fortran language.
6167 * Fortran 90::        @dots{}versus the GNU Fortran language.
6168 * Pedantic Compilation::  Enforcing the standard.
6169 * Distensions::       Misfeatures supported by GNU Fortran.
6170 @end menu
6171
6172 @node Source Form
6173 @section Source Form
6174 @cindex source file format
6175 @cindex source format
6176 @cindex file, source
6177 @cindex source code
6178 @cindex code, source
6179 @cindex fixed form
6180 @cindex free form
6181
6182 GNU Fortran accepts programs written in either fixed form or
6183 free form.
6184
6185 Fixed form
6186 corresponds to ANSI FORTRAN 77 (plus popular extensions, such as
6187 allowing tabs) and Fortran 90's fixed form.
6188
6189 Free form corresponds to
6190 Fortran 90's free form (though possibly not entirely up-to-date, and
6191 without complaining about some things that for which Fortran 90 requires
6192 diagnostics, such as the spaces in the constant in @samp{R = 3 . 1}).
6193
6194 The way a Fortran compiler views source files depends entirely on the
6195 implementation choices made for the compiler, since those choices
6196 are explicitly left to the implementation by the published Fortran
6197 standards.
6198 GNU Fortran currently tries to be somewhat like a few popular compilers
6199 (@code{f2c}, Digital (``DEC'') Fortran, and so on), though a cleaner default
6200 definition along with more
6201 flexibility offered by command-line options is likely to be offered
6202 in version 0.6.
6203
6204 This section describes how @code{g77} interprets source lines.
6205
6206 @menu
6207 * Carriage Returns::  Carriage returns ignored.
6208 * Tabs::              Tabs converted to spaces.
6209 * Short Lines::       Short lines padded with spaces (fixed-form only).
6210 * Long Lines::        Long lines truncated.
6211 * Ampersands::        Special Continuation Lines.
6212 @end menu
6213
6214 @node Carriage Returns
6215 @subsection Carriage Returns
6216 @cindex carriage returns
6217
6218 Carriage returns (@samp{\r}) in source lines are ignored.
6219 This is somewhat different from @code{f2c}, which seems to treat them as
6220 spaces outside character/Hollerith constants, and encodes them as @samp{\r}
6221 inside such constants.
6222
6223 @node Tabs
6224 @subsection Tabs
6225 @cindex tab character
6226 @cindex horizontal tab
6227
6228 A source line with a @key{TAB} character anywhere in it is treated as
6229 entirely significant---however long it is---instead of ending in
6230 column 72 (for fixed-form source) or 132 (for free-form source).
6231 This also is different from @code{f2c}, which encodes tabs as
6232 @samp{\t} (the ASCII @key{TAB} character) inside character
6233 and Hollerith constants, but nevertheless seems to treat the column
6234 position as if it had been affected by the canonical tab positioning.
6235
6236 @code{g77} effectively
6237 translates tabs to the appropriate number of spaces (a la the default
6238 for the UNIX @code{expand} command) before doing any other processing, other
6239 than (currently) noting whether a tab was found on a line and using this
6240 information to decide how to interpret the length of the line and continued
6241 constants.
6242
6243 Note that this default behavior probably will change for version 0.6,
6244 when it will presumably be available via a command-line option.
6245 The default as of version 0.6 is planned to be a ``pure visual''
6246 model, where tabs are immediately
6247 converted to spaces and otherwise have no effect, so the way a typical
6248 user sees source lines produces a consistent result no matter how the
6249 spacing in those source lines is actually implemented via tabs, spaces,
6250 and trailing tabs/spaces before newline.
6251 Command-line options are likely to be added to specify whether all or
6252 just-tabbed lines are to be extended to 132 or full input-line length,
6253 and perhaps even an option will be added to specify the truncated-line
6254 behavior to which some Digital compilers default (and which affects
6255 the way continued character/Hollerith constants are interpreted).
6256
6257 @node Short Lines
6258 @subsection Short Lines
6259 @cindex short source lines
6260 @cindex space, padding with
6261 @cindex source lines, short
6262 @cindex lines, short
6263
6264 Source lines shorter than the applicable fixed-form length are treated as
6265 if they were padded with spaces to that length.
6266 (None of this is relevant to source files written in free form.)
6267
6268 This affects only
6269 continued character and Hollerith constants, and is a different
6270 interpretation than provided by some other popular compilers
6271 (although a bit more consistent with the traditional punched-card
6272 basis of Fortran and the way the Fortran standard expressed fixed
6273 source form).
6274
6275 @code{g77} might someday offer an option to warn about cases where differences
6276 might be seen as a result of this treatment, and perhaps an option to
6277 specify the alternate behavior as well.
6278
6279 Note that this padding cannot apply to lines that are effectively of
6280 infinite length---such lines are specified using command-line options
6281 like @samp{-ffixed-line-length-none}, for example.
6282
6283 @node Long Lines
6284 @subsection Long Lines
6285 @cindex long source lines
6286 @cindex truncation, of long lines
6287 @cindex lines, long
6288 @cindex source lines, long
6289
6290 Source lines longer than the applicable length are truncated to that
6291 length.
6292 Currently, @code{g77} does not warn if the truncated characters are
6293 not spaces, to accommodate existing code written for systems that
6294 treated truncated text as commentary (especially in columns 73 through 80).
6295
6296 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect},
6297 for information on the @samp{-ffixed-line-length-@var{n}} option,
6298 which can be used to set the line length applicable to fixed-form
6299 source files.
6300
6301 @node Ampersands
6302 @subsection Ampersand Continuation Line
6303 @cindex ampersand continuation line
6304 @cindex continuation line, ampersand
6305
6306 A @samp{&} in column 1 of fixed-form source denotes an arbitrary-length
6307 continuation line, imitating the behavior of @code{f2c}.
6308
6309 @node Trailing Comment
6310 @section Trailing Comment
6311
6312 @cindex trailing comment
6313 @cindex comment
6314 @cindex characters, comment
6315 @cindex /*
6316 @cindex !
6317 @cindex exclamation point
6318 @code{g77} supports use of @samp{/*} to start a trailing
6319 comment.
6320 In the GNU Fortran language, @samp{!} is used for this purpose.
6321
6322 @samp{/*} is not in the GNU Fortran language
6323 because the use of @samp{/*} in a program might
6324 suggest to some readers that a block, not trailing, comment is
6325 started (and thus ended by @samp{*/}, not end of line),
6326 since that is the meaning of @samp{/*} in C.
6327
6328 Also, such readers might think they can use @samp{//} to start
6329 a trailing comment as an alternative to @samp{/*}, but
6330 @samp{//} already denotes concatenation, and such a ``comment''
6331 might actually result in a program that compiles without
6332 error (though it would likely behave incorrectly).
6333
6334 @node Debug Line
6335 @section Debug Line
6336 @cindex debug line
6337 @cindex comment line, debug
6338
6339 Use of @samp{D} or @samp{d} as the first character (column 1) of
6340 a source line denotes a debug line.
6341
6342 In turn, a debug line is treated as either a comment line
6343 or a normal line, depending on whether debug lines are enabled.
6344
6345 When treated as a comment line, a line beginning with @samp{D} or
6346 @samp{d} is treated as if it the first character was @samp{C} or @samp{c}, respectively.
6347 When treated as a normal line, such a line is treated as if
6348 the first character was @key{SPC} (space).
6349
6350 (Currently, @code{g77} provides no means for treating debug
6351 lines as normal lines.)
6352
6353 @node Dollar Signs
6354 @section Dollar Signs in Symbol Names
6355 @cindex dollar sign
6356 @cindex $
6357
6358 Dollar signs (@samp{$}) are allowed in symbol names (after the first character)
6359 when the @samp{-fdollar-ok} option is specified.
6360
6361 @node Case Sensitivity
6362 @section Case Sensitivity
6363 @cindex case sensitivity
6364 @cindex source file format
6365 @cindex code, source
6366 @cindex source code
6367 @cindex uppercase letters
6368 @cindex lowercase letters
6369 @cindex letters, uppercase
6370 @cindex letters, lowercase
6371
6372 GNU Fortran offers the programmer way too much flexibility in deciding
6373 how source files are to be treated vis-a-vis uppercase and lowercase
6374 characters.
6375 There are 66 useful settings that affect case sensitivity, plus 10
6376 settings that are nearly useless, with the remaining 116 settings
6377 being either redundant or useless.
6378
6379 None of these settings have any effect on the contents of comments
6380 (the text after a @samp{c} or @samp{C} in Column 1, for example)
6381 or of character or Hollerith constants.
6382 Note that things like the @samp{E} in the statement
6383 @samp{CALL FOO(3.2E10)} and the @samp{TO} in @samp{ASSIGN 10 TO LAB}
6384 are considered built-in keywords, and so are affected by
6385 these settings.
6386
6387 Low-level switches are identified in this section as follows:
6388
6389 @itemize @w{}
6390 @item A
6391 Source Case Conversion:
6392
6393 @itemize @w{}
6394 @item 0
6395 Preserve (see Note 1)
6396 @item 1
6397 Convert to Upper Case
6398 @item 2
6399 Convert to Lower Case
6400 @end itemize
6401
6402 @item B
6403 Built-in Keyword Matching:
6404
6405 @itemize @w{}
6406 @item 0
6407 Match Any Case (per-character basis)
6408 @item 1
6409 Match Upper Case Only
6410 @item 2
6411 Match Lower Case Only
6412 @item 3
6413 Match InitialCaps Only (see tables for spellings)
6414 @end itemize
6415
6416 @item C
6417 Built-in Intrinsic Matching:
6418
6419 @itemize @w{}
6420 @item 0
6421 Match Any Case (per-character basis)
6422 @item 1
6423 Match Upper Case Only
6424 @item 2
6425 Match Lower Case Only
6426 @item 3
6427 Match InitialCaps Only (see tables for spellings)
6428 @end itemize
6429
6430 @item D
6431 User-defined Symbol Possibilities (warnings only):
6432
6433 @itemize @w{}
6434 @item 0
6435 Allow Any Case (per-character basis)
6436 @item 1
6437 Allow Upper Case Only
6438 @item 2
6439 Allow Lower Case Only
6440 @item 3
6441 Allow InitialCaps Only (see Note 2)
6442 @end itemize
6443 @end itemize
6444
6445 Note 1: @code{g77} eventually will support @code{NAMELIST} in a manner that is
6446 consistent with these source switches---in the sense that input will be
6447 expected to meet the same requirements as source code in terms
6448 of matching symbol names and keywords (for the exponent letters).
6449
6450 Currently, however, @code{NAMELIST} is supported by @code{libg2c},
6451 which uppercases @code{NAMELIST} input and symbol names for matching.
6452 This means not only that @code{NAMELIST} output currently shows symbol
6453 (and keyword) names in uppercase even if lower-case source
6454 conversion (option A2) is selected, but that @code{NAMELIST} cannot be
6455 adequately supported when source case preservation (option A0)
6456 is selected.
6457
6458 If A0 is selected, a warning message will be
6459 output for each @code{NAMELIST} statement to this effect.
6460 The behavior
6461 of the program is undefined at run time if two or more symbol names
6462 appear in a given @code{NAMELIST} such that the names are identical
6463 when converted to upper case (e.g. @samp{NAMELIST /X/ VAR, Var, var}).
6464 For complete and total elegance, perhaps there should be a warning
6465 when option A2 is selected, since the output of NAMELIST is currently
6466 in uppercase but will someday be lowercase (when a @code{libg77} is written),
6467 but that seems to be overkill for a product in beta test.
6468
6469 Note 2: Rules for InitialCaps names are:
6470
6471 @itemize @minus
6472 @item
6473 Must be a single uppercase letter, @strong{or}
6474 @item
6475 Must start with an uppercase letter and contain at least one
6476 lowercase letter.
6477 @end itemize
6478
6479 So @samp{A}, @samp{Ab}, @samp{ABc}, @samp{AbC}, and @samp{Abc} are
6480 valid InitialCaps names, but @samp{AB}, @samp{A2}, and @samp{ABC} are
6481 not.
6482 Note that most, but not all, built-in names meet these
6483 requirements---the exceptions are some of the two-letter format
6484 specifiers, such as @code{BN} and @code{BZ}.
6485
6486 Here are the names of the corresponding command-line options:
6487
6488 @smallexample
6489 A0: -fsource-case-preserve
6490 A1: -fsource-case-upper
6491 A2: -fsource-case-lower
6492
6493 B0: -fmatch-case-any
6494 B1: -fmatch-case-upper
6495 B2: -fmatch-case-lower
6496 B3: -fmatch-case-initcap
6497
6498 C0: -fintrin-case-any
6499 C1: -fintrin-case-upper
6500 C2: -fintrin-case-lower
6501 C3: -fintrin-case-initcap
6502
6503 D0: -fsymbol-case-any
6504 D1: -fsymbol-case-upper
6505 D2: -fsymbol-case-lower
6506 D3: -fsymbol-case-initcap
6507 @end smallexample
6508
6509 Useful combinations of the above settings, along with abbreviated
6510 option names that set some of these combinations all at once:
6511
6512 @smallexample
6513  1: A0--  B0---  C0---  D0---    -fcase-preserve
6514  2: A0--  B0---  C0---  D-1--
6515  3: A0--  B0---  C0---  D--2-
6516  4: A0--  B0---  C0---  D---3
6517  5: A0--  B0---  C-1--  D0---
6518  6: A0--  B0---  C-1--  D-1--
6519  7: A0--  B0---  C-1--  D--2-
6520  8: A0--  B0---  C-1--  D---3
6521  9: A0--  B0---  C--2-  D0---
6522 10: A0--  B0---  C--2-  D-1--
6523 11: A0--  B0---  C--2-  D--2-
6524 12: A0--  B0---  C--2-  D---3
6525 13: A0--  B0---  C---3  D0---
6526 14: A0--  B0---  C---3  D-1--
6527 15: A0--  B0---  C---3  D--2-
6528 16: A0--  B0---  C---3  D---3
6529 17: A0--  B-1--  C0---  D0---
6530 18: A0--  B-1--  C0---  D-1--
6531 19: A0--  B-1--  C0---  D--2-
6532 20: A0--  B-1--  C0---  D---3
6533 21: A0--  B-1--  C-1--  D0---
6534 22: A0--  B-1--  C-1--  D-1--    -fcase-strict-upper
6535 23: A0--  B-1--  C-1--  D--2-
6536 24: A0--  B-1--  C-1--  D---3
6537 25: A0--  B-1--  C--2-  D0---
6538 26: A0--  B-1--  C--2-  D-1--
6539 27: A0--  B-1--  C--2-  D--2-
6540 28: A0--  B-1--  C--2-  D---3
6541 29: A0--  B-1--  C---3  D0---
6542 30: A0--  B-1--  C---3  D-1--
6543 31: A0--  B-1--  C---3  D--2-
6544 32: A0--  B-1--  C---3  D---3
6545 33: A0--  B--2-  C0---  D0---
6546 34: A0--  B--2-  C0---  D-1--
6547 35: A0--  B--2-  C0---  D--2-
6548 36: A0--  B--2-  C0---  D---3
6549 37: A0--  B--2-  C-1--  D0---
6550 38: A0--  B--2-  C-1--  D-1--
6551 39: A0--  B--2-  C-1--  D--2-
6552 40: A0--  B--2-  C-1--  D---3
6553 41: A0--  B--2-  C--2-  D0---
6554 42: A0--  B--2-  C--2-  D-1--
6555 43: A0--  B--2-  C--2-  D--2-    -fcase-strict-lower
6556 44: A0--  B--2-  C--2-  D---3
6557 45: A0--  B--2-  C---3  D0---
6558 46: A0--  B--2-  C---3  D-1--
6559 47: A0--  B--2-  C---3  D--2-
6560 48: A0--  B--2-  C---3  D---3
6561 49: A0--  B---3  C0---  D0---
6562 50: A0--  B---3  C0---  D-1--
6563 51: A0--  B---3  C0---  D--2-
6564 52: A0--  B---3  C0---  D---3
6565 53: A0--  B---3  C-1--  D0---
6566 54: A0--  B---3  C-1--  D-1--
6567 55: A0--  B---3  C-1--  D--2-
6568 56: A0--  B---3  C-1--  D---3
6569 57: A0--  B---3  C--2-  D0---
6570 58: A0--  B---3  C--2-  D-1--
6571 59: A0--  B---3  C--2-  D--2-
6572 60: A0--  B---3  C--2-  D---3
6573 61: A0--  B---3  C---3  D0---
6574 62: A0--  B---3  C---3  D-1--
6575 63: A0--  B---3  C---3  D--2-
6576 64: A0--  B---3  C---3  D---3    -fcase-initcap
6577 65: A-1-  B01--  C01--  D01--    -fcase-upper
6578 66: A--2  B0-2-  C0-2-  D0-2-    -fcase-lower
6579 @end smallexample
6580
6581 Number 22 is the ``strict'' ANSI FORTRAN 77 model wherein all input
6582 (except comments, character constants, and Hollerith strings) must
6583 be entered in uppercase.
6584 Use @samp{-fcase-strict-upper} to specify this
6585 combination.
6586
6587 Number 43 is like Number 22 except all input must be lowercase.  Use
6588 @samp{-fcase-strict-lower} to specify this combination.
6589
6590 Number 65 is the ``classic'' ANSI FORTRAN 77 model as implemented on many
6591 non-UNIX machines whereby all the source is translated to uppercase.
6592 Use @samp{-fcase-upper} to specify this combination.
6593
6594 Number 66 is the ``canonical'' UNIX model whereby all the source is
6595 translated to lowercase.
6596 Use @samp{-fcase-lower} to specify this combination.
6597
6598 There are a few nearly useless combinations:
6599
6600 @smallexample
6601 67: A-1-  B01--  C01--  D--2-
6602 68: A-1-  B01--  C01--  D---3
6603 69: A-1-  B01--  C--23  D01--
6604 70: A-1-  B01--  C--23  D--2-
6605 71: A-1-  B01--  C--23  D---3
6606 72: A--2  B01--  C0-2-  D-1--
6607 73: A--2  B01--  C0-2-  D---3
6608 74: A--2  B01--  C-1-3  D0-2-
6609 75: A--2  B01--  C-1-3  D-1--
6610 76: A--2  B01--  C-1-3  D---3
6611 @end smallexample
6612
6613 The above allow some programs to be compiled but with restrictions that
6614 make most useful programs impossible: Numbers 67 and 72 warn about
6615 @emph{any} user-defined symbol names (such as @samp{SUBROUTINE FOO});
6616 Numbers
6617 68 and 73 warn about any user-defined symbol names longer than one
6618 character that don't have at least one non-alphabetic character after
6619 the first;
6620 Numbers 69 and 74 disallow any references to intrinsics;
6621 and Numbers 70, 71, 75, and 76 are combinations of the restrictions in
6622 67+69, 68+69, 72+74, and 73+74, respectively.
6623
6624 All redundant combinations are shown in the above tables anyplace
6625 where more than one setting is shown for a low-level switch.
6626 For example, @samp{B0-2-} means either setting 0 or 2 is valid for switch B.
6627 The ``proper'' setting in such a case is the one that copies the setting
6628 of switch A---any other setting might slightly reduce the speed of
6629 the compiler, though possibly to an unmeasurable extent.
6630
6631 All remaining combinations are useless in that they prevent successful
6632 compilation of non-null source files (source files with something other
6633 than comments).
6634
6635 @node VXT Fortran
6636 @section VXT Fortran
6637
6638 @cindex VXT extensions
6639 @cindex extensions, VXT
6640 @code{g77} supports certain constructs that
6641 have different meanings in VXT Fortran than they
6642 do in the GNU Fortran language.
6643
6644 Generally, this manual uses the invented term VXT Fortran to refer
6645 VAX FORTRAN (circa v4).
6646 That compiler offered many popular features, though not necessarily
6647 those that are specific to the VAX processor architecture,
6648 the VMS operating system,
6649 or Digital Equipment Corporation's Fortran product line.
6650 (VAX and VMS probably are trademarks of Digital Equipment
6651 Corporation.)
6652
6653 An extension offered by a Digital Fortran product that also is
6654 offered by several other Fortran products for different kinds of
6655 systems is probably going to be considered for inclusion in @code{g77}
6656 someday, and is considered a VXT Fortran feature.
6657
6658 The @samp{-fvxt} option generally specifies that, where
6659 the meaning of a construct is ambiguous (means one thing
6660 in GNU Fortran and another in VXT Fortran), the VXT Fortran
6661 meaning is to be assumed.
6662
6663 @menu
6664 * Double Quote Meaning::  @samp{"2000} as octal constant.
6665 * Exclamation Point::     @samp{!} in column 6.
6666 @end menu
6667
6668 @node Double Quote Meaning
6669 @subsection Meaning of Double Quote
6670 @cindex double quotes
6671 @cindex character constants
6672 @cindex constants, character
6673 @cindex octal constants
6674 @cindex constants, octal
6675
6676 @code{g77} treats double-quote (@samp{"})
6677 as beginning an octal constant of @code{INTEGER(KIND=1)} type
6678 when the @samp{-fvxt} option is specified.
6679 The form of this octal constant is
6680
6681 @example
6682 "@var{octal-digits}
6683 @end example
6684
6685 @noindent
6686 where @var{octal-digits} is a nonempty string of characters in
6687 the set @samp{01234567}.
6688
6689 For example, the @samp{-fvxt} option permits this:
6690
6691 @example
6692 PRINT *, "20
6693 END
6694 @end example
6695
6696 @noindent
6697 The above program would print the value @samp{16}.
6698
6699 @xref{Integer Type}, for information on the preferred construct
6700 for integer constants specified using GNU Fortran's octal notation.
6701
6702 (In the GNU Fortran language, the double-quote character (@samp{"})
6703 delimits a character constant just as does apostrophe (@samp{'}).
6704 There is no way to allow
6705 both constructs in the general case, since statements like
6706 @samp{PRINT *,"2000 !comment?"} would be ambiguous.)
6707
6708 @node Exclamation Point
6709 @subsection Meaning of Exclamation Point in Column 6
6710 @cindex !
6711 @cindex exclamation point
6712 @cindex continuation character
6713 @cindex characters, continuation
6714 @cindex comment character
6715 @cindex characters, comment
6716
6717 @code{g77} treats an exclamation point (@samp{!}) in column 6 of
6718 a fixed-form source file
6719 as a continuation character rather than
6720 as the beginning of a comment
6721 (as it does in any other column)
6722 when the @samp{-fvxt} option is specified.
6723
6724 The following program, when run, prints a message indicating
6725 whether it is interpreted according to GNU Fortran (and Fortran 90)
6726 rules or VXT Fortran rules:
6727
6728 @smallexample
6729 C234567  (This line begins in column 1.)
6730       I = 0
6731      !1
6732       IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program'
6733       IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program'
6734       IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer'
6735       END
6736 @end smallexample
6737
6738 (In the GNU Fortran and Fortran 90 languages, exclamation point is
6739 a valid character and, unlike space (@key{SPC}) or zero (@samp{0}),
6740 marks a line as a continuation line when it appears in column 6.)
6741
6742 @node Fortran 90
6743 @section Fortran 90
6744 @cindex compatibility, Fortran 90
6745 @cindex Fortran 90, compatibility
6746
6747 The GNU Fortran language includes a number of features that are
6748 part of Fortran 90, even when the @samp{-ff90} option is not specified.
6749 The features enabled by @samp{-ff90} are intended to be those that,
6750 when @samp{-ff90} is not specified, would have another
6751 meaning to @code{g77}---usually meaning something invalid in the
6752 GNU Fortran language.
6753
6754 So, the purpose of @samp{-ff90} is not to specify whether @code{g77} is
6755 to gratuitously reject Fortran 90 constructs.
6756 The @samp{-pedantic} option specified with @samp{-fno-f90} is intended
6757 to do that, although its implementation is certainly incomplete at
6758 this point.
6759
6760 When @samp{-ff90} is specified:
6761
6762 @itemize @bullet
6763 @item
6764 The type of @samp{REAL(@var{expr})} and @samp{AIMAG(@var{expr})},
6765 where @var{expr} is @code{COMPLEX} type,
6766 is the same type as the real part of @var{expr}.
6767
6768 For example, assuming @samp{Z} is type @code{COMPLEX(KIND=2)},
6769 @samp{REAL(Z)} would return a value of type @code{REAL(KIND=2)},
6770 not of type @code{REAL(KIND=1)}, since @samp{-ff90} is specified.
6771 @end itemize
6772
6773 @node Pedantic Compilation
6774 @section Pedantic Compilation
6775 @cindex pedantic compilation
6776 @cindex compilation, pedantic
6777
6778 The @samp{-fpedantic} command-line option specifies that @code{g77}
6779 is to warn about code that is not standard-conforming.
6780 This is useful for finding
6781 some extensions @code{g77} accepts that other compilers might not accept.
6782 (Note that the @samp{-pedantic} and @samp{-pedantic-errors} options
6783 always imply @samp{-fpedantic}.)
6784
6785 With @samp{-fno-f90} in force, ANSI FORTRAN 77 is used as the standard
6786 for conforming code.
6787 With @samp{-ff90} in force, Fortran 90 is used.
6788
6789 The constructs for which @code{g77} issues diagnostics when @samp{-fpedantic}
6790 and @samp{-fno-f90} are in force are:
6791
6792 @itemize @bullet
6793 @item
6794 Automatic arrays, as in
6795
6796 @example
6797 SUBROUTINE X(N)
6798 REAL A(N)
6799 @dots{}
6800 @end example
6801
6802 @noindent
6803 where @samp{A} is not listed in any @code{ENTRY} statement,
6804 and thus is not a dummy argument.
6805
6806 @item
6807 The commas in @samp{READ (5), I} and @samp{WRITE (10), J}.
6808
6809 These commas are disallowed by FORTRAN 77, but, while strictly
6810 superfluous, are syntactically elegant,
6811 especially given that commas are required in statements such
6812 as @samp{READ 99, I} and @samp{PRINT *, J}.
6813 Many compilers permit the superfluous commas for this reason.
6814
6815 @item
6816 @code{DOUBLE COMPLEX}, either explicitly or implicitly.
6817
6818 An explicit use of this type is via a @code{DOUBLE COMPLEX} or
6819 @code{IMPLICIT DOUBLE COMPLEX} statement, for examples.
6820
6821 An example of an implicit use is the expression @samp{C*D},
6822 where @samp{C} is @code{COMPLEX(KIND=1)}
6823 and @samp{D} is @code{DOUBLE PRECISION}.
6824 This expression is prohibited by ANSI FORTRAN 77
6825 because the rules of promotion would suggest that it
6826 produce a @code{DOUBLE COMPLEX} result---a type not
6827 provided for by that standard.
6828
6829 @item
6830 Automatic conversion of numeric
6831 expressions to @code{INTEGER(KIND=1)} in contexts such as:
6832
6833 @itemize @minus
6834 @item
6835 Array-reference indexes.
6836 @item
6837 Alternate-return values.
6838 @item
6839 Computed @code{GOTO}.
6840 @item
6841 @code{FORMAT} run-time expressions (not yet supported).
6842 @item
6843 Dimension lists in specification statements.
6844 @item
6845 Numbers for I/O statements (such as @samp{READ (UNIT=3.2), I})
6846 @item
6847 Sizes of @code{CHARACTER} entities in specification statements.
6848 @item
6849 Kind types in specification entities (a Fortran 90 feature).
6850 @item
6851 Initial, terminal, and incrementation parameters for implied-@code{DO}
6852 constructs in @code{DATA} statements.
6853 @end itemize
6854
6855 @item
6856 Automatic conversion of @code{LOGICAL} expressions to @code{INTEGER}
6857 in contexts such as arithmetic @code{IF} (where @code{COMPLEX}
6858 expressions are disallowed anyway).
6859
6860 @item
6861 Zero-size array dimensions, as in:
6862
6863 @example
6864 INTEGER I(10,20,4:2)
6865 @end example
6866
6867 @item
6868 Zero-length @code{CHARACTER} entities, as in:
6869
6870 @example
6871 PRINT *, ''
6872 @end example
6873
6874 @item
6875 Substring operators applied to character constants and named
6876 constants, as in:
6877
6878 @example
6879 PRINT *, 'hello'(3:5)
6880 @end example
6881
6882 @item
6883 Null arguments passed to statement function, as in:
6884
6885 @example
6886 PRINT *, FOO(,3)
6887 @end example
6888
6889 @item
6890 Disagreement among program units regarding whether a given @code{COMMON}
6891 area is @code{SAVE}d (for targets where program units in a single source
6892 file are ``glued'' together as they typically are for UNIX development
6893 environments).
6894
6895 @item
6896 Disagreement among program units regarding the size of a
6897 named @code{COMMON} block.
6898
6899 @item
6900 Specification statements following first @code{DATA} statement.
6901
6902 (In the GNU Fortran language, @samp{DATA I/1/} may be followed by @samp{INTEGER J},
6903 but not @samp{INTEGER I}.
6904 The @samp{-fpedantic} option disallows both of these.)
6905
6906 @item
6907 Semicolon as statement separator, as in:
6908
6909 @example
6910 CALL FOO; CALL BAR
6911 @end example
6912 @c
6913 @c @item
6914 @c Comma before list of I/O items in @code{WRITE}
6915 @c  @c, @code{ENCODE}, @code{DECODE}, and @code{REWRITE}
6916 @c statements, as with @code{READ} (as explained above).
6917
6918 @item
6919 Use of @samp{&} in column 1 of fixed-form source (to indicate continuation).
6920
6921 @item
6922 Use of @code{CHARACTER} constants to initialize numeric entities, and vice
6923 versa.
6924
6925 @item
6926 Expressions having two arithmetic operators in a row, such
6927 as @samp{X*-Y}.
6928 @end itemize
6929
6930 If @samp{-fpedantic} is specified along with @samp{-ff90}, the
6931 following constructs result in diagnostics:
6932
6933 @itemize @bullet
6934 @item
6935 Use of semicolon as a statement separator on a line
6936 that has an @code{INCLUDE} directive.
6937 @end itemize
6938
6939 @node Distensions
6940 @section Distensions
6941 @cindex distensions
6942 @cindex ugly features
6943 @cindex features, ugly
6944
6945 The @samp{-fugly-*} command-line options determine whether certain
6946 features supported by VAX FORTRAN and other such compilers, but considered
6947 too ugly to be in code that can be changed to use safer and/or more
6948 portable constructs, are accepted.
6949 These are humorously referred to as ``distensions'',
6950 extensions that just plain look ugly in the harsh light of day.
6951
6952 @menu
6953 * Ugly Implicit Argument Conversion::  Disabled via @samp{-fno-ugly-args}.
6954 * Ugly Assumed-Size Arrays::           Enabled via @samp{-fugly-assumed}.
6955 * Ugly Null Arguments::                Enabled via @samp{-fugly-comma}.
6956 * Ugly Complex Part Extraction::       Enabled via @samp{-fugly-complex}.
6957 * Ugly Conversion of Initializers::    Disabled via @samp{-fno-ugly-init}.
6958 * Ugly Integer Conversions::           Enabled via @samp{-fugly-logint}.
6959 * Ugly Assigned Labels::               Enabled via @samp{-fugly-assign}.
6960 @end menu
6961
6962 @node Ugly Implicit Argument Conversion
6963 @subsection Implicit Argument Conversion
6964 @cindex Hollerith constants
6965 @cindex constants, Hollerith
6966
6967 The @samp{-fno-ugly-args} option disables
6968 passing typeless and Hollerith constants as actual arguments
6969 in procedure invocations.
6970 For example:
6971
6972 @example
6973 CALL FOO(4HABCD)
6974 CALL BAR('123'O)
6975 @end example
6976
6977 @noindent
6978 These constructs can be too easily used to create non-portable
6979 code, but are not considered as ``ugly'' as others.
6980 Further, they are widely used in existing Fortran source code
6981 in ways that often are quite portable.
6982 Therefore, they are enabled by default.
6983
6984 @node Ugly Assumed-Size Arrays
6985 @subsection Ugly Assumed-Size Arrays
6986 @cindex arrays, assumed-size
6987 @cindex assumed-size arrays
6988 @cindex DIMENSION X(1)
6989
6990 The @samp{-fugly-assumed} option enables
6991 the treatment of any array with a final dimension specified as @samp{1}
6992 as an assumed-size array, as if @samp{*} had been specified
6993 instead.
6994
6995 For example, @samp{DIMENSION X(1)} is treated as if it
6996 had read @samp{DIMENSION X(*)} if @samp{X} is listed as
6997 a dummy argument in a preceding @code{SUBROUTINE}, @code{FUNCTION},
6998 or @code{ENTRY} statement in the same program unit.
6999
7000 Use an explicit lower bound to avoid this interpretation.
7001 For example, @samp{DIMENSION X(1:1)} is never treated as if
7002 it had read @samp{DIMENSION X(*)} or @samp{DIMENSION X(1:*)}.
7003 Nor is @samp{DIMENSION X(2-1)} affected by this option,
7004 since that kind of expression is unlikely to have been
7005 intended to designate an assumed-size array.
7006
7007 This option is used to prevent warnings being issued about apparent
7008 out-of-bounds reference such as @samp{X(2) = 99}.
7009
7010 It also prevents the array from being used in contexts that
7011 disallow assumed-size arrays, such as @samp{PRINT *,X}.
7012 In such cases, a diagnostic is generated and the source file is
7013 not compiled.
7014
7015 The construct affected by this option is used only in old code
7016 that pre-exists the widespread acceptance of adjustable and assumed-size
7017 arrays in the Fortran community.
7018
7019 @emph{Note:} This option does not affect how @samp{DIMENSION X(1)} is
7020 treated if @samp{X} is listed as a dummy argument only
7021 @emph{after} the @code{DIMENSION} statement (presumably in
7022 an @code{ENTRY} statement).
7023 For example, @samp{-fugly-assumed} has no effect on the
7024 following program unit:
7025
7026 @example
7027 SUBROUTINE X
7028 REAL A(1)
7029 RETURN
7030 ENTRY Y(A)
7031 PRINT *, A
7032 END
7033 @end example
7034
7035 @node Ugly Complex Part Extraction
7036 @subsection Ugly Complex Part Extraction
7037 @cindex complex values
7038 @cindex real part
7039 @cindex imaginary part
7040
7041 The @samp{-fugly-complex} option enables
7042 use of the @code{REAL()} and @code{AIMAG()}
7043 intrinsics with arguments that are
7044 @code{COMPLEX} types other than @code{COMPLEX(KIND=1)}.
7045
7046 With @samp{-ff90} in effect, these intrinsics return
7047 the unconverted real and imaginary parts (respectively)
7048 of their argument.
7049
7050 With @samp{-fno-f90} in effect, these intrinsics convert
7051 the real and imaginary parts to @code{REAL(KIND=1)}, and return
7052 the result of that conversion.
7053
7054 Due to this ambiguity, the GNU Fortran language defines
7055 these constructs as invalid, except in the specific
7056 case where they are entirely and solely passed as an
7057 argument to an invocation of the @code{REAL()} intrinsic.
7058 For example,
7059
7060 @example
7061 REAL(REAL(Z))
7062 @end example
7063
7064 @noindent
7065 is permitted even when @samp{Z} is @code{COMPLEX(KIND=2)}
7066 and @samp{-fno-ugly-complex} is in effect, because the
7067 meaning is clear.
7068
7069 @code{g77} enforces this restriction, unless @samp{-fugly-complex}
7070 is specified, in which case the appropriate interpretation is
7071 chosen and no diagnostic is issued.
7072
7073 @xref{CMPAMBIG}, for information on how to cope with existing
7074 code with unclear expectations of @code{REAL()} and @code{AIMAG()}
7075 with @code{COMPLEX(KIND=2)} arguments.
7076
7077 @xref{RealPart Intrinsic}, for information on the @code{REALPART()}
7078 intrinsic, used to extract the real part of a complex expression
7079 without conversion.
7080 @xref{ImagPart Intrinsic}, for information on the @code{IMAGPART()}
7081 intrinsic, used to extract the imaginary part of a complex expression
7082 without conversion.
7083
7084 @node Ugly Null Arguments
7085 @subsection Ugly Null Arguments
7086 @cindex trailing comma
7087 @cindex comma, trailing
7088 @cindex characters, comma
7089 @cindex null arguments
7090 @cindex arguments, null
7091
7092 The @samp{-fugly-comma} option enables use of a single trailing comma
7093 to mean ``pass an extra trailing null argument''
7094 in a list of actual arguments to an external procedure,
7095 and use of an empty list of arguments to such a procedure
7096 to mean ``pass a single null argument''.
7097
7098 @cindex omitting arguments
7099 @cindex arguments, omitting
7100 (Null arguments often are used in some procedure-calling
7101 schemes to indicate omitted arguments.)
7102
7103 For example, @samp{CALL FOO(,)} means ``pass
7104 two null arguments'', rather than ``pass one null argument''.
7105 Also, @samp{CALL BAR()} means ``pass one null argument''.
7106
7107 This construct is considered ``ugly'' because it does not
7108 provide an elegant way to pass a single null argument
7109 that is syntactically distinct from passing no arguments.
7110 That is, this construct changes the meaning of code that
7111 makes no use of the construct.
7112
7113 So, with @samp{-fugly-comma} in force, @samp{CALL FOO()}
7114 and @samp{I = JFUNC()} pass a single null argument, instead
7115 of passing no arguments as required by the Fortran 77 and
7116 90 standards.
7117
7118 @emph{Note:} Many systems gracefully allow the case
7119 where a procedure call passes one extra argument that the
7120 called procedure does not expect.
7121
7122 So, in practice, there might be no difference in
7123 the behavior of a program that does @samp{CALL FOO()}
7124 or @samp{I = JFUNC()} and is compiled with @samp{-fugly-comma}
7125 in force as compared to its behavior when compiled
7126 with the default, @samp{-fno-ugly-comma}, in force,
7127 assuming @samp{FOO} and @samp{JFUNC} do not expect any
7128 arguments to be passed.
7129
7130 @node Ugly Conversion of Initializers
7131 @subsection Ugly Conversion of Initializers
7132
7133 The constructs disabled by @samp{-fno-ugly-init} are:
7134
7135 @itemize @bullet
7136 @cindex Hollerith constants
7137 @cindex constants, Hollerith
7138 @item
7139 Use of Hollerith and typeless constants in contexts where they set
7140 initial (compile-time) values for variables, arrays, and named
7141 constants---that is, @code{DATA} and @code{PARAMETER} statements, plus
7142 type-declaration statements specifying initial values.
7143
7144 Here are some sample initializations that are disabled by the
7145 @samp{-fno-ugly-init} option:
7146
7147 @example
7148 PARAMETER (VAL='9A304FFE'X)
7149 REAL*8 STRING/8HOUTPUT00/
7150 DATA VAR/4HABCD/
7151 @end example
7152
7153 @cindex character constants
7154 @cindex constants, character
7155 @item
7156 In the same contexts as above, use of character constants to initialize
7157 numeric items and vice versa (one constant per item).
7158
7159 Here are more sample initializations that are disabled by the
7160 @samp{-fno-ugly-init} option:
7161
7162 @example
7163 INTEGER IA
7164 CHARACTER BELL
7165 PARAMETER (IA = 'A')
7166 PARAMETER (BELL = 7)
7167 @end example
7168
7169 @item
7170 Use of Hollerith and typeless constants on the right-hand side
7171 of assignment statements to numeric types, and in other
7172 contexts (such as passing arguments in invocations of
7173 intrinsic procedures and statement functions) that
7174 are treated as assignments to known types (the dummy
7175 arguments, in these cases).
7176
7177 Here are sample statements that are disabled by the
7178 @samp{-fno-ugly-init} option:
7179
7180 @example
7181 IVAR = 4HABCD
7182 PRINT *, IMAX0(2HAB, 2HBA)
7183 @end example
7184 @end itemize
7185
7186 The above constructs, when used,
7187 can tend to result in non-portable code.
7188 But, they are widely used in existing Fortran code in ways
7189 that often are quite portable.
7190 Therefore, they are enabled by default.
7191
7192 @node Ugly Integer Conversions
7193 @subsection Ugly Integer Conversions
7194
7195 The constructs enabled via @samp{-fugly-logint} are:
7196
7197 @itemize @bullet
7198 @item
7199 Automatic conversion between @code{INTEGER} and @code{LOGICAL} as
7200 dictated by
7201 context (typically implies nonportable dependencies on how a
7202 particular implementation encodes @code{.TRUE.} and @code{.FALSE.}).
7203
7204 @item
7205 Use of a @code{LOGICAL} variable in @code{ASSIGN} and assigned-@code{GOTO}
7206 statements.
7207 @end itemize
7208
7209 The above constructs are disabled by default because use
7210 of them tends to lead to non-portable code.
7211 Even existing Fortran code that uses that often turns out
7212 to be non-portable, if not outright buggy.
7213
7214 Some of this is due to differences among implementations as
7215 far as how @code{.TRUE.} and @code{.FALSE.} are encoded as
7216 @code{INTEGER} values---Fortran code that assumes a particular
7217 coding is likely to use one of the above constructs, and is
7218 also likely to not work correctly on implementations using
7219 different encodings.
7220
7221 @xref{Equivalence Versus Equality}, for more information.
7222
7223 @node Ugly Assigned Labels
7224 @subsection Ugly Assigned Labels
7225 @cindex ASSIGN statement
7226 @cindex statements, ASSIGN
7227 @cindex assigned labels
7228 @cindex pointers
7229
7230 The @samp{-fugly-assign} option forces @code{g77} to use the
7231 same storage for assigned labels as it would for a normal
7232 assignment to the same variable.
7233
7234 For example, consider the following code fragment:
7235
7236 @example
7237 I = 3
7238 ASSIGN 10 TO I
7239 @end example
7240
7241 @noindent
7242 Normally, for portability and improved diagnostics, @code{g77}
7243 reserves distinct storage for a ``sibling'' of @samp{I}, used
7244 only for @code{ASSIGN} statements to that variable (along with
7245 the corresponding assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O
7246 statements that reference the variable).
7247
7248 However, some code (that violates the ANSI FORTRAN 77 standard)
7249 attempts to copy assigned labels among variables involved with
7250 @code{ASSIGN} statements, as in:
7251
7252 @example
7253 ASSIGN 10 TO I
7254 ISTATE(5) = I
7255 @dots{}
7256 J = ISTATE(ICUR)
7257 GOTO J
7258 @end example
7259
7260 @noindent
7261 Such code doesn't work under @code{g77} unless @samp{-fugly-assign}
7262 is specified on the command-line, ensuring that the value of @code{I}
7263 referenced in the second line is whatever value @code{g77} uses
7264 to designate statement label @samp{10}, so the value may be
7265 copied into the @samp{ISTATE} array, later retrieved into a
7266 variable of the appropriate type (@samp{J}), and used as the target of
7267 an assigned-@code{GOTO} statement.
7268
7269 @emph{Note:} To avoid subtle program bugs,
7270 when @samp{-fugly-assign} is specified,
7271 @code{g77} requires the type of variables
7272 specified in assigned-label contexts
7273 @emph{must} be the same type returned by @code{%LOC()}.
7274 On many systems, this type is effectively the same
7275 as @code{INTEGER(KIND=1)}, while, on others, it is
7276 effectively the same as @code{INTEGER(KIND=2)}.
7277
7278 Do @emph{not} depend on @code{g77} actually writing valid pointers
7279 to these variables, however.
7280 While @code{g77} currently chooses that implementation, it might
7281 be changed in the future.
7282
7283 @xref{Assigned Statement Labels,,Assigned Statement Labels (ASSIGN and GOTO)},
7284 for implementation details on assigned-statement labels.
7285
7286 @node Compiler
7287 @chapter The GNU Fortran Compiler
7288
7289 The GNU Fortran compiler, @code{g77}, supports programs written
7290 in the GNU Fortran language and in some other dialects of Fortran.
7291
7292 Some aspects of how @code{g77} works are universal regardless
7293 of dialect, and yet are not properly part of the GNU Fortran
7294 language itself.
7295 These are described below.
7296
7297 @emph{Note: This portion of the documentation definitely needs a lot
7298 of work!}
7299
7300 @menu
7301 * Compiler Limits::
7302 * Run-time Environment Limits::
7303 * Compiler Types::
7304 * Compiler Constants::
7305 * Compiler Intrinsics::
7306 @end menu
7307
7308 @node Compiler Limits
7309 @section Compiler Limits
7310 @cindex limits, compiler
7311 @cindex compiler limits
7312
7313 @code{g77}, as with GNU tools in general, imposes few arbitrary restrictions
7314 on lengths of identifiers, number of continuation lines, number of external
7315 symbols in a program, and so on.
7316
7317 @cindex options, -Nl
7318 @cindex -Nl option
7319 @cindex options, -Nx
7320 @cindex -Nx option
7321 @cindex limits, continuation lines
7322 @cindex limits, lengths of names
7323 For example, some other Fortran compiler have an option
7324 (such as @samp{-Nl@var{x}}) to increase the limit on the
7325 number of continuation lines.
7326 Also, some Fortran compilation systems have an option
7327 (such as @samp{-Nx@var{x}}) to increase the limit on the
7328 number of external symbols.
7329
7330 @code{g77}, @code{gcc}, and GNU @code{ld} (the GNU linker) have
7331 no equivalent options, since they do not impose arbitrary
7332 limits in these areas.
7333
7334 @cindex rank, maximum
7335 @cindex maximum rank
7336 @cindex number of dimensions, maximum
7337 @cindex maximum number of dimensions
7338 @cindex limits, rank
7339 @cindex limits, array dimensions
7340 @code{g77} does currently limit the number of dimensions in an array
7341 to the same degree as do the Fortran standards---seven (7).
7342 This restriction might be lifted in a future version.
7343
7344 @node Run-time Environment Limits
7345 @section Run-time Environment Limits
7346 @cindex limits, run-time library
7347 @cindex wraparound
7348
7349 As a portable Fortran implementation,
7350 @code{g77} offers its users direct access to,
7351 and otherwise depends upon,
7352 the underlying facilities of the system
7353 used to build @code{g77},
7354 the system on which @code{g77} itself is used to compile programs,
7355 and the system on which the @code{g77}-compiled program is actually run.
7356 (For most users, the three systems are of the same
7357 type---combination of operating environment and hardware---often
7358 the same physical system.)
7359
7360 The run-time environment for a particular system
7361 inevitably imposes some limits on a program's use
7362 of various system facilities.
7363 These limits vary from system to system.
7364
7365 Even when such limits might be well beyond the
7366 possibility of being encountered on a particular system,
7367 the @code{g77} run-time environment
7368 has certain built-in limits,
7369 usually, but not always, stemming from intrinsics
7370 with inherently limited interfaces.
7371
7372 Currently, the @code{g77} run-time environment
7373 does not generally offer a less-limiting environment
7374 by augmenting the underlying system's own environment.
7375
7376 Therefore, code written in the GNU Fortran language,
7377 while syntactically and semantically portable,
7378 might nevertheless make non-portable assumptions
7379 about the run-time environment---assumptions that
7380 prove to be false for some particular environments.
7381
7382 The GNU Fortran language,
7383 the @code{g77} compiler and run-time environment,
7384 and the @code{g77} documentation
7385 do not yet offer comprehensive portable work-arounds for such limits,
7386 though programmers should be able to
7387 find their own in specific instances.
7388
7389 Not all of the limitations are described in this document.
7390 Some of the known limitations include:
7391
7392 @menu
7393 * Timer Wraparounds::
7394 * Year 2000 (Y2K) Problems::
7395 * Array Size::
7396 * Character-variable Length::
7397 * Year 10000 (Y10K) Problems::
7398 @end menu
7399
7400 @node Timer Wraparounds
7401 @subsection Timer Wraparounds
7402
7403 Intrinsics that return values computed from system timers,
7404 whether elapsed (wall-clock) timers,
7405 process CPU timers,
7406 or other kinds of timers,
7407 are prone to experiencing wrap-around errors
7408 (or returning wrapped-around values from successive calls)
7409 due to insufficient ranges
7410 offered by the underlying system's timers.
7411
7412 @cindex negative time
7413 @cindex short time
7414 @cindex long time
7415 Some of the symptoms of such behaviors include
7416 apparently negative time being computed for a duration,
7417 an extremely short amount of time being computed for a long duration,
7418 and an extremely long amount of time being computed for a short duration.
7419
7420 See the following for intrinsics
7421 known to have potential problems in these areas
7422 on at least some systems:
7423 @ref{CPU_Time Intrinsic},
7424 @ref{DTime Intrinsic (function)}, @ref{DTime Intrinsic (subroutine)},
7425 @ref{ETime Intrinsic (function)}, @ref{ETime Intrinsic (subroutine)},
7426 @ref{MClock Intrinsic}, @ref{MClock8 Intrinsic},
7427 @ref{Secnds Intrinsic},
7428 @ref{Second Intrinsic (function)}, @ref{Second Intrinsic (subroutine)},
7429 @ref{System_Clock Intrinsic},
7430 @ref{Time Intrinsic (UNIX)}, @ref{Time Intrinsic (VXT)},
7431 @ref{Time8 Intrinsic}.
7432
7433 @node Year 2000 (Y2K) Problems
7434 @subsection Year 2000 (Y2K) Problems
7435 @cindex Y2K compliance
7436 @cindex Year 2000 compliance
7437
7438 While the @code{g77} compiler itself is believed to
7439 be Year-2000 (Y2K) compliant,
7440 some intrinsics are not,
7441 and, potentially, some underlying systems are not,
7442 perhaps rendering some Y2K-compliant intrinsics
7443 non-compliant when used on those particular systems.
7444
7445 Fortran code that uses non-Y2K-compliant intrinsics
7446 (listed below)
7447 is, itself, almost certainly not compliant,
7448 and should be modified to use Y2K-compliant intrinsics instead.
7449
7450 Fortran code that uses no non-Y2K-compliant intrinsics,
7451 but which currently is running on a non-Y2K-compliant system,
7452 can be made more Y2K compliant by compiling and
7453 linking it for use on a new Y2K-compliant system,
7454 such as a new version of an old, non-Y2K-compliant, system.
7455
7456 Currently, information on Y2K and related issues
7457 is being maintained at
7458 @uref{http://www.gnu.org/software/year2000-list.html}.
7459
7460 See the following for intrinsics
7461 known to have potential problems in these areas
7462 on at least some systems:
7463 @ref{Date Intrinsic},
7464 @ref{IDate Intrinsic (VXT)}.
7465
7466 @cindex y2kbuggy
7467 @cindex date_y2kbuggy_0
7468 @cindex vxtidate_y2kbuggy_0
7469 @cindex G77_date_y2kbuggy_0
7470 @cindex G77_vxtidate_y2kbuggy_0
7471 The @code{libg2c} library
7472 shipped with any @code{g77} that warns
7473 about invocation of a non-Y2K-compliant intrinsic
7474 has renamed the @code{EXTERNAL} procedure names
7475 of those intrinsics.
7476 This is done so that
7477 the @code{libg2c} implementations of these intrinsics
7478 cannot be directly linked to
7479 as @code{EXTERNAL} names
7480 (which normally would avoid the non-Y2K-intrinsic warning).
7481
7482 The renamed forms of the @code{EXTERNAL} names
7483 of these renamed procedures
7484 may be linked to
7485 by appending the string @samp{_y2kbug}
7486 to the name of the procedure
7487 in the source code.
7488 For example:
7489
7490 @smallexample
7491 CHARACTER*20 STR
7492 INTEGER YY, MM, DD
7493 EXTERNAL DATE_Y2KBUG, VXTIDATE_Y2KBUG
7494 CALL DATE_Y2KBUG (STR)
7495 CALL VXTIDATE_Y2KBUG (MM, DD, YY)
7496 @end smallexample
7497
7498 (Note that the @code{EXTERNAL} statement
7499 is not actually required,
7500 since the modified names are not recognized as intrinsics
7501 by the current version of @code{g77}.
7502 But it is shown in this specific case,
7503 for purposes of illustration.)
7504
7505 The renaming of @code{EXTERNAL} procedure names of these intrinsics
7506 causes unresolved references at link time.
7507 For example, @samp{EXTERNAL DATE; CALL DATE(STR)}
7508 is normally compiled by @code{g77}
7509 as, in C, @samp{date_(&str, 20);}.
7510 This, in turn, links to the @code{date_} procedure
7511 in the @code{libE77} portion of @code{libg2c},
7512 which purposely calls a nonexistent procedure
7513 named @code{G77_date_y2kbuggy_0}.
7514 The resulting link-time error is designed, via this name,
7515 to encourage the programmer to look up the
7516 index entries to this portion of the @code{g77} documentation.
7517
7518 Generally, we recommend that the @code{EXTERNAL} method
7519 of invoking procedures in @code{libg2c}
7520 @emph{not} be used.
7521 When used, some of the correctness checking
7522 normally performed by @code{g77}
7523 is skipped.
7524
7525 In particular, it is probably better to use the
7526 @code{INTRINSIC} method of invoking
7527 non-Y2K-compliant procedures,
7528 so anyone compiling the code
7529 can quickly notice the potential Y2K problems
7530 (via the warnings printing by @code{g77})
7531 without having to even look at the code itself.
7532
7533 If there are problems linking @code{libg2c}
7534 to code compiled by @code{g77}
7535 that involve the string @samp{y2kbug},
7536 and these are not explained above,
7537 that probably indicates
7538 that a version of @code{libg2c}
7539 older than @code{g77}
7540 is being linked to,
7541 or that the new library is being linked
7542 to code compiled by an older version of @code{g77}.
7543
7544 That's because, as of the version that warns about
7545 non-Y2K-compliant intrinsic invocation,
7546 @code{g77} references the @code{libg2c} implementations
7547 of those intrinsics
7548 using new names, containing the string @samp{y2kbug}.
7549
7550 So, linking newly-compiled code
7551 (invoking one of the intrinsics in question)
7552 to an old library
7553 might yield an unresolved reference
7554 to @code{G77_date_y2kbug_0}.
7555 (The old library calls it @code{G77_date_0}.)
7556
7557 Similarly, linking previously-compiled code
7558 to a new library
7559 might yield an unresolved reference
7560 to @code{G77_vxtidate_0}.
7561 (The new library calls it @code{G77_vxtidate_y2kbug_0}.)
7562
7563 The proper fix for the above problems
7564 is to obtain the latest release of @code{g77}
7565 and related products
7566 (including @code{libg2c})
7567 and install them on all systems,
7568 then recompile, relink, and install
7569 (as appropriate)
7570 all existing Fortran programs.
7571
7572 (Normally, this sort of renaming is steadfastly avoided.
7573 In this case, however, it seems more important to highlight
7574 potential Y2K problems
7575 than to ease the transition
7576 of potentially non-Y2K-compliant code
7577 to new versions of @code{g77} and @code{libg2c}.)
7578
7579 @node Array Size
7580 @subsection Array Size
7581 @cindex limits, array size
7582 @cindex array size
7583
7584 Currently, @code{g77} uses the default @code{INTEGER} type
7585 for array indexes,
7586 which limits the sizes of single-dimension arrays
7587 on systems offering a larger address space
7588 than can be addressed by that type.
7589 (That @code{g77} puts all arrays in memory
7590 could be considered another limitation---it
7591 could use large temporary files---but that decision
7592 is left to the programmer as an implementation choice
7593 by most Fortran implementations.)
7594
7595 @c ??? Investigate this, to offer a more clear statement
7596 @c than the following paragraphs do.  -- burley 1999-02-17
7597 It is not yet clear whether this limitation
7598 never, sometimes, or always applies to the
7599 sizes of multiple-dimension arrays as a whole.
7600
7601 For example, on a system with 64-bit addresses
7602 and 32-bit default @code{INTEGER},
7603 an array with a size greater than can be addressed
7604 by a 32-bit offset
7605 can be declared using multiple dimensions.
7606 Such an array is therefore larger
7607 than a single-dimension array can be,
7608 on the same system.
7609
7610 @cindex limits, multi-dimension arrays
7611 @cindex multi-dimension arrays
7612 @cindex arrays, dimensioning
7613 Whether large multiple-dimension arrays are reliably supported
7614 depends mostly on the @code{gcc} back end (code generator)
7615 used by @code{g77}, and has not yet been fully investigated.
7616
7617 @node Character-variable Length
7618 @subsection Character-variable Length
7619 @cindex limits, on character-variable length
7620 @cindex character-variable length
7621
7622 Currently, @code{g77} uses the default @code{INTEGER} type
7623 for the lengths of @code{CHARACTER} variables
7624 and array elements.
7625
7626 This means that, for example,
7627 a system with a 64-bit address space
7628 and a 32-bit default @code{INTEGER} type
7629 does not, under @code{g77},
7630 support a @code{CHARACTER*@var{n}} declaration
7631 where @var{n} is greater than 2147483647.
7632
7633 @node Year 10000 (Y10K) Problems
7634 @subsection Year 10000 (Y10K) Problems
7635 @cindex Y10K compliance
7636 @cindex Year 10000 compliance
7637
7638 Most intrinsics returning, or computing values based on,
7639 date information are prone to Year-10000 (Y10K) problems,
7640 due to supporting only 4 digits for the year.
7641
7642 See the following for examples:
7643 @ref{FDate Intrinsic (function)}, @ref{FDate Intrinsic (subroutine)},
7644 @ref{IDate Intrinsic (UNIX)},
7645 @ref{Time Intrinsic (VXT)},
7646 @ref{Date_and_Time Intrinsic}.
7647
7648 @node Compiler Types
7649 @section Compiler Types
7650 @cindex types, of data
7651 @cindex data types
7652
7653 Fortran implementations have a fair amount of freedom given them by the
7654 standard as far as how much storage space is used and how much precision
7655 and range is offered by the various types such as @code{LOGICAL(KIND=1)},
7656 @code{INTEGER(KIND=1)}, @code{REAL(KIND=1)}, @code{REAL(KIND=2)},
7657 @code{COMPLEX(KIND=1)}, and @code{CHARACTER}.
7658 Further, many compilers offer so-called @samp{*@var{n}} notation, but
7659 the interpretation of @var{n} varies across compilers and target architectures.
7660
7661 The standard requires that @code{LOGICAL(KIND=1)}, @code{INTEGER(KIND=1)},
7662 and @code{REAL(KIND=1)}
7663 occupy the same amount of storage space, and that @code{COMPLEX(KIND=1)}
7664 and @code{REAL(KIND=2)} take twice as much storage space as @code{REAL(KIND=1)}.
7665 Further, it requires that @code{COMPLEX(KIND=1)}
7666 entities be ordered such that when a @code{COMPLEX(KIND=1)} variable is
7667 storage-associated (such as via @code{EQUIVALENCE})
7668 with a two-element @code{REAL(KIND=1)} array named @samp{R}, @samp{R(1)}
7669 corresponds to the real element and @samp{R(2)} to the imaginary
7670 element of the @code{COMPLEX(KIND=1)} variable.
7671
7672 (Few requirements as to precision or ranges of any of these are
7673 placed on the implementation, nor is the relationship of storage sizes of
7674 these types to the @code{CHARACTER} type specified, by the standard.)
7675
7676 @code{g77} follows the above requirements, warning when compiling
7677 a program requires placement of items in memory that contradict the
7678 requirements of the target architecture.
7679 (For example, a program can require placement of a @code{REAL(KIND=2)}
7680 on a boundary that is not an even multiple of its size, but still an
7681 even multiple of the size of a @code{REAL(KIND=1)} variable.
7682 On some target architectures, using the canonical
7683 mapping of Fortran types to underlying architectural types, such
7684 placement is prohibited by the machine definition or
7685 the Application Binary Interface (ABI) in force for
7686 the configuration defined for building @code{gcc} and @code{g77}.
7687 @code{g77} warns about such
7688 situations when it encounters them.)
7689
7690 @code{g77} follows consistent rules for configuring the mapping between Fortran
7691 types, including the @samp{*@var{n}} notation, and the underlying architectural
7692 types as accessed by a similarly-configured applicable version of the
7693 @code{gcc} compiler.
7694 These rules offer a widely portable, consistent Fortran/C
7695 environment, although they might well conflict with the expectations of
7696 users of Fortran compilers designed and written for particular
7697 architectures.
7698
7699 These rules are based on the configuration that is in force for the
7700 version of @code{gcc} built in the same release as @code{g77} (and
7701 which was therefore used to build both the @code{g77} compiler
7702 components and the @code{libg2c} run-time library):
7703
7704 @table @code
7705 @cindex REAL(KIND=1) type
7706 @cindex types, REAL(KIND=1)
7707 @item REAL(KIND=1)
7708 Same as @code{float} type.
7709
7710 @cindex REAL(KIND=2) type
7711 @cindex types, REAL(KIND=2)
7712 @item REAL(KIND=2)
7713 Same as whatever floating-point type that is twice the size
7714 of a @code{float}---usually, this is a @code{double}.
7715
7716 @cindex INTEGER(KIND=1) type
7717 @cindex types, INTEGER(KIND=1)
7718 @item INTEGER(KIND=1)
7719 Same as an integral type that is occupies the same amount
7720 of memory storage as @code{float}---usually, this is either
7721 an @code{int} or a @code{long int}.
7722
7723 @cindex LOGICAL(KIND=1) type
7724 @cindex types, LOGICAL(KIND=1)
7725 @item LOGICAL(KIND=1)
7726 Same @code{gcc} type as @code{INTEGER(KIND=1)}.
7727
7728 @cindex INTEGER(KIND=2) type
7729 @cindex types, INTEGER(KIND=2)
7730 @item INTEGER(KIND=2)
7731 Twice the size, and usually nearly twice the range,
7732 as @code{INTEGER(KIND=1)}---usually, this is either
7733 a @code{long int} or a @code{long long int}.
7734
7735 @cindex LOGICAL(KIND=2) type
7736 @cindex types, LOGICAL(KIND=2)
7737 @item LOGICAL(KIND=2)
7738 Same @code{gcc} type as @code{INTEGER(KIND=2)}.
7739
7740 @cindex INTEGER(KIND=3) type
7741 @cindex types, INTEGER(KIND=3)
7742 @item INTEGER(KIND=3)
7743 Same @code{gcc} type as signed @code{char}.
7744
7745 @cindex LOGICAL(KIND=3) type
7746 @cindex types, LOGICAL(KIND=3)
7747 @item LOGICAL(KIND=3)
7748 Same @code{gcc} type as @code{INTEGER(KIND=3)}.
7749
7750 @cindex INTEGER(KIND=6) type
7751 @cindex types, INTEGER(KIND=6)
7752 @item INTEGER(KIND=6)
7753 Twice the size, and usually nearly twice the range,
7754 as @code{INTEGER(KIND=3)}---usually, this is
7755 a @code{short}.
7756
7757 @cindex LOGICAL(KIND=6) type
7758 @cindex types, LOGICAL(KIND=6)
7759 @item LOGICAL(KIND=6)
7760 Same @code{gcc} type as @code{INTEGER(KIND=6)}.
7761
7762 @cindex COMPLEX(KIND=1) type
7763 @cindex types, COMPLEX(KIND=1)
7764 @item COMPLEX(KIND=1)
7765 Two @code{REAL(KIND=1)} scalars (one for the real part followed by
7766 one for the imaginary part).
7767
7768 @cindex COMPLEX(KIND=2) type
7769 @cindex types, COMPLEX(KIND=2)
7770 @item COMPLEX(KIND=2)
7771 Two @code{REAL(KIND=2)} scalars.
7772
7773 @cindex *@var{n} notation
7774 @item @var{numeric-type}*@var{n}
7775 (Where @var{numeric-type} is any type other than @code{CHARACTER}.)
7776 Same as whatever @code{gcc} type occupies @var{n} times the storage
7777 space of a @code{gcc} @code{char} item.
7778
7779 @cindex DOUBLE PRECISION type
7780 @cindex types, DOUBLE PRECISION
7781 @item DOUBLE PRECISION
7782 Same as @code{REAL(KIND=2)}.
7783
7784 @cindex DOUBLE COMPLEX type
7785 @cindex types, DOUBLE COMPLEX
7786 @item DOUBLE COMPLEX
7787 Same as @code{COMPLEX(KIND=2)}.
7788 @end table
7789
7790 Note that the above are proposed correspondences and might change
7791 in future versions of @code{g77}---avoid writing code depending
7792 on them.
7793
7794 Other types supported by @code{g77}
7795 are derived from gcc types such as @code{char}, @code{short},
7796 @code{int}, @code{long int}, @code{long long int}, @code{long double},
7797 and so on.
7798 That is, whatever types @code{gcc} already supports, @code{g77} supports
7799 now or probably will support in a future version.
7800 The rules for the @samp{@var{numeric-type}*@var{n}} notation
7801 apply to these types,
7802 and new values for @samp{@var{numeric-type}(KIND=@var{n})} will be
7803 assigned in a way that encourages clarity, consistency, and portability.
7804
7805 @node Compiler Constants
7806 @section Compiler Constants
7807 @cindex constants
7808 @cindex types, constants
7809
7810 @code{g77} strictly assigns types to @emph{all} constants not
7811 documented as ``typeless'' (typeless constants including @samp{'1'Z},
7812 for example).
7813 Many other Fortran compilers attempt to assign types to typed constants
7814 based on their context.
7815 This results in hard-to-find bugs, nonportable
7816 code, and is not in the spirit (though it strictly follows the letter)
7817 of the 77 and 90 standards.
7818
7819 @code{g77} might offer, in a future release, explicit constructs by
7820 which a wider variety of typeless constants may be specified, and/or
7821 user-requested warnings indicating places where @code{g77} might differ
7822 from how other compilers assign types to constants.
7823
7824 @xref{Context-Sensitive Constants}, for more information on this issue.
7825
7826 @node Compiler Intrinsics
7827 @section Compiler Intrinsics
7828
7829 @code{g77} offers an ever-widening set of intrinsics.
7830 Currently these all are procedures (functions and subroutines).
7831
7832 Some of these intrinsics are unimplemented, but their names reserved
7833 to reduce future problems with existing code as they are implemented.
7834 Others are implemented as part of the GNU Fortran language, while
7835 yet others are provided for compatibility with other dialects of
7836 Fortran but are not part of the GNU Fortran language.
7837
7838 To manage these distinctions, @code{g77} provides intrinsic @emph{groups},
7839 a facility that is simply an extension of the intrinsic groups provided
7840 by the GNU Fortran language.
7841
7842 @menu
7843 * Intrinsic Groups::  How intrinsics are grouped for easy management.
7844 * Other Intrinsics::  Intrinsics other than those in the GNU
7845                        Fortran language.
7846 @end menu
7847
7848 @node Intrinsic Groups
7849 @subsection Intrinsic Groups
7850 @cindex groups of intrinsics
7851 @cindex intrinsics, groups
7852
7853 A given specific intrinsic belongs in one or more groups.
7854 Each group is deleted, disabled, hidden, or enabled
7855 by default or a command-line option.
7856 The meaning of each term follows.
7857
7858 @table @b
7859 @cindex deleted intrinsics
7860 @cindex intrinsics, deleted
7861 @item Deleted
7862 No intrinsics are recognized as belonging to that group.
7863
7864 @cindex disabled intrinsics
7865 @cindex intrinsics, disabled
7866 @item Disabled
7867 Intrinsics are recognized as belonging to the group, but
7868 references to them (other than via the @code{INTRINSIC} statement)
7869 are disallowed through that group.
7870
7871 @cindex hidden intrinsics
7872 @cindex intrinsics, hidden
7873 @item Hidden
7874 Intrinsics in that group are recognized and enabled (if implemented)
7875 @emph{only} if the first mention of the actual name of an intrinsic
7876 in a program unit is in an @code{INTRINSIC} statement.
7877
7878 @cindex enabled intrinsics
7879 @cindex intrinsics, enabled
7880 @item Enabled
7881 Intrinsics in that group are recognized and enabled (if implemented).
7882 @end table
7883
7884 The distinction between deleting and disabling a group is illustrated
7885 by the following example.
7886 Assume intrinsic @samp{FOO} belongs only to group @samp{FGR}.
7887 If group @samp{FGR} is deleted, the following program unit will
7888 successfully compile, because @samp{FOO()} will be seen as a
7889 reference to an external function named @samp{FOO}:
7890
7891 @example
7892 PRINT *, FOO()
7893 END
7894 @end example
7895
7896 @noindent
7897 If group @samp{FGR} is disabled, compiling the above program will produce
7898 diagnostics, either because the @samp{FOO} intrinsic is improperly invoked
7899 or, if properly invoked, it is not enabled.
7900 To change the above program so it references an external function @samp{FOO}
7901 instead of the disabled @samp{FOO} intrinsic,
7902 add the following line to the top:
7903
7904 @example
7905 EXTERNAL FOO
7906 @end example
7907
7908 @noindent
7909 So, deleting a group tells @code{g77} to pretend as though the intrinsics in
7910 that group do not exist at all, whereas disabling it tells @code{g77} to
7911 recognize them as (disabled) intrinsics in intrinsic-like contexts.
7912
7913 Hiding a group is like enabling it, but the intrinsic must be first
7914 named in an @code{INTRINSIC} statement to be considered a reference to the
7915 intrinsic rather than to an external procedure.
7916 This might be the ``safest'' way to treat a new group of intrinsics
7917 when compiling old
7918 code, because it allows the old code to be generally written as if
7919 those new intrinsics never existed, but to be changed to use them
7920 by inserting @code{INTRINSIC} statements in the appropriate places.
7921 However, it should be the goal of development to use @code{EXTERNAL}
7922 for all names of external procedures that might be intrinsic names.
7923
7924 If an intrinsic is in more than one group, it is enabled if any of its
7925 containing groups are enabled; if not so enabled, it is hidden if
7926 any of its containing groups are hidden; if not so hidden, it is disabled
7927 if any of its containing groups are disabled; if not so disabled, it is
7928 deleted.
7929 This extra complication is necessary because some intrinsics,
7930 such as @code{IBITS}, belong to more than one group, and hence should be
7931 enabled if any of the groups to which they belong are enabled, and so
7932 on.
7933
7934 The groups are:
7935
7936 @cindex intrinsics, groups of
7937 @cindex groups of intrinsics
7938 @table @code
7939 @cindex @code{badu77} intrinsics group
7940 @item badu77
7941 UNIX intrinsics having inappropriate forms (usually functions that
7942 have intended side effects).
7943
7944 @cindex @code{gnu} intrinsics group
7945 @item gnu
7946 Intrinsics the GNU Fortran language supports that are extensions to
7947 the Fortran standards (77 and 90).
7948
7949 @cindex @code{f2c} intrinsics group
7950 @item f2c
7951 Intrinsics supported by AT&T's @code{f2c} converter and/or @code{libf2c}.
7952
7953 @cindex @code{f90} intrinsics group
7954 @item f90
7955 Fortran 90 intrinsics.
7956
7957 @cindex @code{mil} intrinsics group
7958 @item mil
7959 MIL-STD 1753 intrinsics (@code{MVBITS}, @code{IAND}, @code{BTEST}, and so on).
7960
7961 @cindex @code{mil} intrinsics group
7962 @item unix
7963 UNIX intrinsics (@code{IARGC}, @code{EXIT}, @code{ERF}, and so on).
7964
7965 @cindex @code{mil} intrinsics group
7966 @item vxt
7967 VAX/VMS FORTRAN (current as of v4) intrinsics.
7968 @end table
7969
7970 @node Other Intrinsics
7971 @subsection Other Intrinsics
7972 @cindex intrinsics, others
7973 @cindex other intrinsics
7974
7975 @code{g77} supports intrinsics other than those in the GNU Fortran
7976 language proper.
7977 This set of intrinsics is described below.
7978
7979 @ifinfo
7980 (Note that the empty lines appearing in the menu below
7981 are not intentional---they result from a bug in the
7982 @code{makeinfo} program.)
7983 @end ifinfo
7984
7985 @c The actual documentation for intrinsics comes from
7986 @c intdoc.texi, which in turn is automatically generated
7987 @c from the internal g77 tables in intrin.def _and_ the
7988 @c largely hand-written text in intdoc.h.  So, if you want
7989 @c to change or add to existing documentation on intrinsics,
7990 @c you probably want to edit intdoc.h.
7991 @c
7992 @clear familyF77
7993 @clear familyGNU
7994 @clear familyASC
7995 @clear familyMIL
7996 @clear familyF90
7997 @set familyVXT
7998 @set familyFVZ
7999 @clear familyF2C
8000 @clear familyF2U
8001 @set familyBADU77
8002 @include intdoc.texi
8003
8004 @node Other Compilers
8005 @chapter Other Compilers
8006
8007 An individual Fortran source file can be compiled to
8008 an object (@file{*.o}) file instead of to the final
8009 program executable.
8010 This allows several portions of a program to be compiled
8011 at different times and linked together whenever a new
8012 version of the program is needed.
8013 However, it introduces the issue of @dfn{object compatibility}
8014 across the various object files (and libraries, or @file{*.a}
8015 files) that are linked together to produce any particular
8016 executable file.
8017
8018 Object compatibility is an issue when combining, in one
8019 program, Fortran code compiled by more than one compiler
8020 (or more than one configuration of a compiler).
8021 If the compilers
8022 disagree on how to transform the names of procedures, there
8023 will normally be errors when linking such programs.
8024 Worse, if the compilers agree on naming, but disagree on issues
8025 like how to pass parameters, return arguments, and lay out
8026 @code{COMMON} areas, the earliest detected errors might be the
8027 incorrect results produced by the program (and that assumes
8028 these errors are detected, which is not always the case).
8029
8030 Normally, @code{g77} generates code that is
8031 object-compatible with code generated by a version of
8032 @code{f2c} configured (with, for example, @file{f2c.h} definitions)
8033 to be generally compatible with @code{g77} as built by @code{gcc}.
8034 (Normally, @code{f2c} will, by default, conform to the appropriate
8035 configuration, but it is possible that older or perhaps even newer
8036 versions of @code{f2c}, or versions having certain configuration changes
8037 to @code{f2c} internals, will produce object files that are
8038 incompatible with @code{g77}.)
8039
8040 For example, a Fortran string subroutine
8041 argument will become two arguments on the C side: a @code{char *}
8042 and an @code{int} length.
8043
8044 Much of this compatibility results from the fact that
8045 @code{g77} uses the same run-time library,
8046 @code{libf2c}, used by @code{f2c},
8047 though @code{g77} gives its version the name @code{libg2c}
8048 so as to avoid conflicts when linking,
8049 installing them in the same directories,
8050 and so on.
8051
8052 Other compilers might or might not generate code that
8053 is object-compatible with @code{libg2c} and current @code{g77},
8054 and some might offer such compatibility only when explicitly
8055 selected via a command-line option to the compiler.
8056
8057 @emph{Note: This portion of the documentation definitely needs a lot
8058 of work!}
8059
8060 @menu
8061 * Dropping f2c Compatibility::  When speed is more important.
8062 * Compilers Other Than f2c::    Interoperation with code from other compilers.
8063 @end menu
8064
8065 @node Dropping f2c Compatibility
8066 @section Dropping @code{f2c} Compatibility
8067
8068 Specifying @samp{-fno-f2c} allows @code{g77} to generate, in
8069 some cases, faster code, by not needing to allow to the possibility
8070 of linking with code compiled by @code{f2c}.
8071
8072 For example, this affects how @code{REAL(KIND=1)},
8073 @code{COMPLEX(KIND=1)}, and @code{COMPLEX(KIND=2)} functions are called.
8074 With @samp{-fno-f2c}, they are
8075 compiled as returning the appropriate @code{gcc} type
8076 (@code{float}, @code{__complex__ float}, @code{__complex__ double},
8077 in many configurations).
8078
8079 With @samp{-ff2c} in force, they
8080 are compiled differently (with perhaps slower run-time performance)
8081 to accommodate the restrictions inherent in @code{f2c}'s use of K&R
8082 C as an intermediate language---@code{REAL(KIND=1)} functions
8083 return C's @code{double} type, while @code{COMPLEX} functions return
8084 @code{void} and use an extra argument pointing to a place for the functions to
8085 return their values.
8086
8087 It is possible that, in some cases, leaving @samp{-ff2c} in force
8088 might produce faster code than using @samp{-fno-f2c}.
8089 Feel free to experiment, but remember to experiment with changing the way
8090 @emph{entire programs and their Fortran libraries are compiled} at
8091 a time, since this sort of experimentation affects the interface
8092 of code generated for a Fortran source file---that is, it affects
8093 object compatibility.
8094
8095 Note that @code{f2c} compatibility is a fairly static target to achieve,
8096 though not necessarily perfectly so, since, like @code{g77}, it is
8097 still being improved.
8098 However, specifying @samp{-fno-f2c} causes @code{g77}
8099 to generate code that will probably be incompatible with code
8100 generated by future versions of @code{g77} when the same option
8101 is in force.
8102 You should make sure you are always able to recompile complete
8103 programs from source code when upgrading to new versions of @code{g77}
8104 or @code{f2c}, especially when using options such as @samp{-fno-f2c}.
8105
8106 Therefore, if you are using @code{g77} to compile libraries and other
8107 object files for possible future use and you don't want to require
8108 recompilation for future use with subsequent versions of @code{g77},
8109 you might want to stick with @code{f2c} compatibility for now, and
8110 carefully watch for any announcements about changes to the
8111 @code{f2c}/@code{libf2c} interface that might affect existing programs
8112 (thus requiring recompilation).
8113
8114 It is probable that a future version of @code{g77} will not,
8115 by default, generate object files compatible with @code{f2c},
8116 and that version probably would no longer use @code{libf2c}.
8117 If you expect to depend on this compatibility in the
8118 long term, use the options @samp{-ff2c -ff2c-library} when compiling
8119 all of the applicable code.
8120 This should cause future versions of @code{g77} either to produce
8121 compatible code (at the expense of the availability of some features and
8122 performance), or at the very least, to produce diagnostics.
8123
8124 (The library @code{g77} produces will no longer be named @file{libg2c}
8125 when it is no longer generally compatible with @file{libf2c}.
8126 It will likely be referred to, and, if installed as a distinct
8127 library, named @code{libg77}, or some other as-yet-unused name.)
8128
8129 @node Compilers Other Than f2c
8130 @section Compilers Other Than @code{f2c}
8131
8132 On systems with Fortran compilers other than @code{f2c} and @code{g77},
8133 code compiled by @code{g77} is not expected to work
8134 well with code compiled by the native compiler.
8135 (This is true for @code{f2c}-compiled objects as well.)
8136 Libraries compiled with the native compiler probably will have
8137 to be recompiled with @code{g77} to be used with @code{g77}-compiled code.
8138
8139 Reasons for such incompatibilities include:
8140
8141 @itemize @bullet
8142 @item
8143 There might be differences in the way names of Fortran procedures
8144 are translated for use in the system's object-file format.
8145 For example, the statement @samp{CALL FOO} might be compiled
8146 by @code{g77} to call a procedure the linker @code{ld} sees
8147 given the name @samp{_foo_}, while the apparently corresponding
8148 statement @samp{SUBROUTINE FOO} might be compiled by the
8149 native compiler to define the linker-visible name @samp{_foo},
8150 or @samp{_FOO_}, and so on.
8151
8152 @item
8153 There might be subtle type mismatches which cause subroutine arguments
8154 and function return values to get corrupted.
8155
8156 This is why simply getting @code{g77} to
8157 transform procedure names the same way a native
8158 compiler does is not usually a good idea---unless
8159 some effort has been made to ensure that, aside
8160 from the way the two compilers transform procedure
8161 names, everything else about the way they generate
8162 code for procedure interfaces is identical.
8163
8164 @item
8165 Native compilers
8166 use libraries of private I/O routines which will not be available
8167 at link time unless you have the native compiler---and you would
8168 have to explicitly ask for them.
8169
8170 For example, on the Sun you
8171 would have to add @samp{-L/usr/lang/SCx.x -lF77 -lV77} to the link
8172 command.
8173 @end itemize
8174
8175 @node Other Languages
8176 @chapter Other Languages
8177
8178 @emph{Note: This portion of the documentation definitely needs a lot
8179 of work!}
8180
8181 @menu
8182 * Interoperating with C and C++::
8183 @end menu
8184
8185 @node Interoperating with C and C++
8186 @section Tools and advice for interoperating with C and C++
8187
8188 @cindex C, linking with
8189 @cindex C++, linking with
8190 @cindex linking with C
8191 The following discussion assumes that you are running @code{g77} in @code{f2c}
8192 compatibility mode, i.e.@: not using @samp{-fno-f2c}.
8193 It provides some
8194 advice about quick and simple techniques for linking Fortran and C (or
8195 C++), the most common requirement.
8196 For the full story consult the
8197 description of code generation.
8198 @xref{Debugging and Interfacing}.
8199
8200 When linking Fortran and C, it's usually best to use @code{g77} to do
8201 the linking so that the correct libraries are included (including the
8202 maths one).
8203 If you're linking with C++ you will want to add
8204 @samp{-lstdc++}, @samp{-lg++} or whatever.
8205 If you need to use another
8206 driver program (or @code{ld} directly),
8207 you can find out what linkage
8208 options @code{g77} passes by running @samp{g77 -v}.
8209
8210 @menu
8211 * C Interfacing Tools::
8212 * C Access to Type Information::
8213 * f2c Skeletons and Prototypes::
8214 * C++ Considerations::
8215 * Startup Code::
8216 @end menu
8217
8218 @node C Interfacing Tools
8219 @subsection C Interfacing Tools
8220 @pindex f2c
8221 @cindex cfortran.h
8222 @cindex Netlib
8223 Even if you don't actually use it as a compiler, @code{f2c} from
8224 @uref{ftp://ftp.netlib.org/f2c/src}, can be a useful tool when you're
8225 interfacing (linking) Fortran and C@.
8226 @xref{f2c Skeletons and Prototypes,,Generating Skeletons and Prototypes with @code{f2c}}.
8227
8228 To use @code{f2c} for this purpose you only need retrieve and
8229 build the @file{src} directory from the distribution, consult the
8230 @file{README} instructions there for machine-specifics, and install the
8231 @code{f2c} program on your path.
8232
8233 Something else that might be useful is @samp{cfortran.h} from
8234 @uref{ftp://zebra/desy.de/cfortran}.
8235 This is a fairly general tool which
8236 can be used to generate interfaces for calling in both directions
8237 between Fortran and C@.
8238 It can be used in @code{f2c} mode with
8239 @code{g77}---consult its documentation for details.
8240
8241 @node C Access to Type Information
8242 @subsection Accessing Type Information in C
8243
8244 @cindex types, Fortran/C
8245 Generally, C code written to link with
8246 @code{g77} code---calling and/or being
8247 called from Fortran---should @samp{#include <g2c.h>} to define the C
8248 versions of the Fortran types.
8249 Don't assume Fortran @code{INTEGER} types
8250 correspond to C @code{int}s, for instance; instead, declare them as
8251 @code{integer}, a type defined by @file{g2c.h}.
8252 @file{g2c.h} is installed where @code{gcc} will find it by
8253 default, assuming you use a copy of @code{gcc} compatible with
8254 @code{g77}, probably built at the same time as @code{g77}.
8255
8256 @node f2c Skeletons and Prototypes
8257 @subsection Generating Skeletons and Prototypes with @code{f2c}
8258
8259 @pindex f2c
8260 @cindex -fno-second-underscore
8261 A simple and foolproof way to write @code{g77}-callable C routines---e.g.@: to
8262 interface with an existing library---is to write a file (named, for
8263 example, @file{fred.f}) of dummy Fortran
8264 skeletons comprising just the declaration of the routine(s) and dummy
8265 arguments plus @code{END} statements.
8266 Then run @code{f2c} on file @file{fred.f} to produce @file{fred.c}
8267 into which you can edit
8268 useful code, confident the calling sequence is correct, at least.
8269 (There are some errors otherwise commonly made in generating C
8270 interfaces with @code{f2c} conventions,
8271 such as not using @code{doublereal}
8272 as the return type of a @code{REAL} @code{FUNCTION}.)
8273
8274 @pindex ftnchek
8275 @code{f2c} also can help with calling Fortran from C, using its
8276 @samp{-P} option to generate C prototypes appropriate for calling the
8277 Fortran.@footnote{The files generated like this can also be used for
8278 inter-unit consistency checking of dummy and actual arguments, although
8279 the @code{ftnchek} tool from @uref{ftp://ftp.netlib.org/fortran}
8280 or @uref{ftp://ftp.dsm.fordham.edu} is
8281 probably better for this purpose.}
8282 If the Fortran code containing any
8283 routines to be called from C is in file @file{joe.f}, use the command
8284 @kbd{f2c -P joe.f} to generate the file @file{joe.P} containing
8285 prototype information.
8286 @code{#include} this in the C which has to call
8287 the Fortran routines to make sure you get it right.
8288
8289 @xref{Arrays,,Arrays (DIMENSION)}, for information on the differences
8290 between the way Fortran (including compilers like @code{g77}) and
8291 C handle arrays.
8292
8293 @node C++ Considerations
8294 @subsection C++ Considerations
8295
8296 @cindex C++
8297 @code{f2c} can be used to generate suitable code for compilation with a
8298 C++ system using the @samp{-C++} option.
8299 The important thing about linking @code{g77}-compiled
8300 code with C++ is that the prototypes for the @code{g77}
8301 routines must specify C linkage to avoid name mangling.
8302 So, use an @samp{extern "C"} declaration.
8303 @code{f2c}'s @samp{-C++} option will take care
8304 of this when generating skeletons or prototype files as above, and also
8305 avoid clashes with C++ reserved words in addition to those in C@.
8306
8307 @node Startup Code
8308 @subsection Startup Code
8309
8310 @cindex startup code
8311 @cindex run-time, initialization
8312 @cindex initialization, run-time
8313 Unlike with some runtime systems,
8314 it shouldn't be necessary
8315 (unless there are bugs)
8316 to use a Fortran main program unit to ensure the
8317 runtime---specifically the I/O system---is initialized.
8318
8319 However, to use the @code{g77} intrinsics @code{GETARG} and @code{IARGC},
8320 either the @code{main} routine from the @file{libg2c} library must be used,
8321 or the @code{f_setarg} routine
8322 (new as of @code{egcs} version 1.1 and @code{g77} version 0.5.23)
8323 must be called with the appropriate @code{argc} and @code{argv} arguments
8324 prior to the program calling @code{GETARG} or @code{IARGC}.
8325
8326 To provide more flexibility for mixed-language programming
8327 involving @code{g77} while allowing for shared libraries,
8328 as of @code{egcs} version 1.1 and @code{g77} version 0.5.23,
8329 @code{g77}'s @code{main} routine in @code{libg2c}
8330 does the following, in order:
8331
8332 @enumerate
8333 @item
8334 Calls @code{f_setarg}
8335 with the incoming @code{argc} and @code{argv} arguments,
8336 in the same order as for @code{main} itself.
8337
8338 This sets up the command-line environment
8339 for @code{GETARG} and @code{IARGC}.
8340
8341 @item
8342 Calls @code{f_setsig} (with no arguments).
8343
8344 This sets up the signaling and exception environment.
8345
8346 @item
8347 Calls @code{f_init} (with no arguments).
8348
8349 This initializes the I/O environment,
8350 though that should not be necessary,
8351 as all I/O functions in @code{libf2c}
8352 are believed to call @code{f_init} automatically,
8353 if necessary.
8354
8355 (A future version of @code{g77} might skip this explicit step,
8356 to speed up normal exit of a program.)
8357
8358 @item
8359 Arranges for @code{f_exit} to be called (with no arguments)
8360 when the program exits.
8361
8362 This ensures that the I/O environment is properly shut down
8363 before the program exits normally.
8364 Otherwise, output buffers might not be fully flushed,
8365 scratch files might not be deleted, and so on.
8366
8367 The simple way @code{main} does this is
8368 to call @code{f_exit} itself after calling
8369 @code{MAIN__} (in the next step).
8370
8371 However, this does not catch the cases where the program
8372 might call @code{exit} directly,
8373 instead of using the @code{EXIT} intrinsic
8374 (implemented as @code{exit_} in @code{libf2c}).
8375
8376 So, @code{main} attempts to use
8377 the operating environment's @code{onexit} or @code{atexit}
8378 facility, if available,
8379 to cause @code{f_exit} to be called automatically
8380 upon any invocation of @code{exit}.
8381
8382 @item
8383 Calls @code{MAIN__} (with no arguments).
8384
8385 This starts executing the Fortran main program unit for
8386 the application.
8387 (Both @code{g77} and @code{f2c} currently compile a main
8388 program unit so that its global name is @code{MAIN__}.)
8389
8390 @item
8391 If no @code{onexit} or @code{atexit} is provided by the system,
8392 calls @code{f_exit}.
8393
8394 @item
8395 Calls @code{exit} with a zero argument,
8396 to signal a successful program termination.
8397
8398 @item
8399 Returns a zero value to the caller,
8400 to signal a successful program termination,
8401 in case @code{exit} doesn't exit on the system.
8402 @end enumerate
8403
8404 All of the above names are C @code{extern} names,
8405 i.e.@: not mangled.
8406
8407 When using the @code{main} procedure provided by @code{g77}
8408 without a Fortran main program unit,
8409 you need to provide @code{MAIN__}
8410 as the entry point for your C code.
8411 (Make sure you link the object file that defines that
8412 entry point with the rest of your program.)
8413
8414 To provide your own @code{main} procedure
8415 in place of @code{g77}'s,
8416 make sure you specify the object file defining that procedure
8417 @emph{before} @samp{-lg2c} on the @code{g77} command line.
8418 Since the @samp{-lg2c} option is implicitly provided,
8419 this is usually straightforward.
8420 (Use the @samp{--verbose} option to see how and where
8421 @code{g77} implicitly adds @samp{-lg2c} in a command line
8422 that will link the program.
8423 Feel free to specify @samp{-lg2c} explicitly,
8424 as appropriate.)
8425
8426 However, when providing your own @code{main},
8427 make sure you perform the appropriate tasks in the
8428 appropriate order.
8429 For example, if your @code{main} does not call @code{f_setarg},
8430 make sure the rest of your application does not call
8431 @code{GETARG} or @code{IARGC}.
8432
8433 And, if your @code{main} fails to ensure that @code{f_exit}
8434 is called upon program exit,
8435 some files might end up incompletely written,
8436 some scratch files might be left lying around,
8437 and some existing files being written might be left
8438 with old data not properly truncated at the end.
8439
8440 Note that, generally, the @code{g77} operating environment
8441 does not depend on a procedure named @code{MAIN__} actually
8442 being called prior to any other @code{g77}-compiled code.
8443 That is, @code{MAIN__} does not, itself,
8444 set up any important operating-environment characteristics
8445 upon which other code might depend.
8446 This might change in future versions of @code{g77},
8447 with appropriate notification in the release notes.
8448
8449 For more information, consult the source code for the above routines.
8450 These are in @file{@value{path-libf2c}/libF77/}, named @file{main.c},
8451 @file{setarg.c}, @file{setsig.c}, @file{getarg_.c}, and @file{iargc_.c}.
8452
8453 Also, the file @file{@value{path-g77}/com.c} contains the code @code{g77}
8454 uses to open-code (inline) references to @code{IARGC}.
8455
8456 @include g77install.texi
8457
8458 @node Debugging and Interfacing
8459 @chapter Debugging and Interfacing
8460 @cindex debugging
8461 @cindex interfacing
8462 @cindex calling C routines
8463 @cindex C routines calling Fortran
8464 @cindex f2c compatibility
8465
8466 GNU Fortran currently generates code that is object-compatible with
8467 the @code{f2c} converter.
8468 Also, it avoids limitations in the current GBE, such as the
8469 inability to generate a procedure with
8470 multiple entry points, by generating code that is structured
8471 differently (in terms of procedure names, scopes, arguments, and
8472 so on) than might be expected.
8473
8474 As a result, writing code in other languages that calls on, is
8475 called by, or shares in-memory data with @code{g77}-compiled code generally
8476 requires some understanding of the way @code{g77} compiles code for
8477 various constructs.
8478
8479 Similarly, using a debugger to debug @code{g77}-compiled
8480 code, even if that debugger supports native Fortran debugging, generally
8481 requires this sort of information.
8482
8483 This section describes some of the basic information on how
8484 @code{g77} compiles code for constructs involving interfaces to other
8485 languages and to debuggers.
8486
8487 @emph{Caution:} Much or all of this information pertains to only the current
8488 release of @code{g77}, sometimes even to using certain compiler options
8489 with @code{g77} (such as @samp{-fno-f2c}).
8490 Do not write code that depends on this
8491 information without clearly marking said code as nonportable and
8492 subject to review for every new release of @code{g77}.
8493 This information
8494 is provided primarily to make debugging of code generated by this
8495 particular release of @code{g77} easier for the user, and partly to make
8496 writing (generally nonportable) interface code easier.
8497 Both of these
8498 activities require tracking changes in new version of @code{g77} as they
8499 are installed, because new versions can change the behaviors
8500 described in this section.
8501
8502 @menu
8503 * Main Program Unit::  How @code{g77} compiles a main program unit.
8504 * Procedures::         How @code{g77} constructs parameter lists
8505                        for procedures.
8506 * Functions::          Functions returning floating-point or character data.
8507 * Names::              Naming of user-defined variables, procedures, etc.
8508 * Common Blocks::      Accessing common variables while debugging.
8509 * Local Equivalence Areas::  Accessing @code{EQUIVALENCE} while debugging.
8510 * Complex Variables::  How @code{g77} performs complex arithmetic.
8511 * Arrays::             Dealing with (possibly multi-dimensional) arrays.
8512 * Adjustable Arrays::  Special consideration for adjustable arrays.
8513 * Alternate Entry Points::  How @code{g77} implements alternate @code{ENTRY}.
8514 * Alternate Returns::  How @code{g77} handles alternate returns.
8515 * Assigned Statement Labels::  How @code{g77} handles @code{ASSIGN}.
8516 * Run-time Library Errors::  Meanings of some @code{IOSTAT=} values.
8517 @end menu
8518
8519 @node Main Program Unit
8520 @section Main Program Unit (PROGRAM)
8521 @cindex PROGRAM statement
8522 @cindex statements, PROGRAM
8523
8524 When @code{g77} compiles a main program unit, it gives it the public
8525 procedure name @code{MAIN__}.
8526 The @code{libg2c} library has the actual @code{main()} procedure
8527 as is typical of C-based environments, and
8528 it is this procedure that performs some initial start-up
8529 activity and then calls @code{MAIN__}.
8530
8531 Generally, @code{g77} and @code{libg2c} are designed so that you need not
8532 include a main program unit written in Fortran in your program---it
8533 can be written in C or some other language.
8534 Especially for I/O handling, this is the case, although @code{g77} version 0.5.16
8535 includes a bug fix for @code{libg2c} that solved a problem with using the
8536 @code{OPEN} statement as the first Fortran I/O activity in a program
8537 without a Fortran main program unit.
8538
8539 However, if you don't intend to use @code{g77} (or @code{f2c}) to compile
8540 your main program unit---that is, if you intend to compile a @code{main()}
8541 procedure using some other language---you should carefully
8542 examine the code for @code{main()} in @code{libg2c}, found in the source
8543 file @file{@value{path-libf2c}/libF77/main.c}, to see what kinds of things
8544 might need to be done by your @code{main()} in order to provide the
8545 Fortran environment your Fortran code is expecting.
8546
8547 @cindex @code{IArgC} intrinsic
8548 @cindex intrinsics, @code{IArgC}
8549 @cindex @code{GetArg} intrinsic
8550 @cindex intrinsics, @code{GetArg}
8551 For example, @code{libg2c}'s @code{main()} sets up the information used by
8552 the @code{IARGC} and @code{GETARG} intrinsics.
8553 Bypassing @code{libg2c}'s @code{main()}
8554 without providing a substitute for this activity would mean
8555 that invoking @code{IARGC} and @code{GETARG} would produce undefined
8556 results.
8557
8558 @cindex debugging
8559 @cindex main program unit, debugging
8560 @cindex main()
8561 @cindex MAIN__()
8562 @cindex .gdbinit
8563 When debugging, one implication of the fact that @code{main()}, which
8564 is the place where the debugged program ``starts'' from the
8565 debugger's point of view, is in @code{libg2c} is that you won't be
8566 starting your Fortran program at a point you recognize as your
8567 Fortran code.
8568
8569 The standard way to get around this problem is to set a break
8570 point (a one-time, or temporary, break point will do) at
8571 the entrance to @code{MAIN__}, and then run the program.
8572 A convenient way to do so is to add the @code{gdb} command
8573
8574 @example
8575 tbreak MAIN__
8576 @end example
8577
8578 @noindent
8579 to the file @file{.gdbinit} in the directory in which you're debugging
8580 (using @code{gdb}).
8581
8582 After doing this, the debugger will see the current execution
8583 point of the program as at the beginning of the main program
8584 unit of your program.
8585
8586 Of course, if you really want to set a break point at some
8587 other place in your program and just start the program
8588 running, without first breaking at @code{MAIN__},
8589 that should work fine.
8590
8591 @node Procedures
8592 @section Procedures (SUBROUTINE and FUNCTION)
8593 @cindex procedures
8594 @cindex SUBROUTINE statement
8595 @cindex statements, SUBROUTINE
8596 @cindex FUNCTION statement
8597 @cindex statements, FUNCTION
8598 @cindex signature of procedures
8599
8600 Currently, @code{g77} passes arguments via reference---specifically,
8601 by passing a pointer to the location in memory of a variable, array,
8602 array element, a temporary location that holds the result of evaluating an
8603 expression, or a temporary or permanent location that holds the value
8604 of a constant.
8605
8606 Procedures that accept @code{CHARACTER} arguments are implemented by
8607 @code{g77} so that each @code{CHARACTER} argument has two actual arguments.
8608
8609 The first argument occupies the expected position in the
8610 argument list and has the user-specified name.
8611 This argument
8612 is a pointer to an array of characters, passed by the caller.
8613
8614 The second argument is appended to the end of the user-specified
8615 calling sequence and is named @samp{__g77_length_@var{x}}, where @var{x}
8616 is the user-specified name.
8617 This argument is of the C type @code{ftnlen}
8618 (see @file{@value{path-libf2c}/g2c.h.in} for information on that type) and
8619 is the number of characters the caller has allocated in the
8620 array pointed to by the first argument.
8621
8622 A procedure will ignore the length argument if @samp{X} is not declared
8623 @code{CHARACTER*(*)}, because for other declarations, it knows the
8624 length.
8625 Not all callers necessarily ``know'' this, however, which
8626 is why they all pass the extra argument.
8627
8628 The contents of the @code{CHARACTER} argument are specified by the
8629 address passed in the first argument (named after it).
8630 The procedure can read or write these contents as appropriate.
8631
8632 When more than one @code{CHARACTER} argument is present in the argument
8633 list, the length arguments are appended in the order
8634 the original arguments appear.
8635 So @samp{CALL FOO('HI','THERE')} is implemented in
8636 C as @samp{foo("hi","there",2,5);}, ignoring the fact that @code{g77}
8637 does not provide the trailing null bytes on the constant
8638 strings (@code{f2c} does provide them, but they are unnecessary in
8639 a Fortran environment, and you should not expect them to be
8640 there).
8641
8642 Note that the above information applies to @code{CHARACTER} variables and
8643 arrays @strong{only}.
8644 It does @strong{not} apply to external @code{CHARACTER}
8645 functions or to intrinsic @code{CHARACTER} functions.
8646 That is, no second length argument is passed to @samp{FOO} in this case:
8647
8648 @example
8649 CHARACTER X
8650 EXTERNAL X
8651 CALL FOO(X)
8652 @end example
8653
8654 @noindent
8655 Nor does @samp{FOO} expect such an argument in this case:
8656
8657 @example
8658 SUBROUTINE FOO(X)
8659 CHARACTER X
8660 EXTERNAL X
8661 @end example
8662
8663 Because of this implementation detail, if a program has a bug
8664 such that there is disagreement as to whether an argument is
8665 a procedure, and the type of the argument is @code{CHARACTER}, subtle
8666 symptoms might appear.
8667
8668 @node Functions
8669 @section Functions (FUNCTION and RETURN)
8670 @cindex functions
8671 @cindex FUNCTION statement
8672 @cindex statements, FUNCTION
8673 @cindex RETURN statement
8674 @cindex statements, RETURN
8675 @cindex return type of functions
8676
8677 @code{g77} handles in a special way functions that return the following
8678 types:
8679
8680 @itemize @bullet
8681 @item
8682 @code{CHARACTER}
8683 @item
8684 @code{COMPLEX}
8685 @item
8686 @code{REAL(KIND=1)}
8687 @end itemize
8688
8689 For @code{CHARACTER}, @code{g77} implements a subroutine (a C function
8690 returning @code{void})
8691 with two arguments prepended: @samp{__g77_result}, which the caller passes
8692 as a pointer to a @code{char} array expected to hold the return value,
8693 and @samp{__g77_length}, which the caller passes as an @code{ftnlen} value
8694 specifying the length of the return value as declared in the calling
8695 program.
8696 For @code{CHARACTER*(*)}, the called function uses @samp{__g77_length}
8697 to determine the size of the array that @samp{__g77_result} points to;
8698 otherwise, it ignores that argument.
8699
8700 For @code{COMPLEX}, when @samp{-ff2c} is in
8701 force, @code{g77} implements
8702 a subroutine with one argument prepended: @samp{__g77_result}, which the
8703 caller passes as a pointer to a variable of the type of the function.
8704 The called function writes the return value into this variable instead
8705 of returning it as a function value.
8706 When @samp{-fno-f2c} is in force,
8707 @code{g77} implements a @code{COMPLEX} function as @code{gcc}'s
8708 @samp{__complex__ float} or @samp{__complex__ double} function
8709 (or an emulation thereof, when @samp{-femulate-complex} is in effect),
8710 returning the result of the function in the same way as @code{gcc} would.
8711
8712 For @code{REAL(KIND=1)}, when @samp{-ff2c} is in force, @code{g77} implements
8713 a function that actually returns @code{REAL(KIND=2)} (typically
8714 C's @code{double} type).
8715 When @samp{-fno-f2c} is in force, @code{REAL(KIND=1)}
8716 functions return @code{float}.
8717
8718 @node Names
8719 @section Names
8720 @cindex symbol names
8721 @cindex transforming symbol names
8722
8723 Fortran permits each implementation to decide how to represent
8724 names as far as how they're seen in other contexts, such as debuggers
8725 and when interfacing to other languages, and especially as far
8726 as how casing is handled.
8727
8728 External names---names of entities that are public, or ``accessible'',
8729 to all modules in a program---normally have an underscore (@samp{_})
8730 appended by @code{g77},
8731 to generate code that is compatible with @code{f2c}.
8732 External names include names of Fortran things like common blocks,
8733 external procedures (subroutines and functions, but not including
8734 statement functions, which are internal procedures), and entry point
8735 names.
8736
8737 However, use of the @samp{-fno-underscoring} option
8738 disables this kind of transformation of external names (though inhibiting
8739 the transformation certainly improves the chances of colliding with
8740 incompatible externals written in other languages---but that
8741 might be intentional.
8742
8743 @cindex -fno-underscoring option
8744 @cindex options, -fno-underscoring
8745 @cindex -fno-second-underscore option
8746 @cindex options, -fno-underscoring
8747 When @samp{-funderscoring} is in force, any name (external or local)
8748 that already has at least one underscore in it is
8749 implemented by @code{g77} by appending two underscores.
8750 (This second underscore can be disabled via the
8751 @samp{-fno-second-underscore} option.)
8752 External names are changed this way for @code{f2c} compatibility.
8753 Local names are changed this way to avoid collisions with external names
8754 that are different in the source code---@code{f2c} does the same thing, but
8755 there's no compatibility issue there except for user expectations while
8756 debugging.
8757
8758 For example:
8759
8760 @example
8761 Max_Cost = 0
8762 @end example
8763
8764 @cindex debugging
8765 @noindent
8766 Here, a user would, in the debugger, refer to this variable using the
8767 name @samp{max_cost__} (or @samp{MAX_COST__} or @samp{Max_Cost__},
8768 as described below).
8769 (We hope to improve @code{g77} in this regard in the future---don't
8770 write scripts depending on this behavior!
8771 Also, consider experimenting with the @samp{-fno-underscoring}
8772 option to try out debugging without having to massage names by
8773 hand like this.)
8774
8775 @code{g77} provides a number of command-line options that allow the user
8776 to control how case mapping is handled for source files.
8777 The default is the traditional UNIX model for Fortran compilers---names
8778 are mapped to lower case.
8779 Other command-line options can be specified to map names to upper
8780 case, or to leave them exactly as written in the source file.
8781
8782 For example:
8783
8784 @example
8785 Foo = 9.436
8786 @end example
8787
8788 @noindent
8789 Here, it is normally the case that the variable assigned will be named
8790 @samp{foo}.
8791 This would be the name to enter when using a debugger to
8792 access the variable.
8793
8794 However, depending on the command-line options specified, the
8795 name implemented by @code{g77} might instead be @samp{FOO} or even
8796 @samp{Foo}, thus affecting how debugging is done.
8797
8798 Also:
8799
8800 @example
8801 Call Foo
8802 @end example
8803
8804 @noindent
8805 This would normally call a procedure that, if it were in a separate C program,
8806 be defined starting with the line:
8807
8808 @example
8809 void foo_()
8810 @end example
8811
8812 @noindent
8813 However, @code{g77} command-line options could be used to change the casing
8814 of names, resulting in the name @samp{FOO_} or @samp{Foo_} being given to the
8815 procedure instead of @samp{foo_}, and the @samp{-fno-underscoring} option
8816 could be used to inhibit the appending of the underscore to the name.
8817
8818 @node Common Blocks
8819 @section Common Blocks (COMMON)
8820 @cindex common blocks
8821 @cindex @code{COMMON} statement
8822 @cindex statements, @code{COMMON}
8823
8824 @code{g77} names and lays out @code{COMMON} areas
8825 the same way @code{f2c} does,
8826 for compatibility with @code{f2c}.
8827
8828 Currently, @code{g77} does not emit ``true'' debugging information for
8829 members of a @code{COMMON} area, due to an apparent bug in the GBE.
8830
8831 (As of Version 0.5.19, @code{g77} emits debugging information for such
8832 members in the form of a constant string specifying the base name of
8833 the aggregate area and the offset of the member in bytes from the start
8834 of the area.
8835 Use the @samp{-fdebug-kludge} option to enable this behavior.
8836 In @code{gdb}, use @samp{set language c} before printing the value
8837 of the member, then @samp{set language fortran} to restore the default
8838 language, since @code{gdb} doesn't provide a way to print a readable
8839 version of a character string in Fortran language mode.
8840
8841 This kludge will be removed in a future version of @code{g77} that,
8842 in conjunction with a contemporary version of @code{gdb},
8843 properly supports Fortran-language debugging, including access
8844 to members of @code{COMMON} areas.)
8845
8846 @xref{Code Gen Options,,Options for Code Generation Conventions},
8847 for information on the @samp{-fdebug-kludge} option.
8848
8849 Moreover, @code{g77} currently implements a @code{COMMON} area such that its
8850 type is an array of the C @code{char} data type.
8851
8852 So, when debugging, you must know the offset into a @code{COMMON} area
8853 for a particular item in that area, and you have to take into
8854 account the appropriate multiplier for the respective sizes
8855 of the types (as declared in your code) for the items preceding
8856 the item in question as compared to the size of the @code{char} type.
8857
8858 For example, using default implicit typing, the statement
8859
8860 @example
8861 COMMON I(15), R(20), T
8862 @end example
8863
8864 @noindent
8865 results in a public 144-byte @code{char} array named @samp{_BLNK__}
8866 with @samp{I} placed at @samp{_BLNK__[0]}, @samp{R} at @samp{_BLNK__[60]},
8867 and @samp{T} at @samp{_BLNK__[140]}.
8868 (This is assuming that the target machine for
8869 the compilation has 4-byte @code{INTEGER(KIND=1)} and @code{REAL(KIND=1)}
8870 types.)
8871
8872 @node Local Equivalence Areas
8873 @section Local Equivalence Areas (EQUIVALENCE)
8874 @cindex equivalence areas
8875 @cindex local equivalence areas
8876 @cindex EQUIVALENCE statement
8877 @cindex statements, EQUIVALENCE
8878
8879 @code{g77} treats storage-associated areas involving a @code{COMMON}
8880 block as explained in the section on common blocks.
8881
8882 A local @code{EQUIVALENCE} area is a collection of variables and arrays
8883 connected to each other in any way via @code{EQUIVALENCE}, none of which are
8884 listed in a @code{COMMON} statement.
8885
8886 Currently, @code{g77} does not emit ``true'' debugging information for
8887 members in a local @code{EQUIVALENCE} area, due to an apparent bug in the GBE.
8888
8889 (As of Version 0.5.19, @code{g77} does emit debugging information for such
8890 members in the form of a constant string specifying the base name of
8891 the aggregate area and the offset of the member in bytes from the start
8892 of the area.
8893 Use the @samp{-fdebug-kludge} option to enable this behavior.
8894 In @code{gdb}, use @samp{set language c} before printing the value
8895 of the member, then @samp{set language fortran} to restore the default
8896 language, since @code{gdb} doesn't provide a way to print a readable
8897 version of a character string in Fortran language mode.
8898
8899 This kludge will be removed in a future version of @code{g77} that,
8900 in conjunction with a contemporary version of @code{gdb},
8901 properly supports Fortran-language debugging, including access
8902 to members of @code{EQUIVALENCE} areas.)
8903
8904 @xref{Code Gen Options,,Options for Code Generation Conventions},
8905 for information on the @samp{-fdebug-kludge} option.
8906
8907 Moreover, @code{g77} implements a local @code{EQUIVALENCE} area such that its
8908 type is an array of the C @code{char} data type.
8909
8910 The name @code{g77} gives this array of @code{char} type is @samp{__g77_equiv_@var{x}},
8911 where @var{x} is the name of the item that is placed at the beginning (offset 0)
8912 of this array.
8913 If more than one such item is placed at the beginning, @var{x} is
8914 the name that sorts to the top in an alphabetical sort of the list of
8915 such items.
8916
8917 When debugging, you must therefore access members of @code{EQUIVALENCE}
8918 areas by specifying the appropriate @samp{__g77_equiv_@var{x}}
8919 array section with the appropriate offset.
8920 See the explanation of debugging @code{COMMON} blocks
8921 for info applicable to debugging local @code{EQUIVALENCE} areas.
8922
8923 (@emph{Note:} @code{g77} version 0.5.18 and earlier chose the name
8924 for @var{x} using a different method when more than one name was
8925 in the list of names of entities placed at the beginning of the
8926 array.
8927 Though the documentation specified that the first name listed in
8928 the @code{EQUIVALENCE} statements was chosen for @var{x}, @code{g77}
8929 in fact chose the name using a method that was so complicated,
8930 it seemed easier to change it to an alphabetical sort than to describe the
8931 previous method in the documentation.)
8932
8933 @node Complex Variables
8934 @section Complex Variables (COMPLEX)
8935 @cindex complex variables
8936 @cindex imaginary part
8937 @cindex COMPLEX statement
8938 @cindex statements, COMPLEX
8939
8940 As of 0.5.20, @code{g77} defaults to handling @code{COMPLEX} types
8941 (and related intrinsics, constants, functions, and so on)
8942 in a manner that
8943 makes direct debugging involving these types in Fortran
8944 language mode difficult.
8945
8946 Essentially, @code{g77} implements these types using an
8947 internal construct similar to C's @code{struct}, at least
8948 as seen by the @code{gcc} back end.
8949
8950 Currently, the back end, when outputting debugging info with
8951 the compiled code for the assembler to digest, does not detect
8952 these @code{struct} types as being substitutes for Fortran
8953 complex.
8954 As a result, the Fortran language modes of debuggers such as
8955 @code{gdb} see these types as C @code{struct} types, which
8956 they might or might not support.
8957
8958 Until this is fixed, switch to C language mode to work with
8959 entities of @code{COMPLEX} type and then switch back to Fortran language
8960 mode afterward.
8961 (In @code{gdb}, this is accomplished via @samp{set lang c} and
8962 either @samp{set lang fortran} or @samp{set lang auto}.)
8963
8964 @node Arrays
8965 @section Arrays (DIMENSION)
8966 @cindex DIMENSION statement
8967 @cindex statements, DIMENSION
8968 @cindex array ordering
8969 @cindex ordering, array
8970 @cindex column-major ordering
8971 @cindex row-major ordering
8972 @cindex arrays
8973
8974 Fortran uses ``column-major ordering'' in its arrays.
8975 This differs from other languages, such as C, which use ``row-major ordering''.
8976 The difference is that, with Fortran, array elements adjacent to
8977 each other in memory differ in the @emph{first} subscript instead of
8978 the last; @samp{A(5,10,20)} immediately follows @samp{A(4,10,20)},
8979 whereas with row-major ordering it would follow @samp{A(5,10,19)}.
8980
8981 This consideration
8982 affects not only interfacing with and debugging Fortran code,
8983 it can greatly affect how code is designed and written, especially
8984 when code speed and size is a concern.
8985
8986 Fortran also differs from C, a popular language for interfacing and
8987 to support directly in debuggers, in the way arrays are treated.
8988 In C, arrays are single-dimensional and have interesting relationships
8989 to pointers, neither of which is true for Fortran.
8990 As a result, dealing with Fortran arrays from within
8991 an environment limited to C concepts can be challenging.
8992
8993 For example, accessing the array element @samp{A(5,10,20)} is easy enough
8994 in Fortran (use @samp{A(5,10,20)}), but in C some difficult machinations
8995 are needed.
8996 First, C would treat the A array as a single-dimension array.
8997 Second, C does not understand low bounds for arrays as does Fortran.
8998 Third, C assumes a low bound of zero (0), while Fortran defaults to a
8999 low bound of one (1) and can supports an arbitrary low bound.
9000 Therefore, calculations must be done
9001 to determine what the C equivalent of @samp{A(5,10,20)} would be, and these
9002 calculations require knowing the dimensions of @samp{A}.
9003
9004 For @samp{DIMENSION A(2:11,21,0:29)}, the calculation of the offset of
9005 @samp{A(5,10,20)} would be:
9006
9007 @example
9008   (5-2)
9009 + (10-1)*(11-2+1)
9010 + (20-0)*(11-2+1)*(21-1+1)
9011 = 4293
9012 @end example
9013
9014 @noindent
9015 So the C equivalent in this case would be @samp{a[4293]}.
9016
9017 When using a debugger directly on Fortran code, the C equivalent
9018 might not work, because some debuggers cannot understand the notion
9019 of low bounds other than zero.  However, unlike @code{f2c}, @code{g77}
9020 does inform the GBE that a multi-dimensional array (like @samp{A}
9021 in the above example) is really multi-dimensional, rather than a
9022 single-dimensional array, so at least the dimensionality of the array
9023 is preserved.
9024
9025 Debuggers that understand Fortran should have no trouble with
9026 non-zero low bounds, but for non-Fortran debuggers, especially
9027 C debuggers, the above example might have a C equivalent of
9028 @samp{a[4305]}.
9029 This calculation is arrived at by eliminating the subtraction
9030 of the lower bound in the first parenthesized expression on each
9031 line---that is, for @samp{(5-2)} substitute @samp{(5)}, for @samp{(10-1)}
9032 substitute @samp{(10)}, and for @samp{(20-0)} substitute @samp{(20)}.
9033 Actually, the implication of
9034 this can be that the expression @samp{*(&a[2][1][0] + 4293)} works fine,
9035 but that @samp{a[20][10][5]} produces the equivalent of
9036 @samp{*(&a[0][0][0] + 4305)} because of the missing lower bounds.
9037
9038 Come to think of it, perhaps
9039 the behavior is due to the debugger internally compensating for
9040 the lower bounds by offsetting the base address of @samp{a}, leaving
9041 @samp{&a} set lower, in this case, than @samp{&a[2][1][0]} (the address of
9042 its first element as identified by subscripts equal to the
9043 corresponding lower bounds).
9044
9045 You know, maybe nobody really needs to use arrays.
9046
9047 @node Adjustable Arrays
9048 @section Adjustable Arrays (DIMENSION)
9049 @cindex arrays, adjustable
9050 @cindex adjustable arrays
9051 @cindex arrays, automatic
9052 @cindex automatic arrays
9053 @cindex DIMENSION statement
9054 @cindex statements, DIMENSION
9055 @cindex dimensioning arrays
9056 @cindex arrays, dimensioning
9057
9058 Adjustable and automatic arrays in Fortran require the implementation
9059 (in this
9060 case, the @code{g77} compiler) to ``memorize'' the expressions that
9061 dimension the arrays each time the procedure is invoked.
9062 This is so that subsequent changes to variables used in those
9063 expressions, made during execution of the procedure, do not
9064 have any effect on the dimensions of those arrays.
9065
9066 For example:
9067
9068 @example
9069 REAL ARRAY(5)
9070 DATA ARRAY/5*2/
9071 CALL X(ARRAY, 5)
9072 END
9073 SUBROUTINE X(A, N)
9074 DIMENSION A(N)
9075 N = 20
9076 PRINT *, N, A
9077 END
9078 @end example
9079
9080 @noindent
9081 Here, the implementation should, when running the program, print something
9082 like:
9083
9084 @example
9085 20   2.  2.  2.  2.  2.
9086 @end example
9087
9088 @noindent
9089 Note that this shows that while the value of @samp{N} was successfully
9090 changed, the size of the @samp{A} array remained at 5 elements.
9091
9092 To support this, @code{g77} generates code that executes before any user
9093 code (and before the internally generated computed @code{GOTO} to handle
9094 alternate entry points, as described below) that evaluates each
9095 (nonconstant) expression in the list of subscripts for an
9096 array, and saves the result of each such evaluation to be used when
9097 determining the size of the array (instead of re-evaluating the
9098 expressions).
9099
9100 So, in the above example, when @samp{X} is first invoked, code is
9101 executed that copies the value of @samp{N} to a temporary.
9102 And that same temporary serves as the actual high bound for the single
9103 dimension of the @samp{A} array (the low bound being the constant 1).
9104 Since the user program cannot (legitimately) change the value
9105 of the temporary during execution of the procedure, the size
9106 of the array remains constant during each invocation.
9107
9108 For alternate entry points, the code @code{g77} generates takes into
9109 account the possibility that a dummy adjustable array is not actually
9110 passed to the actual entry point being invoked at that time.
9111 In that case, the public procedure implementing the entry point
9112 passes to the master private procedure implementing all the
9113 code for the entry points a @code{NULL} pointer where a pointer to that
9114 adjustable array would be expected.
9115 The @code{g77}-generated code
9116 doesn't attempt to evaluate any of the expressions in the subscripts
9117 for an array if the pointer to that array is @code{NULL} at run time in
9118 such cases.
9119 (Don't depend on this particular implementation
9120 by writing code that purposely passes @code{NULL} pointers where the
9121 callee expects adjustable arrays, even if you know the callee
9122 won't reference the arrays---nor should you pass @code{NULL} pointers
9123 for any dummy arguments used in calculating the bounds of such
9124 arrays or leave undefined any values used for that purpose in
9125 COMMON---because the way @code{g77} implements these things might
9126 change in the future!)
9127
9128 @node Alternate Entry Points
9129 @section Alternate Entry Points (ENTRY)
9130 @cindex alternate entry points
9131 @cindex entry points
9132 @cindex ENTRY statement
9133 @cindex statements, ENTRY
9134
9135 The GBE does not understand the general concept of
9136 alternate entry points as Fortran provides via the ENTRY statement.
9137 @code{g77} gets around this by using an approach to compiling procedures
9138 having at least one @code{ENTRY} statement that is almost identical to the
9139 approach used by @code{f2c}.
9140 (An alternate approach could be used that
9141 would probably generate faster, but larger, code that would also
9142 be a bit easier to debug.)
9143
9144 Information on how @code{g77} implements @code{ENTRY} is provided for those
9145 trying to debug such code.
9146 The choice of implementation seems
9147 unlikely to affect code (compiled in other languages) that interfaces
9148 to such code.
9149
9150 @code{g77} compiles exactly one public procedure for the primary entry
9151 point of a procedure plus each @code{ENTRY} point it specifies, as usual.
9152 That is, in terms of the public interface, there is no difference
9153 between
9154
9155 @example
9156 SUBROUTINE X
9157 END
9158 SUBROUTINE Y
9159 END
9160 @end example
9161
9162 @noindent
9163 and:
9164
9165 @example
9166 SUBROUTINE X
9167 ENTRY Y
9168 END
9169 @end example
9170
9171 The difference between the above two cases lies in the code compiled
9172 for the @samp{X} and @samp{Y} procedures themselves, plus the fact that,
9173 for the second case, an extra internal procedure is compiled.
9174
9175 For every Fortran procedure with at least one @code{ENTRY}
9176 statement, @code{g77} compiles an extra procedure
9177 named @samp{__g77_masterfun_@var{x}}, where @var{x} is
9178 the name of the primary entry point (which, in the above case,
9179 using the standard compiler options, would be @samp{x_} in C).
9180
9181 This extra procedure is compiled as a private procedure---that is,
9182 a procedure not accessible by name to separately compiled modules.
9183 It contains all the code in the program unit, including the code
9184 for the primary entry point plus for every entry point.
9185 (The code for each public procedure is quite short, and explained later.)
9186
9187 The extra procedure has some other interesting characteristics.
9188
9189 The argument list for this procedure is invented by @code{g77}.
9190 It contains
9191 a single integer argument named @samp{__g77_which_entrypoint},
9192 passed by value (as in Fortran's @samp{%VAL()} intrinsic), specifying the
9193 entry point index---0 for the primary entry point, 1 for the
9194 first entry point (the first @code{ENTRY} statement encountered), 2 for
9195 the second entry point, and so on.
9196
9197 It also contains, for functions returning @code{CHARACTER} and
9198 (when @samp{-ff2c} is in effect) @code{COMPLEX} functions,
9199 and for functions returning different types among the
9200 @code{ENTRY} statements (e.g. @samp{REAL FUNCTION R()}
9201 containing @samp{ENTRY I()}), an argument named @samp{__g77_result} that
9202 is expected at run time to contain a pointer to where to store
9203 the result of the entry point.
9204 For @code{CHARACTER} functions, this
9205 storage area is an array of the appropriate number of characters;
9206 for @code{COMPLEX} functions, it is the appropriate area for the return
9207 type; for multiple-return-type functions, it is a union of all the supported return
9208 types (which cannot include @code{CHARACTER}, since combining @code{CHARACTER}
9209 and non-@code{CHARACTER} return types via @code{ENTRY} in a single function
9210 is not supported by @code{g77}).
9211
9212 For @code{CHARACTER} functions, the @samp{__g77_result} argument is followed
9213 by yet another argument named @samp{__g77_length} that, at run time,
9214 specifies the caller's expected length of the returned value.
9215 Note that only @code{CHARACTER*(*)} functions and entry points actually
9216 make use of this argument, even though it is always passed by
9217 all callers of public @code{CHARACTER} functions (since the caller does not
9218 generally know whether such a function is @code{CHARACTER*(*)} or whether
9219 there are any other callers that don't have that information).
9220
9221 The rest of the argument list is the union of all the arguments
9222 specified for all the entry points (in their usual forms, e.g.
9223 @code{CHARACTER} arguments have extra length arguments, all appended at
9224 the end of this list).
9225 This is considered the ``master list'' of
9226 arguments.
9227
9228 The code for this procedure has, before the code for the first
9229 executable statement, code much like that for the following Fortran
9230 statement:
9231
9232 @smallexample
9233        GOTO (100000,100001,100002), __g77_which_entrypoint
9234 100000 @dots{}code for primary entry point@dots{}
9235 100001 @dots{}code immediately following first ENTRY statement@dots{}
9236 100002 @dots{}code immediately following second ENTRY statement@dots{}
9237 @end smallexample
9238
9239 @noindent
9240 (Note that invalid Fortran statement labels and variable names
9241 are used in the above example to highlight the fact that it
9242 represents code generated by the @code{g77} internals, not code to be
9243 written by the user.)
9244
9245 It is this code that, when the procedure is called, picks which
9246 entry point to start executing.
9247
9248 Getting back to the public procedures (@samp{x} and @samp{Y} in the original
9249 example), those procedures are fairly simple.
9250 Their interfaces
9251 are just like they would be if they were self-contained procedures
9252 (without @code{ENTRY}), of course, since that is what the callers
9253 expect.
9254 Their code consists of simply calling the private
9255 procedure, described above, with the appropriate extra arguments
9256 (the entry point index, and perhaps a pointer to a multiple-type-
9257 return variable, local to the public procedure, that contains
9258 all the supported returnable non-character types).
9259 For arguments
9260 that are not listed for a given entry point that are listed for
9261 other entry points, and therefore that are in the ``master list''
9262 for the private procedure, null pointers (in C, the @code{NULL} macro)
9263 are passed.
9264 Also, for entry points that are part of a multiple-type-
9265 returning function, code is compiled after the call of the private
9266 procedure to extract from the multi-type union the appropriate result,
9267 depending on the type of the entry point in question, returning
9268 that result to the original caller.
9269
9270 When debugging a procedure containing alternate entry points, you
9271 can either set a break point on the public procedure itself (e.g.
9272 a break point on @samp{X} or @samp{Y}) or on the private procedure that
9273 contains most of the pertinent code (e.g. @samp{__g77_masterfun_@var{x}}).
9274 If you do the former, you should use the debugger's command to
9275 ``step into'' the called procedure to get to the actual code; with
9276 the latter approach, the break point leaves you right at the
9277 actual code, skipping over the public entry point and its call
9278 to the private procedure (unless you have set a break point there
9279 as well, of course).
9280
9281 Further, the list of dummy arguments that is visible when the
9282 private procedure is active is going to be the expanded version
9283 of the list for whichever particular entry point is active,
9284 as explained above, and the way in which return values are
9285 handled might well be different from how they would be handled
9286 for an equivalent single-entry function.
9287
9288 @node Alternate Returns
9289 @section Alternate Returns (SUBROUTINE and RETURN)
9290 @cindex subroutines
9291 @cindex alternate returns
9292 @cindex SUBROUTINE statement
9293 @cindex statements, SUBROUTINE
9294 @cindex RETURN statement
9295 @cindex statements, RETURN
9296
9297 Subroutines with alternate returns (e.g. @samp{SUBROUTINE X(*)} and
9298 @samp{CALL X(*50)}) are implemented by @code{g77} as functions returning
9299 the C @code{int} type.
9300 The actual alternate-return arguments are omitted from the calling sequence.
9301 Instead, the caller uses
9302 the return value to do a rough equivalent of the Fortran
9303 computed-@code{GOTO} statement, as in @samp{GOTO (50), X()} in the
9304 example above (where @samp{X} is quietly declared as an @code{INTEGER(KIND=1)}
9305 function), and the callee just returns whatever integer
9306 is specified in the @code{RETURN} statement for the subroutine
9307 For example, @samp{RETURN 1} is implemented as @samp{X = 1} followed
9308 by @samp{RETURN}
9309 in C, and @samp{RETURN} by itself is @samp{X = 0} and @samp{RETURN}).
9310
9311 @node Assigned Statement Labels
9312 @section Assigned Statement Labels (ASSIGN and GOTO)
9313 @cindex assigned statement labels
9314 @cindex statement labels, assigned
9315 @cindex ASSIGN statement
9316 @cindex statements, ASSIGN
9317 @cindex GOTO statement
9318 @cindex statements, GOTO
9319
9320 For portability to machines where a pointer (such as to a label,
9321 which is how @code{g77} implements @code{ASSIGN} and its relatives,
9322 the assigned-@code{GOTO} and assigned-@code{FORMAT}-I/O statements)
9323 is wider (bitwise) than an @code{INTEGER(KIND=1)}, @code{g77}
9324 uses a different memory location to hold the @code{ASSIGN}ed value of a variable
9325 than it does the numerical value in that variable, unless the
9326 variable is wide enough (can hold enough bits).
9327
9328 In particular, while @code{g77} implements
9329
9330 @example
9331 I = 10
9332 @end example
9333
9334 @noindent
9335 as, in C notation, @samp{i = 10;}, it implements
9336
9337 @example
9338 ASSIGN 10 TO I
9339 @end example
9340
9341 @noindent
9342 as, in GNU's extended C notation (for the label syntax),
9343 @samp{__g77_ASSIGN_I = &&L10;} (where @samp{L10} is just a massaging
9344 of the Fortran label @samp{10} to make the syntax C-like; @code{g77} doesn't
9345 actually generate the name @samp{L10} or any other name like that,
9346 since debuggers cannot access labels anyway).
9347
9348 While this currently means that an @code{ASSIGN} statement does not
9349 overwrite the numeric contents of its target variable, @emph{do not}
9350 write any code depending on this feature.
9351 @code{g77} has already changed this implementation across
9352 versions and might do so in the future.
9353 This information is provided only to make debugging Fortran programs
9354 compiled with the current version of @code{g77} somewhat easier.
9355 If there's no debugger-visible variable named @samp{__g77_ASSIGN_I}
9356 in a program unit that does @samp{ASSIGN 10 TO I}, that probably
9357 means @code{g77} has decided it can store the pointer to the label directly
9358 into @samp{I} itself.
9359
9360 @xref{Ugly Assigned Labels}, for information on a command-line option
9361 to force @code{g77} to use the same storage for both normal and
9362 assigned-label uses of a variable.
9363
9364 @node Run-time Library Errors
9365 @section Run-time Library Errors
9366 @cindex IOSTAT=
9367 @cindex error values
9368 @cindex error messages
9369 @cindex messages, run-time
9370 @cindex I/O, errors
9371
9372 The @code{libg2c} library currently has the following table to relate
9373 error code numbers, returned in @code{IOSTAT=} variables, to messages.
9374 This information should, in future versions of this document, be
9375 expanded upon to include detailed descriptions of each message.
9376
9377 In line with good coding practices, any of the numbers in the
9378 list below should @emph{not} be directly written into Fortran
9379 code you write.
9380 Instead, make a separate @code{INCLUDE} file that defines
9381 @code{PARAMETER} names for them, and use those in your code,
9382 so you can more easily change the actual numbers in the future.
9383
9384 The information below is culled from the definition
9385 of @code{F_err} in @file{f/runtime/libI77/err.c} in the
9386 @code{g77} source tree.
9387
9388 @smallexample
9389 100: "error in format"
9390 101: "illegal unit number"
9391 102: "formatted io not allowed"
9392 103: "unformatted io not allowed"
9393 104: "direct io not allowed"
9394 105: "sequential io not allowed"
9395 106: "can't backspace file"
9396 107: "null file name"
9397 108: "can't stat file"
9398 109: "unit not connected"
9399 110: "off end of record"
9400 111: "truncation failed in endfile"
9401 112: "incomprehensible list input"
9402 113: "out of free space"
9403 114: "unit not connected"
9404 115: "read unexpected character"
9405 116: "bad logical input field"
9406 117: "bad variable type"
9407 118: "bad namelist name"
9408 119: "variable not in namelist"
9409 120: "no end record"
9410 121: "variable count incorrect"
9411 122: "subscript for scalar variable"
9412 123: "invalid array section"
9413 124: "substring out of bounds"
9414 125: "subscript out of bounds"
9415 126: "can't read file"
9416 127: "can't write file"
9417 128: "'new' file exists"
9418 129: "can't append to file"
9419 130: "non-positive record number"
9420 131: "I/O started while already doing I/O"
9421 @end smallexample
9422
9423 @node Collected Fortran Wisdom
9424 @chapter Collected Fortran Wisdom
9425 @cindex wisdom
9426 @cindex legacy code
9427 @cindex code, legacy
9428 @cindex writing code
9429 @cindex code, writing
9430
9431 Most users of @code{g77} can be divided into two camps:
9432
9433 @itemize @bullet
9434 @item
9435 Those writing new Fortran code to be compiled by @code{g77}.
9436
9437 @item
9438 Those using @code{g77} to compile existing, ``legacy'' code.
9439 @end itemize
9440
9441 Users writing new code generally understand most of the necessary
9442 aspects of Fortran to write ``mainstream'' code, but often need
9443 help deciding how to handle problems, such as the construction
9444 of libraries containing @code{BLOCK DATA}.
9445
9446 Users dealing with ``legacy'' code sometimes don't have much
9447 experience with Fortran, but believe that the code they're compiling
9448 already works when compiled by other compilers (and might
9449 not understand why, as is sometimes the case, it doesn't work
9450 when compiled by @code{g77}).
9451
9452 The following information is designed to help users do a better job
9453 coping with existing, ``legacy'' Fortran code, and with writing
9454 new code as well.
9455
9456 @menu
9457 * Advantages Over f2c::        If @code{f2c} is so great, why @code{g77}?
9458 * Block Data and Libraries::   How @code{g77} solves a common problem.
9459 * Loops::                      Fortran @code{DO} loops surprise many people.
9460 * Working Programs::           Getting programs to work should be done first.
9461 * Overly Convenient Options::  Temptations to avoid, habits to not form.
9462 * Faster Programs::            Everybody wants these, but at what cost?
9463 @end menu
9464
9465 @node Advantages Over f2c
9466 @section Advantages Over f2c
9467
9468 Without @code{f2c}, @code{g77} would have taken much longer to
9469 do and probably not been as good for quite a while.
9470 Sometimes people who notice how much @code{g77} depends on, and
9471 documents encouragement to use, @code{f2c} ask why @code{g77}
9472 was created if @code{f2c} already existed.
9473
9474 This section gives some basic answers to these questions, though it
9475 is not intended to be comprehensive.
9476
9477 @menu
9478 * Language Extensions::  Features used by Fortran code.
9479 * Diagnostic Abilities:: Abilities to spot problems early.
9480 * Compiler Options::     Features helpful to accommodate legacy code, etc.
9481 * Compiler Speed::       Speed of the compilation process.
9482 * Program Speed::        Speed of the generated, optimized code.
9483 * Ease of Debugging::    Debugging ease-of-use at the source level.
9484 * Character and Hollerith Constants::  A byte saved is a byte earned.
9485 @end menu
9486
9487 @node Language Extensions
9488 @subsection Language Extensions
9489
9490 @code{g77} offers several extensions to FORTRAN 77 language that @code{f2c}
9491 doesn't:
9492
9493 @itemize @bullet
9494 @item
9495 Automatic arrays
9496
9497 @item
9498 @code{CYCLE} and @code{EXIT}
9499
9500 @item
9501 Construct names
9502
9503 @item
9504 @code{SELECT CASE}
9505
9506 @item
9507 @code{KIND=} and @code{LEN=} notation
9508
9509 @item
9510 Semicolon as statement separator
9511
9512 @item
9513 Constant expressions in @code{FORMAT} statements
9514 (such as @samp{FORMAT(I<J>)},
9515 where @samp{J} is a @code{PARAMETER} named constant)
9516
9517 @item
9518 @code{MvBits} intrinsic
9519
9520 @item
9521 @code{libU77} (Unix-compatibility) library,
9522 with routines known to compiler as intrinsics
9523 (so they work even when compiler options are used
9524 to change the interfaces used by Fortran routines)
9525 @end itemize
9526
9527 @code{g77} also implements iterative @code{DO} loops
9528 so that they work even in the presence of certain ``extreme'' inputs,
9529 unlike @code{f2c}.
9530 @xref{Loops}.
9531
9532 However, @code{f2c} offers a few that @code{g77} doesn't, such as:
9533
9534 @itemize @bullet
9535 @item
9536 Intrinsics in @code{PARAMETER} statements
9537
9538 @item
9539 Array bounds expressions (such as @samp{REAL M(N(2))})
9540
9541 @item
9542 @code{AUTOMATIC} statement
9543 @end itemize
9544
9545 It is expected that @code{g77} will offer some or all of these missing
9546 features at some time in the future.
9547
9548 @node Diagnostic Abilities
9549 @subsection Diagnostic Abilities
9550
9551 @code{g77} offers better diagnosis of problems in @code{FORMAT} statements.
9552 @code{f2c} doesn't, for example, emit any diagnostic for
9553 @samp{FORMAT(XZFAJG10324)},
9554 leaving that to be diagnosed, at run time, by
9555 the @code{libf2c} run-time library.
9556
9557 @node Compiler Options
9558 @subsection Compiler Options
9559
9560 @code{g77} offers compiler options that @code{f2c} doesn't,
9561 most of which are designed to more easily accommodate
9562 legacy code:
9563
9564 @itemize @bullet
9565 @item
9566 Two that control the automatic appending of extra
9567 underscores to external names
9568
9569 @item
9570 One that allows dollar signs (@samp{$}) in symbol names
9571
9572 @item
9573 A variety that control acceptance of various
9574 ``ugly'' constructs
9575
9576 @item
9577 Several that specify acceptable use of upper and lower case
9578 in the source code
9579
9580 @item
9581 Many that enable, disable, delete, or hide
9582 groups of intrinsics
9583
9584 @item
9585 One to specify the length of fixed-form source lines
9586 (normally 72)
9587
9588 @item
9589 One to specify the the source code is written in
9590 Fortran-90-style free-form
9591 @end itemize
9592
9593 However, @code{f2c} offers a few that @code{g77} doesn't,
9594 like an option to have @code{REAL} default to @code{REAL*8}.
9595 It is expected that @code{g77} will offer all of the
9596 missing options pertinent to being a Fortran compiler
9597 at some time in the future.
9598
9599 @node Compiler Speed
9600 @subsection Compiler Speed
9601
9602 Saving the steps of writing and then rereading C code is a big reason
9603 why @code{g77} should be able to compile code much faster than using
9604 @code{f2c} in conjunction with the equivalent invocation of @code{gcc}.
9605
9606 However, due to @code{g77}'s youth, lots of self-checking is still being
9607 performed.
9608 As a result, this improvement is as yet unrealized
9609 (though the potential seems to be there for quite a big speedup
9610 in the future).
9611 It is possible that, as of version 0.5.18, @code{g77}
9612 is noticeably faster compiling many Fortran source files than using
9613 @code{f2c} in conjunction with @code{gcc}.
9614
9615 @node Program Speed
9616 @subsection Program Speed
9617
9618 @code{g77} has the potential to better optimize code than @code{f2c},
9619 even when @code{gcc} is used to compile the output of @code{f2c},
9620 because @code{f2c} must necessarily
9621 translate Fortran into a somewhat lower-level language (C) that cannot
9622 preserve all the information that is potentially useful for optimization,
9623 while @code{g77} can gather, preserve, and transmit that information directly
9624 to the GBE.
9625
9626 For example, @code{g77} implements @code{ASSIGN} and assigned
9627 @code{GOTO} using direct assignment of pointers to labels and direct
9628 jumps to labels, whereas @code{f2c} maps the assigned labels to
9629 integer values and then uses a C @code{switch} statement to encode
9630 the assigned @code{GOTO} statements.
9631
9632 However, as is typical, theory and reality don't quite match, at least
9633 not in all cases, so it is still the case that @code{f2c} plus @code{gcc}
9634 can generate code that is faster than @code{g77}.
9635
9636 Version 0.5.18 of @code{g77} offered default
9637 settings and options, via patches to the @code{gcc}
9638 back end, that allow for better program speed, though
9639 some of these improvements also affected the performance
9640 of programs translated by @code{f2c} and then compiled
9641 by @code{g77}'s version of @code{gcc}.
9642
9643 Version 0.5.20 of @code{g77} offers further performance
9644 improvements, at least one of which (alias analysis) is
9645 not generally applicable to @code{f2c} (though @code{f2c}
9646 could presumably be changed to also take advantage of
9647 this new capability of the @code{gcc} back end, assuming
9648 this is made available in an upcoming release of @code{gcc}).
9649
9650 @node Ease of Debugging
9651 @subsection Ease of Debugging
9652
9653 Because @code{g77} compiles directly to assembler code like @code{gcc},
9654 instead of translating to an intermediate language (C) as does @code{f2c},
9655 support for debugging can be better for @code{g77} than @code{f2c}.
9656
9657 However, although @code{g77} might be somewhat more ``native'' in terms of
9658 debugging support than @code{f2c} plus @code{gcc}, there still are a lot
9659 of things ``not quite right''.
9660 Many of the important ones should be resolved in the near future.
9661
9662 For example, @code{g77} doesn't have to worry about reserved names
9663 like @code{f2c} does.
9664 Given @samp{FOR = WHILE}, @code{f2c} must necessarily
9665 translate this to something @emph{other} than
9666 @samp{for = while;}, because C reserves those words.
9667
9668 However, @code{g77} does still uses things like an extra level of indirection
9669 for @code{ENTRY}-laden procedures---in this case, because the back end doesn't
9670 yet support multiple entry points.
9671
9672 Another example is that, given
9673
9674 @smallexample
9675 COMMON A, B
9676 EQUIVALENCE (B, C)
9677 @end smallexample
9678
9679 @noindent
9680 the @code{g77} user should be able to access the variables directly, by name,
9681 without having to traverse C-like structures and unions, while @code{f2c}
9682 is unlikely to ever offer this ability (due to limitations in the
9683 C language).
9684
9685 However, due to apparent bugs in the back end, @code{g77} currently doesn't
9686 take advantage of this facility at all---it doesn't emit any debugging
9687 information for @code{COMMON} and @code{EQUIVALENCE} areas,
9688 other than information
9689 on the array of @code{char} it creates (and, in the case
9690 of local @code{EQUIVALENCE}, names) for each such area.
9691
9692 Yet another example is arrays.
9693 @code{g77} represents them to the debugger
9694 using the same ``dimensionality'' as in the source code, while @code{f2c}
9695 must necessarily convert them all to one-dimensional arrays to fit
9696 into the confines of the C language.
9697 However, the level of support
9698 offered by debuggers for interactive Fortran-style access to arrays
9699 as compiled by @code{g77} can vary widely.
9700 In some cases, it can actually
9701 be an advantage that @code{f2c} converts everything to widely supported
9702 C semantics.
9703
9704 In fairness, @code{g77} could do many of the things @code{f2c} does
9705 to get things working at least as well as @code{f2c}---for now,
9706 the developers prefer making @code{g77} work the
9707 way they think it is supposed to, and finding help improving the
9708 other products (the back end of @code{gcc}; @code{gdb}; and so on)
9709 to get things working properly.
9710
9711 @node Character and Hollerith Constants
9712 @subsection Character and Hollerith Constants
9713 @cindex character constants
9714 @cindex constants, character
9715 @cindex Hollerith constants
9716 @cindex constants, Hollerith
9717 @cindex trailing null byte
9718 @cindex null byte, trailing
9719 @cindex zero byte, trailing
9720
9721 To avoid the extensive hassle that would be needed to avoid this,
9722 @code{f2c} uses C character constants to encode character and Hollerith
9723 constants.
9724 That means a constant like @samp{'HELLO'} is translated to
9725 @samp{"hello"} in C, which further means that an extra null byte is
9726 present at the end of the constant.
9727 This null byte is superfluous.
9728
9729 @code{g77} does not generate such null bytes.
9730 This represents significant
9731 savings of resources, such as on systems where @file{/dev/null} or
9732 @file{/dev/zero} represent bottlenecks in the systems' performance,
9733 because @code{g77} simply asks for fewer zeros from the operating
9734 system than @code{f2c}.
9735 (Avoiding spurious use of zero bytes, each byte typically have
9736 eight zero bits, also reduces the liabilities in case
9737 Microsoft's rumored patent on the digits 0 and 1 is upheld.)
9738
9739 @node Block Data and Libraries
9740 @section Block Data and Libraries
9741 @cindex block data and libraries
9742 @cindex BLOCK DATA statement
9743 @cindex statements, BLOCK DATA
9744 @cindex libraries, containing BLOCK DATA
9745 @cindex f2c compatibility
9746 @cindex compatibility, f2c
9747
9748 To ensure that block data program units are linked, especially a concern
9749 when they are put into libraries, give each one a name (as in
9750 @samp{BLOCK DATA FOO}) and make sure there is an @samp{EXTERNAL FOO}
9751 statement in every program unit that uses any common block
9752 initialized by the corresponding @code{BLOCK DATA}.
9753 @code{g77} currently compiles a @code{BLOCK DATA} as if it were a
9754 @code{SUBROUTINE},
9755 that is, it generates an actual procedure having the appropriate name.
9756 The procedure does nothing but return immediately if it happens to be
9757 called.
9758 For @samp{EXTERNAL FOO}, where @samp{FOO} is not otherwise referenced in the
9759 same program unit, @code{g77} assumes there exists a @samp{BLOCK DATA FOO}
9760 in the program and ensures that by generating a
9761 reference to it so the linker will make sure it is present.
9762 (Specifically, @code{g77} outputs in the data section a static pointer to the
9763 external name @samp{FOO}.)
9764
9765 The implementation @code{g77} currently uses to make this work is
9766 one of the few things not compatible with @code{f2c} as currently
9767 shipped.
9768 @code{f2c} currently does nothing with @samp{EXTERNAL FOO} except
9769 issue a warning that @samp{FOO} is not otherwise referenced,
9770 and, for @samp{BLOCK DATA FOO},
9771 @code{f2c} doesn't generate a dummy procedure with the name @samp{FOO}.
9772 The upshot is that you shouldn't mix @code{f2c} and @code{g77} in
9773 this particular case.
9774 If you use @code{f2c} to compile @samp{BLOCK DATA FOO},
9775 then any @code{g77}-compiled program unit that says @samp{EXTERNAL FOO}
9776 will result in an unresolved reference when linked.
9777 If you do the
9778 opposite, then @samp{FOO} might not be linked in under various
9779 circumstances (such as when @samp{FOO} is in a library, or you're
9780 using a ``clever'' linker---so clever, it produces a broken program
9781 with little or no warning by omitting initializations of global data
9782 because they are contained in unreferenced procedures).
9783
9784 The changes you make to your code to make @code{g77} handle this situation,
9785 however, appear to be a widely portable way to handle it.
9786 That is, many systems permit it (as they should, since the
9787 FORTRAN 77 standard permits @samp{EXTERNAL FOO} when @samp{FOO}
9788 is a block data program unit), and of the ones
9789 that might not link @samp{BLOCK DATA FOO} under some circumstances, most of
9790 them appear to do so once @samp{EXTERNAL FOO} is present in the appropriate
9791 program units.
9792
9793 Here is the recommended approach to modifying a program containing
9794 a program unit such as the following:
9795
9796 @smallexample
9797 BLOCK DATA FOO
9798 COMMON /VARS/ X, Y, Z
9799 DATA X, Y, Z / 3., 4., 5. /
9800 END
9801 @end smallexample
9802
9803 @noindent
9804 If the above program unit might be placed in a library module, then
9805 ensure that every program unit in every program that references that
9806 particular @code{COMMON} area uses the @code{EXTERNAL} statement
9807 to force the area to be initialized.
9808
9809 For example, change a program unit that starts with
9810
9811 @smallexample
9812 INTEGER FUNCTION CURX()
9813 COMMON /VARS/ X, Y, Z
9814 CURX = X
9815 END
9816 @end smallexample
9817
9818 @noindent
9819 so that it uses the @code{EXTERNAL} statement, as in:
9820
9821 @smallexample
9822 INTEGER FUNCTION CURX()
9823 COMMON /VARS/ X, Y, Z
9824 EXTERNAL FOO
9825 CURX = X
9826 END
9827 @end smallexample
9828
9829 @noindent
9830 That way, @samp{CURX} is compiled by @code{g77} (and many other
9831 compilers) so that the linker knows it must include @samp{FOO},
9832 the @code{BLOCK DATA} program unit that sets the initial values
9833 for the variables in @samp{VAR}, in the executable program.
9834
9835 @node Loops
9836 @section Loops
9837 @cindex DO statement
9838 @cindex statements, DO
9839 @cindex trips, number of
9840 @cindex number of trips
9841
9842 The meaning of a @code{DO} loop in Fortran is precisely specified
9843 in the Fortran standard@dots{}and is quite different from what
9844 many programmers might expect.
9845
9846 In particular, Fortran iterative @code{DO} loops are implemented as if
9847 the number of trips through the loop is calculated @emph{before}
9848 the loop is entered.
9849
9850 The number of trips for a loop is calculated from the @var{start},
9851 @var{end}, and @var{increment} values specified in a statement such as:
9852
9853 @smallexample
9854 DO @var{iter} = @var{start}, @var{end}, @var{increment}
9855 @end smallexample
9856
9857 @noindent
9858 The trip count is evaluated using a fairly simple formula
9859 based on the three values following the @samp{=} in the
9860 statement, and it is that trip count that is effectively
9861 decremented during each iteration of the loop.
9862 If, at the beginning of an iteration of the loop, the
9863 trip count is zero or negative, the loop terminates.
9864 The per-loop-iteration modifications to @var{iter} are not
9865 related to determining whether to terminate the loop.
9866
9867 There are two important things to remember about the trip
9868 count:
9869
9870 @itemize @bullet
9871 @item
9872 It can be @emph{negative}, in which case it is
9873 treated as if it was zero---meaning the loop is
9874 not executed at all.
9875
9876 @item
9877 The type used to @emph{calculate} the trip count
9878 is the same type as @var{iter}, but the final
9879 calculation, and thus the type of the trip
9880 count itself, always is @code{INTEGER(KIND=1)}.
9881 @end itemize
9882
9883 These two items mean that there are loops that cannot
9884 be written in straightforward fashion using the Fortran @code{DO}.
9885
9886 For example, on a system with the canonical 32-bit two's-complement
9887 implementation of @code{INTEGER(KIND=1)}, the following loop will not work:
9888
9889 @smallexample
9890 DO I = -2000000000, 2000000000
9891 @end smallexample
9892
9893 @noindent
9894 Although the @var{start} and @var{end} values are well within
9895 the range of @code{INTEGER(KIND=1)}, the @emph{trip count} is not.
9896 The expected trip count is 40000000001, which is outside
9897 the range of @code{INTEGER(KIND=1)} on many systems.
9898
9899 Instead, the above loop should be constructed this way:
9900
9901 @smallexample
9902 I = -2000000000
9903 DO
9904   IF (I .GT. 2000000000) EXIT
9905   @dots{}
9906   I = I + 1
9907 END DO
9908 @end smallexample
9909
9910 @noindent
9911 The simple @code{DO} construct and the @code{EXIT} statement
9912 (used to leave the innermost loop)
9913 are F90 features that @code{g77} supports.
9914
9915 Some Fortran compilers have buggy implementations of @code{DO},
9916 in that they don't follow the standard.
9917 They implement @code{DO} as a straightforward translation
9918 to what, in C, would be a @code{for} statement.
9919 Instead of creating a temporary variable to hold the trip count
9920 as calculated at run time, these compilers
9921 use the iteration variable @var{iter} to control
9922 whether the loop continues at each iteration.
9923
9924 The bug in such an implementation shows up when the
9925 trip count is within the range of the type of @var{iter},
9926 but the magnitude of @samp{ABS(@var{end}) + ABS(@var{incr})}
9927 exceeds that range.  For example:
9928
9929 @smallexample
9930 DO I = 2147483600, 2147483647
9931 @end smallexample
9932
9933 @noindent
9934 A loop started by the above statement will work as implemented
9935 by @code{g77}, but the use, by some compilers, of a
9936 more C-like implementation akin to
9937
9938 @smallexample
9939 for (i = 2147483600; i <= 2147483647; ++i)
9940 @end smallexample
9941
9942 @noindent
9943 produces a loop that does not terminate, because @samp{i}
9944 can never be greater than 2147483647, since incrementing it
9945 beyond that value overflows @samp{i}, setting it to -2147483648.
9946 This is a large, negative number that still is less than 2147483647.
9947
9948 Another example of unexpected behavior of @code{DO} involves
9949 using a nonintegral iteration variable @var{iter}, that is,
9950 a @code{REAL} variable.
9951 Consider the following program:
9952
9953 @smallexample
9954       DATA BEGIN, END, STEP /.1, .31, .007/
9955       DO 10 R = BEGIN, END, STEP
9956          IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
9957          PRINT *,R
9958 10    CONTINUE
9959       PRINT *,'LAST = ',R
9960       IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
9961       END
9962 @end smallexample
9963
9964 @noindent
9965 A C-like view of @code{DO} would hold that the two ``exclamatory''
9966 @code{PRINT} statements are never executed.
9967 However, this is the output of running the above program
9968 as compiled by @code{g77} on a GNU/Linux ix86 system:
9969
9970 @smallexample
9971  .100000001
9972  .107000001
9973  .114
9974  .120999999
9975  @dots{}
9976  .289000005
9977  .296000004
9978  .303000003
9979 LAST =   .310000002
9980  .310000002 .LE.   .310000002!!
9981 @end smallexample
9982
9983 Note that one of the two checks in the program turned up
9984 an apparent violation of the programmer's expectation---yet,
9985 the loop is correctly implemented by @code{g77}, in that
9986 it has 30 iterations.
9987 This trip count of 30 is correct when evaluated using
9988 the floating-point representations for the @var{begin},
9989 @var{end}, and @var{incr} values (.1, .31, .007) on GNU/Linux
9990 ix86 are used.
9991 On other systems, an apparently more accurate trip count
9992 of 31 might result, but, nevertheless, @code{g77} is
9993 faithfully following the Fortran standard, and the result
9994 is not what the author of the sample program above
9995 apparently expected.
9996 (Such other systems might, for different values in the @code{DATA}
9997 statement, violate the other programmer's expectation,
9998 for example.)
9999
10000 Due to this combination of imprecise representation
10001 of floating-point values and the often-misunderstood
10002 interpretation of @code{DO} by standard-conforming
10003 compilers such as @code{g77}, use of @code{DO} loops
10004 with @code{REAL} iteration
10005 variables is not recommended.
10006 Such use can be caught by specifying @samp{-Wsurprising}.
10007 @xref{Warning Options}, for more information on this
10008 option.
10009
10010 @node Working Programs
10011 @section Working Programs
10012
10013 Getting Fortran programs to work in the first place can be
10014 quite a challenge---even when the programs already work on
10015 other systems, or when using other compilers.
10016
10017 @code{g77} offers some facilities that might be useful for
10018 tracking down bugs in such programs.
10019
10020 @menu
10021 * Not My Type::
10022 * Variables Assumed To Be Zero::
10023 * Variables Assumed To Be Saved::
10024 * Unwanted Variables::
10025 * Unused Arguments::
10026 * Surprising Interpretations of Code::
10027 * Aliasing Assumed To Work::
10028 * Output Assumed To Flush::
10029 * Large File Unit Numbers::
10030 * Floating-point precision::
10031 * Inconsistent Calling Sequences::
10032 @end menu
10033
10034 @node Not My Type
10035 @subsection Not My Type
10036 @cindex mistyped variables
10037 @cindex variables, mistyped
10038 @cindex mistyped functions
10039 @cindex functions, mistyped
10040 @cindex implicit typing
10041
10042 A fruitful source of bugs in Fortran source code is use, or
10043 mis-use, of Fortran's implicit-typing feature, whereby the
10044 type of a variable, array, or function is determined by the
10045 first character of its name.
10046
10047 Simple cases of this include statements like @samp{LOGX=9.227},
10048 without a statement such as @samp{REAL LOGX}.
10049 In this case, @samp{LOGX} is implicitly given @code{INTEGER(KIND=1)}
10050 type, with the result of the assignment being that it is given
10051 the value @samp{9}.
10052
10053 More involved cases include a function that is defined starting
10054 with a statement like @samp{DOUBLE PRECISION FUNCTION IPS(@dots{})}.
10055 Any caller of this function that does not also declare @samp{IPS}
10056 as type @code{DOUBLE PRECISION} (or, in GNU Fortran, @code{REAL(KIND=2)})
10057 is likely to assume it returns
10058 @code{INTEGER}, or some other type, leading to invalid results
10059 or even program crashes.
10060
10061 The @samp{-Wimplicit} option might catch failures to
10062 properly specify the types of
10063 variables, arrays, and functions in the code.
10064
10065 However, in code that makes heavy use of Fortran's
10066 implicit-typing facility, this option might produce so
10067 many warnings about cases that are working, it would be
10068 hard to find the one or two that represent bugs.
10069 This is why so many experienced Fortran programmers strongly
10070 recommend widespread use of the @code{IMPLICIT NONE} statement,
10071 despite it not being standard FORTRAN 77, to completely turn
10072 off implicit typing.
10073 (@code{g77} supports @code{IMPLICIT NONE}, as do almost all
10074 FORTRAN 77 compilers.)
10075
10076 Note that @samp{-Wimplicit} catches only implicit typing of
10077 @emph{names}.
10078 It does not catch implicit typing of expressions such
10079 as @samp{X**(2/3)}.
10080 Such expressions can be buggy as well---in fact, @samp{X**(2/3)}
10081 is equivalent to @samp{X**0}, due to the way Fortran expressions
10082 are given types and then evaluated.
10083 (In this particular case, the programmer probably wanted
10084 @samp{X**(2./3.)}.)
10085
10086 @node Variables Assumed To Be Zero
10087 @subsection Variables Assumed To Be Zero
10088 @cindex zero-initialized variables
10089 @cindex variables, assumed to be zero
10090 @cindex uninitialized variables
10091
10092 Many Fortran programs were developed on systems that provided
10093 automatic initialization of all, or some, variables and arrays
10094 to zero.
10095 As a result, many of these programs depend, sometimes
10096 inadvertently, on this behavior, though to do so violates
10097 the Fortran standards.
10098
10099 You can ask @code{g77} for this behavior by specifying the
10100 @samp{-finit-local-zero} option when compiling Fortran code.
10101 (You might want to specify @samp{-fno-automatic} as well,
10102 to avoid code-size inflation for non-optimized compilations.)
10103
10104 Note that a program that works better when compiled with the
10105 @samp{-finit-local-zero} option
10106 is almost certainly depending on a particular system's,
10107 or compiler's, tendency to initialize some variables to zero.
10108 It might be worthwhile finding such cases and fixing them,
10109 using techniques such as compiling with the @samp{-O -Wuninitialized}
10110 options using @code{g77}.
10111
10112 @node Variables Assumed To Be Saved
10113 @subsection Variables Assumed To Be Saved
10114 @cindex variables, retaining values across calls
10115 @cindex saved variables
10116 @cindex static variables
10117
10118 Many Fortran programs were developed on systems that
10119 saved the values of all, or some, variables and arrays
10120 across procedure calls.
10121 As a result, many of these programs depend, sometimes
10122 inadvertently, on being able to assign a value to a
10123 variable, perform a @code{RETURN} to a calling procedure,
10124 and, upon subsequent invocation, reference the previously
10125 assigned variable to obtain the value.
10126
10127 They expect this despite not using the @code{SAVE} statement
10128 to specify that the value in a variable is expected to survive
10129 procedure returns and calls.
10130 Depending on variables and arrays to retain values across
10131 procedure calls without using @code{SAVE} to require it violates
10132 the Fortran standards.
10133
10134 You can ask @code{g77} to assume @code{SAVE} is specified for all
10135 relevant (local) variables and arrays by using the
10136 @samp{-fno-automatic} option.
10137
10138 Note that a program that works better when compiled with the
10139 @samp{-fno-automatic} option
10140 is almost certainly depending on not having to use
10141 the @code{SAVE} statement as required by the Fortran standard.
10142 It might be worthwhile finding such cases and fixing them,
10143 using techniques such as compiling with the @samp{-O -Wuninitialized}
10144 options using @code{g77}.
10145
10146 @node Unwanted Variables
10147 @subsection Unwanted Variables
10148
10149 The @samp{-Wunused} option can find bugs involving
10150 implicit typing, sometimes
10151 more easily than using @samp{-Wimplicit} in code that makes
10152 heavy use of implicit typing.
10153 An unused variable or array might indicate that the
10154 spelling for its declaration is different from that of
10155 its intended uses.
10156
10157 Other than cases involving typos, unused variables rarely
10158 indicate actual bugs in a program.
10159 However, investigating such cases thoroughly has, on occasion,
10160 led to the discovery of code that had not been completely
10161 written---where the programmer wrote declarations as needed
10162 for the whole algorithm, wrote some or even most of the code
10163 for that algorithm, then got distracted and forgot that the
10164 job was not complete.
10165
10166 @node Unused Arguments
10167 @subsection Unused Arguments
10168 @cindex unused arguments
10169 @cindex arguments, unused
10170
10171 As with unused variables, It is possible that unused arguments
10172 to a procedure might indicate a bug.
10173 Compile with @samp{-W -Wunused} option to catch cases of
10174 unused arguments.
10175
10176 Note that @samp{-W} also enables warnings regarding overflow
10177 of floating-point constants under certain circumstances.
10178
10179 @node Surprising Interpretations of Code
10180 @subsection Surprising Interpretations of Code
10181
10182 The @samp{-Wsurprising} option can help find bugs involving
10183 expression evaluation or in
10184 the way @code{DO} loops with non-integral iteration variables
10185 are handled.
10186 Cases found by this option might indicate a difference of
10187 interpretation between the author of the code involved, and
10188 a standard-conforming compiler such as @code{g77}.
10189 Such a difference might produce actual bugs.
10190
10191 In any case, changing the code to explicitly do what the
10192 programmer might have expected it to do, so @code{g77} and
10193 other compilers are more likely to follow the programmer's
10194 expectations, might be worthwhile, especially if such changes
10195 make the program work better.
10196
10197 @node Aliasing Assumed To Work
10198 @subsection Aliasing Assumed To Work
10199 @cindex -falias-check option
10200 @cindex options, -falias-check
10201 @cindex -fargument-alias option
10202 @cindex options, -fargument-alias
10203 @cindex -fargument-noalias option
10204 @cindex options, -fargument-noalias
10205 @cindex -fno-argument-noalias-global option
10206 @cindex options, -fno-argument-noalias-global
10207 @cindex aliasing
10208 @cindex anti-aliasing
10209 @cindex overlapping arguments
10210 @cindex overlays
10211 @cindex association, storage
10212 @cindex storage association
10213 @cindex scheduling of reads and writes
10214 @cindex reads and writes, scheduling
10215
10216 The @samp{-falias-check}, @samp{-fargument-alias},
10217 @samp{-fargument-noalias},
10218 and @samp{-fno-argument-noalias-global} options,
10219 introduced in version 0.5.20 and
10220 @code{g77}'s version 2.7.2.2.f.2 of @code{gcc},
10221 were withdrawn as of @code{g77} version 0.5.23
10222 due to their not being supported by @code{gcc} version 2.8.
10223
10224 These options, which control the assumptions regarding aliasing
10225 (overlapping) of writes and reads to main memory (core) made
10226 by the @code{gcc} back end,
10227 might well be added back (in some form) in a future version
10228 of @code{gcc}.
10229
10230 However, these options @emph{are} supported by @code{egcs}.
10231
10232 The information below still is useful, but applies to
10233 only those versions of @code{g77} that support the
10234 alias analysis implied by support for these options.
10235
10236 These options are effective only when compiling with @samp{-O}
10237 (specifying any level other than @samp{-O0})
10238 or with @samp{-falias-check}.
10239
10240 The default for Fortran code is @samp{-fargument-noalias-global}.
10241 (The default for C code and code written in other C-based languages
10242 is @samp{-fargument-alias}.
10243 These defaults apply regardless of whether you use @code{g77} or
10244 @code{gcc} to compile your code.)
10245
10246 Note that, on some systems, compiling with @samp{-fforce-addr} in
10247 effect can produce more optimal code when the default aliasing
10248 options are in effect (and when optimization is enabled).
10249
10250 If your program is not working when compiled with optimization,
10251 it is possible it is violating the Fortran standards (77 and 90)
10252 by relying on the ability to ``safely'' modify variables and
10253 arrays that are aliased, via procedure calls, to other variables
10254 and arrays, without using @code{EQUIVALENCE} to explicitly
10255 set up this kind of aliasing.
10256
10257 (The FORTRAN 77 standard's prohibition of this sort of
10258 overlap, generally referred to therein as ``storage
10259 assocation'', appears in Sections 15.9.3.6.
10260 This prohibition allows implementations, such as @code{g77},
10261 to, for example, implement the passing of procedures and
10262 even values in @code{COMMON} via copy operations into local,
10263 perhaps more efficiently accessed temporaries at entry to a
10264 procedure, and, where appropriate, via copy operations back
10265 out to their original locations in memory at exit from that
10266 procedure, without having to take into consideration the
10267 order in which the local copies are updated by the code,
10268 among other things.)
10269
10270 To test this hypothesis, try compiling your program with
10271 the @samp{-fargument-alias} option, which causes the
10272 compiler to revert to assumptions essentially the same as
10273 made by versions of @code{g77} prior to 0.5.20.
10274
10275 If the program works using this option, that strongly suggests
10276 that the bug is in your program.
10277 Finding and fixing the bug(s) should result in a program that
10278 is more standard-conforming and that can be compiled by @code{g77}
10279 in a way that results in a faster executable.
10280
10281 (You might want to try compiling with @samp{-fargument-noalias},
10282 a kind of half-way point, to see if the problem is limited to
10283 aliasing between dummy arguments and @code{COMMON} variables---this
10284 option assumes that such aliasing is not done, while still allowing
10285 aliasing among dummy arguments.)
10286
10287 An example of aliasing that is invalid according to the standards
10288 is shown in the following program, which might @emph{not} produce
10289 the expected results when executed:
10290
10291 @smallexample
10292 I = 1
10293 CALL FOO(I, I)
10294 PRINT *, I
10295 END
10296
10297 SUBROUTINE FOO(J, K)
10298 J = J + K
10299 K = J * K
10300 PRINT *, J, K
10301 END
10302 @end smallexample
10303
10304 The above program attempts to use the temporary aliasing of the
10305 @samp{J} and @samp{K} arguments in @samp{FOO} to effect a
10306 pathological behavior---the simultaneous changing of the values
10307 of @emph{both} @samp{J} and @samp{K} when either one of them
10308 is written.
10309
10310 The programmer likely expects the program to print these values:
10311
10312 @example
10313 2  4
10314 4
10315 @end example
10316
10317 However, since the program is not standard-conforming, an
10318 implementation's behavior when running it is undefined, because
10319 subroutine @samp{FOO} modifies at least one of the arguments,
10320 and they are aliased with each other.
10321 (Even if one of the assignment statements was deleted, the
10322 program would still violate these rules.
10323 This kind of on-the-fly aliasing is permitted by the standard
10324 only when none of the aliased items are defined, or written,
10325 while the aliasing is in effect.)
10326
10327 As a practical example, an optimizing compiler might schedule
10328 the @samp{J =} part of the second line of @samp{FOO} @emph{after}
10329 the reading of @samp{J} and @samp{K} for the @samp{J * K} expression,
10330 resulting in the following output:
10331
10332 @example
10333 2  2
10334 2
10335 @end example
10336
10337 Essentially, compilers are promised (by the standard and, therefore,
10338 by programmers who write code they claim to be standard-conforming)
10339 that if they cannot detect aliasing via static analysis of a single
10340 program unit's @code{EQUIVALENCE} and @code{COMMON} statements, no
10341 such aliasing exists.
10342 In such cases, compilers are free to assume that an assignment to
10343 one variable will not change the value of another variable, allowing
10344 it to avoid generating code to re-read the value of the other
10345 variable, to re-schedule reads and writes, and so on, to produce
10346 a faster executable.
10347
10348 The same promise holds true for arrays (as seen by the called
10349 procedure)---an element of one dummy array cannot be aliased
10350 with, or overlap, any element of another dummy array or be
10351 in a @code{COMMON} area known to the procedure.
10352
10353 (These restrictions apply only when the procedure defines, or
10354 writes to, one of the aliased variables or arrays.)
10355
10356 Unfortunately, there is no way to find @emph{all} possible cases of
10357 violations of the prohibitions against aliasing in Fortran code.
10358 Static analysis is certainly imperfect, as is run-time analysis,
10359 since neither can catch all violations.
10360 (Static analysis can catch all likely violations, and some that
10361 might never actually happen, while run-time analysis can catch
10362 only those violations that actually happen during a particular run.
10363 Neither approach can cope with programs mixing Fortran code with
10364 routines written in other languages, however.)
10365
10366 Currently, @code{g77} provides neither static nor run-time facilities
10367 to detect any cases of this problem, although other products might.
10368 Run-time facilities are more likely to be offered by future
10369 versions of @code{g77}, though patches improving @code{g77} so that
10370 it provides either form of detection are welcome.
10371
10372 @node Output Assumed To Flush
10373 @subsection Output Assumed To Flush
10374 @cindex ALWAYS_FLUSH
10375 @cindex synchronous write errors
10376 @cindex disk full
10377 @cindex flushing output
10378 @cindex fflush()
10379 @cindex I/O, flushing
10380 @cindex output, flushing
10381 @cindex writes, flushing
10382 @cindex NFS
10383 @cindex network file system
10384
10385 For several versions prior to 0.5.20, @code{g77} configured its
10386 version of the @code{libf2c} run-time library so that one of
10387 its configuration macros, @code{ALWAYS_FLUSH}, was defined.
10388
10389 This was done as a result of a belief that many programs expected
10390 output to be flushed to the operating system (under UNIX, via
10391 the @code{fflush()} library call) with the result that errors,
10392 such as disk full, would be immediately flagged via the
10393 relevant @code{ERR=} and @code{IOSTAT=} mechanism.
10394
10395 Because of the adverse effects this approach had on the performance
10396 of many programs, @code{g77} no longer configures @code{libf2c}
10397 (now named @code{libg2c} in its @code{g77} incarnation)
10398 to always flush output.
10399
10400 If your program depends on this behavior, either insert the
10401 appropriate @samp{CALL FLUSH} statements, or modify the sources
10402 to the @code{libg2c}, rebuild and reinstall @code{g77}, and
10403 relink your programs with the modified library.
10404
10405 (Ideally, @code{libg2c} would offer the choice at run-time, so
10406 that a compile-time option to @code{g77} or @code{f2c} could
10407 result in generating the appropriate calls to flushing or
10408 non-flushing library routines.)
10409
10410 @xref{Always Flush Output}, for information on how to modify
10411 the @code{g77} source tree so that a version of @code{libg2c}
10412 can be built and installed with the @code{ALWAYS_FLUSH} macro defined.
10413
10414 @node Large File Unit Numbers
10415 @subsection Large File Unit Numbers
10416 @cindex MXUNIT
10417 @cindex unit numbers
10418 @cindex maximum unit number
10419 @cindex illegal unit number
10420 @cindex increasing maximum unit number
10421
10422 If your program crashes at run time with a message including
10423 the text @samp{illegal unit number}, that probably is
10424 a message from the run-time library, @code{libg2c}.
10425
10426 The message means that your program has attempted to use a
10427 file unit number that is out of the range accepted by
10428 @code{libg2c}.
10429 Normally, this range is 0 through 99, and the high end
10430 of the range is controlled by a @code{libg2c} source-file
10431 macro named @code{MXUNIT}.
10432
10433 If you can easily change your program to use unit numbers
10434 in the range 0 through 99, you should do so.
10435
10436 Otherwise, see @ref{Larger File Unit Numbers}, for information on how
10437 to change @code{MXUNIT} in @code{libg2c} so you can build and
10438 install a new version of @code{libg2c} that supports the larger
10439 unit numbers you need.
10440
10441 @emph{Note:} While @code{libg2c} places a limit on the range
10442 of Fortran file-unit numbers, the underlying library and operating
10443 system might impose different kinds of limits.
10444 For example, some systems limit the number of files simultaneously
10445 open by a running program.
10446 Information on how to increase these limits should be found
10447 in your system's documentation.
10448
10449 @node Floating-point precision
10450 @subsection Floating-point precision
10451
10452 @cindex IEEE 754 conformance
10453 @cindex conformance, IEEE 754
10454 @cindex floating-point, precision
10455 @cindex ix86 floating-point
10456 @cindex x86 floating-point
10457 If your program depends on exact IEEE 754 floating-point handling it may
10458 help on some systems---specifically x86 or m68k hardware---to use
10459 the @samp{-ffloat-store} option or to reset the precision flag on the
10460 floating-point unit.
10461 @xref{Optimize Options}.
10462
10463 However, it might be better simply to put the FPU into double precision
10464 mode and not take the performance hit of @samp{-ffloat-store}.  On x86
10465 and m68k GNU systems you can do this with a technique similar to that
10466 for turning on floating-point exceptions
10467 (@pxref{Floating-point Exception Handling}).
10468 The control word could be set to double precision by
10469 replacing the @code{__setfpucw} call with one like this:
10470 @smallexample
10471   __setfpucw ((_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE);
10472 @end smallexample
10473 (It is not clear whether this has any effect on the operation of the GNU
10474 maths library, but we have no evidence of it causing trouble.)
10475
10476 Some targets (such as the Alpha) may need special options for full IEEE
10477 conformance.
10478 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and Porting GNU CC}.
10479
10480 @node Inconsistent Calling Sequences
10481 @subsection Inconsistent Calling Sequences
10482
10483 @pindex ftnchek
10484 @cindex floating-point, errors
10485 @cindex ix86 FPU stack
10486 @cindex x86 FPU stack
10487 Code containing inconsistent calling sequences in the same file is
10488 normally rejected---see @ref{GLOBALS}.
10489 (Use, say, @code{ftnchek} to ensure
10490 consistency across source files.
10491 @xref{f2c Skeletons and Prototypes,,
10492 Generating Skeletons and Prototypes with @code{f2c}}.)
10493
10494 Mysterious errors, which may appear to be code generation problems, can
10495 appear specifically on the x86 architecture with some such
10496 inconsistencies.  On x86 hardware, floating-point return values of
10497 functions are placed on the floating-point unit's register stack, not
10498 the normal stack.  Thus calling a @code{REAL} or @code{DOUBLE PRECISION}
10499 @code{FUNCTION} as some other sort of procedure, or vice versa,
10500 scrambles the floating-point stack.  This may break unrelated code
10501 executed later.  Similarly if, say, external C routines are written
10502 incorrectly.
10503
10504 @node Overly Convenient Options
10505 @section Overly Convenient Command-line Options
10506 @cindex overly convenient options
10507 @cindex options, overly convenient
10508
10509 These options should be used only as a quick-and-dirty way to determine
10510 how well your program will run under different compilation models
10511 without having to change the source.
10512 Some are more problematic
10513 than others, depending on how portable and maintainable you want the
10514 program to be (and, of course, whether you are allowed to change it
10515 at all is crucial).
10516
10517 You should not continue to use these command-line options to compile
10518 a given program, but rather should make changes to the source code:
10519
10520 @table @code
10521 @cindex -finit-local-zero option
10522 @cindex options, -finit-local-zero
10523 @item -finit-local-zero
10524 (This option specifies that any uninitialized local variables
10525 and arrays have default initialization to binary zeros.)
10526
10527 Many other compilers do this automatically, which means lots of
10528 Fortran code developed with those compilers depends on it.
10529
10530 It is safer (and probably
10531 would produce a faster program) to find the variables and arrays that
10532 need such initialization and provide it explicitly via @code{DATA}, so that
10533 @samp{-finit-local-zero} is not needed.
10534
10535 Consider using @samp{-Wuninitialized} (which requires @samp{-O}) to
10536 find likely candidates, but
10537 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
10538 or this technique won't work.
10539
10540 @cindex -fno-automatic option
10541 @cindex options, -fno-automatic
10542 @item -fno-automatic
10543 (This option specifies that all local variables and arrays
10544 are to be treated as if they were named in @code{SAVE} statements.)
10545
10546 Many other compilers do this automatically, which means lots of
10547 Fortran code developed with those compilers depends on it.
10548
10549 The effect of this is that all non-automatic variables and arrays
10550 are made static, that is, not placed on the stack or in heap storage.
10551 This might cause a buggy program to appear to work better.
10552 If so, rather than relying on this command-line option (and hoping all
10553 compilers provide the equivalent one), add @code{SAVE}
10554 statements to some or all program unit sources, as appropriate.
10555 Consider using @samp{-Wuninitialized} (which requires @samp{-O})
10556 to find likely candidates, but
10557 do not specify @samp{-finit-local-zero} or @samp{-fno-automatic},
10558 or this technique won't work.
10559
10560 The default is @samp{-fautomatic}, which tells @code{g77} to try
10561 and put variables and arrays on the stack (or in fast registers)
10562 where possible and reasonable.
10563 This tends to make programs faster.
10564
10565 @cindex automatic arrays
10566 @cindex arrays, automatic
10567 @emph{Note:} Automatic variables and arrays are not affected
10568 by this option.
10569 These are variables and arrays that are @emph{necessarily} automatic,
10570 either due to explicit statements, or due to the way they are
10571 declared.
10572 Examples include local variables and arrays not given the
10573 @code{SAVE} attribute in procedures declared @code{RECURSIVE},
10574 and local arrays declared with non-constant bounds (automatic
10575 arrays).
10576 Currently, @code{g77} supports only automatic arrays, not
10577 @code{RECURSIVE} procedures or other means of explicitly
10578 specifying that variables or arrays are automatic.
10579
10580 @cindex -f@var{group}-intrinsics-hide option
10581 @cindex options, -f@var{group}-intrinsics-hide
10582 @item -f@var{group}-intrinsics-hide
10583 Change the source code to use @code{EXTERNAL} for any external procedure
10584 that might be the name of an intrinsic.
10585 It is easy to find these using @samp{-f@var{group}-intrinsics-disable}.
10586 @end table
10587
10588 @node Faster Programs
10589 @section Faster Programs
10590 @cindex speed, of programs
10591 @cindex programs, speeding up
10592
10593 Aside from the usual @code{gcc} options, such as @samp{-O},
10594 @samp{-ffast-math}, and so on, consider trying some of the
10595 following approaches to speed up your program (once you get
10596 it working).
10597
10598 @menu
10599 * Aligned Data::
10600 * Prefer Automatic Uninitialized Variables::
10601 * Avoid f2c Compatibility::
10602 * Use Submodel Options::
10603 @end menu
10604
10605 @node Aligned Data
10606 @subsection Aligned Data
10607 @cindex alignment
10608 @cindex data, aligned
10609 @cindex stack, aligned
10610 @cindex aligned data
10611 @cindex aligned stack
10612 @cindex Pentium optimizations
10613 @cindex optimization, for Pentium
10614
10615 On some systems, such as those with Pentium Pro CPUs, programs
10616 that make heavy use of @code{REAL(KIND=2)} (@code{DOUBLE PRECISION})
10617 might run much slower
10618 than possible due to the compiler not aligning these 64-bit
10619 values to 64-bit boundaries in memory.
10620 (The effect also is present, though
10621 to a lesser extent, on the 586 (Pentium) architecture.)
10622
10623 The Intel x86 architecture generally ensures that these programs will
10624 work on all its implementations,
10625 but particular implementations (such as Pentium Pro)
10626 perform better with more strict alignment.
10627 (Such behavior isn't unique to the Intel x86 architecture.)
10628 Other architectures might @emph{demand} 64-bit alignment
10629 of 64-bit data.
10630
10631 There are a variety of approaches to use to address this problem:
10632
10633 @itemize @bullet
10634 @item
10635 @cindex @code{COMMON} layout
10636 @cindex layout of @code{COMMON} blocks
10637 Order your @code{COMMON} and @code{EQUIVALENCE} areas such
10638 that the variables and arrays with the widest alignment
10639 guidelines come first.
10640
10641 For example, on most systems, this would mean placing
10642 @code{COMPLEX(KIND=2)}, @code{REAL(KIND=2)}, and
10643 @code{INTEGER(KIND=2)} entities first, followed by @code{REAL(KIND=1)},
10644 @code{INTEGER(KIND=1)}, and @code{LOGICAL(KIND=1)} entities, then
10645 @code{INTEGER(KIND=6)} entities, and finally @code{CHARACTER}
10646 and @code{INTEGER(KIND=3)} entities.
10647
10648 The reason to use such placement is it makes it more likely
10649 that your data will be aligned properly, without requiring
10650 you to do detailed analysis of each aggregate (@code{COMMON}
10651 and @code{EQUIVALENCE}) area.
10652
10653 Specifically, on systems where the above guidelines are
10654 appropriate, placing @code{CHARACTER} entities before
10655 @code{REAL(KIND=2)} entities can work just as well,
10656 but only if the number of bytes occupied by the @code{CHARACTER}
10657 entities is divisible by the recommended alignment for
10658 @code{REAL(KIND=2)}.
10659
10660 By ordering the placement of entities in aggregate
10661 areas according to the simple guidelines above, you
10662 avoid having to carefully count the number of bytes
10663 occupied by each entity to determine whether the
10664 actual alignment of each subsequent entity meets the
10665 alignment guidelines for the type of that entity.
10666
10667 If you don't ensure correct alignment of @code{COMMON} elements, the
10668 compiler may be forced by some systems to violate the Fortran semantics by
10669 adding padding to get @code{DOUBLE PRECISION} data properly aligned.
10670 If the unfortunate practice is employed of overlaying different types of
10671 data in the @code{COMMON} block, the different variants
10672 of this block may become misaligned with respect to each other.
10673 Even if your platform doesn't require strict alignment,
10674 @code{COMMON} should be laid out as above for portability.
10675 (Unfortunately the FORTRAN 77 standard didn't anticipate this
10676 possible requirement, which is compiler-independent on a given platform.)
10677
10678 @item
10679 @cindex -malign-double option
10680 @cindex options, -malign-double
10681 Use the (x86-specific) @samp{-malign-double} option when compiling
10682 programs for the Pentium and Pentium Pro architectures (called 586
10683 and 686 in the @code{gcc} configuration subsystem).
10684 The warning about this in the @code{gcc} manual isn't
10685 generally relevant to Fortran,
10686 but using it will force @code{COMMON} to be padded if necessary to align
10687 @code{DOUBLE PRECISION} data.
10688
10689 When @code{DOUBLE PRECISION} data is forcibly aligned
10690 in @code{COMMON} by @code{g77} due to specifying @samp{-malign-double},
10691 @code{g77} issues a warning about the need to
10692 insert padding.
10693
10694 In this case, each and every program unit that uses
10695 the same @code{COMMON} area
10696 must specify the same layout of variables and their types
10697 for that area
10698 and be compiled with @samp{-malign-double} as well.
10699 @code{g77} will issue warnings in each case,
10700 but as long as every program unit using that area
10701 is compiled with the same warnings,
10702 the resulting object files should work when linked together
10703 unless the program makes additional assumptions about
10704 @code{COMMON} area layouts that are outside the scope
10705 of the FORTRAN 77 standard,
10706 or uses @code{EQUIVALENCE} or different layouts
10707 in ways that assume no padding is ever inserted by the compiler.
10708
10709 @item
10710 Ensure that @file{crt0.o} or @file{crt1.o}
10711 on your system guarantees a 64-bit
10712 aligned stack for @code{main()}.
10713 The recent one from GNU (@code{glibc2}) will do this on x86 systems,
10714 but we don't know of any other x86 setups where it will be right.
10715 Read your system's documentation to determine if
10716 it is appropriate to upgrade to a more recent version
10717 to obtain the optimal alignment.
10718 @end itemize
10719
10720 Progress is being made on making this work
10721 ``out of the box'' on future versions of @code{g77},
10722 @code{gcc}, and some of the relevant operating systems
10723 (such as GNU/Linux).
10724
10725 @cindex alignment testing
10726 @cindex testing alignment
10727 A package that tests the degree to which a Fortran compiler
10728 (such as @code{g77})
10729 aligns 64-bit floating-point variables and arrays
10730 is available at @uref{ftp://alpha.gnu.org/gnu/g77/align/}.
10731
10732 @node Prefer Automatic Uninitialized Variables
10733 @subsection Prefer Automatic Uninitialized Variables
10734
10735 If you're using @samp{-fno-automatic} already, you probably
10736 should change your code to allow compilation with @samp{-fautomatic}
10737 (the default), to allow the program to run faster.
10738
10739 Similarly, you should be able to use @samp{-fno-init-local-zero}
10740 (the default) instead of @samp{-finit-local-zero}.
10741 This is because it is rare that every variable affected by these
10742 options in a given program actually needs to
10743 be so affected.
10744
10745 For example, @samp{-fno-automatic}, which effectively @code{SAVE}s
10746 every local non-automatic variable and array, affects even things like
10747 @code{DO} iteration
10748 variables, which rarely need to be @code{SAVE}d, and this often reduces
10749 run-time performances.
10750 Similarly, @samp{-fno-init-local-zero} forces such
10751 variables to be initialized to zero---when @code{SAVE}d (such as when
10752 @samp{-fno-automatic}), this by itself generally affects only
10753 startup time for a program, but when not @code{SAVE}d,
10754 it can slow down the procedure every time it is called.
10755
10756 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
10757 for information on the @samp{-fno-automatic} and
10758 @samp{-finit-local-zero} options and how to convert
10759 their use into selective changes in your own code.
10760
10761 @node Avoid f2c Compatibility
10762 @subsection Avoid f2c Compatibility
10763 @cindex -fno-f2c option
10764 @cindex options, -fno-f2c
10765 @cindex @code{f2c} compatibility
10766 @cindex compatibility, @code{f2c}
10767
10768 If you aren't linking with any code compiled using
10769 @code{f2c}, try using the @samp{-fno-f2c} option when
10770 compiling @emph{all} the code in your program.
10771 (Note that @code{libf2c} is @emph{not} an example of code
10772 that is compiled using @code{f2c}---it is compiled by a C
10773 compiler, typically @code{gcc}.)
10774
10775 @node Use Submodel Options
10776 @subsection Use Submodel Options
10777 @cindex submodels
10778
10779 Using an appropriate @samp{-m} option to generate specific code for your
10780 CPU may be worthwhile, though it may mean the executable won't run on
10781 other versions of the CPU that don't support the same instruction set.
10782 @xref{Submodel Options,,Hardware Models and Configurations,gcc,Using and
10783 Porting GNU CC}.  For instance on an x86 system the compiler might have
10784 been built---as shown by @samp{g77 -v}---for the target
10785 @samp{i386-pc-linux-gnu}, i.e.@: an @samp{i386} CPU@.  In that case to
10786 generate code best optimized for a Pentium you could use the option
10787 @samp{-march=pentium}.
10788
10789 For recent CPUs that don't have explicit support in the released version
10790 of @code{gcc}, it @emph{might} still be possible to get improvements
10791 with certain @samp{-m} options.
10792
10793 @samp{-fomit-frame-pointer} can help performance on x86 systems and
10794 others.  It will, however, inhibit debugging on the systems on which it
10795 is not turned on anyway by @samp{-O}.
10796
10797 @node Trouble
10798 @chapter Known Causes of Trouble with GNU Fortran
10799 @cindex bugs, known
10800 @cindex installation trouble
10801 @cindex known causes of trouble
10802
10803 This section describes known problems that affect users of GNU Fortran.
10804 Most of these are not GNU Fortran bugs per se---if they were, we would
10805 fix them.
10806 But the result for a user might be like the result of a bug.
10807
10808 Some of these problems are due to bugs in other software, some are
10809 missing features that are too much work to add, and some are places
10810 where people's opinions differ as to what is best.
10811
10812 Information on bugs that show up when configuring, porting, building,
10813 or installing @code{g77} is not provided here.
10814 @xref{Problems Installing}.
10815
10816 To find out about major bugs discovered in the current release and
10817 possible workarounds for them, see
10818 @uref{ftp://alpha.gnu.org/g77.plan}.
10819
10820 (Note that some of this portion of the manual is lifted
10821 directly from the @code{gcc} manual, with minor modifications
10822 to tailor it to users of @code{g77}.
10823 Anytime a bug seems to have more to do with the @code{gcc}
10824 portion of @code{g77}, see
10825 @ref{Trouble,,Known Causes of Trouble with GNU CC,
10826 gcc,Using and Porting GNU CC}.)
10827
10828 @menu
10829 * But-bugs::         Bugs really in other programs or elsewhere.
10830 * Known Bugs::       Bugs known to be in this version of @code{g77}.
10831 * Missing Features:: Features we already know we want to add later.
10832 * Disappointments::  Regrettable things we can't change.
10833 * Non-bugs::         Things we think are right, but some others disagree.
10834 * Warnings and Errors::  Which problems in your code get warnings,
10835                         and which get errors.
10836 @end menu
10837
10838 @node But-bugs
10839 @section Bugs Not In GNU Fortran
10840 @cindex but-bugs
10841
10842 These are bugs to which the maintainers often have to reply,
10843 ``but that isn't a bug in @code{g77}@dots{}''.
10844 Some of these already are fixed in new versions of other
10845 software; some still need to be fixed; some are problems
10846 with how @code{g77} is installed or is being used;
10847 some are the result of bad hardware that causes software
10848 to misbehave in sometimes bizarre ways;
10849 some just cannot be addressed at this time until more
10850 is known about the problem.
10851
10852 Please don't re-report these bugs to the @code{g77} maintainers---if
10853 you must remind someone how important it is to you that the problem
10854 be fixed, talk to the people responsible for the other products
10855 identified below, but preferably only after you've tried the
10856 latest versions of those products.
10857 The @code{g77} maintainers have their hands full working on
10858 just fixing and improving @code{g77}, without serving as a
10859 clearinghouse for all bugs that happen to affect @code{g77}
10860 users.
10861
10862 @xref{Collected Fortran Wisdom}, for information on behavior
10863 of Fortran programs, and the programs that compile them, that
10864 might be @emph{thought} to indicate bugs.
10865
10866 @menu
10867 * Signal 11 and Friends::  Strange behavior by any software.
10868 * Cannot Link Fortran Programs::  Unresolved references.
10869 * Large Common Blocks::    Problems on older GNU/Linux systems.
10870 * Debugger Problems::      When the debugger crashes.
10871 * NeXTStep Problems::      Misbehaving executables.
10872 * Stack Overflow::         More misbehaving executables.
10873 * Nothing Happens::        Less behaving executables.
10874 * Strange Behavior at Run Time::  Executables misbehaving due to
10875                             bugs in your program.
10876 * Floating-point Errors::  The results look wrong, but@dots{}.
10877 @end menu
10878
10879 @node Signal 11 and Friends
10880 @subsection Signal 11 and Friends
10881 @cindex signal 11
10882 @cindex hardware errors
10883
10884 A whole variety of strange behaviors can occur when the
10885 software, or the way you are using the software,
10886 stresses the hardware in a way that triggers hardware bugs.
10887 This might seem hard to believe, but it happens frequently
10888 enough that there exist documents explaining in detail
10889 what the various causes of the problems are, what
10890 typical symptoms look like, and so on.
10891
10892 Generally these problems are referred to in this document
10893 as ``signal 11'' crashes, because the Linux kernel, running
10894 on the most popular hardware (the Intel x86 line), often
10895 stresses the hardware more than other popular operating
10896 systems.
10897 When hardware problems do occur under GNU/Linux on x86
10898 systems, these often manifest themselves as ``signal 11''
10899 problems, as illustrated by the following diagnostic:
10900
10901 @smallexample
10902 sh# @kbd{g77 myprog.f}
10903 gcc: Internal compiler error: program f771 got fatal signal 11
10904 sh#
10905 @end smallexample
10906
10907 It is @emph{very} important to remember that the above
10908 message is @emph{not} the only one that indicates a
10909 hardware problem, nor does it always indicate a hardware
10910 problem.
10911
10912 In particular, on systems other than those running the Linux
10913 kernel, the message might appear somewhat or very different,
10914 as it will if the error manifests itself while running a
10915 program other than the @code{g77} compiler.
10916 For example,
10917 it will appear somewhat different when running your program,
10918 when running Emacs, and so on.
10919
10920 How to cope with such problems is well beyond the scope
10921 of this manual.
10922
10923 However, users of Linux-based systems (such as GNU/Linux)
10924 should review @uref{http://www.bitwizard.nl/sig11/}, a source
10925 of detailed information on diagnosing hardware problems,
10926 by recognizing their common symptoms.
10927
10928 Users of other operating systems and hardware might
10929 find this reference useful as well.
10930 If you know of similar material for another hardware/software
10931 combination, please let us know so we can consider including
10932 a reference to it in future versions of this manual.
10933
10934 @node Cannot Link Fortran Programs
10935 @subsection Cannot Link Fortran Programs
10936 @cindex unresolved reference (various)
10937 @cindex linking error for user code
10938 @cindex code, user
10939 @cindex @code{ld}, error linking user code
10940 @cindex @code{ld}, can't find strange names
10941 On some systems, perhaps just those with out-of-date (shared?)
10942 libraries, unresolved-reference errors happen when linking @code{g77}-compiled
10943 programs (which should be done using @code{g77}).
10944
10945 If this happens to you, try appending @samp{-lc} to the command you
10946 use to link the program, e.g. @samp{g77 foo.f -lc}.
10947 @code{g77} already specifies @samp{-lg2c -lm} when it calls the linker,
10948 but it cannot also specify @samp{-lc} because not all systems have a
10949 file named @file{libc.a}.
10950
10951 It is unclear at this point whether there are legitimately installed
10952 systems where @samp{-lg2c -lm} is insufficient to resolve code produced
10953 by @code{g77}.
10954
10955 @cindex undefined reference (_main)
10956 @cindex linking error, user code
10957 @cindex @code{ld}, error linking user code
10958 @cindex code, user
10959 @cindex @code{ld}, can't find @samp{_main}
10960 If your program doesn't link due to unresolved references to names
10961 like @samp{_main}, make sure you're using the @code{g77} command to do the
10962 link, since this command ensures that the necessary libraries are
10963 loaded by specifying @samp{-lg2c -lm} when it invokes the @code{gcc}
10964 command to do the actual link.
10965 (Use the @samp{-v} option to discover
10966 more about what actually happens when you use the @code{g77} and @code{gcc}
10967 commands.)
10968
10969 Also, try specifying @samp{-lc} as the last item on the @code{g77}
10970 command line, in case that helps.
10971
10972 @node Large Common Blocks
10973 @subsection Large Common Blocks
10974 @cindex common blocks, large
10975 @cindex large common blocks
10976 @cindex linking, errors
10977 @cindex @code{ld}, errors
10978 @cindex errors, linker
10979 On some older GNU/Linux systems, programs with common blocks larger
10980 than 16MB cannot be linked without some kind of error
10981 message being produced.
10982
10983 This is a bug in older versions of @code{ld}, fixed in
10984 more recent versions of @code{binutils}, such as version 2.6.
10985
10986 @node Debugger Problems
10987 @subsection Debugger Problems
10988 @cindex @code{gdb}, support
10989 @cindex support, @code{gdb}
10990 There are some known problems when using @code{gdb} on code
10991 compiled by @code{g77}.
10992 Inadequate investigation as of the release of 0.5.16 results in not
10993 knowing which products are the culprit, but @file{gdb-4.14} definitely
10994 crashes when, for example, an attempt is made to print the contents
10995 of a @code{COMPLEX(KIND=2)} dummy array, on at least some GNU/Linux
10996 machines, plus some others.
10997 Attempts to access assumed-size arrays are
10998 also known to crash recent versions of @code{gdb}.
10999 (@code{gdb}'s Fortran support was done for a different compiler
11000 and isn't properly compatible with @code{g77}.)
11001
11002 @node NeXTStep Problems
11003 @subsection NeXTStep Problems
11004 @cindex NeXTStep problems
11005 @cindex bus error
11006 @cindex segmentation violation
11007 Developers of Fortran code on NeXTStep (all architectures) have to
11008 watch out for the following problem when writing programs with
11009 large, statically allocated (i.e. non-stack based) data structures
11010 (common blocks, saved arrays).
11011
11012 Due to the way the native loader (@file{/bin/ld}) lays out
11013 data structures in virtual memory, it is very easy to create an
11014 executable wherein the @samp{__DATA} segment overlaps (has addresses in
11015 common) with the @samp{UNIX STACK} segment.
11016
11017 This leads to all sorts of trouble, from the executable simply not
11018 executing, to bus errors.
11019 The NeXTStep command line tool @code{ebadexec} points to
11020 the problem as follows:
11021
11022 @smallexample
11023 % @kbd{/bin/ebadexec a.out}
11024 /bin/ebadexec: __LINKEDIT segment (truncated address = 0x3de000
11025 rounded size = 0x2a000) of executable file: a.out overlaps with UNIX
11026 STACK segment (truncated address = 0x400000 rounded size =
11027 0x3c00000) of executable file: a.out
11028 @end smallexample
11029
11030 (In the above case, it is the @samp{__LINKEDIT} segment that overlaps the
11031 stack segment.)
11032
11033 This can be cured by assigning the @samp{__DATA} segment
11034 (virtual) addresses beyond the stack segment.
11035 A conservative
11036 estimate for this is from address 6000000 (hexadecimal) onwards---this
11037 has always worked for me [Toon Moene]:
11038
11039 @smallexample
11040 % @kbd{g77 -segaddr __DATA 6000000 test.f}
11041 % @kbd{ebadexec a.out}
11042 ebadexec: file: a.out appears to be executable
11043 %
11044 @end smallexample
11045
11046 Browsing through @file{@value{path-g77}/Makefile.in},
11047 you will find that the @code{f771} program itself also has to be
11048 linked with these flags---it has large statically allocated
11049 data structures.
11050 (Version 0.5.18 reduces this somewhat, but probably
11051 not enough.)
11052
11053 (The above item was contributed by Toon Moene
11054 (@email{toon@@moene.indiv.nluug.nl}).)
11055
11056 @node Stack Overflow
11057 @subsection Stack Overflow
11058 @cindex stack, overflow
11059 @cindex segmentation violation
11060 @code{g77} code might fail at runtime (probably with a ``segmentation
11061 violation'') due to overflowing the stack.
11062 This happens most often on systems with an environment
11063 that provides substantially more heap space (for use
11064 when arbitrarily allocating and freeing memory) than stack
11065 space.
11066
11067 Often this can be cured by
11068 increasing or removing your shell's limit on stack usage, typically
11069 using @kbd{limit stacksize} (in @code{csh} and derivatives) or
11070 @kbd{ulimit -s} (in @code{sh} and derivatives).
11071
11072 Increasing the allowed stack size might, however, require
11073 changing some operating system or system configuration parameters.
11074
11075 You might be able to work around the problem by compiling with the
11076 @samp{-fno-automatic} option to reduce stack usage, probably at the
11077 expense of speed.
11078
11079 @xref{Maximum Stackable Size}, for information on patching
11080 @code{g77} to use different criteria for placing local
11081 non-automatic variables and arrays on the stack.
11082
11083 @cindex automatic arrays
11084 @cindex arrays, automatic
11085 However, if your program uses large automatic arrays
11086 (for example, has declarations like @samp{REAL A(N)} where
11087 @samp{A} is a local array and @samp{N} is a dummy or
11088 @code{COMMON} variable that can have a large value),
11089 neither use of @samp{-fno-automatic},
11090 nor changing the cut-off point for @code{g77} for using the stack,
11091 will solve the problem by changing the placement of these
11092 large arrays, as they are @emph{necessarily} automatic.
11093
11094 @code{g77} currently provides no means to specify that
11095 automatic arrays are to be allocated on the heap instead
11096 of the stack.
11097 So, other than increasing the stack size, your best bet is to
11098 change your source code to avoid large automatic arrays.
11099 Methods for doing this currently are outside the scope of
11100 this document.
11101
11102 (@emph{Note:} If your system puts stack and heap space in the
11103 same memory area, such that they are effectively combined, then
11104 a stack overflow probably indicates a program that is either
11105 simply too large for the system, or buggy.)
11106
11107 @node Nothing Happens
11108 @subsection Nothing Happens
11109 @cindex nothing happens
11110 @cindex naming programs
11111 @cindex @code{test} programs
11112 @cindex programs, @code{test}
11113 It is occasionally reported that a ``simple'' program,
11114 such as a ``Hello, World!'' program, does nothing when
11115 it is run, even though the compiler reported no errors,
11116 despite the program containing nothing other than a
11117 simple @code{PRINT} statement.
11118
11119 This most often happens because the program has been
11120 compiled and linked on a UNIX system and named @code{test},
11121 though other names can lead to similarly unexpected
11122 run-time behavior on various systems.
11123
11124 Essentially this problem boils down to giving
11125 your program a name that is already known to
11126 the shell you are using to identify some other program,
11127 which the shell continues to execute instead of your
11128 program when you invoke it via, for example:
11129
11130 @smallexample
11131 sh# @kbd{test}
11132 sh#
11133 @end smallexample
11134
11135 Under UNIX and many other system, a simple command name
11136 invokes a searching mechanism that might well not choose
11137 the program located in the current working directory if
11138 there is another alternative (such as the @code{test}
11139 command commonly installed on UNIX systems).
11140
11141 The reliable way to invoke a program you just linked in
11142 the current directory under UNIX is to specify it using
11143 an explicit pathname, as in:
11144
11145 @smallexample
11146 sh# @kbd{./test}
11147  Hello, World!
11148 sh#
11149 @end smallexample
11150
11151 Users who encounter this problem should take the time to
11152 read up on how their shell searches for commands, how to
11153 set their search path, and so on.
11154 The relevant UNIX commands to learn about include
11155 @code{man}, @code{info} (on GNU systems), @code{setenv} (or
11156 @code{set} and @code{env}), @code{which}, and @code{find}.
11157
11158 @node Strange Behavior at Run Time
11159 @subsection Strange Behavior at Run Time
11160 @cindex segmentation violation
11161 @cindex bus error
11162 @cindex overwritten data
11163 @cindex data, overwritten
11164 @code{g77} code might fail at runtime with ``segmentation violation'',
11165 ``bus error'', or even something as subtle as a procedure call
11166 overwriting a variable or array element that it is not supposed
11167 to touch.
11168
11169 These can be symptoms of a wide variety of actual bugs that
11170 occurred earlier during the program's run, but manifested
11171 themselves as @emph{visible} problems some time later.
11172
11173 Overflowing the bounds of an array---usually by writing beyond
11174 the end of it---is one of two kinds of bug that often occurs
11175 in Fortran code.
11176 (Compile your code with the @samp{-fbounds-check} option
11177 to catch many of these kinds of errors at program run time.)
11178
11179 The other kind of bug is a mismatch between the actual arguments
11180 passed to a procedure and the dummy arguments as declared by that
11181 procedure.
11182
11183 Both of these kinds of bugs, and some others as well, can be
11184 difficult to track down, because the bug can change its behavior,
11185 or even appear to not occur, when using a debugger.
11186
11187 That is, these bugs can be quite sensitive to data, including
11188 data representing the placement of other data in memory (that is,
11189 pointers, such as the placement of stack frames in memory).
11190
11191 @code{g77} now offers the
11192 ability to catch and report some of these problems at compile, link, or
11193 run time, such as by generating code to detect references to
11194 beyond the bounds of most arrays (except assumed-size arrays),
11195 and checking for agreement between calling and called procedures.
11196 Future improvements are likely to be made in the procedure-mismatch area,
11197 at least.
11198
11199 In the meantime, finding and fixing the programming
11200 bugs that lead to these behaviors is, ultimately, the user's
11201 responsibility, as difficult as that task can sometimes be.
11202
11203 @cindex infinite spaces printed
11204 @cindex space, endless printing of
11205 @cindex libc, non-ANSI or non-default
11206 @cindex C library
11207 @cindex linking against non-standard library
11208 @cindex Solaris
11209 One runtime problem that has been observed might have a simple solution.
11210 If a formatted @code{WRITE} produces an endless stream of spaces, check
11211 that your program is linked against the correct version of the C library.
11212 The configuration process takes care to account for your
11213 system's normal @file{libc} not being ANSI-standard, which will
11214 otherwise cause this behaviour.
11215 If your system's default library is
11216 ANSI-standard and you subsequently link against a non-ANSI one, there
11217 might be problems such as this one.
11218
11219 Specifically, on Solaris2 systems,
11220 avoid picking up the @code{BSD} library from @file{/usr/ucblib}.
11221
11222 @node Floating-point Errors
11223 @subsection Floating-point Errors
11224 @cindex floating-point errors
11225 @cindex rounding errors
11226 @cindex inconsistent floating-point results
11227 @cindex results, inconsistent
11228 Some programs appear to produce inconsistent floating-point
11229 results compiled by @code{g77} versus by other compilers.
11230
11231 Often the reason for this behavior is the fact that floating-point
11232 values are represented on almost all Fortran systems by
11233 @emph{approximations}, and these approximations are inexact
11234 even for apparently simple values like 0.1, 0.2, 0.3, 0.4, 0.6,
11235 0.7, 0.8, 0.9, 1.1, and so on.
11236 Most Fortran systems, including all current ports of @code{g77},
11237 use binary arithmetic to represent these approximations.
11238
11239 Therefore, the exact value of any floating-point approximation
11240 as manipulated by @code{g77}-compiled code is representable by
11241 adding some combination of the values 1.0, 0.5, 0.25, 0.125, and
11242 so on (just keep dividing by two) through the precision of the
11243 fraction (typically around 23 bits for @code{REAL(KIND=1)}, 52 for
11244 @code{REAL(KIND=2)}), then multiplying the sum by a integral
11245 power of two (in Fortran, by @samp{2**N}) that typically is between
11246 -127 and +128 for @code{REAL(KIND=1)} and -1023 and +1024 for
11247 @code{REAL(KIND=2)}, then multiplying by -1 if the number
11248 is negative.
11249
11250 So, a value like 0.2 is exactly represented in decimal---since
11251 it is a fraction, @samp{2/10}, with a denominator that is compatible
11252 with the base of the number system (base 10).
11253 However, @samp{2/10} cannot be represented by any finite number
11254 of sums of any of 1.0, 0.5, 0.25, and so on, so 0.2 cannot
11255 be exactly represented in binary notation.
11256
11257 (On the other hand, decimal notation can represent any binary
11258 number in a finite number of digits.
11259 Decimal notation cannot do so with ternary, or base-3,
11260 notation, which would represent floating-point numbers as
11261 sums of any of @samp{1/1}, @samp{1/3}, @samp{1/9}, and so on.
11262 After all, no finite number of decimal digits can exactly
11263 represent @samp{1/3}.
11264 Fortunately, few systems use ternary notation.)
11265
11266 Moreover, differences in the way run-time I/O libraries convert
11267 between these approximations and the decimal representation often
11268 used by programmers and the programs they write can result in
11269 apparent differences between results that do not actually exist,
11270 or exist to such a small degree that they usually are not worth
11271 worrying about.
11272
11273 For example, consider the following program:
11274
11275 @smallexample
11276 PRINT *, 0.2
11277 END
11278 @end smallexample
11279
11280 When compiled by @code{g77}, the above program might output
11281 @samp{0.20000003}, while another compiler might produce a
11282 executable that outputs @samp{0.2}.
11283
11284 This particular difference is due to the fact that, currently,
11285 conversion of floating-point values by the @code{libg2c} library,
11286 used by @code{g77}, handles only double-precision values.
11287
11288 Since @samp{0.2} in the program is a single-precision value, it
11289 is converted to double precision (still in binary notation)
11290 before being converted back to decimal.
11291 The conversion to binary appends @emph{binary} zero digits to the
11292 original value---which, again, is an inexact approximation of
11293 0.2---resulting in an approximation that is much less exact
11294 than is connoted by the use of double precision.
11295
11296 (The appending of binary zero digits has essentially the same
11297 effect as taking a particular decimal approximation of
11298 @samp{1/3}, such as @samp{0.3333333}, and appending decimal
11299 zeros to it, producing @samp{0.33333330000000000}.
11300 Treating the resulting decimal approximation as if it really
11301 had 18 or so digits of valid precision would make it seem
11302 a very poor approximation of @samp{1/3}.)
11303
11304 As a result of converting the single-precision approximation
11305 to double precision by appending binary zeros, the conversion
11306 of the resulting double-precision
11307 value to decimal produces what looks like an incorrect
11308 result, when in fact the result is @emph{inexact}, and
11309 is probably no less inaccurate or imprecise an approximation
11310 of 0.2 than is produced by other compilers that happen to output
11311 the converted value as ``exactly'' @samp{0.2}.
11312 (Some compilers behave in a way that can make them appear
11313 to retain more accuracy across a conversion of a single-precision
11314 constant to double precision.
11315 @xref{Context-Sensitive Constants}, to see why
11316 this practice is illusory and even dangerous.)
11317
11318 Note that a more exact approximation of the constant is
11319 computed when the program is changed to specify a
11320 double-precision constant:
11321
11322 @smallexample
11323 PRINT *, 0.2D0
11324 END
11325 @end smallexample
11326
11327 Future versions of @code{g77} and/or @code{libg2c} might convert
11328 single-precision values directly to decimal,
11329 instead of converting them to double precision first.
11330 This would tend to result in output that is more consistent
11331 with that produced by some other Fortran implementations.
11332
11333 A useful source of information on floating-point computation is David
11334 Goldberg, `What Every Computer Scientist Should Know About
11335 Floating-Point Arithmetic', Computing Surveys, 23, March 1991, pp.@:
11336 5-48.
11337 An online version is available at
11338 @uref{http://docs.sun.com/},
11339 and there is a supplemented version, in PostScript form, at
11340 @uref{http://www.validgh.com/goldberg/paper.ps}.
11341
11342 Information related to the IEEE 754
11343 floating-point standard by a leading light can be found at
11344 @uref{http://http.cs.berkeley.edu/%7Ewkahan/ieee754status/};
11345 see also slides from the short course referenced from
11346 @uref{http://http.cs.berkeley.edu/%7Efateman/}.
11347 @uref{http://www.linuxsupportline.com/%7Ebillm/} has a brief
11348 guide to IEEE 754, a somewhat x86-GNU/Linux-specific FAQ,
11349 and library code for GNU/Linux x86 systems.
11350
11351 The supplement to the PostScript-formatted Goldberg document,
11352 referenced above, is available in HTML format.
11353 See `Differences Among IEEE 754 Implementations' by Doug Priest,
11354 available online at
11355 @uref{http://www.validgh.com/goldberg/addendum.html}.
11356 This document explores some of the issues surrounding computing
11357 of extended (80-bit) results on processors such as the x86,
11358 especially when those results are arbitrarily truncated
11359 to 32-bit or 64-bit values by the compiler
11360 as ``spills''.
11361
11362 @cindex spills of floating-point results
11363 @cindex 80-bit spills
11364 @cindex truncation, of floating-point values
11365 (@emph{Note:} @code{g77} specifically, and @code{gcc} generally,
11366 does arbitrarily truncate 80-bit results during spills
11367 as of this writing.
11368 It is not yet clear whether a future version of
11369 the GNU compiler suite will offer 80-bit spills
11370 as an option, or perhaps even as the default behavior.)
11371
11372 @c xref would be different between editions:
11373 The GNU C library provides routines for controlling the FPU, and other
11374 documentation about this.
11375
11376 @xref{Floating-point precision}, regarding IEEE 754 conformance.
11377
11378 @include bugs.texi
11379
11380 @node Missing Features
11381 @section Missing Features
11382
11383 This section lists features we know are missing from @code{g77},
11384 and which we want to add someday.
11385 (There is no priority implied in the ordering below.)
11386
11387 @menu
11388 GNU Fortran language:
11389 * Better Source Model::
11390 * Fortran 90 Support::
11391 * Intrinsics in PARAMETER Statements::
11392 * Arbitrary Concatenation::
11393 * SELECT CASE on CHARACTER Type::
11394 * RECURSIVE Keyword::
11395 * Popular Non-standard Types::
11396 * Full Support for Compiler Types::
11397 * Array Bounds Expressions::
11398 * POINTER Statements::
11399 * Sensible Non-standard Constructs::
11400 * READONLY Keyword::
11401 * FLUSH Statement::
11402 * Expressions in FORMAT Statements::
11403 * Explicit Assembler Code::
11404 * Q Edit Descriptor::
11405
11406 GNU Fortran dialects:
11407 * Old-style PARAMETER Statements::
11408 * TYPE and ACCEPT I/O Statements::
11409 * STRUCTURE UNION RECORD MAP::
11410 * OPEN CLOSE and INQUIRE Keywords::
11411 * ENCODE and DECODE::
11412 * AUTOMATIC Statement::
11413 * Suppressing Space Padding::
11414 * Fortran Preprocessor::
11415 * Bit Operations on Floating-point Data::
11416 * Really Ugly Character Assignments::
11417
11418 New facilities:
11419 * POSIX Standard::
11420 * Floating-point Exception Handling::
11421 * Nonportable Conversions::
11422 * Large Automatic Arrays::
11423 * Support for Threads::
11424 * Increasing Precision/Range::
11425 * Enabling Debug Lines::
11426
11427 Better diagnostics:
11428 * Better Warnings::
11429 * Gracefully Handle Sensible Bad Code::
11430 * Non-standard Conversions::
11431 * Non-standard Intrinsics::
11432 * Modifying DO Variable::
11433 * Better Pedantic Compilation::
11434 * Warn About Implicit Conversions::
11435 * Invalid Use of Hollerith Constant::
11436 * Dummy Array Without Dimensioning Dummy::
11437 * Invalid FORMAT Specifiers::
11438 * Ambiguous Dialects::
11439 * Unused Labels::
11440 * Informational Messages::
11441
11442 Run-time facilities:
11443 * Uninitialized Variables at Run Time::
11444 * Portable Unformatted Files::
11445 * Better List-directed I/O::
11446 * Default to Console I/O::
11447
11448 Debugging:
11449 * Labels Visible to Debugger::
11450 @end menu
11451
11452 @node Better Source Model
11453 @subsection Better Source Model
11454
11455 @code{g77} needs to provide, as the default source-line model,
11456 a ``pure visual'' mode, where
11457 the interpretation of a source program in this mode can be accurately
11458 determined by a user looking at a traditionally displayed rendition
11459 of the program (assuming the user knows whether the program is fixed
11460 or free form).
11461
11462 The design should assume the user cannot tell tabs from spaces
11463 and cannot see trailing spaces on lines, but has canonical tab stops
11464 and, for fixed-form source, has the ability to always know exactly
11465 where column 72 is (since the Fortran standard itself requires
11466 this for fixed-form source).
11467
11468 This would change the default treatment of fixed-form source
11469 to not treat lines with tabs as if they were infinitely long---instead,
11470 they would end at column 72 just as if the tabs were replaced
11471 by spaces in the canonical way.
11472
11473 As part of this, provide common alternate models (Digital, @code{f2c},
11474 and so on) via command-line options.
11475 This includes allowing arbitrarily long
11476 lines for free-form source as well as fixed-form source and providing
11477 various limits and diagnostics as appropriate.
11478
11479 @cindex sequence numbers
11480 @cindex columns 73 through 80
11481 Also, @code{g77} should offer, perhaps even default to, warnings
11482 when characters beyond the last valid column are anything other
11483 than spaces.
11484 This would mean code with ``sequence numbers'' in columns 73 through 80
11485 would be rejected, and there's a lot of that kind of code around,
11486 but one of the most frequent bugs encountered by new users is
11487 accidentally writing fixed-form source code into and beyond
11488 column 73.
11489 So, maybe the users of old code would be able to more easily handle
11490 having to specify, say, a @samp{-Wno-col73to80} option.
11491
11492 @node Fortran 90 Support
11493 @subsection Fortran 90 Support
11494 @cindex Fortran 90, support
11495 @cindex support, Fortran 90
11496
11497 @code{g77} does not support many of the features that
11498 distinguish Fortran 90 (and, now, Fortran 95) from
11499 ANSI FORTRAN 77.
11500
11501 Some Fortran 90 features are supported, because they
11502 make sense to offer even to die-hard users of F77.
11503 For example, many of them codify various ways F77 has
11504 been extended to meet users' needs during its tenure,
11505 so @code{g77} might as well offer them as the primary
11506 way to meet those same needs, even if it offers compatibility
11507 with one or more of the ways those needs were met
11508 by other F77 compilers in the industry.
11509
11510 Still, many important F90 features are not supported,
11511 because no attempt has been made to research each and
11512 every feature and assess its viability in @code{g77}.
11513 In the meantime, users who need those features must
11514 use Fortran 90 compilers anyway, and the best approach
11515 to adding some F90 features to GNU Fortran might well be
11516 to fund a comprehensive project to create GNU Fortran 95.
11517
11518 @node Intrinsics in PARAMETER Statements
11519 @subsection Intrinsics in @code{PARAMETER} Statements
11520 @cindex PARAMETER statement
11521 @cindex statements, PARAMETER
11522
11523 @code{g77} doesn't allow intrinsics in @code{PARAMETER} statements.
11524 This feature is considered to be absolutely vital, even though it
11525 is not standard-conforming, and is scheduled for version 0.6.
11526
11527 Related to this, @code{g77} doesn't allow non-integral
11528 exponentiation in @code{PARAMETER} statements, such as
11529 @samp{PARAMETER (R=2**.25)}.
11530 It is unlikely @code{g77} will ever support this feature,
11531 as doing it properly requires complete emulation of
11532 a target computer's floating-point facilities when
11533 building @code{g77} as a cross-compiler.
11534 But, if the @code{gcc} back end is enhanced to provide
11535 such a facility, @code{g77} will likely use that facility
11536 in implementing this feature soon afterwards.
11537
11538 @node Arbitrary Concatenation
11539 @subsection Arbitrary Concatenation
11540 @cindex concatenation
11541 @cindex CHARACTER*(*)
11542 @cindex run-time, dynamic allocation
11543
11544 @code{g77} doesn't support arbitrary operands for concatenation
11545 in contexts where run-time allocation is required.
11546 For example:
11547
11548 @smallexample
11549 SUBROUTINE X(A)
11550 CHARACTER*(*) A
11551 CALL FOO(A // 'suffix')
11552 @end smallexample
11553
11554 @node SELECT CASE on CHARACTER Type
11555 @subsection @code{SELECT CASE} on @code{CHARACTER} Type
11556
11557 Character-type selector/cases for @code{SELECT CASE} currently
11558 are not supported.
11559
11560 @node RECURSIVE Keyword
11561 @subsection @code{RECURSIVE} Keyword
11562 @cindex RECURSIVE keyword
11563 @cindex keywords, RECURSIVE
11564 @cindex recursion, lack of
11565 @cindex lack of recursion
11566
11567 @code{g77} doesn't support the @code{RECURSIVE} keyword that
11568 F90 compilers do.
11569 Nor does it provide any means for compiling procedures
11570 designed to do recursion.
11571
11572 All recursive code can be rewritten to not use recursion,
11573 but the result is not pretty.
11574
11575 @node Increasing Precision/Range
11576 @subsection Increasing Precision/Range
11577 @cindex -r8
11578 @cindex -qrealsize=8
11579 @cindex -i8
11580 @cindex f2c
11581 @cindex increasing precision
11582 @cindex precision, increasing
11583 @cindex increasing range
11584 @cindex range, increasing
11585 @cindex Toolpack
11586 @cindex Netlib
11587
11588 Some compilers, such as @code{f2c}, have an option (@samp{-r8},
11589 @samp{-qrealsize=8} or
11590 similar) that provides automatic treatment of @code{REAL}
11591 entities such that they have twice the storage size, and
11592 a corresponding increase in the range and precision, of what
11593 would normally be the @code{REAL(KIND=1)} (default @code{REAL}) type.
11594 (This affects @code{COMPLEX} the same way.)
11595
11596 They also typically offer another option (@samp{-i8}) to increase
11597 @code{INTEGER} entities so they are twice as large
11598 (with roughly twice as much range).
11599
11600 (There are potential pitfalls in using these options.)
11601
11602 @code{g77} does not yet offer any option that performs these
11603 kinds of transformations.
11604 Part of the problem is the lack of detailed specifications regarding
11605 exactly how these options affect the interpretation of constants,
11606 intrinsics, and so on.
11607
11608 Until @code{g77} addresses this need, programmers could improve
11609 the portability of their code by modifying it to not require
11610 compile-time options to produce correct results.
11611 Some free tools are available which may help, specifically
11612 in Toolpack (which one would expect to be sound) and the @file{fortran}
11613 section of the Netlib repository.
11614
11615 Use of preprocessors can provide a fairly portable means
11616 to work around the lack of widely portable methods in the Fortran
11617 language itself (though increasing acceptance of Fortran 90 would
11618 alleviate this problem).
11619
11620 @node Popular Non-standard Types
11621 @subsection Popular Non-standard Types
11622 @cindex @code{INTEGER*2} support
11623 @cindex types, @code{INTEGER*2}
11624 @cindex @code{LOGICAL*1} support
11625 @cindex types, @code{LOGICAL*1}
11626
11627 @code{g77} doesn't fully support @code{INTEGER*2}, @code{LOGICAL*1},
11628 and similar.
11629 Version 0.6 will provide full support for this very
11630 popular set of features.
11631 In the meantime, version 0.5.18 provides rudimentary support
11632 for them.
11633
11634 @node Full Support for Compiler Types
11635 @subsection Full Support for Compiler Types
11636
11637 @cindex @code{REAL*16} support
11638 @cindex types, @code{REAL*16}
11639 @cindex @code{INTEGER*8} support
11640 @cindex types, @code{INTEGER*8}
11641 @code{g77} doesn't support @code{INTEGER}, @code{REAL}, and @code{COMPLEX} equivalents
11642 for @emph{all} applicable back-end-supported types (@code{char}, @code{short int},
11643 @code{int}, @code{long int}, @code{long long int}, and @code{long double}).
11644 This means providing intrinsic support, and maybe constant
11645 support (using F90 syntax) as well, and, for most
11646 machines will result in automatic support of @code{INTEGER*1},
11647 @code{INTEGER*2}, @code{INTEGER*8}, maybe even @code{REAL*16},
11648 and so on.
11649 This is scheduled for version 0.6.
11650
11651 @node Array Bounds Expressions
11652 @subsection Array Bounds Expressions
11653 @cindex array elements, in adjustable array bounds
11654 @cindex function references, in adjustable array bounds
11655 @cindex array bounds, adjustable
11656 @cindex @code{DIMENSION} statement
11657 @cindex statements, @code{DIMENSION}
11658
11659 @code{g77} doesn't support more general expressions to dimension
11660 arrays, such as array element references, function
11661 references, etc.
11662
11663 For example, @code{g77} currently does not accept the following:
11664
11665 @smallexample
11666 SUBROUTINE X(M, N)
11667 INTEGER N(10), M(N(2), N(1))
11668 @end smallexample
11669
11670 @node POINTER Statements
11671 @subsection POINTER Statements
11672 @cindex POINTER statement
11673 @cindex statements, POINTER
11674 @cindex Cray pointers
11675
11676 @code{g77} doesn't support pointers or allocatable objects
11677 (other than automatic arrays).
11678 This set of features is
11679 probably considered just behind intrinsics
11680 in @code{PARAMETER} statements on the list of large,
11681 important things to add to @code{g77}.
11682
11683 In the meantime, consider using the @code{INTEGER(KIND=7)}
11684 declaration to specify that a variable must be
11685 able to hold a pointer.
11686 This construct is not portable to other non-GNU compilers,
11687 but it is portable to all machines GNU Fortran supports
11688 when @code{g77} is used.
11689
11690 @xref{Functions and Subroutines}, for information on
11691 @code{%VAL()}, @code{%REF()}, and @code{%DESCR()}
11692 constructs, which are useful for passing pointers to
11693 procedures written in languages other than Fortran.
11694
11695 @node Sensible Non-standard Constructs
11696 @subsection Sensible Non-standard Constructs
11697
11698 @code{g77} rejects things other compilers accept,
11699 like @samp{INTRINSIC SQRT,SQRT}.
11700 As time permits in the future, some of these things that are easy for
11701 humans to read and write and unlikely to be intended to mean something
11702 else will be accepted by @code{g77} (though @samp{-fpedantic} should
11703 trigger warnings about such non-standard constructs).
11704
11705 Until @code{g77} no longer gratuitously rejects sensible code,
11706 you might as well fix your code
11707 to be more standard-conforming and portable.
11708
11709 The kind of case that is important to except from the
11710 recommendation to change your code is one where following
11711 good coding rules would force you to write non-standard
11712 code that nevertheless has a clear meaning.
11713
11714 For example, when writing an @code{INCLUDE} file that
11715 defines a common block, it might be appropriate to
11716 include a @code{SAVE} statement for the common block
11717 (such as @samp{SAVE /CBLOCK/}), so that variables
11718 defined in the common block retain their values even
11719 when all procedures declaring the common block become
11720 inactive (return to their callers).
11721
11722 However, putting @code{SAVE} statements in an @code{INCLUDE}
11723 file would prevent otherwise standard-conforming code
11724 from also specifying the @code{SAVE} statement, by itself,
11725 to indicate that all local variables and arrays are to
11726 have the @code{SAVE} attribute.
11727
11728 For this reason, @code{g77} already has been changed to
11729 allow this combination, because although the general
11730 problem of gratuitously rejecting unambiguous and
11731 ``safe'' constructs still exists in @code{g77}, this
11732 particular construct was deemed useful enough that
11733 it was worth fixing @code{g77} for just this case.
11734
11735 So, while there is no need to change your code
11736 to avoid using this particular construct, there
11737 might be other, equally appropriate but non-standard
11738 constructs, that you shouldn't have to stop using
11739 just because @code{g77} (or any other compiler)
11740 gratuitously rejects it.
11741
11742 Until the general problem is solved, if you have
11743 any such construct you believe is worthwhile
11744 using (e.g. not just an arbitrary, redundant
11745 specification of an attribute), please submit a
11746 bug report with an explanation, so we can consider
11747 fixing @code{g77} just for cases like yours.
11748
11749 @node READONLY Keyword
11750 @subsection @code{READONLY} Keyword
11751 @cindex READONLY
11752
11753 Support for @code{READONLY}, in @code{OPEN} statements,
11754 requires @code{libg2c} support,
11755 to make sure that @samp{CLOSE(@dots{},STATUS='DELETE')}
11756 does not delete a file opened on a unit
11757 with the @code{READONLY} keyword,
11758 and perhaps to trigger a fatal diagnostic
11759 if a @code{WRITE} or @code{PRINT}
11760 to such a unit is attempted.
11761
11762 @emph{Note:} It is not sufficient for @code{g77} and @code{libg2c}
11763 (its version of @code{libf2c})
11764 to assume that @code{READONLY} does not need some kind of explicit support
11765 at run time,
11766 due to UNIX systems not (generally) needing it.
11767 @code{g77} is not just a UNIX-based compiler!
11768
11769 Further, mounting of non-UNIX filesystems on UNIX systems
11770 (such as via NFS)
11771 might require proper @code{READONLY} support.
11772
11773 @cindex SHARED
11774 (Similar issues might be involved with supporting the @code{SHARED}
11775 keyword.)
11776
11777 @node FLUSH Statement
11778 @subsection @code{FLUSH} Statement
11779
11780 @code{g77} could perhaps use a @code{FLUSH} statement that
11781 does what @samp{CALL FLUSH} does,
11782 but that supports @samp{*} as the unit designator (same unit as for
11783 @code{PRINT}) and accepts @code{ERR=} and/or @code{IOSTAT=}
11784 specifiers.
11785
11786 @node Expressions in FORMAT Statements
11787 @subsection Expressions in @code{FORMAT} Statements
11788 @cindex FORMAT statement
11789 @cindex statements, FORMAT
11790
11791 @code{g77} doesn't support @samp{FORMAT(I<J>)} and the like.
11792 Supporting this requires a significant redesign or replacement
11793 of @code{libg2c}.
11794
11795 However, @code{g77} does support
11796 this construct when the expression is constant
11797 (as of version 0.5.22).
11798 For example:
11799
11800 @smallexample
11801       PARAMETER (IWIDTH = 12)
11802 10    FORMAT (I<IWIDTH>)
11803 @end smallexample
11804
11805 Otherwise, at least for output (@code{PRINT} and
11806 @code{WRITE}), Fortran code making use of this feature can
11807 be rewritten to avoid it by constructing the @code{FORMAT}
11808 string in a @code{CHARACTER} variable or array, then
11809 using that variable or array in place of the @code{FORMAT}
11810 statement label to do the original @code{PRINT} or @code{WRITE}.
11811
11812 Many uses of this feature on input can be rewritten this way
11813 as well, but not all can.
11814 For example, this can be rewritten:
11815
11816 @smallexample
11817       READ 20, I
11818 20    FORMAT (I<J>)
11819 @end smallexample
11820
11821 However, this cannot, in general, be rewritten, especially
11822 when @code{ERR=} and @code{END=} constructs are employed:
11823
11824 @smallexample
11825       READ 30, J, I
11826 30    FORMAT (I<J>)
11827 @end smallexample
11828
11829 @node Explicit Assembler Code
11830 @subsection Explicit Assembler Code
11831
11832 @code{g77} needs to provide some way, a la @code{gcc}, for @code{g77}
11833 code to specify explicit assembler code.
11834
11835 @node Q Edit Descriptor
11836 @subsection Q Edit Descriptor
11837 @cindex FORMAT statement
11838 @cindex Q edit descriptor
11839 @cindex edit descriptor, Q
11840
11841 The @code{Q} edit descriptor in @code{FORMAT}s isn't supported.
11842 (This is meant to get the number of characters remaining in an input record.)
11843 Supporting this requires a significant redesign or replacement
11844 of @code{libg2c}.
11845
11846 A workaround might be using internal I/O or the stream-based intrinsics.
11847 @xref{FGetC Intrinsic (subroutine)}.
11848
11849 @node Old-style PARAMETER Statements
11850 @subsection Old-style PARAMETER Statements
11851 @cindex PARAMETER statement
11852 @cindex statements, PARAMETER
11853
11854 @code{g77} doesn't accept @samp{PARAMETER I=1}.
11855 Supporting this obsolete form of
11856 the @code{PARAMETER} statement would not be particularly hard, as most of the
11857 parsing code is already in place and working.
11858
11859 Until time/money is
11860 spent implementing it, you might as well fix your code to use the
11861 standard form, @samp{PARAMETER (I=1)} (possibly needing
11862 @samp{INTEGER I} preceding the @code{PARAMETER} statement as well,
11863 otherwise, in the obsolete form of @code{PARAMETER}, the
11864 type of the variable is set from the type of the constant being
11865 assigned to it).
11866
11867 @node TYPE and ACCEPT I/O Statements
11868 @subsection @code{TYPE} and @code{ACCEPT} I/O Statements
11869 @cindex TYPE statement
11870 @cindex statements, TYPE
11871 @cindex ACCEPT statement
11872 @cindex statements, ACCEPT
11873
11874 @code{g77} doesn't support the I/O statements @code{TYPE} and
11875 @code{ACCEPT}.
11876 These are common extensions that should be easy to support,
11877 but also are fairly easy to work around in user code.
11878
11879 Generally, any @samp{TYPE fmt,list} I/O statement can be replaced
11880 by @samp{PRINT fmt,list}.
11881 And, any @samp{ACCEPT fmt,list} statement can be
11882 replaced by @samp{READ fmt,list}.
11883
11884 @node STRUCTURE UNION RECORD MAP
11885 @subsection @code{STRUCTURE}, @code{UNION}, @code{RECORD}, @code{MAP}
11886 @cindex STRUCTURE statement
11887 @cindex statements, STRUCTURE
11888 @cindex UNION statement
11889 @cindex statements, UNION
11890 @cindex RECORD statement
11891 @cindex statements, RECORD
11892 @cindex MAP statement
11893 @cindex statements, MAP
11894
11895 @code{g77} doesn't support @code{STRUCTURE}, @code{UNION}, @code{RECORD},
11896 @code{MAP}.
11897 This set of extensions is quite a bit
11898 lower on the list of large, important things to add to @code{g77}, partly
11899 because it requires a great deal of work either upgrading or
11900 replacing @code{libg2c}.
11901
11902 @node OPEN CLOSE and INQUIRE Keywords
11903 @subsection @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} Keywords
11904 @cindex disposition of files
11905 @cindex OPEN statement
11906 @cindex statements, OPEN
11907 @cindex CLOSE statement
11908 @cindex statements, CLOSE
11909 @cindex INQUIRE statement
11910 @cindex statements, INQUIRE
11911
11912 @code{g77} doesn't have support for keywords such as @code{DISP='DELETE'} in
11913 the @code{OPEN}, @code{CLOSE}, and @code{INQUIRE} statements.
11914 These extensions are easy to add to @code{g77} itself, but
11915 require much more work on @code{libg2c}.
11916
11917 @cindex FORM='PRINT'
11918 @cindex ANS carriage control
11919 @cindex carriage control
11920 @pindex asa
11921 @pindex fpr
11922 @code{g77} doesn't support @code{FORM='PRINT'} or an equivalent to
11923 translate the traditional `carriage control' characters in column 1 of
11924 output to use backspaces, carriage returns and the like.  However
11925 programs exist to translate them in output files (or standard output).
11926 These are typically called either @code{fpr} or @code{asa}.  You can get
11927 a version of @code{asa} from
11928 @uref{ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran} for GNU
11929 systems which will probably build easily on other systems.
11930 Alternatively, @code{fpr} is in BSD distributions in various archive
11931 sites.
11932
11933 @c (Can both programs can be used in a pipeline,
11934 @c with a named input file,
11935 @c and/or with a named output file???)
11936
11937 @node ENCODE and DECODE
11938 @subsection @code{ENCODE} and @code{DECODE}
11939 @cindex ENCODE statement
11940 @cindex statements, ENCODE
11941 @cindex DECODE statement
11942 @cindex statements, DECODE
11943
11944 @code{g77} doesn't support @code{ENCODE} or @code{DECODE}.
11945
11946 These statements are best replaced by READ and WRITE statements
11947 involving internal files (CHARACTER variables and arrays).
11948
11949 For example, replace a code fragment like
11950
11951 @smallexample
11952       INTEGER*1 LINE(80)
11953 @dots{}
11954       DECODE (80, 9000, LINE) A, B, C
11955 @dots{}
11956 9000  FORMAT (1X, 3(F10.5))
11957 @end smallexample
11958
11959 @noindent
11960 with:
11961
11962 @smallexample
11963       CHARACTER*80 LINE
11964 @dots{}
11965       READ (UNIT=LINE, FMT=9000) A, B, C
11966 @dots{}
11967 9000  FORMAT (1X, 3(F10.5))
11968 @end smallexample
11969
11970 Similarly, replace a code fragment like
11971
11972 @smallexample
11973       INTEGER*1 LINE(80)
11974 @dots{}
11975       ENCODE (80, 9000, LINE) A, B, C
11976 @dots{}
11977 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11978 @end smallexample
11979
11980 @noindent
11981 with:
11982
11983 @smallexample
11984       CHARACTER*80 LINE
11985 @dots{}
11986       WRITE (UNIT=LINE, FMT=9000) A, B, C
11987 @dots{}
11988 9000  FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
11989 @end smallexample
11990
11991 It is entirely possible that @code{ENCODE} and @code{DECODE} will
11992 be supported by a future version of @code{g77}.
11993
11994 @node AUTOMATIC Statement
11995 @subsection @code{AUTOMATIC} Statement
11996 @cindex @code{AUTOMATIC} statement
11997 @cindex statements, @code{AUTOMATIC}
11998 @cindex automatic variables
11999 @cindex variables, automatic
12000
12001 @code{g77} doesn't support the @code{AUTOMATIC} statement that
12002 @code{f2c} does.
12003
12004 @code{AUTOMATIC} would identify a variable or array
12005 as not being @code{SAVE}'d, which is normally the default,
12006 but which would be especially useful for code that, @emph{generally},
12007 needed to be compiled with the @samp{-fno-automatic} option.
12008
12009 @code{AUTOMATIC} also would serve as a hint to the compiler that placing
12010 the variable or array---even a very large array--on the stack is acceptable.
12011
12012 @code{AUTOMATIC} would not, by itself, designate the containing procedure
12013 as recursive.
12014
12015 @code{AUTOMATIC} should work syntactically like @code{SAVE},
12016 in that @code{AUTOMATIC} with no variables listed should apply to
12017 all pertinent variables and arrays
12018 (which would not include common blocks or their members).
12019
12020 Variables and arrays denoted as @code{AUTOMATIC}
12021 would not be permitted to be initialized via @code{DATA}
12022 or other specification of any initial values,
12023 requiring explicit initialization,
12024 such as via assignment statements.
12025
12026 @cindex UNSAVE
12027 @cindex STATIC
12028 Perhaps @code{UNSAVE} and @code{STATIC},
12029 as strict semantic opposites to @code{SAVE} and @code{AUTOMATIC},
12030 should be provided as well.
12031
12032 @node Suppressing Space Padding
12033 @subsection Suppressing Space Padding of Source Lines
12034
12035 @code{g77} should offer VXT-Fortran-style suppression of virtual
12036 spaces at the end of a source line
12037 if an appropriate command-line option is specified.
12038
12039 This affects cases where
12040 a character constant is continued onto the next line in a fixed-form
12041 source file, as in the following example:
12042
12043 @smallexample
12044 10    PRINT *,'HOW MANY
12045      1 SPACES?'
12046 @end smallexample
12047
12048 @noindent
12049 @code{g77}, and many other compilers, virtually extend
12050 the continued line through column 72 with spaces that become part
12051 of the character constant, but Digital Fortran normally didn't,
12052 leaving only one space between @samp{MANY} and @samp{SPACES?}
12053 in the output of the above statement.
12054
12055 Fairly recently, at least one version of Digital Fortran
12056 was enhanced to provide the other behavior when a
12057 command-line option is specified, apparently due to demand
12058 from readers of the USENET group @file{comp.lang.fortran}
12059 to offer conformance to this widespread practice in the
12060 industry.
12061 @code{g77} should return the favor by offering conformance
12062 to Digital's approach to handling the above example.
12063
12064 @node Fortran Preprocessor
12065 @subsection Fortran Preprocessor
12066
12067 @code{g77} should offer a preprocessor designed specifically
12068 for Fortran to replace @samp{cpp -traditional}.
12069 There are several out there worth evaluating, at least.
12070
12071 Such a preprocessor would recognize Hollerith constants,
12072 properly parse comments and character constants, and so on.
12073 It might also recognize, process, and thus preprocess
12074 files included via the @code{INCLUDE} directive.
12075
12076 @node Bit Operations on Floating-point Data
12077 @subsection Bit Operations on Floating-point Data
12078 @cindex @code{And} intrinsic
12079 @cindex intrinsics, @code{And}
12080 @cindex @code{Or} intrinsic
12081 @cindex intrinsics, @code{Or}
12082 @cindex @code{Shift} intrinsic
12083 @cindex intrinsics, @code{Shift}
12084
12085 @code{g77} does not allow @code{REAL} and other non-integral types for
12086 arguments to intrinsics like @code{And}, @code{Or}, and @code{Shift}.
12087
12088 For example, this program is rejected by @code{g77}, because
12089 the intrinsic @code{Iand} does not accept @code{REAL} arguments:
12090
12091 @smallexample
12092 DATA A/7.54/, B/9.112/
12093 PRINT *, IAND(A, B)
12094 END
12095 @end smallexample
12096
12097 @node Really Ugly Character Assignments
12098 @subsection Really Ugly Character Assignments
12099
12100 An option such as @samp{-fugly-char} should be provided
12101 to allow
12102
12103 @smallexample
12104 REAL*8 A1
12105 DATA A1 / '12345678' /
12106 @end smallexample
12107
12108 and:
12109
12110 @smallexample
12111 REAL*8 A1
12112 A1 = 'ABCDEFGH'
12113 @end smallexample
12114
12115 @node POSIX Standard
12116 @subsection @code{POSIX} Standard
12117
12118 @code{g77} should support the POSIX standard for Fortran.
12119
12120 @node Floating-point Exception Handling
12121 @subsection Floating-point Exception Handling
12122 @cindex floating-point, exceptions
12123 @cindex exceptions, floating-point
12124 @cindex FPE handling
12125 @cindex NaN values
12126
12127 The @code{gcc} backend and, consequently, @code{g77}, currently provides no
12128 general control over whether or not floating-point exceptions are trapped or
12129 ignored.
12130 (Ignoring them typically results in NaN values being
12131 propagated in systems that conform to IEEE 754.)
12132 The behaviour is normally inherited from the system-dependent startup
12133 code, though some targets, such as the Alpha, have code generation
12134 options which change the behaviour.
12135
12136 Most systems provide some C-callable mechanism to change this; this can
12137 be invoked at startup using @code{gcc}'s @code{constructor} attribute.
12138 For example, just compiling and linking the following C code with your
12139 program will turn on exception trapping for the ``common'' exceptions
12140 on an x86-based GNU system:
12141
12142 @smallexample
12143 #include <fpu_control.h>
12144 static void __attribute__ ((constructor))
12145 trapfpe ()
12146 @{
12147   __setfpucw (_FPU_DEFAULT &
12148               ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM));
12149 @}
12150 @end smallexample
12151
12152 A convenient trick is to compile this something like:
12153 @smallexample
12154 gcc -o libtrapfpe.a trapfpe.c
12155 @end smallexample
12156 and then use it by adding @samp{-trapfpe} to the @code{g77} command line
12157 when linking.
12158
12159 @node Nonportable Conversions
12160 @subsection Nonportable Conversions
12161 @cindex nonportable conversions
12162 @cindex conversions, nonportable
12163
12164 @code{g77} doesn't accept some particularly nonportable,
12165 silent data-type conversions such as @code{LOGICAL}
12166 to @code{REAL} (as in @samp{A=.FALSE.}, where @samp{A}
12167 is type @code{REAL}), that other compilers might
12168 quietly accept.
12169
12170 Some of these conversions are accepted by @code{g77}
12171 when the @samp{-fugly-logint} option is specified.
12172 Perhaps it should accept more or all of them.
12173
12174 @node Large Automatic Arrays
12175 @subsection Large Automatic Arrays
12176 @cindex automatic arrays
12177 @cindex arrays, automatic
12178
12179 Currently, automatic arrays always are allocated on the stack.
12180 For situations where the stack cannot be made large enough,
12181 @code{g77} should offer a compiler option that specifies
12182 allocation of automatic arrays in heap storage.
12183
12184 @node Support for Threads
12185 @subsection Support for Threads
12186 @cindex threads
12187 @cindex parallel processing
12188
12189 Neither the code produced by @code{g77} nor the @code{libg2c} library
12190 are thread-safe, nor does @code{g77} have support for parallel processing
12191 (other than the instruction-level parallelism available on some
12192 processors).
12193 A package such as PVM might help here.
12194
12195 @node Enabling Debug Lines
12196 @subsection Enabling Debug Lines
12197 @cindex debug line
12198 @cindex comment line, debug
12199
12200 An option such as @samp{-fdebug-lines} should be provided
12201 to turn fixed-form lines beginning with @samp{D}
12202 to be treated as if they began with a space,
12203 instead of as if they began with a @samp{C}
12204 (as comment lines).
12205
12206 @node Better Warnings
12207 @subsection Better Warnings
12208
12209 Because of how @code{g77} generates code via the back end,
12210 it doesn't always provide warnings the user wants.
12211 Consider:
12212
12213 @smallexample
12214 PROGRAM X
12215 PRINT *, A
12216 END
12217 @end smallexample
12218
12219 Currently, the above is not flagged as a case of
12220 using an uninitialized variable,
12221 because @code{g77} generates a run-time library call that looks,
12222 to the GBE, like it might actually @emph{modify} @samp{A} at run time.
12223 (And, in fact, depending on the previous run-time library call,
12224 it would!)
12225
12226 Fixing this requires one of the following:
12227
12228 @itemize @bullet
12229 @item
12230 Switch to new library, @code{libg77}, that provides
12231 a more ``clean'' interface,
12232 vis-a-vis input, output, and modified arguments,
12233 so the GBE can tell what's going on.
12234
12235 This would provide a pretty big performance improvement,
12236 at least theoretically, and, ultimately, in practice,
12237 for some types of code.
12238
12239 @item
12240 Have @code{g77} pass a pointer to a temporary
12241 containing a copy of @samp{A},
12242 instead of to @samp{A} itself.
12243 The GBE would then complain about the copy operation
12244 involving a potentially uninitialized variable.
12245
12246 This might also provide a performance boost for some code,
12247 because @samp{A} might then end up living in a register,
12248 which could help with inner loops.
12249
12250 @item
12251 Have @code{g77} use a GBE construct similar to @code{ADDR_EXPR}
12252 but with extra information on the fact that the
12253 item pointed to won't be modified
12254 (a la @code{const} in C).
12255
12256 Probably the best solution for now, but not quite trivial
12257 to implement in the general case.
12258 Worth considering after @code{g77} 0.6 is considered
12259 pretty solid.
12260 @end itemize
12261
12262 @node Gracefully Handle Sensible Bad Code
12263 @subsection Gracefully Handle Sensible Bad Code
12264
12265 @code{g77} generally should continue processing for
12266 warnings and recoverable (user) errors whenever possible---that
12267 is, it shouldn't gratuitously make bad or useless code.
12268
12269 For example:
12270
12271 @smallexample
12272 INTRINSIC ZABS
12273 CALL FOO(ZABS)
12274 END
12275 @end smallexample
12276
12277 @noindent
12278 When compiling the above with @samp{-ff2c-intrinsics-disable},
12279 @code{g77} should indeed complain about passing @code{ZABS},
12280 but it still should compile, instead of rejecting
12281 the entire @code{CALL} statement.
12282 (Some of this is related to improving
12283 the compiler internals to improve how statements are analyzed.)
12284
12285 @node Non-standard Conversions
12286 @subsection Non-standard Conversions
12287
12288 @samp{-Wconversion} and related should flag places where non-standard
12289 conversions are found.
12290 Perhaps much of this would be part of @samp{-Wugly*}.
12291
12292 @node Non-standard Intrinsics
12293 @subsection Non-standard Intrinsics
12294
12295 @code{g77} needs a new option, like @samp{-Wintrinsics}, to warn about use of
12296 non-standard intrinsics without explicit @code{INTRINSIC} statements for them.
12297 This would help find code that might fail silently when ported to another
12298 compiler.
12299
12300 @node Modifying DO Variable
12301 @subsection Modifying @code{DO} Variable
12302
12303 @code{g77} should warn about modifying @code{DO} variables
12304 via @code{EQUIVALENCE}.
12305 (The internal information gathered to produce this warning
12306 might also be useful in setting the
12307 internal ``doiter'' flag for a variable or even array
12308 reference within a loop, since that might produce faster code someday.)
12309
12310 For example, this code is invalid, so @code{g77} should warn about
12311 the invalid assignment to @samp{NOTHER}:
12312
12313 @smallexample
12314 EQUIVALENCE (I, NOTHER)
12315 DO I = 1, 100
12316    IF (I.EQ. 10) NOTHER = 20
12317 END DO
12318 @end smallexample
12319
12320 @node Better Pedantic Compilation
12321 @subsection Better Pedantic Compilation
12322
12323 @code{g77} needs to support @samp{-fpedantic} more thoroughly,
12324 and use it only to generate
12325 warnings instead of rejecting constructs outright.
12326 Have it warn:
12327 if a variable that dimensions an array is not a dummy or placed
12328 explicitly in @code{COMMON} (F77 does not allow it to be
12329 placed in @code{COMMON} via @code{EQUIVALENCE}); if specification statements
12330 follow statement-function-definition statements; about all sorts of
12331 syntactic extensions.
12332
12333 @node Warn About Implicit Conversions
12334 @subsection Warn About Implicit Conversions
12335
12336 @code{g77} needs a @samp{-Wpromotions} option to warn if source code appears
12337 to expect automatic, silent, and
12338 somewhat dangerous compiler-assisted conversion of @code{REAL(KIND=1)}
12339 constants to @code{REAL(KIND=2)} based on context.
12340
12341 For example, it would warn about cases like this:
12342
12343 @smallexample
12344 DOUBLE PRECISION FOO
12345 PARAMETER (TZPHI = 9.435784839284958)
12346 FOO = TZPHI * 3D0
12347 @end smallexample
12348
12349 @node Invalid Use of Hollerith Constant
12350 @subsection Invalid Use of Hollerith Constant
12351
12352 @code{g77} should disallow statements like @samp{RETURN 2HAB},
12353 which are invalid in both source forms
12354 (unlike @samp{RETURN (2HAB)},
12355 which probably still makes no sense but at least can
12356 be reliably parsed).
12357 Fixed-form processing rejects it, but not free-form, except
12358 in a way that is a bit difficult to understand.
12359
12360 @node Dummy Array Without Dimensioning Dummy
12361 @subsection Dummy Array Without Dimensioning Dummy
12362
12363 @code{g77} should complain when a list of dummy arguments containing an
12364 adjustable dummy array does
12365 not also contain every variable listed in the dimension list of the
12366 adjustable array.
12367
12368 Currently, @code{g77} does complain about a variable that
12369 dimensions an array but doesn't appear in any dummy list or @code{COMMON}
12370 area, but this needs to be extended to catch cases where it doesn't appear in
12371 every dummy list that also lists any arrays it dimensions.
12372
12373 For example, @code{g77} should warn about the entry point @samp{ALT}
12374 below, since it includes @samp{ARRAY} but not @samp{ISIZE} in its
12375 list of arguments:
12376
12377 @smallexample
12378 SUBROUTINE PRIMARY(ARRAY, ISIZE)
12379 REAL ARRAY(ISIZE)
12380 ENTRY ALT(ARRAY)
12381 @end smallexample
12382
12383 @node Invalid FORMAT Specifiers
12384 @subsection Invalid FORMAT Specifiers
12385
12386 @code{g77} should check @code{FORMAT} specifiers for validity
12387 as it does @code{FORMAT} statements.
12388
12389 For example, a diagnostic would be produced for:
12390
12391 @smallexample
12392 PRINT 'HI THERE!'  !User meant PRINT *, 'HI THERE!'
12393 @end smallexample
12394
12395 @node Ambiguous Dialects
12396 @subsection Ambiguous Dialects
12397
12398 @code{g77} needs a set of options such as @samp{-Wugly*}, @samp{-Wautomatic},
12399 @samp{-Wvxt}, @samp{-Wf90}, and so on.
12400 These would warn about places in the user's source where ambiguities
12401 are found, helpful in resolving ambiguities in the program's
12402 dialect or dialects.
12403
12404 @node Unused Labels
12405 @subsection Unused Labels
12406
12407 @code{g77} should warn about unused labels when @samp{-Wunused} is in effect.
12408
12409 @node Informational Messages
12410 @subsection Informational Messages
12411
12412 @code{g77} needs an option to suppress information messages (notes).
12413 @samp{-w} does this but also suppresses warnings.
12414 The default should be to suppress info messages.
12415
12416 Perhaps info messages should simply be eliminated.
12417
12418 @node Uninitialized Variables at Run Time
12419 @subsection Uninitialized Variables at Run Time
12420
12421 @code{g77} needs an option to initialize everything (not otherwise
12422 explicitly initialized) to ``weird''
12423 (machine-dependent) values, e.g. NaNs, bad (non-@code{NULL}) pointers, and
12424 largest-magnitude integers, would help track down references to
12425 some kinds of uninitialized variables at run time.
12426
12427 Note that use of the options @samp{-O -Wuninitialized} can catch
12428 many such bugs at compile time.
12429
12430 @node Portable Unformatted Files
12431 @subsection Portable Unformatted Files
12432
12433 @cindex unformatted files
12434 @cindex file formats
12435 @cindex binary data
12436 @cindex byte ordering
12437 @code{g77} has no facility for exchanging unformatted files with systems
12438 using different number formats---even differing only in endianness (byte
12439 order)---or written by other compilers.  Some compilers provide
12440 facilities at least for doing byte-swapping during unformatted I/O.
12441
12442 It is unrealistic to expect to cope with exchanging unformatted files
12443 with arbitrary other compiler runtimes, but the @code{g77} runtime
12444 should at least be able to read files written by @code{g77} on systems
12445 with different number formats, particularly if they differ only in byte
12446 order.
12447
12448 In case you do need to write a program to translate to or from
12449 @code{g77} (@code{libf2c}) unformatted files, they are written as
12450 follows:
12451 @table @asis
12452 @item Sequential
12453 Unformatted sequential records consist of
12454 @enumerate
12455 @item
12456 A number giving the length of the record contents;
12457 @item
12458 the length of record contents again (for backspace).
12459 @end enumerate
12460
12461 The record length is of C type
12462 @code{long}; this means that it is 8 bytes on 64-bit systems such as
12463 Alpha GNU/Linux and 4 bytes on other systems, such as x86 GNU/Linux.
12464 Consequently such files cannot be exchanged between 64-bit and 32-bit
12465 systems, even with the same basic number format.
12466 @item Direct access
12467 Unformatted direct access files form a byte stream of length
12468 @var{records}*@var{recl} bytes, where @var{records} is the maximum
12469 record number (@code{REC=@var{records}}) written and @var{recl} is the
12470 record length in bytes specified in the @code{OPEN} statement
12471 (@code{RECL=@var{recl}}).  Data appear in the records as determined by
12472 the relevant @code{WRITE} statement.  Dummy records with arbitrary
12473 contents appear in the file in place of records which haven't been
12474 written.
12475 @end table
12476
12477 Thus for exchanging a sequential or direct access unformatted file
12478 between big- and little-endian 32-bit systems using IEEE 754 floating
12479 point it would be sufficient to reverse the bytes in consecutive words
12480 in the file if, and @emph{only} if, only @code{REAL*4}, @code{COMPLEX},
12481 @code{INTEGER*4} and/or @code{LOGICAL*4} data have been written to it by
12482 @code{g77}.
12483
12484 If necessary, it is possible to do byte-oriented i/o with @code{g77}'s
12485 @code{FGETC} and @code{FPUTC} intrinsics.  Byte-swapping can be done in
12486 Fortran by equivalencing larger sized variables to an @code{INTEGER*1}
12487 array or a set of scalars.
12488
12489 @cindex HDF
12490 @cindex PDB
12491 If you need to exchange binary data between arbitrary system and
12492 compiler variations, we recommend using a portable binary format with
12493 Fortran bindings, such as NCSA's HDF (@uref{http://hdf.ncsa.uiuc.edu/})
12494 or PACT's PDB@footnote{No, not @emph{that} one.}
12495 (@uref{http://www.llnl.gov/def_sci/pact/pact_homepage.html}).  (Unlike,
12496 say, CDF or XDR, HDF-like systems write in the native number formats and
12497 only incur overhead when they are read on a system with a different
12498 format.)  A future @code{g77} runtime library should use such
12499 techniques.
12500
12501 @node Better List-directed I/O
12502 @subsection Better List-directed I/O
12503
12504 Values output using list-directed I/O
12505 (@samp{PRINT *, R, D})
12506 should be written with a field width, precision, and so on
12507 appropriate for the type (precision) of each value.
12508
12509 (Currently, no distinction is made between single-precision
12510 and double-precision values
12511 by @code{libf2c}.)
12512
12513 It is likely this item will require the @code{libg77} project
12514 to be undertaken.
12515
12516 In the meantime, use of formatted I/O is recommended.
12517 While it might be of little consolation,
12518 @code{g77} does support @samp{FORMAT(F<WIDTH>.4)}, for example,
12519 as long as @samp{WIDTH} is defined as a named constant
12520 (via @code{PARAMETER}).
12521 That at least allows some compile-time specification
12522 of the precision of a data type,
12523 perhaps controlled by preprocessing directives.
12524
12525 @node Default to Console I/O
12526 @subsection Default to Console I/O
12527
12528 The default I/O units,
12529 specified by @samp{READ @var{fmt}},
12530 @samp{READ (UNIT=*)},
12531 @samp{WRITE (UNIT=*)}, and
12532 @samp{PRINT @var{fmt}},
12533 should not be units 5 (input) and 6 (output),
12534 but, rather, unit numbers not normally available
12535 for use in statements such as @code{OPEN} and @code{CLOSE}.
12536
12537 Changing this would allow a program to connect units 5 and 6
12538 to files via @code{OPEN},
12539 but still use @samp{READ (UNIT=*)} and @samp{PRINT}
12540 to do I/O to the ``console''.
12541
12542 This change probably requires the @code{libg77} project.
12543
12544 @node Labels Visible to Debugger
12545 @subsection Labels Visible to Debugger
12546
12547 @code{g77} should output debugging information for statements labels,
12548 for use by debuggers that know how to support them.
12549 Same with weirder things like construct names.
12550 It is not yet known if any debug formats or debuggers support these.
12551
12552 @node Disappointments
12553 @section Disappointments and Misunderstandings
12554
12555 These problems are perhaps regrettable, but we don't know any practical
12556 way around them for now.
12557
12558 @menu
12559 * Mangling of Names::                       @samp{SUBROUTINE FOO} is given
12560                                               external name @samp{foo_}.
12561 * Multiple Definitions of External Names::  No doing both @samp{COMMON /FOO/}
12562                                               and @samp{SUBROUTINE FOO}.
12563 * Limitation on Implicit Declarations::     No @samp{IMPLICIT CHARACTER*(*)}.
12564 @end menu
12565
12566 @node Mangling of Names
12567 @subsection Mangling of Names in Source Code
12568 @cindex naming issues
12569 @cindex external names
12570 @cindex common blocks
12571 @cindex name space
12572 @cindex underscore
12573
12574 The current external-interface design, which includes naming of
12575 external procedures, COMMON blocks, and the library interface,
12576 has various usability problems, including things like adding
12577 underscores where not really necessary (and preventing easier
12578 inter-language operability) and yet not providing complete
12579 namespace freedom for user C code linked with Fortran apps (due
12580 to the naming of functions in the library, among other things).
12581
12582 Project GNU should at least get all this ``right'' for systems
12583 it fully controls, such as the Hurd, and provide defaults and
12584 options for compatibility with existing systems and interoperability
12585 with popular existing compilers.
12586
12587 @node Multiple Definitions of External Names
12588 @subsection Multiple Definitions of External Names
12589 @cindex block data
12590 @cindex BLOCK DATA statement
12591 @cindex statements, BLOCK DATA
12592 @cindex @code{COMMON} statement
12593 @cindex statements, @code{COMMON}
12594 @cindex naming conflicts
12595
12596 @code{g77} doesn't allow a common block and an external procedure or
12597 @code{BLOCK DATA} to have the same name.
12598 Some systems allow this, but @code{g77} does not,
12599 to be compatible with @code{f2c}.
12600
12601 @code{g77} could special-case the way it handles
12602 @code{BLOCK DATA}, since it is not compatible with @code{f2c} in this
12603 particular area (necessarily, since @code{g77} offers an
12604 important feature here), but
12605 it is likely that such special-casing would be very annoying to people
12606 with programs that use @samp{EXTERNAL FOO}, with no other mention of
12607 @samp{FOO} in the same program unit, to refer to external procedures, since
12608 the result would be that @code{g77} would treat these references as requests to
12609 force-load BLOCK DATA program units.
12610
12611 In that case, if @code{g77} modified
12612 names of @code{BLOCK DATA} so they could have the same names as
12613 @code{COMMON}, users
12614 would find that their programs wouldn't link because the @samp{FOO} procedure
12615 didn't have its name translated the same way.
12616
12617 (Strictly speaking,
12618 @code{g77} could emit a null-but-externally-satisfying definition of
12619 @samp{FOO} with its name transformed as if it had been a
12620 @code{BLOCK DATA}, but that probably invites more trouble than it's
12621 worth.)
12622
12623 @node Limitation on Implicit Declarations
12624 @subsection Limitation on Implicit Declarations
12625 @cindex IMPLICIT CHARACTER*(*) statement
12626 @cindex statements, IMPLICIT CHARACTER*(*)
12627
12628 @code{g77} disallows @code{IMPLICIT CHARACTER*(*)}.
12629 This is not standard-conforming.
12630
12631 @node Non-bugs
12632 @section Certain Changes We Don't Want to Make
12633
12634 This section lists changes that people frequently request, but which
12635 we do not make because we think GNU Fortran is better without them.
12636
12637 @menu
12638 * Backslash in Constants::           Why @samp{'\\'} is a constant that
12639                                        is one, not two, characters long.
12640 * Initializing Before Specifying::   Why @samp{DATA VAR/1/} can't precede
12641                                        @samp{COMMON VAR}.
12642 * Context-Sensitive Intrinsicness::  Why @samp{CALL SQRT} won't work.
12643 * Context-Sensitive Constants::      Why @samp{9.435784839284958} is a
12644                                        single-precision constant,
12645                                        and might be interpreted as
12646                                        @samp{9.435785} or similar.
12647 * Equivalence Versus Equality::      Why @samp{.TRUE. .EQ. .TRUE.} won't work.
12648 * Order of Side Effects::            Why @samp{J = IFUNC() - IFUNC()} might
12649                                        not behave as expected.
12650 @end menu
12651
12652 @node Backslash in Constants
12653 @subsection Backslash in Constants
12654 @cindex backslash
12655 @cindex @code{f77} support
12656 @cindex support, @code{f77}
12657
12658 In the opinion of many experienced Fortran users,
12659 @samp{-fno-backslash} should be the default, not @samp{-fbackslash},
12660 as currently set by @code{g77}.
12661
12662 First of all, you can always specify
12663 @samp{-fno-backslash} to turn off this processing.
12664
12665 Despite not being within the spirit (though apparently within the
12666 letter) of the ANSI FORTRAN 77 standard, @code{g77} defaults to
12667 @samp{-fbackslash} because that is what most UNIX @code{f77} commands
12668 default to, and apparently lots of code depends on this feature.
12669
12670 This is a particularly troubling issue.
12671 The use of a C construct in the midst of Fortran code
12672 is bad enough, worse when it makes existing Fortran
12673 programs stop working (as happens when programs written
12674 for non-UNIX systems are ported to UNIX systems with
12675 compilers that provide the @samp{-fbackslash} feature
12676 as the default---sometimes with no option to turn it off).
12677
12678 The author of GNU Fortran wished, for reasons of linguistic
12679 purity, to make @samp{-fno-backslash} the default for GNU
12680 Fortran and thus require users of UNIX @code{f77} and @code{f2c}
12681 to specify @samp{-fbackslash} to get the UNIX behavior.
12682
12683 However, the realization that @code{g77} is intended as
12684 a replacement for @emph{UNIX} @code{f77}, caused the author
12685 to choose to make @code{g77} as compatible with
12686 @code{f77} as feasible, which meant making @samp{-fbackslash}
12687 the default.
12688
12689 The primary focus on compatibility is at the source-code
12690 level, and the question became ``What will users expect
12691 a replacement for @code{f77} to do, by default?''
12692 Although at least one UNIX @code{f77} does not provide
12693 @samp{-fbackslash} as a default, it appears that
12694 the majority of them do, which suggests that
12695 the majority of code that is compiled by UNIX @code{f77}
12696 compilers expects @samp{-fbackslash} to be the default.
12697
12698 It is probably the case that more code exists
12699 that would @emph{not} work with @samp{-fbackslash}
12700 in force than code that requires it be in force.
12701
12702 However, most of @emph{that} code is not being compiled
12703 with @code{f77},
12704 and when it is, new build procedures (shell scripts,
12705 makefiles, and so on) must be set up anyway so that
12706 they work under UNIX.
12707 That makes a much more natural and safe opportunity for
12708 non-UNIX users to adapt their build procedures for
12709 @code{g77}'s default of @samp{-fbackslash} than would
12710 exist for the majority of UNIX @code{f77} users who
12711 would have to modify existing, working build procedures
12712 to explicitly specify @samp{-fbackslash} if that was
12713 not the default.
12714
12715 One suggestion has been to configure the default for
12716 @samp{-fbackslash} (and perhaps other options as well)
12717 based on the configuration of @code{g77}.
12718
12719 This is technically quite straightforward, but will be avoided
12720 even in cases where not configuring defaults to be
12721 dependent on a particular configuration greatly inconveniences
12722 some users of legacy code.
12723
12724 Many users appreciate the GNU compilers because they provide an
12725 environment that is uniform across machines.
12726 These users would be
12727 inconvenienced if the compiler treated things like the
12728 format of the source code differently on certain machines.
12729
12730 Occasionally users write programs intended only for a particular machine
12731 type.
12732 On these occasions, the users would benefit if the GNU Fortran compiler
12733 were to support by default the same dialect as the other compilers on
12734 that machine.
12735 But such applications are rare.
12736 And users writing a
12737 program to run on more than one type of machine cannot possibly benefit
12738 from this kind of compatibility.
12739 (This is consistent with the design goals for @code{gcc}.
12740 To change them for @code{g77}, you must first change them
12741 for @code{gcc}.
12742 Do not ask the maintainers of @code{g77} to do this for you,
12743 or to disassociate @code{g77} from the widely understood, if
12744 not widely agreed-upon, goals for GNU compilers in general.)
12745
12746 This is why GNU Fortran does and will treat backslashes in the same
12747 fashion on all types of machines (by default).
12748 @xref{Direction of Language Development}, for more information on
12749 this overall philosophy guiding the development of the GNU Fortran
12750 language.
12751
12752 Of course, users strongly concerned about portability should indicate
12753 explicitly in their build procedures which options are expected
12754 by their source code, or write source code that has as few such
12755 expectations as possible.
12756
12757 For example, avoid writing code that depends on backslash (@samp{\})
12758 being interpreted either way in particular, such as by
12759 starting a program unit with:
12760
12761 @smallexample
12762 CHARACTER BACKSL
12763 PARAMETER (BACKSL = '\\')
12764 @end smallexample
12765
12766 @noindent
12767 Then, use concatenation of @samp{BACKSL} anyplace a backslash
12768 is desired.
12769 In this way, users can write programs which have the same meaning
12770 in many Fortran dialects.
12771
12772 (However, this technique does not work for Hollerith constants---which
12773 is just as well, since the only generally portable uses for Hollerith
12774 constants are in places where character constants can and should
12775 be used instead, for readability.)
12776
12777 @node Initializing Before Specifying
12778 @subsection Initializing Before Specifying
12779 @cindex initialization, statement placement
12780 @cindex placing initialization statements
12781
12782 @code{g77} does not allow @samp{DATA VAR/1/} to appear in the
12783 source code before @samp{COMMON VAR},
12784 @samp{DIMENSION VAR(10)}, @samp{INTEGER VAR}, and so on.
12785 In general, @code{g77} requires initialization of a variable
12786 or array to be specified @emph{after} all other specifications
12787 of attributes (type, size, placement, and so on) of that variable
12788 or array are specified (though @emph{confirmation} of data type is
12789 permitted).
12790
12791 It is @emph{possible} @code{g77} will someday allow all of this,
12792 even though it is not allowed by the FORTRAN 77 standard.
12793
12794 Then again, maybe it is better to have
12795 @code{g77} always require placement of @code{DATA}
12796 so that it can possibly immediately write constants
12797 to the output file, thus saving time and space.
12798
12799 That is, @samp{DATA A/1000000*1/} should perhaps always
12800 be immediately writable to canonical assembler, unless it's already known
12801 to be in a @code{COMMON} area following as-yet-uninitialized stuff,
12802 and to do this it cannot be followed by @samp{COMMON A}.
12803
12804 @node Context-Sensitive Intrinsicness
12805 @subsection Context-Sensitive Intrinsicness
12806 @cindex intrinsics, context-sensitive
12807 @cindex context-sensitive intrinsics
12808
12809 @code{g77} treats procedure references to @emph{possible} intrinsic
12810 names as always enabling their intrinsic nature, regardless of
12811 whether the @emph{form} of the reference is valid for that
12812 intrinsic.
12813
12814 For example, @samp{CALL SQRT} is interpreted by @code{g77} as
12815 an invalid reference to the @code{SQRT} intrinsic function,
12816 because the reference is a subroutine invocation.
12817
12818 First, @code{g77} recognizes the statement @samp{CALL SQRT}
12819 as a reference to a @emph{procedure} named @samp{SQRT}, not
12820 to a @emph{variable} with that name (as it would for a statement
12821 such as @samp{V = SQRT}).
12822
12823 Next, @code{g77} establishes that, in the program unit being compiled,
12824 @code{SQRT} is an intrinsic---not a subroutine that
12825 happens to have the same name as an intrinsic (as would be
12826 the case if, for example, @samp{EXTERNAL SQRT} was present).
12827
12828 Finally, @code{g77} recognizes that the @emph{form} of the
12829 reference is invalid for that particular intrinsic.
12830 That is, it recognizes that it is invalid for an intrinsic
12831 @emph{function}, such as @code{SQRT}, to be invoked as
12832 a @emph{subroutine}.
12833
12834 At that point, @code{g77} issues a diagnostic.
12835
12836 Some users claim that it is ``obvious'' that @samp{CALL SQRT}
12837 references an external subroutine of their own, not an
12838 intrinsic function.
12839
12840 However, @code{g77} knows about intrinsic
12841 subroutines, not just functions, and is able to support both having
12842 the same names, for example.
12843
12844 As a result of this, @code{g77} rejects calls
12845 to intrinsics that are not subroutines, and function invocations
12846 of intrinsics that are not functions, just as it (and most compilers)
12847 rejects invocations of intrinsics with the wrong number (or types)
12848 of arguments.
12849
12850 So, use the @samp{EXTERNAL SQRT} statement in a program unit that calls
12851 a user-written subroutine named @samp{SQRT}.
12852
12853 @node Context-Sensitive Constants
12854 @subsection Context-Sensitive Constants
12855 @cindex constants, context-sensitive
12856 @cindex context-sensitive constants
12857
12858 @code{g77} does not use context to determine the types of
12859 constants or named constants (@code{PARAMETER}), except
12860 for (non-standard) typeless constants such as @samp{'123'O}.
12861
12862 For example, consider the following statement:
12863
12864 @smallexample
12865 PRINT *, 9.435784839284958 * 2D0
12866 @end smallexample
12867
12868 @noindent
12869 @code{g77} will interpret the (truncated) constant
12870 @samp{9.435784839284958} as a @code{REAL(KIND=1)}, not @code{REAL(KIND=2)},
12871 constant, because the suffix @code{D0} is not specified.
12872
12873 As a result, the output of the above statement when
12874 compiled by @code{g77} will appear to have ``less precision''
12875 than when compiled by other compilers.
12876
12877 In these and other cases, some compilers detect the
12878 fact that a single-precision constant is used in
12879 a double-precision context and therefore interpret the
12880 single-precision constant as if it was @emph{explicitly}
12881 specified as a double-precision constant.
12882 (This has the effect of appending @emph{decimal}, not
12883 @emph{binary}, zeros to the fractional part of the
12884 number---producing different computational results.)
12885
12886 The reason this misfeature is dangerous is that a slight,
12887 apparently innocuous change to the source code can change
12888 the computational results.
12889 Consider:
12890
12891 @smallexample
12892 REAL ALMOST, CLOSE
12893 DOUBLE PRECISION FIVE
12894 PARAMETER (ALMOST = 5.000000000001)
12895 FIVE = 5
12896 CLOSE = 5.000000000001
12897 PRINT *, 5.000000000001 - FIVE
12898 PRINT *, ALMOST - FIVE
12899 PRINT *, CLOSE - FIVE
12900 END
12901 @end smallexample
12902
12903 @noindent
12904 Running the above program should
12905 result in the same value being
12906 printed three times.
12907 With @code{g77} as the compiler,
12908 it does.
12909
12910 However, compiled by many other compilers,
12911 running the above program would print
12912 two or three distinct values, because
12913 in two or three of the statements, the
12914 constant @samp{5.000000000001}, which
12915 on most systems is exactly equal to @samp{5.}
12916 when interpreted as a single-precision constant,
12917 is instead interpreted as a double-precision
12918 constant, preserving the represented
12919 precision.
12920 However, this ``clever'' promotion of
12921 type does not extend to variables or,
12922 in some compilers, to named constants.
12923
12924 Since programmers often are encouraged to replace manifest
12925 constants or permanently-assigned variables with named
12926 constants (@code{PARAMETER} in Fortran), and might need
12927 to replace some constants with variables having the same
12928 values for pertinent portions of code,
12929 it is important that compilers treat code so modified in the
12930 same way so that the results of such programs are the same.
12931 @code{g77} helps in this regard by treating constants just
12932 the same as variables in terms of determining their types
12933 in a context-independent way.
12934
12935 Still, there is a lot of existing Fortran code that has
12936 been written to depend on the way other compilers freely
12937 interpret constants' types based on context, so anything
12938 @code{g77} can do to help flag cases of this in such code
12939 could be very helpful.
12940
12941 @node Equivalence Versus Equality
12942 @subsection Equivalence Versus Equality
12943 @cindex .EQV., with integer operands
12944 @cindex comparing logical expressions
12945 @cindex logical expressions, comparing
12946
12947 Use of @code{.EQ.} and @code{.NE.} on @code{LOGICAL} operands
12948 is not supported, except via @samp{-fugly-logint}, which is not
12949 recommended except for legacy code (where the behavior expected
12950 by the @emph{code} is assumed).
12951
12952 Legacy code should be changed, as resources permit, to use @code{.EQV.}
12953 and @code{.NEQV.} instead, as these are permitted by the various
12954 Fortran standards.
12955
12956 New code should never be written expecting @code{.EQ.} or @code{.NE.}
12957 to work if either of its operands is @code{LOGICAL}.
12958
12959 The problem with supporting this ``feature'' is that there is
12960 unlikely to be consensus on how it works, as illustrated by the
12961 following sample program:
12962
12963 @smallexample
12964 LOGICAL L,M,N
12965 DATA L,M,N /3*.FALSE./
12966 IF (L.AND.M.EQ.N) PRINT *,'L.AND.M.EQ.N'
12967 END
12968 @end smallexample
12969
12970 The issue raised by the above sample program is: what is the
12971 precedence of @code{.EQ.} (and @code{.NE.}) when applied to
12972 @code{LOGICAL} operands?
12973
12974 Some programmers will argue that it is the same as the precedence
12975 for @code{.EQ.} when applied to numeric (such as @code{INTEGER})
12976 operands.
12977 By this interpretation, the subexpression @samp{M.EQ.N} must be
12978 evaluated first in the above program, resulting in a program that,
12979 when run, does not execute the @code{PRINT} statement.
12980
12981 Other programmers will argue that the precedence is the same as
12982 the precedence for @code{.EQV.}, which is restricted by the standards
12983 to @code{LOGICAL} operands.
12984 By this interpretation, the subexpression @samp{L.AND.M} must be
12985 evaluated first, resulting in a program that @emph{does} execute
12986 the @code{PRINT} statement.
12987
12988 Assigning arbitrary semantic interpretations to syntactic expressions
12989 that might legitimately have more than one ``obvious'' interpretation
12990 is generally unwise.
12991
12992 The creators of the various Fortran standards have done a good job
12993 in this case, requiring a distinct set of operators (which have their
12994 own distinct precedence) to compare @code{LOGICAL} operands.
12995 This requirement results in expression syntax with more certain
12996 precedence (without requiring substantial context), making it easier
12997 for programmers to read existing code.
12998 @code{g77} will avoid muddying up elements of the Fortran language
12999 that were well-designed in the first place.
13000
13001 (Ask C programmers about the precedence of expressions such as
13002 @samp{(a) & (b)} and @samp{(a) - (b)}---they cannot even tell
13003 you, without knowing more context, whether the @samp{&} and @samp{-}
13004 operators are infix (binary) or unary!)
13005
13006 Most dangerous of all is the fact that,
13007 even assuming consensus on its meaning,
13008 an expression like @samp{L.AND.M.EQ.N},
13009 if it is the result of a typographical error,
13010 doesn't @emph{look} like it has such a typo.
13011 Even experienced Fortran programmers would not likely notice that
13012 @samp{L.AND.M.EQV.N} was, in fact, intended.
13013
13014 So, this is a prime example of a circumstance in which
13015 a quality compiler diagnoses the code,
13016 instead of leaving it up to someone debugging it
13017 to know to turn on special compiler options
13018 that might diagnose it.
13019
13020 @node Order of Side Effects
13021 @subsection Order of Side Effects
13022 @cindex side effects, order of evaluation
13023 @cindex order of evaluation, side effects
13024
13025 @code{g77} does not necessarily produce code that, when run, performs
13026 side effects (such as those performed by function invocations)
13027 in the same order as in some other compiler---or even in the same
13028 order as another version, port, or invocation (using different
13029 command-line options) of @code{g77}.
13030
13031 It is never safe to depend on the order of evaluation of side effects.
13032 For example, an expression like this may very well behave differently
13033 from one compiler to another:
13034
13035 @smallexample
13036 J = IFUNC() - IFUNC()
13037 @end smallexample
13038
13039 @noindent
13040 There is no guarantee that @samp{IFUNC} will be evaluated in any particular
13041 order.
13042 Either invocation might happen first.
13043 If @samp{IFUNC} returns 5 the first time it is invoked, and
13044 returns 12 the second time, @samp{J} might end up with the
13045 value @samp{7}, or it might end up with @samp{-7}.
13046
13047 Generally, in Fortran, procedures with side-effects intended to
13048 be visible to the caller are best designed as @emph{subroutines},
13049 not functions.
13050 Examples of such side-effects include:
13051
13052 @itemize @bullet
13053 @item
13054 The generation of random numbers
13055 that are intended to influence return values.
13056
13057 @item
13058 Performing I/O
13059 (other than internal I/O to local variables).
13060
13061 @item
13062 Updating information in common blocks.
13063 @end itemize
13064
13065 An example of a side-effect that is not intended to be visible
13066 to the caller is a function that maintains a cache of recently
13067 calculated results, intended solely to speed repeated invocations
13068 of the function with identical arguments.
13069 Such a function can be safely used in expressions, because
13070 if the compiler optimizes away one or more calls to the
13071 function, operation of the program is unaffected (aside
13072 from being speeded up).
13073
13074 @node Warnings and Errors
13075 @section Warning Messages and Error Messages
13076
13077 @cindex error messages
13078 @cindex warnings vs errors
13079 @cindex messages, warning and error
13080 The GNU compiler can produce two kinds of diagnostics: errors and
13081 warnings.
13082 Each kind has a different purpose:
13083
13084 @itemize @w{}
13085 @item
13086 @emph{Errors} report problems that make it impossible to compile your
13087 program.
13088 GNU Fortran reports errors with the source file name, line
13089 number, and column within the line where the problem is apparent.
13090
13091 @item
13092 @emph{Warnings} report other unusual conditions in your code that
13093 @emph{might} indicate a problem, although compilation can (and does)
13094 proceed.
13095 Warning messages also report the source file name, line number,
13096 and column information,
13097 but include the text @samp{warning:} to distinguish them
13098 from error messages.
13099 @end itemize
13100
13101 Warnings might indicate danger points where you should check to make sure
13102 that your program really does what you intend; or the use of obsolete
13103 features; or the use of nonstandard features of GNU Fortran.
13104 Many warnings are issued only if you ask for them, with one of the
13105 @samp{-W} options (for instance, @samp{-Wall} requests a variety of
13106 useful warnings).
13107
13108 @emph{Note:} Currently, the text of the line and a pointer to the column
13109 is printed in most @code{g77} diagnostics.
13110 Probably, as of version 0.6, @code{g77} will
13111 no longer print the text of the source line, instead printing
13112 the column number following the file name and line number in
13113 a form that GNU Emacs recognizes.
13114 This change is expected to speed up and reduce the memory usage
13115 of the @code{g77} compiler.
13116 @c
13117 @c Say this when it is true -- hopefully 0.6, maybe 0.7 or later.  --burley
13118 @c
13119 @c GNU Fortran always tries to compile your program if possible; it never
13120 @c gratuitously rejects a program whose meaning is clear merely because
13121 @c (for instance) it fails to conform to a standard.  In some cases,
13122 @c however, the Fortran standard specifies that certain extensions are
13123 @c forbidden, and a diagnostic @emph{must} be issued by a conforming
13124 @c compiler.  The @samp{-pedantic} option tells GNU Fortran to issue warnings
13125 @c in such cases; @samp{-pedantic-errors} says to make them errors instead.
13126 @c This does not mean that @emph{all} non-ANSI constructs get warnings
13127 @c or errors.
13128
13129 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
13130 more detail on these and related command-line options.
13131
13132 @node Open Questions
13133 @chapter Open Questions
13134
13135 Please consider offering useful answers to these questions!
13136
13137 @itemize @bullet
13138 @item
13139 @code{LOC()} and other intrinsics are probably somewhat misclassified.
13140 Is the a need for more precise classification of intrinsics, and if so,
13141 what are the appropriate groupings?
13142 Is there a need to individually
13143 enable/disable/delete/hide intrinsics from the command line?
13144 @end itemize
13145
13146 @node Bugs
13147 @chapter Reporting Bugs
13148 @cindex bugs
13149 @cindex reporting bugs
13150
13151 Your bug reports play an essential role in making GNU Fortran reliable.
13152
13153 When you encounter a problem, the first thing to do is to see if it is
13154 already known.
13155 @xref{Trouble}.
13156 If it isn't known, then you should report the problem.
13157
13158 Reporting a bug might help you by bringing a solution to your problem, or
13159 it might not.
13160 (If it does not, look in the service directory; see
13161 @ref{Service}.)
13162 In any case, the principal function of a bug report is
13163 to help the entire community by making the next version of GNU Fortran work
13164 better.
13165 Bug reports are your contribution to the maintenance of GNU Fortran.
13166
13167 Since the maintainers are very overloaded, we cannot respond to every
13168 bug report.
13169 However, if the bug has not been fixed, we are likely to
13170 send you a patch and ask you to tell us whether it works.
13171
13172 In order for a bug report to serve its purpose, you must include the
13173 information that makes for fixing the bug.
13174
13175 @menu
13176 * Criteria: Bug Criteria.    Have you really found a bug?
13177 * Where: Bug Lists.          Where to send your bug report.
13178 * Reporting: Bug Reporting.  How to report a bug effectively.
13179 * Patches: Sending Patches.  How to send a patch for GNU Fortran.
13180 @end menu
13181
13182 @xref{Trouble,,Known Causes of Trouble with GNU Fortran},
13183 for information on problems we already know about.
13184
13185 @xref{Service,,How To Get Help with GNU Fortran},
13186 for information on where to ask for help.
13187
13188 @node Bug Criteria
13189 @section Have You Found a Bug?
13190 @cindex bug criteria
13191
13192 If you are not sure whether you have found a bug, here are some guidelines:
13193
13194 @itemize @bullet
13195 @cindex fatal signal
13196 @cindex core dump
13197 @item
13198 If the compiler gets a fatal signal, for any input whatever, that is a
13199 compiler bug.
13200 Reliable compilers never crash---they just remain obsolete.
13201
13202 @cindex invalid assembly code
13203 @cindex assembly code, invalid
13204 @item
13205 If the compiler produces invalid assembly code, for any input whatever,
13206 @c (except an @code{asm} statement),
13207 that is a compiler bug, unless the
13208 compiler reports errors (not just warnings) which would ordinarily
13209 prevent the assembler from being run.
13210
13211 @cindex undefined behavior
13212 @cindex undefined function value
13213 @item
13214 If the compiler produces valid assembly code that does not correctly
13215 execute the input source code, that is a compiler bug.
13216
13217 However, you must double-check to make sure, because you might have run
13218 into an incompatibility between GNU Fortran and traditional Fortran.
13219 @c (@pxref{Incompatibilities}).
13220 These incompatibilities might be considered
13221 bugs, but they are inescapable consequences of valuable features.
13222
13223 Or you might have a program whose behavior is undefined, which happened
13224 by chance to give the desired results with another Fortran compiler.
13225 It is best to check the relevant Fortran standard thoroughly if
13226 it is possible that the program indeed does something undefined.
13227
13228 After you have localized the error to a single source line, it should
13229 be easy to check for these things.
13230 If your program is correct and well defined, you have found
13231 a compiler bug.
13232
13233 It might help if, in your submission, you identified the specific
13234 language in the relevant Fortran standard that specifies the
13235 desired behavior, if it isn't likely to be obvious and agreed-upon
13236 by all Fortran users.
13237
13238 @item
13239 If the compiler produces an error message for valid input, that is a
13240 compiler bug.
13241
13242 @cindex invalid input
13243 @item
13244 If the compiler does not produce an error message for invalid input,
13245 that is a compiler bug.
13246 However, you should note that your idea of
13247 ``invalid input'' might be someone else's idea
13248 of ``an extension'' or ``support for traditional practice''.
13249
13250 @item
13251 If you are an experienced user of Fortran compilers, your suggestions
13252 for improvement of GNU Fortran are welcome in any case.
13253 @end itemize
13254
13255 Many, perhaps most, bug reports against @code{g77} turn out to
13256 be bugs in the user's code.
13257 While we find such bug reports educational, they sometimes take
13258 a considerable amount of time to track down or at least respond
13259 to---time we could be spending making @code{g77}, not some user's
13260 code, better.
13261
13262 Some steps you can take to verify that the bug is not certainly
13263 in the code you're compiling with @code{g77}:
13264
13265 @itemize @bullet
13266 @item
13267 Compile your code using the @code{g77} options @samp{-W -Wall -O}.
13268 These options enable many useful warning; the @samp{-O} option
13269 enables flow analysis that enables the uninitialized-variable
13270 warning.
13271
13272 If you investigate the warnings and find evidence of possible bugs
13273 in your code, fix them first and retry @code{g77}.
13274
13275 @item
13276 Compile your code using the @code{g77} options @samp{-finit-local-zero},
13277 @samp{-fno-automatic}, @samp{-ffloat-store}, and various
13278 combinations thereof.
13279
13280 If your code works with any of these combinations, that is not
13281 proof that the bug isn't in @code{g77}---a @code{g77} bug exposed
13282 by your code might simply be avoided, or have a different, more subtle
13283 effect, when different options are used---but it can be a
13284 strong indicator that your code is making unwarranted assumptions
13285 about the Fortran dialect and/or underlying machine it is
13286 being compiled and run on.
13287
13288 @xref{Overly Convenient Options,,Overly Convenient Command-Line Options},
13289 for information on the @samp{-fno-automatic} and
13290 @samp{-finit-local-zero} options and how to convert
13291 their use into selective changes in your own code.
13292
13293 @item
13294 @pindex ftnchek
13295 Validate your code with @code{ftnchek} or a similar code-checking
13296 tool.
13297 @code{ftnchek} can be found at @uref{ftp://ftp.netlib.org/fortran}
13298 or @uref{ftp://ftp.dsm.fordham.edu}.
13299
13300 @pindex make
13301 @cindex Makefile example
13302 Here are some sample @file{Makefile} rules using @code{ftnchek}
13303 ``project'' files to do cross-file checking and @code{sfmakedepend}
13304 (from @uref{ftp://ahab.rutgers.edu/pub/perl/sfmakedepend})
13305 to maintain dependencies automatically.
13306 These assume the use of GNU @code{make}.
13307
13308 @smallexample
13309 # Dummy suffix for ftnchek targets:
13310 .SUFFIXES: .chek
13311 .PHONY: chekall
13312
13313 # How to compile .f files (for implicit rule):
13314 FC = g77
13315 # Assume `include' directory:
13316 FFLAGS = -Iinclude -g -O -Wall
13317
13318 # Flags for ftnchek:
13319 CHEK1 = -array=0 -include=includes -noarray
13320 CHEK2 = -nonovice -usage=1 -notruncation
13321 CHEKFLAGS = $(CHEK1) $(CHEK2)
13322
13323 # Run ftnchek with all the .prj files except the one corresponding
13324 # to the target's root:
13325 %.chek : %.f ; \
13326   ftnchek $(filter-out $*.prj,$(PRJS)) $(CHEKFLAGS) \
13327     -noextern -library $<
13328
13329 # Derive a project file from a source file:
13330 %.prj : %.f ; \
13331   ftnchek $(CHEKFLAGS) -noextern -project -library $<
13332
13333 # The list of objects is assumed to be in variable OBJS.
13334 # Sources corresponding to the objects:
13335 SRCS = $(OBJS:%.o=%.f)
13336 # ftnchek project files:
13337 PRJS = $(OBJS:%.o=%.prj)
13338
13339 # Build the program
13340 prog: $(OBJS) ; \
13341   $(FC) -o $@ $(OBJS)
13342
13343 chekall: $(PRJS) ; \
13344   ftnchek $(CHEKFLAGS) $(PRJS)
13345
13346 prjs: $(PRJS)
13347
13348 # For Emacs M-x find-tag:
13349 TAGS: $(SRCS) ; \
13350   etags $(SRCS)
13351
13352 # Rebuild dependencies:
13353 depend: ; \
13354   sfmakedepend -I $(PLTLIBDIR) -I includes -a prj $(SRCS1)
13355 @end smallexample
13356
13357 @item
13358 Try your code out using other Fortran compilers, such as @code{f2c}.
13359 If it does not work on at least one other compiler (assuming the
13360 compiler supports the features the code needs), that is a strong
13361 indicator of a bug in the code.
13362
13363 However, even if your code works on many compilers @emph{except}
13364 @code{g77}, that does @emph{not} mean the bug is in @code{g77}.
13365 It might mean the bug is in your code, and that @code{g77} simply
13366 exposes it more readily than other compilers.
13367 @end itemize
13368
13369 @node Bug Lists
13370 @section Where to Report Bugs
13371 @cindex bug report mailing lists
13372 @kindex @value{email-bugs}
13373 Send bug reports for GNU Fortran to @email{@value{email-bugs}}.
13374
13375 Often people think of posting bug reports to a newsgroup instead of
13376 mailing them.
13377 This sometimes appears to work, but it has one problem which can be
13378 crucial: a newsgroup posting does not contain a mail path back to the
13379 sender.
13380 Thus, if maintainers need more information, they might be unable
13381 to reach you.  For this reason, you should always send bug reports by
13382 mail to the proper mailing list.
13383
13384 As a last resort, send bug reports on paper to:
13385
13386 @example
13387 GNU Compiler Bugs
13388 Free Software Foundation
13389 59 Temple Place - Suite 330
13390 Boston, MA 02111-1307, USA
13391 @end example
13392
13393 @node Bug Reporting
13394 @section How to Report Bugs
13395 @cindex compiler bugs, reporting
13396
13397 The fundamental principle of reporting bugs usefully is this:
13398 @strong{report all the facts}.
13399 If you are not sure whether to state a
13400 fact or leave it out, state it!
13401
13402 Often people omit facts because they think they know what causes the
13403 problem and they conclude that some details don't matter.
13404 Thus, you might
13405 assume that the name of the variable you use in an example does not matter.
13406 Well, probably it doesn't, but one cannot be sure.
13407 Perhaps the bug is a
13408 stray memory reference which happens to fetch from the location where that
13409 name is stored in memory; perhaps, if the name were different, the contents
13410 of that location would fool the compiler into doing the right thing despite
13411 the bug.
13412 Play it safe and give a specific, complete example.
13413 That is the
13414 easiest thing for you to do, and the most helpful.
13415
13416 Keep in mind that the purpose of a bug report is to enable someone to
13417 fix the bug if it is not known.
13418 It isn't very important what happens if
13419 the bug is already known.
13420 Therefore, always write your bug reports on
13421 the assumption that the bug is not known.
13422
13423 Sometimes people give a few sketchy facts and ask, ``Does this ring a
13424 bell?''
13425 This cannot help us fix a bug, so it is rarely helpful.
13426 We respond by asking for enough details to enable us to investigate.
13427 You might as well expedite matters by sending them to begin with.
13428 (Besides, there are enough bells ringing around here as it is.)
13429
13430 Try to make your bug report self-contained.
13431 If we have to ask you for
13432 more information, it is best if you include all the previous information
13433 in your response, as well as the information that was missing.
13434
13435 Please report each bug in a separate message.
13436 This makes it easier for
13437 us to track which bugs have been fixed and to forward your bugs reports
13438 to the appropriate maintainer.
13439
13440 Do not compress and encode any part of your bug report using programs
13441 such as @file{uuencode}.
13442 If you do so it will slow down the processing
13443 of your bug.
13444 If you must submit multiple large files, use @file{shar},
13445 which allows us to read your message without having to run any
13446 decompression programs.
13447
13448 (As a special exception for GNU Fortran bug-reporting, at least
13449 for now, if you are sending more than a few lines of code, if
13450 your program's source file format contains ``interesting'' things
13451 like trailing spaces or strange characters, or if you need to
13452 include binary data files, it is acceptable to put all the
13453 files together in a @code{tar} archive, and, whether you need to
13454 do that, it is acceptable to then compress the single file (@code{tar}
13455 archive or source file)
13456 using @code{gzip} and encode it via @code{uuencode}.
13457 Do not use any MIME stuff---the current maintainer can't decode this.
13458 Using @code{compress} instead of @code{gzip} is acceptable, assuming
13459 you have licensed the use of the patented algorithm in
13460 @code{compress} from Unisys.)
13461
13462 To enable someone to investigate the bug, you should include all these
13463 things:
13464
13465 @itemize @bullet
13466 @item
13467 The version of GNU Fortran.
13468 You can get this by running @code{g77} with the @samp{-v} option.
13469 (Ignore any error messages that might be displayed
13470 when the linker is run.)
13471
13472 Without this, we won't know whether there is any point in looking for
13473 the bug in the current version of GNU Fortran.
13474
13475 @item
13476 @cindex preprocessor
13477 @cindex cpp program
13478 @cindex programs, cpp
13479 @pindex cpp
13480 A complete input file that will reproduce the bug.
13481
13482 If your source file(s) require preprocessing
13483 (for example, their names have suffixes like
13484 @samp{.F}, @samp{.fpp}, @samp{.FPP}, and @samp{.r}),
13485 and the bug is in the compiler proper (@file{f771})
13486 or in a subsequent phase of processing,
13487 run your source file through the C preprocessor
13488 by doing @samp{g77 -E @var{sourcefile} > @var{newfile}}.
13489 Then, include the contents of @var{newfile} in the bug report.
13490 (When you do this, use the same preprocessor options---such as
13491 @samp{-I}, @samp{-D}, and @samp{-U}---that you used in actual
13492 compilation.)
13493
13494 A single statement is not enough of an example.
13495 In order to compile it,
13496 it must be embedded in a complete file of compiler input.
13497 The bug might depend on the details of how this is done.
13498
13499 Without a real example one can compile,
13500 all anyone can do about your bug report is wish you luck.
13501 It would be futile to try to guess how to provoke the bug.
13502 For example, bugs in register allocation and reloading
13503 can depend on every little detail of the source and include files
13504 that trigger them.
13505
13506 @item
13507 @cindex included files
13508 @cindex INCLUDE directive
13509 @cindex directive, INCLUDE
13510 @cindex #include directive
13511 @cindex directive, #include
13512 Note that you should include with your bug report any files
13513 included by the source file
13514 (via the @code{#include} or @code{INCLUDE} directive)
13515 that you send, and any files they include, and so on.
13516
13517 It is not necessary to replace
13518 the @code{#include} and @code{INCLUDE} directives
13519 with the actual files in the version of the source file that
13520 you send, but it might make submitting the bug report easier
13521 in the end.
13522 However, be sure to @emph{reproduce} the bug using the @emph{exact}
13523 version of the source material you submit, to avoid wild-goose
13524 chases.
13525
13526 @item
13527 The command arguments you gave GNU Fortran to compile that example
13528 and observe the bug.  For example, did you use @samp{-O}?  To guarantee
13529 you won't omit something important, list all the options.
13530
13531 If we were to try to guess the arguments, we would probably guess wrong
13532 and then we would not encounter the bug.
13533
13534 @item
13535 The type of machine you are using, and the operating system name and
13536 version number.
13537 (Much of this information is printed by @samp{g77 -v}---if you
13538 include that, send along any additional info you have that you
13539 don't see clearly represented in that output.)
13540
13541 @item
13542 The operands you gave to the @code{configure} command when you installed
13543 the compiler.
13544
13545 @item
13546 A complete list of any modifications you have made to the compiler
13547 source.  (We don't promise to investigate the bug unless it happens in
13548 an unmodified compiler.  But if you've made modifications and don't tell
13549 us, then you are sending us on a wild-goose chase.)
13550
13551 Be precise about these changes.  A description in English is not
13552 enough---send a context diff for them.
13553
13554 Adding files of your own (such as a machine description for a machine we
13555 don't support) is a modification of the compiler source.
13556
13557 @item
13558 Details of any other deviations from the standard procedure for installing
13559 GNU Fortran.
13560
13561 @item
13562 A description of what behavior you observe that you believe is
13563 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
13564 ``The assembler instruction at line 208 in the output is incorrect.''
13565
13566 Of course, if the bug is that the compiler gets a fatal signal, then one
13567 can't miss it.  But if the bug is incorrect output, the maintainer might
13568 not notice unless it is glaringly wrong.  None of us has time to study
13569 all the assembler code from a 50-line Fortran program just on the chance that
13570 one instruction might be wrong.  We need @emph{you} to do this part!
13571
13572 Even if the problem you experience is a fatal signal, you should still
13573 say so explicitly.  Suppose something strange is going on, such as, your
13574 copy of the compiler is out of synch, or you have encountered a bug in
13575 the C library on your system.  (This has happened!)  Your copy might
13576 crash and the copy here would not.  If you @i{said} to expect a crash,
13577 then when the compiler here fails to crash, we would know that the bug
13578 was not happening.  If you don't say to expect a crash, then we would
13579 not know whether the bug was happening.  We would not be able to draw
13580 any conclusion from our observations.
13581
13582 If the problem is a diagnostic when building GNU Fortran with some other
13583 compiler, say whether it is a warning or an error.
13584
13585 Often the observed symptom is incorrect output when your program is run.
13586 Sad to say, this is not enough information unless the program is short
13587 and simple.  None of us has time to study a large program to figure out
13588 how it would work if compiled correctly, much less which line of it was
13589 compiled wrong.  So you will have to do that.  Tell us which source line
13590 it is, and what incorrect result happens when that line is executed.  A
13591 person who understands the program can find this as easily as finding a
13592 bug in the program itself.
13593
13594 @item
13595 If you send examples of assembler code output from GNU Fortran,
13596 please use @samp{-g} when you make them.  The debugging information
13597 includes source line numbers which are essential for correlating the
13598 output with the input.
13599
13600 @item
13601 If you wish to mention something in the GNU Fortran source, refer to it by
13602 context, not by line number.
13603
13604 The line numbers in the development sources don't match those in your
13605 sources.  Your line numbers would convey no convenient information to the
13606 maintainers.
13607
13608 @item
13609 Additional information from a debugger might enable someone to find a
13610 problem on a machine which he does not have available.  However, you
13611 need to think when you collect this information if you want it to have
13612 any chance of being useful.
13613
13614 @cindex backtrace for bug reports
13615 For example, many people send just a backtrace, but that is never
13616 useful by itself.  A simple backtrace with arguments conveys little
13617 about GNU Fortran because the compiler is largely data-driven; the same
13618 functions are called over and over for different RTL insns, doing
13619 different things depending on the details of the insn.
13620
13621 Most of the arguments listed in the backtrace are useless because they
13622 are pointers to RTL list structure.  The numeric values of the
13623 pointers, which the debugger prints in the backtrace, have no
13624 significance whatever; all that matters is the contents of the objects
13625 they point to (and most of the contents are other such pointers).
13626
13627 In addition, most compiler passes consist of one or more loops that
13628 scan the RTL insn sequence.  The most vital piece of information about
13629 such a loop---which insn it has reached---is usually in a local variable,
13630 not in an argument.
13631
13632 @findex debug_rtx
13633 What you need to provide in addition to a backtrace are the values of
13634 the local variables for several stack frames up.  When a local
13635 variable or an argument is an RTX, first print its value and then use
13636 the GDB command @code{pr} to print the RTL expression that it points
13637 to.  (If GDB doesn't run on your machine, use your debugger to call
13638 the function @code{debug_rtx} with the RTX as an argument.)  In
13639 general, whenever a variable is a pointer, its value is no use
13640 without the data it points to.
13641 @end itemize
13642
13643 Here are some things that are not necessary:
13644
13645 @itemize @bullet
13646 @item
13647 A description of the envelope of the bug.
13648
13649 Often people who encounter a bug spend a lot of time investigating
13650 which changes to the input file will make the bug go away and which
13651 changes will not affect it.
13652
13653 This is often time consuming and not very useful, because the way we
13654 will find the bug is by running a single example under the debugger with
13655 breakpoints, not by pure deduction from a series of examples.  You might
13656 as well save your time for something else.
13657
13658 Of course, if you can find a simpler example to report @emph{instead} of
13659 the original one, that is a convenience.  Errors in the output will be
13660 easier to spot, running under the debugger will take less time, etc.
13661 Most GNU Fortran bugs involve just one function, so the most straightforward
13662 way to simplify an example is to delete all the function definitions
13663 except the one where the bug occurs.  Those earlier in the file may be
13664 replaced by external declarations if the crucial function depends on
13665 them.  (Exception: inline functions might affect compilation of functions
13666 defined later in the file.)
13667
13668 However, simplification is not vital; if you don't want to do this,
13669 report the bug anyway and send the entire test case you used.
13670
13671 @item
13672 In particular, some people insert conditionals @samp{#ifdef BUG} around
13673 a statement which, if removed, makes the bug not happen.  These are just
13674 clutter; we won't pay any attention to them anyway.  Besides, you should
13675 send us preprocessor output, and that can't have conditionals.
13676
13677 @item
13678 A patch for the bug.
13679
13680 A patch for the bug is useful if it is a good one.  But don't omit the
13681 necessary information, such as the test case, on the assumption that a
13682 patch is all we need.  We might see problems with your patch and decide
13683 to fix the problem another way, or we might not understand it at all.
13684
13685 Sometimes with a program as complicated as GNU Fortran it is very hard to
13686 construct an example that will make the program follow a certain path
13687 through the code.  If you don't send the example, we won't be able to
13688 construct one, so we won't be able to verify that the bug is fixed.
13689
13690 And if we can't understand what bug you are trying to fix, or why your
13691 patch should be an improvement, we won't install it.  A test case will
13692 help us to understand.
13693
13694 @xref{Sending Patches}, for guidelines on how to make it easy for us to
13695 understand and install your patches.
13696
13697 @item
13698 A guess about what the bug is or what it depends on.
13699
13700 Such guesses are usually wrong.  Even the maintainer can't guess right
13701 about such things without first using the debugger to find the facts.
13702
13703 @item
13704 A core dump file.
13705
13706 We have no way of examining a core dump for your type of machine
13707 unless we have an identical system---and if we do have one,
13708 we should be able to reproduce the crash ourselves.
13709 @end itemize
13710
13711 @node Sending Patches
13712 @section Sending Patches for GNU Fortran
13713
13714 If you would like to write bug fixes or improvements for the GNU Fortran
13715 compiler, that is very helpful.
13716 Send suggested fixes to the bug report
13717 mailing list, @email{@value{email-bugs}}.
13718
13719 Please follow these guidelines so we can study your patches efficiently.
13720 If you don't follow these guidelines, your information might still be
13721 useful, but using it will take extra work.  Maintaining GNU Fortran is a lot
13722 of work in the best of circumstances, and we can't keep up unless you do
13723 your best to help.
13724
13725 @itemize @bullet
13726 @item
13727 Send an explanation with your changes of what problem they fix or what
13728 improvement they bring about.  For a bug fix, just include a copy of the
13729 bug report, and explain why the change fixes the bug.
13730
13731 (Referring to a bug report is not as good as including it, because then
13732 we will have to look it up, and we have probably already deleted it if
13733 we've already fixed the bug.)
13734
13735 @item
13736 Always include a proper bug report for the problem you think you have
13737 fixed.  We need to convince ourselves that the change is right before
13738 installing it.  Even if it is right, we might have trouble judging it if
13739 we don't have a way to reproduce the problem.
13740
13741 @item
13742 Include all the comments that are appropriate to help people reading the
13743 source in the future understand why this change was needed.
13744
13745 @item
13746 Don't mix together changes made for different reasons.
13747 Send them @emph{individually}.
13748
13749 If you make two changes for separate reasons, then we might not want to
13750 install them both.  We might want to install just one.  If you send them
13751 all jumbled together in a single set of diffs, we have to do extra work
13752 to disentangle them---to figure out which parts of the change serve
13753 which purpose.  If we don't have time for this, we might have to ignore
13754 your changes entirely.
13755
13756 If you send each change as soon as you have written it, with its own
13757 explanation, then the two changes never get tangled up, and we can
13758 consider each one properly without any extra work to disentangle them.
13759
13760 Ideally, each change you send should be impossible to subdivide into
13761 parts that we might want to consider separately, because each of its
13762 parts gets its motivation from the other parts.
13763
13764 @item
13765 Send each change as soon as that change is finished.  Sometimes people
13766 think they are helping us by accumulating many changes to send them all
13767 together.  As explained above, this is absolutely the worst thing you
13768 could do.
13769
13770 Since you should send each change separately, you might as well send it
13771 right away.  That gives us the option of installing it immediately if it
13772 is important.
13773
13774 @item
13775 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
13776 for us to install reliably.  More than that, they make it hard for us to
13777 study the diffs to decide whether we want to install them.  Unidiff
13778 format is better than contextless diffs, but not as easy to read as
13779 @samp{-c} format.
13780
13781 If you have GNU @code{diff}, use @samp{diff -cp}, which shows the name of the
13782 function that each change occurs in.
13783 (The maintainer of GNU Fortran currently uses @samp{diff -rcp2N}.)
13784
13785 @item
13786 Write the change log entries for your changes.  We get lots of changes,
13787 and we don't have time to do all the change log writing ourselves.
13788
13789 Read the @file{ChangeLog} file to see what sorts of information to put
13790 in, and to learn the style that we use.  The purpose of the change log
13791 is to show people where to find what was changed.  So you need to be
13792 specific about what functions you changed; in large functions, it's
13793 often helpful to indicate where within the function the change was.
13794
13795 On the other hand, once you have shown people where to find the change,
13796 you need not explain its purpose.  Thus, if you add a new function, all
13797 you need to say about it is that it is new.  If you feel that the
13798 purpose needs explaining, it probably does---but the explanation will be
13799 much more useful if you put it in comments in the code.
13800
13801 If you would like your name to appear in the header line for who made
13802 the change, send us the header line.
13803
13804 @item
13805 When you write the fix, keep in mind that we can't install a change that
13806 would break other systems.
13807
13808 People often suggest fixing a problem by changing machine-independent
13809 files such as @file{toplev.c} to do something special that a particular
13810 system needs.  Sometimes it is totally obvious that such changes would
13811 break GNU Fortran for almost all users.  We can't possibly make a change like
13812 that.  At best it might tell us how to write another patch that would
13813 solve the problem acceptably.
13814
13815 Sometimes people send fixes that @emph{might} be an improvement in
13816 general---but it is hard to be sure of this.  It's hard to install
13817 such changes because we have to study them very carefully.  Of course,
13818 a good explanation of the reasoning by which you concluded the change
13819 was correct can help convince us.
13820
13821 The safest changes are changes to the configuration files for a
13822 particular machine.  These are safe because they can't create new bugs
13823 on other machines.
13824
13825 Please help us keep up with the workload by designing the patch in a
13826 form that is good to install.
13827 @end itemize
13828
13829 @node Service
13830 @chapter How To Get Help with GNU Fortran
13831
13832 If you need help installing, using or changing GNU Fortran, there are two
13833 ways to find it:
13834
13835 @itemize @bullet
13836 @item
13837 Look in the service directory for someone who might help you for a fee.
13838 The service directory is found in the file named @file{SERVICE} in the
13839 GNU CC distribution.
13840
13841 @item
13842 Send a message to @email{@value{email-general}}.
13843 @end itemize
13844
13845 @end ifset
13846 @ifset INTERNALS
13847 @node Adding Options
13848 @chapter Adding Options
13849 @cindex options, adding
13850 @cindex adding options
13851
13852 To add a new command-line option to @code{g77}, first decide
13853 what kind of option you wish to add.
13854 Search the @code{g77} and @code{gcc} documentation for one
13855 or more options that is most closely like the one you want to add
13856 (in terms of what kind of effect it has, and so on) to
13857 help clarify its nature.
13858
13859 @itemize @bullet
13860 @item
13861 @emph{Fortran options} are options that apply only
13862 when compiling Fortran programs.
13863 They are accepted by @code{g77} and @code{gcc}, but
13864 they apply only when compiling Fortran programs.
13865
13866 @item
13867 @emph{Compiler options} are options that apply
13868 when compiling most any kind of program.
13869 @end itemize
13870
13871 @emph{Fortran options} are listed in the file
13872 @file{@value{path-g77}/lang-options.h},
13873 which is used during the build of @code{gcc} to
13874 build a list of all options that are accepted by
13875 at least one language's compiler.
13876 This list goes into the @code{lang_options} array
13877 in @file{gcc/toplev.c}, which uses this array to
13878 determine whether a particular option should be
13879 offered to the linked-in front end for processing
13880 by calling @code{lang_option_decode}, which, for
13881 @code{g77}, is in @file{@value{path-g77}/com.c} and just
13882 calls @code{ffe_decode_option}.
13883
13884 If the linked-in front end ``rejects'' a
13885 particular option passed to it, @file{toplev.c}
13886 just ignores the option, because @emph{some}
13887 language's compiler is willing to accept it.
13888
13889 This allows commands like @samp{gcc -fno-asm foo.c bar.f}
13890 to work, even though Fortran compilation does
13891 not currently support the @samp{-fno-asm} option;
13892 even though the @code{f771} version of @code{lang_decode_option}
13893 rejects @samp{-fno-asm}, @file{toplev.c} doesn't
13894 produce a diagnostic because some other language (C)
13895 does accept it.
13896
13897 This also means that commands like
13898 @samp{g77 -fno-asm foo.f} yield no diagnostics,
13899 despite the fact that no phase of the command was
13900 able to recognize and process @samp{-fno-asm}---perhaps
13901 a warning about this would be helpful if it were
13902 possible.
13903
13904 Code that processes Fortran options is found in
13905 @file{@value{path-g77}/top.c}, function @code{ffe_decode_option}.
13906 This code needs to check positive and negative forms
13907 of each option.
13908
13909 The defaults for Fortran options are set in their
13910 global definitions, also found in @file{@value{path-g77}/top.c}.
13911 Many of these defaults are actually macros defined
13912 in @file{@value{path-g77}/target.h}, since they might be
13913 machine-specific.
13914 However, since, in practice, GNU compilers
13915 should behave the same way on all configurations
13916 (especially when it comes to language constructs),
13917 the practice of setting defaults in @file{target.h}
13918 is likely to be deprecated and, ultimately, stopped
13919 in future versions of @code{g77}.
13920
13921 Accessor macros for Fortran options, used by code
13922 in the @code{g77} FFE, are defined in @file{@value{path-g77}/top.h}.
13923
13924 @emph{Compiler options} are listed in @file{gcc/toplev.c}
13925 in the array @code{f_options}.
13926 An option not listed in @code{lang_options} is
13927 looked up in @code{f_options} and handled from there.
13928
13929 The defaults for compiler options are set in the
13930 global definitions for the corresponding variables,
13931 some of which are in @file{gcc/toplev.c}.
13932
13933 You can set different defaults for @emph{Fortran-oriented}
13934 or @emph{Fortran-reticent} compiler options by changing
13935 the source code of @code{g77} and rebuilding.
13936 How to do this depends on the version of @code{g77}:
13937
13938 @table @code
13939 @item G77 0.5.24 (EGCS 1.1)
13940 @itemx G77 0.5.25 (EGCS 1.2)
13941 Change the @code{lang_init_options} routine in @file{egcs/gcc/f/com.c}.
13942
13943 (Note that these versions of @code{g77}
13944 perform internal consistency checking automatically
13945 when the @samp{-fversion} option is specified.)
13946
13947 @item G77 0.5.23
13948 @itemx G77 0.5.24 (EGCS 1.0)
13949 Change the way @code{f771} handles the @samp{-fset-g77-defaults}
13950 option, which is always provided as the first option when
13951 called by @code{g77} or @code{gcc}.
13952
13953 This code is in @code{ffe_decode_options} in @file{@value{path-g77}/top.c}.
13954 Have it change just the variables that you want to default
13955 to a different setting for Fortran compiles compared to
13956 compiles of other languages.
13957
13958 The @samp{-fset-g77-defaults} option is passed to @code{f771}
13959 automatically because of the specification information
13960 kept in @file{@value{path-g77}/lang-specs.h}.
13961 This file tells the @code{gcc} command how to recognize,
13962 in this case, Fortran source files (those to be preprocessed,
13963 and those that are not), and further, how to invoke the
13964 appropriate programs (including @code{f771}) to process
13965 those source files.
13966
13967 It is in @file{@value{path-g77}/lang-specs.h} that @samp{-fset-g77-defaults},
13968 @samp{-fversion}, and other options are passed, as appropriate,
13969 even when the user has not explicitly specified them.
13970 Other ``internal'' options such as @samp{-quiet} also
13971 are passed via this mechanism.
13972 @end table
13973
13974 @node Projects
13975 @chapter Projects
13976 @cindex projects
13977
13978 If you want to contribute to @code{g77} by doing research,
13979 design, specification, documentation, coding, or testing,
13980 the following information should give you some ideas.
13981 More relevant information might be available from
13982 @uref{ftp://alpha.gnu.org/gnu/g77/projects/}.
13983
13984 @menu
13985 * Efficiency::               Make @code{g77} itself compile code faster.
13986 * Better Optimization::      Teach @code{g77} to generate faster code.
13987 * Simplify Porting::         Make @code{g77} easier to configure, build,
13988                              and install.
13989 * More Extensions::          Features many users won't know to ask for.
13990 * Machine Model::            @code{g77} should better leverage @code{gcc}.
13991 * Internals Documentation::  Make maintenance easier.
13992 * Internals Improvements::   Make internals more robust.
13993 * Better Diagnostics::       Make using @code{g77} on new code easier.
13994 @end menu
13995
13996 @node Efficiency
13997 @section Improve Efficiency
13998 @cindex efficiency
13999
14000 Don't bother doing any performance analysis until most of the
14001 following items are taken care of, because there's no question
14002 they represent serious space/time problems, although some of
14003 them show up only given certain kinds of (popular) input.
14004
14005 @itemize @bullet
14006 @item
14007 Improve @code{malloc} package and its uses to specify more info about
14008 memory pools and, where feasible, use obstacks to implement them.
14009
14010 @item
14011 Skip over uninitialized portions of aggregate areas (arrays,
14012 @code{COMMON} areas, @code{EQUIVALENCE} areas) so zeros need not be output.
14013 This would reduce memory usage for large initialized aggregate
14014 areas, even ones with only one initialized element.
14015
14016 As of version 0.5.18, a portion of this item has already been
14017 accomplished.
14018
14019 @item
14020 Prescan the statement (in @file{sta.c}) so that the nature of the statement
14021 is determined as much as possible by looking entirely at its form,
14022 and not looking at any context (previous statements, including types
14023 of symbols).
14024 This would allow ripping out of the statement-confirmation,
14025 symbol retraction/confirmation, and diagnostic inhibition
14026 mechanisms.
14027 Plus, it would result in much-improved diagnostics.
14028 For example, @samp{CALL some-intrinsic(@dots{})}, where the intrinsic
14029 is not a subroutine intrinsic, would result actual error instead of the
14030 unimplemented-statement catch-all.
14031
14032 @item
14033 Throughout @code{g77}, don't pass line/column pairs where
14034 a simple @code{ffewhere} type, which points to the error as much as is
14035 desired by the configuration, will do, and don't pass @code{ffelexToken} types
14036 where a simple @code{ffewhere} type will do.
14037 Then, allow new default
14038 configuration of @code{ffewhere} such that the source line text is not
14039 preserved, and leave it to things like Emacs' next-error function
14040 to point to them (now that @samp{next-error} supports column,
14041 or, perhaps, character-offset, numbers).
14042 The change in calling sequences should improve performance somewhat,
14043 as should not having to save source lines.
14044 (Whether this whole
14045 item will improve performance is questionable, but it should
14046 improve maintainability.)
14047
14048 @item
14049 Handle @samp{DATA (A(I),I=1,1000000)/1000000*2/} more efficiently, especially
14050 as regards the assembly output.
14051 Some of this might require improving
14052 the back end, but lots of improvement in space/time required in @code{g77}
14053 itself can be fairly easily obtained without touching the back end.
14054 Maybe type-conversion, where necessary, can be speeded up as well in
14055 cases like the one shown (converting the @samp{2} into @samp{2.}).
14056
14057 @item
14058 If analysis shows it to be worthwhile, optimize @file{lex.c}.
14059
14060 @item
14061 Consider redesigning @file{lex.c} to not need any feedback
14062 during tokenization, by keeping track of enough parse state on its
14063 own.
14064 @end itemize
14065
14066 @node Better Optimization
14067 @section Better Optimization
14068 @cindex optimization, better
14069 @cindex code generation, improving
14070
14071 Much of this work should be put off until after @code{g77} has
14072 all the features necessary for its widespread acceptance as a
14073 useful F77 compiler.
14074 However, perhaps this work can be done in parallel during
14075 the feature-adding work.
14076
14077 @itemize @bullet
14078 @item
14079 Do the equivalent of the trick of putting @samp{extern inline} in front
14080 of every function definition in @code{libg2c} and #include'ing the resulting
14081 file in @code{f2c}+@code{gcc}---that is, inline all run-time-library functions
14082 that are at all worth inlining.
14083 (Some of this has already been done, such as for integral exponentiation.)
14084
14085 @item
14086 When doing @samp{CHAR_VAR = CHAR_FUNC(@dots{})},
14087 and it's clear that types line up
14088 and @samp{CHAR_VAR} is addressable or not a @code{VAR_DECL},
14089 make @samp{CHAR_VAR}, not a
14090 temporary, be the receiver for @samp{CHAR_FUNC}.
14091 (This is now done for @code{COMPLEX} variables.)
14092
14093 @item
14094 Design and implement Fortran-specific optimizations that don't
14095 really belong in the back end, or where the front end needs to
14096 give the back end more info than it currently does.
14097
14098 @item
14099 Design and implement a new run-time library interface, with the
14100 code going into @code{libgcc} so no special linking is required to
14101 link Fortran programs using standard language features.
14102 This library
14103 would speed up lots of things, from I/O (using precompiled formats,
14104 doing just one, or, at most, very few, calls for arrays or array sections,
14105 and so on) to general computing (array/section implementations of
14106 various intrinsics, implementation of commonly performed loops that
14107 aren't likely to be optimally compiled otherwise, etc.).
14108
14109 Among the important things the library would do are:
14110
14111 @itemize @bullet
14112 @item
14113 Be a one-stop-shop-type
14114 library, hence shareable and usable by all, in that what are now
14115 library-build-time options in @code{libg2c} would be moved at least to the
14116 @code{g77} compile phase, if not to finer grains (such as choosing how
14117 list-directed I/O formatting is done by default at @code{OPEN} time, for
14118 preconnected units via options or even statements in the main program
14119 unit, maybe even on a per-I/O basis with appropriate pragma-like
14120 devices).
14121 @end itemize
14122
14123 @item
14124 Probably requiring the new library design, change interface to
14125 normally have @code{COMPLEX} functions return their values in the way
14126 @code{gcc} would if they were declared @code{__complex__ float},
14127 rather than using
14128 the mechanism currently used by @code{CHARACTER} functions (whereby the
14129 functions are compiled as returning void and their first arg is
14130 a pointer to where to store the result).
14131 (Don't append underscores to
14132 external names for @code{COMPLEX} functions in some cases once @code{g77} uses
14133 @code{gcc} rather than @code{f2c} calling conventions.)
14134
14135 @item
14136 Do something useful with @code{doiter} references where possible.
14137 For example, @samp{CALL FOO(I)} cannot modify @samp{I} if within
14138 a @code{DO} loop that uses @samp{I} as the
14139 iteration variable, and the back end might find that info useful
14140 in determining whether it needs to read @samp{I} back into a register after
14141 the call.
14142 (It normally has to do that, unless it knows @samp{FOO} never
14143 modifies its passed-by-reference argument, which is rarely the case
14144 for Fortran-77 code.)
14145 @end itemize
14146
14147 @node Simplify Porting
14148 @section Simplify Porting
14149 @cindex porting, simplify
14150 @cindex simplify porting
14151
14152 Making @code{g77} easier to configure, port, build, and install, either
14153 as a single-system compiler or as a cross-compiler, would be
14154 very useful.
14155
14156 @itemize @bullet
14157 @item
14158 A new library (replacing @code{libg2c}) should improve portability as well as
14159 produce more optimal code.
14160 Further, @code{g77} and the new library should
14161 conspire to simplify naming of externals, such as by removing unnecessarily
14162 added underscores, and to reduce/eliminate the possibility of naming
14163 conflicts, while making debugger more straightforward.
14164
14165 Also, it should
14166 make multi-language applications more feasible, such as by providing
14167 Fortran intrinsics that get Fortran unit numbers given C @code{FILE *}
14168 descriptors.
14169
14170 @item
14171 Possibly related to a new library, @code{g77} should produce the equivalent
14172 of a @code{gcc} @samp{main(argc, argv)} function when it compiles a
14173 main program unit, instead of compiling something that must be
14174 called by a library
14175 implementation of @code{main()}.
14176
14177 This would do many useful things such as
14178 provide more flexibility in terms of setting up exception handling,
14179 not requiring programmers to start their debugging sessions with
14180 @kbd{breakpoint MAIN__} followed by @kbd{run}, and so on.
14181
14182 @item
14183 The GBE needs to understand the difference between alignment
14184 requirements and desires.
14185 For example, on Intel x86 machines, @code{g77} currently imposes
14186 overly strict alignment requirements, due to the back end, but it
14187 would be useful for Fortran and C programmers to be able to override
14188 these @emph{recommendations} as long as they don't violate the actual
14189 processor @emph{requirements}.
14190 @end itemize
14191
14192 @node More Extensions
14193 @section More Extensions
14194 @cindex extensions, more
14195
14196 These extensions are not the sort of things users ask for ``by name'',
14197 but they might improve the usability of @code{g77}, and Fortran in
14198 general, in the long run.
14199 Some of these items really pertain to improving @code{g77} internals
14200 so that some popular extensions can be more easily supported.
14201
14202 @itemize @bullet
14203 @item
14204 Look through all the documentation on the GNU Fortran language,
14205 dialects, compiler, missing features, bugs, and so on.
14206 Many mentions of incomplete or missing features are
14207 sprinkled throughout.
14208 It is not worth repeating them here.
14209
14210 @item
14211 Consider adding a @code{NUMERIC} type to designate typeless numeric constants,
14212 named and unnamed.
14213 The idea is to provide a forward-looking, effective
14214 replacement for things like the old-style @code{PARAMETER} statement
14215 when people
14216 really need typelessness in a maintainable, portable, clearly documented
14217 way.
14218 Maybe @code{TYPELESS} would include @code{CHARACTER}, @code{POINTER},
14219 and whatever else might come along.
14220 (This is not really a call for polymorphism per se, just
14221 an ability to express limited, syntactic polymorphism.)
14222
14223 @item
14224 Support @samp{OPEN(@dots{},KEY=(@dots{}),@dots{})}.
14225
14226 @item
14227 Support arbitrary file unit numbers, instead of limiting them
14228 to 0 through @samp{MXUNIT-1}.
14229 (This is a @code{libg2c} issue.)
14230
14231 @item
14232 @samp{OPEN(NOSPANBLOCKS,@dots{})} is treated as
14233 @samp{OPEN(UNIT=NOSPANBLOCKS,@dots{})}, so a
14234 later @code{UNIT=} in the first example is invalid.
14235 Make sure this is what users of this feature would expect.
14236
14237 @item
14238 Currently @code{g77} disallows @samp{READ(1'10)} since
14239 it is an obnoxious syntax, but
14240 supporting it might be pretty easy if needed.
14241 More details are needed, such
14242 as whether general expressions separated by an apostrophe are supported,
14243 or maybe the record number can be a general expression, and so on.
14244
14245 @item
14246 Support @code{STRUCTURE}, @code{UNION}, @code{MAP}, and @code{RECORD}
14247 fully.
14248 Currently there is no support at all
14249 for @code{%FILL} in @code{STRUCTURE} and related syntax,
14250 whereas the rest of the
14251 stuff has at least some parsing support.
14252 This requires either major
14253 changes to @code{libg2c} or its replacement.
14254
14255 @item
14256 F90 and @code{g77} probably disagree about label scoping relative to
14257 @code{INTERFACE} and @code{END INTERFACE}, and their contained
14258 procedure interface bodies (blocks?).
14259
14260 @item
14261 @code{ENTRY} doesn't support F90 @code{RESULT()} yet,
14262 since that was added after S8.112.
14263
14264 @item
14265 Empty-statement handling (10 ;;CONTINUE;;) probably isn't consistent
14266 with the final form of the standard (it was vague at S8.112).
14267
14268 @item
14269 It seems to be an ``open'' question whether a file, immediately after being
14270 @code{OPEN}ed,is positioned at the beginning, the end, or wherever---it
14271 might be nice to offer an option of opening to ``undefined'' status, requiring
14272 an explicit absolute-positioning operation to be performed before any
14273 other (besides @code{CLOSE}) to assist in making applications port to systems
14274 (some IBM?) that @code{OPEN} to the end of a file or some such thing.
14275 @end itemize
14276
14277 @node Machine Model
14278 @section Machine Model
14279
14280 This items pertain to generalizing @code{g77}'s view of
14281 the machine model to more fully accept whatever the GBE
14282 provides it via its configuration.
14283
14284 @itemize @bullet
14285 @item
14286 Switch to using @code{REAL_VALUE_TYPE} to represent floating-point constants
14287 exclusively so the target float format need not be required.
14288 This
14289 means changing the way @code{g77} handles initialization of aggregate areas
14290 having more than one type, such as @code{REAL} and @code{INTEGER},
14291 because currently
14292 it initializes them as if they were arrays of @code{char} and uses the
14293 bit patterns of the constants of the various types in them to determine
14294 what to stuff in elements of the arrays.
14295
14296 @item
14297 Rely more and more on back-end info and capabilities, especially in the
14298 area of constants (where having the @code{g77} front-end's IL just store
14299 the appropriate tree nodes containing constants might be best).
14300
14301 @item
14302 Suite of C and Fortran programs that a user/administrator can run on a
14303 machine to help determine the configuration for @code{g77} before building
14304 and help determine if the compiler works (especially with whatever
14305 libraries are installed) after building.
14306 @end itemize
14307
14308 @node Internals Documentation
14309 @section Internals Documentation
14310
14311 Better info on how @code{g77} works and how to port it is needed.
14312 Much of this should be done only after the redesign planned for
14313 0.6 is complete.
14314
14315 @xref{Front End}, which contains some information
14316 on @code{g77} internals.
14317
14318 @node Internals Improvements
14319 @section Internals Improvements
14320
14321 Some more items that would make @code{g77} more reliable
14322 and easier to maintain:
14323
14324 @itemize @bullet
14325 @item
14326 Generally make expression handling focus
14327 more on critical syntax stuff, leaving semantics to callers.
14328 For example,
14329 anything a caller can check, semantically, let it do so, rather
14330 than having @file{expr.c} do it.
14331 (Exceptions might include things like
14332 diagnosing @samp{FOO(I--K:)=BAR} where @samp{FOO} is a @code{PARAMETER}---if
14333 it seems
14334 important to preserve the left-to-right-in-source order of production
14335 of diagnostics.)
14336
14337 @item
14338 Come up with better naming conventions for @samp{-D} to establish requirements
14339 to achieve desired implementation dialect via @file{proj.h}.
14340
14341 @item
14342 Clean up used tokens and @code{ffewhere}s in @code{ffeglobal_terminate_1}.
14343
14344 @item
14345 Replace @file{sta.c} @code{outpooldisp} mechanism with @code{malloc_pool_use}.
14346
14347 @item
14348 Check for @code{opANY} in more places in @file{com.c}, @file{std.c},
14349 and @file{ste.c}, and get rid of the @samp{opCONVERT(opANY)} kludge
14350 (after determining if there is indeed no real need for it).
14351
14352 @item
14353 Utility to read and check @file{bad.def} messages and their references in the
14354 code, to make sure calls are consistent with message templates.
14355
14356 @item
14357 Search and fix @samp{&ffe@dots{}} and similar so that
14358 @samp{ffe@dots{}ptr@dots{}} macros are
14359 available instead (a good argument for wishing this could have written all
14360 this stuff in C++, perhaps).
14361 On the other hand, it's questionable whether this sort of
14362 improvement is really necessary, given the availability of
14363 tools such as Emacs and Perl, which make finding any
14364 address-taking of structure members easy enough?
14365
14366 @item
14367 Some modules truly export the member names of their structures (and the
14368 structures themselves), maybe fix this, and fix other modules that just
14369 appear to as well (by appending @samp{_}, though it'd be ugly and probably
14370 not worth the time).
14371
14372 @item
14373 Implement C macros @samp{RETURNS(value)} and @samp{SETS(something,value)}
14374 in @file{proj.h}
14375 and use them throughout @code{g77} source code (especially in the definitions
14376 of access macros in @samp{.h} files) so they can be tailored
14377 to catch code writing into a @samp{RETURNS()} or reading from a @samp{SETS()}.
14378
14379 @item
14380 Decorate throughout with @code{const} and other such stuff.
14381
14382 @item
14383 All F90 notational derivations in the source code are still based
14384 on the S8.112 version of the draft standard.
14385 Probably should update
14386 to the official standard, or put documentation of the rules as used
14387 in the code@dots{}uh@dots{}in the code.
14388
14389 @item
14390 Some @code{ffebld_new} calls (those outside of @file{ffeexpr.c} or
14391 inside but invoked via paths not involving @code{ffeexpr_lhs} or
14392 @code{ffeexpr_rhs}) might be creating things
14393 in improper pools, leading to such things staying around too long or
14394 (doubtful, but possible and dangerous) not long enough.
14395
14396 @item
14397 Some @code{ffebld_list_new} (or whatever) calls might not be matched by
14398 @code{ffebld_list_bottom} (or whatever) calls, which might someday matter.
14399 (It definitely is not a problem just yet.)
14400
14401 @item
14402 Probably not doing clean things when we fail to @code{EQUIVALENCE} something
14403 due to alignment/mismatch or other problems---they end up without
14404 @code{ffestorag} objects, so maybe the backend (and other parts of the front
14405 end) can notice that and handle like an @code{opANY} (do what it wants, just
14406 don't complain or crash).
14407 Most of this seems to have been addressed
14408 by now, but a code review wouldn't hurt.
14409 @end itemize
14410
14411 @node Better Diagnostics
14412 @section Better Diagnostics
14413
14414 These are things users might not ask about, or that need to
14415 be looked into, before worrying about.
14416 Also here are items that involve reducing unnecessary diagnostic
14417 clutter.
14418
14419 @itemize @bullet
14420 @item
14421 When @code{FUNCTION} and @code{ENTRY} point types disagree (@code{CHARACTER}
14422 lengths, type classes, and so on),
14423 @code{ANY}-ize the offending @code{ENTRY} point and any @emph{new} dummies
14424 it specifies.
14425
14426 @item
14427 Speed up and improve error handling for data when repeat-count is
14428 specified.
14429 For example, don't output 20 unnecessary messages after the
14430 first necessary one for:
14431
14432 @smallexample
14433 INTEGER X(20)
14434 CONTINUE
14435 DATA (X(I), J= 1, 20) /20*5/
14436 END
14437 @end smallexample
14438
14439 @noindent
14440 (The @code{CONTINUE} statement ensures the @code{DATA} statement
14441 is processed in the context of executable, not specification,
14442 statements.)
14443 @end itemize
14444
14445 @include ffe.texi
14446
14447 @end ifset
14448
14449 @ifset USING
14450 @node Diagnostics
14451 @chapter Diagnostics
14452 @cindex diagnostics
14453
14454 Some diagnostics produced by @code{g77} require sufficient explanation
14455 that the explanations are given below, and the diagnostics themselves
14456 identify the appropriate explanation.
14457
14458 Identification uses the GNU Info format---specifically, the @code{info}
14459 command that displays the explanation is given within square
14460 brackets in the diagnostic.
14461 For example:
14462
14463 @smallexample
14464 foo.f:5: Invalid statement [info -f g77 M FOOEY]
14465 @end smallexample
14466
14467 More details about the above diagnostic is found in the @code{g77} Info
14468 documentation, menu item @samp{M}, submenu item @samp{FOOEY},
14469 which is displayed by typing the UNIX command
14470 @samp{info -f g77 M FOOEY}.
14471
14472 Other Info readers, such as EMACS, may be just as easily used to display
14473 the pertinent node.
14474 In the above example, @samp{g77} is the Info document name,
14475 @samp{M} is the top-level menu item to select,
14476 and, in that node (named @samp{Diagnostics}, the name of
14477 this chapter, which is the very text you're reading now),
14478 @samp{FOOEY} is the menu item to select.
14479
14480 @iftex
14481 In this printed version of the @code{g77} manual, the above example
14482 points to a section, below, entitled @samp{FOOEY}---though, of course,
14483 as the above is just a sample, no such section exists.
14484 @end iftex
14485
14486 @menu
14487 * CMPAMBIG::    Ambiguous use of intrinsic.
14488 * EXPIMP::      Intrinsic used explicitly and implicitly.
14489 * INTGLOB::     Intrinsic also used as name of global.
14490 * LEX::         Various lexer messages
14491 * GLOBALS::     Disagreements about globals.
14492 * LINKFAIL::    When linking @code{f771} fails.
14493 * Y2KBAD::      Use of non-Y2K-compliant intrinsic.
14494 @end menu
14495
14496 @node CMPAMBIG
14497 @section @code{CMPAMBIG}
14498
14499 @noindent
14500 @smallexample
14501 Ambiguous use of intrinsic @var{intrinsic} @dots{}
14502 @end smallexample
14503
14504 The type of the argument to the invocation of the @var{intrinsic}
14505 intrinsic is a @code{COMPLEX} type other than @code{COMPLEX(KIND=1)}.
14506 Typically, it is @code{COMPLEX(KIND=2)}, also known as
14507 @code{DOUBLE COMPLEX}.
14508
14509 The interpretation of this invocation depends on the particular
14510 dialect of Fortran for which the code was written.
14511 Some dialects convert the real part of the argument to
14512 @code{REAL(KIND=1)}, thus losing precision; other dialects,
14513 and Fortran 90, do no such conversion.
14514
14515 So, GNU Fortran rejects such invocations except under certain
14516 circumstances, to avoid making an incorrect assumption that results
14517 in generating the wrong code.
14518
14519 To determine the dialect of the program unit, perhaps even whether
14520 that particular invocation is properly coded, determine how the
14521 result of the intrinsic is used.
14522
14523 The result of @var{intrinsic} is expected (by the original programmer)
14524 to be @code{REAL(KIND=1)} (the non-Fortran-90 interpretation) if:
14525
14526 @itemize @bullet
14527 @item
14528 It is passed as an argument to a procedure that explicitly or
14529 implicitly declares that argument @code{REAL(KIND=1)}.
14530
14531 For example,
14532 a procedure with no @code{DOUBLE PRECISION} or @code{IMPLICIT DOUBLE PRECISION}
14533 statement specifying the dummy argument corresponding to an
14534 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14535 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14536 expected @samp{REAL(Z)} to return @code{REAL(KIND=1)} instead
14537 of @code{REAL(KIND=2)}.
14538
14539 @item
14540 It is used in a context that would otherwise not include
14541 any @code{REAL(KIND=2)} but where treating the @var{intrinsic}
14542 invocation as @code{REAL(KIND=2)} would result in unnecessary
14543 promotions and (typically) more expensive operations on the
14544 wider type.
14545
14546 For example:
14547
14548 @smallexample
14549 DOUBLE COMPLEX Z
14550 @dots{}
14551 R(1) = T * REAL(Z)
14552 @end smallexample
14553
14554 The above example suggests the programmer expected the real part
14555 of @samp{Z} to be converted to @code{REAL(KIND=1)} before being
14556 multiplied by @samp{T} (presumed, along with @samp{R} above, to
14557 be type @code{REAL(KIND=1)}).
14558
14559 Otherwise, the conversion would have to be delayed until after
14560 the multiplication, requiring not only an extra conversion
14561 (of @samp{T} to @code{REAL(KIND=2)}), but a (typically) more
14562 expensive multiplication (a double-precision multiplication instead
14563 of a single-precision one).
14564 @end itemize
14565
14566 The result of @var{intrinsic} is expected (by the original programmer)
14567 to be @code{REAL(KIND=2)} (the Fortran 90 interpretation) if:
14568
14569 @itemize @bullet
14570 @item
14571 It is passed as an argument to a procedure that explicitly or
14572 implicitly declares that argument @code{REAL(KIND=2)}.
14573
14574 For example, a procedure specifying a @code{DOUBLE PRECISION}
14575 dummy argument corresponding to an
14576 actual argument of @samp{REAL(Z)}, where @samp{Z} is declared
14577 @code{DOUBLE COMPLEX}, strongly suggests that the programmer
14578 expected @samp{REAL(Z)} to return @code{REAL(KIND=2)} instead
14579 of @code{REAL(KIND=1)}.
14580
14581 @item
14582 It is used in an expression context that includes
14583 other @code{REAL(KIND=2)} operands,
14584 or is assigned to a @code{REAL(KIND=2)} variable or array element.
14585
14586 For example:
14587
14588 @smallexample
14589 DOUBLE COMPLEX Z
14590 DOUBLE PRECISION R, T
14591 @dots{}
14592 R(1) = T * REAL(Z)
14593 @end smallexample
14594
14595 The above example suggests the programmer expected the real part
14596 of @samp{Z} to @emph{not} be converted to @code{REAL(KIND=1)}
14597 by the @code{REAL()} intrinsic.
14598
14599 Otherwise, the conversion would have to be immediately followed
14600 by a conversion back to @code{REAL(KIND=2)}, losing
14601 the original, full precision of the real part of @code{Z},
14602 before being multiplied by @samp{T}.
14603 @end itemize
14604
14605 Once you have determined whether a particular invocation of @var{intrinsic}
14606 expects the Fortran 90 interpretation, you can:
14607
14608 @itemize @bullet
14609 @item
14610 Change it to @samp{DBLE(@var{expr})} (if @var{intrinsic} is
14611 @code{REAL}) or @samp{DIMAG(@var{expr})} (if @var{intrinsic}
14612 is @code{AIMAG})
14613 if it expected the Fortran 90 interpretation.
14614
14615 This assumes @var{expr} is @code{COMPLEX(KIND=2)}---if it is
14616 some other type, such as @code{COMPLEX*32}, you should use the
14617 appropriate intrinsic, such as the one to convert to @code{REAL*16}
14618 (perhaps @code{DBLEQ()} in place of @code{DBLE()}, and
14619 @code{QIMAG()} in place of @code{DIMAG()}).
14620
14621 @item
14622 Change it to @samp{REAL(@var{intrinsic}(@var{expr}))},
14623 otherwise.
14624 This converts to @code{REAL(KIND=1)} in all working
14625 Fortran compilers.
14626 @end itemize
14627
14628 If you don't want to change the code, and you are certain that all
14629 ambiguous invocations of @var{intrinsic} in the source file have
14630 the same expectation regarding interpretation, you can:
14631
14632 @itemize @bullet
14633 @item
14634 Compile with the @code{g77} option @samp{-ff90}, to enable the
14635 Fortran 90 interpretation.
14636
14637 @item
14638 Compile with the @code{g77} options @samp{-fno-f90 -fugly-complex},
14639 to enable the non-Fortran-90 interpretations.
14640 @end itemize
14641
14642 @xref{REAL() and AIMAG() of Complex}, for more information on this
14643 issue.
14644
14645 Note: If the above suggestions don't produce enough evidence
14646 as to whether a particular program expects the Fortran 90
14647 interpretation of this ambiguous invocation of @var{intrinsic},
14648 there is one more thing you can try.
14649
14650 If you have access to most or all the compilers used on the
14651 program to create successfully tested and deployed executables,
14652 read the documentation for, and @emph{also} test out, each compiler
14653 to determine how it treats the @var{intrinsic} intrinsic in
14654 this case.
14655 (If all the compilers don't agree on an interpretation, there
14656 might be lurking bugs in the deployed versions of the program.)
14657
14658 The following sample program might help:
14659
14660 @cindex JCB003 program
14661 @smallexample
14662       PROGRAM JCB003
14663 C
14664 C Written by James Craig Burley 1997-02-23.
14665 C
14666 C Determine how compilers handle non-standard REAL
14667 C and AIMAG on DOUBLE COMPLEX operands.
14668 C
14669       DOUBLE COMPLEX Z
14670       REAL R
14671       Z = (3.3D0, 4.4D0)
14672       R = Z
14673       CALL DUMDUM(Z, R)
14674       R = REAL(Z) - R
14675       IF (R .NE. 0.) PRINT *, 'REAL() is Fortran 90'
14676       IF (R .EQ. 0.) PRINT *, 'REAL() is not Fortran 90'
14677       R = 4.4D0
14678       CALL DUMDUM(Z, R)
14679       R = AIMAG(Z) - R
14680       IF (R .NE. 0.) PRINT *, 'AIMAG() is Fortran 90'
14681       IF (R .EQ. 0.) PRINT *, 'AIMAG() is not Fortran 90'
14682       END
14683 C
14684 C Just to make sure compiler doesn't use naive flow
14685 C analysis to optimize away careful work above,
14686 C which might invalidate results....
14687 C
14688       SUBROUTINE DUMDUM(Z, R)
14689       DOUBLE COMPLEX Z
14690       REAL R
14691       END
14692 @end smallexample
14693
14694 If the above program prints contradictory results on a
14695 particular compiler, run away!
14696
14697 @node EXPIMP
14698 @section @code{EXPIMP}
14699
14700 @noindent
14701 @smallexample
14702 Intrinsic @var{intrinsic} referenced @dots{}
14703 @end smallexample
14704
14705 The @var{intrinsic} is explicitly declared in one program
14706 unit in the source file and implicitly used as an intrinsic
14707 in another program unit in the same source file.
14708
14709 This diagnostic is designed to catch cases where a program
14710 might depend on using the name @var{intrinsic} as an intrinsic
14711 in one program unit and as a global name (such as the name
14712 of a subroutine or function) in another, but @code{g77} recognizes
14713 the name as an intrinsic in both cases.
14714
14715 After verifying that the program unit making implicit use
14716 of the intrinsic is indeed written expecting the intrinsic,
14717 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14718 program unit to prevent this warning.
14719
14720 This and related warnings are disabled by using
14721 the @samp{-Wno-globals} option when compiling.
14722
14723 Note that this warning is not issued for standard intrinsics.
14724 Standard intrinsics include those described in the FORTRAN 77
14725 standard and, if @samp{-ff90} is specified, those described
14726 in the Fortran 90 standard.
14727 Such intrinsics are not as likely to be confused with user
14728 procedures as intrinsics provided as extensions to the
14729 standard by @code{g77}.
14730
14731 @node INTGLOB
14732 @section @code{INTGLOB}
14733
14734 @noindent
14735 @smallexample
14736 Same name `@var{intrinsic}' given @dots{}
14737 @end smallexample
14738
14739 The name @var{intrinsic} is used for a global entity (a common
14740 block or a program unit) in one program unit and implicitly
14741 used as an intrinsic in another program unit.
14742
14743 This diagnostic is designed to catch cases where a program
14744 intends to use a name entirely as a global name, but @code{g77}
14745 recognizes the name as an intrinsic in the program unit that
14746 references the name, a situation that would likely produce
14747 incorrect code.
14748
14749 For example:
14750
14751 @smallexample
14752 INTEGER FUNCTION TIME()
14753 @dots{}
14754 END
14755 @dots{}
14756 PROGRAM SAMP
14757 INTEGER TIME
14758 PRINT *, 'Time is ', TIME()
14759 END
14760 @end smallexample
14761
14762 The above example defines a program unit named @samp{TIME}, but
14763 the reference to @samp{TIME} in the main program unit @samp{SAMP}
14764 is normally treated by @code{g77} as a reference to the intrinsic
14765 @code{TIME()} (unless a command-line option that prevents such
14766 treatment has been specified).
14767
14768 As a result, the program @samp{SAMP} will @emph{not}
14769 invoke the @samp{TIME} function in the same source file.
14770
14771 Since @code{g77} recognizes @code{libU77} procedures as
14772 intrinsics, and since some existing code uses the same names
14773 for its own procedures as used by some @code{libU77}
14774 procedures, this situation is expected to arise often enough
14775 to make this sort of warning worth issuing.
14776
14777 After verifying that the program unit making implicit use
14778 of the intrinsic is indeed written expecting the intrinsic,
14779 add an @samp{INTRINSIC @var{intrinsic}} statement to that
14780 program unit to prevent this warning.
14781
14782 Or, if you believe the program unit is designed to invoke the
14783 program-defined procedure instead of the intrinsic (as
14784 recognized by @code{g77}), add an @samp{EXTERNAL @var{intrinsic}}
14785 statement to the program unit that references the name to
14786 prevent this warning.
14787
14788 This and related warnings are disabled by using
14789 the @samp{-Wno-globals} option when compiling.
14790
14791 Note that this warning is not issued for standard intrinsics.
14792 Standard intrinsics include those described in the FORTRAN 77
14793 standard and, if @samp{-ff90} is specified, those described
14794 in the Fortran 90 standard.
14795 Such intrinsics are not as likely to be confused with user
14796 procedures as intrinsics provided as extensions to the
14797 standard by @code{g77}.
14798
14799 @node LEX
14800 @section @code{LEX}
14801
14802 @noindent
14803 @smallexample
14804 Unrecognized character @dots{}
14805 Invalid first character @dots{}
14806 Line too long @dots{}
14807 Non-numeric character @dots{}
14808 Continuation indicator @dots{}
14809 Label at @dots{} invalid with continuation line indicator @dots{}
14810 Character constant @dots{}
14811 Continuation line @dots{}
14812 Statement at @dots{} begins with invalid token
14813 @end smallexample
14814
14815 Although the diagnostics identify specific problems, they can
14816 be produced when general problems such as the following occur:
14817
14818 @itemize @bullet
14819 @item
14820 The source file contains something other than Fortran code.
14821
14822 If the code in the file does not look like many of the examples
14823 elsewhere in this document, it might not be Fortran code.
14824 (Note that Fortran code often is written in lower case letters,
14825 while the examples in this document use upper case letters,
14826 for stylistic reasons.)
14827
14828 For example, if the file contains lots of strange-looking
14829 characters, it might be APL source code; if it contains lots
14830 of parentheses, it might be Lisp source code; if it
14831 contains lots of bugs, it might be C++ source code.
14832
14833 @item
14834 The source file contains free-form Fortran code, but @samp{-ffree-form}
14835 was not specified on the command line to compile it.
14836
14837 Free form is a newer form for Fortran code.
14838 The older, classic form is called fixed form.
14839
14840 @cindex continuation character
14841 @cindex characters, continuation
14842 Fixed-form code is visually fairly distinctive, because
14843 numerical labels and comments are all that appear in
14844 the first five columns of a line, the sixth column is
14845 reserved to denote continuation lines,
14846 and actual statements start at or beyond column 7.
14847 Spaces generally are not significant, so if you
14848 see statements such as @samp{REALX,Y} and @samp{DO10I=1,100},
14849 you are looking at fixed-form code.
14850 @cindex *
14851 @cindex asterisk
14852 Comment lines are indicated by the letter @samp{C} or the symbol
14853 @samp{*} in column 1.
14854 @cindex trailing comment
14855 @cindex comment
14856 @cindex characters, comment
14857 @cindex !
14858 @cindex exclamation point
14859 (Some code uses @samp{!} or @samp{/*} to begin in-line comments,
14860 which many compilers support.)
14861
14862 Free-form code is distinguished from fixed-form source
14863 primarily by the fact that statements may start anywhere.
14864 (If lots of statements start in columns 1 through 6,
14865 that's a strong indicator of free-form source.)
14866 Consecutive keywords must be separated by spaces, so
14867 @samp{REALX,Y} is not valid, while @samp{REAL X,Y} is.
14868 There are no comment lines per se, but @samp{!} starts a
14869 comment anywhere in a line (other than within a character or
14870 Hollerith constant).
14871
14872 @xref{Source Form}, for more information.
14873
14874 @item
14875 The source file is in fixed form and has been edited without
14876 sensitivity to the column requirements.
14877
14878 Statements in fixed-form code must be entirely contained within
14879 columns 7 through 72 on a given line.
14880 Starting them ``early'' is more likely to result in diagnostics
14881 than finishing them ``late'', though both kinds of errors are
14882 often caught at compile time.
14883
14884 For example, if the following code fragment is edited by following
14885 the commented instructions literally, the result, shown afterward,
14886 would produce a diagnostic when compiled:
14887
14888 @smallexample
14889 C On XYZZY systems, remove "C" on next line:
14890 C     CALL XYZZY_RESET
14891 @end smallexample
14892
14893 The result of editing the above line might be:
14894
14895 @smallexample
14896 C On XYZZY systems, remove "C" on next line:
14897      CALL XYZZY_RESET
14898 @end smallexample
14899
14900 However, that leaves the first @samp{C} in the @code{CALL}
14901 statement in column 6, making it a comment line, which is
14902 not really what the author intended, and which is likely
14903 to result in one of the above-listed diagnostics.
14904
14905 @emph{Replacing} the @samp{C} in column 1 with a space
14906 is the proper change to make, to ensure the @code{CALL}
14907 keyword starts in or after column 7.
14908
14909 Another common mistake like this is to forget that fixed-form
14910 source lines are significant through only column 72, and that,
14911 normally, any text beyond column 72 is ignored or is diagnosed
14912 at compile time.
14913
14914 @xref{Source Form}, for more information.
14915
14916 @item
14917 The source file requires preprocessing, and the preprocessing
14918 is not being specified at compile time.
14919
14920 A source file containing lines beginning with @code{#define},
14921 @code{#include}, @code{#if}, and so on is likely one that
14922 requires preprocessing.
14923
14924 If the file's suffix is @samp{.f}, @samp{.for}, or @samp{.FOR},
14925 the file normally will be compiled @emph{without} preprocessing
14926 by @code{g77}.
14927
14928 Change the file's suffix from @samp{.f} to @samp{.F}
14929 (or, on systems with case-insensitive file names,
14930 to @samp{.fpp} or @samp{.FPP}),
14931 from @samp{.for} to @samp{.fpp},
14932 or from @samp{.FOR} to @samp{.FPP}.
14933 @code{g77} compiles files with such names @emph{with}
14934 preprocessing.
14935
14936 @pindex cpp
14937 @cindex preprocessor
14938 @cindex cpp program
14939 @cindex programs, cpp
14940 @cindex @samp{-x f77-cpp-input} option
14941 @cindex options, @samp{-x f77-cpp-input}
14942 Or, learn how to use @code{gcc}'s @samp{-x} option to specify
14943 the language @samp{f77-cpp-input} for Fortran files that
14944 require preprocessing.
14945 @xref{Overall Options,,gcc,Using and Porting GNU CC}.
14946
14947 @item
14948 The source file is preprocessed, and the results of preprocessing
14949 result in syntactic errors that are not necessarily obvious to
14950 someone examining the source file itself.
14951
14952 Examples of errors resulting from preprocessor macro expansion
14953 include exceeding the line-length limit, improperly starting,
14954 terminating, or incorporating the apostrophe or double-quote in
14955 a character constant, improperly forming a Hollerith constant,
14956 and so on.
14957
14958 @xref{Overall Options,,Options Controlling the Kind of Output},
14959 for suggestions about how to use, and not use, preprocessing
14960 for Fortran code.
14961 @end itemize
14962
14963 @node GLOBALS
14964 @section @code{GLOBALS}
14965
14966 @noindent
14967 @smallexample
14968 Global name @var{name} defined at @dots{} already defined@dots{}
14969 Global name @var{name} at @dots{} has different type@dots{}
14970 Too many arguments passed to @var{name} at @dots{}
14971 Too few arguments passed to @var{name} at @dots{}
14972 Argument #@var{n} of @var{name} is @dots{}
14973 @end smallexample
14974
14975 These messages all identify disagreements about the
14976 global procedure named @var{name} among different program units
14977 (usually including @var{name} itself).
14978
14979 Whether a particular disagreement is reported
14980 as a warning or an error
14981 can depend on the relative order
14982 of the disagreeing portions of the source file.
14983
14984 Disagreements between a procedure invocation
14985 and the @emph{subsequent} procedure itself
14986 are, usually, diagnosed as errors
14987 when the procedure itself @emph{precedes} the invocation.
14988 Other disagreements are diagnosed via warnings.
14989
14990 @cindex forward references
14991 @cindex in-line code
14992 @cindex compilation, in-line
14993 This distinction, between warnings and errors,
14994 is due primarily to the present tendency of the @code{gcc} back end
14995 to inline only those procedure invocations that are
14996 @emph{preceded} by the corresponding procedure definitions.
14997 If the @code{gcc} back end is changed
14998 to inline ``forward references'',
14999 in which invocations precede definitions,
15000 the @code{g77} front end will be changed
15001 to treat both orderings as errors, accordingly.
15002
15003 The sorts of disagreements that are diagnosed by @code{g77} include
15004 whether a procedure is a subroutine or function;
15005 if it is a function, the type of the return value of the procedure;
15006 the number of arguments the procedure accepts;
15007 and the type of each argument.
15008
15009 Disagreements regarding global names among program units
15010 in a Fortran program @emph{should} be fixed in the code itself.
15011 However, if that is not immediately practical,
15012 and the code has been working for some time,
15013 it is possible it will work
15014 when compiled with the @samp{-fno-globals} option.
15015
15016 The @samp{-fno-globals} option
15017 causes these diagnostics to all be warnings
15018 and disables all inlining of references to global procedures
15019 (to avoid subsequent compiler crashes and bad-code generation).
15020 Use of the @samp{-Wno-globals} option as well as @samp{-fno-globals}
15021 suppresses all of these diagnostics.
15022 (@samp{-Wno-globals} by itself disables only the warnings,
15023 not the errors.)
15024
15025 After using @samp{-fno-globals} to work around these problems,
15026 it is wise to stop using that option and address them by fixing
15027 the Fortran code, because such problems, while they might not
15028 actually result in bugs on some systems, indicate that the code
15029 is not as portable as it could be.
15030 In particular, the code might appear to work on a particular
15031 system, but have bugs that affect the reliability of the data
15032 without exhibiting any other outward manifestations of the bugs.
15033
15034 @node LINKFAIL
15035 @section @code{LINKFAIL}
15036
15037 @noindent
15038 @smallexample
15039 If the above command failed due to an unresolved reference
15040 to strtoul, _strtoul, bsearch, _bsearch, or similar, see
15041 [info -f g77 M LINKFAIL] (a node in the g77 documentation)
15042 for information on what causes this, how to work around
15043 the problem by editing $@{srcdir@}/proj.c, and what else to do.
15044 @end smallexample
15045
15046 @xref{Missing strtoul or bsearch}, for more information on
15047 this problem,
15048 which occurs only in releases of @code{g77}
15049 based on @code{gcc}.
15050 (It does not occur in @code{egcs}.)
15051
15052 On AIX 4.1, @code{g77} might not build with the native (non-GNU) tools
15053 due to a linker bug in coping with the @samp{-bbigtoc} option which
15054 leads to a @samp{Relocation overflow} error.  The GNU linker is not
15055 recommended on current AIX versions, though; it was developed under a
15056 now-unsupported version.  This bug is said to be fixed by `update PTF
15057 U455193 for APAR IX75823'.
15058
15059 Compiling with @samp{-mminimal-toc}
15060 might solve this problem, e.g.@: by adding
15061 @smallexample
15062 BOOT_CFLAGS='-mminimal-toc -O2 -g'
15063 @end smallexample
15064 to the @code{make bootstrap} command line.
15065
15066 @node Y2KBAD
15067 @section @code{Y2KBAD}
15068 @cindex Y2K compliance
15069 @cindex Year 2000 compliance
15070
15071 @noindent
15072 @smallexample
15073 Intrinsic `@var{name}', invoked at (^), known to be non-Y2K-compliant@dots{}
15074 @end smallexample
15075
15076 This diagnostic indicates that
15077 the specific intrinsic invoked by the name @var{name}
15078 is known to have an interface
15079 that is not Year-2000 (Y2K) compliant.
15080
15081 @xref{Year 2000 (Y2K) Problems}.
15082
15083 @end ifset
15084
15085 @node Index
15086 @unnumbered Index
15087
15088 @printindex cp
15089 @summarycontents
15090 @contents
15091 @bye