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

Inconsistent warnings about different data types ?

C51 COMPILER V9.53.0.0
LX51 LINKER/LOCATER V4.66.30.0

I have the following (relevant) lines of code:

extern xdata uint8_t rtu_rx_buf[];
extern xdata uint8_t rtu_tx_buf[];
.
.
.
struct{
    uint8_t func;
    uint16_t start;
    uint16_t qty;
    uint8_t  n;
}xdata *p = &rtu_rx_buf[1];
.
.
.
p = rtu_tx_buf;
.
.
.

The first assignment to 'p' doesn't raise any complaints from the compiler or linker. The second, however, gives me the following warnings:

*** WARNING C182 IN LINE 98 OF C:\blahblahblah.c: pointer to different objects
*** WARNING L25: DATA TYPES DIFFERENT

I'm pretty sure I don't see the difference; am I missing something here?

Parents Reply Children
  • I did not try casting. I'm sure it would probably work. I have decided to take another approach to this "problem". Nobody actually tried to answer my question which is 'why do I get a warning for the assignment statement but not the initialization statement?'. I'm still curious as to why this technique is "dangerous", too. Seems fairly straightforward to me...

    I've decided to try creating a monster union that includes the raw data buffer, a union of request structures, a union of response structures, and an exception response structure. Maybe that will keep me out of trouble.

  • Casting is definitely the most appropriate course, given the limited context provided, using warnings to detect bad coding style in prone to bite at some point. It is your job to understand the use and ramifications at each utilization, use comments to provide context and reminders about the what and why.

    I think Hans-Bernhard Broeker has already mentioned that the semantics are different in the two cases, and while blunter than you might like, does speak to some truths. Try to think of the cleanest ways to express your ideas to the compiler, not the "throw paint till it sticks" method.

  • I thought I'd posted this - but, apparently, not.

    Note that the 2 warnings you initially posted are from different tools: one is from the Linker; the other is from the compiler.

    There's not enough context there to see which diagnostic refers to which source line, but I'd guess that the compiler warning refers to the assignment, whereas the linker warning refers to the initialisation?

    This could also account for why the warnings changed when you changed to two assignments - but you didn't show the actual messages in that case.

    But proper casting should have fixed them all...