user47164: 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

user37622: The mDNSResolver library README has

You can change a few settings by defining some constants before including the mDNSResolver header file [in the sketch]

I added "in the sketch", because it is where you include mDNSResolver header file.
This will not work because mDNSResolver.cpp, which uses the values of the defines, is compiled without any knowledge of the ino file content.
A deeper explanation would be too long and out of scope for Arduino SE.

47164: <p>A question I have long had regards an interaction between <code>#define</code> statements and a library header include. I've seen several Arduino libraries use this rather convenient configuration system where you can write a <code>#define</code> statement, then include the <code>#include header</code> instruction and the library will change its behavior.</p>
<p>Does anyone know why this does or does not work? My understanding of how <code>#include</code> 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 <code>#include</code> a library would have to be seen by the library when the preprocessor does its thing and copies the <code>#include</code>-d file.</p>
<p>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?</p>
<p>Here's a library that does it: <a href="https://github.com/madpilot/mDNSResolver" rel="nofollow noreferrer">https://github.com/madpilot/mDNSResolver</a></p>
 37622: <p>The mDNSResolver library README has</p>
<blockquote>
<p>You can change a few settings by defining some constants before including the mDNSResolver header file <em>[in the sketch]</em></p>
</blockquote>
<p><em>I added &quot;in the sketch&quot;, because it is where <strong>you</strong> include mDNSResolver header file.</em></p>
<p>This will not work because mDNSResolver.cpp, which uses the values of the defines, is compiled without any knowledge of the ino file content.</p>
<p><em>A deeper explanation would be too long and out of scope for Arduino SE.</em></p>
