<?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[Char-Array als Parameter, Zugriff per sizeof]]></title><description><![CDATA[<p>Hi!<br />
Ich bins mal wieder. Ich habe mal wieder so ein in-Java-wär-das-für-mich-kein-Problem-Frage <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> :</p>
<p>Ich möchte über eine Methode (die noch mehr macht) den Namen des gerade gestarteten Prozesses feststellen:<br />
- Als string antworten geht ja nicht, also 'Speicherplatz' ersteinmal als Pointer mitgeben.<br />
- Aber gleich als TCHAR[], weil 'GetModuleFileNameEx' das sowiso so braucht und ein String von Haus aus zu klein sein könnte.</p>
<p>Das ist nun also der Parameter meiner Methode (für die Rückgabe):</p>
<pre><code>TCHAR* p_prozessPfad
</code></pre>
<p>Jetzt macht 'GetModuleFileNameEx' aber ein Problem, weil sizeof vermutlich 1 liefert:</p>
<pre><code>GetModuleFileNameEx(pi.hProcess, hMod, p_prozessPfad, [b]sizeof(p_prozessPfad)[/b]/sizeof(TCHAR));
</code></pre>
<p>Lokal würde das ganze funktionieren:</p>
<pre><code>TCHAR l_prozessPfad[MAX_PATH] = TEXT(&quot;&lt;unknown&gt;&quot;);
GetModuleFileNameEx(pi.hProcess, hMod, l_prozessPfad, sizeof(l_prozessPfad)/sizeof(TCHAR));
</code></pre>
<p>Hab' ich wieder einen Gedanken-Dreher?!<br />
Wie mache ich das, ohne fest 'MAX_PATH' mitzugeben?!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/184269/char-array-als-parameter-zugriff-per-sizeof</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 16:36:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/184269.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 13 Jun 2007 18:41:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Wed, 13 Jun 2007 18:41:32 GMT]]></title><description><![CDATA[<p>Hi!<br />
Ich bins mal wieder. Ich habe mal wieder so ein in-Java-wär-das-für-mich-kein-Problem-Frage <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> :</p>
<p>Ich möchte über eine Methode (die noch mehr macht) den Namen des gerade gestarteten Prozesses feststellen:<br />
- Als string antworten geht ja nicht, also 'Speicherplatz' ersteinmal als Pointer mitgeben.<br />
- Aber gleich als TCHAR[], weil 'GetModuleFileNameEx' das sowiso so braucht und ein String von Haus aus zu klein sein könnte.</p>
<p>Das ist nun also der Parameter meiner Methode (für die Rückgabe):</p>
<pre><code>TCHAR* p_prozessPfad
</code></pre>
<p>Jetzt macht 'GetModuleFileNameEx' aber ein Problem, weil sizeof vermutlich 1 liefert:</p>
<pre><code>GetModuleFileNameEx(pi.hProcess, hMod, p_prozessPfad, [b]sizeof(p_prozessPfad)[/b]/sizeof(TCHAR));
</code></pre>
<p>Lokal würde das ganze funktionieren:</p>
<pre><code>TCHAR l_prozessPfad[MAX_PATH] = TEXT(&quot;&lt;unknown&gt;&quot;);
GetModuleFileNameEx(pi.hProcess, hMod, l_prozessPfad, sizeof(l_prozessPfad)/sizeof(TCHAR));
</code></pre>
<p>Hab' ich wieder einen Gedanken-Dreher?!<br />
Wie mache ich das, ohne fest 'MAX_PATH' mitzugeben?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305109</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 13 Jun 2007 18:41:32 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Wed, 13 Jun 2007 18:45:30 GMT]]></title><description><![CDATA[<p>Aua, ich Idiot :p</p>
<p>Gerade beim Spielstarten kam mir so ein Gedanke....<br />
die Größe auch als Parameter übergeben, genauso wie 'GetModuleFileNameEx' das ja anscheinend auch macht.....</p>
<p>Richtig?! <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="😃"
    /> Man, das war ein Riesen-Brett!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305112</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 13 Jun 2007 18:45:30 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Wed, 13 Jun 2007 22:30:32 GMT]]></title><description><![CDATA[<p>SammyRukka schrieb:</p>
<blockquote>
<p>- Als string antworten geht ja nicht, also 'Speicherplatz' ersteinmal als Pointer mitgeben.<br />
- Aber gleich als TCHAR[], weil 'GetModuleFileNameEx' das sowiso so braucht und ein String von Haus aus zu klein sein könnte.</p>
</blockquote>
<p>ich frage mich, was für eine art von string du meinst... und was TCHAR ist?</p>
<blockquote>
<p>Jetzt macht 'GetModuleFileNameEx' aber ein Problem, weil sizeof vermutlich 1 liefert:</p>
</blockquote>
<p>nicht unbedingt 'wahrscheinlich'.</p>
<blockquote>
<p>Lokal würde das ganze funktionieren:</p>
</blockquote>
<p>lokal?</p>
<pre><code>TCHAR l_prozessPfad[MAX_PATH] = TEXT(&quot;&lt;unknown&gt;&quot;);
GetModuleFileNameEx(pi.hProcess, hMod, l_prozessPfad, sizeof(l_prozessPfad)/sizeof(TCHAR));
</code></pre>
<p>btw. wenn TCHAR nur ein einfaches define auf chars ist, kannst du dir das /sizeof(TCHAR) sparen. sizeof(char) ist nämlich 1. immer.</p>
<p>vertraue sizeof niemals nicht unüberlegt. (siehe unten)</p>
<blockquote>
<p>Wie mache ich das, ohne fest 'MAX_PATH' mitzugeben?!</p>
</blockquote>
<p>entweder so, wie du schon gesagt hast, oder du sagst dem compiler einfach, dass du ein array von der größe MAX_PATH übergeben willst. wenn sich MAX_PATH nicht so wirklich ändern soll, ist das auch ganz passabel:</p>
<pre><code class="language-cpp">//vielleicht in einen namespace packen? namespace my_globals {
const int MAX_PATH;
//}

void foo (char (&amp;str)[MAX_PATH]) //die referenz ist nötig, sonst funktioniert sizeof nicht wegen 4.2/1
{
  //...
}
</code></pre>
<p>allerdings spricht dann auch nichts dagegen, gleich MAX_PATH an die funktion zu übergeben, die du aufrufst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305266</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Wed, 13 Jun 2007 22:30:32 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 00:13:18 GMT]]></title><description><![CDATA[<p>Kuggugg !</p>
<p>Um MAX_PATH brauchst du dir nicht so sehr den Kopf zu zerbrechen, denn<br />
das ist schon in u.a. windef.h definiert:</p>
<pre><code class="language-cpp">#define MAX_PATH 260
</code></pre>
<pre><code class="language-cpp">#include &lt;windows.h&gt; // Hat auch windef.h included.
#include &lt;iostream&gt;
using namespace std;

bool deine_funktion( HANDLE hProcess, MODULE hModule, char* buf )
{
	if ( ! GetModuleFileNameEx( hProcess, hModule, (LPTSTR)buf, sizeof( buf )  ))
	{
		return false;
	}
	else return true;
}

int main()
{
...
	// Die Version für knauserige Bytefuchser:

	#ifdef UNICODE 
		char buf[ 2 * MAX_PATH ] = '\0';	
	#else 
		char buf[ MAX_PATH ] = '\0';	
	#endif 

	// Aber eigentlich kommts ja nicht auf 260 Byte drauf an,
	// dann kann man gleich schreiben:

	char buf[ 2 * MAX_PATH ] = '\0';	
	// Und ist auf der sicheren Seite.

	if ( deine_funktion( hProcess, hModule, char* buf ) )
	{
		cout &lt;&lt; buf &lt;&lt; endl;
	}
	else
	{
		cout &lt;&lt; &quot;Failed on GetModuleFileNameEx&quot; &lt;&lt; endl;
		// Fehlerbehandlung ...
		// DWORD dw = GetLastError ...
	}
		 ...

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1305282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305282</guid><dc:creator><![CDATA[proggingmania]]></dc:creator><pubDate>Thu, 14 Jun 2007 00:13:18 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 05:58:08 GMT]]></title><description><![CDATA[<p>thx - ich hab jetzt die standard-lösung benutzt und die Größe einfach auch noch mitgegeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305314</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 14 Jun 2007 05:58:08 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 06:24:01 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/14600">@queer_boy</a>: Über TCHAR mußt du dir nicht unbedingt den Kopf zerbrechen, das wird je nach Compilereinstellungen umgewandelt in 'char' (ANSI-Umgebung) oder 'wchar_t' (UNICODE-Umgebung). Wer mit WinAPI arbeitet, hantiert fast ständig damit herum.</p>
<p>@Sammy und proggingmania:<br />
sizeof() liefert nur dann die korrekte Größe, wenn du das Array als echtes Array vorliegen hast. Sobald du nur noch den Zeiger auf den Array-Anfang hast, kommst du nicht mehr an die Größenangaben heran - deshalb solltest du entweder die Vorbedingung setzen, daß vor dem Aufruf eine bestimmte Größe verfügbar ist oder die verfügbare Größe mitliefern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305336</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 14 Jun 2007 06:24:01 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 10:22:03 GMT]]></title><description><![CDATA[<p>Ist char buf[ MAX_PATH ] kein echtes Array ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305525</guid><dc:creator><![CDATA[proggingmania]]></dc:creator><pubDate>Thu, 14 Jun 2007 10:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 10:26:24 GMT]]></title><description><![CDATA[<p>proggingmania schrieb:</p>
<blockquote>
<p>Ist char buf[ MAX_PATH ] kein echtes Array ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Doch, aber p_prozessPfad halt nicht ... und ich denke, darauf wollte er hinweisen.<br />
Leider ist die &quot;implizite Array-Information des Compilers&quot; nicht über Funktionsgrenzen hinweg transportierbar .. (aber das hast Du ja eigentlich auch selbst schon geschrieben).</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305532</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 14 Jun 2007 10:26:24 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 11:50:39 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>@Sammy und proggingmania:<br />
sizeof() liefert nur dann die korrekte Größe, wenn du das Array als echtes Array vorliegen hast. Sobald du nur noch den Zeiger auf den Array-Anfang hast, kommst du nicht mehr an die Größenangaben heran - deshalb solltest du entweder die Vorbedingung setzen, daß vor dem Aufruf eine bestimmte Größe verfügbar ist oder die verfügbare Größe mitliefern.</p>
</blockquote>
<p>Und ich finde, dass ich stolz darauf sein, kann, dass ich das selbst bemerkt habe, als ich sah, dass nur der erste Buchstabe kopiert wurde (wg. sizeof = 1 beim Poniter) <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/1305611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305611</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 14 Jun 2007 11:50:39 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 12:24:27 GMT]]></title><description><![CDATA[<p>SammyRukka schrieb:</p>
<blockquote>
<p>Und ich finde, dass ich stolz darauf sein, kann, dass ich das selbst bemerkt habe, als ich sah, dass nur der erste Buchstabe kopiert wurde (wg. sizeof = 1 beim Poniter) <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>
</blockquote>
<p>Das hört sich für mich nach einem anderen Problem an, nämlich dem, das du für<br />
dein TCHAR* p_prozessPfad keinen Speicherplatz mit malloc reserviert hast <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Wie kommst du eigentlich auf TCHAR ?<br />
Gucke mal hier:</p>
<pre><code class="language-cpp">DWORD GetModuleFileNameEx(
  HANDLE hProcess,    // handle to the process
  HMODULE hModule,    // handle to the module
  LPTSTR lpFilename,  // buffer that receives the path
  DWORD nSize         // size of the buffer
);
</code></pre>
<p>Das ist nen LPTSTR.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305663</guid><dc:creator><![CDATA[proggingmania]]></dc:creator><pubDate>Thu, 14 Jun 2007 12:24:27 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 12:27:44 GMT]]></title><description><![CDATA[<p>Ein LPTSTR ist ein &quot;Long Pointer to T String&quot; also ein Zeiger (Pointer) auf eine Kette (String) von TCHAR <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="😮"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305664</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 14 Jun 2007 12:27:44 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 12:27:52 GMT]]></title><description><![CDATA[<p>proggingmania schrieb:</p>
<blockquote>
<p>Ist char buf[ MAX_PATH ] kein echtes Array ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Doch, das schon - aber in der aufgerufenen Funktion hast du 'nur' <code>char* buf</code> und das ist kein Array mehr <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>@Sammy: sizeof() auf einen Zeiger liefert normalerweise mehr als 1 (typisch sind 4 Byte).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305665</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 14 Jun 2007 12:27:52 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 13:50:58 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>... und das ist kein Array mehr <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
...</p>
</blockquote>
<p>Ja, das ist in der Tat Blödsinn <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/1305739</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305739</guid><dc:creator><![CDATA[proggingmania]]></dc:creator><pubDate>Thu, 14 Jun 2007 13:50:58 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Thu, 14 Jun 2007 16:05:23 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>@Sammy: sizeof() auf einen Zeiger liefert normalerweise mehr als 1 (typisch sind 4 Byte).</p>
</blockquote>
<p>Ja, ist wohl korrekt, es waren glaube ich auch 2 Zeichen, aber zumindest vieeeel zu kurz und viel zu gut zu meiner Vermutung passend, als das ich das nicht anerkennen würde. <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 />
Auf TCHAR bin ich durch einer andere, vorher aufgerufene Funktion gekommen.</p>
<p>proggingmania schrieb:</p>
<blockquote>
<p>Das hört sich für mich nach einem anderen Problem an, nämlich dem, das du für<br />
dein TCHAR* p_prozessPfad keinen Speicherplatz mit malloc reserviert hast <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Warum sollte ich da Speicherplatz reservieren. Ich habe das Array als Lokale und kann es halt nicht direkt an eine aufgerufene Methode übergeben. Der Speicherplatz ist ja trotzdem korrekt reserviert.</p>
<p>.....*offtopic* :p Ich finde Java besser, bastle aber trotzdem gern mit C++ herum! <em>/offtopic</em> <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/1305846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305846</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 14 Jun 2007 16:05:23 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Fri, 15 Jun 2007 00:22:49 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Leider ist die &quot;implizite Array-Information des Compilers&quot; nicht über Funktionsgrenzen hinweg transportierbar</p>
</blockquote>
<p>mit dem trick, den ich beschrieben habe, schon. allerdings hat CStoll recht, sobald es ein pointer wird.. futsch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306187</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Fri, 15 Jun 2007 00:22:49 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Fri, 15 Jun 2007 07:36:05 GMT]]></title><description><![CDATA[<p>queer_boy schrieb:</p>
<blockquote>
<p>Simon2 schrieb:</p>
<blockquote>
<p>Leider ist die &quot;implizite Array-Information des Compilers&quot; nicht über Funktionsgrenzen hinweg transportierbar</p>
</blockquote>
<p>mit dem trick, den ich beschrieben habe, schon....</p>
</blockquote>
<p>Oha, den hatte ich noch nicht gesehen und kannte ihn auch nicht.... nice.<br />
Spätestens mit einem typedef wirds dann &quot;schick&quot;:</p>
<pre><code class="language-cpp">typedef char PATH[256];
typedef char FILENAME[15];

void foo (PATH const&amp; str) {
  cout &lt;&lt; &quot;path: &quot; &lt;&lt; str &lt;&lt; &quot; &quot; &lt;&lt; sizeof(str) &lt;&lt; &quot;\n&quot;;
}

void foo (FILENAME const&amp; str) {
  cout &lt;&lt; &quot;filename: &quot; &lt;&lt; str &lt;&lt; &quot; &quot; &lt;&lt; sizeof(str) &lt;&lt; &quot;\n&quot;;
}

int main () {
   PATH p = &quot;path&quot;;
   foo(p);  
   FILENAME f = &quot;FileName&quot;;
   foo(f);  
   return 0;
}
</code></pre>
<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 />
Ich hätte darauf gewettet, dass das nicht funktioniert ... weil ich nicht auf die Referenze gekommen bin. Spätestens hier wird eine &quot;const&amp;&quot; statt einer Kopie wichtig...</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306285</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306285</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 15 Jun 2007 07:36:05 GMT</pubDate></item><item><title><![CDATA[Reply to Char-Array als Parameter, Zugriff per sizeof on Fri, 15 Jun 2007 07:43:57 GMT]]></title><description><![CDATA[<p>Lasst Euch die Arraylänge doch gleich vom Compiler mit in die Funktion übergeben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">template&lt; size_t N &gt;
void foo( char const ( &amp; str )[ N ] )
{
    cout &lt;&lt; &quot;path: &quot; &lt;&lt; str &lt;&lt; &quot; &quot; &lt;&lt; N &lt;&lt; &quot;\n&quot;;
}

int main()
{
    char path[256];
    char *ptr;

    foo(path); // ok
    foo(ptr); // error
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1306294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306294</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 15 Jun 2007 07:43:57 GMT</pubDate></item></channel></rss>