1

I have gone through the concepts of macros but never encountered

#define reg_add_cfghwmod_beacon_led_control(a,b) \
_reg_add_cfghwmod_beacon_led_control(a)

This kind of syntax can any one explain me what the above macro means.

1
  • 1
    Which part don't you understand? The \ at the end of first line, or why is the argument b missing, or something else? Commented May 6, 2015 at 7:32

2 Answers 2

1

This is a multi-line MACRO.

  • Regarding the trailing \, if you see the syntax of a #define directive, C11 standard, chapter §6.10, it says,

    # define identifier replacement-list new-line
    

so, a newline ends the replacement-list and effectively, the directive. So, to have multi-lined definition of #define directive, the \ is used to escape the newline and to make the statements of the follwing line as a part of the replacement list of the same MACRO.

  • Regarding the loss of b in the MACRO definition,

Depends on coding logic. Maybe an attempt to fallback to some earlier version of API having only one argument. Pure guesswork

TL;DR; All it does is to replace the text (Possibly a function call)

reg_add_cfghwmod_beacon_led_control(a,b)

with

_reg_add_cfghwmod_beacon_led_control(a)
Sign up to request clarification or add additional context in comments.

3 Comments

I also thought so but then. I was wondering why the hell some one will first use two arguments in a macro and then use the similar name with just one argument.
@RohitSaluja You never know, maybe the (a,b) part was implemented as a wrapper for some newer version, but they wanted to fall back to the earlier version with 1 argument. Just maybe
This can be used to evolve APIs where, in a different version, the second argument is not used, or to configure some piece of code in an environment where a second argument is not needed.
1

As Sourav Ghosh says above, it is a multiline macro (the \ at the end). Also, it is a little bit unnatural, because what it does is ignoring the second argument. The substitution does not consider the b argument. Otherwise, it is as any other macro.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.