📄 f77
字号:
as in the following example:.DS Ireal a(4)double precision b,c.sp .5equivalence (a(1),b), (a(4),c).DESome machines (e.g., Honeywell 6000, IBM 360) require that double precision quantities be on double word boundaries;other machines (e.g., IBM 370), run inefficiently if this alignment rule is not observed.It is possible to tell which equivalenced and common variables suffer from a forced oddalignment, but every double precision argument would have to be assumed on a bad boundary.To load such a quantity on some machines,it would be necessary to use separate operations to move the upper and lower halvesinto the halves of an aligned temporary, then to load that double precision temporary; the reverse would beneeded to store a result.We have chosen to require that all double precision real and complex quantitiesfall on even word boundaries on machines with corresponding hardware requirements,and to issue a diagnostic if the source code demands a violation of the rule..NH 2Dummy Procedure Arguments.IPIf any argument of a procedure is of type character,all dummy procedure arguments of that procedure must be declaredin an.B externalstatement.This requirement arises as a subtle corollary of the way we represent character string argumentsand of the one-pass nature of the compiler.A warning is printed if a dummy procedure is not declared.B external.Code is correct if there are no.B characterarguments..NH 2T and TL Formats.IPThe implementation of the.B t(absolute tab)and.B tl(leftward tab)format codesis defective.These codes allow rereading or rewriting part of therecord which has already been processed.(Section 6.3.2 in the Appendix.)The implementation uses seeks,so if the unit is not one which allows seeks,such as a terminal,the program is in error.(People who can make a case for using.B tlshould let us know.)A benefit of the implementation chosen isthat there is no upper limit on the length ofa record,nor is it necessary to predeclare any recordlengths except where specifically requiredby Fortran or the operating system..NH 1INTER-PROCEDURE INTERFACE.PPTo be able to write C procedures that call or are called by Fortran procedures,it is necessary to know the conventions for procedure names,data representation,return values,and argument lists that the compiled code obeys..NH 2Procedure Names.PPOn.UXsystems,the name of a common block or a Fortran procedurehas an underscore appended to it by the compilerto distinguish it from a C procedure or external variablewith the same user-assigned name.Fortran library procedure names have embedded underscores to avoid clasheswith user-assigned subroutine names..NH 2Data Representations.PPThe following is a table of corresponding Fortran and C declarations:.KS.TScenter;c cl l.Fortran C.sp .5integer\(**2 x short int x;integer x long int x;logical x long int x;real x float x;double precision x double x;complex x struct { float r, i; } x;double complex x struct { double dr, di; } x;character\(**6 x char x[6];.TE.KE(By the rules of Fortran,.B integer,.B logical,and.B realdata occupy the same amount of memory)..NH 2Return Values.PPA function of type.B integer,.B logical,.B real,or.B "double precision"declared as a C function that returns the corresponding type.A.B complexor.B "double complex"function is equivalent to a C routinewith an additionalinitial argument that points to the place where the return value is to be stored.Thus,.DScomplex function f( . . . ).DEis equivalent to.DSf_(temp, . . .)struct { float r, i; } \(**temp; . . ..DE.DEA character-valued function is equivalent to a C routine withtwo extra initial arguments:a data address and a length.Thus,.DScharacter\(**15 function g( . . . ).DEis equivalent to.DSg_(result, length, . . .)char result[ ];long int length; . . ..DEand could be invoked in C by.DSchar chars[15]; . . .g_(chars, 15L, . . . );.DESubroutines are invoked as if they were \fBinteger\fR-valued functionswhose value specifies which alternate return to use.Alternate return arguments (statement labels) are not passed to the function,but are used to do an indexed branch in the calling procedure.(If the subroutine has no entry points with alternate return arguments,the returned value is undefined.)The statement.DScall nret(\(**1, \(**2, \(**3).DEis treated exactly as if it were the computed.B goto.DSgoto (1, 2, 3), nret( ).DE.NH 2Argument Lists.PPAll Fortran arguments are passed by address.In addition,for every argument that is of type character orthat is a dummy procedure,an argument giving the length of the value is passed.(The string lengths are.B "long int"quantities passed by value).The order of arguments is then:.DSExtra arguments for complex and character functionsAddress for each datum or functionA \fBlong int\fR for each character or procedure argument.DEThus, the call in.DSexternal fcharacter\(**7 sinteger b(3) . . .call sam(f, b(2), s).DEis equivalent to that in.DSint f();char s[7];long int b[3]; . . .sam_(f, &b[1], s, 0L, 7L);.DENote that the first element of a C array always has subscript zero,but Fortran arrays begin at 1 by default.Fortran arrays are stored in column-major order, C arrays are stored in row-major order..NH 1FILE FORMATS.NH 2Structure of Fortran Files.PPFortran requires four kinds of external files:sequential formatted and unformatted,and direct formatted and unformatted.On.UXsystems,these are all implemented as ordinary fileswhich are assumed to have the properinternal structure..PPFortran I/O is based on ``records''.When a direct file is opened in a Fortran program,the record length of the records must be given,and this is used by the Fortran I/O system tomake the file look as if it is made up of recordsof the given length.In the special case that the record length is givenas 1,the files are not considered to be divided into records,but are treated as byte-addressable byte strings;that is,as ordinary.UXfile system files.(A read or write request on such a file keeps consuming bytes untilsatisfied, rather than being restricted to a single record.).PPThe peculiar requirements on sequential unformatted filesmake it unlikely that they will ever be read or written by any means except Fortran I/O statements.Each record is preceded and followed byan integer containing the record's length in bytes..PPThe Fortran I/O system breaks sequential formatted filesinto records while reading by using each newlineas a record separator.The result of reading off the end of a record is undefined according to the Standard.The I/O system is permissive andtreats the record as being extended by blanks.On output,the I/O system will write a newline at the end of eachrecord.It is also possible for programs to write newlinesfor themselves.This is an error,but the only effect will be that the single recordthe user thought he wrote will be treated asmore than one record when being read orbackspaced over..NH 2Portability Considerations.PPThe Fortran I/O system uses only the facilities of thestandard C I/O library,a widely available and fairly portable package,with the following two nonstandard features:The I/O system needs to know whether a filecan be used for direct I/O,and whether or not it is possible to backspace.Both of these facilities are implementedusing the.B fseekroutine,so there is a routine.B canseekwhich determines if.B fseekwill have the desired effect.Also, the.B inquirestatement provides the userwith the ability to find out if two files are thesame,and to get the name of an already opened filein a form which would enable the program to reopenit.(The.UXoperating system implementation attempts to determine the full pathname.)Therefore there are two routines whichdepend on facilities of the operating systemto provide these two services.In any case,the I/O systemruns on the PDP-11, VAX-11/780, and Interdata 8/32.UXsystems..NH 2Pre-Connected Files and File Positions.PPUnits 5, 6, and 0 are preconnected when the program starts.Unit 5 is connected to the standard input,unit 6 is connected to the standard output,and unit 0 is connected to the standard error unit.All are connected for sequential formatted I/O..PPAll the other units are also preconnected when executionbegins.Unit.I nis connected to a file named \fBfort.\fIn\fR.These files need not exist,nor will they be created unless their units are usedwithout first executing an.B open.The default connection is for sequential formatted I/O..PPThe Standard does not specify where a file which has been explicitly \fBopen\fRedfor sequential I/O is initially positioned.In fact,the I/O system attempts to position the file at the end,so a.B writewill append to the file and a.B readwill result in an end-of-file indication.To position a file to its beginning,use a.B rewindstatement.The preconnected units0, 5, and 6 are positioned as they comefrom the program's parent process..SG.SHREFERENCES.LP.IP 1.\fISigplan Notices \fB11\fR, No.3 (1976),as amended in X3J3 internal documents through ``/90.1''..IP 2.\fIUSA Standard FORTRAN, USAS X3.9-1966\fR,New York: United States of America Standards Institute, March 7, 1966.Clarified in\fIComm. ACM \fB12,\fR 289 (1969)and\fIComm. ACM \fB14, \fR 628 (1971)..IP 3.B. W. Kernighan and D. M. Ritchie,.IThe C Programming Language,.REnglewood Cliffs: Prentice-Hall (1978)..IP 4.D. M. Ritchie, private communication..IP 5.S. C. Johnson,``A Portable Compiler: Theory and Practice'',Proc. 5th ACM Symp. on Principles of Programming Languages(January 1978)..IP 6.S. I. Feldman,``An Informal Description of EFL'',internal memorandum..IP 7.B. W. Kernighan,``RATFOR \(em A Preprocessor for a Rational Fortran'',.IBell Laboratories Computing Science Technical Report #55,.R(January 1977)..IP 8.D. M. Ritchie, private communication..bp.SHAPPENDIX. Differences Between Fortran 66 and Fortran 77.PPThe following is a very brief description of the differencesbetween the 1966 [2] and the 1977 [1] Standard languages.We assume that the reader is familiar with Fortran 66.We do not pretend to be complete, precise,or unbiased,but plan to describe what we feel are the most important aspects of the new language.At present the only current information on the 1977 Standard is in publications of the X3J3 Subcommitteeof theAmerican National Standards Institute.The following information is from the ``/92'' document.This draft Standard is written in English rather than a meta-language, but it is forbiddingand legalistic.No tutorials or textbooks are available yet..NH 0Features Deleted from Fortran 66.NH 2Hollerith.IPAll notions of ``Hollerith''(\fIn\|\fBh\fR)as datahave been officially removed, although our compiler, like almost all in the foreseeable future,will continue to support this archaism..NH 2Extended Range.IPIn Fortran 66, under a set of very restrictive and rarely-understood conditions, it is permissibleto jump out of the range of a.B doloop, then jump back into it.Extended range has been removed in the Fortran 77 language.The restrictions are so special, and the implementation of extended range is so unreliable in many compilers,that this change really counts as no loss..NH 1Program Form.NH 2Blank Lines.IPCompletely blank lines are now legal comment lines..NH 2Program and Block Data Statements.IPA main program may now begin with a statement that gives that program an external name:.DSprogram work.DEBlock data procedures may also have names..DSblock data stuff.DEThere is now a rule that only.I oneunnamedblock data procedure may appear in a program.(This rule is not enforced by our system.)The Standard does not specify the effect of the program and block data names,but they are clearly intended to aid conventional loaders..NH 2ENTRY Statement.IPMultiple entry points are now legal.Subroutine and function subprograms may have additional entry points,declared by an.B entrystatement with an optional argument list..DSentry extra(a, b, c).DEExecution begins at the first statement following the.B entryline.All variable declarations must precede all executable statements in the procedure.If the procedure begins with a.B subroutinestatement,all entry points are subroutine names.If it begins with a.B functionstatement, each entry is a function entry point,with type determined by the type declared for the entry name.If any entry is a character-valued function,then all entries must be.In a function, an entry name of the same type as that where control enteredmust be assigned a value.Arguments do not retain their values between calls.(The ancient trick of calling one entry point with a large number of argumentsto cause the procedure to ``remember'' the locations of those arguments,then invoking an entry with just a few arguments for later calculation,is still illegal.Furthermore, the trick doesn't work in our implementation,since arguments are not kept in static storage.).NH 2DO Loops.IP.B dovariables and range parameters may now be of integer, real, or double precision types.(The use of floating point.B dovariables is very dangerousbecause of the possibility of unexpected roundoff,and we strongly recommend against their use).The action of the.B dostatement is now defined for all values of the.B doparameters.The statement.DSdo 10 i = l, u, d.DEperforms$ max (0^,^ left floor ( u - l ) / d^ right floor )$iterations.The.B dovariable has a predictable value when exiting a loop:the value at the time a.B gotoor.B returnterminates the loop;otherwisethe value that failed the limit test..NH 2Alternate Returns
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -