What's new in GCC 4.5?
What's new in GCC 4.5?
Posted May 14, 2010 9:35 UTC (Fri) by jwakely (subscriber, #60262)In reply to: What's new in GCC 4.5? by pr1268
Parent article: What's new in GCC 4.5?
As well as increased type-safety C++ gives you automatic memory management (via destructors) which could potentially replace the garbage collection used today.
Gcc uses lots of hash tables and vectors internally (the VEC type mentioned at the link you gave) which could be replaced by standard C++ containers - although that's a bit less certain, as it would require a working C++ standard library as well as C++ compiler to bootstrap.
There are of course downsides to C++, so let's not have a language war here :)
Posted May 19, 2010 21:46 UTC (Wed)
by roelofs (guest, #2599)
[Link] (3 responses)
Those are excellent benefits, and I've come to like C++ for such reasons--as long as one doesn't go overboard, of course. C++ can lead to "write-only" code, i.e., easy to write, impossible to maintain. One needs a little discipline and design sense, which I'm sure the GCC folks have in abundance. (Doug Crockford has made similar comments about JavaScript, btw. Just because the language officially supports something doesn't mean you should actually use it. :-) )
One unforeseen drawback we encountered, however: generated code size (that is, binaries) exploded. A 15 MB C-only executable grew to ~600 MB as parts of it were rewritten in C++. I still think it was worthwhile overall, but holy cow...don't underestimate the pain of creating, deploying, loading into memory, and core-dumping huge binaries. (Some of it might have been due to symbol visibility; I never had time to investigate. I think quite a bit was due to template use. No doubt you guys will figure out ways to keep it under control in GCC...)
Greg
Posted May 20, 2010 3:56 UTC (Thu)
by quotemstr (subscriber, #45331)
[Link] (2 responses)
Part of the cause is almost certainly forced inline function generaton. Using hidden symbols allows the compiler to skip the generaiton of certain functions --- if they're private symbols, the compiler can assume they're not overwritten at load-time.
Another thing to keep in mind is C++ template generation, as you mentioned. It's easy to achieve a combinatorial explosion of template instantiations when you have a template library used in many difficult circumstances. It's often worthwhile to have generic, templated code just be an inline-only, typesafe wrapper around concrete code; use function pointers to let that concrete code safely work with whatever the higher-level wrapper gives it.
Using that approach, you give up a tiny bit of runtime performance for a huge reduction in code size. Imagine the difference between qsort() and std::sort --- it's easy to write the latter such that the entire sorting agorithm implementation is emitted once per type sorted! (It's also possible for a C++ library implementor to write std::sort using the type erasure technique I mention.)
Posted May 20, 2010 10:03 UTC (Thu)
by jwakely (subscriber, #60262)
[Link]
Posted May 30, 2010 1:01 UTC (Sun)
by roelofs (guest, #2599)
[Link]
With. In this application, auto-gdb-backtrace was pretty much a necessity.
I'm no longer working on that particular project (or even in C++), but I'll keep jwakely's and your suggestions handy in case it crops up again.
Thanks,
Compiling gcc with a C++ compiler has already uncovered a number of latent bugs, such as comparing values of enum_type_1 to values of enum_type_2. That's not an error in C, because enums are just ints, but in C++ they're distinct types and the compiler catches the problem.
What's new in GCC 4.5?
What's new in GCC 4.5?
A 15 MB C-only executable grew to ~600 MB as parts of it were rewritten in C++
That's huge! There's no good reason to tolerate that level of bloat. Was that with or without debugging symbols?
What's new in GCC 4.5?
Was that with or without debugging symbols?
What's new in GCC 4.5?
Greg
