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

Array intialization

I'm seeing some strange behavior when initializing arrays. I'm using the following code to intialize a 256 element array to zeros:

xdata char myarray[256] = {0}

The code seems to hang when I run this using my debugging hardware. If I run this with the simulator it seems to work fine. If I reduce the number of elements to 50 it works OK, but increase it to 60 and I get it to hang again. Has anyone seen this before? Is it a hardware issue vs compiler/assembler issue?

Parents
  • When you have initialized global and static variables, then the linker will take all the initialized data and compress and store in a block in the flash. Ãou will then get a decompress function from the runtime library that will decompress this data from flash and assign to your variables.

    A non-global or non-static variable that has an assign is not considered initialied data, i.e. the compiler will generate code that assigns the value when the execution reaches that point in the code.

    The next thing to think about: Make sure that you separate initialized data that will be modified by your program, and initialized data that will never change. If the data need never change, then you should modify the source code so you don't get a RAM copy of the variables. Your program can access the values directly from the code memory (normally flash) instead.

Reply
  • When you have initialized global and static variables, then the linker will take all the initialized data and compress and store in a block in the flash. Ãou will then get a decompress function from the runtime library that will decompress this data from flash and assign to your variables.

    A non-global or non-static variable that has an assign is not considered initialied data, i.e. the compiler will generate code that assigns the value when the execution reaches that point in the code.

    The next thing to think about: Make sure that you separate initialized data that will be modified by your program, and initialized data that will never change. If the data need never change, then you should modify the source code so you don't get a RAM copy of the variables. Your program can access the values directly from the code memory (normally flash) instead.

Children
No data