[J3] Question involving explicit initialization

Steve Lionel steve at stevelionel.com
Sat May 4 20:51:59 EDT 2019

On 5/4/2019 8:12 PM, Malcolm Cohen via J3 wrote:
> The requirement is precisely that a variable only be explicitly 
> initialised once in the program.
> For variables outside of COMMON, there is no way to initialise them 
> more than once (the rules  that prevent it are at the syntax level).  
> But for variables in COMMON, the syntax does not prevent that: only 
> this rule does.

To follow on to Malcolm's comment, this rule disallows a usage I have 
seen a lot over the years where a COMMON block is defined by an INCLUDE 
file along with DATA statements initializing the COMMON variables. When 
this is INCLUDEd into more than one program unit, the rule is violated. 
Some platforms will allow this and will use the last definition seen by 
the linker/loader, some will disallow it with a linker error, and some 
will possibly give unpredictable results.

The correct usage here is to move the DATA statements to a BLOCK DATA 
subprogram. (Or define the COMMON in a module and initialize it there, 
though module variables would be preferable nowadays.)

More information about the J3 mailing list