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

Pointer Address

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



Joined: 09 Sep 2003
Posts: 22

View user's profile Send private message

Pointer Address
PostPosted: Tue Jan 13, 2004 9:47 pm     Reply with quote

How do you ABSOLUTELY make sure that the pointer holds the correct address if it is pointing to an array.

Sample of this code below presents a problem with addressing. The pointers seems to be confused even though the pointer is initialised by calling it inside main().

Assume that the array aX is allocated in BOTH Bank 1 and Bank 2. Therefore, the address is 14 bits wide but i seems the pointer SOMETIMES only copies the first 8 bits.

//declarations
int aX[60];
int *pA;


void initPointer()
{
pA = aX;
}



main()
{
initPointer();

//more code here to handle timer, processing of ata in aX, so, so...
}

Any help? Or should I just AVOID using pointers at all times.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 14, 2004 1:20 am     Reply with quote

Is this a theoretical problem, or is this a problem that you have
definitely found ?

What PIC are you using ?

What is the version of the compiler ?

Because you mentioned a 14-bit address, I'll assume that you
are using the PCM compiler. I'll assume the PIC is a 16F877.

Quote:
Assume that the array aX is allocated in BOTH Bank 1 and Bank 2
The compiler will never do this. Each array must not exceed
the size of a RAM bank.

Quote:
int aX[60];

Remember that in CCS, an "int" is only 8-bits. Therefore, this
array only uses 60 bytes. Since a RAM bank on a 16F877 is at least
80 bytes, the array will fit within one RAM bank. If it doesn't fit, the
compiler will give you an error messsage.

Quote:
Therefore, the address is 14 bits wide but it seems the pointer SOMETIMES only copies the first 8 bits.

If the compiler is using 8-bit pointers, it will only copy the lower 8-bits.
To enable 16-bit pointers, you need to do this:
Code:
#include <16F877.H>
#device *=16    // This line enables 16-bit pointers
arga



Joined: 09 Sep 2003
Posts: 22

View user's profile Send private message

PostPosted: Wed Jan 14, 2004 3:30 am     Reply with quote

The problem I have is that the array is in bank 1.

The array is type int, and so is the pointer.

#device *=16 is included.

I'm using the pic16f877, compiler ver. 3.173
Ttelmah
Guest







PostPosted: Wed Jan 14, 2004 8:19 am     Reply with quote

arga wrote:
The problem I have is that the array is in bank 1.

The array is type int, and so is the pointer.

#device *=16 is included.

I'm using the pic16f877, compiler ver. 3.173

I hope you mean that the pointer, is a pointer to an int, not an 'int' as such. Remember that an 'int', will only hold an 8bit value on a PIC, and an address (with 16bit RAM addressing), needs a 16bit storage location.
I have run into problems with the compiler truncating pointers in the past, but have not seen this on the more recent versions. When I ran into this, I found that I could 'bodeg' round the problem, by using a forced cast. I found that if you specifically tell the compiler to treat the pointers as being to 'long' types, it prevented the behaviour.
However this fault was definately fixed a long time ago.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 14, 2004 8:21 am     Reply with quote

So what is the problem? The upper byte shouldn't need to be changed if the array is in a bank. It would just be wasted instructions. Are you having a problem with the address being incorrect?
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