Re: Use string syntax with array



David Frank wrote:
I posted below yesterday morning and it never appeared in the newsgroup,
so I am posting it again
=================

"*** Hendrickson" <***.hendrickson@xxxxxxx> wrote in message
news:Neryg.185744$mF2.23642@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I've lost track of the original program, but as I recall,
you declare a as a character with length 1 variable. The
Fortran 2003 rule is that all type parameters of the pointer
must be the same as the type parameters of the target. It's
on page 144, line 22. It's little hard to read because it's
mixed in with a lot of polymorphic stuff. But, the meaning
is clear. If "a" is a length 1 variable, then vstring must
also have a length of 1. Declaring it as 9999 just creates
a run-time error at the pointer assignment. It doesn't
matter whether or not the compiler detects it, it's still
an error and will not be portable.

Someone else (Rich?) asked about how vstring could be a
scalar and point to an array. In the line above, it's
not pointing to an array; it's pointing to a single array
element (which is a scalar thing). I hope I remembered the
question correctly, my newsreader really messed things up.

*** Hendrickson

re: lost track of code...
below is a simplified version.
I think theres a case to be made that CVF's developers interpreted
it differently than you.

The fact remains that below compiles/runs fine with CVF6.6c with or without
bounds checking..
Obvious that they interprete s => a(1) as valid, since both are
character type and scalars.

Would someone try below with Intel Fortran ?

! -----------------------
program Use_string_syntax_with_array
character,allocatable,target :: a(:)
character(9999),pointer :: s
n = 30 ; allocate (a(n))
s => a(1) ! point string to array start
s(:n) = 'the quick brown fox' ! load array using string syntax
write (*,*) a
write (*,*) s(:n) ! use string syntax to access array chars
end program



Nope, this has already appeared; maybe there's something up with your newsreader. My response:

"I find that this compiles and executes with Intel Fortran. Whereas, Lahey lf95 (quite rightly) will not even compile the code:

2005-W: "frank.f90", line 4: 'a' is used but never set.
2394-S: "frank.f90", line 5, column 6: Target of pointer assignment must be of the same type, type parameters, and rank as the pointer.
Encountered 1 error, 1 warning in file frank.f90.

This underlines how unwise it is to assume that, because code works with a given compiler/platform, it must be standard."

cheers,

Rich


.