Slashdot Mirror


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.

255 comments

  1. Translation by RightwingNutjob · · Score: 2, Insightful

    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"

    1. Re:Translation by Anonymous Coward · · Score: 0

      Like running native on windows where GCC doesn't..... Yea, not a feature I'm seriously missing given Micro$oft giving away Visual Studio now...

    2. Re:Translation by ShanghaiBill · · Score: 5, Informative

      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"

      No. Clang produces faster code. What TFA means is that GCC compiles faster. But if slightly faster compiles are that important, just turn off the optimizer, or buy a faster computer. How much time does a modern developer spend waiting for the compiler to finish? For me, it is less than 1%. Far more important is the better error messages, warnings, and static analysis from Clang. Those save me way more time than the speed of the compiler.

    3. Re:Translation by Anonymous Coward · · Score: 1, Funny

      Is this sarcasm? Please tell me this is sarcasm and you intentionally got it backwards.

    4. Re:Translation by Shados · · Score: 1

      How much time does a modern developer spend waiting for the compiler to finish

      In C/C++? All the freagin time. Large applications can take -forever- to compile, even if its not a clean compile.

    5. Re:Translation by Anonymous Coward · · Score: 1

      > No. Clang produces faster code [phoronix.com].

      Engineering optimization versus Technology breakthrough.

      > What TFA means is that GCC compiles faster.

      I believe OP is being sarcastic. "Our users" means the developers for whom compiling speeds are of utmost importance ("premature optimization" etc.) So, faster code is not the main issue here.

      But being paranoid, I'd like to ask... are we safe with Clang regarding those "special compilations" of which we've been warned by Ken Thompson? (search "Trusting Trust")

    6. Re:Translation by Anonymous Coward · · Score: 0

      -1, Factually Incorrect. Clang/llvm do not deliberately lack speed completely, they are just not as fast yet, and endeavor to be just as fast or faster in the future. This is quite importantly distinct from the "fuck your network transparency" approach of Wayland.

      Anyway, if speed is genuinely important you're writing parallel code and using a commercial compiler that fixes most of the common performance sucker-punchers for you. If speed is SUPER important, you're either writing CUDA and using nvcc specifically and/or targetting Xeon Phi using icc/mpss specifically

    7. Re:Translation by Anonymous Coward · · Score: 0

      When compiling a finished product (for actual use) I care about run time.
      But when I'm actually doing development compile time is infinitely more important, particularly if the code base is more than moderately large. Compilation of large C++ projects takes a freaking eternity

    8. Re:Translation by ShanghaiBill · · Score: 4, Informative

      Large applications can take -forever- to compile, even if its not a clean compile.

      Many complaints about slow compiles are due to dysfunctional workflow. You should be using precompiled headers, and set up your makefiles for multiple cores. But most importantly, you should be using TDD to develop and debug code outside of the application. So instead of compiling and linking the entire application repeatedly as you track down a bug, you only integrate after all your unit tests are written and passed in isolation.

      But, anyway, it isn't clear that Gcc actually compiles faster than Clang. Here are some benchmarks, and the results are mixed. Sometimes Clang is faster, sometimes Gcc is faster. For a large app, they would likely be about even in compile time. But Clang would likely generate better code, and almost certainly generate more helpful errors/warnings/analysis.

      I can't see any rational reason to prefer Gcc.

    9. Re:Translation by HiThere · · Score: 2

      If you're dubious about "special compilation", then use GCC to compile clang. (It's not sufficient, but using a different compiler to do the compilation of the compiler is a necessary step.)

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    10. Re:Translation by Anonymous Coward · · Score: 1

      When compiling a finished product (for actual use) I care about run time. But when I'm actually doing development compile time is infinitely more important, particularly if the code base is more than moderately large. Compilation of large C++ projects takes a freaking eternity

      You have a serious problem with how your solution builds then. Hell, we had this problem licked way back with "MAKE" on Unix, where you only had to build the parts you touched and unless you modified a central header file it would figure out the minimum amount of stuff you needed to build, and link. Usually the longest part of the build was the link, and when you got tired of that, we'd start moving things off into shared libraries so you didn't have to write the whole executable statically linked. Then adding the -j x (where x was # of CPU's you had times 2) to the command line on MAKE would usually move things along faster.

      Now days, if you are wasting much time building your project... I'd consider the problem to be how you choose to build stuff, something is wrong there....

    11. Re:Translation by Anonymous Coward · · Score: 0

      Compile time can be greatly reduced by careful header file usage. Instructions can be found in the latest version of Effective C++ by Scott Meyers. I followed his instructions with amazing success on a large project at work. Now they think I'm the god of programming because I can read and follow directions.

    12. Re:Translation by Anonymous Coward · · Score: 0

      gentoo weenie!

    13. Re:Translation by Anonymous Coward · · Score: 0

      redhat/systemd wanker!

    14. Re:Translation by epyT-R · · Score: 2

      No. Sometimes Clang produces faster code. Read the rest of that review.

    15. Re:Translation by Anonymous Coward · · Score: 0

      What kind of garbage code are you compiling? Why don't you reorganize it so that you aren't recompiling everything whenever you make a small change.

    16. Re:Translation by Anonymous Coward · · Score: 1

      Some people work on projects larger than Flappy Bird.

    17. Re:Translation by Anonymous Coward · · Score: 0

      It depends. I work on some projects that have complex template classes that are used all over the place. Change these classes and you need to recompile about 90% of the code, which takes quite some time. Now must of this could be refactored, but I'm in no position to make that happen, so... I care about compile time.

    18. Re:Translation by Anonymous Coward · · Score: 1

      Precompiled headers and multicore compilation aren't always enough. I've worked on projects that were so big that the compiler would actually run out of heap space trying to compile them.

    19. Re: Translation by Anonymous Coward · · Score: 0

      Adam?

    20. Re: Translation by Anonymous Coward · · Score: 5, Funny

      And what kind of garbage programmers are you that need to compile the same code multiple times? Write the code correctly the first time and only compile once.

    21. Re:Translation by Anonymous Coward · · Score: 0

      How much time does a modern developer spend waiting for the compiler to finish

      In C/C++? All the freagin time. Large applications can take -forever- to compile, even if its not a clean compile.

      What's big enough to matter and doesn't have automated builds and regression tests?

    22. Re:Translation by mikael · · Score: 2

      I've seen cross-compile builds of large code bases of 2 million+ lines take 10 minutes. Change one header file of a low-level module, and the whole stack has to be rebuilt. Just because BaseClassA has had a new boolean flag added, DerivedClassB to DerivedClassJ have to be recompiled along with container classes, interface classes, then the GUI layer with custom widgets, the plugins for third-party editors, the dynamic linked libraries, and finally the application itself.

      --
      Vintage computer adverts: http://www.vintageadbrowser.com/computers-and-software-ads
    23. Re:Translation by Anonymous Coward · · Score: 0, Interesting

      > I can't see any rational reason to prefer Gcc.

      1) Long term Freedom. The importance of which can not and should not be understated.

      2) If you're developing with multi-architecture in mind. Good luck using Clang/LLVM outside of x86/ARM.

      I remember the bad old days of working with proprietary C compilers on embedded platforms. It makes me shudder. Clang/LLVM allows this. Never again.

    24. Re:Translation by Anonymous Coward · · Score: 0

      The only reason I prefer gcc is to start porting over Legacy Code.

      Gcc handles backwards compatibility fairly well, while clang is not as forgiving (is actually more correct) to the specifications, which tends to breaks older FOSS abandonware.

      I start with a recent gcc, if it still compiles and functions properly, then I move over to clang.

    25. Re:Translation by dev54335 · · Score: 1

      > Compile time can be greatly reduced by careful header file usage. Instructions can be found in the latest version of Effective C++ by Scott Meyers. When you work on a 10-20 year old enterprise code base this assumption is false. And its not easy to refactor, due to the cost of testing. So faster compiler is a must for faster development, g++/gcc just wins.

    26. Re:Translation by Anonymous Coward · · Score: 0

      > I can't see any rational reason to prefer Gcc.

      Some widely used software doesn't build correctly with clang, I know. I'm one of the ten people on the planet that build their Gentoo system with the test FEATURE flag.

      Sadly, there are many tests that pass when software is built with GCC but fail (sometimes even segfault) when the same software is built with clang.

      I would *love* to be able to build my whole damn system with clang, but I can't. For new stuff, I *definitely* reach for clang.

    27. Re:Translation by Anonymous Coward · · Score: 0

      10 minutes! /me cries as he waits for 4 hours to build an FPGA image.

      It is better than it used to be though

    28. Re:Translation by jcr · · Score: 1

      If you want faster compiles, put your sources and your build folder on a RAM disk. For me, it shortens five minute builds to 30 seconds or less.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    29. Re:Translation by davester666 · · Score: 1

      Time to break that puppy up into two '.cp' files.

      --
      Sleep your way to a whiter smile...date a dentist!
    30. Re:Translation by Yokaze · · Score: 3

      If you are running into that issue often, consider the Pimpl-pattern.

      As always, C++ doesn't take the decision away from you. If you cannot live with the overhead in runtime from one pointer indirection, you have to live with the other downside.

      From my standpoint and experience, most compile time issues were due to people putting things into the headers out of convenience.
      In order to save some forward declarations or pimpl implementations, things were put into the header, which caused constant recompiles,and long compile times.

      --
      "Between strong and weak, between rich and poor [...], it is freedom which oppresses and the law which sets free"
    31. Re: Translation by kthreadd · · Score: 2

      GCC runs native on Windows. It's maintained by the mingw64 project and works really well.

    32. Re:Translation by gargleblast · · Score: 1

      ... sources ... on a RAM disk.

      Whenever anybody loses a fair chunk of a day's work due to a crash / power failure / other dumbass mistake, I always advise them "it's easier the second time around."

      Nobody ever appreciates the advice.

    33. Re:Translation by gargleblast · · Score: 1

      Oh yeah. Get an SSD.

    34. Re: Translation by Anonymous Coward · · Score: 1

      Wrong Adam, but he's right. Cheshire cats, pImpl, not pretending to know better than the compiler about inlining.

      Also not putting code in headers, making interfaces lean. Restricting the public interface, using simplex types in place of complex types at interface boundaries. Minimize compile file depth and preprocessor and object file sizes. Reduce dependency to maximize parallel build efficiency by utilizing more parallel compiles.

      Control structural entropy with active process and attention to detail. No hacking.

      These are the same processes that lead to highly testable and verifiable designs.

    35. Re:Translation by Darinbob · · Score: 4, Insightful

      Apple migrated over to Clang, but they left a bastardized GCC in it's place as a "transition". The preprocessor swears up and down that it's GCC but if you use inline assembler it barfs. So it's basically lying. It's a GCC front end and LLVM back-end, and the solution is to manually install a real GCC in its place (easier than porting the code, easier than ifdef OSX vs Linux, etc). And it's a major pain in the ass for new developers to set up a development environment, and inevitably someone eventually screws up their PATH to pick up the broken compiler...

      Anyway screw it. Clang may be ok, but there's production code that assumes GCC, it's cross-platform code so having stability on x86 doesn't necessarily mean anything about all those other CPUs that GCC supports well. Ie, GCC supports ARM, and ARM supports GCC, so if I go to the team and say "hey guys, I'm going to mix things up for a few months and try out a different compiler, things might break unexpectedly but in the long run you might like it, what do you think?" then I won't get positive feedback.

      Until there are drawbacks to GCC there's no much reason to change.

    36. Re:Translation by Darinbob · · Score: 2

      C++ (in GCC at least) is vastly slower than C, for the same input source. That's without doing the complicated stuff. You can speed a lot of with parallel builds, but a lot of people don't set up their build systems to make that easy (just passing -j to a recursive make can break).

      A decade ago I had an 18 hour build. So bad that people would start shouting if someone tweaked a major header file. Much of the slowdown was from the commercial compiler, and part of the slowdown was by using Visual Studio as a build system which called out to the external compiler. Swap to GCC+make and the build times got down to 20 minutes.

      Also for builds, don't forget the continuous builds that are common these days. Any source code change checked in kicks off a build. You want to see the results of that sooner than later, so you don't get the phone call a few hours later asking you to fix the build. Then the nightly builds will often rebuild every permutation of the project which can take a very long time.

    37. Re:Translation by Darinbob · · Score: 2

      Number 1 is important. The primary reason Apple is supporting Clang is that they got a snit over the new GPL license.

      Now Clang/LLVM do work on more than just PC architectures, but there aren't as many developers and users for them compared to GCC users. So the more users you have the more feedback, the more feedback the better the end product. Especially with something like ARM with lots of processor and instruction set variants you really want to make sure you're not inadvertently the beta tester for the compiler support for your chip.

    38. Re: Translation by Darinbob · · Score: 3, Funny

      I keep telling the users that, run the program correctly the first time and you shouldn't have to run it a second time!

    39. Re:Translation by jcr · · Score: 1

      I don't get daily crashes or power losses where I live. Do you?

      My usual work flow is to copy my project from the SSD to the RAM disk in the morning, work on it and commit changes periodically to my local Git repo. If I were paranoid like you apparently are, I could just add a commit action upon every successful build.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    40. Re:Translation by Anonymous Coward · · Score: 0

      I thought Clang would be cool. Then I realized how much work it would be to write a backend for my target architecture.
      When I found out about the typical memory usage I just stopped following the project.

    41. Re:Translation by Anonymous Coward · · Score: 1

      > I can't see any rational reason to prefer Gcc.

      1) Long term Freedom. The importance of which can not and should not be understated.

      And exactly how is it better for your freedom to avoid compiler with an actual free licence and stick to the one with a fascist "either you're with us or you're against us" mindset?

    42. Re:Translation by Anonymous Coward · · Score: 0

      You know that ARM maintains the LLVM port for ARM? Their own professional compiler is based on it, but they contribute back. So probably they will make sure it works.

    43. Re:Translation by Anonymous Coward · · Score: 0

      Studies find that interruptions (e.g. a phone call) cost an additional 15-20 minutes (on top of the interruption time, e.g. the duration of the phone call), before ones thoughts are fully back on solving whatever problem one was working on before the interruption.

      For me, any time I spend more than two seconds waiting for the computer is an interruption. Be that a slow compile, or a program being slow to start up.

    44. Re: Translation by loufoque · · Score: 1

      >us vs. them
      That guy is such an extremist and so out of touch with reality that it's actually a funny read.

    45. Re:Translation by TheRaven64 · · Score: 4, Insightful

      Apple, whose most profitable product lines all include ARM chips, has a large compiler team working on Clang and LLVM. Google, which doesn't ship any ARM products, but does have a huge investment in the ARM ecosystem, also employs a lot of people contributing to LLVM. They contributed most of the ARMv8 back end. ARM also has several large teams working on LLVM (I think that they've largely consolidated them now - they used to have separate C, OpenCL-ARM, and OpenCL-Mali teams all working largely independently on LLVM) and is now (as the other poster says) using LLVM for their proprietary toolchain (which is mostly expensive because of the debugging / tracing tools), so they're contributing a lot. There are a lot more ARM developers working on LLVM than clang. IBM has people working on PowerPC support, Imagination Tech on MIPS support. SPARC is largely volunteers these days, but Oracle seems to be killing SPARC as a thing anyone else might care about.

      --
      I am TheRaven on Soylent News
    46. Re:Translation by TheRaven64 · · Score: 2

      C++. For efficiency, you often need to put small methods in the headers. If they're templates, then you don't have an option if you want to share them between compilation units. Change a template in a header and you can easily trigger recompilation of a few hundred C++ files.

      --
      I am TheRaven on Soylent News
    47. Re:Translation by TheRaven64 · · Score: 1

      Have you benchmarked it recently? I tried this on our build machines (32 cores, 256GB of RAM, 512GB SSD split mostly as L2ARC with a small amount as log device, 3TB spinning rust in a ZFS mirror) a while ago. The amount of I/O that actually goes to the spinning rust is tiny (object files are written out, but never read back), pretty much all I/O comes from the buffer cache. Putting it on a RAM drive reduced the writes, but there's no synchronisation required for them so they never became a bottleneck. In a couple of cases (some of our builds produce about 40-50GB of object code), the RAM drive made things slower because now you had a copy in the buffer cache and a copy in the RAM drive, whereas previously the authoritative copy is on the spinning rust and the copy that you actually used was on the RAM drive, so using a RAM drive triggered swapping, whereas not using one just had some bursts of 100MB/s streaming writes to the disk.

      TL;DR: If you've got enough RAM, the OS should be able to satisfy reads from RAM irrespective of what the backing store is.

      --
      I am TheRaven on Soylent News
    48. Re: Translation by DrXym · · Score: 2
      It works really well for portable source code and where everything you link to comes from the same compiler. It's not so good if you're trying to link to some dynamic or static lib which was produced for MSVC because memory management and exception handling are incompatible. Unfortunately this happens quite a bit on Windows. IDE support isn't particularly good by comparison to MSVC either, particularly interactive debugging.

      Clang for Windows is taking an approach which is somewhat bizarre but could potentially achieve better compatibility with MSVC - you drop the clang binaries on a system which already has Visual Studio and it compiles code against the same headers and libs. As such it already supports a lot of VC++ extensions, keywords and name mangling. You can even run Visual Studio and develop against clang from there and run MSBuild with clang.

      The flipside, is if you have MSVC installed (a perfectly good compiler suite) then why earth do you need Clang? I think Clang needs to be a standalone package, perhaps using the MingW headers, even if it is capable of using MSVC headers / libs if you have them installed. Then someone can choose what level of compatibility they want.

    49. Re:Translation by TheRaven64 · · Score: 1

      GCC supports ARM, and ARM supports GCC

      ARM has a lot more people working on LLVM than they do on GCC and they're slowly transitioning everything across. Their customers fell into two categories: ones that don't care about the license and ones that won't touch GPLv3. If you want a compiler with long-term support for ARM, then GCC probably isn't your best bet.

      --
      I am TheRaven on Soylent News
    50. Re: Translation by DrXym · · Score: 1
      PImpls are a pain to maintain. This pattern might serve a purpose where you have an interface into your code that you expect other people to cleanly use your header without suffering all the stuff your impl needs. The flipside is if your class changes a lot or isn't that big, you suddenly have twice as much code to maintain and twice as many method signatures to modify each time they change.

      I wouldn't go anywhere near this pattern for self contained code.

    51. Re:Translation by Anonymous Coward · · Score: 0

      I would say not long enough.
      It is still way to easy to just see if it compiles, appears to work and ship.

      As a result the end user ends up with buggy code because the developer spent more time testing if it works rather than reading the code to see if it works.

    52. Re: Translation by Anonymous Coward · · Score: 0

      Every codebase I've ever seen over 15 years old. Probably any sufficiently large company has software skeletons in their closet.

    53. Re:Translation by Anonymous Coward · · Score: 0

      All this wonderful advice is like going to the doctor complaining it hurts when I lift my arm and him responding don't do that. More seriously any time spent fooling around with headers and compiler tricks instead of defining requirements, creating algorithms, data structures etc is wasted. Discussions like this merely show the immaturity of C++ tools which is quite remarkable considering the age of the language.

    54. Re: Translation by Anonymous Coward · · Score: 0

      What kind of programmer are you? I never compile my code, I only check it in.

      I know it compiles, no need to prove it!

    55. Re: Translation by Anonymous Coward · · Score: 0

      GCC runs on Windows, but not natively. mingw is an emulation layer. GCC requires an emulation layer to run on Windows. It is not portable code, as anybody who's ever tried to port it - or even compile it - can attest.

    56. Re:Translation by Anonymous Coward · · Score: 0

      Agreed 100%. Clang is certainly not *noticeably* slower to compile than gcc, and it's link time that dominates, not compile time, for all the projects I've worked on in the last few years (so a comparison of the linkers would be interesting).

      But Clang/LLVM is fully open, and approachable (have you ever read the gcc sources?!?!), and it uses modern compiler techniques from modern compiler books. Even if Clang lags behind gcc on some things, which I'm not even sure it does, but even if it does you can expect these things to resolve in Clang's favour over the next few years, barring a complete ground-up rewrite of gcc.

      Clang is also portable code, which gcc absolutely is not.

    57. Re:Translation by Anonymous Coward · · Score: 2, Insightful

      1) Long term Freedom. The importance of which can not and should not be understated.

      Except gcc doesn't give you that. The FSF keeps changing the goalposts on what constitutes "free" software (see GPLv2 vs GPLv3, for instance), and every time they do it, they lose developers who can no longer adapt to their ideology. Clang is FREE. Sure, someone might fork it, someone might embrace&extend it, this does not mean I will in the future be unable to use the Clang code I have on my hard-drive right now. And it's a compiler. It compiles code, to a standard. Lock-in is not an issue.

      You are pushing a concept of theoretical freedom which doesn't even give people the practical freedoms they actually need, against a different concept of freedom which is for all practical considerations completely unencumbered.

      Choose your compiler based on ideology if you like. The computer industry wasn't created on that basis, and doesn't work on that basis.

    58. Re:Translation by Anonymous Coward · · Score: 0

      "We won't make this obviously-useful architectural change because, although it will help our friends, it will also help our enemies."

      This is the logic by which we ban encryption.

      This is the logic by which we close down the internet.

      This is the logic of an extremist.

      Fuck Stallman, and fuck anyone who confuses the sanctimonious with the righteous.

    59. Re:Translation by DamonHD · · Score: 1

      Been there, done that (because of a sysamdin who thought that doing diagrams with pretty pictures was MUCH more important than doing backups for any of my team for many weeks, on one occasion) and you know what?

      You're right!

      Rgds

      Damon

      PS. Not that I advocate it as normal workflow for the sake of everyone's blood pressure for a start!

      --
      http://m.earth.org.uk/
    60. Re:Translation by Anonymous Coward · · Score: 0

      Yes, if you have dependencies, and you change a root, all dependents require updating. This is independent of computation substrate. It's the same for building texture files using procedural tools as it is for compiling GUI classes which rely on source code for underlying objects. But a container class holding a pointer to BaseClassA does not need recompiling. A GUI layer with custom widgets that talk to the data model using self-describing data formats does not need recompiling (see e.g. proto buffers, or even XML). Design dependencies out if you don't want to pay the cost of updating them.

    61. Re:Translation by Anonymous Coward · · Score: 0

      ... but design them as if they aren't.

    62. Re: Translation by Anonymous Coward · · Score: 0

      You are confusing mingw with cygwin

    63. Re:Translation by BlackHawk-666 · · Score: 1

      Given that's a massive proportion of all the markets I ever wish to program for, I will accept this terrible stricture and forge on in terrible silence.

      --
      All those moments will be lost in time, like tears in rain.
    64. Re:Translation by fche · · Score: 2

      "Clang is also portable code, which gcc absolutely is not." ... Er, gcc has been portable to cpu architectures and os platforms you probably haven't even heard of, in decades you perhaps weren't even born yet. It's probably one of the most portable pieces of software. (It pays for that in many ways.)

    65. Re:Translation by david_thornley · · Score: 1

      Optimization is almost certainly going to be better inside a translation unit than between two translation units. That could be important under certain circumstances. This is one of those cases where there may not be a good answer, but at least memory is cheap.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    66. Re:Translation by 0100010001010011 · · Score: 1

      which doesn't ship any ARM products

      Other than the Nexus product line.

    67. Re: Translation by spongman · · Score: 1

      i'd be interested to know how fast Clang compiles Petzond compared to msvc. including re-compiling with simple change with/without PCH & incremental linking enabled.

    68. Re:Translation by davester666 · · Score: 1

      whoosh.

      --
      Sleep your way to a whiter smile...date a dentist!
    69. Re:Translation by Darinbob · · Score: 1

      Does Apple care about ARM chips other than what's in their phones? Probably not. But still, Clang/LLVM is too new, if you want stability right now you stick to GCC instead of jumping ship because some PC users are in love with something else.

      In the embedded world it's a massive hassle to upgrade compilers even to a new version, you need buy off from everyone on the team, you still need to keep the old ones around to support older releases, you have to put the new tools on every dev and build machine, and you're never allocated any time to do this.

    70. Re: Translation by Darinbob · · Score: 1

      Hmm, what? GCC can be built natively on windows thus it is a native app, it can be built without cygwin libraries.

    71. Re: Translation by Anonymous Coward · · Score: 0

      Mingw is based on cygwin. It's a much lighter layer, but it's definitely not that different of a thing.

    72. Re:Translation by tepples · · Score: 1

      Then use smaller translation units for debug builds and larger ones for release builds. If you use a laptop or compact desktop for your debug builds, you may have to use a full-size desktop or server for release builds.

    73. Re:Translation by tepples · · Score: 1

      Sadly, there are many tests that pass when software is built with GCC but fail (sometimes even segfault) when the same software is built with clang.

      Have you reported each such test to the respective project's bug tracker?

    74. Re:Translation by tepples · · Score: 1

      First focus on quickly achieving correctness, and then add efficiency once the program is correct.

    75. Re:Translation by TheRaven64 · · Score: 1

      That's fine, as long as your program never has any changes to the requirements after the 1.0 release. i.e. in no code ever.

      --
      I am TheRaven on Soylent News
    76. Re:Translation by TheRaven64 · · Score: 1

      Does Apple care about ARM chips other than what's in their phones?

      No, but that still covers ARMv7 and ARMv8. The amount of microarchitectural tuning for specific cores within these families is a very small part of the code. And, as I said, Apple is not the only company throwing resources at the ARM back end. Google and ARM are both spending a lot of resources improving LLVM. So is Qualcomm, so is Linaro, and so is Samsung.

      But still, Clang/LLVM is too new

      You realise that LLVM is over a decade old and Clang is almost this old? And that both are more actively developed than GCC and have been for the last few years? How old does a compiler have to be before it is not 'too new' in your estimation?

      if you want stability right now you stick to GCC instead of jumping ship because some PC users are in love with something else.

      By 'some PC users', I presume you mean the toolchain group and senior management at ARM Ltd.? You know, the ones who have replaced ARMcc with Clang in their toolchain and are recommending LLVM for all of their customers?

      --
      I am TheRaven on Soylent News
    77. Re:Translation by david_thornley · · Score: 1

      So I test something different from what I put into production? Nothing could possibly go wrong that way, yes.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    78. Re:Translation by tepples · · Score: 1

      Perform early testing, while the program is under rapid development, with smaller translation units, and later testing, after most of the functionality has become stable, with larger translation units. That's not the same as shipping untested binaries. Also run both the program with smaller translation units and the program with larger translation units in parallel, and consider it a defect if there is any difference in behavior between the two other than execution time.

    79. Re:Translation by Anonymous Coward · · Score: 0

      rationalize the fact that you are a common street hooker if you want. you're a skanky dinosaur and your days are numbered.

  2. Or compile on everything by Anonymous Coward · · Score: 3, Insightful

    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.

  3. Strongly recommend Clang by Anonymous Coward · · Score: 3, Informative

    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.

    1. Re:Strongly recommend Clang by lgw · · Score: 1

      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.

      Last time I looked, Clang didn't recognize idiomatic "rotate", e.g.:
      (x << 3) | (x >> 29)
      That should compile to a single opcode, dammit. Anyone know if that problem is still there.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    2. Re:Strongly recommend Clang by angel'o'sphere · · Score: 1

      On what processor would that be a single opcode? I'm curious.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    3. Re:Strongly recommend Clang by flargleblarg · · Score: 2

      Actually, that should compile to a single opcode only if x is a 32-bit unsigned integer.

    4. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      At the very least, x86 (therefore also amd64) and 68k. Even most RISC architectures have a rotate instruction because they tend to have 32 bits wide instructions so two shifts, an or, and a temporary register is a lot of fluff in the instruction stream.

    5. Re:Strongly recommend Clang by nctritech · · Score: 2

      Assuming 'uint32_t x' and ignoring any needed shuffling to load 'x' into the appropriate processor register, any 32-bit processor with a native bit rotation instruction.

    6. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      That's equivalent to ROR on x86, isn't it?

    7. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0


      $ cat lgw.c
      unsigned int rot(unsigned int x) {
          return (x << 3) | (x >> 29);
      }
      $ clang-3.5 -O2 lgw.c -S -o -
      rot:
                      roll $3, %edi
                      movl %edi, %eax
                      retq

      Some redactions applied due to /.'s comment filter. Looks like the problem is not still there.

    8. Re:Strongly recommend Clang by mikael · · Score: 1

      You can put function calls inside a switch statement but outside the case statements in gcc. Does that happen in Clang? Even old Borland C++ compilers from 1990's would catch that one.

      --
      Vintage computer adverts: http://www.vintageadbrowser.com/computers-and-software-ads
    9. Re:Strongly recommend Clang by Anonymous Coward · · Score: 2, Informative

      $ cat rol3.c

      #include <stdint.h>
      uint32_t rol3(uint32_t x) {
          return (x << 3) | (x >> 29);
      }

      $ gcc -c rol3.c
      $ objdump -d rol3.o

      0000000000000000 <rol3>:
        0: 55 push %rbp
        1: 48 89 e5 mov %rsp,%rbp
        4: 89 7d fc mov %edi,-0x4(%rbp)
        7: 8b 45 fc mov -0x4(%rbp),%eax
        a: c1 c0 03 rol $0x3,%eax
        d: 5d pop %rbp
        e: c3 retq

      $ gcc -O1 -c rol3.c
      $ objdump -d rol3.o

      0000000000000000 <rol3>:
        0: 89 f8 mov %edi,%eax
        2: c1 c0 03 rol $0x3,%eax
        5: c3 retq

      $ clang -c rol3.c
      $ objdump -d rol3.o

      0000000000000000 <rol3>:
        0: 55 push %rbp
        1: 48 89 e5 mov %rsp,%rbp
        4: 89 7d fc mov %edi,-0x4(%rbp)
        7: 8b 7d fc mov -0x4(%rbp),%edi
        a: c1 e7 03 shl $0x3,%edi
        d: 8b 45 fc mov -0x4(%rbp),%eax
        10: c1 e8 1d shr $0x1d,%eax
        13: 09 c7 or %eax,%edi
        15: 89 f8 mov %edi,%eax
        17: 5d pop %rbp
        18: c3 retq

      $ clang -O1 -c rol3.c
      $ objdump -d rol3.o

      0000000000000000 <rol3>:
        0: c1 c7 03 rol $0x3,%edi
        3: 89 f8 mov %edi,%eax
        5: c3 retq

      tl;dr: gcc uses the rol instruction with default -O0, but clang doesn't use it until you turn on -O1.

      Your comment has too few characters per line (currently 18.1).Your comment has too few characters per line (currently 18.7).Your comment has too few characters per line (currently 19.6).Your comment has too few characters per line (currently 20.6).Your comment has too few characters per line (currently 21.6).Your comment has too few characters per line (currently 22.5).

    10. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      I've actually done test, using this piece of code vs. using the rotate intrinsic function.

      The single rotate instruction is slower than the bunch of instruction that this code generates. I am guessing that since rotate has not been emitted by compilers for a long time, intel decided to implement rotate instructions as backward compatible emulated instructions.

      Did you know that when using floating point x87 instructions and one of the operants is an infinite, denormal or nan, that you get an emulated instruction? Normal float instructions (when pipelined) execute 1 instruction per clock cycle; when one of the operants is special that instruction will take many hundreds of clock cycles.

      SSE is a bit better, since these instructions are maintained (gcc and clang emit SSE instructions instead of x87 instructions for quite a few years now), still don't use denormals, infinite or nan, there are still performance issues.

      https://randomascii.wordpress.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/

    11. Re:Strongly recommend Clang by serviscope_minor · · Score: 1

      fussy? What do you mean? They both pretty much support the entire standard very well. If gcc is failing to accept code, you're probably doing something non standard tha clang has as an extension.

      --
      SJW n. One who posts facts.
    12. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      For any type with a size less than 29 bits the behavior is undefined. The compiler is free to remove the x >> 29 and then it should still be a single instruction.
      For signed types it is implementation defined. The compiler can still do it as a single instruction but doesn't have to.
      That is, according to ISO/IEC 9899 the compiler may handle any right shifts as unsigned (Or keep the 29 top bits unchanged) as long as it specifies this behavior.

    13. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      Have you tried turning on -ansi?
      C allows extension and leaves a lot implementation defined. As long as it compiles code that is ISO-C compliant it doesn't matter what it does with code that isn't.

    14. Re:Strongly recommend Clang by BlackHawk-666 · · Score: 1

      SHL and SHR...been a long time since I used them, but pretty sure they will still be around.

      --
      All those moments will be lost in time, like tears in rain.
    15. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      The single rotate instruction is slower than the bunch of instruction that this code generates. I am guessing that since rotate has not been emitted by compilers for a long time, intel decided to implement rotate instructions as backward compatible emulated instructions.

      Intels own documentation disagrees. Anything Core2 or newer can execute 2 32 or 64 bit rotates per clock. I'll believe intels own microarchitecture docs over a unproven claim by AC.

      Did you know that when using floating point x87 instructions and one of the operants is an infinite, denormal or nan, that you get an emulated instruction? Normal float instructions (when pipelined) execute 1 instruction per clock cycle; when one of the operants is special that instruction will take many hundreds of clock cycles.

      x87 is legacy, might as well start complaining that real mode and virtual 8086 mode have been getting slower on modern uarchs...

    16. Re:Strongly recommend Clang by angel'o'sphere · · Score: 1

      You missed the parent:
      He claimed that instant of
      LDC R1 #value1
      LDC R2 #value2
      SHR R1,something
      SHL R2,something
      OR R3,R1,R2

      You can do the above in a single opcode ... it is beyond me how he would do that or if that is possible because the constants in his example are "special".

      Assuming the registers R1 and R2 already hold the values in question: you need minimum 3 opcodes or a special architecture like ARM, but on an ARM I believe you minimum would need 2 opcodes.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    17. Re:Strongly recommend Clang by angel'o'sphere · · Score: 1

      But you fail to give an example ;D
      Which opcode, on an x86 e.g. can rotate left and right simultaniously and OR the two results together: simultaniously? Feel free to pick a different architecture. Not even on an ARM you can do that in one opcode.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    18. Re:Strongly recommend Clang by nctritech · · Score: 1

      I see the problem. GP didn't write the complete bitwise rotation idiom but I knew what they meant whereas you're evaluating it exactly as written. This is what I'm referring to and what GP was almost certainly trying to refer to as well. https://en.wikipedia.org/wiki/...

    19. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      Even on x86 architecture you have ROR/ROL, if you are already using x, then x would generally be contained in a register. So as a 32-bit instruction, he could use ROL EAX, 3. These instructions have been around at least since 486. These same instructions are available to arm architectures as well. Using rotates (rather than multiple shifts, ors, and possibly ands) speeds up certain parts of encryption and hashing. Its kind of crazy that they don't have a rotate operator though.

    20. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      Not for x86 systems. Although it does use the ROL if its 32 bit without optimization, but with a -O1, and using uint16_t, it compiles to "rol $0x3,%ax", which is correct for a 16-bit rotate

    21. Re:Strongly recommend Clang by angel'o'sphere · · Score: 1

      Ah, I'm coming closer to it. But I have not grasped it yet.
      I shift left 3 times and or the result with the same register shifted right 29 times, both together is a rotate? Never thought about that. I have to test that on paper, does not really look plausible on the first attempt.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    22. Re:Strongly recommend Clang by nctritech · · Score: 1

      Sounds like you've got the gist of it. C only has a bitwise shift (where the end that the shift would "empty" is filled with zeroes for unsigned integers), not a bitwise rotate (ex. 00001011 rotated right by 2 becomes 11000010), so the closest thing to saying "bitwise rotate this" is using a set of expressions that would have the same behavior. Since a bitwise rotate is the same as splitting the binary number into two parts (of sizes determined by the desired rotation amount) you just have to create the two split numbers, then OR them back together. The Wikipedia example tries to be somewhat universally workable (using CHAR_BIT, sizeof(), etc. to make it work with virtually any unsigned integer type without modification) which is why it's a bit confusing. A simplified example:

      If the value in a variable 'uint8_t x' is 10010011 and you want to bitwise rotate it right by 3 bits (to yield the result 01110010), you need to first derive the partial values [000]10010 and 011[00000], then OR them together.

      The right-shift operator '>>3' will create the [000]10010 for us without any extra work.

      We can generate the 011[00000] by doing a left shift '<<5' in the same way but with the reverse number of bits (calculated as BIT_WIDTH_OF_TYPE - left_shift_count to get 8 - 3 = 5).

      Thus, 'x right-rotated by 3' for an 8-bit unsigned integer can be stated most simply (and inflexibly) in C as (x << 3) | (x >> 5), and the compiler will recognize the "two opposite shifts with a total shift of the variable type width ORed together" and emit a single bitwise rotate instruction (like 'r1 ROR r2') for the actual work rather than "load to r1; rotate r1; load to r2; rotate r2; r2 OR r1." Any unsigned integer can be rotated in the same way. Relevant x86 assembly: https://en.wikibooks.org/wiki/...

      Does that help?

    23. Re:Strongly recommend Clang by lgw · · Score: 1

      ROR ROL

      Those are the x86 "rotate" instructions. They work like SHR and SHL, except the "rotate back in" the bits that were shifted out. They're important for a variety of CRC, RNG, and crypto coding.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    24. Re:Strongly recommend Clang by lgw · · Score: 1

      Awesome, please mod up. That's a great, detailed answer.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    25. Re:Strongly recommend Clang by angel'o'sphere · · Score: 1

      I know what ROR and ROL is, facepalm.

      But I don't graps (and I did not dig into it, yet) why an SHL 3 and SHR 29 should be a rotate left if the results are ored together. It is not visible to me ... but as written in another post, I make me a paper example and see how it works :D

      And: assuming the compiler grasps that means: you assume the programmer of the compiler has put a special "if" somewhere in the code just looking for this idiom.
      However, it is beyond me, why C/C++ has not introduced tripple less and triple greater for ROL and ROR as Java e.f for ROL.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    26. Re:Strongly recommend Clang by Anonymous Coward · · Score: 0

      FYI: angel'o'sphere (80593) is a notorious troll.

      YHBT

    27. Re:Strongly recommend Clang by nctritech · · Score: 1

      I'm completely fine with trolls as long as they're not trolling me very hard. ;-) There is often a fine line between trolling and innocent asking of questions regarding something the asker isn't familiar with. Also, a lot of C programmers don't ever have to write code that uses bitwise rotation (for example, I'd be surprised if there were bitwise rotations in a text editor or a text processing program), so even if I got trolled the information may get someone else's mental gears cranking.

    28. Re:Strongly recommend Clang by nctritech · · Score: 1

      C/C++ are slow to evolve. It looks like at least this one proposal to add the various rotation operators to C/C++ has been authored and it has lots of good information. Your working example of "SHL 3 OR SHR 29 = ROL 3" is obvious when you scribble it on paper: a left rotate is a left shift where the bits that get pushed off the left and "discarded" instead appear on the right in the same order they fell off, so the 32-bit number 10000000000000000000000000000000 -> ROL 3 -> 00000000000000000000000000000100. Picture an arrow going from the "fall off" side back around to the "shift in zeroes" side you're used to seeing with the << operator and it makes more sense.

      As for how the compiler "just knows" that this specific construct should become a ROL/ROR instruction, it's not that the compiler has a "special IF" statement on the front-end, but rather has to do with how compilers convert source code into object code. When the compiler breaks down our rotation idiom, it sees it as a series of simpler distinct steps with anonymous temporary variables, and a built-in optimizer can recognize the rotation sequence from there. This is what the compiler sees (see three-address code) when it converts the expression '(x > 29)' into its component parts:

      t1 := x << 3
      t2 := x >> 29
      t3 := t1 | t2

      Even a simple peephole optimizer can easily spot this short sequence of fundamental operations (left shift + right shift, the shift amounts equal the width of the variable type, ORed together -> ROL) and convert it to something like:

      t1 := x ROL 3

      ...which is extremely simple to convert to assembler as i.e. ROL 3, EAX. One more important thing about rotations: if you rotate by the width of the unsigned integer type you're working with, you'll get the exact same number, and for any integer X of given width W,

      X ROL n == X ROR (W - n)

      So ROL 3 and ROR 29 are identical operations when performed on a 32-bit wide integer. That's part of why the C idiom works: a shift is a "rotate" that throws away the bits that "fall off" and zeroes the bits that would be missing, so by ORing two exactly opposing shifts together, you are manually grafting the bits that fell off one side back onto the other side.

  4. What do they mean by speed? by BitterOak · · Score: 1

    When people say gcc beats clang on speed, so they mean compile speed or run-time speed?

    --
    If I can be modded down for being a troll, can I be modded up for being an orc, or a balrog?
    1. Re:What do they mean by speed? by Chris+Mattern · · Score: 4, Funny

      If I can be modded down for being a troll, can I be modded up for being an orc, or a balrog?

      Nope, those still get you modded down. To be modded up, you'll need to be an elf or a hobbit...

    2. Re:What do they mean by speed? by Anonymous Coward · · Score: 0

      The primary consideration is run-time speed. No? Then why aren't you using an interpreted language?

    3. Re:What do they mean by speed? by Anonymous Coward · · Score: 0

      gcc generates faster code.
      clang generates code faster.

    4. Re:What do they mean by speed? by Anonymous Coward · · Score: 0

      Compile speed. GCC-compiled code is usually a little faster at runtime (and sometimes quite a bit faster).

    5. Re:What do they mean by speed? by Anonymous Coward · · Score: 0

      Mod "-1 Hates the Bagginssesss"

    6. Re:What do they mean by speed? by BitterOak · · Score: 1

      If I can be modded down for being a troll, can I be modded up for being an orc, or a balrog?

      Nope, those still get you modded down. To be modded up, you'll need to be an elf or a hobbit...

      I hear you can also get modded up for being an ent, but it can take years.

      --
      If I can be modded down for being a troll, can I be modded up for being an orc, or a balrog?
  5. Neat thing by mveloso · · Score: 1

    One neat thing about LLVM/clang is that theoretically you could provide your application as IR files, which can be flattened to machine-specfic code on the fly by a platform-specific backend.

    I think at some point it was fast enough to generate that code on the fly. I vaguely remember Apple doing that with its OpenGL stuff.

    1. Re:Neat thing by sribe · · Score: 1

      I vaguely remember Apple doing that with its OpenGL stuff.

      CoreImage transforms.

    2. Re:Neat thing by Pseudonym · · Score: 1

      I think at some point it was fast enough to generate that code on the fly.

      Many interpreters are embedding LLVM for JIT these days.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    3. Re:Neat thing by PhrostyMcByte · · Score: 1

      One neat thing about LLVM/clang is that theoretically you could provide your application as IR files, which can be flattened to machine-specfic code on the fly by a platform-specific backend.

      Is this a relatively new feature? The last time I looked at LLVM IR for this purpose, there was no general "pointer-sized" data type that could accomplish this. It would be really cool if this were no longer the case.

    4. Re:Neat thing by complete+loony · · Score: 1

      Chrome's PNaCl defines a stable sub-set of LLVM IR, targeting a generic little-endian 32-bit CPU.

      --
      09F91102 no, 455FE104 nope, F190A1E8 uh-uh, 7A5F8A09 that's not it, C87294CE no. Ah! 452F6E403CDF10714E41DFAA257D313F.
    5. Re:Neat thing by Anonymous Coward · · Score: 1

      They also use it to shrink iOS app distribution. Developers upload IR code to the app store, the app store dynamically recompiles for the user's device and pushes down a custom binary.

    6. Re:Neat thing by TheRaven64 · · Score: 1

      The grandparent is partly right. You can do this for microarchitectural optimisations. I believe that Apple now does this for their app store: if you upload the app as LLVM IR then they will generate versions specialised for each of the ARM cores that they've shipped. This can be quite a big difference (costs of different vector operations on different cores means that you can have quite different decisions in the autovectoriser, for example). You can't do it for different architectures, even if LLVM IR were perfect for the task, if you start with a C-like language. By the time that you've run the C preprocessor, your source code is no longer architecture agnostic. Things like va_list, intptr_t and htons are defined in such a way that encodes pointer size, endian, and variadic calling convention. Things like jmpbuf and ucontext_t encode the architecture fairly precisely.

      --
      I am TheRaven on Soylent News
  6. Use both by Anonymous Coward · · Score: 2, Interesting

    To make sure my code is not using any compiler features I compile my code on both.

  7. Write portable, compile with whatever... by Anonymous Coward · · Score: 0

    ...is available. It's not that hard and it's good practice in any case. So long as whatever compiler is available works, who cares about the specifics?

    If you have stuff that depends on compiler oddness and can't be removed/rewritten then just coral that into as small an area as possible and hedge it if #ifdefs.

  8. Intermediate formats by unixisc · · Score: 1

    Does Clang compile to intermediate formats, such as Bytecode or any other formats? On the GCC side, I believe that the FSF (read RMS) is opposed to it

    1. Re:Intermediate formats by KiloByte · · Score: 1

      You mean, like GIMPLE?

      --
      The creatures outside looked from Alt-Right to Antifa; but already it was impossible to say which was which.
    2. Re:Intermediate formats by dmoen · · Score: 2

      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.
    3. Re:Intermediate formats by Anonymous Coward · · Score: 0

      GCC does emit a link-time optimizer intermediary format in the object files when -flto is used. It's version-specific of course exactly for the same reason as why Linux doesn't support a stable kernel API for modules.

    4. Re:Intermediate formats by TheRaven64 · · Score: 1

      LLVM "IR" format, which is a mostly machine-independent Intermediate Representation

      LLVM IR is target agnostic, not target independent. The format itself is the same across all targets, but various things (e.g. calling conventions - how you split structs between registers and the stack) will be different for different targets.

      --
      I am TheRaven on Soylent News
    5. Re:Intermediate formats by Anonymous Coward · · Score: 0

      mostly machine-independent Intermediate Representation

      It already contains assumptions about endianness, word size, memory alignment restrictions and calling conventions.
      On what planet is that "mostly machine-independent"?

  9. License by danbob999 · · Score: 2

    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.

    1. Re:License by dmoen · · Score: 4, Informative

      No, LLVM/clang is all about having a superior architecture to GCC, so that a lot of new applications become possible. One of the key ideas is that the optimizer and code generator are libraries with a C++ API. One cool application of this is that you can use the LLVM library to implement a JIT compiler for your interpreted language: you generate the machine code directly into memory (instead of to a file), then execute it.

      LLVM has many more developers than GCC, and is evolving and improving more quickly than GCC can. This is because of the licence: it turns out that corporations like Apple are more willing to provide developer resources for this open source project if the licence isn't copyleft. For this particular project, this means that the BSD license is more successful than the GPL. Of course, there are other projects for which the GPL produces better results in the real world.

      If you want to make a GPL fork of LLVM just for the pure pleasure of fucking over the original project due their heresy in choosing a license you don't approve of, well, good luck with that.

      --
      I have written a truly remarkable program which this sig is too small to contain.
    2. Re:License by Anonymous Coward · · Score: 0

      Why would you want a GPLed fork? The current compiler is in a state where you're getting huge amounts of commits from major corporations (primarily Apple, but also Google and some others). Moving a fork to GPL would only get you them not playing nicely with you, while they are playing nicely today.

      Seems like a lose lose situation.

    3. Re:License by Anonymous Coward · · Score: 1, Insightful

      JIT compiled binaries are no good for the end user. For fucks sake, distribute native binaries for your shit.

    4. Re:License by phantomfive · · Score: 4, Interesting

      This is because of the licence: it turns out that corporations like Apple are more willing to provide developer resources for this open source project if the licence isn't copyleft.

      That's not really true, Apple contributed to GCC for years before LLVM. The problem was that Apple wanted features, and GCC wouldn't allow those features to be built. So finally Apple just gave up and built their own.

      This is the rule of running an open source project (and Linus does a really good job of it): give users what they want, or the users will leave.

      --
      "First they came for the slanderers and i said nothing."
    5. Re:License by Anonymous Coward · · Score: 0

      That's not really true, Apple contributed to GCC for years before LLVM. The problem was that Apple wanted features, and GCC wouldn't allow those features to be built. So finally Apple just gave up and built their own.

      Let's not forget that originally, Steve Jobs tried to screw over the GCC project by making a proprietary closed-source fork of it.

    6. Re:License by tlhIngan · · Score: 3, Informative

      This is because of the licence: it turns out that corporations like Apple are more willing to provide developer resources for this open source project if the licence isn't copyleft.

      That's not really true, Apple contributed to GCC for years before LLVM. The problem was that Apple wanted features, and GCC wouldn't allow those features to be built. So finally Apple just gave up and built their own.

      This is the rule of running an open source project (and Linus does a really good job of it): give users what they want, or the users will leave.

      True, but Apple could also see the writing on the wall with the GPLv3 and what that could mean to their use of the compiler. Which is also why they poured a lot of effort into LLVM and wrote clang. This effort dated way back too - the earliest versions of OS X that started coming out with LLVM as an option was around the 10.4 era.

      A lot of companies saw what the GPLv3 was bringing to the table, and they didn't like it, so they moved on. Some, like Apple, realized they could stick around and fight with GCC and GPLv3, or work on an alternative.

      GCC is deliberately obtuse as well - Apple wanted a nice front end to help parse and recompile code in real time, and GCC is intentionally twisty to prevent that (and if you want to write a parser for code, why not reuse what the compiler actually uses?). LLVM is more modular and makes it easier to integrate with an IDE

      And in the end, I think having the diversity we do in compilers is refreshing - even if you hate LLVM with a passion, at least it's also brought forth development on GCC, which seems to have a history of stalling in development before someone else decides to fork it, revamp things, and have the fork become the official GCC.

      FYI - the very last checkin to GCC by Apple was related to Grand Central Dispatch to the Obj-C compiler - basically about blocks.

    7. Re:License by Anonymous Coward · · Score: 0

      Let's not forget that originally, Steve Jobs tried to screw over the GCC project by making a proprietary closed-source fork of it.
      Flag as Inappropriate

      No, he didn't.

      He tried to claim that NeXT's own code in the Objective-C front end was proprietary. He was more than happy to distribute the rest of GCC freely, but wanted to keep Objective-C closed. He failed.

    8. Re:License by Bananenrepublik · · Score: 1

      Let's not forget that originally, Steve Jobs tried to screw over the GCC project by making a proprietary closed-source fork of it.
      Flag as Inappropriate

      No, he didn't.

      He tried to claim that NeXT's own code in the Objective-C front end was proprietary. He was more than happy to distribute the rest of GCC freely, but wanted to keep Objective-C closed. He failed.

      Which is exactly the same thing as the OP said, once one uses precise language: the GPL's requirements also apply to the Objective C frontend precisely because the compiler as a whole is a single program (program = "copyrightable work licenced under this license").

    9. Re:License by Anonymous Coward · · Score: 0

      A GPL fork of LLVM would be pointless. One of the reasons GCC is considered so badly designed is a maintainer driven attempt to protect it from inclusion in any form of proprietary toolchain well beyond the protections its license offers. With clang anyone can insert a fully proprietary step into the workflow, putting it under GPL would not change that and changing the API to protect against this leads you straight to GCC. Also GCC has the open promise to break any API "misused" for proprietary code or otherwise unwanted features or just to use the influence some members of the community have (RMS) to downright make your life miserable until you either give up or start to agree with their vision of free software (TM).

    10. Re:License by Anonymous Coward · · Score: 0

      > That's not really true, Apple contributed to GCC for years before LLVM.

      Nonsense. It's Steve Jobs's ghost, which is still butthurt with the Objective C debacle at NeXT. Once GNU switched to GPLv3, Apple has either kept the old versions or replaced the GNU thingies, their users be damned.

      That's why, as an Apple user you get an old bash and an old Emacs.

    11. Re:License by Anonymous Coward · · Score: 0

      "development" on GCC? Huh? Does "development" of GCC these days consist of anything other than backporting improvements from LLVM and slapping GPLv3 on them?

    12. Re:License by Anonymous Coward · · Score: 0

      huge amounts of commits from evil corporations

      FTFY

    13. Re:License by TheRaven64 · · Score: 1

      The problem was that Apple wanted features, and GCC wouldn't allow those features to be built. So finally Apple just gave up and built their own.

      This was not the issue. Apple maintained their own branch of GCC in the FSF's svn repository for a long time. Lots of features (e.g. blocks support, some Objective-C features) never made it back into the FSF's branch, but this was not a problem for Apple. The problem was that GCC could not be used, for both technical and legal reasons, in some of the places where Apple wanted to use it. Syntax highlighting was one simple example. GCC does constant folding in the front end, so by the time that you have anything like an AST, you can't distinguish between 3+4 and 7 in the source code - that made working out how to colour the tokens difficult. Even if this were addressed, you could only embed GCC in a GPLv3 IDE, and Apple didn't want to have to release XCode under GPLv3.

      --
      I am TheRaven on Soylent News
    14. Re:License by TheDarkMaster · · Score: 1

      Why GCC is deliberately obtuse?

      --
      Religion: The greatest weapon of mass destruction of all time
    15. Re:License by Anonymous Coward · · Score: 0

      See this:- https://gcc.gnu.org/ml/gcc/2014-01/msg00247.html
      Basically, gcc is "deliberately obtuse" to prevent its partial incorporation into non-free systems.
      This is the GNU disease. See also the forced dependancies on Gnome, eg the gtkhtml widget. Or everything-and-its-cat now depending on systemd.
      "If we can't persuade you with the quality of our code, we'll trap you in a maze of twisty inter-dependancies."

    16. Re:License by Anonymous Coward · · Score: 0

      That the front end was part of a "single program" is exactly what Jobs disputed, which is why he thought it didn't have to be GPL'd.

      Saying this is a "proprietary, closed-source fork" of GCC is a gross misrepresentation of what happened.

    17. Re:License by BitZtream · · Score: 1

      Apple started LLVM due to GPL v3. If you know anything about why they switched, that much is obvious ... being that they flat out said thats why they were switching among other things.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    18. Re:License by Anonymous Coward · · Score: 0

      What makes them evil? The reason most people think they're "evil" is because they "don't give anything back to the community". Here we have good evidence that these guys want to be good open source citizens... Just the license needs to be right for them to be able to do it.

    19. Re:License by devent · · Score: 1

      You have cherry picked one comment from Richard Stallman, which was just his personal ideology. David Edelsohn replied this:
      https://gcc.gnu.org/ml/gcc/201...

      GCC is working toward re-factoring its code base toward a more
      compositional approach for "toolification". One can look at
      presentations from the recent GNU Cauldron 2013 for discussion of the
      topic. David Malcolm also has created patches for the GCC backend to be used as a JIT.
      The assertions that FSF policy prevents technical development and
      innovation simply is not true.

      Maybe GCC was "deliberately obtuse", but as I see it, steps are taken to change that and enhance GCC for tool chains and to be used a library just as LVMM is.

      --
      http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
    20. Re:License by Anonymous Coward · · Score: 0

      This is because of the licence: it turns out that corporations like Apple are more willing to provide developer resources for this open source project if the licence isn't copyleft.

      That's not really true, Apple contributed to GCC for years before LLVM. The problem was that Apple wanted features, and GCC wouldn't allow those features to be built. So finally Apple just gave up and built their own.

      This is the rule of running an open source project (and Linus does a really good job of it): give users what they want, or the users will leave.

      Apple wanted control. Imposing features is a byproduct of dominating and controlling an Open Source project. Apple (and Google) prefer projects that they can control while maintaining the patina of Open Source legitimacy.

      Businesses want to reduce risk and increase control of their destiny, and this decision was justified by their corporate requirements and culture. One should not retroactively justifying a business decision as a technical or philosophical decision.

    21. Re:License by Anonymous Coward · · Score: 0

      If you want to make a GPL fork of LLVM just for the pure pleasure of fucking over the original project due their heresy in choosing a license you don't approve of, well, good luck with that.

      I'd do it just for the pleasure of annoying someone who gets swearing mad when he thinks about someone doing something explicitly permitted by the license.

    22. Re:License by Tough+Love · · Score: 1

      It seems to be exactly what happened. A "front end" is clearly a "derived work".

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    23. Re:License by Tough+Love · · Score: 1

      Does "development" of GCC these days consist of anything other than backporting improvements from LLVM and slapping GPLv3 on them?

      It certainly does, however you draw attention to one of the principal superpowers of copyleft.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    24. Re:License by Anonymous Coward · · Score: 0

      Okay, so you're saying that because Jobs was wrong about it not being a derived work, he didn't argue that it wasn't a derived work. Thanks for clarifying.

    25. Re:License by Tough+Love · · Score: 1

      huh?

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    26. Re:License by Anonymous Coward · · Score: 0

      Here it is RMS's own words:

      "The issue first arose when NeXT proposed to distribute a modified GCC in
      two parts and let the user link them. Jobs asked me whether this was
      lawful. It seemed to me at the time that it was, following reasoning
      like what you are using; but since the result was very undesirable for
      free software, I said I would have to ask the lawyer.

      "What the lawyer said surprised me; he said that judges would consider
      such schemes to be "subterfuges" and would be very harsh toward
      them. He said a judge would ask whether it is "really" one program,
      rather than how it is labeled.

      "So I went back to Jobs and said we believed his plan was not allowed
      by the GPL.

      "The direct result of this is that we now have an Objective C front
      end. They had wanted to distribute the Objective C parser as a
      separate proprietary package to link with the GCC back end, but since
      I didn't agree this was allowed, they made it free."

      So Jobs asked if it was okay to do this, and when the answer came back "no," he released their front end under GPL. It sounds to me like NeXT went out of their way to respect the GPL.

    27. Re:License by Tough+Love · · Score: 1

      Anybody with a clue could have told Jobs the same thing, and he did end up respecting the GPL then he did nothing more than respect the law.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    28. Re:License by gerddie · · Score: 1

      Depends, for instance llvm is used as GLSL compiler, and hence, it can select the target platform based on the available hardware. Likewise POCL uses LLVM to compile OpenCL kernels optimized for the hardware the kernels are supposed to run on.

    29. Re:License by gerddie · · Score: 1

      Or everything-and-its-cat now depending on systemd.

      It is interesting that you bring up systemd in a GPL discussion. Their was some discussion about how the IPC infrastructure of systemd can effectively be used to circumvent the GPL by providing a GPL wrapper to a GPL library/program that provides a RPC interface and then use this interface from a non-free program remotely. Since no direct linking is involved, this is actually legal, and the a legal way to prevent this is licensing the code under the AGPL

    30. Re:License by Anonymous Coward · · Score: 0

      In that case, even RMS didn't have a clue, because he initially said it was okay.

  10. Mixed backend languages is recipe for subtle bugs by Ungrounded+Lightning · · Score: 2

    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
  11. How does that work for Rust? by Anonymous Coward · · Score: 0

    While C, C++ and even Objective-C have multiple implementations, how the fuck are we supposed to do that with a language like Rust, where there is only one implementation?!

    1. Re:How does that work for Rust? by Anonymous Coward · · Score: 0

      I think the OP means portability as in writing to a standard... In C you have ANSI C, ISO C, C99 and now C11. I try my best to write C code to the ANSI C standard as it is the most portable, being the oldest. GCC and Clang have the __builtin_expect() function, but only Clang has __has_include() or __has_feature(), for example. None of those are available when compiling with MSVC, though.

  12. Developing in C/C++ by Anonymous Coward · · Score: 1

    First of all, C and C++ are two different and separate languages.

    Second of all, if you are developing in either C or C++, you should develop in a different language.

    1. Re:Developing in C/C++ by HiThere · · Score: 1

      Second of all, if you are developing in either C or C++, you should develop in a different language.

      Depends on what you're doing. There are purposes for which C is the optimal language. I suspect that there are also purposes for which C++ is the optimal language. (In neither case can the purpose include handling unicode strings.)

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    2. Re: Developing in C/C++ by Anonymous Coward · · Score: 0

      The only language with decent handling of Unicode strings is Perl 6, with its built-in Normalization Form G, where every grapheme gets a single, unique code point. It can even roundtrip poorly formed Unicode strings.

    3. Re:Developing in C/C++ by epyT-R · · Score: 1

      Oh. What language is that? javascript?

    4. Re:Developing in C/C++ by Anonymous Coward · · Score: 0

      What's the problem with Unicode in C? ICU is used by a lot of projects and I don't see anyone complaining.

    5. Re:Developing in C/C++ by Anonymous Coward · · Score: 0

      The obvious example for C++ is if you are developing changes in an existing C++ codebase.

      The obvious example for C is code with multiple language bindings, because almost everything binds against C; or for a target that doesn't have many high-level languages, eg. certain embedded scenarios.

      When I see these blanked statements, what I really want is to see a breakdown of what languages to use in which scenarios. Not necessarily completely optimal, but you must cover every conceivable scenario between your other language choices. Otherwise it's easy to just say "nuh-uh!" vs. "uh-huh!"

    6. Re:Developing in C/C++ by Marginal+Coward · · Score: 1

      Second of all, if you are developing in either C or C++, you should develop in a different language.

      OK, I'll bite. C and C++ are commonly used for real-time embedded applications, primarily because of speed. Do you have a better language for that? Remember, it has to compile on the processor you're actually using. 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.

    7. Re: Developing in C/C++ by Anonymous Coward · · Score: 0

      So does Swift.

    8. Re:Developing in C/C++ by serviscope_minor · · Score: 2

      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.
    9. Re:Developing in C/C++ by Anonymous Coward · · Score: 0

      Tell me what language you think is good and I will tell you why you are wrong.

    10. Re:Developing in C/C++ by Anonymous Coward · · Score: 0

      For C++, I concur completely, but I really don't see what's wrong with C. It may not be perfect for every purpose, but it is a very fine language.

    11. Re: Developing in C/C++ by Anonymous Coward · · Score: 0

      What's wrong with cross-compiling? There is nothing magical about a machine that means you can only compile code locally.

    12. Re:Developing in C/C++ by david_thornley · · Score: 1

      C++ typically provides fast code with excellent abstraction capabilities. It's also much safer than C, since modern C++ eliminates a lot of C memory bugs (when used according to reasonable standards, anyway).

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:Developing in C/C++ by Anonymous Coward · · Score: 0

      Second of all, if you are developing in either C or C++, you should develop in a different language.

      ... if you're implying C or C++ have no use anywhere ever, you're an idiot. There simply is no way I could find a better way to phrase what my mind is thinking about this comment.

    14. Re: Developing in C/C++ by HiThere · · Score: 1

      Sorry, but many languages have decent unicode string handling. A partial list is:
      Python, Ruby (with a gem), D, and even Vala. I'm sure there are others, and Vala proves that C *could* be adapted to have decent unicode string handling. It just doesn't. Possibly in the case of C it would interfere with its minimalism, which is crucial for many of its uses. In C++ the only reason that I can imagine is that it might interfere with backwards compatibility. But the kludge they settled on is just atrocious.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
  13. worthless article... blog spam by Anonymous Coward · · Score: 0

    WTF? the article is a few paragraphs that read like an advertisement.... meh

  14. Except RHEL doesn't have clang by halfdan+the+black · · Score: 1

    Sure, I can spend who knows how much time trying to get it to compile myself and install it my home dir, but then I can't ship binaries compiled with clang.

    And I've never had much luck getting clang to compile using gcc c++ stdlib and link against the gnu c++ libs. I suppose I could just statically link against c++ stdlib though.

    1. Re:Except RHEL doesn't have clang by Anonymous Coward · · Score: 0

      Sure, I can spend who knows how much time trying to get it to compile myself and install it my home dir, but then I can't ship binaries compiled with clang.

      Why not? Clang is binary compatible with GCC. Put another way, is this different at all from the problems you would have if you wanted to use gcc 4.9 on RHEL?

    2. Re: Except RHEL doesn't have clang by kthreadd · · Score: 1

      Problems? You can yum install it. https://rhn.redhat.com/errata/... But that's an old version. They are up to GCC 5 now.

    3. Re:Except RHEL doesn't have clang by TheRaven64 · · Score: 1

      Recent LLVM / Clang needs a moderately compliant C++11 compiler to work. I think that means gcc 4.8 or newer, though it could be 4.9. There are some weird things that you sometimes hit with g++ / libstdc++ and C++11 (I was recently bitten by the fact that initialiser lists don't seem to work with std::tuple), but LLVM has buildbots that try to build it with gcc and so avoids these features.

      --
      I am TheRaven on Soylent News
    4. Re:Except RHEL doesn't have clang by Anonymous Coward · · Score: 0

      but then I can't ship binaries compiled with clang

      Interesting. I do. Why can't you?
      Not that clang is worth the hassle, but still.

    5. Re:Except RHEL doesn't have clang by Anonymous Coward · · Score: 0

      Except RHEL doesn't have clang

      Then switch to an OS that doesn't suck.

  15. Evidence? by mveloso · · Score: 3, Interesting

    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?

    1. Re:Evidence? by aberglas · · Score: 1

      No, the trouble is that you just cannot implement an efficient garbage collector in C/++. So Java and .Net do their own compiling. C is only efficient if you think "C".

    2. Re:Evidence? by Anonymous Coward · · Score: 0

      No, the trouble is that you just cannot implement an efficient garbage collector in C/++. So Java and .Net do their own compiling.

      They way I read it is "C/C++ doesn't have an efficient garbage collector, so Java and .Net couldn't copy it. As a result they don't have efficient garbage collectors either."

      I have yet to see a garbage collector that works as advertised.

    3. Re:Evidence? by Anonymous Coward · · Score: 0

      Wrong.

      Since the 1980s Lisp and thus Java and .Net implemented generational garbage collection. That involves moving objects in memory after they have been malloced, so that tricks with virtual memory can be used to minimize the mark phase. That means fining every reference to the object (including those in memory) and updating them. That is unthinkable using C technology.

  16. win64 by Anonymous Coward · · Score: 0

    Clang has issues with Win64. There was a bug that was around for a while with the io library's tellg function that was preventing us from using it. Now there's all sorts of issues with flags we're dealing with

  17. Re: Mixed backend languages is recipe for subtle b by Anonymous Coward · · Score: 0

    So what about the fact that GCC supports a bunch of different languages, too? It sounds as if you are saying that Clang is risky because of supported language impedance, but GCC has the same issue. If the real fear is that Clang is new, then I guess Ths Devil You Know is better, eh?

  18. Auto-vectorization by iamacat · · Score: 1

    Once I checked, clang was not good at generating vector instructions from simple loops. Unless it has improved lately, that would be a show stopper for a class of code.

    1. Re:Auto-vectorization by TheRaven64 · · Score: 1

      It's been hugely improved in the last couple of releases. Linaro did quite a bit of work on the vectoriser, as did Apple.

      --
      I am TheRaven on Soylent News
  19. Comparison by dawilcox · · Score: 1

    I've done POSIX C++ programming for five and a half years. I compile on my mac using clang and on my ubuntu machine using g++. Here's the differences: 1. Clang seems to have better error messages. 2. Of course, clang is usable using libraries (rtags for emacs lets you do ctags but way better for example). 3. Run speed is about the same for optimized build between the two. They're within 1% for our application using the benchmarks for it. 4. Compile speed is a bit faster using clang. I like having two big compilers that compete with each other. It forces both to try harder and to become better compilers in the end.

    1. Re:Comparison by friedmud · · Score: 1

      Exactly this. We do the very same.

      However, Clang is significantly faster for our application. I would do some timings for you right now... but it takes too damn long to compile the entire stack with GCC ;-) Last time I checked it was on the order of 25% faster. Over a whole day of compiling that can make a big difference.

  20. This is an advocacy non-starter by Anonymous Coward · · Score: 0

    Why would I care about an alternative compiler when ccache takes care of most of the GCC speed cost anyway? My personal project's edit-compile-test cycle is down to something like 45 seconds these days, and all but maybe 1-2 are the test suite where many tests use 20ms sleeps to cause ordering.

    Why would I care about the micro-level speed of the program in an era where computers have been fast enough for most of a decade already? Certainly for ARM, Atom, etc. low-power targets there's advantage in being fast -- but again, that's a matter for data structures and algorithms, not micro-level tweaking. If a compiler can optimize a program to greater gains than a performance-oriented, benchmark-guided refactoring, then the program must already have been close to optimal -- and realistically that won't happen until the underlying operating system and user-space middlewares are also optimal.

    I do appreciate the parallel research that clang embodies, and the static analyzer for being another tool in my kit. But to replace the GCC of 2015, clang's got about a decade to go still.

  21. *Facepalm* by Anonymous Coward · · Score: 0

    Knock yourself out! Go make your own GPL branch of an active project that large companies actively develop and see how successful it is.

    Then, for real, go knock yourself out.

    Preferably with a hammer. Don't worry, as best I can tell it won't affect your intelligence.

  22. Graph by JBMcB · · Score: 1

    So you could write a tool against LLVM that looks to see which templates are causing problems, maybe output the usage graph to graphviz to help refactor your code...

    --
    My Other Computer Is A Data General Nova III.
  23. Both GCC and Clang by ortholattice · · Score: 1

    I periodically run both just to get the warnings that each is able to provide. And I clean up all warnings, even if I know that they are harmless, so I won't miss a blunder buried in the noise. Turning on all warnings has saved me from having to chase down more bugs than I care to admit. gcc *.c -o xxx -O -Wall -Wextra -Wmissing-prototypes \ -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-align \ -Wredundant-decls -Wnested-externs -Winline \ -Wno-long-long -Wconversion -Wstrict-prototypes -ansi -pedantic clang *.c -o xxx -Wall -Wextra Any other warnings you'd recommend?

    1. Re:Both GCC and Clang by ortholattice · · Score: 1

      Damn, picked wrong formatting.

      gcc *.c -o xxx -O -Wall -Wextra -Wmissing-prototypes \ -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-align \ -Wredundant-decls -Wnested-externs -Winline \ -Wno-long-long -Wconversion -Wstrict-prototypes -ansi -pedantic

      clang *.c -o xxx -Wall -Wextra

  24. Why is this modded informative? by Ixpath · · Score: 1

    If you bother to actually follow the link it shows gcc producing faster code except in the artificial benchmarks he cherry-picked on page two.

    1. Re:Why is this modded informative? by Anonymous Coward · · Score: 1

      If you bother to actually follow the link it shows gcc producing slower code except in the artificial benchmarks he cherry-picked on page two.

      Fixed that for you.

    2. Re:Why is this modded informative? by Darinbob · · Score: 1

      It's a Dice article. It's therefore intentionally click bait.

  25. G++ versus Clang++ by ShakaUVM · · Score: 4, Informative

    >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.

    1. Re:G++ versus Clang++ by ShakaUVM · · Score: 2

      (Sigh, Slashdot. Stop eating code snippets in Plain Old Text mode. This is a place for geeks.)

      Here's the code that generated the bug, without Slashcode mangling it:

      int x;
      for (int i: x) std::cout i;

      109 lines of error messages in g++, 2 lines in clang++

    2. Re:G++ versus Clang++ by Darinbob · · Score: 1

      My previous job we used C++ with template heavy usage and I ended up being the unofficial translator of G++ error messages. This is really the only part of GCC I dislike (and it's only on the C++ side which I'm not using now).

    3. Re:G++ versus Clang++ by serviscope_minor · · Score: 2

      If you're marvelling over clang producing coloured error messages, then you're using an old version of gcc. Try switching to something in the new gcc-5 series. Contrary to popular belief, it's quite slow, but not hard to compile. Also, many distros have gcc-5 packages available.

      PS, both versions of your code got mangled, so I can't see what you're referring to precisely.

      --
      SJW n. One who posts facts.
    4. Re:G++ versus Clang++ by david_thornley · · Score: 1

      I'd be willing to bet that there's supposed to be less-than or greater-than symbols in there. Slashcode helpfully treats them as some sort of html tag, and ignores what it doesn't recognize.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    5. Re:G++ versus Clang++ by Anonymous Coward · · Score: 0

      You must have not used G++ in a WHILE, because I only get 3 lines of errors in g++

      test.cpp: In function ‘int main()’:
      test.cpp:5:15: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
            for (int i: x) std::cout i;
                                    ^
      test.cpp:5:28: error: expected ‘;’ before ‘i’
            for (int i: x) std::cout i;
                                                              ^

      Sorry, arrows don't line up :-D

    6. Re:G++ versus Clang++ by ShakaUVM · · Score: 1

      You didn't enable c++11 mode. I mentioned the build flags in my original post, but Slashdot ate those as well.

      Try this:
      g++ -std=c++11 test.cc
      clang++ -std=c++11 test.cc

    7. Re:G++ versus Clang++ by ShakaUVM · · Score: 1

      I posted the code in a followup to my own post. It ate my build flags and I guess my version numbers as well if you didn't see them. g++4.8.4 (which is the current default g++ in Ubuntu 14.04) and clang++3.7.1.

      Basically, the bug is trying to use an integer instead of an array of integers in a range-based for loop, which is something people do occasionally by mistake. In g++, they go crosseyed trying to parse the error messages from this, as it spits out over a hundred lines of template substitution errors. Clang just says you can do a range based loop with an int.

      int x = 0;
      for (int i : x) cout i;

    8. Re:G++ versus Clang++ by serviscope_minor · · Score: 1

      I posted the code in a followup to my own post. It ate my build flags and I guess my version numbers as well if you didn't see them. g++4.8.4 (which is the current default g++ in Ubuntu 14.04) and clang++3.7.1.

      Ubuntu 14.04 has a gcc-5 PPA, which I use as gcc 5 has better C++14 support than 4.8.4, not to mention colourful error messages :)

      In g++, they go crosseyed trying to parse the error messages from this, as it spits out over a hundred lines of template substitution errors. Clang just says you can do a range based loop with an int.

      This seems to have improved a great deal: it tells you (correctly) that begin() and end() are missing. If you like to engage in C++ fuckery, you can overload begin() and end() for ints to confuse people, much like going bonkers with operator overloading.

      But then it suggests an alternative which is pointelss. It's a much shorter error message than a list of every substitution failure it had before. They should probably special case it further, but it's much better than it was.

      --
      SJW n. One who posts facts.
    9. Re:G++ versus Clang++ by ShakaUVM · · Score: 1

      That's good to know, thanks!

      I'll wait for gcc5 to be added to the main repository, though, and use clang in the meantime.

    10. Re:G++ versus Clang++ by serviscope_minor · · Score: 1

      I'll wait for gcc5 to be added to the main repository, though, and use clang in the meantime.

      I don't think they do that: 14.04 is meant to be LTS so they won't change the compiler version except for critical patches. The gcc-5 package allows it to coexist with the system compiler (the binary is /usr/bin/g++-5) quite happily.

      16.04 will get gcc 5, I strongly expect.

      --
      SJW n. One who posts facts.
  26. Re:Mixed backend languages is recipe for subtle bu by windwalkr · · Score: 2

    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.

  27. What planet are you on? by Etcetera · · Score: 1

    I care how fast my compiler compiles (as long as it's not insane) about as much as I care how fast my system boots (as long as it's not insane).

    Seriously. Whatever planet you weird devs came from, can you return to it? (And take Lennart with you?)... Spend your free time re-optimizing your cut-and-paste chef recipes or something, and leave the engineering to the rest of us?

    1. Re:What planet are you on? by keltor · · Score: 1

      I have a 3.5mil LoC codebase that takes roughly 15 minutes to compile with gcc and about 8 minutes with clang. That's 7 minutes of my life every few hours. I'm the architect, so most of my changes require a full recompile. I'll save a couple of dozen hours per year TYVM.

    2. Re:What planet are you on? by Anonymous Coward · · Score: 0

      And how many recompiles and other wasted hours of your life will sane compiler errors save you?

    3. Re:What planet are you on? by serviscope_minor · · Score: 1

      Where is the time spent?

      You should probably get someone to fork out for a 64 core build machine for you for nice, fast parallel builds.

      --
      SJW n. One who posts facts.
    4. Re:What planet are you on? by BitZtream · · Score: 1

      I'm the architect, so most of my changes require a full recompile.

      No. You aren't. An architect isn't writing code. And you'd be a shitty one if you were, since its a pretty shitty time spent if you're waiting for the entire system to compile for changes instead of having a CI system, unit tests and integration tests running on an automated system for you.

      Don't try to brag like you're awesome, you're post shows you aren't.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  28. just a warning by Gravis+Zero · · Score: 2

    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.
    1. Re:just a warning by Anonymous Coward · · Score: 0

      Parent didn't cite which versions of clang are affected, so I confirmed his claim on 64-bit Ubuntu 15.10 using gcc 5.2.1-22ubuntu2 (no errors) and clang 3.7.0-2ubuntu1 (see below for error):

      test.cpp:7:5: error: no matching function for call to 'shallow'
          shallow<int>(arg);
          ^~~~~~~~~~~~
      test.cpp:2:37: note: candidate template ignored: failed template argument
            deduction
      template<typename... ArgTypes> void shallow(deeper<ArgTypes...> arg) { }
                                          ^
      1 error generated.

    2. Re:just a warning by Anonymous Coward · · Score: 0

      It is a very broken code to begin with.

    3. Re:just a warning by Anonymous Coward · · Score: 0

      A better solution: find the guy who's writing variadic templates, and fire him (out of a cannon, into the sun).

    4. Re:just a warning by Anonymous Coward · · Score: 0

      This.

    5. Re:just a warning by Anonymous Coward · · Score: 0

      Fire the luddite who refuses to learn variadic templates. If your job requires modern C++ (C++11 or C++14), and you're not comfortable with variadic templates yet, then you don't know how to do your job.

    6. Re:just a warning by Anonymous Coward · · Score: 0

      Yeah... he should change it to deeper = std::function<void(ArgTypes...)> for great justice!

  29. Clang was written by author of Swift by johnrpenner · · Score: 1

    the guy who developed clang - Chris Lattner - also wrote swift.

    he first modernized the architecture of the compiler, and then wrote a better language on top of it that is capaable of doing system level things like C++ with a cleaner semantic style.

    ++

    1. Re:Clang was written by author of Swift by Anonymous Coward · · Score: 1

      Did he wrote that better language before or after he wrote Swift?

  30. Dice again... by Anonymous Coward · · Score: 0

    If I wanted to read dice, I would actually go to dice.com, no /.

    1. Re:Dice again... by Anonymous Coward · · Score: 0

      Who cares. This is Slashdot. Nobody reads the articles.

  31. Linus Torvalds by Anonymous Coward · · Score: 0

    Linus tried clang for the Linux kernel, and it generated terrible code for certain constructs the kernel depends on AND compiled a bit slower.

    They have some way to go.

    1. Re:Linus Torvalds by BitZtream · · Score: 1

      ... you mean code written specifically for GCC doesn't work as well in every case under a different compiler without the same shitty GCC quirks?!

      WHAT IS THIS YOU SPAKE?

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  32. Re:Mixed backend languages is recipe for subtle bu by Anonymous Coward · · Score: 0

    The backend code generation has nothing to do with frontend class and objects semantics, this is not .Net runtime. AFAIK the point of LLVM is not mixing different frontend languages in single backend output, just the ability to combine frontend languages with backend generators for various CPU architectures.

  33. GIMPLE/GENERIC by Anonymous Coward · · Score: 0

    So the new thing about clang is that it works with an intermediate language to allow the front and back ends to optimize cleanly? I thought gcc is also doing this with the GIMPLE/GENERIC layer -- can anyone explain what's the difference?

  34. Just use both by Anonymous Coward · · Score: 0

    For this reason exactly, my debug builds are with Clang and release builds are with gcc. All the bells and whistles of static analysis and nice error messages from clang, and all the speed of gcc. No need to choose one over another when you can have both.

    1. Re: Just use both by Anonymous Coward · · Score: 0

      That sounds like an awful idea: You are shipping binaries you haven't tested!

  35. How exactly is a compiler related to development? by Anonymous Coward · · Score: 0

    How exactly is a compiler related to development?

    Compiler takes part in the deployment phase. It may also throw some warning, so that would be useful for code-review phase. Where exactly is the development here?
    Development is something that happens in your mind. All you need for development is a text editor. May come in with syntax highlighting and code completion, but that's all.
    And here is your problem: you think you 'develop' by writing some code and then using a compiler to check if it works. This is exactly what a bad programmer would do. This is what code-monkeys do.
    And because of this you all end up like that: 'Learn C, instead of just stringing random characters together until it compiles (with warnings).' -- Linus Torvalds https://lkml.org/lkml/2015/9/3/428

    Using the compiler is the very last part of development, just to fine-tune your code. And then to release it, but that's called deployment.
    So it doesn't really matter which one you use for *development*. Or you are doing it wrong.

  36. Kernel? by Anonymous Coward · · Score: 0

    Can Clang compile the Linux Kernel?

  37. My suggestion by jgotts · · Score: 1

    How about writing code that runs well on both compilers?

  38. Parallel make when a program produces 2 files by tepples · · Score: 1

    You should be using precompiled headers

    Until the headers themselves change, causing a cascade throughout all source files that instantiate a class or its subclasses because of C++'s fragile base class tendency.

    and set up your makefiles for multiple cores.

    There are known limits of GNU Make when you have a single program that spits out more than one file. For example, a graphic may be converted for use on a particular platform by decomposing it into a tile file and a map file. Or a collection of documents may be compressed into a static dictionary and a (separate) archive of the compressed documents. The problem is that Make will often try to run the program twice at once, once to produce the tile file and once for the map file, wasting CPU. What's the typical workaround? Is it a good practice to have the program generate an archive file containing both files, and then generate the tile file and map file by extracting them from the archive file?

    Besides, link-time whole-program optimization doesn't parallelize nearly as well.

    So instead of compiling and linking the entire application repeatedly as you track down a bug, you only integrate after all your unit tests are written and passed in isolation.

    Which doesn't help when the bug is in the integration.

  39. uint32_t by tepples · · Score: 1

    For any type with a size less than 29 bits the behavior is undefined. [...] For signed types it is implementation defined.

    But what is it for uint32_t x = 0xdeadbeef;?

  40. shared_ptr by tepples · · Score: 1

    you just cannot implement an efficient garbage collector in C/++.

    Then what's std::shared_ptr if not an efficient reference counting garbage collector?

    1. Re:shared_ptr by bensch128 · · Score: 1

      Then what's std::shared_ptr if not an efficient reference counting garbage collector?

      If there are circular references, then shared_ptr won't help you.
      That being said, there are garbage collectors in C++ that are implemented in the memory allocation system but they aren't great.

    2. Re:shared_ptr by bensch128 · · Score: 1

      Erk, nevermind. I just realized that you were being sarcastic....

    3. Re:shared_ptr by tepples · · Score: 1

      In practice, how hard is it to avoid circular references using a combination of std::shared_ptr and std::weak_ptr? Besides, if you have circular references in any other language, in what order should the language call the objects' finalizers? Not calling them at all breaks the RAII idiom. Or what idiom is superior to RAII for ownership whose lifetime exceeds that of a single try statement?

  41. If only C and C++ compilers exist for an ISA by tepples · · Score: 1

    The fact that you have to install a cross-compiler for that particular (language, architecture) pair. For some less popular architectures, compilers accepting languages other than a handful (C++, C, and possibly Fortran) happen not to exist.