Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ames!skipper!elxsi!maine From: maine@elxsi.dfrf.nasa.gov (Richard Maine) Newsgroups: comp.lang.fortran Subject: Re: RE : MSFORTRAN - bugs !!!! Message-ID: Date: 11 Apr 90 18:18:30 GMT References: <1990Apr11.144430.26803@sun.soe.clarkson.edu> Sender: news@skipper.dfrf.nasa.gov Organization: NASA Dryden, Edwards, Cal. Lines: 65 In-reply-to: pdy@sun.soe.clarkson.edu's message of 11 Apr 90 14:44:30 GMT On 11 Apr 90 14:44:30 GMT, pdy@sun.soe.clarkson.edu (P. D. Yapa) said: Pooji> I had trouble passing a string variable though Pooji> subroutine arguments. It never works on MSFORT Pooji> c --- main prog Pooji> character *8 fnm Pooji> call opnfil('ross.fnm') Pooji> --------- Pooji> subroutine opnfil(fnm) Pooji> character *8 fnm Pooji> Does anyone know whether fort 77 standard allows this ? Yes, that's perfectly legit as you wrote it. Though since the sample isn't complete, there is always the chance that something you didn't show is really the problem. I can't realy tell without dragging out my MS-Fortran compiler and seeing what such codes do. I'd be pretty surprised if passing string variables "never" (your word) works in MSFORT, but I'm not prepared to take the time to check it out at the moment. One comment on your sample, though. There is a possibly subtle problem that has bitten me before. Although the sample you showed was legal (assuming, of course, that subroutine opnfil never changes the value of its argument), the following very minor modification is NOT legal. call opnfil('ros.fnm') --------- subroutine opnfil(fnm) character *8 fnm Do you have trouble noticing the difference? The passed string in this case is only 7 characters long instead of 8. In many contexts like character*8 fnm fnm = 'ros.fnm' it is legal to use shorter strings; the assignment pads with blanks. In the context of argument passing, however, there is no such padding and it is not legal to pass shorter strings than declared. The results are implementation dependent, and often bad. It is not unusual to find the the passed string padded out with garbage, which can be very confusing as in call sub('A') ---- subroutine sub(arg) character arg*2 if (arg.eq.'A') then write (*,*) 'all is cool' else write (*,*) 'oops' endif which is not legal and will usually print "oops" on most systems. Thus, unless fnm is absolutely guaranteed to always have exactly 8 characters and it makes no sense to have fewer, it is better to write the code as ----- subroutine opnfil(fnm) character fnm*(*) --- -- Richard Maine maine@elxsi.dfrf.nasa.gov [130.134.64.6]