Professional Documents
Culture Documents
C Introduction
C Introduction
C: History
C: Characteristics
Block structure
Some encapsulation of code, via functions
Type checking (pretty weak)
C: Dangers
Separate compilation
Source code
file1.c
Preprocesso
r/
Compiler
Object code
file1.o
Source code
file2.c
Preprocesso
r/
Compiler
Object code
file2.o
Libraries
Linker
Executable
code
a.out
Separate compilation
The preprocessor
The preprocessor takes your source code and
following certain directives that you give it
tweaks it in various ways before compilation.
A directive is given as a line of source code
starting with the # symbol
The preprocessor works in a very crude, wordprocessor way, simply cutting and pasting
it doesnt really know anything about C!
Your
source
code
Preprocesso
r
8
Enhanced and
obfuscated
source code
Object
code
Compiler
CS 3090: Safety Critical Programming
in C
Input
Output
Sample input/output
Initial input: 0 2 5 7 10 12 -1
Next input line:
deep C diving
Output:
deeC ding
Next input line:
excitement!
Output:
exceme!
continue ad nauseum
Terminate with ctrl-D (signals end of keyboard
input)
10
Use of comments
/*
** This program reads input lines from the standard input and prints
** each input line, followed by just some portions of the lines, to
** the standard output.
**
** The first input is a list of column numbers, which ends with a
** negative number.
11
Comments on comments
12
Preprocessor directives
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
manipulation functions.
/usr/include
Preprocessor directives
#define MAX_COLS
20
14
Function prototypes
int
void
15
Function prototypes
16
int
main( void )
{
17
printf()
Syntax:
<stdio.h>
18
when \n
encountered
Dont forget \n
when
printing final
return EXIT_SUCCESS;
input[MAX_INPUT];
20
21
NUL
(char)
(char)
(char)
(char)
(char)
(char)
(char)
(char)
What is input?
Its a string!
Its a pointer to
char!
Its an array of
char!
22
input