A matter of propiety

WhatMeWorry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 27 08:30:14 PST 2017


module_common
     import app;     // Ugly?  Bad?  Better way?
     common_func()
     {
         static if (compileTimeFlag1)
             codeBlockA
         static if (compileTimeFlag2)
             codeBlockB
         static if (compileTimeFlag3)
             codeBlockC
     }

I want to have many stand-alone programs that calls the common 
function.
Each app.d is its own separate directory so I can use the same 
name.

app.d
     static bool compileTimeFlag1 = true;
     common_func()

app.d
     static bool compileTimeFlag1 = true;
     static bool compileTimeFlag2 = true;
     common_func()

app.d
     static bool compileTimeFlag1 = true;
     static bool compileTimeFlag2 = true;
     static bool compileTimeFlag3 = true;
     common_func()


I've got this working, but only if I add an "import app;" to 
module_common.
Otherwise I get, "Error: undefined identifier compileTimeFlags

I want to keep all the compileTimeFlags in the main modules. 
Seems like the
most logical place to put them.

But it seems like I'm committing some great sin by doing this. 
Maybe it's my C++ days,
but it just seems wrong to have a module import the main module? 
Is there a more elegant
approach?


Just another quick question: is the module that holds the main() 
function just the
same as any other module?  Or is there some secret sauce?  
(Besides the point of entry)


Thanks.


More information about the Digitalmars-d-learn mailing list