I'm trying to created a linked list of structs for an EFM8 microcontroller project. I want to have the compiler allocate memory for all of the nodes at compile time. The issue I'm having is that no memory is being allocated for struct pointers.
#define FOO_QUEUE_LEN 32
struct Foo {
uint8_t bar0;
struct Foo *next;
};
struct Foo queue[FOO_QUEUE_LEN];
void main (void)
{
while(1) { ;; }
}
I would expect this code to allocate 4 bytes for each Foo
struct (1 byte for bar0
and 3 bytes for next
because in this architecture, if you don't specify memory location a 24-bit address is required.
But when debugging, the structure is reporting back only 1 byte for each struct, and expanding any of the array members shows an Error: cannot dereference this type
message.
What's even more strange is that if you operate on the array of structs in the main loop, the size of the struct in memory is calculated correctly: queue[1].bar0 = 0xCC;
will write the value to memory address 0x4. The problem being that the compile didn't allocate enough memory so we're overwiting past the bounds of each struct (in this case, 0xCC
ends up at queue[4].bar0
).
Is there some directive that is needed to size these struct pointers correctly at compile time?