0

As the question says: Is there a setting in visual studio that will let me build and run in debug mode, but NOT initialize variables to zero? I run into too many problems when I go to release mode and have to hunt down the things that worked fine in debug and crash in release. I just want to forgo this option in debug mode henceforth, is it possible?

Sorry, I forgot to add: This is for C++

Filburt
  • 17,626
  • 12
  • 64
  • 115
KiraHoneybee
  • 495
  • 3
  • 12
  • Does this answer your question? [C# if/then directives for debug vs release](https://stackoverflow.com/questions/2104099/c-sharp-if-then-directives-for-debug-vs-release) – Filburt Jul 16 '23 at 19:24
  • Maybe see if this page helps https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-debug-and-release-configurations?view=vs-2022 in particular, the optimize code section for each type of framework/language – Timothy G. Jul 16 '23 at 19:25
  • Sorry-- my language is C++, I forgot to mention and added it now. And no, neither of the links have any information on that setting, they're both very basic "how to compile in debug mode" – KiraHoneybee Jul 16 '23 at 19:37
  • 2
    None initialized variables aren't zeroed out in _DEBUG builds. Heap allocations get 0xcd pattern by the crt (https://learn.microsoft.com/en-us/cpp/c-runtime-library/find-memory-leaks-using-the-crt-library). – gast128 Jul 17 '23 at 05:57
  • And, sometimes, local variables get zero-initialized even in release mode. Debugging isn't always the answer to poor programming practices. – Adrian Mole Jul 17 '23 at 06:00
  • 1
    ...and code analysis warns on VS2019 these days for none initialized variables. – gast128 Jul 17 '23 at 06:03
  • There is no option to skip zeroing out because no zeroing out happens in the first place. – n. m. could be an AI Jul 17 '23 at 06:11
  • I think you're confused, uninitialised memory in release mode is likely to be zero if it hasn't been used before by the process. In debug mode all memory is initialised to various different values: https://www.asawicki.info/news_1292_magic_numbers_in_visual_c none of which are zero – Alan Birtles Jul 17 '23 at 06:42
  • Can you provide an example that reproduces your problem? – Minxin Yu - MSFT Jul 17 '23 at 09:19

0 Answers0