Cast A primitive type pointer to A structure pointer - Alignment and Padding?
Posted
by
Seçkin Savasçi
on Stack Overflow
See other posts from Stack Overflow
or by Seçkin Savasçi
Published on 2012-08-27T08:02:54Z
Indexed on
2012/09/27
15:37 UTC
Read the original article
Hit count: 146
Just 20 minutes age when I answered a question, I come up with an interesting scenario that I'm not sure of the behavior:
Let me have an integer array of size n, pointed by intPtr;
int* intPtr;
and let me also have a struct like this:
typedef struct {
int val1;
int val2;
//and less or more integer declarations goes on like this(not any other type)
}intStruct;
My question is if I do a cast intStruct* structPtr = (intStruct*) intPtr;
Am I sure to get every element correctly if I traverse the elements of the struct? Is there any possibility of miss-alignment(possible because of padding) in any architecture/compiler?
© Stack Overflow or respective owner