Posts

Showing posts with the label macros

Conditional #define in C

Conditional #define in C I want to write a conditional define in C with controlled with the arguments. Something like this: define RTL_REG(reg_name,inst) inst == 0 ? DUT_0_##reg_name : inst == 1 ? DUT_1_##reg_name : inst == 2 ? DUT_2_##reg_name : inst == 3 ? DUT_3_##reg_name : DUT_0_##reg_name But the code isn't working the way I want. Essentially it is substituting the value of inst for the define. What I a, looking for is: RTL_REG(CLK_EN,0) -> DUT_0_CLK_EN RTL_REG(CLK_EN,1) -> DUT_1_CLK_EN What I am getting: RTL_REG(CLK_EN,0) -> 0 Can you some C experts help me out here? Note: Tried adding () as well at the beginning and ending of the definition, but then again, "(" comes in the define substitution! By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject...