Re: error in sun, ok in ifort
- From: Tobias Burnus <burnus@xxxxxxxx>
- Date: Sat, 25 Apr 2009 11:58:22 +0200
rudra wrote:
my code while compiling with sunstudio12, gives error:
type(typethread):: threadcontext
^
"thread.f90", Line = 14, Column = 21: ERROR: Object "THREADCONTEXT" is
in a common block and is derived-type "TYPETHREAD". This derived-type
must be a sequence type.
the code is
type::typethread
real*8,dimension(lorbit,lorbit)::ap61,ap71
end type typethread
type(typethread):: threadcontext
common/context/threadcontext
gfortran prints:
type(typethread):: threadcontext
1
Error: Derived type variable 'threadcontext' in COMMON at (1) has
neither the SEQUENCE nor the BIND(C) attribute
* * *
The SUN and gfortran compilers are correct - the Fortran 2003 standard has:
"C589 (R558) If a common-block-object is of a derived type, it shall be
sequence type (4.5.1) or a type with the BIND attribute and it shall
have no default initialization."
The point is: Without SEQUENCE [or BIND(C)], the types
type A
integer :: a
double precision :: b
end type A
and
type B
integer :: a
double precision :: b
end type B
might be put differently into the memory: For instance, "A" could have
first the integer and then the double precision variable while "B" has
first the double precision and then the real variable in memory.
A consistent storage order is only guaranteed using the SEQUENCE or
BIND(C) attribute. Normally, the storage order does not matter, but if
you put such a variable into COMMON you storage associated it with
another variable somewhere else - thus you could have at one place
type(A) :: myA
common /BLOCK/ myA
and somewhere else
type(B) :: myB
common /BLOCK/ myB
And that will break if A and B lie differently in the memory.
Thus, you should really use the SEQUENCE attribute:
type::typethread
SEQUENCE
real*8,dimension(lorbit,lorbit)::ap61,ap71
end type typethread
(Or you could get rid of the COMMON block and simply use the module
variable everywhere. Which is arguably the better method.)
* * *
Regarding the Intel compiler: No compiler is required to detect this;
and compilers can support extensions which allow this. (I wouldn't be
surprised if most compilers use the same storage for sequence and for
"normal" derived types.)
Note: At least my ifort prints with "-stand f03" the warning:
test.f90(14): warning #8129: A common-block-object which is neither a
sequence derived type nor a derived type with the BIND attribute is an
extension of Standard F2003. [THREADCONTEXT]
Tobias
.
- Follow-Ups:
- Re: error in sun, ok in ifort
- From: Richard Maine
- Re: error in sun, ok in ifort
- References:
- error in sun, ok in ifort
- From: rudra
- error in sun, ok in ifort
- Prev by Date: error in sun, ok in ifort
- Next by Date: Re: use module
- Previous by thread: error in sun, ok in ifort
- Next by thread: Re: error in sun, ok in ifort
- Index(es):
Relevant Pages
|