Learning C from simulations, #1

Coming from the beauty of Python, now I have to learn C/C++ again (after the course some semesters ago!:P) because of my work. I’m doing this working with the simulation code Gadget2 and the ICs (initial conditions) generator N-GenIC. Here I would like to pin the serious and less serious things I’m learning for my and maybe other’s usefulness and fun!


When I write little pieces of code I usually find Kate comfortable enough but to explore projects like Gadget2 I prefer to use something like KDevelop because it’s easier to manage where a variable is defined, declared and used. And it do this only by positioning the mouse on the variable name. If you put the mouse on a known function (from the standard library for example), KDevelop will open the documentation for you.


Doxygen is a documentation system. It allows you to produce documentation for a project from the comments in the code. With no additional work you can comment your code and be ready to produce the documentation. In KDevelop Doxygen style for comments has a different (and nice) coloring.

Single file compilation
I your C program is simple and short, and fit in a single file you can compile it to produce the executable file with

gcc -O3 -Wall sort.c -o sort.exe

where gcc is the GNU compiler, -O3 is the level of optimization, -Wall activate the print of all the warnings, sort.c is your source code file and -o sort.exe specify the output file (default is “a.out”).

I’ve also learned some other things, but a good combination of my laziness and the fact that it’s not always useful to rewrite things already well-written let me give you the links to those resources!:)

Maybe in the next episodes I will understand how to manage headers, implementations, object files and other funny things!:P

comments powered by Disqus