What is wrong here? Error: cannot cast int to SYSTEMTIME

BCS ao at pathlink.com
Tue Oct 23 08:53:18 PDT 2007


Reply to Spacen,

> Digital Mars D Compiler v1.015
> 
> Neither of these lines will compile and give: Error: cannot cast int
> to SYSTEMTIME
> 
> without a line number. How might I get this to work?
> 
> import std.date;
> 
> //long utc_time1 = std.date.getUTCtime();
> 
> void main()
> {
> //static long utc_time1 = std.date.getUTCtime();
> }
> Regards,
> Jason

For the first line, do this:

utc_time1 = std.date.getUTCtime();
static this(){long utc_time1 = std.date.getUTCtime();}

For the second drop the static (if it isn't actualy in main, you will have 
to do somthing else)

The issue is that D doesn't allow runtime initializers for non stack variables.

For the static function variable one you might be able to get away with this:

template T(char[] str, A...)
{
   long v;
   static this(){v = mixin(str);}
}


void fn()
{
   alias T!("std.date.getUTCtime()", __FILE__, __LINE__).v utc_time1;
}


there will be one version of T!(...).v for each distinct "...". Note, if 
you put this in a templated function, make sure you put pass on the template 
args or things get strange.




More information about the Digitalmars-d-learn mailing list