logoalt Hacker News

horseloverthin • yesterday at 9:53 PM • 1 reply • view on HN

A good way to think about contracts and related features as they relate to memory safety is from the compilers perspective; pretty much any feature that gives the compiler additional information about a users intent for a scope allows the compiler to have to infer less, and thus have more ability to provide 'safety' guarantees.

The most trivial example of this is a check that a caller has provided non-null inputs ( hence allowing 'safe' unchecked access in most cases)


Replies

cpgxiii • yesterday at 10:42 PM

If you're going to rewrite a bunch of C++ to add contracts to assert that your pointer arguments are non-null ... you could, I don't know, just use references instead, the exact construct we have had for decades to express this. If you're cargo-culting the GSG so much you're unwilling to use references appropriately I seriously doubt you are also going to replace whatever existing "pointer argument x is non-null" checks you use with a brand-new contracts mechanism.

➕ show 1 reply