13 ms·
Android NDK: GCC is now deprecated, everyone should be switching to Clang
- jdlyga 11y agoPerhaps for Android, but I'm hesitant about using Clang for Win64 due to some recent bugs (such as tellg not working correctly).
- AlexeyBrin 11y agoNDK is only for Android (as in a C++ toolchain for Android, the toolchain runs on Windows, Linux and Mac but the resulting executables are meant for Android) ... what do you mean with Win64 in this context ?
- xd1936 11y agoHe probably meant the x64 compiler on Windows. From the link: "Also note that Clang packaged in the Windows 64 NDK is actually 32-bit."
- klodolph 11y agoThat's probably a bug in libc++, not Clang. They're under the same roof, but different people work on them. Also, I would mock you for using <iostream> at all but you've probably got legacy code just the same as I do.
- Buge 11y agoI'm curious, what's wrong with iostream?
- duaneb 11y agoI dunno, I think bit shifting a string to write to a file is pretty unreadable, not to mention C already has rock-solid string formatting options. It's an miasma of operator abuse built into "hello world".
- GFK_of_xmaspast 11y ago> C already has rock-solid string formatting options Don't troll.
- duaneb 11y agoDo you have an actual response? How is iostream any better than *printf? At least you can read the format of the former without needing to google un-googleable operators.
- msbarnett 11y ago> How is iostream any better than *printf? Type checking.
- duaneb 11y agoYou already have to do odd casting to get around compiler warnings when passing invalid types to a format—I don't buy this anymore.
- simoncion 11y ago> I don't buy this anymore. You should: https://news.ycombinator.com/item?id=10775022 https://news.ycombinator.com/item?id=10775022
- jmgao 11y agoprintf has type checking in every major compiler. You just need to annotate all of your printf-y functions with attributes to tell the compiler "this function does printf, the format string is the nth argument, and the format arguments start at the mth argument". It doesn't work with non-constexpr format strings, but there aren't many justifications for those.
- simoncion 11y ago> How is iostream any better than [<star>]printf? What consistent mechanism do you use to printf an instance of an arbitrary user-defined type? With ostream, you implement ostream& operator<<(ostream&, const Class&) and you're done. with printf, you have to have a convention and remember to stick to it. (Do I call .toString(), .stringize(), .getString()... ??) For one-off things, printf is great. You take it from me when you pry it from my goddamn cold, dead, hands. However, for real work io*stream are rather nice.
- cbd1984 11y agoHow do you internationalize strings built up from multiple string fragments?
- endgame 11y agoLink for those who need more context: http://yosefk.com/c++fqa/web-vs-c++.html#misfeature-4 http://yosefk.com/c++fqa/web-vs-c++.html#misfeature-4
- simoncion 11y agoThe same way you'd do it in printf? Stringize data and insert it in the middle of static text? (Pardon my inelegant code, I've been away from C++ and doing Erlang for quite a while now.) void printStuff(ostream Os, string WarningPart, string SizePart, string EndPart, int Size) { //The English version might look like: //"Warning: Size too big (200). Get smaller." Os << WarningPart << SizePart << Size << EndPart << endl; }; I expect that if I thought about the problem for a few minutes (and was unable to find any C++ i18n libraries) I would come up with something much nicer and easier to use than this thing I spent ten seconds working on. :)
- prodigal_erik 11y agoPOSIX printf allows a translator to write a conversion spec like "%1$d" that says which arg to print. This lets you do stuff like put currency before or after the amount depending on what's idiomatic for the locale, without recompiling (if you lookup your format strings at runtime).
- simoncion 11y agoSure, but that's l10n, which is a different -but related- thing. :) printf format strings are well thought-out. I was demonstrating that the same ideas can easily be used with io*stream.
- simoncion 11y agoFor the downvoters: Here's a lib that accomplishes this task that's had a fair bit more than 10 seconds of thought put into it: [0]. Examples [1][2]. :) [0] http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/index.html http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/in... [1] http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/hello_8cpp-example.html http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/he... [2] http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/messages_formatting.html http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/me...
- ambrice 11y agoIt's a pain to format text. Things like: printing an int in hex, printing a zero-padded int of a specific length, printing a float to two decimal places. And having those formatting changes be stored silently as global state leads to unexpected behavior.
- saurik 11y agoFWIW, most of these options revert back to default as soon as you format something; but I agree that I would have preferred iomanip to generally be a wrapper around values rather than a silent modifier of the stream.
- bracewel 11y agowaits for RMS to get mad https://gcc.gnu.org/ml/gcc/2014-01/msg00247.html https://gcc.gnu.org/ml/gcc/2014-01/msg00247.html
- haroldp 11y ago> I would guess they describe their work as "open source" and do not talk about freedom. Wow, what an asshole. Maybe they consider legal restrictions on how other people may use their software to be the opposite of freedom? Maybe that is the truth and maybe RMS has a good point to make, but how tone deaf is to call anything that isn't GNU, "unfree"? To suggest that they don't even talk about freedom because their license is a little different? What an asshole.
- the_ancient 11y agoRMS wants user freedom, not developer freedom That is the point people always miss. RMS believes that end user of software / hardware should be in complete control, it was/is never about developers. BSD/MIT/etc lic may provide for more developer freedom, but often they are used to restrict user freedom as the code is folded/packaged into commercial projects with non-free licenses
- BrainInAJar 11y agoThat's terribly ironic, since the source code is completely useless to the user, only developers.
- the_ancient 11y agoThat is not true at all, I know many non-developers that will compile source code themselves, one that is done often would be FFMPEG where you have several compile flags that will make the software preform differently based on the options you select, This is an example of Source Code being useful to non-developers.
- 11y ago
- vvpan 11y agoThe title is a bit misleading. It is deprecated in the context of that project. Meaning they personally won't support it anymore. It's not deprecated in general as a compiler.
- smegel 11y agoDid the title not have "Android NDK:" in it at some point?
- whatever_dude 11y agoPedantic much, but I agree. GCC support is deprecated, not GCC itself.
- detaro 11y agoDon't think so, I guess it could be interpreted as "the NDK project is claiming that GCC should be generally deprecated"
- psibi 11y agoFor someone not following the project, what's the reason for deprecation and switch over to LLVM ?
- earlz 11y agoAs someone messing with LLVM a lot.. basically LLVM is where a ton of development effort is going. GCC is a dead end it seems like. LLVM is designed to be extended where as GCC.. well, usually doesn't really seem to have been designed.
- fixermark 11y agoIt, sadly, goes deeper than that, past architecture to philosophy. LLVM is designed to be modularized and embedded in other binaries and toolchains, which makes it easier to build extensions and tooling around it. In addition to having a mountain of legacy code, gcc's project steering is philosophically opposed to allowing non-free (as in GPL) plugins [https://lwn.net/Articles/582242/ https://lwn.net/Articles/582242/]. Because of this, developers looking for the most flexible toolchain seem to be backing slowly toward the exist regarding gcc, as the Clang / LLVM steering team has made clear that they don't see similar incompatibilities between their tool and the way developers choose to use it. There is a project going on to break the gcc down into components [https://gcc.gnu.org/wiki/rearch https://gcc.gnu.org/wiki/rearch], so time will tell what comes of these two toolchains.
- alblue 11y agoI think you have a typo in exist -> exits? Either that or I couldn't understand the sentence.
- fixermark 11y agoYep. Thanks for catching. :)
- chii 11y ago> gcc's project steering is philosophically opposed to allowing non-free (as in GPL) plugins I think that's the right philosophy. Why shouldn't you be contributing your plugin if you derive value from it, so that other people can derive value from it just as you did with GCC (if you distribute it that is - if you wrote it inhouse for internal use, then it doesn't matter at all!). It's not like the code generated by GCC is licensed virally. It's a shame that GCC's code is hard to modify, and difficult to extend. LLVM's permissive license means that contributions don't flow back unless it's favourable to the entity contributing it (such as good PR). I imagine that if somebody/some company wrote an excellent, non-obvious, non-trivial toolchain using LLVM, derive profit from it, they will not _want_ to contribute it back.
- tobias3 11y agoWhen we tried using clang for Android compiling C++ code half a year ago it caused problems, which disappeared when we switched to GCC. > If you have problems with Clang, please file bugs! Filing compiler bugs is really hard with a closed source project.
- jmtulloss 11y agoI thought this aspect of android was all open source? I may be mistaken. In any event, you can file bugs here: https://code.google.com/p/android/issues/list?q=label:Component-Tools https://code.google.com/p/android/issues/list?q=label:Compon...
- tobias3 11y agoSorry, I meant that the project being compiled was closed source.
- salgernon 11y agoCompiler bugs are usually limited to a single compilation unit and are usually submitted by doing a binary search on a pre processed source file. This is certainly true for closed source as well - just redact the (few) symbol names and create something that will compile to an a.out that demonstrates the problem. God saves a puppy anytime someone filed a compiler bug with a trivial test case that demonstrates the problem.
- onedognight 11y ago> God saves a puppy anytime someone filed a compiler bug with a trivial test case that demonstrates the problem. The current (r10e) shipping version of clang cannot return 128bit floats from a function. #include <iostream> int main(int c, char **v) { std::stringstream("1.5"); double x; s >> x; return x == 1.5 ? 0 : 1; } EDIT: You don't need "long double" in the above. double (or float) will show the problem. The standard library converts all floating point numbers to long double internally.
- JoshTriplett 11y agoThe sad thing is that "easy to link and embed" and "permissive license" really didn't have to go together like they did in LLVM. GCC could have provided a library that made it easy to do code generation or compiler development. That library could still have used the GPL, so that only Free Software could use it. Some of the work that has happened around LLVM wouldn't have happened around such a library, but some of it would have. (GCC has much more recently started down the "plugin" route, but too little too late.) For instance, Swift might not have happened. But Rust may well have; a rustc compiler under GPL would not have broken anyone's ability to use it, any more than GCC's GPL prevents people from building proprietary software with it. But instead, the GNU project chose to make it difficult to build any extension to GCC outside of GCC's own codebase. So instead of having an easy-to-use library provided by GCC under GPL, which might have furthered many of the GNU project's goals and encouraged more Free Software compiler development, they forced the development of an entirely separate compiler project to provide such a library. And the people who came along to do so, since they had to rewrite it anyway, chose to do so under a permissive license. So, at least in hindsight, the Free Software world is worse off than it would have been had GCC provided a library infrastructure.
- the_mitsuhiko 11y agoI doubt that rust would have happened under the gpl but i would love to hear what the rust team has to say about that.
- pcwalton 11y agoI personally see no reason why the GPL would have been a blocker to Rust. But I'm glad for the permissive license.
- kibwen 11y agoThe Rust team knew from the outset that repurposing a C++ backend was the only pragmatic way to compete with C++ on performance given their manpower constraints and projected timeframe. Even if all available backends had required the use of GPL, Rust would have still chosen one and moved forward with it. Fortunately, given that Graydon did prefer a permissive license for the compiler, LLVM provided exactly what he was looking for.
- noobermin 11y agoI'm not sure if this will stoke a flamewar, because I've never seen a discussion here on this (might just be hanging around different articles). Is there any technical reason to prefer clang over gcc other than ideological reasons? I get the modular nature of llvm is useful, but is the android NDK using this feature? Quick google search shows clang lagging gcc in all but one test[0] at least on Intel Broadwell. Again, what is the benefit other than permissiveness of the license? [0] http://www.phoronix.com/scan.php?page=article&item=clang-gcc-broadwell&num=1 http://www.phoronix.com/scan.php?page=article&item=clang-gcc... This is almost a year old, though
- MBCook 11y agoClang had a number of benefits over GCC such as better error messages and integration points for IDEs (syntax checking/etc) which caused Apple to switch to it (on top of licensing). It may have been faster, not sure, but the internals were supposed to be MUCH cleaner and easier to work with. I know a number of these issues have been improved/fixed in GCC over the last few years. Outside friendliness to internal tinkering and non-GPL software I'm not sure if one as serious technical superiority. I believe clang is written in C++ instead of C, for whatever that's worth. GCC has always had a much bigger set of supported platforms and processors.
- MaulingMonkey 11y ago> not sure, but the internals were supposed to be MUCH cleaner and easier to work with. I've bookmarked this bit of GCC code for my own amusement - an anecdote about the quality of GCC's codebase: https://github.com/gcc-mirror/gcc/blob/7057506456ba18f080679b2fe55ec56ee90fd81c/gcc/reload.c#L1056-L1110 https://github.com/gcc-mirror/gcc/blob/7057506456ba18f080679...
- technion 11y agoIt's an entirely subjective argument - but I've felt the warning and error messages from clang were so much better than those from GCC that developing under clang became a no-brainer. Also, I believe ASAN started with clang.
- 11y ago
- belorn 11y agoHow diverse are the CPU manufacturers for android phones? The major concern when it comes to Clang is that developers will need to buy proprietary plugins to compile open source code that depend on proprietary features, or to have application run in native speed.
- swiley 11y agoThis is an underrated post.
- rmstwitterbot 11y agoRequiring a license to use a compiler is straight out of RMS's (now unfortunately prophetic) article "The Right to Read" http://www.gnu.org/philosophy/right-to-read.en.html http://www.gnu.org/philosophy/right-to-read.en.html Majority of Android phones out there are Qualcomm Snapdragon these days, and for the foreseeable future as they just inked an exclusive deal with Samsung. MediaTek SoC was already a proprietary nightmare of unreleased kernels and toolchains except for the leaked MT6589
- LukeShu 11y agoIn "The Right to Read", "license" refers to a license from the state, like a driver's license or gun license; not a license from the vendor (a copyright license). Vendors licensing proprietary compilers isn't something that TRR predicted--it was a common practice before GCC became dominant.
- pjc50 11y agoThey're all ARM, apart from a very few x86. The SoC manufacturers mess around with proprietary peripherals and obstructive boot processes, but haven't messed with the actual instruction set.
- eccstartup 11y agoSeriously, GCC is a belief, not a compiler.
- sunnyps 11y ago> Ctrl-C no longer kills the backgrounded gdbserver. Woohoo!
- dman 11y agoI am pleasantly surprised that so many people have taken the time to read the source code of multiple compilers and have an opinion on why one is better than the other.
- qeabc 11y agoSome comments about how GCC could have avoided this made me think that this is a setback for free software, but why isn't this just a rising tide benefiting both free and proprietary software? The NCSA license explicitly allows sublicensing, so both the GNU project and Microsoft can create derivatives under free and proprietary licenses respectively, for example. [I am not a lawyer, but this is the reasoning of the accepted answer to a stackexchange question applied to the NCSA license: http://programmers.stackexchange.com/questions/105912/can-you-change-code-distributed-under-the-mit-license-and-re-distribute-it-unde http://programmers.stackexchange.com/questions/105912/can-yo...]
- fithisux 11y agoWhile for NDK it is deprecated for general use GCC has a bright future. At least on windows, it is FOSS with a complete SDK for Win64. Clang requires the Windows/Platform SDK. You cannot really use it without it. You cannot create a distribution without it.
- Ace17 11y agoSpeaking of LLVM's "modular" architecture ; LLVM's architecture is so modular that projects like the Rust compiler or Emscripten use their own modified forks of the LLVM tree ... What's the point in being "modular", if you can't add a backend nor a frontend without having to clone-and-modify the whole LLVM tree? (And what if I want to compile Rust to Javascript? Which of these incompatible LLVM branches should I use?)
- sanxiyn 11y agoRust does work with LLVM releases. In the past it didn't because of various bugs in LLVM, but all blocking bug fixes landed, where "blocking" is defined as those preventing compiler bootstrap. Currently, Rust CI checks for every commit that it bootstraps with LLVM 3.7 branch. Rust maintains the fork because in the foreseeable future, there will be non-blocking bug fixes and Rust will not follow LLVM trunk to get them.