ID Number: Q31448
5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a
MS-DOS | OS/2
Summary:
SYMPTOMS
When the following program is compiled and linked under Microsoft C
versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax, the linker generates the
following error:
L2029 -unresolved external for the variable _arr.
However, the array appears to be declared legally. The following
code generates the error:
char huge arr[256*512];
main(){}
C 7.0 will generate the following error:
warning C4307: '*' : integral constant overflow; result truncated
CAUSE
The problem occurs because the multiplication for the array index
is done with integers, and the result of the multiplication is too
large to fit in an integer. This will result in the array index
being 0 (zero). Because of this array, the following declaration:
char huge arr[256*512];
is equivalent to the following declaration:
char huge arr[0];
The second declaration in turn, is equivalent to the following
declaration:
char huge arr[];
This type of declaration will cause the compiler to generate an
explicit external reference for the array arr and force the linker
to look for the variable arr.
RESOLUTION
To solve this problem, do the multiplication for the array index
with long integers by declaring one or both of the integer
constants as long. Below is a code example.
More Information:
Sample Code
-----------
/* Compile options needed: none
*/
char huge arr[256L*512];
Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00