user2579721 user2579721 - 4 months ago 29
C Question

Unfamiilar macro expansion

I am familiar with std #defines and macro expansion for min max function but this one throws me. In particular the #'s in the definition. Your thoughts appreciated.

#define TAB_WIDGET_ROW(t) {t##_seq, t##_len, t##_rep}

Answer

The ## in GCC macros is used for concatenation.

This way, the code :

#define TAB_WIDGET_ROW(t)     {t##_seq, t##_len, t##_rep}

int foo[3] = TAB_WIDGET_ROW(bar);

Will expand to :

int foo[3] = {bar_seq, bar_len, bar_rep};

And the foo array will be filled with values of variables bar_seq, bar_len and bar_rep.

See here for more informations.