You are viewing a single thread.
View all comments
5 points

Should focus on getting rid of undefined behavior.

permalink
report
reply
1 point

Should focus on getting rid of undefined behavior.

What problem do you believe is presented by undefined behavior?

permalink
report
parent
reply
2 points

It violates the principle of least surprise. You don’t expect the compiler to delete your bounds checking etc.

The way c and c++ define and use UB is like finding an error at compile time and instead of reporting it, the compiler decides to exploit it.

permalink
report
parent
reply
1 point
*

It violates the principle of least surprise.

It really doesn’t. I recommend you get acquainted with what undefined behavior is, and how it’s handled by developers.

You don’t expect the compiler to delete your bounds checking etc.

By design, undefined behavior has a very specific purpose. Newbies are instructed to consider code that leads to undefined behavior as a bug they introduced. For decades compilers and static code analysis tools can detect and flag undefined behavior as errors in your code.

As I said before, sometimes it seems clueless developers parrot on about “undefined behavior” as some kind of gotcha although they clearly have no idea what they are talking about. Sometimes it sounds like they heard it somewhere and just mindlessly repeat it as if it meant something.

The way c and c++ define and use UB is like finding an error at compile time and instead of reporting it, the compiler decides to exploit it.

What are you talking about? Compilers can and do flag undefined behavior as errors. I recommend you read up on the documentation of any compiler.

Also, I don’t think you fully understand the subject. For example, as an example, some compiler implementations leverage UB to add failsafes to production code such as preventing programs from crashing when, say, null pointers are dereferenced. We can waste everyone’s time debating whether null pointers should be dereferenced, but what’s not up for discussion is that, given the choice, professional teams prefer that their code doesn’t crash in users’ machine if it stumbles upon one of these errors.

permalink
report
parent
reply

C++

!cpp@programming.dev

Create post

The center for all discussion and news regarding C++.

Rules

  • Respect instance rules.
  • Don’t be a jerk.
  • Please keep all posts related to C++.

Community stats

  • 1

    Monthly active users

  • 125

    Posts

  • 79

    Comments