Live data from Hacker News

How to convince any C developer to dump gcc and use clang

fseek.me

21–30 of 97 posts

Re: How to convince any C developer to dump gcc and use clang

#22
post #4

I've had 40% speed-ups on some math-heavy C code simply by switching from gcc to clang.

Which version of gcc?

I had a 2x speedup a few years ago on math-heavy code (FFTs) by switching from gcc 4.2 to gcc 3.4 -- apparently there was a known issue in gcc's optimizer where it would flag too many values as "keep this in a register" and end up spending lots of time moving data to and from the "register overflow space" on the stack. (I don't know if this has been fixed -- as I said, it was a few years ago that I ran into this issue.)

Re: How to convince any C developer to dump gcc and use clang

#23
post #10

you're saying I should port all my code just because the ui is more user-friendly? what about performance, options, special warnings, builtins, and everything else? I've been using gcc for a while now, and every time I use it I found a new feature. It's rock solid and had never let me down.

You shouldn't need to port your code; C is C, right?

Or do you use a lot of gcc extensions?

Re: How to convince any C developer to dump gcc and use clang

#24
post #13

Since when is it hard to find and correct syntax errors that are preventing your C code from compiling?

I can think of one example, heavy use of macros can create a syntax error nightmare. One of the projects I've worked on (I had inherited it without documentation) had some seriously obtuse nested macros that threw a spanner in the works at least once.

Re: How to convince any C developer to dump gcc and use clang

#25
I am currently switching between gcc and clang for my codebase. The performance is mixed. For some programs (2-level hashtable, for example), the clang version got about 50% speed up against gcc and icc. But other programs (sobel filter for example), clang version slows down about 25% (against gcc 4.4). The result certainly machine specific, but I think clang can do better in a long run.

Re: How to convince any C developer to dump gcc and use clang

#27
post #12
post #5

Earlier quoted context omitted.

Proprietary extensions are one reason that gcc is so hard to unseat. You're always better off writing standard code if you want it to work in ten years.

Hardly proprietary. Apple gave the "block" patches to the gcc team. Gcc isn't interested in them, they are holding off for some future C++ syntax, though I don't see how that helps C programmers. Meanwhile, I got seduced by gcc's nested functions which are not supported by clang. Apparently they are non-trivial in clang so won't appear soon if at all. Two incompatible mechanisms for function decomposition are annoyin…

I think he meant to say "non-standard".

Re: How to convince any C developer to dump gcc and use clang

#28
As a dynamic language guy, I can't help but look at the static analysis here and feel a twinge of jealousy. There really isn't anything like this in the Ruby world.

Some stuff is starting to emerge, but we're still largely dependent on tests to catch stupid mistakes. When I'm chasing down a bug, it would be nice to have a variety of tools to throw at the problem.

Re: How to convince any C developer to dump gcc and use clang

#29
post #6

I'm not sure this screenshot is convincing. Do you see the last error message? In the second error message clang found that `horisontal` doesn't exist and suggested `horizontal`. That's fair enough. The last error message actually assumes the code said `horizontal`, which is just horribly wrong. I think that the compiler should never ever report an error on code that is not really there. What would happen if the prog…

It's quite common and accepted for compilers to make assumptions about the rest of the code, and for those to be wrong if your code is broken. For example, the C# compiler has a large number of passes, and it will do no more passes after seeing an a previous pass. Thus, you might knock a file down to one error, fix that error, and then find that you have a couple dozen more errors.

> It's quite common and accepted for compilers to make assumptions about the rest of the code, and for those to be wrong if your code is broken.

Indeed. Most annoyingly, many "modern" C compilers still attempt to muddle onward by replacing unknown types with "int".

Re: How to convince any C developer to dump gcc and use clang

#30
post #12

Earlier quoted context omitted.

Hardly proprietary. Apple gave the "block" patches to the gcc team. Gcc isn't interested in them, they are holding off for some future C++ syntax, though I don't see how that helps C programmers. Meanwhile, I got seduced by gcc's nested functions which are not supported by clang. Apparently they are non-trivial in clang so won't appear soon if at all. Two incompatible mechanisms for function decomposition are annoyin…

I think he meant to say "non-standard".

Yes, nonstandard. I apologize for my sloppy wording.

By all means play with closures. I don't mean to discourage the original poster from experimenting. I am just pointing out some irony in the context of gcc and clang. Clang is forced to implement nonstandard gcc extensions. I do not see this as a good thing for languages that are essential building blocks and which people have put a lot of work into standardizing. Software development doesn't need to be so ephemeral.

Post reply on HN