Recently, we need to clear the warning in the project. PG does not know much about the differences in programming in Linux and Windows, resulting in a lot of compiling Warning, I can only help them solve the problem sadly. C ++ is less casual than Java. As the underlying layer of the project, it attaches importance to Warnig to maintain code robustness and fix potential bugs. In addition, it is necessary to maintain 0 Warning if it is provided to a third party as lib in the future. The following describes the major Warning generation points:
Note: Online compiler http://codepad.org/is recommended for testing /)
1. format warning
If you print the information in % x hexadecimal format, it may be warning. The hexadecimal format is unsigned, But it matches the unsigned int type. In Windows, int and long are considered the same, but in Linux, long! = In intLinux, long is related to the machine font length. The 32-bit host occupies 4 bytes and the 64-bit host uses 8 bytes. In Windows, the 64-bit host uses 4 bytes, which is equivalent to int ). Therefore, % x cannot match unsigned long.
2. comparison warning
This type of warning is generated when the signed variable is compared with the unsigned variable. For example, when sizeof and strlen are used to receive the return value using size_t according to their return type. In this case, if we directly compare them with int or long type variables, there will be warning. Size_t is defined in the Standard C library and should be an unsigned int, but it is a long unsigned int in a 64-bit system. In this case, we recommend that you perform a signed conversion for the unsigned image.
3. reorder initialize warning
This occurs when the class is used. It is mainly because the initialization sequence of the member is inconsistent with the sequence defined in the class when the constructor uses the initial value table to initialize the member variable. This issue is found when G ++ is compiled.
4. missing braces warning
This type of warning is generated when struct is nested and Initialization is nonstandard.
struct INER{ int m_i;};struct EXTE{ INER m_iner; int m_i;};
The above structure is defined. If we assign a value of 0 during initialization, several warnings will be generated during tool detection. Therefore, pay attention to this.
EXTE exte={0};
We recommend that you use the memset function to avoid unnecessary troubles when initializing struct variables.
For the moment, I will list several easily ignored issues and have the opportunity to supplement them. pay more attention to the specification in future coding to avoid unnecessary Warning.
This article is from the felix blog, please be sure to keep this source http://felixhwang.blog.51cto.com/3263859/1269403