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

Access to element of structure with pointer(V4.104)

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



Joined: 22 Jul 2009
Posts: 5
Location: TKY JPN

View user's profile Send private message Visit poster's website

Access to element of structure with pointer(V4.104)
PostPosted: Thu Feb 04, 2010 7:03 pm     Reply with quote

Hello.

The access to the element of the structure with the pointer doesn't go well.

Is this a specification?
Code:

typedef struct
{
   int1   open;
   uint32 holdSect;
   uint8  index;
   uint8  ttribute;
   uint32 orgSect;
   uint32 curSect;
   uint32 size;
   uint32 x;
   uint16 xLocal;
   char   name[8+3];
} st_fileptr;


st_fileptr g_fp;

void foo( void )
{
   st_fileptr *d;

   d = &g_fp;
   d->size = d->curSect = d->orgSect = 0;
}

[Result for pic18LF2620 and CCS-C3.249]
g_fp.size, g_fp.curSect and g_fp.orgSect is zero.

[Result for pic18LF2620 and CCS-C4.104]
g_fp.size is 50390016.
g_fp.curSect is 50390016.
g_fp.orgSect is zero.
_________________
--- Manzo Saita ---
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 04, 2010 11:59 pm     Reply with quote

Post a test program, in which you initialize those 3 structure elements
to some value, and then run the foo() function, and then display the
results of reading the structure elements. Something like this:

In other words, demonstrate the problem. Post the "before" and "after"
results of running the foo() function.
Code:

#include <18F2620.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

typedef struct
{
   int1   open;
   int32 holdSect;
   int8  index;
   int8  ttribute;
   int32 orgSect;
   int32 curSect;
   int32 size;
   int32 x;
   int16 xLocal;
   char   name[8+3];
}st_fileptr;


//st_fileptr g_fp;

st_fileptr g_fp = {
1,           // open
0x01234567,  // holdSect
0x55,        // index
0xAA,        // ttribute
0x00112233,  // orgSect
0x44556677,  // curSect
0x8899AABB,  // size
0x89ABCDEF,  // x
0x10A9,      // xLocal
{"Filename"}
};

 

void foo( void )
{
st_fileptr *d;

d = &g_fp;
//d = &(st_fileptr *)g_fp;

d->size    = 0x12345678;
d->curSect = 0x89ABCDEF;
d->orgSect = 0x98765432;
}

//=============================================
void main(void)
{

printf("size = %lx \r", g_fp.size);
printf("curSect = %lx \r", g_fp.curSect);
printf("orgSect = %lx \r", g_fp.orgSect);

foo();

printf("size = %lx \r", g_fp.size);
printf("curSect = %lx \r", g_fp.curSect);
printf("orgSect = %lx \r", g_fp.orgSect);

while(1);
}
 
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