compile-time variables?

Bill Baxter dnewsgroup at billbaxter.com
Tue May 22 17:07:39 PDT 2007


Fraser wrote:
> Thanks for the ideas! Unfortunately, it doesn't seem to be working (either way). Here's the complete code I tried:
> 
> --------------------
> import tango.io.Stdout;
> 
> char[] ctfe_itoa(uint value)
> {
> 	if (value < 10) return "0123456789"[value .. value+1];
> 	return ctfe_itoa(value / 10) ~ ctfe_itoa(value % 10);
> }
> 
> uint Counter(){
> 	return 1;
> }
> 
> uint Counter(in uint value){
> 	return value+1;
> }
> 
> uint nextID()
> {
> 	const auto first = Counter();
> 	const auto second = Counter(first);
> 	const auto third = Counter(second);
> 	return third;
> }

Looks to me like this is doing exactly what you asked it to: return 3 no 
matter what.
I think you need a static variable like

uint nextID() {
    static uint id=0;
    return ++id;
}

Unless I'm missing something.

--bb



More information about the Digitalmars-d mailing list