[Tip: log file] some quick notes

Source: Internet
Author: User

1.Log FileIs 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 patientAbout 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>
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>
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 type, Int Is signed int type. The C programming language specification Signed int can be assigned to unsigned int, while unsigned int cannot be assigned to signed Int.
The root cause is that, in C/C ++, the conversion rules are fixed when converting from a signed integer to an unsigned integer, even if the value to be converted is not in the value range of the unsigned number, it is converted from an unsigned integer to an unsigned integer. When the value exceeds the value range of the unsigned number, the conversion result is implementation-related.
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.