Monday, December 28, 2009

Note on C/C++[2]

an interesting one with gcc on Mac OS X

Compiler: gcc version 4.0.1 (Apple Inc. build 5490)
using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5490~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix

Environment: Mac OS X 10.5, Macbook ( intel-based)

Files: main.c and main.cpp. The two files are 100 percent the same ( checked with diff ). Here is the content:

#include

main(int argc, char *argv[])
{
int tmp = 100;
int *ptmp = &tmp;
char *p = "Hello, world!";
char a[] = "Hello, world!";
char ab[10];
printf("%d\n",*ptmp);
printf("%x\n",ptmp);
printf("%x\n",a);
printf("%x\n",p);
printf("%x\n",&ab[9]);
}

Symptom:
In the terminal, type gcc main.c , then ./a.out, the result is
100
bffff874
bffff866
1fe8
bffff865
however if I try gcc main.cpp, I got a compile-time error such that
Undefined symbols:
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in cc6nXMVm.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Gee, this is funny! The only difference between these two source files is the name suffix!
My first guess is the default linker. I bet for this compiler the default links are different for *.c and *.cpp files ( one is gcc and another is g++?). This is confirmed when I tried gcc main.cpp -c and it worked fine but gcc main.o -o failed. But anyway it's still interesting to me!

Tuesday, July 21, 2009

First day with Firefox 3.5

To be honest, I didn't feel any significant change after using Firefox 3.5 today. It seems that this new distribution supports the fonts better so that the surfing window is sharper. Anyway, it's good to have some changes and improvements.

A good tool for ubuntu user is PPA (personal package archives). I really love it. Here is some brief introduction, please turn to PPA overview for more information.

With Launchpad's Personal Package Archives (PPA), you can build and publish binary Ubuntu packages for multiple architectures simply by uploading an Ubuntu source package to Launchpad. Every individual and team in Launchpad can have one or more PPAs.

PPAs give you:

  • An APT repository of up to 1 gigabyte for free software - see our PPA terms of use for more detail.

  • Binary packages built for x86, AMD64 and LPIA architectures against Ubuntu.
  • A web front-end where Launchpad users can browse and search for your packages.

Wednesday, July 8, 2009

无题

never try to change someone.

我又忘了这句话,贴出来,当众羞辱我自己。

Monday, June 8, 2009

mark一个

2009年6月7号晚,偶也算是终于告别单身了。前面的路会更加艰辛,要加油!

Wednesday, June 3, 2009

Leopard on my Macbook

The DVD-ROM of my Macbook is broken, damn it!

I used Tiger since 2006. Although Leopard was released back in 2007, I was so reluctant to upgrade my operating system. So I start getting old, huh~

Today I installed Leopard on my Macbook. Actually the installation process is much easier than I expected, even with a broken DVD-ROM.

Nice to meet you finally, Leopard!

Monday, June 1, 2009

One observation on software installation on ubuntu

There are many ways to install softwares on Ubuntu. However, I think that the best one is install them through its .deb packages. In this case, the system knows what packages you have and what you don't have, therefore your package dependence is consistent.

For example, I had the Gutenprint package of version 5.2.0. I have a new print which is supported by Gutenprint 5.2.3 but not Gutenprint 5.2.0. In the very begining, I download the .tar.gz package of Gutenprint 5.2.3 and install it. But the CUPS didn't recognize the newly installed version. Then I uninstall it and downloaded the .deb file and installed it. Everything is fine right now. I can see the driver for my new printer in CUPS.

BTW, I tried Qt4.5 on Ubuntu. I didn't find the .deb package for Qt4.5 so I installed it through .bundle file. It seems that there are several linkage problems with Qt4.5. Althgouth I fixed them later, I recommend to install qt4 through apt-get. In this way you will install Qt4.x (x is less than 5). Although it's not the latest version, you will find that it's easier to handle so you can focus on your own programs.

