Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Vanukoff

Possible to cast a pointer to a certain type of array?

This topic is 6332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have two structures that look like this:

struct Foo
{
    // stuff
    unsigned char data[ 256 ][ 16 ][ 16 ];
    // other stuff
}

struct Bar
{
    Foo* pfoo;
    // other stuff 
}

 
And I have a function which looks like:

void Funky(Bar* pbar)
{
     // code
     for(int i=0; i<200; i++)
     {
         for(int j=0; j<200; j++)
         {
             // code here uses pbar->pfoo->data[ a ][ b ][ c ];
         }
     }
}

 
I''d like to alias pbar->pfoo->data like this:

void Funky(Bar* pbar)
{
     // code
 
     unsigned char* alias = pbar->pfoo->data;

     for(int i=0; i<200; i++)
     {
         for(int j=0; j<200; j++)
         {
             // code here now uses alias[ a ][ b ][ c ];
         }
     }
}

 
But I cannot do the above alias, because I lose dimensional information. Is there a way to cast ''alias'' so the compiler knows I want the dimensions 256*16*16 ... ?

Share this post


Link to post
Share on other sites
Advertisement
You don''t have dimentions.
Anyway-its shouldn''t be too hard to convert the three to a linear.
Or alternately create an array of pointers to the array, and use it in the same way as your normal array.

Share this post


Link to post
Share on other sites

Yeah, I could''ve used it as a linear, but didn''t want to clutter that line (the real code is more complex). I got it working by doing this:



unsigned char (*alias)[16][16] = pbar->pfoo->data;



Looks really weird, but it works.


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!