Proposal: clean up semantics of array literals vs string literals

monarch_dodra monarchdodra at gmail.com
Tue Oct 2 07:03:49 PDT 2012


On Tuesday, 2 October 2012 at 11:10:46 UTC, Don Clugston wrote:
> [SNIP]
> A proposal to clean up this mess
> [SNIP]

While I think it is convenient to be able to write 
'printf("world");', as you point out, I think that the fact that 
it works "inconsistently" (and by that, I mean there are rules 
and exceptions), is even more dangerous.

If at all possible, I'd rather side with consistency, then the 
"we got your back... except when we don't" approach: IE: strings 
are NEVER null terminated.

In theory, how often do you *really* need null terminated 
strings? And when you do, wouldn't it be safer to just write 
'printf("world\0")'? or 'printf(str ~ "world" ~ '\0');' rather 
than "Am I in a case where it is null terminated? Yeah... 90% 
confident I am..."

If you want 0 termination, then make it explicit, that's my 
opinion.

Besides, as you said, the null termination is not documented, so 
anything relying on it is a bug really. Just an observation of an 
implementation detail.


More information about the Digitalmars-d mailing list