Q
quantumred
Can I use pointer arithmetic on the members of a structure in the
following way? Should I be worried about structure padding? This works
in my debugger but I wonder if I'm bending some rule here.
struct char_struct {
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
};
struct char_struct test = {50,75,100,225};
unsigned char *c;
c = &test;
if (c[2]==100) // this is okay?
printf("c[2] is 100"); // this does work
c++; // this is okay?
printf("*c is 75"); // this does work
following way? Should I be worried about structure padding? This works
in my debugger but I wonder if I'm bending some rule here.
struct char_struct {
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
};
struct char_struct test = {50,75,100,225};
unsigned char *c;
c = &test;
if (c[2]==100) // this is okay?
printf("c[2] is 100"); // this does work
c++; // this is okay?
printf("*c is 75"); // this does work