Sunday, May 31, 2009

Notes of Learning C/C++ [01]

I decided to take some time to study C/C++ again during this summer. I planed to at least finish reading the book The C Programing Language, 2nd edition by Kernighan and Ritchie (refer to k&r).

The first note is about the version of C standard. People are talking about the ANSI C all the time. This is the C standard of USA. It's also widely referred as C89. ISO adopted this standard and named it ISO89 with some minor changes. It seems like that ANSI accepted this adoption. I would like to say that ANSI C is the most classic C standard. You can think of it as the intersection of all other C standard. C99 standard is the renewed version of C89 and has many new features. It adds several extensions with the consideration of the compatibility to C++. C99 is adopted by both ANSI and ISO so it's an official standard.

On the other hand, different C compilers support these standard with slight differences. The designers of the C compiler would like to add some unique features in order to facilitate their work under certain circumstance. For example, if you codes strictly follow the ANSI C standard (C89), you should have no troubles with any compiler on whatever platform. Here comes the tricky part. People actually feel like that C99 is more convenient (maybe!), especially those generations born after late 1980s. But some compilers support C99 very well while some not. For example, GCC, the pervasive compiler on Linux-related platforms, supports C99 well; while VC, the popular IDE on Windows platform, doesn't support C99. Keep this in mind while you are coding with non ANSI C, otherwise you will be frastrated.

Tuesday, January 13, 2009

帝国的中年危机 -写在奥巴马就任前

作为一个在美国求学的中国留学生,时下最关注的话题莫过于次贷危机和美国新任总统奥巴马了。事实上,我非常倾向于把这两件事放在一起来思考,因为我觉得奥巴马能如愿当上美国第四十四位总统,多多少少沾了次贷危机的光。虽然可能毫无意义,但我们可以来做一些假设:如果次贷危机早个一年半载爆发,奥巴马能拼过希拉里吗?我觉得答案是否定的。希拉里多年的从政经验将在危机中获得巨大的优势。同样我们可以考虑如果次贷危机晚个半年爆发,奥巴马能拼过麦凯恩吗?我觉得很悬。美国中部的保守势力还是很强大的。那么这么说来,是历史选择了奥巴马?宿命论者肯定会这样认为。不过作为一个不可知论者以及阴谋论者,我还是倾向于相信这其中必然有着鲜为人知的幕后操控。


很多人喜欢把这次的经济危机跟29年的大萧条联系起来。我也正好想以这个为切入点来展开谈谈。20世纪的30年代对我来说太遥远,所以我也不太可能对它有真切的感受,但是如果我们把它放在当时的天下大势中来看,还是能得到不少有意思的东西。首先就那次经济危机本身而言,我倾向于认为它是一次纯的资本主义式的经济危机,资本高度自由导致产能过剩,就像是一个年轻小伙学会了十八般武艺却暂时没找到地方施展。而那次大萧条,就如同中国古代的少林弟子在学成武艺下山前必须要经过十八罗汉阵的考验一样。在二战的帮助下,美国这个新兴的自由资本主义国家顺利地通过的考验,一跃成为世界的霸主。

之后的世界格局,则不是那么的陌生。二战后的冷战时期,世界是两极的。前苏联凭借着自己顽强的毅力和美国折腾了几十年,最后轰然倒下。在这期间,欧盟凭借着地理优势以及马歇尔计划渐渐成长起来,日本则再次发挥了他们善于学习的特点,在短短的几十年里创造了一个又一个的经济奇迹。那时候的中国,却还基本在忙于意识形态的斗争。

苏联的瓦解彻底成就了美国的霸主地位。美国人开始毫不客气的当起了世界警察。不过这一切在2000年左右开始有了微妙的变化。首先是欧元的问世,让美国开始担心起萧墙之祸;然后是俄罗斯在普京的带领下日渐强盛;中国加入了WTO, 20年改革开放的成果开始以井喷的方式蔓延到全世界;而日本,这个美国最忠实的小弟,则开始步入了漫长的经济衰退。在丝丝寒风中,美国人开始察觉到一些问题:这个世界正在由单极向多极转变,美国的霸主地位受到了严重的挑战!

