Programming exercises for KN King's book C programming - a modern approach.
Compile *.c files with:
export BASENAME=<filename without '.c' extension>
gcc -Wall -Wextra -std=c99 ${BASENAME}.c -o ${BASENAME}.binThen run the binary with:
./${BASENAME}.binMakefiles are introduced at 359. Compile subsequent projects with:
makeThe above command should generate an executable file, e.g. program, which can then be run as follows:
./programClean up the tree with:
make cleanCMakeLists.txt files are introduced at 45607. Compile subsequent projects with:
mkdir build
cd build
cmake --build .
cmake --install .
# run the resulting program with:
./dist/bin/programclang-format formats *.c files (as well as other formats), is customizable, and can inherit
from existing published style guide, e.g. Google, LLVM, etc. See
https://clang.llvm.org/docs/ClangFormatStyleOptions.html.
# print warnings, don't change files
clang-format -Werror --dry-run main.c
# print main.c to stdout including changes,
# but don't change main.c itself
clang-format main.c
# change file in-place
clang-format -i main.cvalgrind can help detect various kinds of errors. By default it runs memcheck, which detects memory errors:
$ valgrind ./program
$ valgrind tool=memcheck ./program
$ valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./programTo have Valgrind output the relevant line numbers, recompile the binary with -g flag ("include debugging information")
and -O0 ("disable optimization"). Note that this requires recompiling the objects as well.
See https://valgrind.org/ for more information.
# TODO
# TODO
- https://cdecl.org/ for decoding declarations
Have gcc generate Assembler code
gcc -c -S main.c # generates main.sPrinting the shared objects (shared libraries) required by each program or shared object specified on the command line:
ldd programList the symbols from an object file:
nm main.o