Re: Cannot compile C file using ImportC

2021-11-12 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 12 November 2021 at 08:12:22 UTC, Ola Fosheim Grøstad wrote: Maybe there are some metaprogramming advantages, but I cannot think of any. Well, one advantage might be that it could be easier to do escape analysis of C code. Not really sure if there is a difference compared to doing

Re: Cannot compile C file using ImportC

2021-11-12 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 11 November 2021 at 02:03:22 UTC, Steven Schveighoffer wrote: I don't think ImportC is that much of a game changer (you can already make C bindings with quite a small effort, and there are tools to get you 90% there), but a broken/not working ImportC will be a huge drawback to the

Re: Cannot compile C file using ImportC

2021-11-10 Thread rempas via Digitalmars-d-learn
On Thursday, 11 November 2021 at 02:03:22 UTC, Steven Schveighoffer wrote: I don't think ImportC is that much of a game changer (you can already make C bindings with quite a small effort, and there are tools to get you 90% there), but a broken/not working ImportC will be a huge drawback to th

Re: Cannot compile C file using ImportC

2021-11-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/10/21 12:38 PM, rempas wrote: On Wednesday, 10 November 2021 at 15:04:35 UTC, Steven Schveighoffer wrote: I'm using the downloaded LDC2 for aarch64. But I'm not building tomld.c that you created, I'm building the reduced example (that I posted). How? What's the difference in your exam

Re: Cannot compile C file using ImportC

2021-11-10 Thread rempas via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 17:57:50 UTC, Imperatorn wrote: Agreed. But, it must be quite seamless. But if we could get there, yes 🌟 It should be able to compile medium to big libraries. Nobody excepts it to be able to compile GIMP but it should be a able to tomlc99 which is a little

Re: Cannot compile C file using ImportC

2021-11-10 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 17:38:12 UTC, rempas wrote: On Wednesday, 10 November 2021 at 15:04:35 UTC, Steven Schveighoffer wrote: [...] How? What's the difference in your example? How you preprocessed and compiled? [...] I did! I personally believe that ImportC is the last and on

Re: Cannot compile C file using ImportC

2021-11-10 Thread rempas via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 15:04:35 UTC, Steven Schveighoffer wrote: I'm using the downloaded LDC2 for aarch64. But I'm not building tomld.c that you created, I'm building the reduced example (that I posted). How? What's the difference in your example? How you preprocessed and compil

Re: Cannot compile C file using ImportC

2021-11-10 Thread rempas via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 15:06:26 UTC, Steven Schveighoffer wrote: It shouldn't. Perhaps you mean that you get more errors if you fix that situation? A compiler typically has phases where it can error out. This means that it might not get to further errors (or further errors are hap

Re: Cannot compile C file using ImportC

2021-11-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/10/21 1:31 AM, rempas wrote: 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)

Re: Cannot compile C file using ImportC

2021-11-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/10/21 2:04 AM, rempas wrote: 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

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 line

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 if

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 to

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) = &malloc;` may solve your issue.

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, and

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 rathe

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 `s

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 ex

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) voi

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 th