0

I don't understand those macros, how does it work?, also what is irc_##name ?..i've got this code from insobot IRC bot,here is the code https://github.com/baines/insobot/blob/master/src/insobot.c

#define IRC_CALLBACK_BASE(name, event_type) static void irc_##name ( \
irc_session_t* session, \
event_type     event,   \
const char*    origin,  \
const char**   params,  \
unsigned int   count    \
)

#define IRC_STR_CALLBACK(name) IRC_CALLBACK_BASE(name, const char*)
#define IRC_NUM_CALLBACK(name) IRC_CALLBACK_BASE(name, unsigned int)
4
  • What research have you done? Commented Sep 30, 2018 at 12:02
  • This is basic preprocessor usage. Please read some online C tutorials or a book about C: for example "The C programming language" by Ritchie and Kernighan. Commented Sep 30, 2018 at 12:02
  • And what specifically are you having problems with? Commented Sep 30, 2018 at 12:02
  • It is basic C grammar. en.cppreference.com/w/cpp/preprocessor/… Commented Sep 30, 2018 at 12:05

1 Answer 1

1

## is the token concatenation operator: it is used in these macro definitions to create the identifier for the name of the callback function by prepending irc_ before the value of the first argument of the macro IRC_STR_CALLBACK and/or IRC_NUM_CALLBACK

Look at this macro invocation at line 183:

IRC_STR_CALLBACK(on_join);

this source line gets expanded to

static void irc_on_join ( irc_session_t* session, event_type     event,   const char*    origin,  const char**   params,  unsigned int   count    );

The macro is used to declare the handler in a consistent fashion without the need to write the prototype explicitly, which is handy because there are many handlers in this source file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.