<?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[Funktion nur 1* ausführen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine Funktion in meinem Programm nur 1 Mal ausführen, obwohl die main-Funktion wiederholt wird.</p>
<p>Ich habe an eine globale bool Variable gedacht (siehe unten). Gibt es aber eine bessere Möglichkeit?</p>
<pre><code>bool tmp = true;

void main(){

   while( ...) {

        initialize(){

                if ( tmp == true){

                    do_something();

                    tmp = false;  

                 }

     }

  }

}
</code></pre>
<p>Grüße,</p>
<p>CP</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/199183/funktion-nur-1-ausführen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 21:42:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/199183.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Nov 2007 17:19:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:19:10 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine Funktion in meinem Programm nur 1 Mal ausführen, obwohl die main-Funktion wiederholt wird.</p>
<p>Ich habe an eine globale bool Variable gedacht (siehe unten). Gibt es aber eine bessere Möglichkeit?</p>
<pre><code>bool tmp = true;

void main(){

   while( ...) {

        initialize(){

                if ( tmp == true){

                    do_something();

                    tmp = false;  

                 }

     }

  }

}
</code></pre>
<p>Grüße,</p>
<p>CP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412458</guid><dc:creator><![CDATA[cpplinux]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:19:10 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:24:19 GMT]]></title><description><![CDATA[<p>Eine lokale Variable, die static deklariert wird. Der Mechanismus ist der gleiche, nur die Sichtbarkeit ist anders.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412462</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:24:19 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:24:38 GMT]]></title><description><![CDATA[<p>cpplinux schrieb:</p>
<blockquote>
<p>Gibt es aber eine bessere Möglichkeit?</p>
</blockquote>
<p>z.b. eine lokale bool variable. oder den aufruf einfach nicht in der schleife machen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412463</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:24:38 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:26:20 GMT]]></title><description><![CDATA[<p>void main?! sollte das nicht INT main sein, daher dein Programm immer ein Rückgabewert hat..</p>
<p>entweder vor der Schleife einbauen oder die Variable in main deklarieren..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412464</guid><dc:creator><![CDATA[wer??]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:26:20 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:32:26 GMT]]></title><description><![CDATA[<p>der standard verbietet void main() nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412468</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:32:26 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:43:56 GMT]]></title><description><![CDATA[<p>Ist es so z.B. richtig? wird dann die Zeile -- static bool tmp = true; -- nur<br />
1 Mal ausgeführt?</p>
<pre><code>void main(){ 

   while( ...) { 

        initialize(){ 
                static bool tmp = true;

                if ( tmp == true){ 

                    do_something(); 

                    tmp = false;   

                 } 

     } 

  } 

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1412473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412473</guid><dc:creator><![CDATA[cpplinux]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:43:56 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:47:05 GMT]]></title><description><![CDATA[<p>dot schrieb:</p>
<blockquote>
<p>der standard verbietet void main() nicht.</p>
</blockquote>
<p>Zitat von <a href="http://tutorial.schornboeck.net/groessten_luegen.htm" rel="nofollow">http://tutorial.schornboeck.net/groessten_luegen.htm</a></p>
<blockquote>
<p>void main()</p>
<p>[...] Aber in zahlreichen Büchern und Tutorials wird erklärt, dass void main() legales C++ sei, dass ist aber falsch! Es gab keinen C++-Standard, der je void main für legal erklärte. Die main-Funktion muss immer int zurückgeben!</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1412475</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412475</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:47:05 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:48:35 GMT]]></title><description><![CDATA[<p>cpplinux schrieb:</p>
<blockquote>
<p>Ist es so z.B. richtig? wird dann die Zeile -- static bool tmp = true; -- nur<br />
1 Mal ausgeführt?</p>
</blockquote>
<p>Bis auf die Syntaxfehler ja. Funktionen können natürlich nicht irgendwo mittendrin definiert werden, das ganze muss so aussehen:</p>
<pre><code class="language-cpp">void initialize() {
  static bool first_run = true;
  if (first_run) {
    /* mach was */
    first_run = false;
  }
}

int main() {
  while (...) {
    initialize();
    ...
  }
}
</code></pre>
<p>Noch einfacher wäre natürlich, initialize nicht in der Schleife aufzurufen ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412477</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412477</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:48:35 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 17:50:48 GMT]]></title><description><![CDATA[<p>Bis auf, daß man keine lokalen Funktionen deklarieren kann, ist die Funktion so richtig, d.h. die statische Variable wird nur einmalig initialisiert.<br />
Kannst es ja einfach mit einem Debugger testen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412479</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Thu, 29 Nov 2007 17:50:48 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 18:29:09 GMT]]></title><description><![CDATA[<p>The-Kenny schrieb:</p>
<blockquote>
<blockquote>
<p>void main()</p>
<p>[...] Aber in zahlreichen Büchern und Tutorials wird erklärt, dass void main() legales C++ sei, dass ist aber falsch! Es gab keinen C++-Standard, der je void main für legal erklärte. Die main-Funktion muss immer int zurückgeben!</p>
</blockquote>
</blockquote>
<p>C++ Standard 2003 §3.6.1 Absatz 2 schrieb:</p>
<blockquote>
<p>...It shall have a return type of type int, but otherwise its type is implementation-defined...</p>
</blockquote>
<p>ich seh nicht, dass da irgendwo steht, dass void main verboten ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412499</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 29 Nov 2007 18:29:09 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 18:22:43 GMT]]></title><description><![CDATA[<p>&quot;It shall have a return type of int&quot;. Wenn doch alle Aussagen im Standard so eindeutig wären...</p>
<p>&quot;but otherwise its type is implementation-defined&quot;: Es gibt ja noch andere Aspekte am Typ einer Funktion als nur den Rückgabetyp. Die Argumente zum Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412505</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 29 Nov 2007 18:22:43 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 18:23:14 GMT]]></title><description><![CDATA[<blockquote>
<p>but otherwise its type is implementation-defined...</p>
</blockquote>
<p>!?</p>
<p>es steht aber weiters, dass ein möglicher anderer rückgabewert implementation defined ist. also nicht, dass es verboten ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412507</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 29 Nov 2007 18:23:14 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 18:31:07 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Es gibt ja noch andere Aspekte am Typ einer Funktion als nur den Rückgabetyp. Die Argumente zum Beispiel.</p>
</blockquote>
<p>im selben abschnitt steht weiters:</p>
<p>C++ Standard 2003 §3.6.1 Absatz 2 schrieb:</p>
<blockquote>
<p>...All implementations shall allow both of the following definitions of main:</p>
<pre><code class="language-cpp">int main() { /* ... */ }
</code></pre>
<p>and</p>
<pre><code class="language-cpp">int main(int argc, char* argv[]) { /* ... */ }
</code></pre>
</blockquote>
<p>es steht hingegen nicht, dass eine andere definition nicht erlaubt wäre.</p>
<p>natürlich ist der code mit void main() dann nicht portabel, aber es ist nicht verboten.</p>
<p>die aussage, dass void main() kein gültiges C++ ist, ist nach meiner interpretation des standards somit falsch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412513</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 29 Nov 2007 18:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 18:32:17 GMT]]></title><description><![CDATA[<p>Da steht, dass der Rückgabetyp int zu sein hat, das ist doch eindeutig. Die nachfolgenden Sätze betreffen die Argumente.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412516</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 29 Nov 2007 18:32:17 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion nur 1* ausführen on Thu, 29 Nov 2007 18:33:14 GMT]]></title><description><![CDATA[<p>omg. sry. du hast recht. ich hab das falsch verstanden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>ich hoffe man verzeiht mir <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="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1412517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1412517</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 29 Nov 2007 18:33:14 GMT</pubDate></item></channel></rss>