Jump to content
Hook

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

Share this post


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

Share this post


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

Share this post


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.

 

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

×