You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/prepub/symmetry-autumn-of-code-report-importc-enhancements.md
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,19 +10,19 @@ categories:
10
10
- Community
11
11
---
12
12
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).
14
14
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.
16
16
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.
18
18
19
19
## Breaking Through Technical Barriers
20
20
21
21
### Complex numbers and s7 library support
22
22
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.
24
24
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:
26
26
27
27
```c
28
28
#include<complex.h>
@@ -94,7 +94,8 @@ struct Bar test = {
94
94
.u.f = 13
95
95
};
96
96
```
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.
98
99
99
100
### Compound Literals
100
101
@@ -103,7 +104,8 @@ Taking the address of compound literals with ImportC did not compile before. Thi
103
104
```c
104
105
int *c = &(int){90};
105
106
```
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`.
107
109
108
110
### Function and Variable Redeclarations
109
111
@@ -118,19 +120,20 @@ extern char x
118
120
int foo();
119
121
double foo();
120
122
```
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.
122
125
123
126
### C Macros
124
127
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.
126
129
127
-
## Builtins support, Backend, and Linking Wins
130
+
## Built-ins support, Backend, and Linking Wins
128
131
129
-
### GNU GCC CRC builtins
132
+
### GNU GCC CRC built-ins
130
133
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.
132
135
133
-
### DMD Backend Symbol duplication
136
+
### DMD backend symbol duplication
134
137
135
138
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.
136
139
@@ -150,8 +153,9 @@ static void static_fun()
150
153
{
151
154
}
152
155
```
156
+
153
157
You will need to pass the `-lib` command-line option when creating a static library. `dmd -lib file.c` now supports this workflow.
154
158
155
159
## Community Acknowledgement
156
160
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