<?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[Via this-&amp;gt;Pointer oder via Reference?]]></title><description><![CDATA[<p>So sieht's aktuell aus:</p>
<p><strong>A</strong> <em>(wie &quot;alt&quot;)</em></p>
<pre><code class="language-cpp">struct board_c {
  // variables
  sintx piece[SQUARES];
  sintx moves[SQUARES];
  uint64 key_list[1024];
  uint64 key_pawns;
  uint64 key_pieces;
  uint64 key_material;
  uint64 white_pawn_bitboard;
  uint64 white_knight_bitboard;
  uint64 white_bishop_bitboard;
  uint64 white_rook_bitboard;
  uint64 white_queen_bitboard;
  uint64 white_bitboard;
  uint64 black_pawn_bitboard;
  uint64 black_knight_bitboard;
  uint64 black_bishop_bitboard;
  uint64 black_rook_bitboard;
  uint64 black_queen_bitboard;
  uint64 black_bitboard;
  // more...
};

// functions

extern sintx generate_captures_w(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_captures_b(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_non_captures_w(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_non_captures_b(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_moves_w(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_moves_b(const board_c &amp; board, sintx move_list[256]);
// more...
</code></pre>
<p>oder besser doch so:</p>
<p><strong>B</strong> <em>(wie vielleicht &quot;besser&quot;)</em></p>
<pre><code class="language-cpp">class board_c {
private:
  // variables
  sintx piece[SQUARES];
  sintx moves[SQUARES];
  uint64 key_list[1024];
  uint64 key_pawns;
  uint64 key_pieces;
  uint64 key_material;
  uint64 white_pawn_bitboard;
  uint64 white_knight_bitboard;
  uint64 white_bishop_bitboard;
  uint64 white_rook_bitboard;
  uint64 white_queen_bitboard;
  uint64 white_bitboard;
  uint64 black_pawn_bitboard;
  uint64 black_knight_bitboard;
  uint64 black_bishop_bitboard;
  uint64 black_rook_bitboard;
  uint64 black_queen_bitboard;
  uint64 black_bitboard;
  // more...

public:
  // functions
  sintx generate_captures_w(sintx move_list[256]) const;
  sintx generate_captures_b(sintx move_list[256]) const;
  sintx generate_non_captures_w(sintx move_list[256]) const;
  sintx generate_non_captures_b(sintx move_list[256]) const;
  sintx generate_moves_w(sintx move_list[256]) const;
  sintx generate_moves_b(sintx move_list[256]) const;
  // more...
};
</code></pre>
<p><strong>Überlegungen</strong></p>
<p>In <strong>A</strong> habe ich zwei grosse Vorteile. Innerhalb der Functions darf ich nur via <em>board.member</em> zugreifen. Daher habe ich bei der Wahl der Variablennamen innerhalb der Functions eine grössere Freiheit. Ausserdem erkenne ich sofort, welche Variable zu <em>board_c</em> gehört und welche nur lokal ist.</p>
<p>In <strong>B</strong> habe ich den offensichtlichen Vorteil die Member-Variable endlich nach &quot;aussen&quot; via <em>private</em> zu schützen. Und das ist auch genau wieder ein Problem (Overhead). Ich muss dann für jede Variable eine kleine Inline-Function schreiben, die die entsprechende Variable nach aussen lesbar macht:</p>
<pre><code class="language-cpp">inline uint64 board_c::white_bitboard_get(void) const {
  return white_bitboard;
}
</code></pre>
<p>Ist es sinnvoll den Aufbau wie in <strong>B</strong> zu verwenden? Bei se Wei, es gibt von den <em>board_c</em> 4-5 Instanzen. Insofern lässt sich B vielleicht doch rechtfertigen?</p>
<p>Danke schonmal für eure Antworten.</p>
<p><strong>PS</strong>:<br />
*Baue gerade meine C-Schachengine nach C++ um, aber nur soweit, es auch wirklich sinnvoll ist. Das heisst, Strukturen via Reference statt via Pointer zu übergeben. Inline-Functions statt Defines. Und Operatoren für den Heap-Speicher. Jetzt plane ich eben noch die Strukturen in Klassen umzubauen, sofern sinnvoll!<br />
*</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252966/via-this-gt-pointer-oder-via-reference</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 03:19:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252966.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Oct 2009 07:03:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Via this-&amp;gt;Pointer oder via Reference? on Tue, 27 Oct 2009 07:03:58 GMT]]></title><description><![CDATA[<p>So sieht's aktuell aus:</p>
<p><strong>A</strong> <em>(wie &quot;alt&quot;)</em></p>
<pre><code class="language-cpp">struct board_c {
  // variables
  sintx piece[SQUARES];
  sintx moves[SQUARES];
  uint64 key_list[1024];
  uint64 key_pawns;
  uint64 key_pieces;
  uint64 key_material;
  uint64 white_pawn_bitboard;
  uint64 white_knight_bitboard;
  uint64 white_bishop_bitboard;
  uint64 white_rook_bitboard;
  uint64 white_queen_bitboard;
  uint64 white_bitboard;
  uint64 black_pawn_bitboard;
  uint64 black_knight_bitboard;
  uint64 black_bishop_bitboard;
  uint64 black_rook_bitboard;
  uint64 black_queen_bitboard;
  uint64 black_bitboard;
  // more...
};

// functions

extern sintx generate_captures_w(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_captures_b(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_non_captures_w(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_non_captures_b(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_moves_w(const board_c &amp; board, sintx move_list[256]);
extern sintx generate_moves_b(const board_c &amp; board, sintx move_list[256]);
// more...
</code></pre>
<p>oder besser doch so:</p>
<p><strong>B</strong> <em>(wie vielleicht &quot;besser&quot;)</em></p>
<pre><code class="language-cpp">class board_c {
private:
  // variables
  sintx piece[SQUARES];
  sintx moves[SQUARES];
  uint64 key_list[1024];
  uint64 key_pawns;
  uint64 key_pieces;
  uint64 key_material;
  uint64 white_pawn_bitboard;
  uint64 white_knight_bitboard;
  uint64 white_bishop_bitboard;
  uint64 white_rook_bitboard;
  uint64 white_queen_bitboard;
  uint64 white_bitboard;
  uint64 black_pawn_bitboard;
  uint64 black_knight_bitboard;
  uint64 black_bishop_bitboard;
  uint64 black_rook_bitboard;
  uint64 black_queen_bitboard;
  uint64 black_bitboard;
  // more...

public:
  // functions
  sintx generate_captures_w(sintx move_list[256]) const;
  sintx generate_captures_b(sintx move_list[256]) const;
  sintx generate_non_captures_w(sintx move_list[256]) const;
  sintx generate_non_captures_b(sintx move_list[256]) const;
  sintx generate_moves_w(sintx move_list[256]) const;
  sintx generate_moves_b(sintx move_list[256]) const;
  // more...
};
</code></pre>
<p><strong>Überlegungen</strong></p>
<p>In <strong>A</strong> habe ich zwei grosse Vorteile. Innerhalb der Functions darf ich nur via <em>board.member</em> zugreifen. Daher habe ich bei der Wahl der Variablennamen innerhalb der Functions eine grössere Freiheit. Ausserdem erkenne ich sofort, welche Variable zu <em>board_c</em> gehört und welche nur lokal ist.</p>
<p>In <strong>B</strong> habe ich den offensichtlichen Vorteil die Member-Variable endlich nach &quot;aussen&quot; via <em>private</em> zu schützen. Und das ist auch genau wieder ein Problem (Overhead). Ich muss dann für jede Variable eine kleine Inline-Function schreiben, die die entsprechende Variable nach aussen lesbar macht:</p>
<pre><code class="language-cpp">inline uint64 board_c::white_bitboard_get(void) const {
  return white_bitboard;
}
</code></pre>
<p>Ist es sinnvoll den Aufbau wie in <strong>B</strong> zu verwenden? Bei se Wei, es gibt von den <em>board_c</em> 4-5 Instanzen. Insofern lässt sich B vielleicht doch rechtfertigen?</p>
<p>Danke schonmal für eure Antworten.</p>
<p><strong>PS</strong>:<br />
*Baue gerade meine C-Schachengine nach C++ um, aber nur soweit, es auch wirklich sinnvoll ist. Das heisst, Strukturen via Reference statt via Pointer zu übergeben. Inline-Functions statt Defines. Und Operatoren für den Heap-Speicher. Jetzt plane ich eben noch die Strukturen in Klassen umzubauen, sofern sinnvoll!<br />
*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798880</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Tue, 27 Oct 2009 07:03:58 GMT</pubDate></item><item><title><![CDATA[Reply to Via this-&amp;gt;Pointer oder via Reference? on Tue, 27 Oct 2009 11:53:22 GMT]]></title><description><![CDATA[<p>Der Sinn von Klassen ist ja Abstraktion. Man sagt dem User nicht, WIE etwas gemacht wird, sondern nur, dass die Klasse etwas machen soll. Wie das geschieht kann/sollte dem User egal sein. Wenn du jetzt jede Variable mit getter und setter koppelst, dann macht der User ja doch irgendwie alles selbst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1799044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1799044</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 27 Oct 2009 11:53:22 GMT</pubDate></item></channel></rss>