G
G Patel
Hi,
As the FAQ and several clc post warn again, I know it's not legal to
use a pointer to step outside the bounds of an array (except one past
the last element, and that pointer must never be dereferenced).
But what about other aggregate objects like structures? If my
structures has arrays, ints, chars, floats, can I just set up a pointer
to a byte (char) and step through the elements of the structure?
A better example would be something like this:
struct {
int a;
int b;
} pairs[30];
int *ptr;
ptr = &pairs[0].a;
/* or ptr = (int *)pairs; */
Now, whenever I want to deal with the a variables separately from the b
variables, I access the structs using normal dot operators, etc.
But there are times when I want to treat the whole thing as 60
conitnuous int variables... can I do this with ptr?
ex:
for(i=0; i < 60; i++) { ptr = 0; }
Is this legal?
As the FAQ and several clc post warn again, I know it's not legal to
use a pointer to step outside the bounds of an array (except one past
the last element, and that pointer must never be dereferenced).
But what about other aggregate objects like structures? If my
structures has arrays, ints, chars, floats, can I just set up a pointer
to a byte (char) and step through the elements of the structure?
A better example would be something like this:
struct {
int a;
int b;
} pairs[30];
int *ptr;
ptr = &pairs[0].a;
/* or ptr = (int *)pairs; */
Now, whenever I want to deal with the a variables separately from the b
variables, I access the structs using normal dot operators, etc.
But there are times when I want to treat the whole thing as 60
conitnuous int variables... can I do this with ptr?
ex:
for(i=0; i < 60; i++) { ptr = 0; }
Is this legal?