Partial classes

Artur Skawina art.08.09 at gmail.com
Tue Jun 26 12:29:15 PDT 2012


On 06/26/12 20:21, Walter Bright wrote:
> On 6/26/2012 3:53 AM, Jacob Carlborg wrote:
>> replace arbitrary methods and classes, even in the standard library. In D you
>> can overwrite an arbitrary piece of memory.
> 
> Not when using safe code, you can't.

   void poke(T)(size_t addr, T val) @safe pure {
      T* ptr;
      ptr[addr/T.sizeof] = val;
   }

   int i = 42;

   void main() @safe {
      writeln(i);
      auto whatever = cast(size_t)&i;
      poke(whatever, 666);
      writeln(i);
      poke(0, 0);
   }
   
   void writeln(A...)(A a) @trusted { import std.stdio; writeln(a); }

artur


More information about the Digitalmars-d mailing list