Developing In C/C++? Why You Should Consider Clang Over GCC (dice.com)
Nerval's Lobster writes: The idea with Clang, a compiler front-end for C, C++, Objective-C++, and Objective-C, and LLVM (a compiler infrastructure) is that you can mix the compiler front-end with a targeted back-end and end up with highly portable and efficient compiler. Clang can perform static analysis of your code, and lets you write tools that give you information about a program. Although many developers prefer developing in C/C++ using GCC, developer David Bolton (in a new Dice article) makes an argument for why you should switch to Clang. While GCC is probably still best when it comes to speed, he argues, Clang is improving release by release, and features tools that developers could find useful.
While GCC is probably still best when it comes to speed, he argues, Clang is improving release by release, and features tools that developers could find useful
Translation: "network tran--I mean speed is a feature that most of our users don't need, so it's not in our development plan"
Compile in both. And visual studio too if possible. Enable all warnings. They are all good at identifying different categories of problems and code that compiles cleanly under multiple compilers will prove easier to maintain.
I strongly recommend Clang. It's speed is about on par with GCC, but the output and syntax checking is so much better. I tried it a bit a few years back and I have been hooked on Clang since. Using GCC feels like a big step backward now because it's so fussy and its warnings are so cryptic in comparison.
Nope, those still get you modded down. To be modded up, you'll need to be an elf or a hobbit...
To make sure my code is not using any compiler features I compile my code on both.
Isn't LLVM/clang all about the license (non-GPL)? Otherwise if clang is good, then we should fork it and make a GPL version of it.
From up-close-and-personal experience with Objective C and C++ (also Smalltalk), these languages have substantially different semantics regarding class identity (primarily: what version of overridden member functions you get) during construction and destruction. I wouldn't be surprised if Objectivce-C++ had yet another semantics, pulling "features" from both, and I have no clue about LVMM.)
Building a frontend to compile to them, interchangeably, is a recipe for subtle bugs, if the frontend doesn't deal with these issues. Efficiency may go out the window if the frontend tries to impose one language's construction/destruction semantics on another. Doing so also brings up the issue of which semantics the compiler exposes to the programmer - each has its good and bad points, and each enables different - and incompatible - useful programming features.
I'd be interested in what (if anything) Clang has done about this issue. (Unfortunately, I'm busy on other stuff, so I'll have to depend on others to elucidate this.)
Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
Clang can compile to the LLVM "IR" format, which is a mostly machine-independent Intermediate Representation. Kind of like bytecode.
The IR file format has two variations: a human readable text format, and a more compact binary format.
Given an IR file, you can optimize it, which produces another IR file, or you can compile it into an object file.
I have written a truly remarkable program which this sig is too small to contain.
I would think that if these subtle bugs exist they'd be caught by the test suites. Do you have any actual evidence of these subtle bugs?
>better error messages, warnings, and static analysis from Clang. Those save me way more time than the speed of the compiler.
This is the truth. Ain't nobody got time to read through a hundred lines of error messages to track down a single bug.
As a simple test, I wrote the following code which has a simple mistake (using an integer instead of an int array in a range-based for loop):
test.cc:
#include
int main() {
int x = 0;
for (int i: x) std::cout constexpr const _Tp* std::end(std::initializer_list)
end(initializer_list __ils) noexcept"
2 lines for a single straightforward error in clang++ 3.7 (with colors even!):
"test2.cc:5:12: error: invalid range expression of type 'int'; no viable 'begin' function available
for (int i: x) std::cout i;"
I currently use g++ with new programmers, and will be switching soon to clang++.
Plus Clang does cool things like interoperate with things like YouCompleteMe to do real time compiling and error message generation for syntax completion in VIM.
From up-close-and-personal experience with Objective C and C++ (also Smalltalk), these languages have substantially different semantics regarding class identity (primarily: what version of overridden member functions you get) during construction and destruction. I wouldn't be surprised if Objectivce-C++ had yet another semantics, pulling "features" from both, and I have no clue about LVMM.)
Objective-C++ mixes the syntax of the two languages, and allows you to use either a C++ object or an Objective-C object at will, however it does not make C++ objects into Objective-C objects or vice versa. Any semantics relating to C++ objects still applies to C++ objects, and no additional semantics are implied.
In short: things work as you'd expect, and there are no hidden gotchas.
The only real complexities are what happens when you embed a C++ object as a member inside an Objective-C object (this doesn't change the semantics of the C++ object itself, but obviously may change the point at which the whole thing is destroyed) and what happens when you reference an Objective-C object from within a C++ object (some of the automatic refcounting syntactic sugar goes away and you have to actually understand what you're doing.) These don't introduce difficulties for the compiler, but could potentially be confusing for the programmer.
I'm sure clang has its fair share of bugs, and I'm sure that GCC does also, that's just the nature of any complex codebase. The shared backend isn't really a contributing factor, any more so than them both emitting x86 machine code is a contributing factor.
while clang is probably fine for most projects, if your project needs -std=c++14 then you should be warned that sometimes Clang can't properly deduce (even when you are explicit) variadic template parameters.
for example, this code will not compile on Clang no matter what but works fine with G++.
template<typename... ArgTypes> using deeper = void(*)(ArgTypes...);
template<typename... ArgTypes> void shallow(deeper<ArgTypes...> arg) { }
int main(int argc, char* argv[])
{
deeper<int> arg;
shallow<int>(arg);
return 0;
}
Anons need not reply. Questions end with a question mark.
My current project uses a Blackfin DSP processor by Analog Devices. The toolset that Analog provides supports only C, C++, and assembly. I don't expect them to provide Java, .Net, PHP, Haskell, Python or [your favorite language here] anytime soon.
You can run Linux on a blackfin. I'd strongly expect you could easily run Python or PHP on it. Not sure why you'd want to.
SJW n. One who posts facts.