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 support@ccsinfo.com

8 bit structure address?

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



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

8 bit structure address?
PostPosted: Wed Mar 09, 2016 10:00 am     Reply with quote

Here is a small test program to show my problem
Code:
typedef struct {
   int      index;
   int16    addr;
   int      location;
   int      dtype;
} TableAddrInfo;

TableAddrInfo   tio = { 1,2,3,4 };
void main ()
{

   TableAddrInfo  *pTi;
   void           *p;

   p = &tio;
   pTi = &tio;

   while (1);
}

The chip is 18F6723. The compiler is version 5.053. The problem is that the compiler thinks that pTi is an 8 bit pointer. Setting a breakpoint at the while statement, the value of p is 28B. The value of pTi is 8B. Why?

Thanks, Russ
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 09, 2016 11:49 am     Reply with quote

russk2txb wrote:

The compiler thinks that pTi is an 8 bit pointer. Setting a breakpoint at the
while statement, the value of p is 28B. The value of pTi is 8B.

I installed vs. 5.053 and compiled the following program. Then I ran it
in MPLAB vs. 8.92 simulator. The output is shown below. Conclusion:
the compiler is using 16-bit pointers for the structure address.
Quote:

p = 028b
pTi = 028b

Code:
#include <18F6723.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)


typedef struct {
   int      index;
   int16    addr;
   int      location;
   int      dtype;
} TableAddrInfo;


TableAddrInfo   tio = { 1,2,3,4 };
#locate tio = 0x28B

//========================
void main()
{
TableAddrInfo  *pTi;
void *p;

p = &tio;
pTi = &tio;

printf("p = %lx \r", p);
printf("pTi = %lx \r", pTi);

while(TRUE);
}

I don't have your full program with many ram variables, so I used the
#locate directive to set the address of 'tio' to 0x28B. Can you add code
to your program so it prints out the pointer values ? Don't use the
debugger with breakpoints and "mouse over". Just print them out with
"%lx". What do you get ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Wed Mar 09, 2016 3:24 pm     Reply with quote

and the PIC18, does not use 8bit pointers. My guess would be that whatever form of debugging you are using 'thinks' that pTi, is an 8bit variable.

As an update to this, a void pointer, will be a 16bit pointer, but until cast to another type, it'll be incremented in ones, while a pointer to another type is incremented in the size of this type. If you want to access the second element of a type, pointed to by a void pointer, you have to cast it to the type _before_ incrementing.
russk2txb



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

PostPosted: Thu Mar 10, 2016 3:50 am     Reply with quote

Thank you PCM. The ^&*(&*() debugger does it to me again! Using a printf as you did does indeed show the correct address. But if you use the debugger to show the address the pTi value will be shown truncated. Try hovering over the values with the mouse in the debugger, or using the eval window, and see if you get the same result, please.

When having problems with a piece of code the debugger has always been my second line of attack when I cannot see the problem by inspection of the code. But I am constantly having to learn how and when it fails in some way...

Regards, Russ
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Thu Mar 10, 2016 4:46 am     Reply with quote

In MPLAB, when you create a watch, you have the option to specify the size of the object being watched.
What is happening, is that MPLAB, is pulling from the Coff data the fact that the pointer points 'to' an 8bit value, and incorrectly defaulting to displaying the pointer 'as' an 8bit value. Manually specify the size as 16bit, and it should work fine.
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