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

CCS Pointer Issue

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



Joined: 21 May 2012
Posts: 1

View user's profile Send private message

CCS Pointer Issue
PostPosted: Mon May 21, 2012 7:39 pm     Reply with quote

I'm facing an issue with CCS compiler version 4.065, when I compile the code below:
Code:

void main(void)
{
rom char Data[] = {1,2,3};
rom char *ShowData;
Mostra = &Data[0];
printf("%x", (char)*Mostra);
}

Instead of receiving the value 1 through the serial port, I'm getting always 10. Could you please someone help me on this. I have executed the same code on Code::Blocks and worked fine.
Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 21, 2012 8:58 pm     Reply with quote

Always post your PIC.
Ttelmah



Joined: 11 Mar 2010
Posts: 19331

View user's profile Send private message

PostPosted: Tue May 22, 2012 1:19 am     Reply with quote

I think 4.065, was before CCS got rom pointers to work. It was one of the features that was 'last' to get going, and my memory was that it didn't work before about 4.07x somewhere.
Sorry, but compiler upgrade only real answer if so.

Best Wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19331

View user's profile Send private message

PostPosted: Tue May 22, 2012 7:40 am     Reply with quote

As another comment though, you don't show the declaration of 'Mostra'. Also remember that 'Data' on it's own, is the address of the first element of the array.

Just tried:
Code:

#include <18F452.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                           //External 20MHz clock
#FUSES PUT                         //Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                //No Debug mode for ICD
#FUSES NOLVP

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,UART1,bits=8,ERRORS)

void main(void) {

   rom char Data[] = {1,2,3};
   rom char* ShowData; 
   int temp;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   ShowData = &Data[0];
   temp=*Showdata;
   printf("%02x\n", temp);
   do {
   } while (TRUE);
}

With 4.070 (the oldest V4 compiler I have kept), and it doesn't work.

Then compiled with 4.099, and it does.

I had tweaked a couple of things that might cause problems (I had found in the past that for some printf operators, you do have to extract the element from the array 'first'), but these didn't help on the older compiler.
So, I'm afraid 'compiler age' is the fundamental problem.

Best Wishes
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