﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-xyjzsh-随笔分类-数据结构</title><link>http://www.cppblog.com/xyjzsh/category/15585.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 10 Aug 2011 16:53:57 GMT</lastBuildDate><pubDate>Wed, 10 Aug 2011 16:53:57 GMT</pubDate><ttl>60</ttl><item><title>一种类型的字符拷贝函数</title><link>http://www.cppblog.com/xyjzsh/archive/2011/08/10/152943.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Wed, 10 Aug 2011 06:02:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/08/10/152943.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/152943.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/08/10/152943.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/152943.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/152943.html</trackback:ping><description><![CDATA[<div>1.函数原型：<br />LPTSTR <font style="background-color: #3399ff" color="#ffffff">lstrcpyn</font>(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; LPTSTR <em>lpString1</em>,<br />&nbsp;&nbsp;&nbsp; LPCTSTR <em>lpString2</em>,//指向一个以NULL结束的字符串<br />&nbsp;&nbsp;&nbsp; int <em>iMaxLength&nbsp;&nbsp;&nbsp;//</em>从lpString2拷贝到lpString1的字符串个数，包括NULL字符<br />);<br />成功返回指向lpString1的指针，否则返回NULL。<br /><br />如果lpString2的长度大于iMaxLength，该方法实际上是<span style="color: red">将lpString2中的前</span><span style="color: #0000ff">iMaxLength-1</span><span style="color: red">个字符</span>和<span style="color: #ff0000">一个NULL字符</span>拷贝到lpString1中。<br />如果该方法成功，则lpString1一定是以NULL结束的字符串。<br /><br />2._tcsncpy是一个宏，考虑在unicode的情况下<br />define _tcsncpy wcsncpy<br /><br />wchar_t *<font style="background-color: #3399ff" color="#ffffff">wcsncpy</font>(<br />&nbsp;&nbsp; wchar_t *<span class="parameter">strDest</span>,<br />&nbsp;&nbsp; const wchar_t *<span class="parameter">strSource</span>,<br />&nbsp;&nbsp; size_t <span class="parameter">count</span> <br />);<br /><br />Parameters 
<div class="section" name="collapseableSection">
<dl class="authored">
<dt><span class="parameter">strDest</span> 
<dd>
<p>Destination string.</p>
<dt><span class="parameter">strSource</span> 
<dd>
<p>Source string.</p>
<dt><span class="parameter">count</span> 
<dd>
<p>Number of characters to be copied.</p></dd></dl></div>
<h1 class="heading"><span style="font-size: 14pt; cursor: default" tabindex="0">Return Value</span></h1>
<div id="returnValueSection" class="section" name="collapseableSection">
<p>Returns <span class="parameter">strDest</span>. No return value is reserved to indicate an error.<br />不能保证NULL结束，将count个字符拷贝到strDest中。</p></div><br /><br /><br /></div><img src ="http://www.cppblog.com/xyjzsh/aggbug/152943.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-08-10 14:02 <a href="http://www.cppblog.com/xyjzsh/archive/2011/08/10/152943.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>猜猜执行结果</title><link>http://www.cppblog.com/xyjzsh/archive/2011/07/20/151480.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Wed, 20 Jul 2011 05:52:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/07/20/151480.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/151480.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/07/20/151480.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/151480.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/151480.html</trackback:ping><description><![CDATA[static const char *msg[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};<br />char *get_a_day(int idx)<br />{ <br />&nbsp;static char buf[20]; <br />&nbsp;strcpy(buf, msg[idx]); <br />&nbsp;return buf;<br />}<br /><br />int main()<br />{<br />&nbsp;char *day0 = get_a_day(0);<br />&nbsp;char *day1 = get_a_day(1);<br />&nbsp;printf("%s %s\n", day0, day1);<br />&nbsp;return 0;<br />}<br /><br /><span style="color: red">结果是什么？</span><img src ="http://www.cppblog.com/xyjzsh/aggbug/151480.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-07-20 13:52 <a href="http://www.cppblog.com/xyjzsh/archive/2011/07/20/151480.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>返回值为函数指针的写法</title><link>http://www.cppblog.com/xyjzsh/archive/2011/04/26/145059.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Tue, 26 Apr 2011 07:36:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/04/26/145059.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/145059.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/04/26/145059.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/145059.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/145059.html</trackback:ping><description><![CDATA[下面方法的作用是：通过key的类型返回对应的哈希函数的指针<br><br>static int (*hashFunction(int keyClass))(const void*,int)<br>{<br>/*内容省略*/<br>}<br><br>函数的名字是：hashFunction,该函数为只有1个int型参数为。<br>该函数的返回值为一个函数指针，函数有2个参数，第一个类型为const void*,第二个为int，返回值为int 。<br><br>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/145059.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-04-26 15:36 <a href="http://www.cppblog.com/xyjzsh/archive/2011/04/26/145059.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c语言中模拟动态绑定</title><link>http://www.cppblog.com/xyjzsh/archive/2011/04/26/145058.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Tue, 26 Apr 2011 07:30:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/04/26/145058.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/145058.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/04/26/145058.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/145058.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/145058.html</trackback:ping><description><![CDATA[<p>struct本身不能支持动态绑定，为了实现统一接口，我们希望实现动态绑定。<br>例如在不同的操作系统下，对文件的操作是不同，但是我们希望统一结构，有如下结构<br>struct OSFile<br>{<br>&nbsp;&nbsp;&nbsp; PIOMethod pMethods;<br>&nbsp;&nbsp;&nbsp;/*<br>&nbsp;&nbsp;&nbsp;其他信息<br>&nbsp; */<br>};<br><br>struct WinOSFile<br>{<br>PIOMethod pMethods;<br>..........<br>};<br><br>struct UnixOSFile<br>{<br>PIOMethod pMethods;<br>..........<br>};<br><br>有如下方法：<br>void UniAPI(OSFile *file);<br>为了实现动态绑定，做法是在调用该方法之前，将WinOSFile或者UnixOSFile的pMethods赋给OSFile的pMethods从而实现动态绑定。<br></p>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/145058.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-04-26 15:30 <a href="http://www.cppblog.com/xyjzsh/archive/2011/04/26/145058.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>按位使用数据以及union</title><link>http://www.cppblog.com/xyjzsh/archive/2011/03/15/141901.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Tue, 15 Mar 2011 09:34:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/03/15/141901.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/141901.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/03/15/141901.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/141901.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/141901.html</trackback:ping><description><![CDATA[<p>例如：<br>typedef union tagData<br>{<br>&nbsp;&nbsp;&nbsp;long x:2;<br>&nbsp;&nbsp;&nbsp;long y:4;<br>&nbsp;&nbsp;&nbsp;long data;<br>}data_item,*pdata_item;</p>
上述是一个联合体，联合体的对象用的空间是类型中占用内存最大的哪个，例如上例中data_item变量占用4个字节。<br>long x:2;<br>表示x占用2bit<br>long y:4;<br>表示y占用4bit<br>long data;<br>data占用4byte<br>所以上述union占用4byte空间。<br>long s=sizeof(data_item);<br>s=4;<br><br>因为x,y,data公用内存空间。<br>从低位开始，即<br>x占用空间的低2bit，即0-1<br>y占用空间2~5bit<br>x,y都是可以是有符号的，相对最高位表示符号位。<br>例如，<br>item_data t={0};<br>(1) t.data = 2;<br>2表示成二进制位10.<br>所以t.x 的值为-2;<br>(2) t.data = 3;<br>3表示成二进制位11<br>所以t.x的值为-1<br>(3) t.data =1;<br>此时t.x的值为1<br><br>t.y的取值的道理同t.x;<br>对于t.y来说第5位表示正负号。<br><br><br><br>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/141901.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-03-15 17:34 <a href="http://www.cppblog.com/xyjzsh/archive/2011/03/15/141901.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>宏定义中字符串连接操作</title><link>http://www.cppblog.com/xyjzsh/archive/2011/03/15/141865.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Tue, 15 Mar 2011 05:49:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/03/15/141865.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/141865.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/03/15/141865.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/141865.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/141865.html</trackback:ping><description><![CDATA[<div class=post-headline>
<h1>宏定义中字符串连接操作</h1>
</div>
<div class="post-bodycopy clearfix">
<p>关于记号粘贴操作符(token&nbsp;paste&nbsp;operator):&nbsp;##</p>
<p>1.&nbsp;简单的说，<span style="COLOR: #ff0000">&#8220;##&#8221;是一种分隔连接方式，它的作用是先分隔，然后进行强制连接</span>。</p>
<p>&nbsp;&nbsp;&nbsp;其中，分隔的作用类似于空格。我们知道在普通的宏定义中，<span style="COLOR: #ff0000">预处理器一般把空格<br>&nbsp;&nbsp;&nbsp;解释成分段标志</span>，对于每一段和前面比较，相同的就被替换。但是这样做的结果是，<br>&nbsp;&nbsp;&nbsp;被替换段之间存在一些空格。<span style="COLOR: #ff0000">如果我们不希望出现这些空格，就可以通过添加一些<br>&nbsp;&nbsp;&nbsp;##来替代空格</span>。</p>
<p>&nbsp;&nbsp;&nbsp;<span style="COLOR: #ff0000">另外一些分隔标志是，包括操作符，比如&nbsp;+,&nbsp;-,&nbsp;*,&nbsp;/,&nbsp;[,],&nbsp;&#8230;，</span>所以尽管下面的<br>&nbsp;&nbsp;&nbsp;宏定义没有空格，但是依然表达有意义的定义：&nbsp;define&nbsp;add(a,&nbsp;b)&nbsp;&nbsp;a+b</p>
<p>&nbsp;&nbsp;&nbsp;而其强制连接的作用是，去掉和前面的字符串之间的空格，而把两者连接起来。</p>
<p>2.&nbsp;举列&nbsp;&#8211;&nbsp;试比较下述几个宏定义的区别</p>
<div style="MARGIN: 3px; FLOAT: left">
<script type=text/javascript><!--
google_ad_client = "pub-2941637122112958";
google_alternate_color = "FFFFFF";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text";
google_ad_channel ="1838017730";
google_color_border = "";
google_color_link = "";
google_color_bg = "";
google_color_text = "";
google_color_url = "";
google_ui_features = "rc:10";
//--></script>
<script type=text/javascript src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<ins style="POSITION: relative; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; MARGIN: 0px; PADDING-LEFT: 0px; WIDTH: 234px; PADDING-RIGHT: 0px; DISPLAY: inline-table; BORDER-TOP-STYLE: none; HEIGHT: 60px; VISIBILITY: visible; BORDER-LEFT-STYLE: none; PADDING-TOP: 0px"><ins style="POSITION: relative; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; MARGIN: 0px; PADDING-LEFT: 0px; WIDTH: 234px; PADDING-RIGHT: 0px; DISPLAY: block; BORDER-TOP-STYLE: none; HEIGHT: 60px; VISIBILITY: visible; BORDER-LEFT-STYLE: none; PADDING-TOP: 0px" id=aswift_0_anchor><iframe style="POSITION: absolute; TOP: 0px; LEFT: 0px" id=aswift_0 onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){i+='.call';setTimeout(h,0)}else if(h.match){i+='.nav';w.location.replace(h)}s.log&amp;&amp;s.log.push(i)}" height=60 marginHeight=0 frameBorder=0 width=234 allowTransparency name=aswift_0 marginWidth=0 scrolling=no></iframe></ins></ins></div>
<p>&nbsp;&nbsp;&nbsp;#define&nbsp;A1(name,&nbsp;type)&nbsp;&nbsp;type&nbsp;name_##type##_type&nbsp;或<br>&nbsp;&nbsp;&nbsp;#define&nbsp;A2(name,&nbsp;type)&nbsp;&nbsp;type&nbsp;name##_##type##_type</p>
<p>&nbsp;&nbsp;&nbsp;A1(a1,&nbsp;int);&nbsp;&nbsp;/*&nbsp;等价于:&nbsp;int&nbsp;name_int_type;&nbsp;*/<br>&nbsp;&nbsp;&nbsp;A2(a1,&nbsp;int);&nbsp;&nbsp;/*&nbsp;等价于:&nbsp;int&nbsp;a1_int_type;&nbsp;&nbsp;&nbsp;*/</p>
<p>&nbsp;&nbsp;&nbsp;解释：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1)&nbsp;在第一个宏定义中，&#8221;name&#8221;和第一个&#8221;_&#8221;之间，以及第2个&#8221;_&#8221;和第二个<br>&nbsp;&nbsp;&nbsp;&#8221;type&#8221;之间没有被分隔，所以预处理器会把name_##type##_type解释成3段：<br>&nbsp;&nbsp;&nbsp;&#8220;name_&#8221;、&#8220;type&#8221;、以及&#8220;_type&#8221;，这中间只有&#8220;type&#8221;是在宏前面出现过<br>&nbsp;&nbsp;&nbsp;&nbsp;的，所以它可以被宏替换。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2)&nbsp;而在第二个宏定义中，&#8220;name&#8221;和第一个&#8220;_&#8221;之间也被分隔了，所以<br>&nbsp;&nbsp;&nbsp;预处理器会把name##_##type##_type解释成4段：&#8220;name&#8221;、&#8220;_&#8221;、&#8220;type&#8221;<br>&nbsp;&nbsp;&nbsp;以及&#8220;_type&#8221;，这其间，就有两个可以被宏替换了。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3)&nbsp;A1和A2的定义也可以如下：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#define&nbsp;A1(name,&nbsp;type)&nbsp;&nbsp;type&nbsp;name_&nbsp;&nbsp;##type&nbsp;##_type&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;##前面随意加上一些空格&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#define&nbsp;A2(name,&nbsp;type)&nbsp;&nbsp;type&nbsp;name&nbsp;##_&nbsp;##type&nbsp;##_type</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;结果是##&nbsp;会把前面的空格去掉完成强连接，得到和上面结果相同的宏定义</p>
<p>3.&nbsp;其他相关&nbsp;&#8211;&nbsp;单独的一个&nbsp;#</p>
<p>&nbsp;&nbsp;&nbsp;至于单独一个#，则表示&nbsp;对这个变量替换后，再加双引号引起来。比如</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#define&nbsp;&nbsp;__stringify_1(x)&nbsp;&nbsp;&nbsp;#x<br>那么<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__stringify_1(linux)&nbsp;&nbsp;&nbsp;&lt;==&gt;&nbsp;&nbsp;&#8221;linux&#8221;</p>
<p>所以，对于MODULE_DEVICE_TABLE</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1)&nbsp;#define&nbsp;MODULE_DEVICE_TABLE(type,name)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MODULE_GENERIC_TABLE(type##_device,name)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2)&nbsp;#define&nbsp;MODULE_GENERIC_TABLE(gtype,name)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extern&nbsp;const&nbsp;struct&nbsp;gtype##_id&nbsp;__mod_##gtype##_table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__attribute__&nbsp;((unused,&nbsp;alias(__stringify(name))))</p>
<p>得到&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MODULE_DEVICE_TABLE(usb,&nbsp;products)&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*notes:&nbsp;struct&nbsp;usb_device_id&nbsp;products;&nbsp;*/<br>&nbsp;&lt;==&gt;&nbsp;MODULE_GENERIC_TABLE(usb_device,products)<br>&nbsp;&lt;==&gt;&nbsp;extern&nbsp;const&nbsp;struct&nbsp;usb_device_id&nbsp;__mod_usb_device_table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__attribute__&nbsp;((unused,&nbsp;alias(&#8220;products&#8221;)))&nbsp;&nbsp;&nbsp;</p>
<p>注意到alias&nbsp;attribute需要一个双引号，所以在这里使用了__stringify(name)来<br>给name加上双引号。另外，还注意到一个外部变量&#8221;__mod_usb_device_table&#8221;被alias<br>到了本驱动专用的由用户自定义的变量products&lt;usb_device_id类型&gt;。这个外部变量<br>是如何使用的，更多的信息请参看《probe()过程分析》。</p>
<p>4.&nbsp;分析方法和验证方式&nbsp;&#8211;&nbsp;编写一个简单的C程序</p>
<p>&nbsp;&nbsp;&nbsp;用宏定义一个变量，同时用直接方式定义一个相同的变量，编译报告重复定义；<br>&nbsp;&nbsp;&nbsp;用宏定义一个变量，直接使用该宏定义的变量名称，编译通过且运行结果正确；<br></p>
</div>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/141865.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-03-15 13:49 <a href="http://www.cppblog.com/xyjzsh/archive/2011/03/15/141865.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>虚拟指针的问题——memset相关</title><link>http://www.cppblog.com/xyjzsh/archive/2011/03/14/141792.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Mon, 14 Mar 2011 07:46:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/03/14/141792.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/141792.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/03/14/141792.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/141792.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/141792.html</trackback:ping><description><![CDATA[<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Node<br><img id=Codehighlighter1_11_80_Open_Image onclick="this.style.display='none'; Codehighlighter1_11_80_Open_Text.style.display='none'; Codehighlighter1_11_80_Closed_Image.style.display='inline'; Codehighlighter1_11_80_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_11_80_Closed_Image onclick="this.style.display='none'; Codehighlighter1_11_80_Closed_Text.style.display='none'; Codehighlighter1_11_80_Open_Image.style.display='inline'; Codehighlighter1_11_80_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_11_80_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_11_80_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img id=Codehighlighter1_33_34_Open_Image onclick="this.style.display='none'; Codehighlighter1_33_34_Open_Text.style.display='none'; Codehighlighter1_33_34_Closed_Image.style.display='inline'; Codehighlighter1_33_34_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_33_34_Closed_Image onclick="this.style.display='none'; Codehighlighter1_33_34_Closed_Text.style.display='none'; Codehighlighter1_33_34_Open_Image.style.display='inline'; Codehighlighter1_33_34_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">Node(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_33_34_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_33_34_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_47_48_Open_Image onclick="this.style.display='none'; Codehighlighter1_47_48_Open_Text.style.display='none'; Codehighlighter1_47_48_Closed_Image.style.display='inline'; Codehighlighter1_47_48_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_47_48_Closed_Image onclick="this.style.display='none'; Codehighlighter1_47_48_Closed_Text.style.display='none'; Codehighlighter1_47_48_Open_Image.style.display='inline'; Codehighlighter1_47_48_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Node(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_47_48_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_47_48_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;IsLeafNode()</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;InternalNode:</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;Node<br><img id=Codehighlighter1_114_212_Open_Image onclick="this.style.display='none'; Codehighlighter1_114_212_Open_Text.style.display='none'; Codehighlighter1_114_212_Closed_Image.style.display='inline'; Codehighlighter1_114_212_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_114_212_Closed_Image onclick="this.style.display='none'; Codehighlighter1_114_212_Closed_Text.style.display='none'; Codehighlighter1_114_212_Open_Image.style.display='inline'; Codehighlighter1_114_212_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_114_212_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_114_212_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img id=Codehighlighter1_138_139_Open_Image onclick="this.style.display='none'; Codehighlighter1_138_139_Open_Text.style.display='none'; Codehighlighter1_138_139_Closed_Image.style.display='inline'; Codehighlighter1_138_139_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_138_139_Closed_Image onclick="this.style.display='none'; Codehighlighter1_138_139_Closed_Text.style.display='none'; Codehighlighter1_138_139_Open_Image.style.display='inline'; Codehighlighter1_138_139_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">InternalNode()</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_138_139_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_138_139_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_168_169_Open_Image onclick="this.style.display='none'; Codehighlighter1_168_169_Open_Text.style.display='none'; Codehighlighter1_168_169_Closed_Image.style.display='inline'; Codehighlighter1_168_169_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_168_169_Closed_Image onclick="this.style.display='none'; Codehighlighter1_168_169_Closed_Text.style.display='none'; Codehighlighter1_168_169_Open_Image.style.display='inline'; Codehighlighter1_168_169_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">InternalNode(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_168_169_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_168_169_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_196_210_Open_Image onclick="this.style.display='none'; Codehighlighter1_196_210_Open_Text.style.display='none'; Codehighlighter1_196_210_Closed_Image.style.display='inline'; Codehighlighter1_196_210_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_196_210_Closed_Image onclick="this.style.display='none'; Codehighlighter1_196_210_Closed_Text.style.display='none'; Codehighlighter1_196_210_Open_Image.style.display='inline'; Codehighlighter1_196_210_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;IsLeafNode()</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_196_210_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_196_210_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;LeafNode:</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;Node<br><img id=Codehighlighter1_243_328_Open_Image onclick="this.style.display='none'; Codehighlighter1_243_328_Open_Text.style.display='none'; Codehighlighter1_243_328_Closed_Image.style.display='inline'; Codehighlighter1_243_328_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_243_328_Closed_Image onclick="this.style.display='none'; Codehighlighter1_243_328_Closed_Text.style.display='none'; Codehighlighter1_243_328_Open_Image.style.display='inline'; Codehighlighter1_243_328_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_243_328_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_243_328_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img id=Codehighlighter1_263_264_Open_Image onclick="this.style.display='none'; Codehighlighter1_263_264_Open_Text.style.display='none'; Codehighlighter1_263_264_Closed_Image.style.display='inline'; Codehighlighter1_263_264_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_263_264_Closed_Image onclick="this.style.display='none'; Codehighlighter1_263_264_Closed_Text.style.display='none'; Codehighlighter1_263_264_Open_Image.style.display='inline'; Codehighlighter1_263_264_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">LeafNode()</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_263_264_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_263_264_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_285_286_Open_Image onclick="this.style.display='none'; Codehighlighter1_285_286_Open_Text.style.display='none'; Codehighlighter1_285_286_Closed_Image.style.display='inline'; Codehighlighter1_285_286_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_285_286_Closed_Image onclick="this.style.display='none'; Codehighlighter1_285_286_Closed_Text.style.display='none'; Codehighlighter1_285_286_Open_Image.style.display='inline'; Codehighlighter1_285_286_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">LeafNode()</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_285_286_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_285_286_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_313_326_Open_Image onclick="this.style.display='none'; Codehighlighter1_313_326_Open_Text.style.display='none'; Codehighlighter1_313_326_Closed_Image.style.display='inline'; Codehighlighter1_313_326_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_313_326_Closed_Image onclick="this.style.display='none'; Codehighlighter1_313_326_Closed_Text.style.display='none'; Codehighlighter1_313_326_Open_Image.style.display='inline'; Codehighlighter1_313_326_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;IsLeafNode()</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_313_326_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_313_326_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
定义以上的继承结构：LeafNode和InternalNode继承自Node<br>有一个虚方法IsLeaf来判断是否为叶子节点。<br>下面有这样的测试代码：<br>test()<br>{<br>&nbsp;&nbsp;&nbsp;Node *node = new InternalNode();<br>&nbsp;&nbsp;&nbsp;memset(node,0,sizeof(InternalNode));<br>&nbsp;&nbsp; node-&gt;IsLeafNode();<br>}<br>上述代码编译正常，而运行时出错！<br>出现上述问题的原因是：<br>对于有虚函数的类，每一个类有一个虚函数表，而每一个对象中会有一个指针指向这个虚函数表。<br>当&nbsp;&nbsp;&nbsp;Node *node = new InternalNode();时编译器会把一个指针知道InternalNode的虚函数表<br>但是memset(node,0,sizeof(InternalNode));却把这个指针设成了。<br>所以在调用的时候出现了运行时错误！<br>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/141792.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-03-14 15:46 <a href="http://www.cppblog.com/xyjzsh/archive/2011/03/14/141792.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用位</title><link>http://www.cppblog.com/xyjzsh/archive/2011/01/04/137947.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Tue, 04 Jan 2011 06:15:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2011/01/04/137947.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/137947.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2011/01/04/137947.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/137947.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/137947.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">windows.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span>&nbsp;<span style="COLOR: #000000">#pragma&nbsp;pack(push,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">&nbsp;3</span>&nbsp;<span style="COLOR: #000000">typedef&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;tagBite<br></span><span style="COLOR: #008080">&nbsp;4</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;5</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UINT&nbsp;&nbsp;&nbsp;&nbsp;bite3:</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;6</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UINT&nbsp;&nbsp;&nbsp;&nbsp;bite2:</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;7</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UINT&nbsp;&nbsp;&nbsp;&nbsp;bite1:</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;8</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UINT&nbsp;&nbsp;&nbsp;&nbsp;bite0:</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;9</span>&nbsp;<span style="COLOR: #000000">}HBITE,</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">PHBITE;<br></span><span style="COLOR: #008080">10</span>&nbsp;<span style="COLOR: #000000">typedef&nbsp;&nbsp;&nbsp;&nbsp;union&nbsp;&nbsp;&nbsp;&nbsp;tagDData<br></span><span style="COLOR: #008080">11</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">12</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;&nbsp;&nbsp;&nbsp;dword;<br></span><span style="COLOR: #008080">13</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;BYTE&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">14</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;HBITE&nbsp;&nbsp;&nbsp;&nbsp;bite;<br></span><span style="COLOR: #008080">15</span>&nbsp;<span style="COLOR: #000000">}DDATA,</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">PDDATA;<br></span><span style="COLOR: #008080">16</span>&nbsp;<span style="COLOR: #000000">#pragma&nbsp;pack(pop)</span></div>
测试<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;testBite()<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img id=Codehighlighter1_16_322_Open_Image onclick="this.style.display='none'; Codehighlighter1_16_322_Open_Text.style.display='none'; Codehighlighter1_16_322_Closed_Image.style.display='inline'; Codehighlighter1_16_322_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_16_322_Closed_Image onclick="this.style.display='none'; Codehighlighter1_16_322_Closed_Text.style.display='none'; Codehighlighter1_16_322_Open_Image.style.display='inline'; Codehighlighter1_16_322_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_16_322_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_16_322_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;PHBITE&nbsp;pHbite&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;HBITE;<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pHbite</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">bite0&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pHbite</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">bite1&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pHbite</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">bite2&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pHbite</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">bite3&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;UINT&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pData&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(UINT</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)pHbite;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">data=%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pData);<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;HBITE&nbsp;hBite;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;UINT&nbsp;uData</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;memcpy(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">hBite,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">uData,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(uData));<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">hBite.bite3=%d,hBite.bite2=%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,hBite.bite3,hBite.bite2);<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/137947.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2011-01-04 14:15 <a href="http://www.cppblog.com/xyjzsh/archive/2011/01/04/137947.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>适合于网络传输的一种数据结构</title><link>http://www.cppblog.com/xyjzsh/archive/2010/12/21/137103.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Tue, 21 Dec 2010 02:45:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2010/12/21/137103.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/137103.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2010/12/21/137103.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/137103.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/137103.html</trackback:ping><description><![CDATA[在网络传输中要传输的数据往往是不定长的，一般我们可以分配足够的空间，使用某个字段用于记录传输的数据的长度。然后对数据压缩后再进行传输。<br><br>定义数据结构<br>typedef struct tagTransferData<br>{<br>&nbsp;&nbsp;&nbsp;///一些其他信息////<br>&nbsp;&nbsp;&nbsp;DWORD dataSize;<br>&nbsp;&nbsp;&nbsp;char buffer[1];//定义一个可变长度的数组<br>}Data,*PData;<br>使用：<br>PData pData = (PData)malloc(10000);<br>memset(pData,0,10000);<br>。。。。。。。。。<br>char sendData[]="good morning everyone!";<br>strcpy(pData-&gt;buffer,send<em>Data</em>);<br>pData-&gt;dataSizse = strlen(sendData);<br>。。。。。。。。。<br>delete pData;<br><br>该数据结构:对于一块内存，开始记录了后面要传输数据的大小，紧接着是要传输的数据。是的数据比较紧凑，易于管理。<br>个人认为:分配的多余的空间使用数据压缩后，不会导致传输太多的无用数据。<br><br>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/137103.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2010-12-21 10:45 <a href="http://www.cppblog.com/xyjzsh/archive/2010/12/21/137103.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>指向类成员对象的指针</title><link>http://www.cppblog.com/xyjzsh/archive/2010/12/15/136485.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Wed, 15 Dec 2010 06:00:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2010/12/15/136485.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/136485.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2010/12/15/136485.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/136485.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/136485.html</trackback:ping><description><![CDATA[定义:<br>class Shape<br>{<br>public:<br>//...<br>void moveTo(Point newLocation);<br>bool validate()const;<br>vritual bool draw() const=0;<br>//...<br>}:<br>class Circle: public Shape<br>{<br>//...<br>bool draw() const;<br>//...<br>};<br><br>void (Shape::*mf1)(Point ) = &amp;Shape::moveTo;//指向类的成员函数的指针。<br><br>ReturnType (ClassName::*pFuncName)(paramList);<br>pFuncName定义了指向ClassName中的一组函数。这组函数的形式是返回值为ReturnType，函数列表为paramList.<br><br>ClassName的限定使得只有ClassName或派生自它的类的对象才能解引用这个函数指针。<br><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;&nbsp;1</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">stdafx.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;&nbsp;2</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;&nbsp;3</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdlib.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;&nbsp;4</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;&nbsp;5</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Base;<br></span><span style="COLOR: #008080">&nbsp;&nbsp;6</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Derived;<br></span><span style="COLOR: #008080">&nbsp;&nbsp;7</span>&nbsp;<span style="COLOR: #000000">typedef&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;(Base::</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">PFunc)(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;&nbsp;8</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;&nbsp;9</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">enum</span><span style="COLOR: #000000">&nbsp;FuncType<br></span><span style="COLOR: #008080">&nbsp;10</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;11</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;ADD</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,<br></span><span style="COLOR: #008080">&nbsp;12</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;SUB,<br></span><span style="COLOR: #008080">&nbsp;13</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;DIV,<br></span><span style="COLOR: #008080">&nbsp;14</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;MUL,<br></span><span style="COLOR: #008080">&nbsp;15</span>&nbsp;<span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">&nbsp;16</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;17</span>&nbsp;<span style="COLOR: #000000">typedef&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;tagCallBackFunc<br></span><span style="COLOR: #008080">&nbsp;18</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;19</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;funcType;<br></span><span style="COLOR: #008080">&nbsp;20</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;PFunc&nbsp;proc;<br></span><span style="COLOR: #008080">&nbsp;21</span>&nbsp;<span style="COLOR: #000000">}COMMAND,</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">PCOMMAND;<br></span><span style="COLOR: #008080">&nbsp;22</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;23</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Base<br></span><span style="COLOR: #008080">&nbsp;24</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;25</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #008080">&nbsp;26</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;27</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;PCOMMAND&nbsp;GetCommands(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;28</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;COMMAND&nbsp;command[];<br></span><span style="COLOR: #008080">&nbsp;29</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;30</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;base_add(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;base_add()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;31</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;base_sub(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;base_sub()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;32</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;base_div(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;base_div()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;33</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;base_mul(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;base_mul()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;34</span>&nbsp;<span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">&nbsp;35</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;36</span>&nbsp;<span style="COLOR: #000000">COMMAND&nbsp;Base::command[]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;37</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ADD,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Base::base_add},<br></span><span style="COLOR: #008080">&nbsp;38</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{SUB,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Base::base_sub},<br></span><span style="COLOR: #008080">&nbsp;39</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{MUL,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Base::base_mul},<br></span><span style="COLOR: #008080">&nbsp;40</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{DIV,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Base::base_div},<br></span><span style="COLOR: #008080">&nbsp;41</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br></span><span style="COLOR: #008080">&nbsp;42</span>&nbsp;<span style="COLOR: #000000">PCOMMAND&nbsp;Base::GetCommands()<br></span><span style="COLOR: #008080">&nbsp;43</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;44</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;command;<br></span><span style="COLOR: #008080">&nbsp;45</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">&nbsp;46</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;47</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Derived:</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;Base<br></span><span style="COLOR: #008080">&nbsp;48</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;49</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #008080">&nbsp;50</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Derived(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">){}<br></span><span style="COLOR: #008080">&nbsp;51</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Derived(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">){}<br></span><span style="COLOR: #008080">&nbsp;52</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;PCOMMAND&nbsp;GetCommands(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;command;}<br></span><span style="COLOR: #008080">&nbsp;53</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;54</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;add(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;add()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;55</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;sub(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;sub()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;56</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;div(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;div()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;57</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;mul(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b){printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">in&nbsp;mul()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b;}<br></span><span style="COLOR: #008080">&nbsp;58</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;59</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;COMMAND&nbsp;command[];<br></span><span style="COLOR: #008080">&nbsp;60</span>&nbsp;<span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">&nbsp;61</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;62</span>&nbsp;<span style="COLOR: #000000">COMMAND&nbsp;Derived::command[]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;63</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">&nbsp;64</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ADD,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Derived::add},<br></span><span style="COLOR: #008080">&nbsp;65</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{SUB,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Derived::sub},<br></span><span style="COLOR: #008080">&nbsp;66</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{MUL,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Derived::mul},<br></span><span style="COLOR: #008080">&nbsp;67</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{DIV,(PFunc)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">Derived::div},<br></span><span style="COLOR: #008080">&nbsp;68</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">&nbsp;69</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">&nbsp;70</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;71</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;72</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;73</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;&nbsp;test(Base&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">control,FuncType&nbsp;funcType,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;operand1,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;operand2)<br></span><span style="COLOR: #008080">&nbsp;74</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;75</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;PCOMMAND&nbsp;pCommand&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;control</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetCommands();<br></span><span style="COLOR: #008080">&nbsp;76</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;PCOMMAND&nbsp;pNowCommand</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">NULL;<br></span><span style="COLOR: #008080">&nbsp;77</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;78</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;pCommand[i].funcType;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)<br></span><span style="COLOR: #008080">&nbsp;79</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">&nbsp;80</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(funcType&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;pCommand[i].funcType)<br></span><span style="COLOR: #008080">&nbsp;81</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">&nbsp;82</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pNowCommand&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pCommand[i];&nbsp;<br></span><span style="COLOR: #008080">&nbsp;83</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;84</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">&nbsp;85</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">&nbsp;86</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;87</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(pNowCommand)<br></span><span style="COLOR: #008080">&nbsp;88</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">&nbsp;89</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;res&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(control</span><span style="COLOR: #000000">-&gt;*</span><span style="COLOR: #000000">pNowCommand</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">proc)(operand1,operand2);<br></span><span style="COLOR: #008080">&nbsp;90</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">res=%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,res);<br></span><span style="COLOR: #008080">&nbsp;91</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">&nbsp;92</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">&nbsp;93</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;94</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">&nbsp;95</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;96</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Derived&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">d&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Derived();<br></span><span style="COLOR: #008080">&nbsp;97</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Base&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(Base</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)d;<br></span><span style="COLOR: #008080">&nbsp;98</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;test(b,ADD,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;99</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">100</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Base&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">bb&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Base;<br></span><span style="COLOR: #008080">101</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;test(bb,MUL,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">102</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;bb;<br></span><span style="COLOR: #008080">103</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;d;<br></span><span style="COLOR: #008080">104</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">105</span>&nbsp;<span style="COLOR: #000000">}</span></div>
<br>第89行是对指向类成员函数的指针的解析。 
<img src ="http://www.cppblog.com/xyjzsh/aggbug/136485.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2010-12-15 14:00 <a href="http://www.cppblog.com/xyjzsh/archive/2010/12/15/136485.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数组、函数指针问题</title><link>http://www.cppblog.com/xyjzsh/archive/2010/12/15/136473.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Wed, 15 Dec 2010 03:39:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2010/12/15/136473.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/136473.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2010/12/15/136473.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/136473.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/136473.html</trackback:ping><description><![CDATA[<p>首先说一下数组指针和函数指针的定义问题。<br>一条重要的规则：<span style="COLOR: red">函数和数组修饰符的优先级比指针修饰符的优先级高</span><span style="COLOR: red">。函数的修饰符为()、数组的修饰符为[]、指针的修饰符为*。<br></span>eg:<br>int *A[N]: 等价于(int*)(A[N])：A[N]表示有N个元素的数组。元素类型为int*<br>int (*A)[N]：因为有括号提高了*的优先级。所以等价于int ((*A)[N])。表示A是一个指针。A指向的是含有N个元素的数组。数组中存放的元素为int型。<br><br><br>对于指向函数的指针。<br>int (*afp2[N])(); afp2[N]表示afp2是个含有N个元素的数组。数组中的元素为指向返回值为int、无参数的函数指针。<br>因为函数的声明较为复杂。可以用typedef来使代码更加明确。<br>我们用typedef来改写上面的声明。<br>typedef int (*FP)();//定义FP为返回值为int、参数列表为空的函数的类型。<br>FP afp2[N];//含有N个元素的数组，返回值为FP。<br><br>将一个函数的地址初始化或赋值给一个指向函数的指针时，无需显示的取其地址。编译器知道隐式的取其地址。<br></p>
void*可以指向任意类型的数据。<br>不存在可以指向任意类型函数的通用指针。<br><br>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/136473.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2010-12-15 11:39 <a href="http://www.cppblog.com/xyjzsh/archive/2010/12/15/136473.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>支持任意个子女的一种树结构</title><link>http://www.cppblog.com/xyjzsh/archive/2010/12/03/135333.html</link><dc:creator> 呆人</dc:creator><author> 呆人</author><pubDate>Fri, 03 Dec 2010 02:20:00 GMT</pubDate><guid>http://www.cppblog.com/xyjzsh/archive/2010/12/03/135333.html</guid><wfw:comment>http://www.cppblog.com/xyjzsh/comments/135333.html</wfw:comment><comments>http://www.cppblog.com/xyjzsh/archive/2010/12/03/135333.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xyjzsh/comments/commentRss/135333.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xyjzsh/services/trackbacks/135333.html</trackback:ping><description><![CDATA[<span style="COLOR: red">对于任意含有n个节点的有根树仅用O(n)的空间。<br><br></span>是一种左孩子、有兄弟的表示。<br>每一个节点包含下列属性：<br>1.指向父节点的指针<br>2.left-child[x]指向节点x的最左孩子<br>3.right-sibling[x]指向节点x紧右边的兄弟。<br><br>
<img src ="http://www.cppblog.com/xyjzsh/aggbug/135333.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xyjzsh/" target="_blank"> 呆人</a> 2010-12-03 10:20 <a href="http://www.cppblog.com/xyjzsh/archive/2010/12/03/135333.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>