Discussion Forum

3d array acces bug

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Vasilij Yanikeev
Posted
28-Apr-2012 13:31 GMT
Toolset
ARM
New! 3d array acces bug

Hello!

I declared 3d array in my Keil project for lpc1788: volatile uint16_t db[16][128][3]. When I read members of the array db[x][y][z] with z < 1 there is no problem. But if I try to read members with z >=1 I always get 0xFFFF, even if they are not equal 0xFFFF (I checked it in debugger). For example:

db[0][1][0] = 0x1515;
uint16_t id_ = db[0][1][0];       //works fine, id_ is equal 0x1515

db[1][0][1] = 0x1515;
uint16_t index_ = db[1][0][1];    //returns index_ equal 0xFFFF


Could anybody explain to me what's wrong?

Regars, Vasilij.

Read-Only
Author
Andrew Neil
Posted
28-Apr-2012 20:15 GMT
Toolset
ARM
New! RE: 3d array acces bug

You need to show a minimum complete example which illustrutes your problem.

Read-Only
Author
Dejan Durdenic
Posted
29-Apr-2012 10:43 GMT
Toolset
ARM
New! RE: 3d array acces bug

I've tried this:

        volatile short db[16][128][3];

int main (void)
{
        short test;

        db[0][1][0] = 0x1515;
        test=db[0][1][0];
        db[1][0][1] = 0x2525;
        test=db[1][0][1];
}

and it works as supposed. Toolset was V4.50

Beware that some other part of your code (e.g.interrupt service routine)
might erroneously overwrite that 3D array...

- Dejan

Read-Only
Author
Andrew Neil
Posted
29-Apr-2012 12:22 GMT
Toolset
ARM
New! RE: I've tried this:

You've assumed that the 3D array is global.

An array of 16*128*3 has 6144 elements - doing that on the stack would need careful consideration of the stack size...

This is why the OP really needs to provide a complete example!

Read-Only
Author
Dejan Durdenic
Posted
29-Apr-2012 15:23 GMT
Toolset
ARM
New! RE: I've tried this:

> You've assumed that the 3D array is global.

Your'e right, I assumed wrongly. Modifying the code in a way that
the 3D-array is defined inside a function and setting stack
size smaller than the array size caused a program to fail.
Anyway, nothing wrong with the compiler, except it would be useful
if the tools can detect such a condition...

- Dejan

Read-Only
Author
Andrew Neil
Posted
29-Apr-2012 17:12 GMT
Toolset
None
New! RE:I assumed wrongly

Only the OP can confirm whether your assumption was correct or not!

Again, that's why the OP needs to provide the example!

"3D-array is defined inside a function and setting stack size smaller than the array size caused a program to fail"

This shows one possible failure mechanism - it may or may not be the particular failure mechanism that the OP is experiencing...

"would be useful if the tools can detect such a condition..."

That would be quite difficult, as the tools don't have full knowledge of the operating environment.

However, Keil does provide an analysis of the stack usage of functions

Read-Only
Author
Andrew Neil
Posted
29-Apr-2012 17:14 GMT
Toolset
None
New! RE: Keil does provide an analysis of the stack usage of functions

http://www.keil.com/support/man/docs/armcc/armcc_cjaiidcg.htm

Read-Only
Author
Dejan Durdenic
Posted
29-Apr-2012 10:47 GMT
Toolset
ARM
New! RE: 3d array acces bug

I also tried c++ version

        volatile short db[16][128][3];

int main (void)
{

        db[0][1][0] = 0x1515;
        short test=db[0][1][0];
        db[1][0][1] = 0x2525;
        short test2=db[1][0][1];
}

with the same (successful) result...

- Dejan

Next Thread | Thread List | Previous Thread Start a Thread | Settings