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

Warning 230

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



Joined: 18 Nov 2013
Posts: 117

View user's profile Send private message

Warning 230
PostPosted: Wed Nov 08, 2017 10:18 am     Reply with quote

I compiled an old program with v5.075 and I now get a warning about "String truncated" and I don't understand it.
Code:

#define MYSTRING  "some string"

void Func()
{
  char *p;
  p = MYSTRING;  // <-- WARNING 230: String truncated.

}

This is for an 18F87J60 with PCWHD v5.075.
PCM programmer



Joined: 06 Sep 2003
Posts: 20093

View user's profile Send private message

PostPosted: Wed Nov 08, 2017 10:47 am     Reply with quote

Quote:
#define MYSTRING "some string"

void Func()
{
char *p;

p = MYSTRING; // <-- WARNING 230: String truncated.

}

I don't see how you think that can work. "some string" is just a bunch of
MOVLW's. It's not an array.

Look at the .LST file to see what's happening. It's just taking the first
two characters from "some string" and stuffing them into the 16-bit
pointer 'p'. That's not what you wanted.
Quote:

.................... void Func()
.................... {
.................... char *p;
....................
.................... p = MYSTRING; // <-- WARNING 230: String truncated.
00004: MOVLW 73 // This is 's'
00006: MOVWF p
00008: MOVLW 6F // This is 'o'
0000A: MOVWF p+1
0000C: GOTO 002A (RETURN)
....................
................
SeeCwriter



Joined: 18 Nov 2013
Posts: 117

View user's profile Send private message

PostPosted: Wed Nov 08, 2017 11:05 am     Reply with quote

I should have looked at the listing. So why does using strcpy work? I don't see why they should work differently.
Code:

#define MYSTRING "some string"

void Func()
{
   char str[16];
   strcpy( str, MYSTRING );

}
PCM programmer



Joined: 06 Sep 2003
Posts: 20093

View user's profile Send private message

PostPosted: Wed Nov 08, 2017 11:29 am     Reply with quote

In the first program, there is no array. The compiler doesn't implicitly
create an array from the #define statement. There is no place for the
string to go.

In the 2nd example, strcpy() copies the constants from MYSTRING into a
RAM array that you declared.
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