Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!sharkey!bnlux0!bam From: bam@bnlux0.bnl.gov (Bruce A. Martin) Newsgroups: comp.lang.fortran Subject: Re: COMMON and SAVE statements Message-ID: <2066@bnlux0.bnl.gov> Date: 16 Aug 90 17:54:42 GMT References: <65861@lll-winken.LLNL.GOV> <1990Aug6.145839.23660@cunixf.cc.columbia.edu> Organization: Grumman SXLS @ Brookhaven National Lab, Upton, NY Lines: 42 >... >I believe that the standard requires COMMON blocks to be saved until the >entire tree of functions using them has exited; thus COMMON blocks declared >in MAIN will be saved without an explicit SAVE anyway. Would someone out there >more knowledgable than I please correct me if I am incorrect, or confirm this >if I am correct? > Correct. However, the standard requires that if SAVE is specified for a given block in one procedure, it must be so specified in ALL procedures (other than the main program) which reference it! At the last minute (San Diego, 1977 Jan.), somebody realized that a loader could have problems when the the last subroutine says that some COMMON block declared by all of the preceding ones had to be kept in SAVE space. This led to the rule that you must say SAVE in all or none of the subroutines. Logically, this should apply when the block is in main, but that was too hard to swallow. Therefore, a loader could still have a problem when the main program is the last module to be loaded! ;-) Section 8.9 is a bit confusing if you take pieces of it out of context. The *effect* of putting a block in main is the same as if you had had a SAVE statement in each subroutine that really used it. However, if you do specify SAVE in one of the subroutines -- even tho it doesn't change anything -- then you must specify it in the others. Some readers are confused by the words which say that when the block appears in the main program then "a SAVE statement in the subprogram has no efect". It has no effect, but it is still required in ALL of those subprograms if it appears in ANY of them. It is "optional" only in the main program.A I think there was an interpretation item on this in one of the FIBs. BAM -/s/- (bam@bnlux0.bnl.gov) Bruce A. Martin [Address given for identification only.] Grumman Space Systems [Every conceivable disclaimer applies!!] c/o National Synchrotron Light Source [Opinions are mine only, & will change,] Bldg. 725C, Brookhaven National Lab. [without notice, whenever appropriate!!] Upton, NY 11973 (516) 282-3712