Re: Virtual methods on stack objects
On Wednesday, 11 May 2022 at 20:53:21 UTC, Marvin Hannott wrote: On Wednesday, 11 May 2022 at 20:23:07 UTC, Ali Çehreli wrote: [...] Yeah, but you can't return `Cat` . And the documentation for `scoped` says: [...] That's kinda very limiting. Anyway, I cooked up another idea based on your first suggestions. ```D struct S { static private interface I { int f(int i); } static private final class A : I { int f(int i) {return i;} } static private final class B : I { int f(int i) {return i+ 1;} } private I i; private int d; this(int d) { this.d = d; if(d < 10) { i = scoped!A(); }else { i = scoped!B(); } } int f() { return i.f(d);} } ``` I mean, this is a super dumb example, but it kinda works. And I think it could be made a lot less tedious with some mixin magic. add a single `writeln("A.f")` to A.f and `writeln("B.f")` B.f, and a simple test ```d void main() { S s1 = S(9); S s2 = S(12); s1.f(); s2.f(); } ``` outputs: ``` A.f Error: program killed by signal 11 (Aka. segmentation fault !) ```
Re: Problem with GC - linking C++ & D (with gdc)
On Tuesday, 26 April 2022 at 13:36:19 UTC, Claude wrote: On Tuesday, 26 April 2022 at 12:49:21 UTC, Alain De Vos wrote: --- I also encountered problems while I was trying to use CTFE only functions (using betterC so I don't have to link phobos/D-runtime). However, if those functions use the GC for instance (like appending a dynamic-array), it will require me to link D-runtime, whereas I only use them at compile-time. So I'm a bit confused... I'll try and get more information and reduce a code sample. dont't use `new` if you mean using betterC, `new` is based on GC. with betterC, you should using `malloc/free` reference info: https://dlang.org/spec/cpp_interface.html#memory-allocation
Re: How to get an IP address from network interfaces
On Friday, 22 April 2022 at 05:28:52 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:38:04 UTC, Alexander Zhirov wrote: [...] ```d struct ifreq { private union ifr_ifrn_ { char[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ } ifr_ifrn_ ifr_ifrn; [...] it's actually POSIX C API binding for D. you should get similar code in C when searching StackOverflow. the only thing to do this is just to look at /usr/include/dlang for POSIX API already complete binding from the official. if something is missing, you just do-it-yourself in your code.
Re: How to get an IP address from network interfaces
On Thursday, 21 April 2022 at 07:38:04 UTC, Alexander Zhirov wrote: On Thursday, 21 April 2022 at 07:20:30 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network interface, to get its IP address? ```d import core.sys.posix.sys.ioctl; import core.sys.posix.arpa.inet; import core.stdc.string; import core.stdc.stdio; import core.stdc.errno; import core.sys.posix.stdio; import core.sys.posix.unistd; string ip; int get(string if_name) { int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { fprintf(stderr, "Create socket failed!errno=%d", errno); return -1; } ifreq ifr; uint nIP, nNetmask, nBroadIP; strcpy(ifr.ifr_name.ptr, std.string.toStringz(if_name)); try { if (ioctl(s, SIOCGIFHWADDR, ) < 0) { return -2; } } catch (Exception e) { writeln("Error operation on netif " ~ if_name); return -2; } memcpy(macaddr.ptr, cast(char *)ifr.ifr_hwaddr.sa_data.ptr, 6); if (ioctl(s, SIOCGIFADDR, ) < 0) { nIP = 0; } else { nIP = *cast(uint*)(_broadaddr.sa_data[2]); ip = fromStringz(inet_ntoa(*cast(in_addr*))).idup; } } ``` Gives a lot of errors when compiling ```d app.d(19): Error: function `std.stdio.makeGlobal!"core.stdc.stdio.stderr".makeGlobal` at /usr/include/dlang/dmd/std/stdio.d(5198) conflicts with variable `core.stdc.stdio.stderr` at /usr/include/dlang/dmd/core/stdc/stdio.d(927) app.d(19): Error: function `core.stdc.stdio.fprintf(shared(_IO_FILE)* stream, scope const(char*) format, scope const ...)` is not callable using argument types `(void, string, int)` app.d(19):cannot pass argument `makeGlobal(StdFileHandle _iob)()` of type `void` to parameter `shared(_IO_FILE)* stream` app.d(23): Error: undefined identifier `ifreq` app.d(26): Error: undefined identifier `string` in package `std` app.d(39): Error: undefined identifier `macaddr` app.d(48): Error: undefined identifier `fromStringz` ``` ```d struct ifreq { private union ifr_ifrn_ { char[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ } ifr_ifrn_ ifr_ifrn; private union ifr_ifru_ { sockaddr ifru_addr; sockaddr ifru_dstaddr; sockaddr ifru_broadaddr; sockaddr ifru_netmask; sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; ifmap ifru_map; byte[IFNAMSIZ] ifru_slave; /* Just fits the size */ byte[IFNAMSIZ] ifru_newname; byte * ifru_data; } ifr_ifru_ ifr_ifru; // NOTE: alias will not work : alias ifr_ifrn.ifrn_name ifr_name; @property ref ifr_name() { return ifr_ifrn.ifrn_name; } /* interface name */ @property ref ifr_hwaddr() { return ifr_ifru.ifru_hwaddr; } /* MAC address */ @property ref ifr_addr() { return ifr_ifru.ifru_addr; } /* address */ @property ref ifr_dstaddr() { return ifr_ifru.ifru_dstaddr; } /* other end of p-p lnk */ @property ref ifr_broadaddr() { return ifr_ifru.ifru_broadaddr; } /* broadcast address */ @property ref ifr_netmask() { return ifr_ifru.ifru_netmask; } /* interface net mask */ @property ref ifr_flags() { return ifr_ifru.ifru_flags; } /* flags */ @property ref ifr_metric() { return ifr_ifru.ifru_ivalue; } /* metric */ @property ref ifr_mtu() { return ifr_ifru.ifru_mtu; } /* mtu */ @property ref ifr_map() { return ifr_ifru.ifru_map; } /* device map */ @property ref ifr_slave() { return ifr_ifru.ifru_slave; } /* slave device */ @property ref ifr_data() { return ifr_ifru.ifru_data; } /* for use by interface */ @property ref ifr_ifindex() { return ifr_ifru.ifru_ivalue; } /* interface index */ @property ref ifr_bandwidth() { return ifr_ifru.ifru_ivalue; } /* link bandwidth */ @property ref ifr_qlen() { return ifr_ifru.ifru_ivalue; } /* queue length */ @property ref ifr_newname() { return ifr_ifru.ifru_newname; } /* New name */ } ```
Re: How to get an IP address from network interfaces
On Thursday, 21 April 2022 at 07:20:30 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network interface, to get its IP address? ```d import core.sys.posix.sys.ioctl; import core.sys.posix.arpa.inet; import core.stdc.string; import core.stdc.stdio; import core.stdc.errno; import core.sys.posix.stdio; import core.sys.posix.unistd; string ip; int get(string if_name) { int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { fprintf(stderr, "Create socket failed!errno=%d", errno); return -1; } ifreq ifr; uint nIP, nNetmask, nBroadIP; strcpy(ifr.ifr_name.ptr, std.string.toStringz(if_name)); try { if (ioctl(s, SIOCGIFHWADDR, ) < 0) { return -2; } } catch (Exception e) { writeln("Error operation on netif " ~ if_name); return -2; } memcpy(macaddr.ptr, cast(char *)ifr.ifr_hwaddr.sa_data.ptr, 6); if (ioctl(s, SIOCGIFADDR, ) < 0) { nIP = 0; } else { nIP = *cast(uint*)(_broadaddr.sa_data[2]); ip = fromStringz(inet_ntoa(*cast(in_addr*))).idup; } } ``` PS: ```d //handle binding to net/if.h struct ifmap { c_ulong mem_start; c_ulong mem_end; ushort base_addr; ubyte irq; ubyte dma; ubyte port; /* 3 bytes spare */ } struct ifreq { private union ifr_ifrn_ { char[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ } ifr_ifrn_ ifr_ifrn; private union ifr_ifru_ { sockaddr ifru_addr; sockaddr ifru_dstaddr; sockaddr ifru_broadaddr; sockaddr ifru_netmask; sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; ifmap ifru_map; byte[IFNAMSIZ] ifru_slave; /* Just fits the size */ byte[IFNAMSIZ] ifru_newname; byte * ifru_data; } ifr_ifru_ ifr_ifru; // NOTE: alias will not work : alias ifr_ifrn.ifrn_name ifr_name; @property ref ifr_name() { return ifr_ifrn.ifrn_name; } /* interface name */ @property ref ifr_hwaddr() { return ifr_ifru.ifru_hwaddr; } /* MAC address */ @property ref ifr_addr() { return ifr_ifru.ifru_addr; } /* address */ @property ref ifr_dstaddr() { return ifr_ifru.ifru_dstaddr; } /* other end of p-p lnk */ @property ref ifr_broadaddr() { return ifr_ifru.ifru_broadaddr; } /* broadcast address */ @property ref ifr_netmask() { return ifr_ifru.ifru_netmask; } /* interface net mask */ @property ref ifr_flags() { return ifr_ifru.ifru_flags; } /* flags */ @property ref ifr_metric() { return ifr_ifru.ifru_ivalue; } /* metric */ @property ref ifr_mtu() { return ifr_ifru.ifru_mtu; } /* mtu */ @property ref ifr_map() { return ifr_ifru.ifru_map; } /* device map */ @property ref ifr_slave() { return ifr_ifru.ifru_slave; } /* slave device */ @property ref ifr_data() { return ifr_ifru.ifru_data; } /* for use by interface */ @property ref ifr_ifindex() { return ifr_ifru.ifru_ivalue; } /* interface index */ @property ref ifr_bandwidth() { return ifr_ifru.ifru_ivalue; } /* link bandwidth */ @property ref ifr_qlen() { return ifr_ifru.ifru_ivalue; } /* queue length */ @property ref ifr_newname() { return ifr_ifru.ifru_newname; } /* New name */ } ```
Re: How to get an IP address from network interfaces
On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network interface, to get its IP address? ```d import core.sys.posix.sys.ioctl; import core.sys.posix.arpa.inet; import core.stdc.string; import core.stdc.stdio; import core.stdc.errno; import core.sys.posix.stdio; import core.sys.posix.unistd; string ip; int get(string if_name) { int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { fprintf(stderr, "Create socket failed!errno=%d", errno); return -1; } ifreq ifr; uint nIP, nNetmask, nBroadIP; strcpy(ifr.ifr_name.ptr, std.string.toStringz(if_name)); try { if (ioctl(s, SIOCGIFHWADDR, ) < 0) { return -2; } } catch (Exception e) { writeln("Error operation on netif " ~ if_name); return -2; } memcpy(macaddr.ptr, cast(char *)ifr.ifr_hwaddr.sa_data.ptr, 6); if (ioctl(s, SIOCGIFADDR, ) < 0) { nIP = 0; } else { nIP = *cast(uint*)(_broadaddr.sa_data[2]); ip = fromStringz(inet_ntoa(*cast(in_addr*))).idup; } } ```
Re: Again, ask help with Dlang program footprint
On Saturday, 9 April 2022 at 02:56:50 UTC, dangbinghoo wrote: On Saturday, 9 April 2022 at 02:19:52 UTC, dangbinghoo wrote: On Friday, 8 April 2022 at 03:26:29 UTC, dangbinghoo wrote: On Friday, 8 April 2022 at 03:20:29 UTC, dangbinghoo wrote: [...] PS: I need the program link Phobos statically, don't want to use .so except the basic C library. so I added option `-link-defaultlib-shared=false` in dub.json by default, this should not be changed. hi, please help with this, can we reduce the footprint? thanks! OK, I just put on another git repo, which is the simpley helloworld in D, and it generates 849KB for print a single line! https://github.com/dangbinghoo/hello_world_d so, maybe there's something wrong with D compiling? thanks! OK, talked in Discord. answer is clear: 1. D runtime is about 400KB on amd64 stripped. 2. phobos is set of big templates, writeln is expensive. betterC print a helloworld only costs 6.3KB stripped. thanks!
Re: Again, ask help with Dlang program footprint
On Saturday, 9 April 2022 at 02:19:52 UTC, dangbinghoo wrote: On Friday, 8 April 2022 at 03:26:29 UTC, dangbinghoo wrote: On Friday, 8 April 2022 at 03:20:29 UTC, dangbinghoo wrote: [...] PS: I need the program link Phobos statically, don't want to use .so except the basic C library. so I added option `-link-defaultlib-shared=false` in dub.json by default, this should not be changed. hi, please help with this, can we reduce the footprint? thanks! OK, I just put on another git repo, which is the simpley helloworld in D, and it generates 849KB for print a single line! https://github.com/dangbinghoo/hello_world_d so, maybe there's something wrong with D compiling? thanks!
Re: Again, ask help with Dlang program footprint
On Friday, 8 April 2022 at 03:26:29 UTC, dangbinghoo wrote: On Friday, 8 April 2022 at 03:20:29 UTC, dangbinghoo wrote: [...] PS: I need the program link Phobos statically, don't want to use .so except the basic C library. so I added option `-link-defaultlib-shared=false` in dub.json by default, this should not be changed. hi, please help with this, can we reduce the footprint? thanks!
Re: Again, ask help with Dlang program footprint
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: https://github.com/dangbinghoo/dlang_footprint_test.git the example is simply a json ser/deser test depends on ASDF, on my machine it generates a binary about 914K using LDC2. Note: as I'm focused on embedded system development, what I want help with is only for the situation using LDC compiler. thanks! PS: I need the program link Phobos statically, don't want to use .so except the basic C library. so I added option `-link-defaultlib-shared=false` in dub.json by default, this should not be changed.
Again, ask help with Dlang program footprint
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 example is simply a json ser/deser test depends on ASDF, on my machine it generates a binary about 914K using LDC2. Note: as I'm focused on embedded system development, what I want help with is only for the situation using LDC compiler. thanks!
Re: How to use ImportC?
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo@leonardo-pc dimportc]$ ls ... /usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ``` LDC works with DMD fronted the same version v2.098.1 LDC - the LLVM D compiler (1.28.1): based on DMD v2.098.1 and LLVM 13.0.1
Re: curses/ncurses liberary in D
On Wednesday, 3 November 2021 at 00:50:31 UTC, pascal111 wrote: How can I include "ncurses" liberary in D? I'm using Ubuntu and GDC! Search ncurses in Dub registray shows that there's 3 ncurses D bingdings. https://code.dlang.org/search?q=ncurses
Re: D equivalent to Rust or Scala's Optional and Result and best practice ?
On Tuesday, 19 October 2021 at 00:01:47 UTC, James Blachly wrote: On 10/18/21 12:03 PM, dangbinghoo wrote: [...] Not quite the same as tagged algebraic union ("sum type" == Rust enum) are not (yet?) a language feature. That being said, I recently integrated mir's Algebraic and Nullable into a project. Integration was pretty easy, and the code was clear and easy to understand. That being said, the terminology of "Some", "None", "Result" and "Err" in Rust are yet easier to understand. http://mir-core.libmir.org/mir_algebraic.html Finally, in addition to `mir.algebraic`, `sumtype`, `Optional`, and `Result` packages, I would add that Tchaloupka's `expected` package looks great: https://code.dlang.org/packages/expected thanks, all is great, but it's better if we have an article explaining how to combine these for real-world project.
D equivalent to Rust or Scala's Optional and Result and best practice ?
hi, It seems that now we have `Optional` and `Result` packages in Dub, are these enough or fully equal to Rust or Scala's error-handling and pattern-matching? if these are enough for real-code, any best practice advice? thanks!
Re: A way to mixin during runtime?
On Friday, 27 August 2021 at 06:52:10 UTC, Kirill wrote: Is there a way to do mixin or similar during runtime? I'm trying to read a csv file and extract data types. Any ideas on how this should be approached in D are greatly appreciated. remember D is a statically compiled language, `mixin` is for generating code, so, it won't work except you have a runtime code parser. you may need a scripting language embedded in your D app to achieve this. thx.
Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?
On Friday, 30 July 2021 at 10:20:36 UTC, Stefan Koch wrote: On Friday, 30 July 2021 at 09:30:13 UTC, Mike Parker wrote: On Friday, 30 July 2021 at 08:38:24 UTC, dangbinghoo wrote: but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online document https://dlang.org/dmd-linux.html That's what he meant by "hidden" switch. I don't know why it isn't documented, but it probably should be. The reason why it's not documented is because we don't want people to rely on the format of the output. I guess if we put that disclaimer in the docs we could ... ok, that is reasonable. thanks!
Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?
On Friday, 30 July 2021 at 09:30:13 UTC, Mike Parker wrote: On Friday, 30 July 2021 at 08:38:24 UTC, dangbinghoo wrote: but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online document https://dlang.org/dmd-linux.html That's what he meant by "hidden" switch. I don't know why it isn't documented, but it probably should be. sorry, I just not noticed "hidden", thanks for all of you!
Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?
On Friday, 30 July 2021 at 06:46:18 UTC, WebFreak001 wrote: On Friday, 30 July 2021 at 06:00:41 UTC, dangbinghoo wrote: Not sure if this is exactly what you want but there is a hidden switch in dmd called `-vcg-ast` that prints out all the templates instantiated. but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online document https://dlang.org/dmd-linux.html thanks! dbh.
Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?
On Friday, 30 July 2021 at 06:46:18 UTC, WebFreak001 wrote: On Friday, 30 July 2021 at 06:00:41 UTC, dangbinghoo wrote: Not sure if this is exactly what you want but there is a hidden switch in dmd called `-vcg-ast` that prints out all the templates instantiated. On run.dlang.io you can use the "AST" button to view this conveniently online. thanks a lot! this is truelly what I exactly want! it's great!
D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?
hi, is there any D compiler option or other method to view the final template instantiation but not compiled (in asm or binary) code? if there's a way, it might be very usefull for newbies like me to learn and understand the the Meta programming of dlang. thanks! dbh
Re: how to make D program footprint smaller ?
On Saturday, 10 July 2021 at 21:40:54 UTC, Bastiaan Veelo wrote: On Friday, 9 July 2021 at 03:07:04 UTC, dangbinghoo wrote: as questioned in the previous thread, I need to find out something like `--as-needed` options available for D. You are probably looking for the [-i](https://dlang.org/dmd-osx.html#switch-i%5B) compiler option. As far as I know `dub` is not devised to work with that, so making use of it can be finicky. I have managed to get it to work on a `sourceLibrary` that we control, not sure how applicable it is on a third party package. — Bastiaan. thanks! but I still think that THIS IS A REAL BUG with D compiling. now, my solution will be remove `rpc` with `vibe.d` dependency and replace `hibernated` using json file storage.
Re: Can I get the time "Duration" in "nsecs" acurracy?
On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and choose the precision. Does anyone know if we can do that? don't expecting 1ns when you running software on GHz clocking CPU running with `normal-linux`. 1ns means 1Ghz. and common x86 cpu runs at 1-4Ghz, and in this situation, only 10ns will be expected from base-metal software(OS). as `normal-linux` is not real-time at all, 100ns is logical. thanks! dbh.
Re: how to make D program footprint smaller ?
On Friday, 9 July 2021 at 01:51:55 UTC, dangbinghoo wrote: On Thursday, 8 July 2021 at 11:18:26 UTC, russhy wrote: On Thursday, 8 July 2021 at 10:01:33 UTC, dangbinghoo wrote: I have tried to add ``` "dflags": ["--link-defaultlib-shared"], "lflags": ["--as-needed"], ``` to dub.json, and my compiler is ldc2, with 800 loc program used `hibernated` and `asdf` package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!) I tried the link flags above, but it seems that the stripped binary is in some size. any suggestions for optimizing this? thanks! --- dbh try: ``` "dflags-ldc": [ "-linkonce-templates", "--Oz" ], ``` but yeah Are you using lot of templates in your code? buffer as global? my 20k LOC game's exe is only just 1.46mb (on windows), but that's because i don't use std at all thanks for your suggestion. I just tried that flags but it seems not working for me. and I just use the `nm` tool with `x86_64-pc-linux-gnu-gcc-nm --size-sort myprg` to get all symbols in the binary, it showed up that. the executable linked with tons of vibe.d symbols. the situation is that: my program relies on another source library which depends on vibe.d, the problem is that the source library is just a set of various tools, my program is using a little sub of that library, which has nothing imported with vibe.d. BUT: the final program compiled with dub seems simply linked all symbols of the sourcelibrary to the executable. So, it there any flags that opt. this like gcc? just to link only needed symbols? thanks! dbh. I tried to delete the dependency of `vibe.d` and `hibernated` package(just an experiment, I finally need them in other process-executables). it shows up that deleting `vibe.d` decreases the size to 1.8MB (stripped) and deleting `vibe.d` and `hibernated` result-in a size of only 530KB(stripped), this is the size it should be. I don't know this is related to dub or LDC itself, but obviously, THIS IS A REAL PROBLEM about D compiling. as questioned in the previous thread, I need to find out something like `--as-needed` options available for D. thanks!
Re: how to make D program footprint smaller ?
On Thursday, 8 July 2021 at 11:18:26 UTC, russhy wrote: On Thursday, 8 July 2021 at 10:01:33 UTC, dangbinghoo wrote: I have tried to add ``` "dflags": ["--link-defaultlib-shared"], "lflags": ["--as-needed"], ``` to dub.json, and my compiler is ldc2, with 800 loc program used `hibernated` and `asdf` package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!) I tried the link flags above, but it seems that the stripped binary is in some size. any suggestions for optimizing this? thanks! --- dbh try: ``` "dflags-ldc": [ "-linkonce-templates", "--Oz" ], ``` but yeah Are you using lot of templates in your code? buffer as global? my 20k LOC game's exe is only just 1.46mb (on windows), but that's because i don't use std at all thanks for your suggestion. I just tried that flags but it seems not working for me. and I just use the `nm` tool with `x86_64-pc-linux-gnu-gcc-nm --size-sort myprg` to get all symbols in the binary, it showed up that. the executable linked with tons of vibe.d symbols. the situation is that: my program relies on another source library which depends on vibe.d, the problem is that the source library is just a set of various tools, my program is using a little sub of that library, which has nothing imported with vibe.d. BUT: the final program compiled with dub seems simply linked all symbols of the sourcelibrary to the executable. So, it there any flags that opt. this like gcc? just to link only needed symbols? thanks! dbh.
how to make D program footprint smaller ?
I have tried to add ``` "dflags": ["--link-defaultlib-shared"], "lflags": ["--as-needed"], ``` to dub.json, and my compiler is ldc2, with 800 loc program used `hibernated` and `asdf` package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!) I tried the link flags above, but it seems that the stripped binary is in some size. any suggestions for optimizing this? thanks! --- dbh
Re: wanting to try a GUI toolkit: needing some advice on which one to choose
On Sunday, 30 May 2021 at 12:27:34 UTC, Siemargl wrote: On Thursday, 27 May 2021 at 01:17:44 UTC, someone wrote: Yes, I know this is a question lacking a straightforward answer. Requirements: - desktop only: forget about support for mobile tablets whatever You forget semi-official DWT https://forum.dlang.org/group/dwt don't sell it official, even semi-*. it had very bad platform support, dub support and ...
Re: get element index when using each!(x)
On Thursday, 17 September 2020 at 03:16:42 UTC, Paul Backus wrote: On Thursday, 17 September 2020 at 03:14:08 UTC, JG wrote: Perhaps there are other ways, but you can use enumerate. For example --- import std.algorithm; import std.range; import std.stdio; void main() { string s = "hello"; s.enumerate.each!(x=>writeln(x[0],":",x[1])); } Worth knowing that the tuples you get from enumerate actually have named members, so you can write: s.enumerate.each!(x => writeln(x.index, ":", x.value)); Documentation: http://dpldocs.info/experimental-docs/std.range.enumerate.html thanks you! and thanks to JG. - binghoo
get element index when using each!(x)
hi, is there any way to get the index for an element when iteration using each!(x)? I know I can do this using foreach statement, but I prefer using the each template. --- string s = "hello"; foreach(i, c; s) { } -- how can I get to ? Thanks! binghoo dang
Re: Does std.net.curl: download have support for callbacks?
On Thursday, 11 June 2020 at 06:13:59 UTC, adnan338 wrote: On Thursday, 11 June 2020 at 06:05:09 UTC, adnan338 wrote: I would like to set a callback for the `download()` function but I do not seem to find a way to add a callback to the procedure. [...] I have also been told that Gtk is not thread safe. What does this mean and does it effect me on this scenario? Don't worry, almost ALL GUI FRAMEWORK in the world IS NOT THREAD SAFE, the wellknow Qt and Gtk, and even morden Android and the java Swing. binghoo dang
Re: GUI library for DMD 2.090 or DMD 2.091
On Friday, 24 April 2020 at 13:45:22 UTC, Phrozen wrote: I'm too new to DLang and I have a lot to learn. Probably that's why I have a lot of difficulties. Has anyone tried using a GUI library to the latest DMD 2.090 or DMD 2.091? I plan to use this language for a specific Thermal calculator application for Windows, but for two days I've been struggling with dub and elementary examples in GUI libraries. I need something simple - a modal window with 3 buttons and a two text boxes. So far I have tested DWT, TKD, DFL, dlangui without success. Can anyone help me with advice or some more recent tutorial. Thank you! working GUI library for D: Gtkd and tkd. --- dbh.
Re: Best way to learn 2d games with D?
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that uses D for learning? Should I just start with another language and then migrate to D later? Anyone recommend any specific tutorial/book? -Steve there's a youtube channel teaching 2D game dev. using dlang: https://www.youtube.com/channel/UCK3fxU3_7tzBhZZ_6rljAQA/videos
Re: Using LDC2 on ARM
On Monday, 2 March 2020 at 17:45:26 UTC, Severin Teona wrote: Hello, I am working on a project that uses a Raspberry Pi (armv7l) and the latest LDC version I found for this architecture is 1.13.0. Can you help me install the latest version(1.20.0)? Also, I'm having problems using the DPP package with the 1.13.0 LDC version, most likely because the latest version of DPP(0.4.1) is using a newer version of Phobos. Is there any reason why the LDC team stopped releasing pre-built binaries for arm? I'm looking forward to your help. Teona. please refer to https://wiki.dlang.org/Programming_in_D_tutorial_on_Embedded_Linux_ARM_devices you can build your own LDC toolchain always using the latest.
Re: Is there any writeln like functions without GC?
On Sunday, 3 November 2019 at 05:46:53 UTC, 9il wrote: On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote: Hi: why writeln need GC? See also Mir's @nogc formatting module https://github.com/libmir/mir-runtime/blob/master/source/mir/format.d hi, is mir right now fully implemented using betterC? thanks! -- binghoo
Re: is the runtime implemented in betterC?
On Saturday, 9 November 2019 at 22:46:16 UTC, kinke wrote: druntime depends on OS, architecture and coupled C runtime - what OS are you going to target? thank you all first! I just made a basic mistake and didn't realized that druntime is just libraries and onlymatter when linking the final executebals. and for xtensa cpu, most used chip is the esp32 mcu, it only has support of freeRTOS, and implemented just few posix api for stdio and threads. so, basically i can only use betterC set of normal D. thanks!
Re: is the runtime implemented in betterC?
On Friday, 8 November 2019 at 13:52:18 UTC, kinke wrote: On Friday, 8 November 2019 at 10:40:15 UTC, dangbinghoo wrote: hi, I'm not sure what you are trying to achieve; you can easily cross-compile druntime & Phobos with LDC, see https://wiki.dlang.org/Building_LDC_runtime_libraries. hmm, if runtime is implemented in regular D, how could the regular D code depends on regular D runtime be compiled when we doesn't have a D runtime even exists? thinking thant we just have xtensa-llvm, and building ldc for xtensa CPU, the runtime will simply just not compiled. it's an egg-chicken problem? -- thanks!
is the runtime implemented in betterC?
hi, is the runtime d code implemented purely with betterC? i was thinking that what's happening when we building ARM dlang compiler, when the dlang compiler ready in the first, there's no ARM version of the runtime lib and phobos, so, it's likely we are using bare metal D and trying to build the runtime. is this true? thanks! --- binghoo
can we use D to programming ESP32?
hi there, Does anyone know what's D's status for ESP32? I just getting started a few days programming with ESP32, and found the official esp-idf SDK even get CPP enabled by default, and this makes the HelloWorld app used 160KB of flash. What I want to talk is that ESP32 might be a powerful Embedded Controller for running D. And It seems that gcc already support Xtensa arch, maybe gdc works with ESP32. thanks! -- binghoo dang
Re: make C is scriptable like D
On Thursday, 20 June 2019 at 16:55:01 UTC, Jonathan Marler wrote: On Thursday, 20 June 2019 at 06:20:17 UTC, dangbinghoo wrote: [...] rdmd adds a few different features as well, but the bigger thing it does is cache the results in a global temporary directory. So If you run rdmd on the same file with the same options twice, the second time it won't compile anything, it will detect that it was already compiled and just run it. great! thanks.
Re: is there any micro-service library in D?
On Wednesday, 19 June 2019 at 11:19:17 UTC, Marco de Wild wrote: On Wednesday, 19 June 2019 at 08:29:15 UTC, dangbinghoo wrote: hi there, Does anyone know the micro-service oriented design library or framework in D? thanks! binghoo dang What do you need from such a library? Some suggestions: For networking, there is vibe.d[0] which provides both a client and a server REST (or web) interface. There is also GraphQL-D[1] that provides a server-side GraphQL interface that can be used by other services. For modelling, there is Depend[2], which visualises dependencies. [0] http://code.dlang.org/packages/vibe-d [1] http://code.dlang.org/packages/graphqld [2] http://code.dlang.org/packages/depend thanks! I want to write a LoRaWAN NS server, and want all module is sit in like a independent service[1]. Or, more generally and big thing like java's OSGI. thanks! [1] : http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-components-manual.html#idp3264320
make C is scriptable like D
hi there, a funny thing: $ cat rgcc #!/bin/sh cf=$@ mycf=__`echo $cf|xargs basename` cat $cf | sed '1d' > ${mycf} gcc ${mycf} -o a.out rm ${mycf} ./a.out $ cat test.c #!/home/user/rgcc #include int main() { printf("hello\n"); } And then, chmod +x test.c ./test.c output hello. is rdmd implemented similarly? thanks! binghoo
is there any micro-service library in D?
hi there, Does anyone know the micro-service oriented design library or framework in D? thanks! binghoo dang
Re: D compiler need -nogc witch and document of library also need nogc button
On Tuesday, 11 June 2019 at 10:24:05 UTC, KnightMare wrote: On Tuesday, 11 June 2019 at 08:05:31 UTC, dangbinghoo wrote: I think that D compiler needs -nogc switch to fully disable gc for a project, LDC -nogc? thanks for help. It's a shame that I didn't look in details of the LCD help info. Yeah, the great LDC already support this! Thanks! --- binghoo dang
Re: D compiler need -nogc witch and document of library also need nogc button
On Tuesday, 11 June 2019 at 12:40:39 UTC, Adam D. Ruppe wrote: On Tuesday, 11 June 2019 at 08:59:01 UTC, dangbinghoo wrote: We need to make sure we use only @nogc API when writing code, not when running the app. That's what the @nogc annotation does, statically forces you to only use other @nogc stuff via compiler errors. yeah, @nogc does the job. But the problem is that, you need to mark all functions, classes, everything you write to manually marked, so if compiler supports -nogc, it will helps great. - binghoo dang
Re: D compiler need -nogc witch and document of library also need nogc button
On Tuesday, 11 June 2019 at 08:16:31 UTC, Basile B. wrote: On Tuesday, 11 June 2019 at 08:08:14 UTC, Basile B. wrote: you can do this with a druntime switch or by calling GC.disable in your main() the druntime switch is "--DRT-gc=gc:manual". You pass it the compiled program after its own args. thanks, I know this from dlang.org. But this is not useful when trying to write @nogc code for a project. We need to make sure we use only @nogc API when writing code, not when running the app. Thanks! binghoo dang
D compiler need -nogc witch and document of library also need nogc button
hi there, I think that D compiler needs -nogc switch to fully disable gc for a project, and document of phobos also needs a friendly way to list-out all @nogc API. we already have -betterC, and betterC disabled GC, why we could not have a standalone option for doing this? binghoo dang
Re: Create object from a library's Class returns Null
change gwlib buildtype to sourceLibrary solves the problem, but it should work for static or shared library.
Re: Create object from a library's Class returns Null
On Wednesday, 29 May 2019 at 05:04:54 UTC, dangbinghoo wrote: On Wednesday, 29 May 2019 at 02:42:23 UTC, Adam D. Ruppe wrote: Object.factory is pretty unreliable and has few supporters among the developers. I wouldn't suggest relying on it and instead building your own factory functions. oh, that's bad news, but the hibernated library is using this feature. what should I do with this? now we found that, class from a module library won't work, if I move gwlib to testobj/source, it works.
Re: Create object from a library's Class returns Null
On Wednesday, 29 May 2019 at 02:42:23 UTC, Adam D. Ruppe wrote: Object.factory is pretty unreliable and has few supporters among the developers. I wouldn't suggest relying on it and instead building your own factory functions. oh, that's bad news, but the hibernated library is using this feature. what should I do with this?
Re: Create object from a library's Class returns Null
On Tuesday, 28 May 2019 at 14:24:30 UTC, dangbinghoo wrote: On Tuesday, 28 May 2019 at 14:16:44 UTC, Nick Treleaven wrote: On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: yeah, I made a typo mistake in the forum post, but the code in github repo is really with no typo problem. This seems to be a serious problem, I found it works when I using Ldc2 1.12 version even on ARM target. hi there, Anyone help with this? Not a typo problem, even this --- writeln(Object.factory(ns.toString())); --- result in `null`. just try the github demo project: https://github.com/dangbinghoo/DObjectCreatTest.git Thanks! --- binghoo dang
Re: Create object from a library's Class returns Null
On Tuesday, 28 May 2019 at 14:16:44 UTC, Nick Treleaven wrote: On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: class NSconf { String name; ... } Does this class have a non-default constructor? yes, I didn't provide constructor, as Class will have a default one if not supplied. Typo, should be NSconf. yeah, I made a typo mistake in the forum post, but the code in github repo is really with no typo problem. This seems to be a serious problem, I found it works when I using Ldc2 1.12 version even on ARM target.
Create object from a library's Class returns Null
hi there, I have a set of DB entity class in a library and creating Object from another project which linked with the library returns Null. I don't know what's wrong there. the source is like this: a. I have a library with such a structure: gwlib/source/gwlib/entity/nsconf.d with content: -- module gwlib.entity.nsconf; class NSconf { String name; ... } -- b. I use this gwlib library in another project named testobj testobj/source/app.d : -- import gwlib.entity.nsconf; void main() { writeln(Object.factory("gwlib.entity.nsconf.NSConf")); } -- this print out `null`. dub file cofig is : - "dependencies": { "gwlib": {"path":"../gwlib"} }, - And I just tested with DMD and LDC2, the result is a little different, but all the two is returning a null object. I don't know what's the reason. Could someone help with this? Thanks! > I posted the dub version of the whole project on github: https://github.com/dangbinghoo/DObjectCreatTest one can just clone and reproduce the result. --- binghoo dang
Re: compiler does not detect accessing on null class object.
On Monday, 27 May 2019 at 15:29:32 UTC, Daniel Kozak wrote: On Monday, 27 May 2019 at 15:13:00 UTC, dangbinghoo wrote: hello, 1.) Yes this is by design. It is not easy to detect this at compile time. It does not break safety 2.) https://dlang.org/spec/function.html#function-safety https://dlang.org/spec/memory-safe-d.html https://dlang.org/articles/safed.html#safed-subset thanks a lot. so, The SafeD Subset consists of [function-safety, memory-safety].
compiler does not detect accessing on null class object.
hello, code below: - class a { string a1; } a a1; writeln(a1.a1); - compiles and produce "core dump" or "segfault", does this fit the original D design? why the compiler does not detect for accessing a null object and refused to compile? And, 2nd question: where can I find the Subset spec of SafeD? Thanks! -- binghoo dang
Re: Logging best practices
On Friday, 26 April 2019 at 08:10:33 UTC, Bastiaan Veelo wrote: std.experimental has been already moved to std. Are you sure about that? https://github.com/dlang/phobos/tree/master/std I think you are confusing the package std.experimental.all that moved to std. It means you can now import all of Phobos by doing `import std;` instead of `import std.experimental.all;`. It does not mean that everything below std.experimental moved to std and thereby lost its experimental status. Bastiaan. yes, you're right, I just made a misunderstanding. Thanks!
Re: Logging best practices
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote: Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives? for the latest alpha version of D release, all std.experimental has been already moved to std. so, just don't be afraid! ~_^ - binghoo dang
Re: How to do alias to a C struct member?
On Monday, 22 April 2019 at 15:50:11 UTC, dangbinghoo wrote: On Monday, 22 April 2019 at 13:10:45 UTC, Adam D. Ruppe wrote: On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote: alias ifr_ifrn.ifrn_nameifr_name; /* interface name */ So, how to do alias for a C struct member? D doesn't support this kind of alias. There's two options: Then you should be able to use it the same way as in C. OK, I'd prefer with option 2. thank you in advance! hi all, the correct answer is : --- struct ifreq { private union ifr_ifrn_ { byte[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ } ifr_ifrn_ ifr_ifrn; private union ifr_ifru_ { sockaddr ifru_addr; sockaddr ifru_dstaddr; sockaddr ifru_broadaddr; sockaddr ifru_netmask; sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; ifmap ifru_map; byte[IFNAMSIZ] ifru_slave; /* Just fits the size */ byte[IFNAMSIZ] ifru_newname; byte * ifru_data; } ifr_ifru_ ifr_ifru; // NOTE: alias will not work : alias ifr_ifrn.ifrn_name ifr_name; @property ref ifr_name() { return ifr_ifrn.ifrn_name; } /* interface name */ --- the `need this` error is telling that `ifr_ifrn` is not an instance but a type for my previous code. so for C struct's union member, we need to first declare a member of that union type, and then using property to implement The C-Macro. but here I have a question in further: As showing above, ifreq has a member of ``byte[IFNAMSIZ] ifrn_name;``, when translating the C style calling code, I need to do such a cast for D byte: ``` strcpy(cast(char *)ifr.ifr_name.ptr, std.string.toStringz(if_name)); if (ioctl(s, SIOCGIFHWADDR, ) < 0) { return; } ``` should I keep the `ifrn_name` to a `char[]` for avoid of doing cast D byte to C (char*) ? and I can calling like this: ``` struct ifreq { private union ifr_ifrn_ { char[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ } ... strcpy(ifr.ifr_name.ptr, std.string.toStringz(if_name)); if (ioctl(s, SIOCGIFHWADDR, ) < 0) { return; } ``` this looks more clean and like the C style code. -- Thanks! Binghoo Dang
Re: How to do alias to a C struct member?
On Monday, 22 April 2019 at 15:45:52 UTC, Arun Chandrasekaran wrote: On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote: hi all, as now we don't have the net/if.h binding, I need to do struct ifreq binding myself, here's my code: [...] Looks like we both were working on the same thing, few hours apart. https://forum.dlang.org/post/nkbnknlgmcwaivppm...@forum.dlang.org yeah, I was doing that 4 hours ago! ^_^
Re: How to do alias to a C struct member?
On Monday, 22 April 2019 at 13:10:45 UTC, Adam D. Ruppe wrote: On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote: alias ifr_ifrn.ifrn_nameifr_name; /* interface name */ So, how to do alias for a C struct member? D doesn't support this kind of alias. There's two options: 1) just write the full name in the code. ifreq ifr; ifr.ifr_ifrn.ifrn_name /* instead of ifr.ifrn_name */ or, if you are linking in the D module containing the translated headers (if you don't link it in, this will cause missing symbol linker errors!) 2) write ref property functions to get to it, using ufcs for the middle. So replace that *alias* line with: @property ref ifr_name(ifreq this_) { return this_.ifr_ifrn.ifrn_name; } Then you should be able to use it the same way as in C. OK, I'd prefer with option 2. thank you in advance!
How to do alias to a C struct member?
hi all, as now we don't have the net/if.h binding, I need to do struct ifreq binding myself, here's my code: struct ifreq { private union ifr_ifrn { byte[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ } private union ifr_ifru { sockaddr ifru_addr; sockaddr ifru_dstaddr; sockaddr ifru_broadaddr; sockaddr ifru_netmask; sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; ifmap ifru_map; byte[IFNAMSIZ] ifru_slave; /* Just fits the size */ byte[IFNAMSIZ] ifru_newname; byte * ifru_data; } alias ifr_ifrn.ifrn_nameifr_name; /* interface name */ alias ifr_ifru.ifru_hwaddr ifr_hwaddr; /* MAC address */ alias ifr_ifru.ifru_addrifr_addr; /* address*/ alias ifr_ifru.ifru_dstaddr ifr_dstaddr; /* other end of p-p lnk */ alias ifr_ifru.ifru_broadaddr ifr_broadaddr;/* broadcast address */ alias ifr_ifru.ifru_netmask ifr_netmask; /* interface net mask */ alias ifr_ifru.ifru_flags ifr_flags;/* flags */ alias ifr_ifru.ifru_ivalue ifr_metric; /* metric */ alias ifr_ifru.ifru_mtu ifr_mtu; /* mtu*/ alias ifr_ifru.ifru_map ifr_map; /* device map */ alias ifr_ifru.ifru_slave ifr_slave;/* slave device */ alias ifr_ifru.ifru_data ifr_data; /* for use by interface */ alias ifr_ifru.ifru_ivalue ifr_ifindex; /* interface index */ alias ifr_ifru.ifru_ivalue ifr_bandwidth;/* link bandwidth */ alias ifr_ifru.ifru_ivalue ifr_qlen; /* queue length */ alias ifr_ifru.ifru_newname ifr_newname; /* New name */ } --- as show above we need to trun the C code # define ifr_name ifr_ifrn.ifrn_name /* interface name */ to D's alias, but when done the binding and trying to compiling this code: --- import core.sys.posix.sys.socket; import core.sys.posix.sys.ioctl; import core.sys.posix.arpa.inet; import core.stdc.string; import core.stdc.stdio; import core.sys.posix.stdio; import core.stdc.errno; import std.string; .. ifreq ifr; strcpy(ifr.ifr_name, std.string.toStringz(if_name)); //line 172 if (ioctl(s, SIOCGIFHWADDR, ) < 0) { return; } --- DMD compiler gives an error : ``` /test.d(172): Error: need this for ifrn_name of type byte[16] ./test.d(172): Error: function core.stdc.string.strcpy(return scope char* s1, scope const(char*) s2) is not callable using argument types (_error_, immutable(char)*) ./test.d(172):cannot pass argument __error of type _error_ to parameter return scope char* s1 ``` So, how to do alias for a C struct member? thanks! Binghoo Dang
Re: could someone test support for Asian languages in nanogui port?
On Sunday, 6 May 2018 at 11:18:17 UTC, drug wrote: On 06.05.2018 06:10, Binghoo Dang wrote: hi, I'm a Chinese, and I just have done the test. I also copied some Japanese text from Dlang twitter channel and added some Chinese wide punctuation Char. And It's all seems displayed correctly. The resulting screenshot is here: https://pasteboard.co/HjRmOYg.png The only problem is that the font style simply looks strange. You can see the 'normal' text display in Win10 by default like this: https://pasteboard.co/HjRrigh.png Can it fixed by other font or there are some other problems? yeah, the bad font display can be resolved after setting a CJK font(I just replaced with msyh.ttf). the result is like this: https://pasteboard.co/HQBdP14.png thanks!
Re: D vs perl6
On Thursday, 22 November 2018 at 09:03:19 UTC, Gary Willoughby wrote: On Monday, 19 November 2018 at 06:46:55 UTC, dangbinghoo wrote: So, can you experts give a more comprehensive compare with perl6 and D? Sure! 1). You can actually read and understand D code. ^_^, yeah, you're right. D code is much simpler, but it's said that perl6 is a new design with great modeling power. But what I think about is that: both D and perl6 have a very long compiler development time, and both have few users. after reading the perl6 official document, I finally found that D has most of what the perl6 says it's modern powerful features, and then D compiles native code, we can write simple and clean code, and runs fast.
D vs perl6
hi, What if D compared with the latest perl6? well, I know that perl6 is a VM targeted language. so which has the greater modeling-power? And perl6 seems is selling for Concurrency[1], but I think D will do this far better than a VM targeted language, right? with the pre-released version of perl6 publicity, perl6 will be a powerful language with features like "lazy and eager list evaluation", but after learned D, look back to perl6, I found very few things that means "powerful". So, can you experts give a more comprehensive compare with perl6 and D? speed? modeling-power? concurrency? package-management dub vs CPAN? ... Thanks! [1]: https://www.evanmiller.org/why-im-learning-perl-6.html
Re: Building GUI projects with D
On Saturday, 20 October 2018 at 15:40:07 UTC, karis njiru wrote: Hi. Am a computer science student from Kenya and decided to use D for my class project on Principles of Programming Languages. Am having a lot of fun with D but have come across an issue. I have been using Visual D for the past 2 months for my coding but after a lot of research i found out that i cannot build GUI projects with visual D. So i took on Entice Designer which for the past week has been a nightmare for me to compile my code error being the system cannot find the path in the command prompt specified. I have installed DMD and DFL lots of times but there is still the same issue. Please help try GtkD or dlangui(UTF8 support is not complete, font rendering is a little bad.) or tkd
Re: assigment to null class object member compiled? is this a bug?
On Friday, 19 October 2018 at 09:08:32 UTC, Vijay Nayar wrote: Technically the code you have is syntactically correct. You are permitted to create a class variable without assigning it to a class object. (Assigning it to a class object would look like "A a = new A();") Which section of The D Programming Language book makes you think this would not compile? I have the book as well, but I'm not quite sure what part of the book you're referring to. the section 6.2, which is --- A a; a.x = 5; --- the book explained this should be refused to compile. thanks! -- dangbinghoo
assigment to null class object member compiled? is this a bug?
hi, why the code bellow compiles? --- import std.stdio; class A { int m; } void main() { A a; a.m = 1; } --- and running this code get: `segmentation fault (core dumped) ./test` I consider this couldn't be compiled according to book Programming Language>. The latest dmd (2.082) and LDC2 behaves the same.
Re: Documents about ddoc? and markdown in ddoc?
On Thursday, 18 October 2018 at 05:59:36 UTC, rikki cattermole wrote: On 18/10/2018 6:38 PM, dangbinghoo wrote: hi, Is there any other documents related about ddoc usage? the only thing I can find is: https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples But I found it never mentioned something like $(LI a list item), is there a full ddoc document available? Default for html output: https://github.com/dlang/dmd/blob/master/res/default_ddoc_theme.ddoc And, is there any info about using markdown in ddoc? Not possible. thanks for your reply. and sorry, I'm too careless for reading the documents https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples the $(LI x y) is a macro which was mentioned.
Documents about ddoc? and markdown in ddoc?
hi, Is there any other documents related about ddoc usage? the only thing I can find is: https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples But I found it never mentioned something like $(LI a list item), is there a full ddoc document available? And, is there any info about using markdown in ddoc? thanks! --- dangbinghoo
Re: is there something like `stm32-rs` in D?
On Wednesday, 26 September 2018 at 05:24:08 UTC, Radu wrote: On Wednesday, 26 September 2018 at 03:46:21 UTC, dangbinghoo wrote: hi, https://github.com/adamgreig/stm32-rs looks great, is there something like this in Dlang? thanks! --- dangbinghoo You might take a look at https://github.com/JinShil/stm32f42_discovery_demo and https://github.com/JinShil/stm32_datasheet_to_d thanks, Radu, I knew that there's a minimal D demo on STM32 exist for years. But, what I'm talking about is that rust community is doing a rust library for very production use. If you look at stm32-rs, you will found that stm32-rs is covering the whole STM32 MCU product line and making a promising peripherals library. The library was generated using CMSIS-SVD files which were maintained by MCU vendors. Anyway, I don't know what's the runtime size situation D vs rust. for those kinds of MCU devices, a runtime code size greater than 5KB may even not suitable for L0 lines MCU from ST. It's not quite clear that whether D or rust is valuable for MCU development, but C is really lacking lots of things for quick development, today MCU is interfacing more IoT modules using AT command, and deal with these string things is quite painful in C. Maybe this is an opportunity for D? Thanks! --- dangbinghoo
is there something like `stm32-rs` in D?
hi, https://github.com/adamgreig/stm32-rs looks great, is there something like this in Dlang? thanks! --- dangbinghoo
Re: SerialPort
On Thursday, 20 September 2018 at 10:51:52 UTC, braboar wrote: I am going to play with serial port read/write, so I fetched serial-port. After that, I wrote simple program: auto port_name = "/dev/ttyUSB1"; auto reader = new SerialPort(port_name); reader.dataBits(DataBits.data8); reader.stopBits(StopBits.one); reader.parity(Parity.none); reader.speed(BaudRate.BR_230400); string[] income; reader.read(income); and the result is serial.device.TimeoutException Can anybody give me a guide of using serial port? And one more question: how to outline code blocks? ''' or --- can't help me. here is my code really works: com is `reader` object in your code. ``` void writeBytes(ubyte[] arr) { com.write(arr); } void serialThread() { ubyte[500] buff; running = true; while (running) { string str; size_t readed; try { readed = com.read(buff); // if (readed > 0) { //writeln("com port readed " ~ std.conv.to!string(readed)); str = cast(string)(buff[0 .. readed]).idup; // Don't use writeln for console or string serail application. write(str); // } } // must catch for continous reading, otherwize, com port will block. catch (TimeoutException e) { } } } ``` thanks!
Re: DMD32 compiling gtkd out of memory on 32bit Windows 7 machine
On Friday, 14 September 2018 at 17:34:59 UTC, Mike Wey wrote: You will also have to pass `--build=plain` to dub because of a optlink bug. https://issues.dlang.org/show_bug.cgi?id=15418 thanks Mike, I tried using `--build-plain`, optlink didn't report out of memory, but it hangs ! ``` Compiling source\utils.d... Linking... OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 9: Unknown Option : LLIB OPTLINK : Warning 9: Unknown Option : WIN32 C:\Users\Administrator.USER-20180912OL\AppData\Local\dub\packages\gtk-d-3.8.3\gtk-d\.dub\build\library-plain-windows-x86-dmd_2082-BF70B0A83AEE3E77C0F6B230586D03B2\gtkd-3.lib Warning 178: .LIB pagesize exceeds 512 ``` my building command is ` dub build --compiler=dmd -a=x86 -c=windows --build-mode=singleFile --build=plain --force` Thanks !
Re: DMD32 compiling gtkd out of memory on 32bit Windows 7 machine
On Wednesday, 12 September 2018 at 15:13:36 UTC, Timoses wrote: try `dub --build-mode=singleFile` ? I believe this will compile each file and then link them together (instead of compiling it all together what dub does, afaik). There's been another topic on memory consumption of compilation [1]. [1]: https://forum.dlang.org/post/ehyfilopozdndjdah...@forum.dlang.org thanks timoses , singleFile mode works for building, but when linking, I got this: -- OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 9: Unknown Option : LLIB OPTLINK : Warning 9: Unknown Option : WIN32 C:\Users\Administrator.USER-20180912OL\AppData\Local\dub\packages\gtk-d-3.8.3\gtk-d\.dub\build\library-debug-windows-x86-dmd_2082-9C5C1D99F672708E9D6D6FE9E60296B4\gtkd-3.lib Warning 178: .LIB pagesize exceeds 512 C:\Users\Administrator.USER-20180912OL\AppData\Local\dub\packages\gtk-d-3.8.3\gtk-d\.dub\build\library-debug-windows-x86-dmd_2082-9C5C1D99F672708E9D6D6FE9E60296B4\gtkd-3.lib Error 7: Out of Memory Error: linker exited with status 1 dmd failed with exit code 1. --- I think that DMD should give up it's DMC linkers, using MinGW ld instead. DMC linker is not even a working linker.
DMD32 compiling gtkd out of memory on 32bit Windows 7 machine
hi , When compiling gtkd using dub, dmd32 reported "Out for memory" and exit. OS: Windows 7 32bit. RAM : 3GB DMD version: v2.0.82.0 32bit. No VC or Windows SDK installed, when setting up dmd, I selected install vc2010 and use mingw lib.
Re: help on how to wrap a C macros when binding linux/spi/spidev.h
On Thursday, 29 March 2018 at 09:16:11 UTC, dangbinghoo wrote: On Thursday, 29 March 2018 at 09:13:27 UTC, dangbinghoo wrote: On Thursday, 29 March 2018 at 09:02:16 UTC, Nicholas Wilson wrote: On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote: [...] try [...] thanks for your reply, but it will also fail, the compiler just gives me : source/spidev.d-mixin-129(129,8): Error: variable n cannot be read at compile time sorry, I just don't notice the `()`. yeah! it compiles, but can you explain it? thanks! just got it! `size_t N` need to be template param. Thanks for the help!
Re: help on how to wrap a C macros when binding linux/spi/spidev.h
On Thursday, 29 March 2018 at 09:13:27 UTC, dangbinghoo wrote: On Thursday, 29 March 2018 at 09:02:16 UTC, Nicholas Wilson wrote: On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote: [...] try [...] thanks for your reply, but it will also fail, the compiler just gives me : source/spidev.d-mixin-129(129,8): Error: variable n cannot be read at compile time sorry, I just don't notice the `()`. yeah! it compiles, but can you explain it? thanks!
Re: help on how to wrap a C macros when binding linux/spi/spidev.h
On Thursday, 29 March 2018 at 09:02:16 UTC, Nicholas Wilson wrote: On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote: * #define SPI_MSGSIZE(N) \ N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \ ? ((N)*(sizeof (struct spi_ioc_transfer))) : 0) */ extern (D) size_t SPI_MSGSIZE(size_t N) { return ((N * (spi_ioc_transfer.sizeof)) < (1 << _IOC_SIZEBITS)) ? (N * (spi_ioc_transfer.sizeof)) : 0; } /* #define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)]) */ extern (D) auto SPI_IOC_MESSAGE(size_t N) { size_t n = SPI_MSGSIZE(N); return _IOW!(char[static n])(SPI_IOC_MAGIC, 0); //mixin("return _IOW!(char[n])(SPI_IOC_MAGIC, 0);"); } ``` try extern (D) auto SPI_IOC_MESSAGE(size_t N)() { enum n = SPI_MSGSIZE(N); return _IOW!(char[n])(SPI_IOC_MAGIC, 0); //mixin("return _IOW!(char[n])(SPI_IOC_MAGIC, 0);"); } thanks for your reply, but it will also fail, the compiler just gives me : source/spidev.d-mixin-129(129,8): Error: variable n cannot be read at compile time
Re: help on how to wrap a C macros when binding linux/spi/spidev.h
On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote: hi, I'm doing a D binding myself to , and has some problems to wrap the C macros. [...] PS: if I just _IOW!(char[])... it compiles, but does it mean it's unsafe? thanks!
help on how to wrap a C macros when binding linux/spi/spidev.h
hi, I'm doing a D binding myself to , and has some problems to wrap the C macros. ``` import core.sys.posix.sys.ioctl; ... /* IOCTL commands */ enum SPI_IOC_MAGIC = 'k'; /** * Orginal C macros. * * #define SPI_MSGSIZE(N) \ N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \ ? ((N)*(sizeof (struct spi_ioc_transfer))) : 0) */ extern (D) size_t SPI_MSGSIZE(size_t N) { return ((N * (spi_ioc_transfer.sizeof)) < (1 << _IOC_SIZEBITS)) ? (N * (spi_ioc_transfer.sizeof)) : 0; } /* #define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)]) */ extern (D) auto SPI_IOC_MESSAGE(size_t N) { size_t n = SPI_MSGSIZE(N); return _IOW!(char[static n])(SPI_IOC_MAGIC, 0); //mixin("return _IOW!(char[n])(SPI_IOC_MAGIC, 0);"); } ``` as shown in the above code, the SPI_IOC_MESSAGE C macro has a param `char[SPI_MSGSIZE(N)]`, what should it be wrapped to the D world? as you can see, I tried to use the type of `char[static n]` or `char[n]`, and the compile failed: ``` source/spidev.d-mixin-129(129,19): Error: expression expected, not static source/spidev.d-mixin-129(129,26): Error: found n when expecting ] source/spidev.d-mixin-129(129,27): Error: found ] when expecting ) following template argument list source/spidev.d-mixin-129(129,28): Error: found ) when expecting ; following return statement ``` or when removed static, ``` source/spidev.d-mixin-129(129,8): Error: variable n cannot be read at compile time ``` Can anyone help me? Thanks!
how to install latest lcd2 for armbain
hi there, I just flased a armbain for nanoPi M3. And, I just installed ldc2-1.2.0 armhf using apt-get. it compiles d code with combination with gcc armhf and compiled program runs great even the arch is aarch64. But I realized that ldc2 is too old, I know that latest ldc2 is 1.8.0. So, does anyone know how to install latest ldc2 from arm-debain? Thanks!