ImportC

Emmanuel emmankoko519 at gmail.com
Sat Dec 6 06:46:23 UTC 2025


Hi all,

I have been trying to make .di files clean as a lot of dirty code 
gets emitted in them when generated from C code.

```
typedef unsigned int uint;
```
Very allowed in C libs and becomes
```
alias unit = unit;
```

Issues opened on that and other unwanted code in the .di files.

We realize that the D generated for the simple example above is 
invalid because the alias semantics is broken by self aliasing 
and also the uint is a token.

I decided to do a little work on this by appending all D keywords 
in C files that are used as identifiers with ‘_’ .  Then we make 
a loud noise in the man pages about that. If any C identifier 
happens to be a D keyword, use a `_` appended version when 
referencing it from D.

So that we can get
```
alias uint_ = uint;
```

It does also affect declarations.

C could have
```
int version = 5 ;
```

When you want to reference it from D,

```
if (_version == 5) // version variable is from C
     // do something
```

It was a little buggy initially but I’ve been able to register it 
at points that now correctly does that with no code breaking. But 
I don’t know how welcoming that will be to the D community. But 
this looks like the best fix for now and I think will save us 
from future trouble. I’ve discussed with Dennis Korpel as well.

Happy to hear what you guys think!



More information about the Digitalmars-d mailing list