Live data from Hacker News

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

fseek.me

81–90 of 97 posts

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

#81
post #67

Earlier quoted context omitted.

I usually try to fix as many errors as I can identify before recompiling. And yes, I usually fix from the bottom up, because that way my changes don't alter the line numbers of future fixes. On large projects, recompile time can be significant.

I think you need to upgrade you editor. For instance both vim & emacs are smart enough to adjust for inserts and removals.

I use vim. How do I get it to adjust for edits?

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

#82

Earlier quoted context omitted.

I usually try to fix as many errors as I can identify before recompiling. And yes, I usually fix from the bottom up, because that way my changes don't alter the line numbers of future fixes. On large projects, recompile time can be significant.

Yes, sure, large projects can take time to compile, but doesn't your compile environment just try to recompile the last file that it failed on during the build? That is, if in trying to build my app FooBar, and foo.c compiles ok but bar.c fails, when I try to run the build the next time having modified bar.c, it starts by trying to compile bar.c anyway... So I guess what I'm trying to say is that I don't understand t…

I don't want to get into the specifics of the build system since it's proprietary, but there's a non-trivial startup cost for it. It's optimized for being able to compile really huge projects in a tractable amount of time, not being able to recompile individual files in the shortest possible amount of time. The latter will execute quickly enough (yes, it only recompiles what you've changed), but the startup time is still annoying enough to want to batch up edits.

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

#83

Wow, the clang error messages are really good. I've never seen a compiler produce such user-friendly error messages.

That is pretty impressive. I use colorgcc to make gcc's messages easier to spot and sort, and I always thought gcc had the best error messages (better than MSVC last time I tried it). I might just try clang to see if its messages are better in all the cases I typically encounter.

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

#84
post #32

According to the clang home page as of March 7th 2010, "Clang's C++ support is currently alpha quality at best, but is evolving rapidly." Obviously, clang does not mean to attract C++ developers. For a while, I'd been adamant about developing in C and not C++. One day I discovered that I'd hand-coded a vtable in order to allow polymorphism in structures of function pointers. The next day, I halved the project complex…

One day I discovered that I'd hand-coded a vtable in order to allow polymorphism in structures of function pointers.

I've found myself in a similar situation. I am writing embedded software which needs to be as portable as possible, but I've found myself starting to implement polymorphism and objects in C. I am tempted to ignore platforms that lack a C compiler and switch to C++, but the reduced predictability of runtimes has kept me from doing so thus far.

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

#85
post #67

Earlier quoted context omitted.

I think you need to upgrade you editor. For instance both vim & emacs are smart enough to adjust for inserts and removals.

I use vim. How do I get it to adjust for edits?

Use the :make command so that vim knows about the errors. Then use :clist to list errors, :cnext to go to the next error, etc. :help clist and :help make will get you started.

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

#86
post #68

Earlier quoted context omitted.

yeah, I'm thinking this might be more useful for c++ :)

In the meantime before clang fully supports C++ I would appreciate a flag for GCC that just gives me abbreviated error info: file.cpp:65: error: please have a look at this line and see if anything jumps out at you. as that is basically all GCC C++ errors are good for.

Something like this might work:

   g++ [options] | sed -e 's/^(.*: (error|warning):).*/\1 please have a look at this line and see if anything jumps out at you/'

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

#87
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 tha…

I second that on gcc version. On many math related code gcc-4.4 is amazing. Specially if vectorization and/or SIMD is possible.

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

#88
post #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.

-E is your friend:

       -E  Stop after the preprocessing stage; do not run the compiler proper.
           The output is in the form of preprocessed source code, which is
           sent to the standard output.

           Input files which don't require preprocessing are ignored.

Take the output of that, compile it, and you will typically get a sensible error message.

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

#89

Earlier quoted context omitted.

One point was mentioned - recompiling time may be huge. On the other hand - if the recompile time is tiny, I don't bother with any specific order, I just fix what I see as trivial first. But when you see the clang's very verbose errors - how many can you fit on the screen? 10? 15? To make sure none of the last ones depend on some code guessing, you'd have to scroll to the top every time, instead of just fixing what y…

How long is recompiling really going to be if it's one file, though? I'm not talking about C++, which clang isn't quite fluent in yet, but one file of pure C shouldn't take long to compile. Or have I not been compiling the right C files?

Let's say you edit point.h, and many files include it. Then these files must be compiled too, and the files that include them, etc. until eventually you compile nearly the whole application.

I've been bitten by the dependencies in C++ before. I have this file "image.h" which contains a templated image class with quite a few algorithms. My app is about image processing, so nearly everything uses the image datatype. I hate having to edit this file because it means recompiling nearly everything. Of course templates make it much worse than pure C...

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

#90
post #67

Earlier quoted context omitted.

I think you need to upgrade you editor. For instance both vim & emacs are smart enough to adjust for inserts and removals.

I use vim. How do I get it to adjust for edits?

If you are using :make, and _don't_ jump out of the file (split the window if you need to jump out), line deletions and additions down the window are automatically accounted for.

As for turning it on or off, I've never had too, unless it's part of cindent.

Post reply on HN