Re: How to implement this?

2022-04-07 Thread Elvis Zhou via Digitalmars-d-learn
On Friday, 8 April 2022 at 05:46:56 UTC, Elvis Zhou wrote: On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote: [...] I know where the issue comes from, dynamic array is GCed and save the reference of a local variable in GCed memory is not allowed, but here structs is assumed to not

Re: How to implement this?

2022-04-07 Thread Elvis Zhou via Digitalmars-d-learn
On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote: struct A {} struct B { A a; } struct C { A a; } A*[] structs; B b; init(); structs ~= cast(A*) //Error: copying `cast(A*)& b` into allocated memory escapes a reference to local variable `b` C c; init(); structs ~= cast(A*) //Error:

Re: How to implement this?

2022-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 4/7/22 21:31, Elvis Zhou wrote: > > struct A {} > struct B { A a; } > struct C { A a; } > > A*[] structs; > > B b; > init(); > structs ~= cast(A*) > //Error: copying `cast(A*)& b` into allocated memory escapes a reference > to local variable `b` If that really is the case, you want to place

Re: How to implement this?

2022-04-07 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 8 April 2022 at 04:54:35 UTC, Era Scarecrow wrote: Maybe it should be `cast(A*) `? Confusing HTML entities bit on here. Probably just ignore it. Maybe you are doing it backwards. What if you had ```d struct B { A* a; } A[] arraylist; ``` then in the init append a new item to

Re: How to implement this?

2022-04-07 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote: B b; init(\); structs ~= cast(A*)\ //Error: copying `cast(A*)\& b` into allocated memory escapes a reference to local variable `b` Maybe it should be `cast(A*) \`?

How to implement this?

2022-04-07 Thread Elvis Zhou via Digitalmars-d-learn
struct A {} struct B { A a; } struct C { A a; } A*[] structs; B b; init(); structs ~= cast(A*) //Error: copying `cast(A*)& b` into allocated memory escapes a reference to local variable `b` C c; init(); structs ~= cast(A*) //Error: copying `cast(A*)& c` into allocated memory escapes a

Re: Again, ask help with Dlang program footprint

2022-04-07 Thread dangbinghoo via Digitalmars-d-learn
On Friday, 8 April 2022 at 03:20:29 UTC, dangbinghoo wrote: hi, I just asked for help about this before, on that time, my solution is to remove whatever dub dependencies which are optional. now, I'm re-examining the dlang program footprint size, and I put a github example repo here:

Again, ask help with Dlang program footprint

2022-04-07 Thread dangbinghoo via Digitalmars-d-learn
hi, I just asked for help about this before, on that time, my solution is to remove whatever dub dependencies which are optional. now, I'm re-examining the dlang program footprint size, and I put a github example repo here: https://github.com/dangbinghoo/dlang_footprint_test.git the

Re: Looking for a workaround

2022-04-07 Thread Guillaume Piolat via Digitalmars-d-learn
On Thursday, 7 April 2022 at 12:56:05 UTC, MoonlightSentinel wrote: On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote: Any idea how to workaround that? I really need the same UDA in parent and child class. Use a frontend >= dmd 2.099, it works according to run.dlang.io.

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
On Thursday, 7 April 2022 at 12:51:26 UTC, Stanislav Blinov wrote: On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: wchar_t* clang_string = cast(wchar_t *)"AA"; You're witnessing undefined behavior. "AA" is a string literal and is stored in the data

Re: Looking for a workaround

2022-04-07 Thread MoonlightSentinel via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote: Any idea how to workaround that? I really need the same UDA in parent and child class. Use a frontend >= dmd 2.099, it works according to run.dlang.io.

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: wchar_t* clang_string = cast(wchar_t *)"AA"; You're witnessing undefined behavior. "AA" is a string literal and is stored in the data segment. Mere cast to wchar_t* does not make writing through that

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
On Thursday, 7 April 2022 at 11:03:39 UTC, Tejas wrote: On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: Here I try to concatenate three character strings using `wcsncat()`. [...] Maybe try using `wstring` instead of string? Also use the `w` postfix ```d wstring dlang_string =

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread Tejas via Digitalmars-d-learn
On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: Here I try to concatenate three character strings using `wcsncat()`. [...] Maybe try using `wstring` instead of string? Also use the `w` postfix ```d wstring dlang_string = "BBB"w; I can't test because I'm not on my PC and I

A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
Here I try to concatenate three character strings using `wcsncat()`. `clang_string` AA `dlang_string` BBB `winpointer_to_string` CC ``` import std.stdio; @system void main(){ import std.utf: toUTF16z, toUTF16; import

Re: Conversion from ANSI 1252 to unicode

2022-04-07 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 7 April 2022 at 07:24:03 UTC, Johann wrote: Hi all, anybody knows if there are functions (preferably) in Phobos, that translate from unicode to other encodings and vice versa? Johann https://dlang.org/phobos/std_encoding.html

Conversion from ANSI 1252 to unicode

2022-04-07 Thread Johann via Digitalmars-d-learn
Hi all, anybody knows if there are functions (preferably) in Phobos, that translate from unicode to other encodings and vice versa? Johann