Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Is a char array initializer a "string literal"? Date: Tue, 26 Jul 2022 19:24:31 -0700 Organization: None to speak of Lines: 24 Message-ID: <87k07zxpgg.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="4cade4b69894ce75454f6fba9132da96"; logging-data="2552379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191Q71RBdKlBkmUfVQCxUDh" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:hu7WNOCR2hC/CvCRJ1+EmvSNodw= sha1:Oawb0wBzl6tSUxYtf0PoadKpj6g= Xref: csiph.com comp.lang.c++:85673 Andrey Tarasevich writes: > On 7/26/2022 12:57 AM, Juha Nieminen wrote: >> In another forum I was discussing string literals and char arrays. >> During the conversation this question occurred to me: >> In an array initialization like this: >> char str[] = "hello"; >> can that "hello" even be considered a "string literal", or should it >> be classified as something else? > > Yes, it is a string literal. I.e. formally it is an independent object > with static storage duration, independent and separate from `str` in > your example. It is a string literal, i.e., it is a source code token starting and ending with a '"' character. The corresponding object with static storage duration is not a string literal. It doesn't exist until execution time. [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */