D alternative for C/C++ -Dfoo=42

Dejan Lekic dejan.lekic at gmail.com
Tue Feb 25 05:09:54 PST 2014


On Tuesday, 25 February 2014 at 12:57:51 UTC, Dejan Lekic wrote:
> On Tuesday, 25 February 2014 at 12:45:06 UTC, Cherry wrote:
>> Hello
>>
>> I want to define an enum int, but I want to make it possible 
>> to set its value when I run dmd from the command line. Is it 
>> possible in D?
>>
>> Regards
>> Cherry
>
> D offers version blocks: http://dlang.org/version.html#version
>
> It would be great if D compiler had a way to substitute enums 
> with given values. (This is a nice candidate for a DIP)
>
> Imagine you have a code like this:
>
> module myproggy;
> import std.stdio;
> enum foo = 5;
> enum bar = "walter";
>
> int main() {
>   writeln(bar);
>   return foo;
> }
>
> ... and you call compiler like:
>   dmd myproggy.d -Dfoo=42 -Dbar=hello
>
> smart, new D compiler would replace enums (iff they exist in 
> the source code) with the given arguments, so when you run 
> myproggy, you get "walter" as output, and the exit code is 42.

And yes, if someone builds multiple modules, he/she would have to 
use fully-qualified name. Example: dmd foo.d bar.d -Dfoo.var1=5 
-Dbar.var4=walter


More information about the Digitalmars-d-learn mailing list