Freelance Projects

Upeksha Wisidagama

UW 103: Introduction to C Programming

Some years ago I was struck by how many false things I had believed, and by how doubtful was the structure of beliefs that I had based on them. I realized that if I wanted to establish anything in the sciences that was stable and likely to last, I needed – just once in my life – to demolish everything completely and start again from the foundations. It looked like an enormous task, and I decided to wait until I was old enough to be sure that there was nothing to be gained from putting it off any longer. I have now delayed it for so long that I have no excuse for going on planning to do it rather than getting to work. So today I have set all my worries aside and arranged for myself a clear stretch of free time. I am here quite alone, and at last I will devote myself, sincerely and without holding back, to demolishing my opinions.

—Rene Descartes, Meditations On First Philosophy

FIRST MEDITATION: On what can be called into doubt

Read More: http://www.marxists.org/reference/archive/descartes/1639/meditations.htm

‘To demolish everything completely and start again from the foundations’, you need to learn C.

C Liberates You from Stupidity

To many programmers, this makes C scary and evil. It is the Devil, Satan, the trickster Loki come to destroy your productivity with his seductive talk of pointers and direct access to the machine. Then, once this computational Lucifer has you hooked, he destroys your world with the evil “segfault” and laughs as he reveals the trickery in your bargain with him.

“The computer is some purely functional fantasy land with padded walls for little babies”

But, C is not to blame for this state of affairs. No my friends, your computer and the Operating System controlling it are the real tricksters. They conspire to hide their true inner workings from you so that you can never really know what is going on. The C programming language’s only failing is giving you access to what is really there, and telling you the cold hard raw truth. C gives you the red pill. C pulls the curtain back to show you the wizard. C is truth.

Why use C then if it’s so dangerous? Because C gives you power over the false reality of abstraction and liberates you from stupidity.

(The above sentences are quoted from c.learncodethehardway.org)

The C Programming Language

C is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. Its design provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, most notably system software like the Unix computer operating system.

C is one of the most widely used programming languages of all time, and C compilers are available for the majority of available computer architectures and operating systems.

Read More: http://en.wikipedia.org/wiki/C_(programming_language)

Read More: http://en.wikipedia.org/wiki/ANSI_C

Ken Thompson and Dennis Ritchie

Ken Thompson and Dennis Ritchie, from left to right. Dennis MacAlistair Ritchie was an American computer scientist who “helped shape the digital era.” He created the C programming language and, with long-time colleague Ken Thompson. Ritchie and Thompson received the Turing Award from the ACM in 1983, the Hamming Medal from the IEEE in 1990 and the National Medal of Technology from President Clinton in 1999.

GNU C Compiler

Richard Stallman

I then realized that the Pastel compiler functioned by parsing the entire input file into a syntax tree, converting the whole syntax tree into a chain of “instructions”, and then generating the whole output file, without ever freeing any storage.

At this point, I concluded I would have to write a new compiler from scratch.

That new compiler is now known as GCC

- Richard Stallman

Read More: http://www.gnu.org/gnu/thegnuproject.html

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain. The Free Software Foundation (FSF) distributes GCC under the GNU General Public License (GNU GPL). GCC has played an important role in the growth of free software, as both a tool and an example.

Do you remember building GNU Linux System from scratch? First Binutils-2.23.1 – Pass 1, Then, GCC-4.7.2 – Pass 1 and Linux-3.8.1 API Headers, finally, Glibc-2.17. Again Binutils-2.23.1 – Pass 2, etc.

Originally named the GNU C Compiler, because it only handled the C programming language, GCC 1.0 was released in 1987 and the compiler was extended to compile C++ in December of that year.[1] Front ends were later developed for Objective-C, Objective-C++, Fortran, Java, Ada, and Go among others.

Read More: https://en.wikipedia.org/wiki/GNU_Compiler_Collection

Compiler Collection Website: http://gcc.gnu.org/

The GNU C Reference Manual is a reference for the C programming language, as implemented by the GNU C Compiler. GNU-C Manual: http://www.gnu.org/software/gnu-c-manual/ View as HTML or Download as PDF.

The GNU C Library

Any Unix-like operating system needs a C library: the library which defines the “system calls” and other basic facilities such as open, malloc, printf, exit…

The GNU C Library is used as the C library in the GNU systems and most systems with the Linux kernel.

Website: https://www.gnu.org/software/libc/index.html

The GNU C Library Manual: https://www.gnu.org/software/libc/manual/

Can You C This?

Create the uw.c file.

‘uw.c’
1
2
3
4
5
int main(int argc, char *argv[])
{
    puts("Hello Upeksha!");
    return 0;
}

Compile the C using GCC – gcc uw.c.

Now execute it using ./a.out.

Simple C Program