int to char at compile time

Hendrik Renken funsheep at gmx.net
Wed Mar 21 00:08:25 PDT 2007


torhu wrote:
> Hendrik Renken wrote:
> 
>> but gdmd complaints that toString() cannot be evaluated at compile 
>> time. is there a way to convert the int to char at compile time?
> 
> 
> std.metastrings has a couple of ways of doing this.

just for the records: with std.metastrings i am running in the same 
problems having with DDL.

the ctfe_itoa function from Frits van Bommel works great. Thanks again.


another little problem/maybe-bug i ran into:
since i currently only have defined int values for "level", i use a 
switch-Statement to get propper String representations.

const int CORE = 100;

char[] foo(int level, char[] msg)
{
     char[] name;
     switch(level)
     {
	case CORE:
		name = "CORE"; /******* important line ********/

		break;
	default:
		name = "TEST";
	}
     return "writefln(\"%s: %s\", "~ name ~", \"" ~ msg ~ "\");";
}


int main(char[][] args)
{
    mixin(foo(CORE, "Testmsg"));
    return 1;
}


using
name = "CORE";
writes to the console

100: Testmsg


using
name = "\"CORE\"";
gives me what i want

CORE: Testmsg

shouldnt it also work with "CORE"? or am i missing something here?

regards
Hendrik


More information about the Digitalmars-d-learn mailing list