以前都是用try{} catch(…){}来捕获C++中一些意想不到的异常, 今天看了Winhack的帖子才知道,这种方法在VC中其实是靠不住的。例如下面的代码:
- try
- {
- BYTE* pch ;
- pch = ( BYTE* )00001234 ; //给予一个非法地址
-
- *pch = 6 ; //对非法地址赋值,会造成Access Violation 异常
- }
- catch(...)
- {
- AfxMessageBox( "catched" ) ;
- }
这段代码在debug下没有问题,异常会被捕获,会弹出”catched”的消息框。 但在Release方式下如果选择了编译器代码优化选项,则VC编译器会去搜索try块中的代码, 如果没有找到throw代码, 他就会认为try catch结构是多余的, 给优化掉。 这样造成在Release模式下,上述代码中的异常不能被捕获,从而迫使程序弹出错误提示框退出。
那么能否在release代码优化状态下捕获这个异常呢, 答案是有的。 就是__try, __except结构, 上述代码如果改成如下代码异常即可捕获。
- __try
- {
- BYTE* pch ;
- pch = ( BYTE* )00001234 ; //给予一个非法地址
-
- *pch = 6 ; //对非法地址赋值,会造成Access Violation 异常
- }
- __except( EXCEPTION_EXECUTE_HANDLER )
- {
- AfxMessageBox( "catched" ) ;
- }
但是用__try, __except块还有问题, 就是这个不是C++标准, 而是Windows平台特有的扩展。 而且如果在使用过程中涉及局部对象析构函数的调用,则会出现C2712 的编译错误。 那么还有没有别的办法呢?
当然有, 就是仍然使用C++标准的try{}catch(..){}, 但在编译命令行中加入 /EHa 的参数。这样VC编译器不会把try catch模块给优化掉了。
找到一篇比较好的英文文章谈这个问题: http://members.cox.net/doug_web/eh.htm
用C++10 年多了 , 居然这么基础的问题都搞错, 真是汗颜。 要加紧学习啊, Stay Hungry, Stay Foolish!
安装了 Justin Blanton 开发的 smart archives 插件, 发现这个插件对中文和韩文支持不佳。我给做了点小修改,并且对他的一些小缺陷也进行了补正。最后的效果请看 http://www.doyj.com/archives/。
安装方法如下:
- 将下面的代码拷贝并存成文件smartarchives.php
- 将smartarchives.php 上载到你的plugin目录
- 到控制面板激活Smart Archives 插件
- 在适当的地方插入smartArchives()函数调用。
这个函数有两个参数,第一个在”both”, “block”,”list”中选择,默认为both 第二个是要排除的分类id.
下面就是修改后的代码:
- <?php
- /*
- Plugin Name: Smart Archives
- Version: 1.5
- Plugin URI: http://justinblanton.com/projects/smartarchives/
- Description: A simple, clean, and future-proof way to present your archives.
- Author: Justin Blanton
- Author URI: http://justinblanton.com
- */
-
- function smartArchives($format='both', $catID='') {
-
- global $tableposts, $wpdb, $PHP_SELF , $month ;
- setlocale(LC_ALL,WPLANG); // set localization language
- // set the URI of your archives; this might not need to be changed (currently, it's http://yoursite.com/archives/)
- $now = gmdate('Y-m-d H:i:s'); // get the current GMT date
-
- if (($format == 'both') || ($format == 'block')) { // check to see if we are supposed to display the block
- $qy = mysql_query("SELECT distinct year(post_date) as year, post_status
- FROM $tableposts
- WHERE post_status='publish'
- AND post_date <= NOW()
- ORDER BY year desc");
- // loop to create the small archive block with year/month links
- while($years = mysql_fetch_array($qy)) {
- echo('<strong><a href="'.get_year_link($years[year]).'">'.$years[year].'</a>:</strong> ');
- $qm = mysql_query("SELECT distinct month(post_date) as monthv
- FROM $tableposts
- ORDER BY monthv asc") or die(mysql_error());
-
- for ($i=1; $i<=12; $i++)
- {
- $q = mysql_query("SELECT *, year(post_date) as year
- FROM $tableposts
- WHERE year(post_date)='$years[year]'
- AND month(post_date)='$i'
- AND post_status='publish'
- AND post_date <= NOW()
- ORDER BY id desc") or die(mysql_error());
- $sm = $month[zeroise($i,2)]; // get the shortened month name; strtotime() localizes
-
- if(mysql_num_rows($q))
- { echo('<a href="'.get_month_link( $years[year], $i ).'">'.$sm.'</a> '); }
- else
- { echo('<span class="emptymonth">'.$sm.'</span> '); }
- }
-
- echo('<br />');
- }
- echo ('<br /><br />');
- }
-
- if (($format == 'both') || ($format == 'list')) { //check to see if we are supposed to display the list
- $qy = mysql_query("SELECT distinct year(post_date) as year, post_status
- FROM $tableposts
- WHERE post_status='publish'
- AND post_date <= NOW()
- ORDER BY year desc");
- // loop to display links to all posts, sorted by descending month and day
- while($years = mysql_fetch_array($qy)) {
- $qm = mysql_query("SELECT distinct month(post_date) as monthv FROM $tableposts ORDER BY monthv desc") or die(mysql_error());
- while($date = mysql_fetch_array($qm)) {
- $q = mysql_query("SELECT *, year(post_date) as year, month(post_date) as monthv
- FROM $tableposts WHERE year(post_date)='$years[year]'
- AND month(post_date)='$date[monthv]'
- AND post_status='publish'
- AND post_date <= NOW()
- ORDER BY id desc") or die(mysql_error());
- if(mysql_num_rows($q)) {
- $lm = $month[zeroise($date[monthv],2)]; // get the full month name; strtotime() localizes
- echo('<h2><a href="'.get_month_link( $years[year], $date[monthv] ).'">'.$lm.' '.$years[year].'</a></h2>');
- echo('<ul>');
- $q = mysql_query("SELECT *, year(post_date) as year, month(post_date) as monthv
- FROM $tableposts WHERE year(post_date)='$years[year]'
- AND month(post_date)='$date[monthv]'
- AND post_status='publish'
- ORDER BY post_date desc") or die(mysql_error());
- while($post = mysql_fetch_array($q)) {
- if ($post[post_date_gmt] <= $now) {
- if ($catID != '') { // check to see if a category id was specified in the arguments
- // get the categories that are attached to the current post
- $cats = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post[ID]");
- $found=false;
- foreach ($cats as $cat) { // look to see if the specified category is attached to the current post
- if ($cat == $catID) $found=true;
- }
- if (!$found) echo('<li><a href="'.get_permalink($post[ID]).'">'.$post[post_title].'</a></li>');
- }
- else echo('<li><a href="'.get_permalink($post[ID]).'">'.$post[post_title].'</a></li>');
- }
- }
- echo ('</ul><br />');
- }
- }
- }
- }
- }
- ?>
去http://www.google.com/searchhistory/ 查到了自己这几个月的搜索纪录,不但有搜索的关键词纪录,在搜索结果中看了哪些网站都一清二楚。
想起去年年底自己写的一个blog: http://www.doyj.com/archives/80 。
我家里是电信的Lan宽带,下载的峰值速度一般在128K字节美妙,大约1MBPS的带宽。 妹妹家是网通的Lan宽带,下载的峰值速度是256K字节每秒,大约2MBPS的带宽。
今天在家里给Blog家了一个XSPF播放器插件,选了9首歌放进去,这样大家可以边看blog边听音乐。在家里的电信宽带上试的都很好,每首歌都播放非常流畅。今晚去了趟妹妹家,发现用她的网通宽带只有第3,6,8首播放流畅,其他都断断续续,根本没法听。
难道这是因为电信和网通互联有问题?
在一个程序员论坛做了一次有关RSS Reader的投票调查,投票的一共有13人。投票结果是,有三人使用离线RSS Reader, 一人使用在线的Reader, 其他9人不使用。有点让自己震惊。身边非技术圈的人没看到一个在用,没想到技术圈里使用的比率也是这么低。
自己原先一直用Firefox的一个RSS Reader插件,前几天转到了Google Reader上,这样到了外地网吧也能看了。我订的RSS不多, 请看http://www.doyj.com/%E6%88%91%E8%AE%A2%E7%9A%84rss/。
从今天起,在我的blog里也搞“您使用的RSS Reader”调查,欢迎大家在左边投票区投票。
8月3日编辑:投票放了2两天没人投,撤下
Google开始为Mountain View的近7万用户提供免费的Wifi服务了,带宽是1M, 从 http://www.networkworld.com/community/?q=node/6438 看到的。
在网上搜还搜到了一篇有趣的文章: Why I Fear Google WiFi
Google到底想做什么呢? 是不是为了完整的分析用户上网的行为模式,而采集样本数据呢?从海量的,看似无规律可循的用户上网数据中,挖掘有价值的宝藏正是我感兴趣的课题。
在本周Redmond的演讲上,微软工作人员针对Vista的语音识别系统进行了演示。让与会者大跌眼镜的是,此次Demo堪称100%失败,Vista的语音识别系统完全不买工作人员的帐,出现严重识别错误。
微 软工作人员以极为标准的美语试图让Vista正确识别“Dear Mom”这个短语的发音,然而,微软开发五年,投入数十亿美元的Vista将工作人员的努力识别为“Dear aunt,let’s set so double the killer delete select all”。
语言识别程序是要经过训练的,看来这个做演示的人准备严重不足。 下面是一些人在Youtube的评论:
Agreed – sure the whole vista thing may be funny but the reporter is an idiot。
Speech recognition improves with training – I doubt the dude did read more than one page to train the software.
Thats wicked…. and so very microsoft!!
这件事也反映了语音识别技术的不成熟,任重道远。记得90年代还参加过一个语音识别技术的会。印象特别深的是Drgon公司,一对夫妻成立的,当时女老板做主题发言前讲了一段话,她说前一天她去爬了长城,在长城上激动不已,心想小时候登上长城的梦想终于实现了。当时看到好几个公司,他们的下场都不太好,Dragon被竞争对手收购了,这个竞争对手后来破产了。IBM的Via Voice后来停止开发了。从李开复一举将识别率从50%提高到80%后,语音识别技术似乎没出现什么根本性的突破。
当初要为老婆架设blog(http://www.filmkiller.net), 因为很多东西要先试,干脆把自己的blog也搬了过来,当成了试验品。本以为就半天事,没想到费了很多功夫。选择blog系统很快,根据自己以前的经验选择了WordPress。 但开头走了些弯路,为了把一些系统和Wordpress集成到一起,选了XOOPS。结果遇到很多问题,第一个就是找不到很理想的XOOPS的Theme, 还有Gallery和XOOPS的集成不是很理想(也可能我没用对)。最后只好换成以Wordpress2.0为主系统。装起来后其他都很顺利,但在选择 Theme上用了好多时间,尝试来尝试去最后选择了现在用的MW。选择好了Theme还没完,调整一些细节也花了不少时间。
安装的插件有:
bsuite 统计站点访问
Cool Weather 显示天气
Emotions 显示表情符号
ImageManager 管理上载图片的插件,很不错,就是有些缩微图有问题
中文 WordPress 工具箱 左边的随机文章,最新留言就是靠它显示的
Quoter 为了引用留言
Google Sitemaps 让Google能搜索到blog内每篇文章的插件
Admin Drop Down Menu 能减少管理网站时的点击次数
WPG2 Gallery2的集成插件,左边的照片就是它显示的
WPvideo 播放在Youtube和Google video等地方的在线视频
wp-cache 加快访问速度
第一次搭Wordpress,有很多不足,请大家多批评指教