C programming beginners page

From OraWiki

Jump to: navigation, search

Contents

C - Programming sources

C programming is smart and powerful. If you learn C programming and Assembly language than you will be able to understand the way computers really work. C is not a very complicated language. The major source of information The C Programming Language written by Kernighan & Ritchie is just 200 pages of DIN A5. You can learn the content of this book in just a few days.


Learning C language matters. Just believe it. It's the best you can start with because this is really a "Computer language" developed by intelligent humans with a generic syntax and semantic. C language is comparable to "LEGO" because you have only a few different pieces which you can use to build anything you want.

Other programming languages are very often pretty much more like a car, a motorcycle or a van. They are specialised and not generic.

C language is a so called General Purpose Language (GPL) and this is just a thing everybody should really understand.


Just read for more details

Books

The best source of information is Kernighan & Ritchie The C Programming Language. You can buy this book but I recommend to lent it from a library.

Web

Documentation for beginners
Documentation for experts


Online documentation

What is a man page and how to use it?


General hints

You have to install a C compiler like gcc and the related man pages to use this feature! The gcc compiler is available for all operating systems I know like Solaris, OpenVMS, Linux, Windows and OS/2 and a lot of others. gcc is a General Purpose Compiler because if you learn programming using gcc you will be able to solve any problem anywhere and if you gather your sources and organize them in libraries you will become faster and faster by time and growing experiences.

Using C language you are able to create your own LEGO pieces to decrease the duration of software development.

Hello world programs

If you want to start programming in any language than the first step is done if you've compiled and run your first program. At Wikipedia you will find Hello world programs for most programming languages. The name Hello world was derived from the first C language manual written by Kernighan & Ritchie because they called the first C language programm Hello World and this is used since that time for all the other programming languages.


Debugging

Debugging means the process to find bugs/errors in a program. There are several methods how to debug a C program. In some cases I do my software development using the good old MS-DOS and Borland C++ 3.1 because this is a great IDE for development of POSIX based C programs. It looks similar to the GUI of Midnight Commander and it is powerful and fast and offers a pretty good integrated debugger. This is software from the nineties but it's best for C programmers.

I use an old Notebook for this. Because a graphical display is not required. You can use any Notebook with 64 MB RAM and 200 Mhz. Pentium and a 20GB harddrive for this. You can buy such old device at EBAY for a few dollars.


Another way to debug C programs is using makros and print instructions. For example:

#ifdef __DEBUG__
printf("Reached line %s in file %s\n",__LINE__,__FILE__);
#endif

The #ifdef and #endif are so called preprocessor instructions and the code between this lines is used only at runtime if __DEBUG__ is defined.

#define __DEBUG__

To make this a little bit smarter I've developed Logwriter.c. Usage of a makro have the benefit that you can compile a release with less code if you unset __DEBUG__. On the other hand syslogprintf will allow to set different levels of debug information.

Using Logwriter.c you should use for debug message a construct like

#ifndef NDEBUG
      syslogprintf(__FILE__,__LINE__,"your group name",5,"<your message>",<your list of printf compatible params>);
#endif

To test for makro NDEBUG is better than using a proprietary makro like __DEBUG__ because this makro is used by standard C makro assert in assert.h.


Another way to debug a C program is using gdb. This is a commandline utility to debug C programs. You will find some more useful instructions at gdb quickStart.

LINT

To create compatible and best practise code there are two options I always use:

  • gcc compiler options -Wall and -pedantic
  • command line utility lint (Solaris and others) / splint (Ubuntu Linux)

Both options help writing compatible and safe code. Both options help to find unused code, not initialized variables , variables which are too small to take an assigned value and so on.

Learning curve and productivity


A regression analysis of time to learn and productivity will give in my opinion a lot of arguments for using C programming language. This is just an idea for someone who would like to write a scientific related article or a dissertation or want to get a degree in Computer Science. In my opinion there is no scientific work done related to this problem.

Personal tools