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

16 bit pointers

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







16 bit pointers
PostPosted: Thu Aug 19, 2004 3:14 am     Reply with quote

Hi.
This code works for 8 bit pointers (#device *=8), but it does not work for 16 bit pointers (#device *=16). &dataBytes is always 0x0000 and so is dataBytes[x] always 0x00.
Who can point me to my mistake?

Code:

// 8 bit -> char*
static void send_packet(byte cmd, char* dataBytes[], byte dataLength) {
// 16 bit -> long*
static void send_packet(byte cmd, long* dataBytes[], byte dataLength) {
   int8 i;

   putc(cmd);
   putc(dataLength);
   for (i = 0; i < dataLength; i++) {
      putc(dataBytes[i]);
   }
   putc(calc_chk(cmd, dataBytes, dataLength));
}

static void main() {
  byte dataBuffer[11];

  strcpy(dataBuffer, str);
  send_packet(cmd, dataBuffer, 10);
}


Regards.
GoatPete
Guest







Re: 16 bit pointers
PostPosted: Thu Aug 19, 2004 6:09 am     Reply with quote

Solved it myself.

Please note that this one is wrong, of course. It's still a pointer to a char.
GoatPete wrote:

Code:

// 16 bit -> long*
static void send_packet(byte cmd, long* dataBytes[], byte dataLength) {



This way it works in 8 bit and 16 bit mode:

Code:

static void send_packet(byte cmd, char* dataBytes, byte dataLength) {
   int8 i;

   putc(cmd);
   putc(dataLength);
   for (i = 0; i < dataLength; i++) {
      putc(dataBytes[i]);
   }
   putc(calc_chk(cmd, dataBytes, dataLength));
}


Regards,
GoatPete
Mark



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

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

PostPosted: Thu Aug 19, 2004 6:09 am     Reply with quote

#device *=8 and #device *=16 have nothing to do with char* and long* but rather the size of the actual pointer and not the size of the data. With #device *=8 pointers are only 8 bits which would allow you to only access a block of 256 bytes of RAM.

Code:

static void send_packet(byte cmd, byte* ptrBytes, byte dataLength)
{
   int8 i;

   putc(cmd);
   putc(dataLength);
   for (i = 0; i < dataLength; i++)
  {
     putc(*(ptrBytes+i));
   }
   putc(calc_chk(cmd, ptrBytes, dataLength));
}

static void main()
{
  byte dataBuffer[11];

  strcpy(dataBuffer, str);
  send_packet(cmd, dataBuffer, 10);
}
valemike
Guest







PostPosted: Thu Aug 19, 2004 8:01 am     Reply with quote

In the 16F family, after some headscratching, I realized that I needed to enable 16 bit pointers when my program started getting big. It also took its toll on overall ROM usage compared to 8-bit pointers.

I never found myself having to do 16 bit pointers for the 18F series. Are 16bit pointers enabled by default by the compiler for the 18F? Or is this convenience built into the 18F architecture?

Thanks,
Mike
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