DEV Community

Ahmed Gouda
Ahmed Gouda

Posted on • Edited on • Originally published at ahmedgouda.hashnode.dev

C Standard Libraries and Development Environment

The C Programming Language

C evolved from two previous languages, BCPL and B. BCPL was developed in 1967 by Martin Richards as a language for writing operating systems and compilers.

C is widely used to develop systems that demand performance, such as operating systems, embedded systems, real-time systems and communications systems.

C Standard Library

C programs consist of pieces called functions. You can program all the functions that you need to form a C program, but most C programmers take advantage of the rich collection of existing functions called the C Standard Library.

Thus, there are really two parts to learning how to program in C

  • learning the C language itself
  • learning how to use the functions in the C Standard Library

When programming in C you’ll typically use the following building blocks:

  • C Standard Library functions
  • Functions you create yourself
  • Functions other people (whom you trust) have created and made available to you

The advantage of creating your own functions is that you’ll know exactly how they work. You’ll be able to examine the C code. The disadvantage is the time-consuming effort that goes into designing, developing, debugging and performance-tuning new functions.


Typical C Program-Development Environment

C systems generally consist of several parts: a program-development environment, the language and the C Standard Library.

C programs typically go through six phases to be execute. These are: edit, preprocess, compile, link, load and execute.

Phase 1: Creating a Program

Phase 1 consists of editing a file. This is accomplished with an editor program. You type a C program with the editor, make corrections if necessary, then store the program on a secondary storage device such as a hard disk. C program filenames should end with the .c extension.

Phases 2 and 3: Preprocessing and Compiling a C Program

In Phase 2, you give the command to compile the program. The compiler translates the C program into machine language code (also referred to as object code). In a C system, a preprocessor program executes automatically before the compiler’s translation phase begins.

The C preprocessor obeys special commands called preprocessor directives,
which indicate that certain manipulations are to be performed on the program before compilation. These manipulations usually consist of including other files in the file to be compiled and performing various text replacements.

In Phase 3, the compiler translates the C program into machine-language code.

A syntax error occurs when the compiler cannot recognize a statement because it violates the rules of the language. The compiler issues an error message to help you locate and fix the incorrect statement. Syntax errors are also called compile errors, or compile-time errors.

Phase 4: Linking

The next phase is called linking. C programs typically contain references to functions defined elsewhere, such as in the standard libraries or in the private libraries of groups of programmers working on a particular project.

The object code produced by the C compiler typically contains “holes” due to these missing parts. A linker links the object code with the code for the missing functions to produce an executable image (with no missing pieces).

Phase 5: Loading

The next phase is called loading. Before a program can be executed, the program must first be placed in memory. This is done by the loader, which takes the executable image from disk and transfers it to memory. Additional components from shared libraries that support the program are also loaded.

Phase 6: Execution

Finally, the computer, under the control of its CPU, executes the program one instruction at a time.

Top comments (0)