Hacker News new | past | comments | ask | show | jobs | submit login

Great post. I’m surprised it requires so much effort. On Windows you pretty just need to make a debug build and… that’s it!

A nice trick with MSVC is you can turn off optimizations for TU or any block of code with:

    #pragma optimize( "", off )
Leaps and bounds easier than hacking the build the system.



Assuming spatulas are absent, I've never had a problem with the build system on Linux. Nonetheless, for GCC the equivalent is:

  #pragma GCC optimize ("O0")
(see also target, push_options, and pop_options)

This is also available as a per-function attribute, using both gnu and standard syntaxes:

  __attribute__((optimize("O0")))
  [[gnu::optimize("O0")]]


For completeness, in Clang `[[clang::optnone]]` as a per-function attribute also works fine. I'm using it for debugging quite frequently lately.


> I’m surprised it requires so much effort. On Windows you pretty just need to make a debug build and... that’s it!

Well, except the Debug build in MSVC doesn't do half of the things from this list. Also, the list tells you how to use the compilation driver directly, so when comparing stuff, you would need to use the "cl.exe" compiler. For a "default" debugging experience it's enough to use CMake's Debug build type. It even has a built-in "release with debug info" build type.


I guess that means not using cmake but using sln and vcxproj and friends, my experience with those was that it's pretty terrible for anything bigger than simple dummy projects.


(author) Nice! I did not know about these pragmas. I have added them to the post as another option and credited y’all in a footnote.


I mean, to be fair, if you're fiddling with/invoking cl.exe manually then you'd need to know a lot of the general equivalents and nits listed here. MSVC's debug build will do a lot for you out of the box though which is great. That said you often have to support/know 400 random build tools when using C++ to enable things like this, so it's often useful knowledge anyway.


>"On Windows you pretty just need to make a debug build and… that’s it!"

I got pretty much the same on Linux when using CLion IDE from JetBrains.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: