Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: C String terminator Date: Sat, 22 Feb 2020 08:13:26 -0800 Organization: A noiseless patient Spider Lines: 46 Message-ID: <86imjyd2hl.fsf@linuxsc.com> References: <87a76ofad3.fsf@bsb.me.uk> <87muaodqqn.fsf@bsb.me.uk> <87zhencyud.fsf@bsb.me.uk> <1by2u7s456.fsf@pfeifferfamily.net> <87o8v3cg0i.fsf@bsb.me.uk> <877e1rc6f7.fsf@bsb.me.uk> <87v9p9bylk.fsf@bsb.me.uk> <861rrtj9hx.fsf@linuxsc.com> <87d0bc8xf6.fsf@nosuchdomain.example.com> <861rquhlqk.fsf@linuxsc.com> <87wo8m9nm4.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="a1e79922b2c02e9149a52088916eaff2"; logging-data="16010"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18crWfAqWWeACkrYw4zprCN//UHWTUg5iA=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Yg2eb4vB89nu6ApKpvmYddjuMs8= sha1:ZQqF+dny95MQshVNX4JdiL556Pw= Xref: csiph.com comp.lang.c:150148 Keith Thompson writes: > Tim Rentsch writes: > >> Keith Thompson writes: > > [...] > >>> A pointer to a string *is* required for a "%s" directive, but the >>> standard says so only indirectly. >> >> I have some quibbles about the wording here, but more importantly I >> think this is a bad way to take in what the Standard does say. What >> the Standard does say is that an 's' specifier takes a pointer to an >> array of character type, which in some situations much include a >> null character within the array (and a %s specification is one of >> those). > > As you know, and as long as we're being precise, it doesn't take a > pointer to an array of character type. It takes a pointer to char (and > the char in question is treated as an element of an array). [...] Yes, I glossed over the distinction between pointing to an array and pointing to the first element of an array. I thought the meaning would be clear from context. I need to add though that 'char' is not really accurate. The Standard says "character type" and I think it means that, not just 'char'. Furthermore if an 'l' length modifier is present then the array elements are assumed to be of type 'wchar_t'. Both the regular character types and wchar_t fall under the common umbrella of "character type". >> It can be convenient to think of a %s directive as needing >> a string argument, but the Standard doesn't say anything about >> strings in its description of 's' specifiers, only arrays of >> character type. In some cases an array argument needs to contain a >> string, but the argument is still the array, not the string. > > The argument is a pointer to the initial element of the array. Other > than that, I agree, and that was pretty much my point. The requirements > for the argument corresponding to a "%s" are equivalent to requiring a > pointer to a string, though they're not stated that way (and it would > not be particularly useful to state them that way). I'm glad we are essentially in agreement.