I know this question has been asked a lot, but I'm still unclear how to access the structs.
I want to make a global pointer to an array of structs:
typdef struct test
{
int obj1;
int obj2;
} test_t;
extern test_t array_t1[1024];
extern test_t array_t2[1024];
extern test_t array_t3[1025];
extern test_t *test_array_ptr;
int main(void)
{
test_array_ptr = array_t1;
test_t new_struct = {0, 0};
(*test_array_ptr)[0] = new_struct;
}
But it gives me warnings. How should I access the specific structs with []?
Similarly, how should I create an array of pointers of struct type? test_t *_array_ptr[2];?
(*test_array_ptr)[0]dereferences twice, but there is only one level of stars.-pedantic-errorsoption makes it behave more strictly.deref.c:18:18: error: subscripted value is neither array nor pointer nor vectorwithout any flags. (Hmm, what's avector, this is C?) For stuff like dereferencing a struct, or accessing a member of anint, where the compiler just has no clue how it should do it, it gives up and throws an error.