make clean

December 17, 2007


Filed under: Uncategorized — k2sings @ 2:16 pm
Tags: , , ,

C as popularly called, is a spartan language that requires a lot of self
discipline to master it and make use of it.

The obsolute freedom and the straight interaction with hardware demands lot of
care, insight and discipline. There are questions on whether a programmer
should be forced to adapt to the ways of a particular language and I personally
dont know whether one should or shouldnt. Nevertheless it is interesting to go
reflect back on C language as a C programmer.

The winning advantages for C are,

No better language to do system programming (kernel, drivers)
across a varied computing architecture. And if an attempt is made to
create a new language in this domain, it will more or less look like C.

Performance. I dont know whether it is to do with the syntax of the
language or to do with the semantics of the language. Or whether it is do
with the people who were chosen to write the compilers. C compiled
binaries are the fastest.

Popularity. I leave it to the reader, since he could be knowing better than

Ecosystem. The toolchain, debugger, IDE, editors are best available for C.
Probably Java programmer could also make that claim, but I dont know any
other language which could measure up in providing that sort of
developer/development ecosystem.

What sucks ?

Pointers. One thing that demands atmost discipline.

Lack of constructs. Programming languages have evolved a lot, to be more
expressive. But when C was made into C++, it increased as much frustration
as it increased fun. Okay, did it increase the fun part ?

Preprocessors. Today it has become an indespensable supplementary tool for
the C language itself, especially for large projects. Without it is very
hard to make the C code portable.
But when a programmer wants to maintain a code, he had to parse two
languages in his mind and very many architectures along with that. Atleast
I find that harmful for my brain.

Portability. A programmer in 1980s would have made portability as a
winning advantage for C language, but the wheel of history have turned the
table around. Faster processors, mature virtual machines, dynamic
translation have made languages like Java and Python as reasonable options
for programmers. There is a section which cover the “features” in C
language that makes it less portable

Undefined features. Compile and run the following code snippet on Irix,
GCC and sparc machines. You will know what “Undefine feature” means.

int i = 10;
printf(” %d %d %d %d %x “, i++, –i, ++i, ++i, i++ );

And, there are quite a few “features” like this.

Is C Portable ?

Not when you compare it with Java or python. Especially Java.

Endianess. There is a perinnial problem of big endian or little endian.

Size of datatypes. The program/programmer cannot make assumptions on the
size of the basic data types like int, shot, long, char, pointer etc…

Memory alignment. Some processors require that the half-word, word, dword
memory access are aligned. That is a half-word (2 byte) memory access
should be only through address which are multiples of 2, a word (4
byte) memory access should be only through address which are multiples of
4 and so on.

Structure packing. Based on mem alignments and packing directives, the way
in the structure members are packed and padded can vary.

Pointer arithmetic. Goddammit !!

Compiler extensions. Not all compilers play the same music. So a program
can be non-portable across compilers even on the same architecture.

Binary and binary files. Another spartan feature of C program is the
control the compiler/language can provide, on where to store sections of
data and code. A C programmer is not yet a complete C programmer without
learning linker scripts and the ELF file format. And beware, knowing them
can lead to as much pain as not knowing them.

Application Binary Interface. The problem is C language does not have one,
and it is left to the compiler to decide on that. So it is better to know
how function calls are made and return values passed back for specific
compiler tool chains that the programmer uses.

Non-exhausting list of portability problems. Well, some might disagree,
and I suggest them to complete this list.

All said, C cannot be replaced and the claims like C has outlived its need are
false. We can choose other languages if they suit better, but on any day, I
would want one language which gives enough power to the programmer. Like C.
Let us just make ourselves more spartan like.



  1. Ecosystem. The toolchain, debugger, IDE, editors are best available for C.
    Probably Java programmer could also make that claim, but I dont know any
    other language which could measure up in providing that sort of
    developer/development ecosystem.

    I disagree with this one. Compared to the amount of tool support, C, or C++ for that matter, doesn’t have even half the support that C# has. Just take a look at the wealth of features that Visual Studio Team System provides for .NET-based applications and compare it with what they give C/C++ programmers.

    Comment by Dmitri — December 18, 2007 @ 12:37 pm | Reply

  2. Probably it was a sweeping statement that I made. I must agree that I have not used C#.
    Can you bullet point few nice tool/language support that you find in C# ? I am not sure whether it will make me to learn C# but I (or others) can learn from that.

    Comment by k2sings — December 18, 2007 @ 2:51 pm | Reply

  3. C# has:

    – A better IDE when you’re trying to do UI. Compared to, e.g., the MFC visual designer, everything is a lot cleaner and easier to understand, whether you’re doing it in WinForms or WPF. Also, what I like about C#’s visual designer is the fact that I can generate imperfect UI code from XML and the IDE actually rearranges the code-behind so that everything is neat and the UI I generated works in the designer.
    – Excellent code analysis tools. FxCop or its VSTS built-in equivalent looks at your code and examines various programming mistakes and inaccuracies. For example, it can warn you that timers that fire more frequently than once per second interfere with the Hibernation feature of Windows. Now, how would I have known about that otherwise?
    – Since C# is a bit easier to analyse than C/C++, one feature I really love is the Maintainability Index, which tells me how well a particular function, class or assembly unit has been programmed. It’s a composite index, taking into account the number of lines of code, the cyclomatic complexity, the depth of inheritance and some other features. The end result is that one can set a check-in policy so that all code is checked to be rating well against this index.
    – With C#, you can enforce a programming style (e.g., naming convention) across the organization. I’m not sure you can do it with C.
    – The debugger is a lot more enjoyable in C# due to the fact that it uses Reflection to the full.
    – The refactoring tools are, arguably, better in C#/VB (see, e.g., JetBrains ReSharper). But then this is a byproduct of the fact that C# is somewhat better defined and a bit more concise than C++. By the way, ReSharper also does a bit of static code analysis, letting you do things like automatically move variables closer to usage, get rid of long unnecessary references, etc.
    – Unit testing in VSTS (or just using NUnit) is a lot better than when using C/C++ – mainly because you can debug a unit test if you let an exception slip.

    Comment by Dmitri — December 19, 2007 @ 12:42 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: