[comp.sys.mips] Externals and Block Data

ddh@hare.cdc.com (Dan Horsfall) (11/06/90)

This subject was beaten to death my myself and James Craig Burley a 
while back, with not much resolved between us.  For those who have
the following problem, here is a potential solution.

Problem: How to load a BLOCK DATA subprogram from a LIBRARY.
    (This can be a problem since you can't CALL a block data subprogram
    in the usual sense, thus the loader/linker process ofmatching
    external references to entry points frequently does not work.)

Flash of insight here: Thinking that a good optimizing compiler does 
NOT allocate storage for a variable which appears ONLY in a type
declaration statement, perhaps some compilers also do not generate
external references for symbols that appear ONLY in EXTERNAL statements.
To force an external reference, the symbol must be USED in a manner
that forces it to exist.

Therefore, to those of you who wish to load block data from a library,
try this:

      PROGRAM FOO
      EXTERNAL BDATA             <- same as before
      ...
      CALL INIT( BDATA )         <- pass address to some routine
      ... etc

      SUBROUTINE INIT            <- the called routine need not have an
 [ or SUBROUTINE INIT() ]           argument, but could have one for 
 [ or SUBROUTINE INIT( BD ) ]       cosmetics, depending on your style
                                    requirements and compiler.

Now, the compiler thinks that the address of bdata must in fact be passed
to init -- which may or may not eve define the argument, and obviously
shouldn't reference it/them.  This works on MIPS-based f77, and is worth
a try on others.

No flames, please, if this doesn't work for you.

--
   Horse
                                       +    Control Data Corporation      
   Dan Horsfall     +1-612-482-4622    +    4201 Lexington Ave North      
   Internet   ddh@dash.udev.cdc.com    +    Arden Hills MN 55126 USA