文章分类 -  Error Code

1
A: Are these codes any error?! ... Amm... I'm sure there is no problem in my code. B: $$$@@@%%%####&&&&***..... A: Oh! Shit! I don't mean that, I want to ... Have you remembered conversation like this? You need to record where you have fallen.
摘要:`CString` is a powerful utility in our daily programming. But recently I found something intuitive and error prone.I have such task: To make sure the file path is end with `360sd`, such as 'c:\program files' -> 'c:\program files\360sd'; but 'c:\program files\360sd' will ke 阅读全文
posted @ 2013-11-08 18:17 walfud 阅读(292) 评论(0) 推荐(0)
摘要:Bug version: // FILETIME ft = ....; ULONGLONG res = ft.dwHighDateTime (ft.dwHighDateTime) `ft.dwHighDateTime << 0x00000000, 00000020`.You can notice, the right operand is expanded to 64-bit, which is bug prone!The operation `<<` will not promote the left operand however there is overflow 阅读全文
posted @ 2013-10-05 11:35 walfud 阅读(330) 评论(0) 推荐(0)
摘要:for (int i = 0; i < 30; ++i) { // Do something other. foo(); bar(); baz(); // ... if (/* Some condition */) { // 满足 xxx 条件, 退出循环. i = INT_MAX; } }这段简短的代码中, 隐藏着一个 bug.当 Some Condition 满足条件时, `i = INT_MAX` 会执行, 此时作... 阅读全文
posted @ 2013-10-04 10:43 walfud 阅读(367) 评论(0) 推荐(0)
摘要:Let's see the piece of code below:Obviously, `foo(false)` will call `foo(bool)` as excepted.But do you know what does `foo("1234")` actually select? The answer is `foo(bool)` too! See here for detail:http://stackoverflow.com/questions/13268608/boostvariant-why-is-const-char-converted-t 阅读全文
posted @ 2013-08-04 13:00 walfud 阅读(206) 评论(0) 推荐(0)
摘要:#include <iostream>#include <string>#include <regex>using namespace std;int main(){ string str = "1234-abcd-!@#$"; //regex e("[^-]+"); for (auto it = sregex_iterator(str.begin(), str.end(), regex("[^-]+")); // 这里可以通过编译, 但是实际上是有问题的. it != sregex_iterato 阅读全文
posted @ 2013-02-07 15:27 walfud 阅读(840) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;class A{public: A() { cout <<"A::A()" <<endl; } auto foo() -> void { cout <<"A::foo(). m_x = " <<m_x <<endl; } int m_x = 100;};class B{public: B() { m_a.foo(); } // Destructive! 'm_a' has not be 阅读全文
posted @ 2012-09-14 09:55 walfud 阅读(241) 评论(0) 推荐(0)
摘要:char *p = new char(4) == Debug Error! 阅读全文
posted @ 2012-02-15 23:18 walfud 阅读(2107) 评论(0) 推荐(0)
摘要:#include "stdafx.h"#include <iostream>using namespace std;class T{public: T() : m_data(0) {} ~T(){}private: T(const T &other){} T &operator=(const T &other){}public: // Interface int QueryWmi() { // Here do something that maybe fail // But we just assume functio... 阅读全文
posted @ 2012-01-17 22:01 walfud 阅读(220) 评论(0) 推荐(0)
摘要:使用标志位 KEY_WOW64_32KEY 和 KEY_WOW64_64KEY 来控制 HKEY_LOCAL_MACHINE\Software 的访问, 如果你的程序可能会运行在 x64 Windows 上. 否则在 Vista x64 上可能会导致找不到 key 的错误. 阅读全文
posted @ 2012-01-03 16:20 walfud 阅读(14875) 评论(12) 推荐(1)
摘要:template <class T>void Fun(typename const T::iterator it){ return ;}int main(){ return 0;}看看下面的正确代码:template <class T>void Fun(const typename T::iterator it){ return ;}int main(){ return 0;}结论就是: typename 需要紧邻嵌套类型(nested dependent name). 阅读全文
posted @ 2011-09-27 17:45 walfud 阅读(395) 评论(0) 推荐(0)
摘要:不要在程序中相近的地方多次执行 srand. 阅读全文
posted @ 2011-09-25 23:17 walfud 阅读(4007) 评论(0) 推荐(0)
摘要:Use 'unsigned' if you treat variable in binary mode. 阅读全文
posted @ 2011-09-21 19:57 walfud 阅读(674) 评论(0) 推荐(0)
摘要:'m/($var)+/' when you want to match a variable string continuously. 阅读全文
posted @ 2011-08-24 21:38 walfud 阅读(161) 评论(0) 推荐(0)
摘要:辗转相除的原理是: if 0 == A % x && 0 == B % x ; then 0 == (A - B) % x ; 因此, 算法通过求这个数的余数, 用小者再和余数求余, 不断迭代, 因而缩小 gcd 的范围, 直到有一次能够找到 gcd 为止, 此时 0 == 任何余数 % gcd 成立. 阅读全文
posted @ 2011-08-21 16:42 walfud 阅读(287) 评论(1) 推荐(0)
摘要:大部分谜题引自: 精通正则表达式, 中文第三版 阅读全文
posted @ 2011-08-14 14:33 walfud 阅读(1266) 评论(0) 推荐(0)
摘要:if ((2 & 2) > 1) // (2 & 2) 一定要加括号 阅读全文
posted @ 2011-06-25 16:53 walfud 阅读(180) 评论(0) 推荐(0)
摘要:当引用类型内的枚举时,无需指定枚举的名称。 文件范围的枚举定义相当于常量,也不需要限定名。 阅读全文
posted @ 2011-06-08 21:44 walfud 阅读(1134) 评论(0) 推荐(0)
摘要:你知道它们错在哪里了么? cout (true ? 0, 1 : 0, 2) endl ; // Cause a warning cout (false ? 0, 1 : 0, 2) endl ; // Cause a warning 整个的三元表达式都无效! 阅读全文
posted @ 2011-05-13 14:04 walfud 阅读(914) 评论(0) 推荐(1)
摘要:问题在于copy(arr, arr + sizeof(arr), out) ; 一个指针 + 一个整数 的结果是指针偏移值加上整数所代表其元素的偏移值. 阅读全文
posted @ 2011-05-05 19:34 walfud 阅读(290) 评论(0) 推荐(0)
摘要:memcpy(&arr[0], &arr[1], 6) ; 这句话有问题, memcpy 是内存拷贝函数, 第三个参数以 byte 为单位进行复制, 然而一个 int 占用 4个byte , 因此, 拷贝的结果是错误的. 阅读全文
posted @ 2011-05-05 19:15 walfud 阅读(570) 评论(0) 推荐(0)

1