vector expression question.
Arjen Markus
arjen.markus895@gmail.com
Fri Nov 18 09:24:00 GMT 2011
2011/11/17 Tobias Burnus <burnus@net-b.de>:
> Mike Kumbera wrote:
>>
>> I would like to start out with I'm not sure if this is a bug or not... The
>> program bellow computes xser and x and I expected them to have the same
>> answer. They didn't.
>> The results with 4.6.1 were xser(:) = 2 and x(:)=1.
>
> It's a bug - but not in the compiler(s) but in your program.
>
> The code in question is:
> integer :: x
> x = 0
> x ([1,2,3,4,5,5,4,3,2,1]) = x ([1,2,3,4,5,5,4,3,2,1]) + 1
>
> A simpler example would be:
> x ( [1, 1] ) = [ 1, 2 ]
> Should this assign "1" or "2" to X(1)? Well, the standard takes a simple way
> out be declaring:
>
> "If a vector subscript has two or more elements with the same value, an
> array section with that vector subscript shall not appear in a variable
> definition context (16.6.7)." [Fortran 2008, 6.5.3.3.2 Vector subscript]
>
> Tobias
>
The standard expresses it in a rather formal way, but the error is
simply that your i vector has two occurrences of the value 1. So you
should not use it as a vector-valued index on the left-hand side of
an assignment.
Regards,
Arjen
More information about the Fortran
mailing list