<?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[Anzahl Elemente eines Vectors bestimmen]]></title><description><![CDATA[<p>Hi</p>
<p>Wie kann ich von size_type zu int umwandeln, ohne diese Warnung zu bekommen?</p>
<blockquote>
<p>warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/topic/156002/anzahl-elemente-eines-vectors-bestimmen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 17:14:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/156002.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Aug 2006 20:39:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 20:39:23 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Wie kann ich von size_type zu int umwandeln, ohne diese Warnung zu bekommen?</p>
<blockquote>
<p>warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1115640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115640</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 20:39:23 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 20:42:55 GMT]]></title><description><![CDATA[<p>Ich würds mal mit reinterpret_cast&lt;int&gt;(...) versuchen.</p>
<p>Das du die Warnung bekommst ist klar, ich glaube size_t ist ein __int64 oder hat wenigstens einen ähnlichen Wertebereich (weiß gerade nicht genau, eventuell kann mich da jemand anders verbessern).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115643</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Fri, 11 Aug 2006 20:42:55 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 20:45:44 GMT]]></title><description><![CDATA[<p>Sollte ich besser die int Variable in size_t abändern?<br />
Oder casten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115648</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 20:45:44 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:15:29 GMT]]></title><description><![CDATA[<p>Kommt auf die Anwendung drauf an, wenn dein vector weniger als 2^32 Elemente hat, kannst du ruhig casten.</p>
<p>Intressant wird der Datentyp size_t erst, wenn du zum Beispiel die größe von Dateien bestimmen willst. 2^32 entsprichen 4 GB, dann wäre mit casten Feierabend. Da es aber Dateien gibt die größer sind als 4 GB lohnt es sich in diesen Fällen size_t oder __int64 zu nutzen.</p>
<p>Ich glaube gegen die Nutzung von size_t und __int64 spricht nur das ein 32 bit Prozessor diesen Datentyp nicht in einem Rechenzyklus verarbeiten kann, sondern zwei braucht. *nicht sicher bin*</p>
<p>//edit: Ups, die aussage von oben ist nicht ganz zutreffend bei int geht der Werte bereich nur bis 2^31 (=2^32/2), da ja noch der negative Bereich hinzukommt. Eventuelle solltest du daher vieleicht besser mit unsigned int arbeiten (da hast du richtige 2^32 zur Verfügung)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115659</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:15:29 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:15:09 GMT]]></title><description><![CDATA[<p>Danke<br />
Ne ich denke so viele Elemente hab ich da nicht drin.<br />
Dann kann ich die Warnung einfach ignorieren oder?<br />
Wo find ich raus, was mein Kompiler für size_t definiert hat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115663</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:15:09 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:23:12 GMT]]></title><description><![CDATA[<p>flammenvogel schrieb:</p>
<blockquote>
<p>Ich würds mal mit reinterpret_cast&lt;int&gt;(...) versuchen.</p>
</blockquote>
<p>Das ist Unsinn. reinterpret_cast ist dazu da um Zeiger zu casten.</p>
<p>flammenvogel schrieb:</p>
<blockquote>
<p>Das du die Warnung bekommst ist klar, ich glaube size_t ist ein __int64 oder hat wenigstens einen ähnlichen Wertebereich (weiß gerade nicht genau, eventuell kann mich da jemand anders verbessern).</p>
</blockquote>
<p>Stimmt auch nicht. size_t ist meistens ein typedef auf unsigned int, also auf 32 Bit Systemen eben 32 Bit und auf 64 Bit Systemen (wie meinem) 64 Bit. Zum Beweis:</p>
<pre><code>$ sizeof size_t
sizeof (size_t) == 64 Bit == 8 Byte
$ CC=gcc32 sizeof size_t
sizeof (size_t) == 32 Bit == 4 Byte
</code></pre>
<p>wobei sizeof ein Shellskript mit diesem Inhalt ist:</p>
<pre><code>#!/bin/bash

if [ $CC ]
then
    compiler=$CC
else
    compiler=&quot;gcc&quot;
fi

if [ $CFLAGS ]
then
    compiler=&quot;$compiler $CFLAGS&quot;
fi

filename=&quot;/tmp/sizeof.c&quot;
arg=$1

echo -n &quot;const char* str = \&quot;&quot; &gt; $filename
echo -n &quot;sizeof (&quot; &gt;&gt; $filename
echo -n $arg | sed &quot;s/\&quot;/\\\\\&quot;/g&quot;  &gt;&gt; $filename
echo &quot;) == %u Bit == %u Byte\\n\&quot;;&quot; &gt;&gt; $filename

echo &quot;#include &lt;stdio.h&gt;
#include &lt;limits.h&gt;
int main ()
{
    printf(str, sizeof ($arg) * CHAR_BIT, sizeof ($arg) * CHAR_BIT / 8);
}&quot; &gt;&gt; $filename
if [ $VERBOSE ]
then
    if $compiler $filename -o$filename.exe
    then
        res=&quot;1&quot;
    fi
else
    if $compiler $filename -o$filename.exe 2&gt; /dev/null
    then
        res=&quot;1&quot;
    fi
fi

if [ $res ]
then
    $filename.exe
    rm $filename.exe
else
    echo &quot;sizeof ($arg) == unknown&quot;
fi
rm $filename
</code></pre>
<p>Ziemlich primitiv, aber äußerst praktisch ;).</p>
<p>Die Warnung kommt möglicherweise, weil in ein int nur halbsoviele positive Werte passen wie in ein unsigned. Verwende unsigned oder size_t und die Sache ist gegessen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115666</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:27:41 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /><br />
Hab kein Linux, daher Shellscript == unkonwn type <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="😃"
    /><br />
Mit unsigned int hab ichs versucht, is nich.<br />
Compiler ist übrigens VC8.0<br />
Mit size_t gehts ohne Warnung, aber wenn das stimmt:</p>
<blockquote>
<p>Ich glaube gegen die Nutzung von size_t und __int64 spricht nur das ein 32 bit Prozessor diesen Datentyp nicht in einem Rechenzyklus verarbeiten kann, sondern zwei braucht. *nicht sicher bin*</p>
</blockquote>
<p>möcht ich das nicht umbedingt.<br />
Hab nur ein 32 bitter *schwanzlängenvergleichverliersniff*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115669</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:27:41 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:32:52 GMT]]></title><description><![CDATA[<p>1. OMG, was ist <strong>ein</strong> Rechenzyklus<br />
2. .filmor hat die Behauptung gerade wiederlegt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115677</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:32:52 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:40:12 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9606">@.filmor</a>: Hmm, ich glaube ich habe size_t mit pos_type verwechselt, der müsste 64 Bit groß sein. Srry</p>
<p>//edit: LordJaxom: eine etwas unglückliche Wortschöpfung von mir, außerdem bezieht sich die Behauptung auf 64 Bit Variabeln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115684</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:40:12 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:38:59 GMT]]></title><description><![CDATA[<p>Class iker schrieb:</p>
<blockquote>
<p>Mit unsigned int hab ichs versucht, is nich.</p>
</blockquote>
<p>Das glaube ich dir nicht :p. Fehlermeldung?</p>
<p>Class iker schrieb:</p>
<blockquote>
<p>Mit size_t gehts ohne Warnung, aber wenn das stimmt:</p>
<blockquote>
<p>Ich glaube gegen die Nutzung von size_t und __int64 spricht nur das ein 32 bit Prozessor diesen Datentyp nicht in einem Rechenzyklus verarbeiten kann, sondern zwei braucht. *nicht sicher bin*</p>
</blockquote>
<p>möcht ich das nicht umbedingt.<br />
Hab nur ein 32 bitter *schwanzlängenvergleichverliersniff*</p>
</blockquote>
<p>Das lässt sich ganz leicht herausfinden. Lass einfach dieses Programm laufen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;limits&gt;

int main ()
{
    std::cout &lt;&lt; std::numeric_limits&lt;std::size_t&gt;::digits  &lt;&lt; std::endl;
}
</code></pre>
<p>Das gibt dir die Größe von size_t aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115687</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115687</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:38:59 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:47:56 GMT]]></title><description><![CDATA[<p>flammenvogel schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9606">@.filmor</a>: Hmm, ich glaube ich habe size_t mit pos_type verwechselt, der müsste 64 Bit groß sein. Srry</p>
</blockquote>
<p>Muss er auch nicht. Standardgemäß gibts bei den meisten 32-Bit Compilern AFAIK gar keine 64-Bit Typen (nur solche Erweiterungen wie __int64 oder long long). pos_type gibts außerdem nicht. Falls du difference_type meinst, das ist beim 32-Bit Compiler ein 32 Bits großer Integer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115695</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:47:56 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:52:15 GMT]]></title><description><![CDATA[<p>.filmor schrieb:</p>
<blockquote>
<p>Class iker schrieb:</p>
<blockquote>
<p>Mit unsigned int hab ichs versucht, is nich.</p>
</blockquote>
<p>Das glaube ich dir nicht :p. Fehlermeldung?</p>
</blockquote>
<p>Mein Kompilierer schrieb:</p>
<blockquote>
<p>------ Rebuild All started: Project: Blabla, Configuration: Debug Win32 ------<br />
Deleting intermediate and output files for project 'Blabla', configuration 'Debug|Win32'<br />
Compiling...<br />
Main.cpp<br />
PathGraph.cpp<br />
...: warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of data<br />
...: warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of data<br />
Generating Code...<br />
Compiling manifest to resources...<br />
Linking...<br />
LINK : ....exe not found or not built by the last incremental link; performing full link<br />
Embedding manifest...<br />
Build log was saved at &quot;file://c:...&quot;<br />
ALG_DijkstraWithBoost - 0 error(s), 2 warning(s)<br />
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========</p>
</blockquote>
<p>:p Na gut, sis nur ne Warnung..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115700</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:52:15 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 21:58:36 GMT]]></title><description><![CDATA[<p>Dein kleines Testprogramm schrieb:</p>
<blockquote>
<p>32</p>
</blockquote>
<p>Leider nicht 42 <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="😃"
    /><br />
Danke man, wieder was gelernt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115706</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 21:58:36 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 22:00:55 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9606">@.filmor</a>: Ich meine den Datentyp der von fstream::teelg() ausgegen wird (nach meiner Referenz ist das pos_type). Der kann bei mit WinXP (gcc Kompiler) problemlos auch 64Bit Werte aufnehmen. Wäre das anderes wäre es in C++ nicht möglich mit Daten zu arbeiten, die größer als 4GB sind, was definitiv nicht der Fall ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1115708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115708</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Fri, 11 Aug 2006 22:00:55 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl Elemente eines Vectors bestimmen on Fri, 11 Aug 2006 23:03:10 GMT]]></title><description><![CDATA[<blockquote>
<p>..(68) : warning C4832: token '.' is illegal after UDT 'std::numeric_limits&lt;int&gt;'<br />
...\limits(653) : see declaration of 'std::numeric_limits&lt;int&gt;'</p>
</blockquote>
<p>S gibt sogar noch eine mehr, mit Deiner kleinen Testzeile <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1115714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1115714</guid><dc:creator><![CDATA[Class iker]]></dc:creator><pubDate>Fri, 11 Aug 2006 23:03:10 GMT</pubDate></item></channel></rss>