Defining compile-time constants?

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 17 08:33:42 PDT 2015


On 18/09/15 3:32 AM, Tim K. wrote:
> 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

Well string imports, could work.
But you would need to save it to a file first.


More information about the Digitalmars-d-learn mailing list