| Re: sharing variables across mulitple files |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c++ · Group Profile
Author: dizzydizzy Date: May 7, 2008 01:39
Jim Langston wrote:
> I have one project where I am forces to use global variables because of
> the engine I am using having multiple callbbacks and it's impossible for
> me to
> pass the data. One thing I did was I put all the global variables in a
> structure and have just one instance of the structure. I'm not sure if it
> simplifies anything, but it helps.
Sounds like a very bad C callback mechanism. It is a "C" callback mechanism
because otherwise it would have allowed generic functors and full compile
time type checking on the given functions and arguments. It is a "bad C
callback mechanism" because otherwise it would take in one form or another
an opaque argument (usually under the form of a "void*" argument) to
register along with the callback and that value is passed back to the
callback, the argument usually being used to transmit state from the code
registering the callback to the callback.
Yeah, organizing the data to be shared in a struct may help (it is usually
required with the "void*" passing method described above).
--
Dizzy
|