You'll notice I did heed your desire
for me to reply in-thread
Thanks!
Please cite the C standard for your claim that the length of a C string
is limited *only* by available memory.
In fact, the maximum length of a string is not even limited by
available memory. [7.1.1.1] (in C99, TC2) defines a "string" and does
not define a limit on its length. There is no number that exists such
that if the length of a string exceeded that number, it would not be
considered a "string" as defined by the standard. The maximum length
of a string is actually infinite.
In practice, the maximum length of a string is a function of the
amount of storage space available where you are storing the string
(the standard does not restrict it's definition of a string to include
only data that resides in memory as opposed to, say, on disk), and
also of the methods you are using to access that data.
For example, strings in memory are, in practice, limited by the
maximum value of size_t (including the null), since that's the largest
block of memory you would be able to allocate using standard functions
like malloc(). The size_t maximum in memory, however, is only a
consequence of how you would obtain the memory to store the string in,
and is independent of the definition of a string. The behavior of
strlen() is also not defined if the string length exceeds size_t,
although that does not in itself place any limits on the maximum
length.
As another example, a string residing in a file on a disk or other
medium is limited only by available space on that medium. While you
may not necessarily be able to directly access it with C's string
functions (instead having to read it sequentially with functions like
fgetc()), it still does not violate the definition of a string: "a
contiguous sequence of characters terminated by and including the
first null
character." [7.1.1.1]
In that example, any limits on the maximum size of a file that an
implementation of fopen() can deal with are only a matter of
inconvenience. You could concoct a scheme of storing a string in
multiple files, opened with fopen(), accessing it only sequentially
(note that the C standard does not include a random-access requirement
in the definition of a string), and it still is, in fact, a C string.
You may be thinking of the maximum length of a string literal. AFAIK
the standard does not define a limit on that, either, but I have
encountered compilers with limits (I've had issues with GCC in the
past -- I don't recall the version or the length, 4096 rings a bell).
The maximum length of a string literal does not affect the maximum
length of a string.
Jason