C:\gfortran\clf\quadtest>type kindtest.f90
program kindtest
use ISO_FORTRAN_ENV
implicit none
integer i
REAL_KINDS(1) = 42
i = sum([(kind(real(0,REAL_KINDS(i))),i=1,size(REAL_KINDS))])
write(*,*) i
end program kindtest
C:\gfortran\clf\quadtest>gfortran kindtest.f90 -okindtest
kindtest.f90:6.3:
REAL_KINDS(1) = 42
1
Error: Named constant 'real_kinds' in variable definition context
(assignment) a
t (1)
kindtest.f90:7.25:
i = sum([(kind(real(0,REAL_KINDS(i))),i=1,size(REAL_KINDS))])
1
Error: 'kind' argument of 'real' intrinsic at (1) must be a constant
Now, if the first error statement is correct, then the array
REAL_KINDS is a named constant and of course i is a constant because
it's an ac-do-variable. N1830.pdf, section 7.1.12 says:
"A constant expression is an expression with limitations that make
it suitable for use as a kind type parameter, initializer, or named
constant. It is an expression in which each operation is intrinsic,
and each primary is
...
(11) an ac-do-variable within an array constructor where each scalar-
int-expr of the corresponding ac-implied-do-control is a constant
expression"
That makes REAL_KINDS(i) a constant, so the second error message would
be incorrect.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
Not at all. Fortran has the concept of read-only variables. Some
languages have only constants and writable variables, but Fortran
is not one (and nor is C).
Regards,
Nick Maclaren.
>>Consider the following program:
I reinstate:
>>kindtest.f90:6.3:
>>
>> REAL_KINDS(1) = 42
>> 1
>>Error: Named constant 'real_kinds' in variable definition context
>>(assignment) a
>>t (1)
Where the first error message calls 'real_kinds' a named constant,
not a variable with the PROTECTED attribute. The array wouldn't be
all that useful if it weren't a named constant because then you
couldn't use it elements as KIND parameters.