digitalmars.D.learn - A matter of propiety
- WhatMeWorry (43/43) Jan 27 2017 module_common
- Adam D. Ruppe (7/11) Jan 27 2017 It is the same as any other module. I say it should be named the
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.
Jan 27 2017
On Friday, 27 January 2017 at 16:30:14 UTC, WhatMeWorry wrote:But it seems like I'm committing some great sin by doing this.meh i see no problem with it.Just another quick question: is the module that holds the main() function just the same as any other module?It is the same as any other module. I say it should be named the same as any other (including a two-part name, `module foo;` is likely to clash if you ever do two libraries, i almost always use `module myproject.foo;` instead), but all the exact same rules apply.
Jan 27 2017