Sujet : Re: Implicit String-Literal Concatenation
De : 433-929-6894 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 07. Mar 2024, 22:44:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240307133736.732@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-07, Lawrence D'Oliveiro <
ldo@nz.invalid> wrote:
On Mon, 04 Mar 2024 20:55:28 -0800, Keith Thompson wrote:
>
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
On Thu, 29 Feb 2024 14:14:52 -0800, Keith Thompson wrote:
>
"A *string* is a contiguous sequence of characters terminated by and
including the first null character."
>
So how come strlen(3) does not include the null?
Because the *length of a string* is by definition "the number of bytes
preceding the null character".
>
So the “string” itself includes the null character, but its “length” does not?
That's correct. However, its size includes it.
sizeof "abc" == 4
strlen("abc") == 3
The abstract string does not include the null character;
we understand "abc" to be a three character string.
The C representation of the string includes the null character;
the size is a representational concept so it counts it.
It is common for C programs to break encapsulation and openly deal with
that terminating null.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca