Binary data in the code?
Bill Baxter
wbaxter at gmail.com
Sat Nov 4 21:09:14 PST 2006
BCS wrote:
> == Quote from Bill Baxter (wbaxter at gmail.com)'s article
>
>>How does one embed binary data in code with D?
>>In C/C++ one would do something like:
>> static const unsigned char data[] = {99,12,2,21};
>>The compiler counts the elements for you, but you still get a
>>compile-time length, so you can do sizeof(data) and you'll get
>>back 4 in the above example.
>
> [...]
>
>>Thanks,
>>--bb
>
>
>
> IIRC, this works:
>
> auto data = [cast(char)99,12,2,21];
> // type of data == char[4];
Ick. Combines the lack of readability of 'auto' with the lameness of
D's first-value array typing rule.
It's beside the point though, since that doesn't actually work.
staticdata.d(9): Error: cannot infer type from initializer
--bb
More information about the Digitalmars-d-learn
mailing list