Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is void** in C#?

Tags:

c

c#

pointers

void

I'm looking through the source of a C# program that uses a library written in C. I came across this line and was unsure what it was:

cvbimUNSAFE.GetImageVPA ((cvbim.IMG)cvImg.Image, 0, (void**)&lpImageBits, &pVPAT);

What is an object of type void **? I did some Google searches and could only find information about void*, which is a pointer to a sort of catch all top level type, if I understood correctly.

like image 947
user12345613 Avatar asked Aug 26 '11 13:08

user12345613


2 Answers

It's a pointer to a pointer to something not specified. Basically, just think of it as a memory pointer to a raw memory pointer.

So, int** is a pointer to a pointer to an int, but void** is a pointer to a pointer, but it's not specified what that pointer is pointing at.

I did some google searches and could only find information about void*, which is a pointer to a sort of catch all top level type, if I understood correctly.

Not quite. void* is a pointer to something, it's just not specified what that something is and should just be thought of as a pointer to a raw hunk of memory that you have to apply some structure to. For example, malloc returns a void* because it's returning a pointer to a raw hunk of memory.

like image 118
jason Avatar answered Sep 18 '22 19:09

jason


It's a void pointer. See this article for details:

http://msdn.microsoft.com/en-us/library/y31yhkeb%28VS.80%29.aspx

And you can take a look at this SO question for details on how to implement it in C#:

How to declare a void pointer in C#

On a side note, that method should be marked as unsafe if it's not.

like image 44
James Johnson Avatar answered Sep 20 '22 19:09

James Johnson