📄 subject_67217.htm
字号:
<p>
序号:67217 发表者:badboy 发表日期:2003-12-30 11:37:56
<br>主题:一个源代码里有那么多宏定义,套来套去,就看不懂了,我想看看不用宏替换之前的代码怎么看?
<br>内容:一个源代码里有那么多宏定义,套来套去,就看不懂了,我想看看不用宏替换之前的代码,怎么看?<BR> <BR> 有什么好办法,不然我只有自己一点一点手动替换了!比如下面这个个程序里就有好几个宏,如果没有没有宏,直接看就容易理解了!但,怎么替换呀? VC里是不是有个预编译器?要是能看看这个预编译器执行后的结果,我看,差不多就可以了!是这样吗?<BR><BR><BR>#include <stdio.h><BR>#define ANSI /* Comment out for UNIX version */<BR>#ifdef ANSI /* ANSI compatible version */<BR>#include <stdarg.h><BR>int average( int first, ... );<BR>#else /* UNIX compatible version */<BR>#include <varargs.h><BR>int average( va_list );<BR>#endif<BR><BR>void main( void )<BR>{<BR> /* Call with 3 integers (-1 is used as terminator). */<BR> printf( "Average is: %d\n", average( 2, 3, 4, -1 ) );<BR><BR> /* Call with 4 integers. */<BR> printf( "Average is: %d\n", average( 5, 7, 9, 11, -1 ) );<BR><BR> /* Call with just -1 terminator. */<BR> printf( "Average is: %d\n", average( -1 ) );<BR>}<BR><BR>/* Returns the average of a variable list of integers. */<BR>#ifdef ANSI /* ANSI compatible version */<BR>int average( int first, ... )<BR>{<BR> int count = 0, sum = 0, i = first;<BR> va_list marker;<BR><BR> va_start( marker, first ); /* Initialize variable arguments. */<BR> while( i != -1 )<BR> {<BR> sum += i;<BR> count++;<BR> i = va_arg( marker, int);<BR> }<BR> va_end( marker ); /* Reset variable arguments. */<BR> return( sum ? (sum / count) : 0 );<BR>}<BR>#else /* UNIX compatible version must use old-style definition. */<BR>int average( va_alist )<BR>va_dcl<BR>{<BR> int i, count, sum;<BR> va_list marker;<BR><BR> va_start( marker ); /* Initialize variable arguments. */<BR> for( sum = count = 0; (i = va_arg( marker, int)) != -1; count++ )<BR> sum += i;<BR> va_end( marker ); /* Reset variable arguments. */<BR> 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>内容: 不是吧?宏是为了让别人更容易的读写代码呀。
<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>内容:"宏是为了让别人更容易的读写代码呀。 "<BR><BR> 不错,他们写代码倒是容易了,但读呢?意义可就不好理解了!<BR>va_list <BR>va_start( marker ); <BR>va_end( marker ); <BR><BR> 这三个就是人家用的宏,不把他们转化为代码我怎么理解他们的实际意义?所以,我想把他们替换成不要宏的样子! <BR> 这几个宏的定义分别为:(对了,上面那个程序是MSDN上的例子)<BR><BR><BR>#define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )<BR>#define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )<BR>#define va_end(ap) ( ap = (va_list)0 ) <BR>#define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )<BR>typedef char * va_list;
<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 + -