<?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[Compiler optimisation und externe Funktionsaufrufe]]></title><description><![CDATA[<p>Gib es eine Möglichkeit dem Compiler mitzuteilen, dass eine externe Funktion keinerlei Auswirkungen hat und weg-optimiert werden kann wenn deren Rückgabewerte nicht verwendet werden?</p>
<p>Ich gehe davon aus dass es in Richtung Compiler spezifische Erweiterungen geht. In meinem Fall ist das GCC und MSVC.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332812/compiler-optimisation-und-externe-funktionsaufrufe</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 10:55:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332812.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 May 2015 14:12:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 14:12:33 GMT]]></title><description><![CDATA[<p>Gib es eine Möglichkeit dem Compiler mitzuteilen, dass eine externe Funktion keinerlei Auswirkungen hat und weg-optimiert werden kann wenn deren Rückgabewerte nicht verwendet werden?</p>
<p>Ich gehe davon aus dass es in Richtung Compiler spezifische Erweiterungen geht. In meinem Fall ist das GCC und MSVC.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454527</guid><dc:creator><![CDATA[Osbios]]></dc:creator><pubDate>Sat, 23 May 2015 14:12:33 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 14:16:14 GMT]]></title><description><![CDATA[<p>Suchste<a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes" rel="nofollow"> <code>const</code> </a>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454528</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 23 May 2015 14:16:14 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 14:50:35 GMT]]></title><description><![CDATA[<p>Stimmt, kann man ja auch auf externe c Funktionen anwenden. Das war einfacher als gedacht! <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/2454530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454530</guid><dc:creator><![CDATA[Osbios]]></dc:creator><pubDate>Sat, 23 May 2015 14:50:35 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 15:35:40 GMT]]></title><description><![CDATA[<p>Ja und optimiert er sie dann tatsächlich weg? Ich bin da eher skeptisch, vor allem bei externen C Funktionen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454531</guid><dc:creator><![CDATA[Mechanics]]></dc:creator><pubDate>Sat, 23 May 2015 15:35:40 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 15:46:56 GMT]]></title><description><![CDATA[<p>Ist vielleicht eine blöde Frage aber wieso ist das so wichtig? Der einzige Grund den ich mir vorstellen kann ist, dass man sich etwas Tipparbeit erspart. Aber wenn man auf jeden Fall verhindern will das eine Funktion unnötigerweise aufgerufen wird sollte man seinen Code einfach so schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454533</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Sat, 23 May 2015 15:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 16:13:37 GMT]]></title><description><![CDATA[<p>Mechanics schrieb:</p>
<blockquote>
<p>Ja und optimiert er sie dann tatsächlich weg? Ich bin da eher skeptisch, vor allem bei externen C Funktionen.</p>
</blockquote>
<p>Laut <a href="http://gcc.godbolt.org" rel="nofollow">gcc.godbolt.org</a> schon bei O1.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454539</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 23 May 2015 16:13:37 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 16:17:19 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Mechanics schrieb:</p>
<blockquote>
<p>Ja und optimiert er sie dann tatsächlich weg? Ich bin da eher skeptisch, vor allem bei externen C Funktionen.</p>
</blockquote>
<p>Laut <a href="http://gcc.godbolt.org" rel="nofollow">gcc.godbolt.org</a> schon bei O1*^[citation needed]^*.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2454541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454541</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 23 May 2015 16:17:19 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 18:34:34 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>Mechanics schrieb:</p>
<blockquote>
<p>Ja und optimiert er sie dann tatsächlich weg? Ich bin da eher skeptisch, vor allem bei externen C Funktionen.</p>
</blockquote>
<p>Laut <a href="http://gcc.godbolt.org" rel="nofollow">gcc.godbolt.org</a> schon bei O1*^[citation needed]^*.</p>
</blockquote>
</blockquote>
<pre><code>&lsqb;&lsqb;gnu::const&rsqb;&rsqb; int foo();
void bar()
{
	foo();
}
</code></pre>
<p>Gibt:</p>
<pre><code>bar():
  rep ret
</code></pre>
<p>Bei -std=c++11 -O1 und GCC 4.9.2 für x86.<br />
<a href="https://goo.gl/eOrspj" rel="nofollow">https://goo.gl/eOrspj</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454565</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 23 May 2015 18:34:34 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Sat, 23 May 2015 19:41:19 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454568</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 23 May 2015 19:41:19 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Tue, 26 May 2015 13:51:51 GMT]]></title><description><![CDATA[<p>sebi707 schrieb:</p>
<blockquote>
<p>Ist vielleicht eine blöde Frage aber wieso ist das so wichtig? Der einzige Grund den ich mir vorstellen kann ist, dass man sich etwas Tipparbeit erspart. Aber wenn man auf jeden Fall verhindern will das eine Funktion unnötigerweise aufgerufen wird sollte man seinen Code einfach so schreiben.</p>
</blockquote>
<p>Es macht durchaus Sinn.<br />
Z.B. in meinem Fall schreibe ich eine statisch zu linkende OpenGL Bibliothek welche unterschiedlich zum Einsatz kommt.<br />
Und wenn const Definitionen genug sind, dass der Compiler jedes mal alles unnötige weg optimieren kann, warum dann nicht?<br />
Es ist sehr viel einfacher und genauer als tonnenweise #ifdef im code zu haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454808</guid><dc:creator><![CDATA[Osbios]]></dc:creator><pubDate>Tue, 26 May 2015 13:51:51 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler optimisation und externe Funktionsaufrufe on Tue, 26 May 2015 16:55:48 GMT]]></title><description><![CDATA[<p>Klar ist das top.<br />
Der Compiler kann dann ja auch so sachen optimieren wie</p>
<pre><code class="language-cpp">int val = Foo(); // Foo = &quot;const&quot;
// ...
if (something&lt;T&gt;::that_is_probably_compile_time_constant)
    UseVal(val);
</code></pre>
<p>Hier kann der Aufruf von <code>Foo()</code> dann u.U. ganz wegoptimiert werden.</p>
<p>Hab nicht ausprobiert ob GCC solche Fälle auch versteht, aber es würde mich wundern wenn nicht. Wenn Foo() inline erweitert werden kann werden solche Fälle ja auch ohne Probleme erkannt und optimiert.</p>
<p>Und selbst wenn Foo() inline erweitert werden kann könnte man &quot;const&quot; noch verwenden. z.B. um Funktionen zu taggen die streng genommen beobachtbare Effekte haben, wo es aber wurst ist ob diese beobachtet werden oder nicht. z.B. Funktionen die Speicher anfordern (temporäre Strings/Container etc.). Oder Funktionen die irgendwelche Config-Werte aus ner DB lesen -- was ja auch reichlich sinnlos ist wenn man den Wert dann nichtmal braucht. In den meisten Fällen kann man solche Aufrufe dann auch komplett weglassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454817</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 26 May 2015 16:55:48 GMT</pubDate></item></channel></rss>