Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!princeton!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.fortran Subject: Re: Problem with substrings Message-ID: <6944@alice.UUCP> Date: Thu, 4-Jun-87 00:33:45 EDT Article-I.D.: alice.6944 Posted: Thu Jun 4 00:33:45 1987 Date-Received: Sat, 6-Jun-87 06:28:05 EDT References: <286@nikhefh.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 40 In article <286@nikhefh.UUCP>, i91@nikhefh.UUCP writes: > Does somebody know what according to the FORTRAN 77 standard > should happen in the following substring expression: > > CHARACTER*10 CH, STR > > STR = 'ABCDEFGHIJ' > I = 6 > NC = 0 > CH = 'FOO'//STR(I:I+NC-1)//'BAR' This is not a valid Fortran 77 program. On page 5-9 of the Fortran 77 specification, the form of a substring expression is given as v ( e1 : e2 ) where v is a string variable and e1 and e2 are optional integer expressions. e1 gives the index of the first character of the substring and e2 gives the index of the last character. Where len is the length of v, e1 and e2 must be such that 1 <= e1 <= e2 <= len If e1 is omitted, 1 is assumed. If e2 is omitted, len is assumed. In the program fragment given as an example, I is 6 and I+NC-1 is 5. Thus the inequality is not satisfied and the program is invalid. The Fortran 77 language definition says elsewhere that it (the language definition) is restrictive on programs and permissive on implementations. That is: the definition says what is a valid program. A valid implementation is one that does the right thing when given a valid program as input. A fortran 77 implementation is thus permitted to do whatever it pleases with an invalid program, including crash or deliver garbage results.