Re: Completing C code with D style

2021-11-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote: btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-) That's not the point. The point is the program is doing unnecessary non-trivial work while

Re: Can we do system calls like that in D?

2021-11-09 Thread rempas via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 12:28:59 UTC, Adam D Ruppe wrote: I'd be very easy to do that as a library mixin. You'd write @syscall(45) void whatever(); mixin BindSyscalls; and then the library generates the bodies as inline asm. Hello Adam! Well this is not exactly the behavior I was

Re: Cannot compile C file using ImportC

2021-11-09 Thread rempas via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 13:44:04 UTC, Steven Schveighoffer wrote: It seems like it should work. Figuring out the "lines" for things is really difficult in this expanded format, even though I know why it does that. I think importC should possibly allow printing of the actual source

Re: Completing C code with D style

2021-11-09 Thread forkit via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov wrote: On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote: They both produce exactly the same output. But do vastly different things. But I tell ya.. the cognitive load .. well.. it increased dramatically ;-) Of

Re: Completing C code with D style

2021-11-09 Thread forkit via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov wrote: On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote: They both produce exactly the same output. But do vastly different things. But I tell ya.. the cognitive load .. well.. it increased dramatically ;-) Of

Re: Cannot compile C file using ImportC

2021-11-09 Thread rempas via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 06:38:58 UTC, rempas wrote: On Tuesday, 9 November 2021 at 22:19:37 UTC, Stefan Koch wrote: It rather tries to interpret the C code as D code. It's not a full C compiler rather it's a shim in front of the D frontend. Therefore bugs like the above can happen

Re: Cannot compile C file using ImportC

2021-11-09 Thread rempas via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 22:19:37 UTC, Stefan Koch wrote: It rather tries to interpret the C code as D code. It's not a full C compiler rather it's a shim in front of the D frontend. Therefore bugs like the above can happen if the compiler wasn't aware that the function identifier was

Re: Cannot compile C file using ImportC

2021-11-09 Thread rempas via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 19:34:44 UTC, Stefan Koch wrote: What's happening here is that dmd seems to see `free` as function rather than a pointer to a function. changing `static void* (*ppmalloc)(size_t) = malloc;` to `static void* (*ppmalloc)(size_t) = ` may solve your issue. Thanks

Re: Completing C code with D style

2021-11-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote: They both produce exactly the same output. But do vastly different things. But I tell ya.. the cognitive load .. well.. it increased dramatically ;-) Of course it did. Cuz you overthunk it. Dramatically. Your D version allocates

Re: Cannot compile C file using ImportC

2021-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/9/21 5:19 PM, Stefan Koch wrote: On Tuesday, 9 November 2021 at 21:03:20 UTC, Steven Schveighoffer wrote: On 11/9/21 3:05 PM, Stefan Koch wrote: Yes it is valid C. It is not valid D though. The file is named `tomld.c` The way importC works is, you pass a .c file to the compiler,

Re: dmd 2.098.0: version `GLIBC_2.14' not found (required by linux/bin64/dmd)

2021-11-09 Thread kdevel via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 00:22:35 UTC, jfondren wrote: On Monday, 8 November 2021 at 23:55:02 UTC, kdevel wrote: In previous versions I used the linux32/dmd with the -m64 switch in order to generate 64-bit code. But this does not work anymore: $ linux/bin32/dmd linux/bin32/dmd:

Re: Cannot compile C file using ImportC

2021-11-09 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 21:03:20 UTC, Steven Schveighoffer wrote: On 11/9/21 3:05 PM, Stefan Koch wrote: Yes it is valid C. It is not valid D though. The file is named `tomld.c` The way importC works is, you pass a .c file to the compiler, and it treats it as C. -Steve It

Re: Cannot compile C file using ImportC

2021-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/9/21 3:05 PM, Stefan Koch wrote: Yes it is valid C. It is not valid D though. The file is named `tomld.c` The way importC works is, you pass a .c file to the compiler, and it treats it as C. -Steve

Re: Cannot compile C file using ImportC

2021-11-09 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 19:53:48 UTC, Steven Schveighoffer wrote: On 11/9/21 2:34 PM, Stefan Koch wrote: On Tuesday, 9 November 2021 at 11:45:28 UTC, rempas wrote: [...] What's happening here is that dmd seems to see `free` as function rather than a pointer to a function. changing

Re: Cannot compile C file using ImportC

2021-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/9/21 2:34 PM, Stefan Koch wrote: On Tuesday, 9 November 2021 at 11:45:28 UTC, rempas wrote: ``` toml.c(39): Error: cannot implicitly convert expression `malloc` of type `extern (C) void*(ulong __size)` to `extern (C) void* function(ulong)` toml.c(40): Error: cannot implicitly convert

Re: Cannot compile C file using ImportC

2021-11-09 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 11:45:28 UTC, rempas wrote: ``` toml.c(39): Error: cannot implicitly convert expression `malloc` of type `extern (C) void*(ulong __size)` to `extern (C) void* function(ulong)` toml.c(40): Error: cannot implicitly convert expression `free` of type `extern (C)

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-09 Thread tchaloupka via Digitalmars-d-learn
On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: Bug or feature? :) I've reported it in https://issues.dlang.org/show_bug.cgi?id=22498.

Knowledge is power

2021-11-09 Thread Imperatorn via Digitalmars-d-learn
Just putting this excellent collection of D idioms here for those new to the language: https://p0nce.github.io/d-idioms/

Re: Cannot compile C file using ImportC

2021-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/9/21 6:45 AM, rempas wrote: So I'm trying to compile the [toml99](https://github.com/cktan/tomlc99) C library with DMD using ImportC. I first preprocessed the file using `cproc`. The reason I didn't used GCC is because it defines some symbols specific to GCC so it will furthermore mess

Re: Can we do system calls like that in D?

2021-11-09 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 11:52:10 UTC, rempas wrote: It's an attribute. I'm talking specifically about the `@extern(syscall, )` attribute that let's you make an system call and bind it under a name without having any library linked or without having to write any assembly. Is this

Can we do system calls like that in D?

2021-11-09 Thread rempas via Digitalmars-d-learn
There is an amazing feature in a language that is is in alpha called [vox](https://github.com/MrSmith33/vox). Vox is actually inspired from the D language. This feature is described [here](https://github.com/MrSmith33/vox/blob/master/spec/index.md#built-in-attributes) and It's an attribute. I'm

Cannot compile C file using ImportC

2021-11-09 Thread rempas via Digitalmars-d-learn
So I'm trying to compile the [toml99](https://github.com/cktan/tomlc99) C library with DMD using ImportC. I first preprocessed the file using `cproc`. The reason I didn't used GCC is because it defines some symbols specific to GCC so it will furthermore mess the compilation process. I created

Re: Completing C code with D style

2021-11-09 Thread forkit via Digitalmars-d-learn
On Monday, 8 November 2021 at 12:04:26 UTC, forkit wrote: On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote: Next code originally was a classic C code I've written, it's pure vertical thinking, now, I converted it successfully to D code, but I think I made no much changes to make it