rahuljn Posted April 10, 2016 Report Share Posted April 10, 2016 Hello As per standard we can create new sc_port in before_end_of_elaboration callback In the following example, I am creating a new port in before_end_of_elaboration callback but it is not connected in sc_main. #include "systemc.h"class test : public sc_module { public: SC_HAS_PROCESS(test); test(sc_module_name name){ SC_THREAD(fun); } void fun(){} void before_end_of_elaboration(){ sc_port<sc_signal_inout_if<bool> > in1; }};int sc_main(int, char**){ test t("t"); sc_start(100,SC_NS); sc_stop(); return 0;} But I am not getting unconnected port error. Thanks RahulJn Quote Link to comment Share on other sites More sharing options...
Stephan Gerth Posted April 11, 2016 Report Share Posted April 11, 2016 The "problem" here is that your variable in1 gets destroyed as soon as the scope of your before_end_of_elaboration function is left. This means this port is non-existant during the call to sc_start and therefore no error occurs. Quote Link to comment Share on other sites More sharing options...
rahuljn Posted April 11, 2016 Author Report Share Posted April 11, 2016 Hello I agree with you but the standard says that you can instantiate new sc_ports etc in before_end_of_elaboration callbacks. If you see @24 of IEEE doc, it says "The instantiation of objects of class sc_module,sc_port,sc_export, sc_prim_channel" Then how it works ? Thanks Rahul Quote Link to comment Share on other sites More sharing options...
Stephan Gerth Posted April 11, 2016 Report Share Posted April 11, 2016 (edited) It has nothing to do with the SystemC standard but with how C++ works. You create in1 on the stack instead of the heap which is why it is destroyed at the and of the function scope. If you can't move the port to be a member of test you would need to do it via a pointer: sc_port<sc_signal_inout_if<bool> >* in1 = new sc_port<sc_signal_inout_if<bool> >(); Please not that you can't access in1 after the function scope. It would need to be a member of test! Edited April 11, 2016 by Stephan Gerth Quote Link to comment Share on other sites More sharing options...
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.