Rod said:
Eric Sosman said:
Rod Pemberton wrote:
[...]
What do you mean by: "one implied in most contexts" ? I'm
interested in the
contexts where there wouldn't be an implict zero byte. C90? C99? I
think
it'd be pretty hard for a compiler to implement string literals without
a
terminating nul... The nul's in the string are embedded nul's, so I
don't
think the compiler could legally get away with ignoring the implicit
nul.
char name[15] = "172.16.0.240\000\000\000";
... has only the three explicit trailing zero bytes, not an
implicit fourth. C99 section 6.7.8 paragraph 14; note the
phrase "if there is room."
Or, less confusingly:
char s[3] = "abc";
So, the answer to my question is: none in any context. With the specific
example, there is never "one implied in most contexts"...
Aha! I think I see where we've failed to communicate.
I wrote that the confusing string had "four trailing zero
bytes (three explicit, one implied in most contexts"). You
may have thought this meant there was a one-valued (or maybe
'1'-valued) byte implied in most contexts, but what I meant
was
- There are four zero-valued trailing bytes.
- Three of those four are explicit in the string literal,
each denoted by an escape sequence \000.
- One more zero-valued byte, the fourth, is implicit,
appended by the compiler in most contexts in which a
string literal appears.
("Most" because there is a situation in which the compiler
does not supply a fourth zero, namely, when the literal is used
as an initializer for an array of known size that doesn't have
enough room for the implied zero. There may be a metaphysical
question about whether the literal does or does not posess that
final zero, which is then elided during compilation and has no
visible "image" in the run-time code; I don't do metaphysics.)
So: When I wrote "one" I was not referring to a one-valued
byte; I was referring to "one" of the four zero-valued bytes.
Chalk it up to the ambiguities of natural language.