Summary: And idea for std.string.toStringz docs
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: websites

--- Comment #0 from 2011-06-30 15:50:44 PDT ---
To the online docs of std.string.toStringz I suggest to add an example like
this, that shows how to use the D type system to avoid passing not
zero-terminated char* to C functions (C functions coming from C libraries,

import std.string: toStringz;

struct CcharPtr {
    const char* ptr;
    alias ptr this;

// example of C function
extern(C) size_t strlen(CcharPtr str);

CcharPtr toStringz2(string s) {
    return CcharPtr(toStringz(s));

void main() {
    string s1 = "this is ";
    string s2 = s1 ~ "just a string";
    auto cs = toStringz2(s2);
    assert(s2.length == strlen(cs));

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to