<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>vividos' blog</title>
	<atom:link href="http://vividos.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vividos.wordpress.com</link>
	<description>to blog. v. Writing what no one reads for people with nothing to do.</description>
	<lastBuildDate>Tue, 12 May 2009 19:19:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='vividos.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>vividos' blog</title>
		<link>http://vividos.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://vividos.wordpress.com/osd.xml" title="vividos&#039; blog" />
	<atom:link rel='hub' href='http://vividos.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Boost 1.35 kompilieren</title>
		<link>http://vividos.wordpress.com/2008/06/28/boost-135-kompilieren/</link>
		<comments>http://vividos.wordpress.com/2008/06/28/boost-135-kompilieren/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 09:11:00 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Boost]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft Visual Studio]]></category>
		<category><![CDATA[STLport]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/?p=25</guid>
		<description><![CDATA[Boost 1.35 ist seit einiger Zeit erschienen, und mit der neuen Version gab es Änderungen, wie man die Bibliotheken kompiliert. Die Getting Started-Anleitung beschreibt dies schon im Ansatz, verlinkt aber leider nicht auf eine etwas tiefergehende Dokumentation (sieht man mal von der für Laien unverständlichen Dokumentation zu Boost.Build ab). Im Nachfolgenden beschreibe ich, was es [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=25&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Boost 1.35 ist seit einiger Zeit erschienen, und mit der neuen Version gab es Änderungen, wie man die Bibliotheken kompiliert. Die <a href="http://www.boost.org/doc/libs/1_35_0/more/getting_started/windows.html">Getting Started</a>-Anleitung <a href="http://www.boost.org/doc/libs/1_35_0/more/getting_started/windows.html#or-build-binaries-from-source">beschreibt</a> dies schon im Ansatz, verlinkt aber leider nicht auf eine etwas tiefergehende Dokumentation (sieht man mal von der für Laien unverständlichen Dokumentation zu Boost.Build ab). Im Nachfolgenden beschreibe ich, was es für neue Schalter für bjam gibt, und wie man die verschiedenen Bibliotheken erstellen läßt.</p>
<p><span id="more-25"></span>Zuerst benötigt man bjam, das Build-Tool. Man kann es herunterladen, oder man erzeugt es sich eben mal aus dem Sourcecode. Im Verzeichnis tools\jam\src (vom Boost-Hauptverzeichnis aus) ruft man die Datei build.bat auf. Voraussetzung ist, man hat die Compiler-Umgebungsvariablen setzen lassen (z.B. über &#8220;vcvarsall.bat x86&#8243; o.ä.). Es wird die Datei bjam.exe im Unterverzeichnis &#8220;bin.ntx86&#8243; erstellt, die man getrost ins Boost-Hauptverzeichnis schieben kann.</p>
<h2>bjam-Kommandozeile</h2>
<p>Zurück in diesem Verzeichnis kann man bjam nun aufrufen. Folgendes Format sollte der Aufruf haben:</p>
<blockquote><p>bjam toolset=msvc &#8211;with-<em>{library-name} {weitere-optionen}</em> stage</p></blockquote>
<p>das Toolset kann für alle Visual C++-Versionen auf msvc belassen werden, das Build-System findet selbst die passende Version heraus. Die &#8211;with-<em>{library-name}</em> -Option kann öfters vorkommen. Folgende library-names sind gültig (die Liste kann sich auch jederzeit mit dem Aufruf &#8220;bjam &#8211;show-libraries&#8221; angezeigt werden):</p>
<ul>
<li>date_time</li>
<li>filesystem</li>
<li>function_types</li>
<li>graph</li>
<li>iostreams</li>
<li>mpi</li>
<li>program_options</li>
<li>python</li>
<li>regex</li>
<li>serialization</li>
<li>signals</li>
<li>system</li>
<li>test</li>
<li>thread</li>
<li>wave</li>
</ul>
<p>Die Angabe <em>stage</em> gibt an, daß die Dateien ins Verzeichnis &#8220;lib/stage&#8221; kopiert werden. Nach dem Kompilieren kann man das Verzeichnis &#8220;bin.v2&#8243; entfernen, es enthält die intermediate-Dateien für die einzelnen Libraries.</p>
<h2>Build-Optionen</h2>
<p>Für die <em>{weitere-optionen}</em> -Option können folgende Optionen angegeben werden:</p>
<ul>
<li>&#8211;build-type=(single|complete)<br />
Gibt an, wie viele der verschiedenen Targets kompiliert werden. single kompiliert nur die release-Versionen mit shared linking (also DLLs)</li>
<li>debug, release bzw variant=(debug|release)<br />
Bestimmt, welche Variante kompiliert wird. Wie im Visual Studio.</li>
<li>stdlib={standard-library}<br />
Gibt die Art der Standard-C++-Library an. Möglicher Wert, z.B.: stlport (siehe weiter unten)</li>
<li>link=(shared|static)<br />
Gibt an, ob eine DLL oder eine statische Library erzeugt wird. Standardmäßig will boost durch den autolink-Mechanismus die statischen .lib-Dateien dazulinken.</li>
<li>define=THIS_DEFINE=1<br />
Praktisch, um Defines an der Kommandozeile festzulegen, z.B. _SECURE_SCL=1</li>
<li>threading=(multi|single)<br />
Gibt an, ob die Bibliotheken multithreaded kompiliert werden. Bei single fallen u.U. mutexe und locking weg und entspricht dem Compiler-Schalter /ML</li>
<li>runtime-link=(shared|static)<br />
Gibt an, welche C und C++-Runtime-Bibliothek zu den erzeugten Bibliotheken dazugelinkt wird. shared linkt die msvcrXY.dll und msvcpXY.dll, static linkt je nach threading-Option die libc.lib/libcp.lib oder die libcmt.lib/libcpmt.lib dazu. XY steht für die interne Visual Studio-Version, fürs 2005er für 80, fürs 2008er für 90.</li>
<li>optimization=(off|speed|&#8230;?)<br />
Schaltet Optimierungen an bzw. aus.</li>
<li>architecture=(x86|ia64|sparc|power|mips(1|2|3|4|32|32r2|64)|&#8230;?)<br />
Prozessorarchitektur</li>
<li>address-model=(32|64)<br />
Gibt das Address-Modell an; die 64 wird benötigt, wenn man unter Visual Studio &gt;= 2005 für AMD64-Plattformen kompiliert.</li>
<li>cxxflags={&#8230;}<br />
Flags, die direkt dem C++-Compiler mit übergeben werden.</li>
<li>linkflags={&#8230;}<br />
Flags, die direkt dem Linker übergeben werden.</li>
<li>inlining=(on|off)<br />
Steuert das Inlining von Funktionen.</li>
<li>debug-symbols=(on|off)<br />
Steuert, ob pdb-Dateien erzeugt werden.</li>
<li>runtime-debugging=(on|off)<br />
Ehrlich gesagt, ich hab keine Ahnung.</li>
<li>profiling=(on|off)<br />
Schaltet das Generieren von profile-barem Code an oder aus.</li>
</ul>
<p>Es gibt natürlich noch mehr Optionen. Bei Bedarf werde ich das Blog-Post entsprechend erweitern. Eine <a href="http://www.boost.org/doc/tools/build/doc/html/bbv2/advanced/builtins/features.html">Liste von &#8220;eingebauten&#8221; Flags</a> gibts auch bei Boost.</p>
<h2>STLport</h2>
<p>Um Bibliotheken erstellt zu bekommen, die mit STLport zusammenarbeiten, reicht es nicht, stdlib=stlport zu übergeben; man muß einen Schritt weitergehen. Die Datei user-config.jam ist anzupassen und ist in tools/build/v2 zu finden. Folgende Zeile sollte man hinzufügen (bzw. man braucht sie nur einzukommentieren, sie ist schon da):</p>
<blockquote><p>using stlport : : {Pfad-zu-stlport-include-Folder} {Pfad-zu-stlport-lib-files} ;</p></blockquote>
<p>Die Zeile könnte in etwa so aussehen:</p>
<blockquote><p>using stlport : : D:\devel\STLport-5.1.4\stlport D:\devel\STLport-5.1.4\lib ;</p></blockquote>
<p>Verwendet man mehrere STLport-Versionen, so gehört die Versionsnummer zwischen die ersten beiden Doppelpunkte (z.B. &#8220;stlport : 5.1.4 : <em>pfad pfad</em>&#8220;). In der bjam-Kommandozeile ist dann stdlib=stlport-<em>{Version} </em>anzugeben (z.B. &#8220;stdlib=stlport-5.1.4&#8243;).</p>
<p>Die erstellten Bibliotheken enthalten im Dateinamens-Suffix zusätzlich den Buchstaben p, der die Abhängigkeit zu STLport signalisiert. Endungen sind dann z.B. &#8220;vc80-mt-gdp-1_35&#8243; oder &#8220;vc80-mt-p-1_35&#8243;.</p>
<p>Noch ein Hinweis für den Debug-Modus: Boost wird mit definiertem _STLP_DEBUG kompiliert, seine Debug-Targets sollte man also besser auch mit dem gesetzen define kompilieren.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=25&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2008/06/28/boost-135-kompilieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>Exceptions vs. Asserts</title>
		<link>http://vividos.wordpress.com/2008/03/14/exceptions-vs-asserts/</link>
		<comments>http://vividos.wordpress.com/2008/03/14/exceptions-vs-asserts/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 19:58:52 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Assert]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[catch]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[throw]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/?p=22</guid>
		<description><![CDATA[Dieser Artikel soll Exceptions und Asserts beleuchten, wozu man sie braucht, wann man sie einsetzt und welche Fehler mal vermeiden sollte. Exceptions Exceptions sind Ausnahmebedingungen im Programm. In vielen Sprachen gibt es Exceptions, in C++, C# und VB.NET (bzw. alle .NET-Sprachen), Javascript und sogar in PHP ab Version 5. In Visual C unter Win32 gibt [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=22&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Dieser Artikel soll Exceptions und Asserts beleuchten, wozu man sie braucht, wann man sie einsetzt und welche Fehler mal vermeiden sollte.<br />
<span id="more-22"></span><br />
<h2>Exceptions</h2>
<p>Exceptions sind Ausnahmebedingungen im Programm. In vielen Sprachen gibt es Exceptions, in C++, C# und VB.NET (bzw. alle .NET-Sprachen), <a href="http://www.w3schools.com/js/js_throw.asp">Javascript</a> und sogar in <a href="http://de.php.net/exceptions">PHP</a> ab Version 5. In Visual C unter Win32 gibt es SEH. Eine Exception wird mit einem throw-Schlüsselwort geworfen. Es kann für gewöhnlich ein Objekt jedes beliebigen Typs geworfen werden, wobei viele Sprachen Exception-Klassen und ganze -Hierarchien definieren.</p>
<p>Programmcode, der Exceptions auslösen kann, kann mit einem try-Block umschlossen werden. Aufgefangen wird eine Exception dann im nachfolgenden catch-Block, und man kann meist mehrere Blöcke für verschiedene Typen angeben. Verläßt der Programmfluß den catch-Teil, ohne wieder eine Exception auszulösen, gilt die ursprüngliche Ausnahme als gehandlet. Es kann die aufgefangene meist rethrow&#8217;t werden, wenn das benötigt wird. Manche Sprachen erlauben einen finally-Block, der nach der Exception-Behandlung oder dem try-Block ausgeführt wird. C++ braucht das nicht, und Bjarne Stroustrup <a href="http://www.research.att.com/~bs/bs_faq2.html#finally">erklärt</a>, warum.</p>
<p>Wird eine Exception vom Programm nicht gehandlet, wird das Programm beendet, und zwar ohne weitere Meldung. Stellte die Applikation ein Fenster da, scheint das Programm von einem auf den nächsten Moment verschwunden zu sein. Dies gilt es natürlich zu vermeiden. In C++ gibt es eine weitere Verhaltensweise, die ähnlich arbeitet. Wird eine Exception geworfen, während das &#8220;stack unwinding&#8221; passiert, also z.B. in einem Destruktor, beendet sich das Programm auch (siehe z.B. dieser <a href="http://www.kolpackov.net/projects/c++/eh/dtor-1.xhtml">Artikel</a> von Boris Kolpackov). Selbes passiert, wenn eine Funktion oder Methode eine Exception wirft, die sie nicht in ihrer &#8220;exception specification&#8221;-Liste erwähnt. Also nicht so ganz trivial in C++.</p>
<p>Nicht ganz einfach ist auch die Frage, wo und wann Exceptions geworfen werden sollen. Dies wird z.B. in einem Artikel von Ned Batchelder aufgegriffen:</p>
<p><a href="http://nedbatchelder.com/text/exceptions-in-the-rainforest.html">http://nedbatchelder.com/text/exceptions-in-the-rainforest.html </a></p>
<h2>Asserts</h2>
<p>Asserts ist bestimmt auch schon jeder begegnet. In C++ über den Header &lt;cassert&gt; bereitgestellt kann man die <a href="http://msdn2.microsoft.com/en-us/library/9sb57dw4.aspx">assert()</a>-Methode aufrufen. Sie zeigt z.B. unter Win32 eine MessageBox an, wenn der Ausdruck, die der Funktion mitgegeben wird, gleich 0 oder false ist. &#8220;to assert&#8221; heißt übersetzt &#8220;bestätigen&#8221; oder &#8220;sich versichern&#8221;, und genau dafür wird die Funktion benutzt. In der MFC gibts das Makro ASSERT (und VALIDATE), in ATL heißt es ATLASSERT (bzw. ATLVALIDATE), in der C-Runtime gibts zusätzlich <a href="http://msdn2.microsoft.com/en-us/library/ezb1wyez(VS.71).aspx">_ASSERT und _ASSERTE</a>, in .NET-Sprachen gibts <a href="http://msdn2.microsoft.com/en-us/library/system.diagnostics.debug.assert.aspx">System.Diagnostics.Debug.Assert</a>, und auch in PHP gibt es eine <a href="http://de.php.net/assert">entsprechende Funktion</a>.</p>
<p>Besonderheit der von Microsoft definierten assert-Makros wie ASSERT und ATLASSERT ist, daß sie über die defines _DEBUG und NDEBUG gesteuert werden. Ist NDEBUG definiert, z.B. beim Kompilieren für das Release-Target, ist ASSERT ein leeres Statement. Mögliche Fehlerquelle ist, wenn man ein Funktionsaufruf in ASSERT verwendet. Dafür hat Microsoft zusätzlich VERIFY erfunden. Die Makros sind im Release-Modus also no-op&#8217;s, im Debug-Modus zeigen sie die oft verwünschten Dialogboxen an. In .NET ist es ähnlich, dort wird allerdings im Konfigurationsfile für die Applikation angegeben, ob die <a href="http://msdn2.microsoft.com/en-us/library/system.diagnostics.debug.aspx">System.Diagnostics.Debug</a>-Klasse etwas ausgibt.</p>
<p>Wer Unit-Tests mit den verschiedenen verfügbaren Frameworks (wie <a href="http://cppunit.sourceforge.net/">CppUnit</a>, <a href="http://www.nunit.org/">NUnit</a>, <a href="http://www.phpunit.de/">PHPUnit</a>, etc.) schreibt, ist noch ein anderer Assert untergekommen. Mit CPPUNIT_ASSERT(), <a href="http://www.nunit.org/index.php?p=classicModel&amp;r=2.4.6">NUnit.Assert</a>, etc. wird z.B. in einer Testfunktion ein erwarteter Zustand abgefragt. Da man Unit-Tests auch mit einer Release-Version laufen lassen will, um sicherzustellen, daß es auch dort keine Überraschungen gibt, müssen diese Asserts natürlich immer ausgeführt werden. Sie heißen zwar auch so, sind aber für was anderes gedacht.</p>
<h2>Exceptions vs. Asserts</h2>
<p>Wann aber verwendet man was? Manche schwören auf Exceptions, andere benutzen (noch) Rückgabewerte zur Fehlerbehandlung. Sie sagen, Exceptions sind unkontrollierbar und setzen sich durchs ganze Programm fort, wenn man nicht aufpaßt. Genauso die Assert-Skeptiker, die bei der Erwähnung der selben schon überall MessageBoxen aufgehen sehen. Beide haben aber Vorteile und sollten so eingesetzt werden, wie die beiden Features angedacht sind. Und das geht sogar gleichzeitig.</p>
<p>Wenn man sich sonst nichts von diesem Post merken braucht, sind es die zwei Kriterien für den Einsatz von Exceptions und Asserts:</p>
<ul>
<li>Exceptions werden verwendet, wenn ein vorhersehbarer Fehler eintritt und gehandled werden soll</li>
<li>Asserts sind zu verwenden, um unvorhersagbare Fehler während der Entwicklung festgestellt werden sollen</li>
</ul>
<p>Exceptions können z.B. auftreten, wenn eine Datei, die ich an einer bestimmten Stelle erwarte, nicht vorhanden ist. Oder wenn ein Soap-Aufruf ein Datenfeld zurückliefert, das Daten in einem anderen Format beinhaltet, als das Programm es erwartet (Soap-Aufrufe können ja von jedermann generiert werden). Exceptions decken also Fehler auf, mit denen gerechnet werden muß.</p>
<p>Exceptions sind im ausgelieferten Programm immer noch vorhanden, müssen also gehandled werden. Irgendwann muß eine lesbare Meldung formatiert und dem Benutzer präsentiert werden. Möglicherweise kann er das Problem beheben (Datei an die passende Stelle kopieren), möglicherweise kann er aber auch nicht viel machen und muß das Programm beenden.</p>
<p>Vorteil von Exceptions ist, daß man sie nicht ignorieren kann. Solche vorhersehbaren Fehler dürfen auch nicht ignoriert werden. Die Ausnahme wird sonst an übergeordnete Programmteile weitergegeben. Das &#8220;Vergessen&#8221; des Prüfens eines Return-Wertes gibt es damit nicht mehr. Nachteil ist, daß Exception-Handling Disziplin vom Programmierer erfordert. Es muß jede Exception aufgefangen und in irgend einer Weise behandelt werden. Es muß schon vor dem Schreiben von Programmcode klar sein, in welcher Schicht Exceptions gehandled werden, und wo sie nur durchgelassen werden. Es muß festgelegt sein, welche Exception-Klassen verwendet werden. Daraus resultiert im Ende dann eine stabilere Software.</p>
<p>Asserts sollten verwendet werden, wenn ein bestimmter Zustand abgeprüft werden soll, der einen Bug aufzeigt. Beispiele sind z.B., wenn der Aufrufer einer Funktion einen NULL-Zeiger übergibt, dieser aber nicht erlaubt ist. Ein weiteres Beispiel ist, wenn eine Klasse eine Initialisierungsreihenfolge erwartet, diese aber vom Benutzer der Klasse nicht korrekt ausgeführt wurde. Ein Assert deckt also Bugs im Programm auf. Gern wird ein Assert benutzt, um Eingangsparameter einer Funktion zu prüfen. Ein möglicher Aufrufer erfährt beim Testen dann schon, ob er die Funktion richtig verwendet (nämlich wenn kein Assert auftritt).</p>
<p>Asserts sind im fertigen Programm nicht mehr vorhanden (da durch Makro zum no-op gemacht oder per Konfiguration ausgeschaltet), können also bei Kundensoftware nicht mehr auftreten. An der Stelle, an der ein Assert auftreten würde, würde das Programm dann einfach von falschen Annahmen ausgehen und abstürzen. Ein klarer Bug, der vom Entwickler gefixt werden müßte. Dies verhindet Bananensoftware (reift beim Kunden) und erzwingt, eine gute Qualitätssicherung und Tests der Software durchzuführen. Auch der Entwickler tut gut daran, mit Unit Tests sicherzustellen, daß seine Klassen auch genau das machen, was sie sollen, und möglichst ohne Asserts (und Bugs).</p>
<p>Vorteil von Asserts sind, daß sie einem sofort zeigen, wo ein Bug ist, und (hat man den Quellcode) sie dokumentieren, welche Erwartungen an den aufrufenden Code gemacht werden. Außerdem verbrauchen sie keinen Speicherplatz und Laufzeit in ausgelieferten Versionen der Software. Nachteil an Asserts ist, daß es schwer ist zu entscheiden, wann ein Assert angebracht ist, oder ob eher eine Exception geworfen werden soll. Das muß man sich am Anfang der Entwicklung überlegen und evtl. in Software-Richtlinien für beteiligte Entwickler festlegen.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=22&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2008/03/14/exceptions-vs-asserts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>Symbol Server im Visual Studio nutzen</title>
		<link>http://vividos.wordpress.com/2008/03/14/symbol-server-im-visual-studio-nutzen/</link>
		<comments>http://vividos.wordpress.com/2008/03/14/symbol-server-im-visual-studio-nutzen/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 17:18:38 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Symbol Server]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/?p=21</guid>
		<description><![CDATA[Beim Debuggen von Applikationen hat man oft das Problem, daß ein Fehler innerhalb der Win32-DLLs auftritt, z.B. kernel32.dll, gdi32.dll oder in anderen DLLs von Microsoft. Man weiß zwar, daß man z.B. die API nicht richtig verwendet oder eine falsche Vorgehensweise bei den Aufrufen anwendet, nur ist es schwierig, nur anhand eines Callstacks mit System-Funktionen herauszubekommen, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=21&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Beim Debuggen von Applikationen hat man oft das Problem, daß ein Fehler innerhalb der Win32-DLLs auftritt, z.B. kernel32.dll, gdi32.dll oder in anderen DLLs von Microsoft. Man weiß zwar, daß man z.B. die API nicht richtig verwendet oder eine falsche Vorgehensweise bei den Aufrufen anwendet, nur ist es schwierig, nur anhand eines Callstacks mit System-Funktionen herauszubekommen, wo eigentlich die Applikation hängt oder crashed. Oder man stoppt das debuggte Programm, aber alle Threads sind in Systemfunktionen. Der Symbol Server hilft hier, Licht ins Dunkel zu bringen.</p>
<p><span id="more-21"></span>Der Symbol Server von Microsoft liefert während des Debuggens die Symbol-Informationen von Microsoft-DLLs, z.B. kernel32.dll oder user32.dll. Manchmal kann dies ganz nützlich sein, da man einen Fehler dann besser eingrenzen kann.<br />
Wie man den Symbol Server benutzt, wird in <a href="http://support.microsoft.com/kb/311503" title="Knowledge Base Artikel 311503" target="_blank">KB 311503</a> erklärt. Voraussetzung ist, daß man die Debugging Tools for Windows installiert hat. Der Konfigurationsstring ist dabei folgendermaßen aufgebaut:</p>
<blockquote><p>SRV*<i>Pfadangabe</i>*http://msdl.microsoft.com/download/symbols</p></blockquote>
<p>Die Angabe für <i>Pfadangabe</i> bezeichnet dabei einen Pfad auf der Festplatte, in dem die Symbol-Dateien abgelegt werden. Der String kann folgendermaßen benutzt werden:</p>
<ul>
<li>In die System-Umgebungsvariable _NT_SYMBOL_PATH schreiben. Dadurch wird in jedem Prozess, der per Visual Studio oder WinDbg debuggt wird, mit den Symbolen aus dem Symbol-Cache gearbeitet</li>
<li>Im Visual Studio eintragen. Dazu gibts für Visual Studio 2003 die Möglichkeit, pro Projekt in den Einstellungen unter “Debug” das Feld “Symbol Info” auszufüllen. In Visual Studio 2005 Express gibts sogar die Möglichkeit unter “Tools -&gt; Options -&gt; Debugging -&gt; Symbols -&gt; ” für alle Projekte den Symbol-Server einzustellen.</li>
<li>Benutzt man die dbghelp.dll aus den Debugging Tools, um Symbole aufzulösen, kann man in der Funktion <a href="http://msdn2.microsoft.com/en-us/library/ms681368.aspx" title="msdn-Artikel zu SymSetSearchPath">SymSetSearchPath</a> den Symbol-Cache angeben.</li>
</ul>
<p>Startet man den Debugger, so werden die Symbole geladen. Hat eine DLL noch keine Symbole, z.B. durch eine vorhandene PDB-Datei, wird der Symbol Server konsultiert, und falls vorhanden eine entsprechende .pdb (oder .dbg, im Fall von WinDbg) im Symbol-Cache gespeichert. Da man am Anfang einen leeren Cache hat, dauert es beim ersten Start oder wenn die Symbole einer neuen Datei noch nicht nachgeladen ist, etwas länger.</p>
<p>Läßt man den hinteren Teil nach dem zweiten * weg, wird nur der lokale Symbol-Cache benutzt, das Visual Studio versucht auch nicht, weitere Symbole nachzuladen. Dadurch wird das Starten eines zu debuggenden Programms wieder schneller.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=21&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2008/03/14/symbol-server-im-visual-studio-nutzen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>WTL Window Resizing</title>
		<link>http://vividos.wordpress.com/2008/03/13/wtl-window-resizing/</link>
		<comments>http://vividos.wordpress.com/2008/03/13/wtl-window-resizing/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 20:02:17 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[CWindow]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Resizing]]></category>
		<category><![CDATA[WTL]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/?p=20</guid>
		<description><![CDATA[CWindow-basierte Klassen der WTL können relativ einfach resizable gemacht werden. So wirds gemacht: 1. Die benötigten Klassen sind in &#60;atlframe.h&#62;, also diese Header irgendwo includen. 2. Zusätzlich das gewünschte Fenster von CDialogResize ableiten: class CMyDialog: public CDialogImpl&#60;CMyDialog&#62;, public CDialogResize&#60;CMyDialog&#62; { 3. Die Resize-Map der Klasse hinzufügen: BEGIN_DLGRESIZE_MAP(CMyDialog) [...] END_DLGRESIZE_MAP() 4. Die Resize-Map ist dann auf [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=20&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>CWindow-basierte Klassen der <a href="http://wtl.sourceforge.net/">WTL</a> können relativ einfach resizable gemacht werden. So wirds gemacht:</p>
<p><span id="more-20"></span>1. Die benötigten Klassen sind in &lt;atlframe.h&gt;, also diese Header irgendwo includen.</p>
<p>2. Zusätzlich das gewünschte Fenster von CDialogResize ableiten:</p>
<pre>  class CMyDialog: public CDialogImpl&lt;CMyDialog&gt;,
     public CDialogResize&lt;CMyDialog&gt;
  {</pre>
<p>3. Die Resize-Map der Klasse hinzufügen:</p>
<pre>  BEGIN_DLGRESIZE_MAP(CMyDialog)
      [...]
  END_DLGRESIZE_MAP()</pre>
<p>4. Die Resize-Map ist dann auf folgende Weise für alle Controls, die resized oder bewegt werden, zu füllen:</p>
<pre>  BEGIN_DLGRESIZE_MAP(CMyDialog)
     DLGRESIZE_CONTROL(IDC_EDIT_NAME, <i>{flags}</i>)
     DLGRESIZE_CONTROL(IDC_BUTTON_START, <i>{flags}</i>)
     BEGIN_DLGRESIZE_GROUP()
        DLGRESIZE_CONTROL(IDC_COMBO_ITEMS, <i>{flags}</i>)
        [...]
     END_DLGRESIZE_GROUP()
  END_DLGRESIZE_MAP()</pre>
<p>Es können Untergruppen spezifiziert werden, die die beinhalteten Controls zusammenfassen.</p>
<p>5. Folgende flags sind erlaubt, die auch per oder-Verknüpfung kombiniert werden können:</p>
<ul>
<li> DLSZ_SIZE_X Das Control wird in X-Richtung vergrößert oder verkleinert.</li>
<li> DLSZ_SIZE_Y Das Control wird in Y-Richtung vergrößert oder verkleinert.</li>
<li> DLSZ_MOVE_X Das Control wird in X-Richtung bewegt.</li>
<li> DLSZ_MOVE_Y Das Control wird in Y-Richtung bewegt.</li>
<li> DLSZ_REPAINT Bei Änderungen wird das Control neu gezeichnet, in dem Invalidate() aufgerufen wird.</li>
</ul>
<p>6. In OnInitDialog() muß folgende Funktion aufgerufen werden:</p>
<pre>  DlgResize_Init(bool bAddGripper = true, bool bUseMinTrackSize = true, DWORD dwForceStyle = WS_CLIPCHILDREN);</pre>
<p>Die Parameter haben folgende Bedeutung:</p>
<ul>
<li> bAddGripper: wenn true, wird ein Gripper-Symbol an der rechte untere Ecke gezeichnet</li>
<li> bUseMinTrackSize: stellt beim ersten Resize-Aufruf fest, welche die kleinste Größe des Dialogs bzw. Fensters ist</li>
<li> dwForceStyle: setzt den angegebenen Style für das Fenster. Hinweis: WS_CLIPCHILDREN funktioniert mit Gruppierungs-Rahmen nicht</li>
</ul>
<p>7. In die Message-Map der Klasse muß folgende Zeile am Ende eingefügt werden, damit die Resize-Klasse mit den nötigen Windows-Messages versorgt werden:</p>
<pre>  CHAIN_MSG_MAP(CDialogResize&lt;CMyDialog&gt;)</pre>
<p>8. Der Dialog oder das Fenster muß den Style WS_THICKFRAME erhalten, sodaß der Benutzer dann auch die Größe des Fensters verändern kann. Im Visual Studio stellt man im Resource-Editor dazu das Property &#8220;Border&#8221; auf &#8220;Resizing&#8221;. Bei Bedarf kann man auch noch &#8220;Minimize Box&#8221; und &#8220;Maximize Box&#8221; einschalten, um die entsprechenden Buttons in der Titelleiste zu bekommen.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=20&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2008/03/13/wtl-window-resizing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>How to compile cairo for PocketPC</title>
		<link>http://vividos.wordpress.com/2008/01/23/how-to-compile-cairo-for-pocketpc/</link>
		<comments>http://vividos.wordpress.com/2008/01/23/how-to-compile-cairo-for-pocketpc/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 22:51:25 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[cairo]]></category>
		<category><![CDATA[PocketPC]]></category>
		<category><![CDATA[Uniscribe]]></category>
		<category><![CDATA[Windows CE]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/2008/01/23/how-to-compile-cairo-for-pocketpc/</guid>
		<description><![CDATA[This article will shed some light on how to compile cairo (the graphics library) for use under PocketPC. I will use Visual Studio 2008 to set up the project for Win32, then create a PocketPC configuration, trying to compile it for this platform. Finally I will discuss which Win32 APIs and thus cairo features are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=18&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article will shed some light on how to compile <a href="http://www.cairographics.org/">cairo</a> (the graphics library) for use under PocketPC. I will use Visual Studio 2008 to set up the project for Win32, then create a PocketPC configuration, trying to compile it for this platform. Finally I will discuss which Win32 APIs and thus cairo features are not going to work.</p>
<p><span id="more-18"></span>I already tried to compile cairo once, using the age-old evc4. See cairo mail archives, <a href="http://lists.cairographics.org/archives/cairo/2006-May/007026.html">post 1</a>, <a href="http://lists.cairographics.org/archives/cairo/2006-June/007045.html">post 2</a> and <a href="http://lists.freedesktop.org/archives/cairo/attachments/20060601/d746f672/cairo-wince-port.obj">patch</a>. Since then, much has happened with the cairo project. The main deficiencies with Windows CE unfortunately stayed, though.</p>
<h2>Setting up a Visual Studio project</h2>
<p>I chose to first set up a project in Visual Studio 2008 (beta 2, still) and compiling cairo for Win32, so that I knew afterwards that I chose the proper files and settings to compile. First, unzip cairo (I used cairo-1.4.14) to a folder of your choice.</p>
<p>1. I created a &#8220;win32&#8243; folder besides the other folders like &#8220;src&#8221; and &#8220;pixman&#8221; to put all win32-related project files in.</p>
<p>2. In this folder I created a Win32 DLL project with no files and added all *.h and all *.cpp files in the &#8220;src&#8221; folder that I could find.</p>
<p>3. I created two files in win32, a cairo-features.h and an empty cairo-deprecated.h. Here&#8217;s the contents of the cairo-features.h file:</p>
<blockquote>
<pre>#ifndef CAIRO_FEATURES_H
#define CAIRO_FEATURES_H

#ifdef  __cplusplus
# define CAIRO_BEGIN_DECLS  extern "C" {
# define CAIRO_END_DECLS    }
#else
# define CAIRO_BEGIN_DECLS
# define CAIRO_END_DECLS
#endif

#ifndef cairo_public
# define cairo_public
#endif

#define CAIRO_VERSION_MAJOR 1
#define CAIRO_VERSION_MINOR 4
#define CAIRO_VERSION_MICRO 14

#define CAIRO_VERSION_STRING "1.4.14"

#define CAIRO_HAS_WIN32_SURFACE 1
#define CAIRO_HAS_WIN32_FONT 1

// stuff that normally belongs to a generated config.h:

#define HAVE_WINDOWS_H 1
#define PACKAGE_VERSION "cairo-" CAIRO_VERSION_STRING
#define PACKAGE_BUGREPORT "http://bugs.freedesktop.org/enter_bug.cgi?product=cairo"

#endif
</pre>
</blockquote>
<p>There are more features that can be enabled with CAIRO_HAS_XXX, but as I&#8217;m only interested in rendering to a window, these should be enough.</p>
<p>4. I disabled the following files (General -&gt; Excluded from Build: Yes); you can also remove them from the project altogether: cairo-atsui-font.c, cairo-beos-surface.cpp, cairo-directfb-surface.c, cairo-ft-font.c, cairo-glitz-surface.c, cairo-os2-surface.c cairo-pdf-surface.c, cairo-png.c, cairo-ps-surface.c, cairo-quartz-surface.cpp, cairo-svg-surface.cpp, cairo-type1-subset.c, cairo-xcb-surface.c, cairo-xlib-display.c, cairo-xlib-screen.c, cairo-xlib-surface.c</p>
<p>5.  Cairo needs <a href="http://www.zlib.net/">zlib</a>, so you have to include the folder containing &#8220;zlib.h&#8221; and &#8220;zconf.h&#8221;. Later you have to link against a precompiled version of zlib (I used the Visual Studio projects in the contrib folder of zlib to generate a static linkable .lib file)</p>
<p>6. Before hitting compile, I set some include paths, namely: &#8220;.;..\src;..\pixman\src&#8221;. Remember that include paths are specified relative to the .vcproj file. I also set some more defines: _CRT_NONSTDC_NO_WARNINGS, to prevent warnings on strdup() usage, and _CRT_SECURE_NO_WARNINGS for silencing warnings on crt functions not considered safe by Microsoft. For proper linking to zlib, I also had to define ZLIB_WINAPI, but that depends on how zlib was compiled. In the linker settings I added in &#8220;Input -&gt; Ignore Specific Library&#8221; the value &#8220;msvcrt&#8221; for debug builds, or else the cairo.dll is then linked to msvcr90.dll and msvcr90d.dll. Note that official cairo DLLs are named libcairo-2.dll, so the output file could be changed to this name if necessary.</p>
<p>7. Cairo needs pixman, a library that is provided in the &#8220;pixman&#8221; subfolder. I created another static lib project and added dependencies for the cairo DLL project. This way cairo.dll automatically links in pixman.lib. It&#8217;s magic! The pixman project doesn&#8217;t need special settings and is pretty much self-contained.</p>
<p>8. Compiling and linking gives a cairo.dll, but checking with <a href="http://www.dependencywalker.com/">Dependency Walker</a> reveals that it doesn&#8217;t export any functions. A cairo.def file is generated by the automake makefiles, but lacking the autotools I just downloaded a developer package from <a href="http://www.gimp.org/%7Etml/gimp/win32/downloads.html">Tor Lillqvist&#8217;s GTK+ for Windows</a> page (e.g. cairo-dev-1.4.10.zip, the version number doesn&#8217;t have to match exactly, since the exported functions are probably the same), got the cairo.def from the &#8220;lib&#8221; folder inside the .zip and placed it in our &#8220;win32&#8243; folder. An entry in the project settings under &#8220;Linker -&gt; Input -&gt; Module Definition File&#8221; completes this task. Note that some functions cannot be found while linking, e.g. for svg or png output; I commented out the entries in the .def file with the ; comment character.</p>
<h2>Going PocketPC</h2>
<p>9. Now we should have a cairo DLL that properly exports its functions. Let&#8217;s create the DLL for the PocketPC platform now. Go into the &#8220;Build -&gt; Configuration Manager&#8221; dialog and  add a new solution platform. I chose &#8220;Windows Mobile 5.0 Pocket PC SDK (ARMV4I)&#8221;. On the next dialog choose &#8220;&lt;Empty&gt;&#8221; for the &#8220;Copy settings from:&#8221; combobox, or else you will get wrong compiler and linker settings for your ARM platform. Note that you have to set up compiler and linker settings and build-ignored files again for this platform, but this should be easy.</p>
<p>10. While compiling there are some errors we have to fix for the PocketPC platform. The first is in pixmanint.h, where MAXSHORT and MINSHORT is redefined, since the macros already exist in ARM compiler&#8217;s winnt.h include file. I replaced the defines with the following:</p>
<blockquote>
<pre>#ifndef _WIN32_WCE
#define MAXSHORT SHRT_MAX
#define MINSHORT SHRT_MIN
#endif</pre>
</blockquote>
<p>The second fix is in cairo-mutex-type-private.h, where mutex stuff is defined. On Win32 the CRITICAL_SECTION type is used for locking, but the structure looks different and has one less member in Windows CE. I replaced the define for CAIRO_MUTEX_NIL_INITIALIZER with this code:</p>
<blockquote>
<pre># ifndef _WIN32_WCE
# define CAIRO_MUTEX_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 }
# else
# define CAIRO_MUTEX_NIL_INITIALIZER { 0, NULL, NULL, 0, 0 }
# endif</pre>
</blockquote>
<h2>Fixing platform deficiencies</h2>
<p>11. Compiling should now work for all files except cairo-win32-surface.c and cairo-win32-font.c. The first one should be easier to fix, the second one does more headaches.</p>
<p>The first error in cairo-win32-surface.c is easily fixed, though. In the function _cairo_win32_print_gdi_error the Win32 function FormatMessageA is called. When compiling with unicode settings (in the General settings, choose &#8220;Use Unicode Character Set&#8221; as &#8220;Character Set&#8221;; it&#8217;s the default setting for new projects in Visual Studio 2005 and 2008) the TCHAR type resolves to WCHAR and LPTSTR resolves to LPWSTR, but FormatMessageA wants LPSTR. The concerning line is changed so that the call looks like:</p>
<blockquote>
<pre>    if (!FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
             FORMAT_MESSAGE_FROM_SYSTEM,
             NULL,
             last_error,
             MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
             <font color="#ff0000">(LPSTR)</font> &amp;lpMsgBuf,
             0, NULL)) {</pre>
</blockquote>
<p>12. The next error one on the list is a warning about an undefined GdiFlush() function. It&#8217;s not available under CE, so I ignore it for now. Later at linking stage the function must be there in some form, and be it some empty dummy function.</p>
<p>13. In the function _composite_alpha_blend there is another warning about converting from char [8] to LPCWSTR. It&#8217;s the same unicode issue as above, so either &#8220;LoadLibraryA(&#8220;msimg32&#8243;);&#8221; or LoadLibraryW(L&#8221;msimg32&#8243;);&#8221; should be used. The GetProcAddress() warning some lines down is a bit tricky. Under Win32 there is only one GetProcAddress() function that always takes an LPCSTR, in the WinCE API there are two versions, GetProcAddressA takes an LPCSTR and GetProcAddressW takes an LPCWSTR. The code again has to be changed to use GetProcAddressA to get it to work on all platforms.</p>
<p>14. Next on the list is usage of HALFTONE in a call to SetStretchBltMode. According to the <a href="http://msdn2.microsoft.com/en-us/library/aa453655.aspx">documentation</a>, the function only supports the flags BLACKONWHITE , COLORONCOLOR and BILINEAR on Windows CE. The <a href="http://blogs.msdn.com/mikehall/default.aspx">Windows Embedded blog</a> <a href="http://blogs.msdn.com/mikehall/archive/2004/06/01/145769.aspx">states the same</a>. A fix is to either define HALFTONE (value on Win32 would be 4) and hope the function is never called or the functionality isn&#8217;t needed, use another value for HALFTONE (e.g. COLORONCOLOR) or just #ifdef out the call to SetStretchBltMode() altogether.</p>
<p>15. The next error is harder; The function <a href="http://msdn2.microsoft.com/en-us/library/ms901129.aspx">ExtTextOutW</a> is called to produce text output. It uses the flags ETO_GLYPH_INDEX and ETO_PDY, which both are not supported on Windows CE (see Win32 <a href="http://msdn2.microsoft.com/en-us/library/ms533949.aspx">documentation </a>counterpart). The flag ETO_GLYPH_INDEX means that the passed lpString pointer contains 16-bit words that represent glyph indices of a certain font. The <a href="http://msdn2.microsoft.com/en-us/library/ms534004(VS.85).aspx">GetCharacterPlacement</a> function (which is not available in WinCE) is used to produce this array. The ETO_PDY flag specifies that the array passed in lpDx actually consists of pairs of x and y displacement values for each glyph. This is used in cairo for drawing rotated or transformed text (I guess so from the sources).</p>
<p>A possible solution for this problem to work around would be to simulate drawing the glyphs on calculated positions using ExtTextOut, character per character, assuming that the glyph index is the same as the unicode character value (which may not always be the case for some languages and composite characters). Another alternative would be to use Uniscribe, but that is available starting with WM5 and isn&#8217;t packaged with every device (see <a href="http://blogs.msdn.com/michkap/archive/2005/05/19/420145.aspx">here</a>; note that OEMs build their ROMs using Platform Builder and choose what to include); more interesting reads: about <a href="http://blogs.msdn.com/michkap/archive/2005/09/23/472656.aspx">GetCharacterPlacement</a>, and about <a href="http://www.mail-archive.com/unicode@unicode.org/msg20122.html">Uniscribe </a>on WinCE.</p>
<p>Since there is no easy solution for this, I just commented out the function body, so text rendering isn&#8217;t supported by cairo on Windows CE for now. Revisiting my changes to cairo, I saw that I tried to reimplement GetCharacterPlacement and some more needed functions, but that code has to be looked upon again. In the end I didn&#8217;t manage to bring rendered text onto a cairo surface.</p>
<h2>Epilog</h2>
<p>For now I&#8217;m closing this article. The next one on that topic describes the remaining missing functions that prevent to compile cairo for Windows CE. Workarounds are discussed, too, so in the end it should be possible to at least get <i>something </i>on the screen.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=18&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2008/01/23/how-to-compile-cairo-for-pocketpc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>In-depth analysis of the ARM &#8220;by-value&#8221; compiler bug</title>
		<link>http://vividos.wordpress.com/2007/12/09/in-depth-analysis-of-the-arm-by-value-compiler-bug/</link>
		<comments>http://vividos.wordpress.com/2007/12/09/in-depth-analysis-of-the-arm-by-value-compiler-bug/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 18:56:48 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[eMbedded Visual C++]]></category>
		<category><![CDATA[PocketPC]]></category>
		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/2007/12/09/in-depth-analysis-of-the-arm-by-value-compiler-bug/</guid>
		<description><![CDATA[Last time I described how the ARM by-value compiler bug happens. This time I will go in-depth to show what happens at the ARM disassembly level. But first, we need a test program to show the bug. You can create empty projects using eMbedded Visual C++ 3 or 4, Visual Studio 2005 and 2008 to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=14&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last time I <a href="http://vividos.vox.com/library/post/the-infamous-arm-by-value-compiler-bug.html">described</a> how the ARM by-value compiler bug happens. This time I will go in-depth to show what happens at the ARM disassembly level. But first, we need a test program to show the bug. <span id="more-14"></span>You can create empty projects using eMbedded Visual C++ 3 or 4, Visual Studio 2005 and 2008 to follow the example code. Note that the class in this example could be called any name, but I used the name Iterator, since the bug manifested the first time in STLport using checked iterators in _STLP_DEBUG mode.</p>
<blockquote>
<pre>#pragma warning(disable: 4355) // 'this' : used in base member initializer list class Iterator
{
public:
   Iterator()
      :m_this(this)
   {
      OutputDebugString(_T("ctor\n"));
   }

   Iterator(const Iterator&amp;)
      :m_this(this)
   {
      OutputDebugString(_T("copy ctor\n"));
   }

   ~Iterator()
   {
      OutputDebugString(_T("dtor\n"));
      if (m_this != this)
         OutputDebugString(_T("wrong m_this!\n"));
   }

   Iterator&amp; operator=(const Iterator&amp;)
   {
      OutputDebugString(_T("assign operator\n"));
      return *this;
   }
private:
   Iterator* m_this;
};

void ByVal(Iterator i)
{
}

void ByRef(Iterator&amp; i)
{
}

void Test()
{
   Iterator i;
   ByVal(i);
   ByRef(i);
}</pre>
</blockquote>
<p>Just running this code in the debugger should yield the following output:</p>
<blockquote>
<pre>ctor
copy-ctor
dtor
wrong m_this! (*)
dtor</pre>
</blockquote>
<p>(*) Note that this line is only printed when the bug is present, that means all compiler versions before the one in Visual Studio 2008.</p>
<p>Let&#8217;s analyze the test code in detail.</p>
<blockquote>
<pre>#pragma warning(disable: 4355) // 'this' : used in base member initializer list
 class Iterator
 {
 public:
    Iterator()
       :m_this(this)
    {
       OutputDebugString(_T("ctor\n"));
    }</pre>
</blockquote>
<p>The pragma is needed to prevent a warning about using this in the ctor. It is allowed to store the this pointer, so we can ignore the warning safely (Since the object isn&#8217;t fully constructed, the this pointer shouldn&#8217;t used for something else). The remainder of the ctor prints out a debug message.</p>
<blockquote>
<pre>   Iterator(const Iterator&amp;)
       :m_this(this)
    {
       OutputDebugString(_T("copy ctor\n"));
    }</pre>
</blockquote>
<p>The copy ctor does the same as the ctor, it stores the this pointer in the m_this member and prints out a diagnostic.</p>
<blockquote>
<pre>   ~Iterator()
    {
       OutputDebugString(_T("dtor\n"));
       if (m_this != this)
          OutputDebugString(_T("wrong m_this!\n"));
    }</pre>
</blockquote>
<p>The destructor checks the m_this pointer if it&#8217;s the same as the address of the object we&#8217;re currently destroying. If it&#8217;s not, a diagnostic message is output. Since we have two ctors that set the m_this member to this and no other way to set m_this, this should always succeed. Or so we thought.</p>
<blockquote>
<pre>   Iterator&amp; operator=(const Iterator&amp;)
    {
       OutputDebugString(_T("assign operator\n"));
       return *this;
    }
private:
   Iterator* m_this;
};</pre>
</blockquote>
<p>As we are good C++ developers, we write an assignment operator along with the copy-ctor, even it isn&#8217;t called anywhere. The remaining class lists the m_this member variable. Now on to the test code&#8230;</p>
<blockquote>
<pre>void ByVal(Iterator i)
{
}

void ByRef(Iterator&amp; i)
{
}

void Test()
{
   Iterator i;
   ByVal(i);
   ByRef(i);
}</pre>
</blockquote>
<p>The first two functions take an object of our test class, either by value or by reference. At the end of the first function the local variable i should be destroyed. The last function calls the two first ones using a local Iterator variable.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=14&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2007/12/09/in-depth-analysis-of-the-arm-by-value-compiler-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>Win32 entry points</title>
		<link>http://vividos.wordpress.com/2007/12/07/win32-entry-points/</link>
		<comments>http://vividos.wordpress.com/2007/12/07/win32-entry-points/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 18:55:47 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[PocketPC]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/2007/12/07/win32-entry-points/</guid>
		<description><![CDATA[One thing that I constantly forget is the names of the various entry points one can use when compiling with Visual C++&#8217;s CRT. Here&#8217;s a blog post to remember it once and for all. When creating a console application (see linker settings under &#8220;System&#8221;, the &#8220;SubSystem&#8221; option), the main function is called main or wmain, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=13&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="asset-content">
<div class="asset-body preview-links">One thing that I constantly forget is the names of the various entry points one can use when compiling with Visual C++&#8217;s CRT. Here&#8217;s a blog post to remember it once and for all.</p>
<p>When creating a console application (see linker settings under &#8220;System&#8221;, the &#8220;SubSystem&#8221; option), the main function is called main or wmain, depending on your unicode settings. I always use _tmain provided by the tchar.h header. The entry points that can specified at the linker&#8217;s /entry option is either <b>mainACRTStartup</b> or <b>mainWCRTStartup</b>. Note that this works for Windows CE, too, but a console window is not shown. This is pretty convenient when porting an application. You don&#8217;t have to rewrite the existing main function for that.</p>
<p>When creating a plain Win32 application that shows no console window, you can use <b>WinMainCRTStartup</b> or <b>wWinMainCRTStartup</b> to specify the WinMain() or the wWinMain() function as function to start. Windows CE projects always use wWinMainCRTStartup unless something different is specified.</div>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=13&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2007/12/07/win32-entry-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>The infamous ARM &#8220;by-value&#8221; compiler bug</title>
		<link>http://vividos.wordpress.com/2007/12/06/the-infamous-arm-by-value-compiler-bug/</link>
		<comments>http://vividos.wordpress.com/2007/12/06/the-infamous-arm-by-value-compiler-bug/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 18:54:28 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[eMbedded Visual C++]]></category>
		<category><![CDATA[PocketPC]]></category>
		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/2007/12/06/the-infamous-arm-by-value-compiler-bug/</guid>
		<description><![CDATA[This post will be about an ARM compiler bug that I discovered some time ago while porting STLport 5 for eMbedded Visual C++ 3 and 4. I also reported the bug to Microsoft and it seems they fixed the bug in Microsoft Visual Studio 2008. Note that the bug report contains a little bit complicated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=12&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post will be about an ARM compiler bug that I discovered some time ago while porting STLport 5 for eMbedded Visual C++ 3 and 4. I also <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=155924" class="snap_shots">reported</a> the bug to Microsoft and it seems they fixed the bug in Microsoft Visual Studio 2008. Note that the bug report contains a little bit complicated example. I will present a more understandable test for the bug here.</p>
<p><span id="more-12"></span>Compiling code for the ARM processor (e.g. for the PocketPC devices) is special in case of calling conventions. The compiler passes the first four 32-bit values of all parameters (e.g. 4 pointers or the first four 32-bit-words of a struct) in the registers R0 to R3. If there is more space needed, the caller of a function stores the remaining data on the stack. The first thing that the called function does is storing the registers to the first four 32-bit-words. I didn&#8217;t try it out, but I guess the compiler doesn&#8217;t store the arguments if they can stay in the registers. For a struct that has to be accessed, e.g. by taking a pointer, the data bytes must be stored somewhere, though. The whole stuff is described in MSDN, in the articles under <a href="http://msdn2.microsoft.com/en-us/library/ms253976%28VS.80%29.aspx" class="snap_shots">ARM Calling Sequence Specification</a>, e.g. in <a href="http://msdn2.microsoft.com/en-us/library/ms253599.aspx" class="snap_shots">ARM Stack Frame Layout</a>. (The topic in the evc4 help even has a fancy image showing the stack; the <a href="http://msdn2.microsoft.com/en-us/library/aa448593.aspx" class="snap_shots">platform builder version</a> of the second link also has the image)</p>
<p>The bug manifests itself when data is passed by-value to a function. When passing a non-POD type by value, the copy-ctor is called to create a temporary copy of the object, usable inside the function. For POD types the memory bytes are just copied to a temporary. Inside the function the dtor is called, essentially cleaning up the temporary again (at least that is the way the Visual C++ ARM compiler generates the code). The combined effect of passing arguments by register and by value may show the bug. The copy-ctor-constructed temporary is passed in the registers R0 to R3 and then copied to the stack by the function itself. The temporary inside the function has an other address as the temporary that was copy-constructed.</p>
<p>This should normally pose no problem, since the object is properly destroyed afterwards. There is one problem, though, and that occurs when the this pointer in the copy-ctor is stored somewhere. One example could be functions that register and deregister the class, e.g. in an observer pattern:</p>
<blockquote>
<pre>struct Resource
{
   Resource(){ Register(this); }
   Resource(const Resource&amp;){ Register(this); }
   ~Resource(){ Unregister(this); }
};</pre>
</blockquote>
<p>In the copy-ctor a wrong pointer would be passed, and at the time of unregistering the pointer wouldn&#8217;t be found.As mentioned, the bug was fixed in Visual Studio 2008, but of course it&#8217;s interesting what happens under the hood. For this to find out I will dig a bit deeper in the next post. We&#8217;re using a test program and ARM disassembly to show what&#8217;s going on.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=12&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2007/12/06/the-infamous-arm-by-value-compiler-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
		<item>
		<title>MoveItemToGroup not implemented</title>
		<link>http://vividos.wordpress.com/2007/07/08/moveitemtogroup-not-implemented/</link>
		<comments>http://vividos.wordpress.com/2007/07/08/moveitemtogroup-not-implemented/#comments</comments>
		<pubDate>Sun, 08 Jul 2007 18:38:05 +0000</pubDate>
		<dc:creator>vividos</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Win32]]></category>

		<guid isPermaLink="false">http://vividos.wordpress.com/2007/07/08/moveitemtogroup-not-implemented/</guid>
		<description><![CDATA[Derzeit versuche ich, das Grouping-Feature des Win32 List Controls zu benutzen. Mittels WTL 8 und entsprechendem Wizard hab ich ein Projekt angelegt, und es lassen sich auch Gruppen einfügen. Gruppen werden jedoch nicht angezeigt, wenn kein Item der Gruppe zugeordnet ist. Als nächstes wollte ich Items zu Gruppen zuordnen. Dabei ist mir aufgefallen, daß die [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=11&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Derzeit versuche ich, das Grouping-Feature des Win32 List Controls zu benutzen. Mittels WTL 8 und entsprechendem Wizard hab ich ein Projekt angelegt, und es lassen sich auch Gruppen einfügen. Gruppen werden jedoch nicht angezeigt, wenn kein Item der Gruppe zugeordnet ist. Als nächstes wollte ich Items zu Gruppen zuordnen. Dabei ist mir aufgefallen, daß die Methode MoveItemToGroup() bzw. die Message <a href="http://msdn2.microsoft.com/en-us/library/ms670799.aspx" class="snap_shots">LVM_MOVEITEMTOGROUP</a> nicht implementiert ist (und daneben noch ein paar andere Details vom Grouping). Das kann man aber per SetItem neu implementieren:</p>
<pre>LVITEM lvItem;
lvItem.mask = LVIF_GROUPID;
lvItem.iItem = iItemIndex;
lvItem.iSubItem = 0;
lvItem.iGroupId = iGroupID;
SetItem(&amp;lvItem);</pre>
<p>Was auch nicht geht, ist für LVGROUP::uAlign das Flag LVGA_FOOTER_CENTER anzugeben. Der InsertGroup()-Aufruf schlägt dann fehl. Außerdem werden bei einem Aufruf von GetGroupMetrics() nicht alle Felder zurückgeliefert. Die <a href="http://msdn2.microsoft.com/en-us/library/ms670565.aspx" class="snap_shots">Dokumentation</a> beschreibt, was <i>not implemented</i> ist. Einfacher wäre fast gewesen zu dokumentieren, was überhaupt implementiert ist.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vividos.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vividos.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vividos.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vividos.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vividos.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vividos.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vividos.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vividos.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vividos.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vividos.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vividos.wordpress.com&amp;blog=2464910&amp;post=11&amp;subd=vividos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vividos.wordpress.com/2007/07/08/moveitemtogroup-not-implemented/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/53cabc108149a53eb464f966a403c734?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vividos</media:title>
		</media:content>
	</item>
	</channel>
</rss>
