PDA

View Full Version : Re: [LF] SIZE intrinsic


Lahey Support
08-15-2003, 01:24 AM
Claudio Ona wrote:

> Aleksandar,
>
> I think that the problem is that PARAMETER values must be resolved
> at compile time. Your 2nd example works fine because SIZE() is assigned
> at run-time. At compile time there is no way to know the SIZE() of a
> subroutine argument.

Thanks,

The way I understand the standard (it almost never even referrs to compile- or run-time,
concepts which appear in practice, but not in the formal definitions), PARAMETER is a
"named constant, a value that will not change during the execution of the program". Now, I
like using PARAMETER as in my example because the compiler checks that a value is not
assigned to a parameter during the program. In other words, it protects from programmer
errors.

Also, it is perfectly valid to have something like:
SUBROUTINE Test(array)
REAL, DIMENSION(:) :: array
! Here is the statement that lf95 considers a bad specification
statement:
REAL, DIMENSION(SIZE(array)) :: new_array
....
END SUBROUTINE Test
which looks much better and less error-prone when written as:
SUBROUTINE Test(array)
REAL, DIMENSION(:) :: array
! Here is the statement that lf95 considers a bad specification
statement:
INTEGER, PARAMETER :: array_size=SIZE(array)
REAL, DIMENSION(array_size) :: new_array
....
END SUBROUTINE Test
(NOTE: The above does not work even without the PARAMETER attribute, lf95 again says that
there is an invalid argument to SIZE. May be a bug!)

Don't you agree? Maybe a standard supplementation is a good idea.

Thanks,
Aleksandar

--
_____________________________________________
Donev Aleksandar
[address removed]
Physics Department, Michigan State University
(517) 432-6770
_____________________________________________


-----------------------------------------------------
To unsubscribe from the Fortran Forum, send a message
to [address removed] with the following command as
the first and only line of the message body:
unsubscribe fortran
-----------------------------------------------------