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

Re: brackets as array constructors, intel vs. gfortran

349 views
Skip to first unread message
Message has been deleted

Richard Weed

unread,
Jul 6, 2019, 3:12:26 PM7/6/19
to
On Saturday, July 6, 2019 at 1:28:01 PM UTC-5, ygal klein wrote:
> Hi,
> Is the following way to assign values to an array using brackets as array constructors against the standard?
>
> The following code is compiled successfully using intel compiler 2019 but gfortran 9.1 results with a compilation error stating that there is a 'syntax error in array constructor'.
>
> Example code:
>
> program test
> implicit none
> integer, parameter :: length
> real(8), dimension(length) :: a
> a(:) = [1:length]
> write(*, *) a(:)
> end program test
>
> Intel compiler succeedes in compiling and gfortran fails.
>
> I would be glad to know why is that.
>
> Thanks!

Unless this is something new in Fortran 2018, I think Intel is wrong but you
never know.

The safest thing to do is the standard way ie

replace

a(:) = [1:length]

with

integer :: i

a(:) = [(REAL(i,8), i=1,length)]

assuming length actually has a value which it doesn't in your
example. The brackets are just a slightly easier way of using array constructors compared to the original f90 syntax ie (/ /). Don't assume they work like matlab or other languages however even though they look like matlab's constructor syntax.

ygal klein

unread,
Jul 6, 2019, 3:15:39 PM7/6/19
to
Hi,
First, Thanks!

Second, I am sorry for the typo in assigning length a value.
Assume length has been assigned.

Intel - succeeds (!) in compiling and the result seems right.
gfortran does not compile.

Is the way I wrote is against the standard?

Thanks.

steve kargl

unread,
Jul 6, 2019, 3:59:22 PM7/6/19
to
yes. Read what Richard wrote.

--
steve

Message has been deleted

Steve Lionel

unread,
Jul 6, 2019, 4:55:43 PM7/6/19
to
On 7/6/2019 2:27 PM, ygal klein wrote:
> Hi,
> Is the following way to assign values to an array using brackets as array constructors against the standard?
>
> The following code is compiled successfully using intel compiler 2019 but gfortran 9.1 results with a compilation error stating that there is a 'syntax error in array constructor'.
>

D:\Projects>ifort /stand t.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on
Intel(R) 64, Version 19.0.4.245 Build 20190417
Copyright (C) 1985-2019 Intel Corporation. All rights reserved.

t.f90(5): warning #7120: The lo:high[:stride] array constructor syntax
is not standard Fortran 2008.
a(:) = [1:length]
^
As noted, this is an extension. I don't know if it was from an earlier
standards draft or a local invention. (If the latter, my guess is that
it was done by Compass, whose F90 front-end was acquired by DEC and
adapted for DEC Fortran 90.) It is described (as an extension) in the
Intel documentation section on array constructors.

A suggestion - if in the future you are uncertain that a particular
usage is valid, even though a compiler accepts it, try turning on
standards checking and see what it says.

By the way, the code you posted wouldn't compile with Intel either as
you omitted the initializer for *length*.

--
Steve Lionel
Retired Intel Fortran developer/support
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
LinkedIn: https://www.linkedin.com/in/stevelionel
Blog: http://intel.com/software/DrFortran

ygal klein

unread,
Jul 6, 2019, 5:01:55 PM7/6/19
to
Thanks Steve.

As I wrote, the assignment of a value to length was mistakenly omitted when writing the post.

The original code included it - of course.

robin....@gmail.com

unread,
Jul 7, 2019, 3:43:56 AM7/7/19
to
On Sunday, July 7, 2019 at 4:28:01 AM UTC+10, ygal klein wrote:
> Hi,
> Is the following way to assign values to an array using brackets as array constructors against the standard?
>
> The following code is compiled successfully using intel compiler 2019 but gfortran 9.1 results with a compilation error stating that there is a 'syntax error in array constructor'.
>
> Example code:
>
> program test
> implicit none
> integer, parameter :: length
> real(8), dimension(length) :: a
> a(:) = [1:length]

LENGTH is undefined.
0 new messages