I am working on an embedded system and I need to implement a linked list.
So I used a struct to construct a node
typedef struct A
{
... //some data
struct A *next;
struct A *prev;
} A;
I think on PC (gcc) this works fine. However, the embedded system compiler complains that "identifier A is not declared"...
What is the best solution for this?
You should add a separate forward declaration of the struct:
struct A;
typedef struct A
{
... //some data
struct A *next;
struct A *prev;
} A;
Some compilers do take your definition the way you posted it, but I've seen older compilers that require a separate forward declaration. This may be related to an older standard, or an incomplete standard implementation. In fact, on a project where we needed to write code that runs on five platforms with different compilers, we made it a companywide coding standard requirement to have the forward declaration separate from the struct's typedef.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With