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:
//app.d
import std.stdio;
import importc;
void main()
{
importc.test();
}
and
//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?
Permalink
Reply