3
I came across a C code that used a compilation directive on #ifdef
and I didn’t really understand what it was for. I found an explanation, but it wasn’t clear. Here is an example of a directive and the explanation I researched:
#ifdef <token>
/* code */
#else
/* code to include if the token is not defined */
#endif
ifdef checks whether the Given token has been #defined earlier in the file or in an included file. If so, it includes Everything between it and the closing #Else or, if no #Else is present, the closing #endif. ifdef can be used with built-in token Identifiers set by the Compiler to indicate that Additional Functionality is available.
ifdef checks if the token was previously assigned through sets in the file or included in it. If so, it will include everything between #Else or, if #Else is not present, in #endif. ifdef can be used with built-in token identifiers defined by the compiler to indicate functionality availability additional.
Source: http://www.cprogramming.com/reference/preprocessor/ifdef.html
After all, what are compilation directives for? When should I use them? In practice, why are they used?