Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Which error is correct?

169 views
Skip to first unread message

James Van Buskirk

unread,
Dec 7, 2010, 11:29:35 PM12/7/10
to
Consider the following program:

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


nm...@cam.ac.uk

unread,
Dec 8, 2010, 2:40:40 AM12/8/10
to
In article <idn1jh$7v4$1...@news.eternal-september.org>,
James Van Buskirk <not_...@comcast.net> wrote:
>Consider the following program:

>
>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:
>
>That makes REAL_KINDS(i) a constant, so the second error message would
>be incorrect.

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.

James Van Buskirk

unread,
Dec 8, 2010, 11:02:25 AM12/8/10
to
<nm...@cam.ac.uk> wrote in message news:idncpo$qp8$1...@gosset.csi.cam.ac.uk...

>>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.

0 new messages