Using gcc compilation parameters in Linux gcc to improve code Quality

Source: Internet
Author: User

In Linux, GCC is a common compilation tool. However, there are many special parameters during GCC compilation, such as compiling to a dynamic link library. Here I would like to mention how to use the GCC warning function to Improve the Quality of code writing.

For example, we want to eliminate useless local variables and unused function parameters. If we use manual check, this workload is very large. It is very easy to use GCC here. In GCC, several parameters are implemented in combination with-W. Unused-variable is a local variable that is not used. Unused-parameter is a function parameter that is not used, implicit-function indicates that the function is used without declaration. Char-subscripts indicates that the char type is used as the array subscript. If the return type does not match, the corresponding return-type is used.

For example,-wunused-parameter-wunused-variable indicates that you need to check both used parameters and unused local variables. -Wall indicates that all checks are enabled,-wall-wnounused-parameter indicates that unused parameters are enabled, and other checks are enabled. -Wuninitialized checks whether automatic variables are initialized before use. When this parameter is enabled, note that the-O option must be added to optimize compilation.

For more details about GCC compilation options, see http://php.freehostingguru.com/gcc_2.htm

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.