Maybe D is right about GC after all !
Walter Bright
newshound2 at digitalmars.com
Wed Dec 27 20:24:04 UTC 2017
On 12/27/2017 8:34 AM, Russel Winder wrote:
> On Tue, 2017-12-26 at 14:54 -0800, Walter Bright via Digitalmars-d
> wrote:
>> That's right. C++ is based on faith in the programmer using best
>> practices. D is
>> not based on faith, it can be automatically checked.
>
> "Can be" is not the same as "is". Perhaps all D compilers should
> enforce the "can be" as "is", with options to switch it off if need be?
This illustrates my point if it was unclear:
C++:
int foo(int* p) { return p[1]; }
int bar(int i) { return foo(&i); }
clang++ -c test.cpp -Wall
D:
@safe:
int foo(int* p) { return p[1]; }
int bar(int i) {return foo(&i); }
dmd -c test.d
test.d(3): Error: safe function 'test.foo' cannot index pointer 'p'
test.d(4): Error: cannot take address of parameter i in @safe function bar
More information about the Digitalmars-d
mailing list