后面的事情我们就再也一点也不陌生。欧盟开始凭借自己雄厚的实力尝试摆脱美国的控制;俄罗斯开始了能源战略;中国则凭借着上海合作组织等开始寻求远东的统治地位,同时通过多年在非洲的积累寻求更高的国际地位;日本也开始渐渐觉得它的政治地位与其经济地位过于不对称,开始对美国不是那么的言听计从。这其实就像个黑帮,美国做老大很多年,已渐渐步入中年,控制力大不如前。下面的几个小弟则在经过漫长的积累后开始蠢蠢欲动,但是又忌于多元关系的复杂性而都不愿做出头鸟。在这样一个大背景下,美国的次贷危机爆发了。

其实美国也不傻。虽然失去了一些年轻人的锐气,却也开始展露其成熟的一面。在目前的这种形势下,美国人认识到对他们最有利的局面是坐山观虎斗,让几个有实力的小弟们自己互相消耗,自己再收拾残局。于是便有了欧盟借奥运之机对中国的人权问题大作文章,导致中欧关系急剧恶化,连今年的中欧峰会也被取消。俄罗斯则一直处于被北约步步紧闭的状态,而这次的天然气危机也进一步恶化了俄罗斯与欧盟的关系。至于日本,则是美国最放心的一个小弟。因为如果说其他几个小弟都是正常的成年男子,那日本充其量就是个太监。日本的存在,然中国和俄罗斯都如梗在侯,好不难受。至于中国和俄罗斯,虽然目前关系不错,但两国漫长的边界线給双方带来了复杂的地缘政治,如处理得稍有不慎则很容易引火上身。

我前面提到了,我是一个阴谋论者。所以上一段提到的这些事情,我认为都是美国幕后操控的结果。萨科奇在奥运期间可是出了一把风头,俨然一人权卫士。这不,奥运刚结束,他就开始吵着问美国要权。这让我相信美国为这事肯定給他开了条件,然后又赖账了。油价疯长好好地肥了一把俄罗斯,可是接下来的暴跌又开始让俄罗斯人不爽,于是乌克兰欠的那点天然气钱就开始显得很珍贵,于是诱发了天然气危机。顺便提一下,这次以色列的武装行动我认为也是美帝的杰作,转移大家的视线呗,还能帮美国消耗些武器。而且时机的选择也很绝妙。表面上看,小布什就快滚蛋了,不方便发表评论;奥巴马还没上任,也不好说什么。但其实就是美帝指示以色列打的,那当然没啥可说的啊。

然后让我们回到次贷危机。我认为这次的危机是美国过度消费的产物,而非过度生产。美国人摆明了就是要让别的国家給他买单。谁?欧盟跟日本在次贷危机中已经跟着美国栽跟头了,出了不少血。俄罗斯金融市场也一片混乱,估计也放了不少血。接下来应该就是中国了。

美国这些年的繁荣,是建立在对资源的高度消耗上的。他们站在世界这个金字塔的顶端,通过各种手段来从外界获得源源不断的输血,从而进一步巩固他的地位。但是这也造成了社会的恶化。比如说医疗保险,简直就是个大窟窿。而且人到了中年,身体也开始变得臃肿,管理成本急剧升高,这一些,都不是吃吃药打打针就能解决好的。

纵观美国的历任总统,其实不乏如林肯,罗斯福等杰出的领袖;也有如胡佛,小布什等遗臭万年的角色;当然,也少不了一些平平淡淡的角色。奥巴马则即荣幸又不幸地站在了这个峰尖浪口,时势注定了他要么名垂千古,要么遗臭万年。让我们拭目以待吧。