typedef struct
{
uint32 item1;
uint32 item2;
uint32 item3;
uint32 item4;
<some_other_typedef struct> *table;
} Inner_t;
typedef struct
{
Inner_t tableA;
Inner_t tableB;
} Outer_t;
Outer_t outer_instance =
{
{NULL},
{
0,
1,
2,
3,
table_defined_somewhere_else,
}
};
My question is how to check if tableA is NULL just like the case for outer_instance.
It tried:
if ( tmp->tableA == NULL ). I get “error: invalid operands to binary ==”
/****************************EDIT:Updated code is below *****************************/
I’ve changed the code according to bta’s suggestion but now I’m getting another error
“error: initializer element is not constant” at the line just under the NULL(at items_instance)
typedef struct
{
uint32 item1;
uint32 item2;
uint32 item3;
uint32 item4;
} Items_t;
typedef struct
{
Items_t *itemsA;
Items_t *itemsB;
} Outer_t;
Items_t items_instance=
{
1,
2,
3,
4
};
Outer_t outer_instance=
{
NULL,
items_instance
};
In the revised code, you’re setting the first field of
outer_instanceto NULL, but trying to set the second field toitems_instancedirectly. Since the field has typeItems_t*butitems_instancehas typeItems_t, you’re getting a type error.You want to set the field to the address of
items_instance, so use&items_instance.