Deepika Rajput Posted September 18, 2013 Report Share Posted September 18, 2013 Hello All, I want to implement the condition or a function that would only be executed if Parameter (used to define it) to 1 otherwise if 0 it won't be executed or even exists in the program. So to say COMMENT A FUNCTION USING PARAMETER. For instance like Class XYZ: public sc_module { --------- ---------------- ---------------------- [group of functions] } Void function_definition () { inst 1 inst 2 PRINT_MY_DEBUG (any arguments); } This PRINT_MY_DEBUG is only required suppose when I need to debug else not . So I want configure the condition whether to allow or not this PRINT_MY_DEBUG using some parameter from top. I think I am clear for my questions, else please notify and reply. Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted September 18, 2013 Report Share Posted September 18, 2013 If I understand you correctly, you want to have a preprocessor switch: #if defined(DEBUG) # define PRINT_MY_DEBUG( Some, Args ) \ print_debug_impl( (Some), (Args) ) #else # define PRINT_MY_DEBUG( Some, Args ) \ ((void)0) /* empty statement */ #endif // DEBUG void print_debug_impl( ... ); // real function implementation In the example above, the preprocessor symbol DEBUG is checked, whether or not to enable calls to the print_debug_impl function through the PRINT_MY_DEBUG function macro. You can define such symbols in the source, or via the command-line of your compiler (usually "-D<symbol>[=<value>]", i.e. here -DDEBUG). hth, Philipp karandeep963 and maehne 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.