This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

autoreferencial structure in ROM

Dear Sir,

I use a structure like this one:

typedef struct st { char t; struct st*;}

I would like to store several structures in ROM.
I wrote the following code

const struct st1 = { 1, &st2};
const struct st2 = { 2, &st1);

The compilation produce an undefined identifier error 202 (c51 V4.02).

What can I do to solve this problem?

Best regards

Parents Reply Children
  • I have tried before to declare the structure as Mike suggests, but it doesn't work (error of multiple definition). In fact, this works with Turbo C, it was like that in my original sources I try to switch to C51.

    In the meantime I found the following code using an array which works:

    struct st { char t; struct st *ptr;};

    const struct st ast[2] = {
    { 1, &ast[1]},
    { 2, &ast[0]}};

    Thanks

  • OK, this code must work (note the extern keyword):

    struct st { char t; struct st *ptr;};
    extern const struct st st2;
    const struct st st1 = { 1, &st2};
    const struct st st2 = { 2, &st1};
    
    This looks like ANSI C compliant code to me. Same code without extern is not ANSI C compliant, I guess.
    Regards,
    - Mike