//test #pragma TODO("this function is not implemented!") voidnot_implement_function() {
} #pragma WARN("this function is implemented by a hack way!") floatfast_inv_sqrt(float x) { float xhalf = 0.5f*x; int i = *(int*)&x; i = 0x5f3759df - (i >> 1); x = *(float*)&i; x = x*(1.5f - xhalf*x*x); return x; } #pragma FIXME("buggy ! !") floatcustom_add(float a, float b) { return a - b; } intmain(int argc, char* argv[]) { return0; }
vs2013输出结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1> ==================================== 1> d:\workspace\local\neontest\neontest.cpp(19) 1> TODO : this function is not implemented! 1> ==================================== 1> 1> 1> ==================================== 1> d:\workspace\local\neontest\neontest.cpp(24) 1> WARN : this function is implemented by a hack way! 1> ==================================== 1> 1> 1> ==================================== 1> d:\workspace\local\neontest\neontest.cpp(34) 1> FIXME : buggy ! ! 1> ====================================
ScopeExit Tool
下面这个代码片段利用了c++11中的lambda表达式以及C++的RAII(Resource Acquisition Is Initialization)特性,使得代码及其优雅,在不用写wrapper class的情况下充分利用RAII的好处。能够降低编码的心智负担,在哪里申请资源就在哪里释放,保证必须成对出现的操作一定会成对执行。总之,好顶赞!
//delete data after process and dump int* processed_data = newint[data_len]; SCOPE_EXIT(delete[] processed_data;); for (int i = 0; i < data_len;i++) { processed_data[i] = data[i] + 100; } fwrite(processed_data, sizeof(processed_data[0]), data_len, fp); }