在 Ubuntu Linux 20.04 机器上,在
/usr/include/x86_64-linux-gnu/bits/resource.h
中,我看到如下代码:
enum __rusage_who
{
/* The calling process. */
RUSAGE_SELF = 0,
#define RUSAGE_SELF RUSAGE_SELF
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
};
我们看到
RUSAGE_SELF
被定义为它本身。其目的/好处是什么?
同一文件的评论中对此进行了解释。
/* Transmute defines to enumerations. The macro re-definitions are
necessary because some programs want to test for operating system
features with #ifdef RUSAGE_SELF. In ISO C the reflexive
definition is a no-op. */
所以它们只是为了功能测试而工作。