Deleting Entries from an Array

Daniel Biehl dbiehl at gmx.net
Wed Jun 27 03:10:15 PDT 2007


Daniel Biehl schrieb:
> Hello,
> 
> I play a little bit with D to learn something more about it. One
> interesting feature is splicing of arrays. I wrote a little function to
> delete some entries from an array of chars. I thought it was easy, but I
> only get a memory access error (Speicherzugriffsfehler in german) under
> Linux with DMD 1.015 and gdc 0.24 and on Windows XP only with gdc 0.23.
> Where is the Bug? Me or Phobos/DMD/GDC?
> 
> module tt;
> 
> import std.stdio;
> 
> char[] cut(inout char[] s, size_t index, size_t count) {
>     s[index..length - count] = s[index+count..length].dup;
>     s.length = s.length - count;
>     return s;
> }
> 
> void main()
> {
>     char[] s = "Hello World";
> 
>     writefln(s.length);
>     writefln(s.cut(1,1));
>     writefln(s.length);
> 
> }
> 
> Greets Daniel

gdb reports:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1209001280 (LWP 10327)]
0x44e6bef5 in memcpy () from /lib/libc.so.6


Daniel



More information about the Digitalmars-d mailing list