icp/oer/courses/c-basics/sections/17-preprocessor/01-introduction/content.html

17 lines
971 B
HTML

<p>
You already learned how to use the preprocessor to include libraries and to use macros.
But there some features you didn't learn yet. One very powerful one is conditional compilation.
This means you can mark up your code with the preprocessor directives #if, #ifdef and #ifndef,
to define, if this code gets to be compiled or will get cut out.
You can give the compiler flags starting with -D to define a flag for the preprocessor to check on.
</p>
<p>
You do this for many reasons. For example you want to make your code platform agnostic. Then you can wrap your system calls with those blocks. Another example could be, if you want to define debug-behavior, which should not end up in the release code.
</p>
<p>
As a reminder: The preprocessor runs before the compiler. It only modifies the sourcefile before it is passed to the compiler. It does not change how the compiler behaves.
</p>
<p>
Check if the preprocessor flag SOMETHING is checked.
</p>