digitalmars.D.bugs - Regarding hex strings
- bearophile (23/23) Oct 17 2012 Maybe hex strings were invented in D1 when strings were
- Jonathan M Davis (4/4) Oct 17 2012 On Thursday, October 18, 2012 01:58:25 bearophile wrote:
- bearophile (5/7) Oct 17 2012 Right Jonathan, I am sorry :-) I will try again in the main D
Maybe hex strings were invented in D1 when strings were
convertible to char[]. But today strings are an array of
immutable UFT-8, so I think this default type is now less useful:
void main() {
string data1 = x"A1 B2 C3 D4"; // OK
immutable(ubyte)[] data2 = x"A1 B2 C3 D4"; // error
}
Gives:
test.d(3): Error: cannot implicitly convert expression
("\xa1\xb2\xc3\xd4") of type string to ubyte[]
Generally I'd like to use hex literals to put binary data nicely
in a program, so usually I need an ubyte[] or uint[]. So I have
to use something like:
auto data3 = cast(ubyte[])(x"A1 B2 C3 D4".dup);
So maybe the following literals are more useful in D2:
ubyte[] data4a = x[A1 B2 C3 D4];
ubyte[4] data4b = x[A1 B2 C3 D4];
uint[] data5a = x[A1 B2 C3 D4];
uint[2] data5b = x[A1 B2 C3 D4];
ulong[] data6a = x[A1 B2 C3 D4 A1 B2 C3 D4];
ulong[1] data6b = x[A1 B2 C3 D4 A1 B2 C3 D4];
Bye,
bearophile
Oct 17 2012
On Thursday, October 18, 2012 01:58:25 bearophile wrote: [snip] You posted to the wrong list. - Jonathan M Davis
Oct 17 2012
Jonathan M Davis:You posted to the wrong list. - Jonathan M DavisRight Jonathan, I am sorry :-) I will try again in the main D newsgroup. Bye, bearophile
Oct 17 2012








"bearophile" <bearophileHUGS lycos.com>