[comp.lang.fortran] RE : MSFORTRAN - bugs !!!!

pdy@sun.soe.clarkson.edu (P. D. Yapa) (04/11/90)

I had trouble passing a string variable though
subroutine arguments. It never works on MSFORT

eg.

c --- main prog
        character *8 fnm


        call opnfil('ross.fnm')

---------
       subroutine opnfil(fnm)
       character *8 fnm

       open (--------------
           do ---------
              read (-----------
              open ( ----------

This does work on our main frame compiler.

Does anyone know whether fort 77 standard allows this  ?
--------------------------------------------------------
Pooji Yapa                  <  pdy.sun.soe.clarkson.edu > 
Civil & Envi. Engg.
Clarkson University
Potsdam, NY 13676

maine@elxsi.dfrf.nasa.gov (Richard Maine) (04/12/90)

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]

silvert@cs.dal.ca (Bill Silvert) (04/14/90)

In article <MAINE.90Apr11111830@altair.dfrf.nasa.gov> maine@elxsi.dfrf.nasa.gov (Richard Maine) writes:
>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
	[... much deleted ...]
>characters and it makes no sense to have fewer, it is better to write
>the code as
>       -----
>       subroutine opnfil(fnm)
>       character fnm*(*)
>       ---

Exactly.  Although I have never used the fixed-length format in the
original example, I have thousands of lines of code that do extensive
string passing, and no Fortran-77 compiler has ever choked on a
declaration of the form of:

	SUBROUTINE SUB(STRING)
	CHARACTER*(*) STRING

and I can see no need to specify fixed-length strings (an exception that
I have used successfully is a string of length one).

-- 
William Silvert, Habitat Ecology Division, Bedford Inst. of Oceanography
P. O. Box 1006, Dartmouth, Nova Scotia, CANADA B2Y 4A2.  Tel. (902)426-1577
UUCP=..!{uunet|watmath}!dalcs!biomel!bill
BITNET=bill%biomel%dalcs@dalac	InterNet=bill%biomel@cs.dal.ca

ngse18@castle.ed.ac.uk (J R Evans) (04/14/90)

In article <1990Apr13.205055.23252@cs.dal.ca> bill@biomel.UUCP writes:
>I have thousands of lines of code that do extensive
>string passing, and no Fortran-77 compiler has ever choked on a
>declaration of the form of:
>
>	SUBROUTINE SUB(STRING)
>	CHARACTER*(*) STRING
>

IMHO, you are fortunate, Bill.  I used to work a lot with the DEC RT-11
FORTRAN-77 compiler (and still do).  This beast was ported from RSX-11
by Multiware.  It will not accept CHARACTER*(*) declarations.  The
reason is that within the RT11 system, quoted strings are passed in
null-terminated form, and there is simply no way to pass string length
information across this subroutine interface without breaking
something, if only the system library.  The writers elected not to
implement some FORTRAN-77 string handling capabilities.

Since the subroutine call format is standard across all PDP-11s,
I guess that the same may be true for some other PDP compilers.  In
defence of DEC and before somebody starts shouting that such compilers
are broken, I seem to recall that the F77 standard lists specific
subsets which compilers can choose to conform to and still describe
themselves as partially conforming.  I believe that that is all that DEC
claim to offer for RT-11.

My own code is littered with C#ifdef RT11  ... constructs for a
preprocessor I was planning to write :-(

Russ Evans
British Geological Survey          e_gs18@va.nmh.ac.uk (Internet/Bitnet)