3 ms·
In C, you can wrap the 'commented' code with #if 0 ... #endif
by throwaway744678 6y ago
In C, you can wrap the 'commented' code with #if 0 ... #endif
- hazeii 6y agoOr indeed if rewriting a block of code: #if 1 ....new code... #else ....old code... #endif Esp. for tricky stuff, it's then possible to just flip the 1/0 to easily test/compare/profile the new/old code. Some IDE's will even work out which block of code to colour and which to dim.
- jack_riminton 6y agoWhy have I never thought of that?
- _0ffh 6y agoI do the same, even in languages without a preprocessor. You can just use a life if-else, most compilers will optimize the test-on-a-constant away. Even when the code is kept in, I doubt it will have a major performance impact during testing in most cases.
- yitchelle 6y agoI would do a bit more by #if !defined(this_works_but_it_suck_memory_too_hard) .... #else .... #endif That should give me a clue why I "disabled" it when I come back to it 5 minutes later.
- MauranKilom 6y agoI usually just do this with a comment behind the #if false. Yes, nobody is probably ever going to define that particular identifier, but comments are also less restrictive (you can write normal text).
- unfunco 6y agoIn languages with multiline comments like /* and single-line comments like //, you can do: //* old_code(); /*/ new_code(); //*/ And remove the first slash from the first line to switch between blocks.