Hey all. New to kernelnewbies. This is more of a plain old C question but relates to code in the kernel.
I've been going through the Linux Device Drivers book, 3rd edition, and looking through the sources to get a feel for the code. When the book referenced the use of the THIS_MODULE macro, I looked it up and found this bit of code in include/linux/export.h, version 3.8 of the kernel, but I'm sure this code is fairly old.
Anyways, I don't understand the second to last line here, "#define THIS_MODULE ((struct module *)0)". I get that the code below looks to see if MODULE is defined and if so assumes it can access an object called __this_module and create a macro to store it's address. If it's not defined, I don't get what the aformentioned line does. Thanks.
#ifdef MODULE
extern struct module __this_module;
#define THIS_MODULE (&__this_module)
#else
#define THIS_MODULE ((struct module *)0)
#endif
I've been going through the Linux Device Drivers book, 3rd edition, and looking through the sources to get a feel for the code. When the book referenced the use of the THIS_MODULE macro, I looked it up and found this bit of code in include/linux/export.h, version 3.8 of the kernel, but I'm sure this code is fairly old.
Anyways, I don't understand the second to last line here, "#define THIS_MODULE ((struct module *)0)". I get that the code below looks to see if MODULE is defined and if so assumes it can access an object called __this_module and create a macro to store it's address. If it's not defined, I don't get what the aformentioned line does. Thanks.
#ifdef MODULE
extern struct module __this_module;
#define THIS_MODULE (&__this_module)
#else
#define THIS_MODULE ((struct module *)0)
#endif