Jump to content

SystemC _ what is mean symbol "\" ??


Recommended Posts

#define STREAM_REPORT_INFO(MSGID,message_stream) \
do {\
  std::ostringstream mout;\
  mout << sc_core::sc_time_stamp() << ": " << message_stream;\
  SC_REPORT_INFO(MSGID,mout.str().c_str());\
} while (0)

Hi All, I dont understand symbol "\" in above code , when I erase symbol "\" then it not working . . why we need "\" in above code , thanks

Link to post
Share on other sites

Hello @Hook,

The \ character is an escape sequence in C/C++.

Here is a reference https://en.m.wikipedia.org/wiki/Escape_sequences_in_C

I would recommend that you brush up your skills on C++ before continuing further.

I would recommend the book "The C++ Programming Language
Book by Bjarne Stroustrup".

 

Hope it helps.

Regards,

Ameya Vikram Singh

Link to post
Share on other sites

Well, the '\' escapes the newlines at the end of each line so that the compiler treats all lines as a single line. '#define' is a pre-processor command which expects everything to be on a single line. If you do not escape the newlines then your code is one several lines and does not work anymore.

HTH

-Eyck

Link to post
Share on other sites

To be slightly more precise, the back-slash character (\) has two contexts. In this context, it is an escape character for CPP, the C Pre-Processor. It should only be used when using the pre-processor #define directive. Without \, the #define must be kept entirely on a single line.

The other context for which \ is used, is inside literal strings and and character constants. Examples: "Hello world\r\n" and "\n". In these cases, it serves to provide an escape to introduce non-printable ASCII characters.

 

Link to post
Share on other sites

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...