Fortran labeled COMMON can be emulated in C by using a global struct.
Table 11-16 Emulating Labeled COMMON
Fortran COMMON Definition |
C "COMMON" Definition |
---|---|
COMMON /BLOCK/ ALPHA,NUM ...
|
extern struct block { float alpha; int num; }; extern struct block block_ ;
main () { ... block_.alpha = 32.; block_.num += 1; ... } |
Note that the external name established by the C routine must end in an underscore to link with the block created by the Fortran program. Note also that the C directive #pragma pack may be needed to get the same padding as with Fortran. Both f77 and f90 align data in COMMON blocks to at most 4-byte boundaries.