Re: error in sun, ok in ifort



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
.



Relevant Pages

  • Re: Cohens paper on byte order
    ... > depend on the applicability of the common hex notation. ... bit sequence, there is a bit-order-within-unit issue for ... *any* multibit storage units, not just octet units, and ... fact true of almost all data storage and transmission ...
    (sci.crypt)
  • Re: World Moonie Herald: The challenge to Darwins theory of evolution - 5
    ... Denton presented his critique of neo-Darwinism based on the latest ... all types of cytochrome-c is similar and therefore common. ... amino-acid sequence differs according to organisms. ...
    (talk.origins)
  • Re: Cantors definition of set
    ... I would not like to say that they have anything in common. ... of the signs we use to portray numbers, ... arranged in a sequence and not numbers after all? ...
    (sci.logic)
  • Re: Article: On the Origins of Chemical Biodefense
    ... >> There is a controversy in the field of molecular evolution. ... >> of sequence similarity could be lost in regions that must preserve ... > It's very strange to hear Larry arguing for convergence - this is the ... a common and important mechanism of evolution. ...
    (sci.bio.evolution)
  • Re: Fortran calls a C function that returns a struct
    ... | at the beginning to the derived type definition. ... However, there's a practical problem with SEQUENCE, which ... There are probably workarounds with compiler switches. ...
    (comp.lang.fortran)