Coldfire: simple question of C string

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Coldfire: simple question of C string

ソリューションへジャンプ
2,947件の閲覧回数
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,030件の閲覧回数
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,030件の閲覧回数
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,030件の閲覧回数
Nouchi
Senior Contributor II
Hi,

So it's forbidden to use escape sequences inside quoted string?
0 件の賞賛
返信
1,031件の閲覧回数
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 件の賞賛
返信