digitalmars.D.learn - What is wrong here? Error: cannot cast int to SYSTEMTIME
- Spacen Jasset (12/12) Oct 23 2007 Digital Mars D Compiler v1.015
- BCS (20/37) Oct 23 2007 For the first line, do this:
- Spacen Jasset (5/57) Oct 23 2007 Ah ok. I need to read up on this. The code I was intending to use in
- BCS (3/21) Oct 23 2007 What do objects have to do with it? I might not be understanding what yo...
- Steven Schveighoffer (8/20) Oct 23 2007 I have seen this error before. It was a bug in the compiler
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
Oct 23 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, JasonFor 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.
Oct 23 2007
BCS wrote:Reply to Spacen,Ah ok. I need to read up on this. The code I was intending to use in that manner was for testing. Presumably the way is to create a class and use objects. Thanks for the assistance.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, JasonFor 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.
Oct 23 2007
Reply to Spacen,BCS wrote:What do objects have to do with it? I might not be understanding what you want to do.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.Ah ok. I need to read up on this. The code I was intending to use in that manner was for testing. Presumably the way is to create a class and use objects.Thanks for the assistance.
Oct 23 2007
I have seen this error before. It was a bug in the compiler (http://d.puremagic.com/issues/show_bug.cgi?id=1300). Try upgrading to latest, I have dmd 1.021 (1.019 fixed this bug). Once you do upgrade, you will find that you get a much more descriptive error, because BCS is right, static initializers must be evaluated at compile time. Follow his instructions to get it working how you want. -Steve "Spacen Jasset" wroteDigital 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
Oct 23 2007