News for hackers. Stuff that matters.
Re:You Can't Always Hash Pointers in C by Bromskloss on Tuesday May 31, 2016 @06:35AM (#11805752)
> I wish "undefined behavior" wasn't a thing in C/C++. It's not worth it. :(

What do you suggest instead? Run-time checks?

Re:You Can't Always Hash Pointers in C by pjmlp on Tuesday May 31, 2016 @07:13AM (#11805863)
Have a proper defined behavior like most sane languages.

The only reason UB exists was that when ANSI C came to be, the compiler writers and hardware vendors that provided C like compilers didn't want to give up on their semantics.

So in order to please everyone, all the semantics that could not be defined on the standard became UB.

Re:You Can't Always Hash Pointers in C by saynsedit on Tuesday May 31, 2016 @12:29PM (#11807515)
I don't think UB is bad. It's a reasonable thing to do when someone invokes an operation with bad input.

For instance, what should `sqrt(-1)` be? Or `head([])`?

You can define all behavior and say "bad input will throw an exception" or "bad input will abort the entire program" but who really cares what it does since it's a malformed program in the first place? Just say it's undefined and it's up to the programmer to make sure it never happens. Otherwise you're littering your code with countless checks for things that should never happen in a properly coded program.

Programmer error is distinct from operational error. There is no sane thing to do in a program error. Constantly checking for programmer error at runtime is wasteful.

Re:You Can't Always Hash Pointers in C by unlinker on Tuesday May 31, 2016 @07:24AM (#11805889)
That is untrue. UB exists because C is supposed to run on so many platforms there is no way to have a defined behaviour for all of them in that standard.
Re:You Can't Always Hash Pointers in C by scott_s on Tuesday May 31, 2016 @09:53AM (#11806485)
You are confusing undefined behavior with implementation defined behavior.
Re:You Can't Always Hash Pointers in C by wongarsu on Tuesday May 31, 2016 @07:38AM (#11805943)
More importantly, C is not only supposed to run on many platforms (many programming languages do that), but also provide very low-level control on wide variety of platforms.
Re:You Can't Always Hash Pointers in C by pjmlp on Tuesday May 31, 2016 @08:26AM (#11806123)
Which people keep forgetting is only available as implementation defined extensions, as such it is no longer ANSI C and any language compiler is free to have extensions.
Re:You Can't Always Hash Pointers in C by jjnoakes on Tuesday May 31, 2016 @07:51AM (#11805986)
This is why implementation defined behavior exists.

Undefined behavior though?

Re:You Can't Always Hash Pointers in C by pjmlp on Tuesday May 31, 2016 @08:25AM (#11806113)
I was already coding before C had any meaning outside UNIX.