How to force the processor to use the result of an expression before inserting

My code

#define PASTE__(a, b) a##b
#define PASTE_(a, b)  PASTE__(a, b)
#define PASTE(a, b) PASTE_(a, b)

int main()
{
    PASTE(1, (1+3)/4);
    return 0;
}

I would like to get the result

int main()
{
    11;
    return 0;
}

Compiled link: http://coliru.stacked-crooked.com/a/b35ea3e35a1b56ae

I introduced two levels of indirection suggested. How can I guarantee full macro decomposition of a parameter before insertion? .

But still, I get a preprocessor error:

main.c:8:11: error: pasting "1" and "(" does not give a valid preprocessing token
     PASTE(1, (1+3)/4);
           ^
main.c:1:23: note: in definition of macro 'PASTE__'
 #define PASTE__(a, b) a##b
                       ^
main.c:3:21: note: in expansion of macro 'PASTE_'
 #define PASTE(a, b) PASTE_(a, b)
                     ^
main.c:8:5: note: in expansion of macro 'PASTE'
     PASTE(1, (1+3)/4);

How to force the preprocessor to resolve the result of this expression before concatenating?

+4
source share
2 answers

, . . - , , BOOST_PP.

http://www.boost.org/doc/libs/1_59_0/libs/preprocessor/doc/index.html

, , . :

PASTE(1, BOOST_PP_DIV(BOOST_PP_ADD(1,3),4));

11, , .

+3

PASTE? 11;? . (: , . . Ofria).

, , IIRC.

0

Source: https://habr.com/ru/post/1613417/


All Articles