Re: String length?
On Jan 17, 1:38 am, Immortal Nephi <Immortal_Ne...@hotmail.com> wrote:
On Jan 16, 6:00 pm, LR <lr...@superlink.net> wrote:
Immortal Nephi wrote:
How many characters are limited on either char* and
string? The maximum 256 characters should be sufficient.
Sufficient for what use?
You might say that you want to write unlimited characters
like 512 or 1,024 characters if you include new line =91\n'.
You might want more. It depends what kind of information
you're storing. Not everyone wants to write out the data
they're storing in a char[] or std::string.
Do you think that maximum 256 characters is best practice
in C++ Standard Library?
No. I don't think this is a limit in the standard. 256
characters seems like an unreasonably low limitation. I
suspect that you are asking about code written to process
text a line at a time, so it may not be exactly what you're
looking for but Appendix B of the last draft I have has
these limits on source code,
- Characters in one logical source line [65 536].
- Characters in a character string literal or wide string literal (afte=
r
concatenation) [65 536].
- Size of an object [262 144].
These seem far more reasonable to me than 256.
Note that these are not binding, according to the standard. And
that the standard actually suggests (IIRC) that the only limits
be resource limits.
If you are writing text processing software 256 is a limit
that will probably come back to hurt you at some point. And
any limit may be problematic at some point. You should
consider that it's possible on many systems for a user to
store a line of text on mass storage that is larger than
available memory.
Well, sometimes programmers prefer to limit 256 characters if
they want clients to type console prompt. The limit of 256
characters may be easier to do string's search functions.
If a programmer wants to limit console input to 256 characters,
he's more or less free to do so, or at least to ignore any
characters after the first 256. Most systems do have an upper
limit to line length in console input, but it's usually
something along the lines of 4KB, or 32KB, or something else
much, much larger than 256. And strings certainly aren't
limited to what you can enter on a console input line; it's
often very practical to read an entire file into a string, and
process it in one go.
If string is for word processor or general purpose, then programmers
can decide to assign the number of limited characters. They can work
to divide one string into several sub-strings. Not a problem.
I'm afraid I'm having problems understanding why you want to
limit strings to 256 characters. Most of the programs I've
worked on have used larger strings, at least in certain
circumstances. Even in cases where the external interface is
limited to a maximum of 256 characters in a string (e.g. Excel
plugins), you'll probably want to use more at times internally.
--
James Kanze