Hi,

On Thu, 23 Aug 2018, Richard Biener wrote:

> > > Can you write a not \0 terminated string literal in C?
> >
> > Yes: char a[2] = "12";
> 
> I thought they are fully defined in translation phase #1 ...

No, you can't write a string literal which is not zero terminated, because 
in translation phase 7 a zero code is appended to all character sequences 
resulting from string literals, which is then used to allocate and 
initialize a static (wide) character array of just the right size, 
including the zero code.

The above construct uses that static char[3] array from the string literal 
to initialize a char[2] array (which is explicitely allowed), and _that_ 
one is not zero terminated.  But it's also no string literal.

(Of course, due to as-if the intermediate char[3] array won't usually be 
explicitely constructed.)


Ciao,
Michael.

Reply via email to