<?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[Compilerbug ?]]></title><description><![CDATA[<p>Konnte das Problem weiter reduzieren und habe immer noch keine Erklärung für das Verhalten dieses simplen Programmes. Ursprünglich ist es in meiner Schachengine aufgetreten, habe den Code aber soweit wie möglich auf das Problem reduziert. Daher ist der folgende Code sinnlos und dient nur zu Untersuchung dieses Compilerproblems.</p>
<p>Die Ausgabe dieses Programmes ist abhängig vom Compiler bzw den Flags des Compilers. Unter allen von mir getesteten Compilern gibt das Programm auf der Konsole folgende korrekten Werte aus:</p>
<pre><code class="language-cpp">value........50100
temp.........50100
</code></pre>
<p>Nur im 64-Bit Release Modus unter Visual Studio 2010 Professional mit den optimierenden Flags und Ob1 oder Ob2 (wichtig) kommt es zu folgende Bildschirmausgabe, welche falsch ist:</p>
<pre><code class="language-cpp">value........50000
temp.........50000
</code></pre>
<p>Hier der fehlerproduzierende Code. Am besten ein neues Projekt unter Microsoft Visual Studio 2010 Professional anlegen und als x64 Release mit Ob2 kompilieren lassen. Das Einfügen von weiteren printfs() ist nicht möglich, da der Fehler dann wieder verschwindet.</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;

namespace {
  const int IS_ENPASSANT = 1 &lt;&lt; 15;

  struct move_info_c { int move, value; };
  struct board_c { int piece_on[64]; } B;

  inline int move_to(int move) { return move &amp; 63; }
  inline int move_from(int move) { return (move &gt;&gt; 6) &amp; 63; }
  inline int move_is_enpassant(int move) { return (move &amp; IS_ENPASSANT) != 0; }
  inline int make_enpassant(int from, int to) { return to | (from &lt;&lt; 6) | IS_ENPASSANT; }
  inline int piece_on_square(int square) { return B.piece_on[square]; }
  inline int move_is_capture(int move) { return (piece_on_square(move_to(move)) != 6) || move_is_enpassant(move); }
  inline int move_piece(int move) { return piece_on_square(move_from(move)); }
  inline int move_piece_captured(int move) { return move_is_enpassant(move) ? 0 : piece_on_square(move_to(move)); }

  inline int piece_value_midgame(int piece) {
    int piece_value_mg[7] = {100, 300, 400, 500, 900, 1000, 0};
    return piece_value_mg[piece];
  }

  void initialize() {
    for (int square = 0; square &lt; 64; square++) B.piece_on[square] = 6;
    B.piece_on[28] = B.piece_on[29] = 0;
  }

  move_info_c * generate(move_info_c * move_list) {
    (move_list++)-&gt;move = make_enpassant(28, 21);
    return move_list;
  }

  class sort_c {
  public:
    sort_c();
    move_info_c * last_move, move_list[256];
  };

  sort_c::sort_c() {
    generate(move_list);
    move_info_c * current = move_list;
    int move = current-&gt;move, value = 0, temp = 0;

    if (value &lt; 0) move_list[0].value = value;
    else if (move_is_capture(move)) {
      temp = 50000 + piece_value_midgame(move_piece_captured(move)) - move_piece(move);
      move_list[0].value = temp;
    }
    else move_list[0].value = 0;

    printf_s(&quot;value...........%d\n&quot;, move_list[0].value);
    printf_s(&quot;temp............%d\n&quot;, temp);
  }
}

int main() {
  initialize();
  sort_c s;
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/269731/compilerbug</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 00:19:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/269731.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Jun 2010 12:41:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Compilerbug ? on Wed, 30 Jun 2010 12:42:12 GMT]]></title><description><![CDATA[<p>Konnte das Problem weiter reduzieren und habe immer noch keine Erklärung für das Verhalten dieses simplen Programmes. Ursprünglich ist es in meiner Schachengine aufgetreten, habe den Code aber soweit wie möglich auf das Problem reduziert. Daher ist der folgende Code sinnlos und dient nur zu Untersuchung dieses Compilerproblems.</p>
<p>Die Ausgabe dieses Programmes ist abhängig vom Compiler bzw den Flags des Compilers. Unter allen von mir getesteten Compilern gibt das Programm auf der Konsole folgende korrekten Werte aus:</p>
<pre><code class="language-cpp">value........50100
temp.........50100
</code></pre>
<p>Nur im 64-Bit Release Modus unter Visual Studio 2010 Professional mit den optimierenden Flags und Ob1 oder Ob2 (wichtig) kommt es zu folgende Bildschirmausgabe, welche falsch ist:</p>
<pre><code class="language-cpp">value........50000
temp.........50000
</code></pre>
<p>Hier der fehlerproduzierende Code. Am besten ein neues Projekt unter Microsoft Visual Studio 2010 Professional anlegen und als x64 Release mit Ob2 kompilieren lassen. Das Einfügen von weiteren printfs() ist nicht möglich, da der Fehler dann wieder verschwindet.</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;

namespace {
  const int IS_ENPASSANT = 1 &lt;&lt; 15;

  struct move_info_c { int move, value; };
  struct board_c { int piece_on[64]; } B;

  inline int move_to(int move) { return move &amp; 63; }
  inline int move_from(int move) { return (move &gt;&gt; 6) &amp; 63; }
  inline int move_is_enpassant(int move) { return (move &amp; IS_ENPASSANT) != 0; }
  inline int make_enpassant(int from, int to) { return to | (from &lt;&lt; 6) | IS_ENPASSANT; }
  inline int piece_on_square(int square) { return B.piece_on[square]; }
  inline int move_is_capture(int move) { return (piece_on_square(move_to(move)) != 6) || move_is_enpassant(move); }
  inline int move_piece(int move) { return piece_on_square(move_from(move)); }
  inline int move_piece_captured(int move) { return move_is_enpassant(move) ? 0 : piece_on_square(move_to(move)); }

  inline int piece_value_midgame(int piece) {
    int piece_value_mg[7] = {100, 300, 400, 500, 900, 1000, 0};
    return piece_value_mg[piece];
  }

  void initialize() {
    for (int square = 0; square &lt; 64; square++) B.piece_on[square] = 6;
    B.piece_on[28] = B.piece_on[29] = 0;
  }

  move_info_c * generate(move_info_c * move_list) {
    (move_list++)-&gt;move = make_enpassant(28, 21);
    return move_list;
  }

  class sort_c {
  public:
    sort_c();
    move_info_c * last_move, move_list[256];
  };

  sort_c::sort_c() {
    generate(move_list);
    move_info_c * current = move_list;
    int move = current-&gt;move, value = 0, temp = 0;

    if (value &lt; 0) move_list[0].value = value;
    else if (move_is_capture(move)) {
      temp = 50000 + piece_value_midgame(move_piece_captured(move)) - move_piece(move);
      move_list[0].value = temp;
    }
    else move_list[0].value = 0;

    printf_s(&quot;value...........%d\n&quot;, move_list[0].value);
    printf_s(&quot;temp............%d\n&quot;, temp);
  }
}

int main() {
  initialize();
  sort_c s;
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1919426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1919426</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Wed, 30 Jun 2010 12:42:12 GMT</pubDate></item><item><title><![CDATA[Reply to Compilerbug ? on Wed, 30 Jun 2010 12:49:48 GMT]]></title><description><![CDATA[<p>Visual Studio 2010 Professional sucks!!!</p>
<p>Mach noch 3 Threads auf!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1919430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1919430</guid><dc:creator><![CDATA[VS sucks]]></dc:creator><pubDate>Wed, 30 Jun 2010 12:49:48 GMT</pubDate></item><item><title><![CDATA[Reply to Compilerbug ? on Wed, 30 Jun 2010 13:11:36 GMT]]></title><description><![CDATA[<p>Würde ein Moderator diesen Thread bitte schließen, das Problem wurde bereits <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-269490-and-start-is-40.html" rel="nofollow">hier</a> diskutiert, und gehört wie auch dort erwähnt entweder wenn als Report an Microsoft gesendet (Und wenn überhaupt noch in das Compiler-Unterforum).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1919443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1919443</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Wed, 30 Jun 2010 13:11:36 GMT</pubDate></item></channel></rss>