Microsoft KB Archive/102679

{|
 * width="100%"|

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

 * }

Q102679

-

The information in this article applies to:


 * The C/C++ Compiler (CL.EXE), included with:
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 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 query words: 7.00 8.00 8.00c 1.00 1.50 gp-fault link initialize

Keywords : kb16bitonly

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCVCComp