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

Compilation problem for constant variable

Dear all,

in my program i declared some variable as constant. After compilation this program gives me some problem related to above declare variable.

Moment i remove constant from those variable my program start working correctly.

I am inital stage of debugging. Please suggest area where i need to see to solve problem.

Regards..

Yogesh

Parents
  • //Follwing are the variable declaration in my code.

    //Array Declarations:

    const UINT8 alphakbd_0KeyValues[] = {"0 "};
    const UINT8 alphakbd_1KeyValues[] = {"1:/\\*()#+-<>"};
    const UINT8 alphakbd_2KeyValues[] = {"2ABC"};
    const UINT8 alphakbd_3KeyValues[] = {"3DEF"};
    const UINT8 alphakbd_4KeyValues[] = {"4GHI"};
    const UINT8 alphakbd_5KeyValues[] = {"5JKL"};
    const UINT8 alphakbd_6KeyValues[] = {"6MNO"};
    const UINT8 alphakbd_7KeyValues[] = {"7PQRS"};
    const UINT8 alphakbd_8KeyValues[] = {"8TUV"};
    const UINT8 alphakbd_9KeyValues[] = {"9WXYZ"};

    //Pointer to the arrays:

    static const UINT8 *pArray[] =
    { alphakbd_0KeyValues,
    alphakbd_1KeyValues,
    alphakbd_2KeyValues,
    alphakbd_3KeyValues,
    alphakbd_4KeyValues,
    alphakbd_5KeyValues,
    alphakbd_6KeyValues,
    alphakbd_7KeyValues,
    alphakbd_8KeyValues,
    alphakbd_9KeyValues
    };

    /*
    For debugging, when we throw first four Addresses pointed by the 'pArray' pointer. they are not maching with the addresses of first four arrays, when compared with the map file.
    */

Reply
  • //Follwing are the variable declaration in my code.

    //Array Declarations:

    const UINT8 alphakbd_0KeyValues[] = {"0 "};
    const UINT8 alphakbd_1KeyValues[] = {"1:/\\*()#+-<>"};
    const UINT8 alphakbd_2KeyValues[] = {"2ABC"};
    const UINT8 alphakbd_3KeyValues[] = {"3DEF"};
    const UINT8 alphakbd_4KeyValues[] = {"4GHI"};
    const UINT8 alphakbd_5KeyValues[] = {"5JKL"};
    const UINT8 alphakbd_6KeyValues[] = {"6MNO"};
    const UINT8 alphakbd_7KeyValues[] = {"7PQRS"};
    const UINT8 alphakbd_8KeyValues[] = {"8TUV"};
    const UINT8 alphakbd_9KeyValues[] = {"9WXYZ"};

    //Pointer to the arrays:

    static const UINT8 *pArray[] =
    { alphakbd_0KeyValues,
    alphakbd_1KeyValues,
    alphakbd_2KeyValues,
    alphakbd_3KeyValues,
    alphakbd_4KeyValues,
    alphakbd_5KeyValues,
    alphakbd_6KeyValues,
    alphakbd_7KeyValues,
    alphakbd_8KeyValues,
    alphakbd_9KeyValues
    };

    /*
    For debugging, when we throw first four Addresses pointed by the 'pArray' pointer. they are not maching with the addresses of first four arrays, when compared with the map file.
    */

Children
  • Please use the pre tag for your source code.

    What do you mean with "not matching"? You should be aware that, depending on the memory model, the 24bit address of your data as shown in the linker listing is different from a 16bit pointer (address) to that data when debugging. Here is an example:

    Say, the address of your constant data is 0xC116E8 in the linker listing. While debugging, you would see this address as 0x56E8. Why? The 16bit address is a 14bit page offset (bits 0~13)

    0x56E8 & 0x3FFF == 0x16E8
    


    and a 2 bit data page pointer (bits 14~15)

    (0x56E8 & 0xC000) >> 14 == 1 i.e. we use DPP1
    


    The lower 10 bits of each DPP register select one of the 1024 possible 16-Kbyte data pages. In our example, DPP1 is 0x0304, so it selects page 772, i.e. the page base address is 772 * 16384 == 0xC10000 which perfectly explains the listing address:

    0xC10000 | 0x16E8 == 0xC116E8
    


    You should check the user manual of your processor for further details on addressing.

    Thomas