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: 160
Posted: Wed Nov 08, 2017 11:05 am
I should have looked at the listing. So why does using strcpy work? I don't see why they should work differently.
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.
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