Coldfire: simple question of C string

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Coldfire: simple question of C string

跳至解决方案
2,933 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,016 次查看
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 项奖励
回复
3 回复数
1,016 次查看
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 项奖励
回复
1,016 次查看
Nouchi
Senior Contributor II
Hi,

So it's forbidden to use escape sequences inside quoted string?
0 项奖励
回复
1,017 次查看
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 项奖励
回复