Re: where is the memory corruption?

2020-12-10 Thread Виталий Фадеев via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 20:35:21 UTC, Jack wrote: I'm on linux/opensuse, trying to pass a wchar_* from C to D but I'm getting only the first letter of that string. Could someone help figure out why? [...] May be this help to you: auto s2 = to!string(s); to auto s2

Re: where is the memory corruption?

2020-12-10 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 21:28:04 UTC, Paul Backus wrote: On Wednesday, 9 December 2020 at 21:21:58 UTC, ag0aep6g wrote: D's wchar is not C's wchar_t. D's wchar is 16 bits wide. The width of C's wchar_t is implementation-defined. In your case it's probably 32 bits. In D, C's wchar_t

Re: where is the memory corruption?

2020-12-09 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 21:21:58 UTC, ag0aep6g wrote: D's wchar is not C's wchar_t. D's wchar is 16 bits wide. The width of C's wchar_t is implementation-defined. In your case it's probably 32 bits. In D, C's wchar_t is available as `core.stdc.stddef.wchar_t`. http://dpldocs.info/e

Re: where is the memory corruption?

2020-12-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.12.20 21:35, Jack wrote: I'm on linux/opensuse, trying to pass a wchar_* from C to D but I'm getting only the first letter of that string. Could someone help figure out why? this is the piece of D code: extern(C) export void sayHello(const (wchar) *s) [...] and below the piece of C cod

Re: where is the memory corruption?

2020-12-09 Thread Dukc via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 20:35:21 UTC, Jack wrote: the output is "h" rather "hello". What am I missing? In the sayHello function, you are converting a pointer to utf16 character into utf8 string, not utf16 string to utf8 string. Convert the C wstring to a D `wstring` first (std.strin

where is the memory corruption?

2020-12-09 Thread Jack via Digitalmars-d-learn
I'm on linux/opensuse, trying to pass a wchar_* from C to D but I'm getting only the first letter of that string. Could someone help figure out why? this is the piece of D code: extern(C) export void sayHello(const (wchar) *s) { import std.stdio : writeln; import std.conv : to;