Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does (~0L) mean?

Tags:

c++

c

x11

ctypes

I'm doing some X11 ctypes coding, I don't know C but need some help understanding this.

In the C code below (might be C++ im not sure) we see (~0L) what does that mean? In Javascript and Python ~0 means -1.

812   int result = GetProperty(window, property_name,
813                            (~0L), // (all of them)
814                            &type, &format, &num_items, &properties);

Thanks

like image 787
Noitidart Avatar asked Dec 22 '14 03:12

Noitidart


People also ask

What does 0L mean?

0L, abbreviation for 0 longitude, or the Prime meridian.

What does 0L mean in Java?

The 0L means the number zero of type long . It uses this constructor to instantiate a Date that refers to zero milliseconds after (i.e. exactly) "the epoch", January 1, 1970, 00:00:00 GMT.

What does 1L mean in C?

The L specifies that the number is a long type, so -1L is a long set to negative one, and 1L is a long set to positive one. As for why ftell doesn't just return NULL , it's because NULL is used for pointers, and here a long is returned. Note that 0 isn't used because 0 is a valid value for ftell to return.

What is 1L in Java?

(long) 1 is a constant expression (because the 1 is directly known) and hence, by the rules of the Java Language Specification (JLS), will be a long after compilation already. However, in my experience, it is far more common that people use the long literal and write 1L for readability.


2 Answers

0L is a long integer 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 long integer with all the bits set to one.

In two's complement arithmetic (which is almost universal) a signed value with all bits set to one is -1.

The reason for using ~0L instead of -1L is 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.

like image 144
Mark Ransom Avatar answered Oct 05 '22 15:10

Mark Ransom


Bitwise compliment of zero of long type.

like image 30
Bill Avatar answered Oct 05 '22 16:10

Bill