Re: Missing library dependencies compiling app with importC
Wich version of visual studio you have? From what i could find online, it could be due to having an older version, try to update it if it's too old
Re: LDC Stacktrace with symbols instead of addresses
I agree, debug builds should show proper stack trace by default You should submit a PR for dmd and call what ever is that function behind a `debug` block when it hooks the C main function As for LDC, it's weird that it doesn't work, they should share the same runtime no?
Re: How to unpack a tuple into multiple variables?
On Wednesday, 7 February 2024 at 05:29:45 UTC, Gary Chike wrote: On Wednesday, 7 February 2024 at 01:17:33 UTC, zjh wrote: Officially, there should be an unpacking solution, like ```d //C++ auto[a,b,c]=tuple. ``` Wouldn't that be nice? I hope a clean and terse direct-implementation comes in the near future. :) There was a DIP for native tuples in D, hopefully we'll get it soon
Re: Why is the following failing?
On Thursday, 25 January 2024 at 17:50:57 UTC, Johan wrote: On Thursday, 25 January 2024 at 16:07:44 UTC, Stefan Koch wrote: On Thursday, 25 January 2024 at 15:39:08 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect for the example above.. Raise a bug, I'll fix it. Hmm. To me, the bug is that string assignment to the array is allowed. Because this also compiles without any compile error: ```D void main() { char[4] id; id = "hello asdad"; } ``` I created an issue and included that case https://issues.dlang.org/show_bug.cgi?id=24355
Re: Why is the following failing?
```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect for the example above..
Re: Why is the following failing?
On Thursday, 25 January 2024 at 15:22:35 UTC, Hipreme wrote: On Thursday, 25 January 2024 at 15:20:01 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; } ``` it should be a simple memcpy, why DMD complain? ``onlineapp.d(6): Error: mismatched array lengths 32 and 6 for assignment `id[] = str[0..6]``` I'm too tired to notice something obvious? You need to slice your `id` variable to be the required size. You're trying to assign the complete `id` variable to a slice of size 6. i.e: that should be used instead `id[0..6] = str[0..6]` That's dumb, compiler knows that ``id`` has enough room and it should do a simple memcpy, i shouldn't have to do that myself.. i'll stick to calling memcpy.. why stray away from C to do worse
Why is the following failing?
```D void main() { char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; } ``` it should be a simple memcpy, why DMD complain? ``onlineapp.d(6): Error: mismatched array lengths 32 and 6 for assignment `id[] = str[0..6]``` I'm too tired to notice something obvious?
Re: opApply + const
On Tuesday, 23 January 2024 at 17:22:25 UTC, Paul Backus wrote: On Tuesday, 23 January 2024 at 16:11:25 UTC, ryuukk_ wrote: It works fine.. but when the variable becomes ``const(Stuff)* stuff;`` It gives me: ``` onlineapp.d(13): Error: cannot uniquely infer `foreach` argument types ``` I have no idea what i should be doing, does anyone have a clue? https://issues.dlang.org/show_bug.cgi?id=24353 Thanks, the error message was confusing me.. I tried to fix it https://github.com/dlang/dmd/pull/16086
Re: opApply + const
On Tuesday, 23 January 2024 at 17:07:18 UTC, Alexandru Ermicioi wrote: On Tuesday, 23 January 2024 at 16:11:25 UTC, ryuukk_ wrote: Hello, I have the following: ```D struct Stuff { int opApply(scope int delegate(Stuff*) dg) { return 0; } }; void main() { Stuff* stuff; foreach(it; *stuff) {} } ``` It works fine.. but when the variable becomes ``const(Stuff)* stuff;`` It gives me: ``` onlineapp.d(13): Error: cannot uniquely infer `foreach` argument types ``` I have no idea what i should be doing, does anyone have a clue? Try making opApply const. Thanks that fixed it
opApply + const
Hello, I have the following: ```D struct Stuff { int opApply(scope int delegate(Stuff*) dg) { return 0; } }; void main() { Stuff* stuff; foreach(it; *stuff) {} } ``` It works fine.. but when the variable becomes ``const(Stuff)* stuff;`` It gives me: ``` onlineapp.d(13): Error: cannot uniquely infer `foreach` argument types ``` I have no idea what i should be doing, does anyone have a clue?
Re: std.sumtype nested SumTypes
On Monday, 22 January 2024 at 16:16:56 UTC, NonNull wrote: I am defining a new value type (small struct) from some old value types that are already `SumType`s. So I want to have some `SumType`s as some of the alternative types in another `SumType`. How how efficient this is, including space efficient? Without knowing what you are doing, this sounds like a bad idea, i suggest to revise your design
Re: Setting field of struct object
I should note that it only took me 1 project to never want to touch C++ again.. that must be telling something, either about the language, or me, or both lol
Re: Setting field of struct object
On Monday, 22 January 2024 at 11:31:11 UTC, zjh wrote: On Monday, 22 January 2024 at 08:54:54 UTC, zjh wrote: ```d struct Person { string name, email; ulong age; } Person a{"n","email",33}; ``` C++ can achieve ultimate `simplicity` without violating `DRY`, And here, D violates the `DRY` principle! Moreover, as the `package level, module level, class level, member level`, D language violates integrity. Because D has no `class level` limit. These are all not `serious states`. I used to want this feature too, but i then got hit by a bug when i reordered the fields in the struct.. i don't want to deal with that stuff anymore But we now have named arguments, so this feature could be make use of it, it's similar with enums, perhaps one day this could be revived: https://github.com/dlang/DIPs/blob/e2ca557ab9d3e60305a37da0d5b58299e0a9de0e/DIPs/DIP1044.md There is even a working implementation: https://github.com/dlang/dmd/pull/14650
Re: macOS Sonoma Linker Issue
On Saturday, 20 January 2024 at 20:35:16 UTC, Renato wrote: On Friday, 22 December 2023 at 17:50:47 UTC, Johan wrote: Some general advice: 1 - use `dub` from LDC's package (this may solve some arm64 vs x86 issues when on Apple Silicon CPU) 2 - when you use a new or different compiler, you have to rebuild _all_ packages. So clear your dub cache. I think point 2 is causing your issues. -Johan Hi again, I hate to repeat myself, but the linker issues on MacOS keep happening, even after using this in the dub recipe: ``` lflags "-ld_classic" ``` Even though this helps, every now and then I am faced with a horrible error like this (happened on multiple projects): ``` ld: warning: pointer not aligned at address 0x10017FA3A ('anon' + 115 from ../../../.dub/cache/prettyprint/1.0.9/build/library-unittest-zRys5rzGP6krRGvFrhQ1nw/libprettyprint.a(primitives_64_42b.o)) ld: warning: pointer not aligned at address 0x10017FACD ('anon' + 115 from ../../../.dub/cache/prettyprint/1.0.9/build/library-unittest-zRys5rzGP6krRGvFrhQ1nw/libprettyprint.a(primitives_65_55a.o)) hundreds of lines just like this ld: warning: pointer not aligned at address 0x100199171 ('anon' + 117 from ../../../.dub/cache/tested/0.9.5/build/library-unittest-GNkuLeNnFlMZmRhvBdmNgA/libtested.a(lifetime_2ae_75b.o)) ld: unaligned pointer(s) for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Error: linker exited with status 1 Error /Users/renato/dlang/dmd-2.106.1/osx/bin/dmd failed with exit code 1. ``` It doesn't matter if I use LDC or DMD. Both cause the same error. I've tried cleaning the DUB cache like this: ``` rm -rf ~/.dub/cache ``` But it doesn't help. It's very frustrating because I'm close to finishing my project, but this kind of random error really delays me... it seems that as I keep changing code, the linker eventually starts working again! I must be hitting some "bad path" in the compiler. So, if anyone who understands about linking on MacOS could have a look, here's a commit on the project I'm currently working on which shows this problem: https://github.com/renatoathaydes/dzipper/commit/54d1f90f18a17d87d71195df68d02089ca4cf27c If you checkout this commit, just run `dub test` and you should see the problem on MacOS Sonoma. Notice that the current state of my code is "in progress" so some stuff may not even be working properly yet, the tests may not even be passing, that's fine (if I only I could run the tests)... but as the error is on the linker, I believe it's compiling properly and there should never be any linker errors like this. dub might not be passing this flag down to dependencies.. Try this env variable: ``LDFLAGS="$LDFLAGS -Wl,-ld_classic" dub build`` If that doesn't work, try this one: ``MACOSX_DEPLOYMENT_TARGET=11 dub build``
Re: Delegates and values captured inside loops
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 ~= () => writeln(name); } foreach (dg; dgs) { dg(); } } ``` Expected output: `foo`, `bar`, `baz` Actual output: `baz`, `baz`, `baz` If I make `names` an `AliasSeq` it works, but I need it to be a runtime array. Is there a workaround? ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dgs; foreach (name; names) { (it) { dgs ~= () => writeln(it); }(name); } foreach (dg; dgs) { dg(); } } ``` This is the workaround according to: https://issues.dlang.org/show_bug.cgi?id=21929#c9
Re: Help optimize D solution to phone encoding problem: extremely slow performace.
On Friday, 19 January 2024 at 17:18:36 UTC, evilrat wrote: On Friday, 19 January 2024 at 16:55:25 UTC, ryuukk_ wrote: You do hash map lookup for every character in D, it's slow, whereas in Rust you do it via pattern matching, java does the same, pattern matching Yet another reason to advocate for pattern matching in D and switch as expression There is another important difference, i quickly looked up D associative array implementation and the search looks like nlog(n) complexity with plain loop iteration of hashes, whereas rust's implementation is using "swisstable" algorithm implementation that has packed SIMD optimized lookups, this is likely where the 3x speed difference comes from. Tried to look up rust implementation and it is SOOO generic that I was unable to decipher it to find the actual key search and stores. Anyway here is an interesting article about rust implementation https://faultlore.com/blah/hashbrown-tldr/ I'm not talking about the difference between the hashmap implementation, but the difference between the algorithm used to lookup the characters https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/9b1d7f026943841638a2729922cf000b1b3ce655/src/java/Main2.java#L106-L134 vs https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/40cd423fc9dd1b1b47f02d8ab66ca03420820e84/src/d/src/dencoder.d#L10-L49 If D had pattern matching and switch as expression, the faster method would be: 1. the most obvious choice 2. the fastest by default 3. the most clean To save from having to write a old-school verbose `switch`, i suspect he went with a hashmap, wich is slower in that case, hence why i keep advocate for that feature, or i should say, that upgrade to `switch`, wich java has adopted, as well as rust: https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/40cd423fc9dd1b1b47f02d8ab66ca03420820e84/src/rust/phone_encoder/src/main.rs#L146-L168
Re: Help optimize D solution to phone encoding problem: extremely slow performace.
On Friday, 19 January 2024 at 13:40:39 UTC, Renato wrote: On Friday, 19 January 2024 at 10:15:57 UTC, evilrat wrote: On Friday, 19 January 2024 at 09:08:17 UTC, Renato wrote: I forgot to mention: the Java version is using a Trie... and it consistently beats the Rust numeric algorithm (which means it's still faster than your D solution), but the Java version that's equivalent to Rust's implementation is around 3x slower... i.e. it runs at about the same speed as my current fastest numeric algorithm in D as well. Additionally if you comparing D by measuring DMD performance - don't. It is valuable in developing for fast iterations, but it lacks many modern optimization techniques, for that we have LDC and GDC. I tried with DMD again, and yeah, it's much slower. Here's the [current implementation in D](https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/dlang-key-hash-incremental/src/d/src/dencoder.d), and the roughly [equivalent Rust implementation](https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/dlang-key-hash-incremental/src/rust/phone_encoder/src/main.rs). The only "significant" difference is that in Rust, an enum `WordOrDigit` is used to represent currently known "words"... I [did try using that in D](https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/dlang-int128-word-and-digit/src/d/src/dencoder.d), but it made the algorithm slower. If you see anything in D that's not as efficient as it should be, or somehow "inferior" to what the Rust version is doing , please let me know. Notice that almost all of the time is spent in the for-loop inside `printTranslations` (which is misnamed as it doesn't necessarily "print" anything, like it did earlier) - the rest of the code almost doesn't matter. Current performance comparison: ``` Proc,Run,Memory(bytes),Time(ms) ===> ./rust ./rust,23920640,31 ./rust,24018944,149 ./rust,24084480,601 ./rust,24248320,1176 ./rust,7798784,2958 ./rust,7815168,15009 ===> src/d/dencoder src/d/dencoder,14254080,36 src/d/dencoder,24477696,368 src/d/dencoder,24510464,1740 src/d/dencoder,24559616,3396 src/d/dencoder,11321344,6740 src/d/dencoder,11321344,36787 ``` So , it's not really 3x slower anymore, here's the "D overhead" considering Rust as the baseline: ``` 1.161290323 2.469798658 2.895174709 2.887755102 2.278566599 2.450996069 ``` You do hash map lookup for every character in D, it's slow, whereas in Rust you do it via pattern matching, java does the same, pattern matching Yet another reason to advocate for pattern matching in D and switch as expression
Re: How to use ImportC to import WebGPU header
You need to use a .c file that include it --- webgpu.c ```c #include "webgpu.h" ``` --- app.d ```d import std.stdio; import webgpu; void main() { writeln(WGPUBlendFactor_Dst); } ``` result: ``` $ dmd -run app.d webgpu.c WGPUBlendFactor_Dst ```
Re: sokol-d: Static Struct
On Wednesday, 3 January 2024 at 17:50:19 UTC, Matheus Catarino wrote: On Saturday, 30 December 2023 at 20:20:50 UTC, ryuukk_ wrote: I suspect you have a typo in one of your definition I debugged some existing bindings, and despite any user-level errors (via code) there's some conflict between ABIs. In fact, it's mentioned by sokol's author below: I've been seeing weird platform-specific ABI related issues in language bindings where the struct params were corrupted on their way to the other language (for instance in Zig on Intel Macs). https://github.com/kassane/sokol-d/issues/5#issuecomment-1875665075 I managed to compile your project, ``sgl_context`` is working for me, it renders and roate I had to remove this from your build script tho: ``try cmds.append(b.fmt("--mcpu={s}", .{lib.target.getCpuModel().name}));`` Otherwise it crashes ``` ryuukk@ark:~/dev/tmp/sokol-d (main) $ zig build sgl_context && ./zig-out/bin/sgl_context 'x86_64' is not a recognized processor for this target (ignoring processor) 'x86_64' is not a recognized processor for this target (ignoring processor) /home/ryuukk/dev/tmp/sokol-d/src/examples/sgl_context.d(36,20): `display` is thread local /home/ryuukk/dev/tmp/sokol-d/src/examples/sgl_context.d(37,22): `offscreen` is thread local 'x86_64' is not a recognized processor for this target (ignoring processor) 'x86_64' is not a recognized processor for this target (ignoring processor) 'x86_64' is not a recognized processor for this target (ignoring processor) 'x86_64' is not a recognized processor for this target (ignoring processor) LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it! #0 0x7f8df5c1f503 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-16.so+0xe1f503) #1 0x7f8df5c1c7bf llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-16.so+0xe1c7bf) #2 0x7f8df5c1c90d (/usr/lib/libLLVM-16.so+0xe1c90d) #3 0x7f8df485c710 (/usr/lib/libc.so.6+0x3e710) #4 0x7f8df48ac83c (/usr/lib/libc.so.6+0x8e83c) #5 0x7f8df485c668 gsignal (/usr/lib/libc.so.6+0x3e668) #6 0x7f8df48444b8 abort (/usr/lib/libc.so.6+0x264b8) #7 0x7f8df594d25f (/usr/lib/libLLVM-16.so+0xb4d25f) #8 0x7f8df5b1f19e (/usr/lib/libLLVM-16.so+0xd1f19e) #9 0x7f8df999688c (/usr/lib/libLLVM-16.so+0x4b9688c) #10 0x7f8df99970b9 (/usr/lib/libLLVM-16.so+0x4b970b9) #11 0x7f8df999eb48 (/usr/lib/libLLVM-16.so+0x4b9eb48) #12 0x7f8df999ee95 (/usr/lib/libLLVM-16.so+0x4b9ee95) #13 0x7f8df822d39a (/usr/lib/libLLVM-16.so+0x342d39a) #14 0x7f8df78e9556 llvm::TargetIRAnalysis::run(llvm::Function const&, llvm::AnalysisManager&) (/usr/lib/libLLVM-16.so+0x2ae9556) #15 0x7f8df6a42b48 (/usr/lib/libLLVM-16.so+0x1c42b48) #16 0x7f8df5dfbe7e llvm::AnalysisManager::getResultImpl(llvm::AnalysisKey*, llvm::Function&) (/usr/lib/libLLVM-16.so+0xffbe7e) #17 0x7f8df75c9af0 llvm::AssumptionAnalysis::run(llvm::Function&, llvm::AnalysisManager&) (/usr/lib/libLLVM-16.so+0x27c9af0) #18 0x7f8df6a839d2 (/usr/lib/libLLVM-16.so+0x1c839d2) #19 0x7f8df5dfbe7e llvm::AnalysisManager::getResultImpl(llvm::AnalysisKey*, llvm::Function&) (/usr/lib/libLLVM-16.so+0xffbe7e) #20 0x7f8df75daecb llvm::BasicAA::run(llvm::Function&, llvm::AnalysisManager&) (/usr/lib/libLLVM-16.so+0x27daecb) #21 0x7f8df9b7086f (/usr/lib/libLLVM-16.so+0x4d7086f) #22 0x7f8df5dfbe7e llvm::AnalysisManager::getResultImpl(llvm::AnalysisKey*, llvm::Function&) (/usr/lib/libLLVM-16.so+0xffbe7e) #23 0x7f8df9bd352c (/usr/lib/libLLVM-16.so+0x4dd352c) #24 0x7f8df75b760b llvm::AAManager::run(llvm::Function&, llvm::AnalysisManager&) (/usr/lib/libLLVM-16.so+0x27b760b) #25 0x7f8df7957b39 (/usr/lib/libLLVM-16.so+0x2b57b39) #26 0x7f8df5dfbe7e llvm::AnalysisManager::getResultImpl(llvm::AnalysisKey*, llvm::Function&) (/usr/lib/libLLVM-16.so+0xffbe7e) #27 0x7f8df71fc56b llvm::AlwaysInlinerPass::run(llvm::Module&, llvm::AnalysisManager&) (/usr/lib/libLLVM-16.so+0x23fc56b) #28 0x7f8df9b727f6 (/usr/lib/libLLVM-16.so+0x4d727f6) #29 0x7f8df5df8466 llvm::PassManagerllvm::AnalysisManager>::run(llvm::Module&, llvm::AnalysisManager&) (/usr/lib/libLLVM-16.so+0xff8466) #30 0x558a65baa7a2 runOptimizationPasses(llvm::Module*) (/usr/bin/ldc2+0x9c37a2) #31 0x558a65bac10f ldc_optimize_module(llvm::Module*) (/usr/bin/ldc2+0x9c510f) #32 0x558a65c92c2d writeModule(llvm::Module*, char const*) (/usr/bin/ldc2+0xaabc2d) #33 0x558a65c8d1f8 ldc::CodeGenerator::writeAndFreeLLModule(char const*) (/usr/bin/ldc2+0xaa61f8) #34 0x558a65c56512 codegenModules(Array&) (/usr/bin/ldc2+0xa6f512) #35 0x558a658a6728 mars_mainBody(Param&, Array&, Array&) (/usr/bin/ldc2+0x6bf728) #36 0x558a65c547c7 cppmain() (/usr/bin/ldc2+0xa6d7c7) #37 0x558a65dffa9d _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv (/usr/bin/ldc2+0xc18a9d) #38 0x558a65dff8b7 _d_run_main2 (/usr/bin/ldc2+0xc188b7) #39
Re: Web APis
nvm, that's not what you are asking for
Re: Web APis
On Sunday, 31 December 2023 at 04:40:02 UTC, Axel Casillas wrote: Hi there, I'm trying to implement web api's into a terminal program. With some help at the IRC have gotten pretty far but just hit a roadblock trying to manipulate the web api to accept input from the user. Example: auto content = get("www.webapiurl.com/data/v4/example?name=category=2022-01-24=2023-01-24=01010101010101010101"); writefln! %s (content); the above is just an example and for the most part it works but I am unable to make the 'category','from=date' and 'to=date' a user modified variable. It doesn't matter how I attempt to split the API into different sections and define variables before running the program it wont compile. Has anybody ever run into this and if someone has could you point me to some example code that might make it ease for me to understand, would greatly appreciate. Try this: ```D import std.uri; auto content = get("www.webapiurl.com/data/v4/example?name=category=2022-01-24=2023-01-24=01010101010101010101".encode); ``` Notice the ``.encode`` https://dlang.org/phobos/std_uri.html#.encode
Re: sokol-d: Static Struct
Use https://renderdoc.org/ and check and compare frames for both your working and non-working example That'll give you an idea at what could be wrong I suspect you have a typo in one of your definition I'll try to take a look later
Re: surviving wasm
I forgot to link this nice website that got me started with WASM: https://schellcode.github.io/webassembly-without-emscripten
Re: surviving wasm
On Wednesday, 13 December 2023 at 20:40:20 UTC, monkyyy wrote: so long term planning on wasm raylib; I want compatibility with the good parts of the std, the std is causal about using libc while ldc-wasm half-baked implication is missing a bunch of basically worthless symbols but given the std is 1 million lines of code it will be a perennial problem that I make something work natively, I try it in wasm, it breaks citing a random core lib at a random line; the options I know about are: 1. use a "team betterc" personal std that doesn't have the apis I want, apis I know and probably limited 2. merge "use libc less" upstream to a std that has been slow to merge changes and probably doesnt care about wasm 3. fork the std 4. maintain patches to the std that go in and rewrite them live with root :D what could go wrong 5. make my own personal std that matches the std api of the parts I use I hate all these options there is no libc on WASM, you'll either have to use WASI or emscripten emscripten was made for this specific case, so you don't have to worry about anything https://theartofmachinery.com/2018/12/20/emscripten_d.html I personally started from scratch, so i only pay for what i use, and carefully craft my own std/runtime, and it's the way to go imo, just like i'd do in C, but with the advantage of using a better language (D)
Re: Request help on allocator.
On Saturday, 2 December 2023 at 19:13:18 UTC, Vino B wrote: Hi All, Request your help in understanding the below program, with the below program I can allocate 8589934592(8GB) it prints the length 8589934592(8GB) where as my laptop has only 4 GB so the confusion is that how can this program allocate 8GB RAM when I have only 4GB of RAM installed ``` import std.algorithm.comparison : max; import std.experimental.allocator.building_blocks.allocator_list : AllocatorList; import std.experimental.allocator.building_blocks.bucketizer; import std.experimental.allocator.building_blocks.free_list : FreeList; import std.experimental.allocator.building_blocks.region : Region; import std.experimental.allocator.building_blocks.segregator; import std.experimental.allocator.common : unbounded; import std.experimental.allocator.mallocator : Mallocator; import std.stdio: writeln; void main () { alias FList = FreeList!(Mallocator, 0, unbounded); alias A = Segregator!( 8, FreeList!(Mallocator, 0, 8), 128, Bucketizer!(FList, 1, 128, 16), 256, Bucketizer!(FList, 129, 256, 32), 512, Bucketizer!(FList, 257, 512, 64), 1024, Bucketizer!(FList, 513, 1024, 128), 2048, Bucketizer!(FList, 1025, 2048, 256), 3584, Bucketizer!(FList, 2049, 3584, 512), 4097 * 1024, AllocatorList!(n => Region!Mallocator(max(n, 1024 * 4096))), Mallocator ); A tuMalloc; auto c = tuMalloc.allocate(8589934592); // 8GB writeln(c.length); // output: 8589934592 tuMalloc.deallocate(c); } ``` From, Vino This is normal behavior on linux, it's called overcommit memory, i think it was meant to allow things like fork() to work properly https://stackoverflow.com/a/7504354
Re: Inversion of conditional compilation statements
On Saturday, 2 December 2023 at 15:48:02 UTC, Nick Treleaven wrote: On Saturday, 2 December 2023 at 15:03:25 UTC, ryuukk_ wrote: I wish we could use ``version`` as expression, to void the repetition: ```D import std.stdio; enum HasTest = version (Test) ? true : false; Tomek SowiĆski wrote this template: ```d enum bool isVersion(string ver) = !is(typeof({ mixin("version(" ~ ver ~ ") static assert(0);"); })); static assert(isVersion!"assert"); static assert(!isVersion!"Broken"); ``` I have something similar that i found somewhere here ```D struct Version { static bool opDispatch(string identifier)() { mixin(" version(", identifier, ") return true; else return false; "); } } static if (Version.something == false) {} ``` But i don't even use it since it requires me to import a module, it not worth it, i'd rather have version as expression
Re: Inversion of conditional compilation statements
On Saturday, 2 December 2023 at 13:16:26 UTC, Johannes Miesenhardt wrote: Hello, I am trying to learn D and I have stumbled upon an issue Consider this code: ```d import std.stdio; //version = Test; int main() { version (Test) { writeln("Hello, world!"); } return 0; } ``` This compiles, however what if we want to turn the version statement around? I first expected `version (!Test)` to work, but it doesn't since the grammar says: ``` VersionCondition: version ( Identifier ) version ( unittest ) version ( assert ) ``` We are using the first way, the one with the Identifier. The reason inverting works with if-statements is because they take an "Expression". I see the way why it doesn't work, but I think it should. Considering that `version (Test) {} else {` works without any issue but looks very ugly. Can somebody explain if this is an intended decision or what I should do instead of using my ugly replacement? It depends what do you want to achieve, if you just want a bool at the top of your module to toggle features, then you can do this: ```D import std.stdio; enum Test = true; int main() { static if (Test == false) { writeln("this will never be called, it won't be compiled"); } else { writeln("hello!"); } return 0; } ``` ``static if`` is evaluated at compile time, you can mix it with ``version`` if you need to provide the flag during compilation ```D import std.stdio; version (Test) enum HasTest = true; else enum HasTest = false; int main() { static if (HasTest == false) { writeln("this will never be called, it won't be compiled"); } else { writeln("hello!"); } return 0; } ``` I wish we could use ``version`` as expression, to void the repetition: ```D import std.stdio; enum HasTest = version (Test) ? true : false; int main() { static if (HasTest == false) { writeln("this will never be called, it won't be compiled"); } else { writeln("hello!"); } return 0; } ``` If someone able to do it, would be cool to see a PR
Re: How should class objects created in betterC be destroyed
Here is how adam seems to be doing it: https://github.com/adamdruppe/webassembly/blob/731a7033174127c0a6dd4f23eabdb440adab286b/arsd-webassembly/object.d#L650-L681 Specially here: ```D void destroy(bool initialize = true, T)(T obj) if (is(T == class)) { (..) else { // Bypass overloaded opCast auto ptr = (() @trusted => *cast(void**) )(); rt_finalize2(ptr, true, initialize); } } ``` and for interface: ```D cast(Object)obj ``` But i suspect you'll have to implement the whole typeinfo
Re: How should class objects created in betterC be destroyed
Please tag your code accordingly, as is it's unreadable ```D // your code here ``` (tick the "Enable Markdown" too, next to the Send button)
Re: Dlang installer with VSCode broken
Looks like his vscode is outdated, make sure your friend has the latest version installed
Re: win32 api & lib issue
On Thursday, 2 November 2023 at 10:17:37 UTC, Peter Hu wrote: On Thursday, 2 November 2023 at 10:02:29 UTC, Imperatorn wrote: On Thursday, 2 November 2023 at 09:58:21 UTC, Peter Hu wrote: On Thursday, 2 November 2023 at 09:13:11 UTC, Imperatorn wrote: On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn wrote: On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote: Greetings! From time to time I encountered issues on the subjected after I upgraded my dmd package.Given below code : [...] If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ``` Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different. Thank you. Below two pragma solved the isse but am confused as they are already in the system path.This is the first time I have to include lib files here.How come other gui programs don't have to do this. pragma(lib,"user32"); pragma(lib,"comdlg32"); I'm not sure why, it works for me, but I think it could be something dmd does different. The pragma lib is inserted into the generated object file, or otherwise passed to the linker, so the linker automatically links in that library. I'm guessing dmd for some reason does not see it in the submodule, but I have no proof that's the issue, I'm just guessing. Really appreciated for the help.I am learning to understand. Not using these two pragma in the source,other in the commandline:dmd -m64 user32.lib comdlg32.lib test.d compiled.But--- In an IDE say PoseidonD it still failed to compile even if I provided the library path to the compiler,I just can't understand how come my other small programs ( based on gui libslike DFL2,iup4D,dwt,NAppGui4D ) works fine without having to provide pragma in the source before compiling. It's probably because these libraries already have the symbols
Re: Symbolic computations in D
On Sunday, 29 October 2023 at 08:55:24 UTC, Dmitry Ponyatov wrote: Yesterday some student asked me about ability to make some dumb symbolic computation in C++ the same like way as it looks in the MathCAD or Maxima CAS, but run it compiled on a robot platform in realtime. I have no idea about CAS design and internals, or any math at all, but today I found some book: - _Tan Kiat Shi, Willi-Hans Steeb and Yorick Hardy_ **SymbolicC++: An Introduction to Computer Algebra using Object-Oriented Programming and** - **Computer Algebra with SymbolicC++** with the same autors (looka like an alias book from another publisher) Maybe someone played in this topic, and can give some advice: is D language with its OOP without multiple inheritance and maybe other semantic limitations able and good enough to be used with these books mechanics? The theme looks complex off the shelf, and I'm not sure to speak about D to this above student, especially I myself can't help him anyway not knowing the language in deep. This is sad that people recommend OOP for this Julia doesn't have OOP and it took over, and that's what i'd recommend your students to check, C++ is a dead end, Julia it is for mathematical computing If D had tagged union and pattern matching, it would be a great candidate to succeed in that field
Re: Can't get into debugger in vscode on macOS
On Thursday, 19 October 2023 at 06:03:06 UTC, Daniel Zuncke wrote: Hello, I need some help getting into the debugger in vscode on macOS. It did work some months ago but that was finicky to set up. Maybe I am forgetting something now? I am compiling the project with `dub build --build debug --compiler ldc2 --force` (the `-ld_classic` flag to fix the new Xcode linker is set in dub.json). Debugging in the terminal with lldb works as expected `lldb bin/dfmt -- --help`. In vscode I the debug process immediately exits with error (as far as I can tell, don't know how to get more output). All required extensions should be installed since it worked some time ago (mainly CodeLLDB, code-d and C++ from what I remember). I have tried 2 launch configs (launch.json): ```json { "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "debug lldb", "cwd": "${workspaceFolder}", "program": "./bin/dfmt", "args": ["--help"], }, { "type": "code-d", "request": "launch", "name": "debug code-d", "cwd": "${workspaceFolder}", "program": "./bin/dfmt", "args": ["--help"], }, ] } ``` And both fail the same way (vscode Debug Console output): ``` Launching: /Users/dz/dev/dfmt/issue578/bin/dfmt --help Launched process 24999 Process exited with code -1. ``` Any ideas what the problem could be? Can I get more verbose output what the problem is after launching the process? I looked at the doc, and looks like you can put a breakpoint on reaching entry point, maybe that'll help diagnose better the issue by stepping in ``` "stopOnEntry": true, ```
Re: strange link error: _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm _My_struct__xopEqualsMxFKxSQBlQBoQBiZb
On Monday, 16 October 2023 at 19:36:07 UTC, Imperatorn wrote: On Monday, 16 October 2023 at 18:20:27 UTC, mw wrote: Hi, I just encountered a strange link error: I have a `struct` type `My_struct`, the program compiles fine, but at link time, it errors out: undefined reference to _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm undefined reference to _My_struct__xopEqualsMxFKxSQBlQBoQBiZb looks like it treats My_struct type as `class` type? I'm just wondering how to fix this? both compilers report the same link error: DMD64 D Compiler v2.105.0 LDC - the LLVM D compiler (1.35.0): Thanks. Show your code here on in Discord https://discord.gg/wKTvGNpc No, show your code here on the forum, don't need to siphon out people to Discord With the forums the problem + solution will be saved for other people
Re: is the array literal in a loop stack or heap allocated?
On Wednesday, 11 October 2023 at 02:54:53 UTC, mw wrote: Hi, I want to confirm: in the following loop, is the array literal `a` vs. `b` stack or heap allocated? and how many times? void main() { int[2] a; int[] b; int i; While(++i <=100) { a = [i, i+1]; // array literal b = [i, i+1]; } } Thanks. a is a static array, therefore it won't allocate any, it's a memcpy b will be heap allocated, and it'll do an allocate at each iteration ```D void test_b() { int[] a; int i; while (++i <= 100) { a = [i, i + 1]; printf("%p\n", a.ptr); } } ``` You can run this, and it'll print a different address each time If you add `[]` it'll do range based copy (memcpy), but since the array is not initialized, it has a length of 0, so you only need to allocate once (either with GC or with malloc) ```D void test_b() { int[] a; int i; a.length = 2; // initialize the heap allocated array here // or with malloc: // auto ptr = malloc(int.sizeof * 2); // a = cast(int[]) ptr[0 .. int.sizeof * 2]; while (++i <= 100) { a[] = [i, i + 1]; printf("%p\n", a.ptr); } } ``` Otherwise you'd get: ``core.exception.RangeError@onlineapp.d(18): Range violation`` I don't use D with the GC, so my memory about it is probably foggy, but i'm pretty sure what i said is right, please anyone correct me if i'm wrong
Re: how to assign multiple variables at once by unpacking array?
On Saturday, 7 October 2023 at 17:23:40 UTC, ryuukk_ wrote: On Saturday, 7 October 2023 at 07:31:45 UTC, mw wrote: https://stackoverflow.com/questions/47046850/is-there-any-way-to-assign-multiple-variable-at-once-with-dlang How to do this Python code in D: ``` s = "1 2 3" A,B,C = map(int, s.split(" ")) A,B,C (1, 2, 3) ``` Is there a better way (since 2017)? You can't, there was a DIP for tuple/deconstruction prior to that question, sadly nothing came out of it, and now the language is frozen... Priorities are sadly outside of the language these days.. Tuple DIP in question: https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
Re: how to assign multiple variables at once by unpacking array?
On Saturday, 7 October 2023 at 07:31:45 UTC, mw wrote: https://stackoverflow.com/questions/47046850/is-there-any-way-to-assign-multiple-variable-at-once-with-dlang How to do this Python code in D: ``` s = "1 2 3" A,B,C = map(int, s.split(" ")) A,B,C (1, 2, 3) ``` Is there a better way (since 2017)? You can't, there was a DIP for tuple/deconstruction prior to that question, sadly nothing came out of it, and now the language is frozen... Priorities are sadly outside of the language these days..
Re: T[] opIndex() Error: .. signal 11
On Tuesday, 3 October 2023 at 15:12:34 UTC, Joel wrote: The following program crashes, but doesnât if I change (see title) T[] to auto. The program doesnât even use that method/function. Whatâs the story? ```d // Adding program - literal functions import std; struct List(T) { class Node { T data; Node next; this(T data) { this.data=data; } } string title; size_t length; Node head; this(string title, T[] data...) { this.title=title; length=data.length; if (length) { head=new Node(data[0]); auto cur=head; data[1..$].each!((d) { cur.next=new Node(d); cur=cur.next; }); } } bool empty() { return head is null; } auto ref front() { return head.data; } void popFront() { head=head.next; } T[] opIndex() { return this.array; } auto opDollar() { return length; } } void main(string[] args) { args.popFront; List!int ints; if (args.length) { ints=List!int(args[0], args[1..$].to!(int[])); } else{ ints=List!int("Car, and Date numbers", 1979,9,3,4,5); } stdout.write(ints.title, ": "); ints.each!((i, d) { stdout.write(d, i+1 Remove: It didn't segfault for me, but it still didn't print what's in the ``ints``, but if you remove the following code: ``` T[] opIndex() { return this.array; } auto opDollar() { return length; } ``` ..then it'll work Sounds like a bug.. i don't use these D features, maybe someone else have more insights? Either way, what a terrible experience
Re: Type constraint
On Tuesday, 3 October 2023 at 11:43:46 UTC, Joel wrote: Iâve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) ⊠but it isnât working. static if (is(T==int)) works for one integer type. ```d struct List(T) { auto addUp() If (isInteger!T) { (Add numbers) } } } ``` ```D static if (__traits(isIntegral, T)) { } else static assert(0, "type no supported"); ``` https://dlang.org/spec/traits.html#isIntegral
Re: Is it possible to create a kernel for an operating system in D?
On Tuesday, 26 September 2023 at 03:31:36 UTC, I come from chill. wrote: It seems very obvious, but I have not been able to find any information on the subject to confirm this. So I'm wondering if it's possible. ** Maybe I shouldn't have created the account, literally this will be one of the few doubts I'll have about D :u, but it'll be worth it I guess **. Yes you can, D is great for system level needs https://github.com/zyedidia/multiplix
Re: C to D: please help translate this weird macro
On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm trying to translate the Nuklear GUI library to D [here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation). My workflow when trying to port weird C code to D is to have a small C file, put an example code, and then run the preprocessor, and try to get how things are expanded Alternatively, latest version of visual studio allows you to see that in real time, you'll still have to write example code tho https://devblogs.microsoft.com/cppblog/visualize-macro-expansion-for-c/
Re: Setting struct as default parameter of a function using struct literal?
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote: https://docarchives.dlang.io/v2.073.0/spec/struct.html#struct-literal I would like to set function's default struct for a function in a way that it would be visible for the reader to see what options are set. Something like `Options option = {silenceErrors: false}` Here is an example of what I would hope for to work but it surely does not work: ``` import std.stdio; struct Options { bool silenceErrors = false; } void someFunction(Options option = {silenceErrors: false}){ writeln(option); } void main() { someFunction(); } ``` Is it possible to make this part work in a simple way, maybe I'm using a wrong syntax here? ``` void someFunction(Options option = {silenceErrors: false}){ writeln(option); } ``` I would love to be able to use C style designated initialization everywhere too.. Recent version of D added named arguments so you can do something like: ```D void someFunction(Options option = Options(silenceErrors: false)) ``` I don't like the useless repeating "option option option", but that's D for you
Re: malloc error when trying to assign the returned pointer to a struct field
On Friday, 8 September 2023 at 13:34:42 UTC, Richard (Rikki) Andrew Cattermole wrote: In case you didn't know, all you need to get unittests working in -betterC is: ```d foreach (module_; allModules) { foreach (unitTest; __traits(getUnitTests, module_)) { unitTest(); } } ``` You'd need to provide allModules somehow, like dub does. https://github.com/dlang/dub/blob/2ea883833adf085095b07a7dba8250fb3db79a71/source/dub/project.d#L1937 TIL, thanks for sharing, this will be very useful!
Re: I don't understand betterC
On Friday, 1 September 2023 at 13:17:08 UTC, confused wrote: On Friday, 1 September 2023 at 08:19:55 UTC, Richard (Rikki) Andrew Cattermole wrote: ``size_t`` is defined in ``object.d`` which is implicitly imported into all modules. If it cannot be found, one of three things is happening: 1) You have messed with some cli args related to picking druntime/phobos 2) You have defined a module called object. 3) You have a broken compiler install. I have in fact defined a module called ``` object ```. How is that related to this error? I'm interested in betterC as a curiosity, and trying to explore the extent to which D classes and object-oriented programming can be preserved within its bounds (because I really like classes, and I really like D, and I really hate C++, and I'm trying to learn about bare-metal programming). Thank you, by the way, for sharing your knowledge and time. If you are looking for a better C you are not looking for classes You contradict yourself If you heard about betterC, then you heard about this: https://dlang.org/spec/betterc.html Read it again, and specially this part: https://dlang.org/spec/betterc.html#consequences C has no GC, therefore no class, see, your contradiction ;)
Re: toLower
On Tuesday, 15 August 2023 at 16:47:36 UTC, Joel wrote: How come toLower works in the sort quotes, but not in the map? ```d void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .sort!"a.toLower c.toLower) .writeln; } ``` onlineapp.d(60): Error: `toLower` matches conflicting symbols: /dlang/dmd/linux/bin64/../../src/phobos/std/uni/package.d(9819): function `std.uni.toLower` /dlang/dmd/linux/bin64/../../src/phobos/std/ascii.d(637): function `std.ascii.toLower!char.toLower` /dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(479):instantiated from here: `MapResult!(__lambda4, SortedRange!(ByCodeUnitImpl, "a.toLower>b.toLower", SortedRangeOptions.assumeSorted))` onlineapp.d(60):instantiated from here: `map!(SortedRange!(ByCodeUnitImpl, "a.toLower>b.toLower", SortedRangeOptions.assumeSorted))` This error message is unreadable, maybe an issue should be opened about it, so it could be improved, took me a while to understand, or rather "decipher", what it says..
Re: Test post - please ignore
On Sunday, 13 August 2023 at 17:27:00 UTC, Cecil Ward wrote: I have been getting error messages when I try to post to the forum. This is just a test, so please ignore. There was some issues with the forums last week, it seems all resolved now https://forum.dlang.org/thread/uar9k5$1kei$1...@digitalmars.com
Re: std.experimental.allocator
On Sunday, 13 August 2023 at 16:00:51 UTC, Richard (Rikki) Andrew Cattermole wrote: Yeah you're right Ternary should probably be replaced, although amazingly it has never caused problems so far. But I cannot agree about RAII. Its a valid tool for managing lifetimes of memory allocators. Memory allocators must be able to store per instance state and that state must not accidentally die on you. If it does that is a great way to give the user a very bad day. We are certainly aiming for different things, for instance I don't trust my (future) users when it comes to memory safety. So they get very well hand held in all aspects. Including locking of RCAllocator internally and using RC there. But internally to API's if you need to optimize you'd use the composable allocator structs directly, rather than the expensive (in comparison) RCAllocator. Core API should subscribe to the premise: give memory allocation control (and therefore dealocation) back to the user I'm not against you using RAII, however, i'm against making RAII a requirement for everyone who want to use the API That's why i'm suggesting moving the API to ``core.memory``, you can have RAII based allocators in phobos ``std.memory``, it's more for general use But ``core`` means it's the foundation, helps port to esoteric platforms easier, or usecases where RAII might not be the best choice / or not possible at all Also if you want people to use D for games, you want an allocator API that doesn't use RAII, same for exceptions btw
Re: stb library and importC
On Sunday, 13 August 2023 at 15:39:19 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/08/2023 3:23 AM, ryuukk_ wrote: On Sunday, 13 August 2023 at 06:43:10 UTC, Richard (Rikki) Andrew Cattermole wrote: I would argue that this should be done by dmd as it knows where the VS installation is and it'll catch people out who aren't using dub. Oh better, let's try to send a PR to dmd then for today, it shouldn't be hard if you say it already know where VS is Knowing where VS is, is the easy part (although it is logic that has been fine tuned over a 10 year period, so not something you'd want to duplicate). Getting the environment variables that are set up by a cobweb of batch scripts is the hard part. We are not the first to need to do this either! https://stackoverflow.com/questions/2123/get-environment-variables-of-child-process-in-vc Well, it's just one batch file to call, if vs path is known, then it's already all solved, i'll try to come up with a PR
Re: std.experimental.allocator
On Sunday, 13 August 2023 at 15:25:16 UTC, Richard (Rikki) Andrew Cattermole wrote: Mine (-betterC) https://github.com/Project-Sidero/basic_memory/tree/main/source/sidero/base/allocators Similar scope to one in Phobos. On that note I'm still waiting a year+ for Atila to get back to me about talking about where to go for std.experimental.allocators. It's almost good, unfortunately it uses RAII.. wich is a red flag for me The premise of an Allocator API is to give control to the user, this is lost Also, i'd personally remove this import: ``import std.typecons : Ternary;``, no need to tap into std just for this struct https://github.com/dlang/phobos/blob/v2.105.0/std/typecons.d#L10472 Mine does't use RAII, and i personally think this is what a good core API should be
Re: stb library and importC
On Sunday, 13 August 2023 at 06:43:10 UTC, Richard (Rikki) Andrew Cattermole wrote: I would argue that this should be done by dmd as it knows where the VS installation is and it'll catch people out who aren't using dub. Oh better, let's try to send a PR to dmd then for today, it shouldn't be hard if you say it already know where VS is
Re: std.experimental.allocator
On Sunday, 13 August 2023 at 11:44:50 UTC, IchorDev wrote: I feel like I can't possibly be the first to ask, but I couldn't find any prior discussion of this: When is `std.experimental.allocator` going to be moved out of `experimental`? Is there any roadmap for it? Is it just in limbo? We can and should do better than ``std.experimental.allocator`` It's unreadable and too complex, and it uses classes/interface therefore not good as a base I also think this is not a job for phobos, i'd love to see the allocator stuff put in ``core.memory` We only need 3 function pointers (allocate, free, resize), perhaps a struct that hold them ``core.memory`` only need 3 type of allocator: ``GCAllocator`` ``PageAllocator`` ``ArenaAllocator`` In fact that's what i do, my core API is as simple as: ```D struct VTable { alloc_d alloc; resize_d resize; free_d free; } private alias alloc_d = ubyte[] function(const void* self, size_t len, ubyte ptr_align); private alias resize_d = bool function(const void* self, ubyte[] buf, ubyte buf_align, size_t new_len); private alias free_d = void function(const void* self, ubyte[] buf, ubyte buf_align); ``` I pass around a struct that has this vtable ```D heap = c_allocator; arena = ArenaAllocator.create(heap); servers.create(heap); entities.create(heap); // use arena for temp stuff // then clean it all in on go (..) arena.dispose(); ``` No need to use classes or interface, a struct is all needed, effective, efficient and just few lines of code Zig was eye opener to me, it should be as simple as possible, there is no reason to be complex or to use advanced features, the price to pay to use allocators should be 0, therefore it should work with -betterC I am super interested in helping get stuff done, let's work together, ping me on the IRC server More eye opening stuff: https://www.gingerbill.org/series/memory-allocation-strategies/
Re: How to create an .exe without execute the terminal in Windows?
On Saturday, 12 August 2023 at 23:22:20 UTC, thePengĂŒin wrote: On Saturday, 12 August 2023 at 23:18:16 UTC, Adam D Ruppe wrote: On Saturday, 12 August 2023 at 23:13:39 UTC, thePengĂŒin wrote: I would know how to make some this but in Dlang: best way is to use the linker switch. On Win32, you can pass -L/subsystem:windows if you don't want a console to be automatically allocated. Please note when compiling on Win64, you need to explicitly list -Lgdi32.lib -Luser32.lib on the build command. If you want the Windows subsystem too, use -L/subsystem:windows -L/entry:mainCRTStartup. If using ldc instead of dmd, use -L/entry:wmainCRTStartup instead of mainCRTStartup; note the "w". import core.sys.windows.windows; void hideConsoleWindow() { ShowWindow(GetConsoleWindow(),SW_HIDE); } ``` woudl also work. Where could I get more information? I can't find this link "import core.sys.windows.windows" It's part of druntime, it comes with every installation of the compiler On windows it usually is: ``C:\D\dmd2\src\druntime\src\core\sys\windows`` One question to D maintainers: Why is ``core.sys`` modules not displayed on the online documentation? this seems to be a bug somewhere? https://dlang.org/phobos/index.html There is ``core`` for everything else, but not for ``core.sys``
Re: how to make pragma(lib)'s path relative to the package's path?
On Monday, 31 July 2023 at 08:58:43 UTC, Johan wrote: On Monday, 31 July 2023 at 00:32:07 UTC, ryuukk_ wrote: I reworked the PR, here is the new link: https://github.com/dlang/dmd/pull/15479 It basically add support for ``pragma(lib, "local:bin/lib.a");`` Makes things easier, and doesn't change any old behavior Before continuing with the PR, there should be a discussion and agreement about what exact behavior is desired. That is: get input and consensus from packagers. cheers, Johan I would like to get the PR merged asap, i'm already using that feature for my game, it greatly simplified my build script and i'm not willing to change back lol How/Where do i kickstart this discussion?
Re: Anyone help me with a stack dump?
Your problem lies at line 1541 You can use `ddemangle` executable to make mangled names readable, i don't know if it comes with the compiler ``` _platform_memmove pure nothrow ref @trusted wchar[] core.internal.array.appending._d_arrayappendT!(wchar[], char)._d_arrayappendT(scope return ref wchar[], scope wchar[]) void asm_parse.AsmTransformTemplate!(wchar).__unittest_L1541_C1_1() asm_parse.__unittest asm_parse.__unittest asm_parse.__unittest asm_parse.__unittest int core.runtime.runModuleUnitTests().__foreachbody6(object.ModuleInfo*) int rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))).__foreachbody2(ref rt.sections_elf_shared.DSO) int rt.sections_elf_shared.DSO.opApply(scope int delegate(ref rt.sections_elf_shared.DSO)) int rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))) int object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)) runModuleUnitTests void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int function(char[][])*).runAll() _d_run_main2 _d_run_main start ```
Re: how to make pragma(lib)'s path relative to the package's path?
I reworked the PR, here is the new link: https://github.com/dlang/dmd/pull/15479 It basically add support for ``pragma(lib, "local:bin/lib.a");`` Makes things easier, and doesn't change any old behavior
Re: how to make pragma(lib)'s path relative to the package's path?
I offered a workaround to this problem as a PR, if everyone is interested in providing feedback, here is the link: https://github.com/dlang/dmd/pull/15478
Re: Is there any place where i can check current status and plans for -preview flags?
I'm interesting in that as well, i use ``-preview=rvaluerefparam`` in all of my projects, i can't live without it, i would love to know about its state and if it'll be merged as a official feature (hopefully not removed lol), i'm in the process of simpifying all of my builds scripts right now, removing one more flag would be cool
Re: pragma lib doesn't support static libraries?
On Sunday, 30 July 2023 at 15:40:08 UTC, Adam D Ruppe wrote: On Sunday, 30 July 2023 at 05:53:55 UTC, Mike Parker wrote: And I'm unaware of any mechanism for embedding static library names in an object file for a linker to read later. There is a mechanism on Windows, so it tends to work there, but yeah no luck on the other platforms. Apparently it works on linux with LDC https://github.com/ldc-developers/ldc/issues/4459#issuecomment-1657200236
Re: pragma lib doesn't support static libraries?
On Sunday, 30 July 2023 at 05:53:55 UTC, Mike Parker wrote: On Sunday, 30 July 2023 at 05:28:32 UTC, ryuukk_ wrote: I should have explained exactly what i am doing.. Looks like it doesn't work when i compile in 2 step - compile with: ``dmd -c of=bin/game.o`` - link with: ``dmd bin/game.o`` When doing it this way, then it doesn't work However, when compiling/linking in one ``dmd`` invocation (without ``-c``), then it all works So it looks like the pragma is not passed on the linked when it was compiled with ``-c`` Is this a bug? should i report it?, or is that the expected behavior? It's expected behavior. There's no link step in the first command, so the pragma is meaningless there. And I'm unaware of any mechanism for embedding static library names in an object file for a linker to read later. Oh ok, i'll stick to a one command invocation then, it'll further simplify my build script
Re: pragma lib doesn't support static libraries?
I should have explained exactly what i am doing.. Looks like it doesn't work when i compile in 2 step - compile with: ``dmd -c of=bin/game.o`` - link with: ``dmd bin/game.o`` When doing it this way, then it doesn't work However, when compiling/linking in one ``dmd`` invocation (without ``-c``), then it all works So it looks like the pragma is not passed on the linked when it was compiled with ``-c`` Is this a bug? should i report it?, or is that the expected behavior?
pragma lib doesn't support static libraries?
Hello, I'm trying to simplify my build script, i have this library that i statically link OS: linux ``dmd app.d mongoose/bin/linux/mongoose.a`` becomes: ``` package mongoose; pragma(lib, "mongoose/bin/linux/mongoose.a"); ``` However, it no longer compile, and it complains about ``undefined reference to `` the functions from that lib I tried different paths, even the full path to that file, nothing works So my question: does prama lib support static libraries? - if yes, then what i am doing wrong? - if no, then what should i do to make it support static libs? Thanks for reading me!
Re: Make a function available under different names.
There are 2 ways you can solve your problem ```d string returnExecutableName(string[] arguments) { // if you compile with `-debug` it'll run this block debug { write("Debug mode is enabled.\n"); write(" Executable_Name: " ~ arguments[0] ~ "\n"); } return arguments[0]; } ``` ```d string returnExecutableName(string[] arguments) { // if you compile with `-version=VERBOSE` it'll run this block version (VERBOSE) { write("Debug mode is enabled.\n"); write(" Executable_Name: " ~ arguments[0] ~ "\n"); } return arguments[0]; } ``` You don't even need that function at this point ```d import std.stdio; void main(string[] args) { debug { write("Debug mode is enabled.\n"); write(" Executable_Name: " ~ args[0] ~ "\n"); } } ``` There, it's cleaner without indirections
Re: Syntax for Static Import of User Define Attributes
Whenever there might be symbol clash, or when i want to make sure i can identify where something from from i do: ```d import me = my.awesome.module; void main() { me.hi(); } ```
Re: WASM - Passing JS objects to D
Think about the readers when you paste code https://www.markdownguide.org/extended-syntax/#syntax-highlighting
Re: Options for Cross-Platform 3D Game Development
Oh, and i forgot to mention Sokol, great C library, i couldn't find D bindings, so you'll have to create your own (it's trivial) https://github.com/floooh/sokol
Re: Options for Cross-Platform 3D Game Development
On Wednesday, 5 July 2023 at 22:27:46 UTC, Andrew wrote: So, I've gotten the itch to have a go at game development in D, after doing a bit of it in Java last year. I've previously used LWJGL, which is a java wrapper for OpenGL, OpenAL, GLFW, and some other useful libs. The problem is, apparently OpenGL is deprecated for apple devices, so I don't really want to use that unless there are no decent alternatives. So far, the most promising I've seen is [bindbc-bgfx](https://code.dlang.org/packages/bindbc-bgfx), but it's been a pain to set up due to having to build the bgfx codebase, which requires a specific version of glibc that my distro (Linux Mint) doesn't offer yet. Are there any other recommendations for cross-platform rendering libraries? Of course I could use a pre-made game engine like Unity or Godot, but for me, most of the fun is in making the engine. Depends what you really want to do If you need something that provides you an API to render things directly without doing raw GPU commands, then RayLib is excellent, you can still build your engine around it, it act like a framework a la libGDX/XNA/MonoGame - https://github.com/schveiguy/raylib-d If you want to create your own engine from scratch, then Vulkan (works on mobile/linux/windows and macOS via moltenvk) Or you can use WebGPU, despite its name it's crossplatform, targets Web via wasm (with LDC, requires some extra work tho), Windows, Linux, macOS, mobiles - https://github.com/gecko0307/bindbc-wgpu
Re: applay for template function with sumtypes result?
Hopefully we'll get tagged union in the future - no templates - proper support - proper error messages
Re: unittest under betterC
On Monday, 5 June 2023 at 11:41:08 UTC, Richard (Rikki) Andrew Cattermole wrote: On 05/06/2023 3:42 PM, ryuukk_ wrote: I don't know how all this works, but the runtime shouldn't know about tests, imagine if you ship a game, and the player can run all the unittests, that doesn't make sense Currently that is not possible. When you turn on unittests to be compiled in, that runtime will automatically run them and then end the program. The compiler should run the unittest, the compiler should run the unittest, no matter what flag the programmer is using, in that case: -betterC Run what? Until its in a binary on the target platform (which may not be the host), there is nothing to run. Running using CTFE will not allow for testing for things that are platform dependent. Which we do plenty of. You guys should read what you suggest to people sometimes, i repeat, D is not a new language, and D is not the only language, provide greatness to people, not dumb and broken stuff It's not broken. It's working exactly how it needs to work. You can't expect a runtime dependent feature that has no way of working without a runtime, to work without a runtime. In my book this is broken and needs to be fixed, as a user i don't care about under the hood things, it's a you problem, user should be able to unit test
Re: unittest under betterC
On Sunday, 4 June 2023 at 22:14:59 UTC, Richard (Rikki) Andrew Cattermole wrote: On 05/06/2023 9:20 AM, ryuukk_ wrote: Then this needs to be fixed asap, unittest needs to work for the flags user will use There is nothing to fix. You literally do not have any of the druntime code needed to handle ModuleInfo and hence call via it. Nor do you have the entry point handled for you to call the functions... This isn't a language only feature, its also a runtime feature. Just like module constructors are. I don't know how all this works, but the runtime shouldn't know about tests, imagine if you ship a game, and the player can run all the unittests, that doesn't make sense The compiler should run the unittest, the compiler should run the unittest, no matter what flag the programmer is using, in that case: -betterC If not, then it is a design flaw that needs to be fixed You guys should read what you suggest to people sometimes, i repeat, D is not a new language, and D is not the only language, provide greatness to people, not dumb and broken stuff Up your standard of quality
Re: unittest under betterC
On Sunday, 4 June 2023 at 20:43:17 UTC, Richard (Rikki) Andrew Cattermole wrote: Unittests require some mechanism to execute them. Druntime provides this capability by default. You can do it manually by using ``__traits(getUnitTests)`` to get access to the symbols. Personally I just use full D for unittests. Then this needs to be fixed asap, unittest needs to work for the flags user will use D should not advertise broken features to the world with "deal with it" as workaround, this is not a new language, let's up out standard of quality
Re: Concepts like c++20 with specialized overload resolution.
On Saturday, 27 May 2023 at 17:49:27 UTC, vushu wrote: On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer wrote: On 5/27/23 9:50 AM, vushu wrote: On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote: [...] Yes I know there is template constraint, but not with specialized overloading right? so you need to use static if for checking if it hasmagma. What is missing is an "else" thing. So you have to repeat the constraint (as a negation) unfortunately. e.g.: ```d struct LavaMan { void magma() { writeln(" LavaMan is throwing LAVA"); } } struct FakeVulcano { void try_making_lava() { writeln(" Making fake lava"); } }; void make_lava(T)(ref T lava) if (hasMagma!T) { lava.magma(); } void make_lava(T)(ref T lava_thing) if (!hasMagma!T){ lava_thing.try_making_lava(); } ``` -Steve I see thanks for the example :), I think this probably the closest equivalent i dlang. I feel like overload in that case make things harder to read My example has less context switch, and hte logic is correctly understandable at first sight Only one make_lava function
Re: Concepts like c++20 with specialized overload resolution.
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote: you can use: ``static if (__traits(hasMember, T, "magma"))`` ```D import std; struct LavaMan { void magma() { writeln(" LavaMan is throwing LAVA"); } } struct FakeVulcano { void try_making_lava() { writeln( " Making fake lava"); } } // all the magic void make_lava(T)(ref T lava_thing){ static if (__traits(hasMember, T, "magma")) lava_thing.magma(); else lava_thing.try_making_lava(); } int main() { LavaMan v; FakeVulcano l; make_lava(l); make_lava(v); return 0; } ``` ``` Making fake lava LavaMan is throwing LAVA ```
Re: How make a Dlang with Windows GUI x64 without console?
On Friday, 26 May 2023 at 18:05:38 UTC, Marcone wrote: How can I hide console of a window GUI on Windows x64? I need run with -m64 Someone asked the exact same thing yesterday, check their post: https://forum.dlang.org/thread/azlraopxmidtcdmnr...@forum.dlang.org ``` "lflags-windows": [ "/SUBSYSTEM:windows", ], ```
Re: How hide console in dub.sdl under windows 11?
On Thursday, 25 May 2023 at 08:37:40 UTC, John Xu wrote: For dmd, I can use a no_console.def file, which has: EXETYPE NT SUBSYSTEM WINDOWS Then `dmd my.d no_console.def` to hide console. But how do I realize it with dub.sdl ? Adding no_console.def to "sourceFiles", doesn't help. you can do that: ```json "lflags-windows": [ "/SUBSYSTEM:windows", ], ``` dub is too dumb, i think "sourceFiles" only accept .d
Re: Best way to convert between GBK/GB18030 to utf8 ?
On Tuesday, 23 May 2023 at 02:58:21 UTC, John Xu wrote: What is the best way to convert a GBK/GB18030 file contents, i.e. read via: std.stdio.read(gbkFile).to!string , to utf8 encoding ? https://github.com/lytsing/gbk-utf8/blob/master/utf8.c Here, it is C, but porting this to D is easy There is both implementation for windows/linux
Re: Can dmd compile a favicon.ico to exe file ?
On Friday, 12 May 2023 at 01:41:10 UTC, John Xu wrote: I saw c# program's exe, often have an favicon.ico image bound together, which can be dragged to desktop. Can dmd compile an icon image to an exe also? you can, if i remember correctly create a ``ressource.rc`` file and paste: ``` IDI_ICON1 ICON DISCARDABLE "myicon.ico" ``` then put your ``mycon.ico`` file next to it ``` my_project\ app.d ressource.rc myicon.ico ``` ``` dmd app.d ressource.rc ``` it should create an .exe that has the icon
Re: A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.
On Sunday, 30 April 2023 at 17:51:15 UTC, Eric P626 wrote: The title of this thread might be weird, but I am currently reconsidering the language and tools I am using before returning to production again. # Objective and projects Make simple turn based (no animation) video games using Allegro 4, maybe 5, and eventually SDL on multiple platforms: Linux and Windows for now, but could expand, if possible, to other OS or hardware like MacOS, Android, Raspberry Pi, Arduino, etc. I will also be using Sqlite databases in most of my projects. I have a set of projects I am decomposing and refactoring. I am wondering if I should continue in the same direction or if I should change my tools and languages. I am considering D or betterC as an alternative. # Language I am currently using plain C and I love it. I am allergic to C++ and object oriented programming. Having read a bit about the features of the D language makes me doubt continuing using the C language. Especially the betterC option that allows making C compatible libraries and software using some of the D syntax. Unlocking for example the use of foreach statements. The D syntax is interesting, trying to extend the C language the same way would require macros which is not recommended for many reasons. The C language evolves very slowly, so I'll probably be dead by the time they implements foreachs (bools are not even native to the language yet(requires stdbool.h). With D, I have 2 options: 1) create a D software with the D runtime 2) Create a betterC software that create C compatible code. I am making both games and libraries, so making C compatible libraries is almost essential. The objective is to have a simple language, without object oriented stuff, that is relatively productive and allow low level manipulations. This explains the interest in getting foreachs for more control, security, less bugs therefore less debugging and more production. So again betterC could be a good solution even though it's not well documented what features is exactly part of betterC. I wonder if it's worth learning the entire D language since a majority of the features might not make it to betterC. Also I have no interest in OOP, which is relatively present in the D language. # Cross-Compiling and Interoperability This is where the troubles are starting. Now I am trying to figure out what can work together in a cross compiling context. Some of my projects are currently compiling windows binaries from linux OS using Mingw on gitlab. Allegro seems to support both C and D, but if I only use the better C switch, I should be able to use any C library without any issue. Sqlite is also a plain C library, it should be usable with betterC and D. But how is this possible in a cross-compiling context. I am not sure if I can do that with the D language either as pure D or better C. DMD does not seem to offer cross compiling. GDC can compile better C, but not sure mingw can compile D/betterC code. So I am not really sure what can be done in cross-compiling, and if it works for Linux and Windows, it might not work for other platforms like MacOS, Rpie, Arduino if one day, I decide to take this route. So what language do you recommend: * Keep everything in plain C * Use C patched with macros to gain some language features like Foreach * Use BetterC for everything * Use D for the games, and better C or C for the libraries(To keep some compatibilities) * Use D for everything, no C compatibility. If you have other suggestions or questions let me know. I recommend using D with -betterC D is better at being a better C than it is at being a better high level language DMD doesn't support cross compilation but LDC do! The consensus is to use DMD for fast compiles and then use LDC for your optimized release builds (LLVM is unmatched for optimizations, LDC is our savior) So since you are making games, that's the perfect combo, and since game devs don't want any kind of GC or exception handling in their way, -betterC will suit your needs -betterC and DMD is still painful to use for scenarios like this so be warned: https://issues.dlang.org/show_bug.cgi?id=20737, it is sad that it still is not fixed in 2023.. I suggest to maintain C compatibility since you are also making libraries, it would be sad for your users to not be able to consume your libs because it requires bunch of needs they do not use, C works everywhere and is one of the few languages that didn't got infested with OOP, screw redhat/gnome people
Re: Why are globals set to tls by default? and why is fast code ugly by default?
On Friday, 31 March 2023 at 16:02:35 UTC, Dennis wrote: On Friday, 31 March 2023 at 15:52:21 UTC, ryuukk_ wrote: the point i bring is ``__gshared`` is ugly, so we want an ugly language? Good code shouldn't look ugly, but global mutable variables are bad, so it's appropriate that they look ugly. You can still put a single `__gshared:` at the top of your module. I disagree, global mutables are not bad That the same bad advice as telling people to "embrace OOP and multiple inheritance" and all the Java BS "just put your variable into a class and make it static, and then have your singleton to access your static variables"
Re: Why are globals set to tls by default? and why is fast code ugly by default?
On Friday, 31 March 2023 at 10:32:53 UTC, Nick Treleaven wrote: On Sunday, 26 March 2023 at 20:36:37 UTC, ryuukk_ wrote: Golang doesn't even have thread local storage, yet they do very well Go doesn't have a solution to preventing data races at compile time, they just say don't share memory. But what if you accidentally share memory? That is *very* easy to do in Go. You and your users are out of luck. All you can do is run the race detector and pray that you happen to test all the code paths with it that might have data races: The race detector only finds races that happen at runtime, so it can't find races in code paths that are not executed https://go.dev/doc/articles/race_detector If you want TLS in GO, you specify that you need a TLS variable, just like every sane languages Go went the smart route on top of having goroutines, making it superior to what ever D offer
Re: Why are globals set to tls by default? and why is fast code ugly by default?
On Friday, 31 March 2023 at 10:26:32 UTC, Nick Treleaven wrote: On Sunday, 26 March 2023 at 20:39:21 UTC, ryuukk_ wrote: if my code doesn't do threads, why should i put my variable into TLS? I don't think writing __gshared is much of a burden. You can use -vtls to print out all variables that are TLS, and add that to an automated test to check you don't have any accidentally. I have thought before that a --no-threads compiler switch that does not link the key thread functions but makes __gshared the default might be a good enhancement for your use case. Then if you accidentally call some code that uses std.parallelism internally you would get a link error. If i want fast code, why should i make use of ugly syntax? 1. If you want fast code, why aren't you using threads? 2. By default D supports threads and accidental data races are far worse than ugly syntax. It is a burden to type things you don't need, and to type things that are ugly on purpose I recently discovered -vtls and indeed is very nice to have, managed to clear out all my TLS usage, but made my code even more ugly ``__gshared`` everywhere.. If you want fast code, why aren't you using threads? threads is not synonymous of fast code and if i were to use thread, i'd not rely on globals to begin with By default D supports threads and accidental data races are far worse than ugly syntax. Debatable, but that's a good point, but that's not the point i bring, the point i bring is ``__gshared`` is ugly, so we want an ugly language?
Re: How to debug and watch globals in windows debugger?
On Wednesday, 29 March 2023 at 15:26:21 UTC, Steven Schveighoffer wrote: On 3/28/23 6:42 PM, ryuukk_ wrote: Am i the only want who want to improve things, is it a lost cause? I'm not one to use a debugger often, but it is very helpful for many people. I lament that the Windows debugging situation out of the box is dreadful. The students I teach D to I don't show the debugger because I'm worried it would confuse them more than help. I only use windows because i'm making a game and i have to test on that platform I both don't use Windows and mostly do debugging via writeln, so for something that doesn't affect me much, I tend not to put effort in. I'm hoping someone who is motivated enough will do it. I am motivated, hopefully someone more knowledgeable can join me figure that out If I recall correctly, visual studio debugging is better than the other solutions. But I don't know having never got debugging to work. I've heard that mago is supposed to work better, and was written for D, but is Visual Studio dependent: https://github.com/rainers/mago I wonder if there isn't some way to make this work well for other IDEs? I couldn't get it to work on VSCode. That's unfortunate that the solution is bound to a proprietary editor that requires a license Effort should be made in the open and be universal, so it's easy to port/adapt to other tools/platforms Coordinated efforts is the way to go, Go/Rust/Zig people are demonstrating this very well and it helped their growth Should i move on? In any case, the debugging experience isn't perfect, but seems like a drastic measure to leave D altogether if you can't debug globals. -Steve I exaggerate a little bit i must admit it, but I'm trying to raise awareness, when other languages have no problem with debugging out of the box on popular IDEs, why should it have problems only with D? Currently, at least on windows, there are 2 problems with debugging: - global variables - extern(C) variables I'm willing to find the cause for the 1st one, then i'll attempt the 2nd one, so expect more frustrated posts I should emphasis again that the reason why i'm into this mess is due to a bug i'm trying to debug related to loading a shared DLL built using DMD on windows, wich apparently is known to be broken for YEARS.. great, more people should voice their complains, D is not a new language.. So what to expect other than frustration? specially when people keep recommending to use "workarounds", well, if the fix is a workaround, one shouldn't be surprised to see people getting frustrated every so often Also it's more of an accumulation of problems that makes me very annoyed https://issues.dlang.org/show_bug.cgi?id=20737 This for example shouldn't be a thing in 2023, period
Re: How to debug and watch globals in windows debugger?
On linux everything works properly out of the box, i tested with gdb and i can inspect globals More info + linux dump on my comment: https://github.com/microsoft/vscode-cpptools/issues/10751#issuecomment-1487694435 So it's a problem either with msvc, or the way dmd/ldc write information for the linker? Anyways.. linux: working out of the box Windows: poop Not a good outlook, then we wonder why people move away, debugging is essential Am i the only want who want to improve things, is it a lost cause? Should i move on?
Re: How can I restrict a library to be only included under a certain OS?
On Tuesday, 28 March 2023 at 21:10:08 UTC, solidstate1991 wrote: I added this line to my SDLang formatted dub build file: ``` dependency "libx11" version="0.0.1" platform="posix" ``` Yet it's included even on Windows, even if I change it to "linux". Since there's a fatal bug in the library that disallows it to be built, I'll be leaving it out for now, and instead move onto something else, or try to issue a correction. I think the way to go is with configuration ``dub build`` // will default to config "posix" since it's the 1st one ``dub build -c windows`` // will use "windows" config, without the dependency https://dub.pm/package-format-sdl.html#configurations ``` configuration "posix" { dependency "libx11" version="0.0.1" } configuration "windows" { platforms "windows" } ``` My dub knowledge is pretty limited, maybe there is a better way?
Re: How to debug and watch globals in windows debugger?
On Tuesday, 28 March 2023 at 14:02:39 UTC, ryuukk_ wrote: Ready to test folder: https://github.com/microsoft/vscode-cpptools/issues/10751#issuecomment-1486948783 Contains simple source to reproduce the issue + build script Also contains binaries + dump in case you just want to see the data Hopefully we can figure that out I noticed in the pdb, there are no mention of the ``app_d`` module I can only find: ``` 40 | S_PROCREF [size = 28] `app_d.main` module = 1, sum name = 0, offset = 40 ``` and ``` 0 | S_GDATA32 [size = 40] `app_d.notice_me_global` type = 0x0074 (int), addr = 0003:3504 ``` Is that why the debugger can't inspect global variables? Why doesn't the pdb contain anything about ``app_d``?
Re: How to debug and watch globals in windows debugger?
Ready to test folder: https://github.com/microsoft/vscode-cpptools/issues/10751#issuecomment-1486948783 Contains simple source to reproduce the issue + build script Also contains binaries + dump in case you just want to see the data Hopefully we can figure that out
Re: How to debug and watch globals in windows debugger?
C program: ```C int notice_me_global = -1; void main() { notice_me_global = -5; } ``` ``cl app_c.c /DEBUG /Zi /EHsc /std:c11 /link /DEBUG /out:app_c.exe`` ``llvm-pdbutil.exe dump --globals app_c.pdb > dump_c`` ``` 688476 | S_GDATA32 [size = 32] `notice_me_global` type = 0x0074 (int), addr = 0003:0040 ``` D program: ```D __gshared int notice_me_global = -1; extern(C) void main() { notice_me_global = 5; int* a; *a = 1; } ``` ``dmd -betterC -m64 -g -debug app_d.d`` ``llvm-pdbutil.exe dump --globals app_d.pdb > dump_d`` ``` 0 | S_GDATA32 [size = 40] `app_d.notice_me_global` type = 0x0074 (int), addr = 0003:3504 ``` Open question: Why is it: For D: ``0 |`` For C: ``688476 |`` Potential issue: Debugger doesn't understand: the ``.`` in the name ``app_d.notice_me_global``, mangled name also doesn't work That's the info i provided in the microsoft tracker, maybe some people here can notice something else that's wrong dump_c: https://gist.github.com/ryuukk/40c6d7d1cd3d6a010242d505380fe233 dump_d: https://gist.github.com/ryuukk/38f43383025907a8f44049503887206c
Re: How to debug and watch globals in windows debugger?
I opened an issue on microsoft's github, let's see what they have to say: https://github.com/microsoft/vscode-cpptools/issues/10751
Re: How to debug and watch globals in windows debugger?
On Tuesday, 28 March 2023 at 11:07:02 UTC, ryuukk_ wrote: On Tuesday, 28 March 2023 at 04:22:24 UTC, Richard (Rikki) Andrew Cattermole wrote: On 28/03/2023 2:25 PM, ryuukk_ wrote: On Tuesday, 28 March 2023 at 01:06:50 UTC, Richard (Rikki) Andrew Cattermole wrote: Have you tried installing mago? https://github.com/rainers/mago There are instructions for vs-code in README. I did not try mago, but it shouldn't be needed as pdb is universally understood by tools Agreed, I would expect globals (including TLS) to work without a debugger extension. While i will try with mago, it shouldn't satisfy us, workarounds are temporary solutions Its not a workaround, mago (in this case) is an extension to MS's debugger framework which provides D specific features, you'd want it regardless if you work with the debugger with D a lot. Debuggers typically have language specific features to make them easier to work with. Jan should be shipping this I think. It is a workaround, it should work already out of the box with existing tools It works for other languages, why not for D? problem Check here: https://godbolt.org/z/nYGfMTqYY int global; on C++ has !dbg int global; on D doesn't have !dbg This is a bug in D, therefore it should be fixed Nevermind the godbolt link
Re: How to debug and watch globals in windows debugger?
On Tuesday, 28 March 2023 at 04:22:24 UTC, Richard (Rikki) Andrew Cattermole wrote: On 28/03/2023 2:25 PM, ryuukk_ wrote: On Tuesday, 28 March 2023 at 01:06:50 UTC, Richard (Rikki) Andrew Cattermole wrote: Have you tried installing mago? https://github.com/rainers/mago There are instructions for vs-code in README. I did not try mago, but it shouldn't be needed as pdb is universally understood by tools Agreed, I would expect globals (including TLS) to work without a debugger extension. While i will try with mago, it shouldn't satisfy us, workarounds are temporary solutions Its not a workaround, mago (in this case) is an extension to MS's debugger framework which provides D specific features, you'd want it regardless if you work with the debugger with D a lot. Debuggers typically have language specific features to make them easier to work with. Jan should be shipping this I think. It is a workaround, it should work already out of the box with existing tools It works for other languages, why not for D? problem Check here: https://godbolt.org/z/nYGfMTqYY int global; on C++ has !dbg int global; on D doesn't have !dbg This is a bug in D, therefore it should be fixed
Re: How to debug and watch globals in windows debugger?
On Tuesday, 28 March 2023 at 01:21:02 UTC, Richard (Rikki) Andrew Cattermole wrote: On 28/03/2023 2:06 PM, Richard (Rikki) Andrew Cattermole wrote: Have you tried installing mago? https://github.com/rainers/mago There are instructions for vs-code in README. Binaries are available in the installer of VisualD, they can be extracted by 7zip (I've checked everything is in there). what is: "Manual Installation of the Concord extension in VS Code", i can't find it anywhere what are: "MagoNatCC.dll, MagoNatCC.vsdconfig and .vsdbg-config.json"? i can only find: "MagoNatDE.dll" So far no bueno
Re: How to debug and watch globals in windows debugger?
On Tuesday, 28 March 2023 at 01:06:50 UTC, Richard (Rikki) Andrew Cattermole wrote: Have you tried installing mago? https://github.com/rainers/mago There are instructions for vs-code in README. I did not try mago, but it shouldn't be needed as pdb is universally understood by tools It also doesn't work with remedybg for example: https://i.imgur.com/P1Ph3Jh.png While i will try with mago, it shouldn't satisfy us, workarounds are temporary solutions This issue being fixed should be the goal, i opened a ticket for it: https://issues.dlang.org/show_bug.cgi?id=23811
Re: How to debug and watch globals in windows debugger?
I've now waste an entire day trying to figure out what's wrong, perhaps trusted D for my projects was a bad idea, i now look like a fool
Re: Is there a -Dmacro like option for D compilers?
I just remembered you can do something like this! ``` import std.stdio; enum FEATURE_A_AVAILABLE() { version(FEATURE_A) return true; else return false; } void main() { static if (!FEATURE_A_AVAILABLE) { writeln("feature A not available"); } } ``` It's evaluated at compile time, so it's branchless!
Re: Is there a -Dmacro like option for D compilers?
On Monday, 27 March 2023 at 22:22:26 UTC, Jeremy wrote: Is there a way I can define a manifest constant from the compiler command-line, like the -Dmacro option for C compilers? You can do this way: ``` dmd -version=FEATURE_A ``` ```D import std.stdio; void main() { version(FEATURE_A) { writeln("feature A enabled"); } } ``` Unfortunatly there is not #ifndef, so in case you want to make sure FEATURE_A is not there you'll have to do: ```D import std.stdio; void main() { version(FEATURE_A) {} else { writeln("feature A not available"); } } ``` or ```D import std.stdio; version(FEATURE_A) { enum FEATURE_A_AVAILABLE = true; } else { enum FEATURE_A_AVAILABLE = false; } void main() { static if (!FEATURE_A_AVAILABLE) { writeln("feature A not available"); } } ``` For some reason they force us to be overly verbose Or it's possible to do it, but i don't know much more than this about ``-version`` (if you use ldc compiler, it's ``-d-version=``)
Re: How to debug and watch globals in windows debugger?
Fore more clarity, all syntax i have tried: ``` type_to_tiledef kshared.defs.type_to_tiledef _D7kshared4defs15type_to_tiledef kshared:defs:type_to_tiledef kshared::defs::type_to_tiledef kshared->defs->type_to_tiledef ```
Re: How to debug and watch globals in windows debugger?
Two questions for the D team: Does globals have a special syntax? as you can see above i also tried the mangled name inside the PDB (using hex viewer https://github.com/WerWolv/ImHex) Walter, how do you debug your programs written in D?
Re: How to debug and watch globals in windows debugger?
To clarify, i tested both dmd/ldc, they both doesn't work on windows To clarify even more: I am a mere user who wants to debug its program on windows using vscode's debugger wich uses msvc I can debug a c/rust/zig executable without issue and see globals The problem only happens with dmd/ldc Is it broken by design for decade and nothing should and could be done about it? Is the only solution to inspect a global variable is to use visual studio and install visuald plugin? If i tell you what i'm trying to debug i bet you'll laugh (loading dll compiled using dmd), but that's a story for another day, 1 frustration a day is plenty
Re: How to debug and watch globals in windows debugger?
On Monday, 27 March 2023 at 19:31:24 UTC, Richard (Rikki) Andrew Cattermole wrote: The person you need is WebFreak and they are not online right now. On IRC earlier today ``` [6:43:29 pm] nope, I haven't gotten globals to work in debugger before [6:43:33 pm] I don't think they are emitted [6:44:02 pm] on linux I think it might work with CodeLLDB, depending on what compiler you used to compile the executable ``` I asked about mode details (who didn't emit what?) and where to report the issue, so far question left unanswered My list of "gripes and wishes" grows larger and larger everyday
Re: How to debug and watch globals in windows debugger?
If anyone know what is the problem exactly, then please speak up, this problem needs to be reported to the right place fixed so it can be fixed, all languages i tested don't have this issue (c, rust, zig, odin) D is not a toy language, let's take this issue seriously, shall we? or is it?..
Re: How to debug and watch globals in windows debugger?
Anyone got an idea? Executable built with : ``dmd -g -debug`` on windows On Visual Studio with the visuald addon i can debug the executable and inspect the globals On VSCode i can debug the executable and inspect locals, but not globals What does visuald does under the hood to be able to inspect globals? No, i don't want to use the slow and bloated multi gigabytes Visual Studio just to inspect a variable I'm starting to loose hope