How to understand the macro __init?
王哲
wangzhe5004 at gmail.com
Mon Aug 13 22:14:42 EDT 2012
hi all
in the kernel modules,we often use the macro __init.
if we only discuss the __init for functions.__init tells the
compiler to put the function in a special section.and the
function are used once.So the code of this function should
be freed from the memory after the first call.
so i write a sample module:
#include <linux/module.h>
#include <linux/init.h>
void __init print_k(void)
{
int k = 9;
printk("<0>k = %d\n",k);
}
static int __init hello_init(void)
{
printk("<0>hello kernel!\n");
print_k();
print_k();
return 0;
}
static void __exit hello_exit(void)
{
printk("<0>bye kernel!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
i use the __init for function print_k.
in my opinion after the fisrt invoking the print_k in the hello_init.
the memory of print_k will be freed,and the second invoking will
not be executed.but the result of second invoking is executing .
why?
Thanks in advance!
wanny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120814/2d3f8fef/attachment.html
More information about the Kernelnewbies
mailing list