title: Defining a Preprocessor Macro
body: <p>I'm relatively new to C++ and I'm taking a class on it. Our class was assigned a lab and my teacher has said that the lab write-up is a bit hard to understand; however, he did not make any changes to the lab write-up. So, I came across this part of the lab:</p>
  <blockquote>
  <p><strong>Defining a Preprocessor Macro</strong></p>
  <p>Long-standing convention capitalizes macro names, and this macro name must be TRACE_FUNC. The macro has a single parameter, a symbol that will be replaced by a function name when you apply the macro to the code. The start of the macro looks like this:</p>
  <pre><code>#define TRACE_FUNC( symbol )  replacement-text`
  </code></pre>
  <p>and the preprocessor will substitute the replacement text everywhere that the TRACE_FUNC( sym ) string exists in the source code, AND feed the symbol into that replacement.</p>
  <p>NOTE: the #define statement must be all on a single, logical line. To keep the length manageable, you can escape the newline character with a backslash at the end of the line; that will keep the preprocessor happy while allowing you to span a definition across multiple lines.</p>
  <p>For this exercise, the replacement text must be a complete statement, including the terminating semi-colon.</p>
  <p>The replacement text must be an output statement that prints the symbol followed by the text () called. and a newline to standard output. You can copy and modify one of the output statements from the warning.cpp source file.</p>
  </blockquote>
  <p><code>warning.cpp</code> is just a file we're using and <code>TRACE_FUNC</code> is being placed in a header file.</p>
  <p>So, I read this a couple times and I'm not 100% sure what it's asking. Looking at it one way, it seems like it's asking me to create a macro called TRACE_FUNC. If you look at it another way, it's asking me to use the macro TRACE_FUNC. All of that is fine, but I don't know how to use TRACE_FUNC at all, I can't find any documentation on it anywhere and I don't know how to create a macro. When I asked for help, my teacher just kind of said. words and not ones that were very helpful because it was a very winding, confusing answer with no explanation of what TRACE_FUNC actually is.</p>
  <p>Basically, all that my teacher said was that the symbol within <code>TRACE_FUNC</code> needs to be the name of one of the functions in the source code. As an example, say we had a function <code>foo()</code> within warning, then the symbol is supposed to be <code>foo()</code> (or foo, I'm not sure of that, either), from his explanation. Also, in the replacement text, apparently the name itself will be replaced if I put <code>#</code> in front of the symbol. I thought that supposed to denote preprocessor directives. Why am I supposed to be using it here?</p>
  <p>Anyway, doing what my teacher says pretty much does nothing. Neither this line</p>
  <p><code>#define TRACE_FUNC( foo() ) #foo() called. ;</code></p>
  <p>nor this line</p>
  <p><code>#define TRACE_FUNC( foo ) #foo () called. ;</code></p>
  <p>replace any text, which I'm pretty sure is the operation of the #define directive. So I must be applying what my teacher said in the wrong way, but I don't really know why it's wrong or how to fix it.</p>
  <p><strong>So, my question. Is <code>TRACE_FUNC</code> actually a macro and if so, is there any documentation on it that I can read? Or am I supposed to be creating <code>TRACE_FUNC</code> and if so, how exactly am I supposed to do that?</strong></p>