BUG: Huge Array in C++ App May Cause General Protection Fault

Last reviewed: July 17, 1997
Article ID: Q102679
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist kbfasttip

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

An attempt to run an application developed in C++ for the Microsoft Windows operating system may fail and cause a general protection (GP) fault when the application accesses a huge array. If you create and run a version of the application for the MS-DOS operating system using the fast compiler, other errors may occur or the machine may hang. A similar application developed in C compiles and runs without error.

CAUSE

The fast compiler does not correctly create the far data segments required to support a huge array in a C++ application.

RESOLUTION

Modify the compiler command line to specify the /f- compiler option switch to build the application with the optimizing compiler.

STATUS

Microsoft has confirmed this to be a problem in C/C++ compiler versions 7.0, 8.0, and 8.0c for MS-DOS. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Microsoft C/C++ version 7.0 and the Professional Edition of Visual C++ include the optimizing compiler. To build an application with the optimizing compiler, specify the /f- compiler option switch or perform the following three steps to modify options in Visual Workbench:

  1. From the Options menu, choose Project.
2. Choose Compiler. 3. Select the Code Generator option and choose Optimizing.

The following C++ code example demonstrates this problem when you build it either as an MS-DOS or as a QuickWin application. The MAP file shows that the compiler builds only one far data segment to hold the contents of the huge array. Because the array dimension in the application is 64,000, the application requires four far data segments to hold all the data.

Sample code

/*
 * Compiler options needed: /AL
 * Linker options recommended: /MAP
 */

long __huge array[64000L];

void main(void)
{
   long i;
   for (i = 0; i < 64000L; i++)
      array[i] = i;
}


Additional reference words: 7.00 8.00 8.00c 1.00 1.50 gp-fault link
initialize
KBCategory: kbtool kbbuglist kbfasttip
KBSubcategory: CPPIss
Keywords : kb16bitonly


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, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.