digitalmars.D.learn - Is it possible to use global variables spanning modules?
- Gary Willoughby (9/9) Jun 21 2013 Yes i know it's horrible but is it possible to use global
- bearophile (5/6) Jun 21 2013 Why don't you use a __gshared module-global var, and then import
- Gary Willoughby (4/10) Jun 21 2013 I've just been looking at that but a little unsure how to use it.
- Adam D. Ruppe (11/13) Jun 21 2013 Import the module then use the variable.
- Gary Willoughby (1/1) Jun 22 2013 That works great thanks all.
Yes i know it's horrible but is it possible to use global variables spanning modules? I need to capture a small amount of program data and deal with it in termination signal handlers. The data will be captured from various classes spread around different modules. I'm thinking the easiest solution is a couple of global vars and then i can access these in the signal handle after the various objects update these values during runtime. Thoughts?
Jun 21 2013
Gary Willoughby:is it possible to use global variables spanning modules?<Why don't you use a __gshared module-global var, and then import it in all the modules where you need it? Bye, bearophile
Jun 21 2013
On Friday, 21 June 2013 at 16:29:06 UTC, bearophile wrote:Gary Willoughby:I've just been looking at that but a little unsure how to use it. Do you import the module that declares the __gshared var or import the var itself?is it possible to use global variables spanning modules?<Why don't you use a __gshared module-global var, and then import it in all the modules where you need it? Bye, bearophile
Jun 21 2013
On Friday, 21 June 2013 at 17:47:49 UTC, Gary Willoughby wrote:Do you import the module that declares the __gshared var or import the var itself?Import the module then use the variable. module globals; int a; // or could be __gshared if you don't want it to be thread local module test1; import globals; a = 10; module test2; import globals; assert(a == 10); // ok because we set it in test1
Jun 21 2013