Compiler Warnings are Helpful; Do Not Ignore

This topic was published by and viewed 665 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author
    Posts
  • DevynCJohnson
    DevynCJohnson
    Keymaster
    • Topics - 444
    • @devyncjohnson

    Many programmers disregard compiler warnings, and numerous programmers do not use all of the available warning flags. This is a poor choice in programming. Compiler warnings are very important; fixing such warnings in the code can fix weird bugs, reduce security flaws, enhance performance, provide portable source code, and yield better programs.

    Many compilers (whether they be for C, GoLang, Vala, Java, etc.) provide many compiler checks that can produce warnings and/or errors. A warning or error indicates poorly written code or a minor over-sight. Many programmers see warnings and disregard it as long as the program still works. However, such behavior harms the quality of the program. The computer does not issue a warning for no logical reason. In other words, if a warning is seen, there is a legitimate issue with the code that should be fixed. Many programming projects yield warnings when compiled such as the Linux kernel, Busybox, Python-Interpreter (CPython), Glibc, and other commonly used software. Programmers must strengthen their programming skills to produce better code. The Betabot source code and Pybooster are examples of two projects that compile flawlessly.

    On GNU-GCC's website, there is a page dedicated to listing the warning flags that are supported (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html). When compiling C code, developers should use the below listed flags.

    -Wall -Wextra -pedantic -Wformat -Werror=format-security -Wformat-nonliteral -Wformat-signedness -Wformat-y2k -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wstrict-overflow=5 -Wuninitialized -Wshadow -Wpointer-arith -Wcast-align -Wcast-qual -Wwrite-strings -Wredundant-decls -Wnested-externs -Winline -Wconversion -Wbad-function-cast -Wdouble-promotion -Wmissing-include-dirs -Wswitch-enum -Wswitch-bool -Wsync-nand -Winit-self -Wsuggest-final-types -Wsuggest-final-methods -Wundef -Wdate-time -Wjump-misses-init -Wlogical-op -Wopenmp-simd -Wpacked -Winvalid-pch -Wunsafe-loop-optimizations -Wvector-operation-performance -Wdisabled-optimization -Wstack-protector -Wswitch-default -Wpadded

    Such flags will show programmers many inconstancies, security issues, performance flaws, and other problems that were not resolved. Once all of the listed issues are properly fixed, the code can be compiled to produce more secure and optimized code.

    Some serious programmers may want to use the -Werror flag to convert warnings into errors.

    Of all of the warning flags, -Wall -Wextra -pedantic are the three most important. These flags also enable numerous code checks.

    When writing code (before compiling), many problems can be found by using lint checks. To check the C programming language, developers can use splint, cppcheck, KWStyle, etc.

    If a developer wishes to produce better code, then one can start by resolving warnings and using proper programming habits.

    Further Reading

Viewing 1 post (of 1 total)