int to char at compile time

Hendrik Renken funsheep at gmx.net
Tue Mar 20 15:09:23 PDT 2007


BCS wrote:
> Reply to Hendrik,
> 
>> hello,
>>
>> i am trying something like that:
>>
>> char[] foo(int level, char[] msg)
>> {
>> static c = toString(level);
>> return "writefln(\"%d: %s\""~ c ~", \"" ~ msg ~ "\");";
>> }
>> int main(char[][] args)
>> {
>> mixin(foo(100, "Test"));
>> return 1;
>> }
>> but gdmd complaints that toString() cannot be evaluated at compile
>> time. is there a way to convert the int to char at compile time?
> 
> 
> Don Clugston's decimaldigit and itoa, see 
> http://trac.dsource.org/projects/ddl/browser/trunk/meta/conv.d


this doesn't work for variables like "level", just with directly wrote 
numbers.

char[] foo(int level, char[] msg)
{
     char[] c = itoa!(level); //does not work
     char[] c = itoa!(100);   //does work
}

is there no chance, to get this variable value converted?


More information about the Digitalmars-d-learn mailing list