KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q66924: extern _based(_segname) May Define Segment of Class CODE

Article: Q66924
Product(s): See article
Version(s): 6.00 6.00a | 6.00 6.00a
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | buglist6.00 buglist6.00a | mspl13_c
Last Modified: 18-NOV-1990

When using the _based keyword to declare data, if the data is declared
externally, the "/Fc" listing and .OBJ file may incorrectly define the
segment as class 'CODE'.

Sample Code
-----------

// file1.c

char _based(_segname("STORAGE")) achar1;
extern char _based(_segname("STORAG1")) achar2;
extern char _based(_segname("STORAG2")) achar3;
char _based(_segname("STORAG2")) achar4;

void main(void) {}

// file2.c

char _based(_segname("STORAG1")) achar2;

The /Fc listing for file1.c declares the _based segments as follows:

STORAGE SEGMENT WORD PUBLIC 'FAR_DATA'
STORAG1 SEGMENT WORD PUBLIC 'CODE'
STORAG2 SEGMENT WORD PUBLIC 'FAR_DATA'

The .OBJ file for file1 will contain a SEGDEF (SEGment DEFinition)
record defining STORAG1 as a class CODE segment. However, there is no
PUBDEF (PUBlic DEFinition) record to confuse the linker. In the .OBJ
file for file2, there is a SEGDEF record defining STORAG1 as a class
'FAR_DATA' segment, AND a PUBDEF record for the linker to resolve the
external reference of achar2 in file1. Therefore, although there will
be an extra segment (of zero length) defined in the final .EXE, there
will be no detrimental effects to this problem.

If there is another variable defined in file1.c that is initialized
and is also based on a named segment, the invalid SEGment DEFinition
will not be generated by the compiler. The above example with the
STORAG2 segment illustrates this.

This is only a problem with the full optimizing compiler. The Quick
Compiler (/qc option) works correctly.

Microsoft has confirmed this to be a problem in Microsoft C version
6.00 and 6.00A. We are researching this problem and will post new
information here as it becomes available.

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.

Copyright Microsoft Corporation 1986-2002.