<?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[main-Argumente const-Qualifizieren?]]></title><description><![CDATA[<p>Einfache Frage: Ist laut Standard folgendes erlaubt?</p>
<pre><code class="language-cpp">int main(int argc, char const* const* argv)
</code></pre>
<p>Grüße,<br />
PI</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/298701/main-argumente-const-qualifizieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 18:47:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/298701.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Jan 2012 00:43:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 00:43:53 GMT]]></title><description><![CDATA[<p>Einfache Frage: Ist laut Standard folgendes erlaubt?</p>
<pre><code class="language-cpp">int main(int argc, char const* const* argv)
</code></pre>
<p>Grüße,<br />
PI</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172673</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 26 Jan 2012 00:43:53 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 08:57:18 GMT]]></title><description><![CDATA[<p>Jein. Dem Compiler ist freigestellt, auch so eine main-Funktion zu erlauben.<br />
Gefordert ist:</p>
<p>- Rückgabewert int<br />
- Die Formen <code>int main()</code> und <code>int main(int argc, char* argv[])</code> müssen erlaubt sein</p>
<p>Heißt: der Standard erlaubt es, aber dein Compiler muss es nicht schlucken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172719</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 26 Jan 2012 08:57:18 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 09:00:08 GMT]]></title><description><![CDATA[<p>Das ist ja doph. Naja, danke für die Antwort.</p>
<p>Weiß jemand zufällig, welche Compiler so eine main nicht akzeptieren? Unter GCC und MSVC funktioniert es.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172720</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 26 Jan 2012 09:00:08 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 09:16:01 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Heißt: der Standard erlaubt es, aber dein Compiler muss es nicht schlucken.</p>
</blockquote>
<p>Ohne jetzt den Standard zu wälzen: Ist das Problem nicht in der Regel, dass Compiler absolut jede main-Definition schlucken, aber sie nicht unbedingt als korrekten Einsprungpunkt umsetzen? Ich könnte mir z.B. vorstellen, dass <code>int main(vector&lt;string&gt; const&amp; args)</code> erstmal anstandslos geschluckt wird, dann aber zu lustigen Ergebnissen führt.</p>
<p>edit: Um die Frage nochmal unter diesem Gesichtspunkt neu zu beantworten: Dass der Compiler eine bestimmte zusätzliche Signatur erlaubt, bedeutet, dass er sie korrekt aufrufen kann. Unter Linux gibt es m.W. eine main-Form mit zusätzlichem Zeiger auf die Umgebungsvariablen. Wenn du eine selbst ausgedachte Signatur verwendest, bewegst du dich im undefinierten Bereich. Im Falle von zusätzlichen const-Qualifikationen würde ich erwarten, dass es aufgrund der identischen internen Repräsentation funktioniert, aber das ist halt nicht garantiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172725</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 26 Jan 2012 09:16:01 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 09:26:40 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>pumuckl schrieb:</p>
<blockquote>
<p>Heißt: der Standard erlaubt es, aber dein Compiler muss es nicht schlucken.</p>
</blockquote>
<p>Ohne jetzt den Standard zu wälzen: Ist das Problem nicht in der Regel, dass Compiler absolut jede main-Definition schlucken, aber sie nicht unbedingt als korrekten Einsprungpunkt umsetzen? Ich könnte mir z.B. vorstellen, dass <code>int main(vector&lt;string&gt; const&amp; args)</code> erstmal anstandslos geschluckt wird, dann aber zu lustigen Ergebnissen führt.</p>
</blockquote>
<p>Naja, ich lese das in §3.6.1 so: Es MUSS eine main im Programm geben, die der Einstiegspunkt des Programms ist. main darf nicht überladen werden. Soll heißen, es darf exakt eine Funktion main geben. Diese Funktion ist der Einstiegspunkt. Wenn eine Implementation das vermurkst, ist die Implementation nicht konform.</p>
<blockquote>
<p>edit: Um die Frage nochmal unter diesem Gesichtspunkt neu zu beantworten: Dass der Compiler eine bestimmte zusätzliche Signatur erlaubt, bedeutet, dass er sie korrekt aufrufen kann.</p>
</blockquote>
<p>Ja.</p>
<blockquote>
<p>Wenn du eine selbst ausgedachte Signatur verwendest, bewegst du dich im undefinierten Bereich.</p>
</blockquote>
<p>Dann sollte der Compiler das bemängeln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172736</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 26 Jan 2012 09:26:40 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 09:45:35 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Naja, ich lese das in §3.6.1 so: Es MUSS eine main im Programm geben, die der Einstiegspunkt des Programms ist. main darf nicht überladen werden. Soll heißen, es darf exakt eine Funktion main geben. Diese Funktion ist der Einstiegspunkt. Wenn eine Implementation das vermurkst, ist die Implementation nicht konform.</p>
</blockquote>
<p>Fragen wir mal andersrum, welche Implementation macht das denn so? MSVC 2010 lässt mein Beispiel zu. Dem ollen Borland C++ war die Signatur der main auch egal. gcc warnt soweit ich weiß nur, das kann ich gerade nicht probieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172747</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 26 Jan 2012 09:45:35 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 10:27:45 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>pumuckl schrieb:</p>
<blockquote>
<p>Naja, ich lese das in §3.6.1 so: Es MUSS eine main im Programm geben, die der Einstiegspunkt des Programms ist. main darf nicht überladen werden. Soll heißen, es darf exakt eine Funktion main geben. Diese Funktion ist der Einstiegspunkt. Wenn eine Implementation das vermurkst, ist die Implementation nicht konform.</p>
</blockquote>
<p>Fragen wir mal andersrum, welche Implementation macht das denn so? MSVC 2010 lässt mein Beispiel zu. Dem ollen Borland C++ war die Signatur der main auch egal. gcc warnt soweit ich weiß nur, das kann ich gerade nicht probieren.</p>
</blockquote>
<p>Nein, der GCC erlaubt GAHNix anderes als int und char**. Siehe <a href="http://ideone.com/UStHY" rel="nofollow">hier</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172757</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 26 Jan 2012 10:27:45 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 10:34:19 GMT]]></title><description><![CDATA[<p><a href="http://ideone.com/XqA5e" rel="nofollow">http://ideone.com/XqA5e</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172762</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172762</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 26 Jan 2012 10:34:19 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 10:39:54 GMT]]></title><description><![CDATA[<p><a href="http://ideone.com/KMjEl" rel="nofollow">http://ideone.com/KMjEl</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172766</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 26 Jan 2012 10:39:54 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 10:49:56 GMT]]></title><description><![CDATA[<blockquote>
<p>2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both of the following definitions of main:<br />
int main() { /* ... <em>/ }<br />
and<br />
int main(int argc, char</em> argv[]) { /* ... */ }<br />
In the latter form argc shall be the number of arguments passed to the program from the environment in which the program is run. If argc is nonzero these arguments shall be supplied in argv[0] through argv[argc-1] as pointers to the initial characters of null-terminated multibyte strings (ntmbs s) (17.5.2.1.4.2) and argv[0] shall be the pointer to the initial character of a ntmbs that represents the name used to invoke the program or &quot;&quot;. The value of argc shall be non-negative. The value of argv[argc] shall be 0. [ Note: It is recommended that any further (optional) parameters be added after argv. —end note ]</p>
</blockquote>
<p>Um also auf die Ursprungsfrage zurückzukommen: Es steht einer Implementation frei, den Code zu akzeptieren oder zurückzuweisen.<br />
C99 kennt die Kategorien <em>strictly conforming program</em> und <em>conforming program</em>. Auf C++ angewandt, wäre ein Programm mit einer solchen main-Funktion konform, aber nicht streng konform, da für letzteres das Verhalten nicht von der implementation abhängen darf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172768</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 26 Jan 2012 10:49:56 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 11:24:40 GMT]]></title><description><![CDATA[<p>camper, liest du aus dem Text heraus, dass ein Compiler eine main-Signatur entweder unterstützen oder ablehnen muss?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172777</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 26 Jan 2012 11:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 12:02:09 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>camper, liest du aus dem Text heraus, dass ein Compiler eine main-Signatur entweder unterstützen oder ablehnen muss?</p>
</blockquote>
<p>Eine (hosted) Implementation muss main unterstützen. Ob und in wieweit zusätzliche Signaturen (außer den beiden vorgegeben) unterstützt werden, ist dagegen durch die Implementation festzulegen (die darf auch festlegen, dass keine zusätzlichen Varianten erlaubt sind - das implementation-defined bezieht sich ja auf alle denkbaren Typen einschließlich der Vorgaben).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172790</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 26 Jan 2012 12:02:09 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 12:05:20 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>camper, liest du aus dem Text heraus, dass ein Compiler eine main-Signatur entweder unterstützen oder ablehnen muss?</p>
</blockquote>
<p>Ich lese das daraus. Mit Betonung auf unterstützen, d.h. sinnvoll umsetzen. Eine main-Signatur nur zu <em>akzeptieren</em> und Murks zu machen ist nicht standardkonform.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172792</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172792</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 26 Jan 2012 12:05:20 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 13:20:50 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Bashar schrieb:</p>
<blockquote>
<p>camper, liest du aus dem Text heraus, dass ein Compiler eine main-Signatur entweder unterstützen oder ablehnen muss?</p>
</blockquote>
<p>Ich lese das daraus. Mit Betonung auf unterstützen, d.h. sinnvoll umsetzen. Eine main-Signatur nur zu <em>akzeptieren</em> und Murks zu machen ist nicht standardkonform.</p>
</blockquote>
<p>Ach die Wortwahl war das Probelm... ja, mit akzeptieren ist hier natürlich sinnvoll umsetzen gemeint.<br />
Die Implementation muss dokumentieren, welche Signaturen unterstützt werden, was bei Verwendung solcher zusätzlichen Signaturen passiert/zu beachten ist, und natürlich auch, was passiert, wenn eine nicht unterstützte Signatur verwendet wird; undefiniertes Verhalten darf nicht auftreten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172820</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172820</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 26 Jan 2012 13:20:50 GMT</pubDate></item><item><title><![CDATA[Reply to main-Argumente const-Qualifizieren? on Thu, 26 Jan 2012 16:45:37 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p><a href="http://ideone.com/XqA5e" rel="nofollow">http://ideone.com/XqA5e</a></p>
</blockquote>
<p>camper schrieb:</p>
<blockquote>
<p><a href="http://ideone.com/KMjEl" rel="nofollow">http://ideone.com/KMjEl</a></p>
</blockquote>
<pre><code>error: second argument of ‘int main(const int&amp;, const char*)’ should be ‘char **’
</code></pre>
<p>Ja aber - ja aber - <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /> Sternchen vergessen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /><br />
<a href="http://ideone.com/jOZqH" rel="nofollow">http://ideone.com/jOZqH</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2172985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2172985</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 26 Jan 2012 16:45:37 GMT</pubDate></item></channel></rss>