hello!

I have a function with the following definition:

void functionName(void** a);

When I want to call that function how am I supposed to send the arguments?

Recommended Answers

All 5 Replies

void* p; // Create a pointer to void
functionName(&p); // Pass its address to create a void**

Note that a void** isn't generic like void*, so you can't pass the address of a char* or int* when void** is expected.

Ok but what I have is a struct A(simple struct which just contains char* and int) and a pointer to that struct

A *a.

All I have done to the pointer is :

a=NULL;

What I need is to pass that pointer when I call the function above as void** the way you suggested.
(instead of void* p)
Can I perform a cast?
Or is there any other way to do it?
thanks in advance

What I need is to pass that pointer when I call the function above as void** the way you suggested.

As I said, void** is not generic. Given my previous example and your added information, you would do this:

void* p = a; // Create a pointer to void
functionName(&p); // Pass its address to create a void**

But at this point I'd question your use of void** in the first place when you're clearly not working with a pointer to void.

yes that's exatly what I did and it works.thanks a lot

A *a;
void* p;
p=a;
functionName(&p);

Now the thing is that I want to assign a certain position , let's say a[2] with a value of type A.
Should I use for the assignment

A b;
a[2]=b;

or

A b;
p[2]=b;

I'm asking because the second one returns an error,but I don't get why.
Now pointer a and pointer p point to the same or pointer p is pointer a?
I'm confused..

I'm asking because the second one returns an error,but I don't get why.

You should study up on pointers, because I sense a lot of confusion. Here's a tutorial that will get you started.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.