enum smallSize = 4; const src = "42"; scope char[src.length + 1] y; @safe void f(in char[] x) { y = x; } src.toCStringThen!(f, smallSize)(); // uses stack assert(y[0 .. $ - 1] == src); assert(y[$ - 1 .. $] == "\0");
enum smallSize = 4; const src = "4200"; scope char[src.length + 1] y; @safe void f(in char[] x) { y = x; } src.toCStringThen!(f, smallSize)(); // uses heap assert(y[0 .. $ - 1] == src); assert(y[$ - 1 .. $] == "\0");
Call dg with src as input.