Defining compile-time constants?

Tim K. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 17 08:32:21 PDT 2015


Hi!

I am wondering if there is any way to define constants to pass to 
the compiler like in C (especially useful in combination with 
Makefiles, for obvious reasons), i.e.:

     gcc -DPREFIX=\"/usr/local\" -o myprogram main.c

Like this a program can look for certain files inside its prefix 
during runtime and the prefix can be modified for installation in 
different locations (like /usr, ~/bin, ...) at compile time.

But how do I do something like this in D? I am using GDC, but I'd 
be interested for solutions for DMD as well. Calling 
standard-library functions at runtime to figure out where the 
binary is located is okay for my current problem as well, but 
it's not as flexible as the "define whatever data at compile time 
and have it available at runtime".


Regards,
Tim


More information about the Digitalmars-d-learn mailing list