Monday, February 27, 2006

Fundamentals of the C Programming Language

The C Programming Language is one of the few programming languages that redefined a programmer's outlook to programming computers in late 70s and early 80s. But, it's important to point out why is C different from others. It's well known fact that it has the simplicity of a standard functional programming language yet has the power of a system programming language. Following are a set of features which differentiates C from others.

Functions vs. Sub-routine

Everything in C is a function. The question comes now is what is a function? A function is a partial program that can take certain inputs and return an output. Subroutine is a modular piece of code that may or may not take any input and certainly will not return any output. C eliminated all this distinction by providing
void
which would mean no input or no output.

Pass by Value

Unlike other programming languages C has no pass by reference concept. Everything that needs to be passed to the function has to be passed by value. What if you need an in/out parameter to a function. C does not have any direct answer to that. However, C definitely has a solution in terms of passing the memory address of the location to the function.

Support for Pointers

Pointers are the saving grace for a language that is a pure pass by value language. Pointers are a round about means of achieving a pass by reference alternative. However, pointers are beyond that actually. Pointers in most architectures actually expose out the exact process memory location to the user. This is an important and useful feature as the address can be obtained and be input to a piece of assembly methods for direct memory operations.

Dynamic Memory Allocation

Memory management which is pretty popular in today's languages were still a big requirement during the days of C. C provided dynamic memory allocation in its standard library implementation which can be used to allocate memory on an as required basis. Memory allocation and resizing gives enormous flexibility in designing programs which do not hog all the memory during program start up.

Abstract Data Design

Ability to design abstract data structures are a very useful feature with C. The following are some of the useful methods of designing abstract data structures.

1. Typedef
2. Struct
3. Bitsets
4. Bit operands and macros

Pre-processor

One of the most disliked features of C yet the most useful as well. Of course pre-processors being compile time constructs do not help a developer during debugging phase. However, this is one of the most useful features for designing generics, inlining and other such programming principles.

Use of C may be declining off late in comparison to C++ or Java, yet it will always be used as a base language that has made significant changes in the way programmers think today.

1 comment:

Anonymous said...

Interesting article. The first point where you mention that C removed differences between functions and subroutines by use of void is particularly insightful.

A not of caution to C programmers though: C also provides you with ....enough rope :-) .