|
|
View previous topic :: View next topic |
Author |
Message |
stephank
Joined: 12 Jul 2014 Posts: 2
|
array of structs does not contain proper values |
Posted: Sat Jul 12, 2014 11:47 am |
|
|
Hello,
This is for PIC24FJ128GA006 and PCDIDE - IDE/Compiler version 5.026..
I'm new to CCS programming. I've gone through the tutorials and am starting some new custom applications. I ran into the following problem with which I cannot find any online answers to.
In the program below I've defined a struct array. Setting a break point in main, I can see the first 2 array elements defined with the expected values. From array element 3 and onward, the data is not correct.
Code: |
#include <24FJ128GA006.h>
#device ICD=2
#fuses HS,NOWDT, PR
#use delay (clock=20mhz)
struct
{
int a;
int b;
int c;
int d;
int e;
float f;
float g;
float h;
float array[10];
} p1[10] =
{
{ 6,7,8,9,10,15.1, 15.2, 15.3, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,0, 0, 0, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} },
{ 6,7,8,9,10,16.1, 16.2, 16.3, {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1} }
};
void breakpoint()
{
}
void main()
{
while(TRUE)
{
breakpoint();
}
}
|
For example, node 9 in the watch window looks like
{1597, 1792, 2048, 2304, 2560, -1.88...E-38, ... etc} which are nothing like specified.
Here is a screenshot of what I'm seeing:
http://imgur.com/wjHQrpq
I think I'm missing something fundamental here. Why are the values not being retained properly?
Thank you for your help,
-Stephan |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1348
|
|
Posted: Sat Jul 12, 2014 7:40 pm |
|
|
older versions did have trouble with arrays of structs. I have some things running currently that seem fine though. Not impossible the issue still persists though.
Are you sure it is actual data that is corrupt and not just the debugger displaying incorrectly? I've had it not show values correctly before in the past, especially when dealing with floats. If so, how are you verifying that? Floats can be tricky to verify. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Sun Jul 13, 2014 1:50 am |
|
|
I can confirm it is the debugger that has the problem.
With complex types, it tends to 'lose track' of where things actually are.
If you generate a manually set 'float' watch, and align this to where the variables are, it shows the correct value.
Compiling on my system, it puts the array at 0x85A.
Now each line in the main array is 40(inner array)+12(3*float)+10 bytes long (62 bytes). So the last line should start at 9*62 = 558bytes (0x22E), after the start, and the last 10 entry array, should be at 22 bytes after this (0x244 in all). Looking at address (0xA9E), the memory contains CCCD 3DCC, which is the -1 that should be at this point.
So, debugger problem. |
|
|
stephank
Joined: 12 Jul 2014 Posts: 2
|
|
Posted: Sun Jul 13, 2014 7:49 pm |
|
|
Thanks for the feedback guys. It looks like after some more digging and troubleshooting, you're right. The debugger is not displaying the right values but the reality is that the values are correct.
This issue makes debugging pretty hairy, but I should be able to get by.
Thanks! |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1348
|
|
Posted: Mon Jul 14, 2014 8:26 am |
|
|
It might be worthwhile reporting this to ccs tech support: support@ccsinfo.com
You have a small program and screenshots to support the ticket, so that will help them fix it in a future rev. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|