<?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[Fehler bei Typumwandlung in Zeiger]]></title><description><![CDATA[<p>Ich habe im Moment das Problem, dass ich eine 2D-MAtrix in einen Doppelpointer umwandeln möchte, aber leider gehen die daten dabei verloren...</p>
<pre><code class="language-cpp">float matrix[10][9]={   {1,1,0,0,0,0,0,1,0},
                        {1,0,0,1,0,0,0,0,0},
                        {0,0,0,1,0,1,0,1,1},
                        {0,0,1,0,0,0,0,0,0},
                        {0,0,0,1,0,0,0,0,1},
                        {0,0,1,0,0,0,1,0,0},
                        {0,0,0,0,0,1,0,0,0},
                        {0,1,0,0,1,0,1,0,0},
                        {0,0,0,0,0,0,0,1,0},
                        {0,0,0,0,0,0,0,0,1} };
</code></pre>
<p>wenn ich diese Matrix nun an eine Funktion übergeben will und dabei konvertiere, kommt Müll raus:</p>
<pre><code class="language-cpp">funktion((float**)matrix, 10);
</code></pre>
<p>also bei sowas zb:</p>
<pre><code class="language-cpp">for(int c = 0; c &lt; 10; c++) {
		for(int i = 0; i &lt; 9; i++)
			std::cout&lt;&lt;&quot; M: &quot;&lt;&lt;matrix[c];
		std::cout&lt;&lt;std::endl;
	}
</code></pre>
<p>wird statt (das ist der Fall, bevor ich konvertiere):</p>
<pre><code>M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60
 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84
 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8
 M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc
 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0
 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14
 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38
 M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c
 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80
 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4
</code></pre>
<p>sowas ausgegeben (das passiert in der Funktion):</p>
<pre><code>M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000
</code></pre>
<p>Wie kann ich korrekt konvertieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213381/fehler-bei-typumwandlung-in-zeiger</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 06:26:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213381.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 May 2008 10:39:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler bei Typumwandlung in Zeiger on Sat, 17 May 2008 10:39:25 GMT]]></title><description><![CDATA[<p>Ich habe im Moment das Problem, dass ich eine 2D-MAtrix in einen Doppelpointer umwandeln möchte, aber leider gehen die daten dabei verloren...</p>
<pre><code class="language-cpp">float matrix[10][9]={   {1,1,0,0,0,0,0,1,0},
                        {1,0,0,1,0,0,0,0,0},
                        {0,0,0,1,0,1,0,1,1},
                        {0,0,1,0,0,0,0,0,0},
                        {0,0,0,1,0,0,0,0,1},
                        {0,0,1,0,0,0,1,0,0},
                        {0,0,0,0,0,1,0,0,0},
                        {0,1,0,0,1,0,1,0,0},
                        {0,0,0,0,0,0,0,1,0},
                        {0,0,0,0,0,0,0,0,1} };
</code></pre>
<p>wenn ich diese Matrix nun an eine Funktion übergeben will und dabei konvertiere, kommt Müll raus:</p>
<pre><code class="language-cpp">funktion((float**)matrix, 10);
</code></pre>
<p>also bei sowas zb:</p>
<pre><code class="language-cpp">for(int c = 0; c &lt; 10; c++) {
		for(int i = 0; i &lt; 9; i++)
			std::cout&lt;&lt;&quot; M: &quot;&lt;&lt;matrix[c];
		std::cout&lt;&lt;std::endl;
	}
</code></pre>
<p>wird statt (das ist der Fall, bevor ich konvertiere):</p>
<pre><code>M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60 M: 0x605b60
 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84 M: 0x605b84
 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8 M: 0x605ba8
 M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc M: 0x605bcc
 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0 M: 0x605bf0
 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14 M: 0x605c14
 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38 M: 0x605c38
 M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c M: 0x605c5c
 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80 M: 0x605c80
 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4 M: 0x605ca4
</code></pre>
<p>sowas ausgegeben (das passiert in der Funktion):</p>
<pre><code>M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0 M: 0
 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000 M: 0x3f80000000000000
</code></pre>
<p>Wie kann ich korrekt konvertieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510944</guid><dc:creator><![CDATA[_Hasu_]]></dc:creator><pubDate>Sat, 17 May 2008 10:39:25 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Typumwandlung in Zeiger on Sat, 17 May 2008 13:04:27 GMT]]></title><description><![CDATA[<p>Eine 2D Matrix hat NICHTS mit Doppelpointer zu tun!</p>
<p>Ich habe jetzt keine Lust nochmal alles durchzukauen. Das gibt es hier immer wieder. (Werde schnell schauen, ob ich es finde).</p>
<p>EDIT:<br />
Ging schnell: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-212469-and-highlight-is-doppelpointer.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-212469-and-highlight-is-doppelpointer.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1511009</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1511009</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sat, 17 May 2008 13:04:27 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Typumwandlung in Zeiger on Sat, 17 May 2008 20:27:05 GMT]]></title><description><![CDATA[<p>hmm, schade. mir war schon klar, dass beides nicht das gleiche ist, aber ich würde gerne doch wissen ob es ne möglichkeit gibt, die daten zu konvertieren, denn scheinbar hängt ein array von den adressen her sehr dicht aneinander.<br />
weil ich die daten nicht einzeln verarbeite, müsste ich also bisher - langsam - in ein anderes 2D-array umkopieren.<br />
folglich denke ich an soetwas wie memset.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1511215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1511215</guid><dc:creator><![CDATA[_Hasu_]]></dc:creator><pubDate>Sat, 17 May 2008 20:27:05 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Typumwandlung in Zeiger on Sat, 17 May 2008 21:25:46 GMT]]></title><description><![CDATA[<p><em>Hasu</em> schrieb:</p>
<blockquote>
<p>hmm, schade. mir war schon klar, dass beides nicht das gleiche ist, aber ich würde gerne doch wissen ob es ne möglichkeit gibt, die daten zu konvertieren, denn scheinbar hängt ein array von den adressen her sehr dicht aneinander.<br />
weil ich die daten nicht einzeln verarbeite, müsste ich also bisher - langsam - in ein anderes 2D-array umkopieren.<br />
folglich denke ich an soetwas wie memset.</p>
</blockquote>
<p>Arrays können NUR als per Reference übergeben werden.<br />
Jede Variante, die ich im Link gepostet habe, übergibt nicht mehr als einen Zeiger. (Abgesehen von den int's)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1511250</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1511250</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sat, 17 May 2008 21:25:46 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Typumwandlung in Zeiger on Sun, 18 May 2008 13:02:16 GMT]]></title><description><![CDATA[<p>funktion erwartet einen Zeiger, der in ein Array aus Zeigern zeigt, welche wiederum in Arrays aus floats zeigen. Ein einfacher Cast hilft hier nicht, denn wir müssen - wenigstens für die Dauer des Funktionsaufrufs - ein Hilfsarray erstellen, dass diese zusätzlichen Zeiger aufnimmt. ein paar Hilfstemplates können uns das erleichtern</p>
<pre><code class="language-cpp">template&lt;typename T, std::size_t N&gt;
class Array2dRef2Ptr
{
public:
    template&lt;std::size_t M&gt;
    Array2dRef2Ptr(T (&amp;a)[N][M])
    {
        std::copy( a, a + N, ptr_ ); // hier wird nichts kopiert
    }
    operator T**() { return ptr_; }
private:
    T* ptr_[N];
};

template&lt;typename T, std::size_t N, std::size_t M&gt;
Array2dRef2Ptr&lt; T, N &gt; array2ptr(T (&amp;a)[N][M])
{
    return a;
}

...

funktion(array2ptr(matrix), 10); // ohne Cast
</code></pre>
<p>Die beste Lösung ist aber immer noch, funktion geeignet anzupassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1511507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1511507</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 18 May 2008 13:02:16 GMT</pubDate></item></channel></rss>