c - using #defines and passing functions to them -
gcc 4.4.2 c89
I re-engineer some code in c89. However, I am completely confused with the code which defines the following #. So I have created a small application, maybe I understand how it is working.
What I can collect MODULE_API will pass the function name and the macro will call MODULE_SOURCE_API and open the name and function. So I created a simple function called print_name and ran the code. I have received the following error message:
The underlying declaration of the function 'print_name' is the undefined reference to 'print_name'
What would be the main reason for doing this?
#include & lt; Stdio.h & gt; #define MODULE_SOURCE_API (name, func) name ## _ ## func #define MODULE_API (func) MODULE_SOURCE_API (mod_print, func) ZERO MODULE_API (print_name) (CONSTORE FOUR CONST * name); Int main (zero) {printf ("=== Start the program === \ n"); Print_name ("Blogs"); Printf ("== Program End === \ n"); Return 0; } Zero MODULE_API (print_name) (const four console * name) {printf ("my name is [% s] \ n", name); }
Many thanks for any advice,
Edit ==== I have made a correction which I should call
< Pre> MODULE_API (print_name) ("blogs");
But how do I get involved, how can I print it? And what is the reason for doing this?
Many thanks,
#define MODULE_SOURCE_API (name, function) Name ##_## function #define MODULE_API (func) MODULE_SOURCE_API (mod_print, func) Zero MODULE_API (print_name) (Const four contact * names); This will produce the mod_print_print_name
function instead of print_name
You can see it on the GCC
gcc-e ak.c
/ * ...... * / Zero mod_print_print_name (const four contact * names); Int main (zero) {printf ("=== Start the program === \ n"); Print_name ("Blogs"); Printf ("== Program End === \ n"); Return 0; } Zero mod_print_print_name (const four const * name) {printf ("my name is [% s] \ n", name); }
Comments
Post a Comment