global date via module howto
John-Mark Gurney
gurney_j at resnet.uoregon.edu
Mon Aug 21 23:08:13 UTC 2006
Warner Losh wrote this message on Sun, Aug 20, 2006 at 22:01 -0600:
> In message: <44E87CCD.30105 at inse.ru>
> Roman Kurakin <rik at inse.ru> writes:
> : I have the following problem:
> : module A
> : int x;
> :
> : module B
> : extern int x;
> :
> : Module A is loaded, module B can't be loaded cause of unknow 'x'.
> : What should I do to make x global?
>
> Better to make module B depend on module A. Making it global is
> generally a bad idea.
>
> in module A:
> MODULE_VERSION(A, 1);
>
> In module B:
> MODULE_DEPEND(B, A, 1, 1, 1);
Our modules do special work to hide all global symbols, so this is
necessary, unless you add special hacks to the Makefile of module A...
It's better to mark the dependancy, since it really does depend upon
that, since if A doesn't exist, and you try to load B, you'll still
get a symbol not found...
The dependancy has the advantage of autoloading module A when you load
module B, so that you don't have to type as much...
For my bktrau HDTV driver, I only have to load iic, bktrau, and bktr, as
each are their own modules, and the i2c bus module automaticly gets brought
in by either iic or bktr (as each depend upon the i2c bus)...
--
John-Mark Gurney Voice: +1 415 225 5579
"All that I will do, has been done, All that I have, has not."
More information about the freebsd-hackers
mailing list