23-08-2013, 05:38 PM
I want to define a list of actions in ROM, so it cannot get corrupted. An array of struct, in ROM, where each struct contains enough information to define what the MCU should do.
One of the actions is to read some info from an exernal device. So it needs to go into a buffer, and the buffer is obviously in RAM.
The problem I have is, how do I make a typedef for a struct, where one member of the struct is a reference to the buffer? I will need to use the buffer as an array, and referring to an array element by index is of course not allowed, if a pointer type is used for the array.
But I cannot find a way to use an array type. For function parameters, I could have foo(uint8_t buf[]) but it's not going to compile in a structure definition
Is there a known way around this, other than creating a deviation?
Thanks
Frank
One of the actions is to read some info from an exernal device. So it needs to go into a buffer, and the buffer is obviously in RAM.
The problem I have is, how do I make a typedef for a struct, where one member of the struct is a reference to the buffer? I will need to use the buffer as an array, and referring to an array element by index is of course not allowed, if a pointer type is used for the array.
Code:
typedef s_SomeStruct
{
uint8_t *buf; /* not ok, because SomeStruct.buf[x] will not be compliant */
size_t bufsize;
} TSomeStruct;
Code:
typedef s_SomeStruct
{
uint8_t buf[]; /* you wha'? */
size_t bufsize;
} TSomeStruct;
Thanks
Frank
<t></t>