user59401: I'm making some code for school, and is adding debug code to it. When compiling, I get the error as written in the title. This is the code in question:
#define DEBUG 1

#ifdef DEBUG
#define Serial.println(x) DEBUG_PRINT(x)
#else
#define DEBUG_PRINT(x)
#endif

And the code in my void setup, which has Serial.begin:
#ifdef DEBUG
Serial.begin(9600);
DEBUG_PRINT("Asteroid");
#endif

What am I getting wrong? I get the feeling it's my define text, but I'm unsure. 
Thank you for your time
Gaarden

user23644: You defined the pre-processor macro the wrong way around.
Think it is like an assign statement. You come up with a name and assign something to it.
#define SHORT_NAME(ARG) some_real_function_that_has_an_awkward_long_name(ARG)
See the manual of your favourite compiler GCC for reference.
It is always a good idea to do that when using features you haven't used before. Sometimes it can be enlighting.

user4143: In short: you have your macro backwards.
Macros are not formed as "Take this set of commands and call it X" but "Make this macro X and have it equate to this set of commands".
Where you have:
#define Serial.println(x) DEBUG_PRINT(x)

it should instead read:
#define DEBUG_PRINT(x) Serial.println(x)

When you call it, because the macro doesn't contain a semi-colon in it, you need to specify the semi-colon as if you were calling a function:
DEBUG_PRINT("Aardvark");

You can omit the semi-colon only if you have a semi-colon in your macro:
#define DEBUG_PRINT(x) Serial.println(x);

and then:
DEBUG_PRINT("Aardvark")

By doing it that way your "empty" macro now does become truly empty when used.  Without the semi-colon in the macro you would have to use:
DEBUG_PRINT("Aardvark");

Which for the empty variant would end up as:
;

Not always desirable, and can cause some problems.
So by adding the semi-colon into the macro you can omit it from the usage of the macro, and your empty variant now becomes:
　　


59401: <p>I'm making some code for school, and is adding debug code to it. When compiling, I get the error as written in the title. This is the code in question:</p>

<pre><code>#define DEBUG 1

#ifdef DEBUG
#define Serial.println(x) DEBUG_PRINT(x)
#else
#define DEBUG_PRINT(x)
#endif
</code></pre>

<p>And the code in my void setup, which has Serial.begin:</p>

<pre><code>#ifdef DEBUG
Serial.begin(9600);
DEBUG_PRINT("Asteroid");
#endif
</code></pre>

<p>What am I getting wrong? I get the feeling it's my define text, but I'm unsure. </p>

<p>Thank you for your time
Gaarden</p>
 23644: <p>You defined the pre-processor macro the wrong way around.<br>
Think it is like an assign statement. You come up with a name and assign something to it.</p>

<p><code>#define SHORT_NAME(ARG) some_real_function_that_has_an_awkward_long_name(ARG)</code></p>

<p>See the manual of your favourite compiler <a href="https://gcc.gnu.org/onlinedocs/cpp/Macros.html" rel="nofollow noreferrer">GCC</a> for reference.<br>
It is always a good idea to do that when using features you haven't used before. Sometimes it can be enlighting.</p>
 4143: <p>In short: you have your macro backwards.</p>

<p>Macros are not formed as "Take this set of commands and call it X" but "Make this macro X and have it equate to this set of commands".</p>

<p>Where you have:</p>

<pre><code>#define Serial.println(x) DEBUG_PRINT(x)
</code></pre>

<p>it should instead read:</p>

<pre><code>#define DEBUG_PRINT(x) Serial.println(x)
</code></pre>

<p>When you call it, because the macro doesn't contain a semi-colon in it, you need to specify the semi-colon as if you were calling a function:</p>

<pre><code>DEBUG_PRINT("Aardvark");
</code></pre>

<p>You can omit the semi-colon only if you have a semi-colon in your macro:</p>

<pre><code>#define DEBUG_PRINT(x) Serial.println(x);
</code></pre>

<p>and then:</p>

<pre><code>DEBUG_PRINT("Aardvark")
</code></pre>

<p>By doing it that way your "empty" macro now does become truly empty when used.  Without the semi-colon in the macro you would have to use:</p>

<pre><code>DEBUG_PRINT("Aardvark");
</code></pre>

<p>Which for the empty variant would end up as:</p>

<pre><code>;
</code></pre>

<p>Not always desirable, and can cause some problems.</p>

<p>So by adding the semi-colon into the macro you can omit it from the usage of the macro, and your empty variant now becomes:</p>

<pre><code>　　
</code></pre>
