[comp.lang.fortran] LEN and CHARACTER arrays.

mckenney@CIMS18.NYU.EDU (Alan M. McKenney) (01/29/91)

Here's a question for all you FORTRAN language lawyers:


	Given a character (dummy argument) array declared

	       CHARACTER*(*) CARRAY(*)

	what is the ANSI-standard-conformant way of getting the length
	of each element?


From reading the standard, I had gotten the impression that
LEN(CARRAY)  was correct, and it works on my Sun workstation, but it
doesn't work on our CONVEX.  Instead, I had to write  LEN(CARRAY(1)).
Is the CONVEX compiler correct?  Or was my impression correct, and
the CONVEX compiler has a bug?  Or is this an area of ambiguity?  The
code I am writing has to be ultra-portable, so it is important what
is standard, rather than just what compilers A, B, and C accept.

Perhaps it would be best to just E-mail me, and I will post the
consensus ("one if by land,...")


Alan McKenney        E-mail:  mckenney@cs.nyu.edu         (INTERNET)
Courant Institute,NYU         ...!cmcl2!cs.nyu.edu!mckenney   (UUCP)

mckenney@CIMS18.NYU.EDU (Alan M. McKenney) (02/01/91)

    In <9101281822.AA03827@cims18.nyu.edu>, I wrote:

>       Given a character (dummy argument) array declared
> 
>              CHARACTER*(*) CARRAY(*)
> 
>       what is the ANSI-standard-conformant way of getting the length
>       of each element?
> 
> 
> From reading the standard, I had gotten the impression that
> LEN(CARRAY)  was correct, and it works on my Sun workstation, but it
> doesn't work on our CONVEX.  Instead, I had to write  LEN(CARRAY(1)).
  ....

I got quite a bit of E-mail, all of it saying, with varying levels of
Authority, that LEN(CARRAY(1)) was correct ANSI FORTRAN-77, and
LEN(CARRAY) was not.  Many thanks to all those who took the trouble
to enlighten me!

Some people also found the standard a little unclear, as I did.
(Others found it quite clear.)  One or two said that LEN can also take
a character expression as an argument (e.g., LEN( 'abc' // CARRAY(2) //
'def' ), I suppose.) A few people said that LEN(CARRAY) would be legal
in FORTRAN-90, though I was unsure whether it would be equivalent to
LEN(CARRAY(1)) or would instead give the number of elements in the
array.  (But that's another question.)

Anyway, thanks again for the advice.


Alan McKenney        E-mail:  mckenney@cs.nyu.edu         (INTERNET)
Courant Institute,NYU         ...!cmcl2!cs.nyu.edu!mckenney   (UUCP)