﻿<?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++博客-Apollo Fang's Blog</title><link>http://www.cppblog.com/scorpio/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:06:49 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:06:49 GMT</pubDate><ttl>60</ttl><item><title>VI十六进制模式正常模式切换</title><link>http://www.cppblog.com/scorpio/archive/2012/10/31/163776.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Wed, 31 Oct 2012 09:16:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2012/10/31/163776.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/163776.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2012/10/31/163776.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/163776.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/163776.html</trackback:ping><description><![CDATA[<span style="font-family: Courier; ">VIM显示十六进制的方法- %!xxd<br /></span><span style="font-family: Courier; ">VIM回复正常显示方法- %!xxd -r</span><img src ="http://www.cppblog.com/scorpio/aggbug/163776.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2012-10-31 17:16 <a href="http://www.cppblog.com/scorpio/archive/2012/10/31/163776.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RTMP协议 - Chunk</title><link>http://www.cppblog.com/scorpio/archive/2012/10/31/194128.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Wed, 31 Oct 2012 09:09:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2012/10/31/194128.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/194128.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2012/10/31/194128.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/194128.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/194128.html</trackback:ping><description><![CDATA[<p style="text-indent:21.0pt"><span style="font-family:新宋体">KEY : Message / Chunk / Stream</span></p>  <p style="text-indent:21.0pt"><span style="font-family: 新宋体; text-indent: 21pt; ">Rtmp中,一个Message通常是分割成多个Chunk进行传输的.每个Chunk通常包含有1~12个字节的头部(该部分与完整的协议不是十分符合).</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">因为</span><span style="font-family:新宋体">Rtmp是基于TCP协议的,所以在Rtmp传输过程中, Chunk头部会根据实际情况使用简化的头部(12字节的头部是完整的头部,8/4/1字节的头部是根据实际情况简化的).</span></p>  <p style="background:#D9D9D9"><span style="font-family:新宋体">一</span><span style="font-family:新宋体">. Chunk头部的简化规则</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="text-indent: 21pt; font-family: 新宋体; ">说明</span><span style="text-indent: 21pt; font-family: 新宋体; ">:以上的"------"为6bit的ChunkId</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">1 . 00------头部</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">在传输开始</span><span style="font-family:新宋体">,的第一个Chunk头部通常使用(00------)格式,包含完整的头部信息,依次包含:时间戳,Message长度,Message类型1B,StreamId1B. 这些信息在程序中是需要保留的.以便后面简化的头部,可根据该头部完善信息.</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">2 . 01------头部</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">当发送多个相关的</span><span style="font-family:新宋体">Message时,Chunk的头部通常使用(01------)开始, 后面追加StreamId,Message类型和Message长度三个字段,这些字段与前一个Chunk的信息保持一致.例如,当交错的发送Video/Audio Message,它们属于同一个StreamId,但其他字段都发生了变化.</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">3 . 10------头部</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">当由一个</span><span style="font-family:新宋体">Message拆分成的连续的两个Chunk的时间戳发生了变化时(尤其是Video/Audio Message),例如,一个Video Message中前一个Chunk和下一个Chunk的时间戳或时间戳增量不一致,后面的Chunk头部会以(10------)开始, 再追加一个3字节的时间戳字段即可.</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">4 . 11------头部</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">当一个</span><span style="font-family:新宋体">Message过长,需要由多个连续的Chunk进行发送时,Chunk的头部通常会以(11------)开始, 没有其他附加字段,所有相关字段与前一个Chunk保持一致.</span></p>  <p>&nbsp;</p>  <p style="background:#D9D9D9"><span style="font-family:新宋体">二</span><span style="font-family:新宋体">. 关于ChunkId和StreamId</span></p>  <p><br /></p>  <p style="text-indent:21.0pt;background:#D9D9D9"><span style="font-family:新宋体">1 . StreamId的使命</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">一个</span><span style="font-family:新宋体">StreamId通常用以完成某些特定的工作. 如使用Id为0的Stream来完成客户端和服务器的连接和控制,用Id为1的Stream来完成Stream的控制和播放等工作.</span></p>  <p style="text-indent:21.0pt;background:#D9D9D9"><span style="font-family:新宋体">2 . ChunkId的使命</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">一个</span><span style="font-family:新宋体">ChunkId通常会完成某个特定的工作. 比如说系统保留的ChunkId为2的就只是用于完成对Stream的控制. 在该通道上,服务器和客户端可以对Stream的具体属性进行设置和交互.如创建一个Stream,告知Stream结束,设定Stream的带宽,设定Chunk大小,终止Message等.这里对Stream的控制不是针对某个Stream的,而是全局的.</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">再比如</span><span style="font-family:新宋体">,使用ChunkId8对播放进行控制.客户端发送"play"命令,服务器也会通过ChunkId8这个通道告知客户端播放的状态,如告知客户端播放开始,播放完成等信息.服务器使用ChunkId5进行媒体数据的传送,如果客户端需要针对这些数据对服务器应答,也要使用该通道.</span></p>  <p style="text-indent:21.0pt;background:#D9D9D9"><span style="font-family:新宋体">3 . ChunkId和StreamId的关系</span></p>  <p style="text-indent:21.0pt"><span style="font-family:新宋体">ChunkId和StreamId的关系目前并不明了,但通常情况下某一个ChunkId会在固定的StreamId中完成相应的工作. 比如ChunkId2对Stream的相关属性进行控制,这些控制的消息必须在StreamId0中完成.也就是说ChunkId2和StreamId0指定了服务器和客户端对Stream控制的以个对话通道.</span></p><img src ="http://www.cppblog.com/scorpio/aggbug/194128.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2012-10-31 17:09 <a href="http://www.cppblog.com/scorpio/archive/2012/10/31/194128.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>文件模式</title><link>http://www.cppblog.com/scorpio/archive/2012/10/31/194099.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Wed, 31 Oct 2012 08:40:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2012/10/31/194099.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/194099.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2012/10/31/194099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/194099.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/194099.html</trackback:ping><description><![CDATA[<div>  <p>&nbsp;</p>  <p style="background:#B3B3B3"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文件</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;Courier New&quot;">C</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">将文件看做是连续字节序列</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">其中每个字节都可以单独读取</span><span style="font-family: &quot;Courier New&quot;">.</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">这个与</span><span style="font-family:&quot;Courier New&quot;">UNIX</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">环境中的文件结构是一致的</span><span style="font-family: &quot;Courier New&quot;">.</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">但</span><span style="font-family:&quot;Courier New&quot;">ANSI C</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">为了与其他的</span><span style="font-family:&quot;Courier New&quot;">OS</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">环境兼容</span><span style="font-family:&quot;Courier New&quot;">(</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">比如</span><span style="font-family:&quot;Courier New&quot;">Windows),</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">提供了两种文件视图</span><span style="font-family:&quot;Courier New&quot;">: </span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文本视图和二进制视图</span><span style="font-family: &quot;Courier New&quot;">.</span></p>  <p style="background:#B3B3B3"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文本视图和二进制视图</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">二进制视图中</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文件中的每个字节都可以为程序访问</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">但文本视图中</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序中看到的内容与文件的内容可能不同</span><span style="font-family:&quot;Courier New&quot;">.</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">例如</span><span style="font-family:&quot;Courier New&quot;">MS-DOS</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文本文件用</span><span style="font-family:&quot;Courier New&quot;">"\r\n"</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">来表示行尾</span><span style="font-family:&quot;Courier New&quot;">; Macintosh</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文本文件中用</span><span style="font-family:&quot;Courier New&quot;">"\r"</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">表示行尾</span><span style="font-family:&quot;Courier New&quot;">; C</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序使用</span><span style="font-family:&quot;Courier New&quot;">"\n"</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">表示行尾</span><span style="font-family:&quot;Courier New&quot;">. So,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">如果</span><span style="font-family:&quot;Courier New&quot;">C</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序以文本视图模式处理一个</span><span style="font-family: &quot;Courier New&quot;">MS-DOS</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文本文件</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">在读取文件时</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">就会将</span><span style="font-family:&quot;Courier New&quot;">"\r\n"</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">转换为</span><span style="font-family:&quot;Courier New&quot;">"\n",</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">在写入文件时</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">就会将</span><span style="font-family:&quot;Courier New&quot;">"\n"</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">转换为</span><span style="font-family:&quot;Courier New&quot;">"\r\n". Macintosh</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">同理</span><span style="font-family:&quot;Courier New&quot;">.</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">说白了</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">两种视图的实现是一样的</span><span style="font-family: &quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">只是在处理行尾或处理文件结尾时有点不同而已</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">采用某种视图打开文件时</span><span style="font-family: &quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">注意一下就是了</span><span style="font-family:&quot;Courier New&quot;">.</span></p>  <p style="background:#B3B3B3"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文件结尾和换行</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文件读取数据的程序需要在达到文件结尾时停止</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">当到达文件结尾时</span><span style="font-family: &quot;Courier New&quot;">,"getc()"</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">函数会返回一个特殊值</span><span style="font-family: &quot;Courier New&quot;">EOF.</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">所以</span><span style="font-family:&quot;Courier New&quot;">C</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序只有在读取超出文件结尾后</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">才会发现文件的结尾</span><span style="font-family: &quot;Courier New&quot;">.</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">为了避免读取空文件带来的问题</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">应该对文件输入使用入口条件循环</span><span style="font-family:&quot;Courier New&quot;">(</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">使用</span><span style="font-family:&quot;Courier New&quot;">while</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">或</span><span style="font-family:&quot;Courier New&quot;">for,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">避免使用</span><span style="font-family:&quot;Courier New&quot;">do...while)</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">如下设计</span><span style="font-family:&quot;Courier New&quot;">:<br /></span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff; font-family: Courier; ">int</span><span style="font-family: Courier; ">&nbsp;ch;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier; ">//</span><span style="color: #008000; font-family: Courier; ">&nbsp;Watching&nbsp;EOF</span><span style="color: #008000; "><br /></span><span style="font-family: Courier; ">FILE*&nbsp;fp;</span><br /><span style="font-family: Courier; ">fp&nbsp;=&nbsp;fopen&nbsp;("_FileName",&nbsp;"_Mode");</span><br /><span style="font-family: Courier; ">ch&nbsp;=&nbsp;getc&nbsp;(fp);</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier; ">while</span><span style="font-family: Courier; ">&nbsp;(ch&nbsp;!=&nbsp;EOF)</span><br /><span style="font-family: Courier; ">{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;putchar&nbsp;(ch);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;ch&nbsp;=&nbsp;getc&nbsp;(fp);</span><br /><span style="font-family: Courier; ">}</span></div></div><div>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">上面的例子可以看做是一个框架</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">来进行文件结尾的判断</span><span style="font-family: &quot;Courier New&quot;">.</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">但</span><span style="font-family:&quot;Courier New&quot;">ANSI C</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">的两种模式</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">对于文件结尾有不同的解释</span><span style="font-family: &quot;Courier New&quot;">.</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">如果文件以文本模式打开</span><span style="font-family:&quot;Courier New&quot;">,C</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">可以认出</span><span style="font-family:&quot;Courier New&quot;">EOF</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">标志文件结尾</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">如果以二进制模式打开</span><span style="font-family: &quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">就会把</span><span style="font-family:&quot;Courier New&quot;">EOF</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">当做是文件中的一个字符</span><span style="font-family: &quot;Courier New&quot;">.</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">真正的文件结尾还在后面</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">文件的结尾</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">可能紧跟着</span><span style="font-family:&quot;Courier New&quot;">EOF,</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">当然</span><span style="font-family:&quot;Courier New&quot;">,</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">也可能用空字符填充文件使其大小为</span><span style="font-family:&quot;Courier New&quot;">256(</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">或其他数</span><span style="font-family:&quot;Courier New&quot;">)</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">的倍数</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">在</span><span style="font-family:&quot;Courier New&quot;">DOS</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">下不打印空字符</span><span style="font-family:&quot;Courier New&quot;">.</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序中包含了防止程序打印</span><span style="font-family: &quot;Courier New&quot;">EOF</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">字符的代码</span><span style="font-family:&quot;Courier New&quot;">.</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;Courier New&quot;">MS-DOS</span><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">的文本文件用二进制模式和文本模式打开</span><span style="font-family:&quot;Courier New&quot;">,C</span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">程序将看到下面的内容</span><span style="font-family: &quot;Courier New&quot;">:</span></p>  <span style="font-size: 10pt; ">  </span><table border="1" cellspacing="0" cellpadding="0" style="margin-left: 5.4pt; border-collapse: collapse; border: none; "><tbody><tr>   <td width="352" valign="top" style="width: 263.65pt; border: 1pt solid windowtext; padding: 0in 5.4pt; ">   <p><span style="font-family: 宋体; font-size: 10pt; ">二进制模式打开文件</span><span style="font-family: 'Courier New'; font-size: 10pt; ">C</span><span style="font-family: 宋体; font-size: 10pt; ">程序看到的内容</span><span style="font-family: 'Courier New'; font-size: 10pt; ">:</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">line1\r\n</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">line2\r\n</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">line3\r\n</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">^Z</span></p>   </td>   <td width="350" valign="top" style="width: 262.85pt; border-style: solid solid solid none; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; padding: 0in 5.4pt; ">   <p><span style="font-family: 宋体; font-size: 10pt; ">文本模式打开文件</span><span style="font-family: 'Courier New'; font-size: 10pt; ">C</span><span style="font-family: 宋体; font-size: 10pt; ">程序看到的内容</span><span style="font-family: 'Courier New'; font-size: 10pt; ">:</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">line1\n</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">line2\n</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">line3\n</span></p>   <p><span style="font-family: 'Courier New'; font-size: 10pt; ">^Z</span></p></td></tr></tbody></table></div>  <p style="background:#B3B3B3"><span style="font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">例子</span><span style="font-family:&quot;Courier New&quot;"> : </span><span style="font-family: 宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;">逆序输出一个文件内容</span></p>  <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="font-family: Courier; ">#include&nbsp;</span><span style="font-family: Courier; ">&lt;</span><span style="font-family: Courier; ">stdio.h</span><span style="font-family: Courier; ">&gt;</span><br /><span style="font-family: Courier; ">#include&nbsp;</span><span style="font-family: Courier; ">&lt;</span><span style="font-family: Courier; ">stdlib.h</span><span style="font-family: Courier; ">&gt;</span><br /><span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;MAC</span><br /><span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;CNTL_Z&nbsp;'\032'&nbsp;/*&nbsp;DOS&nbsp;Text&nbsp;File&nbsp;End&nbsp;Of&nbsp;File&nbsp;Flag&nbsp;*/</span><br /><span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;SLEN&nbsp;&nbsp;&nbsp;50</span><br /><span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;PATH&nbsp;&nbsp;</span><br /><span style="color: #0000ff; font-family: Courier; ">int</span><span style="font-family: Courier; ">&nbsp;main&nbsp;(</span><span style="color: #0000ff; font-family: Courier; ">void</span><span style="font-family: Courier; ">)</span><br /><span style="font-family: Courier; ">{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">char</span><span style="font-family: Courier; ">&nbsp;file[SLEN];</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">char</span><span style="font-family: Courier; ">&nbsp;ch;</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;FILE</span><span style="font-family: Courier; ">*</span><span style="font-family: Courier; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Courier; ">fp;</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">long</span><span style="font-family: Courier; ">&nbsp;count;</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">long</span><span style="font-family: Courier; ">&nbsp;last;</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;(</span><span style="font-family: Courier; ">"</span><span style="font-family: Courier; ">Enter&nbsp;Name&nbsp;Of&nbsp;File&nbsp;To&nbsp;Be&nbsp;Processed&nbsp;:&nbsp;</span><span style="font-family: Courier; ">"</span><span style="font-family: Courier; ">);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;gets&nbsp;(file);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">&nbsp;((fp&nbsp;</span><span style="font-family: Courier; ">=</span><span style="font-family: Courier; ">&nbsp;fopen&nbsp;(file,&nbsp;</span><span style="font-family: Courier; ">"</span><span style="font-family: Courier; ">rb</span><span style="font-family: Courier; ">"</span><span style="font-family: Courier; ">))&nbsp;</span><span style="font-family: Courier; ">==</span><span style="font-family: Courier; ">&nbsp;NULL)</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(</span><span style="font-family: Courier; ">"</span><span style="font-family: Courier; ">Reverse&nbsp;Can't&nbsp;Open&nbsp;%s&nbsp;.\n</span><span style="font-family: Courier; ">"</span><span style="font-family: Courier; ">,&nbsp;file);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit&nbsp;(</span><span style="font-family: Courier; ">1</span><span style="font-family: Courier; ">);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;fseek&nbsp;(fp,&nbsp;</span><span style="font-family: Courier; ">0L</span><span style="font-family: Courier; ">,&nbsp;SEEK_END);&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier; ">/*</span><span style="color: #008000; font-family: Courier; ">&nbsp;Locate&nbsp;To&nbsp;End&nbsp;Of&nbsp;File&nbsp;</span><span style="color: #008000; font-family: Courier; ">*/</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;last&nbsp;</span><span style="font-family: Courier; ">=</span><span style="font-family: Courier; ">&nbsp;ftell&nbsp;(fp);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">for</span><span style="font-family: Courier; ">&nbsp;(count&nbsp;</span><span style="font-family: Courier; ">=</span>&nbsp;<span style="font-family: Courier; ">1L</span><span style="font-family: Courier; ">;&nbsp;count&nbsp;</span><span style="font-family: Courier; ">&lt;=</span><span style="font-family: Courier; ">&nbsp;last;&nbsp;count</span><span style="font-family: Courier; ">++</span><span style="font-family: Courier; ">)</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fseek&nbsp;(fp,&nbsp;</span><span style="font-family: Courier; ">-</span><span style="font-family: Courier; ">count,&nbsp;SEEK_END);&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier; ">/*</span><span style="color: #008000; font-family: Courier; ">&nbsp;Back&nbsp;1&nbsp;Byte&nbsp;</span><span style="color: #008000; font-family: Courier; ">*/</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch&nbsp;</span><span style="font-family: Courier; ">=</span><span style="font-family: Courier; ">&nbsp;getc&nbsp;(fp);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">&nbsp;(ch&nbsp;</span><span style="font-family: Courier; ">!=</span><span style="font-family: Courier; ">&nbsp;CNTL_Z&nbsp;</span><span style="font-family: Courier; ">&amp;&amp;</span><span style="font-family: Courier; ">&nbsp;ch&nbsp;</span><span style="font-family: Courier; ">!=</span>&nbsp;<span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">\r</span><span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">)</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar&nbsp;(ch);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="color: #0000ff; font-family: Courier; ">#if</span><span style="font-family: Courier; ">&nbsp;defined&nbsp;MAC&nbsp;||&nbsp;defined&nbsp;WIN32</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-family: Courier; ">/*</span><span style="color: #008000; font-family: Courier; ">&nbsp;Macintosh&nbsp;||&nbsp;Windows&nbsp;</span><span style="color: #008000; font-family: Courier; ">*/</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">&nbsp;(ch&nbsp;</span><span style="font-family: Courier; ">==</span>&nbsp;<span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">\r</span><span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">)</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar&nbsp;(</span><span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">\n</span><span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">else</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar&nbsp;(ch);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="color: #0000ff; font-family: Courier; ">#endif</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar&nbsp;(</span><span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">\n</span><span style="font-family: Courier; ">'</span><span style="font-family: Courier; ">);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fclose&nbsp;(fp);</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">return</span>&nbsp;<span style="font-family: Courier; ">0</span><span style="font-family: Courier; ">;</span><br /><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-family: Courier; ">}</span></div><br /><br /><br /><br /><img src ="http://www.cppblog.com/scorpio/aggbug/194099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2012-10-31 16:40 <a href="http://www.cppblog.com/scorpio/archive/2012/10/31/194099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>What is "##" string in C code</title><link>http://www.cppblog.com/scorpio/archive/2012/06/08/177471.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Fri, 08 Jun 2012 02:42:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2012/06/08/177471.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/177471.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2012/06/08/177471.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/177471.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/177471.html</trackback:ping><description><![CDATA[<div><span style="font-family: Georgia; ">See code below(</span><span style="font-family: Georgia; color: red; "><em>quoting ffmpeg source code</em></span><span style="font-family: 'Lucida Console'; ">)<br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; font-family: Courier; ">&nbsp;1</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;REGISTER_MUXER(X,x)&nbsp;{&nbsp;\</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;2</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">&nbsp; &nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">e</span><span style="color: #0000ff; font-family: Courier; ">xtern</span><span style="font-family: Courier; ">&nbsp;AVOutputFormat&nbsp;x##_muxer;&nbsp;\</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;3</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">&nbsp; &nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">i</span><span style="color: #0000ff; font-family: Courier; ">f</span><span style="font-family: Courier; ">(CONFIG_##X##_MUXER)&nbsp;av_register_output_format(</span><span style="font-family: Courier; ">&amp;</span><span style="font-family: Courier; ">x##_muxer);&nbsp;}</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;4</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;REGISTER_DEMUXER(X,x)&nbsp;{&nbsp;\</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;5</span>&nbsp;<span style="font-family: Courier; "> &nbsp; &nbsp;</span><span style="color: #0000ff; font-family: Courier; ">extern</span><span style="font-family: Courier; ">&nbsp;AVInputFormat&nbsp;x##_demuxer;&nbsp;\</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;6</span>&nbsp;<span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">(CONFIG_##X##_DEMUXER)&nbsp;av_register_input_format(</span><span style="font-family: Courier; ">&amp;</span><span style="font-family: Courier; ">x##_demuxer);&nbsp;}</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;7</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;REGISTER_MUXDEMUX(X,x)&nbsp;&nbsp;REGISTER_MUXER(X,x);&nbsp;REGISTER_DEMUXER(X,x)</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;8</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;REGISTER_PROTOCOL(X,x)&nbsp;{&nbsp;\</span><br /><span style="color: #008080; font-family: Courier; ">&nbsp;9</span>&nbsp;<span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">extern</span><span style="font-family: Courier; ">&nbsp;URLProtocol&nbsp;x##_protocol;&nbsp;\</span><br /><span style="color: #008080; font-family: Courier; ">10</span>&nbsp;<span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">(CONFIG_##X##_PROTOCOL)&nbsp;av_register_protocol2(</span><span style="font-family: Courier; ">&amp;</span><span style="font-family: Courier; ">x##_protocol,&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">sizeof</span><span style="font-family: Courier; ">(x##_protocol));&nbsp;}</span></div><span style="font-family: 'Lucida Console'; "><br /></span></div><div><span style="font-family: Georgia; ">"##" string in C language code is used for </span><span style="font-family: Georgia; color: red; "><em><u>concatenating the two strings</u></em></span><span style="font-family: Georgia; color: red; "><em><u>&nbsp;which is before and behind it &nbsp;in a macros definition.</u></em></span><br /><span style="font-family: Georgia; ">See a test code below :</span><div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; font-family: Courier; ">1</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;DEFINE(t,&nbsp;x)&nbsp;&nbsp;{t&nbsp;x##_##t;}</span><font color="#008080" face="Courier"><br /></font><span style="color: #008080; font-family: Courier; ">3</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">int</span><span style="font-family: Courier; ">&nbsp;main()</span><br /><span style="color: #008080; font-family: Courier; ">4</span>&nbsp;<span style="font-family: Courier; ">{</span><br /><span style="color: #008080; font-family: Courier; ">5</span>&nbsp;<span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;DEFINE(</span><span style="color: #0000ff; font-family: Courier; ">int</span><span style="font-family: Courier; ">,&nbsp;vvv);</span><br /><span style="color: #008080; font-family: Courier; ">6</span>&nbsp;<span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">return</span>&nbsp;<span style="font-family: Courier; ">0</span><span style="font-family: Courier; ">;</span><br /><span style="color: #008080; font-family: Courier; ">7</span>&nbsp;<span style="font-family: Courier; ">}</span><font color="#008080"><br /></font></div></div><span style="font-family: 'Lucida Console'; "><br /></span><span style="font-family: Georgia; ">Use "</span><span style="font-family: Georgia; font-size: 12pt; color: red; "><u><em>gcc -E test_sharpsharp.c -o test_sharpsharp.i</em></u></span><span style="font-family: Georgia; ">" command to pre-process this file<br /></span><font face="Georgia">And the output file "test_sharpsharp.i" just looks like below :</font><font color="#008080" face="Courier" size="2"><br /></font><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; font-family: Courier; ">1</span>&nbsp;<span style="color: #0000ff; font-family: Courier; ">int</span><span style="font-family: Courier; ">&nbsp;main()</span><br /><span style="color: #008080; font-family: Courier; ">2</span>&nbsp;<span style="font-family: Courier; ">{</span><br /><span style="color: #008080; font-family: Courier; ">3</span>&nbsp;<span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;{</span><span style="color: #0000ff; font-family: Courier; ">int</span><span style="font-family: Courier; ">&nbsp;vvv_int;};</span><br /><span style="color: #008080; font-family: Courier; ">4</span>&nbsp;<span style="font-family: Courier; "> &nbsp; &nbsp;</span><span style="color: #0000ff; font-family: Courier; ">return</span>&nbsp;<span style="font-family: Courier; ">0</span><span style="font-family: Courier; ">;</span><br /><span style="color: #008080; font-family: Courier; ">5</span>&nbsp;<span style="font-family: Courier; ">}</span></div><span style="font-family: Georgia; "><br />The code below is useful, and you can use "##" macro definitions to realize sample <em><u>templates</u></em>&nbsp;with C language<br /></span><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; font-family: Courier; ">1</span><span style="font-family: Courier; ">&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">#define</span><span style="font-family: Courier; ">&nbsp;REGISTER_DATA_COMPARE(x)\</span><br /><span style="color: #008080; font-family: Courier; ">2</span><span style="font-family: Courier; ">&nbsp;</span><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">static</span><span style="font-family: Courier; ">&nbsp;</span><span style="font-family: Courier; color: #0000ff; ">__inline&nbsp;</span><span style="font-family: Courier; ">x&nbsp;x##_compare(x&nbsp;key1,&nbsp;x&nbsp;key2)\</span><br /><span style="color: #008080; font-family: Courier; ">3</span><span style="font-family: Courier; ">&nbsp;</span><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Courier; ">{\</span><br /><span style="color: #008080; font-family: Courier; ">4</span><span style="font-family: Courier; ">&nbsp;</span><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">&nbsp;(key1&nbsp;</span><span style="font-family: Courier; ">&gt;</span><span style="font-family: Courier; ">&nbsp;key2)&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">return</span>&nbsp;<span style="font-family: Courier; ">1</span><span style="font-family: Courier; ">;\</span><br /><span style="color: #008080; font-family: Courier; ">5</span><span style="font-family: Courier; ">&nbsp;</span><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">if</span><span style="font-family: Courier; ">&nbsp;(key1&nbsp;</span><span style="font-family: Courier; ">&lt;</span><span style="font-family: Courier; ">&nbsp;key2)&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">return</span>&nbsp;<span style="font-family: Courier; ">-</span><span style="font-family: Courier; ">1</span><span style="font-family: Courier; ">;\</span><br /><span style="color: #008080; font-family: Courier; ">6</span><span style="font-family: Courier; ">&nbsp;</span><span style="color: #0000ff; font-family: Courier; ">&nbsp; &nbsp; &nbsp; &nbsp; return</span>&nbsp;<span style="font-family: Courier; ">0</span><span style="font-family: Courier; ">;\</span><br /><span style="color: #008080; font-family: Courier; ">7</span><span style="font-family: Courier; ">&nbsp;</span><span style="font-family: Courier; ">&nbsp;&nbsp;&nbsp;&nbsp;}</span></div><span style="font-family: Georgia; ">In this way, you can realize a data comparing function set, when you need comparing some type of data, just register it.</span></div><img src ="http://www.cppblog.com/scorpio/aggbug/177471.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2012-06-08 10:42 <a href="http://www.cppblog.com/scorpio/archive/2012/06/08/177471.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>互斥锁的初始化</title><link>http://www.cppblog.com/scorpio/archive/2012/04/16/171617.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Mon, 16 Apr 2012 05:53:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2012/04/16/171617.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/171617.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2012/04/16/171617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/171617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/171617.html</trackback:ping><description><![CDATA[<p style="text-align: justify; ">
</p>
<p><span style="font-size:11.0pt;font-family:宋体;">互斥锁的初始化</span></p>
<p>&nbsp;</p>
<p><span style="font-size:11.0pt;font-family:宋体;">接口</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">1&gt; </span><span style="font-size:11.0pt; font-family:宋体;">初始化互斥锁</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas;color:#0070C0">int </span><span style="font-size:11.0pt; font-family:Consolas;color:#C00000">pthread_mutexattr_init</span><span style="font-size:11.0pt;font-family:Consolas">(<span style="color:#0070C0">pthread_mutexattr_t</span> *attr);</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">2&gt; </span><span style="font-size:11.0pt; font-family:宋体;">销毁互斥锁</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas;color:#0070C0">int</span><span style="font-size:11.0pt; font-family:Consolas"> <span style="color:#C00000">pthread_mutexattr_destroy</span>(<span style="color:#0070C0">pthread_mutexattr_t</span> *attr);</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">3&gt; </span><span style="font-size:11.0pt; font-family:宋体;">设置互斥锁类型</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas;color:#0070C0">int</span><span style="font-size:11.0pt; font-family:Consolas"> <span style="color:#C00000">pthread_mutexattr_settype</span>(<span style="color:#0070C0">pthread_mutexattr_t</span> *attr, <span style="color: #0070C0">int</span> kind);</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">4&gt; </span><span style="font-size:11.0pt; font-family:宋体;">获取互斥锁类型</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas;color:#0070C0">int</span><span style="font-size:11.0pt; font-family:Consolas"> <span style="color:#C00000">pthread_mutexattr_gettype</span>(<span style="color:#0070C0">const pthread_mutexattr_t</span> *attr, <span style="color:#0070C0">int</span> *kind);</span></p>
<p>&nbsp;</p>
<p><span style="font-size:11.0pt;font-family:宋体;">互斥锁类型</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">1. <span style="color:#FF33CC">PTHREAD_MUTEX_TIMED_NP</span></span></p>
<p><span style="font-size:11.0pt;font-family:宋体;">缺省值</span><span style="font-size:11.0pt; font-family:Consolas">; </span><span style="font-size:11.0pt; font-family:宋体;">当一个线程加锁之后</span><span style="font-size:11.0pt;font-family:Consolas">, </span><span style="font-size:11.0pt;font-family:宋体;">其余请求的线程将形成一个等待队列</span><span style="font-size:11.0pt;font-family:Consolas">, </span><span style="font-size:11.0pt;font-family:宋体;">并在解锁后按照优先级获取锁</span><span style="font-size:11.0pt;font-family:Consolas">. </span><span style="font-size:11.0pt;font-family:宋体;">这种机制保证了资源分配的公平性</span><span style="font-size:11.0pt;font-family:Consolas">.</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">2. <span style="color:#FF33CC">PTHREAD_MUTEX_RECURSIVE_NP</span></span></p>
<p><span style="font-size:11.0pt;font-family:宋体;">嵌套锁</span><span style="font-size:11.0pt; font-family:Consolas">; </span><span style="font-size:11.0pt; font-family:宋体;">允许<u>同一个线程</u>对同一个锁成功获得多次</span><span style="font-size:11.0pt; font-family:Consolas">, </span><span style="font-size:11.0pt; font-family:宋体;">并通过同样次数的解锁操作释放锁</span><span style="font-size:11.0pt;font-family:Consolas">. </span><span style="font-size:11.0pt;font-family:宋体;">如果是不同线程请求</span><span style="font-size:11.0pt;font-family:Consolas">, </span><span style="font-size:11.0pt;font-family:宋体;">则在加锁线程释放锁时重新竞争</span><span style="font-size:11.0pt;font-family:Consolas">.</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">3. <span style="color:#FF33CC">PTHREAD_MUTEX_ERRORCHECK_NP</span></span></p>
<p><span style="font-size:11.0pt;font-family:宋体;">检错锁</span><span style="font-size:11.0pt; font-family:Consolas">; </span><span style="font-size:11.0pt; font-family:宋体;">如果同一个线程请求同一个锁</span><span style="font-size:11.0pt;font-family:Consolas">, </span><span style="font-size:11.0pt;font-family:宋体;">返回</span><span style="font-size:11.0pt;font-family:Consolas">EDEADLK, </span><span style="font-size:11.0pt;font-family:宋体;">否则与缺省相同</span><span style="font-size: 11.0pt;font-family:Consolas">; </span><span style="font-size:11.0pt; font-family:宋体;">这种机制避免了多次加锁产生死锁的情况</span><span style="font-size:11.0pt;font-family: Consolas">.</span></p>
<p><span style="font-size:11.0pt; font-family:Consolas">4. <span style="color:#FF33CC">PTHREAD_MUTEX_ADAPTIVE_NP</span></span></p>
<p><span style="font-size:11.0pt;font-family:宋体;">适应锁</span><span style="font-size:11.0pt; font-family:Consolas">; </span><span style="font-size:11.0pt; font-family:宋体;">仅仅等待解锁后重新竞争</span><span style="font-size:11.0pt;font-family:Consolas">.</span></p>
<p>&nbsp;</p>
<img src ="http://www.cppblog.com/scorpio/aggbug/171617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2012-04-16 13:53 <a href="http://www.cppblog.com/scorpio/archive/2012/04/16/171617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>KMP(1)--KMP算法解析</title><link>http://www.cppblog.com/scorpio/archive/2012/01/07/162295.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Sat, 07 Jan 2012 06:35:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2012/01/07/162295.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/162295.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2012/01/07/162295.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/162295.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/162295.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: KMP(1)--KMP算法解析1.&nbsp;普通字符串匹配BF算法假设S串为原始串,&nbsp;T串为目标串.&nbsp;且S串匹配到i位置,&nbsp;T串匹配到j位置.在BF算法中,&nbsp;如果当前字符匹配成功,&nbsp;(即S[i+j]&nbsp;==&nbsp;T[j])&nbsp;令j++,&nbsp;继续匹配下一个字符;&nbsp;如果失配,&nbsp;(即S[i+j]&nbs...&nbsp;&nbsp;<a href='http://www.cppblog.com/scorpio/archive/2012/01/07/162295.html'>阅读全文</a><img src ="http://www.cppblog.com/scorpio/aggbug/162295.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2012-01-07 14:35 <a href="http://www.cppblog.com/scorpio/archive/2012/01/07/162295.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How to update or install pthread manual reference on Linux</title><link>http://www.cppblog.com/scorpio/archive/2011/10/27/159215.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Thu, 27 Oct 2011 05:28:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2011/10/27/159215.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/159215.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2011/10/27/159215.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/159215.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/159215.html</trackback:ping><description><![CDATA[<span style="font-family: 'Lucida Console'; ">&nbsp; &nbsp; If you want to install the manual reference about pthread, execute the following command:<br />
&nbsp; &nbsp;&nbsp;<br />
</span><span style="font-family: 'Lucida Console'; color: #ff0000; ">&nbsp; &nbsp; sudo apt-get install glibc-doc<br />
</span><span style="font-family: 'Lucida Console'; color: #ff0000; ">&nbsp; &nbsp; sudo apt-get install manpages-posix-dev</span><span style="font-family: 'Lucida Console'; color: #ff0000; "><br />
</span>
<div class="vimiumHUD" style="right: 150px; opacity: 0; display: none; "></div><img src ="http://www.cppblog.com/scorpio/aggbug/159215.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2011-10-27 13:28 <a href="http://www.cppblog.com/scorpio/archive/2011/10/27/159215.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>About C/C++ Data Type</title><link>http://www.cppblog.com/scorpio/archive/2011/10/25/159060.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Tue, 25 Oct 2011 09:28:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2011/10/25/159060.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/159060.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2011/10/25/159060.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/159060.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/159060.html</trackback:ping><description><![CDATA[<div><span style="font-size: 11pt; font-family: 'Lucida Console'; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; background-color: transparent; "> &nbsp;&nbsp;&nbsp;1) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> Integer</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;2) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int*</span>&nbsp;&nbsp;<span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">A pointer point to an Integer</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;3) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int**</span><span style="font-size: 11pt; font-family: Consolas; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span style="white-space: pre; ">&nbsp;</span></span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">A pointer point to a pointer what point to an Integer</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;4) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int* arr[N]</span><span style="font-size: 11pt; font-family: Consolas; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span style="white-space: pre; ">&nbsp;</span></span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">An array that each element is a pointer point to an Integer</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;5) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int(*arr)[N]</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> A pointer point to an array that its each element is an I</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">nteger and it have N elements.</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;6) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int (*fun)(int)</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> A pointer point to a function what with an integer parameter a</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">nd with an integer returning.</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;7) </span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">int (*fun[N])(int)</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> An array that have N elements and each element is a pointer p</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">oint to a point that point to a type of function that have an</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> integer parameter and with an integer returning.</span><br /><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;Maybe understand (4) type just like this :</span><br /><span style="font-size: 11pt; font-family: Consolas; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; vertical-align: baseline; white-space: pre-wrap; "><u>int*[N]</u> arr;<br />    It means "arr"'s type is int*[]. And how to catch the meaning of <u>int*[]</u>? At first it's an array, and each element of this array is a pointer point to an integer.<br /></span><span style="font-size: 11pt; font-family: 'Lucida Console'; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; background-color: transparent; "> &nbsp;&nbsp;&nbsp;And can understand (5) type just like this :<br /></span><span style="font-size: 11pt; font-family: 'Lucida Console'; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; background-color: transparent; ">    int[N]* arr;<br /></span><span style="font-size: 11pt; font-family: 'Lucida Console'; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; background-color: transparent; ">    It means "arr"'s type is int[]*. That's to show that this type is a pointer and this pointer point to an integer array its size is N.<br /></span><span style="font-size: 11pt; font-family: 'Lucida Console'; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; background-color: transparent; "> &nbsp;&nbsp;&nbsp;It means this variable value named "fun" and its type<br /></span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> &nbsp;&nbsp;&nbsp;Well, the above are so complex, and we should follow the </span><span style="font-size: 11pt; font-family: 'Lucida Console'; color: #ff0000; background-color: transparent; font-weight: bold; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">KISS</span><span style="font-size: 11pt; font-family: 'Lucida Console'; background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> principle that is </span><span style="font-size: 11pt; font-family: 'Lucida Console'; color: #ff0000; background-color: transparent; font-weight: bold; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">Keep It Simple</span><span style="font-size: 11pt; font-family: 'Lucida Console'; color: #ff0000; background-color: transparent; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">, </span><span style="font-size: 11pt; font-family: 'Lucida Console'; color: #ff0000; background-color: transparent; font-weight: bold; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">Stupid</span><span style="vertical-align: baseline; background-color: transparent; "><font class="Apple-style-span" face="Consolas"><span class="Apple-style-span" style="font-size: 11pt; white-space: pre-wrap; font-family: 'Lucida Console'; ">.</span></font><br /><font class="Apple-style-span" face="Consolas"><span class="Apple-style-span" style="font-size: 11pt; white-space: pre-wrap; font-family: 'Lucida Console'; ">    Did you catch it ??</span></font><br /><br /><br /><br /><div style="text-align: right;"><font class="Apple-style-span" face="Consolas"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap; font-family: 'Lucida Console'; ">Tuesday, October 25, 2011</span></font></div></span></div><img src ="http://www.cppblog.com/scorpio/aggbug/159060.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2011-10-25 17:28 <a href="http://www.cppblog.com/scorpio/archive/2011/10/25/159060.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How To Disable "_CRT_SECURE_NO_WARNINGS" Warnings</title><link>http://www.cppblog.com/scorpio/archive/2011/10/25/159059.html</link><dc:creator>Apollo Fang</dc:creator><author>Apollo Fang</author><pubDate>Tue, 25 Oct 2011 09:26:00 GMT</pubDate><guid>http://www.cppblog.com/scorpio/archive/2011/10/25/159059.html</guid><wfw:comment>http://www.cppblog.com/scorpio/comments/159059.html</wfw:comment><comments>http://www.cppblog.com/scorpio/archive/2011/10/25/159059.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/scorpio/comments/commentRss/159059.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/scorpio/services/trackbacks/159059.html</trackback:ping><description><![CDATA[<font class="Apple-style-span" face="'Lucida Console'"><span style="font-family: 'Lucida Console'; ">&nbsp; &nbsp; While you using MS Visual Studio, there are always "_CRT_SECURE_NO_WARNINGS" warnings appeared, like bellow:<br /></span></font><br /><span style="font-size: 12pt; font-family: 'Lucida Console'; color: red; "><em>&nbsp; &nbsp;</em></span><span style="font-family: 'Times New Roman'; font-size: 12pt; color: red; "><em>"warning C4996: 'strerror': This function or variable may be unsafe. Using strerror_s instead."</em></span><div><br /><font class="Apple-style-span" face="'Lucida Console'">&nbsp; &nbsp; How to disable this kind deprecation? Do like bellow (VS2010):</font><br /><br /><font class="Apple-style-span" face="'Lucida Console'">&nbsp; &nbsp; Project -&gt; Properties -&gt; Configuration Properties -&gt; C++ -&gt; Processor -&gt; Processor Definitions</font><br /><br /><font class="Apple-style-span" face="'Lucida Console'">&nbsp; &nbsp; And then add a macro definition&nbsp;<span style="font-family: 'Times New Roman'; color: red; "><em>"</em></span><span style="font-family: 'Times New Roman'; color: red; font-size: 12pt; "><em>_CRT_SECURE</em></span><span style="font-family: 'Times New Roman'; color: red; font-size: 12pt; "><em>_</em></span><span style="font-family: 'Times New Roman'; color: red; font-size: 12pt; "><em>NO_WARNINGS"</em></span>, and use a ";" to separated with others</font><br /><br /><font class="Apple-style-span" face="'Lucida Console'">&nbsp; &nbsp; OK, Hit OK and enjoy the silence...</font><br /><br /><br /><div style="text-align: right; "><font class="Apple-style-span" face="'Lucida Console'">Tuesday, October 25, 2011</font></div></div><span class="Apple-style-span" style="background-color: #28557e; "><font class="Apple-style-span"><span style="background-color: #28557e; "><font class="Apple-style-span" face="'Lucida Console'" size="3"><span class="Apple-style-span" style="line-height: 19px;"><br /></span></font><div></div></span></font></span><img src ="http://www.cppblog.com/scorpio/aggbug/159059.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/scorpio/" target="_blank">Apollo Fang</a> 2011-10-25 17:26 <a href="http://www.cppblog.com/scorpio/archive/2011/10/25/159059.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>