Using the NEAR Attribute with FORTRAN COMMON BlocksLast reviewed: July 17, 1995Article ID: Q60079 |
The information in this article applies to:
SUMMARYPage 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 INFORMATIONThe following code example demonstrates using the NEAR attribute to place data in COMMON blocks into the default data segment.
Sample CodeC Compile options needed: None
INTEGER*4 A, B, C COMMON /C1 [NEAR]/ A, C COMMON /C2 [NEAR]/ B ENDThe 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 *** *** 0000The 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 C1The 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 commonC2$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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |