Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Implicit String-Literal Concatenation Date: Thu, 07 Mar 2024 14:25:48 -0800 Organization: None to speak of Lines: 43 Message-ID: <87o7bpof0z.fsf@nosuchdomain.example.com> References: <87frxcuv87.fsf@nosuchdomain.example.com> <87o7bzrll5.fsf@nosuchdomain.example.com> <87bk7ysysj.fsf@nosuchdomain.example.com> <87y1axp9a7.fsf@nosuchdomain.example.com> <20240307133736.732@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="baf60ccaa3a113314bb7d61097e89b2c"; logging-data="1351775"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/O7ylGvF3oy2wayaGtOrpk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:m+HSQz4b/AA9D0QIKdRbZ7Qf1Bs= sha1:ZAwlmcELeYbs0CW07LfDrdSGHfk= Xref: csiph.com comp.lang.c:383460 Kaz Kylheku <433-929-6894@kylheku.com> writes: > On 2024-03-07, Lawrence D'Oliveiro wrote: >> On Mon, 04 Mar 2024 20:55:28 -0800, Keith Thompson wrote: >>> Lawrence D'Oliveiro 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. Sure, if you define "abstract string" that way. I'll just note that C's definition of the word "string" does include the terminating null character, and does not talk about "abstract strings". (A string in the abstract machine clearly includes the null character, but that's a bit of a stretch.) Yes, I'm being annoyingly pedantic. > 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. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */