[Issue 11837] String literals should convert to const(void)*
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 28 19:53:13 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11837
--- Comment #4 from yebblies <yebblies at gmail.com> 2013-12-29 14:53:09 EST ---
(In reply to comment #3)
> (In reply to comment #2)
> > Code like this will compile:
> >
> > memcmp(ptr, "abc", 3);
>
> What's wrong with `memcmp(ptr, "abc".ptr, 3)`?
>
Adding .ptr looses the guarantee that the string will be 0-terminated.
eg
// enum x = "abc";
// immutable x = "abc";
auto x = "abc";
memcmp(ptr, x.ptr, 4); // oops, no guarantee x is 0-terminates, but the
compiler has no way to know that's what you wanted.
> I seem to remember there is an issue with null termination in this kind of
> useage?
...?
The fact that string literals don't convert to const(void)* is IMO an annoying
special case.
This works:
const(char)* x = "askjldfg";
const(void)* y = x;
But this doesn't:
const(void)* y = "askjldfg";
Unless there's a good reason this has to be prevented...
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list