April 29, 2023
On 4/29/2023 2:00 PM, bachmeier wrote:
> On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
> 
>> Thanks! Every .h file we can make work makes ImportC that much more useful. It's a high leverage activity for time invested.
> 
> I filed one earlier today:
> 
> https://issues.dlang.org/show_bug.cgi?id=23867
> 
> Seems to have an easy fix. I added
> 
> #define __builtin_isnan isnan
> 
> to the .c file and it compiled.

Do a PR to add this to importc.h and take the credit for the fix!
April 29, 2023
On Saturday, 29 April 2023 at 21:41:51 UTC, Walter Bright wrote:
> On 4/29/2023 2:00 PM, bachmeier wrote:
>> On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
>> 
>>> Thanks! Every .h file we can make work makes ImportC that much more useful. It's a high leverage activity for time invested.
>> 
>> I filed one earlier today:
>> 
>> https://issues.dlang.org/show_bug.cgi?id=23867
>> 
>> Seems to have an easy fix. I added
>> 
>> #define __builtin_isnan isnan
>> 
>> to the .c file and it compiled.
>
> Do a PR to add this to importc.h and take the credit for the fix!

I'll give it a try. There's a similar trivial fix for the other issue I created.
April 29, 2023
On Saturday, 29 April 2023 at 21:50:03 UTC, bachmeier wrote:
> On Saturday, 29 April 2023 at 21:41:51 UTC, Walter Bright wrote:
>> On 4/29/2023 2:00 PM, bachmeier wrote:
>>> On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
>>> 
>>>> Thanks! Every .h file we can make work makes ImportC that much more useful. It's a high leverage activity for time invested.
>>> 
>>> I filed one earlier today:
>>> 
>>> https://issues.dlang.org/show_bug.cgi?id=23867
>>> 
>>> Seems to have an easy fix. I added
>>> 
>>> #define __builtin_isnan isnan
>>> 
>>> to the .c file and it compiled.
>>
>> Do a PR to add this to importc.h and take the credit for the fix!
>
> I'll give it a try. There's a similar trivial fix for the other issue I created.

Now I can add "compiler developer" to my resume.

https://github.com/dlang/dmd/pull/15147
April 30, 2023
On Saturday, 29 April 2023 at 20:20:28 UTC, Walter Bright wrote:
> On 4/29/2023 3:09 AM, Max Samukha wrote:
>> https://issues.dlang.org/show_bug.cgi?id=23866
>
> Thanks for the help!

One more: https://issues.dlang.org/show_bug.cgi?id=23870
May 02, 2023
On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
> It turns out that every platform we support has "Standard" .h

https://issues.dlang.org/show_bug.cgi?id=23879


May 03, 2023
On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
> It turns out that every platform we support has "Standard" .h files that won't compile with Standard C11. They all rely on multiple extensions, each platform with a different set of reliances (usually unnecessary).
>
> [snip]

Does ImportC work with WSL? I started up my dual boot of linux for the first time in a few years and everything was pretty out of date and I don't feel like dealing with it.
May 03, 2023
On Wednesday, 3 May 2023 at 14:54:10 UTC, jmh530 wrote:
> On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
>> It turns out that every platform we support has "Standard" .h files that won't compile with Standard C11. They all rely on multiple extensions, each platform with a different set of reliances (usually unnecessary).
>>
>> [snip]
>
> Does ImportC work with WSL? I started up my dual boot of linux for the first time in a few years and everything was pretty out of date and I don't feel like dealing with it.

I use a Windows laptop from time to time. Haven't encountered any problems using WSL. You probably want to build the latest DMD from Github if you want to use ImportC.
May 03, 2023
On Wednesday, 3 May 2023 at 15:10:12 UTC, bachmeier wrote:
> On Wednesday, 3 May 2023 at 14:54:10 UTC, jmh530 wrote:
>> On Thursday, 27 April 2023 at 20:16:32 UTC, Walter Bright wrote:
>>> It turns out that every platform we support has "Standard" .h files that won't compile with Standard C11. They all rely on multiple extensions, each platform with a different set of reliances (usually unnecessary).
>>>
>>> [snip]
>>
>> Does ImportC work with WSL? I started up my dual boot of linux for the first time in a few years and everything was pretty out of date and I don't feel like dealing with it.
>
> I use a Windows laptop from time to time. Haven't encountered any problems using WSL. You probably want to build the latest DMD from Github if you want to use ImportC.

Thanks.
May 04, 2023

On Friday, 28 April 2023 at 14:35:25 UTC, bachmeier wrote:

>

[snip]
Compiling with dmd:

dmd test.c -P-I../../gsl-2.7.1 -I/usr/include -I/usr/lib/x86_64-linux-gnu/ -L-lgsl -L-lgslcblas -L-lm

Alright, I built dmd from source on WSL2. I was able to get a simple importc program working, but then I got a little stuck when I try to make it a little more complicated.

What I want to do is the equivalent of #include <math.h> from C, but in a D file. I tried using import math; with a small program that uses it and compiled dmd file.d -L-lm but I get a message that it can't find the math module.

It seemed to do a bit better when I renamed the file to have a .c ending, but then I would have to put the code back in C terms so I get errors related to that. When I fix those and replace the import math; with the include, then it works. But this is just compiling the C code with a D compiler. I want to use the C code in a D program.

May 05, 2023

On Thursday, 4 May 2023 at 13:34:25 UTC, jmh530 wrote:

>

On Friday, 28 April 2023 at 14:35:25 UTC, bachmeier wrote:

>

[snip]
Compiling with dmd:

dmd test.c -P-I../../gsl-2.7.1 -I/usr/include -I/usr/lib/x86_64-linux-gnu/ -L-lgsl -L-lgslcblas -L-lm

Alright, I built dmd from source on WSL2. I was able to get a simple importc program working, but then I got a little stuck when I try to make it a little more complicated.

What I want to do is the equivalent of #include <math.h> from C, but in a D file. I tried using import math; with a small program that uses it and compiled dmd file.d -L-lm but I get a message that it can't find the math module.

It seemed to do a bit better when I renamed the file to have a .c ending, but then I would have to put the code back in C terms so I get errors related to that. When I fix those and replace the import math; with the include, then it works. But this is just compiling the C code with a D compiler. I want to use the C code in a D program.

It would help to have your code. My examples using the R standalone math library are somewhat more involved by the nature of that library.

Here's a file test.d:

import qnorm;
import std.stdio;

void main() {
  writeln(Rf_qnorm5(0.3,1.2, 0.8, 0, 0));
}

The equivalent R code is qnorm(0.3, 1.2, 0.8, FALSE).

The import qnorm line tells DMD to pull in the code from qnorm.c in that same directory. I don't need to add qnorm.c in the compilation command, which is

dmd test.d -P-I. -P-I../gnuwin32/fixed/h -P-I../include -L/usr/lib/libR.so

Is DMD doing something with qnorm.c? I don't know, but if I comment out import qnorm;, I get the error message

test.d(5): Error: undefined identifier `Rf_qnorm5`

so I assume it's working. Maybe I can come up with a simpler/more practical example without the complexity of this library. This is the first time ImportC has worked well enough for me to compile C files.