Recommended coding convention for combining unix and windows code ?

Olivier Pisano via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 8 01:20:10 PDT 2016


Hi,

I personally separate OS-specific implementations in modules with 
the same name, in different directories. From the filesystem 
perspective:

widget.d
linux/widgetimpl.d
windows/widgetimpl.d

 From the code perspective, the *impl modules would present 
homonymic types with the same public interface.

module widget;

class Widget
{
     version(Windows)
     {
         import windows.widgetimpl;
     }
     version(linux)
     {
         import linux.widgetimpl;
     }

     void systemSpecificTask()
     {
         auto s = SystemSpecificStruct(); // defined in every 
widgetimpl.d
         s.execute();
     }
}


More information about the Digitalmars-d-learn mailing list