<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[warning：deprecated conversion from string constant to char * 解决方案]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Mon, 16 Feb 2015 09:00:52 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：用新版本的编译器编译时，原来没有报任何错和警告的代码，现在居然报出警告了，<br/>之前是：<br/><textarea name="code" class="C" rows="15" cols="100">
g++&nbsp;&nbsp;-g multipepollserver.cpp -o multipepollserver&nbsp;&nbsp;-lrt&nbsp;&nbsp;-lpthread
</textarea><br/>无错误，现在是新的gcc v4.4的编译器编译时候出现警告了，如下：<br/><textarea name="code" class="C" rows="15" cols="100">
/usr/bin/g++44&nbsp;&nbsp; -g -Wall multipepollserver.cpp -o multipepollserver&nbsp;&nbsp;-lrt&nbsp;&nbsp;-lpthread&nbsp;&nbsp;-lmemcached&nbsp;&nbsp;-std=c++0x&nbsp;&nbsp;
</textarea><br/><br/>警告如下：<br/>multipepollserver.cpp:530: warning: deprecated conversion from string constant to ‘char*’<br/>multipepollserver.cpp:536: warning: deprecated conversion from string constant to ‘char*’<br/>multipepollserver.cpp:537: warning: deprecated conversion from string constant to ‘char*’<br/><br/>原来是定义pid变量时，新的gcc版本需要加上const，也就是：<br/><textarea name="code" class="C" rows="15" cols="100">
const char * httpmut_prename_buf=&quot;master process&quot;; /* 原命令行参数:主进程运名字 */ 
const char * httpmut_prename_child_buf=&quot;worker process&quot;; /* 原命令行参数:子进程名字。 */&nbsp;&nbsp;
</textarea><br/>为何要加，下面文章有描写道：<br/><br/>研究这个警告的代码如下：<br/><textarea name="code" class="C" rows="15" cols="100">
#include &lt;iostream&gt;
using namespace std;

int fuc(char *a)
&#123;
&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; a &lt;&lt; endl;
&#125;
int main()
&#123;
&nbsp;&nbsp;&nbsp;&nbsp;fuc(&quot;hello&quot;);
&#125;
</textarea><br/>Linux 环境下当GCC版本比较高时，编译代码可能出现的问题<br/><br/>问题是这样产生的，先看这个函数原型：<br/>void someFunc(char *someStr);<br/>再看这个函数调用：<br/>someFunc(&quot;I&#039;m a string!&quot;);<br/>把这两个东西组合起来，用最新的g++编译一下就会得到标题中的警告。<br/><br/>为什么呢？原来char *背后的含义是：给我个字符串，我要修改它。<br/><br/>而理论上，我们传给函数的字面常量是没法被修改的。<br/><br/>所以说，比较和理的办法是把参数类型修改为const char *。<br/><br/>这个类型说背后的含义是：给我个字符串，我只要读取它。<br/> <br/><br/>如何同时接收const类型和非const类型？重载<br/><textarea name="code" class="C" rows="15" cols="100">
#include &lt;iostream&gt;
using namespace std;
 
int fuc(char *a)
&#123;
&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; a &lt;&lt; endl;
&#125;
int fuc(const char *a)
&#123;
&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; a &lt;&lt; endl;
&#125;
int main()
&#123;
&nbsp;&nbsp;&nbsp;&nbsp;char a[] = &quot;hello 123&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;fuc(a);
&nbsp;&nbsp;&nbsp;&nbsp;const char b[] = &quot;hello 123&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;fuc(a);
&#125;

</textarea><br/>结果:<br/>hello 123<br/>hello 123<br/><br/>摘自：http://www.cnblogs.com/kaituorensheng/p/3575403.html
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] warning：deprecated conversion from string constant to char * 解决方案]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>