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

Ponter to Constant

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



Joined: 02 Aug 2005
Posts: 14

View user's profile Send private message

Ponter to Constant
PostPosted: Fri Aug 05, 2005 8:39 am     Reply with quote

Hi,

I want to create a function like this.

void PrintStr( char *StringData )
{
}

When I perform this function: PrintStr("Hello World"), the compiler say:

Attempt to create a pointer to a Constant.

How can i solve this problem?

Thank you.
Leto.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Fri Aug 05, 2005 9:11 am     Reply with quote

CCS does not allow pointer to const. I use a 2D array
Code:

const char error_txt[8][16] =
{
  "USART overflow",  // -0-
  "TXBuffer ovrflw", // -1-
  "RXBuffer ovrflw", // -2-
  "Bad Checksum",    // -3-
  "",                // -4-
  "LCD X exceeded",  // -5-
  "LCD Y exceeded",  // -6-
  ""                 // -7-
};

//========================== err_chk ===============================
void ChkErr(void) //print out any errors that occured
{
  int8 chk=0;
  fprintf(STDERR,"ERROR(%U): %s.\r\n",chk,error_txt[chk]);
}
leto



Joined: 02 Aug 2005
Posts: 14

View user's profile Send private message

PostPosted: Fri Aug 05, 2005 9:39 am     Reply with quote

Thank you. i'll try as you say. But, I ask me how will the compiler do to compile printf("Hello world").

thanks anyway.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Fri Aug 05, 2005 9:47 am     Reply with quote

leto wrote:
Thank you. i'll try as you say. But, I ask me how will the compiler do to compile printf("Hello world").

thanks anyway.


Just use:
Code:
printf("Hello world");

_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Ttelmah
Guest







PostPosted: Fri Aug 05, 2005 10:02 am     Reply with quote

On the PrintStr function, declare a function like this instead:
Code:

void PrintStr(int chr) {
   //Do what you want with a _single_ character here.
   //So something like
   putc(chr);
}

If you then call:

PrintStr("Hello World");

The PrintStr will be called in turn, once for each single character of the output string.

Best Wishes
Mark



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

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

PostPosted: Fri Aug 05, 2005 10:38 am     Reply with quote

If you need to process the entire const string inside a function, then copy it to RAM first and then pass a pointer to the RAM buffer, otherwise ttelmah's suggestion works just fine and is something special that CCS does.
leto



Joined: 02 Aug 2005
Posts: 14

View user's profile Send private message

PostPosted: Fri Aug 05, 2005 11:02 am     Reply with quote

thank you again.

Im trying to improve the GlcdText57 function from graphics.c driver.
It receive a char pointer with the string to print, then it print each byte.
But, you must to declare the buffer previously.

e.g

char buffer[]="Hello Word";
GldText57( row, col, buffer, size, ..)

each time you want to print something you must to copy the String to buffer.

Sprintf(buffer,"string to print");
GldText57( row, col, buffer, size, ..);

I think Ttelmah's suggestion would must be better to dont spend enough memory. may be a little slower. What do you think?

Regards,
Leto.
Mark



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

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

PostPosted: Fri Aug 05, 2005 11:07 am     Reply with quote

If you are only going to print const strings then ttelmah suggestion works if you dont need to process the entire string at once.

However, if you are going to print strings that are "made on the fly" then you might be better off copying them to ram.
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