Skip to content

Commit 3353369

Browse files
committed
Revise ImportC article
1 parent 5c9e12b commit 3353369

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

_posts/prepub/symmetry-autumn-of-code-report-importc-enhancements.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ categories:
1010
- Community
1111
---
1212

13-
Having a central compiler that can compile code from other interoperable languages has long been one of D's major goals. And of course, that language is C. Over the years, D has adopted a powerful initiative to compile C code directly through ImportC, and several improvements were made during the 2025 term of Symmetry Autumn of Code.
13+
Having a central compiler that can compile code from other interoperable languages has long been one of D's major goals. And of course, the best supported language is C. Over the years, D has adopted a powerful initiative to compile C code directly through [a feature called ImportC](https://dlang.org/spec/importc.html).
1414

15-
You can [read more on ImportC here](https://dlang.org/spec/importc.html).
15+
The D programming community has engineered powerful compilers with very fast compile times. C has many libraries that are widely used in numerous systems. Considering D's edge in performance and safety, the ability to compile legacy C code enhances the ease of adoption in several domains. For example, a ticketing system written in C that has functioned for years cannot easily be rewritten in a modern programming language just to improve it. Not every development team is ready for that, considering the cost of re-engineering.
1616

17-
The D programming community has engineered powerful compilers with very fast compile times. C has many libraries that are widely used in numerous systems. Considering D's edge in performance and safety, the ability to compile legacy C code enhances the ease of adoption in several domains. For example, a ticketing system written in C that has functioned for years cannot be easily rewritten in a modern programming language just to improve it. Not every development team is ready for that, considering the cost of re-engineering.
17+
Several improvements to ImportC were made during the 2025 edition of [Symmetry Autumn of Code](https://saoc.io/), plugging some of the holes that hindered interoperability.
1818

1919
## Breaking Through Technical Barriers
2020

2121
### Complex numbers and s7 library support
2222

23-
Complex numbers are heavily used in control systems, signal processing, graphics, and scientific computing. C has been the language of choice for writing libraries used in high-performance DSP, embedded systems, and real-time signal pipelines.
23+
Complex numbers are heavily used in control systems, signal processing, graphics, and scientific computing. C has been the language of choice for writing libraries used in high-performance DSP, embedded systems, and real-time signal pipelines.
2424

25-
Historically, we had a hard time compiling C complex numbers from the frontend. It was even harder, sometimes impossible, to compile libraries with complex signatures, like the scientific **s7** library. There have been massive improvements in compiling such code, and we can now compile almost any C complex code. Below is a simple code snippet that now compiles successfully with D:
25+
Historically, we had a hard time compiling C complex numbers in ImportC. It was even harder, sometimes impossible, to compile libraries with complex signatures, like the scientific **s7** library. There have been massive improvements in compiling such code, and we can now compile almost any C complex number code. Below is a simple code snippet that now compiles successfully with D:
2626

2727
```c
2828
#include <complex.h>
@@ -94,7 +94,8 @@ struct Bar test = {
9494
.u.f = 13
9595
};
9696
```
97-
This is a simple snippet we can look at to the implementation of C struct designated initializers. As with C, you can go as deep as you want, and we will compile that for you while ensuring your struct members contain the desired data.
97+
98+
This is a simple snippet we can look at as an example of support for C struct designated initializers. As with C, you can go as deep as you want, and D will compile that for you while ensuring your struct members contain the desired data.
9899

99100
### Compound Literals
100101

@@ -103,7 +104,8 @@ Taking the address of compound literals with ImportC did not compile before. Thi
103104
```c
104105
int *c = &(int){90};
105106
```
106-
This is an integer pointer referencing a temporary int initialized to 90. Rest assured that you will read 90 at the memory address pointed to by `c`.
107+
108+
This is an integer pointer referencing a temporary `int` initialized to `90`. Rest assured that you will read `90` at the memory address pointed to by `c`.
107109
108110
### Function and Variable Redeclarations
109111
@@ -118,19 +120,20 @@ extern char x
118120
int foo();
119121
double foo();
120122
```
121-
Like in C, this is not permissible, and D has greatly improved to ensure these cases are checked.
123+
124+
As in C, this is not permissible, and D has greatly improved to ensure these cases are checked.
122125

123126
### C Macros
124127

125-
Macros defined in C programs can now be imported from D. These can be easily passed as flags or function arguments, depending on your use case. While this hasn't always functioned well in the past, especially when imported and used in D code, significant improvements have been made. Beyond that, several builtin macros have also been implemented in the compiler.
128+
Macros defined in C programs can now be imported from D. These can be easily passed as flags or function arguments, depending on your use case. While this hasn't always functioned well in the past, especially when imported and used in D code, significant improvements have been made. Beyond that, several built-in macros have also been implemented in the compiler.
126129

127-
## Builtins support, Backend, and Linking Wins
130+
## Built-ins support, Backend, and Linking Wins
128131

129-
### GNU GCC CRC builtins
132+
### GNU GCC CRC built-ins
130133

131-
Most of the GNU GCC Cyclic Redundancy Check (CRC) builtins have been implemented. If any C function referencing them is used in D, we provide the necessary builtin implementation.
134+
Most of the GNU GCC Cyclic Redundancy Check (CRC) built-ins have been implemented. If any C function referencing them is used in D, we provide the necessary built-in implementation.
132135

133-
### DMD Backend Symbol duplication
136+
### DMD backend symbol duplication
134137

135138
Redeclaration of global variables was initially problematic, as it often led to symbol duplication in the symbol table, particularly in DMD. This has been fixed, allowing D to link against large-scale C libraries that rely on redundant global declarations across multiple headers.
136139

@@ -150,8 +153,9 @@ static void static_fun()
150153
{
151154
}
152155
```
156+
153157
You will need to pass the `-lib` command-line option when creating a static library. `dmd -lib file.c` now supports this workflow.
154158

155159
## Community Acknowledgement
156160

157-
This work was done through the 2025 Symmetry Autumn of Code. A big thank you to the D mentors, the D community, and Symmetry Investments for sponsoring this.
161+
This work was done through the 2025 [Symmetry Autumn of Code](https://saoc.io/). A big thank you to the D mentors and the D community, and to Symmetry Investments for sponsoring the event.

0 commit comments

Comments
 (0)