Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

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).

12gauge on
davidoc0.jpg

Posts

  • Bob SappBob Sapp Registered User
    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.

    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.

    davidoc0.jpg
Sign In or Register to comment.