A question I have long had regards an interaction between #define
statements and a library header include. I've seen several Arduino libraries use this rather convenient configuration system where you can write a #define
statement, then include the #include header
instruction and the library will change its behavior.
Does anyone know why this does or does not work? My understanding of how #include
works is that it copies the file into its place in the new file and that C/C++ code with headers should thus form something of a tree shape. It would thus make sense that any lines of code present before I #include
a library would have to be seen by the library when the preprocessor does its thing and copies the #include
-d file.
But I've previously been told it doesn't actually work this way (despite actual examples, but by that point I had misplaced the libraries that did it). However, I've finally tracked down an example of someone doing this, and I'd like to know how this behavior works. Is it a feature of Arduino in specific or something?
Here's a library that does it: https://github.com/madpilot/mDNSResolver