digitalmars.D - ImportC
- Emmanuel (39/39) Dec 05 2025 Hi all,
- Richard (Rikki) Andrew Cattermole (3/3) Dec 05 2025 It may be better to go with a prefix instead.
- Sergey (5/8) Dec 06 2025 Sounds good.
- Emmanuel (5/8) Dec 07 2025 I am a little unsure about using double underscores, I think it
- Walter Bright (2/2) Dec 06 2025 We've been using a _ postfix in the DMD source code for avoiding collisi...
- Emmanuel (2/5) Dec 07 2025 yessss, I think using the _ postfix might be it.
- Jonathan M Davis (6/8) Dec 11 2025 That's what the official style guide says to do when naming symbols whic...
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!
Dec 05 2025
It may be better to go with a prefix instead. __c_ The double underscore is reserved so it won't conflict.
Dec 05 2025
On Saturday, 6 December 2025 at 06:56:22 UTC, Richard (Rikki) Andrew Cattermole wrote:It may be better to go with a prefix instead. __c_ The double underscore is reserved so it won't conflict.Sounds good. Overall idea also seems reasonable. And maybe it could be even used for some tooling integration.
Dec 06 2025
On Saturday, 6 December 2025 at 06:56:22 UTC, Richard (Rikki) Andrew Cattermole wrote:It may be better to go with a prefix instead. __c_ The double underscore is reserved so it won't conflict.I am a little unsure about using double underscores, I think it will make C symbols in the symbol table a bit weird. so maybe simple to just follow D style.
Dec 07 2025
We've been using a _ postfix in the DMD source code for avoiding collisions with keywords. Not many people do that, so it seems to be effective.
Dec 06 2025
On Saturday, 6 December 2025 at 21:29:09 UTC, Walter Bright wrote:We've been using a _ postfix in the DMD source code for avoiding collisions with keywords. Not many people do that, so it seems to be effective.yessss, I think using the _ postfix might be it.
Dec 07 2025
On Saturday, December 6, 2025 2:29:09 PM Mountain Standard Time Walter Bright via Digitalmars-d wrote:We've been using a _ postfix in the DMD source code for avoiding collisions with keywords. Not many people do that, so it seems to be effective.That's what the official style guide says to do when naming symbols which would otherwise be keywords - https://dlang.org/dstyle.html#naming_keywords - so in theory, that's the standard D way to solve the problem, but I don't know what people do in practice. - Jonathan M Davis
Dec 11 2025









Sergey <kornburn yandex.ru> 