- Language
- Platform
- Compilers
- Libraries
The stack of C will be:
- gcc – the compiler
- as – the assembler
- ld – linker
- libc – the C library
Additionally we will need a text editor, and a debugger usually known gdb.
This saturday Patricio Paez gave a talk at Linux cabal on Saturday 28. So the talk main focus is not learning C or Python but a broad view of the interaction between Python and C. The first part was thinking about the way code works. First we will need the following elements:
- Language
- Platform
- Compilers
- Libraries
The stack of C will be:
- gcc – the compiler
- as – the assembler
- ld – linker
- libc – the C library
Additionally we will need a text editor, and a debugger usually known gdb.
A simple sample would be a Hellow World hola-1.c:#include <stdio.h>int main(){ printf("Hola Mundon");}
$ gcc -o hola-1.c hola
#include <stdio.h>int main(){ printf("Hola); printf ("Mundon");}
The result would be the same.
A very importat topic is using version control. Like we went through the last change we had a version 1 of hola and a second version on hola-2.c To use this versioning we could use some tools mainly:- diff
- patch
We can use diff by typing:
]$ diff hola-1.c hola-2.c 5c5,6< printf("Hola Mundon");---> printf("Hola);> printf ("Mundon");
$ sdiff hola-1.c hola-2.c #include <stdio.h> #include <stdio.h>int main() int main(){ { printf("Hola Mundon"); | printf("Hola); > printf ("Mundon");} }
We can see the > and the | stablishing the change from one file to the next. We will use the -o option to merge the differences. This is also an interactive mode.
For the command line impared there is tkdiff which basically is a gui front end to the difference. tkdiff is available on most distros. Although I couldnt find it and instead have gtkdiff, a curses tool also exist called imediff. imediff2 is a curses based tool which uses colors to quickly see the differences as opposed of using a | and > < characters. Unfortunately I coldn’t find this tool in mandriva. Finally the most popular is vimdiff, vimdiff is based on the vim editor. Doing vimdiff tools you will see a combination of curses and the vim editor. You will have 2 panes with each file at each side of the window. You will be able to put some of the keys.- dp – delete and put the difference
- ctl-w -> / L will switch the left panes.
- g – get the changes
Finally a python based is meld, also is pretty nice stylish way. Patch was created by Larry Wall, to use path commonly people will make a diff to a 3rd file.
diff -o hola-1.c hola-2.c > hola-path.cpatch -p0 < hola-patch.c
To have a versioning systems is another tool which are used on multi-user projects we can use systems like:
- rcs – revision control system
- cvs – control/concurrent versioning system
- svn – subversion
Finally the debugging steps which we can use using some samples which I wont put on this post. However the steps to debugg we will asume we have some files called loop.c.
First we will do some compiling:# gcc -o loop loop.c# ./loop
# gcc -g -o loop loop.c# gdb loop
We will have a second command line, some tools are:
- run – will execute the file with errors
- start – will
- n/next – next will go step by step
- arrow bottons – you can go to the next or previous step
- step – similar to next but will get within the functions
- backtrace – we can see what happened previously
- kill – salir del programa de manera emergente
- finish – suficientes next hasta terminar
- print buff – we can print the current buffer
- quit/q – to end the process
Here we can go back to the difference using vi -d or vimdiff we can save having 2 files using on their panes doing:
$vi -d loop-{1,2}.c
There is a document called the linux kernel module programming guide which has a good guide about this kind of tools for those lonely nights.
Python
So now we move into Python and the way to use it:
python:>> import re>> help(re)>> re.findall('a+', 'abcdefg aabccefg')
We can make extensions in for python in C. This is a bit more challenging but it still possible.