1 =假,0 =真的吗? [英] 1 = false and 0 = true?

查看:328
本文介绍了1 =假,0 =真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到一篇is_equals排在工作中的C API,对平等的人(真)不相等的SQL表(假),并返回0 1()函数。我才知道,在我的code,一个是积极的榜样,一个用于运行的负面测试用例后,他们都失败了起初没什么意义。 API中的code不具备作为输出是其文档中正确记录的错误。

I came across an is_equals() function in a c API at work that returned 1 for non-equal sql tables (false) and 0 for equal ones (true). I only realized it after running test cases on my code, one for the positive example and one for the negative and they both failed which at first made little sense. The code in the API does not have a bug as the output was recorded correctly in its documentation.

我的问题 - 是否有倒挂的世界/平行宇宙/编码语言,其中该逻辑关注的是正常的吗?是不是平时1是真的吗?是API的codeR犯错误?

My questions - are there upside down worlds / parallel universes / coding languages where this logical NOTing is normal? Isn't 1 usually true? Is the coder of the API making an error?

推荐答案

这是常见的比较函数返回 0 在等于,让他们也可以返回为小于,并为大于的正数负数。 的strcmp() memcmp()像这样工作。

It is common for comparison functions to return 0 on "equals", so that they can also return a negative number for "less than" and a positive number for "greater than". strcmp() and memcmp() work like this.

然而,这是,地道为零是错误的非零是真实的,因为这是下C流量控制和逻辑布尔运算符的工作。因此,它可能是选择了这个函数的返回值是很好,但它是函数的的名称的是错误的(应该真的只是叫比较()或类似)。

It is, however, idiomatic for zero to be false and nonzero to be true, because this is how the C flow control and logical boolean operators work. So it might be that the return values chosen for this function are fine, but it is the function's name that is in error (it should really just be called compare() or similar).

这篇关于1 =假,0 =真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