11

I have a lot of string literals that are bigger than 65535 bytes. I'm not allowed to save these strings to seperate files, how can I workaround with the string limit?

https://stackoverflow.com/a/11488682/7821462

  • MSVC: 2048

  • GCC: No Limit (up to 100,000 characters), but gives warning after 510 characters:

    String literal of length 100000 exceeds maximum length 509 that
    C90 compilers are required to support
    
MiP
  • 5,846
  • 3
  • 26
  • 41

4 Answers4

4

These large strings seem more like resources than code, and I would use the resource section of a windows binary (FindResource/LoadResource) and the answer to the SO: embedding resources into linux executable to insert the same data into linux.

mksteve
  • 12,614
  • 3
  • 28
  • 50
3

You can split the text string into multiple strings. Following code worked on Visual Studio 2017:

const char* p1 = "1234567890...";  // Very long (length > 65000)
const char* p2 = "abcdefghij...";  // Very long (length > 65000)
string s = p1;
s += p2;
cout << s.size() << endl;

You have to write the text string in multiple lines like:

const char* p = "This is a "
    "very long string...";

Actually the maximum limit in Visual C++ is 65535. Here is the compiler error message:

fatal error C1091: compiler limit: string exceeds 65535 bytes in length

JazzSoft
  • 392
  • 2
  • 11
0

Try using an array.

https://msdn.microsoft.com/en-us/library/81k8cwsz.aspx

The maximum size for an array is defined by size_t. Defined in the header file STDDEF.H, size_t is an unsigned int with the range 0x00000000 to 0x7CFFFFFF.

The Techel
  • 918
  • 8
  • 13
-3

The Microsoft documentation says that using concatenation (i.e., writing "a" "b" "c" instead of "abc") allows you to increase the limit to around 64 KiB bytes. But this is not sufficient for your use case.

If not, you can perhaps save the string separately, convert it to a byte array initializer using xxd -i (xxd comes with [vim](http://www.vim.org/)), and#include` that (but you'll have to add the null terminator manually).

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • I've written that the string literals are bigger than 65535 bytes, I'll take a look at the array initializer technique. – MiP Jul 24 '17 at 08:43