compile-time variables?
BCS
ao at pathlink.com
Sun Jun 10 16:36:27 PDT 2007
Reply to Fraser,
> BCS Wrote:
>
>> ...
>>
>> const int Baz = 0;
>> pragma(msg, "#define Baz 0\n")
>> template Foo(A...)
>> {
>> pragma{msg,"template
>> Foo("~convert_Tuple_To_Args_List_And_Specilization!(A)~"){const
>> int Foo = Baz;}\n#define Baz (Baz+1)\n")
>> }
>> Use this Foo everywhere you need it (with enough stuff in A to make
>> each
>> use unique).
>> Compile everything, pipe through cpp, recompile with the resulting
>> code in
>> place of the original code.
>> I will now retreat to my lair to repent for that blasphemy. <g>
>>
> Heh; works like a charm! Thanks for that hackery!
>
How??? /I/ can't seem to get it working.
I wrote another version instead
module vars;
const char[] prefix = ""; // tag for grep'ing if filtering needed
pragma(msg, prefix~"module vars;");
template Serial(char[] file)
{
pragma(msg,prefix~"template Serial(char[] file : \""~file~"\"){const int
Serial = __LINE__;}");
const Serial = 0;
}
to build:
1 compile everything in one go, don't link
2 redirect output (with filtering if needed) to vars.d
3 re-compile with vars.d in place of the file this code was in
bud seems to fail when you try this directly but you can work around it with
some scripting:
rm -f vars.d vars2.d
build use_hack.d serial.d -nolink -full > vars2.d
mv vars2.d vars.d
build use_hack.d -full
./use_hack
More information about the Digitalmars-d
mailing list