Git Product home page Git Product logo

knk's Introduction

KNK

Programming exercises for KN King's book C programming - a modern approach.

Pre 359

Compile *.c files with:

export BASENAME=<filename without '.c' extension>
gcc -Wall -Wextra -std=c99 ${BASENAME}.c -o ${BASENAME}.bin

Then run the binary with:

./${BASENAME}.bin

Post 359

Makefiles are introduced at 359. Compile subsequent projects with:

make

The above command should generate an executable file, e.g. program, which can then be run as follows:

./program

Clean up the tree with:

make clean

Formatting with clang-format

clang-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.c

Debugging with Valgrind: memcheck

valgrind 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 ./program

To 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.

Debugging with Valgrind: cachegrind

# TODO

Debugging with Valgrind: callgrind

# TODO

Other


Have gcc generate Assembler code

gcc -c -S main.c   # generates main.s

Printing the shared objects (shared libraries) required by each program or shared object specified on the command line:

ldd program

List the symbols from an object file:

nm main.o

knk's People

Contributors

jspaaks avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.