# C programming
WARNING
This page is actually in active development state. Many information will be available soon.
DANGER
I am not a C expert. This language is kinda hard to master, even more when you are using other high level language at the same time. During the past years, I used C for my own personal projects, but never feel really comfortable to use it in daily basis. Anyway, because it is not an easy language, there is lot of things to talk about it. I hope these few notes will help you to avoid some of my mistakes I did in the past.
# Introduction
# Programming
TODO
# Concurrent and Parallel Programming
TODO
# Network Programming
TODO
# Testing
Test suites and test cases are probably the most important part of any
language. It will not remove bugs, but will help you to define your
needs and create a stable software. I mainly used two open-source
framework, atf and minunit. Both are really
light and can help you to define strong test suites.
Another important thing to test when developping in C is the memory
allocation. Unfortunately, I only used valgrind few
times, to ensure all my memory allocations were working find. On
OpenBSD and other system, you can also find different malloc
implementation which can help you during development phase. Here a few
list of them:
- OpenBSD malloc (opens new window)
- TLSF (opens new window)
- rpmalloc (opens new window)
- Doug Lea Memory Allocator (opens new window)
A curated list of actively maintained malloc can be found there:
# Documenting
TODO
# Debugging
TODO
# Tracing
TODO
# Deploying
TODO
# Open Source Project Development
TODO
# FreeBSD
# OpenBSD
# NetBSD
# Linux
# FAQ
# How to define a global data structure?
#include <stdio.h>
struct mystruct {
int id;
char *data;
}
int main (void) {
struct mystruct test;
}
# How to define a global type?
#include <stdio.h>
typedef struct mystruct {
ind id;
char *data;
} mystruct;
int main (void) {
mystruct test;
}
# How to manage memory?
Managing memory is probably one of the main issue with C. Many different libraries exist to help developers to manage the memory with simple routines.
# Do you have a list of alternative C compilers?
- https://gcc.gnu.org/ (opens new window)
- http://clang.llvm.org/ (opens new window)
- http://bellard.org/tcc/ (opens new window)
# How to use enable posix thread during compilation?
cc -l pthread -o yourfile yourfile.c
# How to insert raw assembly in your C code?
__asm__("movl %edx, %eax\n\t"
"addl $2, %eax\n\t");
- http://stackoverflow.com/questions/61341/is-there-a-way-to-insert-assembly-code-into-c (opens new window)
- http://www.codeproject.com/Articles/15971/Using-Inline-Assembly-in-C-C (opens new window)
- http://www.nongnu.org/avr-libc/user-manual/inline_asm.html (opens new window)
# How to trace a function call?
- http://www.delorie.com/gnu/docs/binutils/gprof_25.html (opens new window)
- https://gcc.gnu.org/onlinedocs/gcc-4.5.1/gcc/Code-Gen-Options.html#index-finstrument_002dfunctions-2114 (opens new window)
- http://stackoverflow.com/questions/10374005/how-to-trace-function-call-in-c (opens new window)
- https://balau82.wordpress.com/2010/10/06/trace-and-profile-function-calls-with-gcc/ (opens new window)
# How to debug a child or a parent after calling fork?
- http://www.sourceware.org/gdb/onlinedocs/gdb/Forks.html
- http://stackoverflow.com/questions/6199270/how-do-i-debug-the-child-process-after-fork-in-gdb
- http://visualgdb.com/gdbreference/commands/set_follow-fork-mode
- http://reverseengineering.stackexchange.com/questions/2241/gdb-on-freebsd-and-follow-fork-mode-child
# How to debug threads?
‘thread thread-id’, a command to switch among threads ‘info threads’, a command to inquire about existing threads ‘thread apply [thread-id-list] [all] args’, a command to apply a command to a list of threads thread-specific breakpoints ‘set print thread-events’, which controls printing of messages on thread start and exit. ‘set libthread-db-search-path path’, which lets the user specify which libthread_db to use if the default choice isn't compatible with the program.
- https://www.sourceware.org/gdb/onlinedocs/gdb/Threads.html#Threads
# How to use Valgrind?
- http://valgrind.org/
- http://valgrind.org/docs/manual/manual.html
# References and Resources
← アタエタ