<?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[Enumeration und Wortlänge]]></title><description><![CDATA[<p>Welche Wortlänge hat eine Enumeration? Oder ist das von der Compilereinstellung (x86, x64) abhängig? Meine Abstraktion geht nicht so weit, dass ich den Integertyp vernachlässigen möchte.</p>
<pre><code class="language-cpp">enum File {
  FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NONE
};
</code></pre>
<p>Muss ich, um mit einer Enumeration arbeiten zu können überladene Operatoren explizit definieren?</p>
<p><strong>Beispiel:</strong></p>
<pre><code class="language-cpp">inline File operator+ (File x, int i) { return File(int(x) + i); }
inline File operator+ (File x, File y) { return x + int(y); }
inline void operator++ (File &amp;x, int) { x = File(int(x) + 1); }
inline void operator+= (File &amp;x, int i) { x = File(int(x) + i); }
inline File operator- (File x, int i) { return File(int(x) - i); }
inline void operator-- (File &amp;x, int) { x = File(int(x) - 1); }
inline void operator-= (File &amp;x, int i) { x = File(int(x) - i); }
</code></pre>
<p>Was bietet mir eine Enumeration für Vorteile? Werden damit Fehler vom Compiler erkannt (0 &lt;= File &lt;= 7)?</p>
<p>Vielen Dank für eure hilfreichen Hinweise an einen Laien !</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/253189/enumeration-und-wortlänge</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 23:21:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/253189.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Oct 2009 18:36:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Enumeration und Wortlänge on Thu, 29 Oct 2009 18:36:42 GMT]]></title><description><![CDATA[<p>Welche Wortlänge hat eine Enumeration? Oder ist das von der Compilereinstellung (x86, x64) abhängig? Meine Abstraktion geht nicht so weit, dass ich den Integertyp vernachlässigen möchte.</p>
<pre><code class="language-cpp">enum File {
  FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NONE
};
</code></pre>
<p>Muss ich, um mit einer Enumeration arbeiten zu können überladene Operatoren explizit definieren?</p>
<p><strong>Beispiel:</strong></p>
<pre><code class="language-cpp">inline File operator+ (File x, int i) { return File(int(x) + i); }
inline File operator+ (File x, File y) { return x + int(y); }
inline void operator++ (File &amp;x, int) { x = File(int(x) + 1); }
inline void operator+= (File &amp;x, int i) { x = File(int(x) + i); }
inline File operator- (File x, int i) { return File(int(x) - i); }
inline void operator-- (File &amp;x, int) { x = File(int(x) - 1); }
inline void operator-= (File &amp;x, int i) { x = File(int(x) - i); }
</code></pre>
<p>Was bietet mir eine Enumeration für Vorteile? Werden damit Fehler vom Compiler erkannt (0 &lt;= File &lt;= 7)?</p>
<p>Vielen Dank für eure hilfreichen Hinweise an einen Laien !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800375</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Thu, 29 Oct 2009 18:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Thu, 29 Oct 2009 18:44:10 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<p>Welche Wortlänge hat eine Enumeration? Oder ist das von der Compilereinstellung (x86, x64) abhängig?</p>
</blockquote>
<p>Der <code>enum</code> -Typ sollte genügend gross sein, um alle darin enthaltenen Enumeratoren repräsentieren zu können.</p>
<p>Tomahawk schrieb:</p>
<blockquote>
<p>Meine Abstraktion geht nicht so weit, dass ich den Integertyp vernachlässigen möchte.<br />
[...]<br />
Muss ich, um mit einer Enumeration arbeiten zu können überladene Operatoren explizit definieren?</p>
</blockquote>
<p>Du solltest dich eher fragen, warum du solche Operatoren brauchst. Ein <code>enum</code> ist eigentlich nicht als arithmetischer Datentyp gedacht, sonst kannst du gleich <code>int</code> oder sonst was nehmen. Vielmehr benutzt man <code>enum</code> als Aufzählungen einer kleinen Anzahl Stati, die ein Typ annehmen kann. Also sowas wie</p>
<pre><code class="language-cpp">enum Farbe
{
    Rot,
    Pink,
    Tuerkis,
};
</code></pre>
<p>Der eigentliche integrale Wert dahinter sollte im Normalfall nicht interessieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800377</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 29 Oct 2009 18:44:10 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Thu, 29 Oct 2009 18:47:09 GMT]]></title><description><![CDATA[<p>Ok, also ist es eher ungeeignet um einen Datentyp einzuführen und mit diesem dann im Stile eines Integers zu rechnen.</p>
<p>Wenn das so ist, dann kann ich Enumerationen für meine Zwecke vergessen. Hier wird nämlich nur gerechnet.</p>
<p>THX</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800382</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Thu, 29 Oct 2009 18:47:09 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Thu, 29 Oct 2009 18:50:21 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<p>Ok, also ist es eher ungeeignet um einen Datentyp einzuführen und mit diesem dann im Stile eines Integers zu rechnen.</p>
</blockquote>
<p>Ja, sehr sogar.</p>
<p>Tomahawk schrieb:</p>
<blockquote>
<p>Wenn das so ist, dann kann ich Enumerationen für meine Zwecke vergessen. Hier wird nämlich nur gerechnet.</p>
</blockquote>
<p>Okay... Mich würde aber trotzdem interessieren, wie du genau auf <code>enum</code> kommst? Sind dir normale arithmetische Typen aus einem Grund nicht gut genug? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Um nicht mit Magic-Numbers rechnen zu müssen, kannst du ja immer noch Konstanten des jeweiligen Typs anlegen:</p>
<pre><code class="language-cpp">const int BlaBli = 2312;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1800385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800385</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 29 Oct 2009 18:50:21 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Thu, 29 Oct 2009 19:10:44 GMT]]></title><description><![CDATA[<p>Arithemtische Typen nicht gut genug?</p>
<p>Habe etwas im Hinterkopf, das bei Enumerationen der Bereich geprüft wird und der Compiler eine Warnung ausspuckt, wenn der Bereich der Enumeration verlassen wird. Also nur eine zusätzliche Sicherheitsreserve - mehr nicht.</p>
<p>Gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800394</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Thu, 29 Oct 2009 19:10:44 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Thu, 29 Oct 2009 20:05:02 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<p>Habe etwas im Hinterkopf, das bei Enumerationen der Bereich geprüft wird und der Compiler eine Warnung ausspuckt, wenn der Bereich der Enumeration verlassen wird. Also nur eine zusätzliche Sicherheitsreserve - mehr nicht.</p>
</blockquote>
<p>Kann er gar nicht, weil du ja sowieso casten musst, um damit zu rechnen.<br />
Wenn du zwei <code>File</code> -Werte addierst, kommt ein <code>int</code> raus, kein <code>File</code> . Und einem <code>File</code> kannst du kein <code>int</code> zuweisen, ohne die daraus resultierende Fehlermeldung wegzucasten.<br />
Und selbst wenn, deine Operatoren werden doch erst zur Laufzeit aufgerufen - wie soll der <em>Compiler</em> da eine Wertüberschreitung feststellen können?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800419</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Thu, 29 Oct 2009 20:05:02 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Fri, 30 Oct 2009 07:10:45 GMT]]></title><description><![CDATA[<p>Registrierter Troll schrieb:</p>
<blockquote>
<p>Tomahawk schrieb:</p>
<blockquote>
<p>Habe etwas im Hinterkopf, das bei Enumerationen der Bereich geprüft wird und der Compiler eine Warnung ausspuckt, wenn der Bereich der Enumeration verlassen wird. Also nur eine zusätzliche Sicherheitsreserve - mehr nicht.</p>
</blockquote>
<p>Kann er gar nicht, weil du ja sowieso casten musst, um damit zu rechnen.<br />
Wenn du zwei <code>File</code> -Werte addierst, kommt ein <code>int</code> raus, kein <code>File</code> . Und einem <code>File</code> kannst du kein <code>int</code> zuweisen, ohne die daraus resultierende Fehlermeldung wegzucasten.<br />
Und selbst wenn, deine Operatoren werden doch erst zur Laufzeit aufgerufen - wie soll der <em>Compiler</em> da eine Wertüberschreitung feststellen können?</p>
</blockquote>
<p>Klar! Der Compiler macht auf das ungewollte Mischen von Enumeratortypen ohnes explizite Casten aufmerksam! Das wäre ein zusätzlicher Sicherheitsmechanismus für den Programmierer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800518</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Fri, 30 Oct 2009 07:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Fri, 30 Oct 2009 08:42:00 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<p>Klar! Der Compiler macht auf das ungewollte Mischen von Enumeratortypen ohnes explizite Casten aufmerksam! Das wäre ein zusätzlicher Sicherheitsmechanismus für den Programmierer.</p>
</blockquote>
<p>Das trifft aber auf deine Operatoren nicht zu.</p>
<p>Tomahawk schrieb:</p>
<blockquote>
<pre><code class="language-cpp">inline File operator+ (File x, int i) { return File(int(x) + i); }
inline File operator+ (File x, File y) { return x + int(y); }
inline void operator++ (File &amp;x, int) { x = File(int(x) + 1); }
inline void operator+= (File &amp;x, int i) { x = File(int(x) + i); }
inline File operator- (File x, int i) { return File(int(x) - i); }
inline void operator-- (File &amp;x, int) { x = File(int(x) - 1); }
inline void operator-= (File &amp;x, int i) { x = File(int(x) - i); }
</code></pre>
</blockquote>
<p>Du hast die Typsicherheit hier komplett ausgehebelt, es findet keinerlei Bereichsprüfung statt. Wenn du so eine Prüfung willst, musst du sie selbst programmieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800555</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Fri, 30 Oct 2009 08:42:00 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Fri, 30 Oct 2009 15:30:16 GMT]]></title><description><![CDATA[<p>Jetzt weiss ich auch warum Enumerationen:</p>
<pre><code class="language-cpp">inline bitboard_t bitboard_file(const int file) {
  return bb_file[file];
}

inline bitboard_t bitboard_file(const int square) {
  return bb_file[square_file(square)];
}
</code></pre>
<p>Zwei unterschiedliche Funktionen, die ich NICHT überladen kann. Was mache ich nur, wenn ich doch überladen möchte???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800788</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Fri, 30 Oct 2009 15:30:16 GMT</pubDate></item><item><title><![CDATA[Reply to Enumeration und Wortlänge on Fri, 30 Oct 2009 15:33:19 GMT]]></title><description><![CDATA[<p>Überladen im Sinne der Abstraktion ist damit erstmal Aus+Vorbei.</p>
<pre><code class="language-cpp">inline bitboard_t file_to_bitboard(const int file) {
  return bb_file[file];
}

inline bitboard_t square_to_file_bitboard(const int square) {
  return bb_file[square_file(square)];
}
</code></pre>
<p>1.000.000 verschiedene Funktionsnamen....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1800791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1800791</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Fri, 30 Oct 2009 15:33:19 GMT</pubDate></item></channel></rss>