R6000 -- Stack Overflow at Compile Time with C 6.0/6.0a/6.0ax

ID Number: Q66429

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SYMPTOMS

The Microsoft C Compiler versions 6.0, 6.0a, and 6.0ax produce the

following run-time error during compilation when the sample program

below is compiled under small (/AS) or medium (/AM) memory model with

any these optimizations:

/Oa /Oc /Oi /On /Op /Or /Os /Ot /Ow /Oz

Run-Time Error

--------------

run-time error R6000

- stack overflow

RESOLUTION

If only the above optimizations, including the defaults, are used to

compile the program, the run-time error will occur. However, if one

of the following optimizations is added, the run-time error will not

occur:

/Od /Oe /Og /Ol /Ox

In addition, the following are two additional workarounds that can be

applied to the code itself:

1. Do not use the register storage class for the structure pointer.

2. Use an if-else statement instead of the ternary operator.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0, 6.0a,

and 6.0ax. This problem was corrected in C/C++ version 7.0.

More Information:

Sample Code

-----------

/* Compile options needed: /AS /Oa

*/

void main(void)

{

struct s1 {

int i;

};

int n;

struct s1 *ptr1;

register struct s1 *ptr2;

ptr2 = ptr1;

n = ptr2->i ? ptr2->i : 10000;

}