<?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[[g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;)]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich weiß, wie ich die Warnung bei selbst geschriebenen Funktionen lösen kann (char * -&gt; const char *). Aber geht das auch irgendwie ohne -Wno-write-strings zum compiler hinzu zu fügen?</p>
<p>Bei mir kommt die Warnung, wie im Titel beschrieben, beim Aufruf von:<br />
putenv(&quot;foo&quot;);</p>
<p>Besten Dank,<br />
JRS</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/304384/g-warning-deprecated-conversion-from-string-constant-to-char-bei-putenv-quot-foo-quot</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 17:37:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304384.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Jun 2012 07:32:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 07:32:47 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich weiß, wie ich die Warnung bei selbst geschriebenen Funktionen lösen kann (char * -&gt; const char *). Aber geht das auch irgendwie ohne -Wno-write-strings zum compiler hinzu zu fügen?</p>
<p>Bei mir kommt die Warnung, wie im Titel beschrieben, beim Aufruf von:<br />
putenv(&quot;foo&quot;);</p>
<p>Besten Dank,<br />
JRS</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219577</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219577</guid><dc:creator><![CDATA[JRS]]></dc:creator><pubDate>Tue, 05 Jun 2012 07:32:47 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 07:47:57 GMT]]></title><description><![CDATA[<p>Die Lösung bei Warnungen ist in der Regel, es richtig zu machen, <strong>nicht</strong> die Warnung abzuschalten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> . So auch hier.</p>
<p>Wenn deine Funktion die Zeichenkette verändert, wird sie, wie der Compiler richtig erkennt, explodieren. Wenn sie die Zeichenkette nicht verändert, dann ist dein Code falsch, da er nicht const correct ist (die Funktion sollte dann ein <code>const char*</code> als Parameter nehmen).</p>
<p>P.S.: std::string, schon mal gehört?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219586</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219586</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Jun 2012 07:47:57 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 08:09:19 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Wenn deine Funktion die Zeichenkette verändert</p>
</blockquote>
<p><a href="http://man.cx/putenv" rel="nofollow">man: putenv</a> ist aber nicht seine Funktion.</p>
<p>Das Problem könnte hierin liegen:</p>
<blockquote>
<p>In either case, the string pointed to by string shall become part of the environment, so altering the string shall change the environment. The space used by string is no longer used once a new string which defines name is passed to putenv().</p>
</blockquote>
<p>Ich versteh es nicht so ganz, aber irgendwie scheint es, als wäre es mit Absicht nicht const.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219592</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 05 Jun 2012 08:09:19 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 08:09:09 GMT]]></title><description><![CDATA[<p>Verwende setenv</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219593</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Tue, 05 Jun 2012 08:09:09 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 08:23:01 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>vielen Dank! Ich bin nun auf setenv umgestiegen. Nun ist der Fehler weg. Warum putenv allerdings nicht char const * verwendet ist mir nicht ganz klar...</p>
<p>Beste Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219609</guid><dc:creator><![CDATA[JRS]]></dc:creator><pubDate>Tue, 05 Jun 2012 08:23:01 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 09:31:26 GMT]]></title><description><![CDATA[<p>JRS schrieb:</p>
<blockquote>
<p>Hey,</p>
<p>vielen Dank! Ich bin nun auf setenv umgestiegen. Nun ist der Fehler weg. Warum putenv allerdings nicht char const * verwendet ist mir nicht ganz klar...</p>
<p>Beste Grüße</p>
</blockquote>
<p>Warum was verstehst du nicht? Haste dir den Link zur manpage von putenv druchgelesen?</p>
<p>Da steht doch das dein char* Teil der Umgebung wird und fallst du diesen aenderst das auch in der Umgebung geaendert wird.</p>
<p>z.B.</p>
<pre><code class="language-cpp">/*includes .... */
int main(int argc, char** argv) {
   char* env = new char[100];
   static char* default_value = &quot;home=\user\home&quot;;
   strcpy(env, default_value);
   putenv(env); // nun hat die env variable home den wert &quot;\user\home&quot;

   std::cout &lt;&lt; &quot;set new value for env var home: &quot;;
   std::cin.getline(&amp;env[5], 95);

   std::cout &lt;&lt; &quot;new value for home: &quot; &lt;&lt; getenv(&quot;home&quot;) &lt;&lt; &quot;\n&quot;;

   putenv(default_value); // weiss nicht ob man das braucht ob die variable beim verlassen des Programms nochmal bentutz wird aber sicher ist sicher
   delete[] env;
   return 0;
}
</code></pre>
<p>Ich hoff dir wird jetzt klar warum. Es ist einfach so vorgesehen das man den String aendern kann und damit auch die Umgebung aendert.</p>
<p>Gruessle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219635</guid><dc:creator><![CDATA[C0de4Fun]]></dc:creator><pubDate>Tue, 05 Jun 2012 09:31:26 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 09:49:58 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>ja jetzt ist es mir klar. Vielen Dank nochmal für die Erklärung.<br />
Es macht also auch keinen großen Sinn putenv ein festes Literal zu übergeben.</p>
<p>Beste Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219640</guid><dc:creator><![CDATA[JRS]]></dc:creator><pubDate>Tue, 05 Jun 2012 09:49:58 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 10:24:47 GMT]]></title><description><![CDATA[<p>Die Erklärung ist nicht überzeugend.</p>
<p>Das Argument müsste nur nicht-const sein, wenn putenv <strong>selbst</strong> den String verändern wollte. Was es nicht tut. Änderungen von außen sind auch bei const-Argument möglich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219653</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 05 Jun 2012 10:24:47 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 11:05:45 GMT]]></title><description><![CDATA[<p>Möglicherweise einfach alter C-Code?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219678</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Tue, 05 Jun 2012 11:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to [g++] warning: deprecated conversion from string constant to ‘char*’ bei putenv(&amp;quot;foo&amp;quot;) on Tue, 05 Jun 2012 12:00:24 GMT]]></title><description><![CDATA[<p>Manpage schrieb:</p>
<blockquote>
<p>The type of the argument to this function is changed from const char * to char *. This was indicated as a FUTURE DIRECTION in previous issues.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2219714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219714</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Jun 2012 12:00:24 GMT</pubDate></item></channel></rss>