How to use ImportC?

bachmeier no at spam.net
Fri Mar 4 00:00:53 UTC 2022


On Thursday, 3 March 2022 at 19:05:22 UTC, Leonardo wrote:
> I saw the new feature called ImportC, it's cool to be able to 
> use C code/libraries, but I'm not much experience in C and 
> didn't understand this incomplete documentation: 
> https://dlang.org/spec/importc.html
> How to use ImportC?

You just add the C files like D files when you compile and import 
them in your D code as you would a D module. At least that is all 
I've been doing. Simple example:

foo.c:

```
double twice(double x) {
   return 2.0*x;
}
```

program.d:

```
import foo;
import std.stdio;

void main() {
   writeln(twice(6.8));
}
```

Compilation:

```
dmd program.d foo.c
```



More information about the Digitalmars-d-learn mailing list