Problem with dmd-2.104.0 -dip1000 & @safe

2023-06-08 Thread An Pham via Digitalmars-d-learn
Getting with below error for following codes. Look like bug? onlineapp.d(61): Error: scope variable `a` assigned to non-scope parameter `a` calling `foo` @safe: struct A(S = string) { @safe: S s; void delegate() c; } struct B(S = string) { @safe

Weird floating point rounding - Bug or how to control it correctly

2023-09-13 Thread An Pham via Digitalmars-d-learn
import std.stdio; void main() { float f = 6394763.345f; import std.format : sformat; char[80] vBuffer = void; writeln("6394763.345 = ", sformat(vBuffer[], "%.4f", f)); } Output 6394763.345 = 6394763.5000

Re: How to hash SHA256 from string?

2023-12-02 Thread An Pham via Digitalmars-d-learn
On Saturday, 2 December 2023 at 15:30:39 UTC, zoujiaqing wrote: ```D string appKey = "1"; ubyte[1024] data = cast(ubyte[])(appKey.dup[0..$]); sha256.put(data); Your data has garbage at the end; try sha256.put(data[0..appKey.leng

Re: Delegates and values captured inside loops

2024-01-21 Thread An Pham via Digitalmars-d-learn
On Saturday, 20 January 2024 at 15:59:59 UTC, Anonymouse wrote: I remember reading this was an issue and now I ran into it myself. ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dgs; foreach (name; names) { dgs ~= () => wri

Re: Delegates and values captured inside loops

2024-01-21 Thread An Pham via Digitalmars-d-learn
On Sunday, 21 January 2024 at 20:13:38 UTC, An Pham wrote: On Saturday, 20 January 2024 at 15:59:59 UTC, Anonymouse wrote: I remember reading this was an issue and now I ran into it myself. ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dg

How to terminate thread under module destructor?

2024-03-09 Thread An Pham via Digitalmars-d-learn
import core.thread.osthread : Thread; import std.stdio : writeln; __gshared static Thread th; __gshared static size_t tht; void run() { writeln("run"); while (tht == 0) {} } shared static this() { writeln("this"); th = new Thread(&run).start()

Re: SumType extraction

2024-07-06 Thread An Pham via Digitalmars-d-learn
On Thursday, 27 June 2024 at 18:51:19 UTC, Josh Holtrop wrote: Hello all. In my application I came across a desire to store an ordered array of handles that could point to one of several different objects, and it seems like the tool I want for that is SumType. I started with something like (s

Get compile time string of dmd command line options "-os" & "-target"

2024-07-31 Thread An Pham via Digitalmars-d-learn
pragma(msg, os.stringof...?); pragma(msg, target.stringof...?); what is use case for this? mixin & import Long list of version. version(Windows) mixin(import("foo_windows.enum.")); else version(AArch64) mixin(import("foo_aarch64.enum")); else static as