LWN: Comments on "Russell: GCC and C vs C++ Speed, Measured"
http://lwn.net/Articles/543927/
This is a special feed containing comments posted
to the individual LWN article titled "Russell: GCC and C vs C++ Speed, Measured".
hourly2C, simple?
http://lwn.net/Articles/545027/rss
2013-03-28T19:50:59+00:00dlang
<div class="FormattedComment">
assembly is simpler, and if you only ever had to program one machine it may even be reasonable, but since assembly is different for every system, and it doesn't have any standard way to define higher level structures, C was born<br>
</div>
C, simple?
http://lwn.net/Articles/544995/rss
2013-03-28T17:54:57+00:00apoelstra
<div class="FormattedComment">
<font class="QuotedText">> C isn't really simple at all, it's just uncommonly good at presenting the illusion of simplicity. If it really were simple, you wouldn't like it.</font><br>
<p>
As dlang said, the machine model is very simple compared to that of other imperative languages. Lisp and Haskell are probably simpler, but Java or Python are much more complex (and PHP is so wild that I would argue it -has- no machine model!).<br>
<p>
By "if it really were simple, you wouldn't like it", ITYM "if it really were simple, it couldn't be used to program computers", because C's complexity seems to be an unavoidable consequence of physical machines (e.g. having finitely sized types).<br>
<p>
</div>
C, simple?
http://lwn.net/Articles/544849/rss
2013-03-28T10:01:34+00:00dlang
<div class="FormattedComment">
As languages go, C actually is pretty simple.<br>
<p>
you can do very complex things with very simple building blocks, remember that even the most complex CPU is a combination of AND, OR, NOT gates combined with memory. These are very simple components, but the results that are built with these simple components are very complex.<br>
</div>
C, simple?
http://lwn.net/Articles/544838/rss
2013-03-28T09:27:27+00:00ncm
<div class="FormattedComment">
C isn't really simple at all, it's just uncommonly good at presenting the illusion of simplicity. If it really were simple, you wouldn't like it.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544625/rss
2013-03-27T15:32:22+00:00nix
<div class="FormattedComment">
Ooh. You're right, I never noticed, it's an int. Bizarrely counterintuitive, though I can see why they did it, I think.<br>
<p>
How is it that even a language as simple as C still has corners to learn after decades using it?<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544450/rss
2013-03-26T10:48:47+00:00khim
<blockquote><font class="QuotedText">I mean, even if I do "g++ main.c", main.c is still considered a C file and sizeof('a') should still be 1.</font></blockquote>
<p>Rilly? It's easy to test, you know.</p>
<p><code>$ cat main.c<br />
#include <stdio.h><br />
<br />
int main() {<br />
printf("%zd\n", sizeof 'a');<br />
return 0;<br />
}<br />
$ gcc main.c -o main ; ./main<br />
4<br />
$ g++ main.c -o main ; ./main<br />
1<br />
</code></p>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544420/rss
2013-03-26T01:18:44+00:00andrel
<div class="FormattedComment">
But 'a' is not a char in C.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544416/rss
2013-03-26T00:49:58+00:00nix
<blockquote>
Perhaps the most well-known is the fact that “sizeof 'a'” has size 4 in C, but 1 in C++.
</blockquote>
What? sizeof(char) is 1 by definition in both languages.
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544229/rss
2013-03-24T12:46:10+00:00jwakely
<div class="FormattedComment">
<font class="QuotedText">> What does --enable-build-with-cxx actually do ?</font><br>
<p>
Approximately, it does CC=g++<br>
<p>
<font class="QuotedText">> I mean, even if I do "g++ main.c", main.c is still considered a C file and sizeof('a') should still be 1.</font><br>
<p>
I assume you mean sizeof('a') should be 4 if it was considered a C file, but it isn't, using g++ implies the input file is C++<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544215/rss
2013-03-24T09:29:13+00:00aleXXX
<div class="FormattedComment">
What does --enable-build-with-cxx actually do ?<br>
<p>
I mean, even if I do "g++ main.c", main.c is still considered a C file and sizeof('a') should still be 1.<br>
Or does that forcce cxx as a language on all C files ?<br>
<p>
Alex<br>
<p>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544110/rss
2013-03-23T09:13:22+00:00khim
There are small, subtle, differences. Perhaps the most well-known is the fact that “sizeof 'a'” has size 4 in C, but 1 in C++. This is not big deal since automatic type conversion gives you the same result in the end, but it can easily affect heuristics which will mean that code produced will be equivalent yet different.
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544108/rss
2013-03-23T08:57:43+00:00nix
<div class="FormattedComment">
Wasn't it?<br>
<p>
... oh hell, it says as much right in the excerpt, and I misread it at least three times. Sigh. Brain failure. You're right, of course.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544077/rss
2013-03-23T02:06:01+00:00Kit
<div class="FormattedComment">
This is in line with what the article author wrote in a comment on his blog:<br>
<font class="QuotedText">> Yep… sizes are exactly the same, objdump -d shows only difference is different </font><br>
<font class="QuotedText">> junk in the .notes section.</font><br>
<p>
There might be some corner cases where they produce different code, but if none were exposed by GCC being compiled as C++, then they'll definitely be the exception rather than the rule.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544076/rss
2013-03-23T01:30:27+00:00mveinot
<div class="FormattedComment">
A trivial example I know, but in an uncomprehensive test just now I used both GCC and G++ to generate assembly output (-S param) for a simple "Hello World" C program. The assembly generated for both was identical.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544058/rss
2013-03-22T23:07:05+00:00bmenrigh
<div class="FormattedComment">
Surely gcc and g++ don't emit the exact same machine code for the same C source. It's probably *very* close but still slightly different.<br>
<p>
I'd love to see somebody compare this though.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544052/rss
2013-03-22T21:31:29+00:00HelloWorld
<div class="FormattedComment">
<font class="QuotedText">> Messen ist Wissen!</font><br>
Wer misst, misst meistens Mist.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544048/rss
2013-03-22T21:10:13+00:00daney
<div class="FormattedComment">
The test was not with GCC 4.8, so it cannot be used to make assertions about Abstraction Penalties imposed by the GCC 4.8 code base.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544041/rss
2013-03-22T20:46:35+00:00Tobu
The author does point out GCC's "C as C++" was larger and slower 20 years ago.
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544039/rss
2013-03-22T20:27:15+00:00Yorick
<div class="FormattedComment">
I wouldn't call the experiment meaningless. If anything, we need more of these — simple but properly conducted measurements of things of some practical relevance.<br>
<p>
Even if nobody who knows how a compiler for C and C++ works is the slightest bit surprised of the results, it's still reassuring, and hard data that can be referred to and used to convince those in the doubt.<br>
<p>
Messen ist Wissen!<br>
<p>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544022/rss
2013-03-22T19:10:50+00:00nix
<div class="FormattedComment">
I'm fairly sure (OK, certain) that actual C++ code has already landed in 4.8 (see e.g. gcc/hash_table.* on the 4.8 branch). That makes it a test of the abstraction penalty imposed on the optimizer by those classes (in effect, nil). (Admittedly, quite a lot of that is probably because of -fno-exceptions, which eliminates a huge bunch of abnormal edges that *would* otherwise impede optimization even of code that looks just like C code. I should do some tests with -fexceptions and see how much effect this actually has...)<br>
<p>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544015/rss
2013-03-22T18:48:00+00:00Tara_Li
<div class="FormattedComment">
I would expect that optimally, the exact same machine code should result from the exact same C source file. If not, one or the other has something to learn from its opposite.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544013/rss
2013-03-22T18:47:50+00:00daney
<div class="FormattedComment">
Except there was no abstraction other than that that is possible to achieve using the C language. So this test doesn't even try to measure any hypothetical Abstraction Penalty that may be incurred by using C++ features.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544014/rss
2013-03-22T18:45:36+00:00heijo
<div class="FormattedComment">
Amazing news, who would have thought?<br>
<p>
An incredible insight: this will result in a sweeping paradigm shift.<br>
</div>
Russell: GCC and C vs C++ Speed, Measured
http://lwn.net/Articles/544011/rss
2013-03-22T18:37:13+00:00nix
<div class="FormattedComment">
Take *that*, abstraction penalty!<br>
<p>
</div>