<?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[Defines + switch() == Kaputt]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgender Schnipsel (test.cpp):</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

#define MSG_EINS 1;
#define MSG_ZWEI 2;

using namespace std;

int main()
{
    int test = 2;
    switch (test)
    {
        case MSG_EINS: cout &lt;&lt; &quot;Nachricht 1\n&quot;; break;
        case MSG_ZWEI: cout &lt;&lt; &quot;Nachricht 2\n&quot;; break;
    }
}
</code></pre>
<p>Gibt das hier:</p>
<blockquote>
<p>test.cpp: In function 'int main()':<br />
test.cpp:13: error: expected <code>:' before ';' token test.cpp:13: error: expected primary-expression before ':' token test.cpp:13: error: expected</code>;' before ':' token<br />
test.cpp:14: error: expected <code>:' before ';' token test.cpp:14: error: expected primary-expression before ':' token test.cpp:14: error: expected</code>;' before ':' token</p>
</blockquote>
<p>Kompiliert ist die test.cpp unter Linux mit g++, aber ich kann mir nicht vorstellen, dass das ausschlaggebend ist.</p>
<p>Es kann doch nicht sein, dass #defines in einer switch()-Anweisung nicht als Bedingungen dienen können!?</p>
<p>Ich hoffe ihr könnt mir helfen,<br />
lg Max</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213750/defines-switch-kaputt</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 23:06:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213750.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 May 2008 15:18:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Defines + switch() == Kaputt on Wed, 21 May 2008 15:19:08 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgender Schnipsel (test.cpp):</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

#define MSG_EINS 1;
#define MSG_ZWEI 2;

using namespace std;

int main()
{
    int test = 2;
    switch (test)
    {
        case MSG_EINS: cout &lt;&lt; &quot;Nachricht 1\n&quot;; break;
        case MSG_ZWEI: cout &lt;&lt; &quot;Nachricht 2\n&quot;; break;
    }
}
</code></pre>
<p>Gibt das hier:</p>
<blockquote>
<p>test.cpp: In function 'int main()':<br />
test.cpp:13: error: expected <code>:' before ';' token test.cpp:13: error: expected primary-expression before ':' token test.cpp:13: error: expected</code>;' before ':' token<br />
test.cpp:14: error: expected <code>:' before ';' token test.cpp:14: error: expected primary-expression before ':' token test.cpp:14: error: expected</code>;' before ':' token</p>
</blockquote>
<p>Kompiliert ist die test.cpp unter Linux mit g++, aber ich kann mir nicht vorstellen, dass das ausschlaggebend ist.</p>
<p>Es kann doch nicht sein, dass #defines in einer switch()-Anweisung nicht als Bedingungen dienen können!?</p>
<p>Ich hoffe ihr könnt mir helfen,<br />
lg Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1513674</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1513674</guid><dc:creator><![CDATA[MaDsTyLe]]></dc:creator><pubDate>Wed, 21 May 2008 15:19:08 GMT</pubDate></item><item><title><![CDATA[Reply to Defines + switch() == Kaputt on Wed, 21 May 2008 15:22:07 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#define MSG_EINS 1
#define MSG_ZWEI 2
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1513680</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1513680</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Wed, 21 May 2008 15:22:07 GMT</pubDate></item><item><title><![CDATA[Reply to Defines + switch() == Kaputt on Wed, 21 May 2008 15:24:56 GMT]]></title><description><![CDATA[<p>Deine Defines sind Kaput (Überflüssiger Strichpunkt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

#define MSG_EINS 1
#define MSG_ZWEI 2

using namespace std;

int main()
{
    int test = 2;
    switch (test)
    {
	case MSG_EINS:
        cout &lt;&lt; &quot;Nachricht 1\n&quot;;
        break;
    case MSG_ZWEI:
        cout &lt;&lt; &quot;Nachricht 2\n&quot;;
        break;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1513682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1513682</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Wed, 21 May 2008 15:24:56 GMT</pubDate></item><item><title><![CDATA[Reply to Defines + switch() == Kaputt on Wed, 21 May 2008 15:25:37 GMT]]></title><description><![CDATA[<p>MaDsTyLe schrieb:</p>
<blockquote>
<p>Es kann doch nicht sein, dass #defines in einer switch()-Anweisung nicht als Bedingungen dienen können!?</p>
<p>Ich hoffe ihr könnt mir helfen,</p>
</blockquote>
<p>Unabhängig von drakon (richtiger) Antwort: Du solltest lieber echte Konstanten oder enums verwenden. Dies macht eine Fehlersuche auch deutlich leichter (Gründe gegen define gibt es genug, und nur wenige Stellen erfordern es wirklich. Ausnahmen sind z.B. Includeguards und bedingte Compilierung wo defines tatsächlich sinnvoll sind).</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1513683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1513683</guid><dc:creator><![CDATA[asc@ausgeloggt]]></dc:creator><pubDate>Wed, 21 May 2008 15:25:37 GMT</pubDate></item><item><title><![CDATA[Reply to Defines + switch() == Kaputt on Wed, 21 May 2008 15:29:37 GMT]]></title><description><![CDATA[<p>Oh mein Gott, ich Vollhorst...</p>
<p>Wie kann ein Mensch so neben sich stehen...</p>
<p>Neulich schreibe ich</p>
<pre><code class="language-cpp">#ifndef TEST
...
#endif;
</code></pre>
<p>und wundere mich, dass da was von tokens steht und jetzt mach ich den selben Mist nochmal ...</p>
<p>Vielen Dank Leute ...</p>
<p>Ich werde jetzt zur Geißel greifen ...</p>
<p>lg Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1513687</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1513687</guid><dc:creator><![CDATA[MaDsTyLe]]></dc:creator><pubDate>Wed, 21 May 2008 15:29:37 GMT</pubDate></item><item><title><![CDATA[Reply to Defines + switch() == Kaputt on Wed, 21 May 2008 18:17:35 GMT]]></title><description><![CDATA[<p>mit enums siehts so aus</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

enum Message
{
    MSG_KEINS,
    MSG_EINS,
    MSG_ZWEI
};

using namespace std;

int main()
{
    Message test(MSG_ZWEI);
    switch (test)
    {
        case MSG_EINS: cout &lt;&lt; &quot;Nachricht 1\n&quot;; break;
        case MSG_ZWEI: cout &lt;&lt; &quot;Nachricht 2\n&quot;; break;
    }
}
</code></pre>
<p>ist viel sauberer als mit #define. außerdem hast du sogar einen eigenen typ für deine nachrichten, was vieles bequemer zu programmieren macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1513829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1513829</guid><dc:creator><![CDATA[flenz]]></dc:creator><pubDate>Wed, 21 May 2008 18:17:35 GMT</pubDate></item></channel></rss>