try{} catch(…){}

以前都是用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!

recordhistory.org被封了

决定做的时候就料到的,只是没想到这么快

封的第一天,流量下降到原先的十分之一

当初做这个站只是为了自己历史方面的爱好, 也有借此熟悉wiki系统的意思。现在被封了,感觉很是失落。

对我们这个政府,……………………,实在没什么好说的了。

以后如果孩子们问为什么留给他们这么糟糕的国家的时候, 会告诉他自己曾尽了一个公民的责任去努力让它变好,可这个国家实在不是我们这种卑微草民能改变的。

https协议还可以访问, 谁要看的请点 https://www.recordhistory.org, 只是图片在https显示不出来。

我的blog也开始挣钱了:)

作了近1个月的google adsense, 终于挣到了1.20美刀. Adsense的大牛们别笑,自己很知足了:D。

大家谁要感兴趣也去 google adsense 申请个帐号吧。 不过中文的 adsense 市场比英文要差很多(从我的站点看,中英文adsense要差10倍以上),大家要有心理准备。 要么就是写给老外看的英文blog, 王健硕的blog主要就是英文内容, 据说收入一个月在5000人民币左右。

下面是一些真正挣钱的blog

http://www.boingboing.net/ 年收入100万美元的blog

http://www.techcrunch.com/ 月收入6万美元的blog

http://www.huffingtonpost.com/ 获VC 500万美元的blog

Smart Archives 增强

安装了 Justin Blanton 开发的 smart archives 插件, 发现这个插件对中文和韩文支持不佳。我给做了点小修改,并且对他的一些小缺陷也进行了补正。最后的效果请看 http://www.doyj.com/archives/

安装方法如下:
  1. 将下面的代码拷贝并存成文件smartarchives.php
  2. 将smartarchives.php 上载到你的plugin目录
  3. 到控制面板激活Smart Archives 插件
  4. 在适当的地方插入smartArchives()函数调用。
    这个函数有两个参数,第一个在”both”, “block”,”list”中选择,默认为both 第二个是要排除的分类id.
下面就是修改后的代码:


‘.$years[year].’: ‘);
$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('‘.$sm.’ ‘); }
else
{ echo(‘‘.$sm.’ ‘); }
}

echo(‘
‘);
}
echo (‘

‘);
}

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('

‘.$lm.’ ‘.$years[year].’

‘);
echo(‘

    ‘);
    $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(‘

  • ‘.$post[post_title].’
  • ‘);
    }
    else echo(‘

  • ‘.$post[post_title].’
  • ‘);
    }
    }
    echo (‘

‘);
}
}
}
}
}
?>

为什么去登山?

关于这个问题人们都知道一个非常有名的答案,就是:“山在那里”,这是英国登山家马洛里的话。当时他在珠峰脚下,一个记者向他提出这个问题的时候,他一指珠峰,说出了这个著名的答案。这个答案确实够酷,可能也正因此而流传甚广。其实他在一次攀登珠峰的筹款会上给出过一个更加详尽,更加精彩的回答:

“The first question which you will ask and which I must try
to answer is this, ‘What is the use of climbing Mount
Everest ?’ and my answer must at once be, ‘It is no use’.
There is not the slightest prospect of any gain whatsoever.
Oh, we may learn a little about the behavior of the human
body at high altitudes, and possibly medical men may turn
our observation to some account for the purposes of aviation.
But otherwise nothing will come of it. We shall not bring
back a single bit of gold or silver, not a gem, nor any coal
or iron. We shall not find a single foot of earth that can
be planted with crops to raise food. It’s no use.

So, if you cannot understand that there is something in man
which responds to the challenge of this mountain and goes
out to meet it, that the struggle is the struggle of life
itself upward and forever upward, then you won’t see why we
go. What we get from this adventure is just sheer joy. And
joy is, after all, the end of life. We do not live to eat and
make money. We eat and make money to be able to enjoy life.
That is what life means and what life is for.”
– George Leigh Mallory, 1922

起初也问了自己很多次,始终搞不清。从小就特别喜欢爬山,不知道为什么。后来对这个问题也失去了兴趣,想着不要问那么多,自己喜欢就去做好了。