CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

array of structs does not contain proper values

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stephank



Joined: 12 Jul 2014
Posts: 2

View user's profile Send private message

array of structs does not contain proper values
PostPosted: Sat Jul 12, 2014 11:47 am     Reply with quote

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: 1354

View user's profile Send private message

PostPosted: Sat Jul 12, 2014 7:40 pm     Reply with quote

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: 19537

View user's profile Send private message

PostPosted: Sun Jul 13, 2014 1:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 13, 2014 7:49 pm     Reply with quote

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: 1354

View user's profile Send private message

PostPosted: Mon Jul 14, 2014 8:26 am     Reply with quote

It might be worthwhile reporting this to ccs tech support: [email protected]

You have a small program and screenshots to support the ticket, so that will help them fix it in a future rev.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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