[Issue 8229] string literals are not zero-terminated during CTFE
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jan 20 18:16:28 PST 2015
https://issues.dlang.org/show_bug.cgi?id=8229
--- Comment #6 from Kenji Hara <k.hara.pg at gmail.com> ---
I'd just introduce a sample code.
>From the comment in issue 7570:
bool not_end(const char *s, const int n) {
return s && s[n];
}
bool str_prefix(const char *s, const char *t, const int ns, const int nt) {
return (s == t) || !*(t + nt) || (*(s + ns) == *(t + nt) && (str_prefix(s,
t, ns+1, nt+1)));
}
bool contains(const char *s, const char *needle, const int n=0) {
return not_end(s, n) && (str_prefix(s, needle, n, 0) || contains(s, needle,
n+1));
}
enum int x = contains("froogler", "oogle");
Today the code fails to CTFE by the reading of string zero terminator.
Supporting it in CTFE may be useful for C string operations.
--
More information about the Digitalmars-d-bugs
mailing list