structure 本质是一系列variable的合集,因此在有 a set of related variable definition 的时候,就应该使用structure
structure 作为函数输入时应该传递其指针而不是本身,原因有两点
// structure type definition
typedef struct{
int a;
int * b;
}EthStatus_Type;int global_Var;// variables will be used
EthStatus_Type EthStatus_a;// example in function call
void func( EthStatus_Type *Var)
{// access the int elementVar->a = 10;// access the pointer elementVar->b = &global_Var;// access the pointer element*(Var->b) = 11;
}func( &EthStatus_a );
Structures that contain pointers do not allocate memory to store the data that is pointed to by its members, only the memory to store the addresses.
Structures and pointers in C - DEV Community