Teen Programmers Unite  
 

  Learning C
By Psion

The C programming language may be the most widely used language in applications and server software today. You may have heard a lot about C++ and assumed that C++ is the "next version" of C that everyone uses now, but very little code for UNIX and its derivatives has strayed away from C, the language that was created to make UNIX possible. If you are at all interested in creating efficient programs or anything that interacts with "system-level" interfaces, then you should probably learn C. It also isn't too shabby as a language to learn to jump-start yourself into programming, though simpler languages like BASIC or Pascal may be preferable for those without too much prior experience.

There are several places on the web where you can read C language tutorials. The following are some of the options.

For those of you who have worked with BASIC or similar interpreted languages before, moving to C may seem a little strange. Interpreted languages require a special program, called an interpreter, to read in the code written in a specific human-readable language each time that it is to be run. The result is a pretty much unavoidable speed decrease, and a large one at that. Though any language can be either interpreted or compiled, BASIC tends to be interpreted. C is generally compiled, meaning that a series of software tools converts your code into machine code that can be run without the need for a special interpreter. This may seem daunted if you've only used BASIC before, but it is much more convenient to widely distribute your programs when end users don't need special software to run them. One common mistake that people new to C make is to think that the IDE, integrated development environment or code editor that features tools tailored towards the compiler, is the compiler. The compiler is generally a command line tool, just like dir for DOS or ls for UNIX. You don't need an IDE to use it, and indeed many people edit their code in simple text editors, as you don't need a fancy environment in which to both write and run your code; it is a full-fledged program once compiled and doesn't require the software you used to code it any more than Windows 98 requires QBasic to run. (Which is a bad example, because Windows isn't coded in BASIC, but I'm sure you get the idea. :-) )

The general process that you will use to develop a program using C works as follows. You create a number of .c source files describing your program. The C compiler than compiles these into object files which may have the extensions .o, .obj, or something else tool-dependent. These files have your code translated to machine language, something one step above machine language called assembly, or some other format close to that found in a real executable. The difference between object files and the end result is that the object files also contain information on the variables and functions in your program. If you don't know what these are, that's OK. All that matters is that a linker combines your object files, and perhaps some stored libraries of object files with code that you will often want to re-use found in .a or .lib files, and links them together into a final program. The information about the higher-level details of your source code that was preserved in the object files has been used to allow code from different source files to "communicate," accessing shared information and code.

I'm sure at this point you're itching to get started. Chances are you may not have a compiler and the other tools needed to code in C, so here is a list of links to where you can download various free compilers.

  • GCC - The ubiquitous GNU Compiler Collection; gcc and the related development tools come with pretty much all of the free UNIX clones. Ports are available for most popular platforms.

  • DJGPP - This gcc port gem is for DOS only and is a great way to get into learning C. You don't have to worry about any of the complexities of more featureful operating systems and can concentrate on the basics. For those of you who are interested in games, I would recommend using Allegro, a great all-purpose game programming library, to be able to create real computer games without needing a lot of experience to do so. Allegro has been ported to Windows, Linux, and others these days, so you can use it with other compilers as well. Being able to get immediate results like this is an excellent motivator to learn all about programming, or at least I have found so in my experience. If you don't like games, then try to find something else that interests you to work on; I think this is the key to becoming a great programmer.

  • Cygwin32 - The most popular Windows gcc port, it also features libraries to let you use standard UNIX functions in Windows programs.

  • Borland C++ compiler - A relative of that famous Turbo C++ found in high school programming classes around the world, this version of Borland's compiler has been freely released and does C as well as C++, like all of the compilers listed here.

  • LCC-Win32 - Another choice for a free 32-bit Windows C compiler
 
Copyright TPU 2002. See the Credits and About TPU for more information.