www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [SAOC 2025] Improve importC Weekly Update #5

reply Emmanuel <emmankoko519 gmail.com> writes:
Hi everyone,

This week, it was a pretty tough time with duplicate symbol of 
global redeclarations.

I took my time to understand how redeclaration were handled in 
`dsymbolsem`.
had to come up with a solution that finds an already exisiting 
symbol and then removes it
from module's members. it worked for that but broke other tests 
which were hard to trace.

later decided to handle it in the backend because I realized LDC 
didn't have that problem.
even if you redeclare C symbols globally, LDC merges them into 
one in the symbol table.

so I had to fix a identifier check before we emit symbols. 
Apparently, it worked.
no symbol duplications but the global symbol access seems to 
break initializer reads on x86 targets but works super fine on 
x86_64 targets. I'm still investigating, pretty sure the 32 bit 
registers couldn't handle some reads with the lookup I introduced.


can follow up in this PR: https://github.com/dlang/dmd/pull/22003

Thanks!
Oct 20
next sibling parent reply Serg Gini <kornburn yandex.ru> writes:
On Monday, 20 October 2025 at 17:16:00 UTC, Emmanuel wrote:
 Hi everyone,
 can follow up in this PR: 
 https://github.com/dlang/dmd/pull/22003

 Thanks!
Hi Do you know if `typedef enum` is planned to be enabled in importC?
Oct 27
parent reply Emmanuel <emmankoko519 gmail.com> writes:
On Monday, 27 October 2025 at 11:56:10 UTC, Serg Gini wrote:
 On Monday, 20 October 2025 at 17:16:00 UTC, Emmanuel wrote:
 Hi everyone,
 can follow up in this PR: 
 https://github.com/dlang/dmd/pull/22003

 Thanks!
Hi Do you know if `typedef enum` is planned to be enabled in importC?
Hi, I just tested a simple typedef enum code in a .c file and dmd compiles it for me. please what have you encountered with it that you want to be fixed? Thanks!
Oct 27
parent reply Sergey <kornburn yandex.ru> writes:
On Monday, 27 October 2025 at 13:10:29 UTC, Emmanuel wrote:
 I just tested a simple typedef enum code in a .c file and dmd 
 compiles it for me.

 please what have you encountered with it that you want to be 
 fixed?

 Thanks!
I have a bigger code where I've tried to apply importC. And it gave me errors regarding several parts of the enum definitions that looked like that in the header: ```c typedef enum { kColorBlack, kColorWhite, kColorClear, kColorXOR } LCDSolidColor; ``` In manually prepared code we've used: ```d enum LCDSolidColor { black, white, clear, xor } ```
Oct 27
next sibling parent Hipreme <msnmancini hotmail.com> writes:
On Monday, 27 October 2025 at 20:16:31 UTC, Sergey wrote:
 On Monday, 27 October 2025 at 13:10:29 UTC, Emmanuel wrote:
 I just tested a simple typedef enum code in a .c file and dmd 
 compiles it for me.

 please what have you encountered with it that you want to be 
 fixed?

 Thanks!
I have a bigger code where I've tried to apply importC. And it gave me errors regarding several parts of the enum definitions that looked like that in the header: ```c typedef enum { kColorBlack, kColorWhite, kColorClear, kColorXOR } LCDSolidColor; ``` In manually prepared code we've used: ```d enum LCDSolidColor { black, white, clear, xor } ```
Do not forget that enums in C works quite different than in C++. D's enum is much more akin to C++'s `enum class`. A conversion of a C enum into D, would have actually done: ```d enum { kColorBlack, kColorWhite, kColorClear, kColorXOR } ```
Oct 27
prev sibling parent Emmanuel <emmankoko519 gmail.com> writes:
On Monday, 27 October 2025 at 20:16:31 UTC, Sergey wrote:
 On Monday, 27 October 2025 at 13:10:29 UTC, Emmanuel wrote:
 I just tested a simple typedef enum code in a .c file and dmd 
 compiles it for me.

 please what have you encountered with it that you want to be 
 fixed?

 Thanks!
I have a bigger code where I've tried to apply importC. And it gave me errors regarding several parts of the enum definitions that looked like that in the header: ```c typedef enum { kColorBlack, kColorWhite, kColorClear, kColorXOR } LCDSolidColor; ``` In manually prepared code we've used: ```d enum LCDSolidColor { black, white, clear, xor } ```
Hi, Please can you open an issue with a complete use and test case and the error message. And let me know. I can look at it for you as soon as possible. Thanks!
Oct 28
prev sibling parent jmh530 <john.michael.hall gmail.com> writes:
On Monday, 20 October 2025 at 17:16:00 UTC, Emmanuel wrote:
 Hi everyone,

 [snip]
Thanks again for your work on this.
Oct 27