<?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 * const?]]></title><description><![CDATA[<p>Ich stehe gerade aufm Schlauch und zwar hab ich hier eine Methodendeklaration die diesen Parameter nimmt:</p>
<pre><code>Foo::Foo(char * const);
</code></pre>
<p>Kann mir einer auf die Sprünge helfen? Es ist ja offensichtlich nicht &quot;const char *&quot;</p>
<p>Heißt das hier also dass die Pointer Adresse selbst const, aber das gepointete nicht ist?<br />
(Ich frage, weil es eigentlich an dieser Stelle hier nicht vorkommen kann und darf)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/242029/char-const</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 05:06:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/242029.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 29 May 2009 05:59:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 05:59:53 GMT]]></title><description><![CDATA[<p>Ich stehe gerade aufm Schlauch und zwar hab ich hier eine Methodendeklaration die diesen Parameter nimmt:</p>
<pre><code>Foo::Foo(char * const);
</code></pre>
<p>Kann mir einer auf die Sprünge helfen? Es ist ja offensichtlich nicht &quot;const char *&quot;</p>
<p>Heißt das hier also dass die Pointer Adresse selbst const, aber das gepointete nicht ist?<br />
(Ich frage, weil es eigentlich an dieser Stelle hier nicht vorkommen kann und darf)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717652</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Fri, 29 May 2009 05:59:53 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 06:07:21 GMT]]></title><description><![CDATA[<p>Hier ist der Zeiger konstant. Nicht das Char selber, auf den der Zeiger zeigt.</p>
<p><a href="http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.5" rel="nofollow">http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.5</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717653</guid><dc:creator><![CDATA[Roger Wilco]]></dc:creator><pubDate>Fri, 29 May 2009 06:07:21 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 06:20:31 GMT]]></title><description><![CDATA[<p>Das ist aber nicht implizit durch eine Deklaration wie &quot;char *&quot; gegeben, oder? Wäre auch zu komisch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717661</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717661</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Fri, 29 May 2009 06:20:31 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 08:16:04 GMT]]></title><description><![CDATA[<p>Richtig. Bei char * ist erst mal nix konstant.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717711</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Fri, 29 May 2009 08:16:04 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 08:26:38 GMT]]></title><description><![CDATA[<p>char* - nix konstant, alles kann geändert werden<br />
const char* - Zeiger auf einen konstanten char: Du darfst den Zeiger ändern, aber nicht den char selber<br />
char* const - konstanter Zeiger auf ein char, welchen Du nach belieben ändern darfst<br />
const char* const - Zeiger UND char sind konstant</p>
<p>const char&amp; - Referenz auf ein ein konstantes char<br />
char&amp; const - obsolet, da eine Referenz immer konstant ist</p>
<p>Ergänzend:</p>
<p>char const* == const char*<br />
char const&amp; == const char&amp;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717712</guid><dc:creator><![CDATA[Roger Wilco]]></dc:creator><pubDate>Fri, 29 May 2009 08:26:38 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 09:37:20 GMT]]></title><description><![CDATA[<p>Eine frage,wieso funktioniert das:</p>
<pre><code class="language-cpp">typedef char* string_;
#include &lt;iostream&gt; 

void foobar(string_ wayne)
{

  std::cout &lt;&lt; wayne &lt;&lt; std::endl;
}

int main()
{
  const string_ foo = &quot;abc&quot;;
  foobar(foo);
}
</code></pre>
<p>Aber das nicht:</p>
<pre><code class="language-cpp">typedef char* string_;
#include &lt;iostream&gt; 

void foobar(char * wayne)
{

  std::cout &lt;&lt; wayne &lt;&lt; std::endl;
}

int main()
{
  const char * foo = &quot;abc&quot;;
  foobar(foo);
}
</code></pre>
<p>Mein Compiler VC 7.1.<br />
Ich habe erwartet, das beides nicht geht, seit wann juckt den compiler das mit dem const nicht, wenn ein typedef das &quot;char *&quot; wrappt?</p>
<p>Edit: und g++ macht hier eh was es will:<br />
<a href="http://codepad.org/NcD9oIKb" rel="nofollow">http://codepad.org/NcD9oIKb</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717766</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Fri, 29 May 2009 09:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 09:51:13 GMT]]></title><description><![CDATA[<p>Das das unten nicht funktioniert sollte klar sein(const char* kann nicht in char* umgewandelt werden)...</p>
<p>so wäre es übrigens richtig:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

typedef const char* const_string_;

void foobar(const_string_ wayne)
{
  std::cout &lt;&lt; wayne &lt;&lt; std::endl;
}

int main()
{
  const_string_ foo = &quot;abc&quot;;
  foobar(foo);
}
</code></pre>
<p>edit: doch, es ist ja klar, dass das mit typedef compiliert ^^ eben, weil das const auf das typedef bezogen ist und nicht mehr auf das char*...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717774</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 29 May 2009 09:51:13 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 09:48:31 GMT]]></title><description><![CDATA[<p>Im oberen Fall entspricht:</p>
<p>typedef char *string_;</p>
<p>const string_ foo = &quot;abc&quot;;</p>
<p>folgendem:</p>
<p>char * const foo = &quot;abc&quot;;</p>
<p>Du hast mit typedef einen Typ vereinbart und im Code eine konstante Variable von diesem Typ.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717778</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717778</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Fri, 29 May 2009 09:48:31 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 09:54:34 GMT]]></title><description><![CDATA[<p>Also erstmal: Ich bevorzuge folgende Schreibsweise:</p>
<pre><code class="language-cpp">char const * const a;
</code></pre>
<p>Das liest sich schön von hinten nach vorne:<br />
<code>a</code> ist ein konstanter Zeiger auf konstante <code>char</code> .<br />
Lässt man das eine oder andere <code>const</code> weg, so kann man auch aus dem Satz oben einfach das jeweilige &quot;konstant&quot; rausnehmen.<br />
Zu der Frage, wieso die übergabe eines <code>char * const</code> geht:<br />
Der Zeiger wird als Wert übegeben, also als Kopie.<br />
Folgendes geht ja auch:</p>
<pre><code class="language-cpp">void f(int c);
int const a = 10;
int b = a; //b ist eine Kopie von a
f(a); //c in der Funktion ist eine Kopie von a
</code></pre>
<p>Das ist genau das Gleiche.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717783</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717783</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 29 May 2009 09:54:34 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:19:36 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void f(int c);
int const a = 10;
int b = a; //b ist eine Kopie von a
f(a); //c in der Funktion ist eine Kopie von a
</code></pre>
<p>Das ist genau das Gleiche.</p>
</blockquote>
<p>TE hat offensichtlich erwartet, daß</p>
<p>typedef char *string_;<br />
const string_ foo = &quot;abc&quot;;</p>
<p>gleichbedeutend ist mit:</p>
<p>char const * foo = &quot;abc&quot;;</p>
<p>Wie schon gesagt, entspricht es aber:</p>
<p>char * const foo = &quot;abc&quot;;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717804</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717804</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Fri, 29 May 2009 10:19:36 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:27:15 GMT]]></title><description><![CDATA[<p>Jepp is nun klar.</p>
<p>Aber merkwürdig, wenn der Präprozessor doch einfach nur ersetzt, wieso sieht es dann so unterschiedlich aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717808</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Fri, 29 May 2009 10:27:15 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:29:36 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Jepp is nun klar.</p>
<p>Aber merkwürdig, wenn der Präprozessor doch einfach nur ersetzt, wieso sieht es dann so unterschiedlich aus?</p>
</blockquote>
<p><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="😕"
    /> Wo ersetzt da der Präprozessor?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717814</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717814</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 29 May 2009 10:29:36 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:30:09 GMT]]></title><description><![CDATA[<p>Das typedef?<br />
Nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717815</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Fri, 29 May 2009 10:30:09 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:31:06 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Das typedef?<br />
Nicht?</p>
</blockquote>
<p>Da hat der Präprozessor keine Aktien drin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717817</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 29 May 2009 10:31:06 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:39:46 GMT]]></title><description><![CDATA[<p>Aber ich krieg dann das typedef niemals mehr const ohne ein weiteres typedef?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1717825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717825</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Fri, 29 May 2009 10:39:46 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 10:42:51 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Aber ich krieg dann das typedef niemals mehr const ohne ein weiteres typedef?</p>
</blockquote>
<p>Schau Dir mal die Iteratoren aus der STL an. Da gibt es zu jedem mutable Iterator auch immer eine const-Version.<br />
Beispiel:</p>
<pre><code class="language-cpp">std::vector&lt;T&gt;::iterator
std::vector&lt;T&gt;::const_iterator
</code></pre>
<p>Für Deinen Pointer auf const typedef musst Du das ähnlich machen:</p>
<pre><code class="language-cpp">typedef T * MyTPointerType;
typedef T const * MyConstTPointerType;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1717827</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1717827</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 29 May 2009 10:42:51 GMT</pubDate></item><item><title><![CDATA[Reply to char * const? on Fri, 29 May 2009 16:11:58 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>wenn der Präprozessor doch einfach nur ersetzt, wieso sieht es dann so unterschiedlich aus?</p>
</blockquote>
<p>Das verwechselst Du mit #define</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1718040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1718040</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Fri, 29 May 2009 16:11:58 GMT</pubDate></item></channel></rss>