Article View: comp.std.c
Article #4355Re: String literal as initializer
From: Mark Brader
Date: Tue, 14 Nov 1995 06:21
Date: Tue, 14 Nov 1995 06:21
51 lines
2466 bytes
2466 bytes
Dave Goodman (daveg@netline.net) asks about whether
char s[3] = "hello";
violates a constraint:
> > There is one object ('s'). The question boils down to whether the
> > standard considers a string literal used as an initializer to be one
> > initializer, or several (an initializer-list).
Larry Jones (larry.jones@sdrc.com) answers:
> Several. There's a (pending?) Defect Report / Technical Corrigendum
> that clarifies that a string literal is equivalent to a brace-enclosed
> list of characters.
I think Larry is thinking of Defect Report 060, to be addressed as
part of Technical Corrigendum 2 (which was up for balloting recently,
but I haven't heard what the result was). But DR 060 was specifically
about the case where the initializing string was *shorter* than the
array, as in
char t[10] = "hello";
The last draft of TC2 that I saw, which I assume is being adopted
substantially unchanged, amended 6.5.7/3.5.7 to clarify that t[6]
through t[9] are initialized to 0 (or equivalently '\0'), making
the declaration truly equivalent to
char t[10] = {'h', 'e', 'l', 'l', 'o', 0};
However, I have seen nothing that makes the line that Dave asks about
equivalent to
char s[3] = {'h', 'e', 'l', 'l', 'o'};
nor to the same thing with a 0 or '\0' after the 'o' -- either of these
cases would force a constraint violation. The DR should probably have
covered Dave's case too, but whoever wrote it did not think of it.
I think Dave has identified a new Defect in the standard. As in many
other cases, it is only a technical problem; the intent that this
should be a constraint violation is clear from, among other things,
the resolution of DR 060.
Of course, if Larry is talking about a later DR that I haven't seen,
that's different.
--
Mark Brader "The design of the lowercase e in text faces
msb@sq.com produces strong feelings (or should do so)."
SoftQuad Inc., Toronto -- Walter Tracy
My text in this article is in the public domain.
Technical Details
Message-ID:
<1995Nov14.062159.20990@sq.com>Path:
arc1-ca.pugleaf.net!news.kei.com!simtel!torn!sq!msbReferences:
<4859t8$5o0@tesla.netline.net> <488flk$h7n@info1.sdrc.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!news.kei.com!simtel!torn!sq!msb From: msb@sq.com (Mark Brader) Subject: Re: String literal as initializer Message-ID: <1995Nov14.062159.20990@sq.com> Keywords: string literal, initializer Organization: SoftQuad Inc., Toronto, Canada References: <4859t8$5o0@tesla.netline.net> <488flk$h7n@info1.sdrc.com> Date: Tue, 14 Nov 1995 06:21:59 GMT