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

Declare an initialized array at an absolute pos

Hi,

The following code does not work:
static code BYTE InitArray[] _at_ 0x1234 =
{
0x01, 0x02, 0x03, 0x04
};

Is there a way to put an initialized array at an absolute position in memory?

Second similar question: I need to word-align several constants in memory (a DMA transfer need word-aligned addresses). The code of the previous question could help but I would like a more elegant solution...

Thanks

  • Don't forget to use those &ltpre&gt and &lt/pre&gt tags when posting code:

    static code BYTE InitArray[] _at_ 0x1234 =
    {
        0x01, 0x02, 0x03, 0x04
    };
    Presumably you read the bit in the C51 manual which says, "Absolute variables cannot be initialized."

    This is a VFAQ - Very Frequently Asked Question! Use the Forum search & you'll find 'em!

    In fact, it's asked so often that I wonder why Keil don't just remove that restriction on the _at_ keyword!

    Basically, if you want to stick to 'C', you'll have to get the Linker to fix the address.
    Or you can do it in Assembler instead.

    The Macro Assembler and Utilities User's Guide 07.2000 lists the EVEN (for variables) and WORD (for Segments) directives for the Assembler (possibly only AX51?).

    Are your constants contiguous?
    Or can they be?


  • Thanks a lot,

    Yes, my constants are continuous. I managed to write them in ASM, adding some dummy bytes somewhere to align them, but as I frequently modify them for my developments I would prefeer to use C.

  • Thanks a lot,<br>
    <br>
    Yes, my constants are continuous. I managed to write them in ASM, adding some dummy bytes somewhere to align them, but as I frequently modify them for my developments I would prefeer to use C.<br>