Re: std.format doesn't want to work

2021-10-16 Thread russhy via Digitalmars-d-learn
On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 wrote: When I make this call ``` format(" %3.3f"w, avgFPS); ``` my program immediately crashes with an access violation error. The debugger out is different between x86 and x86-64. I've made all sanity checks, so I need some other

Re: Can we use "ImportC" used yet?

2021-10-16 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 17 October 2021 at 04:45:26 UTC, data pulverizer wrote: I ended up defining `typedef struct __float128__ {unsigned long long x[2];} __float128__;` and doing a find and replace for `__float128` which is totally overkill since I won't be using it and according to the documentation,

Re: Can we use "ImportC" used yet?

2021-10-16 Thread data pulverizer via Digitalmars-d-learn
I ended up defining `typedef struct __float128__ {unsigned long long x[2];} __float128__;` and doing a find and replace for `__float128` which is totally overkill since I won't be using it and according to the documentation, the D compiler doesn't support 128-bit floats yet though it has

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 17 October 2021 at 02:42:54 UTC, Tejas wrote: Doesn't solve the compile-time only problem though :( The only solution I can think of is something with `variant`s, but it'll be messy. Well, the fundamental issue is that in a language like D that compiles to machine code, variable

Re: std.format doesn't want to work

2021-10-16 Thread frame via Digitalmars-d-learn
On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 wrote: When I make this call ``` format(" %3.3f"w, avgFPS); ``` my program immediately crashes with an access violation error. The debugger out is different between x86 and x86-64. I've made all sanity checks, so I need some other

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Sunday, 17 October 2021 at 03:38:43 UTC, data pulverizer wrote: 2. Run the commands: ``` gcc -E -P test_og.c > test_c.c dmd test.d test_c.c && ./test ``` which works. Now I've tried the same thing with library `fftw3` and getting: ``` Error: undefined identifier `__float128` ``` Which I

Re: Can we use "ImportC" used yet?

2021-10-16 Thread data pulverizer via Digitalmars-d-learn
Okay I'm definitely trying to use `importC` rather than the regular `extern(C)` way. I can see where I went wrong. The steps for importC for header files are: 1. Prepend the following directives to `test_og.c` or whatever your interface c script is: ``` #define __restrict restrict #define

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Sunday, 17 October 2021 at 02:45:03 UTC, data pulverizer wrote: While we're on this subject, I've been having similar issues now tried compiling @rempas's example file with: ``` gcc test_og.c -c -o test_og.o dmd test.d test_og.o ``` and get the response: ``` test_og.c(1): Error:

Re: Can we use "ImportC" used yet?

