C++ (~0L) 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27596116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does (~0L) mean?
提问by Noitidart
I'm doing some X11 ctypes coding, I don't know C but need some help understanding this.
我正在做一些 X11 ctypes 编码,我不知道 C,但需要一些帮助来理解这一点。
In the C code below (might be C++ im not sure) we see (~0L)what does that mean? In Javascript and Python ~0means -1.
在下面的 C 代码(可能是 C++ 我不确定)中,我们看到(~0L)了这意味着什么?在 Javascript 和 Python 中的~0意思是-1.
812 int result = GetProperty(window, property_name,
813 (~0L), // (all of them)
814 &type, &format, &num_items, &properties);
Thanks
谢谢
回答by Mark Ransom
0Lis a longinteger value with all the bits set to zero - that's generally the definition of 0. The ~means to invert all the bits, which leaves you with a longinteger with all the bits set to one.
0L是一个long整数值,所有位都设置为零 - 这通常是0. 该~方法反转所有位,这让你有一个long与所有设置为一个位整数。
In two's complement arithmetic (which is almost universal) a signed value with all bits set to one is -1.
在二进制补码算法(几乎是通用的)中,所有位都设置为 1 的有符号值是-1。
The reason for using ~0Linstead of -1Lis to be clearer about the intent - it's not meant to be used as a number at all, but rather as a collection of bits.
使用~0L而不是的原因-1L是为了更清楚地了解意图 - 它根本不打算用作数字,而是用作位的集合。
回答by Bill
Bitwise compliment of zero of long type.
长型零的按位补码。

