What every C Programmer should know about undefined behavior #2/3
What every C Programmer should know about undefined behavior #2/3
Posted May 16, 2011 22:56 UTC (Mon) by cmccabe (guest, #60281)In reply to: What every C Programmer should know about undefined behavior #2/3 by njs
Parent article: What every C Programmer should know about undefined behavior #2/3
> gives some kind of 'security' or something (like many documents about it
> seem to think), but because it lets me know for certain (i.e., prove) that
> I only have to look at a certain bounded amount of code if I want to see
> how certain variables are modified
Actually, the "private" keyword in C++ allows you to prove no such thing. I can simply typecast the class to a byte buffer and modify to my heart's content.
If I want to be even more evil, I can add:
#define public private
to the beginning of my .cc file and include the header file for your class. Then nobody will stop me from doing whatever I want with your private data-and methods-- not the compiler, and certainly not the linker.
Java also has a way for "unauthorized" classes to get access to private data. I think you can use the Reflect package to get at it.
Private data in Java and C++ is not and was not intended to provide the kind of guarantees a proof checker would need.
On the other hand, if the goal is to allow the programmer to have a reasonable mental model, they work pretty well!
> I just want better tools for *non-heuristic* reasoning about programs.
Too bad. Artificial intelligence is about at where chemistry was in 1000 AD. Theorem provers are good for proving theorems, but bad at real-world reasoning.
On the other hand, what I can offer you is sandboxed programming langauges and model checkers. It's amazing how much more productive you can be when you have a garbage colector and a good type system.
C.
