且构网

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

逻辑双重强制的基本原理是什么?

更新时间:2022-12-24 09:22:02

我的猜测是这是从C继承的,例如来自此处:

My guess would be that this is inherited from C, e.g. from here:

在C中,true表示为任何不等于0的数值,false表示为0

In C true is represented by any numeric value not equal to 0 and false is represented by 0

另请参见此处;目前,我找不到官方语言规范的更好来源.

Also see e.g. here; at the moment I can't find a better source for the official language specification.

Kernighan和Ritchie 2d ed的盗版副本.我在网上发现(我不希望链接到它)在p上说. 50,第3.2节"If-Else"(添加了重点):

A pirated copy of Kernighan and Ritchie 2d ed. I found online (I'd rather not link to it) says on p. 50, Section 3.2, "If-Else" (emphasis added):

对表达式求值;如果为真(,即,表达式具有非零值),则执行语句1.如果为假(表达式为零),并且存在其他部分,则改为执行语句2.

The expression is evaluated; if it is true (that is, if expression has a non-zero value), statement 1 is executed. If it is false (expression is zero) and if there is an else part, statement 2 is executed instead.

@hrbrmstr指出,用于转换的LOGICAL的R内部定义在Rinternals.h:

@hrbrmstr points out that the R internal definition of LOGICAL that's used for the conversion is in Rinternals.h:

#define LOGICAL(x) ((int *) DATAPTR(x))