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

Standard Struct?

Having some problems working with a struct typedef. In RTX51, one of the system functions takes as an argument a pointer to a struct:

//function prototype
signed char os_check_mailboxes (t_rtx_allmbxtab xdata *table);
...
/* Type definition for system call os_check_mailboxes */
typedef struct {
            unsigned char message_cnt;
            unsigned char read_task_cnt;
            unsigned char write_task_cnt;
        } t_rtx_allmbxtab[8];

I've never seen an array-of-structs declared within the typedef before, and couldn't find any literature about it. It's declared like a single struct, and used just like an array of structs:

t_rtx_allmbxtab xdata mytable;

if(mytable[x].message.cnt < 2)...

however, I get a warning "C182: pointer to different objects" when trying to use it with the actual system function (exactly as shown in the RTX51 user manual):

os_check_mailboxes(&mytable); //<-- generates warning!

I'm not sure exactly how the array as part of the data type affects this, so i'm stumped. However, that didn't stop me from trying random things to see what DID work. Here's what I came up with; maybe somebody can explain to me why this works:

//declare as an array, effectively making a 2D array
//with one dimension being size 1 only
t_rtx_allmbxtab xdata mytable[1];

//use as a normal 2D array
if(mytable[0][x].message.cnt < 2)...

//system function now works fine. no warnings.
os_check_mailboxes(&mytable);

//using (&mytable[0]) or (&mytable[0][0]) instead will generate 'pointer to different objects' warnings.

Parents
  • It's declared like a single struct,

    No. It's defined as a variable. The type of that is what the typedef says it is --- in this case, it's an array of untagged structs.

    I get a warning "C182: pointer to different objects" when trying to use it with the actual system function (exactly as shown in the RTX51 user manual):

    The warning doesn't match the posted code, so I suspect you must have a mismatch between the actual code and the posted.

Reply
  • It's declared like a single struct,

    No. It's defined as a variable. The type of that is what the typedef says it is --- in this case, it's an array of untagged structs.

    I get a warning "C182: pointer to different objects" when trying to use it with the actual system function (exactly as shown in the RTX51 user manual):

    The warning doesn't match the posted code, so I suspect you must have a mismatch between the actual code and the posted.

Children
  • The warning doesn't match the posted code, so I suspect you must have a mismatch between the actual code and the posted.

    Relevant lines of code copied directly from my project that produce the "pointer to different objects" warning:

    t_rtx_allmbxtab xdata mbxtable;
    ...
    os_check_mailboxes(&mbxtable);
    for(i=0; i<mbxtable[MBX_DEBUG].message_cnt; i++) {...
    

  • Relevant lines of code copied directly from my project

    Unfortunately you've left out a crucial one: the actual prototype definition of function os_check_mailboxes().

    What's really needed is a minimal, self-contained example, i.e. a complete, compilable source code snippet without #include's that, compiled on its own, yields the warning.