[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.

转载于:https://www.cnblogs.com/taoxu0903/archive/2011/05/17/2048965.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值