How to get compiler name and version from D code?

Dennis dkorpel at gmail.com
Fri Jul 29 09:57:43 UTC 2022


On Friday, 29 July 2022 at 09:29:47 UTC, Kirill wrote:
> ```
> Built with COMPILER_NAME COMPILER_VERSION
> ```

Something like this:
```D
version(DigitalMars) enum compiler = "DMD";
else version(LDC)    enum compiler = "LDC";
else version(GNU)    enum compiler = "GDC";
else enum compiler = "Unknown compiler";

enum buildInfo = "Built with "~compiler~" "~__VERSION__.stringof;

pragma(msg, buildInfo); // "Built with DMD 2099L"
```
With a bit more effort you could format the version nicely as 
"2.099".


More information about the Digitalmars-d mailing list