Skip to content
Marcus Ottosson edited this page Jan 11, 2015 · 6 revisions

Preprocessor

// Example
#include <stdio.h>
#include "my_header.h"

Preprocessors are a way of making text processing with your C program before they are actually compiled. Before the actual compilation of every C program it is passed through a Preprocessor. The Preprocessor looks through the program trying to find out specific instructions called Preprocessor directives that it can understand. All Preprocessor directives begin with the # (hash) symbol. These transformations are lexical, meaning that the output of the preprocessor is still text.

When including files, you can use both <> and "":

  • <> will look in default paths.
  • "" will use user_defined paths.

(Source)

Macro

// Example
#define PI 3.1415926

A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. It is a literal search-and-replace before code reaches the compiler, much like #include does. (?)

Typedef

// Example
typedef unsigned int uint

In C, typedef declares a different name for a type. This can almost be thought of as similar to #define, but it is limited to type names only and is performed by the compiler instead of the preprocessor.

Learn C/C++ for Film and Games.

Table of contents

Clone this wiki locally