www.digitalmars.com         C & C++   DMDScript  

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

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

This week, I had a long run with issue 20092 working to make 
compound literals fully work in importC and it has been 
successfully fixed and merged.

issue: https://github.com/dlang/dmd/issues/20092

The whole idea as discussed with my mentor was to create a 
temporary variable and then export it with the addressof operator 
during semantic analysis.

I did a lot of research into the expression semantics to fully 
understand how the compound literals would fit together. for 
local pointers, creating a temporary and making sure the variable 
declaration and the variable expression were exported with the 
`addressof` was enough.

for globals, it needed a little extra tinkering by making sure I 
push the symbol into the symbol table for the address to be 
picked up by the pointer.

PR : https://github.com/dlang/dmd/pull/21908#event-19961166923


`int *p = &(int){0};` in importC should get you a valid pointer 
which you can work with and not necessarily creating an object 
before pointing it as defined by the C standard.
Sep 29
parent reply jmh530 <john.michael.hall gmail.com> writes:
On Monday, 29 September 2025 at 08:51:00 UTC, Emmanuel wrote:
 Hi everyone,

 This week, I had a long run with issue 20092 working to make 
 compound literals fully work in importC and it has been 
 successfully fixed and merged.

 [...]
Thanks. Do you know if the test suite includes C projects?
Sep 29
parent reply Emmanuel <emmankoko519 gmail.com> writes:
On Monday, 29 September 2025 at 12:51:59 UTC, jmh530 wrote:
 On Monday, 29 September 2025 at 08:51:00 UTC, Emmanuel wrote:
 Hi everyone,

 This week, I had a long run with issue 20092 working to make 
 compound literals fully work in importC and it has been 
 successfully fixed and merged.

 [...]
Thanks. Do you know if the test suite includes C projects?
Yes, I think. there are C files being run by DMD in compilable and runnable tests. even in fail compilations as well. I don't really get what you mean by `C projects` but C files are being tested.
Sep 29
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 30/09/2025 2:23 AM, Emmanuel wrote:
 On Monday, 29 September 2025 at 12:51:59 UTC, jmh530 wrote:
 On Monday, 29 September 2025 at 08:51:00 UTC, Emmanuel wrote:
 Hi everyone,

 This week, I had a long run with issue 20092 working to make compound 
 literals fully work in importC and it has been successfully fixed and 
 merged.

 [...]
Thanks. Do you know if the test suite includes C projects?
Yes, I think. there are C files being run by DMD in compilable and runnable tests. even in fail compilations as well. I don't really get what you mean by `C projects` but C files are being tested.
Projects like sljit. We do this with D projects using the buildkite CI test. But not with C. This is one of the libraries I consider a requirement for ImportC to be minimally operational. https://github.com/dlang/dmd/issues/21891 https://github.com/dlang/dmd/issues/21890 ImportC is getting really close, but yes it would be nice if we could track this with actual C projects being tested against.
Sep 29