dmd icon indicating copy to clipboard operation
dmd copied to clipboard

ImportC: .di generator outputs D keywords for members

Open dlangBugzillaToGithub opened this issue 2 years ago • 1 comments

dave287091 reported this on 2024-02-08T20:59:58Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24376

Description

This is already noted as a limitation of ImportC (the mismatch in keywords) and in D code you can work around it using __traits. However, in the .di generator you instead get a parse error:

C code:

struct foo {
    int version;
    const char* function;
    int uint;
};

.di file:

// ...
	struct foo
	{
		int version = void;
		const(char)* function = void;
		int uint = void;
	}
// ...

Trying to import the .di file will then fail.

I think ideally you solve this with adding a mechanism for D identifiers to have the same name as keywords. A new kind of string?

Another way to go is to have the compiler rename identifiers that are D keywords when importing C code (say by appending an underscore). Could also only do that in the .di generation, but then importing the C code and importing the .di file are different.

dlangBugzillaToGithub avatar Feb 08 '24 20:02 dlangBugzillaToGithub

marking down.

Emmankoko avatar Dec 10 '25 13:12 Emmankoko