📄 debugmac.ts.html
字号:
<html><!-- Mirrored from c-faq.com/cpp/debugmac.ts.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:59 GMT --><head><title></title></head><body>From: tstyles@my-dejanews.com<br>Newsgroups: comp.lang.c<br>Subject: Re: Macros with variable number of arguments?<br>Date: Mon, 22 Mar 1999 08:24:26 GMT<br>Message-ID: <7d4unk$2rc$1@nnrp1.dejanews.com><p>In article <SouthSide-2003990057220001@bns.vip.best.com>,<br> SouthSide@kagi.com (Bob Bradley) wrote:<br>> Is it possible to create a macro with a variable number of arguments? I<br>> want to create a debugging macro that accepts a variable-number of<br>> arguments to call a printf-like routine, but when a preprocessor flag is<br>> off, I want it to completely eliminate the function call. For example:<br>><br>> #if( DEBUG )<br>> #define DebugMacro( ... ) printf( ... )<br>> #else<br>> #define DebugMacro( ... )<br>> #endif<p><pre>#if( DEBUG ) #define DebugMacro(Fmt_and_Args) printf(Fmt_and_Args) #define Arg(X) , (X)#else #define DebugMacro(Fmt_and_Args) #define Arg(X)#endif</pre><p>Usage<pre> DebugMacro("Index %d, value %f"Arg(i)Arg(value));</pre>This then allows you to insert 'hidden' arguments, eg<pre>#if( DEBUG ) #define DebugMacro(Fmt_and_Args) fprintf(stderr,Fmt_and_Args)</pre>or even,<pre>#if( DEBUG ) #define DebugMacro(Fmt_and_Args) dbgprintf(__FILE__,__LINE__,Fmt_and_Args)</pre>Tristan Styles #1485<p>Failure is not an Option<br>It is Standard Operating Procedure</body><!-- Mirrored from c-faq.com/cpp/debugmac.ts.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:59 GMT --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -