<?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[Wann verwendet man bestimme Präprozessoranweisungen?]]></title><description><![CDATA[<p>Hi,</p>
<p>ich bin neu in der C++ - Welt und wollte mal fragen wann ich entsprechende Präprozessoranweisungen verwende wie:</p>
<p>#if<br />
#elif<br />
#else<br />
#endif</p>
<p>bzw. auch wann definiere ich eine Funktion oder Konstante über define und wann tue ich dies ganz normal über const?</p>
<p>Ich weiß nicht warum mann 2 verschiedene Varianten benötigt. Könnte sich bitte irgendwer die Zeit nehmen dies zu erläutern?</p>
<p>Danke im Voraus.</p>
<p>MfG<br />
ich</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324741/wann-verwendet-man-bestimme-präprozessoranweisungen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 06:16:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324741.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 30 Mar 2014 12:10:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 12:10:51 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich bin neu in der C++ - Welt und wollte mal fragen wann ich entsprechende Präprozessoranweisungen verwende wie:</p>
<p>#if<br />
#elif<br />
#else<br />
#endif</p>
<p>bzw. auch wann definiere ich eine Funktion oder Konstante über define und wann tue ich dies ganz normal über const?</p>
<p>Ich weiß nicht warum mann 2 verschiedene Varianten benötigt. Könnte sich bitte irgendwer die Zeit nehmen dies zu erläutern?</p>
<p>Danke im Voraus.</p>
<p>MfG<br />
ich</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391879</guid><dc:creator><![CDATA[Komisch]]></dc:creator><pubDate>Sun, 30 Mar 2014 12:10:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 12:23:36 GMT]]></title><description><![CDATA[<blockquote>
<p>Java ist übersichtlicher und einfacher.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Es gibt keinen Grund, Funktionen oder Konstanten über Präprozessoranweisungen zu definieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391881</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391881</guid><dc:creator><![CDATA[fullack]]></dc:creator><pubDate>Sun, 30 Mar 2014 12:23:36 GMT</pubDate></item><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 12:49:49 GMT]]></title><description><![CDATA[<p>Komisch schrieb:</p>
<blockquote>
<p>#if<br />
#elif<br />
#else<br />
#endif</p>
</blockquote>
<p>Meistens als Include Guard um mehrfaches &quot;includieren&quot; zu verhindern.<br />
Beispiel:</p>
<pre><code>#ifndef MY_HEADER_H_INCLUDED // noch nicht definiert? gut!
#define MY_HEADER_H_INCLUDED // jetzt definieren
// hier der Code der in den Header gehört
#endif // block ende
</code></pre>
<p>Einige Entwicklungsumgebungen erzeugen diese von sich aus.<br />
(Visual Studio verwendet &quot;#pragma once&quot;, das im Grunde das Selbe tut, was aber nur Visual Studio kennt.)</p>
<p>Komisch schrieb:</p>
<blockquote>
<p>bzw. auch wann definiere ich eine [...] Konstante über define und wann tue ich dies ganz normal über const?</p>
</blockquote>
<p>Immer const (oder mit constexpr oder enum. Kommt darauf an, was man braucht)</p>
<p>Komisch schrieb:</p>
<blockquote>
<p>Ich weiß nicht warum mann 2 verschiedene Varianten benötigt. Könnte sich bitte irgendwer die Zeit nehmen dies zu erläutern?</p>
</blockquote>
<p>Manchmal möchte man Dinge vorverarbeiten lassen, oder aus dem code &quot;entfernen&quot; (über #if ...) bevor der compiler ran darf. (zB: für Workarounds im code für spezielle Compiler oder für platformabhängigen Code, den man ab- oder anschalten will.</p>
<p>==&gt; Ich würde sagen: versuche einfach erstmal den Präprozessor nicht zu verwenden (Ausnahme: Include Guards).<br />
EDIT: und include selbst natürlich</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391884</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Sun, 30 Mar 2014 12:49:49 GMT</pubDate></item><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 12:41:23 GMT]]></title><description><![CDATA[<p>Tim06TR schrieb:</p>
<blockquote>
<p>Visual Studio verwendet &quot;#pragma once&quot;, das im Grunde das Selbe tut, was aber nur Visual Studio kennt</p>
</blockquote>
<p>Das kennen inzwischen die meisten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391887</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 30 Mar 2014 12:41:23 GMT</pubDate></item><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 13:31:34 GMT]]></title><description><![CDATA[<blockquote>
<h3>[6.15] What does the FAQ mean by &quot;such and such is evil&quot;?</h3>
<p><strong>FAQ:</strong> This means that a feature should be avoided whenever possible. The strong word is supposed to help people change their old thinking.</p>
<p><strong>FQA:</strong> This means the feature satisfies the following conditions:</p>
<ul>
<li>It is inherited from C</li>
<li>It is easy to abuse (especially when it interacts with the new C++ features)</li>
<li>It can cause problems when abused (especially when it interacts with the new C++ features)</li>
<li>C++ provides one or more facilities duplicating the functionality of the feature, replacing the original problems with new and much more complicated problems</li>
</ul>
<p>For example, macros, pointers, and arrays meet this definition (the corresponding C++ &quot;solutions&quot; are const &amp; template, references &amp; smart pointers, and vector/string classes). Include files almost meet this definition, except that C++ doesn't duplicate this functionality (namespaces are a parallel notion of &quot;modules&quot;, but they can't be used to locate definitions). Consequently, the FAQ will not call include files &quot;evil&quot;. On the other hand, function overloading doesn't come from C, so duplicate facilities like template specialization, default arguments, etc. are not enough for the FAQ to call function overloading &quot;evil&quot;. Still, function overloading is very commonly abused leading to major problems.</p>
<p>A C++ user is likely to have a different definition of &quot;evil&quot;. A user doesn't care whether something came from C or not, and whether C++ tried to offer duplicate facilities (while forcing users to deal with the original ones since they're still in the language). A user typically cares about the &quot;easy to abuse and causing trouble when abused&quot; parts. Lots and lots of parts of C++ are like that.</p>
<p>As to the features the FAQ does call evil - why are they in the language? Is it good for the users of the language, or for those who designed and promoted it?</p>
</blockquote>
<p>Macros für Konstanten erfüllen diese Definition seit C++14 (nach dem man Konstanten-Templates definieren kann), Macros für bedingen Kompilierung nicht. D.h. if/elif/endif darfst du nach belieben verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391890</guid><dc:creator><![CDATA[fqa]]></dc:creator><pubDate>Sun, 30 Mar 2014 13:31:34 GMT</pubDate></item><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 17:41:08 GMT]]></title><description><![CDATA[<p>Komisch schrieb:</p>
<blockquote>
<p>Ich weiß nicht warum mann 2 verschiedene Varianten benötigt. Könnte sich bitte irgendwer die Zeit nehmen dies zu erläutern?</p>
</blockquote>
<p>Versuch mal ein plattformübergreifendes Projekt ohne den Präprozessor zu schreiben.<br />
Ich weiss schon, das geht, aber lustig ist es nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391905</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 30 Mar 2014 17:41:08 GMT</pubDate></item><item><title><![CDATA[Reply to Wann verwendet man bestimme Präprozessoranweisungen? on Sun, 30 Mar 2014 20:56:43 GMT]]></title><description><![CDATA[<p>Beispiel:</p>
<pre><code>#ifdef OS_LINUX
#define OS_STRING &quot;linux&quot;
#elif defined(OS_WIN32)
#define OS_STRING &quot;win32&quot;
#else
#error Unsupported OS!
#endif

int main()
{
    std::cout &lt;&lt; OS_STRING &lt;&lt; std::endl;
}
</code></pre>
<p>Generell wenn du auf Betriebssystem, Plattform etc Rücksicht nehmen musst oder dem Nutzer die möglichkeit geben willst den Code zur Compilezeit über Preprozessoranweisungen zu konfigurieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2391935</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2391935</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sun, 30 Mar 2014 20:56:43 GMT</pubDate></item></channel></rss>