Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max length of a string literal?

I am trying to create a long string literal, which I store inside a std::string. If I create a literal up to approximately 2600 characters, everything prints fine. If I go beyond that number of symbols, I only get some random garbage characters printed.

I have been using the C standard as guidance, environmental limits are specified as "4095 characters in a string literal (after concatenation)". But the code is written in C++.

So my question is, what is the minimum amount of characters in a C++ string literal?

(The problem might possibly be elsewhere in the code, but I would like to ensure that I don't pass a limit set by the standard. The text is printed in a RichEdit control, so I doubt that one is the culprit.)

like image 571
Lundin Avatar asked Oct 29 '12 16:10

Lundin


People also ask

What is the maximum length of string in Java?

String is considered as char array internally,So indexing is done within the maximum range. This means we cannot index the 2147483648th member.So the maximum length of String in java is 2147483647.

What is the max size of string in C#?

What is the max string length in C#? The maximum string length in C# is 2^31 characters. That's because String. Length is a 32-bit integer.

Is there a string length limit in Python?

With a typical 32-bit Python installation, of course, the total memory you can use in your application is limited to something like 2 or 3 GB (depending on OS and configuration), so the longest strings you can use will be much smaller than in 64-bit installations with very high amounts of RAM.

How large is a string in bytes?

A string is composed of: An 8-byte object header (4-byte SyncBlock and a 4-byte type descriptor)


1 Answers

The minimum is specified in

Annex B
Implementation quantities [implimits]

Characters in a string literal (after concatenation) [65 536].

But note that:

1) Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known. This documentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

2) The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance. (emphasis mine)

Your implementation should provide you with this number though.

like image 75
Luchian Grigore Avatar answered Oct 18 '22 21:10

Luchian Grigore