Multiple DATA Initialisation of COMMON Blocks
| SimCon Home | fpt Reference Manual Home |
Multiple DATA Initialisation of COMMON Blocks - The Problem
FORTRAN 77 required variables in COMMON blocks to be initialised in BLOCK DATA sub-programs. However there was nothing to stop variables in the same COMMON block from being initialised in two or more different BLOCK DATA sub-programs. Some systems, most importantly VMS Fortran also allowed variables in COMMON to be initialised by DATA statements or embedded data initialisations in any sub-program.
The Unix and Linux linkers cannot handle this situation. Any COMMON block can only have initialisations in one place. If two or more BLOCK DATA sub-programs initialise the same COMMON block, only the data in the last one to be linked will be present. All other data will be lost. In older systems the error usually occurs silently. In newer systems the object files are constructed in such a way that the linker fails with multiple definitions of the same component. The Fortran standard now also forbids this usage.
DATA initialisation of variables in COMMON may occur in three ways:
Detection of Multiple DATA Initialisation of COMMON Blocks
Two fpt commands are used to detect this situation:
The command CHECK DATA IN COMMON checks the first two cases, where the variables are initialised directly. A report from a demographic medical analysis of smoking treatments is shown below:
Data Initialisation of COMMON Blocks ==================================== COMMON /fumer_c/ initialised in: -------------------------------- SUBROUTINE errsay SUBROUTINE file_error PROGRAM fumer SUBROUTINE fumer_check SUBROUTINE fumer_deinit SUBROUTINE fumer_doit SUBROUTINE fumer_dumprecs SUBROUTINE fumer_getrecs SUBROUTINE fumer_init SUBROUTINE fumer_merge SUBROUTINE fumer_visno SUBROUTINE say COMMON /zblock/ initialised in: ------------------------------- PROGRAM fumer SUBROUTINE fumer_init COMMON /zesblk/ initialised in: ------------------------------- PROGRAM fumer SUBROUTINE fumer_init COMMON Blocks with no data initialisation: ------------------------------------------ /fumer_i/, /fumer_l/ ------------------------------------------------------------------------------ !!! WARNING !!! Number 2847 Severity 1 (Worst 2) Count 78 One or more COMMON blocks is initialised by DATA statements in two or more sub-programs ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ !!! WARNING !!! Number 2849 Severity 1 (Worst 2) Count 79 One or more COMMON blocks is initialised by DATA statements or embedded DATA outside BLOCK DATA ------------------------------------------------------------------------------
The command CHECK DATA IN STRUCTURES analyses the third situation where the variables initialised inherit the data initialisation from the embedded data in the STRUCTURE blocks. This also works for derived types. The end of the report from the same medical program, showing the summary of results follows:
Name Scope Use/COMMON Address Type Size Value/Bounds ---- ----- ---------- ------- ---- ---- ------------ r file_error,errsay,say,fumer_init,fumer_getrecs,fumer_doit, fumer_deinit,fumer_dumprecs,fumer_visno,fumer_merge,fumer_check, fumer /fumer_c/ 80 hpsrandiob *8844 df Initialised by embedded data in: errsay,file_error,fumer,fumer_check, fumer_deinit ,fumer_doit,fumer_dumprecs,fumer_getrecs,fumer_init, fumer_merge ,fumer_visno,say r file_error,errsay,say,fumer_init,fumer_getrecs,fumer_doit, fumer_deinit,fumer_dumprecs,fumer_visno,fumer_merge,fumer_check, fumer /fumer_c/ 80 hpsrandiob *8844 df Initialised by embedded data in: errsay,file_error,fumer,fumer_check, fumer_deinit ,fumer_doit,fumer_dumprecs,fumer_getrecs,fumer_init, fumer_merge ,fumer_visno,say r file_error,errsay,say,fumer_init,fumer_getrecs,fumer_doit, fumer_deinit,fumer_dumprecs,fumer_visno,fumer_merge,fumer_check, fumer /fumer_c/ 80 hpsrandiob *8844 df Initialised by embedded data in: errsay,file_error,fumer,fumer_check, fumer_deinit ,fumer_doit,fumer_dumprecs,fumer_getrecs,fumer_init, fumer_merge ,fumer_visno,say ------------------------------------------------------------------------------- !!! Check of Embedded Data in structures !!! Total number of structures with embedded data: 6 Number of structures with embedded data in COMMON: 3 Number records in COMMON initialised in 2 or more sub-programs: 71 -------------------------------------------------------------------------------
Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.