}
else if (e1->op == TOKint64 && e2->op == TOKstring)
{
- // Concatenate the strings
+ // [w|d]?char ~ string --> string
+ // We assume that we only ever prepend one char of the same type
+ // (wchar,dchar) as the string's characters.
StringExp *es2 = (StringExp *)e2;
size_t len = 1 + es2->len;
unsigned char sz = es2->sz;
dinteger_t v = e1->toInteger();
void *s = mem.xmalloc((len + 1) * sz);
- memcpy((char *)s, &v, sz);
+ Port::valcpy((char *)s, v, sz);
memcpy((char *)s + sz, es2->string, es2->len * sz);
// Add terminating 0
struct U { int a; union { char c; int d; } long b; }
-U f = { b:3, d:2, a:1 };
+U f = { b:3, d:0x22222222, a:1 };
void testU()
{
assert(f.b == 3);
- assert(f.d == 2);
- assert(f.c == 2);
+ assert(f.d == 0x22222222);
+ assert(f.c == 0x22);
assert(f.a == 1);
assert(f.sizeof == 16);
assert(U.sizeof == 16);
int hoge(S29 s) {
char[10] b;
- printf("%x\n", s);
- sprintf(b.ptr, "%x", s);
- assert(b[0 .. 7] == "4030201");
+ printf("%x\n", *cast(int*)&s);
+ sprintf(b.ptr, "%x", *cast(int*)&s);
+ version (LittleEndian)
+ assert(b[0 .. 7] == "4030201");
+ version (BigEndian)
+ assert(b[0 .. 7] == "1020304");
return 0;
}
void test25()
{
- char[6] cstr = "123456"c;
- auto str1 = cast(wchar[3])(cstr);
-
- writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1));
- assert(cast(char[])str1 == "123456"c);
-
- auto str2 = cast(wchar[3])("789abc"c);
- writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2));
- assert(cast(char[])str2 == "789abc"c);
-
- auto str3 = cast(wchar[3])("defghi");
- writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3));
- assert(cast(char[])str3 == "d\000e\000f\000"c);
+ char[6] cstr = "123456"c;
+ auto str1 = cast(wchar[3])(cstr);
+
+ writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1));
+ assert(cast(char[])str1 == "123456"c);
+
+ auto str2 = cast(wchar[3])("789abc"c);
+ writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2));
+ assert(cast(char[])str2 == "789abc"c);
+
+ auto str3 = cast(wchar[3])("defghi");
+ writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3));
+ version (LittleEndian)
+ assert(cast(char[])str3 == "d\000e\000f\000"c);
+ version (BigEndian)
+ assert(cast(char[])str3 == "\000d\000e\000f"c);
}
/*******************************************/