Re: merge of character strings



In article <i1G4k.84350$SV4.74552@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Dick Hendrickson <dick.hendrickson@xxxxxxx> wrote:
John Harper wrote:
PROGRAM testmerge
* What happens in merge(string1,string2,mask) if lengths of strings
* are not known at compile time, but are in fact equal at run time?
INTEGER,PARAMETER:: maxlen=60
CHARACTER:: stuff*(maxlen-2),empty*(maxlen)='a blank string'
PRINT *,'Enter a character string (possibly empty or all blanks)'
READ "(A)",stuff
PRINT *, 'You entered '//merge(empty,
$ '"'//trim(stuff)//'"'//repeat(' ',maxlen-2-len_trim(stuff)),
$ len_trim(stuff)==0)
END PROGRAM testmerge
It looks OK to me. The rules for MERGE say that the two thingos
should have the same type parameters. But that doesn't mean they have
to be known at compile time.
I'd suggest trying a simpler example
PROGRAM testmerge
character*20 a,b
a = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
b = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
something = 12
do
READ(*,*) N,M
PRINT *, n,m, merge(a(1:n), b(1:m), n==something)
enddo
END PROGRAM testmerge

and see what happens with the 4 compilers for various n and m.

Dick's version compiled and ran with all 4 compilers. None complained
at run-time if n /= m, though I did get various results as is permitted
by the standard in that case. Bug reports are on their way to the
compilers that my version found internal errors in.

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 6780 fax (+64)(4)463 5045
.



Relevant Pages

  • Re: Comparision of C Sharp and C performance
    ...     double dif; ... compile time with runtime operations. ... you assume that all C compilers will do the constant division ... you don't evaluate an invariant in a for loop IF the preprocessor ...
    (comp.lang.c)
  • Re: Strange error msg.
    ... All good compilers have an array subscript bounds check ... to a single precision argument, ... easy to do with constants--pass 1.0 to a subroutine that ... the compiler to make a slew of compile time error checks. ...
    (comp.lang.fortran)
  • Illegal internal write?
    ... as that term is used in those Fortran standards? ... END PROGRAM testnoforall ... Five f95 compilers that I tried accepted the program at compile time. ...
    (comp.lang.fortran)
  • Breakem good and hard...
    ... will fail in as many different C compilers as possible, ... time or compile time. ...
    (comp.lang.c)
  • Re: Another C# critique (major rewrite!)
    ... >> In the case of a const implementation I'd prefer compile time ... >> validation for all languages though. ... > familiarize myself with compilers. ...
    (microsoft.public.dotnet.languages.csharp)