Why TRACE0, TRACE1, TRACE2 functions even TRACE macro can have variable arguments?

I raised following question in stack overflow some time back.

It’s possible to use TRACE macro as printf like function (variable argument list) . If it supports this facility, then why it’s necessary to have TRACE0, TRACE1 and TRACE2 macros except they’re imposing restrictions on number of arguments. Again, I’d like to know if there are any advantages on restricting number of arguments for TRACE macro.

The viewpoints shared by the community members are.

  • MFC 4 did not have variadic TRACE statements. That was added in a later version. The old-style TRACEn macros are probably there for backward compatibility.
  • The other reason is readability. It isn’t necessary to have the other trace variants (trace1, trace2 etc), but specifying exact number of arguments for a trace function is more readable than infinite number of argument list using TRACE macro

Anyway trace macros are obsolete now. It’s recommended to use ATLTRACE macro instead of TRACE macros. OK here’s quick information on TRACE macros. (See the link above for more info)

To display messages from your program in the debugger Output window, you can use the ATLTRACE macro or the MFC TRACE macro. Like assertions, the trace macros are active only in the Debug version of your program and disappear when compiled in the Release version.

  • TRACE0   Takes a format string (Only) and can be used for simple text messages, which are dumped to afxDump.
  • TRACE1   Takes a format string plus one argument (one variable that is dumped to afxDump).
  • TRACE2   Takes a format string plus two arguments (two variables that are dumped to afxDump).
  • TRACE3   Takes a format string plus three arguments (three variables that are dumped to afxDump)

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

blog comments powered by Disqus