2021-10-16 Thread data pulverizer via Digitalmars-d-learn
On Saturday, 16 October 2021 at 08:19:41 UTC, rempas wrote: On Saturday, 16 October 2021 at 07:09:16 UTC, jfondren wrote: If I understand correctly you mean compile the original file with gcc (`gcc test_og.c -o test_og.o`) and then link it with DMD (`dmd test.d test_og.o`)? ... While we're

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Tejas via Digitalmars-d-learn
On Sunday, 17 October 2021 at 02:31:04 UTC, Paul Backus wrote: On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: ```d void main() { import std.stdio; int fooVar = 4; string strVar; strVar = "fooVar"; writeln(typeof(mixin(strVar))); writeln(mixin(strVar)); } ```

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: ```d void main() { import std.stdio; int fooVar = 4; string strVar; strVar = "fooVar"; writeln(typeof(mixin(strVar))); writeln(mixin(strVar)); } ``` Failed with 2x "Error: variable `strVar` cannot be read at

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Tejas via Digitalmars-d-learn
On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: On Saturday, 16 October 2021 at 19:29:59 UTC, Dennis wrote: On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: How does one obtain from strVar: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar?

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread DLearner via Digitalmars-d-learn
On Saturday, 16 October 2021 at 19:29:59 UTC, Dennis wrote: On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: How does one obtain from strVar: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `mixin(strVar)` ``` void main() { import std.stdio;

std.format doesn't want to work

2021-10-16 Thread solidstate1991 via Digitalmars-d-learn
When I make this call ``` format(" %3.3f"w, avgFPS); ``` my program immediately crashes with an access violation error. The debugger out is different between x86 and x86-64. I've made all sanity checks, so I need some other suggestions.

Re: Parameter forwarding

2021-10-16 Thread Kostiantyn Tokar via Digitalmars-d-learn
On Friday, 15 October 2021 at 17:22:52 UTC, Tejas wrote: On Friday, 15 October 2021 at 06:52:41 UTC, Kostiantyn Tokar wrote: On Thursday, 14 October 2021 at 17:53:57 UTC, Tejas wrote: Maybe DIP 1040 will automatically solve that? last use of objects that is a copy gets elided into a move

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: How does one obtain from strVar: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `mixin(strVar)`

Obtaining type and value of a variable named in another variable

2021-10-16 Thread DLearner via Digitalmars-d-learn
Hi Suppose string variable strVar has value "fooVar". fooVar is a valid variable name used elsewhere in the program. How does one obtain from strVar: 1. The type of fooVar; 2. The value of fooVar? Best regards

Re: Threading challenge: calculate fib(45) while spinning

2021-10-16 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Friday, 15 October 2021 at 03:35:44 UTC, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: [...] Here is a similar implementation using the concurrency library: ```d import concurrency; import concurrency.stream; import concurrency.sender :

Re: Can we use "ImportC" used yet?

2021-10-16 Thread rempas via Digitalmars-d-learn
On Saturday, 16 October 2021 at 11:03:06 UTC, jfondren wrote: I came up with those `#define`s by looking at test_c.c as d complained about it. It includes these functions in the final result: ```c static __uint16_t __bswap_16 (__uint16_t __bsx) { return (__bsx); } static __uint32_t

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Saturday, 16 October 2021 at 08:19:41 UTC, rempas wrote: On Saturday, 16 October 2021 at 07:09:16 UTC, jfondren wrote: This test_og.c works (while obviously breaking some bswap functions): I don't know if I should have known that but what is "bswap"? I came up with those `#define`s by

Re: std.zip expand: memory allocation failed

2021-10-16 Thread Imperatorn via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:41:36 UTC, Selim Ozel wrote: I am simply trying to unzip a compressed zip file slightly over 1GB. The de-compressed size is about 4 GB. The code is very similar to what's explained in the documentation [1] and it works for smaller files. Anyone has a

Re: How to make a function that accepts optional struct but can accept struct literal too

2021-10-16 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:33:33 UTC, JN wrote: Is there some nice way of achieving something like this C99 code in D? [...] The [literal](https://www.ibm.com/docs/sr/xl-c-and-cpp-aix/13.1.0?topic=operators-compound-literal-expressions) in the C version creates an alloca too but it's

Re: Can we use "ImportC" used yet?

2021-10-16 Thread rempas via Digitalmars-d-learn
On Saturday, 16 October 2021 at 07:09:16 UTC, jfondren wrote: This test_og.c works (while obviously breaking some bswap functions): I don't know if I should have known that but what is "bswap"? It would be less annoying to compile the original test_og.o with gcc and then link it in. If I

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Saturday, 16 October 2021 at 06:39:46 UTC, rempas wrote: ``` // Filename: test.d import test_c; void main() { hello_world(); } // Filename: test_og.c #include #include void hello_world() { puts("Hello world!!!"); } ``` After that, I'm using: `gcc -E -P test_og.c > test_c.c` to

Re: Can we use "ImportC" used yet?

2021-10-16 Thread rempas via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:45:35 UTC, jfondren wrote: There's no option, you just use a normal import statement when the module is named .c instead of .d I say 'just' but typical C uses the C preprocessor and can't be imported as-is. [ ... ] First of all, I see you answering