Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28632 Discussions

Using ISO_C_BINDING C_PTR type in COMMON block

rforehan
Beginner
722 Views

I'm trying to use the following declaration:

use ISO_C_BINDING

type(C_PTR) handle

COMMON /MyHandle/handle

This generates the following error:

Error: If a common-block-object is of a derived type, it must be of a sequence type (R549.f)

The Fortran help doc only gives an example of using the SEQUENCE statement inside a type definition block. Since C_PTR is defined in the ISO_C_BINDING module, how do I use SEQUENCE onthe C_PTR variableor is there a better solution for usinga C_PTRin a COMMON block?

Thanks,

Dick

0 Kudos
2 Replies
Les_Neilson
Valued Contributor II
722 Views

Itwould be betterto have "handle" in a module rather than a common block, (even if it is the only item in it.) Especially as you are using modern Fortran.

Les

0 Kudos
Steven_L_Intel1
Employee
722 Views
The standard says that if a COMMON block entity is of derived type, it must be a SEQUENCE type or have the BIND attribute. Type C_PTR has neither, though it is unclear to me whether it should have BIND(C) - I will ask about that.

In any event, as Les suggests, a better approach is this:

module mymod
use ISO_C_BINDING
type(C_PTR), BIND(C,NAME="_MyHandle") :: handle
end

The leading underscore is temporarily necessary until a compiler bug is fixed.
0 Kudos
Reply