使用多个步骤定义函数宏

问题描述 投票:0回答:1

我知道你可以定义一个这样的函数:

#PRINT printf("hello world\n");

相反,是否可以定义这样的函数?

#PRINT printf("hello world\n"), printf("hello stack\n");

(...函数有两个步骤。)这可能吗?

c
1个回答
1
投票

感谢您的上述评论。我想出了我的问题的答案。

要定义具有多个步骤的宏,您需要执行此操作

    #define FOO {\
                     printf("hello world\n");\
                     printf("hello stack\n");\
                 }

然后调用FOO将执行这两个打印语句。

© www.soinside.com 2019 - 2024. All rights reserved.