How can I remove duplication between these C macros?

I have the following few C pre-processor macros to create test functions:

// Defines a test function in the active suite
#define test(name)\
    void test_##name();\
    SuiteAppender test_##name##_appender(TestSuite::active(), test_##name);\
    void test_##name()

      

which is used like this:

test(TestName) {
    // Test code here
}

      

and

// Defines a test function in the specified suite
#define testInSuite(name, suite)\
    void test_##name();\
    SuiteAppender test_##name##_appender(suite, test_##name);\
    void test_##name()

      

which is used like this:

test(TestName, TestSuiteName) {
    // Test code here
}

      

How can I remove duplication between two macros?

+1


a source to share


2 answers


#define test(name) testInSuite( name, TestSuite::active() )

      



However, this does not reduce the amount of C and machine code emitted, it only removes logical duplication.

+6


a source


Try:



#define test(name) testInSuite (name, TestSuite::active())

      

0


a source







All Articles