Hello,
I have a rather complicated pointer/syntax problem. One of my function arguments is a pointer to a structure which contains a void pointer. If I point the pointer to a scalar then in my function I can access it like this: local_var = (appropriate_type *) struc->pointer; But I want to use this pointer to pass to my function a different structure containing 2 members. How can I access these members in the function?

Thanks.

You probably don't want to hear this.
I don't know how to solve your problem and I get the feeling you're creating Frankenstein's monster. Passing around pointers which can point to different types is already giving you a headache. Your testing/debugging will be difficult and the poor swine that maintains it after you've moved on will be cursing your name.
Can I delicately suggest that you consider an alternative design?

In actual fact in your function you need two pointers (or references) to these "two members of two different structures". Do that.
I agree with MrSpigot: "generic" pointer to different structure types in a structure passsed as an argument is a right way to nowhere...

Yeah, I also agree with MrSpigot, you should consider to use an alternative design for your program as it will be really difficult and error-prone to do what you're asking for ...

Thanks for all your good advice, but the function that takes a structure containing that generic pointer already exists. It's one of a library functions that I'm trying to use. So I cannot change this. I just had to figure out the best way of using it for my needs. And I already have.

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.