D Article: Memory Safety

Jon D via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Jan 20 12:28:03 PST 2016


On Wednesday, 20 January 2016 at 14:04:53 UTC, Jakob Ovrum wrote:
> The article aims to explain how to use @safe, @system and 
> importantly, @trusted, including all the hairy details of 
> templates.
>
> https://jakobovrum.github.io/d/2016/01/20/memory-safety.html
>
> Any and all feedback appreciated.

Nice article. I got a much better understanding reading it.

A small thing - I immediately tried adding @safe to one of my 
programs and hit an issue related to the first example in the 
article:

     void main() @safe {
         import std.stdio;
         writeln("hello, world");
     }

This is passes the @safe constraint, but 'stdout.writeln()' and 
'stderr.writeln()' do not. (My program uses stderr.) 
stderr/stdout/stdin are __gshared and can't be referenced by safe 
code. The module level version of writeln, etc., access a trusted 
version of stdout to avoid this.

I don't have a specific suggestion for addressing this in the 
article. It's nicely written and delving into this may take away 
from the key points. But, I wanted to point this out in case 
others hit it.

(Note: This related to a recent thread on the learn forum: 
http://forum.dlang.org/thread/vkihzrwomhiwdzqelrxa@forum.dlang.org)






More information about the Digitalmars-d-announce mailing list