www.digitalmars.com         C & C++   DMDScript  

D - static constructors for modules / files ?

reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Sorry I havent gotten to use D that much , stretched on time like everyone
here.

I see this in stream.d
---------------------

File stdin, stdout, stderr;

version (Win32)
{
    // API imports
    private extern(Windows)
    {
     private import windows;
     HANDLE GetStdHandle(DWORD);
    }

    static this()
    {
     // open standard I/O devices
     stdin = new File(GetStdHandle(-10), FileMode.In);
     stdout = new File(GetStdHandle(-11), FileMode.Out);
     stderr = new File(GetStdHandle(-12), FileMode.Out);
    }
}

and its outside of any class, is this a module initalizer ?  Would I have to
put this in a version statement or how could I use this in my own project
( i mean the seemingly anonymous static this() ) ?

Thanks,
Charles
Sep 19 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
Spoke to soon sorry, at the bottom here:
http://www.digitalmars.com/d/module.html

Doh!
"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bke355$2877$1 digitaldaemon.com...
 Sorry I havent gotten to use D that much , stretched on time like everyone
 here.

 I see this in stream.d
 ---------------------

 File stdin, stdout, stderr;

 version (Win32)
 {
     // API imports
     private extern(Windows)
     {
      private import windows;
      HANDLE GetStdHandle(DWORD);
     }

     static this()
     {
      // open standard I/O devices
      stdin = new File(GetStdHandle(-10), FileMode.In);
      stdout = new File(GetStdHandle(-11), FileMode.Out);
      stderr = new File(GetStdHandle(-12), FileMode.Out);
     }
 }

 and its outside of any class, is this a module initalizer ?  Would I have

 put this in a version statement or how could I use this in my own project
 ( i mean the seemingly anonymous static this() ) ?

 Thanks,
 Charles

Sep 19 2003