随笔分类 -  言必称标准之--C/C++

记录一些比较偏门的东西,老了记性不好了
摘要:最早是在微博上看到这样一个swap函数。void swap(int& a,int& b){ a = b + 0*(b = a);}那么我也来讨论讨论这样的表达式有什么行为。当然这里是我认为的答案,也不敢保证完全正确,因为C++实在是太复杂了,完全不敢说知道的面面俱到。下面来看这两个C++表达式,a和b都是int类型。a = b + 0 * (b=a); // exp 1a = 1 + 0 * (b=a); // exp 2exp 1就是原来swap函数的实现方法,这个比较明显了。因为C++里面规定了子表达式的计算顺序和side effect的发生顺序是不确定的。另外: &quo 阅读全文
posted @ 2012-08-11 09:39 嗷嗷 阅读(749) 评论(0) 推荐(0) 编辑
摘要:#include <complex>#include <iostream>using namespace std;int main(void ){ complex< int> z(20, 200); cout << abs< int>(z) << endl; return 0;}According to the C++ ISO spec, §26.2/2:The effect of instantiating the templatecomplexfor any type other thanfloat,doub 阅读全文
posted @ 2012-06-20 09:30 嗷嗷 阅读(315) 评论(0) 推荐(0) 编辑
摘要:something about concatenated strings and C macro 阅读全文
posted @ 2012-05-25 13:12 嗷嗷 阅读(414) 评论(1) 推荐(0) 编辑
摘要:i = ++i + 1; is well defined in C++0x. 阅读全文
posted @ 2011-06-30 12:10 嗷嗷 阅读(370) 评论(3) 推荐(0) 编辑
摘要:malloc(0) vs operator new(0) 阅读全文
posted @ 2011-01-05 22:53 嗷嗷 阅读(480) 评论(0) 推荐(1) 编辑
摘要:C语言中和的一个细节,也许很多人都不知道 阅读全文
posted @ 2010-12-27 22:32 嗷嗷 阅读(376) 评论(2) 推荐(0) 编辑
摘要:(i = j) = k;的值是多少? 阅读全文
posted @ 2010-12-19 11:10 嗷嗷 阅读(508) 评论(1) 推荐(0) 编辑
摘要:主要是简单解释一下为什么要写这样一个函数,这两个const有什么意义。const char* c_str() const{return m_str;};1.首先说第二个const, 这个const意味this指针是一个const myString*, 所以对于变量const myString c_myStr(ss); 才能调用c_myStr.c_str();2.再说第一个const, 既然c_myStr是一个const类型的变量,自然是希望他不被改变。那么如果不加第一个const,那么c_str()的返回值就可以赋值给一个非const类型的变量,c_myStr将有可能变相地被改变。还有一点小提 阅读全文
posted @ 2010-12-16 11:32 嗷嗷 阅读(628) 评论(2) 推荐(0) 编辑
摘要:一道C语言的题目,关于指针和int类型。 阅读全文
posted @ 2010-10-16 23:30 嗷嗷 阅读(2517) 评论(8) 推荐(2) 编辑
摘要:嗷嗷按,今天被问到在constructor/destructor中调用virtual member function的问题。答错了,很羞耻 阅读全文
posted @ 2010-09-07 21:31 嗷嗷 阅读(1470) 评论(0) 推荐(0) 编辑
摘要:嗷嗷按,用C++这么多年,还真的第一次注意到有这个东西,具体所有细节还没整理出来。先用个例子说明一下大概[代码]};class BB:private AA{public: using AA::i;};int main(){ BB b; b.i = 1; //OK, no problem //b.j = 1;// inaccessible to b.j} 阅读全文
posted @ 2010-09-05 23:30 嗷嗷 阅读(394) 评论(2) 推荐(0) 编辑
摘要:int func(int aa[4]) { return sizeof(aa);}返回值为几何?? 阅读全文
posted @ 2010-09-01 19:01 嗷嗷 阅读(657) 评论(0) 推荐(0) 编辑
摘要:这都是一些细枝末节的东西,我想不做编译器的话,大部分都很难碰到。研究学习这些只是出于对C语言一种偏执狂。 写出来是为了找到和我一样的偏执狂。 阅读全文
posted @ 2010-08-25 16:55 嗷嗷 阅读(4709) 评论(4) 推荐(0) 编辑
摘要:C++ is a horrible language. 阅读全文
posted @ 2010-08-23 19:10 嗷嗷 阅读(623) 评论(0) 推荐(0) 编辑
摘要:i = ++i + i; 值为几何? 阅读全文
posted @ 2010-05-31 12:56 嗷嗷 阅读(678) 评论(7) 推荐(0) 编辑
摘要:sizeof('c')的值为几何? 阅读全文
posted @ 2010-05-31 12:00 嗷嗷 阅读(675) 评论(2) 推荐(0) 编辑

点击右上角即可分享
微信分享提示