<?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[Bool&#x27;scher Returnwert]]></title><description><![CDATA[<p>Bin mir nicht sicher, wie ich einen Wahrheitswert <em>richtig</em> zurückgebe:</p>
<pre><code class="language-cpp">// Version A

int bit_is_set(uint64 a) 
{
  return a &amp; MASK;
}

// Version B

int bit_is_set(uint64 a) 
{
  return (a &amp; MASK) != 0;
}
</code></pre>
<p>Auf <strong>bool</strong> verzichte ich besser, aber das Problem ist dasselbe. In Version A wird dann implizit von uint64 nach int konvertiert. In Version B tatsächlich 1 oder 0 zurückgegeben.</p>
<p>Gruss<br />
T.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/273006/bool-scher-returnwert</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 13:34:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/273006.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 29 Aug 2010 16:09:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bool&#x27;scher Returnwert on Sun, 29 Aug 2010 16:10:40 GMT]]></title><description><![CDATA[<p>Bin mir nicht sicher, wie ich einen Wahrheitswert <em>richtig</em> zurückgebe:</p>
<pre><code class="language-cpp">// Version A

int bit_is_set(uint64 a) 
{
  return a &amp; MASK;
}

// Version B

int bit_is_set(uint64 a) 
{
  return (a &amp; MASK) != 0;
}
</code></pre>
<p>Auf <strong>bool</strong> verzichte ich besser, aber das Problem ist dasselbe. In Version A wird dann implizit von uint64 nach int konvertiert. In Version B tatsächlich 1 oder 0 zurückgegeben.</p>
<p>Gruss<br />
T.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1945768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1945768</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Sun, 29 Aug 2010 16:10:40 GMT</pubDate></item><item><title><![CDATA[Reply to Bool&#x27;scher Returnwert on Sun, 29 Aug 2010 16:20:32 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<p>Auf <strong>bool</strong> verzichte ich besser,</p>
</blockquote>
<p>warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1945775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1945775</guid><dc:creator><![CDATA[Nachrichtentext_ 	[ schm]]></dc:creator><pubDate>Sun, 29 Aug 2010 16:20:32 GMT</pubDate></item><item><title><![CDATA[Reply to Bool&#x27;scher Returnwert on Sun, 29 Aug 2010 16:21:40 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<p>Bin mir nicht sicher, wie ich einen Wahrheitswert <em>richtig</em> zurückgebe:</p>
</blockquote>
<pre><code class="language-cpp">bool bit_is_set(uint64 a) 
{
  return a &amp; MASK;
}
</code></pre>
<p>Tomahawk schrieb:</p>
<blockquote>
<p>Auf <strong>bool</strong> verzichte ich besser, aber das Problem ist dasselbe.</p>
</blockquote>
<p>Nein. Wenn der Wert von MASK nicht &quot;in ein int passt&quot; hast Du bei Deiner Version A entweder undefiniertes oder zumindest ein Implementierungs-definiertes Verhalten. Ein uint64 ist hingegen problemlos zu bool konvertierbar. Dabei wird alles außer der 0 auf true abgebildet. Die 0 auf false.</p>
<p>Tomahawk schrieb:</p>
<blockquote>
<p>In Version A wird dann implizit von uint64 nach int konvertiert. In Version B tatsächlich 1 oder 0 zurückgegeben.</p>
</blockquote>
<p>Ja und?</p>
<pre><code>static_cast&lt;bool&gt;(a &amp; MASK);
</code></pre>
<p>ist so ziemlich dasselbe wie</p>
<pre><code>(a &amp; MASK)!=0
</code></pre>
<p>.</p>
<p>Wenn Du danach wieder einen int draus machst, ist das Dein Bier. bool-&gt;int bildet false auf 0 ab und true auf 1.</p>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1945777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1945777</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 29 Aug 2010 16:21:40 GMT</pubDate></item></channel></rss>