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

I use this sometimes with some C/C++ code.

Mostly, if I want a break somewhere I do this:

  *(int*)0 = 1;
Which will result in a crash, I attach my debugger, run the code and if it reaches that line it will break and I can inspect everything I want.

It's easier than adding a __asm(int3) because it's cross platform. On windows for example it's not possible to perform inline assembly in x64 builds, and compiler intrinsics are not portable.



Have you ever had issues with the compiler removing/ignoring that line when optimizations are turned on?


No, could it? If I ever noticed it I would make it a bit more complex.


On windows you can just call DebugBreak();


Yes, but most of my code is written to be as portable as possible, if not outright cross-platform.


Using undefined behaviour like this is the opposite of portable.




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

Search: