<?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) true immer 1 ?]]></title><description><![CDATA[<p>hola leute</p>
<p>ist es im c++-std so festgelegt das true immer 1 ist ?</p>
<p>dann koennte man eine bool variable durch ne subtraktion mit 1 jeder zeit in den anderen zustand bringen ohne zu wissen welchen er grad hat. oder ?</p>
<p>bool var = true;<br />
var - 1 == 0; also false;<br />
var - 1 == -1; wird intern geaendert nach 1, und somit wieder true.</p>
<p>oder ist das nicht so die optimale loesung ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/144173/bool-true-immer-1</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 14:50:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/144173.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 15 Apr 2006 14:22:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (bool) true immer 1 ? on Sat, 15 Apr 2006 14:22:02 GMT]]></title><description><![CDATA[<p>hola leute</p>
<p>ist es im c++-std so festgelegt das true immer 1 ist ?</p>
<p>dann koennte man eine bool variable durch ne subtraktion mit 1 jeder zeit in den anderen zustand bringen ohne zu wissen welchen er grad hat. oder ?</p>
<p>bool var = true;<br />
var - 1 == 0; also false;<br />
var - 1 == -1; wird intern geaendert nach 1, und somit wieder true.</p>
<p>oder ist das nicht so die optimale loesung ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1037937</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1037937</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sat, 15 Apr 2006 14:22:02 GMT</pubDate></item><item><title><![CDATA[Reply to (bool) true immer 1 ? on Sat, 15 Apr 2006 14:27:09 GMT]]></title><description><![CDATA[<p>&quot;An rvalue of arithmetic, enumeration, pointer, or pointer to member<br />
type can be converted to an rvalue of type bool. A zero value, null<br />
pointer value, or null member pointer value is converted to false; any<br />
other value is converted to true.&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1037944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1037944</guid><dc:creator><![CDATA[Cpt. Tanga]]></dc:creator><pubDate>Sat, 15 Apr 2006 14:27:09 GMT</pubDate></item><item><title><![CDATA[Reply to (bool) true immer 1 ? on Sat, 15 Apr 2006 14:43:25 GMT]]></title><description><![CDATA[<p>Eigentlich geht es ja mehr hierum:</p>
<blockquote>
<p>4.5 Integral promotions [conv.prom]</p>
<p>1 An rvalue of type char, signed char, unsigned char, short int, or unsigned short int can be converted to an rvalue of type int if int can represent all the values of the source type; otherwise, the source rvalue can be converted to an rvalue of type unsigned int.</p>
<p>2 An rvalue of type wchar_t (3.9.1) or an enumeration type (7.2) can be converted to an rvalue of the first of the following types that can represent all the values of its underlying type: int, unsigned int, long, or unsigned long.</p>
<p>3 An rvalue for an integral bitfield (9.6) can be converted to an rvalue of type int if int can represent all the values of the bitfield; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bitfield. If the bitfield is larger yet, no integral promotion applies to it. If the bitfield has an enumerated type, it is treated as any other value of that type for promotion purposes.</p>
<p><strong>4 An rvalue of type bool can be converted to an rvalue of type int, with false becoming zero and true becoming one.</strong></p>
<p>5 These conversions are called integral promotions.</p>
</blockquote>
<p>EDIT:</p>
<p>Den Zustand eines bools kann man auch einfacher ändern:</p>
<pre><code class="language-cpp">int main(void)
{
    bool test; //Nicht initialisiert, eigentlich undefined behaviour, normalerweise ist aber einfach der Wert &quot;zufällig&quot;
    test = !test;
    return (0);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1037948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1037948</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Sat, 15 Apr 2006 14:43:25 GMT</pubDate></item><item><title><![CDATA[Reply to (bool) true immer 1 ? on Sat, 15 Apr 2006 14:42:57 GMT]]></title><description><![CDATA[<p>waer ich mal blos regestriert ^^...</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/26836">@topic</a><br />
&quot;If the destination type is bool, see _conv.bool_. If the source type<br />
is bool, the value false is converted to zero and the value true is<br />
converted to one.&quot;</p>
<p>hoffentlich jetzt ein richtiges zitat <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f611.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--expressionless_face"
      title="-_-"
      alt="😑"
    /></p>
<p>3.9.1 4.5.4 4.11</p>
<p>dachte eigendlich immer aritmetik mit bool typen sei undefiniert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1037951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1037951</guid><dc:creator><![CDATA[Cpt. Tanga]]></dc:creator><pubDate>Sat, 15 Apr 2006 14:42:57 GMT</pubDate></item><item><title><![CDATA[Reply to (bool) true immer 1 ? on Sat, 15 Apr 2006 14:47:37 GMT]]></title><description><![CDATA[<p>Wenn du nen bool von true nach false ändern willst oder umgekehrt, dann nimm entweder meinbool = !meinbool wie von Phoemuex vorgeschlagen, oder meinbool = meinbool ^ true (kurz meinbool ^= true).<br />
Was einfacher zu lesen ist ist ansichtssache.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1037955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1037955</guid><dc:creator><![CDATA[Any]]></dc:creator><pubDate>Sat, 15 Apr 2006 14:47:37 GMT</pubDate></item><item><title><![CDATA[Reply to (bool) true immer 1 ? on Sat, 15 Apr 2006 19:15:55 GMT]]></title><description><![CDATA[<p>^ ist aber ein bitweiser Operator, also der Situation nicht wirklich angmessen. Am besten nimmt man den logischen Negationsoperator (!), denn genau für sowas ist er ja da.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1038136</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1038136</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sat, 15 Apr 2006 19:15:55 GMT</pubDate></item></channel></rss>