<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href='http://feed.feedsky.com/styles/feedsky0.xsl' type='text/xsl' ?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link href="http://feed.shiningray.cn" type="application/rss+xml" rel="self"></atom:link><fs:self_link href="http://feed.feedsky.com/shiningray" type="application/rss+xml"></fs:self_link><lastBuildDate>Mon, 25 Aug 2008 14:11:45 GMT</lastBuildDate><title>ShiningRay的Blog</title><description>一缕阳光</description><image><url>http://www.feedsky.com/feed/shiningray/sc/gif</url><title>ShiningRay的Blog</title><link>http://shiningray.cn</link></image><link>http://shiningray.cn</link><language>en</language><pubDate>Mon, 25 Aug 2008 14:11:45 GMT</pubDate><item><title>上海的洪水</title><link>http://shiningray.cn/shang-hai-de-hong-shui.html</link><content:encoded>&lt;p&gt;今天是到渡维上班的第一天，结果遇上了百年一遇的暴雨，造成上海多个地方积水严重。我9点出门，等69路等了1个小时，找出租车用了半个小时，上了出租车之后绕绕绕，绕到虹井路延安西路，结果到了快一点，还没走多远，打车就85元了。然后路边随便找了一个饭店草草解决了午饭，长途跋涉，沿延安西路一直走到古北路兴义路。途中历经艰难险阻，过中环的时候都是趟着没过膝盖的污水经过的。到这个69路公交车站的时候已经是下午3点了，然后等69路最后坐到长宁路，到达公司的时候已经是4点多。&lt;/p&gt;
&lt;p&gt;所幸，我还是到了。&lt;/p&gt;
&lt;p&gt;晚上回来时乘坐69路则一路畅通，但我仍然看到中环靠近吴中路那边非常堵。&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=21ceb8855eb2451ca314c71d292cfd80&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=21ceb8855eb2451ca314c71d292cfd80&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=aff54eb9b34106db8041e337b6ee10f3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=aff54eb9b34106db8041e337b6ee10f3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=26dda43a2d5df3fa8f4fdd45a0fb756e&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=26dda43a2d5df3fa8f4fdd45a0fb756e&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=7ea456409f7e60a96fbb058d876cc98d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=7ea456409f7e60a96fbb058d876cc98d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=d6e2cd080f8ffdb2e7c88e42215b35a3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=d6e2cd080f8ffdb2e7c88e42215b35a3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=4b4f3480f587ecd1003e8b509ab46c06&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=4b4f3480f587ecd1003e8b509ab46c06&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a91053a1adda0225318574a0965948ae&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a91053a1adda0225318574a0965948ae&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/shang-hai-de-hong-shui.html/feed</wfw:commentRss><description>今天是到渡维上班的第一天，结果遇上了百年一遇的暴雨，造成上海多个地方积水严重。我9点出门，等69路等了1个小时，找出租车用了半个小时，上了出租车之后绕绕绕，绕到虹井路延安西路，结果到了快一点，还没走多远，打车就85元了。然后路边随便找了一个饭店草草解决了午饭，长途跋涉，沿延安西路一直走到古北路兴义路。途中历经艰难险阻，过中环的时候都是趟着没过膝盖的污水经过的。到这个69路公交车站的时候已经是下午3点了，然后等69路最后坐到长宁路，到达公司的时候已经是4点多。
所幸，我还是到了。
晚上回来时乘坐69路则一路畅通，但我仍然看到中环靠近吴中路那边非常堵。&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=21ceb8855eb2451ca314c71d292cfd80&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=21ceb8855eb2451ca314c71d292cfd80&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=aff54eb9b34106db8041e337b6ee10f3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=aff54eb9b34106db8041e337b6ee10f3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=26dda43a2d5df3fa8f4fdd45a0fb756e&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=26dda43a2d5df3fa8f4fdd45a0fb756e&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=7ea456409f7e60a96fbb058d876cc98d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=7ea456409f7e60a96fbb058d876cc98d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=d6e2cd080f8ffdb2e7c88e42215b35a3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=d6e2cd080f8ffdb2e7c88e42215b35a3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=4b4f3480f587ecd1003e8b509ab46c06&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=4b4f3480f587ecd1003e8b509ab46c06&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a91053a1adda0225318574a0965948ae&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a91053a1adda0225318574a0965948ae&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>日记</category><category>洪水</category><category>上班</category><pubDate>Mon, 25 Aug 2008 22:11:45 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/shang-hai-de-hong-shui.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=208</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/shang-hai-de-hong-shui.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614403/1225462</fs:itemid></item><item><title>东西一流行就容易变味</title><link>http://shiningray.cn/dong-xi-yi-liu-xing-jiu-rong-yi-bian-wei.html</link><content:encoded>&lt;p&gt;以前朋友带我去上海的一些店里吃东西，经常说“店大了，东西没有以前好吃了”。然而，我也和朋友去过另外一些小店，味道和店面都一如既往十几年（除了物价上涨）。&lt;/p&gt;
&lt;p&gt;这时候我发现身边很多东西一旦开始流行，就立刻变味——也许这就叫量变到质变。身边的例子很多，记得05年的时候，我还和同学们一起吃一种叫做“掉渣大饼“的东西，那时候这玩意儿突然很流行，但没过多久，突然又消失匿迹了。有人分析原因是这样：“流行风，不适合在一个固定地点开店，适合流动售卖。 口味比较重，油也挺大，不是健康食品。所以刚出来时，大家出于好奇，买的人较多，但不适合常吃。”&lt;sup&gt;[&lt;a href=&quot;http://zhidao.baidu.com/question/50323189.html&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;然而也有人分析是因为“无序加盟”造成的&lt;sup&gt;[&lt;a href=&quot;http://news.sina.com.cn/c/2006-03-06/09068370806s.shtml&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;。&lt;/p&gt;
&lt;p&gt;掉渣大饼的例子算是一类典型，但它的“潮流”，也许还不是那么地引人注目。只能说，它的“流行”只是相对于其他接近的东西，在短时间内聚集了大量关注。也许标题改成“公司在快速扩张过程中容易出现问题”更能符合我所想说的。因为公司产品突然地流行起来，意味着公司更加有利可图，那么公司会想办法扩张，而在扩张过程中，由于某些方面做得不到位，或另些方面做得太过分等，而导致产品不能如公司或者受众的期望继续发展，甚至最终导致公司扩张失败、甚至市场萎缩。&lt;/p&gt;
&lt;p&gt;我很想探究其中的道理。不过我认为应该首先定义“流行”是什么。百度百科上这样解释[&lt;a href=&quot;http://baike.baidu.com/view/277310.htm&quot;&gt;3&lt;/a&gt;]：&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;比如一些事物，刚开始没有太多人去注意，慢慢的引起了很多的注视，后来越来越多的人开始关注它，这就是所谓的“流行＂&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;不过这似乎与我要阐述的流行有所不同，在这里我所谓的流行是指受众比原有变的多，且增长速度也在提升。当然还有受众的问题，当受众之间个体之间相同点少，那么可以说是大众流行，反之，就是小众流行；如果小众是属于有钱人，似乎就是高档的奢侈品；如果在受众中的接受程度高，那么就是该群体中的“主流”；如果在大众中接受程度高，那就可以算“主流”了。&lt;/p&gt;
&lt;p&gt;我把在潮流中的三个类角色划分出来：A. 通过这个事物引领、制造（有意或无意的）潮流的公司或个体，B. 在潮流中模仿A，想分一杯羹的跟风者，C. 潮流的受众们。&lt;/p&gt;
&lt;p&gt;C是原动力，A是导火索，B是推波助澜的。没有广泛的C，就不能成就A所需要的市场，没有市场带来的利益，也就不会有B的跟风。当A不能注重品质，东西就变味了。&lt;/p&gt;
&lt;p&gt;往往当潮流来临的时候，没有人会意识到它有多大，它能持续多长，普通的公司往往都只想在潮流中能捞多少捞多少，而不管自己是不是真的有实力。我归结这些个公司在潮流中失败的原因往往有：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;只注重扩张，而不注重品质：只知道要多捞点，不知道要全面均衡发展。&lt;/li&gt;
&lt;li&gt;有各方面条件更好的后来者居上：没想到被巨头盯上了。&lt;/li&gt;
&lt;li&gt;市场需求被透支：过分炒作流行的概念，等受众回头醒悟发现被骗了。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;所以我想问问，那些准备制造、或刚刚制造了潮流的商家们，你们真的准备好了吗？&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;关于Apple&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;其实突然想写本文其实也是因为Apple。随着Apple的一系列优秀产品iPod、iPhone等一下子流行起来。最近Apple的日子不好过：&lt;/p&gt;
&lt;ul class=&quot;list_009_f14&quot;&gt;
&lt;li&gt;&lt;a title=&quot;3G版iPhone遭遇质量门 苹果称暂无召回计划&quot; href=&quot;http://finance.sina.com.cn/consume/puguangtai/20080805/06495166910.shtml&quot; target=&quot;_blank&quot;&gt;3G版iPhone遭遇质量门 苹果称暂无召回计划&lt;/a&gt;&lt;span style=&quot;color: #808080;&quot;&gt; &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title=&quot;3G版iPhone后盖开裂遭遇质量门&quot; href=&quot;http://tech.sina.com.cn/t/2008-08-05/04472371116.shtml&quot; target=&quot;_blank&quot;&gt;3G版iPhone后盖开裂遭遇质量门&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title=&quot;多部3G iPhone手机曝出塑料外壳无故开裂&quot; href=&quot;http://tech.sina.com.cn/t/2008-08-03/11402368007.shtml&quot; target=&quot;_blank&quot;&gt;多部3G iPhone手机曝出塑料外壳无故开裂&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title=&quot;掉漆又断裂 iPhone 3G质量缺陷曝光&quot; href=&quot;http://tech.sina.com.cn/mobile/n/2008-07-31/12002363500.shtml&quot; target=&quot;_blank&quot;&gt;掉漆又断裂 iPhone 3G质量缺陷曝光&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title=&quot;高价不高质 iPhone 3G外壳龟裂曝光不断&quot; href=&quot;http://tech.sina.com.cn/mobile/n/2008-07-31/0626752484.shtml&quot; target=&quot;_blank&quot;&gt;高价不高质 iPhone 3G外壳龟裂曝光不断&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;种种负面消息传出，我就会说，Apple，你的iPhone还没准备好吧？不可否认，Apple的iPhone的外观设计是出色的、操作系统是优秀的，软件服务也是很棒的，可惜，Apple你本来不是做手机的。iPhone的流行导致这个苹果变味儿了。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;过去的定位与未来目标的冲突&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Apple的产品定位一直是高端用户群体。以前，我对Apple的Mac是有一些好感的，当然我也不讨厌Windows。我一直认为Apple的东西很酷，很有形，用Apple的是设计师，非常有个性的人，他们很有创造力。然而在国外，iPod已然变成了是一个日用品。而在国内，则是一个时尚的代名词，用iPod，就可以显得很前卫，很潮流。其实当用的人多了，也就没有什么前卫不前卫的。因为直到有一天，我发现送外卖的小弟也揣着一个iPod。同时，模仿iPod的MP3、MP4公司越来越多，功能也会超越iPod，iPod虽然能因为Apple的种种魅力保持他的地位，但它在这个领域的份额也会逐渐减少——就好比现在手机与山寨机；如果iPod的份额不减少，甚至越来越高，那么说明市场正在衰退，因为用的人实在太多了，没有人会觉得这很前卫、很时尚。&lt;/p&gt;
&lt;p&gt;其实Apple过去做的东西是有点“奢侈品”的意思在里面，然而，将来它要面对的是自己的产品变得大众化。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;盲目扩张，忽视了品质&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;也许并非Apple不注重品质，而是对于手机的设计制造还缺乏经验，所以才出现了种种“瑕疵”。正因为对iPhone前景过于充满信心而到处签约，却忽视了iPhone的产能问题。这些问题非常容易导致iPhone的品牌被做烂掉。&lt;/p&gt;
&lt;p&gt;Apple没有做过手机，难免会出现一些问题，但是因为Apple之前太成功了，所以iPhone理应成功，人们的期望总是很高。这种突然的潮流，搞不好就会淹没Apple自己。&lt;/p&gt;
&lt;p&gt;其实iPod，在2001年出现第一代iPod，也是出现了很多问题，我的印象中，到05年，国内才开始流行iPod。这种稳步的渐进式的，也许更加符合发展规律。&lt;/p&gt;
&lt;p&gt;这点Google就非常聪明，Google也希望进军手机领域，但它清楚，一方面自己没有做过手机，另一方面蛋糕要一起吃，只有拉拢手机巨头们，才 能抢占这个市场，所以它推出了Open Handset Alliance，自己主导做系统，然后推自己服务。当时Gmail的推出，引发了无限/超大容量邮箱的革命时，Google也是用了类似策略，因为 Google清楚自己无法应付过多的用户，所以他在Gmail推出初期，只有被邀请才能加入，并且刺激别的邮件供应商跟进。这样在占据了合理的市场份额的 同时，保证了Gmail的品质和发展。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;摊子铺太广、独来独往&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;有人经常拿Apple和Microsoft比，其实我觉得两者除了在操作系统上可以进行比较外，其他方面没有很多交集。&lt;/p&gt;
&lt;p&gt;历史上任何一个大浪潮，都不是单单某一个公司能够凭借一己之力完成的，PC机和Windows的流行，并不是一朝一夕的事情，而是顺应历史的必然。在Windows95流行之前，微软就已经做了十几年操作系统，而微软的联盟者，已经做了十几年的PC机。微软从来没有想着自己做硬件去统治整个市场。这就是为何微软抄了苹果的界面，却比苹果更流行的原因。&lt;/p&gt;
&lt;p&gt;因为苹果什么都做，同时又几乎完全封闭自己的架构，一个公司的能力是有限的，所以它一直只能走小众路线。苹果从硬件方面的芯片、机箱、显示器，到软件上的操作系统、各种“i”系列的应用软件，从台式机到服务器，到现在的电子产品、手机，Apple可谓无所不包（虽然不是每个零件都自己做）。这也就是为何苹果机没有最终广泛流行的原因，因为微软不是一个人在战斗，微软的背后有Intel，有IBM，有各大中小PC制造商，有无数共享软件开发者，有无数的游戏厂商。苹果的封闭而又追求完美的面面俱到的开发，使他开发出来的只能是曲高和寡的艺术品。&lt;/p&gt;
&lt;p&gt;当然，苹果也走了几招妙棋。MacOSX是基于BSD系统开发的操作系统，BSD是开源Unix系统家族中的一员，而且苹果也开放了一些东西让广大开发者一起维护。这就使得MacOSX可以兼容相当多的*nix软件，一下子吸引了很多*nix的开发人员。然后苹果又与Intel结盟，采用Intel芯片。&lt;/p&gt;
&lt;p&gt;总结上述一些问题，我认为苹果目前其实处境还是很危险的。希望苹果不要再变味了。&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=4060b05fbf93e8255c77b34113bdfc6f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=4060b05fbf93e8255c77b34113bdfc6f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ad69f7958a76b0f4234004dda9cf0c90&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ad69f7958a76b0f4234004dda9cf0c90&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=09ec1f4d3c4fa9df4d4574952073b1ef&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=09ec1f4d3c4fa9df4d4574952073b1ef&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0132084b37559176a4527f715fd233fa&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0132084b37559176a4527f715fd233fa&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=11705d67f06d639f205158425ded6bdb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=11705d67f06d639f205158425ded6bdb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ca3a454d8dfd8f961db6d824aa3d1865&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ca3a454d8dfd8f961db6d824aa3d1865&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=5a00b8e98084ff05d2ea12951081c131&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=5a00b8e98084ff05d2ea12951081c131&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/dong-xi-yi-liu-xing-jiu-rong-yi-bian-wei.html/feed</wfw:commentRss><description>以前朋友带我去上海的一些店里吃东西，经常说“店大了，东西没有以前好吃了”。然而，我也和朋友去过另外一些小店，味道和店面都一如既往十几年（除了物价上涨）。
这时候我发现身边很多东西一旦开始流行，就立刻变味——也许这就叫量变到质变。身边的例子很多，记得05年的时候，我还和同学们一起吃一种叫做“掉渣大饼“的东西，那时候这玩意儿突然很流行，但没过多久，突然又消失匿迹了。有人分析原因是这样：“流行风，不适合在一个固定地点开店，适合流动售卖。 口味比较重，油也挺大，不是健康食品。所以刚出来时，大家出于好奇，买的人较多，但不适合常吃。”[1]然而也有人分析是因为“无序加盟”造成的[2]。
掉渣大饼的例子算是一类典型，但它的“潮流”，也许还不是那么地引人注目。只能说，它的“流行”只是相对于其他接近的东西，在短时间内聚集了大量关注。也许标题改成“公司在快速扩张过程中容易出现问题”更能符合我所想说的。因为公司产品突然地流行起来，意味着公司更加有利可图，那么公司会想办法扩张，而在扩张过程中，由于某些方面做得不到位，或另些方面做得太过分等，而导致产品不能如公司或者受众的期望继续发展，甚至最终导致公司扩张失败、甚至市场萎缩。
我很想探究其中的道理。不过我认为应该首先定义“流行”是什么。百度百科上这样解释[3]：
比如一些事物，刚开始没有太多人去注意，慢慢的引起了很多的注视，后来越来越多的人开始关注它，这就是所谓的“流行＂
不过这似乎与我要阐述的流行有所不同，在这里我所谓的流行是指受众比原有变的多，且增长速度也在提升。当然还有受众的问题，当受众之间个体之间相同点少，那么可以说是大众流行，反之，就是小众流行；如果小众是属于有钱人，似乎就是高档的奢侈品；如果在受众中的接受程度高，那么就是该群体中的“主流”；如果在大众中接受程度高，那就可以算“主流”了。
我把在潮流中的三个类角色划分出来：A. 通过这个事物引领、制造（有意或无意的）潮流的公司或个体，B. 在潮流中模仿A，想分一杯羹的跟风者，C. 潮流的受众们。
C是原动力，A是导火索，B是推波助澜的。没有广泛的C，就不能成就A所需要的市场，没有市场带来的利益，也就不会有B的跟风。当A不能注重品质，东西就变味了。
往往当潮流来临的时候，没有人会意识到它有多大，它能持续多长，普通的公司往往都只想在潮流中能捞多少捞多少，而不管自己是不是真的有实力。我归结这些个公司在潮流中失败的原因往往有：

只注重扩张，而不注重品质：只知道要多捞点，不知道要全面均衡发展。
有各方面条件更好的后来者居上：没想到被巨头盯上了。
市场需求被透支：过分炒作流行的概念，等受众回头醒悟发现被骗了。

所以我想问问，那些准备制造、或刚刚制造了潮流的商家们，你们真的准备好了吗？
关于Apple
其实突然想写本文其实也是因为Apple。随着Apple的一系列优秀产品iPod、iPhone等一下子流行起来。最近Apple的日子不好过：

3G版iPhone遭遇质量门 苹果称暂无召回计划 
3G版iPhone后盖开裂遭遇质量门
多部3G iPhone手机曝出塑料外壳无故开裂
掉漆又断裂 iPhone 3G质量缺陷曝光
高价不高质 iPhone 3G外壳龟裂曝光不断

种种负面消息传出，我就会说，Apple，你的iPhone还没准备好吧？不可否认，Apple的iPhone的外观设计是出色的、操作系统是优秀的，软件服务也是很棒的，可惜，Apple你本来不是做手机的。iPhone的流行导致这个苹果变味儿了。
过去的定位与未来目标的冲突
Apple的产品定位一直是高端用户群体。以前，我对Apple的Mac是有一些好感的，当然我也不讨厌Windows。我一直认为Apple的东西很酷，很有形，用Apple的是设计师，非常有个性的人，他们很有创造力。然而在国外，iPod已然变成了是一个日用品。而在国内，则是一个时尚的代名词，用iPod，就可以显得很前卫，很潮流。其实当用的人多了，也就没有什么前卫不前卫的。因为直到有一天，我发现送外卖的小弟也揣着一个iPod。同时，模仿iPod的MP3、MP4公司越来越多，功能也会超越iPod，iPod虽然能因为Apple的种种魅力保持他的地位，但它在这个领域的份额也会逐渐减少——就好比现在手机与山寨机；如果iPod的份额不减少，甚至越来越高，那么说明市场正在衰退，因为用的人实在太多了，没有人会觉得这很前卫、很时尚。
其实Apple过去做的东西是有点“奢侈品”的意思在里面，然而，将来它要面对的是自己的产品变得大众化。
盲目扩张，忽视了品质
也许并非Apple不注重品质，而是对于手机的设计制造还缺乏经验，所以才出现了种种“瑕疵”。正因为对iPhone前景过于充满信心而到处签约，却忽视了iPhone的产能问题。这些问题非常容易导致iPhone的品牌被做烂掉。
Apple没有做过手机，难免会出现一些问题，但是因为Apple之前太成功了，所以iPhone理应成功，人们的期望总是很高。这种突然的潮流，搞不好就会淹没Apple自己。
其实iPod，在2001年出现第一代iPod，也是出现了很多问题，我的印象中，到05年，国内才开始流行iPod。这种稳步的渐进式的，也许更加符合发展规律。
这点Google就非常聪明，Google也希望进军手机领域，但它清楚，一方面自己没有做过手机，另一方面蛋糕要一起吃，只有拉拢手机巨头们，才 能抢占这个市场，所以它推出了Open Handset Alliance，自己主导做系统，然后推自己服务。当时Gmail的推出，引发了无限/超大容量邮箱的革命时，Google也是用了类似策略，因为 Google清楚自己无法应付过多的用户，所以他在Gmail推出初期，只有被邀请才能加入，并且刺激别的邮件供应商跟进。这样在占据了合理的市场份额的 同时，保证了Gmail的品质和发展。
摊子铺太广、独来独往
有人经常拿Apple和Microsoft比，其实我觉得两者除了在操作系统上可以进行比较外，其他方面没有很多交集。
历史上任何一个大浪潮，都不是单单某一个公司能够凭借一己之力完成的，PC机和Windows的流行，并不是一朝一夕的事情，而是顺应历史的必然。在Windows95流行之前，微软就已经做了十几年操作系统，而微软的联盟者，已经做了十几年的PC机。微软从来没有想着自己做硬件去统治整个市场。这就是为何微软抄了苹果的界面，却比苹果更流行的原因。
因为苹果什么都做，同时又几乎完全封闭自己的架构，一个公司的能力是有限的，所以它一直只能走小众路线。苹果从硬件方面的芯片、机箱、显示器，到软件上的操作系统、各种“i”系列的应用软件，从台式机到服务器，到现在的电子产品、手机，Apple可谓无所不包（虽然不是每个零件都自己做）。这也就是为何苹果机没有最终广泛流行的原因，因为微软不是一个人在战斗，微软的背后有Intel，有IBM，有各大中小PC制造商，有无数共享软件开发者，有无数的游戏厂商。苹果的封闭而又追求完美的面面俱到的开发，使他开发出来的只能是曲高和寡的艺术品。
当然，苹果也走了几招妙棋。MacOSX是基于BSD系统开发的操作系统，BSD是开源Unix系统家族中的一员，而且苹果也开放了一些东西让广大开发者一起维护。这就使得MacOSX可以兼容相当多的*nix软件，一下子吸引了很多*nix的开发人员。然后苹果又与Intel结盟，采用Intel芯片。
总结上述一些问题，我认为苹果目前其实处境还是很危险的。希望苹果不要再变味了。&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=4060b05fbf93e8255c77b34113bdfc6f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=4060b05fbf93e8255c77b34113bdfc6f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ad69f7958a76b0f4234004dda9cf0c90&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ad69f7958a76b0f4234004dda9cf0c90&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=09ec1f4d3c4fa9df4d4574952073b1ef&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=09ec1f4d3c4fa9df4d4574952073b1ef&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0132084b37559176a4527f715fd233fa&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0132084b37559176a4527f715fd233fa&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=11705d67f06d639f205158425ded6bdb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=11705d67f06d639f205158425ded6bdb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ca3a454d8dfd8f961db6d824aa3d1865&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ca3a454d8dfd8f961db6d824aa3d1865&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=5a00b8e98084ff05d2ea12951081c131&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=5a00b8e98084ff05d2ea12951081c131&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>iPod</category><category>Apple</category><category>感想</category><category>iPhone</category><category>流行</category><pubDate>Fri, 08 Aug 2008 16:43:00 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/dong-xi-yi-liu-xing-jiu-rong-yi-bian-wei.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=195</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/dong-xi-yi-liu-xing-jiu-rong-yi-bian-wei.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614404/1225462</fs:itemid></item><item><title>并行的快速排序</title><link>http://shiningray.cn/parallel-quick-sort-in-erlang.html</link><content:encoded>&lt;p&gt;&lt;a href=&quot;http://zh.wikipedia.org/wiki/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F&quot;&gt;快速排序&lt;/a&gt;是一种应用了“&lt;a href=&quot;http://zh.wikipedia.org/wiki/%E5%88%86%E6%B2%BB%E6%B3%95&quot;&gt;分治法&lt;/a&gt;”的算法，所谓分治法(divid &amp;amp; conquer)，就是把大的问题分割为结构相同的小问题，然后进行解决的方法。因为都是相同的小问题，所以我们可以利用并行计算来并行处理这些问题，使用Erlang可以非常方便非常清晰地利用这种方法解决问题。&lt;br /&gt;
由于Erlang是一种声明式、函数式编程语言，所以要表述基本的快速排序算法非常方便：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;qsort(_, []) -&amp;gt; [];
qsort(F, [H|T]) -&amp;gt;
    qsort(F, [X || X &amp;lt;- T, F(X, H)])
    ++ [H] ++
    qsort(F, [X || X &amp;lt;- T, not F(X, H)]).

qsort(L) -&amp;gt; qsort(fun(X, Y) -&amp;gt; X &amp;lt; Y end, L).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;其中F是一个用于比较的函数。这种描述方式非常精炼，不过效率不高，原因在于1. 不是尾递归, 2.  该代码中应用了两个列表领悟（ list comprehension ），其结果是对同一个列表进行了两次遍历。不过这些问题我们稍后考虑。&lt;br /&gt;
在erlang中，创建和维护进程是非常方便的，可以很容易地将以上的顺序算法变成创建单独的进程解决对每个子问题：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;psort(Pid, _Fun, []) -&amp;gt; Pid ! {self(), []};
psort(Pid, Fun, [H|T]) -&amp;gt;
    Lid = spawn_link(?MODULE, psort, [self(), Fun, [X||X &amp;lt;- T, Fun(X, H)]]),
    Rid = spawn_link(?MODULE, psort, [self(), Fun, [X||X &amp;lt;- T, not Fun(X, H)]]),
    receive
        {Lid, L} -&amp;gt; Left = L
    end,
    receive
        {Rid, R} -&amp;gt; Right = R
    end,
    Pid ! {self(), Left ++ [H] ++ Right}.
%% @spec psort(fun(X, Y) -&amp;gt; bool(), list(any())) -&amp;gt; list(any()).
psort(Fun, L) -&amp;gt;
    Pid = spawn_link(?MODULE, psort, [self(), Fun, L]),
    receive
        {Pid, R} -&amp;gt; R
    end.
psort(L) -&amp;gt; psort(fun(X, Y) -&amp;gt; X &amp;lt; Y end, L).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;解决父任务的进程通过接受子进程发来的消息来获得结果。然而，这个代码除了前面的问题之外，也有两个问题：1. 粒度太小，如果小到连一个空列表都要生成一个新的进程来解决问题，那么创建进程的开销就会大过计算本身。2. Programming Erlang中讲到，并发编程要注意“小消息，大计算”，这里在消息中频繁传递列表是开销较大的操作。&lt;/p&gt;
&lt;p&gt;我通过生成1000个0-1000之间的随机数的列表来测试这两个算法的性能，在我的迅驰1.8G的本上，结果表示：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lists:sort 1.45ms&lt;/li&gt;
&lt;li&gt;qsort  9.44ms&lt;/li&gt;
&lt;li&gt;psort  30.75ms&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;看来我的这两个实现还是比较低效的。首先关于qsort的两个问题，1. 遍历了两次列表，可以通过单独使用一个分区函数来遍历一次完成对列表的划分；2. 不是尾递归，可以使用一个累加器来收集结果，此法可以将其中一个递归变成尾递归（我还无法做到两个都消除）。&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;qsort3(_F, []) -&amp;gt; [];
qsort3(F, L) -&amp;gt; qsort3_acc(F, L, []).

qsort3(L) -&amp;gt; qsort3(fun(X, Y) -&amp;gt; if X &amp;lt; Y -&amp;gt; -1; X =:= Y -&amp;gt; 0; true -&amp;gt; 1 end end, L).

qsort3_acc(_F, [], Acc) -&amp;gt; Acc;
qsort3_acc(F, [H | T], Acc) -&amp;gt;
    part_acc(F, H, T, {[], [H], []}, Acc).

part_acc(F,_, [], {L,E,G}, Acc) -&amp;gt;
    qsort3_acc(F, L, (E ++ qsort3_acc(F, G, Acc)));
part_acc(F, X, [H | T], {L, E, G}, Acc) -&amp;gt;
    C = F(H, X),
    if
        C &amp;lt; 0 -&amp;gt;
            part_acc(F, X, T, {[H | L], E, G}, Acc);
        C =:= 0 -&amp;gt;
            part_acc(F, X, T, {L, [H | E], G}, Acc);
        true -&amp;gt;
            part_acc(F, X, T, {L, E, [H | G]}, Acc)
    end.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;此为改进版的快速排序。在此基础上，再解决并行快速排序的两个问题：1. 粒度太小：可以设置一个阈值，当列表长度小于多少时，调用快速排序解决问题；2. 消息太大——我还没想到解决方案。&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;psort3(Pid, _F, _Granularity, []) -&amp;gt;
    Pid ! {self(), []};
psort3(Pid, F, Granularity, [H|T]=Ls) -&amp;gt;
    if length(Ls) &amp;lt; Granularity -&amp;gt;
        Pid ! {self(), qsort3(F, Ls)};
    true -&amp;gt;
        {Lesser, Eq, Greater} = part(F, H, T, {[], [H], []}),
        Lid = spawn_link(?MODULE, psort3, [self(), F, Granularity, Lesser]),
        Rid = spawn_link(?MODULE, psort3, [self(), F, Granularity, Greater]),
        receive
            {Lid, L} -&amp;gt; Left = L
        end,
        receive
            {Rid, R} -&amp;gt; Right = R
        end,
        Pid ! { self(), Left ++ Eq ++ Right }
    end.

psort3(F, Granularity, L) -&amp;gt;
    Pid = spawn_link(sort, psort3, [self(), F, Granularity, L]),
    receive
        {Pid, R} -&amp;gt; R
    end.
psort3(L) -&amp;gt;
    psort3(fun(X, Y) -&amp;gt; if X &amp;lt; Y -&amp;gt; -1; X =:= Y -&amp;gt; 0; true -&amp;gt; 1 end end, 100, L).&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;测试结果为：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;qsort3: 5.31ms&lt;/li&gt;
&lt;li&gt;psort3: 7.76ms&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;另外，我发现，如果从命令行中传递比较函数，则性能下降非常大，不知何故。&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=da4357ea70fe429c74a26aed4a7b91f5&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=da4357ea70fe429c74a26aed4a7b91f5&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=1c5e0281277f41a7a508ff0924331cac&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=1c5e0281277f41a7a508ff0924331cac&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a86e74b06b88313272708988d89159b9&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a86e74b06b88313272708988d89159b9&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=11c978aaa0bcd7cd92da4ba4c7cd8561&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=11c978aaa0bcd7cd92da4ba4c7cd8561&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=fff3ba23236e3c617644abfbfba9d834&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=fff3ba23236e3c617644abfbfba9d834&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ae0d26f5dbaefb66d9a91150e2abb2dd&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ae0d26f5dbaefb66d9a91150e2abb2dd&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0fd0acb5c9e17f87e6786d58cd6440ea&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0fd0acb5c9e17f87e6786d58cd6440ea&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/parallel-quick-sort-in-erlang.html/feed</wfw:commentRss><description>快速排序是一种应用了“分治法”的算法，所谓分治法(divid &amp;#38; conquer)，就是把大的问题分割为结构相同的小问题，然后进行解决的方法。因为都是相同的小问题，所以我们可以利用并行计算来并行处理这些问题，使用Erlang可以非常方便非常清晰地利用这种方法解决问题。
由于Erlang是一种声明式、函数式编程语言，所以要表述基本的快速排序算法非常方便：
qsort(_, []) -&amp;#62; [];
qsort(F, [H&amp;#124;T]) -&amp;#62;
    qsort(F, [X &amp;#124;&amp;#124; X &amp;#60;- T, F(X, H)])
    ++ [H] ++
    qsort(F, [X &amp;#124;&amp;#124; X &amp;#60;- T, not F(X, H)]).

qsort(L) -&amp;#62; qsort(fun(X, Y) -&amp;#62; X &amp;#60; Y end, L).

其中F是一个用于比较的函数。这种描述方式非常精炼，不过效率不高，原因在于1. 不是尾递归, 2.  该代码中应用了两个列表领悟（ list comprehension ），其结果是对同一个列表进行了两次遍历。不过这些问题我们稍后考虑。
在erlang中，创建和维护进程是非常方便的，可以很容易地将以上的顺序算法变成创建单独的进程解决对每个子问题：
psort(Pid, _Fun, []) -&amp;#62; [...]&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=da4357ea70fe429c74a26aed4a7b91f5&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=da4357ea70fe429c74a26aed4a7b91f5&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=1c5e0281277f41a7a508ff0924331cac&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=1c5e0281277f41a7a508ff0924331cac&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a86e74b06b88313272708988d89159b9&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a86e74b06b88313272708988d89159b9&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=11c978aaa0bcd7cd92da4ba4c7cd8561&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=11c978aaa0bcd7cd92da4ba4c7cd8561&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=fff3ba23236e3c617644abfbfba9d834&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=fff3ba23236e3c617644abfbfba9d834&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ae0d26f5dbaefb66d9a91150e2abb2dd&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ae0d26f5dbaefb66d9a91150e2abb2dd&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0fd0acb5c9e17f87e6786d58cd6440ea&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0fd0acb5c9e17f87e6786d58cd6440ea&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>算法</category><category>erlang</category><category>快速排序</category><category>日记</category><category>并行</category><pubDate>Wed, 06 Aug 2008 09:44:04 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/parallel-quick-sort-in-erlang.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=194</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/parallel-quick-sort-in-erlang.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614405/1225462</fs:itemid></item><item><title>电信的宽带迁移更人性化了</title><link>http://shiningray.cn/dian-xin-de-kuan-dai-qian-yi-geng-ren-xing-hua-liao.html</link><content:encoded>&lt;p&gt;在上海搬了好几次家，每次都要把自己的宽带迁移，前几次电信的方法是这样的：交迁移手续费，并且将过去的欠帐结清，迁移到新的地址之后，帐号和密码都会重新更换，最奇怪的是当月到办理迁移当天剩下的钱却会重新有一个帐单寄到原来的地址，然而我肯定是不会回去拿那个帐单了。&lt;br /&gt;
而这一次非常方便，迁移手续费会直接算入下一个月的帐单中，并且也不需要更改帐号和密码了，很好。&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=27436ac2f7d5cdc13fca4896784a3278&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=27436ac2f7d5cdc13fca4896784a3278&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=7b53762b78a9b9631401d3353d348372&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=7b53762b78a9b9631401d3353d348372&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=dab90ddd24114fbe427a46e2be282c2a&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=dab90ddd24114fbe427a46e2be282c2a&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=55b657c514ea1a46a0b00c3eed83c5c5&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=55b657c514ea1a46a0b00c3eed83c5c5&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=fcbf542ea24c67159e6558841eae353f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=fcbf542ea24c67159e6558841eae353f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0d12ee68e79e599851e6cad929b4833d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0d12ee68e79e599851e6cad929b4833d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=37d93cf8736d29973531b588d289530f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=37d93cf8736d29973531b588d289530f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/dian-xin-de-kuan-dai-qian-yi-geng-ren-xing-hua-liao.html/feed</wfw:commentRss><description>在上海搬了好几次家，每次都要把自己的宽带迁移，前几次电信的方法是这样的：交迁移手续费，并且将过去的欠帐结清，迁移到新的地址之后，帐号和密码都会重新更换，最奇怪的是当月到办理迁移当天剩下的钱却会重新有一个帐单寄到原来的地址，然而我肯定是不会回去拿那个帐单了。
而这一次非常方便，迁移手续费会直接算入下一个月的帐单中，并且也不需要更改帐号和密码了，很好。&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=27436ac2f7d5cdc13fca4896784a3278&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=27436ac2f7d5cdc13fca4896784a3278&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=7b53762b78a9b9631401d3353d348372&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=7b53762b78a9b9631401d3353d348372&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=dab90ddd24114fbe427a46e2be282c2a&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=dab90ddd24114fbe427a46e2be282c2a&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=55b657c514ea1a46a0b00c3eed83c5c5&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=55b657c514ea1a46a0b00c3eed83c5c5&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=fcbf542ea24c67159e6558841eae353f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=fcbf542ea24c67159e6558841eae353f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0d12ee68e79e599851e6cad929b4833d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0d12ee68e79e599851e6cad929b4833d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=37d93cf8736d29973531b588d289530f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=37d93cf8736d29973531b588d289530f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>日记</category><pubDate>Mon, 04 Aug 2008 21:28:53 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/dian-xin-de-kuan-dai-qian-yi-geng-ren-xing-hua-liao.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=193</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/dian-xin-de-kuan-dai-qian-yi-geng-ren-xing-hua-liao.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614406/1225462</fs:itemid></item><item><title>Programming in Erlang</title><link>http://shiningray.cn/programming-in-erlang.html</link><content:encoded>&lt;p&gt;上上周搬了家，把宽带迁了，借着青黄不接的几天不能上网的光景，看完了&amp;#8221;&lt;a href=&quot;http://www.douban.com/subject/2011397/&quot;&gt;Programming in Erlang&lt;/a&gt;&amp;#8220;。&lt;/p&gt;
&lt;p&gt;Erlang是一门面向并发和分布式的编程语言。Programming in Erlang以非常浅显的语言，介绍了&lt;a href=&quot;http://www.erlang.org/&quot;&gt;Erlang&lt;/a&gt;的各个方面的基础，是一本合适的入门教材。作为入门教材，能够提到OTP的一些常用内容和常用的分布式设计的思想，已经非常不错了，加上书后的参考。我更感兴趣的是如何使用erlang来构建高并发、分布式系统，包括它的设计模式、部署模式等等，并没有在本书中涉及，非常关键的OTP、Mnesia也仅仅只涉及了一些基础。当然它还是给出了深入学习的途径。&lt;/p&gt;
&lt;p&gt;看完了本书，加上翻阅了一些资料，我对Erlang有了更深入的了解，也纠正了一些错误概念：&lt;/p&gt;
&lt;p&gt;过去曾认为Erlang就代表高并发，高并发就代表高性能，同时认为Erlang就只是高并发的代名词。其实，Erlang的并发性能也并非最强。首先Erlang的虚拟机是C写的，其次诸如Haskell、OCaml + &lt;a href=&quot;http://jocaml.inria.fr/&quot;&gt;JoCaml&lt;/a&gt;，以及Python的&lt;a href=&quot;http://codespeak.net/pypy/dist/pypy/doc/home.html&quot;&gt;PyPy&lt;/a&gt;，其实都能提供不弱于Erlang的并发能力。&lt;/p&gt;
&lt;p&gt;同时Erlang在顺序计算上的性能也不佳，甚至不能超过Python、Lua这类脚本语言（也许是和其本身的特殊性质有关）。所以就更落后于Haskell和OCaml这类可编译的语言。然而即使并发和并行也需要顺序计算，所以单从并发性能上来说，Erlang还不是最强的。&lt;/p&gt;
&lt;p&gt;Erlang写的Yaws这个Web服务器，虽然能承受高并发，但性能，尤其是IO性能依然无法与lighttpd、nginx这种C写的Web服务相比——Erlang的虚拟机本身也是C写的。&lt;/p&gt;
&lt;p&gt;同时，Erlang本身设计为一个结构化编程语言而非面向对象编程语言。这就令其较难应用更有开发效率的面向对象的项目开发流程和方法。&lt;/p&gt;
&lt;p&gt;那么为何Erlang在并发、分布式编程中如此受推崇？我认为因为它本身是并发和并行在语义、处理上的一致，所以它编写此类程序更加方便。同时，它提供的是一个关于并发、并行以及分布式的统一的解决方案，而不仅仅是高并发。它的目的是构建有容错能力、有伸缩性的可靠系统，同时又能最简化编程工作。这就是它的真正的优势。&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c56a0e224e306ebd4f3faf51aab29db1&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c56a0e224e306ebd4f3faf51aab29db1&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c33c96f7f8a0fa2996e6a9b5a8580fb3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c33c96f7f8a0fa2996e6a9b5a8580fb3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=4678d17f953e5755b486283381ce4f56&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=4678d17f953e5755b486283381ce4f56&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=9042fbd1ead334cb1357f14a492e4afb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=9042fbd1ead334cb1357f14a492e4afb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=5211b12be1a8a635260cf54c4273ee6d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=5211b12be1a8a635260cf54c4273ee6d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=77dba93b83550a41a41f43bc74cf59eb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=77dba93b83550a41a41f43bc74cf59eb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=47f579e629f569054366d97445b168a7&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=47f579e629f569054366d97445b168a7&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/programming-in-erlang.html/feed</wfw:commentRss><description>上上周搬了家，把宽带迁了，借着青黄不接的几天不能上网的光景，看完了&amp;#8221;Programming in Erlang&amp;#8220;。
Erlang是一门面向并发和分布式的编程语言。Programming in Erlang以非常浅显的语言，介绍了Erlang的各个方面的基础，是一本合适的入门教材。作为入门教材，能够提到OTP的一些常用内容和常用的分布式设计的思想，已经非常不错了，加上书后的参考。我更感兴趣的是如何使用erlang来构建高并发、分布式系统，包括它的设计模式、部署模式等等，并没有在本书中涉及，非常关键的OTP、Mnesia也仅仅只涉及了一些基础。当然它还是给出了深入学习的途径。
看完了本书，加上翻阅了一些资料，我对Erlang有了更深入的了解，也纠正了一些错误概念：
过去曾认为Erlang就代表高并发，高并发就代表高性能，同时认为Erlang就只是高并发的代名词。其实，Erlang的并发性能也并非最强。首先Erlang的虚拟机是C写的，其次诸如Haskell、OCaml + JoCaml，以及Python的PyPy，其实都能提供不弱于Erlang的并发能力。
同时Erlang在顺序计算上的性能也不佳，甚至不能超过Python、Lua这类脚本语言（也许是和其本身的特殊性质有关）。所以就更落后于Haskell和OCaml这类可编译的语言。然而即使并发和并行也需要顺序计算，所以单从并发性能上来说，Erlang还不是最强的。
Erlang写的Yaws这个Web服务器，虽然能承受高并发，但性能，尤其是IO性能依然无法与lighttpd、nginx这种C写的Web服务相比——Erlang的虚拟机本身也是C写的。
同时，Erlang本身设计为一个结构化编程语言而非面向对象编程语言。这就令其较难应用更有开发效率的面向对象的项目开发流程和方法。
那么为何Erlang在并发、分布式编程中如此受推崇？我认为因为它本身是并发和并行在语义、处理上的一致，所以它编写此类程序更加方便。同时，它提供的是一个关于并发、并行以及分布式的统一的解决方案，而不仅仅是高并发。它的目的是构建有容错能力、有伸缩性的可靠系统，同时又能最简化编程工作。这就是它的真正的优势。&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c56a0e224e306ebd4f3faf51aab29db1&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c56a0e224e306ebd4f3faf51aab29db1&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c33c96f7f8a0fa2996e6a9b5a8580fb3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c33c96f7f8a0fa2996e6a9b5a8580fb3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=4678d17f953e5755b486283381ce4f56&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=4678d17f953e5755b486283381ce4f56&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=9042fbd1ead334cb1357f14a492e4afb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=9042fbd1ead334cb1357f14a492e4afb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=5211b12be1a8a635260cf54c4273ee6d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=5211b12be1a8a635260cf54c4273ee6d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=77dba93b83550a41a41f43bc74cf59eb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=77dba93b83550a41a41f43bc74cf59eb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=47f579e629f569054366d97445b168a7&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=47f579e629f569054366d97445b168a7&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>erlang</category><category>书籍</category><category>介绍</category><pubDate>Mon, 04 Aug 2008 13:11:34 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/programming-in-erlang.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=192</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/programming-in-erlang.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614407/1225462</fs:itemid></item><item><title>Shanghai on rails 7月26日活动小记</title><link>http://shiningray.cn/shanghai-on-rails-7-yue-26-ri-huo-dong-xiao-ji.html</link><content:encoded>&lt;p&gt;第一次参加Shanghai on rails，不过因为搬家事宜，听完了三个演讲之后就立刻闪人了。&lt;/p&gt;
&lt;div style=&quot;padding: 1em 0pt; text-align: left;&quot;&gt;
&lt;div style=&quot;padding: 1em 0pt; text-align: left;&quot;&gt;&lt;img src=&quot;http://docs.google.com/File?id=ajbnmfjgsqzx_122gpx6h2fr_b&quot; width=&quot;312&quot; height=&quot;427&quot;&gt;&lt;br /&gt;高举旗帜
&lt;div style=&quot;padding: 1em 0pt; text-align: left;&quot;&gt;
&lt;div style=&quot;padding: 1em 0pt; text-align: left;&quot;&gt;&lt;img style=&quot;width: 320px; height: 240px;&quot; src=&quot;http://docs.google.com/File?id=ajbnmfjgsqzx_125gmwxfdcs_b&quot;&gt;伙食很重要&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;padding: 1em 0pt; text-align: left;&quot;&gt;&lt;img style=&quot;width: 320px; height: 426.667px;&quot; src=&quot;http://docs.google.com/File?id=ajbnmfjgsqzx_126hnpzcmfv_b&quot;&gt;&lt;br /&gt;
领导的指示也很重要&lt;/div&gt;
&lt;p&gt;&lt;b&gt;PPT分享：&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;a title=&quot;PPT of Role based Permission&quot; href=&quot;http://www.slideshare.net/wear/rolebasedpermissions/&quot; rel=&quot;nofollow&quot;&gt;PPT of Role based Permission&lt;/a&gt; &lt;br /&gt;给你点新思路&lt;/p&gt;
&lt;p&gt;&lt;a title=&quot;code_refactoring_javaeye_rails1.x_2.x&quot; href=&quot;http://www.slideshare.net/wear/code-refactoring-javaeye-rails1x-2x/&quot; rel=&quot;nofollow&quot;&gt;code_refactoring_javaeye_rails1.x_2.x&lt;/a&gt; &lt;br /&gt;都是干货&lt;/p&gt;
&lt;p&gt;&lt;a title=&quot;open social&quot; href=&quot;http://www.slideshare.net/stingchen/open-social-shaking-the-money-tree/&quot; rel=&quot;nofollow&quot;&gt;open social&lt;/a&gt; &lt;br /&gt;其实题目是‘shaking-the-money-tree’&lt;/p&gt;
&lt;p&gt;感谢Vibram，我们有了视频&lt;br /&gt;&lt;a href=&quot;http://www.tudou.com/playlist/id/4072842/&quot; rel=&quot;nofollow&quot;&gt;http://www.tudou.com/playlist/id/4072842/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
特别感谢：&lt;br /&gt;
演讲嘉宾，包括Javaeye,chinaonrails在内的所有rails社区. 还有，最重要的&lt;br /&gt;
我们的赞助商&lt;br /&gt;
易空海 http://www.ekohe.com/&lt;br /&gt;
ShellShadow http://www.shellshadow.com&lt;br /&gt;
结构数据公司 http://www.structuredcommons.com/&lt;br /&gt;
ELC Technologies http://elctech.com&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0130d3b1893164d1cf685d5b50aff4ce&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0130d3b1893164d1cf685d5b50aff4ce&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=d20e0a61c0d38468ea6c22f7e3a6430d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=d20e0a61c0d38468ea6c22f7e3a6430d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=6d4f6949b8017a187e2cc69df3518464&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=6d4f6949b8017a187e2cc69df3518464&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=1100301cc825fb2bb3e73a6bf733389f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=1100301cc825fb2bb3e73a6bf733389f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=badbe7e554ec155272f95db368c4036f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=badbe7e554ec155272f95db368c4036f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=e3f0580793fcaa4d95e20d4f404ca16d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=e3f0580793fcaa4d95e20d4f404ca16d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=534490baf86409e3d132e4159ba11f55&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=534490baf86409e3d132e4159ba11f55&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/shanghai-on-rails-7-yue-26-ri-huo-dong-xiao-ji.html/feed</wfw:commentRss><description>第一次参加Shanghai on rails，不过因为搬家事宜，听完了三个演讲之后就立刻闪人了。

高举旗帜

伙食很重要




领导的指示也很重要
PPT分享：
PPT of Role based Permission 给你点新思路
code_refactoring_javaeye_rails1.x_2.x 都是干货
open social 其实题目是‘shaking-the-money-tree’
感谢Vibram，我们有了视频http://www.tudou.com/playlist/id/4072842/

特别感谢：
演讲嘉宾，包括Javaeye,chinaonrails在内的所有rails社区. 还有，最重要的
我们的赞助商
易空海 http://www.ekohe.com/
ShellShadow http://www.shellshadow.com
结构数据公司 http://www.structuredcommons.com/
ELC Technologies http://elctech.com&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0130d3b1893164d1cf685d5b50aff4ce&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0130d3b1893164d1cf685d5b50aff4ce&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=d20e0a61c0d38468ea6c22f7e3a6430d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=d20e0a61c0d38468ea6c22f7e3a6430d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=6d4f6949b8017a187e2cc69df3518464&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=6d4f6949b8017a187e2cc69df3518464&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=1100301cc825fb2bb3e73a6bf733389f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=1100301cc825fb2bb3e73a6bf733389f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=badbe7e554ec155272f95db368c4036f&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=badbe7e554ec155272f95db368c4036f&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=e3f0580793fcaa4d95e20d4f404ca16d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=e3f0580793fcaa4d95e20d4f404ca16d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=534490baf86409e3d132e4159ba11f55&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=534490baf86409e3d132e4159ba11f55&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>日记</category><pubDate>Tue, 29 Jul 2008 13:01:36 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/shanghai-on-rails-7-yue-26-ri-huo-dong-xiao-ji.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=191</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/shanghai-on-rails-7-yue-26-ri-huo-dong-xiao-ji.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614408/1225462</fs:itemid></item><item><title>重叠、指针转换和gcc3.3</title><link>http://shiningray.cn/aliasing-pointer-casts-and-gcc-33.html</link><content:encoded>&lt;p&gt;&lt;a title=&quot;http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html&quot; href=&quot;http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html&quot; id=&quot;gg0b&quot;&gt;http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html&lt;/a&gt; &lt;br id=&quot;yphx&quot;&gt;&lt;br /&gt;
Subject: Aliasing, pointer casts and gcc 3.3.&lt;br id=&quot;hlfb&quot;&gt;&lt;br /&gt;
To: None &amp;lt;tech-kern@netbsd.org&amp;gt;&lt;br id=&quot;hlfb0&quot;&gt;&lt;br /&gt;
From: Krister Walfridsson &amp;lt;cato@df.lth.se&amp;gt;&lt;br id=&quot;hlfb1&quot;&gt;&lt;br /&gt;
List: tech-kern&lt;br id=&quot;hlfb2&quot;&gt;&lt;br /&gt;
Date: 08/11/2003 23:16:48&lt;br id=&quot;hlfb3&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb4&quot;&gt;&lt;br /&gt;
我见过一些用来“修复”gcc 3.3 别名警告的提交，这些并没有给我貌似温存的感觉，同时我总是在不同的邮件列表看到很多关于别名（一般来说是ISO C）概念的混淆，所以我尝试解释一些已经/将要困扰我们的一些问题。&lt;br id=&quot;hlfb11&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb12&quot;&gt;&lt;br /&gt;
如果本文太浅显，请包涵。&lt;br id=&quot;hlfb16&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;qk9q0&quot;&gt;重叠（ALIASING）&lt;br id=&quot;hlfb18&quot;&gt;&lt;br /&gt;
&lt;/h3&gt;
&lt;p&gt;什么是重叠？&lt;br id=&quot;hlfb20&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb21&quot;&gt;&lt;br /&gt;
从硬件的角度来看指针的话，指针可以指向任何内存地址，所以通过指针写入可以更改程序中的任何变量：&lt;br id=&quot;hlfb25&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;j0ls&quot;&gt;&lt;p&gt;&lt;span id=&quot;j0ls0&quot; style=&quot;font-family: Courier New;&quot;&gt;int i = 23;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb26&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls1&quot; style=&quot;font-family: Courier New;&quot;&gt;*f = 5;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb27&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls2&quot; style=&quot;font-family: Courier New;&quot;&gt;/* 这时候我们不能确定i是什么值。 */&lt;/span&gt;&lt;br id=&quot;hlfb28&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;我们无法得知i的值，因为指针&amp;amp;i和f可能指向同一个地址（这就是当ISO C说&amp;amp;i与f可能重叠时所表达的意思）。&lt;br id=&quot;hlfb32&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb33&quot;&gt;&lt;br /&gt;
这样就使很多类型的优化无法进行，同时它也确实造成了实实在在的区别，因为现实情况中多数指针是不会指向同一个位置的。ISO C通过（大致）说“不同类型的指针不能指向同一个地址”来（针对编译器）改进了这个情况。&lt;br id=&quot;hlfb39&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;j0ls3&quot;&gt;&lt;p&gt;&lt;span id=&quot;j0ls4&quot; style=&quot;font-family: Courier New;&quot;&gt;int&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb40&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls5&quot; style=&quot;font-family: Courier New;&quot;&gt;foo(float *f) {&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb41&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls6&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i = 23;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb42&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls7&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *f = 5.0;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb43&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls8&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* float* 不能和 int* 指向同一个地址。 */&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb44&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls9&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return i * 2;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb45&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;j0ls10&quot; style=&quot;font-family: Courier New;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb46&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;这样，编译起可以将其优化为：&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb49&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;hw3-&quot;&gt;&lt;p&gt;&lt;span id=&quot;hw3-0&quot; style=&quot;font-family: Courier New;&quot;&gt;int&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb50&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;hw3-1&quot; style=&quot;font-family: Courier New;&quot;&gt;foo(float *f) {&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb51&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;hw3-2&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *f = 5.0;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb52&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;hw3-3&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 46;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb53&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;hw3-4&quot; style=&quot;font-family: Courier New;&quot;&gt;}&lt;/span&gt;&lt;br id=&quot;hlfb54&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The ISO标准并不完全阻止指针指向同一个地址——它指定了当你提领指向一个不同（不兼容）类型的对象的指针时，结果是不确定的。所以以下例子也是可行的： &lt;br id=&quot;hlfb60&quot;&gt;&lt;/p&gt;
&lt;blockquote style=&quot;font-family: Courier New;&quot; id=&quot;kmlu&quot;&gt;&lt;p&gt;int i = 23, *tmp;&lt;br id=&quot;hlfb61&quot;&gt;&lt;br /&gt;
tmp = (int*)f;&lt;br id=&quot;hlfb62&quot;&gt;&lt;br /&gt;
*tmp = 5;&lt;br id=&quot;hlfb63&quot;&gt;&lt;br /&gt;
/* 我们无法确定i现在的值。 */&lt;br id=&quot;hlfb64&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;不过注意，我们实际上在内存中按照“int”写入而非按照“float”。&lt;br id=&quot;hlfb68&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb69&quot;&gt;&lt;br /&gt;
然而以上规则有一个非常重要的例外： char* 可以重叠任何类型（如果ISO阻止这点，那么太多的代码就会坏掉……）&lt;br id=&quot;hlfb72&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb73&quot;&gt;&lt;br /&gt;
很多情况下你还是想以不同的类型来访问同一个地址：&lt;br id=&quot;hlfb76&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;zbdp&quot; style=&quot;font-family: Courier New;&quot;&gt;&lt;p&gt;float *f = 2.718;&lt;br id=&quot;hlfb77&quot;&gt;&lt;br /&gt;
printf(&amp;#8221;The memory word has value 0x%08x\n&amp;#8221;, *((int*)f));&lt;br id=&quot;hlfb78&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;在ISO C中，你不能这么做，但是gcc在这里会进行一个扩展，认为内存中存在一个有多个类型的联合体，所以以下代码可以在gcc中运行（但不能保证在其他编译器中也可以运行！）&lt;br id=&quot;hlfb83&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;zbdp0&quot;&gt;&lt;p&gt;&lt;span id=&quot;zbdp1&quot; style=&quot;font-family: Courier New;&quot;&gt;union {&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb84&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;zbdp2&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb85&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;zbdp3&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; float f;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb86&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;zbdp4&quot; style=&quot;font-family: Courier New;&quot;&gt;} u;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb87&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;zbdp5&quot; style=&quot;font-family: Courier New;&quot;&gt;u.f = 2.718;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb88&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;zbdp6&quot; style=&quot;font-family: Courier New;&quot;&gt;printf(&amp;#8221;The memory word has value 0x%08x\n&amp;#8221;, u.i);&lt;/span&gt;&lt;br id=&quot;hlfb89&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;有个副作用是当你使用很多联合体构造时，gcc可能会损失很多优化。&lt;br id=&quot;hlfb93&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb94&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;rbp-&quot;&gt;标准是如何说的[*]&lt;/h3&gt;
&lt;p&gt;第6.5条（表达式）陈述了重叠规则：&lt;br id=&quot;hlfb98&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb99&quot;&gt;&lt;br /&gt;
&amp;nbsp;7 一个对象只允许通过有以下类型之一的左值表达式来访问对象存储的值：{脚注73}&lt;br id=&quot;hlfb100&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb101&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 一种与该对象的有效类型相兼容的类型，&lt;br id=&quot;hlfb102&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb103&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 一种与该对象的有效类型相兼容的类型的正规版本，&lt;br id=&quot;hlfb104&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb105&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 一种与该对象的有效类型相对应的有符号或无符号类型，&lt;br id=&quot;hlfb106&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb107&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 一种与该对象的有效类型相兼容的类型的正规版本相对应的有符号或无符号类型，&lt;br id=&quot;hlfb108&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb109&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 一种聚合或联合类型包含了上述类型之一成员（包括递归的子聚合或被包含的联合体），或者&lt;br id=&quot;hlfb110&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb111&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 一种字符类型。&lt;br id=&quot;hlfb112&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br id=&quot;hlfb113&quot;&gt;&lt;br /&gt;
&amp;nbsp;{脚注73} 该列表的意图是指定哪些情况下，对象可能或可能不被重叠。&lt;br id=&quot;hlfb114&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb115&quot;&gt;&lt;br /&gt;
&amp;nbsp;7 An object shall have its stored value accessed only by an lvalue&lt;br id=&quot;hlfb116&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; expression that has one of the following types: {footnote 73}&lt;br id=&quot;hlfb117&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb118&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a type compatible with the effective type of the object,&lt;br id=&quot;hlfb119&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb120&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a qualified version of a type compatible with the effective type of&lt;br id=&quot;hlfb121&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the object,&lt;br id=&quot;hlfb122&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb123&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a type that is the signed or unsigned type corresponding to the&lt;br id=&quot;hlfb124&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; effective type of the object,&lt;br id=&quot;hlfb125&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb126&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a type that is the signed or unsigned type corresponding to a&lt;br id=&quot;hlfb127&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qualified version of the effective type of the object,&lt;br id=&quot;hlfb128&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb129&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; an aggregate or union type that includes one of the aforementioned&lt;br id=&quot;hlfb130&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; types among its members (including, recursively, a member of a&lt;br id=&quot;hlfb131&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subaggregate or contained union), or&lt;br id=&quot;hlfb132&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb133&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a character type.&lt;br id=&quot;hlfb134&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb135&quot;&gt;&lt;br /&gt;
&amp;nbsp;{footnote 73} The intent of this list is to specify those circumstances&lt;br id=&quot;hlfb136&quot;&gt;&lt;br /&gt;
&amp;nbsp;in which an object may or may not be aliased.&lt;br id=&quot;hlfb140&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;y:d6&quot;&gt;gcc的警告&lt;br id=&quot;hlfb142&quot;&gt;&lt;br /&gt;
&lt;/h3&gt;
&lt;p&gt;gcc会警告某些可能会破坏重叠规则的构造，但不是所有（甚至大部分都没有警告），所以没有出现警告的源代码并不能给你任何担保。&lt;br id=&quot;hlfb143&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb144&quot;&gt;&lt;br /&gt;
最常见的警告可能是“提领类型双关的指针将破坏强重叠规则”（dereferencing type-punned pointer will break strict-aliasing rules）。它给出警告的位置一般来说是不会错的——gcc想告诉你的是当你提领了指针后，你可能会破坏重叠规则（除非你首先将它转换为原始类型）。该警告应该解释为，你的接口可能设计得很差，同时正确避免该警告的方式是重新以一种无须在相冲突的类型之间转换的方式重新设计他们。（即使你可以通过将void**改成void*来绕过这个警告）&lt;br id=&quot;hlfb146&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb147&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;y:d60&quot;&gt;指针转换和对齐&lt;/h2&gt;
&lt;h3 id=&quot;y:d61&quot;&gt;问题&lt;/h3&gt;
&lt;p&gt;很多架构都要求指针在访问大于一个字节的对象时能够正确对齐。然而系统代码中很多地方你只能接受到未对齐的数据（如，网络栈），所以你需要更正它：&lt;br id=&quot;hlfb157&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb158&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;y:d62&quot;&gt;&lt;p&gt;&lt;span id=&quot;y:d63&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char* data;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb159&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;y:d64&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct foo_header *tmp, header;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb160&quot;&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb161&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;y:d65&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp = data + offset;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb162&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;y:d66&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;header, tmp, sizeof(header));&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb163&quot;&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb164&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;y:d67&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (header.len &amp;lt; FOO)&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb165&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;y:d68&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [...]&lt;/span&gt;&lt;br id=&quot;hlfb166&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;br id=&quot;hlfb167&quot;&gt;&lt;br /&gt;
然而这是无效的……原因是当你将一个未对齐的值赋给指向需要进行对齐的类型的指针的时候，行为是不确定的。在以上例子中所发生的是，gcc注意到tmp和header必须被对齐，所以它可能会使用了一个内联的memcpy，它用到了假设数据已对齐的指令。&lt;br id=&quot;hlfb173&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb174&quot;&gt;&lt;br /&gt;
正确的修正方式是不使用foo_header指针。&lt;br id=&quot;hlfb177&quot;&gt;&lt;/p&gt;
&lt;blockquote id=&quot;mibn&quot;&gt;&lt;p&gt;&lt;span id=&quot;mibn0&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char* data;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb178&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;mibn1&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct foo_header header;&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb179&quot;&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb180&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;mibn2&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;header, data + offset, sizeof(header));&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb181&quot;&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb182&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;mibn3&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (header.len &amp;lt; FOO)&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb183&quot;&gt;&lt;br /&gt;
&lt;span id=&quot;mibn4&quot; style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [...]&lt;/span&gt;&lt;br style=&quot;font-family: Courier New;&quot; id=&quot;hlfb184&quot;&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;上面的例子可能看上去比较傻，但确实是让我们好几次头疼……&lt;br id=&quot;hlfb186&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb187&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb188&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb189&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;mibn5&quot;&gt;标准是如何说的[*]&lt;/h3&gt;
&lt;p&gt;在第6.3.2.3条（指针）中陈述了指针对齐要求：&lt;br id=&quot;hlfb192&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb193&quot;&gt;&lt;br /&gt;
&amp;nbsp;7 [...]指向某个对象或者不完全类型的指针可以被转换成指向另一个不同对象或者不完全类型的指针。如果得到的指针没有针对所指向的对象被正确地对齐{脚注57}，行为是无法确定的。否则，当转换回去时，结果应该与原始指针相同。[...]&lt;br id=&quot;mibn6&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb199&quot;&gt;&lt;br /&gt;
&amp;nbsp;{footnote 57} 一般来说，“被正确对齐”的概念是传递的：如果一个指向A类型的指针被正确为指向B类型的指针进行对齐，同时指向B类型的指针又是正确为一个指向C类型的指针对齐的，那么指向A类型的指针则是针对指向C类型的指针正确对齐的。&lt;br id=&quot;mibn7&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb205&quot;&gt;&lt;br /&gt;
&amp;nbsp;7 A pointer to an object or incomplete type may be converted to a pointer&lt;br id=&quot;hlfb206&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; to a different object or incomplete type. If the resulting pointer is&lt;br id=&quot;hlfb207&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; not correctly aligned {footnote 57} for the pointed-to type, the&lt;br id=&quot;hlfb208&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; behavior is undefined. Otherwise, when converted back again, the result&lt;br id=&quot;hlfb209&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; shall compare equal to the original pointer. [...]&lt;br id=&quot;hlfb210&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb211&quot;&gt;&lt;br /&gt;
&amp;nbsp;{footnote 57} In general, the concept &amp;#8220;correctly aligned&amp;#8221; is transitive:&lt;br id=&quot;hlfb212&quot;&gt;&lt;br /&gt;
&amp;nbsp;if a pointer to type A is correctly aligned for a pointer to type B,&lt;br id=&quot;hlfb213&quot;&gt;&lt;br /&gt;
&amp;nbsp;which in turn is correctly aligned for a pointer to type C, then a&lt;br id=&quot;hlfb214&quot;&gt;&lt;br /&gt;
&amp;nbsp;pointer to type A is correctly aligned for a pointer to type C.&lt;br id=&quot;hlfb215&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb216&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb217&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb218&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb219&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;mibn8&quot;&gt;总结&lt;/h2&gt;
&lt;p&gt;ISO C已经不是爷爷用的C了，同时把它认为是一种高级机器语言的想法也是错的……&lt;br id=&quot;hlfb222&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb223&quot;&gt;&lt;br /&gt;
指针转换非常不和谐（无论是显式还是隐式转换），同时你必须在给代码加入指针转换前三思。&lt;br id=&quot;hlfb224&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb225&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb226&quot;&gt;&lt;br /&gt;
[*] 标准引用来自ISO/IEC 9899:1999，不过老的ANSI/ISO标准基本上说的一样。&lt;br id=&quot;hlfb227&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb228&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb229&quot;&gt;&lt;br /&gt;
作者：Krister，翻译：&lt;a title=&quot;ShiningRay&quot; href=&quot;http://shiningray.cn/&quot; id=&quot;jqw.&quot;&gt;ShiningRay&lt;/a&gt; &lt;br id=&quot;hlfb230&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;hlfb231&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;tdlx&quot;&gt;&lt;br /&gt;
&lt;br id=&quot;nxav&quot;&gt;&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ce734fbde9408ce8a873351b992d2133&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ce734fbde9408ce8a873351b992d2133&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=9680d2c8f1243108785c346cfe4f9fcb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=9680d2c8f1243108785c346cfe4f9fcb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=173fb5c3c5d01ea418913b589ec1a545&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=173fb5c3c5d01ea418913b589ec1a545&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c97daf574537ad0158d3cce8d6c300f3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c97daf574537ad0158d3cce8d6c300f3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a5156b6792b1a1d561d6551c9671c749&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a5156b6792b1a1d561d6551c9671c749&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=9cfd252a7d1d85e672b482ab55eebbc3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=9cfd252a7d1d85e672b482ab55eebbc3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=f09a5ce3272a6af39f84cf5764048d24&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=f09a5ce3272a6af39f84cf5764048d24&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/aliasing-pointer-casts-and-gcc-33.html/feed</wfw:commentRss><description>http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html 
Subject: Aliasing, pointer casts and gcc 3.3.
To: None &amp;#60;tech-kern@netbsd.org&amp;#62;
From: Krister Walfridsson &amp;#60;cato@df.lth.se&amp;#62;
List: tech-kern
Date: 08/11/2003 23:16:48

我见过一些用来“修复”gcc 3.3 别名警告的提交，这些并没有给我貌似温存的感觉，同时我总是在不同的邮件列表看到很多关于别名（一般来说是ISO C）概念的混淆，所以我尝试解释一些已经/将要困扰我们的一些问题。

如果本文太浅显，请包涵。
重叠（ALIASING）

什么是重叠？

从硬件的角度来看指针的话，指针可以指向任何内存地址，所以通过指针写入可以更改程序中的任何变量：
int i = 23;
*f = 5;
/* 这时候我们不能确定i是什么值。 */

我们无法得知i的值，因为指针&amp;#38;i和f可能指向同一个地址（这就是当ISO C说&amp;#38;i与f可能重叠时所表达的意思）。

这样就使很多类型的优化无法进行，同时它也确实造成了实实在在的区别，因为现实情况中多数指针是不会指向同一个位置的。ISO C通过（大致）说“不同类型的指针不能指向同一个地址”来（针对编译器）改进了这个情况。
int
foo(float *f) {
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int i = 23;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *f = 5.0;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /* float* 不能和 int* 指向同一个地址。 */
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return i * 2;
}

这样，编译起可以将其优化为：
int
foo(float *f) {
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *f = 5.0;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return 46;
}

The ISO标准并不完全阻止指针指向同一个地址——它指定了当你提领指向一个不同（不兼容）类型的对象的指针时，结果是不确定的。所以以下例子也是可行的： [...]&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=ce734fbde9408ce8a873351b992d2133&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=ce734fbde9408ce8a873351b992d2133&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=9680d2c8f1243108785c346cfe4f9fcb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=9680d2c8f1243108785c346cfe4f9fcb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=173fb5c3c5d01ea418913b589ec1a545&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=173fb5c3c5d01ea418913b589ec1a545&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c97daf574537ad0158d3cce8d6c300f3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c97daf574537ad0158d3cce8d6c300f3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a5156b6792b1a1d561d6551c9671c749&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a5156b6792b1a1d561d6551c9671c749&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=9cfd252a7d1d85e672b482ab55eebbc3&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=9cfd252a7d1d85e672b482ab55eebbc3&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=f09a5ce3272a6af39f84cf5764048d24&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=f09a5ce3272a6af39f84cf5764048d24&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>日记</category><pubDate>Wed, 23 Jul 2008 15:12:20 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/aliasing-pointer-casts-and-gcc-33.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/190.html</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/aliasing-pointer-casts-and-gcc-33.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614409/1225462</fs:itemid></item><item><title>提领类型双关的指针将破坏强重叠规则</title><link>http://shiningray.cn/ti-ling-lei-xing-shuang-guan-de-zhi-zhen-jiang-po-huai-qiang-zhong-die-gui-ze.html</link><content:encoded>&lt;p&gt;最近复习C/C++，今日用&lt;a href=&quot;http://apr.apache.org/&quot;&gt;APR&lt;/a&gt;编写了一个生产/消费模型的小程序。结果出现了这样一个奇怪的警告：“提领类型双关的指针将破坏强重叠规则”，让我大惑不解，特此和大家讨论一下。&lt;/p&gt;
&lt;p&gt;我用的是gcc 版本 4.2.3 (Ubuntu 4.2.3-2ubuntu7) 线程模型：posix。出现警告的这段是这样的：&lt;/p&gt;
&lt;pre lang=&quot;c&quot;&gt;
    apr_queue_t *queue = (apr_queue_t *) data;
    int *d = NULL;
    while(1){
        apr_queue_pop(queue, (void **)(&amp;#038;d)); // －－ 此处为出现警告的地方。
        printf(&quot;Consumed: %d\n&quot;, *d);
    }
&lt;/pre&gt;
&lt;p&gt;虽然可以运行无误，但该警告还是让我比较无奈，最后我改成了如下：&lt;/p&gt;
&lt;pre lang=&quot;c&quot;&gt;
    apr_queue_t *queue = (apr_queue_t *) data;
    int *d = NULL;
    void *c = NULL;
    while(1){
        apr_queue_pop(queue, &amp;#038;c);
        d = (int *)c;
        printf(&quot;Consumed: %d\n&quot;, *d);
    }
&lt;/pre&gt;
&lt;p&gt;因为很久没有写C，在这里，我的问题是：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;什么叫做“提领类型双关的指针”？&lt;/li&gt;
&lt;li&gt;什么是“强重叠规则”？&lt;/li&gt;
&lt;li&gt;为什么会破坏？&lt;/li&gt;
&lt;li&gt;破坏之后会引发什么问题？&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;希望有C/C++达人能解决我这些疑问，谢谢。&lt;/p&gt;
&lt;p&gt;附源代码：&lt;a href='http://shiningray.cn/wp-content/uploads/2008/07/main.c'&gt;main.c&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=6e25d9a4858f0baaaf0d9d3f2dfc3182&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=6e25d9a4858f0baaaf0d9d3f2dfc3182&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=575641680a5b9c22243c006f2bddbfa6&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=575641680a5b9c22243c006f2bddbfa6&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=7d2ebb6f12c8e6049ea4c4a3403aac31&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=7d2ebb6f12c8e6049ea4c4a3403aac31&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c6c22485ec6e32e9ed15f34395623542&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c6c22485ec6e32e9ed15f34395623542&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=236e968b2a05cc83513ce2462811d955&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=236e968b2a05cc83513ce2462811d955&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=fd91597785de7f19d10a7f7a1b7fa872&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=fd91597785de7f19d10a7f7a1b7fa872&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=8fdd7f296afbc9dc6a425b1929b96579&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=8fdd7f296afbc9dc6a425b1929b96579&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/ti-ling-lei-xing-shuang-guan-de-zhi-zhen-jiang-po-huai-qiang-zhong-die-gui-ze.html/feed</wfw:commentRss><description>最近复习C/C++，今日用APR编写了一个生产/消费模型的小程序。结果出现了这样一个奇怪的警告：“提领类型双关的指针将破坏强重叠规则”，让我大惑不解，特此和大家讨论一下。
我用的是gcc 版本 4.2.3 (Ubuntu 4.2.3-2ubuntu7) 线程模型：posix。出现警告的这段是这样的：

    apr_queue_t *queue = (apr_queue_t *) data;
    int *d = NULL;
    while(1){
        apr_queue_pop(queue, (void **)(&amp;#038;d)); // －－ 此处为出现警告的地方。
        printf(&quot;Consumed: %d\n&quot;, *d);
    }

虽然可以运行无误，但该警告还是让我比较无奈，最后我改成了如下：

   [...]&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=6e25d9a4858f0baaaf0d9d3f2dfc3182&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=6e25d9a4858f0baaaf0d9d3f2dfc3182&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=575641680a5b9c22243c006f2bddbfa6&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=575641680a5b9c22243c006f2bddbfa6&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=7d2ebb6f12c8e6049ea4c4a3403aac31&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=7d2ebb6f12c8e6049ea4c4a3403aac31&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=c6c22485ec6e32e9ed15f34395623542&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=c6c22485ec6e32e9ed15f34395623542&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=236e968b2a05cc83513ce2462811d955&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=236e968b2a05cc83513ce2462811d955&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=fd91597785de7f19d10a7f7a1b7fa872&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=fd91597785de7f19d10a7f7a1b7fa872&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=8fdd7f296afbc9dc6a425b1929b96579&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=8fdd7f296afbc9dc6a425b1929b96579&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>C</category><category>备忘</category><category>警告</category><category>gcc</category><pubDate>Fri, 18 Jul 2008 11:54:13 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/ti-ling-lei-xing-shuang-guan-de-zhi-zhen-jiang-po-huai-qiang-zhong-die-gui-ze.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=186</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/ti-ling-lei-xing-shuang-guan-de-zhi-zhen-jiang-po-huai-qiang-zhong-die-gui-ze.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614410/1225462</fs:itemid></item><item><title>关于《浅析Rails部署》</title><link>http://shiningray.cn/guan-yu-qian-xi-rails-bu-shu.html</link><content:encoded>&lt;p&gt;我之前写的文章《&lt;a href=&quot;http://shiningray.cn/ruby-on-rails-deployment-schemes.html&quot;&gt;浅析Ruby on Rails部署方案&lt;/a&gt;》受到不少同学的关注，在此首先感谢大家。&lt;/p&gt;
&lt;p&gt;但是也有同学对此提出了一些疑问，我经过检查，发现文章确实存在很多漏洞和不足：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Lighttpd作为负载均衡反向代理时，无论是链接FastCGI还是HTTP后端，KeepAlive链接默认都是关闭的&lt;/li&gt;
&lt;li&gt;Nginx的FastCGI模式，默认也是关闭持久链接的&lt;/li&gt;
&lt;li&gt;缺少了一些重要的前后端搭配的方式&lt;/li&gt;
&lt;li&gt;对于Rails应用的内存占用也应该考虑在内&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;我会针对这一些问题，重新设计测试案例，并重写该文章。再次感谢大家的关注。&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=dea57c27d9d06a4d8e95aff8824a81b8&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=dea57c27d9d06a4d8e95aff8824a81b8&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=79d644f1d865cb0dc4457d478acf2a1d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=79d644f1d865cb0dc4457d478acf2a1d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=f2b4e4496945427cc7f34c823a8878f4&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=f2b4e4496945427cc7f34c823a8878f4&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=cf7d9bea586fa1b7c51b25c2be3dfb79&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=cf7d9bea586fa1b7c51b25c2be3dfb79&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=dab5741279ef4e5cb867d21c67980a54&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=dab5741279ef4e5cb867d21c67980a54&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0882cc3a8bcadb0cfef7c6d4080b1c84&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0882cc3a8bcadb0cfef7c6d4080b1c84&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=756b56f34a1a3e94102e5add1f6d2c3e&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=756b56f34a1a3e94102e5add1f6d2c3e&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/guan-yu-qian-xi-rails-bu-shu.html/feed</wfw:commentRss><description>我之前写的文章《浅析Ruby on Rails部署方案》受到不少同学的关注，在此首先感谢大家。
但是也有同学对此提出了一些疑问，我经过检查，发现文章确实存在很多漏洞和不足：

Lighttpd作为负载均衡反向代理时，无论是链接FastCGI还是HTTP后端，KeepAlive链接默认都是关闭的
Nginx的FastCGI模式，默认也是关闭持久链接的
缺少了一些重要的前后端搭配的方式
对于Rails应用的内存占用也应该考虑在内

我会针对这一些问题，重新设计测试案例，并重写该文章。再次感谢大家的关注。&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=dea57c27d9d06a4d8e95aff8824a81b8&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=dea57c27d9d06a4d8e95aff8824a81b8&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=79d644f1d865cb0dc4457d478acf2a1d&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=79d644f1d865cb0dc4457d478acf2a1d&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=f2b4e4496945427cc7f34c823a8878f4&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=f2b4e4496945427cc7f34c823a8878f4&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=cf7d9bea586fa1b7c51b25c2be3dfb79&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=cf7d9bea586fa1b7c51b25c2be3dfb79&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=dab5741279ef4e5cb867d21c67980a54&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=dab5741279ef4e5cb867d21c67980a54&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=0882cc3a8bcadb0cfef7c6d4080b1c84&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=0882cc3a8bcadb0cfef7c6d4080b1c84&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=756b56f34a1a3e94102e5add1f6d2c3e&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=756b56f34a1a3e94102e5add1f6d2c3e&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>部署</category><category>日记</category><category>ruby</category><category>rails</category><pubDate>Fri, 11 Jul 2008 14:18:08 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/guan-yu-qian-xi-rails-bu-shu.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=184</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/guan-yu-qian-xi-rails-bu-shu.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614411/1225462</fs:itemid></item><item><title>php shell</title><link>http://shiningray.cn/php-shell.html</link><content:encoded>&lt;p&gt;本文要讲的php shell并非是使用php来写shell脚本，而是讲一个php的&lt;a href=&quot;http://en.wikipedia.org/wiki/Read-eval-print_loop&quot;&gt;REPL&lt;/a&gt;的交互式shell。所谓REPL，也就是read-eval-print-loop，也就是说，shell读入一个指令，计算，然后输出结果，常见的有Python、Ruby的IRB等。&lt;/p&gt;
&lt;p&gt;对于PHP，我们常常会写一个test.php，然后放入一些自己的代码，再打开浏览器检验一下，如果不对，又要重新修改代码，非常麻烦。交互式shell的好处就可以体现出来了，输入指令之后可以立刻看到执行代码的结果，所以非常适合用来检验代码片段（snippets）的正确性以及进行一些试验。&lt;/p&gt;
&lt;p&gt;PHP本身自带一个交互式的shell，在命令行中输入php -i，便可以交互式运行，但要先输入一个php脚本的起始标签，但是该shell遇到异常的时候会直接退出，非常不方便。那么我找到一个非常接近于REPL的交互式shell便是&lt;a href=&quot;http://jan.kneschke.de/projects/php-shell&quot;&gt;php-shell&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br /&gt;
1. 安装&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;php-shell要求php 5.0以上版本&lt;/p&gt;
&lt;p&gt;下载&lt;a href=&quot;http://jan.kneschke.de/assets/2007/2/17/PHP_Shell-0.3.1.tgz&quot;&gt;PHP_Shell-0.3.1.tgz&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;运行pear install PHP_Shell-0.3.1.tgz&lt;/p&gt;
&lt;p&gt;如果确保pear已经安装，并在你的PATH路径中&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. 使用方法&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;在命令行下输入php-shell（Linux为php-shell.sh）进入交互式命令行：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
PHP-Shell - Version 0.3.1, with readline() support
(c) 2006, Jan Kneschke &amp;lt;jan@kneschke.de&amp;gt;

&amp;gt;&amp;gt; use '?' to open the inline help 

&amp;gt;&amp;gt;
 &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这时候我们可以输入我们所需的表达式了，在php-shell中直接输入变量名，它也可以将内容直接打印出来：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; $a = new ArrayObject( )
ArrayObject::__set_state(array(
))
&amp;gt;&amp;gt; $a-&amp;gt;
__construct(
append(
count(
exchangeArray(
getArrayCopy(
getFlags(
getIterator(
getIteratorClass(
offsetExists(
offsetGet(
offsetSet(
offsetUnset(
setFlags(
setIteratorClass(
&amp;gt;&amp;gt; $a-&amp;gt;append( 'a' )

&amp;gt;&amp;gt; $a-&amp;gt;count( )
1
&amp;gt;&amp;gt; $a-&amp;gt;offsetGet( 0 )
'a'&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;当出现异常时，php-shell也会打印出异常的内容。&lt;br /&gt;
你可以使用exit退出。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Tab补全&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;php-shell一个强大的功能是支持补全，以下内容可以被补全：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;new 类名()&lt;/li&gt;
&lt;li&gt;类名::方法名()&lt;/li&gt;
&lt;li&gt;类名::常量名&lt;/li&gt;
&lt;li&gt;$变量名&lt;/li&gt;
&lt;li&gt;函数名()&lt;/li&gt;
&lt;li&gt;$object-&amp;gt;方法名()&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;请先输入第一个字符然后按TAB按钮。如果只有一种匹配，它便会直接补全名称，否则，再按一次TAB会列出所有的可能性。&lt;/p&gt;
&lt;p&gt;如果你想查看所有已声明的类，你可以使用 getdeclaredclasses()：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; get_&amp;lt;TAB&amp;gt;
&amp;gt;&amp;gt; get_&amp;lt;TAB&amp;gt;&amp;lt;TAB&amp;gt;
get_browser(
...
get_declared_classes(
...
get_resource_type(
&amp;gt;&amp;gt; get_dec&amp;lt;TAB&amp;gt;
&amp;gt;&amp;gt; get_declared_&amp;lt;TAB&amp;gt;&amp;lt;TAB&amp;gt;
get_declared_classes(
get_declared_interfaces(
get_defined_constants(
get_defined_functions(
get_defined_vars(
&amp;gt;&amp;gt; get_declared_classes( )
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;4. 总结&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;如果是php新手，希望php-shell能帮你快速掌握php。老手也可以用其来检验代码段。&lt;/p&gt;
&lt;p&gt;除此之外，也可以尝试一下基于Web页面的php shell，如&lt;a href=&quot;http://phpshell.sf.net/&quot;&gt;http://phpshell.sf.net/&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=f45163fbf1a81deea19284d771462105&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=f45163fbf1a81deea19284d771462105&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=24c3f0892ddfc2211975eee7a3065986&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=24c3f0892ddfc2211975eee7a3065986&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=e5a64a3993a1804028607dcce6edd1c6&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=e5a64a3993a1804028607dcce6edd1c6&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a992c7a52aeb2182d4b4839bddc736ee&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a992c7a52aeb2182d4b4839bddc736ee&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=eeb86863530890c8e754fc0573fc18cb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=eeb86863530890c8e754fc0573fc18cb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=429b12ffba0e7883a80a89d559426b7e&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=429b12ffba0e7883a80a89d559426b7e&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a6299e05a59c9631de45af4a60dfe1a8&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a6299e05a59c9631de45af4a60dfe1a8&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</content:encoded><wfw:commentRss>http://shiningray.cn/php-shell.html/feed</wfw:commentRss><description>本文要讲的php shell并非是使用php来写shell脚本，而是讲一个php的REPL的交互式shell。所谓REPL，也就是read-eval-print-loop，也就是说，shell读入一个指令，计算，然后输出结果，常见的有Python、Ruby的IRB等。
对于PHP，我们常常会写一个test.php，然后放入一些自己的代码，再打开浏览器检验一下，如果不对，又要重新修改代码，非常麻烦。交互式shell的好处就可以体现出来了，输入指令之后可以立刻看到执行代码的结果，所以非常适合用来检验代码片段（snippets）的正确性以及进行一些试验。
PHP本身自带一个交互式的shell，在命令行中输入php -i，便可以交互式运行，但要先输入一个php脚本的起始标签，但是该shell遇到异常的时候会直接退出，非常不方便。那么我找到一个非常接近于REPL的交互式shell便是php-shell

1. 安装
php-shell要求php 5.0以上版本
下载PHP_Shell-0.3.1.tgz
运行pear install PHP_Shell-0.3.1.tgz
如果确保pear已经安装，并在你的PATH路径中
2. 使用方法
在命令行下输入php-shell（Linux为php-shell.sh）进入交互式命令行：

PHP-Shell - Version 0.3.1, with readline() support
(c) 2006, Jan Kneschke &amp;#60;jan@kneschke.de&amp;#62;

&amp;#62;&amp;#62; use '?' to open the inline help 

&amp;#62;&amp;#62;
 
这时候我们可以输入我们所需的表达式了，在php-shell中直接输入变量名，它也可以将内容直接打印出来：
&amp;#62;&amp;#62; $a = new ArrayObject( )
ArrayObject::__set_state(array(
))
&amp;#62;&amp;#62; $a-&amp;#62;
__construct(
append(
count(
exchangeArray(
getArrayCopy(
getFlags(
getIterator(
getIteratorClass(
offsetExists(
offsetGet(
offsetSet(
offsetUnset(
setFlags(
setIteratorClass(
&amp;#62;&amp;#62; $a-&amp;#62;append( 'a' )

&amp;#62;&amp;#62; $a-&amp;#62;count( )
1
&amp;#62;&amp;#62; $a-&amp;#62;offsetGet( 0 )
'a'
当出现异常时，php-shell也会打印出异常的内容。
你可以使用exit退出。
3. Tab补全
php-shell一个强大的功能是支持补全，以下内容可以被补全：

new 类名()
类名::方法名()
类名::常量名
$变量名
函数名()
$object-&amp;#62;方法名()

请先输入第一个字符然后按TAB按钮。如果只有一种匹配，它便会直接补全名称，否则，再按一次TAB会列出所有的可能性。
如果你想查看所有已声明的类，你可以使用 getdeclaredclasses()：
&amp;#62;&amp;#62; get_&amp;#60;TAB&amp;#62;
&amp;#62;&amp;#62; get_&amp;#60;TAB&amp;#62;&amp;#60;TAB&amp;#62;
get_browser(
...
get_declared_classes(
...
get_resource_type(
&amp;#62;&amp;#62; get_dec&amp;#60;TAB&amp;#62;
&amp;#62;&amp;#62; get_declared_&amp;#60;TAB&amp;#62;&amp;#60;TAB&amp;#62;
get_declared_classes(
get_declared_interfaces(
get_defined_constants(
get_defined_functions(
get_defined_vars(
&amp;#62;&amp;#62; get_declared_classes( )

4. 总结
如果是php新手，希望php-shell能帮你快速掌握php。老手也可以用其来检验代码段。
除此之外，也可以尝试一下基于Web页面的php shell，如http://phpshell.sf.net/&lt;br /&gt;&lt;!-- Feedsky flare --&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=f45163fbf1a81deea19284d771462105&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=f45163fbf1a81deea19284d771462105&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=24c3f0892ddfc2211975eee7a3065986&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=24c3f0892ddfc2211975eee7a3065986&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=e5a64a3993a1804028607dcce6edd1c6&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=e5a64a3993a1804028607dcce6edd1c6&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a992c7a52aeb2182d4b4839bddc736ee&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a992c7a52aeb2182d4b4839bddc736ee&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=eeb86863530890c8e754fc0573fc18cb&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=eeb86863530890c8e754fc0573fc18cb&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=429b12ffba0e7883a80a89d559426b7e&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=429b12ffba0e7883a80a89d559426b7e&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://feed.feedsky.com/~flare/shiningray?a=a6299e05a59c9631de45af4a60dfe1a8&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://feed.feedsky.com/~flare/shiningray?i=a6299e05a59c9631de45af4a60dfe1a8&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;!-- /Feedsky flare --&gt;</description><category>php</category><category>shell</category><category>日记</category><pubDate>Fri, 04 Jul 2008 18:15:54 +0800</pubDate><author>ShiningRay</author><comments>http://shiningray.cn/php-shell.html#comments</comments><guid isPermaLink="false">http://shiningray.cn/?p=183</guid><dc:creator>ShiningRay</dc:creator><fs:srclink>http://shiningray.cn/php-shell.html</fs:srclink><fs:srcfeed>http://shiningray.cn/feed/</fs:srcfeed><fs:itemid>feedsky/shiningray/~6119812/107614412/1225462</fs:itemid></item></channel></rss>