Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable "if(0)" elimination in gcc
    text
    copied!<p>How can I prevent GCC from eliminating the code inside <strong>if(0)</strong> block?</p> <p>When I use Visual Studio, one of my debugging techniques is to put code like this in my program:</p> <pre><code>if (0) do_some_debug_printing_and_checking(); </code></pre> <p>Then, when a breakpoint is hit, I click at the <strong>do_some_debug_printing_and_checking()</strong> line, select "set next statement" and force it to execute.</p> <p>When I use gcc/gdb as a back-end, the "set next statement" does not work anymore, as GCC simply removes the code from inside the <strong>if(0)</strong> statement.</p> <p>I am of course using the <strong>-O0</strong> flag to disable optimization. I have also tried the <strong>-fno-dce -fno-tree-dce</strong> flags to disable dead code elimination explicitly, but it has no effect: the contents of <strong>if(0)</strong> is just not present in the binary file and I cannot use <strong>set next statement</strong> to jump into it.</p> <p>Is there any good way to tell gcc to disable elimination of <strong>if(0)</strong> contents?</p> <p>Edit:</p> <p>Thanks for the "additional variable" workaround, however there are 2 things I don't like about it:</p> <ol> <li>It's still an extra line of code</li> <li>It won't be automatically optimized out when I build the release version and do want those debug things to disappear. Surely I can use #ifdef-s, but that's even more extra lines.</li> </ol> <p>Really, there's absolutely no option to make GCC keep that dead code?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload