Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Logic inversion should normally be caught rather easily, flow control misdirections not so much : #define if while .

My favorite (C++) : #define private public



My favorite (C++) : #define private public

Unless I'm mistaken, C++ was (deliberately) specified in such a way that such a redefinition does not affect the behavior of (most) already valid code. Access control doesn't affect overload resolution, for example.

I had to add the (most) qualifier because I bet dynamic_cast<> and other RTTI mechanisms would achieve different runtime results against some classes if private inheritance became public.

Also, I believe that C++ forbids preprocess munging of keywords under penalty of undefined behavior if you include any standard headers, so anything could happen in most modules.


Unless I'm mistaken, C++ was (deliberately) specified in such a way that such a redefinition does not affect the behavior of (most) already valid code.

Perhaps it doesn't change the implementation, but I know I've used the above trick to get access to private functions for unit testing (yes, yes, I know you "should" only test interfaces, or make internal tests; spare me and realize it's useful: http://mrzechonek.github.io/tut-framework/faq.html#can-we-te...)


Funny. Also subtle redefining of Linux commands tar -> zip.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: