#2173 Valid Data pointer may be indistinguishible from NULL. (with possible workaround))

closed-fixed
Maarten Brock
None
MCS51
2
2013-12-22
2013-05-26
Sergey
No

There are some minor trouble with x51 port:

As known, XRAM addresses starts from 0.
Therefore, pointer to first data item, placed to XRAM, has zero numerical value, and indistiguishible from "empty" (==NULL) pointer.
Possible workaround: declaration of dummy variable to XRAM, placed to zero address.

Wrong example:
...

__xdata U8 Xbuffer[Xbuflen];

__xdata U8 TPointer;
...
/
NO other XRAM variables */
....

TPointer = Xbuffer;
...
if (TPointer != NULL)
{
....
}
else
{
.... / this branch will performs, despite to valid pointer /
};

Cure: Add additional, "dummy" byte for shift start address values from zero:

...

xdata at (0x0000) U8 Dummy_byte;

__xdata U8 Xbuffer[Xbuflen];

__xdata U8 TPointer;
...
/
NO other XRAM variables */

It works OK.

Discussion

  • Maarten Brock
    Maarten Brock
    2013-05-26

    Another alternative is to link with --xram-loc 0x0001 to ignore address 0.
    Besides the example suffers from retyping as this will not compile without severe warning indicating a real problem: TPointer is not a pointer.
    Did you mean an xdata pointer or a generic pointer?

     
  • Maarten Brock
    Maarten Brock
    2013-12-16

    • status: open --> closed-wont-fix
    • assigned_to: Maarten Brock
     
  • Maarten Brock
    Maarten Brock
    2013-12-16

    Unfortunately using __at(0) without an initializer does not work as it will not allocate memory. So the conclusion 'It works OK' is wrong.

    And we can't fix this by adding an initialized __at(0) because someone might not want to touch address zero at all. I think we must leave this for the user to fix, using --xram-loc to whereever he wants his xdata to start.

     
  • Maarten Brock
    Maarten Brock
    2013-12-17

    On second thought we might opt to change the default to --xram-loc 0x0001
    I will implement this if no objections arise.

     
  • Sergey
    Sergey
    2013-12-17

    On second thought we might opt to change the default to
    --xram-loc 0x0001
    I will implement this if no objections arise.

    In my opinion, it will be very simple and elegant solution.
    The loss of only a single XRAM byte is immaterial to 99.9% of cases.
    Thanks!

     
    Last edit: Sergey 2013-12-17
  • Maarten Brock
    Maarten Brock
    2013-12-22

    • status: closed-wont-fix --> closed-fixed
     
  • Maarten Brock
    Maarten Brock
    2013-12-22

    Fixed in SDCC 3.3.2 #8922.