<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Präprozessordirektive in Makro]]></title><description><![CDATA[<p>Hallo,<br />
ich möchte diese Präprozessordirektive in ein Makro packen. Mit einem einfachen #define geht es aber leider nicht. Kann mir da einer weiterhelfen.</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG ))
// | | | |                            | | | |
// vvvv geht leider nicht vvvv
#define (START_DEBUG) (#if defined( DEBUG ) || defined( _DEBUG )))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/290389/präprozessordirektive-in-makro</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 14:20:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290389.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Jul 2011 17:12:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 17:12:43 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich möchte diese Präprozessordirektive in ein Makro packen. Mit einem einfachen #define geht es aber leider nicht. Kann mir da einer weiterhelfen.</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG ))
// | | | |                            | | | |
// vvvv geht leider nicht vvvv
#define (START_DEBUG) (#if defined( DEBUG ) || defined( _DEBUG )))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2097715</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097715</guid><dc:creator><![CDATA[KeineAhnung123]]></dc:creator><pubDate>Mon, 25 Jul 2011 17:12:43 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 17:15:31 GMT]]></title><description><![CDATA[<p>Expandierte Makros werden vom Präprozessor nicht noch einmal ausgewertet. Beschreib mal in Worten, was du erreichen möchtest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097718</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 25 Jul 2011 17:15:31 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 17:19:13 GMT]]></title><description><![CDATA[<p>So:</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG ))
#define DEBUG_CODE(code) do { code } while(0)
#else
#define DEBUG_CODE(code) ((void)0)
#endif

//und dann:

int divide(int a, int b) {
   DEBUG_CODE((
      if(b==0) cout&lt;&lt;&quot;WTF? pass besser auf!\n&quot;;
   ));
   return a/b;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2097719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097719</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Mon, 25 Jul 2011 17:19:13 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 17:51:15 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>So:</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG ))
#define DEBUG_CODE(code) do { code } while(0)
#else
#define DEBUG_CODE(code) ((void)0)
#endif

//und dann:

int divide(int a, int b) {
   DEBUG_CODE((
      if(b==0) cout&lt;&lt;&quot;WTF? pass besser auf!\n&quot;;
   ));
   return a/b;
}
</code></pre>
</blockquote>
<p>Kann ich nicht nachvollziehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097733</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 17:51:15 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 18:04:14 GMT]]></title><description><![CDATA[<p>Ich auch nicht. Aber so sollte es gehen:</p>
<pre><code class="language-cpp">int divide(int a, int b) { 
    DEBUG_CODE({ 
       if(b==0) cout&lt;&lt;&quot;WTF? pass besser auf!\n&quot;; 
    }); 
    return a/b; 
 }
</code></pre>
<p>Bzw. so lange wie in diesem Beispiel kein Komma im Code vorkommt, sogar so:</p>
<pre><code class="language-cpp">int divide(int a, int b) { 
    DEBUG_CODE( 
       if(b==0) cout&lt;&lt;&quot;WTF? pass besser auf!\n&quot;; 
    ); 
    return a/b; 
 }
</code></pre>
<p>Man könnte es natürlich auch gleich so machen:</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG ))
#define MY_DEBUG
#endif

int divide(int a, int b) { 
#ifdef MY_DEBUG
    if(b==0) cout&lt;&lt;&quot;WTF? pass besser auf!\n&quot;; 
#endif
    return a/b; 
 }
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097741</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 25 Jul 2011 18:04:14 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 18:13:29 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Kann ich nicht nachvollziehen.</p>
</blockquote>
<p>In der Tat, ich dachte echt dass das so geht. Irgendwas derartiges hatte ich mal. Muss ich mal suchen was damals der Trick war dass das so in der Art geht.</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>PS:<br />
Habe es damals mit BEGIN_* und END_* makros gemacht.<br />
Komische hatte das irgendwie so in erinnerung - aber die Kommas killen einen dann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097742</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Mon, 25 Jul 2011 18:13:29 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 18:23:26 GMT]]></title><description><![CDATA[<p>Ich hatte ne Zeit lang sowas</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG )
#define IF_DEBUG if(false);else
#else
#define IF_DEBUG if(true); else
#endif

//und dann:

int divide(int a, int b)
{
    IF_DEBUG
        if(b==0)
            cout&lt;&lt;&quot;WTF? pass besser auf!\n&quot;;
    return a/b;
}
</code></pre>
<p>Nach IF_* steht genau eine Anweisung, die davon betroffen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097758</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 18:23:26 GMT</pubDate></item><item><title><![CDATA[Reply to Präprozessordirektive in Makro on Mon, 25 Jul 2011 18:32:35 GMT]]></title><description><![CDATA[<p>Spricht etwas dagegen, bei Komma-Problemen einfach folgenden Code zu verwenden?</p>
<pre><code class="language-cpp">#if defined( DEBUG ) || defined( _DEBUG ))
#define DEBUG_CODE(...) do { __VA_ARGS__ } while(0)
#else
#define DEBUG_CODE(...) ((void)0)
#endif
</code></pre>
<p>Übrigens hatte ich dieses Problem auch mal bei einer std::map&lt;Typ1, Typ2&gt; als Parameter - sehr unerwartetes Verhalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097763</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Mon, 25 Jul 2011 18:32:35 GMT</pubDate></item></channel></rss>