- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The following code is rejected by the ifort compiler.
implicit none type t integer :: i = 0 end type type(t) :: a do a%i = 1, 10 print *,'something' enddo end
Looking at the standard, I saw no constraint about the do-variable (other than being of integer type), but gfortran also rejects the code. Am I missing something?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The 2008 standard says "C812 (R819) The do-variable shall be a variable of type integer." and "R819 do-variable is scalar-int-variable-name", which may be interpreted to mean that an element of an array of integers or an integer component of a derived type may not be accepted. The similar program
implicit none integer i(2) do i(2) = 1, 10 print *,'something' enddo end
causes the Intel compiler to emit the following erudite messages:
cdo.f90(5): error #5082: Syntax error, found IDENTIFIER 'I' when expecting one of: ( % [ : . = => do i(2) = 1, 10 ---^ cdo.f90(5): error #5082: Syntax error, found ',' when expecting one of: <END-OF-STATEMENT> ; do i(2) = 1, 10 -----------^ cdo.f90(5): error #6404: This name does not have a type, and must have an explicit type. [DO] do i(2) = 1, 10 ^ cdo.f90(5): error #6460: This is not a field name that is defined in the encompassing structure. do i(2) = 1, 10 ---^ cdo.f90(7): error #6099: An ENDDO statement occurred without a corresponding DO or DO WHILE statement. enddo ^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oddly, the following will work, and a%i takes on the correct values:
implicit none type t integer :: i = 0 end type type(t) :: a associate (i => a%i) do i = 1, 10 print *,'something' enddo end associate end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not odd at all. With ASSOCIATE, i is a named scalar-integer-variable which is "construct associated" with a%i. It's similar to passing a%i as an argument to a subroutine that uses the corresponding dummy argument as a DO variable.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page