Microsoft KB Archive/116441

{|
 * width="100%"|

BUG: Bad Code Generated for Based Structures

 * }

Q116441

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist -- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE), included with: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 -- SYMPTOMS ======== A structure or an array of structures that are based in the code segment using based pointers may not appear to have the proper values when referenced. This happens with both versions 8.0 and 8.0c of the C/C++ Compiler. With version 7.0 of the C/C++ Compiler, the referenced structure values and generated code are correct but the compiler issues a C4762 warning: near/far mismatch in argument; conversion supplied CAUSE ===== An instruction needed to load the segment of the array into the ES register is not generated. Therefore, the wrong code segment is used for the array. RESOLUTION ========== With the 7.0 version of the compiler, the warning can be safely ignored. The warning is not generated if the /f- compiler option is used. With the 8.0 and 8.0c versions of the compiler, the __far keyword must be used when referencing the array to work around the problem. The sample code in the "MORE INFORMATION" section, below, demonstrates the problem and the workaround. STATUS ====== Microsoft has confirmed this to be a bug in the C/C++ Compiler for MS-DOS, versions 7.0, 8.0, and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. This is not an issue with the 32-bit compiler. MORE INFORMATION ================ The following sample code can be used to demonstrate this problem: Sample Code =========== /* Compile options: 7.0: use /f- to supress the warning 8.0/8.0c: use /DFIXED to generate correct code */ #include typedef struct { unsigned c: 8; unsigned accept: 1; unsigned endstat: 1; unsigned spare: 6; int next; #ifdef FIXED } __based(__segname("LR_TEXT")) __far VSTAT; #else } __based(__segname("LR_TEXT")) VSTAT; #endif #ifdef FIXED int findvoc (char c, VSTAT __far a[]); #else int findvoc (char, VSTAT[]); #endif void main { #ifdef FIXED static VSTAT __far va[] = { #else static VSTAT va[] = { #endif {'A', 0, 0, 0, 96}, {'B', 0, 0, 0, 133}, {'C', 0, 0, 0, 143}, {'\0', 0, 1, 0, 0} }; int i; #ifdef FIXED i = findvoc ('C', (VSTAT __far *)va); #else i = findvoc ('C', va); #endif printf( "i = %d\n",i ); return; } #ifdef FIXED int findvoc (char c, VSTAT __far a[]) #else int findvoc (char c, VSTAT a[]) #endif { return ((int)a[c - 'A'].c); } Additional reference words: 1.00 1.50 7.00 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CodeGen

Keywords : kb16bitonly

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCVCComp