Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why it use void** here?

the code pick up from v8-0.2.5

/**
 * Checks whether two handles are the same.
 * Returns true if both are empty, or if the objects
 * to which they refer are identical.
 * The handles' references are not checked.
 */
template <class S> bool operator==(Handle<S> that) {
  void** a = reinterpret_cast<void**>(**this);
  void** b = reinterpret_cast<void**>(*that);
  if (a == 0) return b == 0;
  if (b == 0) return false;
  return *a == *b;
}  

Handle Overload operator* so that **this and *that return type T*.

So it seems

  void* a = reinterpret_cast<void*>(**this);
  void* b = reinterpret_cast<void*>(*that);
  return a == b;

will also work well?

like image 714
myvyang Avatar asked Jan 07 '17 12:01

myvyang


People also ask

What is void * used for?

When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."

Why we are using void?

Void functions are stand-alone statements In computer programming, when void is used as a function return type, it indicates that the function does not return a value. When void appears in a pointer declaration, it specifies that the pointer is universal.

What does void * func () mean?

Void functions are created and used just like value-returning functions except they do not return a value after the function executes. In lieu of a data type, void functions use the keyword "void." A void function performs a task, and then control returns back to the caller--but, it does not return a value.

What is a void * pointer?

The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means it points to the address of variables. It is also called the general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.


1 Answers

If a and b had type void*, then you couldn't dereference them (without casting them to something else first), so *a == *b wouldn't work.

like image 86
sepp2k Avatar answered Sep 21 '22 23:09

sepp2k