Earlier quoted context omitted.
Languages other than C give you options for flow control so that you don't need goto for that. It is a spectrum, if you only use goto to jump to the end of a small function on error it is okay, though I prefer something better in my language. I've seen 30,000 line functions with gotos used for flow control (loops and if branches) - something you can do in C if you are really that stupid and I think we will all agree…
We all agree that you shouldn't write bad code. Not using goto, not using any language construct. But when unbridled gotos were the only tool in the toolbox, bad code was an inevitability in a codebase of any meaningful size. Not even the best programmer was immune. This is what the "Go to statement considered harmful" paper was about. It was written in 1968. We listened. We created languages that addressed the conce…
Improvements to static analysis in GCC 14
71–80 of 147 posts
Re: Improvements to static analysis in GCC 14
#72Earlier quoted context omitted.
Languages other than C give you options for flow control so that you don't need goto for that. It is a spectrum, if you only use goto to jump to the end of a small function on error it is okay, though I prefer something better in my language. I've seen 30,000 line functions with gotos used for flow control (loops and if branches) - something you can do in C if you are really that stupid and I think we will all agree…
> 30,000 line functions with gotos The problem there is the 30K line function, not the goto!
Re: Improvements to static analysis in GCC 14
#73To 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.
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.
Re: Improvements to static analysis in GCC 14
#74Earlier quoted context omitted.
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.
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.
Re: Improvements to static analysis in GCC 14
#75Earlier quoted context omitted.
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.
Not when you called templated functions and were greeted with compile-time template stack traces. Or you called overloaded functions and were presented with 50 alternatives you might have meant. The language is inherently unfriendly to user-friendly error messages.
Re: Improvements to static analysis in GCC 14
#76Earlier quoted context omitted.
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.
> The borrow checker attracts some, but it could have easily been done in a way with terrible usability. Why would anyone use the resulting language over C? What you're describing is C with a slightly friendlier compiler.
Re: Improvements to static analysis in GCC 14
#77Earlier quoted context omitted.
Not when you called templated functions and were greeted with compile-time template stack traces. Or you called overloaded functions and were presented with 50 alternatives you might have meant. The language is inherently unfriendly to user-friendly error messages.
[flagged]
Rust having traits instead of templates is a big ergonomic improvement in that area.
Re: Improvements to static analysis in GCC 14
#78Earlier quoted context omitted.
What's wrong with `strncpy`?
strncpy won't always write a trailing nul byte, causing out of bounds reads elsewhere. It's a nasty little fellow. See the warning at https://linux.die.net/man/3/strncpy strlcpy() is better and what most people think strncpy() is, but still results in truncated strings if not used carefully which can also lead to big problems.
Re: Improvements to static analysis in GCC 14
#79Earlier quoted context omitted.
> The borrow checker attracts some, but it could have easily been done in a way with terrible usability. Why would anyone use the resulting language over C? What you're describing is C with a slightly friendlier compiler.
I have never heard C as being described to have a good type system.
Re: Improvements to static analysis in GCC 14
#80Very cool stuff! I haven't done much C development lately, so I'm curious how often `strcpy` and `strcat` are used. Last I checked they're almost as big no-nos as using goto. (Yes, I know goto is often preferred in kernel dev...) Can anyone share on how helpful the c-string analyses are to them?
There's nothing wrong with simple usages of goto. The strxcpy family on the other hand is complete garbage and should never be used for any reason. I'm horrified that they're used in the kernel at all. All of those functions (and every failed attempt at "fixing" them) should have been nuked from orbit.