<?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[short anderes Verhalten als int, longlong und co]]></title><description><![CDATA[<p>Guten Abend,<br />
gleich zu Anfang, mir ist kein treffender Thread-Titel eingefallen...</p>
<p>Beim Durchforsten der STD viel mir heute auf, dass std::to_string für int, long, long long und die jeweils Vorzeichenlose Variante definiert ist, aber nicht für short. Also habe ich etwas mit short experimentiert und folgendes als Beispiel für euch:</p>
<pre><code>#include &lt;iostream&gt;

struct Short_Int{	
	Short_Int(const short Short){
		std::cout&lt;&lt;&quot;A Short \n&quot;;
	}

	Short_Int(const int Int){
		std::cout&lt;&lt;&quot;A Int \n&quot;;
	}	
};

struct Long_LongLong{	
	Long_LongLong(const long Long){
		std::cout&lt;&lt;&quot;A Long \n&quot;;
	}

	Long_LongLong(const long long LongLong){
		std::cout&lt;&lt;&quot;A LongLong \n&quot;;
	}	
};

int main(int argc, char** argv) {

	//	a)
	short s=30000;
	unsigned short us=60000;

	Short_Int s_i(s);			//Ausgabe: &quot;A Short&quot;
	Short_Int us_i(us);			//Ausgabe: &quot;A Int&quot;	-&gt; Kein Fehler?!

	//	b)
	long l=2000000000;
	unsigned long ul=4000000000;

	Long_LongLong l_ll(l);		//Ausgabe &quot;A Long&quot;
	Long_LongLong ul_ll(ul);	//Fehler: &quot;Call of overloaded 'Long_LongLong(long unsigned int&amp;)' is ambiguous&quot;	

	return 0;
}
</code></pre>
<p>Eigentlich hätte ich bei a) und b) das gleiche Verhalten erwartet, nun frage ich mich/euch warum das so umgesetzt wurde?</p>
<p>Vielen Dank und schönen Abend,<br />
John.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327762/short-anderes-verhalten-als-int-longlong-und-co</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 23:53:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327762.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Sep 2014 16:29:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to short anderes Verhalten als int, longlong und co on Tue, 02 Sep 2014 16:29:48 GMT]]></title><description><![CDATA[<p>Guten Abend,<br />
gleich zu Anfang, mir ist kein treffender Thread-Titel eingefallen...</p>
<p>Beim Durchforsten der STD viel mir heute auf, dass std::to_string für int, long, long long und die jeweils Vorzeichenlose Variante definiert ist, aber nicht für short. Also habe ich etwas mit short experimentiert und folgendes als Beispiel für euch:</p>
<pre><code>#include &lt;iostream&gt;

struct Short_Int{	
	Short_Int(const short Short){
		std::cout&lt;&lt;&quot;A Short \n&quot;;
	}

	Short_Int(const int Int){
		std::cout&lt;&lt;&quot;A Int \n&quot;;
	}	
};

struct Long_LongLong{	
	Long_LongLong(const long Long){
		std::cout&lt;&lt;&quot;A Long \n&quot;;
	}

	Long_LongLong(const long long LongLong){
		std::cout&lt;&lt;&quot;A LongLong \n&quot;;
	}	
};

int main(int argc, char** argv) {

	//	a)
	short s=30000;
	unsigned short us=60000;

	Short_Int s_i(s);			//Ausgabe: &quot;A Short&quot;
	Short_Int us_i(us);			//Ausgabe: &quot;A Int&quot;	-&gt; Kein Fehler?!

	//	b)
	long l=2000000000;
	unsigned long ul=4000000000;

	Long_LongLong l_ll(l);		//Ausgabe &quot;A Long&quot;
	Long_LongLong ul_ll(ul);	//Fehler: &quot;Call of overloaded 'Long_LongLong(long unsigned int&amp;)' is ambiguous&quot;	

	return 0;
}
</code></pre>
<p>Eigentlich hätte ich bei a) und b) das gleiche Verhalten erwartet, nun frage ich mich/euch warum das so umgesetzt wurde?</p>
<p>Vielen Dank und schönen Abend,<br />
John.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415848</guid><dc:creator><![CDATA[John1]]></dc:creator><pubDate>Tue, 02 Sep 2014 16:29:48 GMT</pubDate></item><item><title><![CDATA[Reply to short anderes Verhalten als int, longlong und co on Tue, 02 Sep 2014 16:47:38 GMT]]></title><description><![CDATA[<p>Ganz einfach: das eine ist eine integral promotion.<br />
(unsigned) short hat einen kleineren Rank als int weswegen es via Promotion zu einem int konvertiert werden kann.<br />
unsigned short zu short hingegen wäre eine integral conversion.<br />
Eine promotion ist besser als eine conversion, weswegen int ausgewählt wird.<br />
Beim zweiten Fall ist das hingegen beides eine conversion, deswegen ambig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415850</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 02 Sep 2014 16:47:38 GMT</pubDate></item><item><title><![CDATA[Reply to short anderes Verhalten als int, longlong und co on Tue, 02 Sep 2014 16:59:22 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Beim zweiten Fall ist das hingegen beides eine conversion.</p>
</blockquote>
<p>Und warum ist &quot;unsigned short -&gt; int&quot; eine integral conversion, aber &quot;unsigned long -&gt; long long&quot; nicht ?<br />
Sind doch beides integral typen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415854</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415854</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Tue, 02 Sep 2014 16:59:22 GMT</pubDate></item><item><title><![CDATA[Reply to short anderes Verhalten als int, longlong und co on Tue, 02 Sep 2014 17:09:37 GMT]]></title><description><![CDATA[<p>DarkShadow44 schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>Beim zweiten Fall ist das hingegen beides eine conversion.</p>
</blockquote>
<p>Und warum ist &quot;unsigned short -&gt; int&quot; eine integral conversion, aber &quot;unsigned long -&gt; long long&quot; nicht ?<br />
Sind doch beides integral typen.</p>
</blockquote>
<p>Du meinst wohl promotion. Und deshalb:</p>
<p>§4.5/1 schrieb:</p>
<blockquote>
<p>A prvalue of an integer type other than bool, char16_t, char32_t, or wchar_t whose integer conversion rank (4.13) is less than the rank of int can be converted to a prvalue of type int if int can represent all the values of the source type; otherwise, the source prvalue can be converted to a prvalue of type unsigned int.</p>
</blockquote>
<p>integral promotion ist definiert als die Konvertierung zu int*. Alles andere ist eine Konversion, nur ggf. eine &quot;verlustfreie Konversion&quot;.<br />
Hätte den Paragraphen doch zitiert lassen sollen...</p>
<p>*Außer für char16_t, char32_t und wchar_t, da ist das die Konvertierung zum ersten Typen, der alles aufnehmen kann; steht im Abschnitt dadrunter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415855</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 02 Sep 2014 17:09:37 GMT</pubDate></item></channel></rss>