C-language
Table of Contents
The C programming language
1. Syntax
1.1. Functions
1.2. Control Flow
1.3. Arithmatics
1.4. Data structures
2. Preprocessor
C Preprocessor is a text substitution tool that work with directives. Before feeding source code to compiler, Preprocessor would scan the source code file and substitue all directives according to their meanings.
2.1. list of important directives
| directive | meaning |
#define |
macro def |
#include |
include header file |
#undef |
undefine a macro |
#ifdef |
return true if macro is defined |
#ifndef |
return ture if macro is undefined |
#if |
|
#else |
|
#elif |
|
#endif |
|
#error |
print error message on stderr |
#pragma |
2.2. macro
3. Library management
3.1. Using header file
- header file
file.hcontaining C functions and macros used by multiple source files.
#includedirective- header file could be included with
#includedirective.#include <stdio.h>search a standard list of system directories for"stdio.h"(like/usr/include/ on ubantu). This list could be prepended with-Icompiler option#include "file.h"search the current directory forfile.h
- what
#includedoes - when
#includedirective is scanned, the preprocessor would go to find and scan the given header file.- as result, the compiled program would be equivalent to replace
#include "file.h"with content offile.h. this link
- as result, the compiled program would be equivalent to replace
3.1.1. avoid including twice
to avoid a header file being included twice, could use:
#ifndef HEADER_FILE #define HEADER_FILE /* the entire header file file */ #endif
- #ifndef directive would ignore stuff until #endif if HEADERFILE is defined
3.1.2. computed include
you can select which header file to include with
#define SYSTEM_H "system_1.h" ... #include SYSTEM_H
- SYSTEMH is a macro
- SYSTEMH could be given to compiler with
"-D"option, and thus specified in makefile
4. variable
4.1. constant
4.2. enum
4.3. variable
5. File manipulation
6. Memory management
7. Compiling and Execution
8. Usage
C can be used to manipulate OS concepts like process directly(and of course used to write OS itself).