Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-20 Thread eugene via Digitalmars-d-learn
On Monday, 20 December 2021 at 21:19:43 UTC, rempas wrote: I don't have FreeBSD and I can't check the output and header I have it VirtualBox files myself but from what you are saying this seems to me as a bug. I would recommend you to file an [issue](https://issues.dlang.org/) just so the

Re: Thread exits immediately with no reason.

2021-12-20 Thread bauss via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 01:13:10 UTC, Ali Çehreli wrote: Note: nothrow means "does not throw Exception". Errors can still be thrown. Ali Which sort of makes sense since they're in theory "unrecoverable", but the name is sort of misleading because of this minor detail. It should

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 22:02:02 UTC, russhy wrote: Here how i'd do, but i'm not sure how to keep track of the index of the arguments, i forgot.. ```D import core.stdc.stdio: putc, stdout; void print(T...)(string prompt, T args) { foreach (a; args) { alias A =

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 21:49:59 UTC, Adam D Ruppe wrote: still use foreach(arg; args) and skip that index variable. I know I can use foreach ("static foreach" more specifically) but I need to be able to get the index to choose a specific argument because I want to do formatting

Re: Thread exits immediately with no reason.

2021-12-20 Thread Ali Çehreli via Digitalmars-d-learn
On 12/20/21 3:56 PM, solidstate1991 wrote: > The problem is, that even with disabling all error-handling that would > allow to shut down the thread safely, the thread only runs that while > loop once. I bet it's throwing an Error. Call your thread entry function from a try-catch wrapping

Thread exits immediately with no reason.

2021-12-20 Thread solidstate1991 via Digitalmars-d-learn
Here's this function, which serves as a thread entry point: https://github.com/ZILtoid1991/iota/blob/main/source/iota/audio/wasapi.d#L220 The problem is, that even with disabling all error-handling that would allow to shut down the thread safely, the thread only runs that while loop once.

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread russhy via Digitalmars-d-learn
Here how i'd do, but i'm not sure how to keep track of the index of the arguments, i forgot.. ```D import core.stdc.stdio: putc, stdout; void print(T...)(string prompt, T args) { foreach (a; args) { alias A = typeof(a); static if (is(A : string)) {

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 20 December 2021 at 21:26:45 UTC, rempas wrote: // Suppose all 'args' are of type "string" for this example still use foreach(arg; args) and skip that index variable.

How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
I'm trying to implement "printf" and I'm getting an error. The smallest possible code to demonstrate the error is: ``` import core.stdc.stdio; void print(T...)(string prompt, T args) { // Suppose all 'args' are of type "string" for this example ulong carg = 0; for (ulong i = 0; i <

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-20 Thread rempas via Digitalmars-d-learn
On Sunday, 19 December 2021 at 09:49:29 UTC, eugene wrote: test program: ```d import std.stdio; import core.sys.freebsd.config; import core.sys.freebsd.sys.event; void main(string[] args) { writefln("FreeBSD_version = %s", __FreeBSD_version); writefln("sizeof(kevent_t) = %s",

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:58:39 UTC, bachmeier wrote: You can see the ["String mixins" section here](http://ddili.org/ders/d.en/mixin.html) for more details. Mixins are generated at compile time, so if you're referring to a string mixin inside a runtime loop, the code will not be

Re: Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Jan via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:58:03 UTC, Tim wrote: On Monday, 20 December 2021 at 10:24:00 UTC, Jan wrote: Is this a known issue, or is there a way to instruct DMD to use a specific calling convention for a given type? This looks like a bug. It seems to work without constructor in C++,

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread bachmeier via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:23:44 UTC, rempas wrote: On Monday, 20 December 2021 at 18:12:35 UTC, Stanislav Blinov wrote: https://dlang.org/spec/traits.html#identifier Thanks!!! Finally I was able to do it! The code is the following (well not in my final project but it's a

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:12:35 UTC, Stanislav Blinov wrote: https://dlang.org/spec/traits.html#identifier Thanks!!! Finally I was able to do it! The code is the following (well not in my final project but it's a demonstration): ``` enum add_char(string c) = `if (stdout_index <

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:06:32 UTC, rempas wrote: On Monday, 20 December 2021 at 11:58:58 UTC, Tejas wrote: Ehh, it still fails; should've explicitly put the length of the array and the `extern (C)` in `main` ```d module demo; [ ... ] extern(C) /+added this because you used

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:03:09 UTC, rempas wrote: > Now the problem is that I want it to get the name of so > symbol and add it to a string literal. Let's check this example: enum state(alias name) = `name` ~ ` = 10;`; https://dlang.org/spec/traits.html#identifier

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:58:58 UTC, Tejas wrote: Ehh, it still fails; should've explicitly put the length of the array and the `extern (C)` in `main` ```d module demo; [ ... ] extern(C) /+added this because you used -betterC+/ void main() { while (true) {

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:30:09 UTC, rumbu wrote: Enums (that's why the string is declarated as enum) are evaluated at compile time, the concatenation op will not end in your code as instruction, so you can do anything outside betterC rules as long you do it at compile time. You are

Re: Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:58:03 UTC, Tim wrote: On Monday, 20 December 2021 at 10:24:00 UTC, Jan wrote: Is this a known issue, or is there a way to instruct DMD to use a specific calling convention for a given type? This looks like a bug. It seems to work without constructor in C++,

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:30:09 UTC, rumbu wrote: On Monday, 20 December 2021 at 10:49:20 UTC, rempas wrote: On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote: Thanks a lot for the info. When I try to use this code, I'm getting the following error: ``` Error: expression

Re: Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Tim via Digitalmars-d-learn
On Monday, 20 December 2021 at 10:24:00 UTC, Jan wrote: Is this a known issue, or is there a way to instruct DMD to use a specific calling convention for a given type? This looks like a bug. It seems to work without constructor in C++, but still crashes with a constructor in D. It also seems

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rumbu via Digitalmars-d-learn
On Monday, 20 December 2021 at 10:49:20 UTC, rempas wrote: On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote: Thanks a lot for the info. When I try to use this code, I'm getting the following error: ``` Error: expression expected, not `%` Error: expression expected, not `%` ``` My

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote: because you cannot have statements directly in a template (the fact that is a mixin template is irelevant), only declarations. If you want to just insert some random code, use strings. You can create a templated enum to store your

Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Jan via Digitalmars-d-learn
I have a small struct that I'm trying to interface to. C++ ```cpp struct __declspec(dllexport) SmallStruct { float value = 0; //float value2 = 0; //float value3 = 0; SmallStruct(float val) : value(val) { } static SmallStruct GetValue(float input) { return

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rumbu via Digitalmars-d-learn
On Monday, 20 December 2021 at 08:45:50 UTC, rempas wrote: Here I am having a problem with templates again. No matter how much I read, I can't seem to understand how templates/mixins work. So any ideas why this doesn't work? because you cannot have statements directly in a template (the

Re: dynamic array + copy ctor

2021-12-20 Thread vit via Digitalmars-d-learn
On Sunday, 19 December 2021 at 23:21:00 UTC, Stanislav Blinov wrote: On Sunday, 19 December 2021 at 22:29:21 UTC, vit wrote: Hello, Why is copy ctor in this example not called? Because D runtime isn't properly married to copy constructors yet. I.e. it's a bug, a variant of this one:

How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
Here I am having a problem with templates again. No matter how much I read, I can't seem to understand how templates/mixins work. So I'm having the following code (just a snippet of the real code): ``` if (c != '%') { if (stdout_index < STDOUT_BUF_LEN) {