Detecting at compile time if a string is zero terminated

Jesse Phillips jessekphillips+D at
Wed Jan 19 14:56:23 PST 2011

First off no. Second, is their really going to be a performance gain from this. I wouldn't expect static strings to be converted very often. And last I will copy and past a comment from the source code:

198 	    /+ Unfortunately, this isn't reliable.
199 	     We could make this work if string literals are put
200 	     in read-only memory and we test if s[] is pointing into
201 	     that.
203 	     /* Peek past end of s[], if it's 0, no conversion necessary.
204 	     * Note that the compiler will put a 0 past the end of static
205 	     * strings, and the storage allocator will put a 0 past the end
206 	     * of newly allocated char[]'s.
207 	     */
208 	     char* p = &s[0] + s.length;
209 	     if (*p == 0)
210 	     return s;
211 	     +/

More information about the Digitalmars-d-learn mailing list