March 04, 2007 string literal concatenation | ||||
---|---|---|---|---|
| ||||
Hi, the following code works fine : import std.stdio; import test4mod; char[] d_problem(T)(T x){ static if(is(T B == B[])) { return "[" ~ d_problem(x[0]) ~ "]"; } else { return "bla"; } } void main(char[][] args){ int[][] x = [[1,2,3]]; writefln("%s",d_problem(x)); } The outout is : [[bla]] If I split this into 2 files : import std.stdio; import test4mod; void main(char[][] args){ int[][] x = [[1,2,3]]; writefln("%s",d_problem(x)); } module test4mod; char[] d_problem(T)(T x){ static if(is(T B == B[])) { return "[" ~ d_problem(x[0]) ~ "]"; } else { return "bla"; } } If you run this progam, you get a "segmentation fault". A bug ? It can be corrected : import std.stdio; import test4mod; void main(char[][] args){ int[][] x = [[1,2,3]]; writefln("%s",d_problem(x)); } module test4mod; char[] d_problem(T)(T x){ static char[] a = "[",b = "]"; static if(is(T B == B[])) { return a ~ d_problem(x[0]) ~ b; } else { return "bla"; } } This works fine again. |
Copyright © 1999-2021 by the D Language Foundation