This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] print full STRING_CST in Gimple dumps (PR 87052)


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]