Jump to content
katang

Scope of SC_HAS_PROCESS

Recommended Posts

I am following the alternative style in book SCFTGU, and I wanted to put two closely related modules in the same source file. I collected the experience that using  SC_HAS_PROCESS for the second module in the same source file provokes error message. Why is it so?

 

Share this post


Link to post
Share on other sites

However, if you are splitting into .h and .cpp files for module, e.g., Blah, you must  place the SC_HAS_PROCESS(Blah), on the top of the implementation (.cpp) file, this way:

 

//.h

#import <systemc.h>

...

class Blah: sc_module {

Blah(sc_module_name);

~Blah();

}

//.cpp file

#include "Blah.h"

SC_HAS_PROCESS(Blah);

 

Blah::Blah(sc_module_name nm): sc_module(nm) {

}

Blah::~Blah(){

}

Share this post


Link to post
Share on other sites

Personally, I prefer to put SC_HAS_PROCESS directly into the constructor body, which works very reliably. All that SC_HAS_PROCESS does is to create a typedef called SC_CURRENT_USER_MODULE which refers to .... the current module name. It is only used in the three macros SC_THREAD, SC_METHOD and SC_CTHREAD. Syntactically, C++ allows a typedef to be created within a function (in this case the constructor function).

Advantages of this approach:

  • It's defined very close to the point of usage.
  • The user of a header file, does not need to see it.
/.h

#import <systemc> // I never use systemc.h

...

class Blah: sc_module {

Blah(sc_module_name);

~Blah();

}

//.cpp file

#include "Blah.h"
using namespace sc_core;
  
Blah::Blah(sc_module_name nm): sc_module(nm) {
    SC_HAS_PROCESS(Blah);
    SC_THREAD(blah_thread);
    ...
}

Blah::~Blah(){

}

 

Share this post


Link to post
Share on other sites

"Personally, I prefer to put SC_HAS_PROCESS directly into the constructor body, which works very reliably. All that SC_HAS_PROCESS does is to create a typedef "

Yep you right: "All that SC_HAS_PROCESS does is to create a typedef", now explain to your compiler to 'construct' something, that it was not defined before the constructor call. how do you do that? (rhetoric) . That it is precisely why the authors of SystemC: From the Ground Up, explained to place SC_HAS_PROCESS before the constructors.

GCC,  lets this kind of 'thing' pass, try with Clang++ now.

 

Plus you don't place that in the header file, instead, it is in the implementation file the .cc, .cpp, (whatever extension you are using) that will contain it inside your own namespace if it is the case.

Share this post


Link to post
Share on other sites

Hello @Hook,

The "systemc.h" header file actually include the "systemc" header, if you look at the source.

Note: Reproduced below a section of the systemc.h header from SystemC release 2.3.3

202     using std::memset;
203     using std::strerror;
204     using std::strlen;
205
206 // deprecated strstream support
207 #if defined( SC_INCLUDE_STRSTREAM )
208 #include <strstream>
209
210     using std::strstream;
211     using std::strstreambuf;
212     using std::istrstream;
213     using std::ostrstream;
214
215 #endif // SC_INCLUDE_STRSTREAM
216
217 // INCLUDE SYSTEMC DEFINITIONS for sc_dt AND sc_core NAMESPACES:
218
219 #include "systemc"
220
221 // USINGS FOR THE sc_dt NAMESPACE:
222
223 using sc_dt::SC_BIN;
224 using sc_dt::SC_BIN_SM;
225 using sc_dt::SC_BIN_US;

But it also exports the symbols from the SystemC sc_core and sc_dt namespace in the global scope(as evident from the above snippet).

You can find relevant discussion here:

  1. https://stackoverflow.com/questions/10269012/global-scope-vs-global-namespace
  2. https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice

It is generally considered a bad C++ coding guideline to export everything in the global scope.

Hope it helps.

Regards,

Ameya Vikram Singh

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×