24 lines
1.2 KiB
HTML
24 lines
1.2 KiB
HTML
<p>
|
|
In the last lecture we used the preprocessor to include a library. But it can do
|
|
more stuff than just include files. The preprocessor, as the name suggest, runs
|
|
before the compiler and does some initial work. It <b>includes the files</b>, <b>expands macros</b>,
|
|
gives you <b>compile time information</b> and provides you if <b>conditional compilation</b>.
|
|
Preprocessor directives always start with #.
|
|
</p>
|
|
<p>
|
|
Some of its features should be used with great care. Macros are very powerful,
|
|
but they aren't type checked and are hard to debug.
|
|
Conditional compilation is useful to define debug only features or define
|
|
platform-agnostic macros, but they also can make your code harder to read.
|
|
For now we just take a look at macros. In a later part of the course we will revisit this topic.
|
|
</p>
|
|
<p>
|
|
A macro is something that the preprocessor will replace with what ever you specify.
|
|
To define a macro you simply write <it>#define</it> then the name of the macro with optional
|
|
parameters in parentheses and then what you want your macro to expand to.
|
|
If your macro expands to another macro, then this process starts again.
|
|
</p>
|
|
<p>
|
|
Your task is to find the error in the Square macro and define a macro yourself.
|
|
</p>
|