The danger of typo’s in a switch statement in C

December 1st, 2009

A typo in a case label or default label inside a switch statement can result into normal labels without the compiler complaining. This can introduce serious and hard to find bugs. This will happen in the following two situations:

1. The space in case<space><number>: is forgotten.
2. Any typo in the default: label.

Consider the following code:

/* A typo in the case labels or default label in a switch statement
 * can result into a normal label in the following situations:
 * 1. The space in case<space><number>: is forgotten.
 * 2. Any typo in the default: label.
 * What mostly happens is that the statements under the wrongly typed case label
 * will be part of statements under the case label above. These statements
 * usually end with the break statement and thus the statements under the wrongly
 * typed case label will never be executed.
 * Author: Bianco Zandbergen, november 2009      
#include <stdio.h>
int main(void)
    int i = 0;
    int t1 = 0;
    int t2 = 0;
    switch(i) {
        case 1:
            printf("Case 1\n");
        case2: /* A typo in 'case 2:' results into a normal label */
        defaultt: /* A typo in 'default:' results into a normal label */
    /* lets test if we can jump to these labels */
    if (t1 == 0) {
        t1++; /* avoid looping */
        goto case2;
    if (t2 == 0) {
        t2++; /* avoid looping */
        goto defaultt;
    return 0;

While it is correct that the compiler does not complain (a label can be put anywhere), i think it would be wise if the compiler generates a warning when using the default options.

Output of gcc 4.3.4 on GNU/Linux with the code above:

bianco@box ~/temp/label $ gcc -o label label.c
bianco@box ~/temp/label $

Output of Borland C++ compiler 5.5.1 on Windows with the code above:

C:\dev\C\labels>bcc32 label.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

Running Minix 3 on a Neoware Neostation 3000

June 16th, 2009

I’ve installed Minix 3 on my Neoware Neostation 3000.

My Neostation 3000 is equiped with a 233MHz AMD Geode processor, 32MB SD-RAM in the SO-DIMM slot, one normal SD-RAM DIMM which was empty during installation ,one IDE interface and RTL8139 network chip (which is supported by Minix). Installing an Operating System on the Neostation is less easy than on a regular PC.  First it does not have a build-in optical drive, but it does have an IDE interface. According to this site the Neostation has problems with two devices on the IDE interface. So you can’t connect both a harddrive and an optical drive at the same time. My ‘harddrive’ is a 4GB Transcend Compact Flash card connected to a CF->IDE converter. I’ve connected my CF card with the converter on an other machine and installed Minix from an optical drive. At the installation i choose to use the RTL8139 card even though my system does not have one. After installation it might hang for a while on not finding the ethernet card but you can skip it by pressing control+c. After the installation was done i’ve removed the CF card and put it in the Neostation and it works fine. I’ve put 256MB extra RAM in the free DIMM slot but onfortunately it only supports 128MB per slot, so only 128MB is usable.  Some other ways to consider installing an OS on the neostation is using an USB drive or copying the image to your drive using an other system.

Neostation 3000 with a Transcend 4GB 133x card on an CF->IDE converter

Neostation 3000 with a Transcend 4GB 133x card on an CF->IDE converter

We don't want a short-circuit do we?

We don't want a short-circuit do we?

XMOS XC-1 review

March 28th, 2009

A few months ago i found XMOS a semiconductor startup from Bristol.
XMOS has designed a very innovating new embedded processor (XS1-G family). They call their technology “Software Defined Sillicon”. Components that are traditionally implemented in hardware can be done in software running on the new processor. You can think of UART’s, SPI, I2C, PWM and even Ethernet MAC and USB 2.0 MAC.
I decided to order an evaluation board, the XMOS XC-1. I have received it more than two months ago and had some time to play with it (although i wish i had some more time).

“Software Defined Sillicon” devices are made up of Xcore tiles. Each Xcore has its own dedicated memory. Each Xcore can run 8 threads simultanously. This means that the quadcore XS1-G4 can run 32 threads simultanously! If the chip is running at 400MHz (400MIPS), each thread is guaranteed to be able to use 50MIPS, but each thread is limited to 100MIPS. This means that you cannot run 1 thread using all the processor time.  Context switching between threads are done by a hardware scheduler and based on events (i.e timers, I/O, communication). Threads that block waiting for an event are not scheduled.  Because each thread has its own set of registers context switches do not take time. This makes it possible that an interrupt can be served next-cycle!. Threads can communicate with eachother through Xlink channels. These Xlinks makes it possible to communicate between cores. It is even possible to communicate between devices, making possible to build a grid of SDS devices.

Xcore Tile Architecture

Xcore Tile Architecture



XC-1 evaluation board

The XC-1 evaluation board contains just the most basic interfacing components:

  • 12 dual color (green/orange) leds set up as a clock.
  • 4 buttons
  • 4 button leds
  • piezo speaker

The board offers additional expansion ports in which you can solder 0.1″ headers to interface with your own circuit.

If you want to have a lot of interfacing components like color LCD, audio out, ethernet etcetera take a look at the XDK XS1-G development kit.

Pictures of the XC-1

XC-1 Case

XC-1 Case

XC-1 Case opened

XC-1 Case opened

XC-1 Front

XC-1 Front

XC-1 Back

XC-1 Back

XS1-G4 Closeup

XS1-G4 Closeup

More will follow…

Perfboard design software

February 9th, 2009

When creating a perfboard design you sometimes want to plan out where to place components and wires before you start with it. Doing this on the old way with pen and paper is frustrating. I have found 2 applications in which you can design your perfboard: DIY Layout Creator and Lochmaster.

DIY Layout Creator is free and is java based so it should run on most operating systems.

Lochmaster is not free, you can download a demo to evaluate lochmaster (The demo has limitations.)

One of the most important features of such an application is the abbility to define your own components. Components are safed in .xml format in DIY Layout Creator. There is no tool available to create components. Thus creating new components in DIY Layout Creator is. Lochmaster has some limited capabillity to create new components. I did this by breaking an existing component in parts and modify it. After i’m done with that i can generate a new component to safe my modifications.

Due to the lack of creating components in DIY Layout Creator i have chosen to use Lochmaster.

One of my results:

OpenLaserFrag sensor node in Lochmaster

OpenLaserFrag sensor node in Lochmaster


OpenLaserFrag sensor node implementation on perfboard

new games

December 27th, 2008

Running MOH:AA on recent nVidia cards

December 26th, 2008

I have tried several times to run MOH:AA the last couple of years and it always crashed and returned to the desktop immediately. The difference with my old system on which i used to play mohaa is newer hardware and newer Windows XP (XP no SP -> SP2) The problem seems to be related to the graphics driver. I found the following solution:

Install nHancer.

Run nHancer and let it scan your PC.

I’m not sure if this is enough.

I also clicked tools -> write all profiles to registry.

At least make sure ExtLimit is 11a8.




December 11th, 2008

Today i visited Demcon, a company specialized in mechatronics. They gave a tour in the company today. I was a bit late so the presentation about the company was already started when i arrived. After the presentation we had some demo’s of some of their products: A humanoid robot, a smart tennis robot and a foot photographing device (yes i know it might sound weird :p).

White wallpaper after malware infection

October 29th, 2008

I’ve got infected by some malware yesterday that also changed my wallpaper (Windows XP machine).
After removing the malware i couldn’t change my wallpaper.
I had the following symptoms:

  • Can’t change wallpaper, it stays white.
  • The icons on the desktop are blue shadowed and the text underneath the icons have a blue background.
  • You can’t click on the icons itself, only the text underneath the icon.

I was looking for the problem in the registry but couldn’t find it.

The fix is surprisingly simple:

  • right click on your desktop and select ‘properties’.
  • Select the ‘Desktop’ tab.
  • Click on the ‘Customize Desktop…’ button. A new popup window opens called ‘Desktop Items’.
  • Select the ‘Web’ tab.
  • Make sure the ‘Privacy Protection’ option is not checked.
  • Click on ok. The window will close and click on apply settings on the properties window.

My first MAC!

October 20th, 2008

I have bought an Macbook Air!

It will replace my old laptop which is struggling with more and more problems. I have looked to other ultra portable laptops (screen <= 12″)  but most of them were to high prized or too ugly or had specifications i did not like. Two candidates were the Toshiba Portege R500 and the Lenovo Thinkpad X60. According to reviews the keyboard of the R500 is a bit fragile and the Thinkpad X60 has no touchpad!. The Macbook Air is high prized also (1799 euro), but i bought it from ebay which saved me about 500 euro. I think it’s a very good deal.

The party was over when i discovered that there was no european power plug included, so i had to buy one from a webshop. A week later i received the plug and i was finally able to start the Macbook up. Soon i discovered that the battery was not recognized and the Macbook immediately shuts down when i remove the MagSafe plug. I tried to do an System Management Controller (SMC) reset with no luck. I brought it to an Apple shop and they have repaired it under warranty. Now everything is working fine.

OpenLaserFrag 0.9 Firmware’s tested :)

September 29th, 2008
OpenLaserFrag 0.9 Firmware test platform

OpenLaserFrag 0.9 Firmware test platform

The red LED in the center indicates a player is hit and received a timeout (is unable to shoot). The white LED simulates muzzle flash and burns when shooting.
Microcontroller on top is the Personal Unit, On the left bottom is the weapon and right bottom is the Sensor unit.