3 ms·
> Would be great if somebody could post Python/Ruby/.. code here that achieves the same, just to compare. It's actually really hard to completely rewrite that
by ctz 13y ago
> Would be great if somebody could post Python/Ruby/.. code here that achieves the same, just to compare.
It's actually really hard to completely rewrite that program in most scripting languages: they tend not to have the same concept of undefined behaviour.
'sys.argv[2]' in python (with sys.argv = ['thing.py']) is fully defined (raises an IndexError). 'argv[2]' in C++ (with argv = (char*[2]) { "./thing", 0 }) is undefined.
If you scripting language has an FFI library (ctypes in python, say) then you could probably do something equivalent.
- stinos 13y agogood point about the UB. Together with shin_lao's comment about the error/exception handling bascially sums up why the author's claim only makes some sense, but not a lot.
- mikeash 13y agoDefined behavior is a subset of undefined behavior. Specifically, "raises an IndexError" is a perfectly legal thing for a C++ implementation to do in this case. Approximately zero real world implementations do this, but nothing says they can't.