Notes 3 --- Introduction to C for Pascal Programmers

History of C

Dialects of C:

There are two main divisions here: the language definition and the interface with the compiler and the operating system.

  1. There are at least four main versions of language definition, though only the first three will be significant:
  2. We will be concerned with two principal types of interface:
  3. Significant differences (other than the way in which programs are entered, compiled, and run) include:

Fundamentals :

Types :

Expressions :

Statements:

Functions:

Dynamic structures and allocation:

Input-Output & Files:

Compilation:

  1. Standard compilation of a C program invokes a compiler (typically cc or gcc) at the operating system command line on the source file, and produces an object file named a.out by default. We can redirect the output into another file by using the redirect.
                  cc myprog.c >  myprog.exe...............(or)
                  cc -o myprog.exe myprog.c              (preferable)
  1. The program is executed by typing the file name at the command line; redirects can be used to have the program get its input from one file and put its output on another. The defaults are: input from the keyboard, output to the screen, errors to the screen; A given program may redirect input, output, both, or neither.
                  myprog.exe <  datafile.1 >  outputfile.1
  1. Turbo C/C++ compilation instead invokes the compiler via the Compile command inside the Turbo environment, and produces a file with the same base and extension exe (so myprog.c will automatically compile into myprog.exe).
  2. In Turbo, the Run command executes the exe file associated with the current program. Input arguments (including files) can be specified via the Arguments command of the Run menu.
  3. There are other useful flags for the cc/gcc/tcc commands. In particular, in a UNIX environment, the -g flag compiles the program to permit debugging and profiling. This flag is implicitly on in compiling in Turbo C/C++.
  4. Large projects are typically managed by makefiles (and in Turbo by declaring a Project ).