C programming language most popular

April 22, 2010 Leave a comment

Good news for C programmers: The April 2010 update of the TIOBE index shows that C is the most popular programming language. With about 18% it is close to Java, but 0.007% ahead. Of course, there is criticism of how to measure language popularity, and there are other methods as well. But it is good to know that doing low-level work in C is staying on the popular and important side of software development.

Categories: programming Tags:

Coding in C song

March 14, 2010 Leave a comment

This is a funny song for everybody writing C code:

Categories: programming Tags: , ,

Compiler optimization

January 13, 2010 2 comments

I saw this a while back, but i still think that this is an impressive example of what modern compilers can do. Say, when writing C code you have the need to rotate bits. There is no rotate operator in C so the bit rotation has to be implemented like this:

$ cat rotate.c
unsigned long rotate_left(unsigned long a, unsigned int shift)
return a << shift | a >> (sizeof(a) * 8 - shift);
unsigned long rotate_right(unsigned long a, unsigned int shift)
return a >> shift | a << (sizeof(a) * 8 - shift);

Now compile it with gcc (version 4.4.1 here, but most other versions should do the same):

$ gcc -c -O rotate.c

The compiler knows that the C code only rotates the bits and that this can be done with the x86 rol and ror instructions:

$ objdump -d rotate.o

rotate.o: file format elf32-i386

Disassembly of section .text:

00000000 :
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 4d 0c mov 0xc(%ebp),%ecx
6: 8b 45 08 mov 0x8(%ebp),%eax
9: d3 c0 rol %cl,%eax
b: 5d pop %ebp
c: c3 ret

0000000d :
d: 55 push %ebp
e: 89 e5 mov %esp,%ebp
10: 8b 4d 0c mov 0xc(%ebp),%ecx
13: 8b 45 08 mov 0x8(%ebp),%eax
16: d3 c8 ror %cl,%eax
18: 5d pop %ebp
19: c3 ret

This means that it is usually the best thing to write readable C code and let the compiler optimize things. Modern compilers can be pretty good at this.

Categories: programming Tags: ,

Key ham radio transceiver from command line

October 3, 2009 2 comments

Related to the hamfax project, i have been asked how to key a ham radio transmitter that is connected to the serial port. So far this is fairly untested, i only put together what i think would solve the problem. Please use this as input for your own solutions if it helps you. If something is wrong, i would appreciate corrections.

Basically, this is just a simple program to make use of the circuit at http://www.baycom.org/~tom/pcf/ptt_circ/ptt.html#serial

C program serial_rts_set.c

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>

  Usage: serial_rts_set device_file sleep/seconds
  e.g.   serial_rts_set /dev/ttyS0 10000

int main(int argc, char** argv)
  char* devfile;
  int fd;
  int rc;
  int status;
  unsigned int seconds;

  if(argc<3) {
     puts("Not enough arguments.\n\n"
          "Usage: serial_rts_set devicefile timeout\n"
          "devicefile   Device file for serial port, e.g. /dev/ttyS0\n"
          "timeout      Timeout in seconds\n");

  devfile = argv[1];

  seconds = 0;
  sscanf(argv[2], "%d", &seconds);

  fd = open(devfile, O_RDWR);
  if(fd == -1) {
    perror("Could not open device file: ");

  rc = ioctl(fd, TIOCMGET,&status);
  if(rc == -1) {
    perror("Error during TIOCMGET: ");

  /* Set the RTS bit to raise the RTS line */
  /* The reverse operation would be status&=~TIOCM_RTS; */

  rc = ioctl(fd, TIOCMSET, &status);
  if(rc == -1) {
    perror("Error during TIOCMSET: ");


Compile and use it with:

gcc -o serial_rts_set serial_rts_set.c

Test with

./serial_rts_set /dev/ttyS0 5

to set the RTS line for 5 seconds.

Running from a shell script


# Start the RTS set program in the background and remember
# its process id (PID) for stopping it later. $! is the PID of the
# most recently executed background command.
# The time passed to sleep_rts_set has to be longer than the time
# that is actually used for keying the transmitter.
serial_rts_set /dev/ttyS0 20 &

# Do whatever is necessary while the transmitter is keyed
sleep 10

# Stop the transmit by stopping the RTS set program
kill $RTS_PID

References and more information

Categories: ham radio, Linux Tags: , ,

Diplomarbeit / diploma thesis

August 25, 2009 Leave a comment

This happened a while ago, but in case somebody is interested, here is the public version of my diploma thesis. It is written in German language with the title “Erweiterung einer standardisierten Software-Komponente zur effizienten Ansteuerung gro├čer Tape-Libraries” (Extending a standardized software component for efficient control of large Tape Libraries). As part of this work, i analyzed different interfaces to tape libraries and evaluated how to integrate them with IEEE 1244 based media management systems.

The thesis was written with using the LaTeX typesetting system, i can provide the source files upon request.