Xesium 0 Posted February 16 Report Share Posted February 16 Hi, I have a complicated logger which uses sc_time().value() to print the value of the time. Currently everything is printed in ps resolution. My system at best runs in ms resolution. I want to change the time resolution using sc_set_time_resolution. So I put sc_set_time_resolution(1,sc_core::SC_MS); as the very first line in my sc_main(argc, argv). However the model fails in run-time due to "sc_time object(s) constructed". I'm not quite sure how on the very first line of sc_main() a sc_time object has been created. Any insight is very much appreciated. Also if my approach is incorrect in the first place, please let me know. Quote Link to post Share on other sites
maehne 75 Posted February 17 Report Share Posted February 17 Maybe your application or one of the libraries it is using creates sc_time objects by initialising some global or static constants/variables? Quote Link to post Share on other sites
Xesium 0 Posted February 17 Author Report Share Posted February 17 Very good point. If that's the case (which probably is), is there any way to ever setting time resolution? I knew the compiler would take space for global/static variables and will zero out that piece of memory. Didn't think constructors for those objects will be called prior to sc_main execution! Trying a piece of code and sounds like that's the case. So back to my question, how can I ever set the time resolution assuming that I can't change the current structure of the code? Quote Link to post Share on other sites
Xesium 0 Posted February 17 Author Report Share Posted February 17 Actually I found the answer to my question here: https://stackoverflow.com/questions/19227664/whats-the-c-idiom-equivalent-to-the-java-static-block There is a notion of static block that runs prior to all static variables' initializations. This helped solve the issue as I used the static block to set the time resolution. Quote Link to post Share on other sites
Eyck 92 Posted February 20 Report Share Posted February 20 If you can avoid global variables at all cost. The will bite you more you think. If you need to have static global variables (e.g. for loggers or memory managers) use the Meyers-SIngleton. Those will be initialized upone first use which usually gives you some control over the live cycle. Another example can be found here: https://github.com/Minres/SystemC-Components/blob/master/incl/tlm/tlm_mm.h Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.