Complier directives are sometimes called Preprocessor directives.
They are commands that tell the complier how to behave & treat certain parts of code.
Note, they are not part of the code.
They aren't complied (converted into zeros and ones) and loaded into the arduino.
The preprocessor works by searching for lines that start with the hash sign (#) and have some text after it. This is called a preprocessor directive and it’s a sort of “command” for the preprocessor.
Examples are:
#include -
We use this when including a arduino library ... “adds” the library to the main sketch.
It tells the compiler to get the code from that library.
#define
eg
#define VALUE 3
Here we define a word as a number.
This tells the compiler, every time it sees the word "VALUE"
to change the word VALUE into a 3
#endif
#ifndef
This checks whether a library is included
#ifdef
a just shorthand for #if defined, which can be used to test multiple macros in a single condition. Note that every condition has to end with #endif directive, to specify which parts of the code are affected by the condition, and which ones are not.
#warning
#error
When preprocessor finds these directives, it will print the message into the Arduino IDE console. The difference between the two is that after #warning, compilation proceeds as normal, while #error stops the compilation altogether.
#ifdef DEBUG
#if DEBUG
#else
links
+ https://www.youtube.com/watch?v=kBTM0dLzNXk
No comments:
Post a Comment