我知道这个问题已经被问了很多次,但我仍然不清楚如何访问结构体。
我想创建一个指向结构体数组的全局指针:
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;
}
但它给我警告。我应该如何使用[]
访问特定的结构体?
同样,我应该如何创建结构体类型指针数组?test_t *_array_ptr[2];
?
(*test_array_ptr)[0]
解引用了两次,但是只有一级星号。 - Daniel Fischer-pedantic-errors
选项使其行为更加严格。 - Keith Thompsonderef.c:18:18: error: subscripted value is neither array nor pointer nor vector
。(嗯,什么是“vector”,这是C语言吗?)对于像解引用结构体或访问int
成员之类的东西,编译器根本不知道该如何处理,它放弃并抛出一个错误。 - Daniel Fischer