Using the NEAR Attribute with FORTRAN COMMON Blocks

Last reviewed: July 17, 1995
Article ID: Q60079
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, version 4.1, 5.0, 5.1

SUMMARY

Page 34 of the Microsoft FORTRAN "Advanced Topics" manual includes a discussion of using the NEAR attribute with a COMMON block. By default, in Microsoft FORTRAN each COMMON block is placed into its own data segment to save space in the default data segment (DGROUP). The drawback to this method is that a far pointer is required to access data from a COMMON block which makes the compiled code larger and slower. To address this problem, use the NEAR attribute with small, frequently accessed COMMON blocks. To use this technique, sufficient space must be available in the default data segment.

When an application uses the NEAR attribute with a COMMON block, the data in each COMMON block may appear to remain in its own segment, rather than in the DGROUP segment when you use the /Fs compiler option switch to create a source listing. This may be confusing when space is obviously available in the default data segment for information in the COMMON block. To verify that a NEAR COMMON block is concatenated to the default data segment, view an object listing or a map listing. (To create an object listing, specify the /Fl compiler option switch; to generate a map listing, specify the /Fm compiler option switch.)

MORE INFORMATION

The following code example demonstrates using the NEAR attribute to place data in COMMON blocks into the default data segment.

Sample Code

C Compile options needed: None

      INTEGER*4 A, B, C
      COMMON    /C1 [NEAR]/ A, C
      COMMON    /C2 [NEAR]/ B
      END

The source listing describes each COMMON block as follows:

   Global Symbols
   Name                      Class   Type              Size   Offset
   C1. . . . . . . . . . . . common  ***                  8    0000
   C2. . . . . . . . . . . . common  ***                  4    0000
   main. . . . . . . . . . . FSUBRT  ***                ***    0000

The map file indicates that each COMMON block is included in DGROUP. In the listing below, note that the segment address of each COMMON block is 005Dh, the DGROUP segment address:

 Start  Stop   Length Name                   Class
 00710H 00713H 00004H C2$A                   $C2
 00720H 00727H 00008H C1$A                   $C1

 Origin   Group
 005D:0   DGROUP

  Address         Publics by Name
 005D:0130       C1
 005D:0120       C2

  Address         Publics by Value
 005D:0120       C2
 005D:0130       C1

The object listing includes a description of the manner in which the compiler grouped all segments, including the NEAR COMMON blocks, into DGROUP. That portion of the object listing is as follows:

     NAME    common

C2$A SEGMENT PARA COMMON '$C2' C2$A ENDS C1$A SEGMENT PARA COMMON '$C1' C1$A ENDS
DGROUP    GROUP     CONST, _BSS, _DATA, C2$A, C1$A
     ASSUME  CS: COMMON_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP


Additional reference words: kbinf 4.00 4.01 4.10 5.00 5.10
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.