top | item 39922145

(no title)

quincepie | 1 year ago

To me fanalyzer is one of GCC killer features over clang. It makes programming C much easier by explaining errors. The error messages also began to feel similar to Rust in terms of being developer friendly.

discuss

order

mr_00ff00|1 year ago

I know Rust (esp on HN) is very hyped for its memory safety and nice abstractions, but I really wonder how much Rust owes its popularity to its error messages.

I would say the #1 reason I stop learning a technology is because of frustrating or unclear errors.

EDIT: Getting a bit of topic, but I meant more because I love C and would love it more with rust level error messages.

darby_eight|1 year ago

Clang already had decent error messages by the time rust stabilized. There's simply not much you can do at runtime to explain a segfault.

dist1ll|1 year ago

That's what makes me wary of modifying my NixOS config. A single typo and you get an error dump comparable to C++03 templates.

jonathankoren|1 year ago

> I would say the #1 reason I stop learning a technology is because of frustrating or unclear errors.

Overly verbose error messages that obscure more than illuminate are chief complaint against C++.

Honestly, they can just sap all the energy out of a project.

hardwaregeek|1 year ago

Yeah Rust is popular because it's a practical language with a nice type system, decent escape hatches, and good tooling. The borrow checker attracts some, but it could have easily been done in a way with terrible usability.

Quekid5|1 year ago

The hard problem with C is that it's hard to tell if what the programmer wrote is an error. Hence warnings... which can be very hit or miss, or absurd overkill in some cases.

(Signed overflow being a prime example where you really either just need to define what happens or accept that your compiler is basically never going to warn you about a possible signed overflow -- which is UB. The compromise here by Rust is to allow one to pick between some implementation defined behaviors. That seems pretty sensible.)

someplaceguy|1 year ago

Clang has a similar tool, the Clang Static Analyzer: https://clang-analyzer.llvm.org/

Peter0x44|1 year ago

I've found it to have quite poor defaults for its analysis (things like suggesting "use annex k strcpy_s instead of strcpy"). fanalyzer is still by far the easiest to configure.

account42|1 year ago

And had it for much much longer than GCC.

chc4|1 year ago

I have had the exact opposite experience: clang constantly gives me much better error messages than GCC, implementations of some warnings or errors catch more cases, and clang-tidy is able to do much better static analysis.

kolbe|1 year ago

"Copilot explain this error" has made this whole discussion irrelevant for me.

snarfy|1 year ago

This reminds me one of the reasons I hated C++ so much. 1000+ lines of error messages about template instantiation, instead of 'error: missing semicolon'.

danudey|1 year ago

In our programming class in high school we were using Borland C++; I had a classmate call me over to ask about an error they were getting from the compiler.

> "Missing semicolon on line 32"

I looked at it, looked at them, and said "You're missing a semicolon on line 32". They looked at line 32 and, hey! look at that! Forgot a semicolon at the end. Added it and their program worked fine.

Even the best error messages can't help some people.

szhorvat|1 year ago

I'm quite surprised to hear this. What do you get from GCC's analyser that Clang's static analyser doesn't already report?

I tried to use GCC's analyser several times, but I couldn't find any good front ends to it that make the output readable. Clang has multiple (reasonably good HTML output, CodeChecker, Xcode integration, etc.). How do you read the output?

Furthermore, I find that GCC produces many more false positives than Clang.

quincepie|1 year ago

While I wish GCC would implement integrations and/or a language server, I usually do C programming in the terminal (with entr to trigger automatic rebuild on save).

I do find some false positives, but I haven't had many of them to be a deal breaker for me. Aside from what I mentioned about the errors being descriptive, I do like the defaults and that it's part of the compilation process.

for example, possible malloc null warning is on by default (which i don't think is on clang).

darby_eight|1 year ago

I'm quite surprised that clang doesn't have static analysis! That doesn't seem right, but I don't program much in C anymore.

bluGill|1 year ago

It does. However it catches some different things*