Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
27153 Discussions

ALLOCATE() works when type-spec is specified for CHARACTER in mixed-type statement

ur
Beginner
666 Views

 

I believe this program should produce an error and it does not


program testit
implicit none
character(len=:),allocatable :: s(:)
integer,allocatable :: i(:)
real,allocatable :: r(:)
allocate(character(len=20) :: s(10), i(10), r(10))
write(*,*)size(i),size(r),size(s),len(s)
end program testit
(test1) urbanjs@venus:~/github/bugs$ ifort x1.f90
(test1) urbanjs@venus:~/github/bugs$ ./a.out
10 10 10 20

 

If I try something with other mixed types in an ALLOCATE like

allocate(integer :: i(10),r(10))

I get an error like:

! x1.f90(7): error #8235: If type specification appears, the type and kind
! type parameters of each object being allocated must be the same as type
! and kind type parameters of the type specification. [R]

 

 

0 Kudos
6 Replies
andrew_4619
Honored Contributor I
614 Views

allocate(integer :: size(i), size(r))  does not make sense to me, is that what you intended to write?

 

ur
Beginner
606 Views

No.  Something like "allocate(integer ::  i(10), r(10))" where

integer,allocatable :: i(:)

real,allocatable :: r(:)

 

Just noting that other ALLOCATE(3f) statements do produce an error when a type-spec is present, but the one in the example code does not.

 

Arjen_Markus
Valued Contributor III
599 Views

Well, the first allocate you showed (allocate (character(30) :: ... ) allocates two character arrays, the type specification is for the length of the character strings, but each array is of the same basic type. That is not the case with the second one: you specify the type as integer, but the second array is a real array, so a different basic type.

ur
Beginner
587 Views

allocate(character(len=20) :: s(10), i(10), r(10))

 

is the line I am saying is non-standard, where S is character, I is integer, R is real, but there is a type-spec. Per the cited statement from the standard and after discussion on other forums that line is non-standard.  If Ifort was providing an extension then I would expect other statements with mixed types to work also, but instead get an error message if the type-spec is INTEGER or REAL; indicating the line with the CHARACTER type-spec is being ignored inadvertently and that this is not an intentional extension.

FortranFan
Honored Contributor II
528 Views

Readers are encouraged to read this thread at Fortran Discourse site.

I do wish OP had gone with a really short illustration of the issue e.g.,

   character(len=:), allocatable :: s
   integer, allocatable :: i
   allocate( character :: s, i )
end

 

Intel team: please note a support request #05231947 has already been submitted with this short case at the Intel OSC.

Igor_V_Intel
Employee
459 Views

It is escalated to the Intel Fortran development team and should be fixed. Note that same behaviour is observed with ifx (LLVM based Fortran compiler).


Reply