[Tip: log file]Some Quick Notes

1. Log File is important. I didn't realize its importance until I met a issue that was only reproducible on QA machine and it's hard for me to figure out the reason. I added some code in my project to output some check point status into a log file and post it to QA to use. The generated log file did tell me where went wrong. Keep this in mind: log file is good for debugging issues especially on QA or customer side. STL fstream, ifstream, ofstream is convenient to use.

2. Be patient about compiler / link error never met before. Recently I solved two such errors: 1) 3rd party library conflict issue: GELIB VS RealDWG. For RealDWG, it's a rich toolkit which contains ASM, GELIB and dwg development required libs; and there is a separate GELIB library. In my case, both libraries were used together in the application. So for some projects, if it only depends on GELIB, there is no problem; if it depends on both GELIB and RealDWG, the best solution to fix the possible conflict is to let that project only use RealDWG and its inner GELIB. 2) Template class argument issue.

StrongRef<ComponentInstances> rCompInstances;
ComponentInstance::Make(rCompInstances, pCompDef, name, matrix); // ComponentInstance::Make(PassiveRef<Component> rCompInsts, ..)

Above code snippet will cause compiler error telling template class's argument is not matched:

error C2440: 'initializing' : cannot convert from 'Ns::Comp::ComponentInstances *' to 'Ns::Entity *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
PassiveRef.h(141) : see reference to function template instantiation 'Ns::StrongRef<T>::StrongRef<Ns::Comp::ComponentInstances>(const Ns::StrongRef<Ns::Comp::ComponentInstances> &)' being compiled
1>          with
1>          [
1>              T=Ns::Entity
1>          ]
DWGTranslator.cpp(149) : see reference to function template instantiation 'Ns::PassiveRef<T>::PassiveRef<Ns::Comp::ComponentInstances>(const Ns::StrongRef<T> &)' being compiled
1>          with
1>          [
1>              T=Ns::Comp::ComponentInstances
1>          ]

If the first line of above code snippet is defining a PassiveRef<Component>, it will be compiled without errors. The fact of this issue is: sometimes a pre-declaration of a class is enough and sometimes the class definition is required; for this case, as there will happen a conversion from StrongRef<COmponent> to PassiveRef<Component>, COmponent class definition needs to be known so its header file instead of just a "class component" is required: include <componentInstances.h>, get it fixed.

 

3. Using Namespace organizes utilites instead of using class + static functions

4. size_t VS int

size_t unsigned int类型, int 是 signed int类型. the c programming language 规定 signed int 可以赋给unsigned int 而unsigned int 不能随便赋给signed int.
根本原因是,在C/C++中,从一个有符号整数转换到无符号整数时,转换规则是确定的,即使转换数值不在无符号数的表示范围内;但从一个无符号整数转换到有符号整数,当发生超出无符号数的表示范围时,转换结果是实现相关的。
1) If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type). [Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there
is no truncation).
2) If the destination type is signed, the value is unchanged if it can be represented in the destination type (and bit-field width); otherwise, the value is implementation-defined.

posted @ 2011-05-17 15:47  能巴  阅读(244)  评论(0编辑  收藏  举报