Token Parsing Macro

Token parsing macros are useful to avoid tying same thing multiple times.

For an example, if you have multiple function and some condition checking is required in all functions, this type of macro can be used.

Below code is an example:

#include <stdio.h>
#define TEST(var1, var2) \
void test_func_##var1##_##var2##_test(int i) \
{                                            \
    /* Common part can be written here */
    printf("%s(): var = %d\n", __func__, i);\

    /* Task function can be called here */
}
TEST(r1,r2)
TEST(r3,r4)

int main()
{
    test_func_r1_r2_test(3);
    test_func_r3_r4_test(5);
    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s