News for hackers. Stuff that matters.
Re:My C code works with -O3 but not with -O0 by gameswithgo on Thursday January 16, 2020 @08:11AM (#22064121)
or just start moving away from using c. the last five years have brought nice alternatives like zig and rust
Re:My C code works with -O3 but not with -O0 by gnulinux on Thursday January 16, 2020 @11:01AM (#22065738)
So start over 40 years of progress? Everything in my OS is written in C. Why am I always told not to use this language in HN if it's what my computer runs on. It's dangerous, sure, but seems like as a software engineer it's something I need to learn instead of run away from.
Re:My C code works with -O3 but not with -O0 by apta on Thursday January 16, 2020 @11:22AM (#22065972)
Progress is exactly what brought us safe languages. Proper engineering dictates eliminating, or reducing as much as possible dangerous/unsafe/etc. behavior. There's a reason C and C++ top the CVE lists with their buffer overflows and undefined behavior.

It's pretty much established that even expert C and C++ programmers, especially for larger code bases, will end up making some sort of mistake that will cause a security vulnerability or undefined behavior.

Re:My C code works with -O3 but not with -O0 by gnulinux on Thursday January 16, 2020 @12:11PM (#22066513)
That's not my point, I don't contest that safe languages are safer. I contest the idea that we should "just use" something else. All my tools are written in C, the entire GNU toolchain is in C, how am I supposed to operate in this world if I "just don't use" C?
Re:My C code works with -O3 but not with -O0 by benibela on Thursday January 16, 2020 @05:54PM (#22069949)
That is the disadvantage of open-source, it forces you to use the language of someone else's source.

I used Delphi on Windows. Most of the code I wrote in the last 20 years is in Pascal.

And that works really well on Windows. You have a stable API, and it does not matter what language the API is written in. Any language can use the API in the same way.

I tried to run some old projects this month. My 20 year old Delphi Windows programs run better in WINE on Linux than most programs I wrote 5 years using Linux tools, because the libraries have changed, but the API has not

Re:My C code works with -O3 but not with -O0 by apta on Thursday January 16, 2020 @01:13PM (#22067204)
I think OP was implying not to write new code in C. If possible, we can also use replacement tools written in safer languages if they offer the functionality we need (e.g. `ripgrep` instead of `grep`, or web servers written in safe languages over those written in C/C++).
Re:My C code works with -O3 but not with -O0 by boomer_joe on Thursday January 16, 2020 @01:36PM (#22067434)
ripgrep isn't POSIX compliant. It's hardly a proper replacement.
Re:My C code works with -O3 but not with -O0 by burntsushi on Thursday January 16, 2020 @04:06PM (#22068922)
Right, it is intentionally not POSIX compliant. This saves fairly significant development effort and also permits expanding the tool to be more user friendly, such as transparently searching UTF-16 encoded files.

ripgrep cannot be a drop-in replacement. Despite that, it can certainly replace grep in a wide variety of use cases. See: https://github.com/BurntSushi/ripgrep/blob/master/FAQ.md#pos...

Re:My C code works with -O3 but not with -O0 by 0xdead on Thursday January 16, 2020 @04:42PM (#22069291)
Congratulations. You have succesfully regurgitated the same sentence I've read here a thousand times.
Re:My C code works with -O3 but not with -O0 by pjmlp on Thursday January 16, 2020 @09:21AM (#22064725)
Not only the last 5 years, but I digress.
Re:My C code works with -O3 but not with -O0 by Chlorus on Thursday January 16, 2020 @12:17PM (#22066573)
Yeah, it's kind of weird how little attention some of C's (historical)competitors in the systems programming space get. You'd think to see a lot of comparisons to whatever Ada* or Pascal would do in the same context.

* Probably because the Ada practitioners are all trapped in Scifs somewhere in the inner mantle of the Earth.

Re:My C code works with -O3 but not with -O0 by benibela on Thursday January 16, 2020 @05:25PM (#22069682)
That is why I use Pascal

20 years ago it was advertised as the safe C alternative.

Re:My C code works with -O3 but not with -O0 by 0xdead on Thursday January 16, 2020 @09:49AM (#22064975)
No. I'd rather learn how to use my tools (that I have invested years to be comfortable with) properly than starting over.
Re:My C code works with -O3 but not with -O0 by erik_seaberg on Thursday January 16, 2020 @05:54PM (#22069947)
I would have trouble convincing myself I'm capable of writing C that doesn't blow up randomly, when everyone else has been failing at that for my entire career and more.
Re:My C code works with -O3 but not with -O0 by adamnemecek on Thursday January 16, 2020 @03:34PM (#22068580)
C is not very productive.
Re:My C code works with -O3 but not with -O0 by smabie on Thursday January 16, 2020 @05:59PM (#22069992)
Maybe, but it’s super fun and elegant. C and Scheme are at the top of my “most elegant” list. Though, of course, for different reasons.