Thread overview
Is this a bug or illegal code?
May 29, 2014
safety0ff
May 29, 2014
safety0ff
May 29, 2014
//******* CODE **********
mixin("version = foo;");
version(foo)
{
void main(){}	
}
//****** END CODE *******
If it's illegal in D, what is the reason & where is documented?

The reason I was considering such a construct is the following:
Some C libraries have an associated "config.h" header that gets generated when it is compiled.
I was thinking it may be possible to parse these config.h files at compile time (using text import) and convert some of the #define's into "version = foo;"

It wouldn't do any favors for compile times, but it would save on having an extra step in the build process to convert config.h to config.d.
May 29, 2014
On Thu, 29 May 2014 10:45:28 -0400, safety0ff <safety0ff.dev@gmail.com> wrote:

> //******* CODE **********
> mixin("version = foo;");
> version(foo)
> {
> void main(){}	
> }
> //****** END CODE *******
> If it's illegal in D, what is the reason & where is documented?
>
> The reason I was considering such a construct is the following:
> Some C libraries have an associated "config.h" header that gets generated when it is compiled.
> I was thinking it may be possible to parse these config.h files at compile time (using text import) and convert some of the #define's into "version = foo;"

Even if that is valid code, you are much better off using enums and static if.

enum includeSomeFeature = ...

static if(includeSomeFeature)
{
 ...
}

These work much more like #defines, and can be seen outside the module.

-Steve
May 29, 2014
On Thursday, 29 May 2014 at 15:02:48 UTC, Steven Schveighoffer wrote:
> Even if that is valid code, you are much better off using enums and static if.
>
> enum includeSomeFeature = ...
>
> static if(includeSomeFeature)
> {
>  ...
> }
>
> These work much more like #defines, and can be seen outside the module.
>
> -Steve

Thanks, the following works:
mixin("enum hasFoo = true;");
static if(hasFoo)
{
void main(){}	
}