且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测参数presence与否在C宏

更新时间:2023-12-01 07:54:34

在C99就可以检测一个宏参数是空的,但要做出这样强大的对抗可能出现在参数中的所有可能性(被自己不断扩大的论点,包含()键,这样的东西)是困难的。我的宏包 P99 实现了这样的事情,这样你就不必过于担心。与您的宏可以实现为

In C99 it is possible to detect if a macro argument is empty, but making that robust against all odds that may appear in that argument (arguments that are themselves expanding, contain () and stuff like that) is difficult. My macro package P99 implements such a thing, so you wouldn't have to worry too much. With that your macro can be implemented as

#define IFARGS(YES, NO, ...) P99_IF_EMPTY(__VA_ARGS__)(YES(__VA__ARGS__))(NO())

正如其名称所示,P99仅仅建立在C99的功能为。

As its name indicates, P99 is only building on C99 features for that.