I'm having difficulty understanding codes,
and the code goes like this,
#define MOBJ_ARGS \
struct struct_name *struct_name, \
int (*getvalue)(struct struct_name *struct_name, other variables), \
//other variables....
struct struct_name {
int (*mobj)(MOBJ_ARGS);
}
first of all, I have no idea what that define does. is it that MOBJ_ARGS is defined as some kind of structure and have all that variables inside, or MOBJ_ARGS could be interpreted as any of those variables?
I have never seen any structure like this before, and i can't even google this since I don't know what this is called :(
plz help me
Preprocessor command #define is used to declare macro which has a name and some list (sequence) of tokens which is just a "text"(can be empty). Also there is possible to define function-like macrose with input paremters. If preprocesser finds a defined name of macro in the source code it just replaced it with the list of token.
In your example there is a macro with name MOBJ_ARGS and list of tokens
struct struct_name *struct_name, \
int (*getvalue)(struct struct_name *struct_name, other variables), \
//other variables....
and preprocessor replaces name "MOBJ_ARGS" with these tokens. So after macro "substitution" the code
struct struct_name {
int (*mobj)(MOBJ_ARGS);
}
may looks like
struct struct_name {
int (*mobj)(
struct struct_name *struct_name, \
int (*getvalue)(struct struct_name *struct_name, other variables), \
//other variables....
);
}
or simplier without using line continuation symbols ""
struct struct_name {
int (*mobj)(struct struct_name *struct_name, int (*getvalue)(struct struct_name *struct_name, other variables), //other variables....
);
}
In other words this macro is used to give a "name" to some "text" which is used as a list of arguments in the funciton definitions/declarations
Does this make sense for you?