c - Macro Accessing struct member without type definition -


i bumped macro definition.

#define cmd_ctx (cmd->ctx) 

i understand functionality. trying access member 'ctx' struct 'command_invocation' in following snippet. knew because 'command_invocation' struct has 'ctx' member in code. what's confusing why there no mention type of input argument.

struct command_invocation {     struct command_context *ctx;     struct command *current;     const char *name;     unsigned argc;     const char **argv; }; 

now call of cmd_ctx follows

command_context_mode(cmd_ctx, command_exec); 

and definition of function

int command_context_mode(struct command_context *cmd_ctx, enum command_mode mode) 

i understand return value matches. what's not clear me here how input argument determined in call "command_context_mode(cmd_ctx, command_exec);"

macros named text fragments. so, gets replaced contents before real compilation pre-processor. in case call function

command_context_mode(cmd_ctx,  

will replaced with

command_context_mode((cmd->ctx),  

note '(' , ')' macro definition here well. intentionally did not show second parameter call because looks yet macro provided no definition for.

so, macros not need know types, since replace text. compiler check type matching after replacement happened.

imho, type of macro use makes program more difficult read , more confusing (as did you). not use it.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -