Array constructor with type-spec

Array constructor with type-spec

Hi,

According to The Fortran 2003 handbook (Adams, Brainerd, Hendricksson), p. 112, it should be possible to declare the type of an array as
[ type-spec :: ac-value-list ]
Apparently type specification is not supported by ifort. For instance, this code fails to compile:
>>>>>>>>>>>>>>>>>>>>>>>>>>
program test
implicit none
type a
integer :: b
end type

type(a) :: c(2)

c=[type(a) :: a(b=2),a(b=3)]

end program
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Am I doing something wrong? Are there plans to implement this feature?

8 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

The syntax you want is:

c = [a:: a(b=2),a(b=3)]

though in this case the type-spec is not required. In general, the Intel compiler does support a type-spec in array constructors but for some reason doesn't here. I'll ask the developers why. You would more likely want to use a type-spec in something like:

[real::1,2,3,4,5]

or

[character(5)::'a','ab','abc','abcd','abcde']

Intel Fortran, as an extension, allows the latter without the type-spec.

I'm not entirely sure what use a derived type here is since the standard requires that all ac-values be of that type.

Steve - Intel Developer Support

> The syntax you want is:

> c = [a:: a(b=2),a(b=3)]

Are you 100% sure? Other compilers work fine, plus type() appears everytime a user-derived type is used in the same context as an intrinsic type.

>I'm not entirely sure what use a derived type here is since the standard requires that all ac-values be of that >type.

It is not the most crucial thing, definitely. But on one hand, for the sake of clarity, but most importantly, if implicit type conversion is used.

Thanks,

Sergio

Sorry, you are right. It should be TYPE(a). Escalated as DPD200166644.

There is no implicit type conversion in the language and the standard is quite explicit saying "C4105 (R 469) If type-spec specifies a derived type, all ac-value expressions in the array-constructor shall be of that derived type and shall have the same kind type parameters as specified by type-spec."

Steve - Intel Developer Support

Thanks for clearing that :) I guess that my first contribution was just being a bit of a quibbler...

The syntax you presented for the array-constructor in reply #1 (just "type-name ::", not "TYPE(type-name) ::") seems more consistent with the rules in the standard for an array-constructor.

This is old news, but I now can confirm that the syntax that Steve mentioned ( [a ::], not [type(a) ::] ) is the correct one. So you can scrap DPD200166644.

Best regards,

Sergio

My earlier reply was wrong. As you say, the legal syntax is a:: not type(a)::. Nevertheless, ifort doesn't like the valid syntax either, in my tests.

program U81063

type a
  character(3) :: s
end type a

type(a), dimension(2) :: c

c = [a(s='FAI'),a(s='LED')]  ! This is accepted
c = [a :: a(s='PAS'),a(s='SED')] ! This fails

print '(2A3)',c%s

end program u81063

U81063.f90(10): error #5082: Syntax error, found '::' when expecting one of: , (/ : ]
c = [a :: a(s='PAS'),a(s='SED')] ! This fails
-------^
U81063.f90(10): error #6478: A type-name must not be used as a variable.   [A]c = [a :: a(s='PAS'),a(s='SED')] ! This fails

Steve - Intel Developer Support

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi