C (by )

To be fair, it's not all C's fault. A lot of it seems to be the fault of something in the toolchain. For example, I spent the best part of a day fighting with the fact that my code threw a segfault before entering main when I tried to link against a library I needed. I tried to get gdb to let me breakpoint the entry point of the resulting binary so I could step through the pre-main startup, but it wouldn't. Eventually I found out that the problem was that the start address defined in the ELF header was garbage - 0x75 or something, pointing well into the unmapped zero page. Listing the libraries in a different order made it work again.

Then there was the day spent trying to trace down a core dump that defied explanation, and turned out to be occuring within the stub code that ld.so initially points every function call into an shared library to, which demand-links that function. I don't know why it was dumping core in there, but rearranging my build process so as to make it not use libtool made the problem go away.

I've spent a few days on some problems which probably are C's fault, though. A third party library I use seems to perform double frees repeatably, but only under certain very specific configurations, and I've yet to find rhyme or reason in them. One particular source of difficulty there is that it's hard for me to keep any one configuration around to play with since I have to keep migrating to different hardware, as successive groups of servers are sent out to the datacentre to go live. I've yet to find out if it's my code at fault, corrupting the internal data structures of this library, or the library itself.

But the thing is, all of this is familiar. In hindsight, I can remember spending a lot of my time as a C programmer hunting down obscure bugs. But I can't remember spending much of my time as a Java, PHP, Python, Scheme, or various other kinds of programmer doing that kind of thing. The bugs that arise in garbage collected languages with safe pointers tend to be immediate and relatively obvious, rather than sporadic and caused by code totally unrelated to the code that's reporting the error. In fact, I can remember ending up abandoning hobby projects due to bugs I couldn't hunt down.

I therefore resolve to do as little C programming as I can in future! Chicken Scheme is a lovely language, and happily links against all the C libraries I need, and generates C code so I can use it in places where I have to provide a C interface to something.

The only problem is - C still has a lot of mindshare. Will I be able to get away with using a non-mainstream language, or will clients demand C?

Pages: 1 2

1 Comment

Other Links to this Post

RSS feed for comments on this post.

Leave a comment

WordPress Themes

Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales
Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales