I have a to deal with a structure of a lib :
typedef struct {
uint8_t response_type;
uint8_t error_code;
uint16_t sequence;
uint32_t resource_id;
uint16_t minor_code;
uint8_t major_code;
uint8_t pad0;
uint32_t pad[5];
uint32_t full_sequence;
} a_structure;
my problem come from the pad[5] member of the structure that I don’t really understand.
I thougth this member can be used as the other member in function like that:
uint8_t get_response_type( a_structure * my_struct)
{
return my_struct->response_type;
}
but this function:
uint32_t get_pad_5( a_structure * my_struct)
{
return my_struct->pad[5];
}
generate warning in gcc
error array subscript is above array bounds
Can someone explain me what this means ?
Thxs
Structure field
padwas defined as “array of 5uint32_t“. You must differ variable definition from using the variable. So sincepadis defined,pad[5]means “get the fifth (counting from 0) element ofpadarray”. But there is no such element inpadarray, because the highest index available for this array is 4.Also, it seems that you want to return pointer to the first element of this array, not the fifth element. So you must rewrite your function this way: