As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

C++ problem (I need to get a pointer to an array of ints out of a *void)

12gauge12gauge Registered User regular
edited June 2007 in Help / Advice Forum
Ok, here is my problem:

I have an int array

int previousValue[2];

Fill that up with two values and pass the adress in my call

result = (*queue)->setEventCallout (queue, QueueCallbackFunction, queue, &previousValue);

now, in my QueueCallbackFunction I get a *void refcon with the adress stored in.

How do I make a int array pointer out of that again?

My problem is that I have to store two variables (previous states of cooliehats and dpads).

davidoc0.jpg
12gauge on

Posts

  • Bob SappBob Sapp Registered User regular
    edited June 2007
    An array is really just a pointer to some contiguous memory. A void* is a generic pointer, it can point to any type. You just need to cast it back to something useful. The following should work.

    int* arrayPointer = (int*)voidPointerVariable;

    Then you can use arrayPointer like you would any array.

    arrayPointer[0], arrayPointer[1], etc.

    Bob Sapp on
    fizzatar.jpg
  • 12gauge12gauge Registered User regular
    edited June 2007
    Bob Sapp wrote: »
    An array is really just a pointer to some contiguous memory. A void* is a generic pointer, it can point to any type. You just need to cast it back to something useful. The following should work.

    int* arrayPointer = (int*)voidPointerVariable;

    Then you can use arrayPointer like you would any array.

    arrayPointer[0], arrayPointer[1], etc.

    Perfect - as you can tell, I am not knowledgeable with pointers ;) - thank you very much.

    12gauge on
    davidoc0.jpg
Sign In or Register to comment.