Re: Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?

2022-09-13 Thread Tejas via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 03:13:59 UTC, Daniel Donnell, Jr wrote: On Sunday, 11 September 2022 at 02:14:51 UTC, zjh wrote: On Saturday, 10 September 2022 at 22:07:32 UTC, Ali Çehreli wrote: On 9/10/22 13:04, Daniel Donnell wrote: > https://dlang.org/spec/cpp_interface.html At DConf, Man

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 23:34:33 UTC, Ali Çehreli wrote: On 9/13/22 04:07, test123 wrote: > On Tuesday, 13 September 2022 at 10:59:36 UTC, Dennis wrote: >> Side node, you can use `immutable` instead of `__gshared const`, it >> amounts to the same for global variables. > > because __enum

Re: can not take const struct member address at CTFE , is this a bug?

2022-09-13 Thread test123 via Digitalmars-d-learn
On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The Roobster wrote: The addresses of items stored in memory are by definition not constant. This isn't a bug. If so why this can work ? ```d struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = & d; ``` the `e` can ge

Re: How to work with long paths on Windows?

2022-09-13 Thread Preetpal via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 19:54:15 UTC, Preetpal wrote: In Windows 10, Version 1607 (and later), you can [enable long paths](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry) which bypasses the MAX_PATH limitation for local paths (e.g., C:\Us

Re: can not take const struct member address at CTFE , is this a bug?

2022-09-13 Thread Ruby The Roobster via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 11:16:55 UTC, test123 wrote: ```d struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = &d.a; ``` ./test.d(4): Error: expression `&c(3u, 4u).a` is not a constant I need this to work around C struct array member like this: ```c s

Re: How check if destructor has been called?

2022-09-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.09.22 19:13, Ben Jones wrote: On Tuesday, 13 September 2022 at 14:06:42 UTC, Injeckt wrote: Hi, I'm trying to check if destructor has been called, but when I'm deleting class object I didn't get any calls from destructor. myclass.d     ~this() {     this.log("\nDestructor\n");  

Re: need help to translate C into D

2022-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 9/13/22 04:07, test123 wrote: > On Tuesday, 13 September 2022 at 10:59:36 UTC, Dennis wrote: >> Side node, you can use `immutable` instead of `__gshared const`, it >> amounts to the same for global variables. > > because __enums_layout.ptr need to be part of other object, and this > const ptr

Re: Function attribute best practices

2022-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 9/13/22 10:08, Paul Backus wrote: > Here's my attempt, covering all the attributes found under > [`MemberFunctionAttribute`][1] in the language spec: > > |Attribute|Affects |Inferred?| > |-||-| > |nothrow |Function|Yes | > |pure |Function|Yes | > |@nogc

How to work with long paths on Windows?

2022-09-13 Thread Preetpal via Digitalmars-d-learn
In Windows 10, Version 1607 (and later), you can [enable long paths](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry) which bypasses the MAX_PATH limitation for local paths (e.g., C:\Users\you\log.txt). Currently if you iterate over a directory with

Re: How check if destructor has been called?

2022-09-13 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 14:06:42 UTC, Injeckt wrote: Hi, I'm trying to check if destructor has been called, but when I'm deleting class object I didn't get any calls from destructor. myclass.d ~this() { this.log("\nDestructor\n"); this._free_trash(); } main.

Re: Function attribute best practices

2022-09-13 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 14:16:39 UTC, Ali Çehreli wrote: On 9/12/22 09:39, Paul Backus wrote: > Yes. Except for `@trusted`, explicit attributes on template code are a > smell. Except for 'const' as well because some templates are member functions. And 'const' on a member function cann

Re: Function attribute best practices

2022-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/22 09:39, Paul Backus wrote: > Yes. Except for `@trusted`, explicit attributes on template code are a > smell. Except for 'const' as well because some templates are member functions. And 'const' on a member function cannot be left to inference because it happens to be a part of the typ

How check if destructor has been called?

2022-09-13 Thread Injeckt via Digitalmars-d-learn
Hi, I'm trying to check if destructor has been called, but when I'm deleting class object I didn't get any calls from destructor. myclass.d ~this() { this.log("\nDestructor\n"); this._free_trash(); } main.d try { server.server_init(server); } catch (Ex

Re: Function attribute best practices

2022-09-13 Thread jmh530 via Digitalmars-d-learn
On Monday, 12 September 2022 at 16:39:14 UTC, Paul Backus wrote: [snip] Yes. Except for `@trusted`, explicit attributes on template code are a smell. [snip] If I can be 100% sure that something will always be @safe/nothrow/pure/@nogc, then I might consider marking them as such. For instan

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 11:29:12 UTC, Dennis wrote: On Tuesday, 13 September 2022 at 11:03:30 UTC, test123 wrote: and upb_MiniTable_Enum can include a lot diff types. (for example mixed diff size upb_MiniTable_Enum) I think you'll need a `void*` array then, since pointers to differen

Re: need help to translate C into D

2022-09-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 11:03:30 UTC, test123 wrote: and upb_MiniTable_Enum can include a lot diff types. (for example mixed diff size upb_MiniTable_Enum) I think you'll need a `void*` array then, since pointers to different structs can all implicitly convert to `void*`.

can not take const struct member address at CTFE , is this a bug?

2022-09-13 Thread test123 via Digitalmars-d-learn
```d struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = &d.a; ``` ./test.d(4): Error: expression `&c(3u, 4u).a` is not a constant I need this to work around C struct array member like this: ```c struct c { uint32_t a, b; uint32_t[] arr; } ``` If I

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 10:59:36 UTC, Dennis wrote: On Tuesday, 13 September 2022 at 10:45:03 UTC, test123 wrote: Is there a way to init the __gshared fixed length upb_MiniTable_Enum array ? I don't think so. You could leave your array typed as `validate_KnownRegex_enum_init_type` an

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 10:59:36 UTC, Dennis wrote: On Tuesday, 13 September 2022 at 10:45:03 UTC, test123 wrote: Is there a way to init the __gshared fixed length upb_MiniTable_Enum array ? I don't think so. You could leave your array typed as `validate_KnownRegex_enum_init_type` an

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 10:59:36 UTC, Dennis wrote: On Tuesday, 13 September 2022 at 10:45:03 UTC, test123 wrote: Is there a way to init the __gshared fixed length upb_MiniTable_Enum array ? I don't think so. You could leave your array typed as `validate_KnownRegex_enum_init_type` an

Re: need help to translate C into D

2022-09-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 10:45:03 UTC, test123 wrote: Is there a way to init the __gshared fixed length upb_MiniTable_Enum array ? I don't think so. You could leave your array typed as `validate_KnownRegex_enum_init_type` and access it through a function that casts it to `upb_MiniTabl

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 10:45:03 UTC, test123 wrote: upb_MiniTable_Enum array ? 2 type error I think it cloud be compiler bugs. 1): `expression `&validate_KnownRegex_enum_init_type(64u, 2u, [7u, 0u], ).header` is not a constant` ```d union validate_KnownRegex_enum_init_type {

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 09:57:38 UTC, Dennis wrote: On Tuesday, 13 September 2022 at 09:43:46 UTC, test123 wrote: This will not work since the C have no array like D. You can use a 0-size static array: ```D struct mystruct { uint32_t mask_limit; // Limit enum value that can be test

Re: need help to translate C into D

2022-09-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 09:43:46 UTC, test123 wrote: This will not work since the C have no array like D. You can use a 0-size static array: ```D struct mystruct { uint32_t mask_limit; // Limit enum value that can be tested with mask. uint32_t value_count; // Number of va

Re: need help to translate C into D

2022-09-13 Thread test123 via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 07:31:50 UTC, Marvin wrote: On Tuesday, 13 September 2022 at 06:04:49 UTC, test123 wrote: I can not use importC, I need it to be work in D code. ```d typedef struct { uint32_t mask_limit; // Limit enum value that can be tested with mask. uint32_t value_c

Re: Linker Error with Template Function

2022-09-13 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 03:00:17 UTC, Kyle Ingraham wrote: Any suggestions for being able to call one function for any instance given but maintain flexible return types? Not sure if it helps, but you can define final methods in an interface, which can call virtual interface methods:

Re: need help to translate C into D

2022-09-13 Thread Marvin via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 06:04:49 UTC, test123 wrote: I can not use importC, I need it to be work in D code. ```d typedef struct { uint32_t mask_limit; // Limit enum value that can be tested with mask. uint32_t value_count; // Number of values after the bitfield. uint32_t dat