This topic was published by DevynCJohnson and viewed 942 times since "". The last page revision was "".
- Topics - 444
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
-Werrorflag to convert warnings into errors.
Of all of the warning flags,
-Wall -Wextra -pedanticare 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.
- Programming and Development - http://dcjtech.info/topic/programming-and-development/
- C Programming Article Forum - http://dcjtech.info/forum/articles/programming/c-c-and-c/
- Linux Compilers - http://dcjtech.info/topic/linux-compilers/
- GNU-Toolchain - http://dcjtech.info/topic/gnu-toolchain/
- C vs C++ vs Objective-C vs etc - http://dcjtech.info/topic/c-vs-c-vs-objective-c-vs-etc/
- C Code Examples: Array Rotations - http://dcjtech.info/topic/c-code-examples-array-rotations/
- C Code Examples: Cyclic Redundancy Check (CRC) - http://dcjtech.info/topic/c-code-examples-cyclic-redundancy-check-crc/
- C Code Examples: File IO Tests - http://dcjtech.info/topic/c-code-examples-file-io-tests/
- C Code Examples: Stack and Queue Datatype - http://dcjtech.info/topic/c-code-examples-stack-and-queue-datatype/
- 8051 Microcontroller and Assembly - http://dcjtech.info/topic/8051-microcontroller-and-assembly/
- Embedding Files in C Source Code - http://dcjtech.info/topic/embedding-files-in-c-source-code/