News for hackers. Stuff that matters.
Re:The Value of Undefined Behavior by taneq on Saturday July 21, 2018 @11:26PM (#17585138)
In a perfect world it would either be impossible by design or result in a compile error. I'd settle for "reliably crash with an error message saying where in the code it happened".
Re:The Value of Undefined Behavior by clarry on Sunday July 22, 2018 @02:32AM (#17585539)
I believe that would be impossible to implement without never reusing addresses or actually bolting on a GC.

If you never reuse addresses, long running programs will have some trouble ahead.

Oh, it's not even that simple because you'd have to make access to the region atomic.

Re:The Value of Undefined Behavior by millstone on Sunday July 22, 2018 @03:21AM (#17585648)
What language would you write this hypothetical GC in?
Re:The Value of Undefined Behavior by bluecalm on Sunday July 22, 2018 @02:31AM (#17585538)
You can get it in C. Just set the pointer to NULL after free, you will get your crash, problem solved.
Re:The Value of Undefined Behavior by taneq on Sunday July 22, 2018 @04:20AM (#17585819)
True, you can even macro it for more convenience. I'm more worried about things where some obscure edge case causes the compiler to optimise away something important because it's deemed to be UB.
Re:The Value of Undefined Behavior by gpderetta on Sunday July 22, 2018 @07:47AM (#17586292)
How would that work if you have two pointers pointing to the same object?
Re:The Value of Undefined Behavior by bluecalm on Sunday July 22, 2018 @08:56AM (#17586490)
If your design is such that you destroy thinks more pointers point to you have way bigger issues than UB or even language you use.
Re:The Value of Undefined Behavior by gpderetta on Wednesday July 25, 2018 @06:28AM (#17608191)
Are you saying that a program should have exactly one pointer to each allocated object?
Re:The Value of Undefined Behavior by lomnakkus on Sunday July 22, 2018 @04:30AM (#17585850)
No, you'll get UB.
Re:The Value of Undefined Behavior by bluecalm on Sunday July 22, 2018 @08:40AM (#17586436)
Obviously you check for NULL first. If something may or may not exists you first ask if it exists (check for NULL) and then of it exists you do something with it. When you free something you destroy it, that's why it's useful to set the pointer which before pointed to it to NULL.
Re:The Value of Undefined Behavior by lomnakkus on Friday July 27, 2018 @03:08PM (#17628363)
I just (well, a few days ago) explained to you that your suggested "solution" would result in UB.

Then you come up with the "solution" that everybody must always check for NULL pointers before dereferencing them. If everybody always did that we might as well just define the behavior of reference-after-free, because what you said either a) requires you to keep a reference count (or null-check before every deref which may be even more expensive) at runtime(!), or b) requires a program-level proof.

So... no. What you suggested is not a solution in any meaningful sense.