Size of All String Literals in Single Struct Cannot Exceed 2K

ID Number: Q72389

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

Summary:

String literals are limited to a maximum length of 2048 bytes (2K)

including the terminating null character (\0) in C versions 6.00,

6.00a, and 6.00ax and QuickC versions 2.50 and 2.51. Exceeding this

limit will result in the following compiler error:

warning C4009: string too big, trailing characters truncated

When declaring a data item (such as a structure or an array) with

string data as a size specifier, the total number of bytes used in any

single declaration cannot exceed this 2K limit. In other words, all

string literals within a single structure declaration, when added

together, must not be greater than 2K. This problem was corrected

in C version 7.0

More Information:

The sample code fragment below is an example of a situation where this

may be a problem. The structure "astruct" contains a large number of

arrays where each array is declared to be the size of a string

determined with sizeof(). These strings are never actually used in the

code, so the compiler uses the strings only to determine the size of

each array. Nevertheless, since all the strings are within the same

structure declaration, the total string size overflows the compiler's

2K limit and C4009 warnings are generated for the last two arrays.

To work around this problem, declare the data with an actual numeric

size rather than using sizeof() and a large string.

Sample Code

-----------

/* Compile options needed: /c

*/

struct astruct

{

char array01[sizeof("1234567890123456789012345678901234567890")];

char array02[sizeof("1234567890123456789012345678901234567890")];

char array03[sizeof("1234567890123456789012345678901234567890")];

char array04[sizeof("1234567890123456789012345678901234567890")];

char array05[sizeof("1234567890123456789012345678901234567890")];

char array06[sizeof("1234567890123456789012345678901234567890")];

char array07[sizeof("1234567890123456789012345678901234567890")];

char array08[sizeof("1234567890123456789012345678901234567890")];

char array09[sizeof("1234567890123456789012345678901234567890")];

char array10[sizeof("1234567890123456789012345678901234567890")];

char array11[sizeof("1234567890123456789012345678901234567890")];

char array12[sizeof("1234567890123456789012345678901234567890")];

char array13[sizeof("1234567890123456789012345678901234567890")];

char array14[sizeof("1234567890123456789012345678901234567890")];

char array15[sizeof("1234567890123456789012345678901234567890")];

char array16[sizeof("1234567890123456789012345678901234567890")];

char array17[sizeof("1234567890123456789012345678901234567890")];

char array18[sizeof("1234567890123456789012345678901234567890")];

char array19[sizeof("1234567890123456789012345678901234567890")];

char array20[sizeof("1234567890123456789012345678901234567890")];

char array21[sizeof("1234567890123456789012345678901234567890")];

char array22[sizeof("1234567890123456789012345678901234567890")];

char array23[sizeof("1234567890123456789012345678901234567890")];

char array24[sizeof("1234567890123456789012345678901234567890")];

char array25[sizeof("1234567890123456789012345678901234567890")];

char array26[sizeof("1234567890123456789012345678901234567890")];

char array27[sizeof("1234567890123456789012345678901234567890")];

char array28[sizeof("1234567890123456789012345678901234567890")];

char array29[sizeof("1234567890123456789012345678901234567890")];

char array30[sizeof("1234567890123456789012345678901234567890")];

char array31[sizeof("1234567890123456789012345678901234567890")];

char array32[sizeof("1234567890123456789012345678901234567890")];

char array33[sizeof("1234567890123456789012345678901234567890")];

char array34[sizeof("1234567890123456789012345678901234567890")];

char array35[sizeof("1234567890123456789012345678901234567890")];

char array36[sizeof("1234567890123456789012345678901234567890")];

char array37[sizeof("1234567890123456789012345678901234567890")];

char array38[sizeof("1234567890123456789012345678901234567890")];

char array39[sizeof("1234567890123456789012345678901234567890")];

char array40[sizeof("1234567890123456789012345678901234567890")];

char array41[sizeof("1234567890123456789012345678901234567890")];

char array42[sizeof("1234567890123456789012345678901234567890")];

char array43[sizeof("1234567890123456789012345678901234567890")];

char array44[sizeof("1234567890123456789012345678901234567890")];

char array45[sizeof("1234567890123456789012345678901234567890")];

char array46[sizeof("1234567890123456789012345678901234567890")];

char array47[sizeof("1234567890123456789012345678901234567890")];

char array48[sizeof("1234567890123456789012345678901234567890")];

char array49[sizeof("1234567890123456789012345678901234567890")];

char array50[sizeof("1234567890123456789012345678901234567890")];

char array51[sizeof("1234567890123456789012345678901234567890")];

};