I want to parse a chunk of memory into a struct. The problem is that the members are not one after another and there is some padding.
struct foo {
unsigned int a; // @ 0
unsigned int junk; // @ 0x4
unsigned int b; // @ 0x08
unsigned int more_junk;
.........
};
I don't want to assign each member in the struct for every junk that I have. I know that this is possible with unions but not sure for structs.
Update I'll make another more clear example:
#include <stdio.h>
#include <string.h>
main()
{
struct w {
unsigned long a;
unsigned long b;
unsigned long c;
unsigned long d;
};
struct w *q;
unsigned long array[] =
{
0x11111111,
0x22222222,
0x33333333,
0x44444444
};
q = (struct w*)array;
printf("%x\n", q->a);
printf("%x\n", q->b);
printf("%x\n", q->c);
printf("%x\n", q->d);
}
The output is:
11111111
22222222
33333333
44444444
Lets say that the 3's are junk. The same example:
#include <stdio.h>
#include <string.h>
main()
{
struct w {
unsigned long a;
unsigned long b;
unsigned long d;
};
struct w *q;
unsigned long array[] =
{
0x11111111,
0x22222222,
0x33333333,
0x44444444
};
q = (struct w*)array;
printf("%x\n", q->a);
printf("%x\n", q->b);
printf("%x\n", q->d);
}
The output is:
11111111
22222222
33333333
But it should be:
11111111
22222222
44444444