Coldfire: simple question of C string

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Coldfire: simple question of C string

Jump to solution
2,322 Views
Nouchi
Senior Contributor II
Hi,
 
I'm using CW 6.3 for ColdFire. Somebody can tell me if I am in the wrong way or it's a bug?
I declare this:
const uint8 myString[] = "\x151234567890";
what I want : 0x15,0x31,0x32,.......
and I get : 0x90,0x00
If I do that:
const uint8 myString[] = "\x15 1234567890";
and I get : 0x15,0x20,0x31,............
const uint8 myString[] = "123\x154567890";
and I get : 0x31, 0x32, 0x33, 0x90,0x00
 
 
Emmanuel

Message Edited by CrasyCat on 2007-04-13 01:42 PM

Labels (1)
0 Kudos
1 Solution
405 Views
CompilerGuru
NXP Employee
NXP Employee
Hex escape sequences are taking many hex digits, not just two.
Your original sample was just a string with 1 character (with a very long syntax) and a zero byte.
Don't use hex escape sequences if the next character maybe taken as hex digit. The use of 3 octal digits is safe ("\0251234567890") or you can terminate one string literal and start a new one ("\x15" "1234567890")
or, and that's probably best, use one of the ways Lundin suggested.

Daniel

View solution in original post

0 Kudos
3 Replies
405 Views
Lundin
Senior Contributor IV
It should be

const uint8 myString[] = "\x15\x12\x34\x56\x78\x90";

or as an equal alternative

const uint8 myString[] = {0x15,0x12,0x34,0x56,0x78,0x90, 0x00};
0 Kudos
405 Views
Nouchi
Senior Contributor II
Hi,

So it's forbidden to use escape sequences inside quoted string?
0 Kudos
406 Views
CompilerGuru
NXP Employee
NXP Employee
Hex escape sequences are taking many hex digits, not just two.
Your original sample was just a string with 1 character (with a very long syntax) and a zero byte.
Don't use hex escape sequences if the next character maybe taken as hex digit. The use of 3 octal digits is safe ("\0251234567890") or you can terminate one string literal and start a new one ("\x15" "1234567890")
or, and that's probably best, use one of the ways Lundin suggested.

Daniel
0 Kudos