toString() on struct template

Henning Hasemann hhasemann at web.de
Fri Mar 2 01:55:01 PST 2007


On Fri, 2 Mar 2007 09:53:03 +0100
Henning Hasemann <hhasemann at web.de> wrote:

> 
> Now it seems to me, the problem is when calling format().
> (I thought I exchanged format() before with a simple string without result,
> strange again).
> 
> -- 
> v4sw7Yhw4ln0pr7Ock2/3ma7uLw5Xm0l6/7DGKi2e6t6ELNSTVXb7AHIMOen5a2Xs5Mr2g5ACPR hackerkey.com

It gets stranger more and more.
I added a method to my vector2d struct template:
(line numbers included)

92  char[] my_to_string() {
93    writefln(x);
94    return "(" ~ .toString(x) ~ "|" ~ .toString(y) ~ ")";
95  }

(I wanted to be sure the problem is not somewhere around foo.toString vs toString(foo))

x and y are members of the struct.

The writefln prints the correct x value, so I think the template must have been
correctly instantiated and this exists and is correct.

But the return statement crashes like this:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1209821504 (LWP 3999)]
0xb7ea69cc in memcpy () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt
#0  0xb7ea69cc in memcpy () from /lib/tls/i686/cmov/libc.so.6
#1  0x0805627b in _d_arraycatnT ()
#2  0x0805e521 in _D7indiana8vector2d15__T8Vector2dTiZ8Vector2d12my_to_stringMFZAa (this=0xbf81110c) at vector2d.d:94
#3  0xbf81110c in ?? ()
#4  0xbf811128 in ?? ()
#5  0x0804ac9b in _Dmain () at test.d:45
Previous frame inner to this frame (corrupt stack?)

indiana is the name of the library and the module is vector2d. 
test.d is the module that holds main and calls my_to_string.

It also seems when I at writefln("some_const_string") at the beginning of my_to_string,
it crashes at an internal function called doFormat.

Im getting crazy with this strange thing, I'd be happy about any small hint
what I could do.

Henning


-- 
v4sw7Yhw4ln0pr7Ock2/3ma7uLw5Xm0l6/7DGKi2e6t6ELNSTVXb7AHIMOen5a2Xs5Mr2g5ACPR hackerkey.com



More information about the Digitalmars-d mailing list