C question: Nested sturctures and arrays with Xcode?
Right, if you omit the *, you are telling C to copy the value from RLLBlock to the block member of thePiece. Your Piece_Init function passes a sprite_ptr, which is different than passing the actual sprite. In order to obtain the value of a pointer, you have to de-reference the pointer using the * operator. So in your Piece_Init function you needed piece->block = *sprite. Perhaps looking at it another way might help. An alternative way to do that would be to change your function signature and how you call your function.
A couple of different ways to call the function.
Code:
void GameApp::Piece_Init(t_piece_ptr piece, sprite block)
{
piece->block = block;
}Code:
t_piece_ptr piece;
sprite aSprite
sprite_ptr aSpriteReference;
Piece_Init(piece, aSprite);
Piece_Init(piece, *aSpriteReference); // Function expects a value, so we must de-reference here.Blacktiger Wrote:Right, if you omit the *, you are telling C to copy the value from RLLBlock to the block member of thePiece. Your Piece_Init function passes a sprite_ptr, which is different than passing the actual sprite. In order to obtain the value of a pointer, you have to de-reference the pointer using the * operator. So in your Piece_Init function you needed piece->block = *sprite. Perhaps looking at it another way might help. An alternative way to do that would be to change your function signature and how you call your function.
A couple of different ways to call the function.Code:
void GameApp::Piece_Init(t_piece_ptr piece, sprite block)
{
piece->block = block;
}
Code:
t_piece_ptr piece;
sprite aSprite
sprite_ptr aSpriteReference;
Piece_Init(piece, aSprite);
Piece_Init(piece, *aSpriteReference); // Function expects a value, so we must de-reference here.
Just leaving it blank didn't work. So I looked back and combined what worked before into one line, the (sprite_ptr)& from the function prototype, and the asterisk from the line itself, and surprisingly it worked:
piece->block = *(sprite_ptr)&RLLBlock;
Thanks for the help!
I wonder if you'd be willing to post the entire source, as that line of code is really strange (and as far as I can tell, doesn't actually do anything).
That technique may be necessary if piece->block is a different type of struct than RLLBlock. I've certainly used it more than a few times. However, is this actually the case? And if it is, are you sure it's what you really meant to do?

