<?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[Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt]]></title><description><![CDATA[<p>Hallo, bei folgendem Code wirft mir der Visual C++ Compiler eine Warnung in Zeile 3 (mit /W4)</p>
<pre><code class="language-cpp">typedef unsigned char type;

static const type type_max = ~((type)0u);
</code></pre>
<p>Warnung:</p>
<pre><code>warning C4245: &quot;Initialisierung&quot;: Konvertierung von &quot;int&quot; in &quot;const type&quot;, signed/unsigned-Konflikt.
</code></pre>
<p>Aber ich habe doch type explizit als unsigned deklariert, dazu das literal 0 als unsigned. Oder gibt der ~ Operator immer ein signed zurück??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/269532/verstehe-warnung-nicht-signed-unsigned-konflikt</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 04:23:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/269532.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 27 Jun 2010 02:13:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 02:13:01 GMT]]></title><description><![CDATA[<p>Hallo, bei folgendem Code wirft mir der Visual C++ Compiler eine Warnung in Zeile 3 (mit /W4)</p>
<pre><code class="language-cpp">typedef unsigned char type;

static const type type_max = ~((type)0u);
</code></pre>
<p>Warnung:</p>
<pre><code>warning C4245: &quot;Initialisierung&quot;: Konvertierung von &quot;int&quot; in &quot;const type&quot;, signed/unsigned-Konflikt.
</code></pre>
<p>Aber ich habe doch type explizit als unsigned deklariert, dazu das literal 0 als unsigned. Oder gibt der ~ Operator immer ein signed zurück??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917797</guid><dc:creator><![CDATA[IWish]]></dc:creator><pubDate>Sun, 27 Jun 2010 02:13:01 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 04:37:06 GMT]]></title><description><![CDATA[<p>IWish schrieb:</p>
<blockquote>
<p>Oder gibt der ~ Operator immer ein signed zurück??</p>
</blockquote>
<p>Nicht immer aaaber ...</p>
<p><a href="http://msdn.microsoft.com/de-de/library/dxt4z71k.aspx" rel="nofollow">http://msdn.microsoft.com/de-de/library/dxt4z71k.aspx</a></p>
<p>Im obigen Artikel wird dich vielleicht besonders der Hinweis/Link auf &quot;Integral Promotions&quot; interessieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917799</guid><dc:creator><![CDATA[hmpf]]></dc:creator><pubDate>Sun, 27 Jun 2010 04:37:06 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 10:39:57 GMT]]></title><description><![CDATA[<p>hmpf schrieb:</p>
<blockquote>
<p>IWish schrieb:</p>
<blockquote>
<p>Oder gibt der ~ Operator immer ein signed zurück??</p>
</blockquote>
<p>Nicht immer</p>
</blockquote>
<p>Bitte genauer. Wann gibt ~(unsigned) einen signed zurück und wann nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917856</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 27 Jun 2010 10:39:57 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 11:37:13 GMT]]></title><description><![CDATA[<p>Auszüge aus dem C++-Standard:</p>
<p>4.5, Integral promotions schrieb:</p>
<blockquote>
<p>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>
</blockquote>
<p>13.6, Builtin operators schrieb:</p>
<blockquote>
<p>In this subclause, the term <em>promoted integral</em> type is used to refer to those integral types which are preserved by integral promotion (including e.g. int and long but excluding e.g. char).<br />
[...]<br />
For every promoted integral type T, there exist candidate operator functions of the form</p>
<pre><code class="language-cpp">T operator˜(T);
</code></pre>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1917876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917876</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 27 Jun 2010 11:37:13 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 12:47:36 GMT]]></title><description><![CDATA[<p>Wenn ich das richtig verstanden habe, wird mein unsigned char durch den compl operator auf int promoted und dann wieder in ein unsigned char gespeichert. Da es sich aber um POD's handelt, verhält sich mein Code, so wie ich es mit vorstelle und ich kann die warnung ignorieren.<br />
Richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917900</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917900</guid><dc:creator><![CDATA[IWish]]></dc:creator><pubDate>Sun, 27 Jun 2010 12:47:36 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 21:25:22 GMT]]></title><description><![CDATA[<p>IWish schrieb:</p>
<blockquote>
<p>und ich kann die warnung ignorieren.<br />
Richtig?</p>
</blockquote>
<p>japp. aber noch besser: du deaktivierst sie an dieser stelle:</p>
<pre><code class="language-cpp"># pragma warning(push)
# pragma warning(disable: xxxx) //kA, was die fehlermeldungs-nr ist...

  static unsigned max = ~0;

# pragma warning(pop)
</code></pre>
<p>da das im header (imho) wahnsinnig beim lesen stört, würd ich das in den source-code verschieben.</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1918175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1918175</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 27 Jun 2010 21:25:22 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 22:01:48 GMT]]></title><description><![CDATA[<p>Einfacher und portabler wäre jedoch ein Cast, der sollte die Warnung auch umgehen. Vielleicht noch mit Kommentar, um die Sache verständlicher zu machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1918181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1918181</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 27 Jun 2010 22:01:48 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 22:29:44 GMT]]></title><description><![CDATA[<p>Danke für die schnelle hilfe! Eine Frage habe ich aber noch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<pre><code class="language-cpp">unsigned long long s = 63;
unsigned long long z = (unsigned long long)~0;
if( z &amp; ( 1u&lt;&lt;s ) )
    std::cout&lt;&lt;&quot;JA&quot;;
else
    std::cout&lt;&lt;&quot;NEIN&quot;;
</code></pre>
<p>Dabei bekomme ich eine Warnung für Zeile 3:</p>
<pre><code>warning C4334: &quot;&lt;&lt;&quot;: Das Ergebnis der 32-Bit-Verschiebung wurde implizit in 64 Bits konvertiert. (War eine 64-Bit-Verschiebung vorgesehen?)
</code></pre>
<p>Das Problem ist: Als Ergebnis wird mir &quot;NEIN&quot; ausgegeben.<br />
Wenn ich das Literal &quot;1u&quot; explizit nach unsigned long long caste, ist die Ausgabe &quot;JA&quot;.<br />
Aber sollte das literal nicht implizit in den größeren Typ (also long long) gecastet werden? Muss ich jetzt all meine Literale umcasten, wenn long long im Spiel ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1918186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1918186</guid><dc:creator><![CDATA[IWish]]></dc:creator><pubDate>Sun, 27 Jun 2010 22:29:44 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 22:47:29 GMT]]></title><description><![CDATA[<p>Beim Shift-Operator sieht alles ein wenig anders aus, das Ergebnis richtet sich nach dem linken Operanden (was auch sinnvoll ist, da sich die Anzahl verschobener Stellen meist in einer viel kleineren Grössenordnung befindet).</p>
<p>13.6, Builtin operators, §17 schrieb:</p>
<blockquote>
<p>For every pair of promoted integral types L and R, there exist candidate operator functions of the form</p>
<pre><code class="language-cpp">LR   operator%(L, R);
LR   operator&amp;(L, R);
LR   operatorˆ(L, R);
LR   operator|(L, R);
L    operator&lt;&lt;(L, R);
L    operator&gt;&gt;(L, R);
</code></pre>
<p>where LR is the result of the usual arithmetic conversions between types L and R.</p>
</blockquote>
<p>Verwende anstelle des Casts die Literalsuffixe<br />
** <code>ll</code> **für <code>signed long long int</code> ( <code>long long</code> ) und<br />
** <code>ull</code> **für <code>unsigned long long int</code> ( <code>unsigned long long</code> ).</p>
<p>Und nimm doch für <code>s</code> einen kleineren Datentypen. Selbst <code>unsigned char</code> reicht noch ein paar Jahrzehnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1918187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1918187</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 27 Jun 2010 22:47:29 GMT</pubDate></item><item><title><![CDATA[Reply to Verstehe Warnung nicht: signed&#x2F;unsigned-Konflikt on Sun, 27 Jun 2010 23:22:14 GMT]]></title><description><![CDATA[<p>Danke Nexus, das wusste ich nicht!</p>
<p>Jetzt sind erstmal alle Fragen geklärt :schland:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1918192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1918192</guid><dc:creator><![CDATA[IWish]]></dc:creator><pubDate>Sun, 27 Jun 2010 23:22:14 GMT</pubDate></item></channel></rss>