
C/C++ Knowledge
文章平均质量分 64
huntzw
这个作者很懒,什么都没留下…
展开
-
SEH转换为C++ Exception
以下两段摘自MSDN。The only way to make a rock solid DLL wrapper is to load the buggy DLL in another process, so that if it crashes it doesn't take your primary process down with it.Catching all C++ excep原创 2012-02-14 15:55:13 · 879 阅读 · 0 评论 -
为什么有序数组比无序数组快呢?
来自stackoverflow的题目Why is processing a sorted array faster than an unsorted array?翻译 2014-10-12 14:44:28 · 1281 阅读 · 0 评论 -
为什么C++变量名字和函数名字不能是同一个?
在Java中,函数名字和变量名字yi原创 2014-10-09 15:57:58 · 1427 阅读 · 0 评论 -
Integer division by zero
我们对于除数,之前check原创 2014-11-11 19:23:55 · 15854 阅读 · 0 评论 -
C++11右值引用(Rvalue-reference)
引自知乎的一个问答,作为笔记转载 2014-09-25 19:27:54 · 716 阅读 · 0 评论 -
ThreadSanitizer AddressSanitizer MemorySanitizer
Thread-sanitizer=======ThreadSanitizer (aka TSan) is a data race detector for C/C++. Data races are one of the most common and hardest to debug types of bugs in concurrent systems. A data race转载 2014-07-04 19:46:28 · 2420 阅读 · 0 评论 -
从游戏中看循环不变量
罐中红球与蓝球问题:假设罐中有红球与蓝球若干,从罐中取球,规则是: while (# of marbles inthe jar > 1) { choose (any) twomarbles from the jar; if (the two marblesare of the same color) { toss them asid原创 2014-02-28 09:24:08 · 918 阅读 · 0 评论 -
Loop Invariant 循环不变量
循环不变量(loop invariant)是一个不变量,被用来证明循环的特点,更多地,算法使用循环 (usually 正确性)。非正式的说,一个循环不变量是指在循环开始和循环中每一次迭代时永远为真的量,这意味着在循环中和循环结束时循环不变量和循环终止条件必须同时成立。以二分法为例:已知 A[1..n] 是单调递增的数列,求 A 中所有大于或等于target的值中,最小的那一个的序号。int原创 2014-02-25 14:21:57 · 2494 阅读 · 0 评论 -
雾里看花集锦
有的code咋看起来,感觉没啥问题,typedef bitset mybit;int _tmain(int argc, _TCHAR* argv[]){ mybit test_bs; test_bs.set(1, true); myprintf("%s", test_bs.to_string());}void myprintf(...){}上述的code有时候运行没原创 2013-08-14 22:38:51 · 805 阅读 · 0 评论 -
关于C++构造函数抛出异常
The code like this is inherently vulnerable to memory leaks(if the constructor failed)?class Foo{public: Foo() : a(new int), b(new int) {} ~Foo() { delete a;原创 2012-12-10 15:50:49 · 588 阅读 · 0 评论 -
XOR Linked List
An ordinary doubly linked list stores addresses of the previousand next list items in each list node, requiring two address fields: ... A B C D E ... –>原创 2012-11-16 11:05:02 · 893 阅读 · 0 评论 -
凑钱问题
Q: 有足够量的2分、5分、1分硬币,请问凑齐1元钱有多少种方法?我们从简单情况开始分析,假如有足够量的1分硬币,请问凑齐1分钱有多少种方法?毫无疑问,答案是1。然后,凑齐2分钱有多少种方法?凑齐n分钱有多少种方法?答案均是1。接下来,假如有足够量的1分硬币和2分硬币,凑齐n分钱有多少种方法?对于1分硬币,凑齐任意n分钱都只有1种方法;那么只用1分钱凑齐n-2分钱,有1种方法;只用1分原创 2012-11-15 19:46:32 · 1221 阅读 · 0 评论 -
VC++在release下对return的优化
编译环境 VS2008, release模式。今天,对于如下的code进行debug,单步运行。此时index的值是1,我们一般会认为code走到36行,然后退出。但是,实际上,code走到38行,当时我们就凌乱了,难道code中if语句有问题,看了又看。茫然。。。。。。忽然想到,VS在release模式下,对于code有优化。。。看看汇编code吧,果然,VS原创 2012-09-03 19:27:35 · 607 阅读 · 0 评论 -
C++0X Basic Knowledge
C++0x增加了诸多的feature,使C++俨然变成了新的语言,遂拙记一些。Moving semanticsC++ has supported copying object,but it is less efficient when a large object is copying. So C++0x adds supportfor move object state:Widg原创 2012-09-03 15:11:32 · 633 阅读 · 0 评论 -
What's a ‘sequence point’
A sequence point is a point in time at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete. The sequence points listed in the C standard are:a原创 2012-08-13 13:50:58 · 936 阅读 · 0 评论 -
VC++异常处理
Windows下的C++程序一般会有如下的异常:o 操作系统产生的SHEo C运行库产生CRT错误o 信号每一种异常都需要安装exception handler函数来处理这些异常,以此来防止程序由于这些异常而crash,或者在程序因异常而退出时留下遗言,主要是打印出当时的栈信息,方便我们对其进行分析。如果应用程序是多线程,那么情况变得复杂了。因为有的handl翻译 2012-03-15 12:02:45 · 2781 阅读 · 0 评论 -
一个含有STL的struct问题
前日, 在论坛看到这样的code: struct foolstruct { std::vector vec; int data; }; foolstruct * create(int s, int * array, int n) { int sizedata=sizeof(foolstruct); foolstru原创 2011-11-07 22:34:02 · 483 阅读 · 0 评论 -
一段可爱的C语言的code, 难以发现的bug
代码如下(windows):#include #include #include int main(){ int ival = 67; if (send ival = 89; printf("the ival is %d", ival); return 0;}在上面的code里,很容易发现原创 2011-11-07 22:14:59 · 804 阅读 · 0 评论 -
这是函数声明还是变量声明
我相信如下这个问题,写过C++的人或许douyu原创 2014-10-20 09:28:25 · 650 阅读 · 0 评论