DS1701 Posted April 12, 2018 Report Share Posted April 12, 2018 #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 Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted April 12, 2018 Report Share Posted April 12, 2018 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 Quote Link to comment Share on other sites More sharing options...
DS1701 Posted April 12, 2018 Author Report Share Posted April 12, 2018 thank @AmeyaVS , sorry for my question , but can you explain clear when I erase "\" above code, it not working Quote Link to comment Share on other sites More sharing options...
Eyck Posted April 12, 2018 Report Share Posted April 12, 2018 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 Quote Link to comment Share on other sites More sharing options...
David Black Posted April 12, 2018 Report Share Posted April 12, 2018 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. Quote Link to comment Share on other sites More sharing options...
DS1701 Posted April 12, 2018 Author Report Share Posted April 12, 2018 thanks all , 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.