Jump to content

Best practices: SC_HAS process question for experts


David Black

Recommended Posts

[By 'expert', I am referring to those of you that write SystemC code regularly and have decent proficiency. This is not a newbie question.]

Can anybody give me a specific example of when SC_HAS_PROCESS is needed outside the constructor?

I personally cannot think of any reason to place it outside the constructor with one exception, multiple constructors. Multiple constructors are rare in my experience (use of default constructor parameters is more common). Even with multiple constructors, I suspect placing SC_HAS_PROCESS inside each one is not a huge overhead.

The reason for my question for my question is because I think a strong recommendation for best practices is to move SC_HAS_PROCESS into the constructor where it is used. This has several advantages:

  1. If the constructor is implemented separately in a .cpp file, then the SC_HAS process clutter is removed from the header.
  2. It directs the implementor's/reviewer's attention to the real use of this macro: supporting SC_THREAD, SC_METHOD, etc.

I realize this is a bit of a nit. I am not looking to change the standard, but I am looking to provide good recommendations for best practices.

Link to comment
Share on other sites

8 hours ago, David Black said:

But what about prior to C++11? (Inquisitive minds want to know.)

Keeping declarations in their smallest required scope is generally a good practice in C++. To me, this applies to SC_HAS_PROCESS as well, which currently is a typedef underneath.  I agree, that a repetition in multiple constructors (or before_end_of_ekaboration()) is not a big concern.
 

Link to comment
Share on other sites

  • 9 months later...
On 4/22/2022 at 6:15 PM, Philipp A Hartmann said:

Actually, SC_HAS_PROCESS will no longer be needed at all in future versions of SystemC when using C++11 (and maybe the next standard?).

Hi, I'm a newbie to systemc, I was browsing about SC_HAS_PROCESS when I saw your answer. I wonder why we won't need SC_HAS_PROCESS in the future?
I would be super grateful if you could clear up my confusion.

Link to comment
Share on other sites

  • 1 year later...
On 4/22/2022 at 6:15 PM, Philipp A Hartmann said:

Actually, SC_HAS_PROCESS will no longer be needed at all in future versions of SystemC when using C++11 (and maybe the next standard?).

systems 3.0.0 deprecated SC_HAS_PROCESS. May I ask what's the recommended coding style for C++ >11? Previously I use SC_HAS_PROCESS for constructor with customer arguments.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...