Created: 2023-01-10 15:04
Status: #concept
Subject: Programming
Links: C Compiler Directives

Preprocessor

It is a part of the Compiler which does preliminary work before turning Source Code .c into Object Code .o.

Its functions (Preprocessing, Compiling, and Linking) are often automated and is usually integrated with the compiler.

However, the commands to compile & link vary depending on the operating system.

Preprocessor Flowchart.png

Conditional Compilation in C

We can use the #if, #ifdef, #ifndef Directives together with a wrapping #endif to conditionally compile code based on an Expression.

  • instead of #ifdef MACRO_VALUE, we can use #if defined(MACRO_VALUE).

if Directive in C.png

Example

Conditional Compilation in C Example.png

Using #elif and #else

elif and else Directives in C.png

References