Live data from Hacker News

PLOS2021: ISO-C became unusable for operating systems

yodaiken.com

11–20 of 100 posts

Re: PLOS2021: ISO-C became unusable for operating systems

#11
How much of this is driven by modern C++ style? I always assumed optimizers needed to become much more aggressive because template-heavy code results in convoluted IR with tons of unreachable code. And UB-based reasoning is the most effective tool to prove unreachability.

Re: PLOS2021: ISO-C became unusable for operating systems

#12
post #7
post #4

I think it's about time to abandon C language entirely.

Sometimes I do wonder if all these UB optimisations aren't pushed by people aiming to make C and C++ unusable, so that people will be forced to move to other languages.

UB = Undefined Behavior ?

Re: PLOS2021: ISO-C became unusable for operating systems

#13
post #6

Earlier quoted context omitted.

Absolutely, those optimisations should be opt-in, otherwise it's impossible to reason about the correctness of your code. At work we had to replace some arithmetic by inline assembly, as there was literally no other way of making the compiler generate the correct expression.

I'm very curious to learn more about this as I thought it was easily possible to opt out of the overly aggressive defaults of GCC, Clang, and the like.

It is possible - but not whilst maintaining standards-compliance and there are always/often another one where you least expect it.

At the root is taking a “assume the programmers know what they are doing” language and turning it into a “assume the programmers are drooling morons” language.

Re: PLOS2021: ISO-C became unusable for operating systems

#14
post #7
post #4

I think it's about time to abandon C language entirely.

Sometimes I do wonder if all these UB optimisations aren't pushed by people aiming to make C and C++ unusable, so that people will be forced to move to other languages.

It has come to my mind too. It is user hostile none the less, blaming the user for writing incorrect but intuitive code. The Stackoverflow mindset?

My favourite is how "x + 1 < x" is optimized away for signed ...

Re: PLOS2021: ISO-C became unusable for operating systems

#15
post #7

Earlier quoted context omitted.

Sometimes I do wonder if all these UB optimisations aren't pushed by people aiming to make C and C++ unusable, so that people will be forced to move to other languages.

It has come to my mind too. It is user hostile none the less, blaming the user for writing incorrect but intuitive code. The Stackoverflow mindset? My favourite is how "x + 1 < x" is optimized away for signed ...

If a warning is issued in that case I'm tempted to say it's fair game. If you are sure it'd safe the compiler has extremely well established ways of telling it (i.e. assume or unreachable)

Re: PLOS2021: ISO-C became unusable for operating systems

#16
post #11

How much of this is driven by modern C++ style? I always assumed optimizers needed to become much more aggressive because template-heavy code results in convoluted IR with tons of unreachable code. And UB-based reasoning is the most effective tool to prove unreachability.

> template-heavy code results in convoluted IR with tons of unreachable code

Does it? Honest question; my impression was that template-heavy code can tend to produce deep call trees, but not necessarily outright unreachable code unless you count instantiations ruled out by SFINAE/std::enable_if/tag dispatching, for which UB-based analyses are not necessary.

In addition, I thought template (meta)programming relied very heavily on compile-time knowledge, which seems to obviate the need for UB-based analyses in many cases.

I'm not particularly experienced, though, so maybe there's a gaping hole I'm missing.

Re: PLOS2021: ISO-C became unusable for operating systems

#17
post #7

Earlier quoted context omitted.

Sometimes I do wonder if all these UB optimisations aren't pushed by people aiming to make C and C++ unusable, so that people will be forced to move to other languages.

UB = Undefined Behavior ?

correct. In my experience a focus on UB (often actually said U.B.) tends to come from the C++ community, although a lot of it trickles down to the C community as well. I can recommend watching a few talks from C++ conferences. I especially enjoyed ones by Matt Godbolt, and Miro Knejp.

Re: PLOS2021: ISO-C became unusable for operating systems

#18
post #11

How much of this is driven by modern C++ style? I always assumed optimizers needed to become much more aggressive because template-heavy code results in convoluted IR with tons of unreachable code. And UB-based reasoning is the most effective tool to prove unreachability.

None of it: we're talking about C here, and every point in the article applies to the C standard as it existed when Linus posted his message to comp.os.minux so long ago.

Re: PLOS2021: ISO-C became unusable for operating systems

#19
post #7

Earlier quoted context omitted.

Sometimes I do wonder if all these UB optimisations aren't pushed by people aiming to make C and C++ unusable, so that people will be forced to move to other languages.

It has come to my mind too. It is user hostile none the less, blaming the user for writing incorrect but intuitive code. The Stackoverflow mindset? My favourite is how "x + 1 < x" is optimized away for signed ...

That is the fault of compilers, not the language. That thing should rise at maximum a warning. A compiler should not change the semantic of the code, even if the code relies on undefined/unspecified behavior. I don't get how someone thought that it is a good idea to silently remove apparently unreachable code.

Re: PLOS2021: ISO-C became unusable for operating systems

#20
post #3

The fact that a compiler is allowed/encouraged to silently remove whole sections of code because of some obscure factoid is an amazing source of footguns. At least the warnings are getting a bit better for some of these.

Without these optimizations, you can't write fast scientific code in C. This was realized back in the early 1980s and it's why those rules were added.

In Fortran the aliasing rules are even stricter: given two arrays passed in as arguments the compiler can assume that they do not overlap, for example. I remember messing that up as a student long ago and getting strange results. The Fortran rule was to enable vectorization, which has been done for many decades.

Post reply on HN