a.k.a how we test Your code Debugging a.k.a how we test Your code
Some methods Making the compiler (gcc) “furious” Valgrind gdb Tools provided by the IDE 2017
gcc -Wall – show ‘most’ of the default compiler warnings -Wextra – show even more of the default compiler warnings -pedantic – strict ISO C -Wunreachable-code – code, that will never be run -Wfloat-equal – floating point comparisons -Wshadow – two variables with the same name in the same scope -Wconversion – possible errors due to different types -Wmissing-declaration – no previous declaration of function prototype -g – debugging symbols e.t.c. 2017
gdb It can run code line by line You can observe the values of your variables See the last lines executed before program crash Manually assigning values to variables e.t.c. More on the subject: man gdb internet 2017
Valgrind – identifying memory issues For now: Using uninitialized variables Reading from memory locations not belonging to you Writing to memory locations not belonging to you Using NULL pointers Using invalid pointers In the future: Memory leaks (lost pointers) Unreleased resources Recurring frees to resources e.t.c 2017
How to use it? Additional flag to compilation -g (same for gdb) gcc -g -o myprogram codefile.c -Wall -g adds debugging symbols to the compiled binary so that you can for example find the line number that causes the error To run it valgrind --tool=memcheck --leak-check=full ./myprogram 2017