On Thursday, 18 October 2012 at 10:05:06 UTC, bearophile wrote:
The docs say:
http://dlang.org/lex.html
Hex strings allow string literals to be created using hex data.
The hex data need not form valid UTF characters.<
But this code:
void main() {
immutable ubyte[4] data = x"F9 04 C1 E2";
}
Gives me:
temp.d(2): Error: Outside Unicode code space
Are the docs correct?
--------------------------
foobar:
Seems to me this is in the same ballpark as the built-in
complex numbers. Sure it's nice to be able to write "4+5i"
instead of "complex(4,5)" but how frequently do you actually
ever need the _literals_ even in complex computational heavy
code?
Compared to "oct!5151151511", one problem with code like this
is that binary blobs are sometimes large, so supporting a x""
syntax is better:
immutable ubyte[4] data = hex!"F9 04 C1 E2";
Bye,
bearophile
How often large binary blobs are literally spelled in the source
code (as opposed to just being read from a file)?
In any case, I'm not opposed to such a utility library, in fact I
think it's a rather good idea and we already have a precedent
with "oct!"
I just don't think this belongs as a built-in feature in the
language.