我正在阅读项目的源代码echo.c
coreutils
。
我无法理解以下内容的含义:
_
在第 79 行(以及其他几行),fputs (_("\nIf -e is in effect, the following sequences are recognized:\n\n"), stdout);
在第 116 行
!!
,bool posixly_correct = !!getenv ("POSIXLY_CORRECT");
我正在阅读项目的源代码echo.c
coreutils
。
我无法理解以下内容的含义:
_
在第 79 行(以及其他几行),fputs (_("\nIf -e is in effect, the following sequences are recognized:\n\n"), stdout);
在第 116 行!!
,bool posixly_correct = !!getenv ("POSIXLY_CORRECT");
是非
!
。!!
是非非。!!getenv ("POSIXLY_CORRECT")
被用作 的简写getenv ("POSIXLY_CORRECT") != NULL
。这
_
是 gettext 定义的用于翻译的简写宏。请参阅https://www.gnu.org/software/gettext/manual/gettext.html#Overview。!
是逻辑非运算符。!!
是将任何值转换为 1 或 0 的方法之一,在这种情况下,非NULL
或NULL
值分别转换为 1 或 0(true
或false
)。bool
是特殊的,因此 就bool posixly_correct = getenv ("POSIXLY_CORRECT");
足够了,并且在分配给 时,右侧将隐式转换为 1 或 0。bool
但几天前bool
并不存在,它是用#define bool int
或类似物模拟的,在这种情况下!!
可能有一些意义。