To pass the address of a common block, simply pass the address of the first variable in the block. (In other words, pass the first variable by reference.) The receiving C or C++ module should expect to receive a structure by reference.
In the following example, the C function initcb
receives the address of the variable N
, which it considers to be a pointer to a structure with three fields:
C Fortran SOURCE CODE
C
COMMON /CBLOCK/N, X, Y
INTEGER*4 N
REAL*8 X, Y
.
.
.
CALL INITCB( N )
/* C source code */
struct block_type
{
long n;
double x;
double y;
};
initcb( struct block_type * block_hed )
{
block_hed->n = 1;
block_hed->x = 10.0;
block_hed->y = 20.0;
}