Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  


One other thing that's been in the back of my mind for a while is the SOB compiler; the compiler that takes every part of standard C++ that has undefined behavior and tries to define it as crashing as soon as possible. For example: instead of the vptr in a class being a bare pointer to the vtable, the vptr would be xor'ed with the address of the vptr, so that if you did a bitwise copy of a class with virtual functions it'd probably crash fast. I think some of the undefined behavior would actually be recognized at compile time, like using ++i = ++i. I'd probably turn those into errors rather than bothering with crashing the program at runtime, so I'd guess that the compiler would have to be technically non-standards compliant.

Though admittedly some undefined behaviors are less interesting to crash than others. Like calling exit() during the destruction of an object with static storage duration or dereferencing a pointer that's the result of a request for zero size.
Sign in to follow this  


Recommended Comments

It's an interesting idea to contemplate, but I think you'd run into undecidable behaviour fairly quickly if you actually tried to make such a compiler. That is, you wouldn't be able to determine whether a sequence of operations could invoke undefined behaviour or not.

There's a reason for not requiring compilers to emit a diagnostic for undefined behaviour: as far as we know it's not possible in the general case.

Share this comment

Link to comment
Well duh. The point is to try to make undefineded behaviors crash not to make a compiler that emits diagnosis for undefined behavior. It's not like such a compiler would try to track call trees and then crash, its more of goal to make the implementation fragile enough that things that have undefined behavior does the equivalent of yanking a card from the bottom of a house of cards.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!