module specification for variables

Profile Anaysis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 4 01:31:57 PST 2017


I'd like to have a global variable in a module but it must be 
accessed by the module name outside of the module.

Sort of like a static variable in a class.

private blocks it completely and public will allow it to be 
imported in to the global scope. Haven't tried protected but I 
assume that is meaningless.

Basically it is a sort of module initialization variable that 
only needs to be set once(usually) outside the module. So I do 
not want it to be imported in to other modules scope in any way, 
ever(there is no need so why create potential issues).

module x;

special int X;  // special = some keyword that makes this work as 
I intend. e.g., "no_import int X;"


module y;

void main()
{
     import x;
     x.X = 3;
     // X = 3; fails.
}


I know you can say that one can used a named import and all that 
but that isn't the point(I want all the other stuff imported as 
it would be)


I could create a static class, for example, and go through 
that... but seems like a hoop to jump through.


More information about the Digitalmars-d-learn mailing list