Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 17.4 - can I reference to an array, inside a struct?
#1
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.
Code:
typedef s_SomeStruct
{
  uint8_t *buf;  /* not ok, because SomeStruct.buf[x] will not be compliant */
  size_t bufsize;
} TSomeStruct;
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
Code:
typedef s_SomeStruct
{
  uint8_t buf[]; /* you wha'? */
  size_t bufsize;
} TSomeStruct;
Is there a known way around this, other than creating a deviation?

Thanks

Frank
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)