Is `__GNUC__` defined in dmd when using importC?
felixfxu
felixfxu at gmail.com
Fri Oct 10 08:34:15 UTC 2025
Hi,
I'm testing dmd's _importC_ in Ubuntu 24.04, my .c/.h code has
many code specific to compilers, like
#ifdef __GNUC__
I'm surprise to see that it seems like `__GNUC__` is defined in
dmd.
I can test with this code:
```d
//app.d
import std.stdio;
import importc;
void main()
{
importc.test();
}
```
and
```c
//importc.c
#include <stdio.h>
void test()
{
#ifdef __GNUC__
printf("__GNUC__ is available: %d\n", __GNUC__);
#else
printf("__GNUC__ is NOT available\n");
#endif
}
```
compiled them by : `dmd source/app.d source/importc.c`
and the output is:
>__GNUC__ is available: 16
yes, the value is 16! (maybe it's set by my system? `gcc-16` is
not released yet! but I do have a local gcc compiled/installed
from latest source)
>/usr/local/bin/gcc --version
>gcc (GCC) 16.0.0 20250930 (experimental)
My default gcc is 13:
>/usr/bin/gcc --version
>gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
When the same code is run on Windows dmd, it's:
>__GNUC__ is NOT available
I searched the dmd source code, I don't see `__GNUC__` in the
source code.
What could go wrong here?
More information about the Digitalmars-d-learn
mailing list