String length?

I

Immortal Nephi

How many characters are limited on either char* and string? The
maximum 256 characters should be sufficient. You might say that you
want to write unlimited characters like 512 or 1,024 characters if you
include new line ‘\n’.
Do you think that maximum 256 characters is best practice in C++
Standard Library?
 
L

LR

Immortal said:
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 ‘\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 (after
concatenation) [65 536].

— Size of an object [262 144].

These seem far more reasonable to me than 256.

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.

LR
 
I

Immortal Nephi

Immortal said:
   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 ‘\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 (after
concatenation) [65 536].

— Size of an object [262 144].

These seem far more reasonable to me than 256.

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.

LR

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 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.
 
B

Balog Pal

Immortal Nephi said:
How many characters are limited on either char* and string?

There is no specific limit, just the one imposed in general by your
platform's memory manager.
Do you think that maximum 256 characters is best practice in C++
Standard Library?

As there is no such thing as the implied limit, thinkering about its
practice quality is moot.
 
L

LR

Immortal said:
Immortal said:
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 ‘\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 (after
concatenation) [65 536].

— Size of an object [262 144].

These seem far more reasonable to me than 256.

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.

LR

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.

Why would that be easier?

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.

Not a problem? But why bother doing it? What's the advantage to making
the code more difficult to read and maintain?

LR
 
R

Rolf Magnus

Immortal said:
The maximum 256 characters should be sufficient.

It isn't. I regularly use longer strings.
You might say that you
want to write unlimited characters like 512 or 1,024 characters if you
include new line ‘\n’.

1024 is not "unlimited".
Do you think that maximum 256 characters is best practice in C++
Standard Library?

No.
 
R

Rui Maciel

Immortal said:
How many characters are limited on either char* and string?

The limits of class string are implementation-defined. The character limits imposed on a basic c-string
may depend on your implementation (i.e., how much memory you can dynamically allocate) and also on the
character encoding you use.

The
maximum 256 characters should be sufficient.
Why?


You might say that you
want to write unlimited characters like 512 or 1,024 characters if you
include new line ‘\n’.
Do you think that maximum 256 characters is best practice in C++
Standard Library?

Could you point a single advantage of limiting string lengths to 256 characters?


Rui Maciel
 
J

James Kanze

Immortal said:
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 ‘\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 (after
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.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,154
Messages
2,570,870
Members
47,400
Latest member
FloridaFvt

Latest Threads

Top