<?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/"
	>

<channel>
	<title>jaux.net &#187; C/C++</title>
	<atom:link href="http://jaux.net/tag/cc/feed/" rel="self" type="application/rss+xml" />
	<link>http://jaux.net</link>
	<description>Discovering this wonderful world...</description>
	<lastBuildDate>Fri, 06 Jan 2012 07:49:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Nothing Could Fail in C</title>
		<link>http://jaux.net/2010/01/27/nothing-could-fail-in-c/</link>
		<comments>http://jaux.net/2010/01/27/nothing-could-fail-in-c/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 08:50:05 +0000</pubDate>
		<dc:creator>jaux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://jaux.net/?p=361</guid>
		<description><![CDATA[Best comment of the C programming language ever! via:reddit Here is the whole story: Going back to C by buddhabrot When I was 12 someone gave me a Metrowerks IDE to learn programming on my mac. I learned a lot &#8230; <a href="http://jaux.net/2010/01/27/nothing-could-fail-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Best comment of the C programming language ever!</p>
<p>via:<a href="http://www.reddit.com/r/programming/comments/aue06/going_back_to_c/">reddit</a></p>
<p>Here is the whole story:</p>
<blockquote><p>
Going back to C<br />
by buddhabrot</p>
<p>When I was 12 someone gave me a Metrowerks IDE to learn programming on my mac. I learned a lot with it, and got programming in C. I never really wrote a large program in it, only things like ROM hacks that extracted levels and models from snes/psx games I liked. Later, I got a windows PC and messed around with MFC in C++. That was the end for me, programming UI&#8217;s was too much work in C++ and I couldn&#8217;t handle the encyclopedic knowledge needed to program the Microsoft framework.</p>
<p>Later, I learned Java, which was also the language most commonly in my college. Making UI&#8217;s was a blast with it, I could factorize anything and really loved making as generic code as possible with it, even for small projects. Everything I made was made in Java.</p>
<p>Later in uni, I started learning functional languages, we used Haskell in one class. I got intrigued with Haskell and started solving Euler problems, up to this day I still have not written anything useful in Haskell but I love using it.</p>
<p>In the mean time I did some jobs for writing web sites. I used perl and php. After a while I only used php and used it more frequently.</p>
<p>After working for a while as a programmer I started to love higher-level languages, most of all Ruby. I became convinced that higher-level interpreted languages were the future because the slower execution times were to become meaningless. For any web projects I started using Ruby on Rails and to this day it still is my favourite framework.</p>
<p>Then, I learned Erlang because everyone was talking about it, and it showed me how to unleash parallellization, in whole new ways. I still think Erlang is the most amazing language I have ever seen. But then I found out it was also rather slow for the things I had in mind with it. I just didn&#8217;t find any use for it and never completely learned the language.</p>
<p>Last week I wanted to make a big poster of a fractal. I wanted to compute it on a friend&#8217;s octocore, and write a fast parallellized program. At first, I used Ruby, thinking it would perform better than I thought. And I quickly abandoned the idea because it was too slow.</p>
<p>Then I rewrote the same single-threaded algorithm in Haskell and saw that it was much, much quicker. But when I tried to parallallize it, I couldn&#8217;t fathom how to do it in Haskell and abandoned the idea. I tried to write a parallellized version in Erlang, and while it spreak across the machine nicely, each individual process was way too slow, the parallellized algorithm was hundreds of times slower than the single-threaded haskell.</p>
<p>Because I really wanted that poster, I decided to switch to C because I had this idea that nothing could fail in C. And I started to code in a language I hadn&#8217;t used for years, even a decade. And suddenly it hit me, everything made sense. Sure, I was writing so much boilerplate but it didn&#8217;t bother me. I suddenly realized that everything I wrote would be inside the program&#8217;s code, and that nothing more would. It was a great feeling.<br />
I used simple pthreads to do the parallellization, and I used libgd to output my data to a png file. I started learning about mutex lock hierarchies to make the parallellizations overlap without endangering thread safety, it was all ugly code and the API&#8217;s felt horrible compared to what I was used to.. but it all worked out. The resulting program was thousands of times faster than anything I had written.</p>
<p>And now, I am seriously wondering where I have been all this time. Sure, I still think C is incredibly clunky. But now I got the dust off of my old course on writing compilers (Modern compiler implementation in C), and I want to write a compiler in C for a small programming language. I want to get down to earth again, and write things that are efficient and just run very quickly. I want to write lots and lots of code and know exactly what every line does.</p>
<p>Has anyone else had this feeling, this evolution? Am I going mad? Do you think C will last, and there are intersting jobs left for pure C developers?
</p></blockquote>
<p>I have the same question: <strong>Are there intersting jobs left for pure C developers?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://jaux.net/2010/01/27/nothing-could-fail-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Patch to Broadcom 802.11 Linux STA driver for Kernel 2.6.27</title>
		<link>http://jaux.net/2008/10/14/patch-to-broadcom-80211-linux-sta-driver-for-kernel-2627/</link>
		<comments>http://jaux.net/2008/10/14/patch-to-broadcom-80211-linux-sta-driver-for-kernel-2627/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 07:53:40 +0000</pubDate>
		<dc:creator>jaux</dc:creator>
				<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Broadcom]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[patch]]></category>

		<guid isPermaLink="false">http://jaux.net/?p=128</guid>
		<description><![CDATA[Update 2009-01-04: As Jose mentioned, the latest driver (ver. 5.10.27.12) no longer needs this patch! If you have problem to compile Broadcom 802.11 Linux STA driver (version 5.10.27.6) on Kernel 2.6.27 and get error message like the following: Then you &#8230; <a href="http://jaux.net/2008/10/14/patch-to-broadcom-80211-linux-sta-driver-for-kernel-2627/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Update 2009-01-04: As Jose mentioned, the latest driver (ver. 5.10.27.12) no longer needs this patch!</em></p>
<p>If you have problem to compile Broadcom 802.11 Linux STA driver (<strong>version <em>5.10.27.6</em></strong>) on <strong>Kernel <em>2.6.27</em></strong> and get error message like the following:</p>
<pre class="brush: bash; title: ; notranslate">
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c: In function ‘wl_iw_get_scan’:
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:934: warning: passing argument 1 of ‘iwe_stream_add_event’ from incompatible pointer type
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:934: warning: passing argument 3 of ‘iwe_stream_add_event’ from incompatible pointer type
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:934: warning: passing argument 4 of ‘iwe_stream_add_event’ makes pointer from integer without a cast
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:934: error: too few arguments to function ‘iwe_stream_add_event’
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:939: warning: passing argument 1 of ‘iwe_stream_add_point’ from incompatible pointer type
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:939: warning: passing argument 3 of ‘iwe_stream_add_point’ from incompatible pointer type
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:939: warning: passing argument 4 of ‘iwe_stream_add_point’ from incompatible pointer type
/home/ye/downloads/bcm4328/hybrid_wl/src/wl/sys/wl_iw.c:939: error: too few arguments to function ‘iwe_stream_add_point’
...
</pre>
<p>Then you need to apply the patch: <a href='http://jaux.net/uploads/2008/10/hybrid_wl-5.10.27.6_patch-2.6.27'>hybrid_wl-5.10.27.6_patch-2.6.27</a></p>
<p>How to apply the patch:</p>
<ol>
<li>Download the STA driver and the patch.</li>
<li>Extract the STA driver and switch to the root of source tree (where Makefile is located).</li>
<li><strong>patch -p1 -E < <em>path_to_patch</em>/hybrid_wl_5.10.27.6_patch-2.6.27</strong></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jaux.net/2008/10/14/patch-to-broadcom-80211-linux-sta-driver-for-kernel-2627/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How To Prevent Creating Objects On Heap</title>
		<link>http://jaux.net/2007/12/12/how-to-prevent-creating-objects-on-heap/</link>
		<comments>http://jaux.net/2007/12/12/how-to-prevent-creating-objects-on-heap/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 20:55:33 +0000</pubDate>
		<dc:creator>jaux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://jaux.net/2007-12-12/how-to-prevent-creating-objects-on-heap/</guid>
		<description><![CDATA[Yesterday I saw a C++ interview question that was asking the interviewees to prevent the clients from creating objects on heap. That is, you write a class and your class users can&#8217;t use new to create an object. Here is &#8230; <a href="http://jaux.net/2007/12/12/how-to-prevent-creating-objects-on-heap/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I saw a <strong>C++</strong> interview question that was asking the interviewees to <em>prevent the clients from creating objects on heap</em>. That is, you write a class and your class users can&#8217;t use <strong>new</strong> to create an object.</p>
<p>Here is my solution:</p>
<pre class="brush: cpp; title: ; notranslate">
class Foo
{
public:
    Foo(const Foo&amp; f) {}
    static Foo getAnInstance()
    {
        return Foo();
    }
private:
    Foo() {}
};
</pre>
<h3>Explanation:</h3>
<p>To prevent users from creating objects on heap, I basically can&#8217;t give them any public constructors (ctor); therefore, I need to write at least one ctor myself and make it private since if I fail to do so, the compiler will generate a public default ctor for me and that is exactly what I don&#8217;t want. Then the user can only use the static member function <code>getAnInstance</code> to get an object to use.</p>
<h3>Analysis:</h3>
<p>In fact, my solution contradicts the explanation because I actually have a public ctor &#8212; the copy ctor. The copy ctor makes the following usage work:</p>
<pre lang="cpp" line="1">
Foo f0 = Foo::getAnInstance();
</pre>
<p>But because there is a copy ctor, after the user get his/her first object, he/she can do the following:</p>
<pre lang="cpp" line="1">
Foo* f1 = new Foo(f0);
</pre>
<p>This is saying that my solution can only guarantee <strong>the first object</strong> is on stack and it can&#8217;t go further.</p>
<p>So, my solution fails to solve the question.</p>
<p>p.s. I haven&#8217;t really seen the point of the interview question, but it&#8217;s interesting to think about ;)</p>
<h3>Update:</h3>
<p>The correct solution is to overload the <code>new</code> operator and make it private. <small>Credit to <a href="http://www.daniweb.com/forums/thread100867.html">DANIWEB</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://jaux.net/2007/12/12/how-to-prevent-creating-objects-on-heap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Solving Cyclic Dependencies Is Hard</title>
		<link>http://jaux.net/2007/11/14/solving-cyclic-dependencies-is-hard/</link>
		<comments>http://jaux.net/2007/11/14/solving-cyclic-dependencies-is-hard/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 05:55:52 +0000</pubDate>
		<dc:creator>jaux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://jaux.net/2007-11-14/solving-cyclic-dependencies-is-hard/</guid>
		<description><![CDATA[I am a C/C++ beginner but I&#8217;d been already taught that dependency cycles are generally evil since it&#8217;s very hard to solve. I haven&#8217;t realized how hard the problem is before, because all the works I&#8217;ve done are &#8220;one file&#8221; &#8230; <a href="http://jaux.net/2007/11/14/solving-cyclic-dependencies-is-hard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am a C/C++ beginner but I&#8217;d been already taught that dependency cycles are generally evil since it&#8217;s very hard to solve. I haven&#8217;t realized how hard the problem is before, because all the works I&#8217;ve done are &#8220;one file&#8221; programs or I can just simply throw all the files into a single gcc/g++ command.</p>
<p>However, in my current assignment, I have to use a makefile provided by the prof. and there are dependency cycles among classes. The following is a simplified class digram shows the relationship:</p>
<p><small><em>IMAGE IS MISSING, SORRY!</em></small></p>
<p>I screwed up the header files; I spent almost one hour to solve it. I tried a lot different combinations of #includes and forward declarations, but none of them satisfied the preprocessor and/or the compiler.</p>
<p>After I became tired, I decided to leave the keyboard alone. I picked up my pen and a piece of paper and drew a small class diagram like the one above but much uglier. Suddenly, I found the problem guy was the class B because it had two outgoing dependencies and one incoming. Say that B&#8217;s dependencies count (dc[B]) = outgoing &#8211; incoming = 1, and dc[A] = -1, dc[C] = 0. The greater the number is, the class has more problems.</p>
<p>The problem is clear. Satisfying C&#8217;s dependency is a piece of cake, I just need to forward declare class A in class C&#8217;s header, <code>c.h</code>, then I include <code>c.h</code> header in <code>b.h</code>. Since the declaration of A is in <code>c.h</code>, I don&#8217;t need to declare it again in B&#8217;s header. Then, I include b.h into class A&#8217;s header file <code>a.h</code>.</p>
<p>Done! I&#8217;m not sure the program would work correctly, but now, it can be compiled.</p>
<p>Now I can imagine how hard the problem could be if hundreds or thousands files/classes are there sitting with cycles; therefore, the original design is so important and I believe that&#8217;s why we have to take tons of design/software engineering courses in the university.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaux.net/2007/11/14/solving-cyclic-dependencies-is-hard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Weird Hex Output</title>
		<link>http://jaux.net/2007/10/04/weird-hex-output/</link>
		<comments>http://jaux.net/2007/10/04/weird-hex-output/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 15:59:28 +0000</pubDate>
		<dc:creator>jaux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://jaux.net/2007-10-04/weird-hex-output/</guid>
		<description><![CDATA[In C++, to output and integer in hex, I&#8217;d been taught to do this: And if I want to show &#8220;0x&#8221; before the value, I need to do the following: The above code works well for either positive or negative &#8230; <a href="http://jaux.net/2007/10/04/weird-hex-output/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In C++, to output and integer in hex, I&#8217;d been taught to do this:</p>
<pre class="brush: cpp; title: ; notranslate">cout &lt;&lt; hex &lt;&lt; an_integer;</pre>
<p>And if I want to show &#8220;0x&#8221; before the value, I need to do the following:</p>
<pre class="brush: cpp; title: ; notranslate">
cout.setf(ios::showbase);
cout &lt;&lt; hex &lt;&lt; an_integer;
</pre>
<p>The above code works well for either positive or negative integers, but not the value <em>ZERO</em>. If I run the following code:</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;iostream&gt;

using namespace std;

int main() {
    cout.setf(ios::showbase); //1
    cout &lt;&lt; hex &lt;&lt; 100 &lt;&lt; endl;
    cout &lt;&lt; hex &lt;&lt; 0 &lt;&lt; endl;
    return 0;
}
</pre>
<p>I am expecting this:</p>
<pre class="brush: bash; title: ; notranslate">
0x64
0x0
</pre>
<p>However, the actually output is:</p>
<pre class="brush: bash; title: ; notranslate">
0x64
0
</pre>
<p>The hex number notation &#8220;0x&#8221; is missing for the value <em>0</em>.</p>
<p>I also tried this:</p>
<pre class="brush: cpp; title: ; notranslate">
cout.setf(ios::hex | ios::showbase);
cout &lt;&lt; 0;
</pre>
<p>It doesn&#8217;t work, neither.</p>
<p>This is weird to me. I am wondering why it is and is there a solution without any &#8220;ugly&#8221; hacks such look like:</p>
<pre class="brush: cpp; title: ; notranslate">cout &lt;&lt; &quot;0x&quot; &lt;&lt; hex &lt;&lt; an_integer;</pre>
<p>Update: After asking some of my friends, the solution above seems to be a decent solution to the goal I want to achieve; otherwise, code might become uglier at end of the day. Why not take it easy?</p>
]]></content:encoded>
			<wfw:commentRss>http://jaux.net/2007/10/04/weird-hex-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

