⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_67217.htm

📁 vc
💻 HTM
字号:
<p>
序号:67217 发表者:badboy 发表日期:2003-12-30 11:37:56
<br>主题:一个源代码里有那么多宏定义,套来套去,就看不懂了,我想看看不用宏替换之前的代码怎么看?
<br>内容:一个源代码里有那么多宏定义,套来套去,就看不懂了,我想看看不用宏替换之前的代码,怎么看?<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;有什么好办法,不然我只有自己一点一点手动替换了!比如下面这个个程序里就有好几个宏,如果没有没有宏,直接看就容易理解了!但,怎么替换呀? VC里是不是有个预编译器?要是能看看这个预编译器执行后的结果,我看,差不多就可以了!是这样吗?<BR><BR><BR>#include &lt;stdio.h&gt;<BR>#define ANSI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Comment out for UNIX version&nbsp;&nbsp;&nbsp;&nbsp; */<BR>#ifdef ANSI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* ANSI compatible version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>#include &lt;stdarg.h&gt;<BR>int average( int first, ... );<BR>#else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* UNIX compatible version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>#include &lt;varargs.h&gt;<BR>int average( va_list );<BR>#endif<BR><BR>void main( void )<BR>{<BR>&nbsp;&nbsp; /* Call with 3 integers (-1 is used as terminator). */<BR>&nbsp;&nbsp; printf( &#34;Average is: %d\n&#34;, average( 2, 3, 4, -1 ) );<BR><BR>&nbsp;&nbsp; /* Call with 4 integers. */<BR>&nbsp;&nbsp; printf( &#34;Average is: %d\n&#34;, average( 5, 7, 9, 11, -1 ) );<BR><BR>&nbsp;&nbsp; /* Call with just -1 terminator. */<BR>&nbsp;&nbsp; printf( &#34;Average is: %d\n&#34;, average( -1 ) );<BR>}<BR><BR>/* Returns the average of a variable list of integers. */<BR>#ifdef ANSI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* ANSI compatible version&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>int average( int first, ... )<BR>{<BR>&nbsp;&nbsp; int count = 0, sum = 0, i = first;<BR>&nbsp;&nbsp; va_list marker;<BR><BR>&nbsp;&nbsp; va_start( marker, first );&nbsp;&nbsp;&nbsp;&nbsp; /* Initialize variable arguments. */<BR>&nbsp;&nbsp; while( i != -1 )<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum += i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i = va_arg( marker, int);<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; va_end( marker );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Reset variable arguments.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>&nbsp;&nbsp; return( sum ? (sum / count) : 0 );<BR>}<BR>#else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* UNIX compatible version must use old-style definition.&nbsp;&nbsp;*/<BR>int average( va_alist )<BR>va_dcl<BR>{<BR>&nbsp;&nbsp; int i, count, sum;<BR>&nbsp;&nbsp; va_list marker;<BR><BR>&nbsp;&nbsp; va_start( marker );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Initialize variable arguments. */<BR>&nbsp;&nbsp; for( sum = count = 0; (i = va_arg( marker, int)) != -1; count++ )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum += i;<BR>&nbsp;&nbsp; va_end( marker );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Reset variable arguments.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>&nbsp;&nbsp; return( sum ? (sum / count) : 0 );<BR>}<BR>#endif<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:michael 回复日期:2003-12-30 11:41:44
<br>内容:&nbsp;&nbsp; 不是吧?宏是为了让别人更容易的读写代码呀。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:林建华 回复日期:2003-12-30 13:05:26
<br>内容:没看见有什么宏啊,只看见一些预编译定义啊
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:badboy 回复日期:2003-12-30 15:24:23
<br>内容:&#34;宏是为了让别人更容易的读写代码呀。 &#34;<BR><BR> 不错,他们写代码倒是容易了,但读呢?意义可就不好理解了!<BR>va_list <BR>va_start( marker );&nbsp;&nbsp; <BR>va_end( marker );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>&nbsp;&nbsp;这三个就是人家用的宏,不把他们转化为代码我怎么理解他们的实际意义?所以,我想把他们替换成不要宏的样子!&nbsp;&nbsp;<BR> 这几个宏的定义分别为:(对了,上面那个程序是MSDN上的例子)<BR><BR><BR>#define va_start(ap,v)&nbsp;&nbsp;( ap = (va_list)&amp;v + _INTSIZEOF(v) )<BR>#define va_arg(ap,t)&nbsp;&nbsp;&nbsp;&nbsp;( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )<BR>#define va_end(ap)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( ap = (va_list)0 )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>#define _INTSIZEOF(n)&nbsp;&nbsp; ( (sizeof(n) + sizeof(int) - 1) &amp; ~(sizeof(int) - 1) )<BR>typedef char *&nbsp;&nbsp;va_list;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:林建华 回复日期:2003-12-30 18:59:51
<br>内容:现在写代码的话一般很少宏函数,我们都用inline函数的,那样比较清晰:)
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:badboy 回复日期:2004-01-03 10:10:31
<br>内容:那几个宏,你懂吗?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -