betterC and noboundscheck

Oleg B code.viator at gmail.com
Wed Nov 22 15:10:40 UTC 2017


Hello. I try compile simple example:

import core.stdc.stdio;
import std.algorithm : min;

extern (C) void main()
{
     char[256] buf;
     buf[] = '\0';

     auto str = "hello world";
     auto ln = min(buf.length, str.length);
     buf[0..ln] = str[0..ln];
     printf("%s\n", buf.ptr);
}

rdmd -betterC bettercarray2.d

and get error:

/tmp/.rdmd-1000/rdmd-bettercarray2.d-435C14EC3DAF09FFABF8ED6919B624C1/objs/bettercarray2.o: In function `main':
bettercarray2.d:(.text.main[main]+0xbc): undefined reference to 
`_d_arraycopy'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

If I understand correctly _d_arraycopy is part of druntime and it 
check bounds of array access.

If I add -noboundscheck flag all works fine.

dmd version is 2.076.1

Why -betterC flag not 'include' -noboundscheck flag?
It's bug or in some cases it's useful?


More information about the Digitalmars-d-learn mailing list