On Thursday, 8 February 2018 at 00:24:22 UTC, Walter Bright wrote:
On 2/7/2018 8:03 AM, Ralph Doncaster wrote:
As expected,
auto data = cast(ubyte[]) x"deadbeef";
works with -betterC, but
auto data = cast(ubyte[]) hexString!"deadbeef";
does not.
When I tried it:
import std.conv;
void test() {
auto data = cast(ubyte[]) hexString!"deadbeef";
}
with:
dmd -c -betterC test2.d
it compiled without complaint. Are you doing something
different? (This is why posting complete examples, not
snippets, is better. That way I don't have to fill in the
blanks with guesswork.)
I didn't think it would be that hard to guess I'm trying to make
an executable.
ralphdoncaster@gl1u:~/code/d$ dmd -betterC hex.d
hex.o: In function
`_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa':
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x2e):
undefined reference to `_D11TypeInfo_Aa6__initZ'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x33):
undefined reference to `_d_arraysetlengthiT'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x7c):
undefined reference to `_D3std5ascii10isHexDigitFNaNbNiNfwZb'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x160):
undefined reference to `_D11TypeInfo_Aa6__initZ'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x165):
undefined reference to `_d_arraysetlengthiT'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
ralphdoncaster@gl1u:~/code/d$ cat hex.d
import std.conv;
extern (C) int main() {
//auto data = cast(ubyte[]) x"deadbeef";
auto data = cast(ubyte[]) hexString!"deadbeef";
return cast(int) data[0];
}
While the string hex literal version works fine:
ralphdoncaster@gl1u:~/code/d$ dmd -betterC hex.d
ralphdoncaster@gl1u:~/code/d$ ./hex
ralphdoncaster@gl1u:~/code/d$ echo $?
222
ralphdoncaster@gl1u:~/code/d$ cat hex.d
//import std.conv;
extern (C) int main() {
auto data = cast(ubyte[]) x"deadbeef";
//auto data = cast(ubyte[]) hexString!"deadbeef";
return cast(int) data[0];
}