mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 20:50:41 +03:00
Turn macro translations into template functions (#21108)
This commit is contained in:
parent
ce15cb9c65
commit
cfa763d301
29 changed files with 667 additions and 629 deletions
38
changelog/druntime.macro-templates.dd
Normal file
38
changelog/druntime.macro-templates.dd
Normal file
|
@ -0,0 +1,38 @@
|
|||
C Macro translations in druntime have been translated to templates
|
||||
|
||||
This prevents linking errors when using `-betterC`.
|
||||
For example:
|
||||
|
||||
---
|
||||
import core.sys.posix.stdlib;
|
||||
import core.sys.posix.unistd;
|
||||
|
||||
extern(C) int main()
|
||||
{
|
||||
int status, pid = vfork();
|
||||
if (pid == 0)
|
||||
{
|
||||
// ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
waitpid(pid, &status, 0);
|
||||
if (WIFEXITED(status))
|
||||
{
|
||||
// ...
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
---
|
||||
|
||||
This would fail to compile with the `-betterC` flag:
|
||||
|
||||
---
|
||||
$(CONSOLE
|
||||
Error: undefined reference to `core.sys.posix.sys.wait.WIFEXITED(int)`
|
||||
referenced from `main`
|
||||
)
|
||||
---
|
||||
|
||||
The reason is that `WIFEXITED` is a C macro that was translated to a D function in druntime, which requires linking with druntime to use.
|
||||
Now that it's a template, it will be lazily instantiated and the program compiles.
|
Loading…
Add table
Add a link
Reference in a new issue